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 Oct 6, 2015
1 parent 592620f commit 925e78b
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,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

namespace llvm {
extern Pass *createLowerSimdLoopPass();
Expand Down Expand Up @@ -3737,6 +3738,43 @@ 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);
// LLVM 3.3 doesn't have user_iterator ....
for (Value::use_iterator I = inst->use_begin(), E = inst->use_end();
I != E;++I) {
Instruction *user = dyn_cast<Instruction>(I->getUser());
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 @@ -3783,6 +3821,7 @@ static void finalize_gc_frame(jl_codectx_t *ctx)
builder.CreateStore(V_null, argTempi);
}
emit_gcpops(ctx);
tbaa_decorate_gcframe(ctx);
}

static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_tupletype_t *argt, int64_t isref)
Expand Down Expand Up @@ -5232,6 +5271,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 925e78b

Please sign in to comment.