-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[Clang] Use private address space for builtin_alloca return type for OpenCL #95750
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
vg0204
merged 9 commits into
llvm:main
from
vg0204:vg0204/__builtin_alloca-addrSpace-issue-in-openCL1.2
Jul 26, 2024
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ac967e4
[Clang] Use private address space for builtin_alloca for OpenCL
vg0204 8a5efde
updated return pointer to always point to stack/private address space…
vg0204 8a4a143
Moved the patch to dedicated builtin function in SemaChecking.cpp &
vg0204 a1b8505
Made some changes in comments in OpenCLBuiltinAllocaAddrSpace().
vg0204 e2ac64a
Removed non-OpenCL specific code snippet from OpenCLBuiltinAllocaAddr…
vg0204 3e2e427
Made suggested changes passing opencl_private directly.
vg0204 9cae2ff
Made the suggested changes around the builtinAllocaAddrSpace function.
vg0204 4811263
Modified return type of builtinAllocaAddreSpace function.
vg0204 c4145d2
Removed unused version specific check-prefixes from builtins-alloca.c…
vg0204 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --version 5 | ||
| // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL1.2 \ | ||
| // RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL %s | ||
| // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL2.0 \ | ||
| // RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL %s | ||
| // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 \ | ||
| // RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL %s | ||
| // RUN: %clang_cc1 %s -O0 -triple amdgcn-amd-amdhsa -cl-std=CL3.0 -cl-ext=+__opencl_c_generic_address_space \ | ||
| // RUN: -emit-llvm -o - | FileCheck --check-prefixes=OPENCL %s | ||
|
|
||
| // OPENCL-LABEL: define dso_local void @test1_builtin_alloca( | ||
| // OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0:[0-9]+]] { | ||
| // OPENCL-NEXT: [[ENTRY:.*:]] | ||
| // OPENCL-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // OPENCL-NEXT: [[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, addrspace(5) | ||
| // OPENCL-NEXT: store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[CONV:%.*]] = zext i32 [[TMP0]] to i64 | ||
| // OPENCL-NEXT: [[MUL:%.*]] = mul i64 [[CONV]], 4 | ||
| // OPENCL-NEXT: [[TMP1:%.*]] = alloca i8, i64 [[MUL]], align 8, addrspace(5) | ||
| // OPENCL-NEXT: store ptr addrspace(5) [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], align 4 | ||
| // OPENCL-NEXT: ret void | ||
| // | ||
| void test1_builtin_alloca(unsigned n) { | ||
| __private float* alloc_ptr = (__private float*)__builtin_alloca(n*sizeof(int)); | ||
| } | ||
|
|
||
| // OPENCL-LABEL: define dso_local void @test1_builtin_alloca_uninitialized( | ||
| // OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0]] { | ||
| // OPENCL-NEXT: [[ENTRY:.*:]] | ||
| // OPENCL-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // OPENCL-NEXT: [[ALLOC_PTR_UNINITIALIZED:%.*]] = alloca ptr addrspace(5), align 4, addrspace(5) | ||
| // OPENCL-NEXT: store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[CONV:%.*]] = zext i32 [[TMP0]] to i64 | ||
| // OPENCL-NEXT: [[MUL:%.*]] = mul i64 [[CONV]], 4 | ||
| // OPENCL-NEXT: [[TMP1:%.*]] = alloca i8, i64 [[MUL]], align 8, addrspace(5) | ||
| // OPENCL-NEXT: store ptr addrspace(5) [[TMP1]], ptr addrspace(5) [[ALLOC_PTR_UNINITIALIZED]], align 4 | ||
| // OPENCL-NEXT: ret void | ||
| // | ||
| void test1_builtin_alloca_uninitialized(unsigned n) { | ||
| __private float* alloc_ptr_uninitialized = (__private float*)__builtin_alloca_uninitialized(n*sizeof(int)); | ||
| } | ||
|
|
||
| // OPENCL-LABEL: define dso_local void @test1_builtin_alloca_with_align( | ||
| // OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0]] { | ||
| // OPENCL-NEXT: [[ENTRY:.*:]] | ||
| // OPENCL-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // OPENCL-NEXT: [[ALLOC_PTR_ALIGN:%.*]] = alloca ptr addrspace(5), align 4, addrspace(5) | ||
| // OPENCL-NEXT: store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[CONV:%.*]] = zext i32 [[TMP0]] to i64 | ||
| // OPENCL-NEXT: [[MUL:%.*]] = mul i64 [[CONV]], 4 | ||
| // OPENCL-NEXT: [[TMP1:%.*]] = alloca i8, i64 [[MUL]], align 1, addrspace(5) | ||
| // OPENCL-NEXT: store ptr addrspace(5) [[TMP1]], ptr addrspace(5) [[ALLOC_PTR_ALIGN]], align 4 | ||
| // OPENCL-NEXT: ret void | ||
| // | ||
| void test1_builtin_alloca_with_align(unsigned n) { | ||
| __private float* alloc_ptr_align = (__private float*)__builtin_alloca_with_align((n*sizeof(int)), 8); | ||
| } | ||
|
|
||
| // OPENCL-LABEL: define dso_local void @test1_builtin_alloca_with_align_uninitialized( | ||
| // OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0]] { | ||
| // OPENCL-NEXT: [[ENTRY:.*:]] | ||
| // OPENCL-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // OPENCL-NEXT: [[ALLOC_PTR_ALIGN_UNINITIALIZED:%.*]] = alloca ptr addrspace(5), align 4, addrspace(5) | ||
| // OPENCL-NEXT: store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[CONV:%.*]] = zext i32 [[TMP0]] to i64 | ||
| // OPENCL-NEXT: [[MUL:%.*]] = mul i64 [[CONV]], 4 | ||
| // OPENCL-NEXT: [[TMP1:%.*]] = alloca i8, i64 [[MUL]], align 1, addrspace(5) | ||
| // OPENCL-NEXT: store ptr addrspace(5) [[TMP1]], ptr addrspace(5) [[ALLOC_PTR_ALIGN_UNINITIALIZED]], align 4 | ||
| // OPENCL-NEXT: ret void | ||
| // | ||
| void test1_builtin_alloca_with_align_uninitialized(unsigned n) { | ||
| __private float* alloc_ptr_align_uninitialized = (__private float*)__builtin_alloca_with_align_uninitialized((n*sizeof(int)), 8); | ||
| } | ||
|
|
||
| // OPENCL-LABEL: define dso_local void @test2_builtin_alloca( | ||
| // OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0]] { | ||
| // OPENCL-NEXT: [[ENTRY:.*:]] | ||
| // OPENCL-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // OPENCL-NEXT: [[ALLOC_PTR:%.*]] = alloca ptr addrspace(5), align 4, addrspace(5) | ||
| // OPENCL-NEXT: store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[CONV:%.*]] = zext i32 [[TMP0]] to i64 | ||
| // OPENCL-NEXT: [[TMP1:%.*]] = alloca i8, i64 [[CONV]], align 8, addrspace(5) | ||
| // OPENCL-NEXT: store ptr addrspace(5) [[TMP1]], ptr addrspace(5) [[ALLOC_PTR]], align 4 | ||
| // OPENCL-NEXT: ret void | ||
| // | ||
| void test2_builtin_alloca(unsigned n) { | ||
| __private void *alloc_ptr = __builtin_alloca(n); | ||
| } | ||
|
|
||
| // OPENCL-LABEL: define dso_local void @test2_builtin_alloca_uninitialized( | ||
| // OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0]] { | ||
| // OPENCL-NEXT: [[ENTRY:.*:]] | ||
| // OPENCL-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // OPENCL-NEXT: [[ALLOC_PTR_UNINITIALIZED:%.*]] = alloca ptr addrspace(5), align 4, addrspace(5) | ||
| // OPENCL-NEXT: store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[CONV:%.*]] = zext i32 [[TMP0]] to i64 | ||
| // OPENCL-NEXT: [[TMP1:%.*]] = alloca i8, i64 [[CONV]], align 8, addrspace(5) | ||
| // OPENCL-NEXT: store ptr addrspace(5) [[TMP1]], ptr addrspace(5) [[ALLOC_PTR_UNINITIALIZED]], align 4 | ||
| // OPENCL-NEXT: ret void | ||
| // | ||
| void test2_builtin_alloca_uninitialized(unsigned n) { | ||
| __private void *alloc_ptr_uninitialized = __builtin_alloca_uninitialized(n); | ||
| } | ||
|
|
||
| // OPENCL-LABEL: define dso_local void @test2_builtin_alloca_with_align( | ||
| // OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0]] { | ||
| // OPENCL-NEXT: [[ENTRY:.*:]] | ||
| // OPENCL-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // OPENCL-NEXT: [[ALLOC_PTR_ALIGN:%.*]] = alloca ptr addrspace(5), align 4, addrspace(5) | ||
| // OPENCL-NEXT: store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[CONV:%.*]] = zext i32 [[TMP0]] to i64 | ||
| // OPENCL-NEXT: [[TMP1:%.*]] = alloca i8, i64 [[CONV]], align 1, addrspace(5) | ||
| // OPENCL-NEXT: store ptr addrspace(5) [[TMP1]], ptr addrspace(5) [[ALLOC_PTR_ALIGN]], align 4 | ||
| // OPENCL-NEXT: ret void | ||
| // | ||
| void test2_builtin_alloca_with_align(unsigned n) { | ||
| __private void *alloc_ptr_align = __builtin_alloca_with_align(n, 8); | ||
| } | ||
|
|
||
| // OPENCL-LABEL: define dso_local void @test2_builtin_alloca_with_align_uninitialized( | ||
| // OPENCL-SAME: i32 noundef [[N:%.*]]) #[[ATTR0]] { | ||
| // OPENCL-NEXT: [[ENTRY:.*:]] | ||
| // OPENCL-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // OPENCL-NEXT: [[ALLOC_PTR_ALIGN_UNINITIALIZED:%.*]] = alloca ptr addrspace(5), align 4, addrspace(5) | ||
| // OPENCL-NEXT: store i32 [[N]], ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[TMP0:%.*]] = load i32, ptr addrspace(5) [[N_ADDR]], align 4 | ||
| // OPENCL-NEXT: [[CONV:%.*]] = zext i32 [[TMP0]] to i64 | ||
| // OPENCL-NEXT: [[TMP1:%.*]] = alloca i8, i64 [[CONV]], align 1, addrspace(5) | ||
| // OPENCL-NEXT: store ptr addrspace(5) [[TMP1]], ptr addrspace(5) [[ALLOC_PTR_ALIGN_UNINITIALIZED]], align 4 | ||
| // OPENCL-NEXT: ret void | ||
| // | ||
| void test2_builtin_alloca_with_align_uninitialized(unsigned n) { | ||
| __private void *alloc_ptr_align_uninitialized = __builtin_alloca_with_align_uninitialized(n, 8); | ||
| } |
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.
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.
A bit late tot this review, but right now we have
getASTAllocaAddressSpace()in CodeGen/, could this be used moved so we can make use of it in Sema instead?