Skip to content

Commit 789fcef

Browse files
authored
[MLIR] Migrate some "transform dialect" source to use the standard LDBG macro (NFC) (#150695)
1 parent f8b1c73 commit 789fcef

File tree

7 files changed

+49
-69
lines changed

7 files changed

+49
-69
lines changed

mlir/examples/transform/Ch4/lib/MyExtension.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313

1414
#include "MyExtension.h"
1515
#include "mlir/Dialect/Transform/IR/TransformDialect.h"
16-
#include "llvm/Support/Debug.h"
16+
#include "llvm/Support/DebugLog.h"
1717

18-
#define DEBUG_TYPE_MATCHER "transform-matcher"
19-
#define DBGS_MATCHER() (llvm::dbgs() << "[" DEBUG_TYPE_MATCHER "] ")
20-
#define DEBUG_MATCHER(x) DEBUG_WITH_TYPE(DEBUG_TYPE_MATCHER, x)
18+
#define DEBUG_TYPE "transform-matcher"
2119

2220
#define GET_OP_CLASSES
2321
#include "MyExtension.cpp.inc"
@@ -124,9 +122,8 @@ mlir::transform::HasOperandSatisfyingOp::apply(
124122
// Report failure-to-match for debugging purposes and stop matching this
125123
// operand.
126124
assert(diag.isSilenceableFailure());
127-
DEBUG_MATCHER(DBGS_MATCHER()
128-
<< "failed to match operand #" << operand.getOperandNumber()
129-
<< ": " << diag.getMessage());
125+
LDBG() << "failed to match operand #" << operand.getOperandNumber()
126+
<< ": " << diag.getMessage();
130127
(void)diag.silence();
131128
matchSucceeded = false;
132129
break;

mlir/include/mlir/Dialect/Linalg/TransformOps/GPUHeuristics.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ struct CopyMappingInfo : public MappingInfo {
119119
Status status;
120120
};
121121

122+
inline llvm::raw_ostream &operator<<(llvm::raw_ostream &os,
123+
const CopyMappingInfo &info) {
124+
info.print(os);
125+
return os;
126+
}
127+
122128
} // namespace gpu
123129
} // namespace transform
124130
} // namespace mlir

mlir/lib/Dialect/Affine/Transforms/DecomposeAffineOps.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
#include "mlir/Dialect/Affine/Transforms/Transforms.h"
1616
#include "mlir/IR/PatternMatch.h"
1717
#include "llvm/Support/Debug.h"
18+
#include "llvm/Support/DebugLog.h"
19+
#include "llvm/Support/InterleavedRange.h"
1820

1921
using namespace mlir;
2022
using namespace mlir::affine;
2123

2224
#define DEBUG_TYPE "decompose-affine-ops"
23-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
24-
#define DBGSNL() (llvm::dbgs() << "\n")
2525

2626
/// Count the number of loops surrounding `operand` such that operand could be
2727
/// hoisted above.
@@ -115,7 +115,7 @@ FailureOr<AffineApplyOp> mlir::affine::decompose(RewriterBase &rewriter,
115115
return rewriter.notifyMatchFailure(
116116
op, "only add or mul binary expr can be reassociated");
117117

118-
LLVM_DEBUG(DBGS() << "Start decomposeIntoFinerGrainedOps: " << op << "\n");
118+
LDBG() << "Start decomposeIntoFinerGrainedOps: " << op;
119119

120120
// 2. Iteratively extract the RHS subexpressions while the top-level binary
121121
// expr kind remains the same.
@@ -125,11 +125,11 @@ FailureOr<AffineApplyOp> mlir::affine::decompose(RewriterBase &rewriter,
125125
auto currentBinExpr = dyn_cast<AffineBinaryOpExpr>(remainingExp);
126126
if (!currentBinExpr || currentBinExpr.getKind() != binExpr.getKind()) {
127127
subExpressions.push_back(remainingExp);
128-
LLVM_DEBUG(DBGS() << "--terminal: " << subExpressions.back() << "\n");
128+
LDBG() << "--terminal: " << subExpressions.back();
129129
break;
130130
}
131131
subExpressions.push_back(currentBinExpr.getRHS());
132-
LLVM_DEBUG(DBGS() << "--subExpr: " << subExpressions.back() << "\n");
132+
LDBG() << "--subExpr: " << subExpressions.back();
133133
remainingExp = currentBinExpr.getLHS();
134134
}
135135

@@ -146,9 +146,7 @@ FailureOr<AffineApplyOp> mlir::affine::decompose(RewriterBase &rewriter,
146146
llvm::stable_sort(subExpressions, [&](AffineExpr e1, AffineExpr e2) {
147147
return getMaxSymbol(e1) < getMaxSymbol(e2);
148148
});
149-
LLVM_DEBUG(
150-
llvm::interleaveComma(subExpressions, DBGS() << "--sorted subexprs: ");
151-
llvm::dbgs() << "\n");
149+
LDBG() << "--sorted subexprs: " << llvm::interleaved(subExpressions);
152150

153151
// 4. Merge sorted subExpressions iteratively, thus achieving reassociation.
154152
auto s0 = getAffineSymbolExpr(0, ctx);
@@ -162,7 +160,7 @@ FailureOr<AffineApplyOp> mlir::affine::decompose(RewriterBase &rewriter,
162160
Value tmp = createSubApply(rewriter, op, subExpressions[i]);
163161
current = AffineApplyOp::create(rewriter, op.getLoc(), binMap,
164162
ValueRange{current, tmp});
165-
LLVM_DEBUG(DBGS() << "--reassociate into: " << current << "\n");
163+
LDBG() << "--reassociate into: " << current;
166164
}
167165

168166
// 5. Replace original op.

mlir/lib/Dialect/Affine/Transforms/SimplifyAffineMinMax.cpp

Lines changed: 20 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
#include "mlir/Interfaces/ValueBoundsOpInterface.h"
2020
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2121
#include "llvm/ADT/IntEqClasses.h"
22-
#include "llvm/Support/Debug.h"
22+
#include "llvm/Support/DebugLog.h"
2323
#include "llvm/Support/InterleavedRange.h"
2424

2525
#define DEBUG_TYPE "affine-min-max"
26-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE << "]: ")
2726

2827
using namespace mlir;
2928
using namespace mlir::affine;
@@ -39,7 +38,7 @@ static bool simplifyAffineMinMaxOp(RewriterBase &rewriter, AffineOp affineOp) {
3938
ValueRange operands = affineOp.getOperands();
4039
static constexpr bool isMin = std::is_same_v<AffineOp, AffineMinOp>;
4140

42-
LLVM_DEBUG({ DBGS() << "analyzing value: `" << affineOp << "`\n"; });
41+
LDBG() << "analyzing value: `" << affineOp;
4342

4443
// Create a `Variable` list with values corresponding to each of the results
4544
// in the affine affineMap.
@@ -48,12 +47,9 @@ static bool simplifyAffineMinMaxOp(RewriterBase &rewriter, AffineOp affineOp) {
4847
[&](unsigned i) {
4948
return Variable(affineMap.getSliceMap(i, 1), operands);
5049
});
51-
LLVM_DEBUG({
52-
DBGS() << "- constructed variables are: "
53-
<< llvm::interleaved_array(llvm::map_range(
54-
variables, [](const Variable &v) { return v.getMap(); }))
55-
<< "`\n";
56-
});
50+
LDBG() << "- constructed variables are: "
51+
<< llvm::interleaved_array(llvm::map_range(
52+
variables, [](const Variable &v) { return v.getMap(); }));
5753

5854
// Get the comparison operation.
5955
ComparisonOperator cmpOp =
@@ -72,10 +68,8 @@ static bool simplifyAffineMinMaxOp(RewriterBase &rewriter, AffineOp affineOp) {
7268
// Initialize the bound.
7369
Variable *bound = &v;
7470

75-
LLVM_DEBUG({
76-
DBGS() << "- inspecting variable: #" << i << ", with map: `" << v.getMap()
77-
<< "`\n";
78-
});
71+
LDBG() << "- inspecting variable: #" << i << ", with map: `" << v.getMap()
72+
<< "`\n";
7973

8074
// Check against the other variables.
8175
for (size_t j = i + 1; j < variables.size(); ++j) {
@@ -87,29 +81,23 @@ static bool simplifyAffineMinMaxOp(RewriterBase &rewriter, AffineOp affineOp) {
8781
// Get the bound of the equivalence class or itself.
8882
Variable *nv = bounds.lookup_or(jEqClass, &variables[j]);
8983

90-
LLVM_DEBUG({
91-
DBGS() << "- comparing with variable: #" << jEqClass
92-
<< ", with map: " << nv->getMap() << "\n";
93-
});
84+
LDBG() << "- comparing with variable: #" << jEqClass
85+
<< ", with map: " << nv->getMap();
9486

9587
// Compare the variables.
9688
FailureOr<bool> cmpResult =
9789
ValueBoundsConstraintSet::strongCompare(*bound, cmpOp, *nv);
9890

9991
// The variables cannot be compared.
10092
if (failed(cmpResult)) {
101-
LLVM_DEBUG({
102-
DBGS() << "-- classes: #" << i << ", #" << jEqClass
103-
<< " cannot be merged\n";
104-
});
93+
LDBG() << "-- classes: #" << i << ", #" << jEqClass
94+
<< " cannot be merged";
10595
continue;
10696
}
10797

10898
// Join the equivalent classes and update the bound if necessary.
109-
LLVM_DEBUG({
110-
DBGS() << "-- merging classes: #" << i << ", #" << jEqClass
111-
<< ", is cmp(lhs, rhs): " << *cmpResult << "`\n";
112-
});
99+
LDBG() << "-- merging classes: #" << i << ", #" << jEqClass
100+
<< ", is cmp(lhs, rhs): " << *cmpResult << "`";
113101
if (*cmpResult) {
114102
boundedClasses.join(eqClass, jEqClass);
115103
} else {
@@ -124,8 +112,7 @@ static bool simplifyAffineMinMaxOp(RewriterBase &rewriter, AffineOp affineOp) {
124112

125113
// Return if there's no simplification.
126114
if (bounds.size() >= affineMap.getNumResults()) {
127-
LLVM_DEBUG(
128-
{ DBGS() << "- the affine operation couldn't get simplified\n"; });
115+
LDBG() << "- the affine operation couldn't get simplified";
129116
return false;
130117
}
131118

@@ -135,21 +122,19 @@ static bool simplifyAffineMinMaxOp(RewriterBase &rewriter, AffineOp affineOp) {
135122
for (auto [k, bound] : bounds)
136123
results.push_back(bound->getMap().getResult(0));
137124

138-
LLVM_DEBUG({
139-
DBGS() << "- starting from map: " << affineMap << "\n";
140-
DBGS() << "- creating new map with: \n";
141-
DBGS() << "--- dims: " << affineMap.getNumDims() << "\n";
142-
DBGS() << "--- syms: " << affineMap.getNumSymbols() << "\n";
143-
DBGS() << "--- res: " << llvm::interleaved_array(results) << "\n";
144-
});
125+
LDBG() << "- starting from map: " << affineMap;
126+
LDBG() << "- creating new map with:";
127+
LDBG() << "--- dims: " << affineMap.getNumDims();
128+
LDBG() << "--- syms: " << affineMap.getNumSymbols();
129+
LDBG() << "--- res: " << llvm::interleaved_array(results);
145130

146131
affineMap =
147132
AffineMap::get(0, affineMap.getNumSymbols() + affineMap.getNumDims(),
148133
results, rewriter.getContext());
149134

150135
// Update the affine op.
151136
rewriter.modifyOpInPlace(affineOp, [&]() { affineOp.setMap(affineMap); });
152-
LLVM_DEBUG({ DBGS() << "- simplified affine op: `" << affineOp << "`\n"; });
137+
LDBG() << "- simplified affine op: `" << affineOp << "`";
153138
return true;
154139
}
155140

mlir/lib/Dialect/Linalg/TransformOps/GPUHeuristics.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "mlir/Dialect/GPU/IR/GPUDialect.h"
1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/ADT/STLExtras.h"
14+
#include "llvm/Support/Debug.h"
1415
#include "llvm/Support/DebugLog.h"
1516
#include "llvm/Support/InterleavedRange.h"
1617
#include "llvm/Support/MathExtras.h"
@@ -21,7 +22,6 @@
2122
using namespace mlir;
2223

2324
#define DEBUG_TYPE "linalg-transforms"
24-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
2525

2626
static Attribute linearId0(MLIRContext *ctx) {
2727
return gpu::GPUThreadMappingAttr::get(ctx, gpu::MappingId::LinearDim0);
@@ -81,7 +81,7 @@ transform::gpu::CopyMappingInfo::CopyMappingInfo(MLIRContext *ctx,
8181
this->threadMapping =
8282
llvm::to_vector(ArrayRef(allThreadMappings)
8383
.take_back(this->smallestBoundingTileSizes.size()));
84-
LLVM_DEBUG(this->print(DBGS()); llvm::dbgs() << "\n");
84+
LDBG() << *this;
8585
}
8686

8787
int64_t transform::gpu::CopyMappingInfo::maxContiguousElementsToTransfer(

mlir/lib/Dialect/Linalg/TransformOps/LinalgMatchOps.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515
#include "mlir/Dialect/Transform/IR/TransformTypes.h"
1616
#include "mlir/Dialect/Transform/Interfaces/MatchInterfaces.h"
1717
#include "mlir/IR/BuiltinAttributes.h"
18-
#include "llvm/Support/Debug.h"
18+
#include "llvm/Support/DebugLog.h"
1919
#include "llvm/Support/FormatVariadic.h"
2020
#include "llvm/Support/InterleavedRange.h"
2121

2222
using namespace mlir;
2323

2424
#define DEBUG_TYPE "linalg-transforms"
25-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
2625

2726
//===----------------------------------------------------------------------===//
2827
// StructuredMatchOp
@@ -39,7 +38,7 @@ DiagnosedSilenceableFailure transform::MatchStructuredOp::matchOperation(
3938
return emitSilenceableError() << "expected a Linalg op";
4039
}
4140
// If errors are suppressed, succeed and set all results to empty lists.
42-
LLVM_DEBUG(DBGS() << "optional nested matcher expected a Linalg op");
41+
LDBG() << "optional nested matcher expected a Linalg op";
4342
results.setRemainingToEmpty(cast<TransformOpInterface>(getOperation()));
4443
return DiagnosedSilenceableFailure::success();
4544
}
@@ -75,8 +74,7 @@ DiagnosedSilenceableFailure transform::MatchStructuredOp::matchOperation(
7574
// When they are defined in this block, we additionally check if we have
7675
// already applied the operation that defines them. If not, the
7776
// corresponding results will be set to empty lists.
78-
LLVM_DEBUG(DBGS() << "optional nested matcher failed: " << diag.getMessage()
79-
<< "\n");
77+
LDBG() << "optional nested matcher failed: " << diag.getMessage();
8078
(void)diag.silence();
8179
SmallVector<OpOperand *> undefinedOperands;
8280
for (OpOperand &terminatorOperand :

mlir/lib/Dialect/Transform/Interfaces/TransformInterfaces.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#define DEBUG_TYPE "transform-dialect"
2424
#define DEBUG_TYPE_FULL "transform-dialect-full"
2525
#define DEBUG_PRINT_AFTER_ALL "transform-dialect-print-top-level-after-all"
26-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "] ")
2726
#ifndef NDEBUG
2827
#define FULL_LDBG(X) \
2928
DEBUGLOG_WITH_STREAM_AND_TYPE(llvm::dbgs(), DEBUG_TYPE_FULL)
@@ -818,16 +817,14 @@ void transform::TransformState::compactOpHandles() {
818817

819818
DiagnosedSilenceableFailure
820819
transform::TransformState::applyTransform(TransformOpInterface transform) {
821-
LLVM_DEBUG({
822-
DBGS() << "applying: ";
823-
transform->print(llvm::dbgs(), OpPrintingFlags().skipRegions());
824-
llvm::dbgs() << "\n";
825-
});
820+
LDBG() << "applying: "
821+
<< OpWithFlags(transform, OpPrintingFlags().skipRegions());
826822
FULL_LDBG() << "Top-level payload before application:\n" << *getTopLevel();
827823
auto printOnFailureRAII = llvm::make_scope_exit([this] {
828824
(void)this;
829-
LLVM_DEBUG(DBGS() << "Failing Top-level payload:\n"; getTopLevel()->print(
830-
llvm::dbgs(), mlir::OpPrintingFlags().printGenericOpForm()););
825+
LDBG() << "Failing Top-level payload:\n"
826+
<< OpWithFlags(getTopLevel(),
827+
OpPrintingFlags().printGenericOpForm());
831828
});
832829

833830
// Set current transform op.
@@ -995,8 +992,7 @@ transform::TransformState::applyTransform(TransformOpInterface transform) {
995992

996993
printOnFailureRAII.release();
997994
DEBUG_WITH_TYPE(DEBUG_PRINT_AFTER_ALL, {
998-
DBGS() << "Top-level payload:\n";
999-
getTopLevel()->print(llvm::dbgs());
995+
LDBG() << "Top-level payload:\n" << *getTopLevel();
1000996
});
1001997
return result;
1002998
}
@@ -1273,7 +1269,7 @@ void transform::TrackingListener::notifyMatchFailure(
12731269
LLVM_DEBUG({
12741270
Diagnostic diag(loc, DiagnosticSeverity::Remark);
12751271
reasonCallback(diag);
1276-
DBGS() << "Match Failure : " << diag.str();
1272+
LDBG() << "Match Failure : " << diag.str();
12771273
});
12781274
}
12791275

0 commit comments

Comments
 (0)