Remove TargetMachine::adjustPassManager
authorBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Thu, 10 Nov 2022 19:11:06 +0000 (20:11 +0100)
committerBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Mon, 28 Nov 2022 09:24:16 +0000 (10:24 +0100)
Since opt no longer supports to run default (O0/O1/O2/O3/Os/Oz)
pipelines using the legacy PM, there are no in-tree uses of
TargetMachine::adjustPassManager remaining. This patch removes the
no longer used adjustPassManager functions.

Reviewed By: aeubanks

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

14 files changed:
llvm/docs/NVPTXUsage.rst
llvm/docs/NewPassManager.rst
llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h
llvm/include/llvm/Target/TargetMachine.h
llvm/lib/LTO/LTO.cpp
llvm/lib/LTO/LTOCodeGenerator.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
llvm/lib/Target/BPF/BPFTargetMachine.cpp
llvm/lib/Target/BPF/BPFTargetMachine.h
llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp
llvm/lib/Target/Hexagon/HexagonTargetMachine.h
llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp
llvm/lib/Target/NVPTX/NVPTXTargetMachine.h

index e4b5ace..5c28a3f 100644 (file)
@@ -328,14 +328,16 @@ optimization pipeline before dead-code elimination.
 
 The NVPTX TargetMachine knows how to schedule ``NVVMReflect`` at the beginning
 of your pass manager; just use the following code when setting up your pass
-manager:
+manager and the PassBuilder will use ``registerPassBuilderCallbacks`` to let
+NVPTXTargetMachine::registerPassBuilderCallbacks add the the pass to the
+pass manager:
 
 .. code-block:: c++
 
     std::unique_ptr<TargetMachine> TM = ...;
-    PassManagerBuilder PMBuilder(...);
-    if (TM)
-      TM->adjustPassManager(PMBuilder);
+    PassBuilder PB(TM);
+    ModulePassManager MPM;
+    PB.parsePassPipeline(MPM, ...);
 
 Reflection Parameters
 ---------------------
index 3d0bcde..cf46480 100644 (file)
@@ -171,8 +171,7 @@ managers created by that ``PassBuilder``. See the documentation for
 
 If a ``PassBuilder`` has a corresponding ``TargetMachine`` for a backend, it
 will call ``TargetMachine::registerPassBuilderCallbacks()`` to allow the
-backend to inject passes into the pipeline. This is equivalent to the legacy
-PM's ``TargetMachine::adjustPassManager()``.
+backend to inject passes into the pipeline.
 
 Clang's ``BackendUtil.cpp`` shows examples of a frontend adding (mostly
 sanitizer) passes to various parts of the pipeline.
@@ -518,10 +517,13 @@ remove its usage.
 Some IR passes are considered part of the backend codegen pipeline even if
 they are LLVM IR passes (whereas all MIR passes are codegen passes). This
 includes anything added via ``TargetPassConfig`` hooks, e.g.
-``TargetPassConfig::addCodeGenPrepare()``. As mentioned before, passes added
-in ``TargetMachine::adjustPassManager()`` are part of the optimization
-pipeline, and should have a corresponding line in
-``TargetMachine::registerPassBuilderCallbacks()``.
+``TargetPassConfig::addCodeGenPrepare()``.
+
+The ``TargetMachine::adjustPassManager()`` function that was used to extend a
+legacy PM with passes on a per target basis has been removed. It was mainly
+used from opt, but since support for using the default pipelines has been
+removed in opt the function isn't needed any longer. In the new PM such
+adjustments are done by using ``TargetMachine::registerPassBuilderCallbacks()``.
 
 Currently there are efforts to make the codegen pipeline work with the new
 PM.
index a55dc31..5f64ca4 100644 (file)
@@ -24,6 +24,7 @@
 //   As of this writing, we don't separate IPO and the Post-IPO SOPT. They
 // are intermingled together, and are driven by a single pass manager (see
 // PassManagerBuilder::populateLTOPassManager()).
+//   FIXME: populateLTOPassManager no longer exists.
 //
 //   The "LTOCodeGenerator" is the driver for the IPO and Post-IPO stages.
 // The "CodeGenerator" here is bit confusing. Don't confuse the "CodeGenerator"
index c86b2f2..e15d2b9 100644 (file)
@@ -46,7 +46,6 @@ class MCSubtargetInfo;
 class MCSymbol;
 class raw_pwrite_stream;
 class PassBuilder;
-class PassManagerBuilder;
 struct PerFunctionMIParsingState;
 class SMDiagnostic;
 class SMRange;
@@ -347,12 +346,7 @@ public:
   /// corresponding to \p F.
   virtual TargetTransformInfo getTargetTransformInfo(const Function &F) const;
 
-  /// Allow the target to modify the pass manager, e.g. by calling
-  /// PassManagerBuilder::addExtension.
-  virtual void adjustPassManager(PassManagerBuilder &) {}
-
-  /// Allow the target to modify the pass pipeline with New Pass Manager
-  /// (similar to adjustPassManager for Legacy Pass manager).
+  /// Allow the target to modify the pass pipeline.
   virtual void registerPassBuilderCallbacks(PassBuilder &) {}
 
   /// Allow the target to register alias analyses with the AAManager for use
index 54c1732..27787d9 100644 (file)
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/VCSRevision.h"
 #include "llvm/Support/raw_ostream.h"
-#include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/IPO.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
 #include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/Utils/FunctionImportUtils.h"
 #include "llvm/Transforms/Utils/SplitModule.h"
index c9ecc6d..b1f0cf9 100644 (file)
@@ -36,7 +36,6 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/PassTimingInfo.h"
 #include "llvm/IR/Verifier.h"
-#include "llvm/InitializePasses.h"
 #include "llvm/LTO/LTO.h"
 #include "llvm/LTO/LTOBackend.h"
 #include "llvm/LTO/legacy/LTOModule.h"
@@ -60,7 +59,6 @@
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Transforms/IPO/Internalize.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
 #include "llvm/Transforms/IPO/WholeProgramDevirt.h"
 #include "llvm/Transforms/ObjCARC.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
index df43fb0..2199630 100644 (file)
@@ -51,7 +51,6 @@
 #include "llvm/Transforms/IPO/AlwaysInliner.h"
 #include "llvm/Transforms/IPO/GlobalDCE.h"
 #include "llvm/Transforms/IPO/Internalize.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Scalar/InferAddressSpaces.h"
@@ -576,80 +575,6 @@ static bool mustPreserveGV(const GlobalValue &GV) {
   return !GV.use_empty();
 }
 
-void AMDGPUTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
-  Builder.DivergentTarget = true;
-
-  bool EnableOpt = getOptLevel() > CodeGenOpt::None;
-  bool Internalize = InternalizeSymbols;
-  bool EarlyInline = EarlyInlineAll && EnableOpt && !EnableFunctionCalls;
-  bool AMDGPUAA = EnableAMDGPUAliasAnalysis && EnableOpt;
-  bool LibCallSimplify = EnableLibCallSimplify && EnableOpt;
-  bool PromoteKernelArguments =
-      EnablePromoteKernelArguments && getOptLevel() > CodeGenOpt::Less;
-
-  if (EnableFunctionCalls) {
-    delete Builder.Inliner;
-    Builder.Inliner = createFunctionInliningPass();
-  }
-
-  Builder.addExtension(
-    PassManagerBuilder::EP_ModuleOptimizerEarly,
-    [Internalize, EarlyInline, AMDGPUAA, this](const PassManagerBuilder &,
-                                               legacy::PassManagerBase &PM) {
-      if (AMDGPUAA) {
-        PM.add(createAMDGPUAAWrapperPass());
-        PM.add(createAMDGPUExternalAAWrapperPass());
-      }
-      PM.add(createAMDGPUUnifyMetadataPass());
-      PM.add(createAMDGPUPrintfRuntimeBinding());
-      if (Internalize)
-        PM.add(createInternalizePass(mustPreserveGV));
-      PM.add(createAMDGPUPropagateAttributesLatePass(this));
-      if (Internalize)
-        PM.add(createGlobalDCEPass());
-      if (EarlyInline)
-        PM.add(createAMDGPUAlwaysInlinePass(false));
-  });
-
-  Builder.addExtension(
-    PassManagerBuilder::EP_EarlyAsPossible,
-    [AMDGPUAA, LibCallSimplify, this](const PassManagerBuilder &,
-                                      legacy::PassManagerBase &PM) {
-      if (AMDGPUAA) {
-        PM.add(createAMDGPUAAWrapperPass());
-        PM.add(createAMDGPUExternalAAWrapperPass());
-      }
-      PM.add(llvm::createAMDGPUPropagateAttributesEarlyPass(this));
-      PM.add(llvm::createAMDGPUUseNativeCallsPass());
-      if (LibCallSimplify)
-        PM.add(llvm::createAMDGPUSimplifyLibCallsPass(this));
-  });
-
-  Builder.addExtension(
-    PassManagerBuilder::EP_CGSCCOptimizerLate,
-    [EnableOpt, PromoteKernelArguments](const PassManagerBuilder &,
-                                        legacy::PassManagerBase &PM) {
-      // Add promote kernel arguments pass to the opt pipeline right before
-      // infer address spaces which is needed to do actual address space
-      // rewriting.
-      if (PromoteKernelArguments)
-        PM.add(createAMDGPUPromoteKernelArgumentsPass());
-
-      // Add infer address spaces pass to the opt pipeline after inlining
-      // but before SROA to increase SROA opportunities.
-      PM.add(createInferAddressSpacesPass());
-
-      // This should run after inlining to have any chance of doing anything,
-      // and before other cleanup optimizations.
-      PM.add(createAMDGPULowerKernelAttributesPass());
-
-      // Promote alloca to vector before SROA and loop unroll. If we manage
-      // to eliminate allocas before unroll we may choose to unroll less.
-      if (EnableOpt)
-        PM.add(createAMDGPUPromoteAllocaToVector());
-  });
-}
-
 void AMDGPUTargetMachine::registerDefaultAliasAnalyses(AAManager &AAM) {
   AAM.registerFunctionAnalysis<AMDGPUAA>();
 }
index 567cc9d..caa03de 100644 (file)
@@ -50,8 +50,6 @@ public:
     return TLOF.get();
   }
 
-  void adjustPassManager(PassManagerBuilder &) override;
-
   void registerPassBuilderCallbacks(PassBuilder &PB) override;
   void registerDefaultAliasAnalyses(AAManager &) override;
 
index 97d9ed3..0c22185 100644 (file)
@@ -24,7 +24,6 @@
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Support/FormattedStream.h"
 #include "llvm/Target/TargetOptions.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/SimplifyCFG.h"
 #include "llvm/Transforms/Utils/SimplifyCFGOptions.h"
@@ -102,28 +101,6 @@ TargetPassConfig *BPFTargetMachine::createPassConfig(PassManagerBase &PM) {
   return new BPFPassConfig(*this, PM);
 }
 
-void BPFTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
- Builder.addExtension(
-      PassManagerBuilder::EP_EarlyAsPossible,
-      [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
-        PM.add(createBPFAbstractMemberAccess(this));
-        PM.add(createBPFPreserveDIType());
-        PM.add(createBPFIRPeephole());
-      });
-
-  Builder.addExtension(
-      PassManagerBuilder::EP_Peephole,
-      [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
-        PM.add(createCFGSimplificationPass(
-            SimplifyCFGOptions().hoistCommonInsts(true)));
-      });
-  Builder.addExtension(
-      PassManagerBuilder::EP_ModuleOptimizerEarly,
-      [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
-        PM.add(createBPFAdjustOpt());
-      });
-}
-
 void BPFTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
   PB.registerPipelineStartEPCallback(
       [=](ModulePassManager &MPM, OptimizationLevel) {
index fede520..1a3afb0 100644 (file)
@@ -40,7 +40,6 @@ public:
     return TLOF.get();
   }
 
-  void adjustPassManager(PassManagerBuilder &) override;
   void registerPassBuilderCallbacks(PassBuilder &PB) override;
 };
 }
index 4e04939..0f4e866 100644 (file)
@@ -27,7 +27,6 @@
 #include "llvm/MC/TargetRegistry.h"
 #include "llvm/Passes/PassBuilder.h"
 #include "llvm/Support/CommandLine.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
 #include "llvm/Transforms/Scalar.h"
 
 using namespace llvm;
@@ -273,19 +272,6 @@ HexagonTargetMachine::getSubtargetImpl(const Function &F) const {
   return I.get();
 }
 
-void HexagonTargetMachine::adjustPassManager(PassManagerBuilder &PMB) {
-  PMB.addExtension(
-    PassManagerBuilder::EP_LateLoopOptimizations,
-    [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
-      PM.add(createHexagonLoopIdiomPass());
-    });
-  PMB.addExtension(
-      PassManagerBuilder::EP_LoopOptimizerEnd,
-      [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
-        PM.add(createHexagonVectorLoopCarriedReuseLegacyPass());
-      });
-}
-
 void HexagonTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
   PB.registerLateLoopOptimizationsEPCallback(
       [=](LoopPassManager &LPM, OptimizationLevel Level) {
index 947df75..de2e0b5 100644 (file)
@@ -36,7 +36,6 @@ public:
 
   static unsigned getModuleMatchQuality(const Module &M);
 
-  void adjustPassManager(PassManagerBuilder &PMB) override;
   void registerPassBuilderCallbacks(PassBuilder &PB) override;
   TargetPassConfig *createPassConfig(PassManagerBase &PM) override;
   TargetTransformInfo getTargetTransformInfo(const Function &F) const override;
index 597b8af..3a805cd 100644 (file)
@@ -31,7 +31,6 @@
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
-#include "llvm/Transforms/IPO/PassManagerBuilder.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Vectorize.h"
@@ -201,15 +200,6 @@ TargetPassConfig *NVPTXTargetMachine::createPassConfig(PassManagerBase &PM) {
   return new NVPTXPassConfig(*this, PM);
 }
 
-void NVPTXTargetMachine::adjustPassManager(PassManagerBuilder &Builder) {
-  Builder.addExtension(
-    PassManagerBuilder::EP_EarlyAsPossible,
-    [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
-      PM.add(createNVVMReflectPass(Subtarget.getSmVersion()));
-      PM.add(createNVVMIntrRangePass(Subtarget.getSmVersion()));
-    });
-}
-
 void NVPTXTargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
   PB.registerPipelineParsingCallback(
       [](StringRef PassName, FunctionPassManager &PM,
index 491e721..6f1ee9c 100644 (file)
@@ -62,7 +62,6 @@ public:
     return TLOF.get();
   }
 
-  void adjustPassManager(PassManagerBuilder &) override;
   void registerPassBuilderCallbacks(PassBuilder &PB) override;
 
   TargetTransformInfo getTargetTransformInfo(const Function &F) const override;