[clang] [Clang][CodeGen] Improve support for NPM codegen (PR #210248)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 12 21:58:49 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Vikram Hegde (vikramRH)
<details>
<summary>Changes</summary>
Improve NPM codegen support by
1. adding print-pipeline-passes support
2. register analyses matching legacy
---
Full diff: https://github.com/llvm/llvm-project/pull/210248.diff
2 Files Affected:
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+31-6)
- (added) clang/test/CodeGen/print-pipeline-passes-codegen.c (+16)
``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 068b1b4c262c8..7fbac4a09492d 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1312,6 +1312,22 @@ void EmitAssemblyHelper::RunCodegenPipelineNewPM(
TargetMachine *TMPointer = TM.get();
PassBuilder PB(TMPointer, PTOptions, std::nullopt, &PIC,
CI.getVirtualFileSystemPtr());
+
+ StandardInstrumentations SI(TheModule->getContext(),
+ CodeGenOpts.DebugPassManager,
+ CodeGenOpts.VerifyEach);
+ SI.registerCallbacks(PIC, &MAM);
+
+ TargetLibraryInfoImpl TLII(TheModule->getTargetTriple());
+ FAM.registerPass([&] { return TargetLibraryAnalysis(TLII); });
+ MAM.registerPass([&] { return MachineModuleAnalysis(MMI); });
+ MAM.registerPass([&] {
+ const llvm::TargetOptions &Options = TM->Options;
+ return RuntimeLibraryAnalysis(TargetTriple, Options.ExceptionModel,
+ Options.FloatABIType, Options.EABIVersion,
+ Options.MCOptions.ABIName, Options.VecLib);
+ });
+
PB.registerModuleAnalyses(MAM);
PB.registerCGSCCAnalyses(CGAM);
PB.registerFunctionAnalyses(FAM);
@@ -1319,17 +1335,26 @@ void EmitAssemblyHelper::RunCodegenPipelineNewPM(
PB.registerMachineFunctionAnalyses(MFAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM, &MFAM);
- MAM.registerPass([&] { return MachineModuleAnalysis(MMI); });
-
- Error BuildPipelineError =
- TM->buildCodeGenPipeline(MPM, MAM, *OS, DwoOS ? &DwoOS->os() : nullptr,
- CGFT, Opt, MMI.getContext(), &PIC);
- if (BuildPipelineError) {
+ if (Error BuildPipelineError = TM->buildCodeGenPipeline(
+ MPM, MAM, *OS, DwoOS ? &DwoOS->os() : nullptr, CGFT, Opt,
+ MMI.getContext(), &PIC)) {
Diags.Report(diag::err_fe_unable_to_interface_with_target);
return;
}
+ if (PrintPipelinePasses) {
+ std::string PipelineStr;
+ raw_string_ostream OutS(PipelineStr);
+ MPM.printPipeline(OutS, [&PIC](StringRef ClassName) {
+ auto PassName = PIC.getPassNameForClassName(ClassName);
+ return PassName.empty() ? ClassName : PassName;
+ });
+ outs() << PipelineStr << '\n';
+ return;
+ }
+
TimeCodegenPasses([&] { MPM.run(*TheModule, MAM); });
+ return;
}
void EmitAssemblyHelper::TimeCodegenPasses(
diff --git a/clang/test/CodeGen/print-pipeline-passes-codegen.c b/clang/test/CodeGen/print-pipeline-passes-codegen.c
new file mode 100644
index 0000000000000..bf3eb2197a5fc
--- /dev/null
+++ b/clang/test/CodeGen/print-pipeline-passes-codegen.c
@@ -0,0 +1,16 @@
+// Test that -print-pipeline-passes also prints the codegen pipeline.
+
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -target-cpu gfx900 \
+// RUN: -fenable-new-pm-codegen -emit-obj -o /dev/null \
+// RUN: -mllvm -print-pipeline-passes -O0 %s 2>&1 | FileCheck %s
+
+// Don't try to check all passes, just a few codegen-specific ones (in order) to
+// make sure the machine pipeline is actually printed.
+// CHECK: require<MachineModuleAnalysis>
+// CHECK-SAME: amdgpu-isel
+// CHECK-SAME: prolog-epilog
+// CHECK-SAME: amdgpu-asm-printer
+
+void Foo(void) {}
``````````
</details>
https://github.com/llvm/llvm-project/pull/210248
More information about the cfe-commits
mailing list