From 038abd2354fe1d63617b91a31ad95995546a8624 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Thu, 4 Aug 2016 18:56:04 -0700 Subject: [PATCH] Use JL_LLVM_VERSION instead of LLVMxx in the preprocessor --- src/APInt-C.cpp | 10 +- src/ccall.cpp | 22 ++--- src/cgmemmgr.cpp | 14 +-- src/cgutils.cpp | 42 ++++---- src/codegen.cpp | 220 ++++++++++++++++++++--------------------- src/codegen_internal.h | 4 +- src/debuginfo.cpp | 118 +++++++++++----------- src/disasm.cpp | 84 ++++++++-------- src/intrinsics.cpp | 40 ++++---- src/jitlayers.cpp | 84 ++++++++-------- src/jitlayers.h | 20 ++-- src/llvm-gcroot.cpp | 30 +++--- src/llvm-ptls.cpp | 6 +- src/llvm-simdloop.cpp | 10 +- src/llvm-version.h | 57 ++++------- src/runtime_ccall.cpp | 2 +- 16 files changed, 371 insertions(+), 392 deletions(-) diff --git a/src/APInt-C.cpp b/src/APInt-C.cpp index 43fef14b2a138..a4ba5d0a7158c 100644 --- a/src/APInt-C.cpp +++ b/src/APInt-C.cpp @@ -11,7 +11,7 @@ using namespace llvm; -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 inline uint64_t RoundUpToAlignment(uint64_t Value, uint64_t Align, uint64_t Skew = 0) { return alignTo(Value, Align, Skew); } @@ -448,7 +448,7 @@ void LLVMTrunc(unsigned inumbits, integerPart *pa, unsigned onumbits, integerPar extern "C" JL_DLLEXPORT unsigned countTrailingZeros_8(uint8_t Val) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 return countTrailingZeros(Val); #else return CountTrailingZeros_32(Val); @@ -457,7 +457,7 @@ unsigned countTrailingZeros_8(uint8_t Val) { extern "C" JL_DLLEXPORT unsigned countTrailingZeros_16(uint16_t Val) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 return countTrailingZeros(Val); #else return CountTrailingZeros_32(Val); @@ -466,7 +466,7 @@ unsigned countTrailingZeros_16(uint16_t Val) { extern "C" JL_DLLEXPORT unsigned countTrailingZeros_32(uint32_t Val) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 return countTrailingZeros(Val); #else return CountTrailingZeros_32(Val); @@ -475,7 +475,7 @@ unsigned countTrailingZeros_32(uint32_t Val) { extern "C" JL_DLLEXPORT unsigned countTrailingZeros_64(uint64_t Val) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 return countTrailingZeros(Val); #else return CountTrailingZeros_64(Val); diff --git a/src/ccall.cpp b/src/ccall.cpp index 16b58bea717a9..94767efdcb38f 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -168,13 +168,13 @@ static Value *runtime_sym_lookup(PointerType *funcptype, const char *f_lib, else { libname = literal_static_pointer_val(f_lib, T_pint8); } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *llvmf = builder.CreateCall(prepare_call(jldlsym_func), { libname, stringConstPtr(f_name), libptrgv }); #else Value *llvmf = builder.CreateCall3(prepare_call(jldlsym_func), libname, stringConstPtr(f_name), libptrgv); #endif auto store = builder.CreateAlignedStore(llvmf, llvmgv, sizeof(void*)); -# ifdef LLVM39 +# if JL_LLVM_VERSION >= 30900 store->setAtomic(AtomicOrdering::Release); # else store->setAtomic(Release); @@ -267,7 +267,7 @@ static Value *emit_plt(FunctionType *functype, const AttributeSet &attrs, Value *ptr = runtime_sym_lookup(funcptype, f_lib, f_name, plt, libptrgv, llvmgv, runtime_lib); auto store = builder.CreateAlignedStore(builder.CreateBitCast(ptr, T_pvoidfunc), got, sizeof(void*)); -# ifdef LLVM39 +# if JL_LLVM_VERSION >= 30900 store->setAtomic(AtomicOrdering::Release); # else store->setAtomic(Release); @@ -289,7 +289,7 @@ static Value *emit_plt(FunctionType *functype, const AttributeSet &attrs, else { // musttail support is very bad on ARM, PPC, PPC64 (as of LLVM 3.9) // Known failures includes vararg (not needed here) and sret. -#if defined(LLVM37) && (defined(_CPU_X86_) || defined(_CPU_X86_64_) || \ +#if JL_LLVM_VERSION >= 30700 && (defined(_CPU_X86_) || defined(_CPU_X86_64_) || \ defined(_CPU_AARCH64_)) ret->setTailCallKind(CallInst::TCK_MustTail); #endif @@ -742,7 +742,7 @@ class FunctionMover : public ValueMaterializer VMap[&*I] = &*(DestI++); // Add mapping to VMap } - #ifdef LLVM36 + #if JL_LLVM_VERSION >= 30600 // Clone debug info - Not yet public API // llvm::CloneDebugInfoMetadata(NewF,F,VMap); #endif @@ -781,9 +781,9 @@ class FunctionMover : public ValueMaterializer return NewF; } -#if defined(LLVM39) +#if JL_LLVM_VERSION >= 30900 virtual Value *materialize(Value *V) override -#elif defined(LLVM38) +#elif JL_LLVM_VERSION >= 30800 virtual Value *materializeDeclFor(Value *V) override #else virtual Value *materializeValueFor (Value *V) override @@ -980,7 +980,7 @@ static jl_cgval_t emit_llvmcall(jl_value_t **args, size_t nargs, jl_codectx_t *c << jl_string_data(ir) << "\n}"; SMDiagnostic Err = SMDiagnostic(); std::string ir_string = ir_stream.str(); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 Module *m = NULL; bool failed = parseAssemblyInto(llvm::MemoryBufferRef(ir_string,"llvmcall"),*jl_Module,Err); if (!failed) @@ -1014,7 +1014,7 @@ static jl_cgval_t emit_llvmcall(jl_value_t **args, size_t nargs, jl_codectx_t *c #endif //f->dump(); - #ifndef LLVM35 + #if JL_LLVM_VERSION < 30500 if (verifyFunction(*f,PrintMessageAction)) { #else llvm::raw_fd_ostream out(1,false); @@ -1125,7 +1125,7 @@ static std::string generate_func_sig( else if (use_sret(&abi, (jl_datatype_t*)rt)) { paramattrs.push_back(AttrBuilder()); paramattrs[0].clear(); -#if !defined(_OS_WINDOWS_) || defined(LLVM35) // llvm used to use the old mingw ABI, skipping this marking works around that difference +#if !defined(_OS_WINDOWS_) || JL_LLVM_VERSION >= 30500 // llvm used to use the old mingw ABI, skipping this marking works around that difference paramattrs[0].addAttribute(Attribute::StructRet); #endif paramattrs[0].addAttribute(Attribute::NoAlias); @@ -1781,7 +1781,7 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx) stacksave = CallInst::Create(Intrinsic::getDeclaration(jl_Module, Intrinsic::stacksave)); if (savespot) { -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 instList.insertAfter(savespot->getIterator(), (Instruction*)stacksave); #else instList.insertAfter((Instruction*)savespot, (Instruction*)stacksave); diff --git a/src/cgmemmgr.cpp b/src/cgmemmgr.cpp index b3609e9a0f2a1..044968c54e7e2 100644 --- a/src/cgmemmgr.cpp +++ b/src/cgmemmgr.cpp @@ -9,8 +9,8 @@ #include "julia.h" #include "julia_internal.h" -#ifdef LLVM37 -#ifndef LLVM38 +#if JL_LLVM_VERSION >= 30700 +#if JL_LLVM_VERSION < 30800 # include #endif #ifdef _OS_LINUX_ @@ -727,7 +727,7 @@ class RTDyldMemoryManagerJL : public SectionMemoryManager { uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName, bool isReadOnly) override; -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 void notifyObjectLoaded(RuntimeDyld &Dyld, const object::ObjectFile &Obj) override; #endif @@ -802,7 +802,7 @@ uint8_t *RTDyldMemoryManagerJL::allocateDataSection(uintptr_t Size, SectionName, isReadOnly); } -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 void RTDyldMemoryManagerJL::notifyObjectLoaded(RuntimeDyld &Dyld, const object::ObjectFile &Obj) { @@ -855,7 +855,7 @@ void RTDyldMemoryManagerJL::deregisterEHFrames(uint8_t *Addr, } -#ifndef LLVM38 +#if JL_LLVM_VERSION < 30800 void notifyObjectLoaded(RTDyldMemoryManager *memmgr, llvm::orc::ObjectLinkingLayerBase::ObjSetHandleT H) { @@ -870,9 +870,9 @@ void *lookupWriteAddressFor(RTDyldMemoryManager *memmgr, void *rt_addr) } #endif -#else // LLVM37 +#else // JL_LLVM_VERSION >= 30700 typedef SectionMemoryManager RTDyldMemoryManagerJL; -#endif // LLVM37 +#endif // JL_LLVM_VERSION >= 30700 RTDyldMemoryManager* createRTDyldMemoryManager() { diff --git a/src/cgutils.cpp b/src/cgutils.cpp index b1e50c2661112..94d41667af12b 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -26,7 +26,7 @@ static StringMap stringConstants; static Value *stringConstPtr(const std::string &txt) { StringRef ctxt(txt.c_str(), strlen(txt.c_str()) + 1); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 StringMap::iterator pooledval = stringConstants.insert(std::pair(ctxt, NULL)).first; #else @@ -48,7 +48,7 @@ static Value *stringConstPtr(const std::string &txt) (const unsigned char*)pooledtxt.data(), pooledtxt.size())), ssno.str()); -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 gv->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); #else gv->setUnnamedAddr(true); @@ -60,7 +60,7 @@ static Value *stringConstPtr(const std::string &txt) GlobalVariable *v = prepare_global(pooledval->second); Value *zero = ConstantInt::get(Type::getInt32Ty(jl_LLVMContext), 0); Value *Args[] = { zero, zero }; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 return builder.CreateInBoundsGEP(v->getValueType(), v, Args); #else return builder.CreateInBoundsGEP(v, Args); @@ -76,7 +76,7 @@ static Value *stringConstPtr(const std::string &txt) // --- Debug info --- -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 static DIType *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) @@ -95,9 +95,9 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed assert(jl_is_datatype(jt)); jl_datatype_t *jdt = (jl_datatype_t*)jt; if (jdt->ditype != NULL) { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 DIType* t = (DIType*)jdt->ditype; -#ifndef LLVM39 +#if JL_LLVM_VERSION < 30900 // On LLVM 3.7 and 3.8, DICompositeType with a unique name // are ref'd by their unique name and needs to be explicitly // retained in order to be used in the module. @@ -114,7 +114,7 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed } if (jl_is_bitstype(jt)) { uint64_t SizeInBits = 8*jdt->size; - #ifdef LLVM37 + #if JL_LLVM_VERSION >= 30700 llvm::DIType *t = dbuilder->createBasicType( jl_symbol_name(jdt->name->name), SizeInBits, @@ -133,7 +133,7 @@ static DIType julia_type_to_di(jl_value_t *jt, DIBuilder *dbuilder, bool isboxed return t; #endif } - #ifdef LLVM37 + #if JL_LLVM_VERSION >= 30700 else if (!jl_is_leaf_type(jt)) { jdt->ditype = jl_pvalue_dillvmt; return jl_pvalue_dillvmt; @@ -422,7 +422,7 @@ static Type *julia_struct_to_llvm(jl_value_t *jt, bool *isboxed) #ifndef NDEBUG // If LLVM and Julia disagree about alignment, much trouble ensues, so check it! const DataLayout &DL = -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 jl_ExecutionEngine->getDataLayout(); #else *jl_ExecutionEngine->getDataLayout(); @@ -644,7 +644,7 @@ static void error_unless(Value *cond, const std::string &msg, jl_codectx_t *ctx) static void raise_exception(Value *exc, jl_codectx_t *ctx, BasicBlock *contBB=nullptr) { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlthrow_func), { exc }); #else builder.CreateCall(prepare_call(jlthrow_func), exc); @@ -687,7 +687,7 @@ static void emit_type_error(const jl_cgval_t &x, jl_value_t *type, const std::st { Value *fname_val = stringConstPtr(ctx->funcName); Value *msg_val = stringConstPtr(msg); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jltypeerror_func), { fname_val, msg_val, literal_pointer_val(type), boxed(x, ctx, false)}); // x is rooted by jl_type_error_rt @@ -717,7 +717,7 @@ static void emit_typecheck(const jl_cgval_t &x, jl_value_t *type, const std::str Value *vx = boxed(x, ctx); istype = builder. CreateICmpNE( -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlsubtype_func), { vx, literal_pointer_val(type), ConstantInt::get(T_int32,1) }), #else @@ -755,14 +755,14 @@ static Value *emit_bounds_check(const jl_cgval_t &ainfo, jl_value_t *ty, Value * builder.CreateCondBr(ok, passBB, failBB); builder.SetInsertPoint(failBB); if (!ty) { // jl_value_t** tuple (e.g. the vararg) -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlvboundserror_func), { ainfo.V, len, i }); #else builder.CreateCall3(prepare_call(jlvboundserror_func), ainfo.V, len, i); #endif } else if (ainfo.isboxed) { // jl_datatype_t or boxed jl_value_t -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlboundserror_func), { boxed(ainfo, ctx), i }); #else builder.CreateCall2(prepare_call(jlboundserror_func), boxed(ainfo, ctx), i); @@ -779,7 +779,7 @@ static Value *emit_bounds_check(const jl_cgval_t &ainfo, jl_value_t *ty, Value * builder.CreateStore(a, tempSpace); a = tempSpace; } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jluboundserror_func), { builder.CreatePointerCast(a, T_pint8), literal_pointer_val(ty), @@ -1009,7 +1009,7 @@ static bool emit_getfield_unknownidx(jl_cgval_t *ret, const jl_cgval_t &strct, V } else if (strct.isboxed) { idx = builder.CreateSub(idx, ConstantInt::get(T_size, 1)); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *fld = builder.CreateCall(prepare_call(jlgetnthfieldchecked_func), { boxed(strct, ctx), idx }); #else Value *fld = builder.CreateCall2(prepare_call(jlgetnthfieldchecked_func), boxed(strct, ctx), idx); @@ -1158,7 +1158,7 @@ static Value *emit_arraylen_prim(const jl_cgval_t &tinfo, jl_codectx_t *ctx) jl_value_t *ty = tinfo.typ; #ifdef STORE_ARRAY_LEN Value *addr = builder.CreateStructGEP( -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 nullptr, #endif emit_bitcast(t,jl_parray_llvmt), @@ -1198,7 +1198,7 @@ static Value *emit_arrayptr(const jl_cgval_t &tinfo, jl_codectx_t *ctx) { Value *t = boxed(tinfo, ctx); Value *addr = builder.CreateStructGEP( -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 nullptr, #endif emit_bitcast(t,jl_parray_llvmt), @@ -1233,7 +1233,7 @@ static Value *emit_arrayflags(const jl_cgval_t &tinfo, jl_codectx_t *ctx) int arrayflag_field = 1; #endif Value *addr = builder.CreateStructGEP( -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 nullptr, #endif emit_bitcast(t, jl_parray_llvmt), @@ -1322,7 +1322,7 @@ static Value *emit_array_nd_index(const jl_cgval_t &ainfo, jl_value_t *ex, size_ for(size_t k=0; k < nidxs; k++) { builder.CreateStore(idxs[k], builder.CreateGEP(tmp, ConstantInt::get(T_size, k))); } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlboundserrorv_func), { a, tmp, ConstantInt::get(T_size, nidxs) }); #else builder.CreateCall3(prepare_call(jlboundserrorv_func), a, tmp, ConstantInt::get(T_size, nidxs)); @@ -1801,7 +1801,7 @@ static void emit_signal_fence(void) builder.CreateCall(InlineAsm::get(FunctionType::get(T_void, false), "", "~{memory}", true)); #else -# ifdef LLVM39 +# if JL_LLVM_VERSION >= 30900 builder.CreateFence(AtomicOrdering::SequentiallyConsistent, SingleThread); # else builder.CreateFence(SequentiallyConsistent, SingleThread); diff --git a/src/codegen.cpp b/src/codegen.cpp index 0fe438bc19d30..8684437d263b9 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3,7 +3,7 @@ #include "llvm-version.h" #include "platform.h" #include "options.h" -#if defined(_OS_WINDOWS_) && !defined(LLVM39) +#if defined(_OS_WINDOWS_) && JL_LLVM_VERSION < 30900 // trick pre-llvm39 into skipping the generation of _chkstk calls // since it has some codegen issues associated with them: // (a) assumed to be within 32-bit offset @@ -36,23 +36,23 @@ // target machine computation #include #include -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 #include #endif #include #include #include -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 #include #endif -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 #include #endif // IR building #include -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 #include #include #include @@ -65,7 +65,7 @@ #include #include #include -#ifndef LLVM35 +#if JL_LLVM_VERSION < 30500 #include #include #endif @@ -75,7 +75,7 @@ #include #include // for llvmcall #include // for llvmcall inlining -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 #include // for llvmcall validation #else #include @@ -109,7 +109,7 @@ namespace llvm { #include "codegen_internal.h" // LLVM version compatibility macros -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 legacy::PassManager *jl_globalPM; #define LLVM37_param(x) (x), #else @@ -117,13 +117,13 @@ legacy::PassManager *jl_globalPM; PassManager *jl_globalPM; #endif -#ifdef LLVM40 +#if JL_LLVM_VERSION >= 40000 #define DIFlagZero (DINode::FlagZero) #else #define DIFlagZero (0) #endif -#ifndef LLVM35 +#if JL_LLVM_VERSION < 30500 #define AddrSpaceCastInst BitCastInst #endif @@ -177,7 +177,7 @@ extern void _chkstk(void); #define DISABLE_FLOAT16 // llvm state -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 JL_DLLEXPORT LLVMContext jl_LLVMContext; #else JL_DLLEXPORT LLVMContext &jl_LLVMContext = getGlobalContext(); @@ -196,9 +196,9 @@ Module *shadow_output; #define jl_builderModule builder.GetInsertBlock()->getParent()->getParent() static MDBuilder *mbuilder; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 // No DataLayout pass needed anymore. -#elif defined(LLVM35) +#elif JL_LLVM_VERSION >= 30500 static DataLayoutPass *jl_data_layout; #else static DataLayout *jl_data_layout; @@ -266,7 +266,7 @@ static MDNode *tbaa_arrayflags; // The flags in a jl_array_t MDNode *tbaa_const; // Memory that is immutable by the time LLVM can see it // Basic DITypes -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 static DICompositeType *jl_value_dillvmt; static DIDerivedType *jl_pvalue_dillvmt; static DIDerivedType *jl_ppvalue_dillvmt; @@ -276,7 +276,7 @@ static DISubroutineType *jl_di_func_null_sig; static DICompositeType jl_value_dillvmt; static DIDerivedType jl_pvalue_dillvmt; static DIDerivedType jl_ppvalue_dillvmt; -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 DISubroutineType jl_di_func_sig; DISubroutineType jl_di_func_null_sig; #else @@ -382,7 +382,7 @@ static Function *expect_func; static Function *jldlsym_func; static Function *jlnewbits_func; static Function *jltypeassert_func; -#ifndef LLVM36 +#if JL_LLVM_VERSION < 30600 static Function *jlpow_func; static Function *jlpowf_func; #endif @@ -485,7 +485,7 @@ struct jl_cgval_t { struct jl_varinfo_t { Value *memloc; // an address, if the var is in a jl_value_t* gc stack slot or jl_box_t* Box object (marked tbaa_const, if appropriate) jl_cgval_t value; // a value, if the var is unboxed or SSA (and thus memloc == NULL) -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 DILocalVariable *dinfo; #else DIVariable dinfo; @@ -498,7 +498,7 @@ struct jl_varinfo_t { bool used; jl_varinfo_t() : memloc(NULL), value(jl_cgval_t()), -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 dinfo(NULL), #else dinfo(DIVariable()), @@ -893,7 +893,7 @@ jl_llvm_functions_t jl_compile_linfo(jl_method_instance_t *li, jl_code_info_t *s bool toplevel = li->def == NULL; if (!toplevel) { const DataLayout &DL = -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 m->getDataLayout(); #else *jl_data_layout; @@ -936,7 +936,7 @@ jl_llvm_functions_t jl_compile_linfo(jl_method_instance_t *li, jl_code_info_t *s return decls; } -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 static Value *getModuleFlag(Module *m, StringRef Key) { SmallVector ModuleFlags; @@ -965,21 +965,21 @@ static void jl_setup_module(Module *m) #endif m->addModuleFlag(llvm::Module::Warning, "Dwarf Version", dwarf_version); } -#ifdef LLVM34 +#if JL_LLVM_VERSION >= 30400 if (!getModuleFlag(m,"Debug Info Version")) m->addModuleFlag(llvm::Module::Error, "Debug Info Version", llvm::DEBUG_METADATA_VERSION); #endif -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 #ifdef USE_ORCJIT m->setDataLayout(jl_ExecutionEngine->getDataLayout()); -#elif defined(LLVM38) +#elif JL_LLVM_VERSION >= 30800 m->setDataLayout(jl_ExecutionEngine->getDataLayout().getStringRepresentation()); #else m->setDataLayout(jl_ExecutionEngine->getDataLayout()->getStringRepresentation()); #endif m->setTargetTriple(jl_TargetMachine->getTargetTriple().str()); -#elif defined(LLVM36) +#elif JL_LLVM_VERSION >= 30600 m->setDataLayout(jl_ExecutionEngine->getDataLayout()); #endif } @@ -1195,10 +1195,10 @@ void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) // make the alias to the shadow_module GlobalAlias *GA = -#if defined(LLVM38) +#if JL_LLVM_VERSION >= 30800 GlobalAlias::create(llvmf->getType()->getElementType(), llvmf->getType()->getAddressSpace(), GlobalValue::ExternalLinkage, name, llvmf, shadow_output); -#elif defined(LLVM37) +#elif JL_LLVM_VERSION >= 30700 GlobalAlias::create(cast(llvmf->getType()), GlobalValue::ExternalLinkage, name, llvmf, shadow_output); #else @@ -1432,7 +1432,7 @@ static uint64_t compute_obj_symsize(const object::ObjectFile *obj, uint64_t offs uint64_t lo = 0; uint64_t hi = 0; bool setlo = false; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 for (const object::SectionRef &Section : obj->sections()) { #else llvm::error_code err; @@ -1441,13 +1441,13 @@ static uint64_t compute_obj_symsize(const object::ObjectFile *obj, uint64_t offs object::SectionRef Section = *I; #endif uint64_t SAddr, SSize; -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 if (!Section.isText()) continue; #else bool isText; if (Section.isText(isText) || !isText) continue; #endif -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 SAddr = Section.getAddress(); SSize = Section.getSize(); #else @@ -1459,7 +1459,7 @@ static uint64_t compute_obj_symsize(const object::ObjectFile *obj, uint64_t offs // test for lower and upper symbol bounds relative to other symbols hi = SAddr + SSize; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 object::section_iterator ESection = obj->section_end(); for (const object::SymbolRef &Sym : obj->symbols()) { #else @@ -1471,7 +1471,7 @@ static uint64_t compute_obj_symsize(const object::ObjectFile *obj, uint64_t offs #endif uint64_t Addr; object::section_iterator Sect = ESection; -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 auto SectOrError = Sym.getSection(); assert(SectOrError); Sect = SectOrError.get(); @@ -1480,7 +1480,7 @@ static uint64_t compute_obj_symsize(const object::ObjectFile *obj, uint64_t offs #endif if (Sect == ESection) continue; if (Sect != Section) continue; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 auto AddrOrError = Sym.getAddress(); assert(AddrOrError); Addr = AddrOrError.get(); @@ -1510,7 +1510,7 @@ const jl_value_t *jl_dump_function_asm(void *f, int raw_mc) jl_ptls_t ptls = jl_get_ptls_states(); std::string code; llvm::raw_string_ostream stream(code); -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 llvm::formatted_raw_ostream fstream(stream); #endif @@ -1558,14 +1558,14 @@ const jl_value_t *jl_dump_function_asm(void *f, int raw_mc) context, #endif object, objcontext, -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 stream #else fstream #endif ); -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 fstream.flush(); #endif jl_gc_safe_leave(ptls, gc_state); @@ -1625,7 +1625,7 @@ static void mallocVisitLine(StringRef filename, int line) } visitLine( mallocData[filename], line, builder.CreateCall(prepare_call(diff_gc_total_bytes_func) -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 , {} #endif ), @@ -2117,7 +2117,7 @@ static jl_cgval_t emit_getfield(jl_value_t *expr, jl_sym_t *name, jl_codectx_t * jl_cgval_t arg2 = mark_julia_const((jl_value_t*)name); const jl_cgval_t* myargs_array[2] = {&arg1, &arg2}; Value *myargs = make_jlcall(makeArrayRef(myargs_array), ctx); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *result = builder.CreateCall(prepare_call(jlgetfield_func), {V_null, myargs, ConstantInt::get(T_int32,2)}); #else @@ -2161,7 +2161,7 @@ static Value *emit_bits_compare(const jl_cgval_t &arg1, const jl_cgval_t &arg2, assert(arg1.ispointer() && arg2.ispointer()); size_t sz = jl_datatype_size(arg1.typ); if (sz > 512 && !((jl_datatype_t*)arg1.typ)->layout->haspadding) { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *answer = builder.CreateCall(prepare_call(memcmp_func), { data_pointer(arg1, ctx, T_pint8), @@ -2242,7 +2242,7 @@ static Value *emit_f_is(const jl_cgval_t &arg1, const jl_cgval_t &arg2, jl_codec Value *varg1 = boxed(arg1, ctx); Value *varg2 = boxed(arg2, ctx, false); // potentially unrooted! -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 return builder.CreateTrunc(builder.CreateCall(prepare_call(jlegal_func), {varg1, varg2}), T_int1); #else return builder.CreateTrunc(builder.CreateCall2(prepare_call(jlegal_func), varg1, varg2), T_int1); @@ -2319,7 +2319,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args, } if (jl_subtype(ty, (jl_value_t*)jl_type_type, 0)) { *ret = emit_expr(args[1], ctx); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jltypeassert_func), {boxed(*ret, ctx), boxed(emit_expr(args[2], ctx), ctx)}); #else builder.CreateCall2(prepare_call(jltypeassert_func), boxed(*ret, ctx), boxed(emit_expr(args[2], ctx), ctx)); @@ -2388,7 +2388,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args, nva = builder.CreateTrunc(nva, T_int32); #endif Value *r = -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlapply2va_func), {theF, builder.CreateGEP(ctx->argArray, ConstantInt::get(T_size, ctx->nReqArgs)), @@ -2565,7 +2565,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args, T_ppjlvalue))); } else { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 own_ptr = builder.CreateCall( prepare_call(jlarray_data_owner_func), {aryv}); @@ -2794,7 +2794,7 @@ static Value *emit_jlcall(Value *theFptr, Value *theF, jl_value_t **args, else { myargs = Constant::getNullValue(T_ppjlvalue); } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *result = builder.CreateCall(prepare_call(theFptr), {theF, myargs, ConstantInt::get(T_int32,nargs)}); #else @@ -2957,7 +2957,7 @@ static jl_cgval_t emit_call(jl_expr_t *ex, jl_codectx_t *ctx) } // put into argument space Value *myargs = make_jlcall(makeArrayRef(largs, nargs), ctx); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *callval = builder.CreateCall(prepare_call(jlapplygeneric_func), {myargs, ConstantInt::get(T_int32, nargs)}); #else @@ -3013,7 +3013,7 @@ static Value *global_binding_pointer(jl_module_t *m, jl_sym_t *s, builder.CreateCondBr(builder.CreateICmpNE(cachedval, initnul), have_val, not_found); ctx->f->getBasicBlockList().push_back(not_found); builder.SetInsertPoint(not_found); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *bval = builder.CreateCall(prepare_call(jlgetbindingorerror_func), {literal_pointer_val((jl_value_t*)m), literal_pointer_val((jl_value_t*)s)}); @@ -3162,7 +3162,7 @@ static void emit_assignment(jl_value_t *l, jl_value_t *r, jl_codectx_t *ctx) if (bp != NULL) { // it's a global assert(bnd); Value *rval = boxed(emit_expr(r, ctx), ctx, false); // no root needed since this is about to be assigned to a global -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlcheckassign_func), {literal_pointer_val(bnd), rval}); @@ -3571,7 +3571,7 @@ static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_t funcName.str(), M); jl_init_function(cw); cw->setAttributes(attrs); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 cw->addFnAttr("no-frame-pointer-elim", "true"); #endif Function *cw_proto = function_proto(cw); @@ -3749,7 +3749,7 @@ static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_t jl_cgval_t retval; if (lam == NULL) { assert(theFptr); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *ret = builder.CreateCall(prepare_call(theFptr), {myargs, ConstantInt::get(T_int32, nargs + 1)}); #else @@ -3774,7 +3774,7 @@ static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_t // for jlcall, we need to pass the function object even if it is a ghost. // here we reconstruct the function instance from its type (first elt of argt) Value *theF = literal_pointer_val((jl_value_t*)ff); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *ret = builder.CreateCall(prepare_call(theFptr), {theF, myargs, ConstantInt::get(T_int32, nargs)}); #else @@ -3927,7 +3927,7 @@ static Function *gen_jlcall_wrapper(jl_method_instance_t *lam, Function *f, bool Function *w = Function::Create(jl_func_sig, GlobalVariable::ExternalLinkage, funcName.str(), M); jl_init_function(w); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 w->addFnAttr("no-frame-pointer-elim", "true"); #endif Function::arg_iterator AI = w->arg_begin(); @@ -4113,7 +4113,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ std::stringstream funcName; // try to avoid conflicts in the global symbol table funcName << "julia_" << ctx.name -#if (defined(_OS_LINUX_) && !defined(LLVM34)) +#if (defined(_OS_LINUX_) && JL_LLVM_VERSION < 30400) + (ctx.name[0] == '@') ? 1 : 0 #endif ; @@ -4156,7 +4156,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ f->addAttribute(1, Attribute::StructRet); f->addAttribute(1, Attribute::NoAlias); } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 f->addFnAttr("no-frame-pointer-elim", "true"); #endif fwrap = gen_jlcall_wrapper(lam, f, ctx.sret, M); @@ -4168,7 +4168,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ GlobalVariable::ExternalLinkage, funcName.str(), M); jl_init_function(f); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 f->addFnAttr("no-frame-pointer-elim", "true"); #endif declarations->functionObject = function_proto(f); @@ -4188,7 +4188,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ AttributeSet::FunctionIndex,*attr)); #endif -#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) && defined(LLVM35) +#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) && JL_LLVM_VERSION >= 30500 f->setHasUWTable(); // force NeedsWinEH #endif @@ -4217,7 +4217,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ ctx.file = filename; DIBuilder dbuilder(*M); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 DIFile *topfile = NULL; DISubprogram *SP = NULL; #else @@ -4245,18 +4245,18 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ if (ctx.debug_enabled) { // TODO: Fix when moving to new LLVM version - #ifndef LLVM34 + #if JL_LLVM_VERSION < 30400 dbuilder.createCompileUnit(0x01, filename, ".", "julia", true, "", 0); - #elif defined(LLVM37) + #elif JL_LLVM_VERSION >= 30700 DICompileUnit *CU = dbuilder.createCompileUnit(0x01, filename, ".", "julia", true, "", 0); #else DICompileUnit CU = dbuilder.createCompileUnit(0x01, filename, ".", "julia", true, "", 0); assert(CU.Verify()); #endif -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 DISubroutineType *subrty; -#elif defined(LLVM36) +#elif JL_LLVM_VERSION >= 30600 DISubroutineType subrty; #else DICompositeType subrty; @@ -4269,7 +4269,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ subrty = jl_di_func_sig; } else { -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 std::vector ditypes(0); #else std::vector ditypes(0); @@ -4279,9 +4279,9 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ continue; ditypes.push_back(julia_type_to_di(jl_tparam(lam->specTypes,i),&dbuilder,false)); } -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 subrty = dbuilder.createSubroutineType(dbuilder.getOrCreateTypeArray(ditypes)); -#elif defined(LLVM36) +#elif JL_LLVM_VERSION >= 30600 subrty = dbuilder.createSubroutineType(topfile,dbuilder.getOrCreateTypeArray(ditypes)); #else subrty = dbuilder.createSubroutineType(topfile,dbuilder.getOrCreateArray(ditypes)); @@ -4289,7 +4289,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ } topfile = dbuilder.createFile(filename, "."); - #ifndef LLVM34 + #if JL_LLVM_VERSION < 30400 SP = dbuilder.createFunction((DIDescriptor)dbuilder.getCU(), #else SP = dbuilder.createFunction(CU, @@ -4304,16 +4304,16 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ 0, // ScopeLine DIFlagZero, // Flags true, // isOptimized - #ifdef LLVM38 + #if JL_LLVM_VERSION >= 30800 nullptr); // Template Parameters #else f); // Function #endif topdebugloc = DebugLoc::get(toplineno, 0, SP, NULL); - #ifdef LLVM38 + #if JL_LLVM_VERSION >= 30800 f->setSubprogram(SP); #endif - #ifndef LLVM37 + #if JL_LLVM_VERSION < 30700 assert(SP.Verify() && SP.describes(f) && SP.getFunction() == f); #endif } @@ -4327,7 +4327,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ if (argname == unused_sym) continue; jl_varinfo_t &varinfo = ctx.slots[i]; -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 varinfo.dinfo = dbuilder.createParameterVariable( SP, // Scope (current function will be fill in later) jl_symbol_name(argname), // Variable name @@ -4352,7 +4352,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ #endif } if (va && ctx.vaSlot != -1) { -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 ctx.slots[ctx.vaSlot].dinfo = dbuilder.createParameterVariable( SP, // Scope (current function will be fill in later) std::string(jl_symbol_name(slot_symbol(ctx.vaSlot, &ctx))) + "...", // Variable name @@ -4380,7 +4380,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ jl_varinfo_t &varinfo = ctx.slots[i]; if (varinfo.isArgument || s == compiler_temp_sym || s == unused_sym) continue; -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 varinfo.dinfo = dbuilder.createAutoVariable( #else varinfo.dinfo = dbuilder.createLocalVariable( @@ -4393,14 +4393,14 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ julia_type_to_di(varinfo.value.typ, &dbuilder, false), // Variable type AlwaysPreserve, // May be deleted if optimized out DIFlagZero // Flags (TODO: Do we need any) -#ifndef LLVM38 +#if JL_LLVM_VERSION < 30800 ,0 // Argument number (1-based) #endif ); } } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 std::map filescopes; #else std::map filescopes; @@ -4459,11 +4459,11 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ else if (store_unboxed_p(i, &ctx)) { if (!varinfo.isArgument) { // otherwise, just leave it in the input register Value *lv = alloc_local(i, &ctx); (void)lv; -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 if (ctx.debug_enabled && varinfo.dinfo) { assert((Metadata*)varinfo.dinfo->getType() != jl_pvalue_dillvmt); dbuilder.insertDeclare(lv, varinfo.dinfo, dbuilder.createExpression(), -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 topdebugloc, #endif builder.GetInsertBlock()); @@ -4479,7 +4479,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ (s != unused_sym && i == 0)) { // or it is the first argument (which isn't in `argArray`) AllocaInst *av = new AllocaInst(T_pjlvalue, jl_symbol_name(s), /*InsertBefore*/ctx.ptlsStates); varinfo.memloc = av; -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 if (ctx.debug_enabled && varinfo.dinfo) { DIExpression *expr; if ((Metadata*)varinfo.dinfo->getType() == jl_pvalue_dillvmt) { @@ -4491,7 +4491,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ expr = dbuilder.createExpression(addr); } dbuilder.insertDeclare(av, varinfo.dinfo, expr, -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 topdebugloc, #endif builder.GetInsertBlock()); @@ -4541,7 +4541,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ else { Value *argPtr = builder.CreateGEP(argArray, ConstantInt::get(T_size, i-1)); theArg = mark_julia_type(builder.CreateLoad(argPtr), true, vi.value.typ, &ctx, /*needsgcroot*/false); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 if (ctx.debug_enabled && vi.dinfo && !vi.memloc && !vi.value.V) { SmallVector addr; addr.push_back(llvm::dwarf::DW_OP_deref); @@ -4550,7 +4550,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ if ((Metadata*)vi.dinfo->getType() != jl_pvalue_dillvmt) addr.push_back(llvm::dwarf::DW_OP_deref); dbuilder.insertDeclare(pargArray, vi.dinfo, dbuilder.createExpression(addr), -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 topdebugloc, #endif builder.GetInsertBlock()); @@ -4571,7 +4571,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ else { // keep track of original (possibly boxed) value to avoid re-boxing or moving vi.value = theArg; -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 if (specsig && theArg.V && ctx.debug_enabled && vi.dinfo) { SmallVector addr; if ((Metadata*)vi.dinfo->getType() != jl_pvalue_dillvmt && theArg.ispointer()) @@ -4582,7 +4582,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ builder.CreateStore(theArg.V, parg); } dbuilder.insertDeclare(parg, vi.dinfo, dbuilder.createExpression(addr), -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 topdebugloc, #endif builder.GetInsertBlock()); @@ -4613,7 +4613,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ else if (!vi.value.constant) { // restarg = jl_f_tuple(NULL, &args[nreq], nargs-nreq) if (vi.memloc != NULL) { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *restTuple = builder.CreateCall(prepare_call(jltuple_func), {V_null, builder.CreateGEP(argArray, @@ -4651,7 +4651,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ }; struct DbgState { DebugLoc loc; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 DISubprogram *sp; #else DISubprogram sp; @@ -4711,7 +4711,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ } MDNode *inlinedAt = NULL; if (DI_stack.size() > 0) { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 inlinedAt = DI_stack.back().loc; #else inlinedAt = DI_stack.back().loc.getAsMDNode(jl_LLVMContext); @@ -4731,7 +4731,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ jl_sym_t *filesym = (jl_sym_t*)jl_exprarg(expr, 1); if (filesym != empty_sym) new_filename = jl_symbol_name(filesym); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 DIFile *new_file = nullptr; #else DIFile new_file; @@ -4775,7 +4775,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ true, nullptr); MDNode *inlinedAt = NULL; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 inlinedAt = cur_prop.loc; #else inlinedAt = cur_prop.loc.getAsMDNode(jl_LLVMContext); @@ -5003,7 +5003,7 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ resetstkoflw_blk, handlr); builder.SetInsertPoint(resetstkoflw_blk); builder.CreateCall(prepare_call(resetstkoflw_func) -# ifdef LLVM37 +# if JL_LLVM_VERSION >= 30700 , {} # endif ); @@ -5054,8 +5054,8 @@ static std::unique_ptr emit_function(jl_method_instance_t *lam, jl_code_ static MDNode *tbaa_make_child( const char *name, MDNode *parent, bool isConstant=false ) { MDNode *n = mbuilder->createTBAANode(name,parent,isConstant); -#ifndef LLVM36 -#ifdef LLVM35 +#if JL_LLVM_VERSION < 30600 +#if JL_LLVM_VERSION >= 30500 n->setValueName( ValueName::Create(name)); #else n->setValueName( ValueName::Create(name, name+strlen(name))); @@ -5228,7 +5228,7 @@ static void init_julia_llvm_env(Module *m) T_jlvalue = valueSt; DIBuilder dbuilder(*m); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 DIFile *julia_h = dbuilder.createFile("julia.h",""); jl_value_dillvmt = dbuilder.createStructType(nullptr, #else @@ -5241,7 +5241,7 @@ static void init_julia_llvm_env(Module *m) 0 * 8, // sizeof(jl_value_t) * 8, __alignof__(void*) * 8, // __alignof__(jl_value_t) * 8, DIFlagZero, // Flags -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 nullptr, // Derived from nullptr); // Elements - will be corrected later #else @@ -5252,7 +5252,7 @@ static void init_julia_llvm_env(Module *m) jl_pvalue_dillvmt = dbuilder.createPointerType(jl_value_dillvmt, sizeof(jl_value_t*) * 8, __alignof__(jl_value_t*) * 8); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 SmallVector Elts; std::vector diargs(0); Elts.push_back(jl_pvalue_dillvmt); @@ -5274,12 +5274,12 @@ static void init_julia_llvm_env(Module *m) // Third argument (length(argv)) diargs.push_back(julia_type_to_di((jl_value_t*)jl_int32_type,&dbuilder,false)); -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 jl_di_func_sig = dbuilder.createSubroutineType( dbuilder.getOrCreateTypeArray(diargs)); jl_di_func_null_sig = dbuilder.createSubroutineType( dbuilder.getOrCreateTypeArray(None)); -#elif defined(LLVM36) +#elif JL_LLVM_VERSION >= 30600 jl_di_func_sig = dbuilder.createSubroutineType(julia_h, dbuilder.getOrCreateTypeArray(diargs)); jl_di_func_null_sig = dbuilder.createSubroutineType(julia_h, @@ -5762,7 +5762,7 @@ static void init_julia_llvm_env(Module *m) "jl_gc_diff_total_bytes", m); add_named_global(diff_gc_total_bytes_func, *jl_gc_diff_total_bytes); -#ifndef LLVM36 +#if JL_LLVM_VERSION < 30600 Type *powf_type[2] = { T_float32, T_float32 }; jlpowf_func = Function::Create(FunctionType::get(T_float32, powf_type, false), Function::ExternalLinkage, @@ -5825,27 +5825,27 @@ static void init_julia_llvm_env(Module *m) add_named_global(except_enter_func, (void*)NULL, /*dllimport*/false); // set up optimization passes -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 // No DataLayout pass needed anymore. -#elif defined(LLVM36) +#elif JL_LLVM_VERSION >= 30600 jl_data_layout = new llvm::DataLayoutPass(); -#elif defined(LLVM35) +#elif JL_LLVM_VERSION >= 30500 jl_data_layout = new llvm::DataLayoutPass(*jl_ExecutionEngine->getDataLayout()); #else jl_data_layout = new DataLayout(*jl_ExecutionEngine->getDataLayout()); #endif -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 jl_globalPM = new legacy::PassManager(); #else jl_globalPM = new PassManager(); #endif -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 jl_globalPM->add(new TargetLibraryInfo(Triple(jl_TargetMachine->getTargetTriple()))); #else jl_globalPM->add(new TargetLibraryInfoWrapperPass(Triple(jl_TargetMachine->getTargetTriple()))); #endif -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 jl_globalPM->add(jl_data_layout); #endif addOptimizationPasses(jl_globalPM); @@ -5931,7 +5931,7 @@ static inline SmallVector getTargetFeatures(std::string &cpu) HostFeatures["avx"] = false; #endif #endif -#if defined(_CPU_X86_64_) && defined(LLVM36) +#if defined(_CPU_X86_64_) && JL_LLVM_VERSION >= 30600 // Require cx16 (cmpxchg16b) // We need this for 128-bit atomic operations. We only need this // when threading is enabled; however, to test whether this @@ -6024,7 +6024,7 @@ extern "C" void jl_init_codegen(void) jl_init_debuginfo(); jl_init_runtime_ccall(); -#ifndef LLVM34 +#if JL_LLVM_VERSION < 30400 // this option disables LLVM's signal handlers llvm::DisablePrettyStackTrace = true; #endif @@ -6051,13 +6051,13 @@ extern "C" void jl_init_codegen(void) TargetOptions options = TargetOptions(); //options.PrintMachineCode = true; //Print machine code produced during JIT compiling -#if defined(JL_DEBUG_BUILD) && !defined(LLVM37) +#if defined(JL_DEBUG_BUILD) && JL_LLVM_VERSION < 30700 options.JITEmitDebugInfo = true; #endif -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 options.NoFramePointerElim = true; #endif -#ifndef LLVM34 +#if JL_LLVM_VERSION < 30400 options.NoFramePointerElimNonLeaf = true; #endif #if defined(_OS_WINDOWS_) && !defined(_CPU_X86_64_) @@ -6066,12 +6066,12 @@ extern "C" void jl_init_codegen(void) // to ensure compatibility with GCC codes options.StackAlignmentOverride = 16; #endif -#if defined(__APPLE__) && !defined(LLVM34) +#if defined(__APPLE__) && JL_LLVM_VERSION < 30400 // turn on JIT support for libunwind to walk the stack options.JITExceptionHandling = 1; #endif -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 EngineBuilder eb((std::unique_ptr(engine_module))); #else EngineBuilder eb(engine_module); @@ -6086,7 +6086,7 @@ extern "C" void jl_init_codegen(void) .setTargetOptions(options) #if (defined(_OS_LINUX_) && defined(_CPU_X86_64_)) .setRelocationModel(Reloc::PIC_) -#elif !defined(LLVM39) +#elif JL_LLVM_VERSION < 30900 .setRelocationModel(Reloc::Default) #endif #ifdef _P64 @@ -6099,7 +6099,7 @@ extern "C" void jl_init_codegen(void) #else .setOptLevel(jl_options.opt_level == 0 ? CodeGenOpt::None : CodeGenOpt::Aggressive) #endif -#if defined(USE_MCJIT) && !defined(LLVM36) +#if defined(USE_MCJIT) && JL_LLVM_VERSION < 30600 .setUseMCJIT(true) #endif #ifdef USE_ORCMCJIT @@ -6108,7 +6108,7 @@ extern "C" void jl_init_codegen(void) ; Triple TheTriple(sys::getProcessTriple()); #if defined(FORCE_ELF) -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 TheTriple.setObjectFormat(Triple::ELF); #else TheTriple.setEnvironment(Triple::ELF); @@ -6141,7 +6141,7 @@ extern "C" void jl_init_codegen(void) ErrorStr.c_str()); exit(1); } -#if defined(LLVM35) && !defined(USE_ORCMCJIT) +#if JL_LLVM_VERSION >= 30500 && !defined(USE_ORCMCJIT) jl_ExecutionEngine->setProcessAllSections(true); #endif jl_ExecutionEngine->DisableLazyCompilation(); diff --git a/src/codegen_internal.h b/src/codegen_internal.h index 12ab6fb2bf645..da18ce501ac5c 100644 --- a/src/codegen_internal.h +++ b/src/codegen_internal.h @@ -1,6 +1,6 @@ // This file is a part of Julia. License is MIT: http://julialang.org/license -#if defined(LLVM38) && !defined(LLVM37) +#if defined(USE_ORCJIT) && JL_LLVM_VERSION <= 30800 # include void notifyObjectLoaded(RTDyldMemoryManager *memmgr, llvm::orc::ObjectLinkingLayerBase::ObjSetHandleT H); @@ -14,7 +14,7 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, #endif const object::ObjectFile *object, llvm::DIContext *context, -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 raw_ostream &rstream #else formatted_raw_ostream &stream diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index 3ec064ee0f182..016c046232d75 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -6,7 +6,7 @@ #include #include #include -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 #include #include #endif @@ -14,7 +14,7 @@ #include #include #include -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 #include #else #include @@ -22,7 +22,7 @@ #if defined(USE_MCJIT) || defined(USE_ORCJIT) #include #include -#ifndef LLVM36 +#if JL_LLVM_VERSION < 30600 #include #endif #include @@ -31,11 +31,11 @@ #endif #include #include -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 # include #endif -#if defined(USE_MCJIT) && !defined(LLVM36) && defined(_OS_DARWIN_) +#if defined(USE_MCJIT) && JL_LLVM_VERSION < 30600 && defined(_OS_DARWIN_) #include "../deps/llvm-3.5.0/lib/ExecutionEngine/MCJIT/MCJIT.h" #endif @@ -59,7 +59,7 @@ using namespace llvm; #include #include -#if defined(LLVM35) && !defined(LLVM36) +#if JL_LLVM_VERSION >= 30500 && JL_LLVM_VERSION < 30600 extern ExecutionEngine *jl_ExecutionEngine; #endif @@ -93,10 +93,10 @@ struct ObjectInfo { const object::ObjectFile *object; size_t SectionSize; ptrdiff_t slide; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 DIContext *context; #endif -#if defined(_OS_DARWIN_) && !defined(LLVM37) +#if defined(_OS_DARWIN_) && JL_LLVM_VERSION < 30700 const char *name; #endif }; @@ -206,7 +206,7 @@ struct revcomp { { return lhs>rhs; } }; -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 struct strrefcomp { bool operator() (const StringRef& lhs, const StringRef& rhs) const { @@ -293,7 +293,7 @@ class JuliaJITEventListener: public JITEventListener else return NULL; } -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 virtual void NotifyObjectEmitted(const object::ObjectFile &obj, const RuntimeDyld::LoadedObjectInfo &L) @@ -314,7 +314,7 @@ class JuliaJITEventListener: public JITEventListener // This should be fine since the GC won't scan this field. int8_t gc_state = jl_gc_safe_enter(ptls); uv_rwlock_wrlock(&threadsafe); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 object::section_iterator Section = debugObj.section_begin(); object::section_iterator EndSection = debugObj.section_end(); #else @@ -322,7 +322,7 @@ class JuliaJITEventListener: public JITEventListener object::section_iterator EndSection = debugObj.end_sections(); #endif -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 std::map loadedSections; for (const object::SectionRef &lSection: obj.sections()) { StringRef sName; @@ -346,7 +346,7 @@ class JuliaJITEventListener: public JITEventListener uint8_t *catchjmp = NULL; for (const object::SymbolRef &sym_iter : debugObj.symbols()) { StringRef sName; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 auto sNameOrError = sym_iter.getName(); assert(sNameOrError); sName = sNameOrError.get(); @@ -362,7 +362,7 @@ class JuliaJITEventListener: public JITEventListener } if (pAddr) { uint64_t Addr, SectionAddr, SectionLoadAddr; -#if defined(LLVM38) +#if JL_LLVM_VERSION >= 30800 auto AddrOrError = sym_iter.getAddress(); assert(AddrOrError); Addr = AddrOrError.get(); @@ -373,7 +373,7 @@ class JuliaJITEventListener: public JITEventListener SectionAddr = Section->getAddress(); Section->getName(sName); SectionLoadAddr = getLoadAddress(sName); -#elif defined(LLVM37) +#elif JL_LLVM_VERSION >= 30700 auto AddrOrError = sym_iter.getAddress(); assert(AddrOrError); Addr = AddrOrError.get(); @@ -382,14 +382,14 @@ class JuliaJITEventListener: public JITEventListener Section->getName(sName); SectionAddr = Section->getAddress(); SectionLoadAddr = L.getSectionLoadAddress(sName); -#elif defined(LLVM36) +#elif JL_LLVM_VERSION >= 30600 sym_iter.getAddress(Addr); sym_iter.getSection(Section); assert(Section != EndSection && Section->isText()); Section->getName(sName); SectionAddr = Section->getAddress(); SectionLoadAddr = L.getSectionLoadAddress(sName); -#else // LLVM35 +#else // JL_LLVM_VERSION >= 30500 sym_iter.getAddress(Addr); sym_iter.getSection(Section); assert(Section != EndSection); @@ -437,12 +437,12 @@ class JuliaJITEventListener: public JITEventListener #endif // defined(_OS_X86_64_) #endif // defined(_OS_WINDOWS_) -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 auto symbols = object::computeSymbolSizes(debugObj); bool first = true; for(const auto &sym_size : symbols) { const object::SymbolRef &sym_iter = sym_size.first; -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 auto SymbolTypeOrError = sym_iter.getType(); assert(SymbolTypeOrError); object::SymbolRef::Type SymbolType = SymbolTypeOrError.get(); @@ -453,7 +453,7 @@ class JuliaJITEventListener: public JITEventListener auto AddrOrError = sym_iter.getAddress(); assert(AddrOrError); uint64_t Addr = AddrOrError.get(); -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 auto SectionOrError = sym_iter.getSection(); assert(SectionOrError); Section = SectionOrError.get(); @@ -465,7 +465,7 @@ class JuliaJITEventListener: public JITEventListener uint64_t SectionAddr = Section->getAddress(); StringRef secName; Section->getName(secName); -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 uint64_t SectionLoadAddr = getLoadAddress(secName); #else uint64_t SectionLoadAddr = L.getSectionLoadAddress(secName); @@ -517,17 +517,17 @@ class JuliaJITEventListener: public JITEventListener } } -#else // pre-LLVM37 +#else // pre-LLVM 3.7 uint64_t Addr; uint64_t Size; object::SymbolRef::Type SymbolType; StringRef sName; uint64_t SectionLoadAddr = 0, SectionAddr = 0; -#ifndef LLVM36 +#if JL_LLVM_VERSION < 30600 bool isText; #endif -#if defined(LLVM35) +#if JL_LLVM_VERSION >= 30500 for (const object::SymbolRef &sym_iter : obj.symbols()) { sym_iter.getType(SymbolType); if (SymbolType != object::SymbolRef::ST_Function) continue; @@ -535,7 +535,7 @@ class JuliaJITEventListener: public JITEventListener sym_iter.getAddress(Addr); sym_iter.getSection(Section); if (Section == EndSection) continue; -#if defined(LLVM36) +#if JL_LLVM_VERSION >= 30600 if (!Section->isText()) continue; Section->getName(sName); SectionAddr = Section->getAddress(); @@ -548,7 +548,7 @@ class JuliaJITEventListener: public JITEventListener #endif sym_iter.getName(sName); #ifdef _OS_DARWIN_ -# if !defined(LLVM36) +# if JL_LLVM_VERSION < 30600 Addr = ((MCJIT*)jl_ExecutionEngine)->getSymbolAddress(sName, true); if (!Addr && sName[0] == '_') { Addr = ((MCJIT*)jl_ExecutionEngine)->getSymbolAddress(sName.substr(1), true); @@ -557,7 +557,7 @@ class JuliaJITEventListener: public JITEventListener # endif #elif defined(_OS_WINDOWS_) uint64_t SectionSize = 0; -# if defined(LLVM36) +# if JL_LLVM_VERSION >= 30600 SectionSize = Section->getSize(); # else Section->getSize(SectionSize); @@ -590,7 +590,7 @@ class JuliaJITEventListener: public JITEventListener if (linfo) linfomap[Addr] = std::make_pair(Size, linfo); const object::ObjectFile *objfile = -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 &obj; #else obj.getObjectFile(); @@ -604,7 +604,7 @@ class JuliaJITEventListener: public JITEventListener }; objectmap[Addr] = tmp; } -#else //LLVM34 +#else //JL_LLVM_VERSION >= 30400 error_code itererr; object::symbol_iterator sym_iter = obj.begin_symbols(); object::symbol_iterator sym_end = obj.end_symbols(); @@ -701,7 +701,7 @@ static int lookup_pointer(DIContext *context, jl_frame_t **frames, } return 1; } -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 DILineInfoSpecifier infoSpec(DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, DILineInfoSpecifier::FunctionNameKind::ShortName); #else @@ -736,7 +736,7 @@ static int lookup_pointer(DIContext *context, jl_frame_t **frames, } jl_frame_t *frame = &(*frames)[i]; -#ifndef LLVM35 +#if JL_LLVM_VERSION < 30500 std::string func_name(info.getFunctionName()); #else std::string func_name(info.FunctionName); @@ -758,7 +758,7 @@ static int lookup_pointer(DIContext *context, jl_frame_t **frames, frame->func_name = NULL; else jl_copy_str(&frame->func_name, func_name.c_str()); -#ifndef LLVM35 +#if JL_LLVM_VERSION < 30500 frame->line = info.getLine(); std::string file_name(info.getFileName()); #else @@ -796,10 +796,10 @@ static obfiletype objfilemap; static bool getObjUUID(llvm::object::MachOObjectFile *obj, uint8_t uuid[16]) { -# ifdef LLVM37 +# if JL_LLVM_VERSION >= 30700 for (auto Load : obj->load_commands()) # else -# ifdef LLVM35 +# if JL_LLVM_VERSION >= 30500 uint32_t LoadCommandCount = obj->getHeader().ncmds; # else uint32_t LoadCommandCount = obj->getHeader().NumLoadCommands; @@ -809,7 +809,7 @@ static bool getObjUUID(llvm::object::MachOObjectFile *obj, uint8_t uuid[16]) # endif { if ( -# ifdef LLVM35 +# if JL_LLVM_VERSION >= 30500 Load.C.cmd == LC_UUID # else Load.C.Type == LC_UUID @@ -818,7 +818,7 @@ static bool getObjUUID(llvm::object::MachOObjectFile *obj, uint8_t uuid[16]) memcpy(uuid, ((const MachO::uuid_command*)Load.Ptr)->uuid, 16); return true; } -# ifndef LLVM37 +# if JL_LLVM_VERSION < 30700 else if (I == LoadCommandCount - 1) { return false; } @@ -830,7 +830,7 @@ static bool getObjUUID(llvm::object::MachOObjectFile *obj, uint8_t uuid[16]) return false; } -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 struct debug_link_info { StringRef filename; uint32_t crc32; @@ -916,7 +916,7 @@ calc_gnu_debuglink_crc32(const void *buf, size_t size) return crc ^ ~0U; } -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 static Expected> #else static ErrorOr> @@ -925,7 +925,7 @@ openDebugInfo(StringRef debuginfopath, const debug_link_info &info) { auto SplitFile = MemoryBuffer::getFile(debuginfopath); if (std::error_code EC = SplitFile.getError()) { -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 return errorCodeToError(EC); #else return EC; @@ -936,7 +936,7 @@ openDebugInfo(StringRef debuginfopath, const debug_link_info &info) SplitFile.get()->getBufferStart(), SplitFile.get()->getBufferSize()); if (crc32 != info.crc32) { -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 return errorCodeToError(object::object_error::arch_not_found); #else return object::object_error::arch_not_found; @@ -947,7 +947,7 @@ openDebugInfo(StringRef debuginfopath, const debug_link_info &info) SplitFile.get().get()->getMemBufferRef(), sys::fs::file_magic::unknown); if (!error_splitobj) { -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 return error_splitobj.takeError(); #else return error_splitobj.getError(); @@ -976,7 +976,7 @@ extern "C" void jl_register_fptrs(uint64_t sysimage_base, void **fptrs, jl_metho template static inline void ignoreError(T &err) { -#if defined(LLVM39) && !defined(NDEBUG) +#if JL_LLVM_VERSION >= 30900 && !defined(NDEBUG) consumeError(err.takeError()); #endif } @@ -1087,7 +1087,7 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, iswindows = 1; #endif -#ifndef LLVM35 +#if JL_LLVM_VERSION < 30500 if (iswindows) { return true; } @@ -1111,12 +1111,12 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, uint8_t uuid[16], uuid2[16]; if (isdarwin) { size_t msize = (size_t)(((uint64_t)-1) - fbase); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 std::unique_ptr membuf = MemoryBuffer::getMemBuffer( StringRef((const char *)fbase, msize), "", false); auto origerrorobj = llvm::object::ObjectFile::createObjectFile( membuf->getMemBufferRef(), sys::fs::file_magic::unknown); -#elif defined(LLVM35) +#elif JL_LLVM_VERSION >= 30500 MemoryBuffer *membuf = MemoryBuffer::getMemBuffer( StringRef((const char *)fbase, msize), "", false); std::unique_ptr buf(membuf); @@ -1135,7 +1135,7 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, } llvm::object::MachOObjectFile *morigobj = (llvm::object::MachOObjectFile*) -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 origerrorobj.get().get(); #else origerrorobj.get(); @@ -1164,7 +1164,7 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, // On Windows we need to mmap another copy since reading the in-memory copy seems to return object_error:unexpected_eof objpath = fname; } -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 auto errorobj = llvm::object::ObjectFile::createObjectFile(objpath); #else std::unique_ptr errorobj(llvm::object::ObjectFile::createObjectFile(objpath)); @@ -1172,14 +1172,14 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, // GOAL: Assign *obj, *context, *slide (if above succeeded) if (errorobj) { -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 auto *debugobj = errorobj->getBinary(); #else auto *debugobj = errorobj.get(); #endif if (islinux) { -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 // if the file has a .gnu_debuglink section, // try to load its companion file instead // in the expected locations @@ -1187,7 +1187,7 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, debug_link_info info = getDebuglink(*debugobj); if (!info.filename.empty()) { size_t sep = fname.rfind('/'); -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 Expected> DebugInfo(errorCodeToError(std::make_error_code(std::errc::no_such_file_or_directory))); // Can't find a way to construct an empty Expected object @@ -1240,7 +1240,7 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, } if (iswindows) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 assert(debugobj->isCOFF()); const llvm::object::COFFObjectFile *coffobj = (const llvm::object::COFFObjectFile*)debugobj; const llvm::object::pe32plus_header *pe32plus; @@ -1268,15 +1268,15 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, *slide = -(int64_t)fbase; } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 *context = new DWARFContextInMemory(*debugobj); -#elif defined(LLVM36) +#elif JL_LLVM_VERSION >= 30600 *context = DIContext::getDWARFContext(*debugobj); #else *context = DIContext::getDWARFContext(debugobj); #endif *obj = debugobj; -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 auto binary = errorobj->takeBinary(); binary.first.release(); binary.second.release(); @@ -1391,7 +1391,7 @@ int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide, int64_t *se *section_slide = fit->second.slide; *object = fit->second.object; if (context) { -#if defined(LLVM37) +#if JL_LLVM_VERSION >= 30700 *context = fit->second.context; #else *context = DIContext::getDWARFContext(*fit->second.object); @@ -1578,7 +1578,7 @@ extern "C" jl_method_instance_t *jl_gdblookuplinfo(void *p) #endif } -#if defined(LLVM37) && (defined(_OS_LINUX_) || (defined(_OS_DARWIN_) && defined(LLVM_SHLIB))) +#if JL_LLVM_VERSION >= 30700 && (defined(_OS_LINUX_) || (defined(_OS_DARWIN_) && defined(LLVM_SHLIB))) extern "C" void __register_frame(void*); extern "C" void __deregister_frame(void*); @@ -1605,7 +1605,7 @@ static void processFDEs(const char *EHFrameAddr, size_t EHFrameSize, callback f) } #endif -#if defined(_OS_DARWIN_) && defined(LLVM37) && defined(LLVM_SHLIB) +#if defined(_OS_DARWIN_) && JL_LLVM_VERSION >= 30700 && defined(LLVM_SHLIB) /* * We use a custom unwinder, so we need to make sure that when registering dynamic @@ -1645,7 +1645,7 @@ void deregister_eh_frames(uint8_t *Addr, size_t Size) }); } -#elif defined(_OS_LINUX_) && defined(LLVM37) && defined(JL_UNW_HAS_FORMAT_IP) +#elif defined(_OS_LINUX_) && JL_LLVM_VERSION >= 30700 && defined(JL_UNW_HAS_FORMAT_IP) #include struct unw_table_entry @@ -2063,7 +2063,7 @@ class JITMemoryManagerWin : public JITMemoryManager { virtual unsigned GetNumDataSlabs() { return JMM->GetNumDataSlabs(); } virtual unsigned GetNumStubSlabs() { return JMM->GetNumStubSlabs(); } -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, llvm::StringRef SectionName) { diff --git a/src/disasm.cpp b/src/disasm.cpp index 356e57add0b9b..7bd8e5a54d01f 100644 --- a/src/disasm.cpp +++ b/src/disasm.cpp @@ -44,9 +44,9 @@ #include #include #include -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 # include -# ifdef LLVM39 +# if JL_LLVM_VERSION >= 30900 # include # include # else @@ -67,16 +67,16 @@ #include "llvm/Support/TargetSelect.h" #include #include "llvm/Support/FormattedStream.h" -#ifndef LLVM35 +#if JL_LLVM_VERSION < 30500 #include #endif #include #include #include -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 #include "llvm/DebugInfo/DWARF/DWARFContext.h" #endif -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 #include #else #include @@ -90,7 +90,7 @@ using namespace llvm; extern JL_DLLEXPORT LLVMContext &jl_LLVMContext; namespace { -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 #define FuncMCView ArrayRef #else class FuncMCView : public MemoryObject { @@ -172,7 +172,7 @@ const char *SymbolTable::lookupLocalPC(size_t addr) { StringRef SymbolTable::getSymbolNameAt(uint64_t offset) const { if (object == NULL) return StringRef(); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 object::section_iterator ESection = object->section_end(); for (const object::SymbolRef &Sym : object->symbols()) { #else @@ -184,7 +184,7 @@ StringRef SymbolTable::getSymbolNameAt(uint64_t offset) const #endif uint64_t Addr, SAddr; object::section_iterator Sect = ESection; -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 auto SectOrError = Sym.getSection(); assert(SectOrError); Sect = SectOrError.get(); @@ -192,13 +192,13 @@ StringRef SymbolTable::getSymbolNameAt(uint64_t offset) const if (Sym.getSection(Sect)) continue; #endif if (Sect == ESection) continue; -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 SAddr = Sect->getAddress(); if (SAddr == 0) continue; #else if (Sym.getAddress(SAddr) || SAddr == 0) continue; #endif -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 auto AddrOrError = Sym.getAddress(); assert(AddrOrError); Addr = AddrOrError.get(); @@ -250,7 +250,7 @@ void SymbolTable::createSymbols() name << global; } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 MCSymbol *symb = Ctx.getOrCreateSymbol(StringRef(name.str())); assert(symb->isUndefined()); #else @@ -296,7 +296,7 @@ static const char *SymbolLookup(void *DisInfo, uint64_t ReferenceValue, uint64_t else if (*ReferenceType == LLVMDisassembler_ReferenceType_In_PCrel_Load) { const char *symbolName = SymTab->lookupSymbolName(addr, false); if (symbolName) { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 *ReferenceType = LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr; #else *ReferenceType = LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr; @@ -361,7 +361,7 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, #endif const object::ObjectFile *object, DIContext *di_ctx, -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 raw_ostream &rstream #else formatted_raw_ostream &stream @@ -387,50 +387,50 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, const Target *TheTarget = TargetRegistry::lookupTarget(TripleName, err); // Set up required helpers and streamer -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 std::unique_ptr Streamer; #else OwningPtr Streamer; #endif SourceMgr SrcMgr; -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 std::unique_ptr MAI(TheTarget->createMCAsmInfo(*TheTarget->createMCRegInfo(TripleName),TripleName)); -#elif defined(LLVM34) +#elif JL_LLVM_VERSION >= 30400 llvm::OwningPtr MAI(TheTarget->createMCAsmInfo(*TheTarget->createMCRegInfo(TripleName),TripleName)); #else llvm::OwningPtr MAI(TheTarget->createMCAsmInfo(TripleName)); #endif assert(MAI && "Unable to create target asm info!"); -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 std::unique_ptr MRI(TheTarget->createMCRegInfo(TripleName)); #else llvm::OwningPtr MRI(TheTarget->createMCRegInfo(TripleName)); #endif assert(MRI && "Unable to create target register info!"); -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 std::unique_ptr MOFI(new MCObjectFileInfo()); #else OwningPtr MOFI(new MCObjectFileInfo()); #endif -#ifdef LLVM34 +#if JL_LLVM_VERSION >= 30400 MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr); #else MCContext Ctx(*MAI, *MRI, MOFI.get(), &SrcMgr); #endif -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 MOFI->InitMCObjectFileInfo(TheTriple, /* PIC */ false, CodeModel::Default, Ctx); -#elif defined(LLVM37) +#elif JL_LLVM_VERSION >= 30700 MOFI->InitMCObjectFileInfo(TheTriple, Reloc::Default, CodeModel::Default, Ctx); #else MOFI->InitMCObjectFileInfo(TripleName, Reloc::Default, CodeModel::Default, Ctx); #endif // Set up Subtarget and Disassembler -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 std::unique_ptr STI(TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString())); std::unique_ptr DisAsm(TheTarget->createMCDisassembler(*STI, Ctx)); @@ -448,7 +448,7 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, unsigned OutputAsmVariant = 0; // ATT or Intel-style assembly bool ShowEncoding = false; -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 std::unique_ptr MCII(TheTarget->createMCInstrInfo()); std::unique_ptr MCIA(TheTarget->createMCInstrAnalysis(MCII.get())); @@ -457,7 +457,7 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, OwningPtr MCIA(TheTarget->createMCInstrAnalysis(MCII.get())); #endif -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 MCInstPrinter *IP = TheTarget->createMCInstPrinter(TheTriple, OutputAsmVariant, *MAI, *MCII, *MRI); #else @@ -468,22 +468,22 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, MCCodeEmitter *CE = 0; MCAsmBackend *MAB = 0; if (ShowEncoding) { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx); #else CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx); #endif -#ifdef LLVM40 +#if JL_LLVM_VERSION >= 40000 MCTargetOptions Options; MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, MCPU, Options); -#elif defined(LLVM34) +#elif JL_LLVM_VERSION >= 30400 MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, MCPU); #else MAB = TheTarget->createMCAsmBackend(TripleName, MCPU); #endif } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 // createAsmStreamer expects a unique_ptr to a formatted stream, which means // it will destruct the stream when it is done. We cannot have this, so we // start out with a raw stream, and create formatted stream from it here. @@ -493,20 +493,20 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, #else Streamer.reset(TheTarget->createAsmStreamer(Ctx, stream, /*asmverbose*/true, #endif -#ifndef LLVM35 +#if JL_LLVM_VERSION < 30500 /*useLoc*/ true, /*useCFI*/ true, #endif /*useDwarfDirectory*/ true, IP, CE, MAB, /*ShowInst*/ false)); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 Streamer->InitSections(true); #else Streamer->InitSections(); #endif // Make the MemoryObject wrapper -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 ArrayRef memoryObject(const_cast((const uint8_t*)Fptr),Fsize); #else FuncMCView memoryObject((const uint8_t*)Fptr, Fsize); @@ -533,14 +533,14 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, // MCIA->evaluateBranch. (It should be possible to rewrite // this routine to handle this case correctly as well.) // Could add OpInfoLookup here -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 DisAsm->setSymbolizer(std::unique_ptr(new MCExternalSymbolizer( Ctx, std::unique_ptr(new MCRelocationInfo(Ctx)), OpInfoLookup, SymbolLookup, &DisInfo))); -#elif defined LLVM34 +#elif JL_LLVM_VERSION >= 30400 OwningPtr relinfo(new MCRelocationInfo(Ctx)); DisAsm->setupForSymbolicDisassembly(OpInfoLookup, SymbolLookup, &DisInfo, &Ctx, relinfo); @@ -560,16 +560,16 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, if (di_ctx) { // Set up the line info if (di_lineIter != di_lineEnd) { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 std::ostringstream buf; buf << "Filename: " << di_lineIter->second.FileName << "\n"; Streamer->EmitRawText(buf.str()); -#elif defined LLVM35 +#elif JL_LLVM_VERSION >= 30500 stream << "Filename: " << di_lineIter->second.FileName << "\n"; #else stream << "Filename: " << di_lineIter->second.getFileName() << "\n"; #endif -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 if (di_lineIter->second.Line <= 0) #else if (di_lineIter->second.getLine() <= 0) @@ -593,7 +593,7 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, stream << "Filename: " << debugscope.getFilename() << "\n"; if (Loc.getLine() > 0) stream << "Source line: " << Loc.getLine() << "\n"; -#if defined(LLVM35) +#if JL_LLVM_VERSION >= 30500 nextLineAddr = (*lineIter).Address; #endif } @@ -609,11 +609,11 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, if (nextLineAddr != (uint64_t)-1 && Index + Fptr + slide == nextLineAddr) { if (di_ctx) { -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 std::ostringstream buf; buf << "Source line: " << di_lineIter->second.Line << "\n"; Streamer->EmitRawText(buf.str()); -#elif defined(LLVM35) +#elif JL_LLVM_VERSION >= 30500 stream << "Source line: " << di_lineIter->second.Line << "\n"; #else stream << "Source line: " << di_lineIter->second.getLine() << "\n"; @@ -638,7 +638,7 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, if (pass != 0) { // Uncomment this to output addresses for all instructions // stream << Index << ": "; -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 MCSymbol *symbol = DisInfo.lookupSymbol(Fptr+Index); if (symbol) Streamer->EmitLabel(symbol); @@ -691,7 +691,7 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, // Pass 0: Record all branch targets if (MCIA && (MCIA->isBranch(Inst) || MCIA->isCall(Inst))) { uint64_t addr; -#ifdef LLVM34 +#if JL_LLVM_VERSION >= 30400 if (MCIA->evaluateBranch(Inst, Fptr+Index, insSize, addr)) #else if ((addr = MCIA->evaluateBranch(Inst, Fptr+Index, insSize)) != (uint64_t)-1) @@ -701,7 +701,7 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, } else { // Pass 1: Output instruction -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 Streamer->EmitInstruction(Inst, *STI); #else Streamer->EmitInstruction(Inst); diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index b33ed2b01cb69..5cfa2e862063b 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -434,7 +434,7 @@ static jl_cgval_t generic_box(jl_value_t *targ, jl_value_t *x, jl_codectx_t *ctx Value *arg1 = boxed(bt_value, ctx); Value *arg2 = boxed(v, ctx); Value *func = prepare_call(runtime_func[reinterpret]); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *r = builder.CreateCall(func, {arg1, arg2}); #else Value *r = builder.CreateCall2(func, arg1, arg2); @@ -732,7 +732,7 @@ static jl_cgval_t emit_runtime_pointerref(jl_value_t *e, jl_value_t *i, jl_value jl_cgval_t parg = emit_expr(e, ctx); Value *iarg = boxed(emit_expr(i, ctx), ctx); Value *alignarg = boxed(emit_expr(align, ctx), ctx); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *ret = builder.CreateCall(prepare_call(jlpref_func), { boxed(parg, ctx), iarg, alignarg }); #else Value *ret = builder.CreateCall3(prepare_call(jlpref_func), boxed(parg, ctx), iarg, alignarg); @@ -799,7 +799,7 @@ static jl_cgval_t emit_runtime_pointerset(jl_value_t *e, jl_value_t *x, jl_value Value *xarg = boxed(emit_expr(x, ctx), ctx); Value *iarg = boxed(emit_expr(i, ctx), ctx); Value *alignarg = boxed(emit_expr(align, ctx), ctx); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlpset_func), { boxed(parg, ctx), xarg, iarg, alignarg }); #else builder.CreateCall4(prepare_call(jlpset_func), boxed(parg, ctx), xarg, iarg, alignarg); @@ -896,7 +896,7 @@ struct math_builder { jl_options.fast_math == JL_OPTIONS_FAST_MATH_ON)) { FastMathFlags fmf; fmf.setUnsafeAlgebra(); -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 builder.setFastMathFlags(fmf); #else builder.SetFastMathFlags(fmf); @@ -905,7 +905,7 @@ struct math_builder { } IRBuilder<>& operator()() const { return builder; } ~math_builder() { -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 builder.setFastMathFlags(old_fmf); #else builder.SetFastMathFlags(old_fmf); @@ -944,7 +944,7 @@ static jl_cgval_t emit_intrinsic(intrinsic f, jl_value_t **args, size_t nargs, Value *func = prepare_call(runtime_func[f]); if (nargs == 1) { Value *x = boxed(emit_expr(args[1], ctx), ctx); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 r = builder.CreateCall(func, {x}); #else r = builder.CreateCall(func, x); @@ -953,7 +953,7 @@ static jl_cgval_t emit_intrinsic(intrinsic f, jl_value_t **args, size_t nargs, else if (nargs == 2) { Value *x = boxed(emit_expr(args[1], ctx), ctx); Value *y = boxed(emit_expr(args[2], ctx), ctx); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 r = builder.CreateCall(func, {x, y}); #else r = builder.CreateCall2(func, x, y); @@ -963,7 +963,7 @@ static jl_cgval_t emit_intrinsic(intrinsic f, jl_value_t **args, size_t nargs, Value *x = boxed(emit_expr(args[1], ctx), ctx); Value *y = boxed(emit_expr(args[2], ctx), ctx); Value *z = boxed(emit_expr(args[3], ctx), ctx); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 r = builder.CreateCall(func, {x, y, z}); #else r = builder.CreateCall3(func, x, y, z); @@ -1166,7 +1166,7 @@ static Value *emit_untyped_intrinsic(intrinsic f, Value *x, Value *y, Value *z, Value *typemin; switch (f) { case neg_int: -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 return builder.CreateNeg(JL_INT(x)); #else return builder.CreateSub(ConstantInt::get(t, 0), JL_INT(x)); @@ -1183,7 +1183,7 @@ static Value *emit_untyped_intrinsic(intrinsic f, Value *x, Value *y, Value *z, // to implement this in LLVM 3.4, though there are two different idioms // that do the correct thing on LLVM <= 3.3 and >= 3.5 respectively. // See issue #7868 -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 case neg_float: return math_builder(ctx)().CreateFSub(ConstantFP::get(FT(t), -0.0), FP(x)); case neg_float_fast: return math_builder(ctx, true)().CreateFNeg(FP(x)); #else @@ -1207,25 +1207,25 @@ static Value *emit_untyped_intrinsic(intrinsic f, Value *x, Value *y, Value *z, assert(z->getType() == y->getType()); Value *fmaintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::fma, ArrayRef(x->getType())); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 return builder.CreateCall(fmaintr,{ FP(x), FP(y), FP(z) }); #else return builder.CreateCall3(fmaintr, FP(x), FP(y), FP(z)); #endif } case muladd_float: -#ifdef LLVM34 +#if JL_LLVM_VERSION >= 30400 { assert(y->getType() == x->getType()); assert(z->getType() == y->getType()); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 return builder.CreateCall #else return builder.CreateCall3 #endif (Intrinsic::getDeclaration(jl_Module, Intrinsic::fmuladd, ArrayRef(x->getType())), - #ifdef LLVM37 + #if JL_LLVM_VERSION >= 30700 {FP(x), FP(y), FP(z)} #else FP(x), FP(y), FP(z) @@ -1259,7 +1259,7 @@ static Value *emit_untyped_intrinsic(intrinsic f, Value *x, Value *y, Value *z, Intrinsic::smul_with_overflow : Intrinsic::umul_with_overflow)))), ArrayRef(ix->getType())); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 Value *res = builder.CreateCall(intr,{ix, iy}); #else Value *res = builder.CreateCall2(intr, ix, iy); @@ -1413,7 +1413,7 @@ static Value *emit_untyped_intrinsic(intrinsic f, Value *x, Value *y, Value *z, Type *types[1] = {x->getType()}; Value *ctlz = Intrinsic::getDeclaration(jl_Module, Intrinsic::ctlz, ArrayRef(types)); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 return builder.CreateCall(ctlz, {x, ConstantInt::get(T_int1,0)}); #else return builder.CreateCall2(ctlz, x, ConstantInt::get(T_int1,0)); @@ -1423,7 +1423,7 @@ static Value *emit_untyped_intrinsic(intrinsic f, Value *x, Value *y, Value *z, x = JL_INT(x); Type *types[1] = {x->getType()}; Value *cttz = Intrinsic::getDeclaration(jl_Module, Intrinsic::cttz, ArrayRef(types)); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 return builder.CreateCall(cttz, {x, ConstantInt::get(T_int1, 0)}); #else return builder.CreateCall2(cttz, x, ConstantInt::get(T_int1, 0)); @@ -1433,7 +1433,7 @@ static Value *emit_untyped_intrinsic(intrinsic f, Value *x, Value *y, Value *z, case abs_float: { x = FP(x); -#ifdef LLVM34 +#if JL_LLVM_VERSION >= 30400 return builder.CreateCall( Intrinsic::getDeclaration(jl_Module, Intrinsic::fabs, ArrayRef(x->getType())), @@ -1521,11 +1521,11 @@ static Value *emit_untyped_intrinsic(intrinsic f, Value *x, Value *y, Value *z, x = FP(x); y = JL_INT(y); Type *tx = x->getType(); // TODO: LLVM expects this to be i32 -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 Type *ts[1] = { tx }; Value *powi = Intrinsic::getDeclaration(jl_Module, Intrinsic::powi, ArrayRef(ts)); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 return builder.CreateCall(powi, {x, y}); #else return builder.CreateCall2(powi, x, y); diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index 81010548828b7..ef8855ef2cb97 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -8,15 +8,15 @@ // analysis passes #include -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 #include #include #endif -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 #include #include #endif -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 #include #else #include @@ -31,7 +31,7 @@ #include #include #include -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 #include #endif @@ -40,7 +40,7 @@ namespace llvm { } #include -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 #include #endif @@ -50,7 +50,7 @@ namespace llvm { // target support #include #include -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 #include #endif #include @@ -96,7 +96,7 @@ void jl_init_jit(Type *T_pjlvalue_) // Except for parts of this file which were copied from LLVM, under the UIUC license (marked below). // this defines the set of optimization passes defined for Julia at various optimization levels -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 void addOptimizationPasses(legacy::PassManager *PM) #else void addOptimizationPasses(PassManager *PM) @@ -108,7 +108,7 @@ void addOptimizationPasses(PassManager *PM) #endif #if defined(JL_ASAN_ENABLED) -# if defined(LLVM37) && !defined(LLVM38) +# if JL_LLVM_VERSION >= 30700 && JL_LLVM_VERSION < 30800 // LLVM 3.7 BUG: ASAN pass doesn't properly initialize its dependencies initializeTargetLibraryInfoWrapperPassPass(*PassRegistry::getPassRegistry()); # endif @@ -121,18 +121,18 @@ void addOptimizationPasses(PassManager *PM) PM->add(createLowerPTLSPass(imaging_mode, tbaa_const)); return; } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 PM->add(createTargetTransformInfoWrapperPass(jl_TargetMachine->getTargetIRAnalysis())); #else jl_TargetMachine->addAnalysisPasses(*PM); #endif -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 PM->add(createTypeBasedAAWrapperPass()); #else PM->add(createTypeBasedAliasAnalysisPass()); #endif if (jl_options.opt_level >= 3) { -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 PM->add(createBasicAAWrapperPass()); #else PM->add(createBasicAliasAnalysisPass()); @@ -189,12 +189,12 @@ void addOptimizationPasses(PassManager *PM) #endif PM->add(createIndVarSimplifyPass()); // Canonicalize indvars PM->add(createLoopDeletionPass()); // Delete dead loops -#if defined(LLVM35) +#if JL_LLVM_VERSION >= 30500 PM->add(createSimpleLoopUnrollPass()); // Unroll small loops #else PM->add(createLoopUnrollPass()); // Unroll small loops #endif -#if !defined(LLVM35) && !defined(INSTCOMBINE_BUG) +#if JL_LLVM_VERSION < 30500 && !defined(INSTCOMBINE_BUG) PM->add(createLoopVectorizePass()); // Vectorize loops #endif //PM->add(createLoopStrengthReducePass()); // (jwb added) @@ -226,7 +226,7 @@ void addOptimizationPasses(PassManager *PM) if (jl_options.opt_level >= 3) PM->add(createInstructionCombiningPass()); // Clean up after SLP loop vectorizer #endif -#if defined(LLVM35) +#if JL_LLVM_VERSION >= 30500 PM->add(createLoopVectorizePass()); // Vectorize loops PM->add(createInstructionCombiningPass()); // Clean up after loop vectorizer #endif @@ -235,7 +235,7 @@ void addOptimizationPasses(PassManager *PM) #ifdef USE_ORCJIT -#ifndef LLVM38 +#if JL_LLVM_VERSION < 30800 void notifyObjectLoaded(RTDyldMemoryManager *memmgr, llvm::orc::ObjectLinkingLayerBase::ObjSetHandleT H); #endif @@ -332,13 +332,13 @@ template void JuliaOJIT::DebugObjectRegistrar::operator()(ObjectLinkingLayerBase::ObjSetHandleT H, const ObjSetT &Objects, const LoadResult &LOS) { -#ifndef LLVM38 +#if JL_LLVM_VERSION < 30800 notifyObjectLoaded(JIT.MemMgr, H); #endif auto oit = Objects.begin(); auto lit = LOS.begin(); for (; oit != Objects.end(); ++oit, ++lit) { -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 const auto &Object = (*oit)->getBinary(); #else auto &Object = *oit; @@ -425,7 +425,7 @@ JuliaOJIT::JuliaOJIT(TargetMachine &TM) if (!Obj) { M.dump(); -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 std::string Buf; raw_string_ostream OS(Buf); logAllUnhandledErrors(Obj.takeError(), OS, ""); @@ -517,7 +517,7 @@ void JuliaOJIT::addModule(std::unique_ptr M) // Step 0: ObjectLinkingLayer has checked whether it is in the current module // Step 1: See if it's something known to the ExecutionEngine if (auto Sym = findSymbol(Name, true)) { -#ifdef LLVM40 +#if JL_LLVM_VERSION >= 40000 // `findSymbol` already eagerly resolved the address // return it directly. return Sym; @@ -625,7 +625,7 @@ ExecutionEngine *jl_ExecutionEngine; template // for GlobalObject's static T *addComdat(T *G) { -#if defined(_OS_WINDOWS_) && defined(LLVM35) +#if defined(_OS_WINDOWS_) && JL_LLVM_VERSION >= 30500 if (imaging_mode && !G->isDeclaration()) { // Add comdat information to make MSVC link.exe happy // it's valid to emit this for ld.exe too, @@ -731,7 +731,7 @@ static void jl_merge_module(Module *dest, std::unique_ptr src) NamedMDNode *sNMD = src->getNamedMetadata("llvm.dbg.cu"); if (sNMD) { NamedMDNode *dNMD = dest->getOrInsertNamedMetadata("llvm.dbg.cu"); -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 for (NamedMDNode::op_iterator I = sNMD->op_begin(), E = sNMD->op_end(); I != E; ++I) { dNMD->addOperand(*I); } @@ -752,7 +752,7 @@ static void jl_merge_recursive(Module *m, Module *collector); #if defined(USE_MCJIT) || defined(USE_ORCJIT) static void jl_add_to_ee(std::unique_ptr m) { -#if defined(_CPU_X86_64_) && defined(_OS_WINDOWS_) && defined(LLVM35) +#if defined(_CPU_X86_64_) && defined(_OS_WINDOWS_) && JL_LLVM_VERSION >= 30500 // Add special values used by debuginfo to build the UnwindData table registration for Win64 ArrayType *atype = ArrayType::get(T_uint32, 3); // want 4-byte alignment of 12-bytes of data (new GlobalVariable(*m, atype, @@ -763,7 +763,7 @@ static void jl_add_to_ee(std::unique_ptr m) ConstantAggregateZero::get(atype), "__catchjmp"))->setSection(".text"); #endif assert(jl_ExecutionEngine); -#if defined(LLVM36) +#if JL_LLVM_VERSION >= 30600 jl_ExecutionEngine->addModule(std::move(m)); #else jl_ExecutionEngine->addModule(m.release()); @@ -831,7 +831,7 @@ static bool jl_can_finalize_function(StringRef F, SmallSet &known) if (incomplete_fname.find(F) != incomplete_fname.end()) return false; Module *M = module_for_fname.lookup(F); -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 if (M && known.insert(M).second) #else if (M && known.insert(M)) @@ -894,7 +894,7 @@ void jl_finalize_module(Module *m, bool shadow) // helper function for adding a DLLImport (dlsym) address to the execution engine // (for values created locally or in the sysimage, jl_emit_and_add_to_shadow is generally preferable) -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 void add_named_global(GlobalObject *gv, void *addr, bool dllimport) #else void add_named_global(GlobalValue *gv, void *addr, bool dllimport) @@ -905,7 +905,7 @@ void add_named_global(GlobalValue *gv, void *addr, bool dllimport) // (global_proto will strip this from the JIT) if (dllimport && imaging_mode) { assert(gv->getLinkage() == GlobalValue::ExternalLinkage); -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 // add the __declspec(dllimport) attribute gv->setDLLStorageClass(GlobalValue::DLLImportStorageClass); #else @@ -1118,19 +1118,19 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys Triple TheTriple = Triple(jl_TargetMachine->getTargetTriple()); // make sure to emit the native object format, even if FORCE_ELF was set in codegen #if defined(_OS_WINDOWS_) -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 TheTriple.setObjectFormat(Triple::COFF); #else TheTriple.setEnvironment(Triple::UnknownEnvironment); #endif #elif defined(_OS_DARWIN_) -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 TheTriple.setObjectFormat(Triple::MachO); #else TheTriple.setEnvironment(Triple::MachO); #endif #endif -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 std::unique_ptr #else OwningPtr @@ -1142,7 +1142,7 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys jl_TargetMachine->Options, #if defined(_OS_LINUX_) || defined(_OS_FREEBSD_) Reloc::PIC_, -#elif defined(LLVM39) +#elif JL_LLVM_VERSION >= 30900 Optional(), #else Reloc::Default, @@ -1151,12 +1151,12 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys CodeGenOpt::Aggressive // -O3 TODO: respect command -O0 flag? )); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 legacy::PassManager PM; #else PassManager PM; #endif -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 PM.add(new TargetLibraryInfo(Triple(TM->getTargetTriple()))); #else PM.add(new TargetLibraryInfoWrapperPass(Triple(TM->getTargetTriple()))); @@ -1164,11 +1164,11 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys // set up optimization passes -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 // No DataLayout pass needed anymore. -#elif defined(LLVM36) +#elif JL_LLVM_VERSION >= 30600 PM.add(new DataLayoutPass()); -#elif defined(LLVM35) +#elif JL_LLVM_VERSION >= 30500 PM.add(new DataLayoutPass(*jl_ExecutionEngine->getDataLayout())); #else PM.add(new DataLayout(*jl_ExecutionEngine->getDataLayout())); @@ -1178,7 +1178,7 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys std::unique_ptr bc_OS; std::unique_ptr obj_OS; -#ifdef LLVM37 // 3.7 simplified formatted output; just use the raw stream alone +#if JL_LLVM_VERSION >= 30700 // 3.7 simplified formatted output; just use the raw stream alone std::unique_ptr &bc_FOS = bc_OS; std::unique_ptr &obj_FOS = obj_OS; #else @@ -1187,7 +1187,7 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys #endif if (bc_fname) { -#if defined(LLVM35) +#if JL_LLVM_VERSION >= 30500 // call output handler directly to avoid special case handling of `-` filename int FD; std::error_code EC = sys::fs::openFileForWrite(bc_fname, FD, sys::fs::F_None); @@ -1202,7 +1202,7 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys if (!err.empty()) jl_safe_printf("%s\n", err.c_str()); else { -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 bc_FOS.reset(new formatted_raw_ostream(*bc_OS.get())); #endif PM.add(createBitcodeWriterPass(*bc_FOS.get())); // Unroll small loops @@ -1210,7 +1210,7 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys } if (obj_fname) { -#if defined(LLVM35) +#if JL_LLVM_VERSION >= 30500 // call output handler directly to avoid special case handling of `-` filename int FD; std::error_code EC = sys::fs::openFileForWrite(obj_fname, FD, sys::fs::F_None); @@ -1225,7 +1225,7 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys if (!err.empty()) jl_safe_printf("%s\n", err.c_str()); else { -#ifndef LLVM37 +#if JL_LLVM_VERSION < 30700 obj_FOS.reset(new formatted_raw_ostream(*obj_OS.get())); #endif if (TM->addPassesToEmitFile(PM, *obj_FOS.get(), TargetMachine::CGFT_ObjectFile, false)) { @@ -1242,10 +1242,10 @@ void jl_dump_native(const char *bc_fname, const char *obj_fname, const char *sys Module *clone = CloneModule(shadow_output, VMap); #endif -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 // Reset the target triple to make sure it matches the new target machine clone->setTargetTriple(TM->getTargetTriple().str()); -#ifdef LLVM38 +#if JL_LLVM_VERSION >= 30800 clone->setDataLayout(TM->createDataLayout()); #else clone->setDataLayout(TM->getDataLayout()->getStringRepresentation()); diff --git a/src/jitlayers.h b/src/jitlayers.h index bffa7aa7e5022..51e4f3901493e 100644 --- a/src/jitlayers.h +++ b/src/jitlayers.h @@ -25,7 +25,7 @@ #include #endif -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 #include "llvm/IR/LegacyPassManager.h" extern legacy::PassManager *jl_globalPM; #else @@ -33,7 +33,7 @@ extern legacy::PassManager *jl_globalPM; extern PassManager *jl_globalPM; #endif -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 #include #endif @@ -54,7 +54,7 @@ extern size_t jltls_states_func_idx; typedef struct {Value *gv; int32_t index;} jl_value_llvm; // uses 1-based indexing -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 void addOptimizationPasses(legacy::PassManager *PM); #else void addOptimizationPasses(PassManager *PM); @@ -78,7 +78,7 @@ static inline GlobalVariable *global_proto(GlobalVariable *G, Module *M = NULL) G->isConstant(), GlobalVariable::ExternalLinkage, NULL, G->getName(), G->getThreadLocalMode()); proto->copyAttributesFrom(G); -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 // DLLImport only needs to be set for the shadow module // it just gets annoying in the JIT proto->setDLLStorageClass(GlobalValue::DefaultStorageClass); @@ -100,7 +100,7 @@ static inline Function *function_proto(Function *F, Module *M = NULL) // routine from `F`, since copying it and then resetting is more expensive // as well as introducing an extra use from this unowned function, which // can cause crashes in the LLVMContext's global destructor. -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 llvm::Constant *OldPersonalityFn = nullptr; if (F->hasPersonalityFn()) { OldPersonalityFn = F->getPersonalityFn(); @@ -112,12 +112,12 @@ static inline Function *function_proto(Function *F, Module *M = NULL) // as codegen may make decisions based on the presence of certain attributes NewF->copyAttributesFrom(F); -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 if (OldPersonalityFn) F->setPersonalityFn(OldPersonalityFn); #endif -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 // DLLImport only needs to be set for the shadow module // it just gets annoying in the JIT NewF->setDLLStorageClass(GlobalValue::DefaultStorageClass); @@ -137,7 +137,7 @@ static inline GlobalVariable *prepare_global(GlobalVariable *G, Module *M) return cast(local); } -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 void add_named_global(GlobalObject *gv, void *addr, bool dllimport); template static inline void add_named_global(GlobalObject *gv, T *addr, bool dllimport = true) @@ -154,7 +154,7 @@ static inline void add_named_global(GlobalValue *gv, T *addr, bool dllimport = t void jl_init_jit(Type *T_pjlvalue_); #ifdef USE_ORCJIT -#ifdef LLVM40 +#if JL_LLVM_VERSION >= 40000 typedef JITSymbol JL_JITSymbol; // The type that is similar to SymbolInfo on LLVM 4.0 is actually // `JITEvaluatedSymbol`. However, we only use this type when a JITSymbol @@ -226,7 +226,7 @@ extern JuliaOJIT *jl_ExecutionEngine; #else extern ExecutionEngine *jl_ExecutionEngine; #endif -#ifdef LLVM39 +#if JL_LLVM_VERSION >= 30900 JL_DLLEXPORT extern LLVMContext jl_LLVMContext; #else JL_DLLEXPORT extern LLVMContext &jl_LLVMContext; diff --git a/src/llvm-gcroot.cpp b/src/llvm-gcroot.cpp index 3802d94d49f5f..954d0c9de172f 100644 --- a/src/llvm-gcroot.cpp +++ b/src/llvm-gcroot.cpp @@ -13,7 +13,7 @@ #include #include #include -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 #include #include #endif @@ -26,7 +26,7 @@ #include "julia.h" -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 #define LLVM37_param(x) (x), #else #define LLVM37_param(x) @@ -80,7 +80,7 @@ static void tbaa_decorate_gcframe(Instruction *inst, { if (!visited.insert(inst).second) return; -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 Value::user_iterator I = inst->user_begin(), E = inst->user_end(); #else Value::use_iterator I = inst->use_begin(), E = inst->use_end(); @@ -358,7 +358,7 @@ void JuliaGCAllocator::lowerHandlers() #endif // We need to mark this on the call site as well. See issue #6757 sj->setCanReturnTwice(); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 if (auto dbg = enter->getMetadata(LLVMContext::MD_dbg)) { new_enter->setMetadata(LLVMContext::MD_dbg, dbg); sj->setMetadata(LLVMContext::MD_dbg, dbg); @@ -427,7 +427,7 @@ void JuliaGCAllocator::collapseRedundantRoots() bool variable_slot = true; // whether this gc-root is only used as a variable-slot; e.g. whether theLoad is theValue LoadInst *theLoad = NULL; for (User::use_iterator use = callInst->use_begin(), usee = callInst->use_end(); use != usee; ) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 User *user = use->getUser(); #else User *user = use.getUse().getUser(); @@ -472,7 +472,7 @@ void JuliaGCAllocator::collapseRedundantRoots() // this gc-root is never loaded from, so we don't need it as a variable location // delete any stores to this gc-root that would be keeping an otherwise-unused value alive for (User::use_iterator use = callInst->use_begin(), usee = callInst->use_end(); use != usee; ) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 User *user = use->getUser(); #else User *user = use.getUse().getUser(); @@ -491,7 +491,7 @@ void JuliaGCAllocator::collapseRedundantRoots() } else if (callInst->hasOneUse()) { User::use_iterator use = callInst->use_begin(); -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 theStore = cast(use->getUser()); #else theStore = cast(use.getUse().getUser()); @@ -507,7 +507,7 @@ void JuliaGCAllocator::collapseRedundantRoots() User::use_iterator value_use = theValue->use_begin(); if (theLoad && *value_use == theStore) ++value_use; -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 StoreInst *theOther = dyn_cast(value_use->getUser()); unsigned OperandNo = value_use->getOperandNo(); #else @@ -542,7 +542,7 @@ void JuliaGCAllocator::collapseRedundantRoots() } if (++bbi == bbi_end) { // iterate the basicblock forward, if it's a simple branch -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 BasicBlock *next = current->getUniqueSuccessor(); #else succ_iterator SI = succ_begin(current), E = succ_end(current); @@ -597,7 +597,7 @@ void JuliaGCAllocator::collapseRedundantRoots() } else { for (User::use_iterator use = callInst->use_begin(), usee = callInst->use_end(); use != usee; ) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 User *user = use->getUser(); #else User *user = use.getUse().getUser(); @@ -762,7 +762,7 @@ void JuliaGCAllocator::allocate_frame() frames.push(std::make_pair(arg_n, callInst)); // the jlcall frame should have been passed to exactly one call (the jlcall) -- find its basic-block for (User::use_iterator use = callInst->use_begin(), usee = callInst->use_end(); use != usee; ++use) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 User *user = use->getUser(); #else User *user = use.getUse().getUser(); @@ -997,7 +997,7 @@ void JuliaGCAllocator::allocate_frame() * Replace(slot, newslot) -> at InsertPoint(gc-frame) * CreateStore(NULL, newslot) -> at InsertPoint(gc-frame) */ -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 DIBuilder dbuilder(M, false); #endif unsigned argSpaceSize = 0; @@ -1009,7 +1009,7 @@ void JuliaGCAllocator::allocate_frame() unsigned offset = 2 + argSpaceSize++; Instruction *argTempi = GetElementPtrInst::Create(LLVM37_param(NULL) gcframe, ArrayRef(ConstantInt::get(T_int32, offset))); argTempi->insertAfter(last_gcframe_inst); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 Metadata *md = ValueAsMetadata::getIfExists(callInst); if (md) { Value *mdValue = MetadataAsValue::get(M.getContext(), md); @@ -1028,7 +1028,7 @@ void JuliaGCAllocator::allocate_frame() addr.append(expr->elements_begin(), expr->elements_end()); expr = dbuilder.createExpression(addr); dbuilder.insertDeclare(gcframe, dinfo, expr, -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 dbg->getDebugLoc(), #endif dbg->getParent()); @@ -1056,7 +1056,7 @@ void JuliaGCAllocator::allocate_frame() } } } -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 dbuilder.finalize(); #endif diff --git a/src/llvm-ptls.cpp b/src/llvm-ptls.cpp index f9567a3a5b007..091b29c24e8af 100644 --- a/src/llvm-ptls.cpp +++ b/src/llvm-ptls.cpp @@ -19,7 +19,7 @@ #include "julia.h" #include "julia_internal.h" -#if defined(LLVM37) && defined(JULIA_ENABLE_THREADING) +#if JL_LLVM_VERSION >= 30700 && defined(JULIA_ENABLE_THREADING) # include #endif @@ -55,7 +55,7 @@ static void ensure_global(const char *name, Type *t, Module &M, // setting JL_DLLEXPORT correctly only matters when building a binary // (global_proto will strip this from the JIT) if (dllimport) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 // add the __declspec(dllimport) attribute proto->setDLLStorageClass(GlobalValue::DLLImportStorageClass); #else @@ -100,7 +100,7 @@ void LowerPTLS::runOnFunction(LLVMContext &ctx, Module &M, Function *F, ptlsStates->addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind); } -#ifdef LLVM37 +#if JL_LLVM_VERSION >= 30700 else if (jl_tls_offset != -1) { auto T_int8 = Type::getInt8Ty(ctx); auto T_pint8 = PointerType::get(T_int8, 0); diff --git a/src/llvm-simdloop.cpp b/src/llvm-simdloop.cpp index d12f1d08288c8..a30a4091e6092 100644 --- a/src/llvm-simdloop.cpp +++ b/src/llvm-simdloop.cpp @@ -30,7 +30,7 @@ bool annotateSimdLoop(BasicBlock *incr) // Lazy initialization if (!simd_loop_mdkind) { simd_loop_mdkind = incr->getContext().getMDKindID("simd_loop"); -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 simd_loop_md = MDNode::get(incr->getContext(), ArrayRef()); #else simd_loop_md = MDNode::get(incr->getContext(), ArrayRef()); @@ -94,7 +94,7 @@ void LowerSIMDLoop::enableUnsafeAlgebraIfReduction(PHINode *Phi, Loop *L) const for (Instruction *I = Phi; ; I=J) { J = NULL; // Find the user of instruction I that is within loop L. -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 for (User *UI : I->users()) { /*}*/ Instruction *U = cast(UI); #else @@ -151,11 +151,11 @@ bool LowerSIMDLoop::runOnLoop(Loop *L, LPPassManager &LPM) DEBUG(dbgs() << "LSL: simd_loop found\n"); BasicBlock *Lh = L->getHeader(); DEBUG(dbgs() << "LSL: loop header: " << *Lh << "\n"); -#ifdef LLVM34 +#if JL_LLVM_VERSION >= 30400 MDNode *n = L->getLoopID(); if (!n) { // Loop does not have a LoopID yet, so give it one. -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 n = MDNode::get(Lh->getContext(), ArrayRef(NULL)); #else n = MDNode::get(Lh->getContext(), ArrayRef(NULL)); @@ -167,7 +167,7 @@ bool LowerSIMDLoop::runOnLoop(Loop *L, LPPassManager &LPM) MDNode *n = MDNode::get(Lh->getContext(), ArrayRef()); L->getLoopLatch()->getTerminator()->setMetadata("llvm.loop.parallel", n); #endif -#ifdef LLVM36 +#if JL_LLVM_VERSION >= 30600 MDNode *m = MDNode::get(Lh->getContext(), ArrayRef(n)); #else MDNode *m = MDNode::get(Lh->getContext(), ArrayRef(n)); diff --git a/src/llvm-version.h b/src/llvm-version.h index b63a397d4fb3c..e9c42ff400331 100644 --- a/src/llvm-version.h +++ b/src/llvm-version.h @@ -2,53 +2,32 @@ #include -#if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 4 && LLVM_VERSION_MINOR >= 0 -#define LLVM40 1 -#endif - -#if defined(LLVM40) || (defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 9) -#define LLVM39 1 -#endif +// The LLVM version used, JL_LLVM_VERSION, is represented as a 5-digit integer +// of the form ABBCC, where A is the major version, B is minor, and C is patch. +// So for example, LLVM 3.7.0 is 30700. +#define JL_LLVM_VERSION (LLVM_VERSION_MAJOR * 10000 + LLVM_VERSION_MINOR * 100 \ + + LLVM_VERSION_PATCH) -#if defined(LLVM40) || (defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 8) -#define LLVM38 1 -#define USE_ORCJIT +#if JL_LLVM_VERSION != 30300 && JL_LLVM_VERSION < 30701 + #error Only LLVM versions 3.3 and >= 3.7.1 are supported by Julia #endif -#if defined(LLVM40) || (defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 7) -#define LLVM37 1 - +#if JL_LLVM_VERSION >= 30800 + #define USE_ORCJIT // We enable ORCJIT only if we have our custom patches -#ifndef SYSTEM_LLVM -#define USE_ORCJIT -#endif - +#elif JL_LLVM_VERSION >= 30700 && !defined(SYSTEM_LLVM) + #define USE_ORCJIT #endif -#if defined(LLVM40) || (defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 6) -#define LLVM36 1 +#if JL_LLVM_VERSION >= 30400 + #define USE_MCJIT #endif -#if defined(LLVM40) || (defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 5) -#define LLVM35 1 -#endif - -#if defined(LLVM40) || (defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR >= 4) -#define LLVM34 1 -#define USE_MCJIT -#endif - -#if defined(LLVM_VERSION_MAJOR) && LLVM_VERSION_MAJOR >= 3 -#if defined(LLVM40) || LLVM_VERSION_MINOR >= 3 -#define LLVM33 1 -#endif -#else -#error LLVM versions < 3.3 are not supported by Julia -#endif -#ifdef USE_ORCJIT //temporary, since in some places USE_MCJIT may be used instead of the correct LLVM version test -#define USE_MCJIT +//temporary, since in some places USE_MCJIT may be used instead of the correct LLVM version test +#ifdef USE_ORCJIT + #define USE_MCJIT #endif -#ifdef USE_ORCMCJIT //temporary, since in some places USE_MCJIT may be used instead of the correct LLVM version test -#define USE_MCJIT +#ifdef USE_ORCMCJIT + #define USE_MCJIT #endif diff --git a/src/runtime_ccall.cpp b/src/runtime_ccall.cpp index ca86501e223d8..9800805e87106 100644 --- a/src/runtime_ccall.cpp +++ b/src/runtime_ccall.cpp @@ -174,7 +174,7 @@ void *jl_load_and_lookup(const char *f_lib, const char *f_name, void **hnd) extern "C" JL_DLLEXPORT jl_value_t *jl_get_cpu_name(void) { -#ifdef LLVM35 +#if JL_LLVM_VERSION >= 30500 StringRef HostCPUName = llvm::sys::getHostCPUName(); #else const std::string& HostCPUName = llvm::sys::getHostCPUName();