Skip to content

Commit

Permalink
[SYCL] Put constant initializer list data in non-generic addr space. (i…
Browse files Browse the repository at this point in the history
…ntel#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]>
  • Loading branch information
kbobrovs authored Jan 13, 2021
1 parent 45e1b14 commit 0f2cf4d
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions clang/lib/CodeGen/CGExprAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, llvm::ArrayType *AType,
CodeGen::CodeGenModule &CGM = CGF.CGM;
ConstantEmitter Emitter(CGF);
LangAS AS = ArrayQTy.getAddressSpace();
if (CGM.getLangOpts().SYCLIsDevice && AS == LangAS::Default) {
// SYCL's default AS is 'generic', which can't be used to define constant
// initializer data in. It is reasonable to keep it in the same AS
// as string literals.
AS = CGM.getStringLiteralAddressSpace();
}
if (llvm::Constant *C = Emitter.tryEmitForInitializer(E, AS, ArrayQTy)) {
auto GV = new llvm::GlobalVariable(
CGM.getModule(), C->getType(),
Expand Down
30 changes: 30 additions & 0 deletions clang/test/CodeGenSYCL/local_var_big_init_as.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// RUN: %clang_cc1 -fsycl -fsycl-is-device -triple spir64-unknown-unknown-sycldevice \
// RUN: -emit-llvm -o - %s | FileCheck %s

// This test checks that data for big constant initializer lists is placed
// into the global address space by the SYCL compiler.

struct Test {
Test() : set{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} {};
int set[32];
};
// CHECK-DAG: @constinit = private unnamed_addr addrspace(1) constant
// CHECK: [32 x i32]
// CHECK: [i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7,
// CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15,
// CHECK: i32 0, i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7,
// CHECK: i32 8, i32 9, i32 10, i32 11, i32 12, i32 13, i32 14, i32 15
// CHECK: ], align 4
// CHECK-NOT: @constinit = private unnamed_addr addrspace(0)
// CHECK-NOT: @constinit = private unnamed_addr addrspace(2)
// CHECK-NOT: @constinit = private unnamed_addr addrspace(3)
// CHECK-NOT: @constinit = private unnamed_addr addrspace(4)

__attribute__((sycl_device)) void bar(Test &x);

__attribute__((sycl_device)) void zoo() {
Test mc;
bar(mc);
}

0 comments on commit 0f2cf4d

Please sign in to comment.