diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp --- a/mlir/lib/Rewrite/ByteCode.cpp +++ b/mlir/lib/Rewrite/ByteCode.cpp @@ -137,6 +137,8 @@ GetValueRangeTypes, /// Check if a generic value is not null. IsNotNull, + /// No operation, used in the debug mode to consume the line number. + NoOp, /// Record a successful pattern match. RecordMatch, /// Replace an operation. @@ -689,6 +691,12 @@ } void Generator::generate(Operation *op, ByteCodeWriter &writer) { + LLVM_DEBUG({ + if (auto loc = op->getLoc().dyn_cast()) + writer.append(ByteCodeAddr(loc.getLine())); + else + writer.append(ByteCodeAddr(0)); + }); TypeSwitch(op) .Case &matches); void executeReplaceOp(PatternRewriter &rewriter); @@ -1506,6 +1518,8 @@ LLVM_DEBUG(llvm::dbgs() << "Executing ForEach:\n"); // Subtract 1 for the op code. const ByteCodeField *it = curCodeIt - 1; + // Subtract 2 for the line number. + LLVM_DEBUG(it -= 2); unsigned rangeIndex = read(); unsigned memIndex = read(); const void *value = nullptr; @@ -1831,6 +1845,10 @@ selectJump(value != nullptr); } +void ByteCodeExecutor::executeNoOp() { + LLVM_DEBUG(llvm::dbgs() << "Executing NoOp\n"); +} + void ByteCodeExecutor::executeRecordMatch( PatternRewriter &rewriter, SmallVectorImpl &matches) { @@ -1983,6 +2001,10 @@ SmallVectorImpl *matches, Optional mainRewriteLoc) { while (true) { + LLVM_DEBUG({ + if (unsigned line = read()) + llvm::dbgs() << line << ": "; + }); OpCode opCode = static_cast(read()); switch (opCode) { case ApplyConstraint: @@ -2084,6 +2106,9 @@ case IsNotNull: executeIsNotNull(); break; + case NoOp: + executeNoOp(); + break; case RecordMatch: assert(matches && "expected matches to be provided when executing the matcher");