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
[CIR][Lowering] Support lowering of nested string ConstantArrays. #244
Conversation
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.
Overall looks good, few inline comments (and this needs rebasing too).
@@ -244,6 +244,8 @@ class CIRGenBuilderTy : public mlir::OpBuilder { | |||
} | |||
|
|||
if (const auto arrayVal = attr.dyn_cast<mlir::cir::ConstArrayAttr>()) { | |||
if (arrayVal.getElts().isa<mlir::StringAttr>()) |
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.
While here, what should happen for the following cases below?
- There are no elements:
""
. - The string is null terminated
"\0"
.
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.
Ideally, I think this should return true if all characters in the string are \0
.
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.
Yes, for zero strings this branch is true as well. I've added tests to check suggested cases.
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.
@yugr a few minor suggestions.
@@ -244,6 +244,8 @@ class CIRGenBuilderTy : public mlir::OpBuilder { | |||
} | |||
|
|||
if (const auto arrayVal = attr.dyn_cast<mlir::cir::ConstArrayAttr>()) { | |||
if (arrayVal.getElts().isa<mlir::StringAttr>()) |
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.
Ideally, I think this should return true if all characters in the string are \0
.
e501bbc
to
c7a4852
Compare
char y[3]; | ||
char z[3]; | ||
} nestedString = {"1", "", "\0"}; | ||
// CHECK: cir.global external @nestedString = #cir.const_struct<{#cir.const_array<"1\00\00" : !cir.array<!s8i x 3>> : !cir.array<!s8i x 3>, #cir.const_array<"\00\00\00" : !cir.array<!s8i x 3>> : !cir.array<!s8i x 3>, #cir.const_array<"\00\00\00" : !cir.array<!s8i x 3>> : !cir.array<!s8i x 3>}> |
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.
The initializer for the null strings should leverage #cir.zero
in some way. The reason for this is to improve performance when facing large zero/prefix-initialized strings. For example:
struct {
char r[100000];
char g[100000];
char b[100000];
} image = {"", "1234", "\0"};
The resulting CIR code for this example consists of three #cir.const_array
s with thousands \00
hexadecimal chars each, making them unnecessarily large.
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.
@yugr no need to apply this. It's not caused by your PR. I'm just leaving it here to open an issue for it later.
No description provided.