-
Notifications
You must be signed in to change notification settings - Fork 177
[CIR][ABI][AArch64][Lowering] Support calls for struct types > 128 bits #1074
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
CC @gitoleg for recent work in this area and @sitio-couto for ABI. |
bcardosolopes
requested changes
Nov 8, 2024
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.
Thanks for working on this!
clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp
Outdated
Show resolved
Hide resolved
clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp
Outdated
Show resolved
Hide resolved
bcardosolopes
requested changes
Nov 13, 2024
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.
Mostly nits and good to go
clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp
Outdated
Show resolved
Hide resolved
clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp
Outdated
Show resolved
Hide resolved
bcardosolopes
approved these changes
Nov 14, 2024
bcardosolopes
pushed a commit
that referenced
this pull request
Feb 12, 2025
…1335) In [PR#1074](#1074) we introduced calls for struct types > 128 bits, but there's is an issue here. [This](https://github.com/llvm/clangir/blob/3e17e7b9404e1a28bf33bdd5943f4a208134d479/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp#L1169) is meant to be a `memcpy` of the alloca instead of directly passing the alloca, just like in the [OG](https://github.com/llvm/clangir/blob/3e17e7b9404e1a28bf33bdd5943f4a208134d479/clang/lib/CodeGen/CGCall.cpp#L5323). The PR was meant to use a `memcpy` and later handle cases where we don't need the `memcpy`. For example, running the following code snippet `tmp.c` using `bin/clang tmp.c -o tmp -Xclang -fclangir -Xclang -fclangir-call-conv-lowering --target=aarch64-none-linux-gnu`: ``` #include <stdio.h> typedef struct { int a, b, c, d, e; } S; void change(S s) { s.a = 10; } void foo(void) { S s; s.a = 9; change(s); printf("%d\n", s.a); } int main(void) { foo(); return 0; } ``` gives 10 instead of 9, because we pass the pointer instead of a copy. Relevant part of the OG LLVM output: ``` @foo() %s = alloca %struct.S, align 4 %byval-temp = alloca %struct.S, align 4 %a = getelementptr inbounds nuw %struct.S, ptr %s, i32 0, i32 0 store i32 9, ptr %a, align 4 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %byval-temp, ptr align 4 %s, i64 20, i1 false) call void @change(ptr noundef %byval-temp) ``` Current LLVM output through CIR: ``` @foo() %1 = alloca %struct.S, i64 1, align 4 %2 = getelementptr %struct.S, ptr %1, i32 0, i32 0 store i32 9, ptr %2, align 4 %3 = load %struct.S, ptr %1, align 4 call void @change(ptr %1) ``` So, there should be a memcpy. This PR fixes this, and adds a comment/note for the future cases where we need to check if the copy is not needed. I have also updated the old test with structs having size > 128.
lanza
pushed a commit
that referenced
this pull request
Mar 18, 2025
…1335) In [PR#1074](#1074) we introduced calls for struct types > 128 bits, but there's is an issue here. [This](https://github.com/llvm/clangir/blob/3e17e7b9404e1a28bf33bdd5943f4a208134d479/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp#L1169) is meant to be a `memcpy` of the alloca instead of directly passing the alloca, just like in the [OG](https://github.com/llvm/clangir/blob/3e17e7b9404e1a28bf33bdd5943f4a208134d479/clang/lib/CodeGen/CGCall.cpp#L5323). The PR was meant to use a `memcpy` and later handle cases where we don't need the `memcpy`. For example, running the following code snippet `tmp.c` using `bin/clang tmp.c -o tmp -Xclang -fclangir -Xclang -fclangir-call-conv-lowering --target=aarch64-none-linux-gnu`: ``` #include <stdio.h> typedef struct { int a, b, c, d, e; } S; void change(S s) { s.a = 10; } void foo(void) { S s; s.a = 9; change(s); printf("%d\n", s.a); } int main(void) { foo(); return 0; } ``` gives 10 instead of 9, because we pass the pointer instead of a copy. Relevant part of the OG LLVM output: ``` @foo() %s = alloca %struct.S, align 4 %byval-temp = alloca %struct.S, align 4 %a = getelementptr inbounds nuw %struct.S, ptr %s, i32 0, i32 0 store i32 9, ptr %a, align 4 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %byval-temp, ptr align 4 %s, i64 20, i1 false) call void @change(ptr noundef %byval-temp) ``` Current LLVM output through CIR: ``` @foo() %1 = alloca %struct.S, i64 1, align 4 %2 = getelementptr %struct.S, ptr %1, i32 0, i32 0 store i32 9, ptr %2, align 4 %3 = load %struct.S, ptr %1, align 4 call void @change(ptr %1) ``` So, there should be a memcpy. This PR fixes this, and adds a comment/note for the future cases where we need to check if the copy is not needed. I have also updated the old test with structs having size > 128.
lanza
pushed a commit
to lanza/llvm-project
that referenced
this pull request
Aug 11, 2025
…lvm#1335) In [PR#1074](llvm/clangir#1074) we introduced calls for struct types > 128 bits, but there's is an issue here. [This](https://github.com/llvm/clangir/blob/3e17e7b9404e1a28bf33bdd5943f4a208134d479/clang/lib/CIR/Dialect/Transforms/TargetLowering/LowerFunction.cpp#L1169) is meant to be a `memcpy` of the alloca instead of directly passing the alloca, just like in the [OG](https://github.com/llvm/clangir/blob/3e17e7b9404e1a28bf33bdd5943f4a208134d479/clang/lib/CodeGen/CGCall.cpp#L5323). The PR was meant to use a `memcpy` and later handle cases where we don't need the `memcpy`. For example, running the following code snippet `tmp.c` using `bin/clang tmp.c -o tmp -Xclang -fclangir -Xclang -fclangir-call-conv-lowering --target=aarch64-none-linux-gnu`: ``` typedef struct { int a, b, c, d, e; } S; void change(S s) { s.a = 10; } void foo(void) { S s; s.a = 9; change(s); printf("%d\n", s.a); } int main(void) { foo(); return 0; } ``` gives 10 instead of 9, because we pass the pointer instead of a copy. Relevant part of the OG LLVM output: ``` @foo() %s = alloca %struct.S, align 4 %byval-temp = alloca %struct.S, align 4 %a = getelementptr inbounds nuw %struct.S, ptr %s, i32 0, i32 0 store i32 9, ptr %a, align 4 call void @llvm.memcpy.p0.p0.i64(ptr align 4 %byval-temp, ptr align 4 %s, i64 20, i1 false) call void @change(ptr noundef %byval-temp) ``` Current LLVM output through CIR: ``` @foo() %1 = alloca %struct.S, i64 1, align 4 %2 = getelementptr %struct.S, ptr %1, i32 0, i32 0 store i32 9, ptr %2, align 4 %3 = load %struct.S, ptr %1, align 4 call void @change(ptr %1) ``` So, there should be a memcpy. This PR fixes this, and adds a comment/note for the future cases where we need to check if the copy is not needed. I have also updated the old test with structs having size > 128.
terapines-osc-cir
pushed a commit
to Terapines/clangir
that referenced
this pull request
Sep 2, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As the title says, this PR adds support for calls with struct types > 128 bits, building upon this PR.
The idea is gotten from the original Codegen, and I have added a couple of tests.