Skip to content

Commit 2b863b6

Browse files
authored
[HWToBTOR2] Support unary case of variadics (#9169)
1 parent a04eac9 commit 2b863b6

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

lib/Conversion/HWToBTOR2/HWToBTOR2.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,15 @@ struct ConvertHWToBTOR2Pass
301301
auto operands = op->getOperands();
302302
size_t sid = sortToLIDMap.at(width);
303303

304-
if (operands.size() < 2) {
305-
op->emitError("variadic operations with less than 2 operands are not "
306-
"currently supported");
304+
// No need to consider 0-operand case as it'll be rejected by the verifier
305+
// If there's only one operand, then we don't generate a BTOR2 instruction,
306+
// we just reuse the operand's existing LID
307+
if (operands.size() == 1) {
308+
auto existingLID = getOpLID(operands[0]);
309+
// Check that we haven't somehow got a value that doesn't have a
310+
// corresponding LID
311+
assert(existingLID != noLID);
312+
opLIDMap[op] = existingLID;
307313
return;
308314
}
309315

test/Conversion/HWToBTOR2/comb.mlir

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,14 @@ module {
5555
// CHECK: [[NID18:[0-9]+]] and [[NID0]] [[NID17]] [[NID10]]
5656
%10 = comb.and %a, %3, %3 : i32
5757

58-
59-
// CHECK: [[NID19:[0-9]+]] implies [[NID3]] [[NID5]] [[NID12]]
60-
// CHECK: [[NID20:[0-9]+]] not [[NID3]] [[NID19]]
61-
// CHECK: [[NID21:[0-9]+]] bad [[NID20:[0-9]+]]
58+
// Variadic ops with one operand should be forwarded to the operand's LID
59+
// CHECK: [[NID19:[0-9]+]] and [[NID0]] 2 [[NID18]]
60+
%11 = comb.and %10 : i32
61+
%12 = comb.and %a, %11 : i32
62+
63+
// CHECK: [[ASSERTNID1:[0-9]+]] implies [[NID3]] [[NID5]] [[NID12]]
64+
// CHECK: [[ASSERTNID2:[0-9]+]] not [[NID3]] [[ASSERTNID1]]
65+
// CHECK: [[ASSERTNID3:[0-9]+]] bad [[ASSERTNID2:[0-9]+]]
6266
sv.always posedge %0 {
6367
sv.if %true {
6468
sv.assert %5, immediate message "a + 1 should be greater than a"

0 commit comments

Comments
 (0)