[clang] fdcb9c2 - [OpenCL] Refactor shuffle builtin decls

Sven van Haastregt via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 21 04:00:14 PDT 2021


Author: Sven van Haastregt
Date: 2021-04-21T11:59:24+01:00
New Revision: fdcb9c272899fc270bd9bd067dc20363f54ff190

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

LOG: [OpenCL] Refactor shuffle builtin decls

The shuffle and shuffle2 builtins relied on processing two TypeLists
for different arguments in sync.  This will no longer work when a type
(e.g. double) in one of the TypeLists is optional.

Rewrite the declarations using explicit types instead of GenericTypes.

Added: 
    

Modified: 
    clang/lib/Sema/OpenCLBuiltins.td

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index 03235985ab42..1f9a7390cd14 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -343,15 +343,10 @@ def MemoryScope           : EnumType<"memory_scope">;
 def VecAndScalar: IntList<"VecAndScalar", [1, 2, 3, 4, 8, 16]>;
 def VecNoScalar : IntList<"VecNoScalar", [2, 3, 4, 8, 16]>;
 def Vec1        : IntList<"Vec1", [1]>;
-def Vec2        : IntList<"Vec2", [2]>;
-def Vec4        : IntList<"Vec4", [4]>;
-def Vec8        : IntList<"Vec8", [8]>;
-def Vec16       : IntList<"Vec16", [16]>;
 def Vec1234     : IntList<"Vec1234", [1, 2, 3, 4]>;
 
 // Type lists.
 def TLAll           : TypeList<[Char,  UChar, Short,  UShort, Int,  UInt, Long,  ULong, Float, Double, Half]>;
-def TLAllUnsigned   : TypeList<[UChar, UChar, UShort, UShort, UInt, UInt, ULong, ULong, UInt,  ULong,  UShort]>;
 def TLFloat         : TypeList<[Float, Double, Half]>;
 def TLSignedInts    : TypeList<[Char, Short, Int, Long]>;
 def TLUnsignedInts  : TypeList<[UChar, UShort, UInt, ULong]>;
@@ -1141,21 +1136,33 @@ let MinVersion = CL20 in {
 //--------------------------------------------------------------------
 // OpenCL v1.1 s6.11.12, v1.2 s6.12.12, v2.0 s6.13.12 - Miscellaneous Vector Functions
 // --- Table 19 ---
-foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
-  foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
-    def : Builtin<"shuffle", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
-                              GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
-                              GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
-                  Attr.Const>;
-  }
-}
-foreach VSize1 = [Vec2, Vec4, Vec8, Vec16] in {
-  foreach VSize2 = [Vec2, Vec4, Vec8, Vec16] in {
-    def : Builtin<"shuffle2", [GenericType<"TLAll" # VSize1.Name, TLAll, VSize1>,
-                               GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
-                               GenericType<"TLAll" # VSize2.Name, TLAll, VSize2>,
-                               GenericType<"TLAllUnsigned" # VSize1.Name, TLAllUnsigned, VSize1>],
-                  Attr.Const>;
+foreach VSize1 = [2, 4, 8, 16] in {
+  foreach VSize2 = [2, 4, 8, 16] in {
+    foreach VecAndMaskType = [[Char, UChar], [UChar, UChar],
+                              [Short, UShort], [UShort, UShort],
+                              [Int, UInt], [UInt, UInt],
+                              [Long, ULong], [ULong, ULong],
+                              [Float, UInt], [Double, ULong], [Half, UShort]] in {
+      def : Builtin<"shuffle", [VectorType<VecAndMaskType[0], VSize1>,
+                                VectorType<VecAndMaskType[0], VSize2>,
+                                VectorType<VecAndMaskType[1], VSize1>],
+                               Attr.Const>;
+    }
+  }
+}
+foreach VSize1 = [2, 4, 8, 16] in {
+  foreach VSize2 = [2, 4, 8, 16] in {
+    foreach VecAndMaskType = [[Char, UChar], [UChar, UChar],
+                              [Short, UShort], [UShort, UShort],
+                              [Int, UInt], [UInt, UInt],
+                              [Long, ULong], [ULong, ULong],
+                              [Float, UInt], [Double, ULong], [Half, UShort]] in {
+      def : Builtin<"shuffle2", [VectorType<VecAndMaskType[0], VSize1>,
+                                 VectorType<VecAndMaskType[0], VSize2>,
+                                 VectorType<VecAndMaskType[0], VSize2>,
+                                 VectorType<VecAndMaskType[1], VSize1>],
+                                Attr.Const>;
+    }
   }
 }
 


        


More information about the cfe-commits mailing list