Skip to content

Commit 0665b2c

Browse files
Yu-Zhewenpstarkcdpr
authored andcommitted
Migrate custom LDBG macro to LLVM’s built-in debug logging (iree-org#22456)
This change removes IREE’s local LDBG macro definition in favor of the LLVM-provided version introduced in llvm/llvm-project#143704. This update is also in preparation for llvm/llvm-project#165429, which would otherwise cause a macro redefinition error due to the existing local LDBG definition. Signed-off-by: Yu-Zhewen <[email protected]>
1 parent 672e1de commit 0665b2c

File tree

6 files changed

+20
-28
lines changed

6 files changed

+20
-28
lines changed

compiler/src/iree/compiler/Dialect/Encoding/IR/EncodingAttrs.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
#include <cassert>
2626

2727
#define DEBUG_TYPE "iree-encoding-attrs"
28-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
29-
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
3028

3129
namespace mlir::iree_compiler::IREE::Encoding {
3230

compiler/src/iree/compiler/Dialect/LinalgExt/Utils/Utils.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "llvm/ADT/SetOperations.h"
1111
#include "llvm/ADT/TypeSwitch.h"
1212
#include "llvm/Support/Debug.h"
13+
#include "llvm/Support/DebugLog.h"
1314
#include "mlir/Analysis/SliceAnalysis.h"
1415
#include "mlir/Dialect/Affine/IR/AffineOps.h"
1516
#include "mlir/Dialect/Arith/IR/Arith.h"
@@ -23,8 +24,6 @@
2324
#include "mlir/Transforms/RegionUtils.h"
2425

2526
#define DEBUG_TYPE "iree-linalgExt-utils"
26-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
27-
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
2827

2928
namespace mlir::iree_compiler::IREE::LinalgExt {
3029

@@ -447,15 +446,15 @@ getIGEMMGenericConvDetails(linalg::LinalgOp linalgOp) {
447446
auto outputType = llvm::cast<ShapedType>(output.getType());
448447

449448
if (!filterType.hasStaticShape() || !inputType.hasStaticShape()) {
450-
LDBG("[unimplemented] expected 'filterType' and 'inputType' to have static "
451-
"shapes.");
449+
LDBG() << "[unimplemented] expected 'filterType' and 'inputType' to have "
450+
"static shapes.";
452451
return failure();
453452
}
454453

455454
// TODO: Support pooling operations. For pooling ops, the input/output channel
456455
// size will be categorized as the additional batch dimension.
457456
if (convDims.outputChannel.empty() || convDims.inputChannel.empty()) {
458-
LDBG("[unimplemented] expected no pooling operations");
457+
LDBG() << "[unimplemented] expected no pooling operations.";
459458
return failure();
460459
}
461460
auto filterShape = filterType.getShape();
@@ -480,7 +479,7 @@ getIGEMMGenericConvDetails(linalg::LinalgOp linalgOp) {
480479
std::optional<int64_t> outputImageFirstDim = outputMap.getResultPosition(
481480
getAffineDimExpr(outputImagePos[0], outputMap.getContext()));
482481
if (!outputImageFirstDim || !outputChannelLastDim) {
483-
LDBG("output image or output channel dim not found in output.");
482+
LDBG() << "output image or output channel dim not found in output.";
484483
return failure();
485484
}
486485
if (outputChannelLastDim.value() < outputImageFirstDim.value())

compiler/src/iree/compiler/DispatchCreation/HoistEncodingOps.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "iree/compiler/DispatchCreation/Passes.h"
2121
#include "llvm/ADT/STLExtras.h"
2222
#include "llvm/Support/Debug.h"
23+
#include "llvm/Support/DebugLog.h"
2324
#include "mlir/Dialect/Linalg/IR/Linalg.h"
2425
#include "mlir/Dialect/Linalg/Utils/Utils.h"
2526
#include "mlir/Dialect/MemRef/Transforms/Transforms.h"
@@ -37,8 +38,6 @@
3738
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
3839

3940
#define DEBUG_TYPE "iree-dispatch-creation-hoist-encoding-ops"
40-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
41-
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
4241

4342
namespace mlir::iree_compiler::DispatchCreation {
4443
#define GEN_PASS_DEF_HOISTENCODINGOPSPASS
@@ -330,20 +329,20 @@ void HoistEncodingOpsPass::runOnOperation() {
330329
const IREE::Util::ConstExprAnalysis::ConstValueInfo *constInfo =
331330
constExprs.lookup(setEncodingOp.getSource());
332331
if (!constInfo) {
333-
LDBG("Non-hoistable op (failed to get constInfo): " << setEncodingOp);
332+
LDBG() << "Non-hoistable op (failed to get constInfo): " << setEncodingOp;
334333
return;
335334
}
336335
if (policy.getDecision(constInfo)->getOutcome() ==
337336
IREE::Util::ConstExprHoistingPolicy::ENABLE_HOIST) {
338337
candidates.push_back(llvm::to_vector(llvm::reverse(opsWithinDispatch)));
339338
return;
340339
}
341-
LDBG("Non-hoistable op: " << setEncodingOp);
340+
LDBG() << "Non-hoistable op: " << setEncodingOp;
342341
});
343342

344343
IRRewriter rewriter(ctx);
345344
for (ArrayRef<Operation *> hoistableOps : candidates) {
346-
LDBG("Hoisting the ops for " << *hoistableOps.back());
345+
LDBG() << "Hoisting the ops for " << *hoistableOps.back();
347346
for (Operation *op : hoistableOps) {
348347
if (failed(IREE::Flow::hoistOutOfDispatch(rewriter, op))) {
349348
op->emitOpError("failed to hoist the op out of dispatch");

compiler/src/iree/compiler/GlobalOptimization/GeneralizeLinalgNamedOps.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include "mlir/Pass/Pass.h"
1919

2020
#define DEBUG_TYPE "iree-global-opt-generalize-linalg-named-ops"
21-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
22-
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
2321

2422
namespace mlir::iree_compiler::GlobalOptimization {
2523

compiler/src/iree/compiler/Preprocessing/Common/ConvertConvFilterToChannelsLast.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "iree/compiler/Preprocessing/Common/Passes.h"
88
#include "llvm/ADT/SmallVector.h"
99
#include "llvm/Support/Debug.h"
10+
#include "llvm/Support/DebugLog.h"
1011
#include "llvm/Support/LogicalResult.h"
1112
#include "mlir/Dialect/Arith/IR/Arith.h"
1213
#include "mlir/Dialect/Linalg/IR/Linalg.h"
@@ -20,8 +21,6 @@
2021
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2122

2223
#define DEBUG_TYPE "iree-preprocessing-convert-conv-filter-to-channels-last"
23-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
24-
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
2524

2625
namespace mlir::iree_compiler::Preprocessing {
2726

@@ -265,15 +264,15 @@ class ConvertConvFilterToChannelsLastPass
265264

266265
RewritePatternSet patterns(context);
267266
if (filterLayout == "hwfc") {
268-
LDBG("Converting filter layout to hwfc.");
267+
LDBG() << "Converting filter layout to hwfc.";
269268
patterns.add<ConvertHwcfToHwfc>(context);
270269
} else if (filterLayout == "fhwc") {
271-
LDBG("Converting filter layout to fhwc.");
270+
LDBG() << "Converting filter layout to fhwc.";
272271
patterns.add<ConvertHwcfToFhwc, ConvertGenericChwfToFhwc>(context);
273272
} else {
274-
LDBG("convert-filter-to-channels-last pass didn't apply since an "
275-
"unsupported layout is given. Please use hwfc or fhwc as pass "
276-
"filter-layout option.");
273+
LDBG() << "convert-filter-to-channels-last pass didn't apply since an "
274+
"unsupported layout is given. Please use hwfc or fhwc as pass "
275+
"filter-layout option.";
277276
return signalPassFailure();
278277
}
279278

compiler/src/iree/compiler/Preprocessing/Common/ConvertConvToChannelsLast.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "llvm/ADT/STLExtras.h"
99
#include "llvm/ADT/StringRef.h"
1010
#include "llvm/Support/Debug.h"
11+
#include "llvm/Support/DebugLog.h"
1112
#include "mlir/Dialect/Arith/IR/Arith.h"
1213
#include "mlir/Dialect/Linalg/IR/Linalg.h"
1314
#include "mlir/Dialect/Linalg/Transforms/Transforms.h"
@@ -22,8 +23,6 @@
2223
#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
2324

2425
#define DEBUG_TYPE "iree-preprocessing-convert-conv-to-channels-last"
25-
#define DBGS() (llvm::dbgs() << "[" DEBUG_TYPE "]: ")
26-
#define LDBG(X) LLVM_DEBUG(DBGS() << X << "\n")
2726

2827
namespace mlir::iree_compiler::Preprocessing {
2928

@@ -672,7 +671,7 @@ class ConvertConvToChannelsLastPass
672671
}
673672
}
674673

675-
LDBG("after converting convolutions to channels last\n" << *op);
674+
LDBG() << "after converting convolutions to channels last\n" << *op;
676675

677676
// Propagate packs introduced by the conversion patterns through adjacent
678677
// pads. Note that packs introduced by the above patterns will never include
@@ -688,7 +687,7 @@ class ConvertConvToChannelsLastPass
688687
}
689688
}
690689

691-
LDBG("after propagating packs/unpacks\n" << *op);
690+
LDBG() << "after propagating packs/unpacks\n" << *op;
692691

693692
// Run pack/unpack canonicalization to try to cancel any packs.
694693
{
@@ -701,7 +700,7 @@ class ConvertConvToChannelsLastPass
701700
}
702701
}
703702

704-
LDBG("after canonicalizing packs/unpacks\n" << *op);
703+
LDBG() << "after canonicalizing packs/unpacks\n" << *op;
705704

706705
// Generalize leftover packs and unpacks that are just transposes to allow
707706
// for transpose propagation and unit dim folding to handle them more
@@ -715,7 +714,7 @@ class ConvertConvToChannelsLastPass
715714
}
716715
}
717716

718-
LDBG("after generalizing all remaining packs/unpacks\n" << *op);
717+
LDBG() << "after generalizing all remaining packs/unpacks\n" << *op;
719718
}
720719
};
721720

0 commit comments

Comments
 (0)