[PATCH] D21567: [OpenCL] Generate struct type for sampler_t and function call for the initializer

Yaxun Liu via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 11 10:56:54 PDT 2016


yaxunl marked 20 inline comments as done.

================
Comment at: lib/CodeGen/CGExprConstant.cpp:694
@@ +693,3 @@
+    case CK_IntToOCLSampler:
+      llvm_unreachable("global sampler variables are not generated");
+
----------------
Anastasia wrote:
> Does this only apply to global variable samplers?
Yes. The translation of local sampler is like

   sampler_t p = X;

->

   __sampler** p = alloca __sampler*;
   store __translate_sampler_initializer(X), p

================
Comment at: lib/CodeGen/CodeGenModule.cpp:4309
@@ +4308,3 @@
+  // in SPIR spec v1.2 and also opencl-c.h
+  unsigned AddressingMode  = (0x0E & SamplerValue) >> 1;
+  unsigned FilterMode      = (0x30 & SamplerValue) >> 4;
----------------
Anastasia wrote:
> Seems like this code is specific to SPIR and not OpenCL?
This warning msg is emitted for SPIR incompatible sampler value. It belongs to a category spir-compat. How about we turn off this category of warning by default and only enable it for SPIR target by default?

================
Comment at: lib/Sema/SemaInit.cpp:6907
@@ -6906,3 +6907,1 @@
     case SK_OCLSamplerInit: {
-      assert(Step->Type->isSamplerT() && 
-             "Sampler initialization on non-sampler type.");
----------------
Anastasia wrote:
> Is the assert no longer needed?
This assert is unlikely to happen. not so useful.

================
Comment at: test/CodeGenOpenCL/sampler.cl:23
@@ +22,3 @@
+  fnc4smp(smp);
+  // CHECK: [[SAMP:%[0-9]+]] = call %__sampler addrspace(2)* @__translate_sampler_initializer(i32 19)
+  // CHECK: call spir_func void @fnc4smp(%__sampler addrspace(2)* [[SAMP]])
----------------
Anastasia wrote:
> Why does the initialization  happen second time here?
We cannot call function in the initializer of an LLVM global variable, so each reference of the global variable is replaced by a call of `__transform_sampler_initializer` and the original global variable is eliminated.

================
Comment at: test/CodeGenOpenCL/sampler.cl:26
@@ +25,3 @@
+
+  fnc4smp(glb_smp);
+  // CHECK: [[SAMP:%[0-9]+]] = call %__sampler addrspace(2)* @__translate_sampler_initializer(i32 35)
----------------
Anastasia wrote:
> Could we check definition of global sampler variable in IR too?
The original global variable is eliminated and its references are replaced by call of `__transform_sampler_initializer`.


http://reviews.llvm.org/D21567





More information about the cfe-commits mailing list