Skip to content

Commit 8104ea2

Browse files
jpienaarJaddyen
authored andcommitted
[mlir] Switch to new LDBG macro (llvm#150616)
Change local variants to use new central one.
1 parent 0e64d82 commit 8104ea2

File tree

20 files changed

+372
-433
lines changed

20 files changed

+372
-433
lines changed

mlir/lib/Analysis/DataFlow/DeadCodeAnalysis.cpp

Lines changed: 65 additions & 65 deletions
Large diffs are not rendered by default.

mlir/lib/Analysis/DataFlow/LivenessAnalysis.cpp

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <cassert>
1111
#include <mlir/Analysis/DataFlow/LivenessAnalysis.h>
1212

13-
#include <llvm/Support/Debug.h>
13+
#include <llvm/Support/DebugLog.h>
1414
#include <mlir/Analysis/DataFlow/SparseAnalysis.h>
1515
#include <mlir/Analysis/DataFlow/Utils.h>
1616
#include <mlir/Analysis/DataFlowFramework.h>
@@ -22,7 +22,6 @@
2222

2323
#define DEBUG_TYPE "liveness-analysis"
2424
#define DBGS() (llvm::dbgs() << '[' << DEBUG_TYPE << "] ")
25-
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
2625

2726
using namespace mlir;
2827
using namespace mlir::dataflow;
@@ -86,11 +85,11 @@ LivenessAnalysis::visitOperation(Operation *op, ArrayRef<Liveness *> operands,
8685
llvm::dbgs() << "\n");
8786
// This marks values of type (1.a) and (4) liveness as "live".
8887
if (!isMemoryEffectFree(op) || op->hasTrait<OpTrait::ReturnLike>()) {
89-
LDBG("[visitOperation] Operation has memory effects or is "
90-
"return-like, marking operands live");
88+
LDBG() << "[visitOperation] Operation has memory effects or is "
89+
"return-like, marking operands live";
9190
for (auto *operand : operands) {
92-
LDBG(" [visitOperation] Marking operand live: "
93-
<< operand << " (" << operand->isLive << ")");
91+
LDBG() << " [visitOperation] Marking operand live: " << operand << " ("
92+
<< operand->isLive << ")";
9493
propagateIfChanged(operand, operand->markLive());
9594
}
9695
}
@@ -99,28 +98,28 @@ LivenessAnalysis::visitOperation(Operation *op, ArrayRef<Liveness *> operands,
9998
bool foundLiveResult = false;
10099
for (const Liveness *r : results) {
101100
if (r->isLive && !foundLiveResult) {
102-
LDBG("[visitOperation] Found live result, "
103-
"meeting all operands with result: "
104-
<< r);
101+
LDBG() << "[visitOperation] Found live result, "
102+
"meeting all operands with result: "
103+
<< r;
105104
// It is assumed that each operand is used to compute each result of an
106105
// op. Thus, if at least one result is live, each operand is live.
107106
for (Liveness *operand : operands) {
108-
LDBG(" [visitOperation] Meeting operand: " << operand
109-
<< " with result: " << r);
107+
LDBG() << " [visitOperation] Meeting operand: " << operand
108+
<< " with result: " << r;
110109
meet(operand, *r);
111110
}
112111
foundLiveResult = true;
113112
}
114-
LDBG("[visitOperation] Adding dependency for result: " << r << " after op: "
115-
<< *op);
113+
LDBG() << "[visitOperation] Adding dependency for result: " << r
114+
<< " after op: " << *op;
116115
addDependency(const_cast<Liveness *>(r), getProgramPointAfter(op));
117116
}
118117
return success();
119118
}
120119

121120
void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
122-
LDBG("Visiting branch operand: " << operand.get()
123-
<< " in op: " << *operand.getOwner());
121+
LDBG() << "Visiting branch operand: " << operand.get()
122+
<< " in op: " << *operand.getOwner();
124123
// We know (at the moment) and assume (for the future) that `operand` is a
125124
// non-forwarded branch operand of a `RegionBranchOpInterface`,
126125
// `BranchOpInterface`, `RegionBranchTerminatorOpInterface` or return-like op.
@@ -152,9 +151,9 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
152151
for (Value result : op->getResults()) {
153152
if (getLatticeElement(result)->isLive) {
154153
mayLive = true;
155-
LDBG("[visitBranchOperand] Non-forwarded branch "
156-
"operand may be live due to live result: "
157-
<< result);
154+
LDBG() << "[visitBranchOperand] Non-forwarded branch "
155+
"operand may be live due to live result: "
156+
<< result;
158157
break;
159158
}
160159
}
@@ -174,8 +173,8 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
174173
// Therefore, we conservatively consider the non-forwarded operand of the
175174
// branch operation may live.
176175
mayLive = true;
177-
LDBG("[visitBranchOperand] Non-forwarded branch operand may "
178-
"be live due to branch op interface");
176+
LDBG() << "[visitBranchOperand] Non-forwarded branch operand may "
177+
"be live due to branch op interface";
179178
} else {
180179
Operation *parentOp = op->getParentOp();
181180
assert(isa<RegionBranchOpInterface>(parentOp) &&
@@ -191,9 +190,9 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
191190
for (Value result : parentOp->getResults()) {
192191
if (getLatticeElement(result)->isLive) {
193192
mayLive = true;
194-
LDBG("[visitBranchOperand] Non-forwarded branch "
195-
"operand may be live due to parent live result: "
196-
<< result);
193+
LDBG() << "[visitBranchOperand] Non-forwarded branch "
194+
"operand may be live due to parent live result: "
195+
<< result;
197196
break;
198197
}
199198
}
@@ -214,17 +213,17 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
214213
for (Operation &nestedOp : *block) {
215214
if (!isMemoryEffectFree(&nestedOp)) {
216215
mayLive = true;
217-
LDBG("Non-forwarded branch operand may be "
218-
"live due to memory effect in block: "
219-
<< block);
216+
LDBG() << "Non-forwarded branch operand may be "
217+
"live due to memory effect in block: "
218+
<< block;
220219
break;
221220
}
222221
}
223222
}
224223

225224
if (mayLive) {
226225
Liveness *operandLiveness = getLatticeElement(operand.get());
227-
LDBG("Marking branch operand live: " << operand.get());
226+
LDBG() << "Marking branch operand live: " << operand.get();
228227
propagateIfChanged(operandLiveness, operandLiveness->markLive());
229228
}
230229

@@ -236,7 +235,7 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
236235
SmallVector<const Liveness *, 4> resultsLiveness;
237236
for (const Value result : op->getResults())
238237
resultsLiveness.push_back(getLatticeElement(result));
239-
LDBG("Visiting operation for non-forwarded branch operand: " << *op);
238+
LDBG() << "Visiting operation for non-forwarded branch operand: " << *op;
240239
(void)visitOperation(op, operandLiveness, resultsLiveness);
241240

242241
// We also visit the parent op with the parent's results and this operand if
@@ -249,14 +248,14 @@ void LivenessAnalysis::visitBranchOperand(OpOperand &operand) {
249248
SmallVector<const Liveness *, 4> parentResultsLiveness;
250249
for (const Value parentResult : parentOp->getResults())
251250
parentResultsLiveness.push_back(getLatticeElement(parentResult));
252-
LDBG("Visiting parent operation for non-forwarded branch operand: "
253-
<< *parentOp);
251+
LDBG() << "Visiting parent operation for non-forwarded branch operand: "
252+
<< *parentOp;
254253
(void)visitOperation(parentOp, operandLiveness, parentResultsLiveness);
255254
}
256255

257256
void LivenessAnalysis::visitCallOperand(OpOperand &operand) {
258-
LDBG("Visiting call operand: " << operand.get()
259-
<< " in op: " << *operand.getOwner());
257+
LDBG() << "Visiting call operand: " << operand.get()
258+
<< " in op: " << *operand.getOwner();
260259
// We know (at the moment) and assume (for the future) that `operand` is a
261260
// non-forwarded call operand of an op implementing `CallOpInterface`.
262261
assert(isa<CallOpInterface>(operand.getOwner()) &&
@@ -269,18 +268,18 @@ void LivenessAnalysis::visitCallOperand(OpOperand &operand) {
269268
// This marks values of type (1.c) liveness as "live". A non-forwarded
270269
// call operand is live.
271270
Liveness *operandLiveness = getLatticeElement(operand.get());
272-
LDBG("Marking call operand live: " << operand.get());
271+
LDBG() << "Marking call operand live: " << operand.get();
273272
propagateIfChanged(operandLiveness, operandLiveness->markLive());
274273
}
275274

276275
void LivenessAnalysis::setToExitState(Liveness *lattice) {
277-
LDBG("setToExitState for lattice: " << lattice);
276+
LDBG() << "setToExitState for lattice: " << lattice;
278277
if (lattice->isLive) {
279-
LDBG("Lattice already live, nothing to do");
278+
LDBG() << "Lattice already live, nothing to do";
280279
return;
281280
}
282281
// This marks values of type (2) liveness as "live".
283-
LDBG("Marking lattice live due to exit state");
282+
LDBG() << "Marking lattice live due to exit state";
284283
(void)lattice->markLive();
285284
propagateIfChanged(lattice, ChangeResult::Change);
286285
}
@@ -290,14 +289,14 @@ void LivenessAnalysis::setToExitState(Liveness *lattice) {
290289
//===----------------------------------------------------------------------===//
291290

292291
RunLivenessAnalysis::RunLivenessAnalysis(Operation *op) {
293-
LDBG("Constructing RunLivenessAnalysis for op: " << op->getName());
292+
LDBG() << "Constructing RunLivenessAnalysis for op: " << op->getName();
294293
SymbolTableCollection symbolTable;
295294

296295
loadBaselineAnalyses(solver);
297296
solver.load<LivenessAnalysis>(symbolTable);
298-
LDBG("Initializing and running solver");
297+
LDBG() << "Initializing and running solver";
299298
(void)solver.initializeAndRun(op);
300-
LDBG("Dumping liveness state for op");
299+
LDBG() << "Dumping liveness state for op";
301300
}
302301

303302
const Liveness *RunLivenessAnalysis::getLiveness(Value val) {

mlir/lib/Dialect/Bufferization/IR/BufferizableOpInterface.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "mlir/IR/Value.h"
1919
#include "mlir/Interfaces/ControlFlowInterfaces.h"
2020
#include "llvm/ADT/ScopeExit.h"
21-
#include "llvm/Support/Debug.h"
2221

2322
//===----------------------------------------------------------------------===//
2423
// BufferizableOpInterface
@@ -35,8 +34,6 @@ namespace bufferization {
3534
MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::bufferization::AnalysisState)
3635

3736
#define DEBUG_TYPE "bufferizable-op-interface"
38-
#define DBGS() (llvm::dbgs() << '[' << DEBUG_TYPE << "] ")
39-
#define LDBG(X) LLVM_DEBUG(DBGS() << (X))
4037

4138
using namespace mlir;
4239
using namespace bufferization;

mlir/lib/Dialect/Bufferization/Transforms/OptimizeAllocationLiveness.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@
1818
#include "mlir/IR/Operation.h"
1919
#include "mlir/IR/Value.h"
2020
#include "mlir/Interfaces/SideEffectInterfaces.h"
21-
#include "llvm/Support/Debug.h"
21+
#include "llvm/Support/DebugLog.h"
2222

2323
#define DEBUG_TYPE "optimize-allocation-liveness"
24-
#define DBGS() (llvm::dbgs() << '[' << DEBUG_TYPE << "] ")
25-
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
2624

2725
namespace mlir {
2826
namespace bufferization {
@@ -65,8 +63,8 @@ Operation *findUserWithFreeSideEffect(Value value) {
6563
for (const auto &effect : effects) {
6664
if (isa<MemoryEffects::Free>(effect.getEffect())) {
6765
if (freeOpUser) {
68-
LDBG("Multiple users with free effect found: " << *freeOpUser
69-
<< " and " << *user);
66+
LDBG() << "Multiple users with free effect found: " << *freeOpUser
67+
<< " and " << *user;
7068
return nullptr;
7169
}
7270
freeOpUser = user;
@@ -121,15 +119,15 @@ struct OptimizeAllocationLiveness
121119
return WalkResult::advance();
122120

123121
auto allocOp = memEffectOp;
124-
LDBG("Checking alloc op: " << allocOp);
122+
LDBG() << "Checking alloc op: " << allocOp;
125123

126124
SmallVector<OpResult> allocationResults = collectAllocations(allocOp);
127125
// Multiple allocations from a single op are not considered here yet.
128126
if (allocationResults.size() != 1)
129127
return WalkResult::advance();
130128

131129
OpResult allocResult = allocationResults[0];
132-
LDBG("On allocation result: " << allocResult);
130+
LDBG() << "On allocation result: " << allocResult;
133131

134132
auto *deallocOp = findUserWithFreeSideEffect(allocResult);
135133
if (!deallocOp || (deallocOp->getBlock() != allocOp->getBlock())) {
@@ -159,12 +157,12 @@ struct OptimizeAllocationLiveness
159157
if (lastUser == nullptr) {
160158
return WalkResult::advance();
161159
}
162-
LDBG("Last user found: " << *lastUser);
160+
LDBG() << "Last user found: " << *lastUser;
163161
assert(lastUser->getBlock() == allocOp->getBlock());
164162
assert(lastUser->getBlock() == deallocOp->getBlock());
165163
// Move the dealloc op after the last user.
166164
deallocOp->moveAfter(lastUser);
167-
LDBG("Moved dealloc op after: " << *lastUser);
165+
LDBG() << "Moved dealloc op after: " << *lastUser;
168166

169167
return WalkResult::advance();
170168
});

mlir/lib/Dialect/GPU/TransformOps/GPUTransformOps.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include "llvm/ADT/STLExtras.h"
4040
#include "llvm/ADT/SmallVector.h"
4141
#include "llvm/ADT/TypeSwitch.h"
42-
#include "llvm/Support/Debug.h"
42+
#include "llvm/Support/DebugLog.h"
4343
#include "llvm/Support/ErrorHandling.h"
4444
#include "llvm/Support/InterleavedRange.h"
4545
#include "llvm/Support/LogicalResult.h"
@@ -51,11 +51,6 @@ using namespace mlir::transform;
5151
using namespace mlir::transform::gpu;
5252

5353
#define DEBUG_TYPE "gpu-transforms"
54-
#define DEBUG_TYPE_ALIAS "gpu-transforms-alias"
55-
56-
#define DBGS() (llvm::dbgs() << '[' << DEBUG_TYPE << "] ")
57-
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
58-
#define DBGS_ALIAS() (llvm::dbgs() << '[' << DEBUG_TYPE_ALIAS << "] ")
5954

6055
//===----------------------------------------------------------------------===//
6156
// Apply...ConversionPatternsOp
@@ -471,7 +466,7 @@ static DiagnosedSilenceableFailure rewriteOneForallCommonImpl(
471466
RewriterBase &rewriter, std::optional<TransformOpInterface> transformOp,
472467
scf::ForallOp forallOp, ArrayRef<int64_t> availableMappingSizes,
473468
ForallRewriteResult &result, const GpuIdBuilder &gpuIdBuilder) {
474-
LDBG("--start rewriteOneForallCommonImpl");
469+
LDBG() << "--start rewriteOneForallCommonImpl";
475470

476471
// Step 1. Complete the mapping to a full mapping (with 1s) if necessary.
477472
auto numParallelIterations =
@@ -506,14 +501,14 @@ static DiagnosedSilenceableFailure rewriteOneForallCommonImpl(
506501
// Otherwise, we have a new insertion without a size -> use size 1.
507502
tmpMappingSizes.push_back(1);
508503
}
509-
LDBG("----tmpMappingSizes extracted from scf.forall op: "
510-
<< llvm::interleaved(tmpMappingSizes));
504+
LDBG() << "----tmpMappingSizes extracted from scf.forall op: "
505+
<< llvm::interleaved(tmpMappingSizes);
511506

512507
// Step 2. sort the values by the corresponding DeviceMappingAttrInterface.
513508
SmallVector<int64_t> forallMappingSizes = getValuesSortedByKey(
514509
forallMappingAttrs.getArrayRef(), tmpMappingSizes, comparator);
515-
LDBG("----forallMappingSizes: " << llvm::interleaved(forallMappingSizes));
516-
LDBG("----forallMappingAttrs: " << llvm::interleaved(forallMappingAttrs));
510+
LDBG() << "----forallMappingSizes: " << llvm::interleaved(forallMappingSizes);
511+
LDBG() << "----forallMappingAttrs: " << llvm::interleaved(forallMappingAttrs);
517512

518513
// Step 3. Generate the mappingIdOps using the provided generator.
519514
Location loc = forallOp.getLoc();
@@ -522,24 +517,24 @@ static DiagnosedSilenceableFailure rewriteOneForallCommonImpl(
522517
SmallVector<int64_t> originalBasis(availableMappingSizes);
523518
bool originalBasisWasProvided = !originalBasis.empty();
524519
if (!originalBasisWasProvided) {
525-
LDBG("----originalBasis was not provided, deriving it and there will be no "
526-
"predication");
520+
LDBG() << "----originalBasis was not provided, deriving it and there will "
521+
"be no "
522+
"predication";
527523
originalBasis = forallMappingSizes;
528524
while (originalBasis.size() < 3)
529525
originalBasis.push_back(1);
530526
} else {
531-
LDBG("----originalBasis was provided, using it, there will be predication");
527+
LDBG() << "----originalBasis was provided, using it, there will be "
528+
"predication";
532529
}
533-
LLVM_DEBUG(
534-
llvm::interleaveComma(originalBasis, DBGS() << "------originalBasis: ");
535-
llvm::dbgs() << "\n");
530+
LDBG() << "------originalBasis: " << llvm::interleaved(originalBasis);
536531

537532
IdBuilderResult builderResult =
538533
gpuIdBuilder.idBuilder(rewriter, loc, forallMappingSizes, originalBasis);
539534
if (!builderResult.errorMsg.empty())
540535
return definiteFailureHelper(transformOp, forallOp, builderResult.errorMsg);
541536

542-
LLVM_DEBUG(DBGS() << builderResult);
537+
LDBG() << builderResult;
543538

544539
// Step 4. Map the induction variables to the mappingIdOps, this may involve
545540
// a permutation.
@@ -550,7 +545,7 @@ static DiagnosedSilenceableFailure rewriteOneForallCommonImpl(
550545
forallMappingAttrs.getArrayRef().take_front(forallOp.getRank()))) {
551546
auto mappingAttr = cast<DeviceMappingAttrInterface>(dim);
552547
Value peIdOp = mappingIdOps[mappingAttr.getRelativeIndex()];
553-
LDBG("----map: " << iv << " to " << peIdOp);
548+
LDBG() << "----map: " << iv << " to " << peIdOp;
554549
bvm.map(iv, peIdOp);
555550
}
556551

@@ -596,9 +591,9 @@ static DiagnosedSilenceableFailure rewriteOneForallCommonImpl(
596591
// Step 8. Erase old op.
597592
rewriter.eraseOp(forallOp);
598593

599-
LDBG("----result forallMappingSizes: "
600-
<< llvm::interleaved(forallMappingSizes));
601-
LDBG("----result mappingIdOps: " << llvm::interleaved(mappingIdOps));
594+
LDBG() << "----result forallMappingSizes: "
595+
<< llvm::interleaved(forallMappingSizes);
596+
LDBG() << "----result mappingIdOps: " << llvm::interleaved(mappingIdOps);
602597

603598
result = ForallRewriteResult{forallMappingSizes, mappingIdOps};
604599
return DiagnosedSilenceableFailure::success();
@@ -612,7 +607,7 @@ DiagnosedSilenceableFailure mlir::transform::gpu::mapForallToBlocksImpl(
612607
RewriterBase &rewriter, TransformOpInterface transformOp,
613608
scf::ForallOp forallOp, SmallVectorImpl<int64_t> &gridDims,
614609
const GpuIdBuilder &gpuIdBuilder) {
615-
LDBG("Start mapForallToBlocksImpl");
610+
LDBG() << "Start mapForallToBlocksImpl";
616611

617612
{
618613
// GPU-specific verifications. There is no better place to anchor
@@ -893,7 +888,7 @@ DiagnosedSilenceableFailure mlir::transform::gpu::mapNestedForallToThreadsImpl(
893888
RewriterBase &rewriter, std::optional<TransformOpInterface> transformOp,
894889
Operation *target, ArrayRef<int64_t> blockDims, int64_t warpSize,
895890
bool syncAfterDistribute) {
896-
LDBG("Start mapNestedForallToThreadsImpl");
891+
LDBG() << "Start mapNestedForallToThreadsImpl";
897892
if (blockDims.size() != 3) {
898893
return definiteFailureHelper(transformOp, target,
899894
"requires size-3 thread mapping");

0 commit comments

Comments
 (0)