Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ladisgin
Copy link

Support for sized unpacked arrays in 'inside' expressions. Implementation recursively traverses the array to find the singular value and compares all found ones with the lhs, adding the condition results to the original conditions vector.

Copy link
Member

@hailongSun2000 hailongSun2000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯 Thanks @ladisgin a lot for this work 😄!
@fabianschuiki WDYT 🤔

Comment on lines +565 to +567
cond = conditions.back();
conditions
.pop_back(); // avoiding repetition of cond in the vector
Copy link
Contributor

@fabianschuiki fabianschuiki Dec 13, 2024

Choose a reason for hiding this comment

The 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 conditions.push_back(cond); below into the if branches that need it? That should make the code clearer (no removing and adding back of the condition).

Comment on lines +1127 to +1130
if (!type) {
mlir::emitError(loc, "can't convert slang::ast::FixedSizeUnpackedArrayType "
"to moore::UnpackedArrayType");
}
Copy link
Contributor

Choose a reason for hiding this comment

The 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 LogicalResult and doing a return failure(); here. The convertType function also already produces a diagnostic explaining to the user what exact type couldn't be converted, so you don't need to generate an additional error here 👍.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Comment on lines +1148 to +1153
} else {
mlir::emitError(loc,
"only singular values and fixed-size unpacked arrays "
"allowed as elements of unpacked arrays in 'inside' "
"expressions");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to above, a return failure(); would be great here 🙂

Comment on lines +563 to +564
context.collectConditionsForUnpackedArray(uaType, value,
conditions, lhs, loc);
Copy link
Contributor

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:

if (failed(context.collect...))
  return {};

conditions, lhs, loc);
cond = conditions.back();
conditions
.pop_back(); // avoiding repetition of cond in the vector
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

conditions
.pop_back(); // avoiding repetition of cond in the vector
} else {
mlir::emitError(loc, "unsized unpacked arrays in 'inside' "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you do the LogicalResult conversion, you can just return mlir::emitError.

It might be useful to emit the error on the op? I'm not sure, I haven't thought about it.

const slang::ast::FixedSizeUnpackedArrayType &slangType,
Value upackedArrayValue, SmallVector<Value> &conditions, Value lhs,
Location loc) {
Value cond;
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

} else {
cond = builder.create<moore::EqOp>(loc, lhs, elemValue);
}
conditions.push_back(cond);
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@@ -68,8 +68,8 @@ endmodule

// -----
module Foo;
int a, b[3];
// expected-error @below {{unpacked arrays in 'inside' expressions not supported}}
int a, b[];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you added a lot more errors. Please add checks for them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants