Index: include/llvm/Target/TargetMachine.h =================================================================== --- include/llvm/Target/TargetMachine.h +++ include/llvm/Target/TargetMachine.h @@ -34,6 +34,7 @@ class MCSubtargetInfo; class MCSymbol; class raw_pwrite_stream; +class PassManagerBuilder; class Target; class TargetIntrinsicInfo; class TargetIRAnalysis; @@ -205,10 +206,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 @@ -33,6 +33,7 @@ #include "llvm/Support/TargetRegistry.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/IPO/AlwaysInliner.h" +#include "llvm/Transforms/IPO/PassManagerBuilder.h" #include "llvm/Transforms/Scalar.h" #include "llvm/Transforms/Scalar/GVN.h" #include "llvm/Transforms/Vectorize.h" @@ -205,8 +206,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 @@ -28,6 +28,7 @@ #include "llvm/Support/TargetRegistry.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" @@ -167,9 +168,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);