diff --git a/src/aotcompile.cpp b/src/aotcompile.cpp index 566d7b3b37e4a..93096d5ff8b50 100644 --- a/src/aotcompile.cpp +++ b/src/aotcompile.cpp @@ -1001,7 +1001,7 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer SourceTM.getRelocationModel(), SourceTM.getCodeModel(), SourceTM.getOptLevel())); - + fixupTM(*TM); if (unopt) { timers.unopt.startTimer(); raw_svector_ostream OS(out.unopt); @@ -1029,6 +1029,7 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer SourceTM.getRelocationModel(), SourceTM.getCodeModel(), SourceTM.getOptLevel())); + fixupTM(*PMTM); NewPM optimizer{std::move(PMTM), getOptLevel(jl_options.opt_level), OptimizationOptions::defaults(true, true)}; optimizer.run(M); assert(!verifyLLVMIR(M)); @@ -1514,6 +1515,7 @@ void jl_dump_native_impl(void *native_code, CMModel, CodeGenOpt::Aggressive // -O3 TODO: respect command -O0 flag? )); + fixupTM(*SourceTM); auto DL = jl_create_datalayout(*SourceTM); std::string StackProtectorGuard; unsigned OverrideStackAlignment; diff --git a/src/codegen.cpp b/src/codegen.cpp index fc396af404d6d..5d063c84fef19 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -4802,7 +4802,7 @@ static Value *global_binding_pointer(jl_codectx_t &ctx, jl_module_t *m, jl_sym_t // var not found. switch to delayed lookup. Constant *initnul = Constant::getNullValue(ctx.types().T_pjlvalue); GlobalVariable *bindinggv = new GlobalVariable(*ctx.f->getParent(), ctx.types().T_pjlvalue, - false, GlobalVariable::PrivateLinkage, initnul); + false, GlobalVariable::PrivateLinkage, initnul, "jl_binding_ptr"); // LLVM has bugs with nameless globals LoadInst *cachedval = ctx.builder.CreateAlignedLoad(ctx.types().T_pjlvalue, bindinggv, Align(sizeof(void*))); setName(ctx.emission_context, cachedval, jl_symbol_name(m->name) + StringRef(".") + jl_symbol_name(s) + ".cached"); cachedval->setOrdering(AtomicOrdering::Unordered); diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index e35268012e422..07a8aa90b853b 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -1198,6 +1198,12 @@ namespace { #else None; #endif + if (TheTriple.isAArch64()) + codemodel = CodeModel::Small; + if (TheTriple.isPPC()) { + // On PPC the small model is limited to 16bit offsets + codemodel = CodeModel::Medium; + } auto optlevel = CodeGenOptLevelFor(jl_options.opt_level); auto TM = TheTarget->createTargetMachine( TheTriple.getTriple(), TheCPU, FeaturesStr, @@ -1209,11 +1215,7 @@ namespace { ); assert(TM && "Failed to select target machine -" " Is the LLVM backend for this CPU enabled?"); - if (!TheTriple.isARM() && !TheTriple.isPPC64()) { - // FastISel seems to be buggy for ARM. Ref #13321 - if (jl_options.opt_level < 2) - TM->setFastISel(true); - } + fixupTM(*TM); return std::unique_ptr(TM); } } // namespace @@ -1239,7 +1241,9 @@ namespace { : JTMB(createJTMBFromTM(TM, optlevel)) {} std::unique_ptr operator()() JL_NOTSAFEPOINT { - return cantFail(JTMB.createTargetMachine()); + auto TM = cantFail(JTMB.createTargetMachine()); + fixupTM(*TM); + return TM; } }; @@ -1251,7 +1255,9 @@ namespace { : JTMB(createJTMBFromTM(TM, optlevel)), O(getOptLevel(optlevel)), printers(printers) {} auto operator()() JL_NOTSAFEPOINT { - auto NPM = std::make_unique(cantFail(JTMB.createTargetMachine()), O); + auto TM = cantFail(JTMB.createTargetMachine()); + fixupTM(*TM); + auto NPM = std::make_unique(std::move(TM), O); // TODO this needs to be locked, as different resource pools may add to the printer vector at the same time printers.push_back([NPM = NPM.get()]() JL_NOTSAFEPOINT { NPM->printTimers(); @@ -1637,6 +1643,16 @@ void optimizeDLSyms(Module &M) { JuliaOJIT::DLSymOptimizer(true)(M); } +void fixupTM(TargetMachine &TM){ + auto TheTriple = TM.getTargetTriple(); + if (jl_options.opt_level < 2) { + if (!TheTriple.isARM() && !TheTriple.isPPC64() && !TheTriple.isAArch64()) + TM.setFastISel(true); + else // FastISel seems to be buggy Ref #13321 + TM.setFastISel(false); + } +} + llvm::DataLayout jl_create_datalayout(TargetMachine &TM) { // Mark our address spaces as non-integral auto jl_data_layout = TM.createDataLayout(); @@ -2153,7 +2169,7 @@ void jl_merge_module(orc::ThreadSafeModule &destTSM, orc::ThreadSafeModule srcTS std::unique_ptr JuliaOJIT::cloneTargetMachine() const { - return std::unique_ptr(getTarget() + auto NewTM = std::unique_ptr(getTarget() .createTargetMachine( getTargetTriple().str(), getTargetCPU(), @@ -2162,6 +2178,8 @@ std::unique_ptr JuliaOJIT::cloneTargetMachine() const TM->getRelocationModel(), TM->getCodeModel(), TM->getOptLevel())); + fixupTM(*NewTM); + return NewTM; } const Triple& JuliaOJIT::getTargetTriple() const { diff --git a/src/jitlayers.h b/src/jitlayers.h index fff7fe756f459..baa1f2b946e60 100644 --- a/src/jitlayers.h +++ b/src/jitlayers.h @@ -569,6 +569,7 @@ Module &jl_codegen_params_t::shared_module() JL_NOTSAFEPOINT { } return *_shared_module; } +void fixupTM(TargetMachine &TM) JL_NOTSAFEPOINT; void optimizeDLSyms(Module &M); diff --git a/src/pipeline.cpp b/src/pipeline.cpp index 0813477129f66..7ff2d8d64ddba 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -744,9 +744,9 @@ PIC.addClassToPassName(decltype(CREATE_PASS)::name(), NAME); } NewPM::NewPM(std::unique_ptr TM, OptimizationLevel O, OptimizationOptions options) : - TM(std::move(TM)), + TM(std::move(TM)), #if JL_LLVM_VERSION < 160000 - SI(false), + SI(false), PIC(createPIC(SI)), #else PIC(createPIC()),