r310477 - [OpenCL] Minor refactoring to reduce copy/pasted code

2017-08-09 Thread Joey Gouly via cfe-commits
Author: joey
Date: Wed Aug  9 07:52:47 2017
New Revision: 310477

URL: http://llvm.org/viewvc/llvm-project?rev=310477=rev
Log:
[OpenCL] Minor refactoring to reduce copy/pasted code

Set the type of TheCall inside SemaBuiltinReserveRWPipe to reduce
duplicated code.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=310477=310476=310477=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Aug  9 07:52:47 2017
@@ -683,6 +683,11 @@ static bool SemaBuiltinReserveRWPipe(Sem
 return true;
   }
 
+  // Since return type of reserve_read/write_pipe built-in function is
+  // reserve_id_t, which is not defined in the builtin def file , we used int
+  // as return type and need to override the return type of these functions.
+  Call->setType(S.Context.OCLReserveIDTy);
+
   return false;
 }
 
@@ -1086,20 +1091,12 @@ Sema::CheckBuiltinFunctionCall(FunctionD
   case Builtin::BIwork_group_reserve_write_pipe:
 if (SemaBuiltinReserveRWPipe(*this, TheCall))
   return ExprError();
-// Since return type of reserve_read/write_pipe built-in function is
-// reserve_id_t, which is not defined in the builtin def file , we used int
-// as return type and need to override the return type of these functions.
-TheCall->setType(Context.OCLReserveIDTy);
 break;
   case Builtin::BIsub_group_reserve_read_pipe:
   case Builtin::BIsub_group_reserve_write_pipe:
 if (checkOpenCLSubgroupExt(*this, TheCall) ||
 SemaBuiltinReserveRWPipe(*this, TheCall))
   return ExprError();
-// Since return type of reserve_read/write_pipe built-in function is
-// reserve_id_t, which is not defined in the builtin def file , we used int
-// as return type and need to override the return type of these functions.
-TheCall->setType(Context.OCLReserveIDTy);
 break;
   case Builtin::BIcommit_read_pipe:
   case Builtin::BIcommit_write_pipe:


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


r309678 - [OpenCL] Add missing subgroup builtins

2017-08-01 Thread Joey Gouly via cfe-commits
Author: joey
Date: Tue Aug  1 06:27:09 2017
New Revision: 309678

URL: http://llvm.org/viewvc/llvm-project?rev=309678=rev
Log:
[OpenCL] Add missing subgroup builtins

This adds get_kernel_max_sub_group_size_for_ndrange and
get_kernel_sub_group_count_for_ndrange.

Modified:
cfe/trunk/include/clang/Basic/Builtins.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/include/clang/Basic/Builtins.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Builtins.def?rev=309678=309677=309678=diff
==
--- cfe/trunk/include/clang/Basic/Builtins.def (original)
+++ cfe/trunk/include/clang/Basic/Builtins.def Tue Aug  1 06:27:09 2017
@@ -1398,8 +1398,10 @@ LANGBUILTIN(get_pipe_max_packets, "Ui.",
 // OpenCL v2.0 s6.13.17 - Enqueue kernel functions.
 // Custom builtin check allows to perform special check of passed block 
arguments.
 LANGBUILTIN(enqueue_kernel, "i.", "tn", OCLC20_LANG)
-LANGBUILTIN(get_kernel_work_group_size, "i.", "tn", OCLC20_LANG)
-LANGBUILTIN(get_kernel_preferred_work_group_size_multiple, "i.", "tn", 
OCLC20_LANG)
+LANGBUILTIN(get_kernel_work_group_size, "Ui.", "tn", OCLC20_LANG)
+LANGBUILTIN(get_kernel_preferred_work_group_size_multiple, "Ui.", "tn", 
OCLC20_LANG)
+LANGBUILTIN(get_kernel_max_sub_group_size_for_ndrange, "Ui.", "tn", 
OCLC20_LANG)
+LANGBUILTIN(get_kernel_sub_group_count_for_ndrange, "Ui.", "tn", OCLC20_LANG)
 
 // OpenCL v2.0 s6.13.9 - Address space qualifier functions.
 LANGBUILTIN(to_global, "v*v*", "tn", OCLC20_LANG)

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=309678=309677=309678=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Tue Aug  1 06:27:09 2017
@@ -2704,6 +2704,25 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 "__get_kernel_preferred_work_group_multiple_impl"),
 Arg));
   }
+  case Builtin::BIget_kernel_max_sub_group_size_for_ndrange:
+  case Builtin::BIget_kernel_sub_group_count_for_ndrange: {
+llvm::Type *GenericVoidPtrTy = Builder.getInt8PtrTy(
+getContext().getTargetAddressSpace(LangAS::opencl_generic));
+LValue NDRangeL = EmitAggExprToLValue(E->getArg(0));
+llvm::Value *NDRange = NDRangeL.getAddress().getPointer();
+Value *Block = EmitScalarExpr(E->getArg(1));
+Block = Builder.CreatePointerCast(Block, GenericVoidPtrTy);
+const char *Name =
+BuiltinID == Builtin::BIget_kernel_max_sub_group_size_for_ndrange
+? "__get_kernel_max_sub_group_size_for_ndrange_impl"
+: "__get_kernel_sub_group_count_for_ndrange_impl";
+return RValue::get(Builder.CreateCall(
+CGM.CreateRuntimeFunction(
+llvm::FunctionType::get(
+IntTy, {NDRange->getType(), GenericVoidPtrTy}, false),
+Name),
+{NDRange, Block}));
+  }
   case Builtin::BIprintf:
 if (getTarget().getTriple().isNVPTX())
   return EmitNVPTXDevicePrintfCallExpr(E, ReturnValue);

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=309678=309677=309678=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Aug  1 06:27:09 2017
@@ -308,6 +308,32 @@ static bool checkOpenCLSubgroupExt(Sema
   return false;
 }
 
+static bool SemaOpenCLBuiltinNDRangeAndBlock(Sema , CallExpr *TheCall) {
+  if (checkArgCount(S, TheCall, 2))
+return true;
+
+  if (checkOpenCLSubgroupExt(S, TheCall))
+return true;
+
+  // First argument is an ndrange_t type.
+  Expr *NDRangeArg = TheCall->getArg(0);
+  if (NDRangeArg->getType().getAsString() != "ndrange_t") {
+S.Diag(NDRangeArg->getLocStart(),
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "'ndrange_t'";
+return true;
+  }
+
+  Expr *BlockArg = TheCall->getArg(1);
+  if (!isBlockPointer(BlockArg)) {
+S.Diag(BlockArg->getLocStart(),
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "block";
+return true;
+  }
+  return checkOpenCLBlockArgs(S, BlockArg);
+}
+
 /// OpenCL C v2.0, s6.13.17.6 - Check the argument to the
 /// get_kernel_work_group_size
 /// and get_kernel_preferred_work_group_size_multiple builtin functions.
@@ -1109,6 +1135,12 @@ Sema::CheckBuiltinFunctionCall(FunctionD
 if (SemaOpenCLBuiltinKernelWorkGroupSize(*this, TheCall))
   return ExprError();
 break;
+break;
+  case Builtin::BIget_kernel_max_sub_group_size_for_ndrange:
+  case 

r309571 - [OpenCL] Enable subgroup extension in tests

2017-07-31 Thread Joey Gouly via cfe-commits
Author: joey
Date: Mon Jul 31 08:50:27 2017
New Revision: 309571

URL: http://llvm.org/viewvc/llvm-project?rev=309571=rev
Log:
[OpenCL] Enable subgroup extension in tests

This fixes the test, so that it can be run on different hosts that may have
different OpenCL extensions enabled.

Modified:
cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Modified: cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl?rev=309571=309570=309571=diff
==
--- cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl Mon Jul 31 08:50:27 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -emit-llvm -O0 -cl-std=CL2.0 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -cl-ext=+cl_khr_subgroups -O0 -cl-std=CL2.0 -o - 
%s | FileCheck %s
 
 // CHECK: %opencl.pipe_t = type opaque
 // CHECK: %opencl.reserve_id_t = type opaque

Modified: cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl?rev=309571=309570=309571=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl Mon Jul 31 08:50:27 
2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -cl-std=CL2.0 
-cl-ext=+cl_khr_subgroups
 
 #pragma OPENCL EXTENSION cl_khr_subgroups : enable
 


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


r309567 - [OpenCL] Add extension Sema check for subgroup builtins

2017-07-31 Thread Joey Gouly via cfe-commits
Author: joey
Date: Mon Jul 31 08:15:59 2017
New Revision: 309567

URL: http://llvm.org/viewvc/llvm-project?rev=309567=rev
Log:
[OpenCL] Add extension Sema check for subgroup builtins

Check the subgroup extension is enabled, before doing other Sema checks.

Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=309567=309566=309567=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Jul 31 08:15:59 2017
@@ -299,6 +299,15 @@ static bool checkOpenCLBlockArgs(Sema 
   return IllegalParams;
 }
 
+static bool checkOpenCLSubgroupExt(Sema , CallExpr *Call) {
+  if (!S.getOpenCLOptions().isEnabled("cl_khr_subgroups")) {
+S.Diag(Call->getLocStart(), diag::err_opencl_requires_extension)
+  << 1 << Call->getDirectCallee() << "cl_khr_subgroups";
+return true;
+  }
+  return false;
+}
+
 /// OpenCL C v2.0, s6.13.17.6 - Check the argument to the
 /// get_kernel_work_group_size
 /// and get_kernel_preferred_work_group_size_multiple builtin functions.
@@ -1048,9 +1057,17 @@ Sema::CheckBuiltinFunctionCall(FunctionD
   case Builtin::BIreserve_write_pipe:
   case Builtin::BIwork_group_reserve_read_pipe:
   case Builtin::BIwork_group_reserve_write_pipe:
+if (SemaBuiltinReserveRWPipe(*this, TheCall))
+  return ExprError();
+// Since return type of reserve_read/write_pipe built-in function is
+// reserve_id_t, which is not defined in the builtin def file , we used int
+// as return type and need to override the return type of these functions.
+TheCall->setType(Context.OCLReserveIDTy);
+break;
   case Builtin::BIsub_group_reserve_read_pipe:
   case Builtin::BIsub_group_reserve_write_pipe:
-if (SemaBuiltinReserveRWPipe(*this, TheCall))
+if (checkOpenCLSubgroupExt(*this, TheCall) ||
+SemaBuiltinReserveRWPipe(*this, TheCall))
   return ExprError();
 // Since return type of reserve_read/write_pipe built-in function is
 // reserve_id_t, which is not defined in the builtin def file , we used int
@@ -1061,9 +1078,13 @@ Sema::CheckBuiltinFunctionCall(FunctionD
   case Builtin::BIcommit_write_pipe:
   case Builtin::BIwork_group_commit_read_pipe:
   case Builtin::BIwork_group_commit_write_pipe:
+if (SemaBuiltinCommitRWPipe(*this, TheCall))
+  return ExprError();
+break;
   case Builtin::BIsub_group_commit_read_pipe:
   case Builtin::BIsub_group_commit_write_pipe:
-if (SemaBuiltinCommitRWPipe(*this, TheCall))
+if (checkOpenCLSubgroupExt(*this, TheCall) ||
+SemaBuiltinCommitRWPipe(*this, TheCall))
   return ExprError();
 break;
   case Builtin::BIget_pipe_num_packets:

Modified: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl?rev=309567=309566=309567=diff
==
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl Mon Jul 31 
08:15:59 2017
@@ -1,6 +1,8 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o 
- -triple "spir-unknown-unknown" | FileCheck %s --check-prefix=COMMON 
--check-prefix=B32
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -ffake-address-space-map -O0 -emit-llvm -o 
- -triple "spir64-unknown-unknown" | FileCheck %s --check-prefix=COMMON 
--check-prefix=B64
 
+#pragma OPENCL EXTENSION cl_khr_subgroups : enable
+
 typedef void (^bl_t)(local void *);
 typedef struct {int a;} ndrange_t;
 

Modified: cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl?rev=309567=309566=309567=diff
==
--- cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/pipe_builtin.cl Mon Jul 31 08:15:59 2017
@@ -3,6 +3,8 @@
 // CHECK: %opencl.pipe_t = type opaque
 // CHECK: %opencl.reserve_id_t = type opaque
 
+#pragma OPENCL EXTENSION cl_khr_subgroups : enable
+
 void test1(read_only pipe int p, global int *ptr) {
   // CHECK: call i32 @__read_pipe_2(%opencl.pipe_t* %{{.*}}, i8* %{{.*}}, i32 
4, i32 4)
   read_pipe(p, ptr);

Modified: cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl?rev=309567=309566=309567=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-pipe-builtin-cl2.0.cl (original)
+++ 

r307067 - [OpenCL] Rename err_opencl_enqueue_kernel_expected_type

2017-07-05 Thread Joey Gouly via cfe-commits
Author: joey
Date: Tue Jul  4 04:50:23 2017
New Revision: 307067

URL: http://llvm.org/viewvc/llvm-project?rev=307067=rev
Log:
[OpenCL] Rename err_opencl_enqueue_kernel_expected_type

Rename err_opencl_enqueue_kernel_expected_type so that other builtins
can use the same diagnostic.

https://reviews.llvm.org/D34948

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=307067=307066=307067=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jul  4 04:50:23 
2017
@@ -8457,8 +8457,6 @@ def err_opencl_builtin_to_addr_invalid_a
 // OpenCL v2.0 s6.13.17 Enqueue kernel restrictions.
 def err_opencl_enqueue_kernel_incorrect_args : Error<
   "illegal call to enqueue_kernel, incorrect argument types">;
-def err_opencl_enqueue_kernel_expected_type : Error<
-  "illegal call to enqueue_kernel, expected %0 argument type">;
 def err_opencl_enqueue_kernel_local_size_args : Error<
   "mismatch in number of block parameters and local size arguments passed">;
 def err_opencl_enqueue_kernel_invalid_local_size_type : Error<
@@ -8468,6 +8466,9 @@ def err_opencl_enqueue_kernel_blocks_non
 def err_opencl_enqueue_kernel_blocks_no_args : Error<
   "blocks with parameters are not accepted in this prototype of enqueue_kernel 
call">;
 
+def err_opencl_builtin_expected_type : Error<
+  "illegal call to %0, expected %1 argument type">;
+
 // OpenCL v2.2 s2.1.2.3 - Vector Component Access
 def ext_opencl_ext_vector_type_rgba_selector: ExtWarn<
   "vector component name '%0' is an OpenCL version 2.2 feature">,

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=307067=307066=307067=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Tue Jul  4 04:50:23 2017
@@ -309,7 +309,8 @@ static bool SemaOpenCLBuiltinKernelWorkG
   Expr *BlockArg = TheCall->getArg(0);
   if (!isBlockPointer(BlockArg)) {
 S.Diag(BlockArg->getLocStart(),
-   diag::err_opencl_enqueue_kernel_expected_type) << "block";
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "block";
 return true;
   }
   return checkOpenCLBlockArgs(S, BlockArg);
@@ -394,24 +395,24 @@ static bool SemaOpenCLBuiltinEnqueueKern
   // First argument always needs to be a queue_t type.
   if (!Arg0->getType()->isQueueT()) {
 S.Diag(TheCall->getArg(0)->getLocStart(),
-   diag::err_opencl_enqueue_kernel_expected_type)
-<< S.Context.OCLQueueTy;
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << S.Context.OCLQueueTy;
 return true;
   }
 
   // Second argument always needs to be a kernel_enqueue_flags_t enum value.
   if (!Arg1->getType()->isIntegerType()) {
 S.Diag(TheCall->getArg(1)->getLocStart(),
-   diag::err_opencl_enqueue_kernel_expected_type)
-<< "'kernel_enqueue_flags_t' (i.e. uint)";
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "'kernel_enqueue_flags_t' (i.e. 
uint)";
 return true;
   }
 
   // Third argument is always an ndrange_t type.
   if (Arg2->getType().getUnqualifiedType().getAsString() != "ndrange_t") {
 S.Diag(TheCall->getArg(2)->getLocStart(),
-   diag::err_opencl_enqueue_kernel_expected_type)
-<< "'ndrange_t'";
+   diag::err_opencl_builtin_expected_type)
+<< TheCall->getDirectCallee() << "'ndrange_t'";
 return true;
   }
 
@@ -420,8 +421,8 @@ static bool SemaOpenCLBuiltinEnqueueKern
   if (NumArgs == 4) {
 // check that the last argument is the right block type.
 if (!isBlockPointer(Arg3)) {
-  S.Diag(Arg3->getLocStart(), 
diag::err_opencl_enqueue_kernel_expected_type)
-  << "block";
+  S.Diag(Arg3->getLocStart(), diag::err_opencl_builtin_expected_type)
+  << TheCall->getDirectCallee() << "block";
   return true;
 }
 // we have a block type, check the prototype
@@ -443,8 +444,8 @@ static bool SemaOpenCLBuiltinEnqueueKern
 // check common block argument.
 Expr *Arg6 = TheCall->getArg(6);
 if (!isBlockPointer(Arg6)) {
-  S.Diag(Arg6->getLocStart(), 
diag::err_opencl_enqueue_kernel_expected_type)
-  << "block";
+  S.Diag(Arg6->getLocStart(), diag::err_opencl_builtin_expected_type)
+  << TheCall->getDirectCallee() << "block";
   return true;
 }
 if (checkOpenCLBlockArgs(S, Arg6))
@@ -453,8 +454,8 @@ static bool 

r306827 - [OpenCL] Add function name to extension diagnostic

2017-06-30 Thread Joey Gouly via cfe-commits
Author: joey
Date: Fri Jun 30 07:23:01 2017
New Revision: 306827

URL: http://llvm.org/viewvc/llvm-project?rev=306827=rev
Log:
[OpenCL] Add function name to extension diagnostic

Slightly improve the diagnostic by including the function name.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/Sema.cpp
cfe/trunk/test/SemaOpenCL/extension-begin.cl

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=306827=306826=306827=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 30 07:23:01 
2017
@@ -8410,7 +8410,7 @@ def warn_opencl_attr_deprecated_ignored
 def err_opencl_variadic_function : Error<
   "invalid prototype, variadic arguments are not allowed in OpenCL">;
 def err_opencl_requires_extension : Error<
-  "use of %select{type |declaration}0%1 requires %2 extension to be enabled">;
+  "use of %select{type|declaration}0 %1 requires %2 extension to be enabled">;
 
 // OpenCL v2.0 s6.13.6 -- Builtin Pipe Functions
 def err_opencl_builtin_pipe_first_arg : Error<

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=306827=306826=306827=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Jun 30 07:23:01 2017
@@ -8432,7 +8432,7 @@ public:
   /// is disabled due to required OpenCL extensions being disabled. If so,
   /// emit diagnostics.
   /// \return true if type is disabled.
-  bool checkOpenCLDisabledDecl(const Decl , const Expr );
+  bool checkOpenCLDisabledDecl(const NamedDecl , const Expr );
 
   
//======//
   // OpenMP directives and clauses.

Modified: cfe/trunk/lib/Sema/Sema.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.cpp?rev=306827=306826=306827=diff
==
--- cfe/trunk/lib/Sema/Sema.cpp (original)
+++ cfe/trunk/lib/Sema/Sema.cpp Fri Jun 30 07:23:01 2017
@@ -1688,7 +1688,8 @@ bool Sema::checkOpenCLDisabledTypeDeclSp
QT, OpenCLTypeExtMap);
 }
 
-bool Sema::checkOpenCLDisabledDecl(const Decl , const Expr ) {
-  return checkOpenCLDisabledTypeOrDecl(, E.getLocStart(), "",
+bool Sema::checkOpenCLDisabledDecl(const NamedDecl , const Expr ) {
+  IdentifierInfo *FnName = D.getIdentifier();
+  return checkOpenCLDisabledTypeOrDecl(, E.getLocStart(), FnName,
OpenCLDeclExtMap, 1, 
D.getSourceRange());
 }

Modified: cfe/trunk/test/SemaOpenCL/extension-begin.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/extension-begin.cl?rev=306827=306826=306827=diff
==
--- cfe/trunk/test/SemaOpenCL/extension-begin.cl (original)
+++ cfe/trunk/test/SemaOpenCL/extension-begin.cl Fri Jun 30 07:23:01 2017
@@ -46,7 +46,7 @@ void test_f2(void) {
   const struct A test_A_local; // expected-error {{use of type 'struct A' 
requires my_ext extension to be enabled}}
   TypedefOfA test_typedef_A; // expected-error {{use of type 'TypedefOfA' (aka 
'struct A') requires my_ext extension to be enabled}}
   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 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@-22 {{candidate function not viable: requires 0 
arguments, but 1 was provided}}


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


r294754 - [libclang] [OpenCL] Expose half type.

2017-02-10 Thread Joey Gouly via cfe-commits
Author: joey
Date: Fri Feb 10 09:51:11 2017
New Revision: 294754

URL: http://llvm.org/viewvc/llvm-project?rev=294754=rev
Log:
[libclang] [OpenCL] Expose half type.

Expose the half type (fp16) through libclang and the python bindings.

It seems CXType_LastBuiltin was not updated in b2ea6d9 ("Enable
support for __float128 in Clang", 2016-04-13), so update it now.

Add an Index test for OpenCL types; in the future we will add other
OpenCL types such as images to this test.

Patch by Sven van Haastregt.

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

Added:
cfe/trunk/test/Index/opencl-types.cl
Modified:
cfe/trunk/bindings/python/clang/cindex.py
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/libclang/CXType.cpp

Modified: cfe/trunk/bindings/python/clang/cindex.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/bindings/python/clang/cindex.py?rev=294754=294753=294754=diff
==
--- cfe/trunk/bindings/python/clang/cindex.py (original)
+++ cfe/trunk/bindings/python/clang/cindex.py Fri Feb 10 09:51:11 2017
@@ -1887,6 +1887,7 @@ TypeKind.OBJCID = TypeKind(27)
 TypeKind.OBJCCLASS = TypeKind(28)
 TypeKind.OBJCSEL = TypeKind(29)
 TypeKind.FLOAT128 = TypeKind(30)
+TypeKind.HALF = TypeKind(31)
 TypeKind.COMPLEX = TypeKind(100)
 TypeKind.POINTER = TypeKind(101)
 TypeKind.BLOCKPOINTER = TypeKind(102)

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=294754=294753=294754=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Fri Feb 10 09:51:11 2017
@@ -3011,8 +3011,9 @@ enum CXTypeKind {
   CXType_ObjCClass = 28,
   CXType_ObjCSel = 29,
   CXType_Float128 = 30,
+  CXType_Half = 31,
   CXType_FirstBuiltin = CXType_Void,
-  CXType_LastBuiltin  = CXType_ObjCSel,
+  CXType_LastBuiltin  = CXType_Half,
 
   CXType_Complex = 100,
   CXType_Pointer = 101,

Added: cfe/trunk/test/Index/opencl-types.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/opencl-types.cl?rev=294754=auto
==
--- cfe/trunk/test/Index/opencl-types.cl (added)
+++ cfe/trunk/test/Index/opencl-types.cl Fri Feb 10 09:51:11 2017
@@ -0,0 +1,24 @@
+// RUN: c-index-test -test-print-type %s | FileCheck %s
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+typedef half half4 __attribute__((ext_vector_type(4)));
+typedef float float4 __attribute__((ext_vector_type(4)));
+typedef double double4 __attribute__((ext_vector_type(4)));
+
+void kernel testFloatTypes() {
+  half scalarHalf;
+  half4 vectorHalf;
+  float scalarFloat;
+  float4 vectorFloat;
+  double scalarDouble;
+  double4 vectorDouble;
+}
+
+// CHECK: VarDecl=scalarHalf:11:8 (Definition) [type=half] [typekind=Half] 
[isPOD=1]
+// CHECK: VarDecl=vectorHalf:12:9 (Definition) [type=half4] [typekind=Typedef] 
[canonicaltype=half __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=Unexposed] [isPOD=1]
+// CHECK: VarDecl=scalarFloat:13:9 (Definition) [type=float] [typekind=Float] 
[isPOD=1]
+// CHECK: VarDecl=vectorFloat:14:10 (Definition) [type=float4] 
[typekind=Typedef] [canonicaltype=float __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=Unexposed] [isPOD=1]
+// CHECK: VarDecl=scalarDouble:15:10 (Definition) [type=double] 
[typekind=Double] [isPOD=1]
+// CHECK: VarDecl=vectorDouble:16:11 (Definition) [type=double4] 
[typekind=Typedef] [canonicaltype=double __attribute__((ext_vector_type(4)))] 
[canonicaltypekind=Unexposed] [isPOD=1]

Modified: cfe/trunk/tools/libclang/CXType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXType.cpp?rev=294754=294753=294754=diff
==
--- cfe/trunk/tools/libclang/CXType.cpp (original)
+++ cfe/trunk/tools/libclang/CXType.cpp Fri Feb 10 09:51:11 2017
@@ -48,6 +48,7 @@ static CXTypeKind GetBuiltinTypeKind(con
 BTCASE(Long);
 BTCASE(LongLong);
 BTCASE(Int128);
+BTCASE(Half);
 BTCASE(Float);
 BTCASE(Double);
 BTCASE(LongDouble);
@@ -503,6 +504,7 @@ CXString clang_getTypeKindSpelling(enum
 TKIND(Long);
 TKIND(LongLong);
 TKIND(Int128);
+TKIND(Half);
 TKIND(Float);
 TKIND(Double);
 TKIND(LongDouble);


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


r288332 - [OpenCL] Refactor read_only/write_only pipes.

2016-12-01 Thread Joey Gouly via cfe-commits
Author: joey
Date: Thu Dec  1 05:30:49 2016
New Revision: 288332

URL: http://llvm.org/viewvc/llvm-project?rev=288332=rev
Log:
[OpenCL] Refactor read_only/write_only pipes.

This adds the access qualifier to the Pipe Type, rather than using a class
hierarchy. 

It also fixes mergeTypes for Pipes, by disallowing merges. Only identical
pipe types can be merged. The test case in invalid-pipes-cl2.0.cl is added
to check that.

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=288332=288331=288332=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Dec  1 05:30:49 2016
@@ -135,8 +135,7 @@ class ASTContext : public RefCountedBase
   mutable llvm::FoldingSet AutoTypes;
   mutable llvm::FoldingSet AtomicTypes;
   llvm::FoldingSet AttributedTypes;
-  mutable llvm::FoldingSet ReadPipeTypes;
-  mutable llvm::FoldingSet WritePipeTypes;
+  mutable llvm::FoldingSet PipeTypes;
 
   mutable llvm::FoldingSet QualifiedTemplateNames;
   mutable llvm::FoldingSet DependentTemplateNames;
@@ -1012,6 +1011,8 @@ private:
 
   QualType getTypeDeclTypeSlow(const TypeDecl *Decl) const;
 
+  QualType getPipeType(QualType T, bool ReadOnly) const;
+
 public:
   /// \brief Return the uniqued reference to the type for an address space
   /// qualified type with the specified type and address space.

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=288332=288331=288332=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Thu Dec  1 05:30:49 2016
@@ -5285,7 +5285,6 @@ class AtomicType : public Type, public l
 
 /// PipeType - OpenCL20.
 class PipeType : public Type, public llvm::FoldingSetNode {
-protected:
   QualType ElementType;
   bool isRead;
 
@@ -5295,6 +5294,7 @@ protected:
  elemType->isVariablyModifiedType(),
  elemType->containsUnexpandedParameterPack()),
 ElementType(elemType), isRead(isRead) {}
+  friend class ASTContext;  // ASTContext creates these.
 
 public:
   QualType getElementType() const { return ElementType; }
@@ -5304,11 +5304,12 @@ public:
   QualType desugar() const { return QualType(this, 0); }
 
   void Profile(llvm::FoldingSetNodeID ) {
-Profile(ID, getElementType());
+Profile(ID, getElementType(), isReadOnly());
   }
 
-  static void Profile(llvm::FoldingSetNodeID , QualType T) {
+  static void Profile(llvm::FoldingSetNodeID , QualType T, bool isRead) {
 ID.AddPointer(T.getAsOpaquePtr());
+ID.AddBoolean(isRead);
   }
 
   static bool classof(const Type *T) {
@@ -5318,18 +5319,6 @@ public:
   bool isReadOnly() const { return isRead; }
 };
 
-class ReadPipeType : public PipeType {
-  ReadPipeType(QualType elemType, QualType CanonicalPtr) :
-PipeType(elemType, CanonicalPtr, true) {}
-  friend class ASTContext;  // ASTContext creates these.
-};
-
-class WritePipeType : public PipeType {
-  WritePipeType(QualType elemType, QualType CanonicalPtr) :
-PipeType(elemType, CanonicalPtr, false) {}
-  friend class ASTContext;  // ASTContext creates these.
-};
-
 /// A qualifier set is used to build a set of qualifiers.
 class QualifierCollector : public Qualifiers {
 public:

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Serialization/ASTBitCodes.h?rev=288332=288331=288332=diff
==
--- cfe/trunk/include/clang/Serialization/ASTBitCodes.h (original)
+++ cfe/trunk/include/clang/Serialization/ASTBitCodes.h Thu Dec  1 05:30:49 2016
@@ -905,12 +905,10 @@ namespace clang {
   TYPE_DECAYED   = 41,
   /// \brief An AdjustedType record.
   TYPE_ADJUSTED  = 42,
-  /// \brief A ReadPipeType record.
-  TYPE_READ_PIPE = 43,
+  /// \brief A PipeType record.
+  TYPE_PIPE  = 43,
   /// \brief An ObjCTypeParamType record.
-  TYPE_OBJC_TYPE_PARAM   = 44,
-  /// \brief A WritePipeType record.
-  TYPE_WRITE_PIPE= 45,
+  TYPE_OBJC_TYPE_PARAM   = 44
 };
 
 /// \brief The type IDs for special types constructed by semantic

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=288332=288331=288332=diff

[PATCH] D27049: [OpenCL] Refactor out ReadPipe/WritePipe

2016-11-23 Thread Joey Gouly via cfe-commits
joey created this revision.
joey added reviewers: yaron.keren, bader.
joey added a subscriber: cfe-commits.
joey set the repository for this revision to rL LLVM.
Herald added a subscriber: yaxunl.

This patch to keep the pipe access qualifier inside PipeType itself looks 
cleaner overall than my previous approach.

Yaron had a post-commit comment, which lead me to re-think the original code.


Repository:
  rL LLVM

https://reviews.llvm.org/D27049

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp

Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -516,10 +516,8 @@
 void
 ASTTypeWriter::VisitPipeType(const PipeType *T) {
   Record.AddTypeRef(T->getElementType());
-  if (T->isReadOnly())
-Code = TYPE_READ_PIPE;
-  else
-Code = TYPE_WRITE_PIPE;
+  Record.push_back(T->isReadOnly());
+  Code = TYPE_PIPE;
 }
 
 namespace {
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -5793,27 +5793,21 @@
 return Context.getAtomicType(ValueType);
   }
 
-  case TYPE_READ_PIPE: {
-if (Record.size() != 1) {
+  case TYPE_PIPE: {
+if (Record.size() != 2) {
   Error("Incorrect encoding of pipe type");
   return QualType();
 }
 
 // Reading the pipe element type.
 QualType ElementType = readType(*Loc.F, Record, Idx);
-return Context.getReadPipeType(ElementType);
+unsigned ReadOnly = Record[1];
+if (ReadOnly)
+  return Context.getReadPipeType(ElementType);
+else
+  return Context.getWritePipeType(ElementType);
   }
 
-  case TYPE_WRITE_PIPE: {
-if (Record.size() != 1) {
-  Error("Incorrect encoding of pipe type");
-  return QualType();
-}
-
-// Reading the pipe element type.
-QualType ElementType = readType(*Loc.F, Record, Idx);
-return Context.getWritePipeType(ElementType);
-  }
   }
   llvm_unreachable("Invalid TypeCode!");
 }
Index: lib/AST/ASTContext.cpp
===
--- lib/AST/ASTContext.cpp
+++ lib/AST/ASTContext.cpp
@@ -3338,54 +3338,37 @@
   return QualType(FTP, 0);
 }
 
-QualType ASTContext::getReadPipeType(QualType T) const {
+QualType ASTContext::getPipeType(QualType T, bool ReadOnly) const {
   llvm::FoldingSetNodeID ID;
-  ReadPipeType::Profile(ID, T);
+  PipeType::Profile(ID, T, ReadOnly);
 
   void *InsertPos = 0;
-  if (ReadPipeType *PT = ReadPipeTypes.FindNodeOrInsertPos(ID, InsertPos))
+  if (PipeType *PT = PipeTypes.FindNodeOrInsertPos(ID, InsertPos))
 return QualType(PT, 0);
 
   // If the pipe element type isn't canonical, this won't be a canonical type
   // either, so fill in the canonical type field.
   QualType Canonical;
   if (!T.isCanonical()) {
-Canonical = getReadPipeType(getCanonicalType(T));
+Canonical = getPipeType(getCanonicalType(T), ReadOnly);
 
 // Get the new insert position for the node we care about.
-ReadPipeType *NewIP = ReadPipeTypes.FindNodeOrInsertPos(ID, InsertPos);
+PipeType *NewIP = PipeTypes.FindNodeOrInsertPos(ID, InsertPos);
 assert(!NewIP && "Shouldn't be in the map!");
 (void)NewIP;
   }
-  ReadPipeType *New = new (*this, TypeAlignment) ReadPipeType(T, Canonical);
+  PipeType *New = new (*this, TypeAlignment) PipeType(T, Canonical, ReadOnly);
   Types.push_back(New);
-  ReadPipeTypes.InsertNode(New, InsertPos);
+  PipeTypes.InsertNode(New, InsertPos);
   return QualType(New, 0);
 }
 
-QualType ASTContext::getWritePipeType(QualType T) const {
-  llvm::FoldingSetNodeID ID;
-  WritePipeType::Profile(ID, T);
-
-  void *InsertPos = 0;
-  if (WritePipeType *PT = WritePipeTypes.FindNodeOrInsertPos(ID, InsertPos))
-return QualType(PT, 0);
-
-  // If the pipe element type isn't canonical, this won't be a canonical type
-  // either, so fill in the canonical type field.
-  QualType Canonical;
-  if (!T.isCanonical()) {
-Canonical = getWritePipeType(getCanonicalType(T));
+QualType ASTContext::getReadPipeType(QualType T) const {
+  return getPipeType(T, true);
+}
 
-// Get the new insert position for the node we care about.
-WritePipeType *NewIP = WritePipeTypes.FindNodeOrInsertPos(ID, InsertPos);
-assert(!NewIP && "Shouldn't be in the map!");
-(void)NewIP;
-  }
-  WritePipeType *New = new (*this, TypeAlignment) WritePipeType(T, Canonical);
-  Types.push_back(New);
-  WritePipeTypes.InsertNode(New, InsertPos);
-  return QualType(New, 0);
+QualType ASTContext::getWritePipeType(QualType T) const {
+  return getPipeType(T, false);
 }
 
 #ifndef NDEBUG
@@ -8272,8 +8255,9 @@
   return LHS;
 if (getCanonicalType(RHSValue) == getCanonicalType(ResultType))
   return RHS;
-

Re: r287343 - [OpenCL] Introduce ReadPipeType and WritePipeType.

2016-11-23 Thread Joey Gouly via cfe-commits
Hi Yaron,

I have changed how I implemented this, will open a review soon.

Thanks,
Joey

On 21 November 2016 at 14:42, Yaron Keren <yaron.ke...@gmail.com> wrote:
> Hi Joey,
>
> In order for  ReadPipeType and WritePipeType to work with LLVM type system
> (isa, dyn_cast), you need to modify the existing TypeClass::Pipe kind into
> TypeClass::ReadPipe and TypeClass::WritePipe, have Pipe::classof recognize
> both kinds and have ReadPipe::classof and WritePipe::classof recognize their
> respective kinds.
>
> See rule 4 in http://llvm.org/docs/HowToSetUpLLVMStyleRTTI.html
>
> Good example is how ConstantArrayType, IncompleteArrayType,
> VariableArrayType, DependentSizedArrayType inherit from ArrayType.
>
> Yaron
>
>
>
> 2016-11-18 16:10 GMT+02:00 Joey Gouly via cfe-commits
> <cfe-commits@lists.llvm.org>:
>>
>> Author: joey
>> Date: Fri Nov 18 08:10:54 2016
>> New Revision: 287343
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=287343=rev
>> Log:
>> [OpenCL] Introduce ReadPipeType and WritePipeType.
>>
>> This allows Sema to diagnose passing a read_only pipe to a
>> write_only pipe argument.
>>
>> Modified:
>> cfe/trunk/include/clang/AST/ASTContext.h
>> cfe/trunk/include/clang/AST/Type.h
>> cfe/trunk/include/clang/Sema/Sema.h
>> cfe/trunk/include/clang/Serialization/ASTBitCodes.h
>> cfe/trunk/lib/AST/ASTContext.cpp
>> cfe/trunk/lib/AST/TypePrinter.cpp
>> cfe/trunk/lib/Sema/SemaType.cpp
>> cfe/trunk/lib/Sema/TreeTransform.h
>> cfe/trunk/lib/Serialization/ASTReader.cpp
>> cfe/trunk/lib/Serialization/ASTWriter.cpp
>> cfe/trunk/test/Misc/ast-dump-pipe.cl
>> cfe/trunk/test/SemaOpenCL/access-qualifier.cl
>> cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl
>>
>> Modified: cfe/trunk/include/clang/AST/ASTContext.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=287343=287342=287343=diff
>>
>> ==
>> --- cfe/trunk/include/clang/AST/ASTContext.h (original)
>> +++ cfe/trunk/include/clang/AST/ASTContext.h Fri Nov 18 08:10:54 2016
>> @@ -135,7 +135,8 @@ class ASTContext : public RefCountedBase
>>mutable llvm::FoldingSet AutoTypes;
>>mutable llvm::FoldingSet AtomicTypes;
>>llvm::FoldingSet AttributedTypes;
>> -  mutable llvm::FoldingSet PipeTypes;
>> +  mutable llvm::FoldingSet ReadPipeTypes;
>> +  mutable llvm::FoldingSet WritePipeTypes;
>>
>>mutable llvm::FoldingSet QualifiedTemplateNames;
>>mutable llvm::FoldingSet DependentTemplateNames;
>> @@ -1120,8 +1121,10 @@ public:
>>/// blocks.
>>QualType getBlockDescriptorType() const;
>>
>> -  /// \brief Return pipe type for the specified type.
>> -  QualType getPipeType(QualType T) const;
>> +  /// \brief Return a read_only pipe type for the specified type.
>> +  QualType getReadPipeType(QualType T) const;
>> +  /// \brief Return a write_only pipe type for the specified type.
>> +  QualType getWritePipeType(QualType T) const;
>>
>>/// Gets the struct used to keep track of the extended descriptor for
>>/// pointer to blocks.
>>
>> Modified: cfe/trunk/include/clang/AST/Type.h
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=287343=287342=287343=diff
>>
>> ==
>> --- cfe/trunk/include/clang/AST/Type.h (original)
>> +++ cfe/trunk/include/clang/AST/Type.h Fri Nov 18 08:10:54 2016
>> @@ -5285,18 +5285,18 @@ class AtomicType : public Type, public l
>>
>>  /// PipeType - OpenCL20.
>>  class PipeType : public Type, public llvm::FoldingSetNode {
>> +protected:
>>QualType ElementType;
>> +  bool isRead;
>>
>> -  PipeType(QualType elemType, QualType CanonicalPtr) :
>> +  PipeType(QualType elemType, QualType CanonicalPtr, bool isRead) :
>>  Type(Pipe, CanonicalPtr, elemType->isDependentType(),
>>   elemType->isInstantiationDependentType(),
>>   elemType->isVariablyModifiedType(),
>>   elemType->containsUnexpandedParameterPack()),
>> -ElementType(elemType) {}
>> -  friend class ASTContext;  // ASTContext creates these.
>> +ElementType(elemType), isRead(isRead) {}
>>
>>  public:
>> -
>>QualType getElementType() const { return ElementType; }
>>
>>bool isSugared() const { return false; }
>> @@ -5311,11 +5311,23 @@ public:
>>

[PATCH] D26746: [OpenCL] Split PipeType into ReadPipe/WritePipe

2016-11-18 Thread Joey Gouly via cfe-commits
joey closed this revision.
joey marked 3 inline comments as done.
joey added a comment.

Committed as r287343.


Repository:
  rL LLVM

https://reviews.llvm.org/D26746



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


r287343 - [OpenCL] Introduce ReadPipeType and WritePipeType.

2016-11-18 Thread Joey Gouly via cfe-commits
Author: joey
Date: Fri Nov 18 08:10:54 2016
New Revision: 287343

URL: http://llvm.org/viewvc/llvm-project?rev=287343=rev
Log:
[OpenCL] Introduce ReadPipeType and WritePipeType.

This allows Sema to diagnose passing a read_only pipe to a
write_only pipe argument.

Modified:
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Serialization/ASTBitCodes.h
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/TypePrinter.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Sema/TreeTransform.h
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp
cfe/trunk/test/Misc/ast-dump-pipe.cl
cfe/trunk/test/SemaOpenCL/access-qualifier.cl
cfe/trunk/test/SemaOpenCL/invalid-pipes-cl2.0.cl

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=287343=287342=287343=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Fri Nov 18 08:10:54 2016
@@ -135,7 +135,8 @@ class ASTContext : public RefCountedBase
   mutable llvm::FoldingSet AutoTypes;
   mutable llvm::FoldingSet AtomicTypes;
   llvm::FoldingSet AttributedTypes;
-  mutable llvm::FoldingSet PipeTypes;
+  mutable llvm::FoldingSet ReadPipeTypes;
+  mutable llvm::FoldingSet WritePipeTypes;
 
   mutable llvm::FoldingSet QualifiedTemplateNames;
   mutable llvm::FoldingSet DependentTemplateNames;
@@ -1120,8 +1121,10 @@ public:
   /// blocks.
   QualType getBlockDescriptorType() const;
 
-  /// \brief Return pipe type for the specified type.
-  QualType getPipeType(QualType T) const;
+  /// \brief Return a read_only pipe type for the specified type.
+  QualType getReadPipeType(QualType T) const;
+  /// \brief Return a write_only pipe type for the specified type.
+  QualType getWritePipeType(QualType T) const;
 
   /// Gets the struct used to keep track of the extended descriptor for
   /// pointer to blocks.

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=287343=287342=287343=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Nov 18 08:10:54 2016
@@ -5285,18 +5285,18 @@ class AtomicType : public Type, public l
 
 /// PipeType - OpenCL20.
 class PipeType : public Type, public llvm::FoldingSetNode {
+protected:
   QualType ElementType;
+  bool isRead;
 
-  PipeType(QualType elemType, QualType CanonicalPtr) :
+  PipeType(QualType elemType, QualType CanonicalPtr, bool isRead) :
 Type(Pipe, CanonicalPtr, elemType->isDependentType(),
  elemType->isInstantiationDependentType(),
  elemType->isVariablyModifiedType(),
  elemType->containsUnexpandedParameterPack()),
-ElementType(elemType) {}
-  friend class ASTContext;  // ASTContext creates these.
+ElementType(elemType), isRead(isRead) {}
 
 public:
-
   QualType getElementType() const { return ElementType; }
 
   bool isSugared() const { return false; }
@@ -5311,11 +5311,23 @@ public:
 ID.AddPointer(T.getAsOpaquePtr());
   }
 
-
   static bool classof(const Type *T) {
 return T->getTypeClass() == Pipe;
   }
 
+  bool isReadOnly() const { return isRead; }
+};
+
+class ReadPipeType : public PipeType {
+  ReadPipeType(QualType elemType, QualType CanonicalPtr) :
+PipeType(elemType, CanonicalPtr, true) {}
+  friend class ASTContext;  // ASTContext creates these.
+};
+
+class WritePipeType : public PipeType {
+  WritePipeType(QualType elemType, QualType CanonicalPtr) :
+PipeType(elemType, CanonicalPtr, false) {}
+  friend class ASTContext;  // ASTContext creates these.
 };
 
 /// A qualifier set is used to build a set of qualifiers.

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=287343=287342=287343=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Fri Nov 18 08:10:54 2016
@@ -1303,7 +1303,9 @@ public:
  SourceLocation Loc, DeclarationName Entity);
   QualType BuildParenType(QualType T);
   QualType BuildAtomicType(QualType T, SourceLocation Loc);
-  QualType BuildPipeType(QualType T,
+  QualType BuildReadPipeType(QualType T,
+ SourceLocation Loc);
+  QualType BuildWritePipeType(QualType T,
  SourceLocation Loc);
 
   TypeSourceInfo *GetTypeForDeclarator(Declarator , Scope *S);

Modified: cfe/trunk/include/clang/Serialization/ASTBitCodes.h
URL: 

[PATCH] D26746: [OpenCL] Split PipeType into ReadPipe/WritePipe

2016-11-16 Thread Joey Gouly via cfe-commits
joey created this revision.
joey added a subscriber: cfe-commits.
joey set the repository for this revision to rL LLVM.
Herald added a subscriber: yaxunl.

Split the PipeType into two derived classes. This allows Sema to diagnose 
passing read_only to write_only and vice versa.


Repository:
  rL LLVM

https://reviews.llvm.org/D26746

Files:
  include/clang/AST/ASTContext.h
  include/clang/AST/Type.h
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTContext.cpp
  lib/AST/TypePrinter.cpp
  lib/Sema/SemaType.cpp
  lib/Sema/TreeTransform.h
  lib/Serialization/ASTReader.cpp
  lib/Serialization/ASTWriter.cpp
  test/Misc/ast-dump-pipe.cl
  test/SemaOpenCL/access-qualifier.cl
  test/SemaOpenCL/invalid-pipes-cl2.0.cl

Index: test/SemaOpenCL/invalid-pipes-cl2.0.cl
===
--- test/SemaOpenCL/invalid-pipes-cl2.0.cl
+++ test/SemaOpenCL/invalid-pipes-cl2.0.cl
@@ -7,16 +7,16 @@
 void test3(int pipe p) {// expected-error {{cannot combine with previous 'int' declaration specifier}}
 }
 void test4() {
-  pipe int p; // expected-error {{type 'pipe int' can only be used as a function parameter}}
+  pipe int p; // expected-error {{type 'read_only pipe int' can only be used as a function parameter}}
   //TODO: fix parsing of this pipe int (*p);
 }
 
 void test5(pipe int p) {
-  p+p; // expected-error{{invalid operands to binary expression ('pipe int' and 'pipe int')}}
-  p=p; // expected-error{{invalid operands to binary expression ('pipe int' and 'pipe int')}}
-   // expected-error{{invalid argument type 'pipe int' to unary expression}}
-  *p; // expected-error{{invalid argument type 'pipe int' to unary expression}}
+  p+p; // expected-error{{invalid operands to binary expression ('read_only pipe int' and 'read_only pipe int')}}
+  p=p; // expected-error{{invalid operands to binary expression ('read_only pipe int' and 'read_only pipe int')}}
+   // expected-error{{invalid argument type 'read_only pipe int' to unary expression}}
+  *p; // expected-error{{invalid argument type 'read_only pipe int' to unary expression}}
 }
 
 typedef pipe int pipe_int_t;
-pipe_int_t test6() {} // expected-error{{declaring function return value of type 'pipe_int_t' (aka 'pipe int') is not allowed}}
+pipe_int_t test6() {} // expected-error{{declaring function return value of type 'pipe_int_t' (aka 'read_only pipe int') is not allowed}}
Index: test/SemaOpenCL/access-qualifier.cl
===
--- test/SemaOpenCL/access-qualifier.cl
+++ test/SemaOpenCL/access-qualifier.cl
@@ -63,7 +63,14 @@
 kernel void k12(read_only read_only image1d_t i){} // expected-error{{multiple access qualifiers}}
 
 #if __OPENCL_C_VERSION__ >= 200
-kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'pipe int'}}
+kernel void k13(read_write pipe int i){} // expected-error{{access qualifier 'read_write' can not be used for 'read_only pipe int'}}
 #else
 kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
 #endif
+
+#if __OPENCL_C_VERSION__ >= 200
+void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}}
+kernel void k14(read_only pipe int p) {
+  myPipeWrite(p); // expected-error {{passing 'read_only pipe int' to parameter of incompatible type 'write_only pipe int'}}
+}
+#endif
Index: test/Misc/ast-dump-pipe.cl
===
--- test/Misc/ast-dump-pipe.cl
+++ test/Misc/ast-dump-pipe.cl
@@ -1,4 +1,12 @@
 // RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter pipetype %s | FileCheck -strict-whitespace %s
 typedef pipe int pipetype;
-// CHECK:  PipeType {{.*}} 'pipe int'
+// CHECK:  PipeType {{.*}} 'read_only pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
+
+typedef read_only pipe int pipetype2;
+// CHECK:  PipeType {{.*}} 'read_only pipe int'
+// CHECK-NEXT:   BuiltinType {{.*}} 'int'
+
+typedef write_only pipe int pipetype3;
+// CHECK:  PipeType {{.*}} 'write_only pipe int'
 // CHECK-NEXT:   BuiltinType {{.*}} 'int'
Index: lib/Serialization/ASTWriter.cpp
===
--- lib/Serialization/ASTWriter.cpp
+++ lib/Serialization/ASTWriter.cpp
@@ -516,7 +516,10 @@
 void
 ASTTypeWriter::VisitPipeType(const PipeType *T) {
   Record.AddTypeRef(T->getElementType());
-  Code = TYPE_PIPE;
+  if (T->isReadOnly())
+Code = TYPE_READ_PIPE;
+  else
+Code = TYPE_WRITE_PIPE;
 }
 
 namespace {
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -5794,15 +5794,25 @@
 return Context.getAtomicType(ValueType);
   }
 
-  case TYPE_PIPE: {
+  case 

[PATCH] D26668: [OpenCL] Minor cleanup to access attributes on images

2016-11-16 Thread Joey Gouly via cfe-commits
joey closed this revision.
joey added a comment.

Committed as r287100.




Comment at: test/SemaOpenCL/access-qualifier.cl:71
+
+#if __OPENCL_C_VERSION__ >= 200
+void myPipeWrite(write_only pipe int); // expected-note {{passing argument to 
parameter here}}

This was an unintentional test change, and was not committed.


Repository:
  rL LLVM

https://reviews.llvm.org/D26668



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


r287100 - [OpenCL] Use the semantic spelling of the Access attribute, rather than a string.

2016-11-16 Thread Joey Gouly via cfe-commits
Author: joey
Date: Wed Nov 16 05:34:09 2016
New Revision: 287100

URL: http://llvm.org/viewvc/llvm-project?rev=287100=rev
Log:
[OpenCL] Use the semantic spelling of the Access attribute, rather than a 
string.

Also fix a latent bug, due to an incorrect traversal of the AttributeList.

Modified:
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/test/SemaOpenCL/invalid-image.cl

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=287100=287099=287100=diff
==
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Wed Nov 16 05:34:09 2016
@@ -1209,19 +1209,19 @@ TypeResult Sema::actOnObjCTypeArgsAndPro
   return CreateParsedType(Result, ResultTInfo);
 }
 
-static StringRef getImageAccessAttrStr(AttributeList *attrs) {
-  if (attrs) {
-
-AttributeList *Next;
+static OpenCLAccessAttr::Spelling getImageAccess(const AttributeList *Attrs) {
+  if (Attrs) {
+const AttributeList *Next = Attrs;
 do {
-  AttributeList  = *attrs;
+  const AttributeList  = *Next;
   Next = Attr.getNext();
   if (Attr.getKind() == AttributeList::AT_OpenCLAccess) {
-return Attr.getName()->getName();
+return static_cast(
+Attr.getSemanticSpelling());
   }
 } while (Next);
   }
-  return "";
+  return OpenCLAccessAttr::Keyword_read_only;
 }
 
 /// \brief Convert the specified declspec to the appropriate type
@@ -1619,11 +1619,14 @@ static QualType ConvertDeclSpecToType(Ty
 
 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
   case DeclSpec::TST_##ImgType##_t: \
-Result = llvm::StringSwitch( \
- getImageAccessAttrStr(DS.getAttributes().getList())) \
- .Cases("write_only", "__write_only", Context.Id##WOTy) \
- .Cases("read_write", "__read_write", Context.Id##RWTy) \
- .Default(Context.Id##ROTy); \
+switch (getImageAccess(DS.getAttributes().getList())) { \
+case OpenCLAccessAttr::Keyword_write_only: \
+  Result = Context.Id##WOTy; break; \
+case OpenCLAccessAttr::Keyword_read_write: \
+  Result = Context.Id##RWTy; break; \
+case OpenCLAccessAttr::Keyword_read_only: \
+  Result = Context.Id##ROTy; break; \
+} \
 break;
 #include "clang/Basic/OpenCLImageTypes.def"
 

Modified: cfe/trunk/test/SemaOpenCL/invalid-image.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/invalid-image.cl?rev=287100=287099=287100=diff
==
--- cfe/trunk/test/SemaOpenCL/invalid-image.cl (original)
+++ cfe/trunk/test/SemaOpenCL/invalid-image.cl Wed Nov 16 05:34:09 2016
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -D=ATTR_TEST -fms-compatibility %s
 
 void test1(image1d_t *i) {} // expected-error{{pointer to type '__read_only 
image1d_t' is invalid in OpenCL}}
 
@@ -12,3 +13,8 @@ void test2(image1d_t i) {
 }
 
 image1d_t test3() {} // expected-error{{declaring function return value of 
type '__read_only image1d_t' is not allowed}}
+
+#ifdef ATTR_TEST
+// Test case for an infinite loop bug.
+kernel void foob(read_only __ptr32  image2d_t i) { } // 
expected-error{{'__ptr32' attribute only applies to pointer arguments}}
+#endif


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


[PATCH] D26668: [OpenCL] Minor cleanup to access attributes on images

2016-11-15 Thread Joey Gouly via cfe-commits
joey marked an inline comment as done.
joey added inline comments.



Comment at: lib/Sema/SemaType.cpp:1224
   }
-  return "";
+  return OpenCLAccessAttr::Keyword_read_only;
 }

aaron.ballman wrote:
> The caller can no longer tell the difference between a real-only OpenCL 
> access attribute and no OpenCL access attribute. I know that this was the 
> effective behavior of the original code, but that's specific to the current 
> use case, so I think this change is a tiny regression in the semantics.
I renamed this function.



Comment at: lib/Sema/SemaType.cpp:1629
+  Result = Context.Id##ROTy; break; \
+default: assert(0 && "Unknown access attribute!"); \
+} \

aaron.ballman wrote:
> Just checking, but, has this situation already been diagnosed elsewhere?
Maybe I should actually replace this with an llvm_unreachable?


Repository:
  rL LLVM

https://reviews.llvm.org/D26668



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


[PATCH] D26668: [OpenCL] Minor cleanup to access attributes on images

2016-11-15 Thread Joey Gouly via cfe-commits
joey updated this revision to Diff 78017.
joey added a comment.

Fixed a latent infinite loop bug in 'getImageAccess', it was dereferencing 
Attrs, instead of Next.


Repository:
  rL LLVM

https://reviews.llvm.org/D26668

Files:
  lib/Sema/SemaType.cpp
  test/SemaOpenCL/access-qualifier.cl
  test/SemaOpenCL/invalid-image.cl


Index: test/SemaOpenCL/invalid-image.cl
===
--- test/SemaOpenCL/invalid-image.cl
+++ test/SemaOpenCL/invalid-image.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -D=ATTR_TEST -fms-compatibility %s
 
 void test1(image1d_t *i) {} // expected-error{{pointer to type '__read_only 
image1d_t' is invalid in OpenCL}}
 
@@ -12,3 +13,8 @@
 }
 
 image1d_t test3() {} // expected-error{{declaring function return value of 
type '__read_only image1d_t' is not allowed}}
+
+#ifdef ATTR_TEST
+// Test case for an infinite loop bug.
+kernel void foob(read_only __ptr32  image2d_t i) { } // 
expected-error{{'__ptr32' attribute only applies to pointer arguments}}
+#endif
Index: test/SemaOpenCL/access-qualifier.cl
===
--- test/SemaOpenCL/access-qualifier.cl
+++ test/SemaOpenCL/access-qualifier.cl
@@ -67,3 +67,10 @@
 #else
 kernel void k13(__read_write image1d_t i){} // expected-error{{access 
qualifier '__read_write' can not be used for '__read_write image1d_t' prior to 
OpenCL version 2.0}}
 #endif
+
+#if __OPENCL_C_VERSION__ >= 200
+void myPipeWrite(write_only pipe int); // expected-note {{passing argument to 
parameter here}}
+kernel void k14(read_only pipe int p) {
+  myPipeWrite(p); // expected-error {{passing 'read_only pipe int' to 
parameter of incompatible type 'write_only pipe int'}}
+}
+#endif
Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1209,19 +1209,19 @@
   return CreateParsedType(Result, ResultTInfo);
 }
 
-static StringRef getImageAccessAttrStr(AttributeList *attrs) {
-  if (attrs) {
-
-AttributeList *Next;
+static OpenCLAccessAttr::Spelling getImageAccess(const AttributeList *Attrs) {
+  if (Attrs) {
+const AttributeList *Next = Attrs;
 do {
-  AttributeList  = *attrs;
+  const AttributeList  = *Next;
   Next = Attr.getNext();
   if (Attr.getKind() == AttributeList::AT_OpenCLAccess) {
-return Attr.getName()->getName();
+return static_cast(
+Attr.getSemanticSpelling());
   }
 } while (Next);
   }
-  return "";
+  return OpenCLAccessAttr::Keyword_read_only;
 }
 
 /// \brief Convert the specified declspec to the appropriate type
@@ -1619,11 +1619,15 @@
 
 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
   case DeclSpec::TST_##ImgType##_t: \
-Result = llvm::StringSwitch( \
- getImageAccessAttrStr(DS.getAttributes().getList())) \
- .Cases("write_only", "__write_only", Context.Id##WOTy) \
- .Cases("read_write", "__read_write", Context.Id##RWTy) \
- .Default(Context.Id##ROTy); \
+switch (getImageAccess(DS.getAttributes().getList())) { \
+case OpenCLAccessAttr::Keyword_write_only: \
+  Result = Context.Id##WOTy; break; \
+case OpenCLAccessAttr::Keyword_read_write: \
+  Result = Context.Id##RWTy; break; \
+case OpenCLAccessAttr::Keyword_read_only: \
+  Result = Context.Id##ROTy; break; \
+default: assert(0 && "Unknown access attribute!"); \
+} \
 break;
 #include "clang/Basic/OpenCLImageTypes.def"
 


Index: test/SemaOpenCL/invalid-image.cl
===
--- test/SemaOpenCL/invalid-image.cl
+++ test/SemaOpenCL/invalid-image.cl
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -verify %s
+// RUN: %clang_cc1 -verify -D=ATTR_TEST -fms-compatibility %s
 
 void test1(image1d_t *i) {} // expected-error{{pointer to type '__read_only image1d_t' is invalid in OpenCL}}
 
@@ -12,3 +13,8 @@
 }
 
 image1d_t test3() {} // expected-error{{declaring function return value of type '__read_only image1d_t' is not allowed}}
+
+#ifdef ATTR_TEST
+// Test case for an infinite loop bug.
+kernel void foob(read_only __ptr32  image2d_t i) { } // expected-error{{'__ptr32' attribute only applies to pointer arguments}}
+#endif
Index: test/SemaOpenCL/access-qualifier.cl
===
--- test/SemaOpenCL/access-qualifier.cl
+++ test/SemaOpenCL/access-qualifier.cl
@@ -67,3 +67,10 @@
 #else
 kernel void k13(__read_write image1d_t i){} // expected-error{{access qualifier '__read_write' can not be used for '__read_write image1d_t' prior to OpenCL version 2.0}}
 #endif
+
+#if __OPENCL_C_VERSION__ >= 200
+void myPipeWrite(write_only pipe int); // expected-note {{passing argument to parameter here}}
+kernel void k14(read_only pipe int p) {
+  myPipeWrite(p); // expected-error {{passing 'read_only pipe int' to parameter 

[PATCH] D26668: [OpenCL] Minor cleanup to access attributes on images

2016-11-15 Thread Joey Gouly via cfe-commits
joey created this revision.
joey added a subscriber: cfe-commits.
joey set the repository for this revision to rL LLVM.
Herald added a subscriber: yaxunl.

Use the semantic spelling (an enum) rather than a string, to determine what 
access qualifier is used.


Repository:
  rL LLVM

https://reviews.llvm.org/D26668

Files:
  lib/Sema/SemaType.cpp


Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1209,19 +1209,19 @@
   return CreateParsedType(Result, ResultTInfo);
 }
 
-static StringRef getImageAccessAttrStr(AttributeList *attrs) {
+static OpenCLAccessAttr::Spelling getImageAccessAttr(AttributeList *attrs) {
   if (attrs) {
-
 AttributeList *Next;
 do {
   AttributeList  = *attrs;
   Next = Attr.getNext();
   if (Attr.getKind() == AttributeList::AT_OpenCLAccess) {
-return Attr.getName()->getName();
+return static_cast(
+Attr.getSemanticSpelling());
   }
 } while (Next);
   }
-  return "";
+  return OpenCLAccessAttr::Keyword_read_only;
 }
 
 /// \brief Convert the specified declspec to the appropriate type
@@ -1619,11 +1619,15 @@
 
 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
   case DeclSpec::TST_##ImgType##_t: \
-Result = llvm::StringSwitch( \
- getImageAccessAttrStr(DS.getAttributes().getList())) \
- .Cases("write_only", "__write_only", Context.Id##WOTy) \
- .Cases("read_write", "__read_write", Context.Id##RWTy) \
- .Default(Context.Id##ROTy); \
+switch (getImageAccessAttr(DS.getAttributes().getList())) { \
+case OpenCLAccessAttr::Keyword_write_only: \
+  Result = Context.Id##WOTy; break; \
+case OpenCLAccessAttr::Keyword_read_write: \
+  Result = Context.Id##RWTy; break; \
+case OpenCLAccessAttr::Keyword_read_only: \
+  Result = Context.Id##ROTy; break; \
+default: assert(0 && "Unknown access attribute!"); \
+} \
 break;
 #include "clang/Basic/OpenCLImageTypes.def"
 


Index: lib/Sema/SemaType.cpp
===
--- lib/Sema/SemaType.cpp
+++ lib/Sema/SemaType.cpp
@@ -1209,19 +1209,19 @@
   return CreateParsedType(Result, ResultTInfo);
 }
 
-static StringRef getImageAccessAttrStr(AttributeList *attrs) {
+static OpenCLAccessAttr::Spelling getImageAccessAttr(AttributeList *attrs) {
   if (attrs) {
-
 AttributeList *Next;
 do {
   AttributeList  = *attrs;
   Next = Attr.getNext();
   if (Attr.getKind() == AttributeList::AT_OpenCLAccess) {
-return Attr.getName()->getName();
+return static_cast(
+Attr.getSemanticSpelling());
   }
 } while (Next);
   }
-  return "";
+  return OpenCLAccessAttr::Keyword_read_only;
 }
 
 /// \brief Convert the specified declspec to the appropriate type
@@ -1619,11 +1619,15 @@
 
 #define GENERIC_IMAGE_TYPE(ImgType, Id) \
   case DeclSpec::TST_##ImgType##_t: \
-Result = llvm::StringSwitch( \
- getImageAccessAttrStr(DS.getAttributes().getList())) \
- .Cases("write_only", "__write_only", Context.Id##WOTy) \
- .Cases("read_write", "__read_write", Context.Id##RWTy) \
- .Default(Context.Id##ROTy); \
+switch (getImageAccessAttr(DS.getAttributes().getList())) { \
+case OpenCLAccessAttr::Keyword_write_only: \
+  Result = Context.Id##WOTy; break; \
+case OpenCLAccessAttr::Keyword_read_write: \
+  Result = Context.Id##RWTy; break; \
+case OpenCLAccessAttr::Keyword_read_only: \
+  Result = Context.Id##ROTy; break; \
+default: assert(0 && "Unknown access attribute!"); \
+} \
 break;
 #include "clang/Basic/OpenCLImageTypes.def"
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23712: [OpenCL] Override supported OpenCL extensions with -cl-ext option

2016-10-24 Thread Joey Gouly via cfe-commits
joey added a comment.

Two minor comments, but otherwise LGTM!




Comment at: include/clang/Basic/OpenCLOptions.h:33
 
   // Enable all options.
+  void setAll(bool Enable = true) {

This comment needs to be changed, to reflect that they are now all enabled or 
disabled.



Comment at: include/clang/Basic/TargetInfo.h:992
+  virtual void setOpenCLExtensionOpts() {
+for (const auto :getTargetOpts().OpenCLExtensionsAsWritten) {
+  getTargetOpts().SupportedOpenCLOptions.set(Ext);

Can you put a space around the ':'.


https://reviews.llvm.org/D23712



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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-12 Thread Joey Gouly via cfe-commits
joey added a subscriber: joey.


Comment at: lib/CodeGen/CodeGenModule.cpp:101
@@ -100,3 +100,3 @@
   DoubleTy = llvm::Type::getDoubleTy(LLVMContext);
   PointerWidthInBits = C.getTargetInfo().getPointerWidth(0);
   PointerAlignInBytes =

What if you create a new function in TargetInfo called 
getMaxPointerWidth(unsigned AddrSpace), and call that here? That would by 
default just call 'getPointerWidth', but in your AMDGPU TargetInfo you can 
override that.
That feels more generic.


https://reviews.llvm.org/D23361



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


r278235 - [OpenCL] Fix typo in test that I accidentally introduced in my previous commit.

2016-08-10 Thread Joey Gouly via cfe-commits
Author: joey
Date: Wed Aug 10 11:04:14 2016
New Revision: 278235

URL: http://llvm.org/viewvc/llvm-project?rev=278235=rev
Log:
[OpenCL] Fix typo in test that I accidentally introduced in my previous commit.

Modified:
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl?rev=278235=278234=278235=diff
==
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl Wed Aug 10 
11:04:14 2016
@@ -5,7 +5,7 @@ typedef void (^bl_t)(local void *);
 const bl_t block_G = (bl_t) ^ (local void *a) {};
 
 kernel void device_side_enqueue(global int *a, global int *b, int i) {
-  // CHECK: %deafault_queue = alloca %opencl.queue_t*
+  // CHECK: %default_queue = alloca %opencl.queue_t*
   queue_t default_queue;
   // CHECK: %flags = alloca i32
   unsigned flags = 0;


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


r278234 - [OpenCL] Change block descriptor address space to constant.

2016-08-10 Thread Joey Gouly via cfe-commits
Author: joey
Date: Wed Aug 10 10:57:02 2016
New Revision: 278234

URL: http://llvm.org/viewvc/llvm-project?rev=278234=rev
Log:
[OpenCL] Change block descriptor address space to constant.

The block descriptor is a GlobalVariable in the LLVM IR, so it shouldn't be
in the private address space.

Modified:
cfe/trunk/lib/CodeGen/CGBlocks.cpp
cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Modified: cfe/trunk/lib/CodeGen/CGBlocks.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBlocks.cpp?rev=278234=278233=278234=diff
==
--- cfe/trunk/lib/CodeGen/CGBlocks.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBlocks.cpp Wed Aug 10 10:57:02 2016
@@ -125,10 +125,15 @@ static llvm::Constant *buildBlockDescrip
 
   llvm::Constant *init = llvm::ConstantStruct::getAnon(elements);
 
+  unsigned AddrSpace = 0;
+  if (C.getLangOpts().OpenCL)
+AddrSpace = C.getTargetAddressSpace(LangAS::opencl_constant);
   llvm::GlobalVariable *global =
 new llvm::GlobalVariable(CGM.getModule(), init->getType(), true,
  llvm::GlobalValue::InternalLinkage,
- init, "__block_descriptor_tmp");
+ init, "__block_descriptor_tmp", nullptr,
+ llvm::GlobalValue::NotThreadLocal,
+ AddrSpace);
 
   return llvm::ConstantExpr::getBitCast(global, CGM.getBlockDescriptorType());
 }
@@ -927,7 +932,10 @@ llvm::Type *CodeGenModule::getBlockDescr
  UnsignedLongTy, UnsignedLongTy, nullptr);
 
   // Now form a pointer to that.
-  BlockDescriptorType = llvm::PointerType::getUnqual(BlockDescriptorType);
+  unsigned AddrSpace = 0;
+  if (getLangOpts().OpenCL)
+AddrSpace = getContext().getTargetAddressSpace(LangAS::opencl_constant);
+  BlockDescriptorType = llvm::PointerType::get(BlockDescriptorType, AddrSpace);
   return BlockDescriptorType;
 }
 

Modified: cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl?rev=278234=278233=278234=diff
==
--- cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/cl20-device-side-enqueue.cl Wed Aug 10 
10:57:02 2016
@@ -5,7 +5,7 @@ typedef void (^bl_t)(local void *);
 const bl_t block_G = (bl_t) ^ (local void *a) {};
 
 kernel void device_side_enqueue(global int *a, global int *b, int i) {
-  // CHECK: %default_queue = alloca %opencl.queue_t*
+  // CHECK: %deafault_queue = alloca %opencl.queue_t*
   queue_t default_queue;
   // CHECK: %flags = alloca i32
   unsigned flags = 0;
@@ -21,7 +21,7 @@ kernel void device_side_enqueue(global i
   // CHECK: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t*, %opencl.queue_t** 
%default_queue
   // CHECK: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // CHECK: [[NDR:%[0-9]+]] = load %opencl.ndrange_t*, %opencl.ndrange_t** 
%ndrange
-  // CHECK: [[BL:%[0-9]+]] = bitcast <{ i8*, i32, i32, i8*, 
%struct.__block_descriptor*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* %block to void 
()*
+  // CHECK: [[BL:%[0-9]+]] = bitcast <{ i8*, i32, i32, i8*, 
%struct.__block_descriptor addrspace(3)*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* 
%block to void ()*
   // CHECK: [[BL_I8:%[0-9]+]] = bitcast void ()* [[BL]] to i8*
   // CHECK: call i32 @__enqueue_kernel_basic(%opencl.queue_t* [[DEF_Q]], i32 
[[FLAGS]], %opencl.ndrange_t* [[NDR]], i8* [[BL_I8]])
   enqueue_kernel(default_queue, flags, ndrange,
@@ -32,7 +32,7 @@ kernel void device_side_enqueue(global i
   // CHECK: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t*, %opencl.queue_t** 
%default_queue
   // CHECK: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // CHECK: [[NDR:%[0-9]+]] = load %opencl.ndrange_t*, %opencl.ndrange_t** 
%ndrange
-  // CHECK: [[BL:%[0-9]+]] = bitcast <{ i8*, i32, i32, i8*, 
%struct.__block_descriptor*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* %block3 to 
void ()*
+  // CHECK: [[BL:%[0-9]+]] = bitcast <{ i8*, i32, i32, i8*, 
%struct.__block_descriptor addrspace(3)*, i32{{.*}}, i32{{.*}}, i32{{.*}} }>* 
%block3 to void ()*
   // CHECK: [[BL_I8:%[0-9]+]] = bitcast void ()* [[BL]] to i8*
   // CHECK: call i32 @__enqueue_kernel_basic_events(%opencl.queue_t* 
[[DEF_Q]], i32 [[FLAGS]], %opencl.ndrange_t* [[NDR]], i32 2, 
%opencl.clk_event_t** %event_wait_list, %opencl.clk_event_t** %clk_event, i8* 
[[BL_I8]])
   enqueue_kernel(default_queue, flags, ndrange, 2, _wait_list, 
_event,
@@ -43,7 +43,7 @@ kernel void device_side_enqueue(global i
   // CHECK: [[DEF_Q:%[0-9]+]] = load %opencl.queue_t*, %opencl.queue_t** 
%default_queue
   // CHECK: [[FLAGS:%[0-9]+]] = load i32, i32* %flags
   // CHECK: [[NDR:%[0-9]+]] = load %opencl.ndrange_t*, %opencl.ndrange_t** 
%ndrange
-  // CHECK: call i32 (%opencl.queue_t*, i32, %opencl.ndrange_t*, i8*, i32, 
...) 

Re: [PATCH] D17578: [OpenCL]Allowing explicit conversion of "0" to event_t type

2016-05-11 Thread Joey Gouly via cfe-commits
joey accepted this revision.
joey added a comment.
This revision is now accepted and ready to land.

LGTM!


http://reviews.llvm.org/D17578



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