Skip to content

Commit

Permalink
[FIRParser] Do not swallow stop ops when parsing FIR (llvm#6834)
Browse files Browse the repository at this point in the history
  • Loading branch information
nandor authored Mar 15, 2024
1 parent 6914bc6 commit c848464
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
34 changes: 17 additions & 17 deletions lib/Dialect/FIRRTL/Import/FIRParserAsserts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,6 @@ ParseResult circt::firrtl::foldWhenEncodedVerifOp(PrintFOp printOp) {
auto opIt = std::next(printOp->getIterator());
auto opEnd = thenBlock.end();

// optional `stop(clock, enable, ...)`
//
// FIXME: Currently, we can't detetct stopOp in the following IR:
// when invCond:
// printf(io.clock, UInt<1>(1), "assert: ..")
// stop(io.clock, UInt<1>(1), 1)
// It is because `io.clock` will create another subfield op so StopOp is not
// the next operation. Also, we will have to modify `stopOp.clock() !=
// printOp.clock()` below since they are not CSEd.
if (opIt != opEnd) {
auto stopOp = dyn_cast<StopOp>(*opIt++);
if (!stopOp || opIt != opEnd || stopOp.getClock() != printOp.getClock() ||
stopOp.getCond() != printOp.getCond())
return success();
stopOp.erase();
}

// Detect if we're dealing with a verification statement, and what flavor of
// statement it is.
auto fmt = printOp.getFormatString();
Expand All @@ -281,6 +264,23 @@ ParseResult circt::firrtl::foldWhenEncodedVerifOp(PrintFOp printOp) {
else
return success();

// optional `stop(clock, enable, ...)`
//
// FIXME: Currently, we can't detetct stopOp in the following IR:
// when invCond:
// printf(io.clock, UInt<1>(1), "assert: ..")
// stop(io.clock, UInt<1>(1), 1)
// It is because `io.clock` will create another subfield op so StopOp is not
// the next operation. Also, we will have to modify `stopOp.clock() !=
// printOp.clock()` below since they are not CSEd.
if (opIt != opEnd) {
auto stopOp = dyn_cast<StopOp>(*opIt++);
if (!stopOp || opIt != opEnd || stopOp.getClock() != printOp.getClock() ||
stopOp.getCond() != printOp.getCond())
return success();
stopOp.erase();
}

// Check if the condition of the `WhenOp` is a trivial inversion operation,
// and remove any immediately preceding verification ops that ensure this
// condition. This caters to the following pattern emitted by Chisel:
Expand Down
1 change: 1 addition & 0 deletions test/firtool/stop.fir
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@ circuit StopAndFinishTest:
; CHECK: }
; CHECK: }

printf(clock, cond, "Stop message")
stop(clock, cond, 0)
stop(clock, cond, 1)

0 comments on commit c848464

Please sign in to comment.