Skip to content

Commit

Permalink
More LLVM 3.7 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Keno committed Apr 27, 2015
1 parent 0398bb2 commit a344d33
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 25 deletions.
15 changes: 13 additions & 2 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,22 +255,33 @@ class FunctionMover : public ValueMaterializer
};
#endif

#ifdef LLVM37
static MDType *julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed = false)
#else
static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed = false)
#endif
{
if (jl_is_abstracttype(jt) || !jl_is_datatype(jt) || !jl_isbits(jt) || isboxed)
return jl_pvalue_dillvmt;
jl_datatype_t *jdt = (jl_datatype_t*)jt;
if (jdt->ditype != NULL)
if (jdt->ditype != NULL) {
#ifdef LLVM37
return DIType((llvm::MDType*)jdt->ditype);
return (llvm::MDType*)jdt->ditype;
#else
return DIType((llvm::MDNode*)jdt->ditype);
#endif
}
if (jl_is_bitstype(jt)) {
#ifdef LLVM37
llvm::MDType *t = dbuilder->createBasicType(jdt->name->name->name,jdt->size,jdt->alignment,llvm::dwarf::DW_ATE_unsigned);
jdt->ditype = t;
return t;
#else
DIType t = dbuilder->createBasicType(jdt->name->name->name,jdt->size,jdt->alignment,llvm::dwarf::DW_ATE_unsigned);
MDNode *M = t;
jdt->ditype = M;
return t;
#endif
}
// TODO: Fixme
return jl_pvalue_dillvmt;
Expand Down
77 changes: 62 additions & 15 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@
#include <llvm/Assembly/Parser.h>
#include <llvm/Analysis/Verifier.h>
#endif
#ifdef LLVM37
#include <llvm/DebugInfo/DWARF/DIContext.h>
#else
#include <llvm/DebugInfo/DIContext.h>
#endif
#ifdef USE_MCJIT
#include <llvm/ExecutionEngine/MCJIT.h>
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
Expand Down Expand Up @@ -218,6 +214,12 @@ namespace llvm {
}

// Basic DITypes
#ifdef LLVM37
static MDCompositeType *jl_value_dillvmt;
static MDDerivedType *jl_pvalue_dillvmt;
static MDDerivedType *jl_ppvalue_dillvmt;
static MDSubroutineType *jl_di_func_sig;
#else
static DICompositeType jl_value_dillvmt;
static DIDerivedType jl_pvalue_dillvmt;
static DIDerivedType jl_ppvalue_dillvmt;
Expand All @@ -226,6 +228,7 @@ DISubroutineType jl_di_func_sig;
#else
DICompositeType jl_di_func_sig;
#endif
#endif

// constants
static Value *V_null;
Expand Down Expand Up @@ -340,7 +343,11 @@ struct jl_varinfo_t {
Value *memvalue; // an address, if the var is alloca'd
Value *SAvalue; // register, if the var is SSA
Value *passedAs; // if an argument, the original passed value
#ifdef LLVM37
MDLocalVariable *dinfo;
#else
DIVariable dinfo;
#endif
int closureidx; // index in closure env, or -1
bool isAssigned;
bool isCaptured;
Expand All @@ -355,7 +362,12 @@ struct jl_varinfo_t {
jl_value_t *declType;
jl_value_t *initExpr; // initializing expression for SSA variables

jl_varinfo_t() : memvalue(NULL), SAvalue(NULL), passedAs(NULL), dinfo(DIVariable()),
jl_varinfo_t() : memvalue(NULL), SAvalue(NULL), passedAs(NULL),
#ifdef LLVM37
dinfo(NULL),
#else
dinfo(DIVariable()),
#endif
closureidx(-1), isAssigned(true), isCaptured(false), isSA(false),
isVolatile(false), isArgument(false), isGhost(false), hasGCRoot(false),
escapes(true), usedUndef(false), used(false),
Expand Down Expand Up @@ -1514,8 +1526,13 @@ static Value *make_gcroot(Value *v, jl_codectx_t *ctx, jl_sym_t *var)
addr.push_back(llvm::dwarf::DW_OP_plus);
addr.push_back(slot * sizeof(void*));
addr.push_back(llvm::dwarf::DW_OP_deref);
#ifdef LLVM37
ctx->dbuilder->insertDeclare(ctx->argTemp, it->second.dinfo,
ctx->dbuilder->createExpression(addr),builder.getCurrentDebugLocation().get(),builder.GetInsertBlock());
#else
ctx->dbuilder->insertDeclare(ctx->argTemp, it->second.dinfo,
ctx->dbuilder->createExpression(addr), builder.GetInsertBlock());
ctx->dbuilder->createExpression(addr),builder.GetInsertBlock());
#endif
}
}
}
Expand Down Expand Up @@ -3215,8 +3232,14 @@ static Value *alloc_local(jl_sym_t *s, jl_codectx_t *ctx)
}
vi.memvalue = lv;
#ifdef LLVM36
if (!vi.isGhost && ctx->debug_enabled)
if (!vi.isGhost && ctx->debug_enabled) {
#ifdef LLVM37
ctx->dbuilder->insertDeclare(lv,vi.dinfo,ctx->dbuilder->createExpression(),
builder.getCurrentDebugLocation().get(),builder.GetInsertBlock());
#else
ctx->dbuilder->insertDeclare(lv,vi.dinfo,ctx->dbuilder->createExpression(),builder.GetInsertBlock());
#endif
}
#endif
return lv;
}
Expand Down Expand Up @@ -3927,8 +3950,13 @@ static Function *emit_function(jl_lambda_info_t *lam)

DIBuilder dbuilder(*m);
ctx.dbuilder = &dbuilder;
#ifdef LLVM37
MDFile *fil = NULL;
MDSubprogram *SP;
#else
DIFile fil;
DISubprogram SP;
#endif

BasicBlock *b0 = BasicBlock::Create(jl_LLVMContext, "top", f);
builder.SetInsertPoint(b0);
Expand All @@ -3949,15 +3977,16 @@ static Function *emit_function(jl_lambda_info_t *lam)
// TODO: Fix when moving to new LLVM version
#ifndef LLVM34
dbuilder.createCompileUnit(0x01, filename, ".", "julia", true, "", 0);
#elif LLVM37
MDCompileUnit *CU = dbuilder.createCompileUnit(0x01, filename, ".", "julia", true, "", 0);
#else
DICompileUnit CU = dbuilder.createCompileUnit(0x01, filename, ".", "julia", true, "", 0);
#ifndef LLVM37
assert(CU.Verify());
#endif
#endif


#ifdef LLVM36
#ifdef LLVM37
MDSubroutineType *subrty;
#elif LLVM36
DISubroutineType subrty;
#else
DICompositeType subrty;
Expand All @@ -3967,7 +3996,6 @@ static Function *emit_function(jl_lambda_info_t *lam)
subrty = jl_di_func_sig;
}
else {
llvm::DIArray EltTypeArray;
#ifdef LLVM36
std::vector<Metadata*> ditypes(0);
#else
Expand Down Expand Up @@ -4099,8 +4127,14 @@ static Function *emit_function(jl_lambda_info_t *lam)
addr.push_back(llvm::dwarf::DW_OP_plus);
addr.push_back(argIdx * sizeof(void*));
//addr.push_back(llvm::dwarf::DW_OP_deref);
#ifdef LLVM37
ctx.dbuilder->insertDbgValueIntrinsic(argArray, 0, ctx.vars[s].dinfo,
ctx.dbuilder->createExpression(addr),
builder.getCurrentDebugLocation().get(), builder.GetInsertBlock());
#else
ctx.dbuilder->insertDbgValueIntrinsic(argArray, 0, ctx.vars[s].dinfo,
ctx.dbuilder->createExpression(addr), builder.GetInsertBlock());
#endif
}
argIdx++;
}
Expand Down Expand Up @@ -4455,8 +4489,13 @@ static Function *emit_function(jl_lambda_info_t *lam)
MDNode *scope;
if (dfil == NULL)
scope = SP;
else
else {
#ifdef LLVM37
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,dfil);
#else
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,DIFile(dfil));
#endif
}
builder.SetCurrentDebugLocation(DebugLoc::get(lno, 1, scope, NULL));
}
if (do_coverage)
Expand Down Expand Up @@ -4691,22 +4730,30 @@ static void init_julia_llvm_env(Module *m)
jl_value_llvmt = valueSt;

DIBuilder dbuilder(*m);
#ifdef LLVM37
MDFile *julia_h = dbuilder.createFile("julia.h","");
jl_value_dillvmt = dbuilder.createStructType(nullptr,
#else
DIFile julia_h = dbuilder.createFile("julia.h","");

jl_value_dillvmt = dbuilder.createStructType(DIDescriptor(),
#endif
"jl_value_t",
julia_h,
71, // At the time of this writing. Not sure if it's worth it to keep this in sync
sizeof(jl_value_t)*8,
__alignof__(jl_value_t)*8,
0, // Flags
#ifdef LLVM37
nullptr, // Derived from
nullptr); // Elements - will be corrected later
#else
DIType(), // Derived from
DIArray()); // Elements - will be corrected later
#endif

jl_pvalue_dillvmt = dbuilder.createPointerType(jl_value_dillvmt,sizeof(jl_value_t*)*8,
__alignof__(jl_value_t*)*8);

DIArray types;
#ifdef LLVM36
SmallVector<llvm::Metadata *, 1> Elts;
std::vector<Metadata*> diargs(0);
Expand Down
13 changes: 9 additions & 4 deletions src/debuginfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
#include "llvm-version.h"
#include <llvm/ExecutionEngine/ExecutionEngine.h>
#include <llvm/ExecutionEngine/JITEventListener.h>
#ifdef LLVM37
#include <llvm/DebugInfo/DWARF/DIContext.h>
#else
#include <llvm/DebugInfo/DIContext.h>
#ifdef LLVM37
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#endif
#include <llvm/Support/MemoryBuffer.h>
#include <llvm/IR/Function.h>
Expand Down Expand Up @@ -640,7 +639,9 @@ void jl_getDylibFunctionInfo(const char **name, size_t *line, const char **filen
#ifdef _OS_DARWIN_
if (getObjUUID(morigobj,uuid2) && memcmp(uuid,uuid2,sizeof(uuid)) == 0) {
#endif
#ifdef LLVM36
#ifdef LLVM37
context = new DWARFContextInMemory(*obj);
#elif LLVM36
context = DIContext::getDWARFContext(*obj);
#else
context = DIContext::getDWARFContext(obj);
Expand Down Expand Up @@ -710,7 +711,11 @@ void jl_getFunctionInfo(const char **name, size_t *line, const char **filename,
DIContext *context = NULL; // current versions of MCJIT can't handle MachO relocations
#else
#ifdef LLVM36
#ifdef LLVM37
DIContext *context = new DWARFContextInMemory(*it->second.object);
#else
DIContext *context = DIContext::getDWARFContext(*it->second.object);
#endif
pointer -= (*it).second.slide;
#else
DIContext *context = DIContext::getDWARFContext(const_cast<object::ObjectFile*>(it->second.object));
Expand Down
9 changes: 5 additions & 4 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,9 @@
#endif
#include <llvm/ExecutionEngine/JITEventListener.h>
#include <llvm/IR/LLVMContext.h>
#ifdef LLVM37
#include <llvm/DebugInfo/DWARF/DIContext.h>
#else
#include <llvm/DebugInfo/DIContext.h>
#ifdef LLVM37
#include "llvm/DebugInfo/DWARF/DWARFContext.h"
#endif
#ifdef LLVM35
#include <llvm/IR/DebugInfo.h>
Expand Down Expand Up @@ -387,7 +386,9 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, size_t slide,

#ifdef USE_MCJIT
if (!objectfile) return;
#ifdef LLVM36
#ifdef LLVM37
DIContext *di_ctx = new DWARFContextInMemory(*objectfile);
#elif LLVM36
DIContext *di_ctx = DIContext::getDWARFContext(*objectfile);
#else
DIContext *di_ctx = DIContext::getDWARFContext(const_cast<object::ObjectFile*>(objectfile));
Expand Down

0 comments on commit a344d33

Please sign in to comment.