[PATCH] D141008: [Clang][SPIR-V] Emit target extension types for OpenCL types on SPIR-V.

2023-02-09 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added inline comments.



Comment at: clang/lib/CodeGen/TargetInfo.cpp:10980
+/// Construct a SPIR-V target extension type for the given OpenCL image type.
+static llvm::Type *getSPIRVType(llvm::LLVMContext , StringRef BaseType,
+StringRef OpenCLName,

There probably can be more types


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141008/new/

https://reviews.llvm.org/D141008

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D66850: Avoid crash when dumping NULL Type as JSON

2019-08-28 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added a comment.

LGTM. I'm not an expert in JSON, but may be it makes sense to move the change a 
line earlier before creation of pointer representation?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66850/new/

https://reviews.llvm.org/D66850



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59493: [OpenCL] Generate 'unroll.enable' metadata for __attribute__((opencl_unroll_hint))

2019-03-18 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd created this revision.
sidorovd added reviewers: Anastasia, yaxunl.
Herald added subscribers: cfe-commits, jdoerfert, dmgreen, zzheng.
Herald added a project: clang.

[OpenCL] Generate 'unroll.enable' metadata for  
__attribute__((opencl_unroll_hint))

  

For both !{!"llvm.loop.unroll.enable"} and !{!"llvm.loop.unroll.full"} the 
unroller
will try to fully unroll a loop unless the trip count is not known at compile 
time.
In that case for '.full' metadata no unrolling will be processed, while for 
'.enable'
the loop will be partially unrolled with a heuristically chosen unroll factor.

  

See: docs/LanguageExtensions.rst

  

>From 
>https://www.khronos.org/registry/OpenCL/sdk/2.0/docs/man/xhtml/attributes-loopUnroll.html
--

  __attribute__((opencl_unroll_hint))
  for (int i=0; i<2; i++)
  {
  ...
  }


In the example above, the compiler will determine how much to unroll the loop.
--

Before the patch for  __attribute__((opencl_unroll_hint)) was generated metadata
!{!"llvm.loop.unroll.full"}, which limits ability of loop unroller to decide, 
how
much to unroll the loop.


Repository:
  rC Clang

https://reviews.llvm.org/D59493

Files:
  lib/CodeGen/CGLoopInfo.cpp
  test/CodeGenOpenCL/unroll-hint.cl


Index: test/CodeGenOpenCL/unroll-hint.cl
===
--- test/CodeGenOpenCL/unroll-hint.cl
+++ test/CodeGenOpenCL/unroll-hint.cl
@@ -18,12 +18,12 @@
 // CHECK: br label %{{.*}}, !llvm.loop ![[FOR_DISABLE:.*]]
 }
 
-void for_full()
+void for_enable()
 {
-// CHECK-LABEL: for_full
+// CHECK-LABEL: for_enable
 __attribute__((opencl_unroll_hint))
 for( int i = 0; i < 1000; ++i);
-// CHECK: br label %{{.*}}, !llvm.loop ![[FOR_FULL:.*]]
+// CHECK: br label %{{.*}}, !llvm.loop ![[FOR_ENABLE:.*]]
 }
 
 /*** while ***/
@@ -45,13 +45,13 @@
 // CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_DISABLE:.*]]
 }
 
-void while_full()
+void while_enable()
 {
-// CHECK-LABEL: while_full
+// CHECK-LABEL: while_enable
 int i = 1000;
 __attribute__((opencl_unroll_hint))
 while(i-->0);
-// CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_FULL:.*]]
+// CHECK: br label %{{.*}}, !llvm.loop ![[WHILE_ENABLE:.*]]
 }
 
 /*** do ***/
@@ -73,13 +73,13 @@
 // CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop 
![[DO_DISABLE:.*]]
 }
 
-void do_full()
+void do_enable()
 {
-// CHECK-LABEL: do_full
+// CHECK-LABEL: do_enable
 int i = 1000;
 __attribute__((opencl_unroll_hint))
 do {} while(i--> 0);
-// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop 
![[DO_FULL:.*]]
+// CHECK: br i1 %{{.*}}, label %{{.*}}, label %{{.*}}, !llvm.loop 
![[DO_ENABLE:.*]]
 }
 
 
@@ -87,11 +87,11 @@
 // CHECK: ![[COUNT]] =  !{!"llvm.loop.unroll.count", i32 8}
 // CHECK: ![[FOR_DISABLE]]   =  distinct !{![[FOR_DISABLE]],  ![[DISABLE:.*]]}
 // CHECK: ![[DISABLE]]   =  !{!"llvm.loop.unroll.disable"}
-// CHECK: ![[FOR_FULL]]  =  distinct !{![[FOR_FULL]],  ![[FULL:.*]]}
-// CHECK: ![[FULL]]  =  !{!"llvm.loop.unroll.full"}
+// CHECK: ![[FOR_ENABLE]]  =  distinct !{![[FOR_ENABLE]],  ![[ENABLE:.*]]}
+// CHECK: ![[ENABLE]]  =  !{!"llvm.loop.unroll.enable"}
 // CHECK: ![[WHILE_COUNT]]   =  distinct !{![[WHILE_COUNT]],![[COUNT]]}
 // CHECK: ![[WHILE_DISABLE]] =  distinct !{![[WHILE_DISABLE]],  ![[DISABLE]]}
-// CHECK: ![[WHILE_FULL]]=  distinct !{![[WHILE_FULL]], ![[FULL]]}
+// CHECK: ![[WHILE_ENABLE]]=  distinct !{![[WHILE_ENABLE]], 
![[ENABLE]]}
 // CHECK: ![[DO_COUNT]]  =  distinct !{![[DO_COUNT]],   ![[COUNT]]}
 // CHECK: ![[DO_DISABLE]]=  distinct !{![[DO_DISABLE]], ![[DISABLE]]}
-// CHECK: ![[DO_FULL]]   =  distinct !{![[DO_FULL]],![[FULL]]}
+// CHECK: ![[DO_ENABLE]]   =  distinct !{![[DO_ENABLE]],
![[ENABLE]]}
Index: lib/CodeGen/CGLoopInfo.cpp
===
--- lib/CodeGen/CGLoopInfo.cpp
+++ lib/CodeGen/CGLoopInfo.cpp
@@ -208,13 +208,13 @@
 // Translate opencl_unroll_hint attribute argument to
 // equivalent LoopHintAttr enums.
 // OpenCL v2.0 s6.11.5:
-// 0 - full unroll (no argument).
+// 0 - enable unroll (no argument).
 // 1 - disable unroll.
 // other positive integer n - unroll by n.
 if (OpenCLHint) {
   ValueInt = OpenCLHint->getUnrollHint();
   if (ValueInt == 0) {
-State = LoopHintAttr::Full;
+State = LoopHintAttr::Enable;
   } else if (ValueInt != 1) {
 Option = LoopHintAttr::UnrollCount;
 State = LoopHintAttr::Numeric;


Index: test/CodeGenOpenCL/unroll-hint.cl
===
--- test/CodeGenOpenCL/unroll-hint.cl
+++ test/CodeGenOpenCL/unroll-hint.cl
@@ -18,12 +18,12 @@
 // CHECK: br label 

[PATCH] D58666: [OpenCL] Undefine cl_intel_planar_yuv extension

2019-02-28 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd marked an inline comment as done.
sidorovd added inline comments.



Comment at: test/SemaOpenCL/extension-begin.cl:26
+
 #ifndef IMPLICIT_INCLUDE
 #include "extension-begin.h"

Anastasia wrote:
> sidorovd wrote:
> > Anastasia wrote:
> > > sidorovd wrote:
> > > > Anastasia wrote:
> > > > > Can we also test that macro `my_ext` is not defined here but defined 
> > > > > above?
> > > > > 
> > > > > It seems we are not testing anything like this...
> > > > #pragma OPENCL EXTENSION my_ext : begin doesn't define an appropriate 
> > > > macro. And so cl-ext=+my_ext.
> > > But don't you need to expose the definition of it?
> > Certainly I need, but now the only proper way to do so is by adding an 
> > extension via adding it in OpenCLExtensions.def. Previously we decided to 
> > avoid adding an extension directly into clang, so with a new approach I'd 
> > prefer not to add a definition of the macro in the header but define it 
> > somewhere else, otherwise the macro becomes defined  where it's not 
> > supposed to be (even for ARM and AMD =) ). 
> However, my understanding is that you should define the macro when you define 
> the extension itself.
> 
> 
> ```
> #pragma OPENCL EXTENSION my_ext : begin
> #define my_ext
> ...
> #pragma OPENCL EXTENSION my_ext : end
> ```
> 
> does it not work for you?
```
#pragma OPENCL EXTENSION my_ext : begin
#define my_ext
...
#pragma OPENCL EXTENSION my_ext : end
```
 ^
 I
 It defines the macro regardless begin : end range, so one can consider that 
it's the same code as:

```
#define my_ext
#pragma OPENCL EXTENSION my_ext : begin
...
#pragma OPENCL EXTENSION my_ext : end
```

I agree, that it's a better way to define a macro with defining an appropriate 
extension itself, but it makes it be defined where it's not supposed to be (at 
least from my perspective).

To sum up:
1. #pragma OPENCL EXTENSION my_ext : begin ... end  - makes an extension known 
for clang if the header included and if the extension enabled; doesn't affect a 
macro definition anyhow;
2.  OPENCLEXT_INTERNAL(my_ext, *version*, ~0U) -  makes an extension known for 
clang and defines an appropriate macro if the extension enabled.

I believe we are okay not to define cl_intel_planar_yuv macro in the header - 
just make the extension known for clang. 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58666/new/

https://reviews.llvm.org/D58666



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58666: [OpenCL] Undefine cl_intel_planar_yuv extension

2019-02-27 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd marked an inline comment as done.
sidorovd added inline comments.



Comment at: test/SemaOpenCL/extension-begin.cl:26
+
 #ifndef IMPLICIT_INCLUDE
 #include "extension-begin.h"

Anastasia wrote:
> sidorovd wrote:
> > Anastasia wrote:
> > > Can we also test that macro `my_ext` is not defined here but defined 
> > > above?
> > > 
> > > It seems we are not testing anything like this...
> > #pragma OPENCL EXTENSION my_ext : begin doesn't define an appropriate 
> > macro. And so cl-ext=+my_ext.
> But don't you need to expose the definition of it?
Certainly I need, but now the only proper way to do so is by adding an 
extension via adding it in OpenCLExtensions.def. Previously we decided to avoid 
adding an extension directly into clang, so with a new approach I'd prefer not 
to add a definition of the macro in the header but define it somewhere else, 
otherwise the macro becomes defined  where it's not supposed to be (even for 
ARM and AMD =) ). 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58666/new/

https://reviews.llvm.org/D58666



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58666: [OpenCL] Undefine cl_intel_planar_yuv extension

2019-02-26 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd marked an inline comment as done.
sidorovd added inline comments.



Comment at: test/SemaOpenCL/extension-begin.cl:26
+
 #ifndef IMPLICIT_INCLUDE
 #include "extension-begin.h"

Anastasia wrote:
> Can we also test that macro `my_ext` is not defined here but defined above?
> 
> It seems we are not testing anything like this...
#pragma OPENCL EXTENSION my_ext : begin doesn't define an appropriate macro. 
And so cl-ext=+my_ext.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58666/new/

https://reviews.llvm.org/D58666



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58666: [OpenCL] Undefine cl_intel_planar_yuv extension

2019-02-26 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 188338.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58666/new/

https://reviews.llvm.org/D58666

Files:
  lib/Headers/opencl-c.h
  test/Headers/opencl-c-header.cl
  test/SemaOpenCL/extension-begin.cl


Index: test/SemaOpenCL/extension-begin.cl
===
--- test/SemaOpenCL/extension-begin.cl
+++ test/SemaOpenCL/extension-begin.cl
@@ -16,6 +16,13 @@
 //
 // RUN: %clang_cc1 -cl-std=CL2.0 -DIMPLICIT_INCLUDE -include 
%S/extension-begin.h -triple spir-unknown-unknown -O0 -emit-llvm -o - -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t.modules %s -verify -pedantic
 
+#pragma OPENCL EXTENSION my_ext : enable
+#ifndef IMPLICIT_INCLUDE
+// expected-warning@-2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+// expected-warning@+2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+#endif // IMPLICIT_INCLUDE
+#pragma OPENCL EXTENSION my_ext : disable
+
 #ifndef IMPLICIT_INCLUDE
 #include "extension-begin.h"
 #endif // IMPLICIT_INCLUDE
Index: test/Headers/opencl-c-header.cl
===
--- test/Headers/opencl-c-header.cl
+++ test/Headers/opencl-c-header.cl
@@ -77,9 +77,6 @@
 // OpenCL 1.2 onwards.
 #if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // expected-no-diagnostics
-#ifndef cl_intel_planar_yuv
-#error "Missing cl_intel_planar_yuv define"
-#endif
 #else //__OPENCL_C_VERSION__
 // expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
 #endif //__OPENCL_C_VERSION__
Index: lib/Headers/opencl-c.h
===
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -22,9 +22,6 @@
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
-#ifndef cl_intel_planar_yuv
-#define cl_intel_planar_yuv
-#endif // cl_intel_planar_yuv
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : end
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2


Index: test/SemaOpenCL/extension-begin.cl
===
--- test/SemaOpenCL/extension-begin.cl
+++ test/SemaOpenCL/extension-begin.cl
@@ -16,6 +16,13 @@
 //
 // RUN: %clang_cc1 -cl-std=CL2.0 -DIMPLICIT_INCLUDE -include %S/extension-begin.h -triple spir-unknown-unknown -O0 -emit-llvm -o - -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.modules %s -verify -pedantic
 
+#pragma OPENCL EXTENSION my_ext : enable
+#ifndef IMPLICIT_INCLUDE
+// expected-warning@-2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+// expected-warning@+2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+#endif // IMPLICIT_INCLUDE
+#pragma OPENCL EXTENSION my_ext : disable
+
 #ifndef IMPLICIT_INCLUDE
 #include "extension-begin.h"
 #endif // IMPLICIT_INCLUDE
Index: test/Headers/opencl-c-header.cl
===
--- test/Headers/opencl-c-header.cl
+++ test/Headers/opencl-c-header.cl
@@ -77,9 +77,6 @@
 // OpenCL 1.2 onwards.
 #if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // expected-no-diagnostics
-#ifndef cl_intel_planar_yuv
-#error "Missing cl_intel_planar_yuv define"
-#endif
 #else //__OPENCL_C_VERSION__
 // expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - ignoring}}
 #endif //__OPENCL_C_VERSION__
Index: lib/Headers/opencl-c.h
===
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -22,9 +22,6 @@
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
-#ifndef cl_intel_planar_yuv
-#define cl_intel_planar_yuv
-#endif // cl_intel_planar_yuv
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : end
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D58666: [OpenCL] Undefine cl_intel_planar_yuv extension

2019-02-26 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd created this revision.
sidorovd added reviewers: Anastasia, yaxunl.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Consider the code:

  #pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
  // some declarations
  #pragma OPENCL EXTENSION cl_intel_planar_yuv : end

is enough for extension to become known for clang.

Remove unnecessary definition (otherwise the extension will be define where 
it's not supposed to be defined).


Repository:
  rC Clang

https://reviews.llvm.org/D58666

Files:
  lib/Headers/opencl-c-common.h
  test/Headers/opencl-c-header.cl
  test/SemaOpenCL/extension-begin.cl


Index: test/SemaOpenCL/extension-begin.cl
===
--- test/SemaOpenCL/extension-begin.cl
+++ test/SemaOpenCL/extension-begin.cl
@@ -16,6 +16,13 @@
 //
 // RUN: %clang_cc1 -cl-std=CL2.0 -DIMPLICIT_INCLUDE -include 
%S/extension-begin.h -triple spir-unknown-unknown -O0 -emit-llvm -o - -fmodules 
-fimplicit-module-maps -fmodules-cache-path=%t.modules %s -verify -pedantic
 
+#pragma OPENCL EXTENSION my_ext : enable
+#ifndef IMPLICIT_INCLUDE
+// expected-warning@-2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+// expected-warning@+2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+#endif // IMPLICIT_INCLUDE
+#pragma OPENCL EXTENSION my_ext : disable
+
 #ifndef IMPLICIT_INCLUDE
 #include "extension-begin.h"
 #endif // IMPLICIT_INCLUDE
@@ -31,8 +38,8 @@
   f();
   g(0);
 }
+#pragma OPENCL EXTENSION my_ext : disable
 
-#pragma OPENCL EXTENSION my_ext : disable 
 void test_f2(void) {
   struct A test_A2; // expected-error {{use of type 'struct A' requires my_ext 
extension to be enabled}}
   const struct A test_A_local; // expected-error {{use of type 'struct A' 
requires my_ext extension to be enabled}}
@@ -43,4 +50,3 @@
 // expected-note@extension-begin.h:18 {{candidate unavailable as it 
requires OpenCL extension 'my_ext' to be enabled}}
 // expected-note@extension-begin.h:23 {{candidate function not viable: 
requires 0 arguments, but 1 was provided}}
 }
-
Index: test/Headers/opencl-c-header.cl
===
--- test/Headers/opencl-c-header.cl
+++ test/Headers/opencl-c-header.cl
@@ -77,9 +77,6 @@
 // OpenCL 1.2 onwards.
 #if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // expected-no-diagnostics
-#ifndef cl_intel_planar_yuv
-#error "Missing cl_intel_planar_yuv define"
-#endif
 #else //__OPENCL_C_VERSION__
 // expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
 #endif //__OPENCL_C_VERSION__
Index: lib/Headers/opencl-c-common.h
===
--- lib/Headers/opencl-c-common.h
+++ lib/Headers/opencl-c-common.h
@@ -21,9 +21,6 @@
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
 #if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
-#ifndef cl_intel_planar_yuv
-#define cl_intel_planar_yuv
-#endif // cl_intel_planar_yuv
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : end
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2


Index: test/SemaOpenCL/extension-begin.cl
===
--- test/SemaOpenCL/extension-begin.cl
+++ test/SemaOpenCL/extension-begin.cl
@@ -16,6 +16,13 @@
 //
 // RUN: %clang_cc1 -cl-std=CL2.0 -DIMPLICIT_INCLUDE -include %S/extension-begin.h -triple spir-unknown-unknown -O0 -emit-llvm -o - -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.modules %s -verify -pedantic
 
+#pragma OPENCL EXTENSION my_ext : enable
+#ifndef IMPLICIT_INCLUDE
+// expected-warning@-2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+// expected-warning@+2 {{unknown OpenCL extension 'my_ext' - ignoring}}
+#endif // IMPLICIT_INCLUDE
+#pragma OPENCL EXTENSION my_ext : disable
+
 #ifndef IMPLICIT_INCLUDE
 #include "extension-begin.h"
 #endif // IMPLICIT_INCLUDE
@@ -31,8 +38,8 @@
   f();
   g(0);
 }
+#pragma OPENCL EXTENSION my_ext : disable
 
-#pragma OPENCL EXTENSION my_ext : disable 
 void test_f2(void) {
   struct A test_A2; // expected-error {{use of type 'struct A' requires my_ext extension to be enabled}}
   const struct A test_A_local; // expected-error {{use of type 'struct A' requires my_ext extension to be enabled}}
@@ -43,4 +50,3 @@
 // expected-note@extension-begin.h:18 {{candidate unavailable as it requires OpenCL extension 'my_ext' to be enabled}}
 // expected-note@extension-begin.h:23 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
 }
-
Index: test/Headers/opencl-c-header.cl
===
--- test/Headers/opencl-c-header.cl
+++ test/Headers/opencl-c-header.cl
@@ -77,9 +77,6 @@
 // OpenCL 1.2 onwards.
 #if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // expected-no-diagnostics
-#ifndef cl_intel_planar_yuv
-#error "Missing cl_intel_planar_yuv define"
-#endif
 #else 

[PATCH] D54947: [OpenCL][CodeGen] Fix replacing memcpy with addrspacecast

2018-11-30 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 176085.
sidorovd marked an inline comment as done.
sidorovd added a comment.

Removed redundant lines in a comment


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54947/new/

https://reviews.llvm.org/D54947

Files:
  lib/CodeGen/CGCall.cpp
  test/CodeGenOpenCL/addr-space-struct-arg.cl


Index: test/CodeGenOpenCL/addr-space-struct-arg.cl
===
--- test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header 
-ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope 
-check-prefixes=COM,X86 %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple 
amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 
-finclude-default-header -triple amdgcn | FileCheck -enable-var-scope 
-check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -ffake-address-space-map -triple 
i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -triple amdgcn | FileCheck 
-enable-var-scope -check-prefixes=COM,AMDGCN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -triple amdgcn | 
FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O0 -triple 
spir-unknown-unknown-unknown | FileCheck -enable-var-scope -check-prefixes=SPIR 
%s
+
+typedef int int2 __attribute__((ext_vector_type(2)));
 
 typedef struct {
   int cells[9];
@@ -130,6 +133,12 @@
   FuncOneMember(u);
 }
 
+// SPIR: call void @llvm.memcpy.p0i8.p1i8.i32
+// SPIR-NOT: addrspacecast
+kernel void KernelOneMemberSpir(global struct StructOneMember* u) {
+  FuncOneMember(*u);
+}
+
 // AMDGCN-LABEL: define amdgpu_kernel void @KernelLargeOneMember(
 // AMDGCN:  %[[U:.*]] = alloca %struct.LargeStructOneMember, align 8, 
addrspace(5)
 // AMDGCN:  store %struct.LargeStructOneMember %u.coerce, 
%struct.LargeStructOneMember addrspace(5)* %[[U]], align 8
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -3954,15 +3954,28 @@
 } else if (I->hasLValue()) {
   auto LV = I->getKnownLValue();
   auto AS = LV.getAddressSpace();
+
   if ((!ArgInfo.getIndirectByVal() &&
(LV.getAlignment() >=
-getContext().getTypeAlignInChars(I->Ty))) ||
-  (ArgInfo.getIndirectByVal() &&
-   ((AS != LangAS::Default && AS != LangAS::opencl_private &&
- AS != CGM.getASTAllocaAddressSpace() {
+getContext().getTypeAlignInChars(I->Ty {
+NeedCopy = true;
+  }
+  if (!getLangOpts().OpenCL) {
+if ((ArgInfo.getIndirectByVal() &&
+(AS != LangAS::Default &&
+ AS != CGM.getASTAllocaAddressSpace( {
+  NeedCopy = true;
+}
+  }
+  // For OpenCL even if RV is located in default or alloca address 
space
+  // we don't want to perform address space cast for it.
+  else if ((ArgInfo.getIndirectByVal() &&
+Addr.getType()->getAddressSpace() != IRFuncTy->
+  getParamType(FirstIRArg)->getPointerAddressSpace())) {
 NeedCopy = true;
   }
 }
+
 if (NeedCopy) {
   // Create an aligned temporary, and copy to it.
   Address AI = CreateMemTempWithoutCast(


Index: test/CodeGenOpenCL/addr-space-struct-arg.cl
===
--- test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -finclude-default-header -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O0 -triple spir-unknown-unknown-unknown | FileCheck -enable-var-scope -check-prefixes=SPIR %s
+

[PATCH] D54947: [OpenCL][CodeGen] Fix replacing memcpy with addrspacecast

2018-11-30 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added inline comments.



Comment at: lib/CodeGen/CGCall.cpp:3972
+  // we don't want to perform address space cast for it, since that
+  // leads to casting __private * (default addr space in OpenCL) to
+  // __global * which is not valid. Create memcpy call instead.

Anastasia wrote:
> sidorovd wrote:
> > Anastasia wrote:
> > > This statement is incorrect. Private is only default AS in CL versions 
> > > before 2.0.
> > > 
> > > I feel this can be expressed simpler. I guess the observation here is 
> > > that if addr space mismatches it has to generate a copy because even if 
> > > it would be a generic we can't get what the original specific addr space 
> > > was? So it's safe to generate a copy.
> > > This statement is incorrect. Private is only default AS in CL versions 
> > > before 2.0.
> > You are right, thanks!
> > 
> > Still I want to leave the comment almost as is, since it creates a link 
> > with a previous one on lines 3928-3935.
> I feel it doesn't add much value, but rather exactly says what code does. At 
> least this is definitely obvious from this code:
>   Create memcpy call if RV is located in an address space different than that 
> of
Agree


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54947/new/

https://reviews.llvm.org/D54947



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54947: [OpenCL][CodeGen] Fix replacing memcpy with addrspacecast

2018-11-28 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 175722.
sidorovd marked 4 inline comments as done.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54947/new/

https://reviews.llvm.org/D54947

Files:
  lib/CodeGen/CGCall.cpp
  test/CodeGenOpenCL/addr-space-struct-arg.cl


Index: test/CodeGenOpenCL/addr-space-struct-arg.cl
===
--- test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header 
-ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope 
-check-prefixes=COM,X86 %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple 
amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 
-finclude-default-header -triple amdgcn | FileCheck -enable-var-scope 
-check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -ffake-address-space-map -triple 
i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -triple amdgcn | FileCheck 
-enable-var-scope -check-prefixes=COM,AMDGCN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -triple amdgcn | 
FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O0 -triple 
spir-unknown-unknown-unknown | FileCheck -enable-var-scope -check-prefixes=SPIR 
%s
+
+typedef int int2 __attribute__((ext_vector_type(2)));
 
 typedef struct {
   int cells[9];
@@ -130,6 +133,12 @@
   FuncOneMember(u);
 }
 
+// SPIR: call void @llvm.memcpy.p0i8.p1i8.i32
+// SPIR-NOT: addrspacecast
+kernel void KernelOneMemberSpir(global struct StructOneMember* u) {
+  FuncOneMember(*u);
+}
+
 // AMDGCN-LABEL: define amdgpu_kernel void @KernelLargeOneMember(
 // AMDGCN:  %[[U:.*]] = alloca %struct.LargeStructOneMember, align 8, 
addrspace(5)
 // AMDGCN:  store %struct.LargeStructOneMember %u.coerce, 
%struct.LargeStructOneMember addrspace(5)* %[[U]], align 8
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -3954,15 +3954,30 @@
 } else if (I->hasLValue()) {
   auto LV = I->getKnownLValue();
   auto AS = LV.getAddressSpace();
+
   if ((!ArgInfo.getIndirectByVal() &&
(LV.getAlignment() >=
-getContext().getTypeAlignInChars(I->Ty))) ||
-  (ArgInfo.getIndirectByVal() &&
-   ((AS != LangAS::Default && AS != LangAS::opencl_private &&
- AS != CGM.getASTAllocaAddressSpace() {
+getContext().getTypeAlignInChars(I->Ty {
+NeedCopy = true;
+  }
+  if (!getLangOpts().OpenCL) {
+if ((ArgInfo.getIndirectByVal() &&
+(AS != LangAS::Default &&
+ AS != CGM.getASTAllocaAddressSpace( {
+  NeedCopy = true;
+}
+  }
+  // For OpenCL even if RV is located in default or alloca address 
space
+  // we don't want to perform address space cast for it. Create memcpy
+  // call if RV is located in an address space different than that of
+  // the argument (0) instead.
+  else if ((ArgInfo.getIndirectByVal() &&
+Addr.getType()->getAddressSpace() != IRFuncTy->
+  getParamType(FirstIRArg)->getPointerAddressSpace())) {
 NeedCopy = true;
   }
 }
+
 if (NeedCopy) {
   // Create an aligned temporary, and copy to it.
   Address AI = CreateMemTempWithoutCast(


Index: test/CodeGenOpenCL/addr-space-struct-arg.cl
===
--- test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
-// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -finclude-default-header -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -O0 -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O0 -triple 

[PATCH] D54947: [OpenCL][CodeGen] Fix replacing memcpy with addrspacecast

2018-11-28 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added a comment.

@yaxunl, since I'm partially reverting your change 
https://reviews.llvm.org/D34367 can you give a feedback on this?




Comment at: lib/CodeGen/CGCall.cpp:3972
+  // we don't want to perform address space cast for it, since that
+  // leads to casting __private * (default addr space in OpenCL) to
+  // __global * which is not valid. Create memcpy call instead.

Anastasia wrote:
> This statement is incorrect. Private is only default AS in CL versions before 
> 2.0.
> 
> I feel this can be expressed simpler. I guess the observation here is that if 
> addr space mismatches it has to generate a copy because even if it would be a 
> generic we can't get what the original specific addr space was? So it's safe 
> to generate a copy.
> This statement is incorrect. Private is only default AS in CL versions before 
> 2.0.
You are right, thanks!

Still I want to leave the comment almost as is, since it creates a link with a 
previous one on lines 3928-3935.



Comment at: test/CodeGenOpenCL/addr-space-struct-arg.cl:4
 // RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 
-finclude-default-header -triple amdgcn | FileCheck -enable-var-scope 
-check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O0 
-finclude-default-header -triple spir-unknown-unknown-unknown | FileCheck 
-enable-var-scope -check-prefixes=SPIR %s
 

Anastasia wrote:
> Do you know why we need `-finclude-default-header` here? If it's just for 
> vector types perhaps we should just declare them here... headers parsing is 
> expensive in terms of time.
Yeap, it's just for vectors. Added typedef for int2.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D54947/new/

https://reviews.llvm.org/D54947



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54947: [OpenCL][CodeGen] Fix replacing memcpy with addrspacecast

2018-11-27 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd created this revision.
sidorovd added reviewers: yaxunl, Anastasia.
Herald added a subscriber: cfe-commits.

If a function argument is byval and RV is located in default or alloca address 
space
an optimization of creating addrspacecast instead of memcpy is performed. That 
is
not correct for OpenCL, where that can lead to a situation of address space 
casting
from __private * to __global *. See an example below:

  typedef struct {
int x;
  } MyStruct;
  
  void foo(MyStruct val) {}
  
  kernel void KernelOneMember(__global MyStruct* x) {
foo (*x);
  }

for this code clang generated following IR:
...
%0 = load %struct.MyStruct addrspace(1)*, %struct.MyStruct addrspace(1)**
%x.addr, align 4
%1 = addrspacecast %struct.MyStruct addrspace(1)* %0 to %struct.MyStruct*
...

So the optimization was disallowed for OpenCL if RV is located in an address 
space
different than that of the argument (0).


Repository:
  rC Clang

https://reviews.llvm.org/D54947

Files:
  lib/CodeGen/CGCall.cpp
  test/CodeGenOpenCL/addr-space-struct-arg.cl


Index: test/CodeGenOpenCL/addr-space-struct-arg.cl
===
--- test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header 
-ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope 
-check-prefixes=COM,X86 %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple 
amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 
-finclude-default-header -triple amdgcn | FileCheck -enable-var-scope 
-check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O0 
-finclude-default-header -triple spir-unknown-unknown-unknown | FileCheck 
-enable-var-scope -check-prefixes=SPIR %s
 
 typedef struct {
   int cells[9];
@@ -130,6 +131,12 @@
   FuncOneMember(u);
 }
 
+// SPIR: call void @llvm.memcpy.p0i8.p1i8.i32
+// SPIR-NOT: addrspacecast
+kernel void KernelOneMemberSpir(global struct StructOneMember* u) {
+  FuncOneMember(*u);
+}
+
 // AMDGCN-LABEL: define amdgpu_kernel void @KernelLargeOneMember(
 // AMDGCN:  %[[U:.*]] = alloca %struct.LargeStructOneMember, align 8, 
addrspace(5)
 // AMDGCN:  store %struct.LargeStructOneMember %u.coerce, 
%struct.LargeStructOneMember addrspace(5)* %[[U]], align 8
Index: lib/CodeGen/CGCall.cpp
===
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -3954,15 +3954,30 @@
 } else if (I->hasLValue()) {
   auto LV = I->getKnownLValue();
   auto AS = LV.getAddressSpace();
+
   if ((!ArgInfo.getIndirectByVal() &&
(LV.getAlignment() >=
-getContext().getTypeAlignInChars(I->Ty))) ||
-  (ArgInfo.getIndirectByVal() &&
-   ((AS != LangAS::Default && AS != LangAS::opencl_private &&
- AS != CGM.getASTAllocaAddressSpace() {
+getContext().getTypeAlignInChars(I->Ty {
+NeedCopy = true;
+  }
+  if (!getLangOpts().OpenCL) {
+if ((ArgInfo.getIndirectByVal() &&
+(AS != LangAS::Default &&
+ AS != CGM.getASTAllocaAddressSpace( {
+  NeedCopy = true;
+}
+  }
+  // For OpenCL even if RV is located in default or alloca address 
space
+  // we don't want to perform address space cast for it, since that
+  // leads to casting __private * (default addr space in OpenCL) to
+  // __global * which is not valid. Create memcpy call instead.
+  else if ((ArgInfo.getIndirectByVal() &&
+Addr.getType()->getAddressSpace() != IRFuncTy->
+  getParamType(FirstIRArg)->getPointerAddressSpace())) {
 NeedCopy = true;
   }
 }
+
 if (NeedCopy) {
   // Create an aligned temporary, and copy to it.
   Address AI = CreateMemTempWithoutCast(


Index: test/CodeGenOpenCL/addr-space-struct-arg.cl
===
--- test/CodeGenOpenCL/addr-space-struct-arg.cl
+++ test/CodeGenOpenCL/addr-space-struct-arg.cl
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -ffake-address-space-map -triple i686-pc-darwin | FileCheck -enable-var-scope -check-prefixes=COM,X86 %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -O0 -finclude-default-header -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN %s
 // RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL2.0 -O0 -finclude-default-header -triple amdgcn | FileCheck -enable-var-scope -check-prefixes=COM,AMDGCN,AMDGCN20 %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -cl-std=CL1.2 -O0 -finclude-default-header -triple spir-unknown-unknown-unknown | 

[PATCH] D51341: [HEADER] Overloadable function candidates for half/double types

2018-11-16 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added a comment.

@Anastasia @yaxunl 
Hi, I am working on generalizing this patch and several questions have raised 
during this, so I want to discuss them with you:

1. Should #pragma OPENCL EXTENSION ext_name : begin enables the extension as 
well? For now I see it's not, as an example:

  #pragma OPENCL EXTENSION cl_khr_fp16 : enable
  half __attribute__((overloadable)) goo(half in1, half in2); // all ok
  #pragma OPENCL EXTENSION cl_khr_fp16 : disable
  
  #pragma OPENCL EXTENSION cl_khr_fp16 : begin
  half __attribute__((overloadable)) goo(half in1, half in2); // declaring 
function parameter of type 'half' is not allowed; did you forget * ?
  #pragma OPENCL EXTENSION cl_khr_fp16 : end

2. As far as I understand, when declaring an extension we shall have 1 #pragma 
begin and 1 #pragma end. But here is a test called extension-begin and it's 
header one can see this construction:

  #pragma OPENCL EXTENSION all : begin
  #pragma OPENCL EXTENSION all : end 
  
  #pragma OPENCL EXTENSION my_ext : begin
  ///some code
  #pragma OPENCL EXTENSION my_ext : end 
  #pragma OPENCL EXTENSION my_ext : end // why?
  }

so here my_ext has double ending. And in this way the test passes, but if I 
remove second ending (which is redundant from my perspective), I see following 
diagnostics: " OpenCL extension end directive mismatches begin directive - 
ignoring". Is it a bug or it's supposed to work that way?


https://reviews.llvm.org/D51341



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51402: [OpenCL] Adding cl_intel_planar_yuv extension

2018-10-19 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added a comment.

Ping


https://reviews.llvm.org/D51402



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51402: [OpenCL] Adding cl_intel_planar_yuv extension

2018-10-11 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 169188.
sidorovd added a comment.

- Forgot to add clarification comments on conditional branching.  Added.


https://reviews.llvm.org/D51402

Files:
  Headers/opencl-c-header.cl
  Headers/opencl-c.h


Index: Headers/opencl-c-header.cl
===
--- Headers/opencl-c-header.cl
+++ Headers/opencl-c-header.cl
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s| FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -cl-std=CL1.1| 
FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1| 
FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2| 
FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -71,4 +72,16 @@
 }
 #endif //__OPENCL_C_VERSION__
 
+// Verify that non-builtin cl_intel_planar_yuv extension is defined from
+// OpenCL 1.2 onwards.
+#if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
+// expected-no-diagnostics
+#ifndef cl_intel_planar_yuv
+#error "Missing cl_intel_planar_yuv define"
+#endif
+#else //__OPENCL_C_VERSION__
+// expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
+#endif //__OPENCL_C_VERSION__
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
+
 // CHECK-MOD: Reading modules
Index: Headers/opencl-c.h
===
--- Headers/opencl-c.h
+++ Headers/opencl-c.h
@@ -22,6 +22,14 @@
 #endif //cl_khr_3d_image_writes
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
+#if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#ifndef cl_intel_planar_yuv
+#define cl_intel_planar_yuv
+#endif // cl_intel_planar_yuv
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : end
+#endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+
 #define __ovld __attribute__((overloadable))
 #define __conv __attribute__((convergent))
 


Index: Headers/opencl-c-header.cl
===
--- Headers/opencl-c-header.cl
+++ Headers/opencl-c-header.cl
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s| FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -cl-std=CL1.1| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2| FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -71,4 +72,16 @@
 }
 #endif //__OPENCL_C_VERSION__
 
+// Verify that non-builtin cl_intel_planar_yuv extension is defined from
+// OpenCL 1.2 onwards.
+#if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
+// expected-no-diagnostics
+#ifndef cl_intel_planar_yuv
+#error "Missing cl_intel_planar_yuv define"
+#endif
+#else //__OPENCL_C_VERSION__
+// expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - ignoring}}
+#endif //__OPENCL_C_VERSION__
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
+
 // CHECK-MOD: Reading modules
Index: Headers/opencl-c.h
===
--- Headers/opencl-c.h
+++ Headers/opencl-c.h
@@ -22,6 +22,14 @@
 #endif //cl_khr_3d_image_writes
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
+#if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#ifndef cl_intel_planar_yuv
+#define cl_intel_planar_yuv
+#endif // cl_intel_planar_yuv
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : end
+#endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+
 #define __ovld __attribute__((overloadable))
 #define __conv __attribute__((convergent))
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51402: [OpenCL] Adding cl_intel_planar_yuv extension

2018-10-11 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 169187.
sidorovd added a comment.

Moved the test to test/Headers/opencl-c-header.cl


https://reviews.llvm.org/D51402

Files:
  Headers/opencl-c-header.cl
  Headers/opencl-c.h


Index: Headers/opencl-c-header.cl
===
--- Headers/opencl-c-header.cl
+++ Headers/opencl-c-header.cl
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s| FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -cl-std=CL1.1| 
FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1| 
FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem 
../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2| 
FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -71,4 +72,16 @@
 }
 #endif //__OPENCL_C_VERSION__
 
+// Verify that non-builtin cl_intel_planar_yuv extension is defined from
+// OpenCL 1.2 onwards.
+#if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
+// expected-no-diagnostics
+#ifndef cl_intel_planar_yuv
+#error "Missing cl_intel_planar_yuv define"
+#endif
+#else
+// expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
+#endif
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
+
 // CHECK-MOD: Reading modules
Index: Headers/opencl-c.h
===
--- Headers/opencl-c.h
+++ Headers/opencl-c.h
@@ -22,6 +22,14 @@
 #endif //cl_khr_3d_image_writes
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
+#if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#ifndef cl_intel_planar_yuv
+#define cl_intel_planar_yuv
+#endif // cl_intel_planar_yuv
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : end
+#endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+
 #define __ovld __attribute__((overloadable))
 #define __conv __attribute__((convergent))
 


Index: Headers/opencl-c-header.cl
===
--- Headers/opencl-c-header.cl
+++ Headers/opencl-c-header.cl
@@ -1,5 +1,6 @@
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s| FileCheck %s
-// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -cl-std=CL1.1| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify | FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.1| FileCheck %s
+// RUN: %clang_cc1 -O0 -triple spir-unknown-unknown -internal-isystem ../../lib/Headers -include opencl-c.h -emit-llvm -o - %s -verify -cl-std=CL1.2| FileCheck %s
 
 // Test including the default header as a module.
 // The module should be compiled only once and loaded from cache afterwards.
@@ -71,4 +72,16 @@
 }
 #endif //__OPENCL_C_VERSION__
 
+// Verify that non-builtin cl_intel_planar_yuv extension is defined from
+// OpenCL 1.2 onwards.
+#if (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
+// expected-no-diagnostics
+#ifndef cl_intel_planar_yuv
+#error "Missing cl_intel_planar_yuv define"
+#endif
+#else
+// expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - ignoring}}
+#endif
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
+
 // CHECK-MOD: Reading modules
Index: Headers/opencl-c.h
===
--- Headers/opencl-c.h
+++ Headers/opencl-c.h
@@ -22,6 +22,14 @@
 #endif //cl_khr_3d_image_writes
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
+#if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#ifndef cl_intel_planar_yuv
+#define cl_intel_planar_yuv
+#endif // cl_intel_planar_yuv
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : end
+#endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+
 #define __ovld __attribute__((overloadable))
 #define __conv __attribute__((convergent))
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52658: [OpenCL] Remove PIPE_RESERVE_ID_VALID_BIT from opencl-c.h

2018-10-02 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added a comment.

In https://reviews.llvm.org/D52658#1252744, @Anastasia wrote:

> Does it mean we should close https://reviews.llvm.org/D32896?


Yes

In https://reviews.llvm.org/D52658#1252744, @Anastasia wrote:

> Would it make sense to keep this value as Clang implementation and if vendors 
> need to change this they can `undef` it and redefine a new value. Would this 
> work?


This would work, but the macro isn't existing in the spec and while there 
already is implementation defined function 'is_valid_reserve_id()' I don't see 
any reason for PIPE_RESERVE_ID_VALID_BIT to be defined in the header.


Repository:
  rC Clang

https://reviews.llvm.org/D52658



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51402: [OpenCL] Adding cl_intel_planar_yuv extension

2018-10-02 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added a comment.

@Anastasia , since there is a problem I described, wouldn't you mind if I stay 
with the first iteration of the patch (adding the extension to 
OpenCLExtensions.def) and after we'll investigate what is wrong with -cl-ext 
approach?


https://reviews.llvm.org/D51402



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52658: [OpenCL] Remove PIPE_RESERVE_ID_VALID_BIT from the common header

2018-09-28 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd created this revision.
sidorovd added reviewers: Anastasia, yaxunl.
Herald added a subscriber: cfe-commits.

PIPE_RESERVE_ID_VALID_BIT is implementation defined, so lets not keep it in the 
header.

Previously the topic was discussed here: https://reviews.llvm.org/D32896


Repository:
  rC Clang

https://reviews.llvm.org/D52658

Files:
  lib/Headers/opencl-c.h


Index: lib/Headers/opencl-c.h
===
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -15707,7 +15707,6 @@
 
 // OpenCL v2.0 s6.13.16 - Pipe Functions
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
-#define PIPE_RESERVE_ID_VALID_BIT (1U << 30)
 #define CLK_NULL_RESERVE_ID (__builtin_astype(((void*)(__SIZE_MAX__)), 
reserve_id_t))
 bool __ovld is_valid_reserve_id(reserve_id_t reserve_id);
 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0


Index: lib/Headers/opencl-c.h
===
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -15707,7 +15707,6 @@
 
 // OpenCL v2.0 s6.13.16 - Pipe Functions
 #if __OPENCL_C_VERSION__ >= CL_VERSION_2_0
-#define PIPE_RESERVE_ID_VALID_BIT (1U << 30)
 #define CLK_NULL_RESERVE_ID (__builtin_astype(((void*)(__SIZE_MAX__)), reserve_id_t))
 bool __ovld is_valid_reserve_id(reserve_id_t reserve_id);
 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_2_0
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51402: [OpenCL] Adding cl_intel_planar_yuv extension

2018-09-26 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added inline comments.



Comment at: lib/Headers/opencl-c.h:26
+#if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#ifndef cl_intel_planar_yuv
+#define cl_intel_planar_yuv

Anastasia wrote:
> Anastasia wrote:
> > @yaxunl, do you think we need to add some kind of architecture guard for 
> > such things? Like it should only be added if the architecture supports the 
> > extension? But I guess `-cl-ext=+cl_intel_planar_yuv` trick might not work 
> > here because it's not a Clang known extension?
> > 
> > So may be the right solution here is to introduce a target specific header? 
> > For now it can be explicitly included but we could think of a target hook 
> > to preload a target specific header...
> @sidorovd, I am wondering if we could instead extend 
> '-cl-ext=+cl_intel_planar_yuv' to work with non-builtin extensions? Would 
> that be an acceptable solution for vendor extensions to be added to the 
> common header?
Sorry for a long response.
I have covered a little study on how to enable extensions via adding them in 
clang, common header or without any changes (yeap, that is also a case) and how 
adding -cl-ext+ in the RUN string affects the test's (introduced in this patch, 
but with removed versioning) result. And found out that I don't understand how 
it works or it's supposed to work. Here is a result of my study: {F7312300}
 

|  Changes  | cl-ext+ | cl-ext- | no cl-ext |  
| opencl-c.hver  >=1.2 | defined, known, supported | defined, 
known, supported| defined, known, supported|
| opencl-c.h   ver < 1.2   | undefined, known, supported | undefined, 
unknown  | undefined, unknown  |  
| OpenCLExtensions.def  ver  >=1.2 | defined, known, supported |   
undefined, known, unsupported   |  defined, known, supported  |
| OpenCLExtensions.def  ver < 1.2   | undefined, known, unsupported | 
undefined, known, unsupported |undefined, known, unsupported |
| No changes  ver  >=1.2 | undefined, known, supported| undefined, unknown  
  | undefined, unknown |
| No changes  ver < 1.2| undefined, known, supported   | undefined, unknown 
| undefined, unknown|

So from my perspective there shouldn't be any difference between the result 
depending on an approach to use to enable an extension. But that is not how 
it's happening in reality, as an example see how values put in column #3 
differs for changes in opencl-c.h and OpenCLExtensions.def.
Or am I wrong?






https://reviews.llvm.org/D51402



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52292: [Sema][OpenCL] Improve diagnostics for not viable overloadable function candidates

2018-09-21 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 166425.
sidorovd added a comment.

getOpenCLExtensionsFromTypeExtMap was added


https://reviews.llvm.org/D52292

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaOverload.cpp
  test/SemaOpenCL/extension-begin.cl

Index: test/SemaOpenCL/extension-begin.cl
===
--- test/SemaOpenCL/extension-begin.cl
+++ test/SemaOpenCL/extension-begin.cl
@@ -48,7 +48,7 @@
   PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 'const struct A *') requires my_ext extension to be enabled}}
   f(); // expected-error {{use of declaration 'f' requires my_ext extension to be enabled}}
   g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@-26 {{candidate disabled due to OpenCL extension}}
+// expected-note@-26 {{candidate unavailable as it requires OpenCL extension 'my_ext' to be disabled}}
 // expected-note@-22 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
 }
 
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -10242,7 +10242,8 @@
   FunctionDecl *Callee = Cand->Function;
 
   S.Diag(Callee->getLocation(),
- diag::note_ovl_candidate_disabled_by_extension);
+ diag::note_ovl_candidate_disabled_by_extension)
+<< S.getOpenCLExtensionsFromDeclExtMap(Callee);
 }
 
 /// Generates a 'note' diagnostic for an overload candidate.  We've
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1853,6 +1853,34 @@
   setOpenCLExtensionForDecl(D, CurrOpenCLExtension);
 }
 
+std::string Sema::getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD) {
+  if (!OpenCLDeclExtMap.empty())
+return getOpenCLExtensionsFromExtMap(FD, OpenCLDeclExtMap);
+
+  return "";
+}
+
+std::string Sema::getOpenCLExtensionsFromTypeExtMap(FunctionType *FT) {
+  if (!OpenCLTypeExtMap.empty())
+return getOpenCLExtensionsFromExtMap(FT, OpenCLTypeExtMap);
+
+  return "";
+}
+
+template 
+std::string Sema::getOpenCLExtensionsFromExtMap(T *FDT, MapT ) {
+  std::string ExtensionNames = "";
+  auto Loc = Map.find(FDT);
+
+  for (auto const& I : Loc->second) {
+ExtensionNames += I;
+ExtensionNames += " ";
+  }
+  ExtensionNames.pop_back();
+
+  return ExtensionNames;
+}
+
 bool Sema::isOpenCLDisabledDecl(Decl *FD) {
   auto Loc = OpenCLDeclExtMap.find(FD);
   if (Loc == OpenCLDeclExtMap.end())
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -8567,6 +8567,21 @@
   llvm::StringRef getCurrentOpenCLExtension() const {
 return CurrOpenCLExtension;
   }
+
+  /// Check if a function declaration \p FD associates with any
+  /// extensions present in OpenCLDeclExtMap and if so return the
+  /// extension(s) name(s).
+  std::string getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD);
+
+  /// Check if a function type \p FT associates with any
+  /// extensions present in OpenCLTypeExtMap and if so return the
+  /// extension(s) name(s).
+  std::string getOpenCLExtensionsFromTypeExtMap(FunctionType *FT);
+
+  /// Find an extension in an appropriate extension map and return its name
+  template
+  std::string getOpenCLExtensionsFromExtMap(T* FT, MapT );
+
   void setCurrentOpenCLExtension(llvm::StringRef Ext) {
 CurrOpenCLExtension = Ext;
   }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -3652,7 +3652,7 @@
 def note_ovl_candidate_disabled_by_function_cond_attr : Note<
 "candidate disabled: %0">;
 def note_ovl_candidate_disabled_by_extension : Note<
-"candidate disabled due to OpenCL extension">;
+"candidate unavailable as it requires OpenCL extension '%0' to be disabled">;
 def err_addrof_function_disabled_by_enable_if_attr : Error<
 "cannot take address of function %0 because it has one or more "
 "non-tautological enable_if conditions">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52292: [Sema][OpenCL] Improve diagnostics for not viable overloadable function candidates

2018-09-20 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added inline comments.



Comment at: include/clang/Sema/Sema.h:8576
+
+  /// Find and extension in an extension map and return its name
+  template

Anastasia wrote:
> and extension -> an extension ?
Thanks!



Comment at: lib/Sema/Sema.cpp:1856
 
+std::string Sema::getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD) {
+  if (!OpenCLDeclExtMap.empty())

Anastasia wrote:
> Is this function to be used for both `OpenCLDeclExtMap` and 
> `OpenCLTypeExtMap`? If yes, may be we could give it more generic name like 
> 'getOpenCLExtensionsFromExtMap'...
No, this exact function is only for 'OpenCLDeclExtMap', for the type map one 
should implement a new function 'getOpenCLExtensionsFromTypeExtMap'. Actually I 
have done this for https://reviews.llvm.org/D51341 to make the patch more 
generic, but since I'm not sure if it ever came to light I can add it here 
unused.


https://reviews.llvm.org/D52292



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D52292: [Sema][OpenCL] Improve diagnostics for not viable overloadable function candidates

2018-09-20 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 166270.
sidorovd marked an inline comment as done.

https://reviews.llvm.org/D52292

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaOverload.cpp
  test/SemaOpenCL/extension-begin.cl


Index: test/SemaOpenCL/extension-begin.cl
===
--- test/SemaOpenCL/extension-begin.cl
+++ test/SemaOpenCL/extension-begin.cl
@@ -48,7 +48,7 @@
   PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 
'const struct A *') requires my_ext extension to be enabled}}
   f(); // expected-error {{use of declaration 'f' requires my_ext extension to 
be enabled}}
   g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@-26 {{candidate disabled due to OpenCL extension}}
+// expected-note@-26 {{candidate unavailable as it requires OpenCL 
extension 'my_ext' to be disabled}}
 // expected-note@-22 {{candidate function not viable: requires 0 
arguments, but 1 was provided}}
 }
 
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -10242,7 +10242,8 @@
   FunctionDecl *Callee = Cand->Function;
 
   S.Diag(Callee->getLocation(),
- diag::note_ovl_candidate_disabled_by_extension);
+ diag::note_ovl_candidate_disabled_by_extension)
+<< S.getOpenCLExtensionsFromDeclExtMap(Callee);
 }
 
 /// Generates a 'note' diagnostic for an overload candidate.  We've
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1853,6 +1853,27 @@
   setOpenCLExtensionForDecl(D, CurrOpenCLExtension);
 }
 
+std::string Sema::getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD) {
+  if (!OpenCLDeclExtMap.empty())
+return getOpenCLExtensionsFromExtMap(FD, OpenCLDeclExtMap);
+
+  return "";
+}
+
+template 
+std::string Sema::getOpenCLExtensionsFromExtMap(T *FDT, MapT ) {
+  std::string ExtensionNames = "";
+  auto Loc = Map.find(FDT);
+
+  for (auto const& I : Loc->second) {
+ExtensionNames += I;
+ExtensionNames += " ";
+  }
+  ExtensionNames.pop_back();
+
+  return ExtensionNames;
+}
+
 bool Sema::isOpenCLDisabledDecl(Decl *FD) {
   auto Loc = OpenCLDeclExtMap.find(FD);
   if (Loc == OpenCLDeclExtMap.end())
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -8567,6 +8567,16 @@
   llvm::StringRef getCurrentOpenCLExtension() const {
 return CurrOpenCLExtension;
   }
+
+  /// Check if a function declaration \p FD associates with any
+  /// extensions present in OpenCLDeclExtMap and if so return the
+  /// extension(s) name(s).
+  std::string getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD);
+
+  /// Find an extension in appropriate extension map and return its name
+  template
+  std::string getOpenCLExtensionsFromExtMap(T* FT, MapT );
+
   void setCurrentOpenCLExtension(llvm::StringRef Ext) {
 CurrOpenCLExtension = Ext;
   }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -3652,7 +3652,7 @@
 def note_ovl_candidate_disabled_by_function_cond_attr : Note<
 "candidate disabled: %0">;
 def note_ovl_candidate_disabled_by_extension : Note<
-"candidate disabled due to OpenCL extension">;
+"candidate unavailable as it requires OpenCL extension '%0' to be 
disabled">;
 def err_addrof_function_disabled_by_enable_if_attr : Error<
 "cannot take address of function %0 because it has one or more "
 "non-tautological enable_if conditions">;


Index: test/SemaOpenCL/extension-begin.cl
===
--- test/SemaOpenCL/extension-begin.cl
+++ test/SemaOpenCL/extension-begin.cl
@@ -48,7 +48,7 @@
   PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 'const struct A *') requires my_ext extension to be enabled}}
   f(); // expected-error {{use of declaration 'f' requires my_ext extension to be enabled}}
   g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@-26 {{candidate disabled due to OpenCL extension}}
+// expected-note@-26 {{candidate unavailable as it requires OpenCL extension 'my_ext' to be disabled}}
 // expected-note@-22 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
 }
 
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -10242,7 +10242,8 @@
   FunctionDecl *Callee = Cand->Function;
 
   S.Diag(Callee->getLocation(),
- 

[PATCH] D52292: [Sema][OpenCL] Improve diagnostics for not viable overloadable function candidates

2018-09-20 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd created this revision.
sidorovd added reviewers: Anastasia, yaxunl.
Herald added a subscriber: cfe-commits.

Allowed extension name (that ought to be disabled) printing in the note message.

This diagnostic was proposed here: https://reviews.llvm.org/D51341


Repository:
  rC Clang

https://reviews.llvm.org/D52292

Files:
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Sema/Sema.h
  lib/Sema/Sema.cpp
  lib/Sema/SemaOverload.cpp
  test/SemaOpenCL/extension-begin.cl


Index: test/SemaOpenCL/extension-begin.cl
===
--- test/SemaOpenCL/extension-begin.cl
+++ test/SemaOpenCL/extension-begin.cl
@@ -48,7 +48,7 @@
   PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 
'const struct A *') requires my_ext extension to be enabled}}
   f(); // expected-error {{use of declaration 'f' requires my_ext extension to 
be enabled}}
   g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@-26 {{candidate disabled due to OpenCL extension}}
+// expected-note@-26 {{candidate unavailable as it requires OpenCL 
extension 'my_ext' to be disabled}}
 // expected-note@-22 {{candidate function not viable: requires 0 
arguments, but 1 was provided}}
 }
 
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -10242,7 +10242,8 @@
   FunctionDecl *Callee = Cand->Function;
 
   S.Diag(Callee->getLocation(),
- diag::note_ovl_candidate_disabled_by_extension);
+ diag::note_ovl_candidate_disabled_by_extension)
+<< S.getOpenCLExtensionsFromDeclExtMap(Callee);
 }
 
 /// Generates a 'note' diagnostic for an overload candidate.  We've
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -1853,6 +1853,27 @@
   setOpenCLExtensionForDecl(D, CurrOpenCLExtension);
 }
 
+std::string Sema::getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD) {
+  if (!OpenCLDeclExtMap.empty())
+return getOpenCLExtensionsFromExtMap(FD, OpenCLDeclExtMap);
+
+  return "";
+}
+
+template 
+std::string Sema::getOpenCLExtensionsFromExtMap(T *FDT, MapT ) {
+  std::string ExtensionNames = "";
+  auto Loc = Map.find(FDT);
+
+  for (auto const& I : Loc->second) {
+ExtensionNames += I;
+ExtensionNames += " ";
+  }
+  ExtensionNames.pop_back();
+
+  return ExtensionNames;
+}
+
 bool Sema::isOpenCLDisabledDecl(Decl *FD) {
   auto Loc = OpenCLDeclExtMap.find(FD);
   if (Loc == OpenCLDeclExtMap.end())
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -8567,6 +8567,16 @@
   llvm::StringRef getCurrentOpenCLExtension() const {
 return CurrOpenCLExtension;
   }
+
+  /// Check if a function declaration \p FD associates with any
+  /// extensions present in OpenCLDeclExtMap and if so return the
+  /// extension(s) name(s).
+  std::string getOpenCLExtensionsFromDeclExtMap(FunctionDecl *FD);
+
+  /// Find and extension in an extension map and return its name
+  template
+  std::string getOpenCLExtensionsFromExtMap(T* FT, MapT );
+
   void setCurrentOpenCLExtension(llvm::StringRef Ext) {
 CurrOpenCLExtension = Ext;
   }
Index: include/clang/Basic/DiagnosticSemaKinds.td
===
--- include/clang/Basic/DiagnosticSemaKinds.td
+++ include/clang/Basic/DiagnosticSemaKinds.td
@@ -3652,7 +3652,7 @@
 def note_ovl_candidate_disabled_by_function_cond_attr : Note<
 "candidate disabled: %0">;
 def note_ovl_candidate_disabled_by_extension : Note<
-"candidate disabled due to OpenCL extension">;
+"candidate unavailable as it requires OpenCL extension '%0' to be 
disabled">;
 def err_addrof_function_disabled_by_enable_if_attr : Error<
 "cannot take address of function %0 because it has one or more "
 "non-tautological enable_if conditions">;


Index: test/SemaOpenCL/extension-begin.cl
===
--- test/SemaOpenCL/extension-begin.cl
+++ test/SemaOpenCL/extension-begin.cl
@@ -48,7 +48,7 @@
   PointerOfA test_A_pointer; // expected-error {{use of type 'PointerOfA' (aka 'const struct A *') requires my_ext extension to be enabled}}
   f(); // expected-error {{use of declaration 'f' requires my_ext extension to be enabled}}
   g(0); // expected-error {{no matching function for call to 'g'}}
-// expected-note@-26 {{candidate disabled due to OpenCL extension}}
+// expected-note@-26 {{candidate unavailable as it requires OpenCL extension 'my_ext' to be disabled}}
 // expected-note@-22 {{candidate function not viable: requires 0 arguments, but 1 was provided}}
 }
 
Index: lib/Sema/SemaOverload.cpp

[PATCH] D51341: [HEADER] Overloadable function candidates for half/double types

2018-09-17 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added a comment.

For now this patch is on hold since it adds no new functionality. Its future 
will be decided after @asavonic finished https://reviews.llvm.org/D51544


https://reviews.llvm.org/D51341



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51722: [OpenCL] Allow blocks to capture arrays in OpenCL

2018-09-06 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 164214.
sidorovd added a comment.

Reference to the Spec was added


https://reviews.llvm.org/D51722

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/block-array-capturing.cl


Index: test/SemaOpenCL/block-array-capturing.cl
===
--- /dev/null
+++ test/SemaOpenCL/block-array-capturing.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm 
%s -o -| FileCheck %s
+// expected-no-diagnostics
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+  // CHECK: %{{.*}} = alloca <{ i32, i32, [3 x i32] }>
+  int a[3] = {1, 2, 3};
+  // CHECK: call void @llvm.memcpy{{.*}}
+  block_t b = ^() { return a[0]; };
+  return b();
+}
+
+// CHECK: define {{.*}} @__block_typedef_kernel_block_invoke
+// CHECK: %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32] addrspace(4)* 
%{{.*}}, i64 0, i64 0
+// CHECK-NOT: call void @llvm.memcpy{{.*}}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14624,8 +14624,10 @@
   Expr *CopyExpr = nullptr;
   bool ByRef = false;
 
-  // Blocks are not allowed to capture arrays.
-  if (CaptureType->isArrayType()) {
+  // Blocks are not allowed to capture arrays, excepting OpenCL.
+  // OpenCL v2.0 s1.12.5 (revision 40): arrays are captured by reference
+  // (decayed to pointers).
+  if (!S.getLangOpts().OpenCL && CaptureType->isArrayType()) {
 if (BuildAndDiagnose) {
   S.Diag(Loc, diag::err_ref_array_type);
   S.Diag(Var->getLocation(), diag::note_previous_decl)


Index: test/SemaOpenCL/block-array-capturing.cl
===
--- /dev/null
+++ test/SemaOpenCL/block-array-capturing.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm %s -o -| FileCheck %s
+// expected-no-diagnostics
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+  // CHECK: %{{.*}} = alloca <{ i32, i32, [3 x i32] }>
+  int a[3] = {1, 2, 3};
+  // CHECK: call void @llvm.memcpy{{.*}}
+  block_t b = ^() { return a[0]; };
+  return b();
+}
+
+// CHECK: define {{.*}} @__block_typedef_kernel_block_invoke
+// CHECK: %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32] addrspace(4)* %{{.*}}, i64 0, i64 0
+// CHECK-NOT: call void @llvm.memcpy{{.*}}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14624,8 +14624,10 @@
   Expr *CopyExpr = nullptr;
   bool ByRef = false;
 
-  // Blocks are not allowed to capture arrays.
-  if (CaptureType->isArrayType()) {
+  // Blocks are not allowed to capture arrays, excepting OpenCL.
+  // OpenCL v2.0 s1.12.5 (revision 40): arrays are captured by reference
+  // (decayed to pointers).
+  if (!S.getLangOpts().OpenCL && CaptureType->isArrayType()) {
 if (BuildAndDiagnose) {
   S.Diag(Loc, diag::err_ref_array_type);
   S.Diag(Var->getLocation(), diag::note_previous_decl)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51341: [HEADER] Overloadable function candidates for half/double types

2018-09-06 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 164169.
sidorovd edited the summary of this revision.

https://reviews.llvm.org/D51341

Files:
  include/clang/AST/Type.h
  lib/AST/Type.cpp
  lib/Sema/SemaOverload.cpp
  test/SemaOpenCL/half-double-overload.cl


Index: test/SemaOpenCL/half-double-overload.cl
===
--- /dev/null
+++ test/SemaOpenCL/half-double-overload.cl
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+
+float __attribute__((overloadable)) foo(float in1, float in2);
+int __attribute__((overloadable)) goo(float in1, float in2);
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo(half in1, half in2);
+half __attribute__((overloadable)) goo(double in1, double in2);
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi(int x, int y) {
+  foo(x, y);
+  goo(x, y);
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo_err(half in1, half in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+float __attribute__((overloadable)) foo_err(half in1, int in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi_err(int x, int y) {
+  foo_err(x, y);
+  // expected-error@-1 {{no matching function for call to 'foo_err'}}
+}
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -6059,6 +6059,33 @@
 return;
   }
 
+  // OpenCL: A candidate function that uses extentions that are not enabled or
+  // supported is not viable.
+  if (getLangOpts().OpenCL) {
+bool HasHalf =
+  getOpenCLOptions().isSupported("cl_khr_fp16", 
getLangOpts().OpenCLVersion)
+  && getOpenCLOptions().isEnabled("cl_khr_fp16");
+bool HasDouble =
+  getOpenCLOptions().isSupported("cl_khr_fp64", 
getLangOpts().OpenCLVersion)
+  && getOpenCLOptions().isEnabled("cl_khr_fp64");
+
+if ((!HasHalf && Function->getReturnType()->isHalfType()) ||
+(!HasDouble && Function->getReturnType()->isDoubleType())) {
+  Candidate.Viable = false;
+  Candidate.FailureKind = ovl_fail_ext_disabled;
+  return;
+}
+for (const auto *PI : Function->parameters()) {
+  QualType PTy = PI->getType();
+  if ((!HasHalf && PTy->isHalfType()) ||
+  (!HasDouble && PTy->isDoubleType())) {
+Candidate.Viable = false;
+Candidate.FailureKind = ovl_fail_ext_disabled;
+return;
+  }
+}
+  }
+
   // (CUDA B.1): Check for invalid calls between targets.
   if (getLangOpts().CUDA)
 if (const FunctionDecl *Caller = dyn_cast(CurContext))
Index: lib/AST/Type.cpp
===
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -1919,6 +1919,13 @@
   return false;
 }
 
+bool Type::isDoubleType() const {
+  if (const BuiltinType *BT = dyn_cast(CanonicalType))
+return BT->getKind() >= BuiltinType::Double &&
+  BT->getKind() <= BuiltinType::LongDouble;
+  return false;
+}
+
 bool Type::hasFloatingRepresentation() const {
   if (const auto *VT = dyn_cast(CanonicalType))
 return VT->getElementType()->isFloatingType();
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -1924,6 +1924,7 @@
   bool isAggregateType() const;
   bool isFundamentalType() const;
   bool isCompoundType() const;
+  bool isDoubleType() const;   // (double + long double)
 
   // Type Predicates: Check to see if this type is structurally the specified
   // type, ignoring typedefs and qualifiers.


Index: test/SemaOpenCL/half-double-overload.cl
===
--- /dev/null
+++ test/SemaOpenCL/half-double-overload.cl
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+
+float __attribute__((overloadable)) foo(float in1, float in2);
+int __attribute__((overloadable)) goo(float in1, float in2);
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo(half in1, half in2);
+half __attribute__((overloadable)) goo(double in1, double in2);
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi(int x, int y) {
+  foo(x, y);
+  goo(x, y);
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo_err(half in1, half in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+float __attribute__((overloadable)) foo_err(half in1, int in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi_err(int x, int y) {
+  foo_err(x, y);
+  // expected-error@-1 {{no matching function for call to 'foo_err'}}
+}
Index: 

[PATCH] D51341: [HEADER] Overloadable function candidates for half/double types

2018-09-06 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd marked an inline comment as done.
sidorovd added inline comments.



Comment at: lib/Sema/SemaOverload.cpp:6063
+  // OpenCL: A candidate function that uses extentions that are not enabled or
+  // supported is not viable.
+  if (getLangOpts().OpenCL) {

Anastasia wrote:
> I would imagine if extension isn't supported the candidate function with data 
> type defined by extension shouldn't be available at all during compilation?
> 
> Also is there any good way to generalize this for all types and extensions 
> including vendor ones that are added with the pragmas?
> https://clang.llvm.org/docs/UsersManual.html#opencl-extensions
> I would imagine if extension isn't supported the candidate function with data 
> type defined by extension shouldn't be available at all during compilation?

Yes, you are right.

> Also is there any good way to generalize this for all types and extensions 
> including vendor ones that are added with the pragmas?
https://clang.llvm.org/docs/UsersManual.html#opencl-extensions

There might be a way but I can't properly answer this question right now. By 
default types and extensions aren't associated to each other.



Comment at: test/SemaOpenCL/half-double-overload.cl:18
+float __attribute__((overloadable)) foo_err(half in1, half in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+float __attribute__((overloadable)) foo_err(half in1, int in2);

Anastasia wrote:
> Wondering if better message could be:
>   candidate unavailable as it requires OpenCL extension to be disabled
> 
> Could it also print the extension name?
Sounds good. And I'd prefer to split it into another patch, because it would 
affect unrelated to the change tests and also require changes in Sema to allow 
extension name printing. 


https://reviews.llvm.org/D51341



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51722: [OpenCL] Allow blocks to capture arrays in OpenCL

2018-09-06 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd created this revision.
sidorovd added reviewers: Anastasia, yaxunl.
Herald added a subscriber: cfe-commits.
sidorovd added a comment.

Previously this patch was reviewed here: https://reviews.llvm.org/D26794 . I 
wasn't able to update it, so I created a new one with the comments applied.


Patch by Egor Churaev


Repository:
  rC Clang

https://reviews.llvm.org/D51722

Files:
  lib/Sema/SemaExpr.cpp
  test/SemaOpenCL/block-array-capturing.cl


Index: test/SemaOpenCL/block-array-capturing.cl
===
--- /dev/null
+++ test/SemaOpenCL/block-array-capturing.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm 
%s -o -| FileCheck %s
+// expected-no-diagnostics
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+  // CHECK: %{{.*}} = alloca <{ i32, i32, [3 x i32] }>
+  int a[3] = {1, 2, 3};
+  // CHECK: call void @llvm.memcpy{{.*}}
+  block_t b = ^() { return a[0]; };
+  return b();
+}
+
+// CHECK: define {{.*}} @__block_typedef_kernel_block_invoke
+// CHECK: %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32] addrspace(4)* 
%{{.*}}, i64 0, i64 0
+// CHECK-NOT: call void @llvm.memcpy{{.*}}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14624,8 +14624,8 @@
   Expr *CopyExpr = nullptr;
   bool ByRef = false;
 
-  // Blocks are not allowed to capture arrays.
-  if (CaptureType->isArrayType()) {
+  // Blocks are not allowed to capture arrays, excepting OpenCL.
+  if (!S.getLangOpts().OpenCL && CaptureType->isArrayType()) {
 if (BuildAndDiagnose) {
   S.Diag(Loc, diag::err_ref_array_type);
   S.Diag(Var->getLocation(), diag::note_previous_decl)


Index: test/SemaOpenCL/block-array-capturing.cl
===
--- /dev/null
+++ test/SemaOpenCL/block-array-capturing.cl
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple spir64-unkown-unkown -emit-llvm %s -o -| FileCheck %s
+// expected-no-diagnostics
+
+typedef int (^block_t)();
+
+int block_typedef_kernel(global int* res) {
+  // CHECK: %{{.*}} = alloca <{ i32, i32, [3 x i32] }>
+  int a[3] = {1, 2, 3};
+  // CHECK: call void @llvm.memcpy{{.*}}
+  block_t b = ^() { return a[0]; };
+  return b();
+}
+
+// CHECK: define {{.*}} @__block_typedef_kernel_block_invoke
+// CHECK: %{{.*}} = getelementptr inbounds [3 x i32], [3 x i32] addrspace(4)* %{{.*}}, i64 0, i64 0
+// CHECK-NOT: call void @llvm.memcpy{{.*}}
Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -14624,8 +14624,8 @@
   Expr *CopyExpr = nullptr;
   bool ByRef = false;
 
-  // Blocks are not allowed to capture arrays.
-  if (CaptureType->isArrayType()) {
+  // Blocks are not allowed to capture arrays, excepting OpenCL.
+  if (!S.getLangOpts().OpenCL && CaptureType->isArrayType()) {
 if (BuildAndDiagnose) {
   S.Diag(Loc, diag::err_ref_array_type);
   S.Diag(Var->getLocation(), diag::note_previous_decl)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51722: [OpenCL] Allow blocks to capture arrays in OpenCL

2018-09-06 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd added a comment.

Previously this patch was reviewed here: https://reviews.llvm.org/D26794 . I 
wasn't able to update it, so I created a new one with the comments applied.


Repository:
  rC Clang

https://reviews.llvm.org/D51722



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51402: [OpenCL] Adding cl_intel_planar_yuv extension

2018-09-06 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 164157.
sidorovd added a comment.

I'm not sure if I put pragmas in an appropriate place (I mean in the very 
beginning of the header).


https://reviews.llvm.org/D51402

Files:
  lib/Headers/opencl-c.h
  test/SemaOpenCL/extension-version.cl


Index: test/SemaOpenCL/extension-version.cl
===
--- test/SemaOpenCL/extension-version.cl
+++ test/SemaOpenCL/extension-version.cl
@@ -1,11 +1,11 @@
-// RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple spir-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple spir-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple spir-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple spir-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple spir-unknown-unknown 
-Wpedantic-core-features -DTEST_CORE_FEATURES
-// RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple spir-unknown-unknown 
-Wpedantic-core-features -DTEST_CORE_FEATURES
-// RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple spir-unknown-unknown 
-Wpedantic-core-features -DTEST_CORE_FEATURES
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple spir-unknown-unknown 
-Wpedantic-core-features -DTEST_CORE_FEATURES
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL %s -verify 
-triple spir-unknown-unknown
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL1.1 %s -verify 
-triple spir-unknown-unknown
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL1.2 %s -verify 
-triple spir-unknown-unknown
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL2.0 %s -verify 
-triple spir-unknown-unknown
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL %s -verify 
-triple spir-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL1.1 %s -verify 
-triple spir-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL1.2 %s -verify 
-triple spir-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL2.0 %s -verify 
-triple spir-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
 
 #if __OPENCL_C_VERSION__ >= 200 && ! defined TEST_CORE_FEATURES
 // expected-no-diagnostics
@@ -300,3 +300,11 @@
 #endif
 #pragma OPENCL EXTENSION cl_intel_subgroups_short : enable
 
+#if (__OPENCL_C_VERSION__ >= 120)
+#ifndef cl_intel_planar_yuv
+#error "Missing cl_intel_planar_yuv define"
+#endif
+#else
+// expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
+#endif
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
Index: lib/Headers/opencl-c.h
===
--- lib/Headers/opencl-c.h
+++ lib/Headers/opencl-c.h
@@ -22,6 +22,14 @@
 #endif //cl_khr_3d_image_writes
 #endif //__OPENCL_C_VERSION__ < CL_VERSION_2_0
 
+#if __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+#ifndef cl_intel_planar_yuv
+#define cl_intel_planar_yuv
+#endif // cl_intel_planar_yuv
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : begin
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : end
+#endif // __OPENCL_C_VERSION__ >= CL_VERSION_1_2
+
 #define __ovld __attribute__((overloadable))
 #define __conv __attribute__((convergent))
 


Index: test/SemaOpenCL/extension-version.cl
===
--- test/SemaOpenCL/extension-version.cl
+++ test/SemaOpenCL/extension-version.cl
@@ -1,11 +1,11 @@
-// RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple spir-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple spir-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple spir-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple spir-unknown-unknown
-// RUN: %clang_cc1 -x cl -cl-std=CL %s -verify -triple spir-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
-// RUN: %clang_cc1 -x cl -cl-std=CL1.1 %s -verify -triple spir-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
-// RUN: %clang_cc1 -x cl -cl-std=CL1.2 %s -verify -triple spir-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
-// RUN: %clang_cc1 -x cl -cl-std=CL2.0 %s -verify -triple spir-unknown-unknown -Wpedantic-core-features -DTEST_CORE_FEATURES
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL %s -verify -triple spir-unknown-unknown
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL1.1 %s -verify -triple spir-unknown-unknown
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL1.2 %s -verify -triple spir-unknown-unknown
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL2.0 %s -verify -triple spir-unknown-unknown
+// RUN: %clang_cc1 -x cl -finclude-default-header -cl-std=CL %s -verify -triple spir-unknown-unknown 

[PATCH] D51402: [OpenCL] Adding cl_intel_planar_yuv extension

2018-08-29 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd created this revision.
sidorovd added reviewers: yaxunl, Anastasia.
Herald added a subscriber: cfe-commits.

Just adding a preprocessor #define for the extension.

Patch by Alexey Sotkin


Repository:
  rC Clang

https://reviews.llvm.org/D51402

Files:
  include/clang/Basic/OpenCLExtensions.def
  test/SemaOpenCL/extension-version.cl


Index: test/SemaOpenCL/extension-version.cl
===
--- test/SemaOpenCL/extension-version.cl
+++ test/SemaOpenCL/extension-version.cl
@@ -300,3 +300,11 @@
 #endif
 #pragma OPENCL EXTENSION cl_intel_subgroups_short : enable
 
+#if (__OPENCL_C_VERSION__ >= 120)
+#ifndef cl_intel_planar_yuv
+#error "Missing cl_intel_planar_yuv define"
+#endif
+#else
+// expected-warning@+2{{unsupported OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
+#endif
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
Index: include/clang/Basic/OpenCLExtensions.def
===
--- include/clang/Basic/OpenCLExtensions.def
+++ include/clang/Basic/OpenCLExtensions.def
@@ -85,6 +85,7 @@
 // Intel OpenCL extensions
 OPENCLEXT_INTERNAL(cl_intel_subgroups, 120, ~0U)
 OPENCLEXT_INTERNAL(cl_intel_subgroups_short, 120, ~0U)
+OPENCLEXT_INTERNAL(cl_intel_planar_yuv, 120, ~0U)
 
 #undef OPENCLEXT_INTERNAL
 


Index: test/SemaOpenCL/extension-version.cl
===
--- test/SemaOpenCL/extension-version.cl
+++ test/SemaOpenCL/extension-version.cl
@@ -300,3 +300,11 @@
 #endif
 #pragma OPENCL EXTENSION cl_intel_subgroups_short : enable
 
+#if (__OPENCL_C_VERSION__ >= 120)
+#ifndef cl_intel_planar_yuv
+#error "Missing cl_intel_planar_yuv define"
+#endif
+#else
+// expected-warning@+2{{unsupported OpenCL extension 'cl_intel_planar_yuv' - ignoring}}
+#endif
+#pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
Index: include/clang/Basic/OpenCLExtensions.def
===
--- include/clang/Basic/OpenCLExtensions.def
+++ include/clang/Basic/OpenCLExtensions.def
@@ -85,6 +85,7 @@
 // Intel OpenCL extensions
 OPENCLEXT_INTERNAL(cl_intel_subgroups, 120, ~0U)
 OPENCLEXT_INTERNAL(cl_intel_subgroups_short, 120, ~0U)
+OPENCLEXT_INTERNAL(cl_intel_planar_yuv, 120, ~0U)
 
 #undef OPENCLEXT_INTERNAL
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D51341: [HEADER] Overloadable function candidates for half/double types

2018-08-28 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd updated this revision to Diff 162812.

https://reviews.llvm.org/D51341

Files:
  include/clang/AST/Type.h
  lib/AST/Type.cpp
  lib/Sema/SemaOverload.cpp
  test/SemaOpenCL/half-double-overload.cl


Index: test/SemaOpenCL/half-double-overload.cl
===
--- /dev/null
+++ test/SemaOpenCL/half-double-overload.cl
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo(float in1, float in2);
+float __attribute__((overloadable)) foo(half in1, half in2);
+
+int __attribute__((overloadable)) goo(float in1, float in2);
+half __attribute__((overloadable)) goo(double in1, double in2);
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi(int x, int y) {
+  foo(x, y);
+  goo(x, y);
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo_err(half in1, half in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+float __attribute__((overloadable)) foo_err(half in1, int in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi_err(int x, int y) {
+  foo_err(x, y);
+  // expected-error@-1 {{no matching function for call to 'foo_err'}}
+}
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -6059,6 +6059,33 @@
 return;
   }
 
+  // OpenCL: A candidate function that uses extentions that are not enabled or
+  // supported is not viable.
+  if (getLangOpts().OpenCL) {
+bool HasHalf =
+  getOpenCLOptions().isSupported("cl_khr_fp16", 
getLangOpts().OpenCLVersion)
+  && getOpenCLOptions().isEnabled("cl_khr_fp16");
+bool HasDouble =
+  getOpenCLOptions().isSupported("cl_khr_fp64", 
getLangOpts().OpenCLVersion)
+  && getOpenCLOptions().isEnabled("cl_khr_fp64");
+
+if ((!HasHalf && Function->getReturnType()->isHalfType()) ||
+(!HasDouble && Function->getReturnType()->isDoubleType())) {
+  Candidate.Viable = false;
+  Candidate.FailureKind = ovl_fail_ext_disabled;
+  return;
+}
+for (const auto *PI : Function->parameters()) {
+  QualType PTy = PI->getType();
+  if ((!HasHalf && PTy->isHalfType()) ||
+  (!HasDouble && PTy->isDoubleType())) {
+Candidate.Viable = false;
+Candidate.FailureKind = ovl_fail_ext_disabled;
+return;
+  }
+}
+  }
+
   // (CUDA B.1): Check for invalid calls between targets.
   if (getLangOpts().CUDA)
 if (const FunctionDecl *Caller = dyn_cast(CurContext))
Index: lib/AST/Type.cpp
===
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -1919,6 +1919,13 @@
   return false;
 }
 
+bool Type::isDoubleType() const {
+  if (const BuiltinType *BT = dyn_cast(CanonicalType))
+return BT->getKind() >= BuiltinType::Double &&
+  BT->getKind() <= BuiltinType::LongDouble;
+  return false;
+}
+
 bool Type::hasFloatingRepresentation() const {
   if (const auto *VT = dyn_cast(CanonicalType))
 return VT->getElementType()->isFloatingType();
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -1924,6 +1924,7 @@
   bool isAggregateType() const;
   bool isFundamentalType() const;
   bool isCompoundType() const;
+  bool isDoubleType() const;   // (double + long double)
 
   // Type Predicates: Check to see if this type is structurally the specified
   // type, ignoring typedefs and qualifiers.


Index: test/SemaOpenCL/half-double-overload.cl
===
--- /dev/null
+++ test/SemaOpenCL/half-double-overload.cl
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo(float in1, float in2);
+float __attribute__((overloadable)) foo(half in1, half in2);
+
+int __attribute__((overloadable)) goo(float in1, float in2);
+half __attribute__((overloadable)) goo(double in1, double in2);
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi(int x, int y) {
+  foo(x, y);
+  goo(x, y);
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo_err(half in1, half in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+float __attribute__((overloadable)) foo_err(half in1, int in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi_err(int x, int y) {
+  foo_err(x, y);
+  // expected-error@-1 {{no matching function for call to 'foo_err'}}
+}
Index: lib/Sema/SemaOverload.cpp

[PATCH] D51341: [HEADER] Overloadable function candidates for half/double types

2018-08-28 Thread Dmitry Sidorov via Phabricator via cfe-commits
sidorovd created this revision.
sidorovd added reviewers: yaxunl, Anastasia.
Herald added a subscriber: cfe-commits.

Overloadable function candidate should not be viable if it uses extensions 
(Half or Double type) that are not enabled or supported.


Repository:
  rC Clang

https://reviews.llvm.org/D51341

Files:
  include/clang/AST/Type.h
  lib/AST/Type.cpp
  lib/Sema/SemaOverload.cpp
  test/SemaOpenCL/intel-half-double-overload.cl


Index: test/SemaOpenCL/intel-half-double-overload.cl
===
--- /dev/null
+++ test/SemaOpenCL/intel-half-double-overload.cl
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo(float in1, float in2);
+float __attribute__((overloadable)) foo(half in1, half in2);
+
+int __attribute__((overloadable)) goo(float in1, float in2);
+half __attribute__((overloadable)) goo(double in1, double in2);
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi(int x, int y) {
+  foo(x, y);
+  goo(x, y);
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo_err(half in1, half in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+float __attribute__((overloadable)) foo_err(half in1, int in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi_err(int x, int y) {
+  foo_err(x, y);
+  // expected-error@-1 {{no matching function for call to 'foo_err'}}
+}
Index: lib/Sema/SemaOverload.cpp
===
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -6059,6 +6059,33 @@
 return;
   }
 
+  // OpenCL: A candidate function that uses extentions that are not enabled or
+  // supported is not viable.
+  if (getLangOpts().OpenCL) {
+bool HasHalf =
+  getOpenCLOptions().isSupported("cl_khr_fp16", 
getLangOpts().OpenCLVersion)
+  && getOpenCLOptions().isEnabled("cl_khr_fp16");
+bool HasDouble =
+  getOpenCLOptions().isSupported("cl_khr_fp64", 
getLangOpts().OpenCLVersion)
+  && getOpenCLOptions().isEnabled("cl_khr_fp64");
+
+if ((!HasHalf && Function->getReturnType()->isHalfType()) ||
+(!HasDouble && Function->getReturnType()->isDoubleType())) {
+  Candidate.Viable = false;
+  Candidate.FailureKind = ovl_fail_ext_disabled;
+  return;
+}
+for (const auto *PI : Function->parameters()) {
+  QualType PTy = PI->getType();
+  if ((!HasHalf && PTy->isHalfType()) ||
+  (!HasDouble && PTy->isDoubleType())) {
+Candidate.Viable = false;
+Candidate.FailureKind = ovl_fail_ext_disabled;
+return;
+  }
+}
+  }
+
   // (CUDA B.1): Check for invalid calls between targets.
   if (getLangOpts().CUDA)
 if (const FunctionDecl *Caller = dyn_cast(CurContext))
Index: lib/AST/Type.cpp
===
--- lib/AST/Type.cpp
+++ lib/AST/Type.cpp
@@ -1919,6 +1919,13 @@
   return false;
 }
 
+bool Type::isDoubleType() const {
+  if (const BuiltinType *BT = dyn_cast(CanonicalType))
+return BT->getKind() >= BuiltinType::Double &&
+  BT->getKind() <= BuiltinType::LongDouble;
+  return false;
+}
+
 bool Type::hasFloatingRepresentation() const {
   if (const auto *VT = dyn_cast(CanonicalType))
 return VT->getElementType()->isFloatingType();
Index: include/clang/AST/Type.h
===
--- include/clang/AST/Type.h
+++ include/clang/AST/Type.h
@@ -1924,6 +1924,7 @@
   bool isAggregateType() const;
   bool isFundamentalType() const;
   bool isCompoundType() const;
+  bool isDoubleType() const;   // (double + long double)
 
   // Type Predicates: Check to see if this type is structurally the specified
   // type, ignoring typedefs and qualifiers.


Index: test/SemaOpenCL/intel-half-double-overload.cl
===
--- /dev/null
+++ test/SemaOpenCL/intel-half-double-overload.cl
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL1.2
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo(float in1, float in2);
+float __attribute__((overloadable)) foo(half in1, half in2);
+
+int __attribute__((overloadable)) goo(float in1, float in2);
+half __attribute__((overloadable)) goo(double in1, double in2);
+#pragma OPENCL EXTENSION cl_khr_fp16 : disable
+
+__kernel void vi(int x, int y) {
+  foo(x, y);
+  goo(x, y);
+}
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+float __attribute__((overloadable)) foo_err(half in1, half in2);
+// expected-note@-1 {{candidate disabled due to OpenCL extension}}
+float __attribute__((overloadable)) foo_err(half in1, int in2);
+// expected-note@-1 {{candidate disabled due