1414#include " llvm/IR/AssemblyAnnotationWriter.h"
1515#include " llvm/IR/IntrinsicInst.h"
1616#include " llvm/IR/Verifier.h"
17+ #include " llvm/MC/TargetRegistry.h"
1718#include " llvm/Object/ObjectFile.h"
1819#include " llvm/Object/IRObjectFile.h"
1920#include " llvm/Passes/PassBuilder.h"
2526#include " llvm/Support/VirtualFileSystem.h"
2627#endif
2728#include " llvm/Support/Host.h"
28- #if LLVM_VERSION_LT(14, 0)
29- #include " llvm/Support/TargetRegistry.h"
30- #else
31- #include " llvm/MC/TargetRegistry.h"
32- #endif
3329#include " llvm/Target/TargetMachine.h"
3430#include " llvm/Transforms/IPO/PassManagerBuilder.h"
3531#include " llvm/Transforms/IPO/AlwaysInliner.h"
@@ -267,10 +263,6 @@ enum class LLVMRustPassBuilderOptLevel {
267263 Oz,
268264};
269265
270- #if LLVM_VERSION_LT(14,0)
271- using OptimizationLevel = PassBuilder::OptimizationLevel;
272- #endif
273-
274266static OptimizationLevel fromRust (LLVMRustPassBuilderOptLevel Level) {
275267 switch (Level) {
276268 case LLVMRustPassBuilderOptLevel::O0:
@@ -747,27 +739,18 @@ LLVMRustOptimize(
747739
748740 if (SanitizerOptions) {
749741 if (SanitizerOptions->SanitizeMemory ) {
750- #if LLVM_VERSION_GE(14, 0)
751742 MemorySanitizerOptions Options (
752743 SanitizerOptions->SanitizeMemoryTrackOrigins ,
753744 SanitizerOptions->SanitizeMemoryRecover ,
754745 /* CompileKernel=*/ false ,
755746 /* EagerChecks=*/ true );
756- #else
757- MemorySanitizerOptions Options (
758- SanitizerOptions->SanitizeMemoryTrackOrigins ,
759- SanitizerOptions->SanitizeMemoryRecover ,
760- /* CompileKernel=*/ false );
761- #endif
762747 OptimizerLastEPCallbacks.push_back (
763748 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
764- #if LLVM_VERSION_GE(14, 0) && LLVM_VERSION_LT(16, 0)
749+ #if LLVM_VERSION_LT(16, 0)
765750 MPM.addPass (ModuleMemorySanitizerPass (Options));
751+ MPM.addPass (createModuleToFunctionPassAdaptor (MemorySanitizerPass (Options)));
766752#else
767753 MPM.addPass (MemorySanitizerPass (Options));
768- #endif
769- #if LLVM_VERSION_LT(16, 0)
770- MPM.addPass (createModuleToFunctionPassAdaptor (MemorySanitizerPass (Options)));
771754#endif
772755 }
773756 );
@@ -776,11 +759,7 @@ LLVMRustOptimize(
776759 if (SanitizerOptions->SanitizeThread ) {
777760 OptimizerLastEPCallbacks.push_back (
778761 [](ModulePassManager &MPM, OptimizationLevel Level) {
779- #if LLVM_VERSION_GE(14, 0)
780762 MPM.addPass (ModuleThreadSanitizerPass ());
781- #else
782- MPM.addPass (ThreadSanitizerPass ());
783- #endif
784763 MPM.addPass (createModuleToFunctionPassAdaptor (ThreadSanitizerPass ()));
785764 }
786765 );
@@ -792,7 +771,6 @@ LLVMRustOptimize(
792771#if LLVM_VERSION_LT(15, 0)
793772 MPM.addPass (RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
794773#endif
795- #if LLVM_VERSION_GE(14, 0)
796774 AddressSanitizerOptions opts = AddressSanitizerOptions{
797775 /* CompileKernel=*/ false ,
798776 SanitizerOptions->SanitizeAddressRecover ,
@@ -803,29 +781,17 @@ LLVMRustOptimize(
803781 MPM.addPass (ModuleAddressSanitizerPass (opts));
804782#else
805783 MPM.addPass (AddressSanitizerPass (opts));
806- #endif
807- #else
808- MPM.addPass (ModuleAddressSanitizerPass (
809- /* CompileKernel=*/ false , SanitizerOptions->SanitizeAddressRecover ));
810- MPM.addPass (createModuleToFunctionPassAdaptor (AddressSanitizerPass (
811- /* CompileKernel=*/ false , SanitizerOptions->SanitizeAddressRecover ,
812- /* UseAfterScope=*/ true )));
813784#endif
814785 }
815786 );
816787 }
817788 if (SanitizerOptions->SanitizeHWAddress ) {
818789 OptimizerLastEPCallbacks.push_back (
819790 [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
820- #if LLVM_VERSION_GE(14, 0)
821791 HWAddressSanitizerOptions opts (
822792 /* CompileKernel=*/ false , SanitizerOptions->SanitizeHWAddressRecover ,
823793 /* DisableOptimization=*/ false );
824794 MPM.addPass (HWAddressSanitizerPass (opts));
825- #else
826- MPM.addPass (HWAddressSanitizerPass (
827- /* CompileKernel=*/ false , SanitizerOptions->SanitizeHWAddressRecover ));
828- #endif
829795 }
830796 );
831797 }
@@ -1328,11 +1294,7 @@ extern "C" bool
13281294LLVMRustPrepareThinLTOResolveWeak (const LLVMRustThinLTOData *Data, LLVMModuleRef M) {
13291295 Module &Mod = *unwrap (M);
13301296 const auto &DefinedGlobals = Data->ModuleToDefinedGVSummaries .lookup (Mod.getModuleIdentifier ());
1331- #if LLVM_VERSION_GE(14, 0)
13321297 thinLTOFinalizeInModule (Mod, DefinedGlobals, /* PropagateAttrs=*/ true );
1333- #else
1334- thinLTOResolvePrevailingInModule (Mod, DefinedGlobals);
1335- #endif
13361298 return true ;
13371299}
13381300
0 commit comments