Skip to content

[mlir][Transforms] GreedyPatternRewriteDriver: log successful folding #77796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,21 @@ struct DebugFingerPrints : public RewriterBase::ForwardingListener {
};
#endif // MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS

#ifndef NDEBUG
static Operation *getDumpRootOp(Operation *op) {
// Dump the parent op so that materialized constants are visible. If the op
// is a top-level op, dump it directly.
if (Operation *parentOp = op->getParentOp())
return parentOp;
return op;
}
static void logSuccessfulFolding(Operation *op) {
llvm::dbgs() << "// *** IR Dump After Successful Folding ***\n";
op->dump();
llvm::dbgs() << "\n\n";
}
#endif // NDEBUG

//===----------------------------------------------------------------------===//
// Worklist
//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -434,10 +449,14 @@ bool GreedyPatternRewriteDriver::processWorklist() {
SmallVector<OpFoldResult> foldResults;
if (succeeded(op->fold(foldResults))) {
LLVM_DEBUG(logResultWithLine("success", "operation was folded"));
#ifndef NDEBUG
Operation *dumpRootOp = getDumpRootOp(op);
#endif // NDEBUG
if (foldResults.empty()) {
// Op was modified in-place.
notifyOperationModified(op);
changed = true;
LLVM_DEBUG(logSuccessfulFolding(dumpRootOp));
#if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
if (config.scope && failed(verify(config.scope->getParentOp())))
llvm::report_fatal_error("IR failed to verify after folding");
Expand Down Expand Up @@ -492,6 +511,7 @@ bool GreedyPatternRewriteDriver::processWorklist() {
if (materializationSucceeded) {
replaceOp(op, replacements);
changed = true;
LLVM_DEBUG(logSuccessfulFolding(dumpRootOp));
#if MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS
if (config.scope && failed(verify(config.scope->getParentOp())))
llvm::report_fatal_error("IR failed to verify after folding");
Expand Down