Skip to content

Commit ca52474

Browse files
committed
[MooreToCore] Add nested moore.conditional support
This code adds correct lowering for nested ternary operators like this: ```verilog module Mod(input a, input b, output logic [1:0] c); always_comb c = a ? b ? 2'd0 : 2'd1 : 2'd2; endmodule ```
1 parent d47a9d2 commit ca52474

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

lib/Conversion/MooreToCore/MooreToCore.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -1346,6 +1346,9 @@ struct ConditionalOpConversion : public OpConversionPattern<ConditionalOp> {
13461346
!memOp.hasEffect<MemoryEffects::Free>())
13471347
return WalkResult::advance();
13481348

1349+
if (operation->hasTrait<OpTrait::HasRecursiveMemoryEffects>())
1350+
return WalkResult::advance();
1351+
13491352
return WalkResult::interrupt();
13501353
});
13511354
return !result.wasInterrupted();

test/Conversion/MooreToCore/basic.mlir

+25
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,31 @@ moore.module @StringConstant() {
982982
}
983983
}
984984

985+
// CHECK-LABEL: func.func @RecurciveConditional
986+
func.func @RecurciveConditional(%arg0 : !moore.l1, %arg1 : !moore.l1) {
987+
// CHECK: [[C_2:%.+]] = hw.constant -2 : i2
988+
// CHECK: [[C_1:%.+]] = hw.constant 1 : i2
989+
// CHECK: [[C_0:%.+]] = hw.constant 0 : i2
990+
%c_2 = moore.constant -2 : l2
991+
%c_1 = moore.constant 1 : l2
992+
%c_0 = moore.constant 0 : l2
993+
994+
// CHECK: [[MUX0:%.+]] = comb.mux %arg1, [[C_0]], [[C_1]] : i2
995+
// CHECK: [[MUX1:%.+]] = comb.mux %arg0, [[MUX0]], [[C_2]] : i2
996+
%0 = moore.conditional %arg0 : l1 -> l2 {
997+
%1 = moore.conditional %arg1 : l1 -> l2 {
998+
moore.yield %c_0 : l2
999+
} {
1000+
moore.yield %c_1 : l2
1001+
}
1002+
moore.yield %1 : l2
1003+
} {
1004+
moore.yield %c_2 : l2
1005+
}
1006+
1007+
return
1008+
}
1009+
9851010
// CHECK-LABEL: func.func @Conversions
9861011
func.func @Conversions(%arg0: !moore.i16, %arg1: !moore.l16) {
9871012
// CHECK: [[TMP:%.+]] = comb.extract %arg0 from 0 : (i16) -> i8

0 commit comments

Comments
 (0)