Skip to content

Commit 2cdd246

Browse files
authored
[Sim] Introduce sim.triggered op (#10450)
1 parent 96997a1 commit 2cdd246

3 files changed

Lines changed: 61 additions & 0 deletions

File tree

include/circt/Dialect/Sim/SimOps.td

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,4 +1146,31 @@ def PauseOp : SimOp<"pause", [ProceduralOp]> {
11461146
}];
11471147
}
11481148

1149+
def TriggeredOp : SimOp<"triggered", [
1150+
SingleBlock, NoTerminator, NonProceduralOp, ProceduralRegion]> {
1151+
let summary = "A procedural region triggered on a clock edge";
1152+
let description = [{
1153+
A procedural region that executes on the rising edge of the given clock.
1154+
An optional 1-bit condition can be provided to guard execution of the
1155+
region on that clock edge.
1156+
}];
1157+
1158+
let arguments = (ins ClockType:$clock, Optional<I1>:$condition);
1159+
let regions = (region SizedRegion<1>:$body);
1160+
let assemblyFormat = [{
1161+
$clock (`if` $condition^)? $body attr-dict
1162+
}];
1163+
1164+
let extraClassDeclaration = [{
1165+
Block *getBodyBlock() { return &getBody().front(); }
1166+
}];
1167+
1168+
let skipDefaultBuilders = 1;
1169+
let builders = [
1170+
OpBuilder<(ins
1171+
"Value":$clock,
1172+
CArg<"Value", "mlir::Value()">:$condition)>
1173+
];
1174+
}
1175+
11491176
#endif // CIRCT_DIALECT_SIM_SIMOPS_TD

lib/Dialect/Sim/SimOps.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,20 @@ LogicalResult QueueConcatOp::verify() {
757757
return success();
758758
}
759759

760+
//===----------------------------------------------------------------------===//
761+
// TriggeredOp
762+
//===----------------------------------------------------------------------===//
763+
764+
void TriggeredOp::build(OpBuilder &builder, OperationState &odsState,
765+
Value clock, Value condition) {
766+
odsState.addOperands(clock);
767+
if (condition)
768+
odsState.addOperands(condition);
769+
770+
auto *region = odsState.addRegion();
771+
region->push_back(new Block());
772+
}
773+
760774
//===----------------------------------------------------------------------===//
761775
// TableGen generated logic.
762776
//===----------------------------------------------------------------------===//

test/Dialect/Sim/round-trip.mlir

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,26 @@ hw.module @ProceduralPrint(in %trigger: i1, in %condition: i1) {
145145
}
146146
}
147147

148+
// CHECK-LABEL: hw.module @SimTriggered
149+
hw.module @SimTriggered(in %clock: !seq.clock, in %condition: i1) {
150+
// CHECK: %[[MSG0:.*]] = sim.fmt.literal "tick"
151+
%msg0 = sim.fmt.literal "tick"
152+
// CHECK: %[[MSG1:.*]] = sim.fmt.literal "tock"
153+
%msg1 = sim.fmt.literal "tock"
154+
155+
// CHECK: sim.triggered %clock {
156+
sim.triggered %clock {
157+
// CHECK: sim.proc.print %[[MSG0]]
158+
sim.proc.print %msg0
159+
}
160+
161+
// CHECK: sim.triggered %clock if %condition {
162+
sim.triggered %clock if %condition {
163+
// CHECK: sim.proc.print %[[MSG1]]
164+
sim.proc.print %msg1
165+
}
166+
}
167+
148168
// CHECK-LABEL: hw.module @StdoutAndStderr
149169
hw.module @StdoutAndStderr(in %clock: !seq.clock, in %condition: i1) {
150170
// CHECK: %[[STDOUT_STR:.*]] = sim.fmt.literal "Hello, stdout!"

0 commit comments

Comments
 (0)