@@ -681,7 +681,6 @@ void LLVMSelfProfileInitializeCallbacks(
681
681
PassInstrumentationCallbacks& PIC, void * LlvmSelfProfiler,
682
682
LLVMRustSelfProfileBeforePassCallback BeforePassCallback,
683
683
LLVMRustSelfProfileAfterPassCallback AfterPassCallback) {
684
- #if LLVM_VERSION_GE(12, 0)
685
684
PIC.registerBeforeNonSkippedPassCallback ([LlvmSelfProfiler, BeforePassCallback](
686
685
StringRef Pass, llvm::Any Ir) {
687
686
std::string PassName = Pass.str ();
@@ -699,25 +698,6 @@ void LLVMSelfProfileInitializeCallbacks(
699
698
[LlvmSelfProfiler, AfterPassCallback](StringRef Pass, const PreservedAnalyses &Preserved) {
700
699
AfterPassCallback (LlvmSelfProfiler);
701
700
});
702
- #else
703
- PIC.registerBeforePassCallback ([LlvmSelfProfiler, BeforePassCallback](
704
- StringRef Pass, llvm::Any Ir) {
705
- std::string PassName = Pass.str ();
706
- std::string IrName = LLVMRustwrappedIrGetName (Ir);
707
- BeforePassCallback (LlvmSelfProfiler, PassName.c_str (), IrName.c_str ());
708
- return true ;
709
- });
710
-
711
- PIC.registerAfterPassCallback (
712
- [LlvmSelfProfiler, AfterPassCallback](StringRef Pass, llvm::Any Ir) {
713
- AfterPassCallback (LlvmSelfProfiler);
714
- });
715
-
716
- PIC.registerAfterPassInvalidatedCallback (
717
- [LlvmSelfProfiler, AfterPassCallback](StringRef Pass) {
718
- AfterPassCallback (LlvmSelfProfiler);
719
- });
720
- #endif
721
701
722
702
PIC.registerBeforeAnalysisCallback ([LlvmSelfProfiler, BeforePassCallback](
723
703
StringRef Pass, llvm::Any Ir) {
@@ -778,22 +758,13 @@ LLVMRustOptimizeWithNewPassManager(
778
758
PTO.LoopInterleaving = UnrollLoops;
779
759
PTO.LoopVectorization = LoopVectorize;
780
760
PTO.SLPVectorization = SLPVectorize;
781
- #if LLVM_VERSION_GE(12, 0)
782
761
PTO.MergeFunctions = MergeFunctions;
783
- #else
784
- // MergeFunctions is not supported by NewPM in older LLVM versions.
785
- (void ) MergeFunctions;
786
- #endif
787
762
788
763
// FIXME: We may want to expose this as an option.
789
764
bool DebugPassManager = false ;
790
765
791
766
PassInstrumentationCallbacks PIC;
792
- #if LLVM_VERSION_GE(12, 0)
793
767
StandardInstrumentations SI (DebugPassManager);
794
- #else
795
- StandardInstrumentations SI;
796
- #endif
797
768
SI.registerCallbacks (PIC);
798
769
799
770
if (LlvmSelfProfiler){
@@ -817,18 +788,14 @@ LLVMRustOptimizeWithNewPassManager(
817
788
PGOOptions::NoCSAction, DebugInfoForProfiling);
818
789
}
819
790
820
- #if LLVM_VERSION_GE(12, 0) && !LLVM_VERSION_GE(13,0)
821
- PassBuilder PB (DebugPassManager, TM, PTO, PGOOpt, &PIC);
822
- #else
823
- PassBuilder PB (TM, PTO, PGOOpt, &PIC);
824
- #endif
825
-
826
791
#if LLVM_VERSION_GE(13, 0)
792
+ PassBuilder PB (TM, PTO, PGOOpt, &PIC);
827
793
LoopAnalysisManager LAM;
828
794
FunctionAnalysisManager FAM;
829
795
CGSCCAnalysisManager CGAM;
830
796
ModuleAnalysisManager MAM;
831
797
#else
798
+ PassBuilder PB (DebugPassManager, TM, PTO, PGOOpt, &PIC);
832
799
LoopAnalysisManager LAM (DebugPassManager);
833
800
FunctionAnalysisManager FAM (DebugPassManager);
834
801
CGSCCAnalysisManager CGAM (DebugPassManager);
@@ -960,39 +927,16 @@ LLVMRustOptimizeWithNewPassManager(
960
927
// At the same time, the LTO pipelines do support O0 and using them is required.
961
928
bool IsLTO = OptStage == LLVMRustOptStage::ThinLTO || OptStage == LLVMRustOptStage::FatLTO;
962
929
if (OptLevel == OptimizationLevel::O0 && !IsLTO) {
963
- #if LLVM_VERSION_GE(12, 0)
964
930
for (const auto &C : PipelineStartEPCallbacks)
965
931
PB.registerPipelineStartEPCallback (C);
966
932
for (const auto &C : OptimizerLastEPCallbacks)
967
933
PB.registerOptimizerLastEPCallback (C);
968
934
969
935
// Pass false as we manually schedule ThinLTOBufferPasses below.
970
936
MPM = PB.buildO0DefaultPipeline (OptLevel, /* PreLinkLTO */ false );
971
- #else
972
- for (const auto &C : PipelineStartEPCallbacks)
973
- C (MPM, OptLevel);
974
-
975
- for (const auto &C : OptimizerLastEPCallbacks)
976
- C (MPM, OptLevel);
977
-
978
- MPM.addPass (AlwaysInlinerPass (EmitLifetimeMarkers));
979
-
980
- if (PGOOpt) {
981
- PB.addPGOInstrPassesForO0 (
982
- MPM, DebugPassManager, PGOOpt->Action == PGOOptions::IRInstr,
983
- /* IsCS=*/ false , PGOOpt->ProfileFile , PGOOpt->ProfileRemappingFile );
984
- }
985
- #endif
986
937
} else {
987
- #if LLVM_VERSION_GE(12, 0)
988
938
for (const auto &C : PipelineStartEPCallbacks)
989
939
PB.registerPipelineStartEPCallback (C);
990
- #else
991
- for (const auto &C : PipelineStartEPCallbacks)
992
- PB.registerPipelineStartEPCallback ([C, OptLevel](ModulePassManager &MPM) {
993
- C (MPM, OptLevel);
994
- });
995
- #endif
996
940
if (OptStage != LLVMRustOptStage::PreLinkThinLTO) {
997
941
for (const auto &C : OptimizerLastEPCallbacks)
998
942
PB.registerOptimizerLastEPCallback (C);
@@ -1003,43 +947,27 @@ LLVMRustOptimizeWithNewPassManager(
1003
947
MPM = PB.buildPerModuleDefaultPipeline (OptLevel, DebugPassManager);
1004
948
break ;
1005
949
case LLVMRustOptStage::PreLinkThinLTO:
1006
- #if LLVM_VERSION_GE(12, 0)
1007
950
MPM = PB.buildThinLTOPreLinkDefaultPipeline (OptLevel);
1008
951
// The ThinLTOPreLink pipeline already includes ThinLTOBuffer passes. However, callback
1009
952
// passes may still run afterwards. This means we need to run the buffer passes again.
1010
953
// FIXME: In LLVM 13, the ThinLTOPreLink pipeline also runs OptimizerLastEPCallbacks
1011
954
// before the RequiredLTOPreLinkPasses, in which case we can remove these hacks.
1012
955
if (OptimizerLastEPCallbacks.empty ())
1013
956
NeedThinLTOBufferPasses = false ;
1014
- #else
1015
- MPM = PB.buildThinLTOPreLinkDefaultPipeline (OptLevel, DebugPassManager);
1016
- #endif
1017
957
for (const auto &C : OptimizerLastEPCallbacks)
1018
958
C (MPM, OptLevel);
1019
959
break ;
1020
960
case LLVMRustOptStage::PreLinkFatLTO:
1021
- #if LLVM_VERSION_GE(12, 0)
1022
961
MPM = PB.buildLTOPreLinkDefaultPipeline (OptLevel);
1023
962
NeedThinLTOBufferPasses = false ;
1024
- #else
1025
- MPM = PB.buildLTOPreLinkDefaultPipeline (OptLevel, DebugPassManager);
1026
- #endif
1027
963
break ;
1028
964
case LLVMRustOptStage::ThinLTO:
1029
965
// FIXME: Does it make sense to pass the ModuleSummaryIndex?
1030
966
// It only seems to be needed for C++ specific optimizations.
1031
- #if LLVM_VERSION_GE(12, 0)
1032
967
MPM = PB.buildThinLTODefaultPipeline (OptLevel, nullptr );
1033
- #else
1034
- MPM = PB.buildThinLTODefaultPipeline (OptLevel, DebugPassManager, nullptr );
1035
- #endif
1036
968
break ;
1037
969
case LLVMRustOptStage::FatLTO:
1038
- #if LLVM_VERSION_GE(12, 0)
1039
970
MPM = PB.buildLTODefaultPipeline (OptLevel, nullptr );
1040
- #else
1041
- MPM = PB.buildLTODefaultPipeline (OptLevel, DebugPassManager, nullptr );
1042
- #endif
1043
971
break ;
1044
972
}
1045
973
}
0 commit comments