https://github.com/vikramRH updated https://github.com/llvm/llvm-project/pull/210248
>From 4489b48b577f23523d7f39db2f1ef27100d01f7c Mon Sep 17 00:00:00 2001 From: vikhegde <[email protected]> Date: Thu, 16 Jul 2026 16:12:34 +0530 Subject: [PATCH] [Clang][CodeGen] Improve support for NPM codegen --- clang/lib/CodeGen/BackendUtil.cpp | 37 ++++++++++++++++--- .../CodeGen/print-pipeline-passes-codegen.c | 16 ++++++++ 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGen/print-pipeline-passes-codegen.c diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index e55d242cde68a..e8322a359ddf4 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1319,6 +1319,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); @@ -1326,17 +1342,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) {} _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
