@@ -54,10 +54,6 @@ typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
54
54
55
55
DEFINE_STDCXX_CONVERSION_FUNCTIONS (Pass, LLVMPassRef)
56
56
DEFINE_STDCXX_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
57
- #if LLVM_VERSION_LT(11, 0)
58
- DEFINE_STDCXX_CONVERSION_FUNCTIONS (PassManagerBuilder,
59
- LLVMPassManagerBuilderRef)
60
- #endif
61
57
62
58
extern "C" void LLVMInitializePasses() {
63
59
PassRegistry &Registry = *PassRegistry::getPassRegistry ();
@@ -685,7 +681,6 @@ void LLVMSelfProfileInitializeCallbacks(
685
681
PassInstrumentationCallbacks& PIC, void * LlvmSelfProfiler,
686
682
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
687
683
LLVMRustSelfProfileAfterPassCallback AfterPassCallback) {
688
- #if LLVM_VERSION_GE(12, 0)
689
684
PIC.registerBeforeNonSkippedPassCallback ([LlvmSelfProfiler, BeforePassCallback](
690
685
StringRef Pass, llvm::Any Ir) {
691
686
std::string PassName = Pass.str ();
@@ -703,25 +698,6 @@ void LLVMSelfProfileInitializeCallbacks(
703
698
[LlvmSelfProfiler, AfterPassCallback](StringRef Pass, const PreservedAnalyses &Preserved) {
704
699
AfterPassCallback (LlvmSelfProfiler);
705
700
});
706
- #else
707
- PIC.registerBeforePassCallback ([LlvmSelfProfiler, BeforePassCallback](
708
- StringRef Pass, llvm::Any Ir) {
709
- std::string PassName = Pass.str ();
710
- std::string IrName = LLVMRustwrappedIrGetName (Ir);
711
- BeforePassCallback (LlvmSelfProfiler, PassName.c_str (), IrName.c_str ());
712
- return true ;
713
- });
714
-
715
- PIC.registerAfterPassCallback (
716
- [LlvmSelfProfiler, AfterPassCallback](StringRef Pass, llvm::Any Ir) {
717
- AfterPassCallback (LlvmSelfProfiler);
718
- });
719
-
720
- PIC.registerAfterPassInvalidatedCallback (
721
- [LlvmSelfProfiler, AfterPassCallback](StringRef Pass) {
722
- AfterPassCallback (LlvmSelfProfiler);
723
- });
724
- #endif
725
701
726
702
PIC.registerBeforeAnalysisCallback ([LlvmSelfProfiler, BeforePassCallback](
727
703
StringRef Pass, llvm::Any Ir) {
@@ -782,22 +758,13 @@ LLVMRustOptimizeWithNewPassManager(
782
758
PTO.LoopInterleaving = UnrollLoops;
783
759
PTO.LoopVectorization = LoopVectorize;
784
760
PTO.SLPVectorization = SLPVectorize;
785
- #if LLVM_VERSION_GE(12, 0)
786
761
PTO.MergeFunctions = MergeFunctions;
787
- #else
788
- // MergeFunctions is not supported by NewPM in older LLVM versions.
789
- (void ) MergeFunctions;
790
- #endif
791
762
792
763
// FIXME: We may want to expose this as an option.
793
764
bool DebugPassManager = false ;
794
765
795
766
PassInstrumentationCallbacks PIC;
796
- #if LLVM_VERSION_GE(12, 0)
797
767
StandardInstrumentations SI (DebugPassManager);
798
- #else
799
- StandardInstrumentations SI;
800
- #endif
801
768
SI.registerCallbacks (PIC);
802
769
803
770
if (LlvmSelfProfiler){
@@ -821,18 +788,14 @@ LLVMRustOptimizeWithNewPassManager(
821
788
PGOOptions::NoCSAction, DebugInfoForProfiling);
822
789
}
823
790
824
- #if LLVM_VERSION_GE(12, 0) && !LLVM_VERSION_GE(13,0)
825
- PassBuilder PB (DebugPassManager, TM, PTO, PGOOpt, &PIC);
826
- #else
827
- PassBuilder PB (TM, PTO, PGOOpt, &PIC);
828
- #endif
829
-
830
791
#if LLVM_VERSION_GE(13, 0)
792
+ PassBuilder PB (TM, PTO, PGOOpt, &PIC);
831
793
LoopAnalysisManager LAM;
832
794
FunctionAnalysisManager FAM;
833
795
CGSCCAnalysisManager CGAM;
834
796
ModuleAnalysisManager MAM;
835
797
#else
798
+ PassBuilder PB (DebugPassManager, TM, PTO, PGOOpt, &PIC);
836
799
LoopAnalysisManager LAM (DebugPassManager);
837
800
FunctionAnalysisManager FAM (DebugPassManager);
838
801
CGSCCAnalysisManager CGAM (DebugPassManager);
@@ -857,13 +820,8 @@ LLVMRustOptimizeWithNewPassManager(
857
820
// PassBuilder does not create a pipeline.
858
821
std::vector<std::function<void (ModulePassManager &, OptimizationLevel)>>
859
822
PipelineStartEPCallbacks;
860
- #if LLVM_VERSION_GE(11, 0)
861
823
std::vector<std::function<void (ModulePassManager &, OptimizationLevel)>>
862
824
OptimizerLastEPCallbacks;
863
- #else
864
- std::vector<std::function<void (FunctionPassManager &, OptimizationLevel)>>
865
- OptimizerLastEPCallbacks;
866
- #endif
867
825
868
826
if (VerifyIR) {
869
827
PipelineStartEPCallbacks.push_back (
@@ -896,7 +854,6 @@ LLVMRustOptimizeWithNewPassManager(
896
854
SanitizerOptions->SanitizeMemoryTrackOrigins ,
897
855
SanitizerOptions->SanitizeMemoryRecover ,
898
856
/* CompileKernel=*/ false );
899
- #if LLVM_VERSION_GE(11, 0)
900
857
OptimizerLastEPCallbacks.push_back (
901
858
[Options](ModulePassManager &MPM, OptimizationLevel Level) {
902
859
#if LLVM_VERSION_GE(14, 0)
@@ -907,22 +864,9 @@ LLVMRustOptimizeWithNewPassManager(
907
864
MPM.addPass (createModuleToFunctionPassAdaptor (MemorySanitizerPass (Options)));
908
865
}
909
866
);
910
- #else
911
- PipelineStartEPCallbacks.push_back (
912
- [Options](ModulePassManager &MPM, OptimizationLevel Level) {
913
- MPM.addPass (MemorySanitizerPass (Options));
914
- }
915
- );
916
- OptimizerLastEPCallbacks.push_back (
917
- [Options](FunctionPassManager &FPM, OptimizationLevel Level) {
918
- FPM.addPass (MemorySanitizerPass (Options));
919
- }
920
- );
921
- #endif
922
867
}
923
868
924
869
if (SanitizerOptions->SanitizeThread ) {
925
- #if LLVM_VERSION_GE(11, 0)
926
870
OptimizerLastEPCallbacks.push_back (
927
871
[](ModulePassManager &MPM, OptimizationLevel Level) {
928
872
#if LLVM_VERSION_GE(14, 0)
@@ -933,22 +877,9 @@ LLVMRustOptimizeWithNewPassManager(
933
877
MPM.addPass (createModuleToFunctionPassAdaptor (ThreadSanitizerPass ()));
934
878
}
935
879
);
936
- #else
937
- PipelineStartEPCallbacks.push_back (
938
- [](ModulePassManager &MPM, OptimizationLevel Level) {
939
- MPM.addPass (ThreadSanitizerPass ());
940
- }
941
- );
942
- OptimizerLastEPCallbacks.push_back (
943
- [](FunctionPassManager &FPM, OptimizationLevel Level) {
944
- FPM.addPass (ThreadSanitizerPass ());
945
- }
946
- );
947
- #endif
948
880
}
949
881
950
882
if (SanitizerOptions->SanitizeAddress ) {
951
- #if LLVM_VERSION_GE(11, 0)
952
883
OptimizerLastEPCallbacks.push_back (
953
884
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
954
885
MPM.addPass (RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
@@ -967,29 +898,8 @@ LLVMRustOptimizeWithNewPassManager(
967
898
#endif
968
899
}
969
900
);
970
- #else
971
- PipelineStartEPCallbacks.push_back (
972
- [&](ModulePassManager &MPM, OptimizationLevel Level) {
973
- MPM.addPass (RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
974
- }
975
- );
976
- OptimizerLastEPCallbacks.push_back (
977
- [SanitizerOptions](FunctionPassManager &FPM, OptimizationLevel Level) {
978
- FPM.addPass (AddressSanitizerPass (
979
- /* CompileKernel=*/ false , SanitizerOptions->SanitizeAddressRecover ,
980
- /* UseAfterScope=*/ true ));
981
- }
982
- );
983
- PipelineStartEPCallbacks.push_back (
984
- [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
985
- MPM.addPass (ModuleAddressSanitizerPass (
986
- /* CompileKernel=*/ false , SanitizerOptions->SanitizeAddressRecover ));
987
- }
988
- );
989
- #endif
990
901
}
991
902
if (SanitizerOptions->SanitizeHWAddress ) {
992
- #if LLVM_VERSION_GE(11, 0)
993
903
OptimizerLastEPCallbacks.push_back (
994
904
[SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
995
905
#if LLVM_VERSION_GE(14, 0)
@@ -1003,14 +913,6 @@ LLVMRustOptimizeWithNewPassManager(
1003
913
#endif
1004
914
}
1005
915
);
1006
- #else
1007
- PipelineStartEPCallbacks.push_back (
1008
- [SanitizerOptions](ModulePassManager &MPM, OptimizationLevel Level) {
1009
- MPM.addPass (HWAddressSanitizerPass (
1010
- /* CompileKernel=*/ false , SanitizerOptions->SanitizeHWAddressRecover ));
1011
- }
1012
- );
1013
- #endif
1014
916
}
1015
917
}
1016
918
@@ -1025,48 +927,16 @@ LLVMRustOptimizeWithNewPassManager(
1025
927
// At the same time, the LTO pipelines do support O0 and using them is required.
1026
928
bool IsLTO = OptStage == LLVMRustOptStage::ThinLTO || OptStage == LLVMRustOptStage::FatLTO;
1027
929
if (OptLevel == OptimizationLevel::O0 && !IsLTO) {
1028
- #if LLVM_VERSION_GE(12, 0)
1029
930
for (const auto &C : PipelineStartEPCallbacks)
1030
931
PB.registerPipelineStartEPCallback (C);
1031
932
for (const auto &C : OptimizerLastEPCallbacks)
1032
933
PB.registerOptimizerLastEPCallback (C);
1033
934
1034
935
// Pass false as we manually schedule ThinLTOBufferPasses below.
1035
936
MPM = PB.buildO0DefaultPipeline (OptLevel, /* PreLinkLTO */ false );
1036
- #else
1037
- for (const auto &C : PipelineStartEPCallbacks)
1038
- C (MPM, OptLevel);
1039
-
1040
- # if LLVM_VERSION_GE(11, 0)
1041
- for (const auto &C : OptimizerLastEPCallbacks)
1042
- C (MPM, OptLevel);
1043
- # else
1044
- if (!OptimizerLastEPCallbacks.empty ()) {
1045
- FunctionPassManager FPM (DebugPassManager);
1046
- for (const auto &C : OptimizerLastEPCallbacks)
1047
- C (FPM, OptLevel);
1048
- MPM.addPass (createModuleToFunctionPassAdaptor (std::move (FPM)));
1049
- }
1050
- # endif
1051
-
1052
- MPM.addPass (AlwaysInlinerPass (EmitLifetimeMarkers));
1053
-
1054
- if (PGOOpt) {
1055
- PB.addPGOInstrPassesForO0 (
1056
- MPM, DebugPassManager, PGOOpt->Action == PGOOptions::IRInstr,
1057
- /* IsCS=*/ false , PGOOpt->ProfileFile , PGOOpt->ProfileRemappingFile );
1058
- }
1059
- #endif
1060
937
} else {
1061
- #if LLVM_VERSION_GE(12, 0)
1062
938
for (const auto &C : PipelineStartEPCallbacks)
1063
939
PB.registerPipelineStartEPCallback (C);
1064
- #else
1065
- for (const auto &C : PipelineStartEPCallbacks)
1066
- PB.registerPipelineStartEPCallback ([C, OptLevel](ModulePassManager &MPM) {
1067
- C (MPM, OptLevel);
1068
- });
1069
- #endif
1070
940
if (OptStage != LLVMRustOptStage::PreLinkThinLTO) {
1071
941
for (const auto &C : OptimizerLastEPCallbacks)
1072
942
PB.registerOptimizerLastEPCallback (C);
@@ -1077,52 +947,27 @@ LLVMRustOptimizeWithNewPassManager(
1077
947
MPM = PB.buildPerModuleDefaultPipeline (OptLevel, DebugPassManager);
1078
948
break ;
1079
949
case LLVMRustOptStage::PreLinkThinLTO:
1080
- #if LLVM_VERSION_GE(12, 0)
1081
950
MPM = PB.buildThinLTOPreLinkDefaultPipeline (OptLevel);
1082
951
// The ThinLTOPreLink pipeline already includes ThinLTOBuffer passes. However, callback
1083
952
// passes may still run afterwards. This means we need to run the buffer passes again.
1084
953
// FIXME: In LLVM 13, the ThinLTOPreLink pipeline also runs OptimizerLastEPCallbacks
1085
954
// before the RequiredLTOPreLinkPasses, in which case we can remove these hacks.
1086
955
if (OptimizerLastEPCallbacks.empty ())
1087
956
NeedThinLTOBufferPasses = false ;
1088
- #else
1089
- MPM = PB.buildThinLTOPreLinkDefaultPipeline (OptLevel, DebugPassManager);
1090
- #endif
1091
- #if LLVM_VERSION_GE(11, 0)
1092
957
for (const auto &C : OptimizerLastEPCallbacks)
1093
958
C (MPM, OptLevel);
1094
- #else
1095
- if (!OptimizerLastEPCallbacks.empty ()) {
1096
- FunctionPassManager FPM (DebugPassManager);
1097
- for (const auto &C : OptimizerLastEPCallbacks)
1098
- C (FPM, OptLevel);
1099
- MPM.addPass (createModuleToFunctionPassAdaptor (std::move (FPM)));
1100
- }
1101
- #endif
1102
959
break ;
1103
960
case LLVMRustOptStage::PreLinkFatLTO:
1104
- #if LLVM_VERSION_GE(12, 0)
1105
961
MPM = PB.buildLTOPreLinkDefaultPipeline (OptLevel);
1106
962
NeedThinLTOBufferPasses = false ;
1107
- #else
1108
- MPM = PB.buildLTOPreLinkDefaultPipeline (OptLevel, DebugPassManager);
1109
- #endif
1110
963
break ;
1111
964
case LLVMRustOptStage::ThinLTO:
1112
965
// FIXME: Does it make sense to pass the ModuleSummaryIndex?
1113
966
// It only seems to be needed for C++ specific optimizations.
1114
- #if LLVM_VERSION_GE(12, 0)
1115
967
MPM = PB.buildThinLTODefaultPipeline (OptLevel, nullptr );
1116
- #else
1117
- MPM = PB.buildThinLTODefaultPipeline (OptLevel, DebugPassManager, nullptr );
1118
- #endif
1119
968
break ;
1120
969
case LLVMRustOptStage::FatLTO:
1121
- #if LLVM_VERSION_GE(12, 0)
1122
970
MPM = PB.buildLTODefaultPipeline (OptLevel, nullptr );
1123
- #else
1124
- MPM = PB.buildLTODefaultPipeline (OptLevel, DebugPassManager, nullptr );
1125
- #endif
1126
971
break ;
1127
972
}
1128
973
}
@@ -1552,7 +1397,6 @@ LLVMRustFreeThinLTOData(LLVMRustThinLTOData *Data) {
1552
1397
// `ProcessThinLTOModule` function. Here they're split up into separate steps
1553
1398
// so rustc can save off the intermediate bytecode between each step.
1554
1399
1555
- #if LLVM_VERSION_GE(11, 0)
1556
1400
static bool
1557
1401
clearDSOLocalOnDeclarations (Module &Mod, TargetMachine &TM) {
1558
1402
// When linking an ELF shared object, dso_local should be dropped. We
@@ -1563,20 +1407,15 @@ clearDSOLocalOnDeclarations(Module &Mod, TargetMachine &TM) {
1563
1407
Mod.getPIELevel () == PIELevel::Default;
1564
1408
return ClearDSOLocalOnDeclarations;
1565
1409
}
1566
- #endif
1567
1410
1568
1411
extern " C" bool
1569
1412
LLVMRustPrepareThinLTORename (const LLVMRustThinLTOData *Data, LLVMModuleRef M,
1570
1413
LLVMTargetMachineRef TM) {
1571
1414
Module &Mod = *unwrap (M);
1572
1415
TargetMachine &Target = *unwrap (TM);
1573
1416
1574
- #if LLVM_VERSION_GE(11, 0)
1575
1417
bool ClearDSOLocal = clearDSOLocalOnDeclarations (Mod, Target);
1576
1418
bool error = renameModuleForThinLTO (Mod, Data->Index , ClearDSOLocal);
1577
- #else
1578
- bool error = renameModuleForThinLTO (Mod, Data->Index );
1579
- #endif
1580
1419
1581
1420
if (error) {
1582
1421
LLVMRustSetLastError (" renameModuleForThinLTO failed" );
@@ -1645,12 +1484,8 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M,
1645
1484
1646
1485
return MOrErr;
1647
1486
};
1648
- #if LLVM_VERSION_GE(11, 0)
1649
1487
bool ClearDSOLocal = clearDSOLocalOnDeclarations (Mod, Target);
1650
1488
FunctionImporter Importer (Data->Index , Loader, ClearDSOLocal);
1651
- #else
1652
- FunctionImporter Importer (Data->Index , Loader);
1653
- #endif
1654
1489
Expected<bool > Result = Importer.importFunctions (Mod, ImportList);
1655
1490
if (!Result) {
1656
1491
LLVMRustSetLastError (toString (Result.takeError ()).c_str ());
0 commit comments