-
Notifications
You must be signed in to change notification settings - Fork 305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ImportVerilog] Support for sized unpacked arrays in 'inside' expressions #7971
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -554,19 +554,35 @@ struct RvalueExprVisitor { | |
// Handle expressions. | ||
if (!listExpr->type->isSimpleBitVector()) { | ||
if (listExpr->type->isUnpackedArray()) { | ||
if (listExpr->type->isFixedSize()) { | ||
const auto &uaType = | ||
listExpr->type->as<slang::ast::FixedSizeUnpackedArrayType>(); | ||
auto value = context.convertRvalueExpression(*listExpr); | ||
if (!value) | ||
return {}; | ||
context.collectConditionsForUnpackedArray(uaType, value, | ||
conditions, lhs, loc); | ||
cond = conditions.back(); | ||
conditions | ||
.pop_back(); // avoiding repetition of cond in the vector | ||
Comment on lines
+565
to
+567
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks a lot for working on this! 🙂 This might make the code hard to understand. Could you instead move the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. super nit: comment before the line to keep the code on one line. |
||
} else { | ||
mlir::emitError(loc, "unsized unpacked arrays in 'inside' " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you do the LogicalResult conversion, you can just It might be useful to emit the error on the op? I'm not sure, I haven't thought about it. |
||
"expressions not supported"); | ||
return {}; | ||
} | ||
} else { | ||
mlir::emitError( | ||
loc, "unpacked arrays in 'inside' expressions not supported"); | ||
loc, | ||
"only simple bit vectors supported in 'inside' expressions"); | ||
return {}; | ||
} | ||
mlir::emitError( | ||
loc, "only simple bit vectors supported in 'inside' expressions"); | ||
return {}; | ||
} else { | ||
auto value = context.convertToSimpleBitVector( | ||
context.convertRvalueExpression(*listExpr)); | ||
if (!value) | ||
return {}; | ||
cond = builder.create<moore::WildcardEqOp>(loc, lhs, value); | ||
} | ||
auto value = context.convertToSimpleBitVector( | ||
context.convertRvalueExpression(*listExpr)); | ||
if (!value) | ||
return {}; | ||
cond = builder.create<moore::WildcardEqOp>(loc, lhs, value); | ||
} | ||
conditions.push_back(cond); | ||
} | ||
|
@@ -1101,3 +1117,39 @@ Value Context::materializeConversion(Type type, Value value, bool isSigned, | |
value = builder.create<moore::ConversionOp>(loc, type, value); | ||
return value; | ||
} | ||
|
||
void Context::collectConditionsForUnpackedArray( | ||
const slang::ast::FixedSizeUnpackedArrayType &slangType, | ||
Value upackedArrayValue, SmallVector<Value> &conditions, Value lhs, | ||
Location loc) { | ||
Value cond; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks like it can be sunk into the condition branch in the loop. |
||
auto type = convertType(slangType); | ||
if (!type) { | ||
mlir::emitError(loc, "can't convert slang::ast::FixedSizeUnpackedArrayType " | ||
"to moore::UnpackedArrayType"); | ||
} | ||
Comment on lines
+1127
to
+1130
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for checking for errors here 😃! You also need to return with some form of error here, ideally by making the function return type a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And to add to Fabian's comment, make sure your tests hit all these error message cases. |
||
auto mooreType = dyn_cast<moore::UnpackedArrayType>(type); | ||
const auto &elementType = slangType.elementType; | ||
for (slang::int32_t i = slangType.getFixedRange().lower(); | ||
i <= slangType.getFixedRange().upper(); i++) { | ||
auto elemValue = builder.create<moore::ExtractOp>( | ||
loc, mooreType.getElementType(), upackedArrayValue, i); | ||
if (elementType.isUnpackedArray()) { | ||
collectConditionsForUnpackedArray( | ||
elementType.as<slang::ast::FixedSizeUnpackedArrayType>(), elemValue, | ||
conditions, lhs, loc); | ||
} else if (elementType.isSingular()) { | ||
if (elementType.isIntegral()) { | ||
cond = builder.create<moore::WildcardEqOp>(loc, lhs, elemValue); | ||
} else { | ||
cond = builder.create<moore::EqOp>(loc, lhs, elemValue); | ||
} | ||
conditions.push_back(cond); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the comment above, the cond can sink towards here. Or be eliminated by switching to a trinary instead of a if. Or elminated by duplicating the push_back. |
||
} else { | ||
mlir::emitError(loc, | ||
"only singular values and fixed-size unpacked arrays " | ||
"allowed as elements of unpacked arrays in 'inside' " | ||
"expressions"); | ||
} | ||
Comment on lines
+1148
to
+1153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to above, a |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,8 +68,8 @@ endmodule | |
|
||
// ----- | ||
module Foo; | ||
int a, b[3]; | ||
// expected-error @below {{unpacked arrays in 'inside' expressions not supported}} | ||
int a, b[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you added a lot more errors. Please add checks for them. |
||
// expected-error @below {{unsized unpacked arrays in 'inside' expressions not supported}} | ||
int c = a inside { b }; | ||
endmodule | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the
LogicalResult
return type comment from below, you can check for that here like this: