Skip to content

Commit 311bc6e

Browse files
author
Andrew Savonichev
committed
[SYCL] Move static const variables to constant address space
Previously when ENASBLE_INFER_AS is enabled (see: 1a3a536 [SYCL] Optionally override addrspace map for SYCL device code), static variables were put into generic address space. Now, if a static variable has a const qualifier, it will go to constant address space. Non-const variables with static storage are not supported by the SYCL 1.2.1 specification (see s6.3 "Language restrictions for kernels"), but this patch handles this case as well by putting such variables into global address space (we cannot do anything better in CodeGen anyway). Signed-off-by: Andrew Savonichev <andrew.savonichev@intel.com>
1 parent c94e347 commit 311bc6e

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3396,6 +3396,13 @@ LangAS CodeGenModule::GetGlobalVarAddressSpace(const VarDecl *D) {
33963396
return AddrSpace;
33973397
}
33983398

3399+
if (LangOpts.SYCLIsDevice) {
3400+
if (D && D->getType().isConstQualified())
3401+
return LangAS::opencl_constant;
3402+
3403+
return LangAS::opencl_global;
3404+
}
3405+
33993406
if (LangOpts.CUDA && LangOpts.CUDAIsDevice) {
34003407
if (D && D->hasAttr<CUDAConstantAttr>())
34013408
return LangAS::cuda_constant;

clang/test/CodeGenSYCL/address-space-new.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,17 @@
33

44

55
void test() {
6+
static const int foo = 0x42;
7+
// CHECK-DEFAULT: @_ZZ4testvE3foo = internal addrspace(2) constant i32 66, align 4
8+
// CHECK-NEW: @_ZZ4testvE3foo = internal addrspace(2) constant i32 66, align 4
9+
610
int i = 0;
711
int *pptr = &i;
812
// CHECK-DEFAULT: store i32* %i, i32** %pptr
913
// CHECK-NEW: %[[GEN:[0-9]+]] = addrspacecast i32* %i to i32 addrspace(4)*
1014
// CHECK-NEW: store i32 addrspace(4)* %[[GEN]], i32 addrspace(4)** %pptr
15+
16+
*pptr = foo;
1117
}
1218

1319

0 commit comments

Comments
 (0)