-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[OpenMP][clang][HIP][CUDA] fix weak alias emit on device compilation #164326
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
Open
Jason-VanBeusekom
wants to merge
5
commits into
llvm:main
Choose a base branch
from
Jason-VanBeusekom:alias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+454
−1
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
26b90e0
[OpenMP][clang][HIP][CUDA] fix weak alias emit on device compilation …
Jason-VanBeusekom 16c1a68
Move weak alias code to seperate function, refactor weak alias, updat…
Jason-VanBeusekom 73f219f
Update lit tests for variable and non weak aliasing
Jason-VanBeusekom 7fd51cc
update Hip documentation
Jason-VanBeusekom 2949485
Trim lit tests and format fixes
Jason-VanBeusekom 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
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,17 @@ | ||
| // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --version 6 | ||
| // RUN: %clang_cc1 -x cuda -triple x86_64-unknown-linux-gnu -aux-triple nvptx64-nvidia-cuda -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST | ||
|
|
||
| extern "C" { | ||
|
|
||
| //. | ||
| // HOST: @HostFunc = weak alias i32 (), ptr @__HostFunc | ||
| //. | ||
| // HOST-LABEL: define dso_local i32 @__HostFunc( | ||
| // HOST-SAME: ) #[[ATTR0:[0-9]+]] { | ||
| // HOST-NEXT: [[ENTRY:.*:]] | ||
| // HOST-NEXT: ret i32 42 | ||
| // | ||
| int __HostFunc(void) { return 42; } | ||
| int HostFunc(void) __attribute__ ((weak, alias("__HostFunc"))); | ||
|
|
||
| } |
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,125 @@ | ||
| // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --version 6 | ||
| // REQUIRES: amdgpu-registered-target | ||
| // RUN: %clang_cc1 -x hip -triple x86_64-unknown-linux-gnu -aux-triple amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-host.bc | ||
| // RUN: %clang_cc1 -x hip -triple x86_64-unknown-linux-gnu -aux-triple amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST | ||
| // RUN: %clang_cc1 -x hip -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu -emit-llvm %s -fcuda-is-device -o - | FileCheck %s --check-prefix=DEVICE | ||
|
|
||
| #define __device__ __attribute__((device)) | ||
| #define __host__ __attribute__((host)) | ||
|
|
||
| extern "C" { | ||
| //. | ||
| // HOST: @HostFunc = weak alias i32 (), ptr @__HostFunc | ||
| // HOST: @HostFunc_ = alias i32 (), ptr @__HostFunc | ||
| // HOST: @HostVar = weak alias i32, ptr @__HostVar | ||
| // HOST: @HostVar_ = alias i32, ptr @__HostVar | ||
| // HOST: @Two = weak alias i32 (), ptr @__Two | ||
| // HOST: @Two_ = alias i32 (), ptr @__Two | ||
| // HOST: @_Z5Threev = weak alias i32 (), ptr @_Z7__Threev | ||
| // HOST: @_Z6Three_v = alias i32 (), ptr @_Z7__Threev | ||
| // HOST: @_Z4Fourv = weak alias i32 (), ptr @_Z6__Fourv | ||
| // HOST: @_Z4Fourf = weak alias float (float), ptr @_Z6__Fourf | ||
| //. | ||
| // DEVICE: @One = weak alias i32 (), ptr @__One | ||
| // DEVICE: @One_ = alias i32 (), ptr @__One | ||
| // DEVICE: @Two = weak alias i32 (), ptr @__Two | ||
| // DEVICE: @Two_ = alias i32 (), ptr @__Two | ||
| // DEVICE: @_Z5Threev = weak alias i32 (), ptr @_Z7__Threev | ||
| // DEVICE: @_Z6Three_v = alias i32 (), ptr @_Z7__Threev | ||
| // DEVICE: @_Z4Fourv = weak alias i32 (), ptr @_Z6__Fourv | ||
| // DEVICE: @_Z4Fourf = weak alias float (float), ptr @_Z6__Fourf | ||
| //. | ||
| // HOST-LABEL: define dso_local i32 @__HostFunc( | ||
| // HOST-SAME: ) #[[ATTR0:[0-9]+]] { | ||
| // HOST-NEXT: [[ENTRY:.*:]] | ||
| // HOST-NEXT: ret i32 42 | ||
| // | ||
| int __HostFunc(void) { return 42; } | ||
| int __HostVar = 1; | ||
| int HostFunc(void) __attribute__((weak, alias("__HostFunc"))); | ||
| int HostFunc_(void) __attribute__((alias("__HostFunc"))); | ||
| extern int __attribute__((weak, alias("__HostVar"))) HostVar; | ||
| extern int __attribute__((alias("__HostVar"))) HostVar_; | ||
|
|
||
| // DEVICE-LABEL: define dso_local i32 @__One( | ||
| // DEVICE-SAME: ) #[[ATTR0:[0-9]+]] { | ||
| // DEVICE-NEXT: [[ENTRY:.*:]] | ||
| // DEVICE-NEXT: [[RETVAL:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // DEVICE-NEXT: [[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr | ||
| // DEVICE-NEXT: ret i32 1 | ||
| // | ||
| __device__ int __One(void) { return 1; } | ||
| __device__ int One(void) __attribute__((weak, alias("__One"))); | ||
| __device__ int One_(void) __attribute__((alias("__One"))); | ||
|
|
||
| // HOST-LABEL: define dso_local i32 @__Two( | ||
| // HOST-SAME: ) #[[ATTR0]] { | ||
| // HOST-NEXT: [[ENTRY:.*:]] | ||
| // HOST-NEXT: ret i32 2 | ||
| // | ||
| // DEVICE-LABEL: define dso_local i32 @__Two( | ||
| // DEVICE-SAME: ) #[[ATTR0]] { | ||
| // DEVICE-NEXT: [[ENTRY:.*:]] | ||
| // DEVICE-NEXT: [[RETVAL:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // DEVICE-NEXT: [[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr | ||
| // DEVICE-NEXT: ret i32 2 | ||
| // | ||
| __host__ __device__ int __Two(void) { return 2; } | ||
| __host__ __device__ int Two(void) __attribute__((weak, alias("__Two"))); | ||
| __host__ __device__ int Two_(void) __attribute__((alias("__Two"))); | ||
| } | ||
|
|
||
| // HOST-LABEL: define linkonce_odr noundef i32 @_Z7__Threev( | ||
| // HOST-SAME: ) #[[ATTR0]] comdat { | ||
| // HOST-NEXT: [[ENTRY:.*:]] | ||
| // HOST-NEXT: ret i32 5 | ||
| // | ||
| // DEVICE-LABEL: define linkonce_odr noundef i32 @_Z7__Threev( | ||
| // DEVICE-SAME: ) #[[ATTR0]] comdat { | ||
| // DEVICE-NEXT: [[ENTRY:.*:]] | ||
| // DEVICE-NEXT: [[RETVAL:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // DEVICE-NEXT: [[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr | ||
| // DEVICE-NEXT: ret i32 5 | ||
| // | ||
| __host__ __device__ constexpr int __Three(void) { return 5; } | ||
| __host__ __device__ int Three(void) __attribute__((weak, alias("_Z7__Threev"))); | ||
| __host__ __device__ int Three_(void) __attribute__((alias("_Z7__Threev"))); | ||
|
|
||
|
|
||
| // HOST-LABEL: define dso_local noundef i32 @_Z6__Fourv( | ||
| // HOST-SAME: ) #[[ATTR0]] { | ||
| // HOST-NEXT: [[ENTRY:.*:]] | ||
| // HOST-NEXT: ret i32 2 | ||
| // | ||
| // DEVICE-LABEL: define dso_local noundef i32 @_Z6__Fourv( | ||
| // DEVICE-SAME: ) #[[ATTR0]] { | ||
| // DEVICE-NEXT: [[ENTRY:.*:]] | ||
| // DEVICE-NEXT: [[RETVAL:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // DEVICE-NEXT: [[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr | ||
| // DEVICE-NEXT: ret i32 2 | ||
| // | ||
| __host__ __device__ int __Four(void) { return 2; } | ||
| // HOST-LABEL: define dso_local noundef float @_Z6__Fourf( | ||
| // HOST-SAME: float noundef [[F:%.*]]) #[[ATTR0]] { | ||
| // HOST-NEXT: [[ENTRY:.*:]] | ||
| // HOST-NEXT: [[F_ADDR:%.*]] = alloca float, align 4 | ||
| // HOST-NEXT: store float [[F]], ptr [[F_ADDR]], align 4 | ||
| // HOST-NEXT: [[TMP0:%.*]] = load float, ptr [[F_ADDR]], align 4 | ||
| // HOST-NEXT: [[MUL:%.*]] = fmul contract float 2.000000e+00, [[TMP0]] | ||
| // HOST-NEXT: ret float [[MUL]] | ||
| // | ||
| // DEVICE-LABEL: define dso_local noundef float @_Z6__Fourf( | ||
| // DEVICE-SAME: float noundef [[F:%.*]]) #[[ATTR0]] { | ||
| // DEVICE-NEXT: [[ENTRY:.*:]] | ||
| // DEVICE-NEXT: [[RETVAL:%.*]] = alloca float, align 4, addrspace(5) | ||
| // DEVICE-NEXT: [[F_ADDR:%.*]] = alloca float, align 4, addrspace(5) | ||
| // DEVICE-NEXT: [[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr | ||
| // DEVICE-NEXT: [[F_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[F_ADDR]] to ptr | ||
| // DEVICE-NEXT: store float [[F]], ptr [[F_ADDR_ASCAST]], align 4 | ||
| // DEVICE-NEXT: [[TMP0:%.*]] = load float, ptr [[F_ADDR_ASCAST]], align 4 | ||
| // DEVICE-NEXT: [[MUL:%.*]] = fmul contract float 2.000000e+00, [[TMP0]] | ||
| // DEVICE-NEXT: ret float [[MUL]] | ||
| // | ||
| __host__ __device__ float __Four(float f) { return 2.0f * f; } | ||
| __host__ __device__ int Four(void) __attribute__((weak, alias("_Z6__Fourv"))); | ||
| __host__ __device__ float Four(float f) __attribute__((weak, alias("_Z6__Fourf"))); | ||
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,103 @@ | ||
| // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --version 6 | ||
| // REQUIRES: amdgpu-registered-target | ||
|
|
||
| // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm-bc %s -o %t-ppc-host.bc | ||
| // RUN: %clang_cc1 -fopenmp -x c -triple x86_64-unknown-unknown -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -o - | FileCheck %s --check-prefix=HOST | ||
| // RUN: %clang_cc1 -fopenmp -x c -triple amdgcn-amd-amdhsa -fopenmp-targets=amdgcn-amd-amdhsa -emit-llvm %s -fopenmp-is-target-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix=DEVICE | ||
|
|
||
| //. | ||
| // HOST: @__One_var = global i32 1, align 4 | ||
| // HOST: @__Two_var = global i32 2, align 4 | ||
| // HOST: @__Three_var = global i32 3, align 4 | ||
| // HOST: @.offloading.entry_name = internal unnamed_addr constant [10 x i8] c"__Two_var\00", section ".llvm.rodata.offloading", align 1 | ||
| // HOST: @.offloading.entry.__Two_var = weak constant %struct.__tgt_offload_entry { i64 0, i16 1, i16 1, i32 0, ptr @__Two_var, ptr @.offloading.entry_name, i64 4, i64 0, ptr null }, section "llvm_offload_entries", align 8 | ||
| // HOST: @.offloading.entry_name.1 = internal unnamed_addr constant [12 x i8] c"__Three_var\00", section ".llvm.rodata.offloading", align 1 | ||
| // HOST: @.offloading.entry.__Three_var = weak constant %struct.__tgt_offload_entry { i64 0, i16 1, i16 1, i32 0, ptr @__Three_var, ptr @.offloading.entry_name.1, i64 4, i64 0, ptr null }, section "llvm_offload_entries", align 8 | ||
| // HOST: @One = weak alias i32 (), ptr @__One | ||
| // HOST: @One_ = alias i32 (), ptr @__One | ||
| // HOST: @One_var = weak alias i32, ptr @__One_var | ||
| // HOST: @One_var_ = alias i32, ptr @__One_var | ||
| // HOST: @Two = weak alias i32 (), ptr @__Two | ||
| // HOST: @Two_ = alias i32 (), ptr @__Two | ||
| // HOST: @Two_var = weak alias i32, ptr @__Two_var | ||
| // HOST: @Two_var_ = alias i32, ptr @__Two_var | ||
| // HOST: @Three = weak alias i32 (), ptr @__Three | ||
| // HOST: @Three_ = alias i32 (), ptr @__Three | ||
| // HOST: @Three_var = weak alias i32, ptr @__Three_var | ||
| // HOST: @Three_var_ = alias i32, ptr @__Three_var | ||
| //. | ||
| // DEVICE: @__Two_var = addrspace(1) global i32 2, align 4 | ||
| // DEVICE: @__Three_var = addrspace(1) global i32 3, align 4 | ||
| // DEVICE: @Two = weak hidden alias i32 (), ptr @__Two | ||
| // DEVICE: @Two_ = hidden alias i32 (), ptr @__Two | ||
| // DEVICE: @Two_var = weak alias i32, addrspacecast (ptr addrspace(1) @__Two_var to ptr) | ||
| // DEVICE: @Two_var_ = alias i32, addrspacecast (ptr addrspace(1) @__Two_var to ptr) | ||
| // DEVICE: @Three = weak hidden alias i32 (), ptr @__Three | ||
| // DEVICE: @Three.1 = weak hidden alias i32 (), ptr @__Three | ||
| // DEVICE: @Three_ = hidden alias i32 (), ptr @__Three | ||
| // DEVICE: @Three_.2 = hidden alias i32 (), ptr @__Three | ||
| // DEVICE: @Three_var = weak alias i32, addrspacecast (ptr addrspace(1) @__Three_var to ptr) | ||
| // DEVICE: @Three_var_ = alias i32, addrspacecast (ptr addrspace(1) @__Three_var to ptr) | ||
| //. | ||
| // HOST-LABEL: define dso_local i32 @__One( | ||
| // HOST-SAME: ) #[[ATTR0:[0-9]+]] { | ||
| // HOST-NEXT: [[ENTRY:.*:]] | ||
| // HOST-NEXT: ret i32 1 | ||
| // | ||
| int __One(void) { return 1; } | ||
| int One(void) __attribute__ ((weak, alias("__One"))); | ||
| int One_(void) __attribute__ ((alias("__One"))); | ||
|
|
||
| int __One_var = 1; | ||
| extern int __attribute__((weak, alias("__One_var"))) One_var; | ||
| extern int __attribute__((alias("__One_var"))) One_var_; | ||
|
|
||
| #pragma omp declare target | ||
| // HOST-LABEL: define dso_local i32 @__Two( | ||
| // HOST-SAME: ) #[[ATTR0]] { | ||
| // HOST-NEXT: [[ENTRY:.*:]] | ||
| // HOST-NEXT: ret i32 2 | ||
| // | ||
| // DEVICE-LABEL: define hidden i32 @__Two( | ||
| // DEVICE-SAME: ) #[[ATTR0:[0-9]+]] { | ||
| // DEVICE-NEXT: [[ENTRY:.*:]] | ||
| // DEVICE-NEXT: [[RETVAL:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // DEVICE-NEXT: [[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr | ||
| // DEVICE-NEXT: ret i32 2 | ||
| // | ||
| int __Two(void) { return 2; } | ||
| int Two(void) __attribute__ ((weak, alias("__Two"))); | ||
| int Two_(void) __attribute__ ((alias("__Two"))); | ||
|
|
||
| int __Two_var = 2; | ||
| extern int __attribute__((weak, alias("__Two_var"))) Two_var; | ||
| extern int __attribute__((alias("__Two_var"))) Two_var_; | ||
| #pragma omp end declare target | ||
|
|
||
| #pragma omp declare target | ||
| // HOST-LABEL: define dso_local i32 @__Three( | ||
| // HOST-SAME: ) #[[ATTR0]] { | ||
| // HOST-NEXT: [[ENTRY:.*:]] | ||
| // HOST-NEXT: ret i32 3 | ||
| // | ||
| // DEVICE-LABEL: define hidden i32 @__Three( | ||
| // DEVICE-SAME: ) #[[ATTR0]] { | ||
| // DEVICE-NEXT: [[ENTRY:.*:]] | ||
| // DEVICE-NEXT: [[RETVAL:%.*]] = alloca i32, align 4, addrspace(5) | ||
| // DEVICE-NEXT: [[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[RETVAL]] to ptr | ||
| // DEVICE-NEXT: ret i32 3 | ||
| // | ||
| int __Three(void) { return 3; } | ||
| int __Three_var = 3; | ||
| #pragma omp end declare target | ||
| int Three(void) __attribute__ ((weak, alias("__Three"))); | ||
| int Three_(void) __attribute__ ((alias("__Three"))); | ||
| extern int __attribute__((weak, alias("__Three_var"))) Three_var; | ||
| extern int __attribute__((alias("__Three_var"))) Three_var_; | ||
| //. | ||
| // HOST: [[META0:![0-9]+]] = !{i32 1, !"__Two_var", i32 0, i32 0} | ||
| // HOST: [[META1:![0-9]+]] = !{i32 1, !"__Three_var", i32 0, i32 1} | ||
| //. | ||
| // DEVICE: [[META0:![0-9]+]] = !{i32 1, !"__Two_var", i32 0, i32 0} | ||
| // DEVICE: [[META1:![0-9]+]] = !{i32 1, !"__Three_var", i32 0, i32 1} | ||
| //. |
Oops, something went wrong.
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.
can we add lit tests for:
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.
I added the cases for HIP and amdgcn for OpenMP in 16c1a68,
The cases work without modification of the patch.