[clang] bf49237 - [Clang] Enable -print-pipeline-passes in clang.
Joshua Cranmer via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 13 09:01:13 PDT 2023
Author: Joshua Cranmer
Date: 2023-09-13T08:57:10-07:00
New Revision: bf492371033378cec4c0443a3f87db0f818bbade
URL: https://github.com/llvm/llvm-project/commit/bf492371033378cec4c0443a3f87db0f818bbade
DIFF: https://github.com/llvm/llvm-project/commit/bf492371033378cec4c0443a3f87db0f818bbade.diff
LOG: [Clang] Enable -print-pipeline-passes in clang.
Reviewed By: arsenm, aeubanks
Differential Revision: https://reviews.llvm.org/D127221
Added:
clang/test/CodeGen/print-pipeline-passes.c
Modified:
clang/lib/CodeGen/BackendUtil.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 2f649678b4f20df..04cb9064dc789a3 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -91,6 +91,7 @@ using namespace llvm;
namespace llvm {
extern cl::opt<bool> DebugInfoCorrelate;
+extern cl::opt<bool> PrintPipelinePasses;
// Experiment to move sanitizers earlier.
static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
@@ -1090,6 +1091,17 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
TheModule->addModuleFlag(Module::Error, "UnifiedLTO", uint32_t(1));
}
+ // Print a textual, '-passes=' compatible, representation of pipeline if
+ // requested.
+ if (PrintPipelinePasses) {
+ MPM.printPipeline(outs(), [&PIC](StringRef ClassName) {
+ auto PassName = PIC.getPassNameForClassName(ClassName);
+ return PassName.empty() ? ClassName : PassName;
+ });
+ outs() << "\n";
+ return;
+ }
+
// Now that we have all of the passes ready, run them.
{
PrettyStackTraceString CrashInfo("Optimizer");
@@ -1127,6 +1139,13 @@ void EmitAssemblyHelper::RunCodegenPipeline(
return;
}
+ // If -print-pipeline-passes is requested, don't run the legacy pass manager.
+ // FIXME: when codegen is switched to use the new pass manager, it should also
+ // emit pass names here.
+ if (PrintPipelinePasses) {
+ return;
+ }
+
{
PrettyStackTraceString CrashInfo("Code generation");
llvm::TimeTraceScope TimeScope("CodeGenPasses");
diff --git a/clang/test/CodeGen/print-pipeline-passes.c b/clang/test/CodeGen/print-pipeline-passes.c
new file mode 100644
index 000000000000000..904d2416bc9e19f
--- /dev/null
+++ b/clang/test/CodeGen/print-pipeline-passes.c
@@ -0,0 +1,9 @@
+// Test that -print-pipeline-passes works in Clang
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm-bc -o /dev/null -mllvm -print-pipeline-passes -O0 %s 2>&1 | FileCheck %s
+
+// Don't try to check all passes, just a few to make sure that something is
+// actually printed.
+// CHECK: always-inline
+// CHECK-SAME: annotation-remarks
+void Foo(void) {}
More information about the cfe-commits
mailing list