[Pipeline] Move some GlobalOpt/GlobalDCE runs into simplification pipeline
authorArthur Eubanks <aeubanks@google.com>
Mon, 13 Mar 2023 17:45:32 +0000 (10:45 -0700)
committerArthur Eubanks <aeubanks@google.com>
Tue, 14 Mar 2023 16:01:14 +0000 (09:01 -0700)
These are very clearly more simplification than optimization.

Mostly NFC, except for some ordering around passes that don't really matter.

Reviewed By: nikic

Differential Revision: https://reviews.llvm.org/D145967

llvm/lib/Passes/PassBuilderPipelines.cpp

index 9efc161..c3a8506 100644 (file)
@@ -1072,6 +1072,14 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
 
   MPM.addPass(CoroCleanupPass());
 
+  // Optimize globals now that functions are fully simplified.
+  MPM.addPass(GlobalOptPass());
+
+  // Remove dead code, except in the ThinLTO pre-link pipeline where we may want
+  // to keep available_externally functions.
+  if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink)
+    MPM.addPass(GlobalDCEPass());
+
   if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) {
     MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
     MPM.addPass(ModuleMemProfilerPass());
@@ -1227,10 +1235,6 @@ PassBuilder::buildModuleOptimizationPipeline(OptimizationLevel Level,
                            LTOPhase == ThinOrFullLTOPhase::FullLTOPreLink);
   ModulePassManager MPM;
 
-  // Optimize globals now that the module is fully simplified.
-  MPM.addPass(GlobalOptPass());
-  MPM.addPass(GlobalDCEPass());
-
   // Run partial inlining pass to partially inline functions that have
   // large bodies.
   if (RunPartialInlining)
@@ -1475,9 +1479,6 @@ PassBuilder::buildThinLTOPreLinkDefaultPipeline(OptimizationLevel Level) {
   if (RunPartialInlining)
     MPM.addPass(PartialInlinerPass());
 
-  // Reduce the size of the IR as much as possible.
-  MPM.addPass(GlobalOptPass());
-
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
       PGOOpt->Action == PGOOptions::SampleUse)
     MPM.addPass(PseudoProbeUpdatePass());