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

Anastasia Stulova via cfe-commits cfe-commits at lists.llvm.org
Wed Jul 20 07:45:52 PDT 2016


Anastasia added inline comments.

================
Comment at: lib/Sema/SemaInit.cpp:6945
@@ +6944,3 @@
+          // get the integer literal.
+          Init = cast<ImplicitCastExpr>(const_cast<Expr*>(
+            Var->getInit()))->getSubExpr();
----------------
What if global variable sampler is initialized with another sampler variable:
  sampler_t s1 = ...;
  sampler_t s2 = s1;
  ...
  foo(s2);

Btw, I am wondering whether this code is needed at all, because I am guessing variable initialization will be handled separately anyways, irrespective to whether it's being used in a call or not...

================
Comment at: lib/Sema/SemaInit.cpp:6949-6980
@@ -6917,3 +6948,34 @@
+        }
       }
 
+      // Case 1a, 2a and 2b
+      // Insert cast from integer to sampler.
+      if (!Init->isConstantInitializer(S.Context, false))
+        S.Diag(Kind.getLocation(),
+               diag::err_sampler_initializer_not_constant);
+      if (!SourceType->isIntegerType() ||
+          32 != S.Context.getIntWidth(SourceType))
+        S.Diag(Kind.getLocation(), diag::err_sampler_initializer_not_integer)
+          << SourceType;
+
+      llvm::APSInt Result;
+      Init->EvaluateAsInt(Result, S.Context);
+      const uint64_t SamplerValue = Result.getLimitedValue();
+      // 32-bit value of sampler's initializer is interpreted as
+      // bit-field with the following structure:
+      // |unspecified|Filter|Addressing Mode| Normalized Coords|
+      // |31        6|5    4|3             1|                 0|
+      // This structure corresponds to enum values of sampler properties defined
+      // in SPIR spec v1.2 and also opencl-c.h
+      unsigned AddressingMode  = (0x0E & SamplerValue) >> 1;
+      unsigned FilterMode      = (0x30 & SamplerValue) >> 4;
+      if (FilterMode != 1 && FilterMode != 2)
+        S.Diag(Kind.getLocation(), diag::warn_sampler_initializer_invalid_bits)
+          << "Filter Mode";
+      if (AddressingMode > 4)
+        S.Diag(Kind.getLocation(), diag::warn_sampler_initializer_invalid_bits)
+          << "Addressing Mode";
+
+      CurInit = S.ImpCastExprToType(Init, S.Context.OCLSamplerTy,
+                                      CK_IntToOCLSampler);
       break;
----------------
Is this being tested anywhere:
  sampler_t initialization requires 32-bit integer


https://reviews.llvm.org/D21567





More information about the cfe-commits mailing list