Skip to content

Commit

Permalink
Create tbaa_gcframe and decorate all stores and loads from the GC fra…
Browse files Browse the repository at this point in the history
…me with it. Close #13301
  • Loading branch information
yuyichao committed Jan 31, 2016
1 parent f228b83 commit 7124144
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ static MDNode *tbaa_sveclen; // The len in a jl_svec_t
static MDNode *tbaa_func; // A jl_function_t
static MDNode *tbaa_datatype; // A jl_datatype_t
static MDNode *tbaa_const; // Memory that is immutable by the time LLVM can see it
static MDNode *tbaa_gcframe; // A GC frame

// Basic DITypes
#ifdef LLVM37
Expand Down Expand Up @@ -3792,6 +3793,46 @@ static void clear_gc_frame(jl_gcinfo_t *gc)
il.erase(gc->last_gcframe_inst);
}

// Decorate all stores and loads of derived pointers from the GC frame to have
// tbaa_gcframe
static void
tbaa_decorate_gcframe(std::set<Instruction*> &visited, Instruction *inst)
{
if (visited.find(inst) != visited.end())
return;
visited.insert(inst);
#ifdef LLVM35
Value::user_iterator I = inst->user_begin(), E = inst->user_end();
#else
Value::use_iterator I = inst->use_begin(), E = inst->use_end();
#endif
for (;I != E;++I) {
Instruction *user = dyn_cast<Instruction>(*I);
if (!user) {
continue;
} else if (isa<GetElementPtrInst>(user)) {
if (__likely(user->getOperand(0) == inst)) {
tbaa_decorate_gcframe(visited, user);
}
} else if (isa<StoreInst>(user)) {
if (user->getOperand(1) == inst) {
tbaa_decorate(tbaa_gcframe, user);
}
} else if (isa<LoadInst>(user)) {
tbaa_decorate(tbaa_gcframe, user);
} else if (isa<BitCastInst>(user)) {
tbaa_decorate_gcframe(visited, user);
}
}
}

static void
tbaa_decorate_gcframe(jl_codectx_t *ctx)
{
std::set<Instruction*> visited;
tbaa_decorate_gcframe(visited, ctx->gc.gcframe);
}

static void
emit_gcpops(jl_codectx_t *ctx)
{
Expand Down Expand Up @@ -3838,6 +3879,7 @@ static void finalize_gc_frame(jl_codectx_t *ctx)
builder.CreateStore(V_null, argTempi);
}
emit_gcpops(ctx);
tbaa_decorate_gcframe(ctx);
}

// here argt does not include the leading function type argument
Expand Down Expand Up @@ -5223,6 +5265,7 @@ static void init_julia_llvm_env(Module *m)
tbaa_func = tbaa_make_child("jtbaa_func",tbaa_value);
tbaa_datatype = tbaa_make_child("jtbaa_datatype",tbaa_value);
tbaa_const = tbaa_make_child("jtbaa_const",tbaa_root,true);
tbaa_gcframe = tbaa_make_child("jtbaa_gcframe",tbaa_root);

// every variable or function mapped in this function must be
// exported from libjulia, to support static compilation
Expand Down

0 comments on commit 7124144

Please sign in to comment.