Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -20,6 +20,7 @@ #include "llvm/Pass.h" #include "llvm/Support/CodeGen.h" #include "llvm/Target/TargetOptions.h" +#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include #include @@ -214,10 +215,9 @@ /// uses this to answer queries about the IR. virtual TargetIRAnalysis getTargetIRAnalysis(); - /// Add target-specific function passes that should be run as early as - /// possible in the optimization pipeline. Most TargetMachines have no such - /// passes. - virtual void addEarlyAsPossiblePasses(PassManagerBase &) {} + /// Allow the target to modify the pass manager, e.g. by calling + /// PassManagerBuilder::addExtension. + virtual void adjustPassManager(PassManagerBuilder &) {} /// These enums are meant to be passed into addPassesToEmitFile to indicate /// what type of file to emit, and returned by it to indicate what type of Index: lib/Target/AMDGPU/AMDGPUTargetMachine.h =================================================================== --- lib/Target/AMDGPU/AMDGPUTargetMachine.h +++ lib/Target/AMDGPU/AMDGPUTargetMachine.h @@ -57,7 +57,8 @@ TargetLoweringObjectFile *getObjFileLowering() const override { return TLOF.get(); } - void addEarlyAsPossiblePasses(PassManagerBase &PM) override; + + void adjustPassManager(PassManagerBuilder &) override; }; //===----------------------------------------------------------------------===// Index: lib/Target/AMDGPU/AMDGPUTargetMachine.cpp =================================================================== --- lib/Target/AMDGPU/AMDGPUTargetMachine.cpp +++ lib/Target/AMDGPU/AMDGPUTargetMachine.cpp @@ -199,8 +199,12 @@ FSAttr.getValueAsString(); } -void AMDGPUTargetMachine::addEarlyAsPossiblePasses(PassManagerBase &PM) { - PM.add(createAMDGPUUnifyMetadataPass()); +void AMDGPUTargetMachine::adjustPassManager(PassManagerBuilder &Builder) { + Builder.addExtension( + PassManagerBuilder::EP_EarlyAsPossible, + [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) { + PM.add(createAMDGPUUnifyMetadataPass()); + }); } //===----------------------------------------------------------------------===// Index: lib/Target/NVPTX/NVPTXTargetMachine.h =================================================================== --- lib/Target/NVPTX/NVPTXTargetMachine.h +++ lib/Target/NVPTX/NVPTXTargetMachine.h @@ -61,7 +61,8 @@ return TLOF.get(); } - void addEarlyAsPossiblePasses(PassManagerBase &PM) override; + void adjustPassManager(PassManagerBuilder &) override; + TargetIRAnalysis getTargetIRAnalysis() override; }; // NVPTXTargetMachine. Index: lib/Target/NVPTX/NVPTXTargetMachine.cpp =================================================================== --- lib/Target/NVPTX/NVPTXTargetMachine.cpp +++ lib/Target/NVPTX/NVPTXTargetMachine.cpp @@ -176,9 +176,13 @@ return new NVPTXPassConfig(this, PM); } -void NVPTXTargetMachine::addEarlyAsPossiblePasses(PassManagerBase &PM) { - PM.add(createNVVMReflectPass()); - PM.add(createNVVMIntrRangePass(Subtarget.getSmVersion())); +void NVPTXTargetMachine::adjustPassManager(PassManagerBuilder &Builder) { + Builder.addExtension( + PassManagerBuilder::EP_EarlyAsPossible, + [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) { + PM.add(createNVVMReflectPass()); + PM.add(createNVVMIntrRangePass(Subtarget.getSmVersion())); + }); } TargetIRAnalysis NVPTXTargetMachine::getTargetIRAnalysis() { Index: tools/opt/opt.cpp =================================================================== --- tools/opt/opt.cpp +++ tools/opt/opt.cpp @@ -287,13 +287,8 @@ Builder.SLPVectorize = DisableSLPVectorization ? false : OptLevel > 1 && SizeLevel < 2; - // Add target-specific passes that need to run as early as possible. if (TM) - Builder.addExtension( - PassManagerBuilder::EP_EarlyAsPossible, - [&](const PassManagerBuilder &, legacy::PassManagerBase &PM) { - TM->addEarlyAsPossiblePasses(PM); - }); + TM->adjustPassManager(Builder); if (Coroutines) addCoroutinePassesToExtensionPoints(Builder);