Skip to content

Commit

Permalink
[mlir][bufferize][NFC] Debug output during bufferization
Browse files Browse the repository at this point in the history
When running with `-debug`, print the IR after bufferizing each op.

Differential Revision: https://reviews.llvm.org/D137065
  • Loading branch information
matthias-springer committed Oct 31, 2022
1 parent 181ede0 commit df23ede
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions mlir/lib/Dialect/Bufferization/Transforms/Bufferize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace bufferization {
} // namespace bufferization
} // namespace mlir

#define DEBUG_TYPE "bufferize"

using namespace mlir;
using namespace mlir::bufferization;

Expand Down Expand Up @@ -436,23 +438,33 @@ LogicalResult bufferization::bufferizeOp(Operation *op,
BufferizationRewriter rewriter(op->getContext(), erasedOps, toMemrefOps,
worklist, options, opFilter);
for (unsigned i = 0; i < worklist.size(); ++i) {
Operation *op = worklist[i];
Operation *nextOp = worklist[i];
// Skip ops that were erased.
if (erasedOps.contains(op))
if (erasedOps.contains(nextOp))
continue;
// Skip ops that are not bufferizable or not allowed.
auto bufferizableOp = options.dynCastBufferizableOp(op);
auto bufferizableOp = options.dynCastBufferizableOp(nextOp);
if (!bufferizableOp)
continue;
if (opFilter && !opFilter->isOpAllowed(op))
if (opFilter && !opFilter->isOpAllowed(nextOp))
continue;
// Skip ops that no longer have tensor semantics.
if (!hasTensorSemantics(op))
if (!hasTensorSemantics(nextOp))
continue;
// Bufferize the op.
rewriter.setInsertionPoint(op);
if (failed(bufferizableOp.bufferize(rewriter, options)))
return op->emitError("failed to bufferize op");
LLVM_DEBUG(llvm::dbgs()
<< "//===-------------------------------------------===//\n"
<< "IR after bufferizing: " << nextOp->getName() << "\n");
rewriter.setInsertionPoint(nextOp);
if (failed(bufferizableOp.bufferize(rewriter, options))) {
LLVM_DEBUG(llvm::dbgs()
<< "failed to bufferize\n"
<< "//===-------------------------------------------===//\n");
return nextOp->emitError("failed to bufferize op");
}
LLVM_DEBUG(llvm::dbgs()
<< *op
<< "\n//===-------------------------------------------===//\n");
}

// Fold all to_memref(to_tensor(x)) pairs.
Expand Down

0 comments on commit df23ede

Please sign in to comment.