diff --git a/llvm/docs/NVPTXUsage.rst b/llvm/docs/NVPTXUsage.rst --- a/llvm/docs/NVPTXUsage.rst +++ b/llvm/docs/NVPTXUsage.rst @@ -328,14 +328,16 @@ 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 TM = ...; - PassManagerBuilder PMBuilder(...); - if (TM) - TM->adjustPassManager(PMBuilder); + PassBuilder PB(TM); + ModulePassManager MPM; + PB.parsePassPipeline(MPM, ...); Reflection Parameters --------------------- diff --git a/llvm/docs/NewPassManager.rst b/llvm/docs/NewPassManager.rst --- a/llvm/docs/NewPassManager.rst +++ b/llvm/docs/NewPassManager.rst @@ -171,8 +171,7 @@ 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 @@ 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. diff --git a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h --- a/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h +++ b/llvm/include/llvm/LTO/legacy/LTOCodeGenerator.h @@ -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" diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h --- a/llvm/include/llvm/Target/TargetMachine.h +++ b/llvm/include/llvm/Target/TargetMachine.h @@ -46,7 +46,6 @@ class MCSymbol; class raw_pwrite_stream; class PassBuilder; -class PassManagerBuilder; struct PerFunctionMIParsingState; class SMDiagnostic; class SMRange; @@ -347,12 +346,7 @@ /// 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 diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -49,10 +49,8 @@ #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" diff --git a/llvm/lib/LTO/LTOCodeGenerator.cpp b/llvm/lib/LTO/LTOCodeGenerator.cpp --- a/llvm/lib/LTO/LTOCodeGenerator.cpp +++ b/llvm/lib/LTO/LTOCodeGenerator.cpp @@ -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" diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h @@ -50,8 +50,6 @@ return TLOF.get(); } - void adjustPassManager(PassManagerBuilder &) override; - void registerPassBuilderCallbacks(PassBuilder &PB) override; void registerDefaultAliasAnalyses(AAManager &) override; diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -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 @@ 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(); } diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.h b/llvm/lib/Target/BPF/BPFTargetMachine.h --- a/llvm/lib/Target/BPF/BPFTargetMachine.h +++ b/llvm/lib/Target/BPF/BPFTargetMachine.h @@ -40,7 +40,6 @@ return TLOF.get(); } - void adjustPassManager(PassManagerBuilder &) override; void registerPassBuilderCallbacks(PassBuilder &PB) override; }; } diff --git a/llvm/lib/Target/BPF/BPFTargetMachine.cpp b/llvm/lib/Target/BPF/BPFTargetMachine.cpp --- a/llvm/lib/Target/BPF/BPFTargetMachine.cpp +++ b/llvm/lib/Target/BPF/BPFTargetMachine.cpp @@ -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 @@ 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) { diff --git a/llvm/lib/Target/Hexagon/HexagonTargetMachine.h b/llvm/lib/Target/Hexagon/HexagonTargetMachine.h --- a/llvm/lib/Target/Hexagon/HexagonTargetMachine.h +++ b/llvm/lib/Target/Hexagon/HexagonTargetMachine.h @@ -36,7 +36,6 @@ 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; diff --git a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp --- a/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp +++ b/llvm/lib/Target/Hexagon/HexagonTargetMachine.cpp @@ -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 @@ 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) { diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.h b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.h --- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.h +++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.h @@ -62,7 +62,6 @@ return TLOF.get(); } - void adjustPassManager(PassManagerBuilder &) override; void registerPassBuilderCallbacks(PassBuilder &PB) override; TargetTransformInfo getTargetTransformInfo(const Function &F) const override; diff --git a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp --- a/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp +++ b/llvm/lib/Target/NVPTX/NVPTXTargetMachine.cpp @@ -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 @@ 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,