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

[CIR][Lowering] Support lowering of nested string ConstantArrays. #244

Merged
merged 1 commit into from Aug 30, 2023

Conversation

yugr
Copy link
Member

@yugr yugr commented Aug 24, 2023

No description provided.

Copy link
Member

@bcardosolopes bcardosolopes left a 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>())
Copy link
Member

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

Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Collaborator

@sitio-couto sitio-couto left a 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>())
Copy link
Collaborator

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.

clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp Outdated Show resolved Hide resolved
clang/test/CIR/Lowering/globals.cir Outdated Show resolved Hide resolved
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>}>
Copy link
Collaborator

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_arrays with thousands \00 hexadecimal chars each, making them unnecessarily large.

Copy link
Collaborator

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.

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

Successfully merging this pull request may close these issues.

None yet

3 participants