diff options
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp')
| -rw-r--r-- | compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 99 |
1 files changed, 70 insertions, 29 deletions
diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 3595e37cf96..ddb5f7dcebf 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -201,6 +201,12 @@ void LLVMRustAddLastExtensionPasses( #define SUBTARGET_AVR #endif +#ifdef LLVM_COMPONENT_M68k +#define SUBTARGET_M68K SUBTARGET(M68k) +#else +#define SUBTARGET_M68K +#endif + #ifdef LLVM_COMPONENT_MIPS #define SUBTARGET_MIPS SUBTARGET(Mips) #else @@ -248,6 +254,7 @@ void LLVMRustAddLastExtensionPasses( SUBTARGET_ARM \ SUBTARGET_AARCH64 \ SUBTARGET_AVR \ + SUBTARGET_M68K \ SUBTARGET_MIPS \ SUBTARGET_PPC \ SUBTARGET_SYSTEMZ \ @@ -331,20 +338,24 @@ enum class LLVMRustPassBuilderOptLevel { Oz, }; -static PassBuilder::OptimizationLevel fromRust(LLVMRustPassBuilderOptLevel Level) { +#if LLVM_VERSION_LT(14,0) +using OptimizationLevel = PassBuilder::OptimizationLevel; +#endif + +static OptimizationLevel fromRust(LLVMRustPassBuilderOptLevel Level) { switch (Level) { case LLVMRustPassBuilderOptLevel::O0: - return PassBuilder::OptimizationLevel::O0; + return OptimizationLevel::O0; case LLVMRustPassBuilderOptLevel::O1: - return PassBuilder::OptimizationLevel::O1; + return OptimizationLevel::O1; case LLVMRustPassBuilderOptLevel::O2: - return PassBuilder::OptimizationLevel::O2; + return OptimizationLevel::O2; case LLVMRustPassBuilderOptLevel::O3: - return PassBuilder::OptimizationLevel::O3; + return OptimizationLevel::O3; case LLVMRustPassBuilderOptLevel::Os: - return PassBuilder::OptimizationLevel::Os; + return OptimizationLevel::Os; case LLVMRustPassBuilderOptLevel::Oz: - return PassBuilder::OptimizationLevel::Oz; + return OptimizationLevel::Oz; default: report_fatal_error("Bad PassBuilderOptLevel."); } @@ -754,7 +765,7 @@ LLVMRustOptimizeWithNewPassManager( const char *ExtraPasses, size_t ExtraPassesLen) { Module *TheModule = unwrap(ModuleRef); TargetMachine *TM = unwrap(TMRef); - PassBuilder::OptimizationLevel OptLevel = fromRust(OptLevelRust); + OptimizationLevel OptLevel = fromRust(OptLevelRust); PipelineTuningOptions PTO; @@ -827,19 +838,19 @@ LLVMRustOptimizeWithNewPassManager( // We manually collect pipeline callbacks so we can apply them at O0, where the // PassBuilder does not create a pipeline. - std::vector<std::function<void(ModulePassManager &, PassBuilder::OptimizationLevel)>> + std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>> PipelineStartEPCallbacks; #if LLVM_VERSION_GE(11, 0) - std::vector<std::function<void(ModulePassManager &, PassBuilder::OptimizationLevel)>> + std::vector<std::function<void(ModulePassManager &, OptimizationLevel)>> OptimizerLastEPCallbacks; #else - std::vector<std::function<void(FunctionPassManager &, PassBuilder::OptimizationLevel)>> + std::vector<std::function<void(FunctionPassManager &, OptimizationLevel)>> OptimizerLastEPCallbacks; #endif if (VerifyIR) { PipelineStartEPCallbacks.push_back( - [VerifyIR](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [VerifyIR](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(VerifierPass()); } ); @@ -847,7 +858,7 @@ LLVMRustOptimizeWithNewPassManager( if (InstrumentGCOV) { PipelineStartEPCallbacks.push_back( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(GCOVProfilerPass(GCOVOptions::getDefault())); } ); @@ -855,7 +866,7 @@ LLVMRustOptimizeWithNewPassManager( if (InstrumentCoverage) { PipelineStartEPCallbacks.push_back( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [](ModulePassManager &MPM, OptimizationLevel Level) { InstrProfOptions Options; MPM.addPass(InstrProfiling(Options, false)); } @@ -870,19 +881,23 @@ LLVMRustOptimizeWithNewPassManager( /*CompileKernel=*/false); #if LLVM_VERSION_GE(11, 0) OptimizerLastEPCallbacks.push_back( - [Options](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [Options](ModulePassManager &MPM, OptimizationLevel Level) { +#if LLVM_VERSION_GE(14, 0) + MPM.addPass(ModuleMemorySanitizerPass(Options)); +#else MPM.addPass(MemorySanitizerPass(Options)); +#endif MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass(Options))); } ); #else PipelineStartEPCallbacks.push_back( - [Options](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [Options](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(MemorySanitizerPass(Options)); } ); OptimizerLastEPCallbacks.push_back( - [Options](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { + [Options](FunctionPassManager &FPM, OptimizationLevel Level) { FPM.addPass(MemorySanitizerPass(Options)); } ); @@ -892,19 +907,23 @@ LLVMRustOptimizeWithNewPassManager( if (SanitizerOptions->SanitizeThread) { #if LLVM_VERSION_GE(11, 0) OptimizerLastEPCallbacks.push_back( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [](ModulePassManager &MPM, OptimizationLevel Level) { +#if LLVM_VERSION_GE(14, 0) + MPM.addPass(ModuleThreadSanitizerPass()); +#else MPM.addPass(ThreadSanitizerPass()); +#endif MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); } ); #else PipelineStartEPCallbacks.push_back( - [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(ThreadSanitizerPass()); } ); OptimizerLastEPCallbacks.push_back( - [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { + [](FunctionPassManager &FPM, OptimizationLevel Level) { FPM.addPass(ThreadSanitizerPass()); } ); @@ -914,30 +933,38 @@ LLVMRustOptimizeWithNewPassManager( if (SanitizerOptions->SanitizeAddress) { #if LLVM_VERSION_GE(11, 0) OptimizerLastEPCallbacks.push_back( - [SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>()); MPM.addPass(ModuleAddressSanitizerPass( /*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover)); +#if LLVM_VERSION_GE(14, 0) + AddressSanitizerOptions opts(/*CompileKernel=*/false, + SanitizerOptions->SanitizeAddressRecover, + /*UseAfterScope=*/true, + AsanDetectStackUseAfterReturnMode::Runtime); + MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass(opts))); +#else MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass( /*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover, /*UseAfterScope=*/true))); +#endif } ); #else PipelineStartEPCallbacks.push_back( - [&](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [&](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>()); } ); OptimizerLastEPCallbacks.push_back( - [SanitizerOptions](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) { + [SanitizerOptions](FunctionPassManager &FPM, OptimizationLevel Level) { FPM.addPass(AddressSanitizerPass( /*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover, /*UseAfterScope=*/true)); } ); PipelineStartEPCallbacks.push_back( - [SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(ModuleAddressSanitizerPass( /*CompileKernel=*/false, SanitizerOptions->SanitizeAddressRecover)); } @@ -947,14 +974,21 @@ LLVMRustOptimizeWithNewPassManager( if (SanitizerOptions->SanitizeHWAddress) { #if LLVM_VERSION_GE(11, 0) OptimizerLastEPCallbacks.push_back( - [SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) { +#if LLVM_VERSION_GE(14, 0) + HWAddressSanitizerOptions opts( + /*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover, + /*DisableOptimization=*/false); + MPM.addPass(HWAddressSanitizerPass(opts)); +#else MPM.addPass(HWAddressSanitizerPass( /*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover)); +#endif } ); #else PipelineStartEPCallbacks.push_back( - [SanitizerOptions](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) { + [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) { MPM.addPass(HWAddressSanitizerPass( /*CompileKernel=*/false, SanitizerOptions->SanitizeHWAddressRecover)); } @@ -970,7 +1004,10 @@ LLVMRustOptimizeWithNewPassManager( #endif bool NeedThinLTOBufferPasses = UseThinLTOBuffers; if (!NoPrepopulatePasses) { - if (OptLevel == PassBuilder::OptimizationLevel::O0) { + // The pre-link pipelines don't support O0 and require using budilO0DefaultPipeline() instead. + // At the same time, the LTO pipelines do support O0 and using them is required. + bool IsLTO = OptStage == LLVMRustOptStage::ThinLTO || OptStage == LLVMRustOptStage::FatLTO; + if (OptLevel == OptimizationLevel::O0 && !IsLTO) { #if LLVM_VERSION_GE(12, 0) for (const auto &C : PipelineStartEPCallbacks) PB.registerPipelineStartEPCallback(C); @@ -1535,7 +1572,11 @@ extern "C" bool LLVMRustPrepareThinLTOResolveWeak(const LLVMRustThinLTOData *Data, LLVMModuleRef M) { Module &Mod = *unwrap(M); const auto &DefinedGlobals = Data->ModuleToDefinedGVSummaries.lookup(Mod.getModuleIdentifier()); +#if LLVM_VERSION_GE(14, 0) + thinLTOFinalizeInModule(Mod, DefinedGlobals, /*PropagateAttrs=*/true); +#else thinLTOResolvePrevailingInModule(Mod, DefinedGlobals); +#endif return true; } @@ -1713,7 +1754,7 @@ LLVMRustGetBitcodeSliceFromObjectData(const char *data, // Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See // the comment in `back/lto.rs` for why this exists. extern "C" void -LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod, +LLVMRustLTOGetDICompileUnit(LLVMModuleRef Mod, DICompileUnit **A, DICompileUnit **B) { Module *M = unwrap(Mod); @@ -1731,7 +1772,7 @@ LLVMRustThinLTOGetDICompileUnit(LLVMModuleRef Mod, // Rewrite all `DICompileUnit` pointers to the `DICompileUnit` specified. See // the comment in `back/lto.rs` for why this exists. extern "C" void -LLVMRustThinLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) { +LLVMRustLTOPatchDICompileUnit(LLVMModuleRef Mod, DICompileUnit *Unit) { Module *M = unwrap(Mod); // If the original source module didn't have a `DICompileUnit` then try to |
