[llvm-branch-commits] [CodeGen][NewPM] Plumb MCContext through buildCodeGenPipeline (PR #182794)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Sun Feb 22 20:12:09 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
Otherwise we cannot create an MCStreamer without getting MMI, which we
cannot do until we have started running AsmPrinter without also plumbing
MMI through CodeGenPassBuilder.
---
Full diff: https://github.com/llvm/llvm-project/pull/182794.diff
9 Files Affected:
- (modified) llvm/include/llvm/Passes/CodeGenPassBuilder.h (+7-6)
- (modified) llvm/include/llvm/Target/TargetMachine.h (+5-6)
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp (+2-2)
- (modified) llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h (+1-1)
- (modified) llvm/lib/Target/AMDGPU/R600TargetMachine.cpp (+2-2)
- (modified) llvm/lib/Target/AMDGPU/R600TargetMachine.h (+1-1)
- (modified) llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp (+3-3)
- (modified) llvm/lib/Target/X86/X86TargetMachine.h (+1-1)
- (modified) llvm/tools/llc/NewPMDriver.cpp (+3-2)
``````````diff
diff --git a/llvm/include/llvm/Passes/CodeGenPassBuilder.h b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
index 8130737ae4c20..e3829d104f280 100644
--- a/llvm/include/llvm/Passes/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/Passes/CodeGenPassBuilder.h
@@ -164,6 +164,9 @@ class PassManagerWrapper {
friend class CodeGenPassBuilder;
};
+using CreateMCStreamer =
+ std::function<Expected<std::unique_ptr<MCStreamer>>(TargetMachine &)>;
+
/// This class provides access to building LLVM's passes.
///
/// Its members provide the baseline state available to passes during their
@@ -196,8 +199,8 @@ template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
}
Error buildPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
- raw_pwrite_stream *DwoOut,
- CodeGenFileType FileType) const;
+ raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
+ MCContext &Ctx) const;
PassInstrumentationCallbacks *getPassInstrumentationCallbacks() const {
return PIC;
@@ -487,8 +490,6 @@ template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
void addPostBBSections(PassManagerWrapper &PMW) const {}
- using CreateMCStreamer =
- std::function<Expected<std::unique_ptr<MCStreamer>>(MCContext &)>;
void addAsmPrinter(PassManagerWrapper &PMW, CreateMCStreamer) const {
llvm_unreachable("addAsmPrinter is not overridden");
}
@@ -562,7 +563,7 @@ template <typename DerivedT, typename TargetMachineT> class CodeGenPassBuilder {
template <typename Derived, typename TargetMachineT>
Error CodeGenPassBuilder<Derived, TargetMachineT>::buildPipeline(
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
- CodeGenFileType FileType) const {
+ CodeGenFileType FileType, MCContext &Ctx) const {
auto StartStopInfo = TargetPassConfig::getStartStopInfo(*PIC);
if (!StartStopInfo)
return StartStopInfo.takeError();
@@ -601,7 +602,7 @@ Error CodeGenPassBuilder<Derived, TargetMachineT>::buildPipeline(
if (PrintAsm) {
derived().addAsmPrinter(
- PMW, [this, &Out, DwoOut, FileType](MCContext &Ctx) {
+ PMW, [this, &Out, DwoOut, FileType, &Ctx](TargetMachine &TM) {
return this->TM.createMCStreamer(Out, DwoOut, FileType, Ctx);
});
}
diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h
index a7217444e3c1e..4d9b52c9bf191 100644
--- a/llvm/include/llvm/Target/TargetMachine.h
+++ b/llvm/include/llvm/Target/TargetMachine.h
@@ -485,12 +485,11 @@ class LLVM_ABI TargetMachine {
return nullptr;
}
- virtual Error buildCodeGenPipeline(ModulePassManager &MPM,
- raw_pwrite_stream &Out,
- raw_pwrite_stream *DwoOut,
- CodeGenFileType FileType,
- const CGPassBuilderOption &Opt,
- PassInstrumentationCallbacks *PIC) {
+ virtual Error
+ buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
+ raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
+ const CGPassBuilderOption &Opt, MCContext &Ctx,
+ PassInstrumentationCallbacks *PIC) {
return make_error<StringError>("buildCodeGenPipeline is not overridden",
inconvertibleErrorCode());
}
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
index 49c60c254f6f7..433a9065b8bc1 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.cpp
@@ -1228,10 +1228,10 @@ GCNTargetMachine::getTargetTransformInfo(const Function &F) const {
Error GCNTargetMachine::buildCodeGenPipeline(
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
- CodeGenFileType FileType, const CGPassBuilderOption &Opts,
+ CodeGenFileType FileType, const CGPassBuilderOption &Opts, MCContext &Ctx,
PassInstrumentationCallbacks *PIC) {
AMDGPUCodeGenPassBuilder CGPB(*this, Opts, PIC);
- return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
+ return CGPB.buildPipeline(MPM, Out, DwoOut, FileType, Ctx);
}
ScheduleDAGInstrs *
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
index 06a3047196b8a..362899bd260eb 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetMachine.h
@@ -100,7 +100,7 @@ class GCNTargetMachine final : public AMDGPUTargetMachine {
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
raw_pwrite_stream *DwoOut,
CodeGenFileType FileType,
- const CGPassBuilderOption &Opts,
+ const CGPassBuilderOption &Opts, MCContext &Ctx,
PassInstrumentationCallbacks *PIC) override;
void registerMachineRegisterInfoCallback(MachineFunction &MF) const override;
diff --git a/llvm/lib/Target/AMDGPU/R600TargetMachine.cpp b/llvm/lib/Target/AMDGPU/R600TargetMachine.cpp
index 47719673a840c..fecf32942bddd 100644
--- a/llvm/lib/Target/AMDGPU/R600TargetMachine.cpp
+++ b/llvm/lib/Target/AMDGPU/R600TargetMachine.cpp
@@ -164,10 +164,10 @@ TargetPassConfig *R600TargetMachine::createPassConfig(PassManagerBase &PM) {
Error R600TargetMachine::buildCodeGenPipeline(
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
- CodeGenFileType FileType, const CGPassBuilderOption &Opts,
+ CodeGenFileType FileType, const CGPassBuilderOption &Opts, MCContext &Ctx,
PassInstrumentationCallbacks *PIC) {
R600CodeGenPassBuilder CGPB(*this, Opts, PIC);
- return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
+ return CGPB.buildPipeline(MPM, Out, DwoOut, FileType, Ctx);
}
MachineFunctionInfo *R600TargetMachine::createMachineFunctionInfo(
diff --git a/llvm/lib/Target/AMDGPU/R600TargetMachine.h b/llvm/lib/Target/AMDGPU/R600TargetMachine.h
index 7985ef136cead..7a240cde5363f 100644
--- a/llvm/lib/Target/AMDGPU/R600TargetMachine.h
+++ b/llvm/lib/Target/AMDGPU/R600TargetMachine.h
@@ -41,7 +41,7 @@ class R600TargetMachine final : public AMDGPUTargetMachine {
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
raw_pwrite_stream *DwoOut,
CodeGenFileType FileType,
- const CGPassBuilderOption &Opt,
+ const CGPassBuilderOption &Opt, MCContext &Ctx,
PassInstrumentationCallbacks *PIC) override;
const TargetSubtargetInfo *getSubtargetImpl(const Function &) const override;
diff --git a/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp b/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
index 11d843c8d371e..e7607452e56b1 100644
--- a/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
+++ b/llvm/lib/Target/X86/X86CodeGenPassBuilder.cpp
@@ -257,15 +257,15 @@ void X86CodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW,
} // namespace
-void X86TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB) {
+void X86TargetMachine::registerPassBuilderCallbacks(PassBuilder &PB){
#define GET_PASS_REGISTRY "X86PassRegistry.def"
#include "llvm/Passes/TargetPassRegistry.inc"
}
Error X86TargetMachine::buildCodeGenPipeline(
ModulePassManager &MPM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
- CodeGenFileType FileType, const CGPassBuilderOption &Opt,
+ CodeGenFileType FileType, const CGPassBuilderOption &Opt, MCContext &Ctx,
PassInstrumentationCallbacks *PIC) {
auto CGPB = X86CodeGenPassBuilder(*this, Opt, PIC);
- return CGPB.buildPipeline(MPM, Out, DwoOut, FileType);
+ return CGPB.buildPipeline(MPM, Out, DwoOut, FileType, Ctx);
}
diff --git a/llvm/lib/Target/X86/X86TargetMachine.h b/llvm/lib/Target/X86/X86TargetMachine.h
index 5bf7e57779302..a3871da89fccd 100644
--- a/llvm/lib/Target/X86/X86TargetMachine.h
+++ b/llvm/lib/Target/X86/X86TargetMachine.h
@@ -74,7 +74,7 @@ class X86TargetMachine final : public CodeGenTargetMachineImpl {
Error buildCodeGenPipeline(ModulePassManager &MPM, raw_pwrite_stream &Out,
raw_pwrite_stream *DwoOut,
CodeGenFileType FileType,
- const CGPassBuilderOption &Opt,
+ const CGPassBuilderOption &Opt, MCContext &Ctx,
PassInstrumentationCallbacks *PIC) override;
bool isJIT() const { return IsJIT; }
diff --git a/llvm/tools/llc/NewPMDriver.cpp b/llvm/tools/llc/NewPMDriver.cpp
index ebb478992326c..fe5e762e36dcf 100644
--- a/llvm/tools/llc/NewPMDriver.cpp
+++ b/llvm/tools/llc/NewPMDriver.cpp
@@ -173,8 +173,9 @@ int llvm::compileModuleWithNewPM(
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
} else {
- ExitOnErr(Target->buildCodeGenPipeline(
- MPM, *OS, DwoOut ? &DwoOut->os() : nullptr, FileType, Opt, &PIC));
+ ExitOnErr(
+ Target->buildCodeGenPipeline(MPM, *OS, DwoOut ? &DwoOut->os() : nullptr,
+ FileType, Opt, MMI.getContext(), &PIC));
}
// If user only wants to print the pipeline, print it before parsing the MIR.
``````````
</details>
https://github.com/llvm/llvm-project/pull/182794
More information about the llvm-branch-commits
mailing list