r358151 - [OpenCL] Re-fix invalid address space generation for clk_event_t arguments of enqueue_kernel builtin function

2019-04-10 Thread Alexey Sotkin via cfe-commits
Author: alexeysotkin
Date: Wed Apr 10 23:18:17 2019
New Revision: 358151

URL: http://llvm.org/viewvc/llvm-project?rev=358151&view=rev
Log:
[OpenCL] Re-fix invalid address space generation for clk_event_t arguments of 
enqueue_kernel builtin function

Summary:
https://reviews.llvm.org/D53809 fixed wrong address space(assert in debug build)
generated for event_ret argument. But exactly the same problem exists for
event_wait_list argument. This patch should fix both.

Reviewers: Anastasia, yaxunl

Reviewed By:  Anastasia

Subscribers: kristina, ebevhan, cfe-commits

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


Modified:
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=358151&r1=358150&r2=358151&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Apr 10 23:18:17 2019
@@ -3738,21 +3738,35 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 // Any calls now have event arguments passed.
 if (NumArgs >= 7) {
   llvm::Type *EventTy = ConvertType(getContext().OCLClkEventTy);
-  llvm::Type *EventPtrTy = EventTy->getPointerTo(
+  llvm::PointerType *EventPtrTy = EventTy->getPointerTo(
   CGM.getContext().getTargetAddressSpace(LangAS::opencl_generic));
 
   llvm::Value *NumEvents =
   Builder.CreateZExtOrTrunc(EmitScalarExpr(E->getArg(3)), Int32Ty);
-  llvm::Value *EventList =
-  E->getArg(4)->getType()->isArrayType()
-  ? EmitArrayToPointerDecay(E->getArg(4)).getPointer()
-  : EmitScalarExpr(E->getArg(4));
-  llvm::Value *ClkEvent = EmitScalarExpr(E->getArg(5));
-  // Convert to generic address space.
-  EventList = Builder.CreatePointerCast(EventList, EventPtrTy);
-  ClkEvent = ClkEvent->getType()->isIntegerTy()
-   ? Builder.CreateBitOrPointerCast(ClkEvent, EventPtrTy)
-   : Builder.CreatePointerCast(ClkEvent, EventPtrTy);
+
+  // Since SemaOpenCLBuiltinEnqueueKernel allows fifth and sixth arguments
+  // to be a null pointer constant (including `0` literal), we can take it
+  // into account and emit null pointer directly.
+  llvm::Value *EventWaitList = nullptr;
+  if (E->getArg(4)->isNullPointerConstant(
+  getContext(), Expr::NPC_ValueDependentIsNotNull)) {
+EventWaitList = llvm::ConstantPointerNull::get(EventPtrTy);
+  } else {
+EventWaitList = E->getArg(4)->getType()->isArrayType()
+? EmitArrayToPointerDecay(E->getArg(4)).getPointer()
+: EmitScalarExpr(E->getArg(4));
+// Convert to generic address space.
+EventWaitList = Builder.CreatePointerCast(EventWaitList, EventPtrTy);
+  }
+  llvm::Value *EventRet = nullptr;
+  if (E->getArg(5)->isNullPointerConstant(
+  getContext(), Expr::NPC_ValueDependentIsNotNull)) {
+EventRet = llvm::ConstantPointerNull::get(EventPtrTy);
+  } else {
+EventRet =
+Builder.CreatePointerCast(EmitScalarExpr(E->getArg(5)), 
EventPtrTy);
+  }
+
   auto Info =
   CGM.getOpenCLRuntime().emitOpenCLEnqueuedBlock(*this, E->getArg(6));
   llvm::Value *Kernel =
@@ -3764,8 +3778,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(
   QueueTy,Int32Ty,RangeTy,  Int32Ty,
   EventPtrTy, EventPtrTy, GenericVoidPtrTy, GenericVoidPtrTy};
 
-  std::vector Args = {Queue, Flags,Range,  
NumEvents,
- EventList, ClkEvent, Kernel, Block};
+  std::vector Args = {Queue, Flags, Range,
+ NumEvents, EventWaitList, EventRet,
+ Kernel,Block};
 
   if (NumArgs == 7) {
 // Has events but no variadics.

Modified: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl?rev=358151&r1=358150&r2=358151&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl Wed Apr 10 
23:18:17 2019
@@ -107,8 +107,8 @@ kernel void device_side_enqueue(global i
  });
 
   // COMMON-LABEL: call i32 @__enqueue_kernel_basic_events
-  // COMMON-SAME: (%opencl.queue_t{{.*}}* {{%[0-9]+}}, i32 {{%[0-9]+}}, 
%struct.ndrange_t* {{.*}}, i32 1, %opencl.clk_event_t{{.*}}* addrspace(4)* 
{{%[0-9]+}}, %opencl.clk_event_t{{.*}}* addrspace(4)* null,
-  enqueue_kernel(default_queue, flags, ndrange, 1, &event_wait_list, 0,
+  // COMMON-SAME: (%opencl.queue_t{{.*}}* {{%[0-9]+}

[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-13 Thread Alexey Sotkin via cfe-commits
AlexeySotkin removed rL LLVM as the repository for this revision.
AlexeySotkin updated this revision to Diff 74482.
AlexeySotkin added a comment.

Adding test checking address space of array initializer


https://reviews.llvm.org/D25305

Files:
  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)
+}


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)
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-14 Thread Alexey Sotkin via cfe-commits
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)


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)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-14 Thread Alexey Sotkin via cfe-commits
AlexeySotkin added a comment.

Now there should be both :)


https://reviews.llvm.org/D25305



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] f780e15 - [OpenCL] Fix support for cl_khr_mipmap_image_writes

2020-02-05 Thread Alexey Sotkin via cfe-commits

Author: Alexey Sotkin
Date: 2020-02-05T14:55:32+03:00
New Revision: f780e15caf1bed0a9fbc87fde70bd5ab3d80a439

URL: 
https://github.com/llvm/llvm-project/commit/f780e15caf1bed0a9fbc87fde70bd5ab3d80a439
DIFF: 
https://github.com/llvm/llvm-project/commit/f780e15caf1bed0a9fbc87fde70bd5ab3d80a439.diff

LOG: [OpenCL] Fix support for cl_khr_mipmap_image_writes

Text of the extension is available here:
https://github.com/KhronosGroup/OpenCL-Docs/blob/master/ext/cl_khr_mipmap_image.asciidoc

Patch by Ilya Mashkov

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

Added: 


Modified: 
clang/include/clang/Basic/OpenCLExtensions.def
clang/lib/Headers/opencl-c.h
clang/test/SemaOpenCL/extension-version.cl

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index 5536a6e8e4df..517481584313 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -70,6 +70,7 @@ OPENCLEXT_INTERNAL(cl_khr_spir, 120, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_egl_event, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_egl_image, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_mipmap_image, 200, ~0U)
+OPENCLEXT_INTERNAL(cl_khr_mipmap_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_srgb_image_writes, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_subgroups, 200, ~0U)
 OPENCLEXT_INTERNAL(cl_khr_terminate_context, 200, ~0U)

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 06c5ab6a72f0..3210f93cc851 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -14682,7 +14682,7 @@ void __ovld write_imagef(write_only 
image2d_array_depth_t image, int4 coord, flo
 
 // OpenCL Extension v2.0 s9.18 - Mipmaps
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
-#ifdef cl_khr_mipmap_image
+#if defined(cl_khr_mipmap_image_writes)
 void __ovld write_imagef(write_only image1d_t image, int coord, int lod, 
float4 color);
 void __ovld write_imagei(write_only image1d_t image, int coord, int lod, int4 
color);
 void __ovld write_imageui(write_only image1d_t image, int coord, int lod, 
uint4 color);
@@ -14699,15 +14699,16 @@ void __ovld write_imagef(write_only image2d_array_t 
image_array, int4 coord, int
 void __ovld write_imagei(write_only image2d_array_t image_array, int4 coord, 
int lod, int4 color);
 void __ovld write_imageui(write_only image2d_array_t image_array, int4 coord, 
int lod, uint4 color);
 
-void __ovld write_imagef(write_only image2d_depth_t image, int2 coord, int 
lod, float color);
-void __ovld write_imagef(write_only image2d_array_depth_t image, int4 coord, 
int lod, float color);
+void __ovld write_imagef(write_only image2d_depth_t image, int2 coord, int 
lod, float depth);
+void __ovld write_imagef(write_only image2d_array_depth_t image, int4 coord, 
int lod, float depth);
 
 #ifdef cl_khr_3d_image_writes
 void __ovld write_imagef(write_only image3d_t image, int4 coord, int lod, 
float4 color);
 void __ovld write_imagei(write_only image3d_t image, int4 coord, int lod, int4 
color);
 void __ovld write_imageui(write_only image3d_t image, int4 coord, int lod, 
uint4 color);
-#endif
-#endif //cl_khr_mipmap_image
+#endif //cl_khr_3d_image_writes
+
+#endif //defined(cl_khr_mipmap_image_writes)
 #endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
 
 // Image write functions for half4 type
@@ -14756,7 +14757,7 @@ void __ovld write_imagef(read_write 
image2d_array_depth_t image, int4 coord, flo
 #endif //cl_khr_depth_images
 
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
-#ifdef cl_khr_mipmap_image
+#if defined(cl_khr_mipmap_image_writes)
 void __ovld write_imagef(read_write image1d_t image, int coord, int lod, 
float4 color);
 void __ovld write_imagei(read_write image1d_t image, int coord, int lod, int4 
color);
 void __ovld write_imageui(read_write image1d_t image, int coord, int lod, 
uint4 color);
@@ -14780,8 +14781,9 @@ void __ovld write_imagef(read_write 
image2d_array_depth_t image, int4 coord, int
 void __ovld write_imagef(read_write image3d_t image, int4 coord, int lod, 
float4 color);
 void __ovld write_imagei(read_write image3d_t image, int4 coord, int lod, int4 
color);
 void __ovld write_imageui(read_write image3d_t image, int4 coord, int lod, 
uint4 color);
-#endif
-#endif //cl_khr_mipmap_image
+#endif //cl_khr_3d_image_writes
+
+#endif //cl_khr_mipmap_image_writes
 #endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
 
 // Image write functions for half4 type

diff  --git a/clang/test/SemaOpenCL/extension-version.cl 
b/clang/test/SemaOpenCL/extension-version.cl
index 19d088495350..0e6bbb7d3bcd 100644
--- a/clang/test/SemaOpenCL/extension-version.cl
+++ b/clang/test/SemaOpenCL/extension-version.cl
@@ -242,6 +242,18 @@
 #endif
 #pragma OPENCL EXTENSION cl_khr_m

[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-24 Thread Alexey Sotkin via cfe-commits
AlexeySotkin added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1272
+if (getLangOpts().OpenCL) {
+  UA = llvm::GlobalValue::UnnamedAddr::None;
+  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);

Anastasia wrote:
> Why this change?
Without this change, global variables with unnamed address space are translated 
to SPIR-V as variables with "Function" storage class, which is wrong.
This should fix this issue: https://github.com/KhronosGroup/SPIRV-LLVM/issues/50


https://reviews.llvm.org/D25305



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-25 Thread Alexey Sotkin via cfe-commits
AlexeySotkin added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1272
+if (getLangOpts().OpenCL) {
+  UA = llvm::GlobalValue::UnnamedAddr::None;
+  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);

bader wrote:
> Anastasia wrote:
> > bader wrote:
> > > AlexeySotkin wrote:
> > > > Anastasia wrote:
> > > > > Why this change?
> > > > Without this change, global variables with unnamed address space are 
> > > > translated to SPIR-V as variables with "Function" storage class, which 
> > > > is wrong.
> > > > This should fix this issue: 
> > > > https://github.com/KhronosGroup/SPIRV-LLVM/issues/50
> > > There is inconsistency with how Clang maps initializers to OpenCL memory 
> > > model.
> > > Consider example from the test case:
> > > ```
> > > __private int arr[] = {1, 2, 3};
> > > ```
> > > This code allocates a global constant for initializer {1, 2, 3} and later 
> > > copies values from this global constant to the private array using memcpy 
> > > intrinsic. The global constant must be allocated in constant address 
> > > space, but old code do assign any address space, which is considered to 
> > > be a private memory region.
> > > This patch puts global constant objects to constant address space.
> > Yes, this is perfectly fine. I was specifically asking about setting 
> > llvm::GlobalValue::UnnamedAddr::None attribute. I can't see why this has to 
> > be done or is it because we now assign concrete address space and private 
> > was treated as no address space at all?
> This attribute has nothing to do with address spaces.
> See http://llvm.org/docs/LangRef.html#global-variables for local_unnamed_addr 
> and unnamed_addr attributes description.
> My understanding is that llvm::GlobalValue::UnnamedAddr::Global should be 
> fine here.
llvm::GlobalValue::UnnamedAddr::None is default value of UnnamedAddr for 
GlobalValue. This line can be removed, but extra "if" statement must be added 
before GV->setUnnamedAddr(UA);


https://reviews.llvm.org/D25305



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-26 Thread Alexey Sotkin via cfe-commits
AlexeySotkin updated this revision to Diff 75893.
AlexeySotkin added a comment.

Setting UnnamedAddr to Global


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,10 +1266,16 @@
 // 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);
 


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,10 +1266,16 @@
 // 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);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D25305: [OpenCL] Setting constant address space for array initializers

2016-10-26 Thread Alexey Sotkin via cfe-commits
AlexeySotkin added inline comments.



Comment at: lib/CodeGen/CGDecl.cpp:1272
+if (getLangOpts().OpenCL) {
+  UA = llvm::GlobalValue::UnnamedAddr::None;
+  AS = CGM.getContext().getTargetAddressSpace(LangAS::opencl_constant);

Anastasia wrote:
> AlexeySotkin wrote:
> > bader wrote:
> > > Anastasia wrote:
> > > > bader wrote:
> > > > > AlexeySotkin wrote:
> > > > > > Anastasia wrote:
> > > > > > > Why this change?
> > > > > > Without this change, global variables with unnamed address space 
> > > > > > are translated to SPIR-V as variables with "Function" storage 
> > > > > > class, which is wrong.
> > > > > > This should fix this issue: 
> > > > > > https://github.com/KhronosGroup/SPIRV-LLVM/issues/50
> > > > > There is inconsistency with how Clang maps initializers to OpenCL 
> > > > > memory model.
> > > > > Consider example from the test case:
> > > > > ```
> > > > > __private int arr[] = {1, 2, 3};
> > > > > ```
> > > > > This code allocates a global constant for initializer {1, 2, 3} and 
> > > > > later copies values from this global constant to the private array 
> > > > > using memcpy intrinsic. The global constant must be allocated in 
> > > > > constant address space, but old code do assign any address space, 
> > > > > which is considered to be a private memory region.
> > > > > This patch puts global constant objects to constant address space.
> > > > Yes, this is perfectly fine. I was specifically asking about setting 
> > > > llvm::GlobalValue::UnnamedAddr::None attribute. I can't see why this 
> > > > has to be done or is it because we now assign concrete address space 
> > > > and private was treated as no address space at all?
> > > This attribute has nothing to do with address spaces.
> > > See http://llvm.org/docs/LangRef.html#global-variables for 
> > > local_unnamed_addr and unnamed_addr attributes description.
> > > My understanding is that llvm::GlobalValue::UnnamedAddr::Global should be 
> > > fine here.
> > llvm::GlobalValue::UnnamedAddr::None is default value of UnnamedAddr for 
> > GlobalValue. This line can be removed, but extra "if" statement must be 
> > added before GV->setUnnamedAddr(UA);
> Yes, I also think that leaving global should be fine here. So could we just 
> undo the change to line 1274?
Changed to Global


https://reviews.llvm.org/D25305



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits