Skip to content

Commit 0f2cf4d

Browse files
authored
[SYCL] Put constant initializer list data in non-generic addr space. (intel#3005)
* [SYCL] Put constant initializer list data in non-generic addr space. Big constant initializer lists (>= 16 elements) were represented as a global in the generic address space. This is incorrect, as this is an alias AS, and allocation is not possible in it - compiler will have no clue where to really put data. Gen vector BE crashed on this pattern. The fix is to put this data into the same address space as a string literal. Signed-off-by: Konstantin S Bobrovsky <[email protected]>
1 parent 45e1b14 commit 0f2cf4d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

clang/lib/CodeGen/CGExprAgg.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,12 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
499499
CodeGen::CodeGenModule &CGM = CGF.CGM;
500500
ConstantEmitter Emitter(CGF);
501501
LangAS AS = ArrayQTy.getAddressSpace();
502+
if (CGM.getLangOpts().SYCLIsDevice && AS == LangAS::Default) {
503+
// SYCL's default AS is 'generic', which can't be used to define constant
504+
// initializer data in. It is reasonable to keep it in the same AS
505+
// as string literals.
506+
AS = CGM.getStringLiteralAddressSpace();
507+
}
502508
if (llvm::Constant *C = Emitter.tryEmitForInitializer(E, AS, ArrayQTy)) {
503509
auto GV = new llvm::GlobalVariable(
504510
CGM.getModule(), C->getType(),
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice \
2+
// RUN: -emit-llvm -o - %s | FileCheck %s
3+
4+
// This test checks that data for big constant initializer lists is placed
5+
// into the global address space by the SYCL compiler.
6+
7+
struct Test {
8+
Test() : set{
9+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
10+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} {};
11+
int set[32];
12+
};
13+
// CHECK-DAG: @constinit = private unnamed_addr addrspace(1) constant
14+
// CHECK: [32 x i32]
15+
// CHECK: [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7,
16+
// CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15,
17+
// CHECK: i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7,
18+
// CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15
19+
// CHECK: ], align 4
20+
// CHECK-NOT: @constinit = private unnamed_addr addrspace(0)
21+
// CHECK-NOT: @constinit = private unnamed_addr addrspace(2)
22+
// CHECK-NOT: @constinit = private unnamed_addr addrspace(3)
23+
// CHECK-NOT: @constinit = private unnamed_addr addrspace(4)
24+
25+
__attribute__((sycl_device)) void bar(Test &x);
26+
27+
__attribute__((sycl_device)) void zoo() {
28+
Test mc;
29+
bar(mc);
30+
}

0 commit comments

Comments
 (0)