Skip to content

Commit

Permalink
[MooreToCore] Branch to resume block instead of wait block (#8184)
Browse files Browse the repository at this point in the history
  • Loading branch information
maerhart authored Feb 3, 2025
1 parent 3177484 commit 1b33c44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 11 additions & 7 deletions lib/Conversion/MooreToCore/MooreToCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,20 @@ struct WaitEventOpConversion : public OpConversionPattern<WaitEventOp> {
rewriter.eraseOp(detectOp);
}

// If any `detect_event` op detected an event, branch to the "resume" block
// which contains any code after the `wait_event` op. If no events were
// detected, branch back to the "wait" block to wait for the next change on
// the interesting signals.
rewriter.setInsertionPointToEnd(checkBlock);
if (!triggers.empty()) {
if (triggers.empty()) {
// If there are no triggers to check, we always branch to the resume
// block. If there are no detect_event operations in the wait event, the
// 'llhd.wait' operation will not have any observed values and thus the
// process will hang there forever.
rewriter.create<cf::BranchOp>(loc, resumeBlock);
} else {
// If any `detect_event` op detected an event, branch to the "resume"
// block which contains any code after the `wait_event` op. If no events
// were detected, branch back to the "wait" block to wait for the next
// change on the interesting signals.
auto triggered = rewriter.createOrFold<comb::OrOp>(loc, triggers, true);
rewriter.create<cf::CondBranchOp>(loc, triggered, resumeBlock, waitBlock);
} else {
rewriter.create<cf::BranchOp>(loc, waitBlock);
}

return success();
Expand Down
3 changes: 2 additions & 1 deletion test/Conversion/MooreToCore/basic.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,8 @@ moore.module @WaitEvent() {
// CHECK: [[BEFORE:%.+]] = llhd.prb %a
// CHECK: llhd.wait ([[PRB_A0]] : {{.+}}), ^[[CHECK:.+]]
// CHECK: ^[[CHECK]]:
// CHECK: cf.br
// CHECK: cf.br ^[[RESUME:.+]]
// CHECK: ^[[RESUME]]:
moore.wait_event {
%0 = moore.read %a : <i1>
moore.detect_event any %0 : i1
Expand Down

0 comments on commit 1b33c44

Please sign in to comment.