[polly] [Polly] Print params with stmt tracing (PR #189362)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 03:15:11 PDT 2026
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/189362
>From d20f60c2803d4f4deed21a03fd4db0a5ad9e7b03 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 30 Mar 2026 11:57:48 +0200
Subject: [PATCH 1/2] debug-print parameters
---
polly/include/polly/CodeGen/IslNodeBuilder.h | 2 ++
.../polly/CodeGen/RuntimeDebugBuilder.h | 1 +
polly/lib/CodeGen/BlockGenerators.cpp | 5 ++--
polly/lib/CodeGen/CodeGeneration.cpp | 2 ++
polly/lib/CodeGen/IslNodeBuilder.cpp | 24 +++++++++++++++++++
.../RuntimeDebugBuilder/stmt_tracing.ll | 20 ++++++++++++----
6 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/polly/include/polly/CodeGen/IslNodeBuilder.h b/polly/include/polly/CodeGen/IslNodeBuilder.h
index 03c47155894e8..e8b776d74eb09 100644
--- a/polly/include/polly/CodeGen/IslNodeBuilder.h
+++ b/polly/include/polly/CodeGen/IslNodeBuilder.h
@@ -91,6 +91,8 @@ class IslNodeBuilder {
/// otherwise.
Value *createRTC(isl_ast_expr *Condition);
+ void generateBeginScopTrace();
+
void create(__isl_take isl_ast_node *Node);
/// Allocate memory for all new arrays created by Polly.
diff --git a/polly/include/polly/CodeGen/RuntimeDebugBuilder.h b/polly/include/polly/CodeGen/RuntimeDebugBuilder.h
index 2e5349d9edd6e..6394f6ab71d5e 100644
--- a/polly/include/polly/CodeGen/RuntimeDebugBuilder.h
+++ b/polly/include/polly/CodeGen/RuntimeDebugBuilder.h
@@ -124,5 +124,6 @@ struct RuntimeDebugBuilder {
} // namespace polly
extern bool PollyDebugPrinting;
+extern bool TraceStmts;
#endif
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index e5c0236338189..96ca0b8cf42be 100644
--- a/polly/lib/CodeGen/BlockGenerators.cpp
+++ b/polly/lib/CodeGen/BlockGenerators.cpp
@@ -42,10 +42,11 @@ static cl::opt<bool, true> DebugPrintingX(
cl::desc("Add printf calls that show the values loaded/stored."),
cl::location(PollyDebugPrinting), cl::Hidden, cl::cat(PollyCategory));
-static cl::opt<bool> TraceStmts(
+bool TraceStmts;
+static cl::opt<bool, true> TraceStmtsX(
"polly-codegen-trace-stmts",
cl::desc("Add printf calls that print the statement being executed"),
- cl::Hidden, cl::cat(PollyCategory));
+ cl::location(TraceStmts), cl::Hidden, cl::cat(PollyCategory));
static cl::opt<bool> TraceScalars(
"polly-codegen-trace-scalars",
diff --git a/polly/lib/CodeGen/CodeGeneration.cpp b/polly/lib/CodeGen/CodeGeneration.cpp
index 5d2b6363ddf38..d9f4a7f78a322 100644
--- a/polly/lib/CodeGen/CodeGeneration.cpp
+++ b/polly/lib/CodeGen/CodeGeneration.cpp
@@ -297,6 +297,8 @@ static bool generateCode(Scop &S, IslAstInfo &AI, LoopInfo &LI,
Builder.SetInsertPoint(StartBlock,
StartBlock->getTerminator()->getIterator());
+ NodeBuilder.generateBeginScopTrace();
+
NodeBuilder.create(AstRoot.release());
NodeBuilder.finalize();
fixRegionInfo(*EnteringBB->getParent(), *R->getParent(), RI);
diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index d620ac768abd6..efede7368ea3c 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -925,6 +925,30 @@ void IslNodeBuilder::createBlock(__isl_take isl_ast_node *Block) {
isl_ast_node_list_free(List);
}
+void IslNodeBuilder::generateBeginScopTrace() {
+ if (!TraceStmts)
+ return;
+
+ // Sequence of strings to print.
+ SmallVector<llvm::Value *, 8> Values;
+ Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "Scop: "));
+
+ auto Params = S.getParamSpace();
+ for (int i : rangeIslSize(0, Params.dim(isl::dim::param))) {
+ if (i != 0)
+ Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, " "));
+
+ isl::id PId = Params.get_dim_id(isl::dim::param, i);
+ Values.push_back(
+ RuntimeDebugBuilder::getPrintableString(Builder, PId.get_name()));
+ Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "="));
+ Values.push_back(IDToValue.lookup(PId.get()));
+ }
+
+ Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "\n"));
+ RuntimeDebugBuilder::createCPUPrinter(Builder, ArrayRef<Value *>(Values));
+}
+
void IslNodeBuilder::create(__isl_take isl_ast_node *Node) {
switch (isl_ast_node_get_type(Node)) {
case isl_ast_node_error:
diff --git a/polly/test/CodeGen/RuntimeDebugBuilder/stmt_tracing.ll b/polly/test/CodeGen/RuntimeDebugBuilder/stmt_tracing.ll
index 736c136eeb67c..03c55c990c1d3 100644
--- a/polly/test/CodeGen/RuntimeDebugBuilder/stmt_tracing.ll
+++ b/polly/test/CodeGen/RuntimeDebugBuilder/stmt_tracing.ll
@@ -27,12 +27,22 @@ return:
}
-; CHECK: @0 = private unnamed_addr addrspace(4) constant [10 x i8] c"Stmt_body\00"
-; CHECK: @1 = private unnamed_addr addrspace(4) constant [2 x i8] c"(\00"
-; CHECK: @2 = private unnamed_addr addrspace(4) constant [2 x i8] c")\00"
+; CHECK: @0 = private unnamed_addr addrspace(4) constant [7 x i8] c"Scop: \00"
+; CHECK: @1 = private unnamed_addr addrspace(4) constant [2 x i8] c"n\00"
+; CHECK: @2 = private unnamed_addr addrspace(4) constant [2 x i8] c"=\00"
; CHECK: @3 = private unnamed_addr addrspace(4) constant [2 x i8] c"\0A\00"
-; CHECK: @4 = private unnamed_addr constant [12 x i8] c"%s%s%ld%s%s\00"
+; CHECK: @4 = private unnamed_addr constant [12 x i8] c"%s%s%s%ld%s\00"
+
+; CHECK: @5 = private unnamed_addr addrspace(4) constant [10 x i8] c"Stmt_body\00"
+; CHECK: @6 = private unnamed_addr addrspace(4) constant [2 x i8] c"(\00"
+; CHECK: @7 = private unnamed_addr addrspace(4) constant [2 x i8] c")\00"
+; CHECK: @8 = private unnamed_addr addrspace(4) constant [2 x i8] c"\0A\00"
+; CHECK: @9 = private unnamed_addr constant [12 x i8] c"%s%s%ld%s%s\00"
+
+; CHECK: polly.start:
+; CHECK: call i32 (...) @printf(ptr @4, ptr addrspace(4) @0, ptr addrspace(4) @1, ptr addrspace(4) @2, i64 %0, ptr addrspace(4) @3)
+; CHECK-NEXT: call i32 @fflush(ptr null)
; CHECK: polly.stmt.body:
-; CHECK: call i32 (...) @printf(ptr @4, ptr addrspace(4) @0, ptr addrspace(4) @1, i64 %polly.indvar, ptr addrspace(4) @2, ptr addrspace(4) @3)
+; CHECK: call i32 (...) @printf(ptr @9, ptr addrspace(4) @5, ptr addrspace(4) @6, i64 %polly.indvar, ptr addrspace(4) @7, ptr addrspace(4) @8)
; CHECK-NEXT: call i32 @fflush(ptr null)
>From 1541f4612cc4fd0f6cd61a4fa9c93e4d6abf35e1 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Mon, 30 Mar 2026 13:40:37 +0200
Subject: [PATCH 2/2] polly-update-format
---
polly/lib/CodeGen/BlockGenerators.cpp | 1 +
polly/lib/CodeGen/IslNodeBuilder.cpp | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/polly/lib/CodeGen/BlockGenerators.cpp b/polly/lib/CodeGen/BlockGenerators.cpp
index 96ca0b8cf42be..a2dae0961fdd2 100644
--- a/polly/lib/CodeGen/BlockGenerators.cpp
+++ b/polly/lib/CodeGen/BlockGenerators.cpp
@@ -48,6 +48,7 @@ static cl::opt<bool, true> TraceStmtsX(
cl::desc("Add printf calls that print the statement being executed"),
cl::location(TraceStmts), cl::Hidden, cl::cat(PollyCategory));
+bool TraceStmts;
static cl::opt<bool> TraceScalars(
"polly-codegen-trace-scalars",
cl::desc("Add printf calls that print the values of all scalar values "
diff --git a/polly/lib/CodeGen/IslNodeBuilder.cpp b/polly/lib/CodeGen/IslNodeBuilder.cpp
index efede7368ea3c..a52a9bf5a6c0f 100644
--- a/polly/lib/CodeGen/IslNodeBuilder.cpp
+++ b/polly/lib/CodeGen/IslNodeBuilder.cpp
@@ -938,7 +938,7 @@ void IslNodeBuilder::generateBeginScopTrace() {
if (i != 0)
Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, " "));
- isl::id PId = Params.get_dim_id(isl::dim::param, i);
+ isl::id PId = Params.get_dim_id(isl::dim::param, i);
Values.push_back(
RuntimeDebugBuilder::getPrintableString(Builder, PId.get_name()));
Values.push_back(RuntimeDebugBuilder::getPrintableString(Builder, "="));
More information about the llvm-commits
mailing list