r285557 - [OpenCL] Setting constant address space for array initializers

Alexey Bader via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 31 03:26:31 PDT 2016


Author: bader
Date: Mon Oct 31 05:26:31 2016
New Revision: 285557

URL: http://llvm.org/viewvc/llvm-project?rev=285557&view=rev
Log:
[OpenCL] Setting constant address space for array initializers

Summary: Setting constant address space for global constants used for memcpy-initialization of arrays.

Patch by Alexey Sotkin.

Reviewers: bader, yaxunl, Anastasia

Subscribers: cfe-commits, AlexeySotkin

Differential Revision: https://reviews.llvm.org/D25305


Added:
    cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl
Modified:
    cfe/trunk/lib/CodeGen/CGDecl.cpp
    cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=285557&r1=285556&r2=285557&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Mon Oct 31 05:26:31 2016
@@ -1225,10 +1225,16 @@ void CodeGenFunction::EmitAutoVarInit(co
     // 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;
+    if (getLangOpts().OpenCL) {
+      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);
 

Modified: cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl?rev=285557&r1=285556&r2=285557&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/partial_initializer.cl Mon Oct 31 05:26:31 2016
@@ -24,7 +24,7 @@ int4 GV1 = (int4)((int2)(1,2),3,4);
 // CHECK: @GV2 = addrspace(1) global <4 x i32> <i32 1, i32 1, i32 1, i32 1>, align 16
 int4 GV2 = (int4)(1);
 
-// CHECK: @f.S = private unnamed_addr constant %struct.StrucTy { i32 1, i32 2, i32 0 }, align 4
+// CHECK: @f.S = private unnamed_addr addrspace(2) constant %struct.StrucTy { i32 1, i32 2, i32 0 }, align 4
 
 // CHECK-LABEL: define spir_func void @f()
 void f(void) {
@@ -46,7 +46,7 @@ void f(void) {
   float A[6][6]  = {1.0f, 2.0f};
 
   // CHECK: %[[v5:.*]] = bitcast %struct.StrucTy* %S to i8*
-  // CHECK: call void @llvm.memcpy.p0i8.p0i8.i32(i8* %[[v5]], i8* bitcast (%struct.StrucTy* @f.S to i8*), i32 12, i32 4, i1 false)
+  // CHECK: call void @llvm.memcpy.p0i8.p2i8.i32(i8* %[[v5]], i8 addrspace(2)* bitcast (%struct.StrucTy addrspace(2)* @f.S to i8 addrspace(2)*), i32 12, i32 4, i1 false)
   StrucTy S = {1, 2};
 
   // CHECK: store <2 x i32> <i32 1, i32 2>, <2 x i32>* %[[compoundliteral1]], align 8

Added: cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl?rev=285557&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/private-array-initialization.cl Mon Oct 31 05:26:31 2016
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 %s -triple spir-unknown-unknown -O0 -emit-llvm -o - | FileCheck %s
+
+// CHECK: @test.arr = private unnamed_addr 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)
+}




More information about the cfe-commits mailing list