Skip to content

Commit

Permalink
In inference, make string constants module local
Browse files Browse the repository at this point in the history
During inference, we can end up in a situation where the stack looks like

COMPILE B
CALL B
COMPILE A
CALL A

If A and B are methods of the same functions, it is likely that they share
string constants, but in MCJIT these will be allocated in the module for A,
so when B references them, the call to B tries to materialize the modules for
both A and B, leading to an assertion failure, because the compile for A is
not finished yet. Work around this by disabling string constant pooling in
inference. The proper fix is to write an LLVM pass that records the location
of global constants before the module is emitted and merges them there.
  • Loading branch information
Keno committed Mar 19, 2015
1 parent 0d47fd7 commit da3d7d5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,18 @@ static inline void add_named_global(GlobalValue *gv, void *addr)
// --- string constants ---
static std::map<const std::string, GlobalVariable*> stringConstants;

extern "C" {
extern int jl_in_inference;
}

static GlobalVariable *stringConst(const std::string &txt)
{
GlobalVariable *gv = stringConstants[txt];
static int strno = 0;
if (gv == NULL) {
// in inference, we can not share string constants between
// modules as there might be multiple compiles on the stack
// with calls in between them.
if (gv == NULL || jl_in_inference) {
std::stringstream ssno;
std::string vname;
ssno << strno;
Expand All @@ -102,6 +109,7 @@ static GlobalVariable *stringConst(const std::string &txt)
txt.length()+1)),
#endif
vname);
gv->setUnnamedAddr(true);
stringConstants[txt] = gv;
strno++;
}
Expand Down
6 changes: 6 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3520,9 +3520,15 @@ static void finalize_gc_frame(jl_codectx_t *ctx)
Instruction *after = ctx->argSpaceInits;

for(size_t i=0; i < (size_t)ctx->maxDepth; i++) {
#ifdef LLVM37
Instruction *argTempi =
GetElementPtrInst::Create(NULL,newgcframe,
ConstantInt::get(T_int32, i+ctx->argSpaceOffs+2));
#else
Instruction *argTempi =
GetElementPtrInst::Create(newgcframe,
ConstantInt::get(T_int32, i+ctx->argSpaceOffs+2));
#endif
instList.insertAfter(after, argTempi);
after = new StoreInst(V_null, argTempi);
instList.insertAfter(argTempi, after);
Expand Down

0 comments on commit da3d7d5

Please sign in to comment.