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] supports lowering of const arrays of structs #370

Merged
merged 5 commits into from
Jan 16, 2024

Conversation

gitoleg
Copy link
Collaborator

@gitoleg gitoleg commented Dec 28, 2023

This PR fixes CIR lowering for the next case.

void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}}; 
}

Note, we don't create attribute here and lower such const arrays as values.

@bcardosolopes
Copy link
Member

bcardosolopes commented Jan 4, 2024

Note, we don't create attribute here and lower such const arrays as values.

Fair, I do wonder in the long run if, during LoweringPrepare, we want to promote array values as globals so we get closer to mirror traditional LLVM codegen output more closely, such LLVM output will likely be more willing to allow optimizations in the LLVM pipeline to later kick-in. Thoughts?

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.

LGTM after fixing conflicts

Copy link

github-actions bot commented Jan 11, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@gitoleg
Copy link
Collaborator Author

gitoleg commented Jan 11, 2024

LGTM after fixing conflicts

@bcardosolopes done! refactored a bit

Fair, I do wonder in the long run if, during LoweringPrepare, we want to promote array values as globals so we get closer to mirror traditional LLVM codegen output more closely, such LLVM output will likely be more willing to allow optimizations in the LLVM pipeline to later kick-in. Thoughts?

Well, yes. I faced with the same issue in the #393 . And I'm sure we should not touch LoweringPrepare until we fix unimplemented features. Actually, I already tried for that PR - and it was terrible, so I discarded all the changes.

And the original codegen emit memcpy or memset approximately here. And it's important to notice, that it's done on the codegen stage. I.e. memcpy from a global var is also created there.
I add LLVM IR just for the reference (for the example from above):

@__const.foo.a = private unnamed_addr constant [1 x %struct.anon] [%struct.anon { i32 0, i32 1 }], align 4

; Function Attrs: noinline nounwind optnone uwtable
define dso_local void @foo() #0 {
entry:
  %a = alloca [1 x %struct.anon], align 4
  call void @llvm.memcpy.p0.p0.i64(ptr align 4 %a, ptr align 4 @__const.foo.a, i64 8, i1 false)
  ret void
}

So I would say - first we need to implement all this unimplemented features and take a look, what do we get. And only after do something in the lowering prepare.

@bcardosolopes
Copy link
Member

So I would say - first we need to implement all this unimplemented features and take a look, what do we get. And only after do something in the lowering prepare.

Totally agree, tracking in #403

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.

LGTM

@bcardosolopes bcardosolopes merged commit ff834e2 into llvm:main Jan 16, 2024
6 checks passed
lanza pushed a commit that referenced this pull request Jan 29, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}}; 
}
```
Note, we don't create attribute here and lower such const arrays as
values.
lanza pushed a commit that referenced this pull request Mar 23, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}}; 
}
```
Note, we don't create attribute here and lower such const arrays as
values.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}}; 
}
```
Note, we don't create attribute here and lower such const arrays as
values.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Mar 24, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}}; 
}
```
Note, we don't create attribute here and lower such const arrays as
values.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}}; 
}
```
Note, we don't create attribute here and lower such const arrays as
values.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}}; 
}
```
Note, we don't create attribute here and lower such const arrays as
values.
eZWALT pushed a commit to eZWALT/clangir that referenced this pull request Apr 29, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}}; 
}
```
Note, we don't create attribute here and lower such const arrays as
values.
lanza pushed a commit that referenced this pull request Apr 29, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}};
}
```
Note, we don't create attribute here and lower such const arrays as
values.
bruteforceboy pushed a commit to bruteforceboy/clangir that referenced this pull request Oct 2, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}};
}
```
Note, we don't create attribute here and lower such const arrays as
values.
Hugobros3 pushed a commit to shady-gang/clangir that referenced this pull request Oct 2, 2024
This PR fixes CIR lowering for the next case.

```
void foo() {
    struct {
        int a;
        int b;
    } a[1] = {{0,1}};
}
```
Note, we don't create attribute here and lower such const arrays as
values.
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.

2 participants