@@ -898,183 +898,6 @@ void PassManagerBuilder::populateModulePassManager(
898
898
MPM.add (createAnnotationRemarksLegacyPass ());
899
899
}
900
900
901
- void PassManagerBuilder::addLTOOptimizationPasses (legacy::PassManagerBase &PM) {
902
- // Load sample profile before running the LTO optimization pipeline.
903
- if (!PGOSampleUse.empty ()) {
904
- PM.add (createPruneEHPass ());
905
- PM.add (createSampleProfileLoaderPass (PGOSampleUse));
906
- }
907
-
908
- // Remove unused virtual tables to improve the quality of code generated by
909
- // whole-program devirtualization and bitset lowering.
910
- PM.add (createGlobalDCEPass ());
911
-
912
- // Provide AliasAnalysis services for optimizations.
913
- addInitialAliasAnalysisPasses (PM);
914
-
915
- // Allow forcing function attributes as a debugging and tuning aid.
916
- PM.add (createForceFunctionAttrsLegacyPass ());
917
-
918
- // Infer attributes about declarations if possible.
919
- PM.add (createInferFunctionAttrsLegacyPass ());
920
-
921
- if (OptLevel > 1 ) {
922
- // Split call-site with more constrained arguments.
923
- PM.add (createCallSiteSplittingPass ());
924
-
925
- // Propage constant function arguments by specializing the functions.
926
- if (EnableFunctionSpecialization && OptLevel > 2 )
927
- PM.add (createFunctionSpecializationPass ());
928
-
929
- // Propagate constants at call sites into the functions they call. This
930
- // opens opportunities for globalopt (and inlining) by substituting function
931
- // pointers passed as arguments to direct uses of functions.
932
- PM.add (createIPSCCPPass ());
933
-
934
- // Attach metadata to indirect call sites indicating the set of functions
935
- // they may target at run-time. This should follow IPSCCP.
936
- PM.add (createCalledValuePropagationPass ());
937
-
938
- // Infer attributes on declarations, call sites, arguments, etc.
939
- if (AttributorRun & AttributorRunOption::MODULE)
940
- PM.add (createAttributorLegacyPass ());
941
- }
942
-
943
- // Infer attributes about definitions. The readnone attribute in particular is
944
- // required for virtual constant propagation.
945
- PM.add (createPostOrderFunctionAttrsLegacyPass ());
946
- PM.add (createReversePostOrderFunctionAttrsPass ());
947
-
948
- // Split globals using inrange annotations on GEP indices. This can help
949
- // improve the quality of generated code when virtual constant propagation or
950
- // control flow integrity are enabled.
951
- PM.add (createGlobalSplitPass ());
952
-
953
- // Apply whole-program devirtualization and virtual constant propagation.
954
- PM.add (createWholeProgramDevirtPass (ExportSummary, nullptr ));
955
-
956
- // That's all we need at opt level 1.
957
- if (OptLevel == 1 )
958
- return ;
959
-
960
- // Now that we internalized some globals, see if we can hack on them!
961
- PM.add (createGlobalOptimizerPass ());
962
- // Promote any localized global vars.
963
- PM.add (createPromoteMemoryToRegisterPass ());
964
-
965
- // Linking modules together can lead to duplicated global constants, only
966
- // keep one copy of each constant.
967
- PM.add (createConstantMergePass ());
968
-
969
- // Remove unused arguments from functions.
970
- PM.add (createDeadArgEliminationPass ());
971
-
972
- // Reduce the code after globalopt and ipsccp. Both can open up significant
973
- // simplification opportunities, and both can propagate functions through
974
- // function pointers. When this happens, we often have to resolve varargs
975
- // calls, etc, so let instcombine do this.
976
- if (OptLevel > 2 )
977
- PM.add (createAggressiveInstCombinerPass ());
978
- PM.add (createInstructionCombiningPass ());
979
- addExtensionsToPM (EP_Peephole, PM);
980
-
981
- // Inline small functions
982
- bool RunInliner = Inliner;
983
- if (RunInliner) {
984
- PM.add (Inliner);
985
- Inliner = nullptr ;
986
- }
987
-
988
- PM.add (createPruneEHPass ()); // Remove dead EH info.
989
-
990
- // Infer attributes on declarations, call sites, arguments, etc. for an SCC.
991
- if (AttributorRun & AttributorRunOption::CGSCC)
992
- PM.add (createAttributorCGSCCLegacyPass ());
993
-
994
- // Try to perform OpenMP specific optimizations. This is a (quick!) no-op if
995
- // there are no OpenMP runtime calls present in the module.
996
- if (OptLevel > 1 )
997
- PM.add (createOpenMPOptCGSCCLegacyPass ());
998
-
999
- // Optimize globals again if we ran the inliner.
1000
- if (RunInliner)
1001
- PM.add (createGlobalOptimizerPass ());
1002
- PM.add (createGlobalDCEPass ()); // Remove dead functions.
1003
-
1004
- // The IPO passes may leave cruft around. Clean up after them.
1005
- PM.add (createInstructionCombiningPass ());
1006
- addExtensionsToPM (EP_Peephole, PM);
1007
- PM.add (createJumpThreadingPass ());
1008
-
1009
- // Break up allocas
1010
- PM.add (createSROAPass ());
1011
-
1012
- // LTO provides additional opportunities for tailcall elimination due to
1013
- // link-time inlining, and visibility of nocapture attribute.
1014
- if (OptLevel > 1 )
1015
- PM.add (createTailCallEliminationPass ());
1016
-
1017
- // Infer attributes on declarations, call sites, arguments, etc.
1018
- PM.add (createPostOrderFunctionAttrsLegacyPass ()); // Add nocapture.
1019
- // Run a few AA driven optimizations here and now, to cleanup the code.
1020
- PM.add (createGlobalsAAWrapperPass ()); // IP alias analysis.
1021
-
1022
- PM.add (createLICMPass (LicmMssaOptCap, LicmMssaNoAccForPromotionCap,
1023
- /* AllowSpeculation=*/ true ));
1024
- PM.add (NewGVN ? createNewGVNPass ()
1025
- : createGVNPass (DisableGVNLoadPRE)); // Remove redundancies.
1026
- PM.add (createMemCpyOptPass ()); // Remove dead memcpys.
1027
-
1028
- // Nuke dead stores.
1029
- PM.add (createDeadStoreEliminationPass ());
1030
- PM.add (createMergedLoadStoreMotionPass ()); // Merge ld/st in diamonds.
1031
-
1032
- // More loops are countable; try to optimize them.
1033
- if (EnableLoopFlatten)
1034
- PM.add (createLoopFlattenPass ());
1035
- PM.add (createIndVarSimplifyPass ());
1036
- PM.add (createLoopDeletionPass ());
1037
- if (EnableLoopInterchange)
1038
- PM.add (createLoopInterchangePass ());
1039
-
1040
- if (EnableConstraintElimination)
1041
- PM.add (createConstraintEliminationPass ());
1042
-
1043
- // Unroll small loops and perform peeling.
1044
- PM.add (createSimpleLoopUnrollPass (OptLevel, DisableUnrollLoops,
1045
- ForgetAllSCEVInLoopUnroll));
1046
- PM.add (createLoopDistributePass ());
1047
-
1048
- addVectorPasses (PM, /* IsFullLTO */ true );
1049
-
1050
- addExtensionsToPM (EP_Peephole, PM);
1051
-
1052
- PM.add (createJumpThreadingPass ());
1053
- }
1054
-
1055
- void PassManagerBuilder::addLateLTOOptimizationPasses (
1056
- legacy::PassManagerBase &PM) {
1057
- // See comment in the new PM for justification of scheduling splitting at
1058
- // this stage (\ref buildLTODefaultPipeline).
1059
- if (EnableHotColdSplit)
1060
- PM.add (createHotColdSplittingPass ());
1061
-
1062
- // Delete basic blocks, which optimization passes may have killed.
1063
- PM.add (
1064
- createCFGSimplificationPass (SimplifyCFGOptions ().hoistCommonInsts (true )));
1065
-
1066
- // Drop bodies of available externally objects to improve GlobalDCE.
1067
- PM.add (createEliminateAvailableExternallyPass ());
1068
-
1069
- // Now that we have optimized the program, discard unreachable functions.
1070
- PM.add (createGlobalDCEPass ());
1071
-
1072
- // FIXME: this is profitable (for compiler time) to do at -O0 too, but
1073
- // currently it damages debug info.
1074
- if (MergeFunctions)
1075
- PM.add (createMergeFunctionsPass ());
1076
- }
1077
-
1078
901
LLVMPassManagerBuilderRef LLVMPassManagerBuilderCreate () {
1079
902
PassManagerBuilder *PMB = new PassManagerBuilder ();
1080
903
return wrap (PMB);
0 commit comments