[llvm] 964f810 - [NFC] Combine runNewPMPasses() and runNewPMCustomPasses()

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 12 16:45:00 PST 2021


Author: Arthur Eubanks
Date: 2021-02-12T16:44:52-08:00
New Revision: 964f8103c58db5917c66ef39f50acf2004c90144

URL: https://github.com/llvm/llvm-project/commit/964f8103c58db5917c66ef39f50acf2004c90144
DIFF: https://github.com/llvm/llvm-project/commit/964f8103c58db5917c66ef39f50acf2004c90144.diff

LOG: [NFC] Combine runNewPMPasses() and runNewPMCustomPasses()

I've already witnessed two separate changes missing runNewPMPasses()
because runNewPMCustomPasses() is so similar.

This cleans up some duplicated code.

Reviewed By: tejohnson

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

Added: 
    

Modified: 
    llvm/lib/LTO/LTOBackend.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index bf49e5d8bc11..5eaa621292f9 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -224,11 +224,6 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   StandardInstrumentations SI(Conf.DebugPassManager);
   SI.registerCallbacks(PIC);
   PassBuilder PB(Conf.DebugPassManager, TM, Conf.PTO, PGOOpt, &PIC);
-  AAManager AA;
-
-  // Parse a custom AA pipeline if asked to.
-  if (auto Err = PB.parseAAPipeline(AA, "default"))
-    report_fatal_error("Error parsing default AA pipeline");
 
   RegisterPassPlugins(Conf.PassPlugins, PB);
 
@@ -243,6 +238,16 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
     TLII->disableAllFunctions();
   FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
 
+  AAManager AA;
+  // Parse a custom AA pipeline if asked to.
+  if (!Conf.AAPipeline.empty()) {
+    if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline)) {
+      report_fatal_error("unable to parse AA pipeline description '" +
+                         Conf.AAPipeline + "': " + toString(std::move(Err)));
+    }
+  } else {
+    AA = PB.buildDefaultAAPipeline();
+  }
   // Register the AA manager first so that our version is the one used.
   FAM.registerPass([&] { return std::move(AA); });
 
@@ -277,10 +282,17 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
     break;
   }
 
-  if (IsThinLTO)
+  // Parse a custom pipeline if asked to.
+  if (!Conf.OptPipeline.empty()) {
+    if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline)) {
+      report_fatal_error("unable to parse pass pipeline description '" +
+                         Conf.OptPipeline + "': " + toString(std::move(Err)));
+    }
+  } else if (IsThinLTO) {
     MPM.addPass(PB.buildThinLTODefaultPipeline(OL, ImportSummary));
-  else
+  } else {
     MPM.addPass(PB.buildLTODefaultPipeline(OL, ExportSummary));
+  }
 
   if (!Conf.DisableVerify)
     MPM.addPass(VerifierPass());
@@ -288,55 +300,6 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   MPM.run(Mod, MAM);
 }
 
-static void runNewPMCustomPasses(const Config &Conf, Module &Mod,
-                                 TargetMachine *TM) {
-  PassBuilder PB(Conf.DebugPassManager, TM);
-  AAManager AA;
-
-  // Parse a custom AA pipeline if asked to.
-  if (!Conf.AAPipeline.empty())
-    if (auto Err = PB.parseAAPipeline(AA, Conf.AAPipeline))
-      report_fatal_error("unable to parse AA pipeline description '" +
-                         Conf.AAPipeline + "': " + toString(std::move(Err)));
-
-  RegisterPassPlugins(Conf.PassPlugins, PB);
-
-  LoopAnalysisManager LAM;
-  FunctionAnalysisManager FAM;
-  CGSCCAnalysisManager CGAM;
-  ModuleAnalysisManager MAM;
-
-  std::unique_ptr<TargetLibraryInfoImpl> TLII(
-      new TargetLibraryInfoImpl(Triple(TM->getTargetTriple())));
-  if (Conf.Freestanding)
-    TLII->disableAllFunctions();
-  FAM.registerPass([&] { return TargetLibraryAnalysis(*TLII); });
-
-  // Register the AA manager first so that our version is the one used.
-  FAM.registerPass([&] { return std::move(AA); });
-
-  // Register all the basic analyses with the managers.
-  PB.registerModuleAnalyses(MAM);
-  PB.registerCGSCCAnalyses(CGAM);
-  PB.registerFunctionAnalyses(FAM);
-  PB.registerLoopAnalyses(LAM);
-  PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
-
-  ModulePassManager MPM;
-
-  // Always verify the input.
-  MPM.addPass(VerifierPass());
-
-  // Now, add all the passes we've been requested to.
-  if (auto Err = PB.parsePassPipeline(MPM, Conf.OptPipeline))
-    report_fatal_error("unable to parse pass pipeline description '" +
-                       Conf.OptPipeline + "': " + toString(std::move(Err)));
-
-  if (!Conf.DisableVerify)
-    MPM.addPass(VerifierPass());
-  MPM.run(Mod, MAM);
-}
-
 static void runOldPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
                            bool IsThinLTO, ModuleSummaryIndex *ExportSummary,
                            const ModuleSummaryIndex *ImportSummary) {
@@ -392,13 +355,12 @@ bool lto::opt(const Config &Conf, TargetMachine *TM, unsigned Task, Module &Mod,
                                /*Cmdline*/ CmdArgs);
   }
   // FIXME: Plumb the combined index into the new pass manager.
-  if (!Conf.OptPipeline.empty())
-    runNewPMCustomPasses(Conf, Mod, TM);
-  else if (Conf.UseNewPM)
+  if (Conf.UseNewPM) {
     runNewPMPasses(Conf, Mod, TM, Conf.OptLevel, IsThinLTO, ExportSummary,
                    ImportSummary);
-  else
+  } else {
     runOldPMPasses(Conf, Mod, TM, IsThinLTO, ExportSummary, ImportSummary);
+  }
   return !Conf.PostOptModuleHook || Conf.PostOptModuleHook(Task, Mod);
 }
 


        


More information about the llvm-commits mailing list