Skip to content

Commit ea08c4c

Browse files
committed
[CUDA] Fix static device variables with -fgpu-rdc
NVPTX does not allow dots in the identifier, so ptxas errors out with fatal : Parsing error near '.static': syntax error because it parses .static as a directive. Avoid this problem by using two underscores, similar to what OpenMP does for outlined functions. Differential Revision: https://reviews.llvm.org/D108456
1 parent 5fc4828 commit ea08c4c

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6444,5 +6444,5 @@ bool CodeGenModule::stopAutoInit() {
64446444

64456445
void CodeGenModule::printPostfixForExternalizedStaticVar(
64466446
llvm::raw_ostream &OS) const {
6447-
OS << ".static." << getContext().getCUIDHash();
6447+
OS << "__static__" << getContext().getCUIDHash();
64486448
}

clang/test/CodeGenCUDA/device-var-linkage.cu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ extern __constant__ int ev2;
3737
extern __managed__ int ev3;
3838

3939
// NORDC-DAG: @_ZL3sv1 = addrspace(1) externally_initialized global i32 0
40-
// RDC-DAG: @_ZL3sv1.static.[[HASH:.*]] = addrspace(1) externally_initialized global i32 0
40+
// RDC-DAG: @_ZL3sv1__static__[[HASH:.*]] = addrspace(1) externally_initialized global i32 0
4141
// HOST-DAG: @_ZL3sv1 = internal global i32 undef
4242
static __device__ int sv1;
4343
// NORDC-DAG: @_ZL3sv2 = addrspace(4) externally_initialized global i32 0
44-
// RDC-DAG: @_ZL3sv2.static.[[HASH]] = addrspace(4) externally_initialized global i32 0
44+
// RDC-DAG: @_ZL3sv2__static__[[HASH]] = addrspace(4) externally_initialized global i32 0
4545
// HOST-DAG: @_ZL3sv2 = internal global i32 undef
4646
static __constant__ int sv2;
4747
// NORDC-DAG: @_ZL3sv3 = addrspace(1) externally_initialized global i32 addrspace(1)* null
48-
// RDC-DAG: @_ZL3sv3.static.[[HASH]] = addrspace(1) externally_initialized global i32 addrspace(1)* null
48+
// RDC-DAG: @_ZL3sv3__static__[[HASH]] = addrspace(1) externally_initialized global i32 addrspace(1)* null
4949
// HOST-DAG: @_ZL3sv3 = internal externally_initialized global i32* null
5050
static __managed__ int sv3;
5151

clang/test/CodeGenCUDA/managed-var.cu

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ extern __managed__ int ex;
5252

5353
// NORDC-D-DAG: @_ZL2sx.managed = addrspace(1) externally_initialized global i32 1, align 4
5454
// NORDC-D-DAG: @_ZL2sx = addrspace(1) externally_initialized global i32 addrspace(1)* null
55-
// RDC-D-DAG: @_ZL2sx.static.[[HASH:.*]].managed = addrspace(1) externally_initialized global i32 1, align 4
56-
// RDC-D-DAG: @_ZL2sx.static.[[HASH]] = addrspace(1) externally_initialized global i32 addrspace(1)* null
55+
// RDC-D-DAG: @_ZL2sx__static__[[HASH:.*]].managed = addrspace(1) externally_initialized global i32 1, align 4
56+
// RDC-D-DAG: @_ZL2sx__static__[[HASH]] = addrspace(1) externally_initialized global i32 addrspace(1)* null
5757
// HOST-DAG: @_ZL2sx.managed = internal global i32 1
5858
// HOST-DAG: @_ZL2sx = internal externally_initialized global i32* null
5959
// NORDC-DAG: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx\00"
60-
// RDC-DAG: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx.static.[[HASH:.*]]\00"
60+
// RDC-DAG: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx__static__[[HASH:.*]]\00"
6161

62-
// POSTFIX: @_ZL2sx.static.[[HASH:.*]] = addrspace(1) externally_initialized global i32 addrspace(1)* null
63-
// POSTFIX: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx.static.[[HASH]]\00"
62+
// POSTFIX: @_ZL2sx__static__[[HASH:.*]] = addrspace(1) externally_initialized global i32 addrspace(1)* null
63+
// POSTFIX: @[[DEVNAMESX:[0-9]+]] = {{.*}}c"_ZL2sx__static__[[HASH]]\00"
6464
static __managed__ int sx = 1;
6565

6666
// DEV-DAG: @llvm.compiler.used

clang/test/CodeGenCUDA/static-device-var-rdc.cu

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@
5555
// INT-HOST-DAG: @[[DEVNAMEX:[0-9]+]] = {{.*}}c"_ZL1x\00"
5656

5757
// Test externalized static device variables
58-
// EXT-DEV-DAG: @_ZL1x.static.[[HASH:.*]] = addrspace(1) externally_initialized global i32 0
59-
// EXT-HOST-DAG: @[[DEVNAMEX:[0-9]+]] = {{.*}}c"_ZL1x.static.[[HASH:.*]]\00"
58+
// EXT-DEV-DAG: @_ZL1x__static__[[HASH:.*]] = addrspace(1) externally_initialized global i32 0
59+
// EXT-HOST-DAG: @[[DEVNAMEX:[0-9]+]] = {{.*}}c"_ZL1x__static__[[HASH:.*]]\00"
6060

61-
// POSTFIX: @_ZL1x.static.[[HASH:.*]] = addrspace(1) externally_initialized global i32 0
62-
// POSTFIX: @[[DEVNAMEX:[0-9]+]] = {{.*}}c"_ZL1x.static.[[HASH]]\00"
61+
// POSTFIX: @_ZL1x__static__[[HASH:.*]] = addrspace(1) externally_initialized global i32 0
62+
// POSTFIX: @[[DEVNAMEX:[0-9]+]] = {{.*}}c"_ZL1x__static__[[HASH]]\00"
6363

6464
static __device__ int x;
6565

@@ -73,8 +73,8 @@ static __device__ int x2;
7373
// INT-HOST-DAG: @[[DEVNAMEY:[0-9]+]] = {{.*}}c"_ZL1y\00"
7474

7575
// Test externalized static device variables
76-
// EXT-DEV-DAG: @_ZL1y.static.[[HASH]] = addrspace(4) externally_initialized global i32 0
77-
// EXT-HOST-DAG: @[[DEVNAMEY:[0-9]+]] = {{.*}}c"_ZL1y.static.[[HASH]]\00"
76+
// EXT-DEV-DAG: @_ZL1y__static__[[HASH]] = addrspace(4) externally_initialized global i32 0
77+
// EXT-HOST-DAG: @[[DEVNAMEY:[0-9]+]] = {{.*}}c"_ZL1y__static__[[HASH]]\00"
7878

7979
static __constant__ int y;
8080

0 commit comments

Comments
 (0)