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 @@ -347,10 +347,6 @@ /// 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). virtual void registerPassBuilderCallbacks(PassBuilder &) {} 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 @@ -576,80 +576,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 @@ -102,28 +102,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 @@ -273,19 +273,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 @@ -201,15 +201,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, diff --git a/llvm/tools/opt/opt.cpp b/llvm/tools/opt/opt.cpp --- a/llvm/tools/opt/opt.cpp +++ b/llvm/tools/opt/opt.cpp @@ -52,8 +52,6 @@ #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/YAMLTraits.h" #include "llvm/Target/TargetMachine.h" -#include "llvm/Transforms/IPO/AlwaysInliner.h" -#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/IPO/WholeProgramDevirt.h" #include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/Debugify.h" @@ -324,40 +322,6 @@ PM.add(createVerifierPass()); } -/// This routine adds optimization passes based on selected optimization level, -/// OptLevel. -/// -/// OptLevel - Optimization Level -static void AddOptimizationPasses(legacy::PassManagerBase &MPM, - legacy::FunctionPassManager &FPM, - TargetMachine *TM, unsigned OptLevel, - unsigned SizeLevel) { - if (!NoVerify || VerifyEach) - FPM.add(createVerifierPass()); // Verify that input is correct - - PassManagerBuilder Builder; - Builder.OptLevel = OptLevel; - Builder.SizeLevel = SizeLevel; - - if (OptLevel > 1) { - Builder.Inliner = createFunctionInliningPass(OptLevel, SizeLevel, false); - } else { - Builder.Inliner = createAlwaysInlinerLegacyPass(); - } - Builder.DisableUnrollLoops = (DisableLoopUnrolling.getNumOccurrences() > 0) ? - DisableLoopUnrolling : OptLevel == 0; - - Builder.LoopVectorize = OptLevel > 1 && SizeLevel < 2; - - Builder.SLPVectorize = OptLevel > 1 && SizeLevel < 2; - - if (TM) - TM->adjustPassManager(Builder); - - Builder.populateFunctionPassManager(FPM); - Builder.populateModulePassManager(MPM); -} - //===----------------------------------------------------------------------===// // CodeGen-related helper functions. // @@ -791,6 +755,12 @@ : 1; } + if (OptLevelO0 || OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || + OptLevelO3) { + errs() << "Cannot use -O# with legacy PM.\n"; + return 1; + } + // Create a PassManager to hold and optimize the collection of passes we are // about to build. If the -debugify-each option is set, wrap each pass with // the (-check)-debugify passes. @@ -830,12 +800,6 @@ } std::unique_ptr FPasses; - if (OptLevelO0 || OptLevelO1 || OptLevelO2 || OptLevelOs || OptLevelOz || - OptLevelO3) { - FPasses.reset(new legacy::FunctionPassManager(M.get())); - FPasses->add(createTargetTransformInfoWrapperPass( - TM ? TM->getTargetIRAnalysis() : TargetIRAnalysis())); - } if (PrintBreakpoints) { // Default to standard output. @@ -864,36 +828,6 @@ // Create a new optimization pass for each one specified on the command line for (unsigned i = 0; i < PassList.size(); ++i) { - if (OptLevelO0 && OptLevelO0.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 0, 0); - OptLevelO0 = false; - } - - if (OptLevelO1 && OptLevelO1.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 1, 0); - OptLevelO1 = false; - } - - if (OptLevelO2 && OptLevelO2.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 0); - OptLevelO2 = false; - } - - if (OptLevelOs && OptLevelOs.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 1); - OptLevelOs = false; - } - - if (OptLevelOz && OptLevelOz.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 2); - OptLevelOz = false; - } - - if (OptLevelO3 && OptLevelO3.getPosition() < PassList.getPosition(i)) { - AddOptimizationPasses(Passes, *FPasses, TM.get(), 3, 0); - OptLevelO3 = false; - } - const PassInfo *PassInf = PassList[i]; Pass *P = nullptr; if (PassInf->getNormalCtor()) @@ -905,24 +839,6 @@ addPass(Passes, P); } - if (OptLevelO0) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 0, 0); - - if (OptLevelO1) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 1, 0); - - if (OptLevelO2) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 0); - - if (OptLevelOs) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 1); - - if (OptLevelOz) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 2, 2); - - if (OptLevelO3) - AddOptimizationPasses(Passes, *FPasses, TM.get(), 3, 0); - if (FPasses) { FPasses->doInitialization(); for (Function &F : *M)