r298366 - [OpenCL] Added implicit conversion rank for overloading functions with vector data type in OpenCL

Egor Churaev via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 21 05:55:55 PDT 2017


Author: echuraev
Date: Tue Mar 21 07:55:55 2017
New Revision: 298366

URL: http://llvm.org/viewvc/llvm-project?rev=298366&view=rev
Log:
[OpenCL] Added implicit conversion rank for overloading functions with vector data type in OpenCL

Summary: I added a new rank to ImplicitConversionRank enum to resolve the function overload ambiguity with vector types. Rank of scalar types conversion is lower than vector splat. So, we can choose which function should we call. See test for more details.

Reviewers: Anastasia, cfe-commits

Reviewed By: Anastasia

Subscribers: bader, yaxunl

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

Added:
    cfe/trunk/test/CodeGenOpenCL/overload.cl
Removed:
    cfe/trunk/test/SemaOpenCL/overload_addrspace_resolution.cl
Modified:
    cfe/trunk/include/clang/Sema/Overload.h
    cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/Sema/Overload.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Overload.h?rev=298366&r1=298365&r2=298366&view=diff
==============================================================================
--- cfe/trunk/include/clang/Sema/Overload.h (original)
+++ cfe/trunk/include/clang/Sema/Overload.h Tue Mar 21 07:55:55 2017
@@ -98,6 +98,7 @@ namespace clang {
     ICR_Exact_Match = 0,         ///< Exact Match
     ICR_Promotion,               ///< Promotion
     ICR_Conversion,              ///< Conversion
+    ICR_OCL_Scalar_Widening,     ///< OpenCL Scalar Widening
     ICR_Complex_Real_Conversion, ///< Complex <-> Real conversion
     ICR_Writeback_Conversion,    ///< ObjC ARC writeback conversion
     ICR_C_Conversion,            ///< Conversion only allowed in the C standard.

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=298366&r1=298365&r2=298366&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Tue Mar 21 07:55:55 2017
@@ -131,7 +131,7 @@ ImplicitConversionRank clang::GetConvers
     ICR_Conversion,
     ICR_Conversion,
     ICR_Conversion,
-    ICR_Conversion,
+    ICR_OCL_Scalar_Widening,
     ICR_Complex_Real_Conversion,
     ICR_Conversion,
     ICR_Conversion,

Added: cfe/trunk/test/CodeGenOpenCL/overload.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/overload.cl?rev=298366&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenOpenCL/overload.cl (added)
+++ cfe/trunk/test/CodeGenOpenCL/overload.cl Tue Mar 21 07:55:55 2017
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -cl-std=CL2.0 -emit-llvm -o - -triple spir-unknown-unknown %s | FileCheck %s
+
+typedef short short4 __attribute__((ext_vector_type(4)));
+
+// CHECK-DAG: declare spir_func <4 x i16> @_Z5clampDv4_sS_S_(<4 x i16>, <4 x i16>, <4 x i16>)
+short4 __attribute__ ((overloadable)) clamp(short4 x, short4 minval, short4 maxval);
+// CHECK-DAG: declare spir_func <4 x i16> @_Z5clampDv4_sss(<4 x i16>, i16 signext, i16 signext)
+short4 __attribute__ ((overloadable)) clamp(short4 x, short minval, short maxval);
+void __attribute__((overloadable)) foo(global int *a, global int *b);
+void __attribute__((overloadable)) foo(generic int *a, generic int *b);
+void __attribute__((overloadable)) bar(generic int *global *a, generic int *global *b);
+void __attribute__((overloadable)) bar(generic int *generic *a, generic int *generic *b);
+
+// Checking address space resolution
+void kernel test1() {
+  global int *a;
+  global int *b;
+  generic int *c;
+  local int *d;
+  generic int *generic *gengen;
+  generic int *local *genloc;
+  generic int *global *genglob;
+  // CHECK-DAG: call spir_func void @_Z3fooPU3AS1iS0_(i32 addrspace(1)* undef, i32 addrspace(1)* undef)
+  foo(a, b);
+  // CHECK-DAG: call spir_func void @_Z3fooPU3AS4iS0_(i32 addrspace(4)* undef, i32 addrspace(4)* undef)
+  foo(b, c);
+  // CHECK-DAG: call spir_func void @_Z3fooPU3AS4iS0_(i32 addrspace(4)* undef, i32 addrspace(4)* undef)
+  foo(a, d);
+
+  // CHECK-DAG: call spir_func void @_Z3barPU3AS4PU3AS4iS2_(i32 addrspace(4)* addrspace(4)* undef, i32 addrspace(4)* addrspace(4)* undef)
+  bar(gengen, genloc);
+  // CHECK-DAG: call spir_func void @_Z3barPU3AS4PU3AS4iS2_(i32 addrspace(4)* addrspace(4)* undef, i32 addrspace(4)* addrspace(4)* undef)
+  bar(gengen, genglob);
+  // CHECK-DAG: call spir_func void @_Z3barPU3AS1PU3AS4iS2_(i32 addrspace(4)* addrspace(1)* undef, i32 addrspace(4)* addrspace(1)* undef)
+  bar(genglob, genglob);
+}
+
+// Checking vector vs scalar resolution
+void kernel test2() {
+  short4 e0=0;
+
+  // CHECK-DAG: call spir_func <4 x i16> @_Z5clampDv4_sss(<4 x i16> zeroinitializer, i16 signext 0, i16 signext 255)
+  clamp(e0, 0, 255);
+  // CHECK-DAG: call spir_func <4 x i16> @_Z5clampDv4_sS_S_(<4 x i16> zeroinitializer, <4 x i16> zeroinitializer, <4 x i16> zeroinitializer)
+  clamp(e0, e0, e0);
+}

Removed: cfe/trunk/test/SemaOpenCL/overload_addrspace_resolution.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/overload_addrspace_resolution.cl?rev=298365&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/overload_addrspace_resolution.cl (original)
+++ cfe/trunk/test/SemaOpenCL/overload_addrspace_resolution.cl (removed)
@@ -1,29 +0,0 @@
-// RUN: %clang_cc1 -cl-std=CL2.0 -emit-llvm -o - -triple x86_64-unknown-unknown %s | FileCheck %s
-
-void __attribute__((overloadable)) foo(global int *a, global int *b);
-void __attribute__((overloadable)) foo(generic int *a, generic int *b);
-void __attribute__((overloadable)) bar(generic int *global *a, generic int *global *b);
-void __attribute__((overloadable)) bar(generic int *generic *a, generic int *generic *b);
-
-void kernel ker() {
-  global int *a;
-  global int *b;
-  generic int *c;
-  local int *d;
-  generic int *generic *gengen;
-  generic int *local *genloc;
-  generic int *global *genglob;
-  // CHECK: call void @_Z3fooPU8CLglobaliS0_(i32* undef, i32* undef)
-  foo(a, b);
-  // CHECK: call void @_Z3fooPU9CLgenericiS0_(i32* undef, i32* undef)
-  foo(b, c);
-  // CHECK: call void @_Z3fooPU9CLgenericiS0_(i32* undef, i32* undef)
-  foo(a, d);
-
-  // CHECK: call void @_Z3barPU9CLgenericPU9CLgenericiS2_(i32** undef, i32** undef)
-  bar(gengen, genloc);
-  // CHECK: call void @_Z3barPU9CLgenericPU9CLgenericiS2_(i32** undef, i32** undef)
-  bar(gengen, genglob);
-  // CHECK: call void @_Z3barPU8CLglobalPU9CLgenericiS2_(i32** undef, i32** undef)
-  bar(genglob, genglob);
-}




More information about the cfe-commits mailing list