[PATCH] D25305: [OpenCL] Setting constant address space for array initializers
Alexey Sotkin via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 14 08:28:36 PDT 2016
AlexeySotkin updated this revision to Diff 74693.
AlexeySotkin added a comment.
Squashing commits
https://reviews.llvm.org/D25305
Files:
lib/CodeGen/CGDecl.cpp
test/CodeGenOpenCL/private-array-initialization.cl
Index: test/CodeGenOpenCL/private-array-initialization.cl
===================================================================
--- /dev/null
+++ test/CodeGenOpenCL/private-array-initialization.cl
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | FileCheck %s
+
+// CHECK: @test.arr = private addrspace(2) constant [3 x i32] [i32 1, i32 2, i32 3], align 4
+
+void test() {
+ __private int arr[] = {1, 2, 3};
+// CHECK: %[[arr_i8_ptr:[0-9]+]] = bitcast [3 x i32]* %arr to i8*
+// CHECK: call void @llvm.memcpy.p0i8.p2i8.i32(i8* %[[arr_i8_ptr]], i8 addrspace(2)* bitcast ([3 x i32] addrspace(2)* @test.arr to i8 addrspace(2)*), i32 12, i32 4, i1 false)
+}
\ No newline at end of file
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -1266,12 +1266,20 @@
// Otherwise, create a temporary global with the initializer then
// memcpy from the global to the alloca.
std::string Name = getStaticDeclName(CGM, D);
+ unsigned AS = 0;
+ llvm::GlobalValue::UnnamedAddr UA = llvm::GlobalValue::UnnamedAddr::Global;
+ if (getLangOpts().OpenCL) {
+ UA = llvm::GlobalValue::UnnamedAddr::None;
+ AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);
+ BP = llvm::PointerType::getInt8PtrTy(getLLVMContext(), AS);
+ }
llvm::GlobalVariable *GV =
new llvm::GlobalVariable(CGM.getModule(), constant->getType(), true,
llvm::GlobalValue::PrivateLinkage,
- constant, Name);
+ constant, Name, nullptr,
+ llvm::GlobalValue::NotThreadLocal, AS);
GV->setAlignment(Loc.getAlignment().getQuantity());
- GV->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
+ GV->setUnnamedAddr(UA);
Address SrcPtr = Address(GV, Loc.getAlignment());
if (SrcPtr.getType() != BP)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D25305.74693.patch
Type: text/x-patch
Size: 1998 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20161014/0081dd84/attachment.bin>
More information about the cfe-commits
mailing list