diff --git a/src/ccall.cpp b/src/ccall.cpp index e19de5d1ff166c..a19d54c78d5620 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -166,17 +166,9 @@ static Value *runtime_sym_lookup(PointerType *funcptype, const char *f_lib, else { libname = literal_static_pointer_val(f_lib, T_pint8); } -#if JL_LLVM_VERSION >= 30700 Value *llvmf = builder.CreateCall(prepare_call(builder, jldlsym_func), { libname, stringConstPtr(builder, f_name), libptrgv }); -#else - Value *llvmf = builder.CreateCall3(prepare_call(builder, jldlsym_func), libname, stringConstPtr(builder, f_name), libptrgv); -#endif auto store = builder.CreateAlignedStore(llvmf, llvmgv, sizeof(void*)); -# if JL_LLVM_VERSION >= 30900 store->setAtomic(AtomicOrdering::Release); -# else - store->setAtomic(Release); -# endif builder.CreateBr(ccall_bb); f->getBasicBlockList().push_back(ccall_bb); @@ -254,11 +246,7 @@ static GlobalVariable *emit_plt_thunk(Module *M, FunctionType *functype, 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*)); -#if JL_LLVM_VERSION >= 30900 store->setAtomic(AtomicOrdering::Release); -#else - store->setAtomic(Release); -#endif SmallVector args; for (Function::arg_iterator arg = plt->arg_begin(), arg_e = plt->arg_end(); arg != arg_e; ++arg) args.push_back(&*arg); @@ -280,7 +268,7 @@ static GlobalVariable *emit_plt_thunk(Module *M, FunctionType *functype, 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 JL_LLVM_VERSION >= 30700 && (defined(_CPU_X86_) || defined(_CPU_X86_64_) || \ +#if (defined(_CPU_X86_) || defined(_CPU_X86_64_) || \ defined(_CPU_AARCH64_)) ret->setTailCallKind(CallInst::TCK_MustTail); #endif @@ -461,10 +449,8 @@ static Value *llvm_type_rewrite( Value *to; #if JL_LLVM_VERSION >= 40000 const DataLayout &DL = jl_data_layout; -#elif JL_LLVM_VERSION >= 30600 - const DataLayout &DL = jl_ExecutionEngine->getDataLayout(); #else - const DataLayout &DL = *jl_ExecutionEngine->getDataLayout(); + const DataLayout &DL = jl_ExecutionEngine->getDataLayout(); #endif if (DL.getTypeAllocSize(target_type) >= DL.getTypeAllocSize(from_type)) { to = emit_static_alloca(target_type, ctx); @@ -487,7 +473,7 @@ static Value *runtime_apply_type(jl_value_t *ty, jl_unionall_t *unionall, jl_cod args[0] = literal_pointer_val(ty); args[1] = literal_pointer_val((jl_value_t*)ctx->linfo->def.method->sig); args[2] = builder.CreateInBoundsGEP( - LLVM37_param(T_prjlvalue) + T_prjlvalue, emit_bitcast(decay_derived(ctx->spvals_ptr), T_pprjlvalue), ConstantInt::get(T_size, sizeof(jl_svec_t) / sizeof(jl_value_t*))); return builder.CreateCall(prepare_call(jlapplytype_func), makeArrayRef(args)); @@ -519,11 +505,7 @@ static void typeassert_input(const jl_cgval_t &jvinfo, jl_value_t *jlto, jl_unio Value *vx = boxed(jvinfo, ctx); Value *istype = builder. CreateICmpNE( -#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlisa_func), { vx, boxed(jlto_runtime, ctx) }), -#else - builder.CreateCall2(prepare_call(jlisa_func), vx, boxed(jlto_runtime, ctx)), -#endif ConstantInt::get(T_int32, 0)); BasicBlock *failBB = BasicBlock::Create(jl_LLVMContext, "fail", ctx->f); BasicBlock *passBB = BasicBlock::Create(jl_LLVMContext, "pass", ctx->f); @@ -834,7 +816,6 @@ static jl_cgval_t emit_cglobal(jl_value_t **args, size_t nargs, jl_codectx_t *ct return mark_julia_type(res, false, rt, ctx); } -#ifdef USE_MCJIT class FunctionMover final : public ValueMaterializer { public: @@ -871,11 +852,6 @@ class FunctionMover final : public ValueMaterializer VMap[&*I] = &*(DestI++); // Add mapping to VMap } -#if JL_LLVM_VERSION >= 30600 - // Clone debug info - Not yet public API - // llvm::CloneDebugInfoMetadata(NewF,F,VMap); -#endif - SmallVector Returns; llvm::CloneFunctionInto(NewF,F,VMap,true,Returns,"",NULL,NULL,this); NewF->setComdat(nullptr); @@ -910,13 +886,7 @@ class FunctionMover final : public ValueMaterializer return NewF; } -#if JL_LLVM_VERSION >= 30900 Value *materialize(Value *V) override -#elif JL_LLVM_VERSION >= 30800 - Value *materializeDeclFor(Value *V) override -#else - Value *materializeValueFor (Value *V) override -#endif { Function *F = dyn_cast(V); if (F) { @@ -984,7 +954,6 @@ class FunctionMover final : public ValueMaterializer return NULL; }; }; -#endif // llvmcall(ir, (rettypes...), (argtypes...), args...) static jl_cgval_t emit_llvmcall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx) @@ -1109,14 +1078,10 @@ 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(); -#if JL_LLVM_VERSION >= 30600 Module *m = NULL; bool failed = parseAssemblyInto(llvm::MemoryBufferRef(ir_string,"llvmcall"),*jl_Module,Err); if (!failed) m = jl_Module; -#else - Module *m = ParseAssemblyString(ir_string.c_str(),jl_Module,Err,jl_LLVMContext); -#endif if (m == NULL) { std::string message = "Failed to parse LLVM Assembly: \n"; llvm::raw_string_ostream stream(message); @@ -1136,20 +1101,14 @@ static jl_cgval_t emit_llvmcall(jl_value_t **args, size_t nargs, jl_codectx_t *c it != argtypes.end(); ++it, ++i) assert(*it == f->getFunctionType()->getParamType(i)); -#ifdef USE_MCJIT if (f->getParent() != jl_Module) { FunctionMover mover(jl_Module, f->getParent()); f = mover.CloneFunction(f); } -#endif //f->dump(); -#if JL_LLVM_VERSION < 30500 - if (verifyFunction(*f,PrintMessageAction)) { -#else llvm::raw_fd_ostream out(1,false); if (verifyFunction(*f,&out)) { -#endif #if JL_LLVM_VERSION >= 50000 f->print(llvm::dbgs(), nullptr, false, true); #else @@ -1212,10 +1171,8 @@ static jl_cgval_t mark_or_box_ccall_result(Value *result, bool isboxed, jl_value emit_leafcheck(runtime_dt, "ccall: return type must be a leaf DataType", ctx); #if JL_LLVM_VERSION >= 40000 const DataLayout &DL = jl_data_layout; -#elif JL_LLVM_VERSION >= 30600 - const DataLayout &DL = jl_ExecutionEngine->getDataLayout(); #else - const DataLayout &DL = *jl_ExecutionEngine->getDataLayout(); + const DataLayout &DL = jl_ExecutionEngine->getDataLayout(); #endif unsigned nb = DL.getTypeStoreSize(result->getType()); MDNode *tbaa = jl_is_mutable(rt) ? tbaa_mutab : tbaa_immut; @@ -1301,7 +1258,7 @@ std::string generate_func_sig() } else if (abi->use_sret((jl_datatype_t*)rt)) { AttrBuilder retattrs = AttrBuilder(); -#if !defined(_OS_WINDOWS_) || JL_LLVM_VERSION >= 30500 // llvm used to use the old mingw ABI, skipping this marking works around that difference +#if !defined(_OS_WINDOWS_) // llvm used to use the old mingw ABI, skipping this marking works around that difference retattrs.addAttribute(Attribute::StructRet); #endif retattrs.addAttribute(Attribute::NoAlias); @@ -1679,13 +1636,11 @@ static jl_cgval_t emit_ccall(jl_value_t **args, size_t nargs, jl_codectx_t *ctx) #ifdef __MIC__ // TODO #elif defined(_CPU_X86_64_) || defined(_CPU_X86_) /* !__MIC__ */ -#if JL_LLVM_VERSION >= 30700 static auto pauseinst = InlineAsm::get(FunctionType::get(T_void, false), "pause", "~{memory}", true); builder.CreateCall(pauseinst); JL_GC_POP(); return ghostValue(jl_void_type); -#endif #elif defined(_CPU_AARCH64_) || (defined(_CPU_ARM_) && __ARM_ARCH >= 7) static auto wfeinst = InlineAsm::get(FunctionType::get(T_void, false), "wfe", "~{memory}", true); @@ -2051,11 +2006,7 @@ jl_cgval_t function_sig_t::emit_a_ccall( stacksave = CallInst::Create(Intrinsic::getDeclaration(jl_Module, Intrinsic::stacksave)); if (savespot) { -#if JL_LLVM_VERSION >= 30800 instList.insertAfter(savespot->getIterator(), stacksave); -#else - instList.insertAfter(savespot, stacksave); -#endif } else { instList.push_front(stacksave); @@ -2197,10 +2148,8 @@ jl_cgval_t function_sig_t::emit_a_ccall( #ifndef JL_NDEBUG #if JL_LLVM_VERSION >= 40000 const DataLayout &DL = jl_data_layout; -#elif JL_LLVM_VERSION >= 30600 - const DataLayout &DL = jl_ExecutionEngine->getDataLayout(); #else - const DataLayout &DL = *jl_ExecutionEngine->getDataLayout(); + const DataLayout &DL = jl_ExecutionEngine->getDataLayout(); #endif // ARM and AArch64 can use a LLVM type larger than the julia // type. However, the LLVM type size should be no larger than diff --git a/src/cgmemmgr.cpp b/src/cgmemmgr.cpp index 6b2f43ebffdcf2..b4f0ff0969b694 100644 --- a/src/cgmemmgr.cpp +++ b/src/cgmemmgr.cpp @@ -4,17 +4,11 @@ #include "platform.h" #include "options.h" -#ifdef USE_MCJIT #include #include "fix_llvm_assert.h" #include "julia.h" #include "julia_internal.h" -#if JL_LLVM_VERSION >= 30700 -#if JL_LLVM_VERSION < 30800 -# include -# include "fix_llvm_assert.h" -#endif #ifdef _OS_LINUX_ # include # include @@ -755,11 +749,9 @@ class RTDyldMemoryManagerJL : public SectionMemoryManager { uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, unsigned SectionID, StringRef SectionName, bool isReadOnly) override; -#if JL_LLVM_VERSION >= 30800 using SectionMemoryManager::notifyObjectLoaded; void notifyObjectLoaded(RuntimeDyld &Dyld, const object::ObjectFile &Obj) override; -#endif bool finalizeMemory(std::string *ErrMsg = nullptr) override; template void mapAddresses(DL &Dyld, Alloc &&allocator) @@ -831,7 +823,6 @@ uint8_t *RTDyldMemoryManagerJL::allocateDataSection(uintptr_t Size, SectionName, isReadOnly); } -#if JL_LLVM_VERSION >= 30800 void RTDyldMemoryManagerJL::notifyObjectLoaded(RuntimeDyld &Dyld, const object::ObjectFile &Obj) { @@ -843,7 +834,6 @@ void RTDyldMemoryManagerJL::notifyObjectLoaded(RuntimeDyld &Dyld, assert(exe_alloc); mapAddresses(Dyld); } -#endif bool RTDyldMemoryManagerJL::finalizeMemory(std::string *ErrMsg) { @@ -886,14 +876,6 @@ void RTDyldMemoryManagerJL::deregisterEHFrames(uint8_t *Addr, } -#if JL_LLVM_VERSION < 30800 -void notifyObjectLoaded(RTDyldMemoryManager *memmgr, - llvm::orc::ObjectLinkingLayerBase::ObjSetHandleT H) -{ - ((RTDyldMemoryManagerJL*)memmgr)->mapAddresses(**H); -} -#endif - #ifdef _OS_WINDOWS_ void *lookupWriteAddressFor(RTDyldMemoryManager *memmgr, void *rt_addr) { @@ -901,12 +883,7 @@ void *lookupWriteAddressFor(RTDyldMemoryManager *memmgr, void *rt_addr) } #endif -#else // JL_LLVM_VERSION >= 30700 -typedef SectionMemoryManager RTDyldMemoryManagerJL; -#endif // JL_LLVM_VERSION >= 30700 - RTDyldMemoryManager* createRTDyldMemoryManager() { return new RTDyldMemoryManagerJL(); } -#endif // USE_MCJIT diff --git a/src/cgutils.cpp b/src/cgutils.cpp index bb0013c1a3fc76..9ca01c96ddfe2e 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -1156,7 +1156,7 @@ static void emit_leafcheck(Value *typ, const std::string &msg, jl_codectx_t *ctx assert(typ->getType() == T_pjlvalue); emit_typecheck(mark_julia_type(typ, true, jl_any_type, ctx, false), (jl_value_t*)jl_datatype_type, msg, ctx); Value *isleaf; - isleaf = builder.CreateConstInBoundsGEP1_32(LLVM37_param(T_int8) emit_bitcast(decay_derived(typ), T_pint8), offsetof(jl_datatype_t, isleaftype)); + isleaf = builder.CreateConstInBoundsGEP1_32(T_int8, emit_bitcast(decay_derived(typ), T_pint8), offsetof(jl_datatype_t, isleaftype)); isleaf = builder.CreateLoad(isleaf, tbaa_const); isleaf = builder.CreateTrunc(isleaf, T_int1); error_unless(isleaf, msg, ctx); @@ -1526,14 +1526,14 @@ static jl_cgval_t emit_getfield_knownidx(const jl_cgval_t &strct, unsigned idx, lt = vlt->getElementType(); Value *ptr = data_pointer(strct, ctx, lt->getPointerTo()); Value *llvm_idx = ConstantInt::get(T_size, idx); - addr = builder.CreateGEP(LLVM37_param(lt) ptr, llvm_idx); + addr = builder.CreateGEP(lt, ptr, llvm_idx); } else if (lt->isSingleValueType()) { addr = data_pointer(strct, ctx, lt->getPointerTo()); } else { Value *ptr = data_pointer(strct, ctx, lt->getPointerTo()); - addr = builder.CreateStructGEP(LLVM37_param(lt) ptr, idx); + addr = builder.CreateStructGEP(lt, ptr, idx); } } if (jl_field_isptr(jt, idx)) { @@ -2394,7 +2394,7 @@ static jl_cgval_t emit_new_struct(jl_value_t *ty, size_t nargs, jl_value_t **arg if (!init_as_value) { // avoid unboxing the argument explicitely // and use memcpy instead - dest = builder.CreateConstInBoundsGEP2_32(LLVM37_param(lt) strct, 0, i); + dest = builder.CreateConstInBoundsGEP2_32(lt, strct, 0, i); } fval = emit_unbox(fty, fval_info, jtype, dest); diff --git a/src/codegen.cpp b/src/codegen.cpp index 475cb70837ed34..8abe8ef92ec5c1 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -38,39 +38,23 @@ // target machine computation #include #include -#if JL_LLVM_VERSION < 30700 -#include -#endif #include #include #include -#if JL_LLVM_VERSION >= 30700 #include -#endif - -#if JL_LLVM_VERSION >= 30700 #include -#endif // IR building #include -#if JL_LLVM_VERSION >= 30500 #include #include #include -#else -#include -#endif #include #include #include #include #include #include -#if JL_LLVM_VERSION < 30500 -#include -#include -#endif // support #include @@ -79,26 +63,16 @@ #include #include // for llvmcall #include // for llvmcall inlining -#if JL_LLVM_VERSION >= 30500 #include // for llvmcall validation -#else -#include -#endif // C API -#if JL_LLVM_VERSION >= 30800 #include -#else -#include -#endif // for configuration options #include #include -#if JL_LLVM_VERSION >= 30700 -# include -#endif +#include #if defined(_CPU_ARM_) || defined(_CPU_AARCH64_) # include #endif @@ -123,13 +97,7 @@ namespace llvm { #include "codegen_internal.h" // LLVM version compatibility macros -#if JL_LLVM_VERSION >= 30700 legacy::PassManager *jl_globalPM; -#define LLVM37_param(x) (x), -#else -#define LLVM37_param(x) -PassManager *jl_globalPM; -#endif #if JL_LLVM_VERSION >= 40000 #define DIFlagZero (DINode::FlagZero) @@ -137,10 +105,6 @@ PassManager *jl_globalPM; #define DIFlagZero (0) #endif -#if JL_LLVM_VERSION < 30500 -#define AddrSpaceCastInst BitCastInst -#endif - extern "C" { #include "builtin_proto.h" @@ -187,11 +151,7 @@ extern void _chkstk(void); #define DISABLE_FLOAT16 // llvm state -#if JL_LLVM_VERSION >= 30900 JL_DLLEXPORT LLVMContext jl_LLVMContext; -#else -JL_DLLEXPORT LLVMContext &jl_LLVMContext = getGlobalContext(); -#endif static IRBuilder<> builder(jl_LLVMContext); static bool nested_compile = false; TargetMachine *jl_TargetMachine; @@ -205,14 +165,7 @@ Module *shadow_output; #define jl_Module ctx->f->getParent() #define jl_builderModule builder.GetInsertBlock()->getParent()->getParent() -#if JL_LLVM_VERSION >= 30700 static DataLayout jl_data_layout(""); -// No DataLayout pass needed anymore. -#elif JL_LLVM_VERSION >= 30500 -static DataLayoutPass *jl_data_layout; -#else -static DataLayout *jl_data_layout; -#endif // types static Type *T_jlvalue; @@ -279,25 +232,11 @@ static MDNode *tbaa_arrayflags; // The flags in a jl_array_t static MDNode *tbaa_const; // Memory that is immutable by the time LLVM can see it // Basic DITypes -#if JL_LLVM_VERSION >= 30700 static DICompositeType *jl_value_dillvmt; static DIDerivedType *jl_pvalue_dillvmt; static DIDerivedType *jl_ppvalue_dillvmt; static DISubroutineType *jl_di_func_sig; static DISubroutineType *jl_di_func_null_sig; -#else -static DICompositeType jl_value_dillvmt; -static DIDerivedType jl_pvalue_dillvmt; -static DIDerivedType jl_ppvalue_dillvmt; -#if JL_LLVM_VERSION >= 30600 -DISubroutineType jl_di_func_sig; -DISubroutineType jl_di_func_null_sig; -#else -DICompositeType jl_di_func_sig; -DICompositeType jl_di_func_null_sig; -#endif -#endif - extern "C" int32_t jl_jlcall_api(const void *function) @@ -334,9 +273,6 @@ static GlobalVariable *jlRTLD_DEFAULT_var; #ifdef _OS_WINDOWS_ static GlobalVariable *jlexe_var; static GlobalVariable *jldll_var; -#if defined(_CPU_X86_64_) && !defined(USE_MCJIT) -JITMemoryManager *createJITMemoryManagerWin(); -#endif #endif //_OS_WINDOWS_ static Function *jltls_states_func; @@ -541,11 +477,7 @@ struct jl_varinfo_t { Instruction *boxroot; // an address, if the var might be in a jl_value_t** stack slot (marked tbaa_const, if appropriate) jl_cgval_t value; // a stack slot or constant value Value *pTIndex; // i8* stack slot for the value.TIndex tag describing `value.V` -#if JL_LLVM_VERSION >= 30700 DILocalVariable *dinfo; -#else - DIVariable dinfo; -#endif // if the variable might be used undefined and is not boxed // this i1 flag is true when it is defined Value *defFlag; @@ -559,11 +491,7 @@ struct jl_varinfo_t { jl_varinfo_t() : boxroot(NULL), value(jl_cgval_t()), pTIndex(NULL), -#if JL_LLVM_VERSION >= 30700 dinfo(NULL), -#else - dinfo(DIVariable()), -#endif defFlag(NULL), isSA(false), isVolatile(false), @@ -687,11 +615,7 @@ static GlobalVariable *get_pointer_to_constant(Constant *val, StringRef name, Mo GlobalVariable::PrivateLinkage, val, name); -#if JL_LLVM_VERSION >= 30900 gv->setUnnamedAddr(GlobalValue::UnnamedAddr::Global); -#else - gv->setUnnamedAddr(true); -#endif return gv; } @@ -1289,12 +1213,7 @@ jl_llvm_functions_t jl_compile_linfo(jl_method_instance_t **pli, jl_code_info_t // so we can build a reverse mapping for debug-info. bool toplevel = !jl_is_method(li->def.method); if (!toplevel) { - const DataLayout &DL = -#if JL_LLVM_VERSION >= 30500 - m->getDataLayout(); -#else - *jl_data_layout; -#endif + const DataLayout &DL = m->getDataLayout(); // but don't remember toplevel thunks because // they may not be rooted in the gc for the life of the program, // and the runtime doesn't notify us when the code becomes unreachable :( @@ -1350,21 +1269,7 @@ jl_llvm_functions_t jl_compile_linfo(jl_method_instance_t **pli, jl_code_info_t return decls; } -#if JL_LLVM_VERSION < 30700 -static Value *getModuleFlag(Module *m, StringRef Key) -{ - SmallVector ModuleFlags; - m->getModuleFlagsMetadata(ModuleFlags); - SmallVector::iterator it = ModuleFlags.begin(); - for (;it != ModuleFlags.end(); ++it) { - if (Key == it->Key->getString()) - return it->Val; - } - return NULL; -} -#else #define getModuleFlag(m,str) m->getModuleFlag(str) -#endif static void jl_setup_module(Module *m, const jl_cgparams_t *params = &jl_default_cgparams) { @@ -1384,25 +1289,16 @@ static void jl_setup_module(Module *m, const jl_cgparams_t *params = &jl_default #endif m->addModuleFlag(llvm::Module::Warning, "Dwarf Version", dwarf_version); } -#if JL_LLVM_VERSION >= 30400 if (!getModuleFlag(m,"Debug Info Version")) m->addModuleFlag(llvm::Module::Error, "Debug Info Version", llvm::DEBUG_METADATA_VERSION); -#endif #if JL_LLVM_VERSION >= 40000 m->setDataLayout(jl_data_layout); -#elif JL_LLVM_VERSION >= 30700 -#ifdef USE_ORCJIT - m->setDataLayout(jl_ExecutionEngine->getDataLayout()); -#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 JL_LLVM_VERSION >= 30600 m->setDataLayout(jl_ExecutionEngine->getDataLayout()); #endif + m->setTargetTriple(jl_TargetMachine->getTargetTriple().str()); + } // this ensures that llvmf has been emitted to the execution engine, @@ -1414,17 +1310,12 @@ static uint64_t getAddressForFunction(llvm::Function *llvmf) #ifdef JL_DEBUG_BUILD llvm::raw_fd_ostream out(1,false); #endif -#ifdef USE_MCJIT jl_finalize_function(llvmf); uint64_t ret = jl_ExecutionEngine->getFunctionAddress(llvmf->getName()); // delay executing trace callbacks until here to make sure there's no // recursive compilation. jl_callback_triggered_linfos(); return ret; -#else - return (uint64_t)jl_ExecutionEngine->getPointerToFunction( - cast(shadow_output->getNamedValue(llvmf->getName()))); -#endif } extern "C" JL_DLLEXPORT @@ -1586,31 +1477,16 @@ void jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) // force eager emission of the function (llvm 3.3 gets confused otherwise and tries to do recursive compilation) uint64_t Addr = getAddressForFunction(llvmf); -#if defined(USE_ORCJIT) || defined(USE_MCJIT) if (imaging_mode) - // in the old JIT, the shadow_module aliases the engine_module, - // otherwise, just point the alias to the declaration -#endif llvmf = cast(shadow_output->getNamedValue(llvmf->getName())); // make the alias to the shadow_module GlobalAlias *GA = -#if JL_LLVM_VERSION >= 30800 GlobalAlias::create(llvmf->getType()->getElementType(), llvmf->getType()->getAddressSpace(), GlobalValue::ExternalLinkage, name, llvmf, shadow_output); -#elif JL_LLVM_VERSION >= 30700 - GlobalAlias::create(cast(llvmf->getType()), - GlobalValue::ExternalLinkage, name, llvmf, shadow_output); -#else - new GlobalAlias(llvmf->getType(), GlobalValue::ExternalLinkage, name, llvmf, shadow_output); -#endif -#if defined(USE_ORCJIT) || defined(USE_MCJIT) // make sure the alias name is valid for the current session jl_ExecutionEngine->addGlobalMapping(GA, (void*)(uintptr_t)Addr); -#else - (void)GA; (void)Addr; -#endif JL_UNLOCK(&codegen_lock); } @@ -1808,61 +1684,28 @@ static uint64_t compute_obj_symsize(const object::ObjectFile *obj, uint64_t offs uint64_t lo = 0; uint64_t hi = 0; bool setlo = false; -#if JL_LLVM_VERSION >= 30700 for (const object::SectionRef &Section : obj->sections()) { -#else - llvm::error_code err; - for (object::section_iterator I = obj->begin_sections(), E = obj->end_sections(); - !err && I != E; I.increment(err)) { - object::SectionRef Section = *I; -#endif uint64_t SAddr, SSize; -#if JL_LLVM_VERSION >= 30500 if (!Section.isText()) continue; -#else - bool isText; - if (Section.isText(isText) || !isText) continue; -#endif -#if JL_LLVM_VERSION >= 30600 SAddr = Section.getAddress(); SSize = Section.getSize(); -#else - Section.getAddress(SAddr); - Section.getSize(SSize); -#endif if (offset < SAddr || offset >= SAddr + SSize) continue; assert(hi == 0); // test for lower and upper symbol bounds relative to other symbols hi = SAddr + SSize; -#if JL_LLVM_VERSION >= 30700 object::section_iterator ESection = obj->section_end(); for (const object::SymbolRef &Sym : obj->symbols()) { -#else - llvm::error_code err; - object::section_iterator ESection = obj->end_sections(); - for (object::symbol_iterator I = obj->begin_symbols(), E = obj->end_symbols(); - !err && I != E; I.increment(err)) { - object::SymbolRef Sym = *I; -#endif uint64_t Addr; object::section_iterator Sect = ESection; -#if JL_LLVM_VERSION >= 30800 auto SectOrError = Sym.getSection(); assert(SectOrError); Sect = SectOrError.get(); -#else - if (Sym.getSection(Sect)) continue; -#endif if (Sect == ESection) continue; if (Sect != Section) continue; -#if JL_LLVM_VERSION >= 30700 auto AddrOrError = Sym.getAddress(); assert(AddrOrError); Addr = AddrOrError.get(); -#else - if (Sym.getAddress(Addr)) continue; -#endif if (Addr <= offset && Addr >= lo) { // test for lower bound on symbol lo = Addr; @@ -1886,9 +1729,6 @@ const jl_value_t *jl_dump_function_asm(void *f, int raw_mc, const char* asm_vari jl_ptls_t ptls = jl_get_ptls_states(); std::string code; llvm::raw_string_ostream stream(code); -#if JL_LLVM_VERSION < 30700 - llvm::formatted_raw_ostream fstream(stream); -#endif Function *llvmf = dyn_cast((Function*)f); if (!llvmf) @@ -1898,16 +1738,11 @@ const jl_value_t *jl_dump_function_asm(void *f, int raw_mc, const char* asm_vari uint64_t symsize = 0; int64_t slide = 0, section_slide = 0; uint64_t fptr = getAddressForFunction(llvmf); -#ifdef USE_MCJIT // Look in the system image as well if (fptr == 0) fptr = (uintptr_t)jl_ExecutionEngine->getPointerToGlobalIfAvailable(llvmf); llvm::DIContext *context = NULL; llvm::DIContext *&objcontext = context; -#else - std::vector context; - llvm::DIContext *objcontext = NULL; -#endif const object::ObjectFile *object = NULL; assert(fptr != 0); if (!jl_DI_for_fptr(fptr, &symsize, &slide, §ion_slide, &object, &context)) { @@ -1930,21 +1765,11 @@ const jl_value_t *jl_dump_function_asm(void *f, int raw_mc, const char* asm_vari int8_t gc_state = jl_gc_safe_enter(ptls); jl_dump_asm_internal(fptr, symsize, slide, -#ifndef USE_MCJIT - context, -#endif object, objcontext, -#if JL_LLVM_VERSION >= 30700 stream, -#else - fstream, -#endif asm_variant ); -#if JL_LLVM_VERSION < 30700 - fstream.flush(); -#endif jl_gc_safe_leave(ptls, gc_state); return jl_cstr_to_string(const_cast(stream.str().c_str())); @@ -2001,11 +1826,7 @@ static void mallocVisitLine(StringRef filename, int line) return; } visitLine( mallocData[filename], line, - builder.CreateCall(prepare_call(diff_gc_total_bytes_func) -#if JL_LLVM_VERSION >= 30700 - , {} -#endif - ), + builder.CreateCall(prepare_call(diff_gc_total_bytes_func), {}), "bytecnt"); } @@ -2512,19 +2333,12 @@ 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) { -#if JL_LLVM_VERSION >= 30700 Value *answer = builder.CreateCall(prepare_call(memcmp_func), { data_pointer(arg1, ctx, T_pint8), data_pointer(arg2, ctx, T_pint8), ConstantInt::get(T_size, sz) }); -#else - Value *answer = builder.CreateCall3(prepare_call(memcmp_func), - data_pointer(arg1, ctx, T_pint8), - data_pointer(arg2, ctx, T_pint8), - ConstantInt::get(T_size, sz)); -#endif return builder.CreateICmpEQ(answer, ConstantInt::get(T_int32, 0)); } else { @@ -2537,8 +2351,8 @@ static Value *emit_bits_compare(const jl_cgval_t &arg1, const jl_cgval_t &arg2, for(unsigned i=0; i < l; i++) { jl_value_t *fldty = jl_svecref(types, i); Value *subAns, *fld1, *fld2; - fld1 = builder.CreateConstGEP2_32(LLVM37_param(at) varg1, 0, i); - fld2 = builder.CreateConstGEP2_32(LLVM37_param(at) varg2, 0, i); + fld1 = builder.CreateConstGEP2_32(at, varg1, 0, i); + fld2 = builder.CreateConstGEP2_32(at, varg2, 0, i); if (type_is_ghost(fld1->getType()->getPointerElementType())) continue; subAns = emit_bits_compare( @@ -2627,11 +2441,7 @@ static Value *emit_f_is(const jl_cgval_t &arg1, const jl_cgval_t &arg2, jl_codec JL_FEAT_REQUIRE(ctx, runtime); Value *varg1 = mark_callee_rooted(boxed(arg1, ctx)); Value *varg2 = mark_callee_rooted(boxed(arg2, ctx, false)); // potentially unrooted! -#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); -#endif } static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args, size_t nargs, @@ -2692,11 +2502,7 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args, Value *rt_ty = boxed(emit_expr(args[2], ctx), ctx); Value *rt_val = boxed(*ret, ctx); JL_FEAT_REQUIRE(ctx, runtime); -#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jltypeassert_func), {rt_val, rt_ty}); -#else - builder.CreateCall2(prepare_call(jltypeassert_func), rt_val, rt_ty); -#endif JL_GC_POP(); return true; } @@ -2748,17 +2554,10 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args, #endif JL_FEAT_REQUIRE(ctx, runtime); Value *r = -#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlapply2va_func), {theF, builder.CreateGEP(ctx->argArray, ConstantInt::get(T_size, ctx->nReqArgs)), nva}); -#else - builder.CreateCall3(prepare_call(jlapply2va_func), theF, - builder.CreateGEP(ctx->argArray, - ConstantInt::get(T_size, ctx->nReqArgs)), - nva); -#endif *ret = mark_julia_type(r, true, expr_type(expr, ctx), ctx); JL_GC_POP(); return true; @@ -2931,15 +2730,9 @@ static bool emit_builtin_call(jl_cgval_t *ret, jl_value_t *f, jl_value_t **args, T_pprjlvalue))); } else { -#if JL_LLVM_VERSION >= 30700 own_ptr = builder.CreateCall( prepare_call(jlarray_data_owner_func), {aryv}); -#else - own_ptr = builder.CreateCall( - prepare_call(jlarray_data_owner_func), - aryv); -#endif } builder.CreateBr(mergeBB); builder.SetInsertPoint(mergeBB); @@ -3529,15 +3322,9 @@ 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); -#if JL_LLVM_VERSION >= 30700 Value *bval = builder.CreateCall(prepare_call(jlgetbindingorerror_func), {maybe_decay_untracked(literal_pointer_val((jl_value_t*)m)), literal_pointer_val((jl_value_t*)s)}); -#else - Value *bval = builder.CreateCall2(prepare_call(jlgetbindingorerror_func), - maybe_decay_untracked(literal_pointer_val((jl_value_t*)m)), - literal_pointer_val((jl_value_t*)s)); -#endif builder.CreateStore(bval, bindinggv); builder.CreateBr(have_val); ctx->f->getBasicBlockList().push_back(have_val); @@ -3572,7 +3359,7 @@ static jl_cgval_t emit_sparam(size_t i, jl_codectx_t *ctx) } } assert(ctx->spvals_ptr != NULL); - Value *bp = builder.CreateConstInBoundsGEP1_32(LLVM37_param(T_prjlvalue) + Value *bp = builder.CreateConstInBoundsGEP1_32(T_prjlvalue, emit_bitcast(decay_derived(ctx->spvals_ptr), T_pprjlvalue), i + sizeof(jl_svec_t) / sizeof(jl_value_t*)); return mark_julia_type(tbaa_decorate(tbaa_const, builder.CreateLoad(bp)), true, jl_any_type, ctx, false); @@ -3894,15 +3681,9 @@ static void emit_assignment(jl_value_t *l, jl_value_t *r, jl_codectx_t *ctx) JL_FEAT_REQUIRE(ctx, runtime); assert(bnd); Value *rval = mark_callee_rooted(boxed(emit_expr(r, ctx), ctx, false)); // no root needed since this is about to be assigned to a global -#if JL_LLVM_VERSION >= 30700 builder.CreateCall(prepare_call(jlcheckassign_func), {literal_pointer_val(bnd), rval}); -#else - builder.CreateCall2(prepare_call(jlcheckassign_func), - literal_pointer_val(bnd), - rval); -#endif // Global variable. Does not need debug info because the debugger knows about // its memory location. return; @@ -4450,9 +4231,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(sig.attributes); -#if JL_LLVM_VERSION >= 30700 cw->addFnAttr("no-frame-pointer-elim", "true"); -#endif Function *cw_proto = function_proto(cw); BasicBlock *b0 = BasicBlock::Create(jl_LLVMContext, "top", cw); @@ -4484,7 +4263,7 @@ static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_t if (lam) { Value *lam_max = builder.CreateLoad( builder.CreateConstInBoundsGEP1_32( - LLVM37_param(T_size) + T_size, emit_bitcast(decay_derived(literal_pointer_val((jl_value_t*)lam)), T_psize), offsetof(jl_method_instance_t, max_world) / sizeof(size_t))); // XXX: age is always OK if we don't have a TLS. This is a hack required due to `@threadcall` abuse. @@ -4628,7 +4407,7 @@ static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_t // figure out how to repack this type if (!specsig) { Value *arg = boxed(inputarg, &ctx, false); // don't want a gcroot, since it's about to be put into the jlcall frame anyways - GetElementPtrInst *slot = GetElementPtrInst::Create(LLVM37_param(NULL) myargs, + GetElementPtrInst *slot = GetElementPtrInst::Create(NULL, myargs, ArrayRef(ConstantInt::get(T_int32, FParamIndex))); slot->insertAfter(ctx.ptlsStates); builder.CreateStore(arg, slot); @@ -4676,9 +4455,7 @@ static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_t funcName.str(), M); jl_init_function(gf_thunk); gf_thunk->setAttributes(theFptr->getAttributes()); -#if JL_LLVM_VERSION >= 30700 gf_thunk->addFnAttr("no-frame-pointer-elim", "true"); -#endif call_v = builder.CreateSelect(age_ok, call_v, gf_thunk); } CallInst *call = builder.CreateCall(call_v, ArrayRef(args)); @@ -4710,7 +4487,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); - GetElementPtrInst *slot = GetElementPtrInst::Create(LLVM37_param(NULL) myargs, + GetElementPtrInst *slot = GetElementPtrInst::Create(NULL, myargs, ArrayRef(ConstantInt::get(T_int32, 0))); slot->insertAfter(ctx.ptlsStates); builder.CreateStore(theF, slot); @@ -4725,22 +4502,14 @@ static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_t builder.CreateCondBr(age_ok, b_jlcall, b_generic); builder.SetInsertPoint(b_jlcall); Value *nargs_v = ConstantInt::get(T_int32, nargs); - Value *myargs1 = builder.CreateConstInBoundsGEP1_32(LLVM37_param(NULL) myargs, 1); -#if JL_LLVM_VERSION >= 30700 + Value *myargs1 = builder.CreateConstInBoundsGEP1_32(NULL, myargs, 1); ret_jlcall = builder.CreateCall(prepare_call(theFptr), {theF, myargs1, nargs_v}); -#else - ret_jlcall = builder.CreateCall3(prepare_call(theFptr), theF, myargs1, nargs_v); -#endif builder.CreateBr(b_after); builder.SetInsertPoint(b_generic); } Value *nargs_v = ConstantInt::get(T_int32, nargs + 1); -#if JL_LLVM_VERSION >= 30700 Value *ret = builder.CreateCall(prepare_call(jlapplygeneric_func), {myargs, nargs_v}); -#else - Value *ret = builder.CreateCall2(prepare_call(jlapplygeneric_func), myargs, nargs_v); -#endif if (age_ok) { builder.CreateBr(b_after); builder.SetInsertPoint(b_after); @@ -4842,16 +4611,12 @@ static Function *gen_cfun_wrapper(jl_function_t *ff, jl_value_t *jlrettype, jl_t } (void)at; } - Value *argn = builder.CreateConstInBoundsGEP1_32(LLVM37_param(NULL) myargs, i); + Value *argn = builder.CreateConstInBoundsGEP1_32(NULL, myargs, i); builder.CreateStore(maybe_decay_untracked(arg_box), argn); } assert(AI == gf_thunk->arg_end()); Value *nargs_v = ConstantInt::get(T_int32, nargs + 1); -#if JL_LLVM_VERSION >= 30700 Value *gf_ret = builder.CreateCall(prepare_call(jlapplygeneric_func), {myargs, nargs_v}); -#else - Value *gf_ret = builder.CreateCall2(prepare_call(jlapplygeneric_func), myargs, nargs_v); -#endif jl_cgval_t gf_retbox = mark_julia_type(gf_ret, true, jl_any_type, &ctx, /*needsroot*/false); if (cc != jl_returninfo_t::Boxed) { emit_typecheck(gf_retbox, astrt, "cfunction", &ctx2); @@ -5011,9 +4776,7 @@ static Function *gen_jlcall_wrapper(jl_method_instance_t *lam, const jl_returnin Function *w = Function::Create(jl_func_sig, GlobalVariable::ExternalLinkage, funcName, M); jl_init_function(w); -#if JL_LLVM_VERSION >= 30700 w->addFnAttr("no-frame-pointer-elim", "true"); -#endif Function::arg_iterator AI = w->arg_begin(); Value *fArg = &*AI++; Value *argArray = &*AI++; @@ -5180,9 +4943,7 @@ static jl_returninfo_t get_specsig_function(Module *M, const std::string &name, continue; if (ty->isAggregateType()) { // aggregate types are passed by pointer attributes = attributes.addAttribute(jl_LLVMContext, fsig.size() + 1, Attribute::NoCapture); -#if JL_LLVM_VERSION >= 30500 attributes = attributes.addAttribute(jl_LLVMContext, fsig.size() + 1, Attribute::ReadOnly); -#endif ty = PointerType::get(ty, AddressSpace::Derived); } if (isboxed) @@ -5196,26 +4957,10 @@ static jl_returninfo_t get_specsig_function(Module *M, const std::string &name, return props; } -#if JL_LLVM_VERSION >= 30700 static DISubroutineType * -#elif JL_LLVM_VERSION >= 30600 -static DISubroutineType -#else -static DICompositeType -#endif -get_specsig_di(jl_value_t *sig, -#if JL_LLVM_VERSION >= 30700 - DIFile *topfile, -#else - DIFile topfile, -#endif - DIBuilder &dbuilder) +get_specsig_di(jl_value_t *sig, DIFile *topfile, DIBuilder &dbuilder) { -#if JL_LLVM_VERSION >= 30600 std::vector ditypes(0); -#else - std::vector ditypes(0); -#endif for (size_t i = 0; i < jl_nparams(sig); i++) { jl_value_t *jt = jl_tparam(sig, i); Type *ty = julia_type_to_llvm(jt); @@ -5223,13 +4968,7 @@ get_specsig_di(jl_value_t *sig, continue; ditypes.push_back(julia_type_to_di(jt, &dbuilder, false)); } -#if JL_LLVM_VERSION >= 30800 return dbuilder.createSubroutineType(dbuilder.getOrCreateTypeArray(ditypes)); -#elif JL_LLVM_VERSION >= 30600 - return dbuilder.createSubroutineType(topfile, dbuilder.getOrCreateTypeArray(ditypes)); -#else - return dbuilder.createSubroutineType(topfile, dbuilder.getOrCreateArray(ditypes)); -#endif } @@ -5427,9 +5166,7 @@ static std::unique_ptr emit_function( declarations->specFunctionObject = NULL; } -#if JL_LLVM_VERSION >= 30700 f->addFnAttr("no-frame-pointer-elim", "true"); -#endif if (jlrettype == (jl_value_t*)jl_bottom_type) f->setDoesNotReturn(); #if defined(_OS_WINDOWS_) && !defined(_CPU_X86_64_) @@ -5449,7 +5186,7 @@ static std::unique_ptr emit_function( AttributeSet::FunctionIndex, *attr)); #endif #endif -#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) && JL_LLVM_VERSION >= 30500 +#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) f->setHasUWTable(); // force NeedsWinEH #endif @@ -5466,36 +5203,19 @@ static std::unique_ptr emit_function( // Step 4b. determine debug info signature and other type info for locals DIBuilder dbuilder(*M); -#if JL_LLVM_VERSION >= 30700 DIFile *topfile = NULL; DISubprogram *SP = NULL; -#else - DIFile topfile; - DISubprogram SP; -#endif DebugLoc noDbg, topdebugloc; if (ctx.debug_enabled) { // TODO: Fix when moving to new LLVM version topfile = dbuilder.createFile(filename, "."); -#if JL_LLVM_VERSION < 30400 - dbuilder.createCompileUnit(0x01, filename, ".", "julia", true, "", 0); - DIDescriptor CU = DIDescriptor(dbuilder.getCU()); -#elif JL_LLVM_VERSION >= 40000 +#if JL_LLVM_VERSION >= 40000 DICompileUnit *CU = dbuilder.createCompileUnit(0x01, topfile, "julia", true, "", 0); -#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()); + DICompileUnit *CU = dbuilder.createCompileUnit(0x01, filename, ".", "julia", true, "", 0); #endif -#if JL_LLVM_VERSION >= 30700 DISubroutineType *subrty; -#elif JL_LLVM_VERSION >= 30600 - DISubroutineType subrty; -#else - DICompositeType subrty; -#endif if (jl_options.debug_level <= 1) { subrty = jl_di_func_null_sig; } @@ -5516,19 +5236,9 @@ static std::unique_ptr emit_function( 0, // ScopeLine DIFlagZero, // Flags true, // isOptimized -#if JL_LLVM_VERSION >= 30800 nullptr); // Template Parameters -#else - f); // Function -#endif topdebugloc = DebugLoc::get(toplineno, 0, SP, NULL); -#if JL_LLVM_VERSION >= 30800 f->setSubprogram(SP); -#endif -#if JL_LLVM_VERSION < 30700 - assert(SP.Verify() && SP.describes(f) && SP.getFunction() == f); -#endif - if (jl_options.debug_level >= 2) { const bool AlwaysPreserve = true; // Go over all arguments and local variables and initialize their debug information @@ -5537,7 +5247,6 @@ static std::unique_ptr emit_function( if (argname == unused_sym) continue; jl_varinfo_t &varinfo = ctx.slots[i]; -#if JL_LLVM_VERSION >= 30800 varinfo.dinfo = dbuilder.createParameterVariable( SP, // Scope (current function will be fill in later) jl_symbol_name(argname), // Variable name @@ -5548,21 +5257,8 @@ static std::unique_ptr emit_function( julia_type_to_di(varinfo.value.typ, &dbuilder, false), AlwaysPreserve, // May be deleted if optimized out DIFlagZero); // Flags (TODO: Do we need any) -#else - varinfo.dinfo = dbuilder.createLocalVariable( - llvm::dwarf::DW_TAG_arg_variable, // Tag - SP, // Scope (current function will be fill in later) - jl_symbol_name(argname), // Variable name - topfile, // File - toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function) - julia_type_to_di(varinfo.value.typ, &dbuilder, false), // Variable type - AlwaysPreserve, // May be deleted if optimized out - 0, // Flags (TODO: Do we need any) - ctx.has_sret + i + 1); // Argument number (1-based) -#endif } if (va && ctx.vaSlot != -1) { -#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 @@ -5572,18 +5268,6 @@ static std::unique_ptr emit_function( julia_type_to_di(ctx.slots[ctx.vaSlot].value.typ, &dbuilder, false), AlwaysPreserve, // May be deleted if optimized out DIFlagZero); // Flags (TODO: Do we need any) -#else - ctx.slots[ctx.vaSlot].dinfo = dbuilder.createLocalVariable( - llvm::dwarf::DW_TAG_arg_variable, // Tag - SP, // Scope (current function will be fill in later) - std::string(jl_symbol_name(slot_symbol(ctx.vaSlot, &ctx))) + "...", // Variable name - topfile, // File - toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function) - julia_type_to_di(ctx.slots[ctx.vaSlot].value.typ, &dbuilder, false), // Variable type - AlwaysPreserve, // May be deleted if optimized out - 0, // Flags (TODO: Do we need any) - ctx.has_sret + nreq + 1); // Argument number (1-based) -#endif } for (i = 0; i < vinfoslen; i++) { jl_sym_t *s = (jl_sym_t*)jl_array_ptr_ref(src->slotnames, i); @@ -5591,12 +5275,7 @@ static std::unique_ptr emit_function( if (varinfo.isArgument || s == compiler_temp_sym || s == unused_sym) continue; // LLVM 4.0: Assume the variable has default alignment -#if JL_LLVM_VERSION >= 30800 varinfo.dinfo = dbuilder.createAutoVariable( -#else - varinfo.dinfo = dbuilder.createLocalVariable( - llvm::dwarf::DW_TAG_auto_variable, // Tag -#endif SP, // Scope (current function will be fill in later) jl_symbol_name(s), // Variable name topfile, // File @@ -5604,9 +5283,6 @@ static std::unique_ptr emit_function( 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) -#if JL_LLVM_VERSION < 30800 - ,0 // Argument number (1-based) -#endif ); } } @@ -5712,16 +5388,12 @@ static std::unique_ptr emit_function( // slot is not immutable if there are multiple assignments varinfo.value.isimmutable &= varinfo.isSA; alloc_def_flag(varinfo, &ctx); -#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(), -#if JL_LLVM_VERSION >= 30700 topdebugloc, -#endif builder.GetInsertBlock()); } -#endif continue; } if (!varinfo.isArgument || // always need a slot if the variable is assigned @@ -5739,7 +5411,6 @@ static std::unique_ptr emit_function( false); SI->insertAfter(ctx.ptlsStates); varinfo.boxroot = av; -#if JL_LLVM_VERSION >= 30600 if (ctx.debug_enabled && varinfo.dinfo) { DIExpression *expr; if ((Metadata*)varinfo.dinfo->getType() == jl_pvalue_dillvmt) { @@ -5751,12 +5422,9 @@ static std::unique_ptr emit_function( expr = dbuilder.createExpression(addr); } dbuilder.insertDeclare(av, varinfo.dinfo, expr, -#if JL_LLVM_VERSION >= 30700 topdebugloc, -#endif builder.GetInsertBlock()); } -#endif } maybe_alloc_arrayvar(i, &ctx); } @@ -5808,7 +5476,6 @@ static std::unique_ptr emit_function( 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); -#if JL_LLVM_VERSION >= 30600 if (ctx.debug_enabled && vi.dinfo && !vi.boxroot && !vi.value.V) { SmallVector addr; addr.push_back(llvm::dwarf::DW_OP_deref); @@ -5817,12 +5484,9 @@ static std::unique_ptr emit_function( if ((Metadata*)vi.dinfo->getType() != jl_pvalue_dillvmt) addr.push_back(llvm::dwarf::DW_OP_deref); dbuilder.insertDeclare(pargArray, vi.dinfo, dbuilder.createExpression(addr), -#if JL_LLVM_VERSION >= 30700 topdebugloc, -#endif builder.GetInsertBlock()); } -#endif } } @@ -5830,7 +5494,6 @@ static std::unique_ptr emit_function( assert(vi.value.V == NULL && "unexpected variable slot created for argument"); // keep track of original (possibly boxed) value to avoid re-boxing or moving vi.value = theArg; -#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()) @@ -5841,12 +5504,9 @@ static std::unique_ptr emit_function( builder.CreateStore(theArg.V, parg); } dbuilder.insertDeclare(parg, vi.dinfo, dbuilder.createExpression(addr), -#if JL_LLVM_VERSION >= 30700 topdebugloc, -#endif builder.GetInsertBlock()); } -#endif } else { Value *argp = boxed(theArg, &ctx, false); // skip the temporary gcroot since it would be folded to argp anyways @@ -5871,21 +5531,12 @@ static std::unique_ptr emit_function( else if (!vi.value.constant) { // restarg = jl_f_tuple(NULL, &args[nreq], nargs-nreq) if (vi.boxroot != NULL) { -#if JL_LLVM_VERSION >= 30700 Value *restTuple = builder.CreateCall(prepare_call(jltuple_func), {maybe_decay_untracked(V_null), builder.CreateGEP(argArray, ConstantInt::get(T_size,nreq-1)), builder.CreateSub(argCount, ConstantInt::get(T_int32,nreq-1))}); -#else - Value *restTuple = - builder.CreateCall3(prepare_call(jltuple_func), maybe_decay_untracked(V_null), - builder.CreateGEP(argArray, - ConstantInt::get(T_size,nreq-1)), - builder.CreateSub(argCount, - ConstantInt::get(T_int32,nreq-1))); -#endif builder.CreateStore(restTuple, vi.boxroot); emit_local_root(&ctx, &vi); // create a root for vi } @@ -5909,11 +5560,7 @@ static std::unique_ptr emit_function( }; struct DbgState { DebugLoc loc; -#if JL_LLVM_VERSION >= 30700 DISubprogram *sp; -#else - DISubprogram sp; -#endif StringRef file; ssize_t line; bool in_user_code; @@ -5970,11 +5617,7 @@ static std::unique_ptr emit_function( } MDNode *inlinedAt = NULL; if (DI_stack.size() > 0) { -#if JL_LLVM_VERSION >= 30700 inlinedAt = DI_stack.back().loc; -#else - inlinedAt = DI_stack.back().loc.getAsMDNode(jl_LLVMContext); -#endif } if (ctx.debug_enabled) cur_prop.loc = DebugLoc::get(lno, 0, SP, inlinedAt); @@ -5990,11 +5633,7 @@ static std::unique_ptr emit_function( jl_sym_t *filesym = (jl_sym_t*)jl_exprarg(expr, 1); if (filesym != empty_sym) new_filename = jl_symbol_name(filesym); -#if JL_LLVM_VERSION >= 30700 DIFile *new_file = nullptr; -#else - DIFile new_file; -#endif if (ctx.debug_enabled) new_file = dbuilder.createFile(new_filename, "."); DI_stack.push_back(DbgState{cur_prop.loc, SP, @@ -6034,11 +5673,7 @@ static std::unique_ptr emit_function( true, nullptr); MDNode *inlinedAt = NULL; -#if JL_LLVM_VERSION >= 30700 inlinedAt = cur_prop.loc; -#else - inlinedAt = cur_prop.loc.getAsMDNode(jl_LLVMContext); -#endif cur_prop.loc = DebugLoc::get(inlined_func_lineno, 0, SP, inlinedAt); } @@ -6337,11 +5972,7 @@ static std::unique_ptr emit_function( builder.CreateLoad(emit_exc_in_transit(&ctx), true)), resetstkoflw_blk, handlr); builder.SetInsertPoint(resetstkoflw_blk); - builder.CreateCall(prepare_call(resetstkoflw_func) -# if JL_LLVM_VERSION >= 30700 - , {} -# endif - ); + builder.CreateCall(prepare_call(resetstkoflw_func), {}); builder.CreateBr(handlr); #else builder.CreateCondBr(isz, tryblk, handlr); @@ -6403,20 +6034,8 @@ std::pair tbaa_make_child(const char *name, MDNode *parent=null static MDNode *tbaa_root = mbuilder->createTBAARoot("jtbaa"); if (!parent) parent = tbaa_root; -#if JL_LLVM_VERSION >= 30700 MDNode *scalar = mbuilder->createTBAAScalarTypeNode(name, parent); MDNode *n = mbuilder->createTBAAStructTagNode(scalar, scalar, 0, isConstant); -#else - MDNode *n = mbuilder->createTBAANode(name, parent, isConstant); - MDNode *scalar = n; -#if JL_LLVM_VERSION < 30600 -#if JL_LLVM_VERSION >= 30500 - n->setValueName(ValueName::Create(name)); -#else - n->setValueName(ValueName::Create(name, name + strlen(name))); -#endif -#endif -#endif return std::make_pair(n, scalar); } @@ -6468,10 +6087,6 @@ extern "C" void jl_fptr_to_llvm(jl_fptr_t fptr, jl_method_instance_t *lam, int s else if (lam->jlcall_api == 1) funcName << "jsys1_"; // it's a jlcall without a specsig const char* unadorned_name = jl_symbol_name(lam->def.method->name); -#if (defined(_OS_LINUX_) && JL_LLVM_VERSION < 30400) - if (unadorned_name[0] == '@') - unadorned_name++; -#endif funcName << unadorned_name << "_" << globalUnique++; if (specsig) { // assumes !va Function *f = get_specsig_function(shadow_output, funcName.str(), lam->specTypes, lam->rettype).decl; @@ -6497,11 +6112,6 @@ extern "C" void jl_fptr_to_llvm(jl_fptr_t fptr, jl_method_instance_t *lam, int s } } -#if LLVM_VERSION_MAJOR == 3 && LLVM_VERSION_MINOR == 3 && defined(SYSTEM_LLVM) -#define INSTCOMBINE_BUG -#define V128_BUG -#endif - static void init_julia_llvm_meta(void) { tbaa_gcframe = tbaa_make_child("jtbaa_gcframe").first; @@ -6564,42 +6174,25 @@ static void init_julia_llvm_env(Module *m) // add needed base debugging definitions to our LLVM environment DIBuilder dbuilder(*m); -#if JL_LLVM_VERSION >= 30700 DIFile *julia_h = dbuilder.createFile("julia.h",""); jl_value_dillvmt = dbuilder.createStructType(nullptr, -#else - DIFile julia_h = dbuilder.createFile("julia.h",""); - jl_value_dillvmt = dbuilder.createStructType(DIDescriptor(), -#endif "jl_value_t", julia_h, 71, // At the time of this writing. Not sure if it's worth it to keep this in sync 0 * 8, // sizeof(jl_value_t) * 8, __alignof__(void*) * 8, // __alignof__(jl_value_t) * 8, DIFlagZero, // Flags -#if JL_LLVM_VERSION >= 30700 nullptr, // Derived from nullptr); // Elements - will be corrected later -#else - DIType(), // Derived from - DIArray()); // Elements - will be corrected later -#endif jl_pvalue_dillvmt = dbuilder.createPointerType(jl_value_dillvmt, sizeof(jl_value_t*) * 8, __alignof__(jl_value_t*) * 8); -#if JL_LLVM_VERSION >= 30600 SmallVector Elts; std::vector diargs(0); Elts.push_back(jl_pvalue_dillvmt); dbuilder.replaceArrays(jl_value_dillvmt, dbuilder.getOrCreateArray(Elts)); -#else - SmallVector Elts; - std::vector diargs(0); - Elts.push_back(jl_pvalue_dillvmt); - jl_value_dillvmt.setTypeArray(dbuilder.getOrCreateArray(Elts)); -#endif jl_ppvalue_dillvmt = dbuilder.createPointerType(jl_pvalue_dillvmt,sizeof(jl_value_t**)*8, __alignof__(jl_value_t**)*8); @@ -6610,22 +6203,10 @@ 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)); -#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 JL_LLVM_VERSION >= 30600 - jl_di_func_sig = dbuilder.createSubroutineType(julia_h, - dbuilder.getOrCreateTypeArray(diargs)); - jl_di_func_null_sig = dbuilder.createSubroutineType(julia_h, - dbuilder.getOrCreateTypeArray(None)); -#else - jl_di_func_sig = dbuilder.createSubroutineType(julia_h, - dbuilder.getOrCreateArray(diargs)); - jl_di_func_null_sig = dbuilder.createSubroutineType(julia_h, - dbuilder.getOrCreateArray(ArrayRef())); -#endif T_jlvalue = StructType::create(jl_LLVMContext, "jl_value_t"); T_pjlvalue = PointerType::get(T_jlvalue, 0); @@ -7200,30 +6781,8 @@ static void init_julia_llvm_env(Module *m) NULL, "jl_world_counter"); add_named_global(jlgetworld_global, &jl_world_counter); - // set up optimization passes -#if JL_LLVM_VERSION >= 30700 -// No DataLayout pass needed anymore. -#elif JL_LLVM_VERSION >= 30600 - jl_data_layout = new llvm::DataLayoutPass(); -#elif JL_LLVM_VERSION >= 30500 - jl_data_layout = new llvm::DataLayoutPass(*jl_ExecutionEngine->getDataLayout()); -#else - jl_data_layout = new DataLayout(*jl_ExecutionEngine->getDataLayout()); -#endif - -#if JL_LLVM_VERSION >= 30700 jl_globalPM = new legacy::PassManager(); -#else - jl_globalPM = new PassManager(); -#endif -#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 -#if JL_LLVM_VERSION < 30700 - jl_globalPM->add(jl_data_layout); -#endif addOptimizationPasses(jl_globalPM, jl_options.opt_level); } @@ -7314,17 +6873,7 @@ static inline SmallVector getTargetFeatures(std::string &cpu) } // Platform specific overides follow -#if defined(_CPU_X86_64_) || defined(_CPU_X86_) -#ifndef USE_MCJIT - // Temporarily disable Haswell BMI2 features due to LLVM bug. - HostFeatures["bmi2"] = false; - HostFeatures["avx2"] = false; -#endif -#ifdef V128_BUG - HostFeatures["avx"] = false; -#endif -#endif -#if defined(_CPU_X86_64_) && JL_LLVM_VERSION >= 30600 +#if defined(_CPU_X86_64_) // Require cx16 (cmpxchg16b) // We need this for 128-bit atomic operations. We only need this // when threading is enabled; however, to test whether this @@ -7436,11 +6985,6 @@ extern "C" void *jl_init_llvm(void) jl_init_debuginfo(); jl_init_runtime_ccall(); -#if JL_LLVM_VERSION < 30400 - // this option disables LLVM's signal handlers - llvm::DisablePrettyStackTrace = true; -#endif - #ifdef USE_POLLY PassRegistry &Registry = *PassRegistry::getPassRegistry(); polly::initializePollyPasses(Registry); @@ -7454,52 +6998,24 @@ extern "C" void *jl_init_llvm(void) Module *m, *engine_module; engine_module = new Module("julia", jl_LLVMContext); -#ifdef USE_MCJIT m = new Module("julia", jl_LLVMContext); -#else - m = engine_module; -#endif shadow_output = m; TargetOptions options = TargetOptions(); //options.PrintMachineCode = true; //Print machine code produced during JIT compiling -#if defined(JL_DEBUG_BUILD) && JL_LLVM_VERSION < 30700 - options.JITEmitDebugInfo = true; -#endif -#if JL_LLVM_VERSION < 30700 - options.NoFramePointerElim = true; -#endif -#if JL_LLVM_VERSION < 30400 - options.NoFramePointerElimNonLeaf = true; -#endif #if defined(_OS_WINDOWS_) && !defined(_CPU_X86_64_) // tell Win32 to assume the stack is always 16-byte aligned, // and to ensure that it is 16-byte aligned for out-going calls, // to ensure compatibility with GCC codes options.StackAlignmentOverride = 16; #endif -#if defined(__APPLE__) && JL_LLVM_VERSION < 30400 - // turn on JIT support for libunwind to walk the stack - options.JITExceptionHandling = 1; -#endif - -#if JL_LLVM_VERSION >= 30600 EngineBuilder eb((std::unique_ptr(engine_module))); -#else - EngineBuilder eb(engine_module); -#endif std::string ErrorStr; eb .setEngineKind(EngineKind::JIT) -#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_) && !defined(USE_MCJIT) - .setJITMemoryManager(createJITMemoryManagerWin()) -#elif defined(USE_MCJIT) .setMCJITMemoryManager(std::unique_ptr{createRTDyldMemoryManager()}) -#endif .setTargetOptions(options) #if (defined(_OS_LINUX_) && defined(_CPU_X86_64_)) .setRelocationModel(Reloc::PIC_) -#elif JL_LLVM_VERSION < 30900 - .setRelocationModel(Reloc::Default) #endif #ifdef _P64 .setCodeModel(CodeModel::Large) @@ -7511,20 +7027,13 @@ extern "C" void *jl_init_llvm(void) #else .setOptLevel(jl_options.opt_level == 0 ? CodeGenOpt::None : CodeGenOpt::Aggressive) #endif -#if defined(USE_MCJIT) && JL_LLVM_VERSION < 30600 - .setUseMCJIT(true) -#endif #ifdef USE_ORCMCJIT .setUseOrcMCJITReplacement(true) #endif ; Triple TheTriple(sys::getProcessTriple()); #if defined(FORCE_ELF) -#if JL_LLVM_VERSION >= 30500 TheTriple.setObjectFormat(Triple::ELF); -#else - TheTriple.setEnvironment(Triple::ELF); -#endif #endif std::string TheCPU; SmallVector targetFeatures = getTargetFeatures(TheCPU); @@ -7535,7 +7044,7 @@ extern "C" void *jl_init_llvm(void) targetFeatures); assert(jl_TargetMachine && "Failed to select target machine -" " Is the LLVM backend for this CPU enabled?"); - #if defined(USE_MCJIT) && (!defined(_CPU_ARM_) && !defined(_CPU_PPC64_)) + #if (!defined(_CPU_ARM_) && !defined(_CPU_PPC64_)) // FastISel seems to be buggy for ARM. Ref #13321 if (jl_options.opt_level < 2) jl_TargetMachine->setFastISel(true); @@ -7552,7 +7061,7 @@ extern "C" void *jl_init_llvm(void) ErrorStr.c_str()); exit(1); } -#if JL_LLVM_VERSION >= 30500 && !defined(USE_ORCMCJIT) +#if !defined(USE_ORCMCJIT) jl_ExecutionEngine->setProcessAllSections(true); #endif jl_ExecutionEngine->DisableLazyCompilation(); diff --git a/src/codegen_internal.h b/src/codegen_internal.h index 1ee60e0611af44..49543b27199b5f 100644 --- a/src/codegen_internal.h +++ b/src/codegen_internal.h @@ -2,36 +2,19 @@ #include "codegen_shared.h" -#if defined(USE_ORCJIT) && JL_LLVM_VERSION <= 30800 -# include -void notifyObjectLoaded(RTDyldMemoryManager *memmgr, - llvm::orc::ObjectLinkingLayerBase::ObjSetHandleT H); -#endif - // Declarations for disasm.cpp extern "C" void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, -#ifndef USE_MCJIT - std::vector lineinfo, -#endif const object::ObjectFile *object, llvm::DIContext *context, -#if JL_LLVM_VERSION >= 30700 raw_ostream &rstream, -#else - formatted_raw_ostream &stream, -#endif const char* asm_variant="att" ); // Declarations for debuginfo.cpp extern int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide, int64_t *section_slide, const object::ObjectFile **object, -#ifdef USE_MCJIT llvm::DIContext **context -#else - std::vector *lines -#endif ); extern bool jl_dylib_DI_for_fptr(size_t pointer, const object::ObjectFile **object, llvm::DIContext **context, int64_t *slide, int64_t *section_slide, @@ -43,6 +26,4 @@ void *lookupWriteAddressFor(RTDyldMemoryManager *memmgr, void *rt_addr); #endif #endif -#ifdef USE_MCJIT RTDyldMemoryManager* createRTDyldMemoryManager(void); -#endif diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index 558bb83fcff71e..95106b098321ce 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -6,37 +6,22 @@ #include #include #include -#if JL_LLVM_VERSION >= 30700 #include #include -#endif #include #include #include #include -#if JL_LLVM_VERSION >= 30500 #include -#else -#include -#endif -#if defined(USE_MCJIT) || defined(USE_ORCJIT) #include #include -#if JL_LLVM_VERSION < 30600 -#include -#endif #include -#else -#include -#endif #if JL_LLVM_VERSION >= 50000 #include #endif #include #include -#if JL_LLVM_VERSION >= 30700 -# include -#endif +#include #include "fix_llvm_assert.h" using namespace llvm; @@ -63,13 +48,7 @@ using llvm_file_magic = sys::fs::file_magic; #include #include -#if JL_LLVM_VERSION >= 30500 && JL_LLVM_VERSION < 30600 -extern ExecutionEngine *jl_ExecutionEngine; -#endif - -#ifdef USE_MCJIT typedef object::SymbolRef SymRef; -#endif // Any function that acquires this lock must be either a unmanaged thread // or in the GC safe region and must NOT allocate anything through the GC @@ -85,26 +64,12 @@ extern "C" void jl_init_debuginfo() // --- storing and accessing source location metadata --- -#ifndef USE_MCJIT -struct FuncInfo { - const Function *func; - size_t lengthAdr; - std::vector lines; - jl_method_instance_t *linfo; -}; -#else struct ObjectInfo { const object::ObjectFile *object; size_t SectionSize; ptrdiff_t slide; -#if JL_LLVM_VERSION >= 30700 DIContext *context; -#endif -#if defined(_OS_DARWIN_) && JL_LLVM_VERSION < 30700 - const char *name; -#endif }; -#endif // Maintain a mapping of unrealized function names -> linfo objects // so that when we see it get emitted, we can add a link back to the linfo @@ -112,16 +77,12 @@ struct ObjectInfo { static StringMap linfo_in_flight; static std::string mangle(const std::string &Name, const DataLayout &DL) { -#if defined(USE_MCJIT) || defined(USE_ORCJIT) std::string MangledName; { raw_string_ostream MangledNameStream(MangledName); Mangler::getNameWithPrefix(MangledNameStream, Name, DL); } return MangledName; -#else - return Name; -#endif } void jl_add_linfo_in_flight(StringRef name, jl_method_instance_t *linfo, const DataLayout &DL) { @@ -135,30 +96,7 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam // GC safe DWORD mod_size = 0; #if defined(_CPU_X86_64_) -#if !defined(USE_MCJIT) - uint8_t *catchjmp = Section+Allocated; - UnwindData = (uint8_t*)(((uintptr_t)catchjmp+12+3)&~(uintptr_t)3); - if (!catchjmp[0]) { - catchjmp[0] = 0x48; - catchjmp[1] = 0xb8; // mov RAX, QWORD PTR [...] - *(uint64_t*)(&catchjmp[2]) = (uint64_t)&__julia_personality; - catchjmp[10] = 0xff; - catchjmp[11] = 0xe0; // jmp RAX - UnwindData[0] = 0x09; // version info, UNW_FLAG_EHANDLER - UnwindData[1] = 4; // size of prolog (bytes) - UnwindData[2] = 2; // count of unwind codes (slots) - UnwindData[3] = 0x05; // frame register (rbp) = rsp - UnwindData[4] = 4; // second instruction - UnwindData[5] = 0x03; // mov RBP, RSP - UnwindData[6] = 1; // first instruction - UnwindData[7] = 0x50; // push RBP - *(DWORD*)&UnwindData[8] = (DWORD)(catchjmp - Section); // relative location of catchjmp - mod_size = (DWORD)Allocated+48; - } - PRUNTIME_FUNCTION tbl = (PRUNTIME_FUNCTION)(UnwindData+12); -#else PRUNTIME_FUNCTION tbl = (PRUNTIME_FUNCTION)malloc(sizeof(RUNTIME_FUNCTION)); -#endif tbl->BeginAddress = (DWORD)(Code - Section); tbl->EndAddress = (DWORD)(Code - Section + Size); tbl->UnwindData = (DWORD)(UnwindData - Section); @@ -170,9 +108,6 @@ static void create_PRUNTIME_FUNCTION(uint8_t *Code, size_t Size, StringRef fnnam assert(!jl_in_stackwalk); jl_in_stackwalk = 1; if (mod_size && !SymLoadModuleEx(GetCurrentProcess(), NULL, NULL, NULL, (DWORD64)Section, mod_size, NULL, SLMFLAG_VIRTUAL)) { -#if defined(_CPU_X86_64_) && !defined(USE_MCJIT) - catchjmp[0] = 0; -#endif static int warned = 0; if (!warned) { jl_printf(JL_STDERR, "WARNING: failed to insert module info for backtrace: %lu\n", GetLastError()); @@ -210,14 +145,12 @@ struct revcomp { { return lhs>rhs; } }; -#if JL_LLVM_VERSION >= 30800 struct strrefcomp { bool operator() (const StringRef& lhs, const StringRef& rhs) const { return lhs.compare(rhs) > 0; } }; -#endif extern "C" tracer_cb jl_linfo_tracer; static std::vector triggered_linfos; @@ -234,61 +167,13 @@ void jl_callback_triggered_linfos(void) class JuliaJITEventListener: public JITEventListener { -#ifndef USE_MCJIT - std::map info; -#else std::map objectmap; std::map, revcomp> linfomap; -#endif public: JuliaJITEventListener(){} virtual ~JuliaJITEventListener() {} -#ifndef USE_MCJIT - virtual void NotifyFunctionEmitted(const Function &F, void *Code, - size_t Size, const EmittedFunctionDetails &Details) - { - jl_ptls_t ptls = jl_get_ptls_states(); - // This function modify linfo->fptr in GC safe region. - // 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); - StringRef sName = F.getName(); - StringMap::iterator linfo_it = linfo_in_flight.find(sName); - jl_method_instance_t *linfo = NULL; - if (linfo_it != linfo_in_flight.end()) { - linfo = linfo_it->second; - linfo_in_flight.erase(linfo_it); - if (!linfo->fptr && linfo->functionObjectsDecls.functionObject && - ((Function*)linfo->functionObjectsDecls.functionObject)->getName().equals(sName)) { - int jlcall_api = jl_jlcall_api(&F); - if (linfo->inferred || jlcall_api != 1) { - linfo->jlcall_api = jlcall_api; - linfo->fptr = (jl_fptr_t)(uintptr_t)Code; - } - else { - linfo->unspecialized_ducttape = (jl_fptr_t)(uintptr_t)Code; - } - } - } -#if defined(_OS_WINDOWS_) - create_PRUNTIME_FUNCTION((uint8_t*)Code, Size, F.getName(), (uint8_t*)Code, Size, NULL); -#endif - FuncInfo tmp = {&F, Size, Details.LineStarts, linfo}; - info[(size_t)(Code)] = tmp; - uv_rwlock_wrunlock(&threadsafe); - jl_gc_safe_leave(ptls, gc_state); - } - - std::map& getMap() - { - uv_rwlock_rdlock(&threadsafe); - return info; - } -#endif // ifndef USE_MCJIT - -#ifdef USE_MCJIT jl_method_instance_t *lookupLinfo(size_t pointer) { auto linfo = linfomap.lower_bound(pointer); @@ -297,7 +182,6 @@ class JuliaJITEventListener: public JITEventListener else return NULL; } -#if JL_LLVM_VERSION >= 30600 virtual void NotifyObjectEmitted(const object::ObjectFile &obj, const RuntimeDyld::LoadedObjectInfo &L) @@ -309,24 +193,15 @@ class JuliaJITEventListener: public JITEventListener const object::ObjectFile &debugObj, const RuntimeDyld::LoadedObjectInfo &L, RTDyldMemoryManager *memmgr) -#else - virtual void NotifyObjectEmitted(const ObjectImage &obj) -#endif { jl_ptls_t ptls = jl_get_ptls_states(); // This function modify linfo->fptr in GC safe region. // 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); -#if JL_LLVM_VERSION >= 30600 object::section_iterator Section = debugObj.section_begin(); object::section_iterator EndSection = debugObj.section_end(); -#else - object::section_iterator Section = debugObj.begin_sections(); - object::section_iterator EndSection = debugObj.end_sections(); -#endif -#if JL_LLVM_VERSION >= 30800 std::map loadedSections; for (const object::SectionRef &lSection: obj.sections()) { StringRef sName; @@ -340,7 +215,6 @@ class JuliaJITEventListener: public JITEventListener return 0; return L.getSectionLoadAddress(search->second); }; -#endif #ifdef _CPU_ARM_ // ARM does not have/use .eh_frame @@ -361,11 +235,7 @@ class JuliaJITEventListener: public JITEventListener continue; } } -#if JL_LLVM_VERSION >= 30800 uint64_t loadaddr = L.getSectionLoadAddress(section); -#else - uint64_t loadaddr = L.getSectionLoadAddress(sName); -#endif size_t seclen = section.getSize(); if (istext) { arm_text_addr = loadaddr; @@ -402,13 +272,9 @@ class JuliaJITEventListener: public JITEventListener uint8_t *catchjmp = NULL; for (const object::SymbolRef &sym_iter : debugObj.symbols()) { StringRef sName; -#if JL_LLVM_VERSION >= 30700 auto sNameOrError = sym_iter.getName(); assert(sNameOrError); sName = sNameOrError.get(); -#else - sym_iter.getName(sName); -#endif uint8_t **pAddr = NULL; if (sName.equals("__UnwindData")) { pAddr = &UnwindData; @@ -418,7 +284,6 @@ class JuliaJITEventListener: public JITEventListener } if (pAddr) { uint64_t Addr, SectionAddr, SectionLoadAddr; -#if JL_LLVM_VERSION >= 30800 auto AddrOrError = sym_iter.getAddress(); assert(AddrOrError); Addr = AddrOrError.get(); @@ -429,42 +294,16 @@ class JuliaJITEventListener: public JITEventListener SectionAddr = Section->getAddress(); Section->getName(sName); SectionLoadAddr = getLoadAddress(sName); -#elif JL_LLVM_VERSION >= 30700 - auto AddrOrError = sym_iter.getAddress(); - assert(AddrOrError); - Addr = AddrOrError.get(); - sym_iter.getSection(Section); - assert(Section != EndSection && Section->isText()); - Section->getName(sName); - SectionAddr = Section->getAddress(); - SectionLoadAddr = L.getSectionLoadAddress(sName); -#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 // JL_LLVM_VERSION >= 30500 - sym_iter.getAddress(Addr); - sym_iter.getSection(Section); - assert(Section != EndSection); - assert(!Section->isText(isText) && isText); - Section->getAddress(SectionAddr); - Section->getAddress(SectionLoadAddr); -#endif Addr -= SectionAddr - SectionLoadAddr; *pAddr = (uint8_t*)Addr; if (SectionAddrCheck) assert(SectionAddrCheck == SectionLoadAddr); else SectionAddrCheck = SectionLoadAddr; -#ifdef USE_ORCJIT if (memmgr) SectionAddr = (uintptr_t)lookupWriteAddressFor(memmgr, (void*)SectionLoadAddr); -#endif if (SectionLoadOffset != 1) assert(SectionLoadOffset == SectionAddr - SectionLoadAddr); else @@ -493,39 +332,26 @@ class JuliaJITEventListener: public JITEventListener #endif // defined(_OS_X86_64_) #endif // defined(_OS_WINDOWS_) -#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; -#if JL_LLVM_VERSION >= 30900 auto SymbolTypeOrError = sym_iter.getType(); assert(SymbolTypeOrError); object::SymbolRef::Type SymbolType = SymbolTypeOrError.get(); -#else - object::SymbolRef::Type SymbolType = sym_iter.getType(); -#endif if (SymbolType != object::SymbolRef::ST_Function) continue; auto AddrOrError = sym_iter.getAddress(); assert(AddrOrError); uint64_t Addr = AddrOrError.get(); -#if JL_LLVM_VERSION >= 30800 auto SectionOrError = sym_iter.getSection(); assert(SectionOrError); Section = SectionOrError.get(); -#else - sym_iter.getSection(Section); -#endif if (Section == EndSection) continue; if (!Section->isText()) continue; uint64_t SectionAddr = Section->getAddress(); StringRef secName; Section->getName(secName); -#if JL_LLVM_VERSION >= 30800 uint64_t SectionLoadAddr = getLoadAddress(secName); -#else - uint64_t SectionLoadAddr = L.getSectionLoadAddress(secName); -#endif Addr -= SectionAddr - SectionLoadAddr; auto sNameOrError = sym_iter.getName(); assert(sNameOrError); @@ -572,109 +398,6 @@ class JuliaJITEventListener: public JITEventListener first = false; } } - -#else // pre-LLVM 3.7 - uint64_t Addr; - uint64_t Size; - object::SymbolRef::Type SymbolType; - StringRef sName; - uint64_t SectionLoadAddr = 0, SectionAddr = 0; -#if JL_LLVM_VERSION < 30600 - bool isText; -#endif - -#if JL_LLVM_VERSION >= 30500 - for (const object::SymbolRef &sym_iter : obj.symbols()) { - sym_iter.getType(SymbolType); - if (SymbolType != object::SymbolRef::ST_Function) continue; - sym_iter.getSize(Size); - sym_iter.getAddress(Addr); - sym_iter.getSection(Section); - if (Section == EndSection) continue; -#if JL_LLVM_VERSION >= 30600 - if (!Section->isText()) continue; - Section->getName(sName); - SectionAddr = Section->getAddress(); - SectionLoadAddr = L.getSectionLoadAddress(sName); - Addr += SectionLoadAddr; -#else - if (Section->isText(isText) || !isText) continue; - Section->getAddress(SectionAddr); - Section->getAddress(SectionLoadAddr); -#endif - sym_iter.getName(sName); -#ifdef _OS_DARWIN_ -# 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); - } - if (!Addr) continue; -# endif -#elif defined(_OS_WINDOWS_) - uint64_t SectionSize = 0; -# if JL_LLVM_VERSION >= 30600 - SectionSize = Section->getSize(); -# else - Section->getSize(SectionSize); -# endif - if (SectionAddrCheck) - assert(SectionAddrCheck == SectionLoadAddr); - else - SectionAddrCheck = SectionLoadAddr; - create_PRUNTIME_FUNCTION( - (uint8_t*)(uintptr_t)Addr, (size_t)Size, sName, - (uint8_t*)(uintptr_t)SectionLoadAddr, (size_t)SectionSize, UnwindData); -#endif - StringMap::iterator linfo_it = linfo_in_flight.find(sName); - jl_method_instance_t *linfo = NULL; - if (linfo_it != linfo_in_flight.end()) { - linfo = linfo_it->second; - linfo_in_flight.erase(linfo_it); - Function *F = (Function*)linfo->functionObjectsDecls.functionObject; - if (!linfo->fptr && F && F->getName().equals(sName)) { - int jlcall_api = jl_jlcall_api(F); - if (linfo->inferred || jlcall_api != 1) { - linfo->jlcall_api = jlcall_api; - linfo->fptr = (jl_fptr_t)(uintptr_t)Addr; - } - else { - linfo->unspecialized_ducttape = (jl_fptr_t)(uintptr_t)Addr; - } - } - } - if (linfo) - linfomap[Addr] = std::make_pair(Size, linfo); - const object::ObjectFile *objfile = -#if JL_LLVM_VERSION >= 30600 - &obj; -#else - obj.getObjectFile(); -#endif - ObjectInfo tmp = {objfile, (size_t)Size, - (ptrdiff_t)(SectionAddr - SectionLoadAddr), -#ifdef _OS_DARWIN_ - strndup(sName.data(), sName.size()), -#endif - linfo - }; - objectmap[Addr] = tmp; - } -#else //JL_LLVM_VERSION >= 30400 - error_code itererr; - object::symbol_iterator sym_iter = obj.begin_symbols(); - object::symbol_iterator sym_end = obj.end_symbols(); - for (; sym_iter != sym_end; sym_iter.increment(itererr)) { - sym_iter->getType(SymbolType); - if (SymbolType != object::SymbolRef::ST_Function) continue; - sym_iter->getAddress(Addr); - sym_iter->getSize(Size); - - ObjectInfo tmp = {obj.getObjectFile(), (size_t)Size}; - objectmap[Addr] = tmp; - } -#endif -#endif uv_rwlock_wrunlock(&threadsafe); jl_gc_safe_leave(ptls, gc_state); } @@ -688,7 +411,6 @@ class JuliaJITEventListener: public JITEventListener uv_rwlock_rdlock(&threadsafe); return objectmap; } -#endif // USE_MCJIT }; #ifdef USE_ORCJIT @@ -769,14 +491,8 @@ static int lookup_pointer(DIContext *context, jl_frame_t **frames, return 1; } jl_mutex_lock_maybe_nogc(&codegen_lock); -#if JL_LLVM_VERSION >= 30500 DILineInfoSpecifier infoSpec(DILineInfoSpecifier::FileLineInfoKind::AbsoluteFilePath, DILineInfoSpecifier::FunctionNameKind::ShortName); -#else - int infoSpec = DILineInfoSpecifier::FileLineInfo | - DILineInfoSpecifier::AbsoluteFilePath | - DILineInfoSpecifier::FunctionName; -#endif auto inlineInfo = context->getInliningInfoForAddress(pointer, infoSpec); @@ -806,11 +522,7 @@ static int lookup_pointer(DIContext *context, jl_frame_t **frames, } jl_frame_t *frame = &(*frames)[i]; -#if JL_LLVM_VERSION < 30500 - std::string func_name(info.getFunctionName()); -#else std::string func_name(info.FunctionName); -#endif if (inlined_frame) { frame->inlined = 1; @@ -831,13 +543,8 @@ static int lookup_pointer(DIContext *context, jl_frame_t **frames, if (!frame->func_name) frame->fromC = 1; -#if JL_LLVM_VERSION < 30500 - frame->line = info.getLine(); - std::string file_name(info.getFileName()); -#else frame->line = info.Line; std::string file_name(info.FileName); -#endif if (file_name == "") frame->file_name = NULL; @@ -867,41 +574,16 @@ static obfiletype objfilemap; static bool getObjUUID(llvm::object::MachOObjectFile *obj, uint8_t uuid[16]) { -# if JL_LLVM_VERSION >= 30700 for (auto Load : obj->load_commands()) -# else -# if JL_LLVM_VERSION >= 30500 - uint32_t LoadCommandCount = obj->getHeader().ncmds; -# else - uint32_t LoadCommandCount = obj->getHeader().NumLoadCommands; -# endif - llvm::object::MachOObjectFile::LoadCommandInfo Load = obj->getFirstLoadCommandInfo(); - for (unsigned I = 0; ; ++I) -# endif { - if ( -# if JL_LLVM_VERSION >= 30500 - Load.C.cmd == LC_UUID -# else - Load.C.Type == LC_UUID -# endif - ) { + if (Load.C.cmd == LC_UUID) { memcpy(uuid, ((const MachO::uuid_command*)Load.Ptr)->uuid, 16); return true; } -# if JL_LLVM_VERSION < 30700 - else if (I == LoadCommandCount - 1) { - return false; - } - else { - Load = obj->getNextLoadCommandInfo(Load); - } -# endif } return false; } -#if JL_LLVM_VERSION >= 30600 struct debug_link_info { StringRef filename; uint32_t crc32; @@ -987,42 +669,26 @@ calc_gnu_debuglink_crc32(const void *buf, size_t size) return crc ^ ~0U; } -#if JL_LLVM_VERSION >= 30900 static Expected> -#else -static ErrorOr> -#endif openDebugInfo(StringRef debuginfopath, const debug_link_info &info) { auto SplitFile = MemoryBuffer::getFile(debuginfopath); if (std::error_code EC = SplitFile.getError()) { -#if JL_LLVM_VERSION >= 30900 return errorCodeToError(EC); -#else - return EC; -#endif } uint32_t crc32 = calc_gnu_debuglink_crc32( SplitFile.get()->getBufferStart(), SplitFile.get()->getBufferSize()); if (crc32 != info.crc32) { -#if JL_LLVM_VERSION >= 30900 return errorCodeToError(object::object_error::arch_not_found); -#else - return object::object_error::arch_not_found; -#endif } auto error_splitobj = object::ObjectFile::createObjectFile( SplitFile.get().get()->getMemBufferRef(), llvm_file_magic::unknown); if (!error_splitobj) { -#if JL_LLVM_VERSION >= 30900 return error_splitobj.takeError(); -#else - return error_splitobj.getError(); -#endif } // successfully validated and loaded split debug info file @@ -1030,7 +696,6 @@ openDebugInfo(StringRef debuginfopath, const debug_link_info &info) std::move(error_splitobj.get()), std::move(SplitFile.get())); } -#endif static uint64_t jl_sysimage_base; static void **sysimg_fvars; @@ -1047,7 +712,7 @@ extern "C" void jl_register_fptrs(uint64_t sysimage_base, void **fptrs, jl_metho template static inline void ignoreError(T &err) { -#if JL_LLVM_VERSION >= 30900 && !defined(NDEBUG) +#if !defined(NDEBUG) // Needed only with LLVM assertion build consumeError(err.takeError()); #endif @@ -1160,12 +825,6 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, #endif (void)iswindows; -#if JL_LLVM_VERSION < 30500 - if (iswindows) { - return true; - } -#endif - // GOAL: Read debuginfo from file // TODO: need read/write lock here for objfilemap synchronization obfiletype::iterator it = objfilemap.find(fbase); @@ -1184,23 +843,10 @@ 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); -#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(), llvm_file_magic::unknown); -#elif JL_LLVM_VERSION >= 30500 - MemoryBuffer *membuf = MemoryBuffer::getMemBuffer( - StringRef((const char *)fbase, msize), "", false); - std::unique_ptr buf(membuf); - auto origerrorobj = llvm::object::ObjectFile::createObjectFile( - buf, llvm_file_magic::unknown); -#else - MemoryBuffer *membuf = MemoryBuffer::getMemBuffer( - StringRef((const char *)fbase, msize), "", false); - std::unique_ptr origerrorobj(llvm::object::ObjectFile::createObjectFile( - membuf)); -#endif if (!origerrorobj) { objfileentry_t entry = {}; objfilemap[fbase] = entry; @@ -1208,11 +854,7 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, } llvm::object::MachOObjectFile *morigobj = (llvm::object::MachOObjectFile*) -#if JL_LLVM_VERSION >= 30600 origerrorobj.get().get(); -#else - origerrorobj.get(); -#endif // First find the uuid of the object file (we'll use this to make sure we find the // correct debug symbol file). @@ -1237,22 +879,13 @@ 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; } -#if JL_LLVM_VERSION >= 30500 auto errorobj = llvm::object::ObjectFile::createObjectFile(objpath); -#else - std::unique_ptr errorobj(llvm::object::ObjectFile::createObjectFile(objpath)); -#endif // GOAL: Assign *obj, *context, *slide (if above succeeded) if (errorobj) { -#if JL_LLVM_VERSION >= 30600 auto *debugobj = errorobj->getBinary(); -#else - auto *debugobj = errorobj.get(); -#endif if (islinux) { -#if JL_LLVM_VERSION >= 30600 // if the file has a .gnu_debuglink section, // try to load its companion file instead // in the expected locations @@ -1260,16 +893,11 @@ 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('/'); -#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 // that can be ignored. ignoreError(DebugInfo); -#else - ErrorOr> - DebugInfo(std::errc::no_such_file_or_directory); -#endif if (fname.substr(sep + 1) != info.filename) { debuginfopath = fname.substr(0, sep + 1); debuginfopath += info.filename; @@ -1299,7 +927,6 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, ignoreError(DebugInfo); } } -#endif } if (isdarwin) { @@ -1314,50 +941,18 @@ bool jl_dylib_DI_for_fptr(size_t pointer, const llvm::object::ObjectFile **obj, if (auto *OF = dyn_cast(debugobj)) { assert(iswindows); -#if JL_LLVM_VERSION >= 30800 *slide = OF->getImageBase() - fbase; *section_slide = 0; // Since LLVM 3.8+ addresses are adjusted correctly -#elif JL_LLVM_VERSION >= 30500 - const llvm::object::pe32plus_header *pe32plus; - OF->getPE32PlusHeader(pe32plus); - if (pe32plus != NULL) { - *slide = pe32plus->ImageBase - fbase; - *section_slide = -(int64_t)pe32plus->ImageBase; - } - else { - const llvm::object::pe32_header *pe32; - OF->getPE32Header(pe32); - if (pe32 == NULL) { - objfileentry_t entry = {}; - objfilemap[fbase] = entry; - return true; - } - else { - *slide = pe32->ImageBase - fbase; - *section_slide = -(int64_t)pe32->ImageBase; - } - } -#endif } else { *slide = -(int64_t)fbase; } -#if JL_LLVM_VERSION >= 30700 *context = new DWARFContextInMemory(*debugobj); -#elif JL_LLVM_VERSION >= 30600 - *context = DIContext::getDWARFContext(*debugobj); -#else - *context = DIContext::getDWARFContext(debugobj); -#endif *obj = debugobj; -#if JL_LLVM_VERSION >= 30600 auto binary = errorobj->takeBinary(); binary.first.release(); binary.second.release(); -#else - errorobj.release(); -#endif } else { // TODO: report the error instead of silently consuming it? @@ -1436,26 +1031,11 @@ static int jl_getDylibFunctionInfo(jl_frame_t **frames, size_t pointer, int skip int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide, int64_t *section_slide, const object::ObjectFile **object, -#ifdef USE_MCJIT llvm::DIContext **context -#else - std::vector *lines -#endif ) { int found = 0; *slide = 0; -#ifndef USE_MCJIT - std::map &fmap = jl_jit_events->getMap(); - std::map::iterator fit = fmap.lower_bound(fptr); - - if (fit != fmap.end() && fptr < fit->first + fit->second.lengthAdr) { - if (symsize) - *symsize = fit->second.lengthAdr; - *lines = fit->second.lines; - found = 1; - } -#else // MCJIT version std::map &objmap = jl_jit_events->getObjectMap(); std::map::iterator fit = objmap.lower_bound(fptr); @@ -1466,20 +1046,14 @@ 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 JL_LLVM_VERSION >= 30700 *context = fit->second.context; -#else - *context = DIContext::getDWARFContext(*fit->second.object); -#endif } found = 1; } -#endif uv_rwlock_rdunlock(&threadsafe); return found; } -#ifdef USE_MCJIT extern "C" JL_DLLEXPORT jl_value_t *jl_get_dobj_data(uint64_t fptr) { @@ -1528,8 +1102,6 @@ JL_DLLEXPORT uint64_t jl_get_section_start(uint64_t fptr) return ret; } -#endif - // Set *name and *filename to either NULL or malloc'd string int jl_getFunctionInfo(jl_frame_t **frames_out, size_t pointer, int skipC, int noInline) { @@ -1540,7 +1112,6 @@ int jl_getFunctionInfo(jl_frame_t **frames_out, size_t pointer, int skipC, int n frames[0].line = -1; *frames_out = frames; -#ifdef USE_MCJIT llvm::DIContext *context; const llvm::object::ObjectFile *object; uint64_t symsize; @@ -1550,112 +1121,15 @@ int jl_getFunctionInfo(jl_frame_t **frames_out, size_t pointer, int skipC, int n int nf = lookup_pointer(context, frames_out, pointer+slide, 1, noInline); return nf; } -#else // !USE_MCJIT -// Without MCJIT we use the FuncInfo structure containing address maps - std::map &info = jl_jit_events->getMap(); - std::map::iterator it = info.lower_bound(pointer); - if (it != info.end() && (uintptr_t)(*it).first + (*it).second.lengthAdr >= pointer) { - // We do this to hide the jlcall wrappers when getting julia backtraces, - // but it is still good to have them for regular lookup of C frames. - if (skipC && (*it).second.lines.empty()) { - // Technically not true, but we don't want them - // in julia backtraces, so close enough - frames[0].fromC = 1; - uv_rwlock_rdunlock(&threadsafe); - return 1; - } - - jl_copy_str(&frames[0].func_name, (*it).second.func->getName().str().c_str()); - jl_copy_str(&frames[0].file_name, ""); - - if ((*it).second.lines.empty()) { - frames[0].fromC = 1; - uv_rwlock_rdunlock(&threadsafe); - return 1; - } - - frames[0].linfo = (*it).second.linfo; - std::vector::iterator vit = - (*it).second.lines.begin(); - JITEvent_EmittedFunctionDetails::LineStart prev = *vit; - LLVMContext &Ctx = (*it).second.func->getContext(); - - DISubprogram debugscope(prev.Loc.getScope(Ctx)); - jl_copy_str(&frames[0].file_name, debugscope.getFilename().str().c_str()); - // The DISubprogram has the un-mangled name, so use that if - // available. However, the scope need not be the current subprogram. - if (debugscope.getName().data() != NULL) { - jl_copy_str(&frames[0].func_name, debugscope.getName().str().c_str()); - } - else { - char *oldname = frames[0].func_name; - std::pair demangled = jl_demangle(oldname); - frames[0].func_name = demangled.first; - frames[0].fromC = !demangled.second; - free(oldname); - } - - // find nearest line info - ++vit; - while (vit != (*it).second.lines.end()) { - if (pointer <= (*vit).Address) { - break; - } - prev = *vit; - ++vit; - } - - // read out inlining and line number information - int n_frames = 1; - if (!noInline) { - MDNode *inlinedAt = prev.Loc.getInlinedAt(Ctx); - while (inlinedAt != NULL) { - DebugLoc inlineloc = DebugLoc::getFromDILocation(inlinedAt); - inlinedAt = inlineloc.getInlinedAt(Ctx); - n_frames++; - } - if (n_frames > 1) { - frames = (jl_frame_t*)calloc(sizeof(jl_frame_t), n_frames); - memcpy(&frames[n_frames - 1], *frames_out, sizeof(jl_frame_t)); - free(*frames_out); - *frames_out = frames; - } - } - DebugLoc inlineloc = prev.Loc; - for (int i = 0; i < n_frames; i++) { - frames[i].inlined = i != n_frames - 1; - frames[i].line = inlineloc.getLine(); - DISubprogram locscope(inlineloc.getScope(Ctx)); - jl_copy_str(&frames[i].file_name, locscope.getFilename().str().c_str()); - jl_copy_str(&frames[i].func_name, locscope.getName().str().c_str()); - MDNode *inlinedAt = inlineloc.getInlinedAt(Ctx); - inlineloc = DebugLoc::getFromDILocation(inlinedAt); - } - - uv_rwlock_rdunlock(&threadsafe); - return n_frames; - } - uv_rwlock_rdunlock(&threadsafe); -#endif // USE_MCJIT return jl_getDylibFunctionInfo(frames_out, pointer, skipC, noInline); } extern "C" jl_method_instance_t *jl_gdblookuplinfo(void *p) { -#ifndef USE_MCJIT - std::map &info = jl_jit_events->getMap(); - std::map::iterator it = info.lower_bound((size_t)p); - jl_method_instance_t *li = NULL; - if (it != info.end() && (uintptr_t)(*it).first + (*it).second.lengthAdr >= (uintptr_t)p) - li = (*it).second.linfo; - uv_rwlock_rdunlock(&threadsafe); - return li; -#else return jl_jit_events->lookupLinfo((size_t)p); -#endif } -#if JL_LLVM_VERSION >= 30700 && (defined(_OS_LINUX_) || (defined(_OS_DARWIN_) && defined(LLVM_SHLIB))) +#if (defined(_OS_LINUX_) || (defined(_OS_DARWIN_) && defined(LLVM_SHLIB))) extern "C" void __register_frame(void*); extern "C" void __deregister_frame(void*); @@ -1682,7 +1156,7 @@ static void processFDEs(const char *EHFrameAddr, size_t EHFrameSize, callback f) } #endif -#if defined(_OS_DARWIN_) && JL_LLVM_VERSION >= 30700 && defined(LLVM_SHLIB) +#if defined(_OS_DARWIN_) && defined(LLVM_SHLIB) /* * We use a custom unwinder, so we need to make sure that when registering dynamic @@ -1722,7 +1196,7 @@ void deregister_eh_frames(uint8_t *Addr, size_t Size) }); } -#elif defined(_OS_LINUX_) && JL_LLVM_VERSION >= 30700 && \ +#elif defined(_OS_LINUX_) && \ defined(JL_UNW_HAS_FORMAT_IP) && !defined(_CPU_ARM_) #include @@ -2064,7 +1538,6 @@ void deregister_eh_frames(uint8_t *Addr, size_t Size) #endif -#ifdef USE_MCJIT extern "C" uint64_t jl_getUnwindInfo(uint64_t dwAddr) { @@ -2078,109 +1551,3 @@ uint64_t jl_getUnwindInfo(uint64_t dwAddr) uv_rwlock_rdunlock(&threadsafe); return ipstart; } -#else -extern "C" -uint64_t jl_getUnwindInfo(uint64_t dwAddr) -{ - // Might be called from unmanaged thread - std::map &info = jl_jit_events->getMap(); - std::map::iterator it = info.lower_bound(dwAddr); - uint64_t ipstart = 0; // ip of the first instruction in the function (if found) - if (it != info.end() && (uintptr_t)(*it).first + (*it).second.lengthAdr > dwAddr) { - ipstart = (uint64_t)(uintptr_t)(*it).first; - } - uv_rwlock_rdunlock(&threadsafe); - return ipstart; -} -#endif - - -#if defined(_OS_WINDOWS_) && !defined(USE_MCJIT) && defined(_CPU_X86_64_) -// Custom memory manager for exception handling on Windows -// we overallocate 48 bytes at the end of each function -// for unwind information (see NotifyFunctionEmitted) -class JITMemoryManagerWin : public JITMemoryManager { -private: - JITMemoryManager *JMM; -public: - JITMemoryManagerWin() : JITMemoryManager() - { - JMM = JITMemoryManager::CreateDefaultMemManager(); - } - virtual void setMemoryWritable() { return JMM->setMemoryWritable(); } - virtual void setMemoryExecutable() { return JMM->setMemoryExecutable(); } - virtual void setPoisonMemory(bool poison) { return JMM->setPoisonMemory(poison); } - virtual void AllocateGOT() { JMM->AllocateGOT(); HasGOT = true; } - virtual uint8_t *getGOTBase() const { return JMM->getGOTBase(); } - virtual uint8_t *startFunctionBody(const Function *F, uintptr_t &ActualSize) - { - if (ActualSize == 0) - ActualSize += 64; - ActualSize += 48; - uint8_t *mem = JMM->startFunctionBody(F,ActualSize); - ActualSize -= 48; - return mem; - } - virtual uint8_t *allocateStub(const GlobalValue *F, unsigned StubSize, unsigned Alignment) - { - return JMM->allocateStub(F,StubSize,Alignment); - } - virtual void endFunctionBody(const Function *F, uint8_t *FunctionStart, uint8_t *FunctionEnd) - { - FunctionEnd[0] = 0; - JMM->endFunctionBody(F,FunctionStart,FunctionEnd+48); - } - virtual uint8_t *allocateSpace(intptr_t Size, unsigned Alignment) { return JMM->allocateSpace(Size,Alignment); } - virtual uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment) { return JMM->allocateGlobal(Size,Alignment); } - virtual void deallocateFunctionBody(void *Body) { return JMM->deallocateFunctionBody(Body); } - virtual uint8_t *startExceptionTable(const Function *F, - uintptr_t &ActualSize) { return JMM->startExceptionTable(F,ActualSize); } - virtual void endExceptionTable(const Function *F, uint8_t *TableStart, - uint8_t *TableEnd, uint8_t *FrameRegister) { return JMM->endExceptionTable(F,TableStart,TableEnd,FrameRegister); } - virtual void deallocateExceptionTable(void *ET) { return JMM->deallocateExceptionTable(ET); } - virtual bool CheckInvariants(std::string &str) { return JMM->CheckInvariants(str); } - virtual size_t GetDefaultCodeSlabSize() { return JMM->GetDefaultCodeSlabSize(); } - virtual size_t GetDefaultDataSlabSize() { return JMM->GetDefaultDataSlabSize(); } - virtual size_t GetDefaultStubSlabSize() { return JMM->GetDefaultStubSlabSize(); } - virtual unsigned GetNumCodeSlabs() { return JMM->GetNumCodeSlabs(); } - virtual unsigned GetNumDataSlabs() { return JMM->GetNumDataSlabs(); } - virtual unsigned GetNumStubSlabs() { return JMM->GetNumStubSlabs(); } - -#if JL_LLVM_VERSION >= 30500 - virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, llvm::StringRef SectionName) - { - uint8_t *mem = JMM->allocateCodeSection(Size+48, Alignment, SectionID, SectionName); - mem[Size] = 0; - return mem; - } - virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, llvm::StringRef SectionName, bool IsReadOnly) - { - return JMM->allocateDataSection(Size,Alignment,SectionID,SectionName,IsReadOnly); - } -#else - virtual uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment, unsigned SectionID) - { - uint8_t *mem = JMM->allocateCodeSection(Size+48, Alignment, SectionID); - mem[Size] = 0; - return mem; - } - virtual uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, - unsigned SectionID, bool IsReadOnly) - { - return JMM->allocateDataSection(Size,Alignment,SectionID,IsReadOnly); - } -#endif - virtual void *getPointerToNamedFunction(const std::string &Name, bool AbortOnFailure = true) - { - return JMM->getPointerToNamedFunction(Name,AbortOnFailure); - } - virtual bool applyPermissions(std::string *ErrMsg = 0) { return JMM->applyPermissions(ErrMsg); } - virtual void registerEHFrames(StringRef SectionData) { return JMM->registerEHFrames(SectionData); } -}; -JITMemoryManager *createJITMemoryManagerWin() -{ - return new JITMemoryManagerWin(); -} -#endif diff --git a/src/disasm.cpp b/src/disasm.cpp index 766f726303fcee..9e75e6ce316314 100644 --- a/src/disasm.cpp +++ b/src/disasm.cpp @@ -49,45 +49,22 @@ #include #include #include -#if JL_LLVM_VERSION >= 30500 -# include -# if JL_LLVM_VERSION >= 30900 -# include -# include -# else -# include -# include -# endif -#else -# include -# include -# include -#endif +#include +#include +#include #include #include -#if JL_LLVM_VERSION < 30600 -#include -#endif #include #include #include #include "llvm/Support/TargetSelect.h" #include #include "llvm/Support/FormattedStream.h" -#if JL_LLVM_VERSION < 30500 -#include -#endif #include #include #include -#if JL_LLVM_VERSION >= 30700 #include "llvm/DebugInfo/DWARF/DWARFContext.h" -#endif -#if JL_LLVM_VERSION >= 30500 #include -#else -#include -#endif #include "fix_llvm_assert.h" #include "julia.h" @@ -98,31 +75,7 @@ using namespace llvm; extern JL_DLLEXPORT LLVMContext &jl_LLVMContext; namespace { -#if JL_LLVM_VERSION >= 30600 #define FuncMCView ArrayRef -#else -class FuncMCView : public MemoryObject { -private: - const char *Fptr; - const size_t Fsize; -public: - FuncMCView(const void *fptr, size_t size) : Fptr((const char*)fptr), Fsize(size) {} - uint64_t getBase() const { return 0; } - uint64_t getExtent() const { return Fsize; } - int readByte(uint64_t Addr, uint8_t *Byte) const { - if (Addr >= getExtent()) - return -1; - *Byte = Fptr[Addr]; - return 0; - } - - // ArrayRef-like accessors: - const char operator[] (const size_t idx) const { return Fptr[idx]; } - uint64_t size() const { return Fsize; } - const uint8_t *data() const { return (const uint8_t*)Fptr; } - FuncMCView slice(unsigned N) const { return FuncMCView(Fptr+N, Fsize-N); } -}; -#endif // Look up a symbol, and return a const char* to its name when the // address matches. We currently just use "L
" as name for the @@ -180,33 +133,16 @@ const char *SymbolTable::lookupLocalPC(size_t addr) { StringRef SymbolTable::getSymbolNameAt(uint64_t offset) const { if (object == NULL) return StringRef(); -#if JL_LLVM_VERSION >= 30700 object::section_iterator ESection = object->section_end(); for (const object::SymbolRef &Sym : object->symbols()) { -#else - llvm::error_code err; - object::section_iterator ESection = object->end_sections(); - for (object::symbol_iterator I = object->begin_symbols(), E = object->end_symbols(); - !err && I != E; I.increment(err)) { - object::SymbolRef Sym = *I; -#endif uint64_t Addr, SAddr; object::section_iterator Sect = ESection; -#if JL_LLVM_VERSION >= 30800 auto SectOrError = Sym.getSection(); assert(SectOrError); Sect = SectOrError.get(); -#else - if (Sym.getSection(Sect)) continue; -#endif if (Sect == ESection) continue; -#if JL_LLVM_VERSION >= 30500 SAddr = Sect->getAddress(); if (SAddr == 0) continue; -#else - if (Sym.getAddress(SAddr) || SAddr == 0) continue; -#endif -#if JL_LLVM_VERSION >= 30700 auto AddrOrError = Sym.getAddress(); assert(AddrOrError); Addr = AddrOrError.get(); @@ -215,14 +151,6 @@ StringRef SymbolTable::getSymbolNameAt(uint64_t offset) const if (sNameOrError) return sNameOrError.get(); } -#else - if (Sym.getAddress(Addr)) continue; - if (Addr == offset) { - StringRef Name; - if (!Sym.getName(Name)) - return Name; - } -#endif } return StringRef(); } @@ -258,13 +186,8 @@ void SymbolTable::createSymbols() name << global; } -#if JL_LLVM_VERSION >= 30700 MCSymbol *symb = Ctx.getOrCreateSymbol(StringRef(name.str())); assert(symb->isUndefined()); -#else - MCSymbol *symb = Ctx.GetOrCreateSymbol(StringRef(name.str())); - symb->setVariableValue(MCConstantExpr::Create(rel, Ctx)); -#endif isymb->second = symb; } } @@ -304,11 +227,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) { -#if JL_LLVM_VERSION >= 30700 *ReferenceType = LLVMDisassembler_ReferenceType_Out_LitPool_SymAddr; -#else - *ReferenceType = LLVMDisassembler_ReferenceType_Out_LitPool_CstrAddr; -#endif *ReferenceName = symbolName; return NULL; } @@ -364,16 +283,9 @@ JL_DLLEXPORT size_t jl_LLVMDisasmInstruction(LLVMDisasmContextRef DC, uint8_t *B } void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, -#ifndef USE_MCJIT - std::vector lineinfo, -#endif const object::ObjectFile *object, DIContext *di_ctx, -#if JL_LLVM_VERSION >= 30700 raw_ostream &rstream, -#else - formatted_raw_ostream &stream, -#endif const char* asm_variant="att" ) { @@ -396,58 +308,24 @@ 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 -#if JL_LLVM_VERSION >= 30500 std::unique_ptr Streamer; -#else - OwningPtr Streamer; -#endif SourceMgr SrcMgr; -#if JL_LLVM_VERSION >= 30500 std::unique_ptr MAI(TheTarget->createMCAsmInfo(*TheTarget->createMCRegInfo(TripleName),TripleName)); -#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!"); -#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!"); -#if JL_LLVM_VERSION >= 30500 std::unique_ptr MOFI(new MCObjectFileInfo()); -#else - OwningPtr MOFI(new MCObjectFileInfo()); -#endif -#if JL_LLVM_VERSION >= 30400 MCContext Ctx(MAI.get(), MRI.get(), MOFI.get(), &SrcMgr); -#else - MCContext Ctx(*MAI, *MRI, MOFI.get(), &SrcMgr); -#endif -#if JL_LLVM_VERSION >= 30900 MOFI->InitMCObjectFileInfo(TheTriple, /* PIC */ false, CodeModel::Default, Ctx); -#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 -#if JL_LLVM_VERSION >= 30500 std::unique_ptr STI(TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString())); std::unique_ptr DisAsm(TheTarget->createMCDisassembler(*STI, Ctx)); -#else - OwningPtr - STI(TheTarget->createMCSubtargetInfo(TripleName, MCPU, Features.getString())); - OwningPtr DisAsm(TheTarget->createMCDisassembler(*STI)); -#endif if (!DisAsm) { jl_printf(JL_STDERR, "ERROR: no disassembler for target %s\n", TripleName.c_str()); @@ -460,75 +338,38 @@ void jl_dump_asm_internal(uintptr_t Fptr, size_t Fsize, int64_t slide, } bool ShowEncoding = false; -#if JL_LLVM_VERSION >= 30500 std::unique_ptr MCII(TheTarget->createMCInstrInfo()); std::unique_ptr MCIA(TheTarget->createMCInstrAnalysis(MCII.get())); -#else - OwningPtr MCII(TheTarget->createMCInstrInfo()); - OwningPtr - MCIA(TheTarget->createMCInstrAnalysis(MCII.get())); -#endif -#if JL_LLVM_VERSION >= 30700 MCInstPrinter *IP = TheTarget->createMCInstPrinter(TheTriple, OutputAsmVariant, *MAI, *MCII, *MRI); -#else - MCInstPrinter *IP = - TheTarget->createMCInstPrinter(OutputAsmVariant, *MAI, *MCII, *MRI, *STI); -#endif //IP->setPrintImmHex(true); // prefer hex or decimal immediates MCCodeEmitter *CE = 0; MCAsmBackend *MAB = 0; if (ShowEncoding) { -#if JL_LLVM_VERSION >= 30700 CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx); -#else - CE = TheTarget->createMCCodeEmitter(*MCII, *MRI, *STI, Ctx); -#endif #if JL_LLVM_VERSION >= 40000 MCTargetOptions Options; MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, MCPU, Options); -#elif JL_LLVM_VERSION >= 30400 - MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, MCPU); #else - MAB = TheTarget->createMCAsmBackend(TripleName, MCPU); + MAB = TheTarget->createMCAsmBackend(*MRI, TripleName, MCPU); #endif } -#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. // LLVM will desctruct the formatted stream, and we keep the raw stream. auto ustream = llvm::make_unique(rstream); Streamer.reset(TheTarget->createAsmStreamer(Ctx, std::move(ustream), /*asmverbose*/true, -#else - Streamer.reset(TheTarget->createAsmStreamer(Ctx, stream, /*asmverbose*/true, -#endif -#if JL_LLVM_VERSION < 30500 - /*useLoc*/ true, - /*useCFI*/ true, -#endif /*useDwarfDirectory*/ true, IP, CE, MAB, /*ShowInst*/ false)); -#if JL_LLVM_VERSION >= 30600 Streamer->InitSections(true); -#else - Streamer->InitSections(); -#endif // Make the MemoryObject wrapper -#if JL_LLVM_VERSION >= 30600 ArrayRef memoryObject(const_cast((const uint8_t*)Fptr),Fsize); -#else - FuncMCView memoryObject((const uint8_t*)Fptr, Fsize); -#endif SymbolTable DisInfo(Ctx, object, slide, memoryObject); -#ifndef USE_MCJIT - typedef std::vector LInfoVec; -#endif - DILineInfoTable di_lineinfo; if (di_ctx) di_lineinfo = di_ctx->getLineInfoForAddressRange(Fptr+slide, Fsize); @@ -545,72 +386,29 @@ 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 -#if JL_LLVM_VERSION >= 30500 DisAsm->setSymbolizer(std::unique_ptr(new MCExternalSymbolizer( Ctx, std::unique_ptr(new MCRelocationInfo(Ctx)), OpInfoLookup, SymbolLookup, &DisInfo))); -#elif JL_LLVM_VERSION >= 30400 - OwningPtr relinfo(new MCRelocationInfo(Ctx)); - DisAsm->setupForSymbolicDisassembly(OpInfoLookup, SymbolLookup, &DisInfo, &Ctx, - relinfo); -#else - DisAsm->setupForSymbolicDisassembly(OpInfoLookup, SymbolLookup, &DisInfo, &Ctx); -#endif } uint64_t nextLineAddr = -1; DILineInfoTable::iterator di_lineIter = di_lineinfo.begin(); DILineInfoTable::iterator di_lineEnd = di_lineinfo.end(); -#ifndef USE_MCJIT - LInfoVec::iterator lineIter = lineinfo.begin(); - LInfoVec::iterator lineEnd = lineinfo.end(); -#endif if (pass != 0) { if (di_ctx) { // Set up the line info if (di_lineIter != di_lineEnd) { -#if JL_LLVM_VERSION >= 30700 std::ostringstream buf; buf << "Filename: " << di_lineIter->second.FileName << "\n"; Streamer->EmitRawText(buf.str()); -#elif JL_LLVM_VERSION >= 30500 - stream << "Filename: " << di_lineIter->second.FileName << "\n"; -#else - stream << "Filename: " << di_lineIter->second.getFileName() << "\n"; -#endif -#if JL_LLVM_VERSION >= 30500 if (di_lineIter->second.Line <= 0) -#else - if (di_lineIter->second.getLine() <= 0) -#endif ++di_lineIter; nextLineAddr = di_lineIter->first; } } -#ifndef USE_MCJIT - else { - // Set up the line info - if (lineIter != lineEnd) { - DebugLoc Loc = (*lineIter).Loc; - MDNode *outer = Loc.getInlinedAt(jl_LLVMContext); - while (outer) { - Loc = DebugLoc::getFromDILocation(outer); - outer = Loc.getInlinedAt(jl_LLVMContext); - } - StringRef FileName; - DISubprogram debugscope = DISubprogram(Loc.getScope(jl_LLVMContext)); - stream << "Filename: " << debugscope.getFilename() << "\n"; - if (Loc.getLine() > 0) - stream << "Source line: " << Loc.getLine() << "\n"; -#if JL_LLVM_VERSION >= 30500 - nextLineAddr = (*lineIter).Address; -#endif - } - } -#endif } uint64_t Index = 0; @@ -621,45 +419,21 @@ 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) { -#if JL_LLVM_VERSION >= 30700 std::ostringstream buf; buf << "Source line: " << di_lineIter->second.Line << "\n"; Streamer->EmitRawText(buf.str()); -#elif JL_LLVM_VERSION >= 30500 - stream << "Source line: " << di_lineIter->second.Line << "\n"; -#else - stream << "Source line: " << di_lineIter->second.getLine() << "\n"; -#endif nextLineAddr = (++di_lineIter)->first; } -#ifndef USE_MCJIT - else { - DebugLoc Loc = (*lineIter).Loc; - MDNode *outer = Loc.getInlinedAt(jl_LLVMContext); - while (outer) { - Loc = DebugLoc::getFromDILocation(outer); - outer = Loc.getInlinedAt(jl_LLVMContext); - } - stream << "Source line: " << Loc.getLine() << "\n"; - nextLineAddr = (*++lineIter).Address; - } -#endif } DisInfo.setIP(Fptr+Index); if (pass != 0) { // Uncomment this to output addresses for all instructions // stream << Index << ": "; -#if JL_LLVM_VERSION >= 30700 MCSymbol *symbol = DisInfo.lookupSymbol(Fptr+Index); if (symbol) Streamer->EmitLabel(symbol); // emitInstructionAnnot -#else - const char *symbolName = DisInfo.lookupSymbolName(Fptr + Index, true); - if (symbolName) - stream << symbolName << ":"; -#endif } MCInst Inst; @@ -703,21 +477,13 @@ 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; -#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) -#endif DisInfo.insertAddress(addr); } } else { // Pass 1: Output instruction -#if JL_LLVM_VERSION >= 30500 Streamer->EmitInstruction(Inst, *STI); -#else - Streamer->EmitInstruction(Inst); -#endif } break; } diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index 3b41b41438b2cb..26dfac6977fd84 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -8,19 +8,11 @@ // analysis passes #include -#if JL_LLVM_VERSION >= 30800 #include #include -#endif -#if JL_LLVM_VERSION >= 30700 #include #include -#endif -#if JL_LLVM_VERSION >= 30500 #include -#else -#include -#endif #if defined(USE_POLLY) #include #include @@ -35,9 +27,7 @@ #include #include #include -#if JL_LLVM_VERSION >= 30900 #include -#endif #if JL_LLVM_VERSION >= 40000 #include #endif @@ -51,9 +41,7 @@ namespace llvm { #else # include #endif -#if JL_LLVM_VERSION >= 30500 #include -#endif #include #include @@ -63,9 +51,6 @@ namespace llvm { // target support #include #include -#if JL_LLVM_VERSION < 30700 -#include -#endif #include #include @@ -82,9 +67,7 @@ using namespace llvm; #include "julia.h" #include "julia_internal.h" #include "jitlayers.h" -#ifdef USE_MCJIT RTDyldMemoryManager* createRTDyldMemoryManager(void); -#endif static Type *T_void; static IntegerType *T_uint32; @@ -110,11 +93,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 -#if JL_LLVM_VERSION >= 30700 void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level) -#else -void addOptimizationPasses(PassManager *PM, int opt_level) -#endif { #ifdef JL_DEBUG_BUILD PM->add(createGCInvariantVerifierPass(true)); @@ -122,10 +101,6 @@ void addOptimizationPasses(PassManager *PM, int opt_level) #endif #if defined(JL_ASAN_ENABLED) -# 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 PM->add(createAddressSanitizerFunctionPass()); #endif #if defined(JL_MSAN_ENABLED) @@ -157,22 +132,10 @@ void addOptimizationPasses(PassManager *PM, int opt_level) return; } PM->add(createPropagateJuliaAddrspaces()); -#if JL_LLVM_VERSION >= 30700 PM->add(createTargetTransformInfoWrapperPass(jl_TargetMachine->getTargetIRAnalysis())); -#else - jl_TargetMachine->addAnalysisPasses(*PM); -#endif -#if JL_LLVM_VERSION >= 30800 PM->add(createTypeBasedAAWrapperPass()); -#else - PM->add(createTypeBasedAliasAnalysisPass()); -#endif if (jl_options.opt_level >= 3) { -#if JL_LLVM_VERSION >= 30800 PM->add(createBasicAAWrapperPass()); -#else - PM->add(createBasicAliasAnalysisPass()); -#endif } // list of passes from vmkit PM->add(createCFGSimplificationPass()); // Clean up disgusting code @@ -198,22 +161,16 @@ void addOptimizationPasses(PassManager *PM, int opt_level) PM->add(createAlwaysInlinerPass()); // Respect always_inline #endif -#ifndef INSTCOMBINE_BUG PM->add(createInstructionCombiningPass()); // Cleanup for scalarrepl. -#endif // Let the InstCombine pass remove the unnecessary load of // safepoint address first PM->add(createSROAPass()); // Break up aggregate allocas -#ifndef INSTCOMBINE_BUG PM->add(createInstructionCombiningPass()); // Cleanup for scalarrepl. -#endif PM->add(createJumpThreadingPass()); // Thread jumps. // NOTE: CFG simp passes after this point seem to hurt native codegen. // See issue #6112. Should be re-evaluated when we switch to MCJIT. //PM->add(createCFGSimplificationPass()); // Merge & remove BBs -#ifndef INSTCOMBINE_BUG PM->add(createInstructionCombiningPass()); // Combine silly seq's -#endif //PM->add(createCFGSimplificationPass()); // Merge & remove BBs PM->add(createReassociatePass()); // Reassociate expressions @@ -239,24 +196,13 @@ void addOptimizationPasses(PassManager *PM, int opt_level) PM->add(createLICMPass()); // Hoist loop invariants PM->add(createLoopUnswitchPass()); // Unswitch loops. // Subsequent passes not stripping metadata from terminator -#ifndef INSTCOMBINE_BUG PM->add(createInstructionCombiningPass()); -#endif PM->add(createIndVarSimplifyPass()); // Canonicalize indvars PM->add(createLoopDeletionPass()); // Delete dead loops -#if JL_LLVM_VERSION >= 30500 PM->add(createSimpleLoopUnrollPass()); // Unroll small loops -#else - PM->add(createLoopUnrollPass()); // Unroll small loops -#endif -#if JL_LLVM_VERSION < 30500 && !defined(INSTCOMBINE_BUG) - PM->add(createLoopVectorizePass()); // Vectorize loops -#endif //PM->add(createLoopStrengthReducePass()); // (jwb added) -#ifndef INSTCOMBINE_BUG PM->add(createInstructionCombiningPass()); // Clean up after the unroller -#endif PM->add(createGVNPass()); // Remove redundancies PM->add(createMemCpyOptPass()); // Remove memcpy / form memset PM->add(createSCCPPass()); // Constant prop with SCCP @@ -265,9 +211,7 @@ void addOptimizationPasses(PassManager *PM, int opt_level) // opened up by them. PM->add(createSinkingPass()); ////////////// **** PM->add(createInstructionSimplifierPass());///////// **** -#ifndef INSTCOMBINE_BUG PM->add(createInstructionCombiningPass()); -#endif PM->add(createJumpThreadingPass()); // Thread jumps PM->add(createDeadStoreEliminationPass()); // Delete dead stores @@ -279,19 +223,15 @@ void addOptimizationPasses(PassManager *PM, int opt_level) PM->add(createLoopDeletionPass()); // Delete dead loops PM->add(createJumpThreadingPass()); // Thread jumps -#if JL_LLVM_VERSION >= 30500 if (jl_options.opt_level >= 3) { PM->add(createSLPVectorizerPass()); // Vectorize straight-line code } -#endif PM->add(createAggressiveDCEPass()); // Delete dead instructions -#if JL_LLVM_VERSION >= 30500 if (jl_options.opt_level >= 3) PM->add(createInstructionCombiningPass()); // Clean up after SLP loop vectorizer PM->add(createLoopVectorizePass()); // Vectorize loops PM->add(createInstructionCombiningPass()); // Clean up after loop vectorizer -#endif // LowerPTLS removes an indirect call. As a result, it is likely to trigger // LLVM's devirtualization heuristics, which would result in the entire // pass pipeline being re-exectuted. Prevent this by inserting a barrier. @@ -304,13 +244,6 @@ void addOptimizationPasses(PassManager *PM, int opt_level) #endif } -#ifdef USE_ORCJIT - -#if JL_LLVM_VERSION < 30800 -void notifyObjectLoaded(RTDyldMemoryManager *memmgr, - llvm::orc::ObjectLinkingLayerBase::ObjSetHandleT H); -#endif - // ------------------------ TEMPORARILY COPIED FROM LLVM ----------------- // This must be kept in sync with gdb/gdb/jit.h . extern "C" { @@ -410,17 +343,10 @@ template void JuliaOJIT::DebugObjectRegistrar::operator()(RTDyldObjectLinkingLayerBase::ObjSetHandleT H, const ObjSetT &Objects, const LoadResult &LOS) { -#if JL_LLVM_VERSION < 30800 - notifyObjectLoaded(JIT.MemMgr, H); -#endif auto oit = Objects.begin(); auto lit = LOS.begin(); for (; oit != Objects.end(); ++oit, ++lit) { -#if JL_LLVM_VERSION >= 30900 const auto &Object = (*oit)->getBinary(); -#else - auto &Object = *oit; -#endif auto &LO = *lit; OwningBinary SavedObject = LO->getObjectForDebug(*Object); @@ -509,17 +435,12 @@ JuliaOJIT::JuliaOJIT(TargetMachine &TM) #else M.dump(); #endif -#if JL_LLVM_VERSION >= 30900 std::string Buf; raw_string_ostream OS(Buf); logAllUnhandledErrors(Obj.takeError(), OS, ""); OS.flush(); llvm::report_fatal_error("FATAL: Unable to compile LLVM Module: '" + Buf + "'\n" "The module's content was printed above. Please file a bug report"); -#else - llvm::report_fatal_error("FATAL: Unable to compile LLVM Module.\n" - "The module's content was printed above. Please file a bug report"); -#endif } return OwningObj(std::move(*Obj), std::move(ObjBuffer)); @@ -691,9 +612,6 @@ std::string JuliaOJIT::getMangledName(const GlobalValue *GV) } JuliaOJIT *jl_ExecutionEngine; -#else -ExecutionEngine *jl_ExecutionEngine; -#endif // MSVC's link.exe requires each function declaration to have a Comdat section // So rather than litter the code with conditionals, @@ -703,7 +621,7 @@ ExecutionEngine *jl_ExecutionEngine; template // for GlobalObject's static T *addComdat(T *G) { -#if defined(_OS_WINDOWS_) && JL_LLVM_VERSION >= 30500 +#if defined(_OS_WINDOWS_) if (imaging_mode && !G->isDeclaration()) { // Add comdat information to make MSVC link.exe happy // it's valid to emit this for ld.exe too, @@ -809,15 +727,9 @@ 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"); -#if JL_LLVM_VERSION >= 30500 for (NamedMDNode::op_iterator I = sNMD->op_begin(), E = sNMD->op_end(); I != E; ++I) { dNMD->addOperand(*I); } -#else - for (unsigned i = 0, l = sNMD->getNumOperands(); i < l; i++) { - dNMD->addOperand(sNMD->getOperand(i)); - } -#endif } } @@ -827,10 +739,9 @@ static void jl_merge_module(Module *dest, std::unique_ptr src) static StringMap module_for_fname; 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_) && JL_LLVM_VERSION >= 30500 +#if defined(_CPU_X86_64_) && defined(_OS_WINDOWS_) // 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, @@ -841,11 +752,7 @@ static void jl_add_to_ee(std::unique_ptr m) ConstantAggregateZero::get(atype), "__catchjmp"))->setSection(".text"); #endif assert(jl_ExecutionEngine); -#if JL_LLVM_VERSION >= 30600 jl_ExecutionEngine->addModule(std::move(m)); -#else - jl_ExecutionEngine->addModule(m.release()); -#endif } void jl_finalize_function(Function *F) @@ -856,21 +763,6 @@ void jl_finalize_function(Function *F) jl_add_to_ee(std::move(m)); } } -#else -static bool jl_try_finalize(Module *m) -{ - for (Module::iterator I = m->begin(), E = m->end(); I != E; ++I) { - Function *F = &*I; - if (F->isDeclaration() && !isIntrinsicFunction(F)) { - if (!jl_can_finalize_function(F)) - return false; - } - } - jl_merge_recursive(m, shadow_output); - jl_merge_module(shadow_output, std::unique_ptr(m)); - return true; -} -#endif static void jl_finalize_function(const std::string &F, Module *collector) { @@ -909,11 +801,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); -#if JL_LLVM_VERSION >= 30500 if (M && known.insert(M).second) -#else - if (M && known.insert(M)) -#endif { for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I) { Function *F = &*I; @@ -954,47 +842,22 @@ void jl_finalize_module(Module *m, bool shadow) module_for_fname[F->getName()] = m; } } -#if defined(USE_ORCJIT) || defined(USE_MCJIT) // in the newer JITs, the shadow module is separate from the execution module if (shadow) jl_add_to_shadow(m); -#else - bool changes = jl_try_finalize(m); - while (changes) { - // this definitely isn't the most efficient, but it's only for the old LLVM 3.3 JIT - changes = false; - for (StringMap::iterator MI = module_for_fname.begin(), ME = module_for_fname.end(); MI != ME; ++MI) { - changes |= jl_try_finalize(MI->second); - } - } -#endif } // 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) -#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) -#endif { #ifdef _OS_WINDOWS_ // setting JL_DLLEXPORT correctly only matters when building a binary // (global_proto will strip this from the JIT) if (dllimport && imaging_mode) { assert(gv->getLinkage() == GlobalValue::ExternalLinkage); -#if JL_LLVM_VERSION >= 30500 // add the __declspec(dllimport) attribute gv->setDLLStorageClass(GlobalValue::DLLImportStorageClass); -#else - gv->setLinkage(GlobalValue::DLLImportLinkage); -#if defined(_P64) - // __imp_ variables are indirection pointers, so use malloc to simulate that - void **imp_addr = (void**)malloc(sizeof(void*)); - *imp_addr = addr; - addr = (void*)imp_addr; -#endif -#endif } #endif // _OS_WINDOWS_ @@ -1020,9 +883,7 @@ void* jl_emit_and_add_to_shadow(GlobalVariable *gv, void *gvarinit) PointerType *T = cast(gv->getType()->getElementType()); // pointer is the only supported type here GlobalVariable *shadowvar = NULL; -#if defined(USE_MCJIT) || defined(USE_ORCJIT) if (imaging_mode) -#endif shadowvar = global_proto(gv, shadow_output); if (shadowvar) { @@ -1040,13 +901,9 @@ void* jl_emit_and_add_to_shadow(GlobalVariable *gv, void *gvarinit) } // make the pointer valid for this session -#if defined(USE_MCJIT) || defined(USE_ORCJIT) void *slot = calloc(1, sizeof(void*)); jl_ExecutionEngine->addGlobalMapping(gv, slot); return slot; -#else - return jl_ExecutionEngine->getPointerToGlobal(shadowvar); -#endif } // Emit a slot in the system image to be filled at sysimg init time. @@ -1065,13 +922,8 @@ GlobalVariable *jl_emit_sysimg_slot(Module *m, Type *typ, const char *name, Constant::getNullValue(typ), name); addComdat(gv); // make the pointer valid for this session -#if defined(USE_MCJIT) || defined(USE_ORCJIT) auto p = new uintptr_t(init); jl_ExecutionEngine->addGlobalMapping(gv, (void*)p); -#else - uintptr_t *p = (uintptr_t*)jl_ExecutionEngine->getPointerToGlobal(gv); - *p = init; -#endif jl_sysimg_gvars.push_back(ConstantExpr::getBitCast(gv, T_psize)); idx = jl_sysimg_gvars.size(); return gv; @@ -1079,18 +931,12 @@ GlobalVariable *jl_emit_sysimg_slot(Module *m, Type *typ, const char *name, void* jl_get_globalvar(GlobalVariable *gv) { -#if defined(USE_MCJIT) || defined(USE_ORCJIT) void *p = (void*)(intptr_t)jl_ExecutionEngine->getPointerToGlobalIfAvailable(gv); -#else - void *p = jl_ExecutionEngine->getPointerToGlobal( - shadow_output->getNamedValue(gv->getName())); -#endif assert(p); return p; } // clones the contents of the module `m` to the shadow_output collector -#if defined(USE_MCJIT) || defined(USE_ORCJIT) void jl_add_to_shadow(Module *m) { #ifndef KEEP_BODIES @@ -1108,7 +954,6 @@ void jl_add_to_shadow(Module *m) } jl_merge_module(shadow_output, std::move(clone)); } -#endif #ifdef HAVE_CPUID extern "C" { @@ -1213,23 +1058,11 @@ void jl_dump_native(const char *bc_fname, const char *unopt_bc_fname, const char 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_) -#if JL_LLVM_VERSION >= 30500 TheTriple.setObjectFormat(Triple::COFF); -#else - TheTriple.setEnvironment(Triple::UnknownEnvironment); -#endif #elif defined(_OS_DARWIN_) -#if JL_LLVM_VERSION >= 30500 TheTriple.setObjectFormat(Triple::MachO); -#else - TheTriple.setEnvironment(Triple::MachO); -#endif #endif -#if JL_LLVM_VERSION >= 30500 std::unique_ptr -#else - OwningPtr -#endif TM(jl_TargetMachine->getTarget().createTargetMachine( TheTriple.getTriple(), jl_TargetMachine->getTargetCPU(), @@ -1237,72 +1070,33 @@ void jl_dump_native(const char *bc_fname, const char *unopt_bc_fname, const char jl_TargetMachine->Options, #if defined(_OS_LINUX_) || defined(_OS_FREEBSD_) Reloc::PIC_, -#elif JL_LLVM_VERSION >= 30900 - Optional(), #else - Reloc::Default, + Optional(), #endif CodeModel::Default, CodeGenOpt::Aggressive // -O3 TODO: respect command -O0 flag? )); -#if JL_LLVM_VERSION >= 30700 legacy::PassManager PM; -#else - PassManager PM; -#endif -#if JL_LLVM_VERSION < 30700 - PM.add(new TargetLibraryInfo(Triple(TM->getTargetTriple()))); -#else PM.add(new TargetLibraryInfoWrapperPass(Triple(TM->getTargetTriple()))); -#endif - // set up optimization passes -#if JL_LLVM_VERSION >= 30700 - // No DataLayout pass needed anymore. -#elif JL_LLVM_VERSION >= 30600 - PM.add(new DataLayoutPass()); -#elif JL_LLVM_VERSION >= 30500 - PM.add(new DataLayoutPass(*jl_ExecutionEngine->getDataLayout())); -#else - PM.add(new DataLayout(*jl_ExecutionEngine->getDataLayout())); -#endif - std::unique_ptr unopt_bc_OS; std::unique_ptr bc_OS; std::unique_ptr obj_OS; -#if JL_LLVM_VERSION >= 30700 // 3.7 simplified formatted output; just use the raw stream alone - std::unique_ptr &unopt_bc_FOS = unopt_bc_OS; - std::unique_ptr &bc_FOS = bc_OS; - std::unique_ptr &obj_FOS = obj_OS; -#else - std::unique_ptr unopt_bc_FOS; - std::unique_ptr bc_FOS; - std::unique_ptr obj_FOS; -#endif - if (unopt_bc_fname) { -#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(unopt_bc_fname, FD, sys::fs::F_None); - unopt_bc_FOS.reset(new raw_fd_ostream(FD, true)); + unopt_bc_OS.reset(new raw_fd_ostream(FD, true)); std::string err; if (EC) err = "ERROR: failed to open --output-unopt-bc file '" + std::string(unopt_bc_fname) + "': " + EC.message(); -#else - std::string err; - unopt_bc_OS.reset(new raw_fd_ostream(unopt_bc_fname, err, raw_fd_ostream::F_Binary)); -#endif if (!err.empty()) jl_safe_printf("%s\n", err.c_str()); else { -#if JL_LLVM_VERSION < 30700 - unopt_bc_FOS.reset(new formatted_raw_ostream(*unopt_bc_OS.get())); -#endif - PM.add(createBitcodeWriterPass(*unopt_bc_FOS.get())); + PM.add(createBitcodeWriterPass(*unopt_bc_OS.get())); } } @@ -1310,7 +1104,6 @@ void jl_dump_native(const char *bc_fname, const char *unopt_bc_fname, const char addOptimizationPasses(&PM, jl_options.opt_level); if (bc_fname) { -#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); @@ -1318,22 +1111,14 @@ void jl_dump_native(const char *bc_fname, const char *unopt_bc_fname, const char std::string err; if (EC) err = "ERROR: failed to open --output-bc file '" + std::string(bc_fname) + "': " + EC.message(); -#else - std::string err; - bc_OS.reset(new raw_fd_ostream(bc_fname, err, raw_fd_ostream::F_Binary)); -#endif if (!err.empty()) jl_safe_printf("%s\n", err.c_str()); else { -#if JL_LLVM_VERSION < 30700 - bc_FOS.reset(new formatted_raw_ostream(*bc_OS.get())); -#endif - PM.add(createBitcodeWriterPass(*bc_FOS.get())); + PM.add(createBitcodeWriterPass(*bc_OS.get())); } } if (obj_fname) { -#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); @@ -1341,42 +1126,26 @@ void jl_dump_native(const char *bc_fname, const char *unopt_bc_fname, const char std::string err; if (EC) err = "ERROR: failed to open --output-o file '" + std::string(obj_fname) + "': " + EC.message(); -#else - std::string err; - obj_OS.reset(new raw_fd_ostream(obj_fname, err, raw_fd_ostream::F_Binary)); -#endif if (!err.empty()) jl_safe_printf("%s\n", err.c_str()); else { -#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)) { + if (TM->addPassesToEmitFile(PM, *obj_OS.get(), TargetMachine::CGFT_ObjectFile, false)) { jl_safe_printf("ERROR: target does not support generation of object files\n"); } } } ValueToValueMapTy VMap; -#if defined(USE_MCJIT) || defined(USE_ORCJIT) - // now copy the module (if using the old JIT), since PM.run may modify it Module *clone = shadow_output; -#else - Module *clone = CloneModule(shadow_output, VMap); -#endif -#if JL_LLVM_VERSION >= 30700 // Reset the target triple to make sure it matches the new target machine clone->setTargetTriple(TM->getTargetTriple().str()); #if JL_LLVM_VERSION >= 40000 DataLayout DL = TM->createDataLayout(); DL.reset(DL.getStringRepresentation() + "-ni:10:11:12"); clone->setDataLayout(DL); -#elif JL_LLVM_VERSION >= 30800 - clone->setDataLayout(TM->createDataLayout()); #else - clone->setDataLayout(TM->getDataLayout()->getStringRepresentation()); -#endif + clone->setDataLayout(TM->createDataLayout()); #endif // add metadata information @@ -1384,9 +1153,6 @@ void jl_dump_native(const char *bc_fname, const char *unopt_bc_fname, const char // do the actual work PM.run(*clone); -#if !defined(USE_MCJIT) && !defined(USE_ORCJIT) - delete clone; -#endif imaging_mode = false; } diff --git a/src/jitlayers.h b/src/jitlayers.h index 78f4147aff6a4b..407ca9021cd12a 100644 --- a/src/jitlayers.h +++ b/src/jitlayers.h @@ -17,29 +17,16 @@ # include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" #endif #include "llvm/ExecutionEngine/ObjectMemoryBuffer.h" -#elif defined(USE_MCJIT) +#else #include #include #include -#else -#include -#include -#include -#include -#include #endif -#if JL_LLVM_VERSION >= 30700 #include "llvm/IR/LegacyPassManager.h" extern legacy::PassManager *jl_globalPM; -#else -#include -extern PassManager *jl_globalPM; -#endif -#if JL_LLVM_VERSION >= 30500 #include -#endif #include "fix_llvm_assert.h" extern "C" { @@ -60,11 +47,7 @@ extern size_t jltls_offset_idx; typedef struct {Value *gv; int32_t index;} jl_value_llvm; // uses 1-based indexing -#if JL_LLVM_VERSION >= 30700 void addOptimizationPasses(legacy::PassManagerBase *PM, int opt_level); -#else -void addOptimizationPasses(PassManager *PM, int opt_level); -#endif void* jl_emit_and_add_to_shadow(GlobalVariable *gv, void *gvarinit = NULL); GlobalVariable *jl_emit_sysimg_slot(Module *m, Type *typ, const char *name, uintptr_t init, size_t &idx); @@ -84,11 +67,9 @@ static inline GlobalVariable *global_proto(GlobalVariable *G, Module *M = NULL) G->isConstant(), GlobalVariable::ExternalLinkage, NULL, G->getName(), G->getThreadLocalMode()); proto->copyAttributesFrom(G); -#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); -#endif if (M) M->getGlobalList().push_back(proto); return proto; @@ -106,28 +87,22 @@ 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. -#if JL_LLVM_VERSION >= 30700 llvm::Constant *OldPersonalityFn = nullptr; if (F->hasPersonalityFn()) { OldPersonalityFn = F->getPersonalityFn(); F->setPersonalityFn(nullptr); } -#endif // FunctionType does not include any attributes. Copy them over manually // as codegen may make decisions based on the presence of certain attributes NewF->copyAttributesFrom(F); -#if JL_LLVM_VERSION >= 30700 if (OldPersonalityFn) F->setPersonalityFn(OldPersonalityFn); -#endif -#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); -#endif return NewF; } @@ -143,15 +118,9 @@ static inline GlobalVariable *prepare_global(GlobalVariable *G, Module *M) return cast(local); } -#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) -#else -void add_named_global(GlobalValue *gv, void *addr, bool dllimport); -template -static inline void add_named_global(GlobalValue *gv, T *addr, bool dllimport = true) -#endif { // cast through integer to avoid c++ pedantic warning about casting between // data and code pointers @@ -240,11 +209,7 @@ extern JuliaOJIT *jl_ExecutionEngine; #else extern ExecutionEngine *jl_ExecutionEngine; #endif -#if JL_LLVM_VERSION >= 30900 JL_DLLEXPORT extern LLVMContext jl_LLVMContext; -#else -JL_DLLEXPORT extern LLVMContext &jl_LLVMContext; -#endif Pass *createLowerPTLSPass(bool imaging_mode); Pass *createLateLowerGCFramePass(); diff --git a/src/llvm-ptls.cpp b/src/llvm-ptls.cpp index b8b6584c09a0ed..8ac71da16abf40 100644 --- a/src/llvm-ptls.cpp +++ b/src/llvm-ptls.cpp @@ -15,14 +15,10 @@ #include #include #include -#if JL_LLVM_VERSION >= 30700 #include -#else -#include -#endif #include -#if JL_LLVM_VERSION >= 30700 && defined(JULIA_ENABLE_THREADING) +#if defined(JULIA_ENABLE_THREADING) # include # include #endif @@ -63,12 +59,8 @@ 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) { -#if JL_LLVM_VERSION >= 30500 // add the __declspec(dllimport) attribute proto->setDLLStorageClass(GlobalValue::DLLImportStorageClass); -#else - proto->setLinkage(GlobalValue::DLLImportLinkage); -#endif } #else // _OS_WINDOWS_ (void)proto; @@ -87,7 +79,6 @@ static void setCallPtlsAttrs(CallInst *ptlsStates) #endif } -#if JL_LLVM_VERSION >= 30700 static Instruction *emit_ptls_tp(LLVMContext &ctx, Value *offset, Type *T_ppjlvalue, Instruction *insertBefore) { @@ -153,7 +144,6 @@ static Instruction *emit_ptls_tp(LLVMContext &ctx, Value *offset, Type *T_ppjlva return nullptr; # endif } -#endif #endif @@ -182,7 +172,6 @@ void LowerPTLS::runOnFunction(LLVMContext &ctx, Module &M, Function *F, if (imaging_mode) { GlobalVariable *GV = cast( M.getNamedValue("jl_get_ptls_states.ptr")); -#if JL_LLVM_VERSION >= 30700 if (jl_tls_elf_support) { GlobalVariable *OffsetGV = cast( M.getNamedValue("jl_tls_offset.val")); @@ -215,18 +204,15 @@ void LowerPTLS::runOnFunction(LLVMContext &ctx, Module &M, Function *F, return; } -#endif auto getter = new LoadInst(GV, "", ptlsStates); getter->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const); ptlsStates->setCalledFunction(getter); setCallPtlsAttrs(ptlsStates); } -#if JL_LLVM_VERSION >= 30700 else if (jl_tls_offset != -1) { ptlsStates->replaceAllUsesWith(emit_ptls_tp(ctx, nullptr, T_ppjlvalue, ptlsStates)); ptlsStates->eraseFromParent(); } -#endif else { setCallPtlsAttrs(ptlsStates); } diff --git a/src/llvm-simdloop.cpp b/src/llvm-simdloop.cpp index 58da4b57163a82..72dbe86ee6bebd 100644 --- a/src/llvm-simdloop.cpp +++ b/src/llvm-simdloop.cpp @@ -32,11 +32,7 @@ bool annotateSimdLoop(BasicBlock *incr) // Lazy initialization if (!simd_loop_mdkind) { simd_loop_mdkind = incr->getContext().getMDKindID("simd_loop"); -#if JL_LLVM_VERSION >= 30600 simd_loop_md = MDNode::get(incr->getContext(), ArrayRef()); -#else - simd_loop_md = MDNode::get(incr->getContext(), ArrayRef()); -#endif } // Ideally, the decoration would go on the block itself, but LLVM 3.3 does not // support putting metadata on blocks. So instead, put the decoration on the last @@ -118,13 +114,8 @@ 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. -#if JL_LLVM_VERSION >= 30500 for (User *UI : I->users()) { /*}*/ Instruction *U = cast(UI); -#else - for (Value::use_iterator UI = I->use_begin(), UE = I->use_end(); UI != UE; ++UI) { - Instruction *U = cast(*UI); -#endif if (L->contains(U)) { if (J) { DEBUG(dbgs() << "LSL: not a reduction var because op has two internal uses: " << *I << "\n"); @@ -168,11 +159,7 @@ bool LowerSIMDLoop::runOnLoop(Loop *L, LPPassManager &LPM) { if (!simd_loop_mdkind) { simd_loop_mdkind = L->getHeader()->getContext().getMDKindID("simd_loop"); -#if JL_LLVM_VERSION >= 30600 simd_loop_md = MDNode::get(L->getHeader()->getContext(), ArrayRef()); -#else - simd_loop_md = MDNode::get(L->getHeader()->getContext(), ArrayRef()); -#endif } if (!hasSIMDLoopMetadata(L)) @@ -181,27 +168,14 @@ 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"); -#if JL_LLVM_VERSION >= 30400 MDNode *n = L->getLoopID(); if (!n) { // Loop does not have a LoopID yet, so give it one. -#if JL_LLVM_VERSION >= 30600 n = MDNode::get(Lh->getContext(), ArrayRef(NULL)); -#else - n = MDNode::get(Lh->getContext(), ArrayRef(NULL)); -#endif n->replaceOperandWith(0,n); L->setLoopID(n); } -#else - MDNode *n = MDNode::get(Lh->getContext(), ArrayRef()); - L->getLoopLatch()->getTerminator()->setMetadata("llvm.loop.parallel", n); -#endif -#if JL_LLVM_VERSION >= 30600 MDNode *m = MDNode::get(Lh->getContext(), ArrayRef(n)); -#else - MDNode *m = MDNode::get(Lh->getContext(), ArrayRef(n)); -#endif // Mark memory references so that Loop::isAnnotatedParallel will return true for this loop. for(Loop::block_iterator BBI = L->block_begin(), E=L->block_end(); BBI!=E; ++BBI) diff --git a/src/llvm-version.h b/src/llvm-version.h index 308aa42e14bddf..77879bb8b96e46 100644 --- a/src/llvm-version.h +++ b/src/llvm-version.h @@ -3,36 +3,14 @@ #include #include "fix_llvm_assert.h" -#ifndef LLVM_VERSION_PATCH // for LLVM 3.3 -#define LLVM_VERSION_PATCH 0 -#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 JL_LLVM_VERSION != 30300 && JL_LLVM_VERSION < 30701 - #error Only LLVM versions 3.3 and >= 3.7.1 are supported by Julia +#if JL_LLVM_VERSION < 30901 + #error Only LLVM versions >= 3.9.1 are supported by Julia #endif -#if JL_LLVM_VERSION >= 30800 - #define USE_ORCJIT -// We enable ORCJIT only if we have our custom patches -#elif JL_LLVM_VERSION >= 30700 && !defined(SYSTEM_LLVM) - #define USE_ORCJIT -#endif - -#if JL_LLVM_VERSION >= 30400 - #define USE_MCJIT -#endif - - -//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 - #define USE_MCJIT -#endif +#define USE_ORCJIT