[polly] bed2761 - [Polly] Print params with stmt tracing (#189362)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 03:51:44 PDT 2026
Author: Michael Kruse
Date: 2026-04-02T10:51:39Z
New Revision: bed2761bc012b23e652c1f9377a7fd0a9a302bee
URL: https://github.com/llvm/llvm-project/commit/bed2761bc012b23e652c1f9377a7fd0a9a302bee
DIFF: https://github.com/llvm/llvm-project/commit/bed2761bc012b23e652c1f9377a7fd0a9a302bee.diff
LOG: [Polly] Print params with stmt tracing (#189362)
It was helpful for #189350.
Added:
Modified:
polly/include/polly/CodeGen/IslNodeBuilder.h
polly/include/polly/CodeGen/RuntimeDebugBuilder.h
polly/lib/CodeGen/BlockGenerators.cpp
polly/lib/CodeGen/CodeGeneration.cpp
polly/lib/CodeGen/IslNodeBuilder.cpp
polly/test/CodeGen/RuntimeDebugBuilder/stmt_tracing.ll
Removed:
################################################################################
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..a52a9bf5a6c0f 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)
More information about the llvm-commits
mailing list