[PATCH] D39129: [OpenCL] Fix generation of constant address space sampler in function scope

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 10:55:28 PDT 2017


Anastasia created this revision.

After the change of constant address space function scope variable in 6e34f0e ("[OpenCL] Emit function-scope variable in constant address space as static variable", 2017-05-15)  a bug has been introduced that triggered unreachable during generation of samplers.

This is because sampler in global scope has not to be generated. The initialization function has to be used instead of a variable everywhere the sampler variable is being referenced.

This patch fixes the bug and adds missing test case.


https://reviews.llvm.org/D39129

Files:
  lib/CodeGen/CGDecl.cpp
  test/CodeGenOpenCL/sampler.cl


Index: test/CodeGenOpenCL/sampler.cl
===================================================================
--- test/CodeGenOpenCL/sampler.cl
+++ test/CodeGenOpenCL/sampler.cl
@@ -33,6 +33,10 @@
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
   // CHECK: store %opencl.sampler_t addrspace(2)* [[SAMP]], %opencl.sampler_t addrspace(2)** [[smp_ptr]]
 
+  // Initialising constant AS sampler will be handled as global (we won't generate local alloca for it)
+  // CHECK-NOT: alloca %opencl.sampler_t addrspace(2)*
+  constant sampler_t smp_const_as = 11;
+
   // Case 1b
   fnc4smp(smp);
   // CHECK-NOT: call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 19)
@@ -58,4 +62,8 @@
   fnc4smp(5);
   // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 5)
   // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
+
+  fnc4smp(smp_const_as);
+  // CHECK: [[SAMP:%[0-9]+]] = call %opencl.sampler_t addrspace(2)* @__translate_sampler_initializer(i32 11)
+  // CHECK: call spir_func void @fnc4smp(%opencl.sampler_t addrspace(2)* [[SAMP]])
 }
Index: lib/CodeGen/CGDecl.cpp
===================================================================
--- lib/CodeGen/CGDecl.cpp
+++ lib/CodeGen/CGDecl.cpp
@@ -158,6 +158,13 @@
     // Don't emit it now, allow it to be emitted lazily on its first use.
     return;
 
+   // Samplers in constant address space are handled as a special case
+   // unlike other variables they are not generated as globals
+   // and their initialiser will be used everywhere it is being referenced.
+   if (D.getType().getAddressSpace() == LangAS::opencl_constant &&
+       D.getType().getTypePtr()->isSamplerT())
+     return;
+
   // Some function-scope variable does not have static storage but still
   // needs to be emitted like a static variable, e.g. a function-scope
   // variable in constant address space in OpenCL.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39129.119669.patch
Type: text/x-patch
Size: 1997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171020/b85a6a64/attachment.bin>


More information about the cfe-commits mailing list