[Mlir-commits] [mlir] [MLIR] Fixup the LDBG() logging in dataflow/deadcodeanalysis (NFC) (PR #155085)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Aug 23 02:48:39 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Mehdi Amini (joker-eph)
<details>
<summary>Changes</summary>
This is improving the debug output:
- avoid printing pointers, print ops without regions in general.
- skip extra new-lines in the output
- minor other consistency aspects.
---
Full diff: https://github.com/llvm/llvm-project/pull/155085.diff
2 Files Affected:
- (modified) mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp (+35-15)
- (modified) mlir/lib/Analysis/DataFlowFramework.cpp (+5-4)
``````````diff
diff --git a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
index 4addff9610e88..b91da5a4c05d3 100644
--- a/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
+++ b/mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp
@@ -79,9 +79,17 @@ void Executable::onUpdate(DataFlowSolver *solver) const {
void PredecessorState::print(raw_ostream &os) const {
if (allPredecessorsKnown())
os << "(all) ";
- os << "predecessors:\n";
- for (Operation *op : getKnownPredecessors())
- os << " " << *op << "\n";
+ os << "predecessors:";
+ if (getKnownPredecessors().empty())
+ os << " (none)";
+ else
+ os << "\n";
+ llvm::interleave(
+ getKnownPredecessors(), os,
+ [&](Operation *op) {
+ os << " " << OpWithFlags(op, OpPrintingFlags().skipRegions());
+ },
+ "\n");
}
ChangeResult PredecessorState::join(Operation *predecessor) {
@@ -235,7 +243,8 @@ LogicalResult DeadCodeAnalysis::initializeRecursively(Operation *op) {
// Initialize the analysis by visiting every op with control-flow semantics.
if (op->getNumRegions() || op->getNumSuccessors() ||
isRegionOrCallableReturn(op) || isa<CallOpInterface>(op)) {
- LDBG() << "[init] Visiting op with control-flow semantics: " << *op;
+ LDBG() << "[init] Visiting op with control-flow semantics: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
// When the liveness of the parent block changes, make sure to
// re-invoke the analysis on the op.
if (op->getBlock())
@@ -247,7 +256,8 @@ LogicalResult DeadCodeAnalysis::initializeRecursively(Operation *op) {
}
// Recurse on nested operations.
for (Region ®ion : op->getRegions()) {
- LDBG() << "[init] Recursing into region of op: " << op->getName();
+ LDBG() << "[init] Recursing into region of op: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
for (Operation &nestedOp : region.getOps()) {
LDBG() << "[init] Recursing into nested op: "
<< OpWithFlags(&nestedOp, OpPrintingFlags().skipRegions());
@@ -286,19 +296,22 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint *point) {
if (point->isBlockStart())
return success();
Operation *op = point->getPrevOp();
- LDBG() << "Visiting operation: " << *op;
+ LDBG() << "Visiting operation: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
// If the parent block is not executable, there is nothing to do.
if (op->getBlock() != nullptr &&
!getOrCreate<Executable>(getProgramPointBefore(op->getBlock()))
->isLive()) {
- LDBG() << "Parent block not live, skipping op: " << *op;
+ LDBG() << "Parent block not live, skipping op: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
return success();
}
// We have a live call op. Add this as a live predecessor of the callee.
if (auto call = dyn_cast<CallOpInterface>(op)) {
- LDBG() << "Visiting call operation: " << *op;
+ LDBG() << "Visiting call operation: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
visitCallOperation(call);
}
@@ -306,12 +319,14 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint *point) {
if (op->getNumRegions()) {
// Check if we can reason about the region control-flow.
if (auto branch = dyn_cast<RegionBranchOpInterface>(op)) {
- LDBG() << "Visiting region branch operation: " << *op;
+ LDBG() << "Visiting region branch operation: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
visitRegionBranchOperation(branch);
// Check if this is a callable operation.
} else if (auto callable = dyn_cast<CallableOpInterface>(op)) {
- LDBG() << "Visiting callable operation: " << *op;
+ LDBG() << "Visiting callable operation: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
const auto *callsites = getOrCreateFor<PredecessorState>(
getProgramPointAfter(op), getProgramPointAfter(callable));
@@ -323,19 +338,22 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint *point) {
// Otherwise, conservatively mark all entry blocks as executable.
} else {
- LDBG() << "Marking all entry blocks live for op: " << *op;
+ LDBG() << "Marking all entry blocks live for op: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
markEntryBlocksLive(op);
}
}
if (isRegionOrCallableReturn(op)) {
if (auto branch = dyn_cast<RegionBranchOpInterface>(op->getParentOp())) {
- LDBG() << "Visiting region terminator: " << *op;
+ LDBG() << "Visiting region terminator: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
// Visit the exiting terminator of a region.
visitRegionTerminator(op, branch);
} else if (auto callable =
dyn_cast<CallableOpInterface>(op->getParentOp())) {
- LDBG() << "Visiting callable terminator: " << *op;
+ LDBG() << "Visiting callable terminator: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
// Visit the exiting terminator of a callable.
visitCallableTerminator(op, callable);
}
@@ -344,12 +362,14 @@ LogicalResult DeadCodeAnalysis::visit(ProgramPoint *point) {
if (op->getNumSuccessors()) {
// Check if we can reason about the control-flow.
if (auto branch = dyn_cast<BranchOpInterface>(op)) {
- LDBG() << "Visiting branch operation: " << *op;
+ LDBG() << "Visiting branch operation: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
visitBranchOperation(branch);
// Otherwise, conservatively mark all successors as exectuable.
} else {
- LDBG() << "Marking all successors live for op: " << *op;
+ LDBG() << "Marking all successors live for op: "
+ << OpWithFlags(op, OpPrintingFlags().skipRegions());
for (Block *successor : op->getSuccessors())
markEdgeLive(op->getBlock(), successor);
}
diff --git a/mlir/lib/Analysis/DataFlowFramework.cpp b/mlir/lib/Analysis/DataFlowFramework.cpp
index 76bf94aed9e02..7e1b4052027d3 100644
--- a/mlir/lib/Analysis/DataFlowFramework.cpp
+++ b/mlir/lib/Analysis/DataFlowFramework.cpp
@@ -62,11 +62,12 @@ void ProgramPoint::print(raw_ostream &os) const {
return;
}
if (!isBlockStart()) {
- os << "<after operation>:";
- return getPrevOp()->print(os, OpPrintingFlags().skipRegions());
+ os << "<after operation>:"
+ << OpWithFlags(getPrevOp(), OpPrintingFlags().skipRegions());
+ return;
}
- os << "<before operation>:";
- return getNextOp()->print(os, OpPrintingFlags().skipRegions());
+ os << "<before operation>:"
+ << OpWithFlags(getNextOp(), OpPrintingFlags().skipRegions());
}
//===----------------------------------------------------------------------===//
``````````
</details>
https://github.com/llvm/llvm-project/pull/155085
More information about the Mlir-commits
mailing list