[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-24 Thread Sven van Haastregt via cfe-commits
Henry =?utf-8?q?Linjamäki?= 
Message-ID:
In-Reply-To: 


svenvh wrote:

> Thanks for the review. Could you merge this PR on my behalf (I don't have 
> write access)?

Yes I am happy to do so, but would you mind rebasing this PR onto latest `main` 
first?  Just so that the checks can run again to avoid any potential new 
regressions since the checks ran last.

https://github.com/llvm/llvm-project/pull/77897
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Add cl_khr_kernel_clock builtins (PR #91950)

2024-05-20 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh closed https://github.com/llvm/llvm-project/pull/91950
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-05-17 Thread Sven van Haastregt via cfe-commits


@@ -535,20 +535,23 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
-LangAS AS = ArrayQTy.getAddressSpace();
+QualType GVArrayQTy = CGM.getContext().getAddrSpaceQualType(
+CGM.getContext().removeAddrSpaceQualType(ArrayQTy),

svenvh wrote:

@changpeng would you be able to provide an input source that demonstrates the 
issue?

https://github.com/llvm/llvm-project/pull/90048
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SPIR-V] Prefer llvm-spirv- tool (PR #77897)

2024-05-16 Thread Sven van Haastregt via cfe-commits
Henry =?utf-8?q?Linjam=C3=A4ki?= 
Message-ID:
In-Reply-To: 


https://github.com/svenvh approved this pull request.


https://github.com/llvm/llvm-project/pull/77897
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Emit opencl.cxx.version metadata for C++ (PR #92140)

2024-05-14 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh created 
https://github.com/llvm/llvm-project/pull/92140

Currently there is no way to tell whether an IR module was generated using 
`-cl-std=cl3.0` or `-cl-std=clc++2021`, i.e., whether the origin was a OpenCL C 
or C++ for OpenCL source.

Add new `opencl.cxx.version` named metadata when compiling C++.  Keep the 
`opencl.ocl.version` metadata to convey the compatible OpenCL C version.

Fixes https://github.com/llvm/llvm-project/issues/91912

>From 1ae9a8e94306e6ced8b45c36380128a1cb867a1f Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Tue, 14 May 2024 16:14:08 +0100
Subject: [PATCH] [OpenCL] Emit opencl.cxx.version metadata for C++

Currently there is no way to tell whether an IR module was generated
using `-cl-std=cl3.0` or `-cl-std=clc++2021`, i.e., whether the origin
was a OpenCL C or C++ for OpenCL source.

Add new `opencl.cxx.version` named metadata when compiling C++.  Keep
the `opencl.ocl.version` metadata to convey the compatible OpenCL C
version.

Fixes https://github.com/llvm/llvm-project/issues/91912
---
 clang/lib/CodeGen/CodeGenModule.cpp   | 30 ++-
 clang/test/CodeGenOpenCLCXX/version.clcpp | 21 
 2 files changed, 40 insertions(+), 11 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCLCXX/version.clcpp

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 489c08a4d4819..028ae9c5915db 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1394,17 +1394,25 @@ void CodeGenModule::Release() {
 void CodeGenModule::EmitOpenCLMetadata() {
   // SPIR v2.0 s2.13 - The OpenCL version used by the module is stored in the
   // opencl.ocl.version named metadata node.
-  // C++ for OpenCL has a distinct mapping for versions compatibile with 
OpenCL.
-  auto Version = LangOpts.getOpenCLCompatibleVersion();
-  llvm::Metadata *OCLVerElts[] = {
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
-  Int32Ty, Version / 100)),
-  llvm::ConstantAsMetadata::get(llvm::ConstantInt::get(
-  Int32Ty, (Version % 100) / 10))};
-  llvm::NamedMDNode *OCLVerMD =
-  TheModule.getOrInsertNamedMetadata("opencl.ocl.version");
-  llvm::LLVMContext  = TheModule.getContext();
-  OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+  // C++ for OpenCL has a distinct mapping for versions compatible with OpenCL.
+  auto CLVersion = LangOpts.getOpenCLCompatibleVersion();
+
+  auto EmitVersion = [this](StringRef MDName, int Version) {
+llvm::Metadata *OCLVerElts[] = {
+llvm::ConstantAsMetadata::get(
+llvm::ConstantInt::get(Int32Ty, Version / 100)),
+llvm::ConstantAsMetadata::get(
+llvm::ConstantInt::get(Int32Ty, (Version % 100) / 10))};
+llvm::NamedMDNode *OCLVerMD = TheModule.getOrInsertNamedMetadata(MDName);
+llvm::LLVMContext  = TheModule.getContext();
+OCLVerMD->addOperand(llvm::MDNode::get(Ctx, OCLVerElts));
+  };
+
+  EmitVersion("opencl.ocl.version", CLVersion);
+  if (LangOpts.OpenCLCPlusPlus) {
+// In addition to the OpenCL compatible version, emit the C++ version.
+EmitVersion("opencl.cxx.version", LangOpts.OpenCLCPlusPlusVersion);
+  }
 }
 
 void CodeGenModule::EmitBackendOptionsMetadata(
diff --git a/clang/test/CodeGenOpenCLCXX/version.clcpp 
b/clang/test/CodeGenOpenCLCXX/version.clcpp
new file mode 100644
index 0..2f2aa022afab2
--- /dev/null
+++ b/clang/test/CodeGenOpenCLCXX/version.clcpp
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=CL2.0 | FileCheck %s --check-prefix=CHECK-NO-CXX
+
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=clc++1.0 | FileCheck %s --check-prefix=CHECK-CXX100
+// RUN: %clang_cc1 %s -triple "spir64-unknown-unknown" -emit-llvm -o - 
-cl-std=clc++2021 | FileCheck %s --check-prefix=CHECK-CXX2021
+
+// This test checks that opencl.cxx.version metadata is emitted accordingly.
+// It avoids any C++ features to enable checking that the metadata is not 
emitted in non-C++ mode.
+
+kernel void foo() {}
+
+// CHECK-NO-CXX-NOT: opencl.cxx.version
+
+// CHECK-CXX100-DAG: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CHECK-CXX100-DAG: !opencl.cxx.version = !{[[CXX:![0-9]+]]}
+// CHECK-CXX100-DAG: [[OCL]] = !{i32 2, i32 0}
+// CHECK-CXX100-DAG: [[CXX]] = !{i32 1, i32 0}
+
+// CHECK-CXX2021-DAG: !opencl.ocl.version = !{[[OCL:![0-9]+]]}
+// CHECK-CXX2021-DAG: !opencl.cxx.version = !{[[CXX:![0-9]+]]}
+// CHECK-CXX2021-DAG: [[OCL]] = !{i32 3, i32 0}
+// CHECK-CXX2021-DAG: [[CXX]] = !{i32 2021, i32 0}

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


[clang] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-05-14 Thread Sven van Haastregt via cfe-commits

svenvh wrote:

> It allows the source to be parsed, but then I don't see the attribute in the 
> LLVM IR generated for libclc.

You will need to also convert the attribute into an LLVM IR construct (e.g. 
metadata) in Clang CodeGen.  See `CodeGenFunction::EmitKernelMetadata` for 
inspiration for example.

https://github.com/llvm/llvm-project/pull/84934
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Add cl_khr_kernel_clock builtins (PR #91950)

2024-05-13 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh created 
https://github.com/llvm/llvm-project/pull/91950

Provisional extension description: 
https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_API.html#cl_khr_kernel_clock
 and
https://registry.khronos.org/OpenCL/specs/3.0-unified/html/OpenCL_C.html#kernel-clock-functions
 .

>From a13bb735ddb11209456386136e0ab010c3d71cf2 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Mon, 13 May 2024 12:23:33 +0100
Subject: [PATCH] [OpenCL] Add cl_khr_kernel_clock builtins

---
 clang/lib/Headers/opencl-c-base.h |  4 
 clang/lib/Headers/opencl-c.h  | 15 +++
 clang/lib/Sema/OpenCLBuiltins.td  | 14 ++
 3 files changed, 33 insertions(+)

diff --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 2494f6213fc56..786678b9d8a75 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -46,6 +46,10 @@
 #define __opencl_c_ext_fp32_global_atomic_min_max 1
 #define __opencl_c_ext_fp32_local_atomic_min_max 1
 #define __opencl_c_ext_image_raw10_raw12 1
+#define cl_khr_kernel_clock 1
+#define __opencl_c_kernel_clock_scope_device 1
+#define __opencl_c_kernel_clock_scope_work_group 1
+#define __opencl_c_kernel_clock_scope_sub_group 1
 
 #endif // defined(__SPIR__) || defined(__SPIRV__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 288bb18bc654e..20719b74b6b8d 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -17314,6 +17314,21 @@ half __ovld __conv sub_group_clustered_rotate(half, 
int, uint);
 #endif // cl_khr_fp16
 #endif // cl_khr_subgroup_rotate
 
+#if defined(cl_khr_kernel_clock)
+#if defined(__opencl_c_kernel_clock_scope_device)
+ulong __ovld clock_read_device();
+uint2 __ovld clock_read_hilo_device();
+#endif // __opencl_c_kernel_clock_scope_device
+#if defined(__opencl_c_kernel_clock_scope_work_group)
+ulong __ovld clock_read_work_group();
+uint2 __ovld clock_read_hilo_work_group();
+#endif // __opencl_c_kernel_clock_scope_work_group
+#if defined(__opencl_c_kernel_clock_scope_sub_group)
+ulong __ovld clock_read_sub_group();
+uint2 __ovld clock_read_hilo_sub_group();
+#endif // __opencl_c_kernel_clock_scope_sub_group
+#endif // cl_khr_kernel_clock
+
 #if defined(cl_intel_subgroups)
 // Intel-Specific Sub Group Functions
 float   __ovld __conv intel_sub_group_shuffle( float , uint );
diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index a7bdfe20b9828..4da61429fcce7 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1852,6 +1852,20 @@ let Extension = 
FunctionExtension<"cl_khr_subgroup_rotate"> in {
   def : Builtin<"sub_group_clustered_rotate", [AGenType1, AGenType1, Int, 
UInt], Attr.Convergent>;
 }
 
+// cl_khr_kernel_clock
+let Extension = FunctionExtension<"cl_khr_kernel_clock 
__opencl_c_kernel_clock_scope_device"> in {
+  def : Builtin<"clock_read_device", [ULong]>;
+  def : Builtin<"clock_read_hilo_device", [VectorType]>;
+}
+let Extension = FunctionExtension<"cl_khr_kernel_clock 
__opencl_c_kernel_clock_scope_work_group"> in {
+  def : Builtin<"clock_read_work_group", [ULong]>;
+  def : Builtin<"clock_read_hilo_work_group", [VectorType]>;
+}
+let Extension = FunctionExtension<"cl_khr_kernel_clock 
__opencl_c_kernel_clock_scope_sub_group"> in {
+  def : Builtin<"clock_read_sub_group", [ULong]>;
+  def : Builtin<"clock_read_hilo_sub_group", [VectorType]>;
+}
+
 //
 // Arm extensions.
 let Extension = ArmIntegerDotProductInt8 in {

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


[clang] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-05-08 Thread Sven van Haastregt via cfe-commits

svenvh wrote:

The libclc usage seems to have been added by @rjodinchr in 
https://reviews.llvm.org/D147773 (and approved by @alan-baker).  Perhaps they 
have an opinion?

https://github.com/llvm/llvm-project/pull/84934
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-05-02 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh closed https://github.com/llvm/llvm-project/pull/90048
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-30 Thread Sven van Haastregt via cfe-commits


@@ -535,20 +535,24 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
-LangAS AS = ArrayQTy.getAddressSpace();
+QualType GVArrayQTy = ArrayQTy;
+if (!GVArrayQTy.hasAddressSpace())
+  GVArrayQTy = CGM.getContext().getAddrSpaceQualType(

svenvh wrote:

Thanks, updated.

https://github.com/llvm/llvm-project/pull/90048
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-30 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh updated 
https://github.com/llvm/llvm-project/pull/90048

>From c5e7b2d5936a7317ebc33159b4cb72bf2aa66cf9 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Thu, 25 Apr 2024 14:10:19 +0100
Subject: [PATCH 1/4] [OpenCL] Put constant initializer globals into constant
 addrspace

Place constant initializer globals into the constant address space.
Clang generates such globals for e.g. larger array member initializers
of classes and then emits copy operations from the global to the
object(s).  The globals are never written so they ought to be in the
constant address space.
---
 clang/lib/CodeGen/CGExprAgg.cpp| 2 ++
 clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp | 5 -
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 355fec42be4489..30cde245cc837c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -536,6 +536,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
 LangAS AS = ArrayQTy.getAddressSpace();
+if (CGF.getLangOpts().OpenCL)
+  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(
diff --git a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp 
b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
index 18d97a989a4364..a0ed03b25535c8 100644
--- a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
+++ b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
@@ -5,7 +5,7 @@
 // for constructors, member functions and destructors.
 // See also atexit.cl and global_init.cl for other specific tests.
 
-// CHECK: %struct.MyType = type { i32 }
+// CHECK: %struct.MyType = type { i32, [5 x i32] }
 struct MyType {
   MyType(int i) : i(i) {}
   MyType(int i) __constant : i(i) {}
@@ -14,6 +14,7 @@ struct MyType {
   int bar() { return i + 2; }
   int bar() __constant { return i + 1; }
   int i;
+  int a[5] = {42, 43, 44, 45, 46};
 };
 
 // CHECK: @const1 ={{.*}} addrspace(2) global %struct.MyType zeroinitializer
@@ -23,6 +24,8 @@ __constant MyType const2(2);
 // CHECK: @glob ={{.*}} addrspace(1) global %struct.MyType zeroinitializer
 MyType glob(1);
 
+// CHECK: @constinit ={{.*}} addrspace(2) constant [5 x i32] [i32 42, i32 43, 
i32 44, i32 45, i32 46]
+
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const1, i32 noundef 1)
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const2, i32 noundef 2)
 // CHECK: call spir_func void @_ZNU3AS46MyTypeC1Ei(ptr addrspace(4) {{[^,]*}} 
addrspacecast (ptr addrspace(1) @glob to ptr addrspace(4)), i32 noundef 1)

>From 08936e55847bd866a1a602a2d7b7c7de5a603df8 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Fri, 26 Apr 2024 13:56:25 +0100
Subject: [PATCH 2/4] Address code review comment: set ArrayQTy addrspace

---
 clang/lib/CodeGen/CGExprAgg.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 30cde245cc837c..44514c830b09cf 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -535,9 +535,10 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
+if (CGF.getLangOpts().OpenCL && !ArrayQTy.hasAddressSpace())
+  ArrayQTy = CGM.getContext().getAddrSpaceQualType(ArrayQTy,
+   
LangAS::opencl_constant);
 LangAS AS = ArrayQTy.getAddressSpace();
-if (CGF.getLangOpts().OpenCL)
-  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(

>From ebefe4bf61db905748da330a22aeb8782ef8cebf Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Mon, 29 Apr 2024 13:18:53 +0100
Subject: [PATCH 3/4] Address review comment: use GetGlobalConstantAddressSpace
 and extract GVArrayQTy

---
 clang/lib/CodeGen/CGExprAgg.cpp | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 44514c830b09cf..41a183ac829949 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -535,12 +535,13 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
-if (CGF.getLangOpts().OpenCL && !ArrayQTy.hasAddressSpace())
-  ArrayQTy = 

[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-29 Thread Sven van Haastregt via cfe-commits


@@ -536,6 +536,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
 LangAS AS = ArrayQTy.getAddressSpace();
+if (CGF.getLangOpts().OpenCL)
+  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(

svenvh wrote:

Nice catch, that wasn't obvious to me from the code.  Updated by splitting out 
a separate QualType variable for the global.

https://github.com/llvm/llvm-project/pull/90048
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-29 Thread Sven van Haastregt via cfe-commits


@@ -536,6 +536,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
 LangAS AS = ArrayQTy.getAddressSpace();
+if (CGF.getLangOpts().OpenCL)
+  AS = LangAS::opencl_constant;

svenvh wrote:

Thanks for the suggestion; updated to use `GetGlobalConstantAddressSpace()`.

https://github.com/llvm/llvm-project/pull/90048
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-29 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh updated 
https://github.com/llvm/llvm-project/pull/90048

>From c5e7b2d5936a7317ebc33159b4cb72bf2aa66cf9 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Thu, 25 Apr 2024 14:10:19 +0100
Subject: [PATCH 1/3] [OpenCL] Put constant initializer globals into constant
 addrspace

Place constant initializer globals into the constant address space.
Clang generates such globals for e.g. larger array member initializers
of classes and then emits copy operations from the global to the
object(s).  The globals are never written so they ought to be in the
constant address space.
---
 clang/lib/CodeGen/CGExprAgg.cpp| 2 ++
 clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp | 5 -
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 355fec42be4489..30cde245cc837c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -536,6 +536,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
 LangAS AS = ArrayQTy.getAddressSpace();
+if (CGF.getLangOpts().OpenCL)
+  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(
diff --git a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp 
b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
index 18d97a989a4364..a0ed03b25535c8 100644
--- a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
+++ b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
@@ -5,7 +5,7 @@
 // for constructors, member functions and destructors.
 // See also atexit.cl and global_init.cl for other specific tests.
 
-// CHECK: %struct.MyType = type { i32 }
+// CHECK: %struct.MyType = type { i32, [5 x i32] }
 struct MyType {
   MyType(int i) : i(i) {}
   MyType(int i) __constant : i(i) {}
@@ -14,6 +14,7 @@ struct MyType {
   int bar() { return i + 2; }
   int bar() __constant { return i + 1; }
   int i;
+  int a[5] = {42, 43, 44, 45, 46};
 };
 
 // CHECK: @const1 ={{.*}} addrspace(2) global %struct.MyType zeroinitializer
@@ -23,6 +24,8 @@ __constant MyType const2(2);
 // CHECK: @glob ={{.*}} addrspace(1) global %struct.MyType zeroinitializer
 MyType glob(1);
 
+// CHECK: @constinit ={{.*}} addrspace(2) constant [5 x i32] [i32 42, i32 43, 
i32 44, i32 45, i32 46]
+
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const1, i32 noundef 1)
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const2, i32 noundef 2)
 // CHECK: call spir_func void @_ZNU3AS46MyTypeC1Ei(ptr addrspace(4) {{[^,]*}} 
addrspacecast (ptr addrspace(1) @glob to ptr addrspace(4)), i32 noundef 1)

>From 08936e55847bd866a1a602a2d7b7c7de5a603df8 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Fri, 26 Apr 2024 13:56:25 +0100
Subject: [PATCH 2/3] Address code review comment: set ArrayQTy addrspace

---
 clang/lib/CodeGen/CGExprAgg.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 30cde245cc837c..44514c830b09cf 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -535,9 +535,10 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
+if (CGF.getLangOpts().OpenCL && !ArrayQTy.hasAddressSpace())
+  ArrayQTy = CGM.getContext().getAddrSpaceQualType(ArrayQTy,
+   
LangAS::opencl_constant);
 LangAS AS = ArrayQTy.getAddressSpace();
-if (CGF.getLangOpts().OpenCL)
-  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(

>From ebefe4bf61db905748da330a22aeb8782ef8cebf Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Mon, 29 Apr 2024 13:18:53 +0100
Subject: [PATCH 3/3] Address review comment: use GetGlobalConstantAddressSpace
 and extract GVArrayQTy

---
 clang/lib/CodeGen/CGExprAgg.cpp | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 44514c830b09cf..41a183ac829949 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -535,12 +535,13 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
-if (CGF.getLangOpts().OpenCL && !ArrayQTy.hasAddressSpace())
-  ArrayQTy = 

[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-26 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh updated 
https://github.com/llvm/llvm-project/pull/90048

>From c5e7b2d5936a7317ebc33159b4cb72bf2aa66cf9 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Thu, 25 Apr 2024 14:10:19 +0100
Subject: [PATCH 1/2] [OpenCL] Put constant initializer globals into constant
 addrspace

Place constant initializer globals into the constant address space.
Clang generates such globals for e.g. larger array member initializers
of classes and then emits copy operations from the global to the
object(s).  The globals are never written so they ought to be in the
constant address space.
---
 clang/lib/CodeGen/CGExprAgg.cpp| 2 ++
 clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp | 5 -
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 355fec42be4489..30cde245cc837c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -536,6 +536,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
 LangAS AS = ArrayQTy.getAddressSpace();
+if (CGF.getLangOpts().OpenCL)
+  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(
diff --git a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp 
b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
index 18d97a989a4364..a0ed03b25535c8 100644
--- a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
+++ b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
@@ -5,7 +5,7 @@
 // for constructors, member functions and destructors.
 // See also atexit.cl and global_init.cl for other specific tests.
 
-// CHECK: %struct.MyType = type { i32 }
+// CHECK: %struct.MyType = type { i32, [5 x i32] }
 struct MyType {
   MyType(int i) : i(i) {}
   MyType(int i) __constant : i(i) {}
@@ -14,6 +14,7 @@ struct MyType {
   int bar() { return i + 2; }
   int bar() __constant { return i + 1; }
   int i;
+  int a[5] = {42, 43, 44, 45, 46};
 };
 
 // CHECK: @const1 ={{.*}} addrspace(2) global %struct.MyType zeroinitializer
@@ -23,6 +24,8 @@ __constant MyType const2(2);
 // CHECK: @glob ={{.*}} addrspace(1) global %struct.MyType zeroinitializer
 MyType glob(1);
 
+// CHECK: @constinit ={{.*}} addrspace(2) constant [5 x i32] [i32 42, i32 43, 
i32 44, i32 45, i32 46]
+
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const1, i32 noundef 1)
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const2, i32 noundef 2)
 // CHECK: call spir_func void @_ZNU3AS46MyTypeC1Ei(ptr addrspace(4) {{[^,]*}} 
addrspacecast (ptr addrspace(1) @glob to ptr addrspace(4)), i32 noundef 1)

>From 08936e55847bd866a1a602a2d7b7c7de5a603df8 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Fri, 26 Apr 2024 13:56:25 +0100
Subject: [PATCH 2/2] Address code review comment: set ArrayQTy addrspace

---
 clang/lib/CodeGen/CGExprAgg.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 30cde245cc837c..44514c830b09cf 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -535,9 +535,10 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
   elementType.isTriviallyCopyableType(CGF.getContext())) {
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
+if (CGF.getLangOpts().OpenCL && !ArrayQTy.hasAddressSpace())
+  ArrayQTy = CGM.getContext().getAddrSpaceQualType(ArrayQTy,
+   
LangAS::opencl_constant);
 LangAS AS = ArrayQTy.getAddressSpace();
-if (CGF.getLangOpts().OpenCL)
-  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(

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


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-26 Thread Sven van Haastregt via cfe-commits


@@ -536,6 +536,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
 LangAS AS = ArrayQTy.getAddressSpace();
+if (CGF.getLangOpts().OpenCL)
+  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(

svenvh wrote:

It seems to have worked indeed, but we should probably adjust the address space 
of `ArrayQTy` everywhere then?  I'll upload a new revision to do so.

https://github.com/llvm/llvm-project/pull/90048
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-26 Thread Sven van Haastregt via cfe-commits


@@ -536,6 +536,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
 LangAS AS = ArrayQTy.getAddressSpace();
+if (CGF.getLangOpts().OpenCL)
+  AS = LangAS::opencl_constant;

svenvh wrote:

The OpenCL language defines the constant address space for read-only variables. 
 Targets can decide for themselves how to map the language address space to a 
target address space (which is done further down at the GlobalVariable 
creation).

https://github.com/llvm/llvm-project/pull/90048
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [OpenCL] Put constant initializer globals into constant addrspace (PR #90048)

2024-04-25 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh created 
https://github.com/llvm/llvm-project/pull/90048

Place constant initializer globals into the constant address space. Clang 
generates such globals for e.g. larger array member initializers of classes and 
then emits copy operations from the global to the object(s).  The globals are 
never written so they ought to be in the constant address space.

>From c5e7b2d5936a7317ebc33159b4cb72bf2aa66cf9 Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Thu, 25 Apr 2024 14:10:19 +0100
Subject: [PATCH] [OpenCL] Put constant initializer globals into constant
 addrspace

Place constant initializer globals into the constant address space.
Clang generates such globals for e.g. larger array member initializers
of classes and then emits copy operations from the global to the
object(s).  The globals are never written so they ought to be in the
constant address space.
---
 clang/lib/CodeGen/CGExprAgg.cpp| 2 ++
 clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp | 5 -
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 355fec42be4489..30cde245cc837c 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -536,6 +536,8 @@ void AggExprEmitter::EmitArrayInit(Address DestPtr, 
llvm::ArrayType *AType,
 CodeGen::CodeGenModule  = CGF.CGM;
 ConstantEmitter Emitter(CGF);
 LangAS AS = ArrayQTy.getAddressSpace();
+if (CGF.getLangOpts().OpenCL)
+  AS = LangAS::opencl_constant;
 if (llvm::Constant *C =
 Emitter.tryEmitForInitializer(ExprToVisit, AS, ArrayQTy)) {
   auto GV = new llvm::GlobalVariable(
diff --git a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp 
b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
index 18d97a989a4364..a0ed03b25535c8 100644
--- a/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
+++ b/clang/test/CodeGenOpenCLCXX/addrspace-with-class.clcpp
@@ -5,7 +5,7 @@
 // for constructors, member functions and destructors.
 // See also atexit.cl and global_init.cl for other specific tests.
 
-// CHECK: %struct.MyType = type { i32 }
+// CHECK: %struct.MyType = type { i32, [5 x i32] }
 struct MyType {
   MyType(int i) : i(i) {}
   MyType(int i) __constant : i(i) {}
@@ -14,6 +14,7 @@ struct MyType {
   int bar() { return i + 2; }
   int bar() __constant { return i + 1; }
   int i;
+  int a[5] = {42, 43, 44, 45, 46};
 };
 
 // CHECK: @const1 ={{.*}} addrspace(2) global %struct.MyType zeroinitializer
@@ -23,6 +24,8 @@ __constant MyType const2(2);
 // CHECK: @glob ={{.*}} addrspace(1) global %struct.MyType zeroinitializer
 MyType glob(1);
 
+// CHECK: @constinit ={{.*}} addrspace(2) constant [5 x i32] [i32 42, i32 43, 
i32 44, i32 45, i32 46]
+
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const1, i32 noundef 1)
 // CHECK: call spir_func void @_ZNU3AS26MyTypeC1Ei(ptr addrspace(2) {{[^,]*}} 
@const2, i32 noundef 2)
 // CHECK: call spir_func void @_ZNU3AS46MyTypeC1Ei(ptr addrspace(4) {{[^,]*}} 
addrspacecast (ptr addrspace(1) @glob to ptr addrspace(4)), i32 noundef 1)

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


[clang] [OpenCL] Fix BIenqueue_kernel fallthrough (PR #83238)

2024-04-02 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh closed https://github.com/llvm/llvm-project/pull/83238
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] c7f1a98 - [OpenCL] Elaborate about BIenqueue_kernel expansion; NFC

2024-03-12 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2024-03-12T12:53:22Z
New Revision: c7f1a987a66a1ba0865ecc18adbe4dc8dbc0c788

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

LOG: [OpenCL] Elaborate about BIenqueue_kernel expansion; NFC

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 20c35757939152..93ab465079777b 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5460,7 +5460,13 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   }
 
   // OpenCL v2.0, s6.13.17 - Enqueue kernel function.
-  // It contains four 
diff erent overload formats specified in Table 6.13.17.1.
+  // Table 6.13.17.1 specifies four overload forms of enqueue_kernel.
+  // The code below expands the builtin call to a call to one of the following
+  // functions that an OpenCL runtime library will have to provide:
+  //   __enqueue_kernel_basic
+  //   __enqueue_kernel_varargs
+  //   __enqueue_kernel_basic_events
+  //   __enqueue_kernel_events_varargs
   case Builtin::BIenqueue_kernel: {
 StringRef Name; // Generated function call name
 unsigned NumArgs = E->getNumArgs();



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


[clang] [OpenCL] Fix BIenqueue_kernel fallthrough (PR #83238)

2024-02-28 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh created 
https://github.com/llvm/llvm-project/pull/83238

Handling of the `BIenqueue_kernel` builtin must not fallthrough to the 
`BIget_kernel_work_group_size` builtin, as these builtins have no common 
functionality.

>From a7375b651a2ec392e0edf4cbe3658981f56ea67a Mon Sep 17 00:00:00 2001
From: Sven van Haastregt 
Date: Wed, 28 Feb 2024 08:37:22 +
Subject: [PATCH] [OpenCL] Fix BIenqueue_kernel fallthrough

Handling of the `BIenqueue_kernel` builtin must not fallthrough to
the `BIget_kernel_work_group_size` builtin, as these builtins have
no common functionality.
---
 clang/lib/CodeGen/CGBuiltin.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2d16e7cdc06053..7a42174d7ec692 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5640,7 +5640,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 EmitLifetimeEnd(TmpSize, TmpPtr);
   return Call;
 }
-[[fallthrough]];
+llvm_unreachable("Unexpected enqueue_kernel signature");
   }
   // OpenCL v2.0 s6.13.17.6 - Kernel query functions need bitcast of block
   // parameter.

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


[clang] [clang] Use CPlusPlus language option instead of Bool (PR #80975)

2024-02-08 Thread Sven van Haastregt via cfe-commits

https://github.com/svenvh approved this pull request.

The side-effect on OpenCL looks good to me; thanks!

https://github.com/llvm/llvm-project/pull/80975
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 7f00389 - [OpenCL] Fix grammar in test error messages; NFC

2023-08-07 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-08-07T13:45:23+01:00
New Revision: 7f00389e7792d585cdda615324ebc094fa3c4247

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

LOG: [OpenCL] Fix grammar in test error messages; NFC

Added: 


Modified: 
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index 15b52ec04e667b..7c4c673cf2ee07 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -233,46 +233,46 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #error "Incorrect cl_ext_float_atomics define"
 #endif
 #ifdef __opencl_c_ext_fp16_global_atomic_load_store
-#error "Incorrectly __opencl_c_ext_fp16_global_atomic_load_store defined"
+#error "Incorrect __opencl_c_ext_fp16_global_atomic_load_store define"
 #endif
 #ifdef __opencl_c_ext_fp16_local_atomic_load_store
-#error "Incorrectly __opencl_c_ext_fp16_local_atomic_load_store defined"
+#error "Incorrect __opencl_c_ext_fp16_local_atomic_load_store define"
 #endif
 #ifdef __opencl_c_ext_fp16_global_atomic_add
-#error "Incorrectly __opencl_c_ext_fp16_global_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp16_global_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp32_global_atomic_add
-#error "Incorrectly __opencl_c_ext_fp32_global_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp32_global_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp64_global_atomic_add
-#error "Incorrectly __opencl_c_ext_fp64_global_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp64_global_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp16_local_atomic_add
-#error "Incorrectly __opencl_c_ext_fp16_local_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp16_local_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp32_local_atomic_add
-#error "Incorrectly __opencl_c_ext_fp32_local_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp32_local_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp64_local_atomic_add
-#error "Incorrectly __opencl_c_ext_fp64_local_atomic_add defined"
+#error "Incorrect __opencl_c_ext_fp64_local_atomic_add define"
 #endif
 #ifdef __opencl_c_ext_fp16_global_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp16_global_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp16_global_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp32_global_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp32_global_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp32_global_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp64_global_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp64_global_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp64_global_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp16_local_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp16_local_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp16_local_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp32_local_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp32_local_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp32_local_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
-#error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
+#error "Incorrect __opencl_c_ext_fp64_local_atomic_min_max define"
 #endif
 #ifdef __opencl_c_ext_image_raw10_raw12
 #error "Incorrect __opencl_c_ext_image_raw10_raw12 define"



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


[clang] 5e8b44c - [OpenCL] Add cl_ext_image_raw10_raw12 extension

2023-07-26 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-07-26T11:59:12+01:00
New Revision: 5e8b44cc447e9b901c8168825f0c77491d9111e8

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

LOG: [OpenCL] Add cl_ext_image_raw10_raw12 extension

Add the defines for the `cl_ext_image_raw10_raw12` extension.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index af3deae892c7c9..2494f6213fc569 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -45,6 +45,7 @@
 #define __opencl_c_ext_fp32_local_atomic_add 1
 #define __opencl_c_ext_fp32_global_atomic_min_max 1
 #define __opencl_c_ext_fp32_local_atomic_min_max 1
+#define __opencl_c_ext_image_raw10_raw12 1
 
 #endif // defined(__SPIR__) || defined(__SPIRV__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
@@ -477,6 +478,10 @@ typedef enum memory_order
 #if __OPENCL_C_VERSION__ >= CL_VERSION_3_0
 #define CLK_UNORM_INT_101010_2 0x10E0
 #endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+#ifdef __opencl_c_ext_image_raw10_raw12
+#define CLK_UNSIGNED_INT_RAW10_EXT 0x10E3
+#define CLK_UNSIGNED_INT_RAW12_EXT 0x10E4
+#endif // __opencl_c_ext_image_raw10_raw12
 
 // Channel order, numbering must be aligned with cl_channel_order in cl.h
 //

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index 8242798106ac30..15b52ec04e667b 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -187,6 +187,9 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #if __opencl_c_ext_fp64_local_atomic_min_max != 1
 #error "Incorrectly defined __opencl_c_ext_fp64_local_atomic_min_max"
 #endif
+#if __opencl_c_ext_image_raw10_raw12 != 1
+#error "Incorrectly defined __opencl_c_ext_image_raw10_raw12"
+#endif
 
 #else
 
@@ -271,6 +274,9 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #ifdef __opencl_c_ext_fp64_local_atomic_min_max
 #error "Incorrectly __opencl_c_ext_fp64_local_atomic_min_max defined"
 #endif
+#ifdef __opencl_c_ext_image_raw10_raw12
+#error "Incorrect __opencl_c_ext_image_raw10_raw12 define"
+#endif
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 



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


[clang] 5952664 - [OpenCL] Add CLK_UNORM_INT_101010_2 channel type

2023-06-01 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-06-01T16:21:54+01:00
New Revision: 595266456a3067f522081d6d8069df2a98adfa16

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

LOG: [OpenCL] Add CLK_UNORM_INT_101010_2 channel type

This new channel data type was added in OpenCL C 3.0.

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index fad2f9c0272bf..af3deae892c7c 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -474,6 +474,9 @@ typedef enum memory_order
 #define CLK_HALF_FLOAT0x10DD
 #define CLK_FLOAT 0x10DE
 #define CLK_UNORM_INT24   0x10DF
+#if __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+#define CLK_UNORM_INT_101010_2 0x10E0
+#endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0
 
 // Channel order, numbering must be aligned with cl_channel_order in cl.h
 //



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


[clang] f454a7c - [OpenCL] Emit EOL at end of generated header

2023-03-24 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-03-24T11:03:10Z
New Revision: f454a7c6853def66c4f3a68bd2a0520489f6833c

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

LOG: [OpenCL] Emit EOL at end of generated header

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 79022ce67232a..1c3b7e4398a8c 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -1328,7 +1328,7 @@ void OpenCLBuiltinHeaderEmitter::emit() {
   }
 
   OS << "\n// Disable any extensions we may have enabled previously.\n"
-"#pragma OPENCL EXTENSION all : disable";
+"#pragma OPENCL EXTENSION all : disable\n";
 }
 
 void clang::EmitClangOpenCLBuiltins(RecordKeeper , raw_ostream ) {



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


[clang] 4cb843d - [OpenCL] Add builtin header TableGen emitter

2023-03-09 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-03-09T10:20:04Z
New Revision: 4cb843d099422e5d77d0f7e16cbb18ee64d457a5

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

LOG: [OpenCL] Add builtin header TableGen emitter

Add an emitter to produce something similar to opencl-c.h from the
OpenCL builtin descriptions in OpenCLBuiltins.td

This only adds the emitter, without any direct use of it.  This allows
opencl-c.h additions to be generated from the builtin descriptions by
manually invoking `clang-tblgen -gen-clang-opencl-builtin-header`.

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

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
clang/utils/TableGen/TableGen.cpp
clang/utils/TableGen/TableGenBackends.h

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index da5d1fdc2eae3..c3ffa3f72f76d 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -324,6 +324,18 @@ class OpenCLBuiltinTestEmitter : public 
OpenCLBuiltinFileEmitterBase {
   void emit() override;
 };
 
+// OpenCL builtin header generator.  This class processes the same TableGen
+// input as BuiltinNameEmitter, but generates a .h file that contains a
+// prototype for each builtin function described in the .td input.
+class OpenCLBuiltinHeaderEmitter : public OpenCLBuiltinFileEmitterBase {
+public:
+  OpenCLBuiltinHeaderEmitter(RecordKeeper , raw_ostream )
+  : OpenCLBuiltinFileEmitterBase(Records, OS) {}
+
+  // Entrypoint to generate the header.
+  void emit() override;
+};
+
 } // namespace
 
 void BuiltinNameEmitter::Emit() {
@@ -1260,11 +1272,76 @@ void OpenCLBuiltinTestEmitter::emit() {
   }
 }
 
+void OpenCLBuiltinHeaderEmitter::emit() {
+  emitSourceFileHeader("OpenCL Builtin declarations", OS);
+
+  emitExtensionSetup();
+
+  OS << R"(
+#define __ovld __attribute__((overloadable))
+#define __conv __attribute__((convergent))
+#define __purefn __attribute__((pure))
+#define __cnfn __attribute__((const))
+
+)";
+
+  // Iterate over all builtins; sort to follow order of definition in .td file.
+  std::vector Builtins = Records.getAllDerivedDefinitions("Builtin");
+  llvm::sort(Builtins, LessRecord());
+
+  for (const auto *B : Builtins) {
+StringRef Name = B->getValueAsString("Name");
+
+std::string OptionalExtensionEndif = emitExtensionGuard(B);
+std::string OptionalVersionEndif = emitVersionGuard(B);
+
+SmallVector, 4> FTypes;
+expandTypesInSignature(B->getValueAsListOfDefs("Signature"), FTypes);
+
+for (const auto  : FTypes) {
+  StringRef OptionalTypeExtEndif = emitTypeExtensionGuards(Signature);
+
+  // Emit function declaration.
+  OS << Signature[0] << " __ovld ";
+  if (B->getValueAsBit("IsConst"))
+OS << "__cnfn ";
+  if (B->getValueAsBit("IsPure"))
+OS << "__purefn ";
+  if (B->getValueAsBit("IsConv"))
+OS << "__conv ";
+
+  OS << Name << "(";
+  if (Signature.size() > 1) {
+for (unsigned I = 1; I < Signature.size(); I++) {
+  if (I != 1)
+OS << ", ";
+  OS << Signature[I];
+}
+  }
+  OS << ");\n";
+
+  OS << OptionalTypeExtEndif;
+}
+
+OS << OptionalVersionEndif;
+OS << OptionalExtensionEndif;
+  }
+
+  OS << "\n// Disable any extensions we may have enabled previously.\n"
+"#pragma OPENCL EXTENSION all : disable";
+}
+
 void clang::EmitClangOpenCLBuiltins(RecordKeeper , raw_ostream ) {
   BuiltinNameEmitter NameChecker(Records, OS);
   NameChecker.Emit();
 }
 
+void clang::EmitClangOpenCLBuiltinHeader(RecordKeeper ,
+ raw_ostream ) {
+  OpenCLBuiltinHeaderEmitter HeaderFileGenerator(Records, OS);
+  HeaderFileGenerator.emit();
+}
+
 void clang::EmitClangOpenCLBuiltinTests(RecordKeeper ,
 raw_ostream ) {
   OpenCLBuiltinTestEmitter TestFileGenerator(Records, OS);

diff  --git a/clang/utils/TableGen/TableGen.cpp 
b/clang/utils/TableGen/TableGen.cpp
index 6864ba2040ef9..a67e1d1af5d75 100644
--- a/clang/utils/TableGen/TableGen.cpp
+++ b/clang/utils/TableGen/TableGen.cpp
@@ -65,6 +65,7 @@ enum ActionType {
   GenClangCommentCommandInfo,
   GenClangCommentCommandList,
   GenClangOpenCLBuiltins,
+  GenClangOpenCLBuiltinHeader,
   GenClangOpenCLBuiltinTests,
   GenArmNeon,
   GenArmFP16,
@@ -200,6 +201,9 @@ cl::opt Action(
"documentation comments"),
 clEnumValN(GenClangOpenCLBuiltins, "gen-clang-opencl-builtins",
"Generate OpenCL builtin declaration handlers"),
+clEnumValN(GenClangOpenCLBuiltinHeader,
+   

[clang] 1495210 - [OpenCL] Always add nounwind attribute for OpenCL

2023-01-20 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-01-20T12:01:22Z
New Revision: 1495210914997bcd0ca6937be0ae3cd6809b5ef5

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

LOG: [OpenCL] Always add nounwind attribute for OpenCL

Neither OpenCL nor C++ for OpenCL support exceptions, so add the
`nounwind` attribute unconditionally for those languages.

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

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
clang/test/CodeGenOpenCL/convergent.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 276d91fa2758d..dfa552161d7ca 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1969,11 +1969,11 @@ void 
CodeGenModule::getDefaultFunctionAttributes(StringRef Name,
 FuncAttrs.addAttribute(llvm::Attribute::Convergent);
   }
 
-  // TODO: NoUnwind attribute should be added for other GPU modes OpenCL, HIP,
+  // TODO: NoUnwind attribute should be added for other GPU modes HIP,
   // SYCL, OpenMP offload. AFAIK, none of them support exceptions in device
   // code.
-  if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice) {
-// Exceptions aren't supported in CUDA device code.
+  if ((getLangOpts().CUDA && getLangOpts().CUDAIsDevice) ||
+  getLangOpts().OpenCL) {
 FuncAttrs.addAttribute(llvm::Attribute::NoUnwind);
   }
 

diff  --git a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl 
b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
index 210014d14c086..4277dbbc20530 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -298,7 +298,7 @@ kernel void test(global char *a, char b, global long *c, 
long d) {
 // CHECK: attributes #2 = { nocallback nofree nounwind willreturn 
memory(argmem: readwrite) }
 // CHECK: attributes #3 = { convergent noinline nounwind optnone 
"no-trapping-math"="true" "stack-protector-buffer-size"="8" 
"target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64"
 }
 // CHECK: attributes #4 = { nounwind "enqueued-block" }
-// CHECK: attributes #5 = { convergent }
+// CHECK: attributes #5 = { convergent nounwind }
 //.
 // CHECK: !0 = !{i32 1, !"amdgpu_code_object_version", i32 400}
 // CHECK: !1 = !{i32 1, !"wchar_size", i32 4}

diff  --git a/clang/test/CodeGenOpenCL/convergent.cl 
b/clang/test/CodeGenOpenCL/convergent.cl
index f764cf0fc782d..123adba7b40d2 100644
--- a/clang/test/CodeGenOpenCL/convergent.cl
+++ b/clang/test/CodeGenOpenCL/convergent.cl
@@ -139,4 +139,5 @@ kernel void assume_convergent_asm()
 // CHECK: attributes #3 = { {{[^}]*}}convergent noduplicate{{[^}]*}} }
 // CHECK: attributes #4 = { {{[^}]*}}convergent{{[^}]*}} }
 // CHECK: attributes #5 = { {{[^}]*}}convergent{{[^}]*}} }
-// CHECK: attributes #6 = { {{[^}]*}}convergent noduplicate{{[^}]*}} }
+// CHECK: attributes #6 = { {{[^}]*}}nounwind{{[^}]*}} }
+// CHECK: attributes #7 = { {{[^}]*}}convergent noduplicate nounwind{{[^}]*}} }



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


[clang] a60b8f4 - [OpenCL] Allow undefining header-only features

2023-01-16 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2023-01-16T11:32:12Z
New Revision: a60b8f468119065f8a6cb4a16598263cb00de0b5

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

LOG: [OpenCL] Allow undefining header-only features

`opencl-c-base.h` always defines 5 particular feature macros for
SPIR-V, making it impossible to disable those features.

To allow disabling any of those features, let the header recognize
`__undef_` macros.  The user can then pass the
`-D__undef_` flag on the command line to disable a specific
feature.  The __undef macro could potentially also be set from
`-cl-ext=-feature`, but for now only change the header and only
provide __undef macros for the 5 features that are always enabled in
`opencl-c-base.h`.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/test/SemaOpenCL/features.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index c433b4f7eb1af..fad2f9c0272bf 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -74,6 +74,25 @@
 #define __opencl_c_atomic_scope_all_devices 1
 #define __opencl_c_read_write_images 1
 #endif // defined(__SPIR__)
+
+// Undefine any feature macros that have been explicitly disabled using
+// an __undef_ macro.
+#ifdef __undef___opencl_c_work_group_collective_functions
+#undef __opencl_c_work_group_collective_functions
+#endif
+#ifdef __undef___opencl_c_atomic_order_seq_cst
+#undef __opencl_c_atomic_order_seq_cst
+#endif
+#ifdef __undef___opencl_c_atomic_scope_device
+#undef __opencl_c_atomic_scope_device
+#endif
+#ifdef __undef___opencl_c_atomic_scope_all_devices
+#undef __opencl_c_atomic_scope_all_devices
+#endif
+#ifdef __undef___opencl_c_read_write_images
+#undef __opencl_c_read_write_images
+#endif
+
 #endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
 
 #if !defined(__opencl_c_generic_address_space)

diff  --git a/clang/test/SemaOpenCL/features.cl 
b/clang/test/SemaOpenCL/features.cl
index af058b5e69828..3f59b4ea3b5ae 100644
--- a/clang/test/SemaOpenCL/features.cl
+++ b/clang/test/SemaOpenCL/features.cl
@@ -26,6 +26,15 @@
 // RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=clc++1.0 \
 // RUN:   | FileCheck -match-full-lines %s  --check-prefix=NO-FEATURES
 
+// For OpenCL C 3.0, header-only features can be disabled using macros.
+// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl 
-cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header \
+// RUN:-D__undef___opencl_c_work_group_collective_functions=1 \
+// RUN:-D__undef___opencl_c_atomic_order_seq_cst=1 \
+// RUN:-D__undef___opencl_c_atomic_scope_device=1 \
+// RUN:-D__undef___opencl_c_atomic_scope_all_devices=1 \
+// RUN:-D__undef___opencl_c_read_write_images=1 \
+// RUN:   | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
+
 // Note that __opencl_c_int64 is always defined assuming
 // always compiling for FULL OpenCL profile
 
@@ -43,14 +52,20 @@
 // FEATURES: #define __opencl_c_subgroups 1
 
 // NO-FEATURES: #define __opencl_c_int64 1
-// NO-FEATURES-NOT: __opencl_c_3d_image_writes
-// NO-FEATURES-NOT: __opencl_c_atomic_order_acq_rel
-// NO-FEATURES-NOT: __opencl_c_atomic_order_seq_cst
-// NO-FEATURES-NOT: __opencl_c_device_enqueue
-// NO-FEATURES-NOT: __opencl_c_fp64
-// NO-FEATURES-NOT: __opencl_c_generic_address_space
-// NO-FEATURES-NOT: __opencl_c_images
-// NO-FEATURES-NOT: __opencl_c_pipes
-// NO-FEATURES-NOT: __opencl_c_program_scope_global_variables
-// NO-FEATURES-NOT: __opencl_c_read_write_images
-// NO-FEATURES-NOT: __opencl_c_subgroups
+// NO-FEATURES-NOT: #define __opencl_c_3d_image_writes
+// NO-FEATURES-NOT: #define __opencl_c_atomic_order_acq_rel
+// NO-FEATURES-NOT: #define __opencl_c_atomic_order_seq_cst
+// NO-FEATURES-NOT: #define __opencl_c_device_enqueue
+// NO-FEATURES-NOT: #define __opencl_c_fp64
+// NO-FEATURES-NOT: #define __opencl_c_generic_address_space
+// NO-FEATURES-NOT: #define __opencl_c_images
+// NO-FEATURES-NOT: #define __opencl_c_pipes
+// NO-FEATURES-NOT: #define __opencl_c_program_scope_global_variables
+// NO-FEATURES-NOT: #define __opencl_c_read_write_images
+// NO-FEATURES-NOT: #define __opencl_c_subgroups
+
+// NO-HEADERONLY-FEATURES-NOT: #define 
__opencl_c_work_group_collective_functions
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_atomic_order_seq_cst
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_atomic_scope_device
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_atomic_scope_all_devices
+// NO-HEADERONLY-FEATURES-NOT: #define __opencl_c_read_write_images



___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[clang] b0e4897 - [OpenCL] Remove arm-integer-dot-product extension pragmas

2022-11-29 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-11-29T13:26:50Z
New Revision: b0e4897a1bd2ea5eeeb8c104e32df1402a397ac1

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

LOG: [OpenCL] Remove arm-integer-dot-product extension pragmas

This extension only adds builtin functions and thus doesn't need to be
included as an extension.  Instead of a pragma, the builtin functions
of the extension can be exposed through enabling preprocessor defines.

Added: 


Modified: 
clang/include/clang/Basic/OpenCLExtensions.def
clang/test/CodeGenOpenCL/arm-integer-dot-product.cl

Removed: 




diff  --git a/clang/include/clang/Basic/OpenCLExtensions.def 
b/clang/include/clang/Basic/OpenCLExtensions.def
index a053a0e9adb5..70b4f15a95a7 100644
--- a/clang/include/clang/Basic/OpenCLExtensions.def
+++ b/clang/include/clang/Basic/OpenCLExtensions.def
@@ -94,12 +94,6 @@ OPENCL_EXTENSION(__cl_clang_bitfields, true, 100)
 OPENCL_EXTENSION(cl_amd_media_ops, true, 100)
 OPENCL_EXTENSION(cl_amd_media_ops2, true, 100)
 
-// ARM OpenCL extensions
-OPENCL_EXTENSION(cl_arm_integer_dot_product_int8, true, 120)
-OPENCL_EXTENSION(cl_arm_integer_dot_product_accumulate_int8, true, 120)
-OPENCL_EXTENSION(cl_arm_integer_dot_product_accumulate_int16, true, 120)
-OPENCL_EXTENSION(cl_arm_integer_dot_product_accumulate_saturate_int8, true, 
120)
-
 // Intel OpenCL extensions
 OPENCL_EXTENSION(cl_intel_subgroups, true, 120)
 OPENCL_EXTENSION(cl_intel_subgroups_short, true, 120)

diff  --git a/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl 
b/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
index c98615c5dd98..e3172f28afd7 100644
--- a/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
+++ b/clang/test/CodeGenOpenCL/arm-integer-dot-product.cl
@@ -1,6 +1,12 @@
 // RUN: %clang_cc1 %s -triple spir-unknown-unknown -finclude-default-header 
-fdeclare-opencl-builtins -cl-std=CL1.2 -emit-llvm -o - -O0 | FileCheck %s
 
 // Pragmas are only accepted for backward compatibility.
+// The builtins are made available with the following defines.
+
+#define cl_arm_integer_dot_product_int8 1
+#define cl_arm_integer_dot_product_accumulate_int8 1
+#define cl_arm_integer_dot_product_accumulate_int16 1
+#define cl_arm_integer_dot_product_accumulate_saturate_int8 1
 
 #pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : enable
 #pragma OPENCL EXTENSION cl_arm_integer_dot_product_int8 : disable



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


[clang] 0f4f246 - [OpenCL] Guard read_write image3d with cl_khr_3d_image_writes

2022-11-09 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-11-09T13:17:59Z
New Revision: 0f4f246783fa5866f6fa5db4043e898060cdf98d

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

LOG: [OpenCL] Guard read_write image3d with cl_khr_3d_image_writes

Not all `read_write image3d_t` occurrences in opencl-c.h were guarded
with `cl_khr_3d_image_writes`.  Align with `-fdeclare-opencl-builtins`.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 2afe0231cd74b..288bb18bc654e 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15388,9 +15388,11 @@ float4 __ovld __purefn read_imagef(read_write 
image2d_array_t, int4);
 int4 __ovld __purefn read_imagei(read_write image2d_array_t, int4);
 uint4 __ovld __purefn read_imageui(read_write image2d_array_t, int4);
 
+#ifdef cl_khr_3d_image_writes
 float4 __ovld __purefn read_imagef(read_write image3d_t, int4);
 int4 __ovld __purefn read_imagei(read_write image3d_t, int4);
 uint4 __ovld __purefn read_imageui(read_write image3d_t, int4);
+#endif // cl_khr_3d_image_writes
 
 #ifdef cl_khr_depth_images
 float __ovld __purefn read_imagef(read_write image2d_depth_t, int2);
@@ -15431,9 +15433,11 @@ uint4 __ovld __purefn read_imageui(read_write 
image2d_array_t, sampler_t, float4
 
 float __ovld __purefn read_imagef(read_write image2d_array_depth_t, sampler_t, 
float4, float);
 
+#ifdef cl_khr_3d_image_writes
 float4 __ovld __purefn read_imagef(read_write image3d_t, sampler_t, float4, 
float);
 int4 __ovld __purefn read_imagei(read_write image3d_t, sampler_t, float4, 
float);
 uint4 __ovld __purefn read_imageui(read_write image3d_t, sampler_t, float4, 
float);
+#endif // cl_khr_3d_image_writes
 
 float4 __ovld __purefn read_imagef(read_write image1d_t, sampler_t, float, 
float, float);
 int4 __ovld __purefn read_imagei(read_write image1d_t, sampler_t, float, 
float, float);
@@ -15455,9 +15459,11 @@ uint4 __ovld __purefn read_imageui(read_write 
image2d_array_t, sampler_t, float4
 
 float __ovld __purefn read_imagef(read_write image2d_array_depth_t, sampler_t, 
float4, float2, float2);
 
+#ifdef cl_khr_3d_image_writes
 float4 __ovld __purefn read_imagef(read_write image3d_t, sampler_t, float4, 
float4, float4);
 int4 __ovld __purefn read_imagei(read_write image3d_t, sampler_t, float4, 
float4, float4);
 uint4 __ovld __purefn read_imageui(read_write image3d_t, sampler_t, float4, 
float4, float4);
+#endif // cl_khr_3d_image_writes
 
 #endif //cl_khr_mipmap_image
 
@@ -15465,7 +15471,9 @@ uint4 __ovld __purefn read_imageui(read_write 
image3d_t, sampler_t, float4, floa
 #ifdef cl_khr_fp16
 half4 __ovld __purefn read_imageh(read_write image1d_t, int);
 half4 __ovld __purefn read_imageh(read_write image2d_t, int2);
+#ifdef cl_khr_3d_image_writes
 half4 __ovld __purefn read_imageh(read_write image3d_t, int4);
+#endif // cl_khr_3d_image_writes
 half4 __ovld __purefn read_imageh(read_write image1d_array_t, int2);
 half4 __ovld __purefn read_imageh(read_write image2d_array_t, int4);
 half4 __ovld __purefn read_imageh(read_write image1d_buffer_t, int);
@@ -15735,7 +15743,9 @@ int __ovld __cnfn get_image_width(write_only 
image2d_array_msaa_depth_t);
 int __ovld __cnfn get_image_width(read_write image1d_t);
 int __ovld __cnfn get_image_width(read_write image1d_buffer_t);
 int __ovld __cnfn get_image_width(read_write image2d_t);
+#ifdef cl_khr_3d_image_writes
 int __ovld __cnfn get_image_width(read_write image3d_t);
+#endif // cl_khr_3d_image_writes
 int __ovld __cnfn get_image_width(read_write image1d_array_t);
 int __ovld __cnfn get_image_width(read_write image2d_array_t);
 #ifdef cl_khr_depth_images
@@ -15785,7 +15795,9 @@ int __ovld __cnfn get_image_height(write_only 
image2d_array_msaa_depth_t);
 
 #if defined(__opencl_c_read_write_images)
 int __ovld __cnfn get_image_height(read_write image2d_t);
+#ifdef cl_khr_3d_image_writes
 int __ovld __cnfn get_image_height(read_write image3d_t);
+#endif // cl_khr_3d_image_writes
 int __ovld __cnfn get_image_height(read_write image2d_array_t);
 #ifdef cl_khr_depth_images
 int __ovld __cnfn get_image_height(read_write image2d_depth_t);
@@ -15806,11 +15818,11 @@ int __ovld __cnfn get_image_depth(read_only 
image3d_t);
 
 #ifdef cl_khr_3d_image_writes
 int __ovld __cnfn get_image_depth(write_only image3d_t);
-#endif
 
 #if defined(__opencl_c_read_write_images)
 int __ovld __cnfn get_image_depth(read_write image3d_t);
 #endif //defined(__opencl_c_read_write_images)
+#endif // cl_khr_3d_image_writes
 
 // OpenCL Extension v2.0 s9.18 - Mipmaps
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
@@ -15832,7 +15844,9 @@ int __ovld get_image_num_mip_levels(write_only 
image3d_t);
 #if 

[clang] 5a7764c - [OpenCL] Guard depth image builtins

2022-09-13 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-09-13T10:10:48+01:00
New Revision: 5a7764c9ff5db8c460b52bc2dec95d19df44d4c8

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

LOG: [OpenCL] Guard depth image builtins

Ensure any uses of `image2d_depth_t` and `image2d_array_depth_t` are
guarded behind the `cl_khr_depth_images` extension in
`OpenCLBuiltins.td`.

Fix a few missing guards in `opencl-c.h`.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 8499ee0120da..2afe0231cd74 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15257,13 +15257,17 @@ float4 __ovld __purefn read_imagef(read_only 
image2d_t, sampler_t, float2, float
 int4 __ovld __purefn read_imagei(read_only image2d_t, sampler_t, float2, 
float);
 uint4 __ovld __purefn read_imageui(read_only image2d_t, sampler_t, float2, 
float);
 
+#ifdef cl_khr_depth_images
 float __ovld __purefn read_imagef(read_only image2d_depth_t, sampler_t, 
float2, float);
+#endif // cl_khr_depth_images
 
 float4 __ovld __purefn read_imagef(read_only image2d_array_t, sampler_t, 
float4, float);
 int4 __ovld __purefn read_imagei(read_only image2d_array_t, sampler_t, float4, 
float);
 uint4 __ovld __purefn read_imageui(read_only image2d_array_t, sampler_t, 
float4, float);
 
+#ifdef cl_khr_depth_images
 float __ovld __purefn read_imagef(read_only image2d_array_depth_t, sampler_t, 
float4, float);
+#endif // cl_khr_depth_images
 
 float4 __ovld __purefn read_imagef(read_only image3d_t, sampler_t, float4, 
float);
 int4 __ovld __purefn read_imagei(read_only image3d_t, sampler_t, float4, 
float);
@@ -15281,13 +15285,17 @@ float4 __ovld __purefn read_imagef(read_only 
image2d_t, sampler_t, float2, float
 int4 __ovld __purefn read_imagei(read_only image2d_t, sampler_t, float2, 
float2, float2);
 uint4 __ovld __purefn read_imageui(read_only image2d_t, sampler_t, float2, 
float2, float2);
 
+#ifdef cl_khr_depth_images
 float __ovld __purefn read_imagef(read_only image2d_depth_t, sampler_t, 
float2, float2, float2);
+#endif // cl_khr_depth_images
 
 float4 __ovld __purefn read_imagef(read_only image2d_array_t, sampler_t, 
float4, float2, float2);
 int4 __ovld __purefn read_imagei(read_only image2d_array_t, sampler_t, float4, 
float2, float2);
 uint4 __ovld __purefn read_imageui(read_only image2d_array_t, sampler_t, 
float4, float2, float2);
 
+#ifdef cl_khr_depth_images
 float __ovld __purefn read_imagef(read_only image2d_array_depth_t, sampler_t, 
float4, float2, float2);
+#endif // cl_khr_depth_images
 
 float4 __ovld __purefn read_imagef(read_only image3d_t, sampler_t, float4, 
float4, float4);
 int4 __ovld __purefn read_imagei(read_only image3d_t, sampler_t, float4, 
float4, float4);
@@ -15829,19 +15837,25 @@ int __ovld get_image_num_mip_levels(read_write 
image3d_t);
 
 int __ovld get_image_num_mip_levels(read_only image1d_array_t);
 int __ovld get_image_num_mip_levels(read_only image2d_array_t);
+#ifdef cl_khr_depth_images
 int __ovld get_image_num_mip_levels(read_only image2d_array_depth_t);
 int __ovld get_image_num_mip_levels(read_only image2d_depth_t);
+#endif // cl_khr_depth_images
 
 int __ovld get_image_num_mip_levels(write_only image1d_array_t);
 int __ovld get_image_num_mip_levels(write_only image2d_array_t);
+#ifdef cl_khr_depth_images
 int __ovld get_image_num_mip_levels(write_only image2d_array_depth_t);
 int __ovld get_image_num_mip_levels(write_only image2d_depth_t);
+#endif // cl_khr_depth_images
 
 #if defined(__opencl_c_read_write_images)
 int __ovld get_image_num_mip_levels(read_write image1d_array_t);
 int __ovld get_image_num_mip_levels(read_write image2d_array_t);
+#ifdef cl_khr_depth_images
 int __ovld get_image_num_mip_levels(read_write image2d_array_depth_t);
 int __ovld get_image_num_mip_levels(read_write image2d_depth_t);
+#endif // cl_khr_depth_images
 #endif //defined(__opencl_c_read_write_images)
 
 #endif //cl_khr_mipmap_image

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index dc158454556a..0cceba090bd8 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -246,6 +246,7 @@ class ImageType :
   let Extension = !cond(
   !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "WO")) : 
TypeExtension<"cl_khr_3d_image_writes">,
   !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "RW")) : 
TypeExtension<"cl_khr_3d_image_writes __opencl_c_read_write_images">,
+  !or(!eq(_Ty.Name, "image2d_depth_t"), !eq(_Ty.Name, 
"image2d_array_depth_t")) : TypeExtension<"cl_khr_depth_images">,
   !eq(_AccessQualifier, "RW") : 
TypeExtension<"__opencl_c_read_write_images">,
   true : 

[clang] f2c17a1 - [OpenCL] Remove argument names from atomic/fence builtins

2022-09-06 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-09-06T10:50:57+01:00
New Revision: f2c17a130a27cadd9d204bef09fd4ad64518c9da

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

LOG: [OpenCL] Remove argument names from atomic/fence builtins

This simplifies completeness comparisons against OpenCLBuiltins.td and
also makes the header no longer "claim" the argument name identifiers.

Continues the direction set out in D119560.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 5cadb488b06cd..8499ee0120da0 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -12396,11 +12396,11 @@ void __ovld vstorea_half16_rtn(double16, size_t, 
__private half *);
  * image objects and then want to read the updated data.
  */
 
-void __ovld __conv barrier(cl_mem_fence_flags flags);
+void __ovld __conv barrier(cl_mem_fence_flags);
 
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
-void __ovld __conv work_group_barrier(cl_mem_fence_flags flags, memory_scope);
-void __ovld __conv work_group_barrier(cl_mem_fence_flags flags);
+void __ovld __conv work_group_barrier(cl_mem_fence_flags, memory_scope);
+void __ovld __conv work_group_barrier(cl_mem_fence_flags);
 #endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
 
 // OpenCL v1.1 s6.11.9, v1.2 s6.12.9 - Explicit Memory Fence Functions
@@ -12418,7 +12418,7 @@ void __ovld __conv 
work_group_barrier(cl_mem_fence_flags flags);
  * CLK_LOCAL_MEM_FENCE
  * CLK_GLOBAL_MEM_FENCE.
  */
-void __ovld mem_fence(cl_mem_fence_flags flags);
+void __ovld mem_fence(cl_mem_fence_flags);
 
 /**
  * Read memory barrier that orders only
@@ -12430,7 +12430,7 @@ void __ovld mem_fence(cl_mem_fence_flags flags);
  * CLK_LOCAL_MEM_FENCE
  * CLK_GLOBAL_MEM_FENCE.
  */
-void __ovld read_mem_fence(cl_mem_fence_flags flags);
+void __ovld read_mem_fence(cl_mem_fence_flags);
 
 /**
  * Write memory barrier that orders only
@@ -12442,7 +12442,7 @@ void __ovld read_mem_fence(cl_mem_fence_flags flags);
  * CLK_LOCAL_MEM_FENCE
  * CLK_GLOBAL_MEM_FENCE.
  */
-void __ovld write_mem_fence(cl_mem_fence_flags flags);
+void __ovld write_mem_fence(cl_mem_fence_flags);
 
 // OpenCL v2.0 s6.13.9 - Address Space Qualifier Functions
 
@@ -12891,29 +12891,29 @@ void __ovld prefetch(const __global half16 *, size_t);
  * (old + val) and store result at location
  * pointed by p. The function returns old.
  */
-int __ovld atomic_add(volatile __global int *p, int val);
-uint __ovld atomic_add(volatile __global uint *p, uint val);
-int __ovld atomic_add(volatile __local int *p, int val);
-uint __ovld atomic_add(volatile __local uint *p, uint val);
+int __ovld atomic_add(volatile __global int *, int);
+uint __ovld atomic_add(volatile __global uint *, uint);
+int __ovld atomic_add(volatile __local int *, int);
+uint __ovld atomic_add(volatile __local uint *, uint);
 #ifdef __OPENCL_CPP_VERSION__
-int __ovld atomic_add(volatile int *p, int val);
-uint __ovld atomic_add(volatile uint *p, uint val);
+int __ovld atomic_add(volatile int *, int);
+uint __ovld atomic_add(volatile uint *, uint);
 #endif
 
 #if defined(cl_khr_global_int32_base_atomics)
-int __ovld atom_add(volatile __global int *p, int val);
-uint __ovld atom_add(volatile __global uint *p, uint val);
+int __ovld atom_add(volatile __global int *, int);
+uint __ovld atom_add(volatile __global uint *, uint);
 #endif
 #if defined(cl_khr_local_int32_base_atomics)
-int __ovld atom_add(volatile __local int *p, int val);
-uint __ovld atom_add(volatile __local uint *p, uint val);
+int __ovld atom_add(volatile __local int *, int);
+uint __ovld atom_add(volatile __local uint *, uint);
 #endif
 
 #if defined(cl_khr_int64_base_atomics)
-long __ovld atom_add(volatile __global long *p, long val);
-ulong __ovld atom_add(volatile __global ulong *p, ulong val);
-long __ovld atom_add(volatile __local long *p, long val);
-ulong __ovld atom_add(volatile __local ulong *p, ulong val);
+long __ovld atom_add(volatile __global long *, long);
+ulong __ovld atom_add(volatile __global ulong *, ulong);
+long __ovld atom_add(volatile __local long *, long);
+ulong __ovld atom_add(volatile __local ulong *, ulong);
 #endif
 
 /**
@@ -12921,29 +12921,29 @@ ulong __ovld atom_add(volatile __local ulong *p, 
ulong val);
  * Compute (old - val) and store result at location pointed by p. The function
  * returns old.
  */
-int __ovld atomic_sub(volatile __global int *p, int val);
-uint __ovld atomic_sub(volatile __global uint *p, uint val);
-int __ovld atomic_sub(volatile __local int *p, int val);
-uint __ovld atomic_sub(volatile __local uint *p, uint val);
+int __ovld atomic_sub(volatile __global int *, int);
+uint 

[clang] f8e658e - [OpenCL] Remove fast_ half geometric builtins

2022-07-05 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-07-05T10:22:34+01:00
New Revision: f8e658ec9ff5b82d0c1f9d54d78c137b539319ca

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

LOG: [OpenCL] Remove fast_ half geometric builtins

These are not mentioned in the OpenCL C Specification nor in the
OpenCL Extension Specification.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index ed647d9e9c064..72a6bfeafd6a2 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -10467,12 +10467,6 @@ float __ovld __cnfn fast_distance(float, float);
 float __ovld __cnfn fast_distance(float2, float2);
 float __ovld __cnfn fast_distance(float3, float3);
 float __ovld __cnfn fast_distance(float4, float4);
-#ifdef cl_khr_fp16
-half __ovld __cnfn fast_distance(half, half);
-half __ovld __cnfn fast_distance(half2, half2);
-half __ovld __cnfn fast_distance(half3, half3);
-half __ovld __cnfn fast_distance(half4, half4);
-#endif //cl_khr_fp16
 
 /**
  * Returns the length of vector p computed as:
@@ -10482,12 +10476,6 @@ float __ovld __cnfn fast_length(float);
 float __ovld __cnfn fast_length(float2);
 float __ovld __cnfn fast_length(float3);
 float __ovld __cnfn fast_length(float4);
-#ifdef cl_khr_fp16
-half __ovld __cnfn fast_length(half);
-half __ovld __cnfn fast_length(half2);
-half __ovld __cnfn fast_length(half3);
-half __ovld __cnfn fast_length(half4);
-#endif //cl_khr_fp16
 
 /**
  * Returns a vector in the same direction as p but with a
@@ -10514,12 +10502,6 @@ float __ovld __cnfn fast_normalize(float);
 float2 __ovld __cnfn fast_normalize(float2);
 float3 __ovld __cnfn fast_normalize(float3);
 float4 __ovld __cnfn fast_normalize(float4);
-#ifdef cl_khr_fp16
-half __ovld __cnfn fast_normalize(half);
-half2 __ovld __cnfn fast_normalize(half2);
-half3 __ovld __cnfn fast_normalize(half3);
-half4 __ovld __cnfn fast_normalize(half4);
-#endif //cl_khr_fp16
 
 // OpenCL v1.1 s6.11.6, v1.2 s6.12.6, v2.0 s6.13.6 - Relational Functions
 



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


[clang] 1d421e6 - [OpenCL] Remove half scalar vload/vstore builtins

2022-06-30 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-06-30T11:01:19+01:00
New Revision: 1d421e6e3b789ede2f61756a72e2b27456f868e3

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

LOG: [OpenCL] Remove half scalar vload/vstore builtins

These are not mentioned in the OpenCL C Specification nor in the
OpenCL Extension Specification.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 1942da77f5e50..ed647d9e9c064 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -11255,7 +11255,6 @@ double16 __ovld __purefn vload16(size_t, const 
__constant double *);
 #endif //cl_khr_fp64
 
 #ifdef cl_khr_fp16
-half __ovld __purefn vload(size_t, const __constant half *);
 half2 __ovld __purefn vload2(size_t, const __constant half *);
 half3 __ovld __purefn vload3(size_t, const __constant half *);
 half4 __ovld __purefn vload4(size_t, const __constant half *);
@@ -11319,7 +11318,6 @@ double16 __ovld __purefn vload16(size_t, const double 
*);
 #endif //cl_khr_fp64
 
 #ifdef cl_khr_fp16
-half __ovld __purefn vload(size_t, const half *);
 half2 __ovld __purefn vload2(size_t, const half *);
 half3 __ovld __purefn vload3(size_t, const half *);
 half4 __ovld __purefn vload4(size_t, const half *);
@@ -11484,19 +11482,16 @@ double16 __ovld __purefn vload16(size_t, const 
__private double *);
 #endif //cl_khr_fp64
 
 #ifdef cl_khr_fp16
-half __ovld __purefn vload(size_t, const __global half *);
 half2 __ovld __purefn vload2(size_t, const __global half *);
 half3 __ovld __purefn vload3(size_t, const __global half *);
 half4 __ovld __purefn vload4(size_t, const __global half *);
 half8 __ovld __purefn vload8(size_t, const __global half *);
 half16 __ovld __purefn vload16(size_t, const __global half *);
-half __ovld __purefn vload(size_t, const __local half *);
 half2 __ovld __purefn vload2(size_t, const __local half *);
 half3 __ovld __purefn vload3(size_t, const __local half *);
 half4 __ovld __purefn vload4(size_t, const __local half *);
 half8 __ovld __purefn vload8(size_t, const __local half *);
 half16 __ovld __purefn vload16(size_t, const __local half *);
-half __ovld __purefn vload(size_t, const __private half *);
 half2 __ovld __purefn vload2(size_t, const __private half *);
 half3 __ovld __purefn vload3(size_t, const __private half *);
 half4 __ovld __purefn vload4(size_t, const __private half *);
@@ -11559,7 +11554,6 @@ void __ovld vstore8(double8, size_t, double *);
 void __ovld vstore16(double16, size_t, double *);
 #endif //cl_khr_fp64
 #ifdef cl_khr_fp16
-void __ovld vstore(half, size_t, half *);
 void __ovld vstore2(half2, size_t, half *);
 void __ovld vstore3(half3, size_t, half *);
 void __ovld vstore4(half4, size_t, half *);
@@ -11722,19 +11716,16 @@ void __ovld vstore8(double8, size_t, __private double 
*);
 void __ovld vstore16(double16, size_t, __private double *);
 #endif //cl_khr_fp64
 #ifdef cl_khr_fp16
-void __ovld vstore(half, size_t, __global half *);
 void __ovld vstore2(half2, size_t, __global half *);
 void __ovld vstore3(half3, size_t, __global half *);
 void __ovld vstore4(half4, size_t, __global half *);
 void __ovld vstore8(half8, size_t, __global half *);
 void __ovld vstore16(half16, size_t, __global half *);
-void __ovld vstore(half, size_t, __local half *);
 void __ovld vstore2(half2, size_t, __local half *);
 void __ovld vstore3(half3, size_t, __local half *);
 void __ovld vstore4(half4, size_t, __local half *);
 void __ovld vstore8(half8, size_t, __local half *);
 void __ovld vstore16(half16, size_t, __local half *);
-void __ovld vstore(half, size_t, __private half *);
 void __ovld vstore2(half2, size_t, __private half *);
 void __ovld vstore3(half3, size_t, __private half *);
 void __ovld vstore4(half4, size_t, __private half *);



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


[clang] 663e47a - [OpenCL] Reduce emitting candidate notes for builtins

2022-06-27 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-06-27T09:55:44+01:00
New Revision: 663e47a50f50c9ff0da9ba805f804c06645638ed

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

LOG: [OpenCL] Reduce emitting candidate notes for builtins

When overload resolution fails, clang emits a note diagnostic for each
candidate.  For OpenCL builtins this often leads to many repeated note
diagnostics with no new information.  Stop emitting such notes.

Update a test that was relying on counting those notes to check how
many builtins are available for certain extension configurations.

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

Added: 


Modified: 
clang/lib/Sema/SemaOverload.cpp
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index c627d631714d5..c226ed6254790 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -11266,6 +11266,13 @@ static void NoteFunctionCandidate(Sema , 
OverloadCandidate *Cand,
   if (shouldSkipNotingLambdaConversionDecl(Fn))
 return;
 
+  // There is no physical candidate declaration to point to for OpenCL 
builtins.
+  // Except for failed conversions, the notes are identical for each candidate,
+  // so do not generate such notes.
+  if (S.getLangOpts().OpenCL && Fn->isImplicit() &&
+  Cand->FailureKind != ovl_fail_bad_conversion)
+return;
+
   // Note deleted candidates, but only if they're viable.
   if (Cand->Viable) {
 if (Fn->isDeleted()) {

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl 
b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index 737632fdf07b1..bf943a400320c 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -171,14 +171,14 @@ void test_atomic_fetch_with_address_space(volatile 
__generic atomic_float *a_flo
 // extension is disabled.  Test this by counting the number of notes about
 // candidate functions.
 void test_atomic_double_reporting(volatile __generic atomic_int *a) {
-  atomic_init(a);
+  atomic_init(a, a);
   // expected-error@-1{{no matching function for call to 'atomic_init'}}
 #if defined(NO_FP64)
   // Expecting 5 candidates: int, uint, long, ulong, float
-  // expected-note@-4 5 {{candidate function not viable: requires 2 arguments, 
but 1 was provided}}
+  // expected-note@-4 5 {{candidate function not viable: no known conversion}}
 #else
   // Expecting 6 candidates: int, uint, long, ulong, float, double
-  // expected-note@-7 6 {{candidate function not viable: requires 2 arguments, 
but 1 was provided}}
+  // expected-note@-7 6 {{candidate function not viable: no known conversion}}
 #endif
 }
 
@@ -198,7 +198,6 @@ void test_atomics_without_scope_device(volatile __generic 
atomic_int *a_int) {
 
   atomic_exchange_explicit(a_int, d, memory_order_seq_cst);
   // expected-error@-1{{no matching function for call to 
'atomic_exchange_explicit'}}
-  // expected-note@-2 + {{candidate function not viable}}
 
   atomic_exchange_explicit(a_int, d, memory_order_seq_cst, 
memory_scope_work_group);
 }
@@ -272,9 +271,7 @@ kernel void basic_image_readonly(read_only image2d_t 
image_read_only_image2d) {
   res = read_imageh(image_read_only_image2d, i2);
 #if __OPENCL_C_VERSION__ < CL_VERSION_1_2 && !defined(__OPENCL_CPP_VERSION__)
   // expected-error@-3{{no matching function for call to 'read_imagef'}}
-  // expected-note@-4 + {{candidate function not viable}}
-  // expected-error@-4{{no matching function for call to 'read_imageh'}}
-  // expected-note@-5 + {{candidate function not viable}}
+  // expected-error@-3{{no matching function for call to 'read_imageh'}}
 #endif
   res = read_imageh(image_read_only_image2d, sampler, i2);
 
@@ -304,7 +301,6 @@ kernel void basic_image_writeonly(write_only 
image1d_buffer_t image_write_only_i
   write_imagef(image3dwo, i4, i, f4);
 #if __OPENCL_C_VERSION__ <= CL_VERSION_1_2 && !defined(__OPENCL_CPP_VERSION__)
   // expected-error@-2{{no matching function for call to 'write_imagef'}}
-  // expected-note@-3 + {{candidate function not viable}}
 #endif
 }
 



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


[clang] 8c3fa31 - [OpenCL][TableGen] Fix type extension guard emission

2022-06-20 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-06-20T10:07:34+01:00
New Revision: 8c3fa31701c4b874138c52266e7ab96818092f47

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

LOG: [OpenCL][TableGen] Fix type extension guard emission

For certain cases (such as for the double subtype of AGenType), the
OpenCLBuiltinFileEmitterBase would not emit the extension #if-guard.
Fix that by looking at the extension of the actual type instead of the
argument type (which could be a GenType that does not carry any
extension information).

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index dca9970444a73..cddbd7b17c5f6 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -1082,7 +1082,7 @@ void OpenCLBuiltinFileEmitterBase::expandTypesInSignature(
 // If the type requires an extension, add a TypeExtMap entry mapping
 // the full type name to the extension.
 StringRef Ext =
-Arg->getValueAsDef("Extension")->getValueAsString("ExtName");
+Type->getValueAsDef("Extension")->getValueAsString("ExtName");
 if (!Ext.empty() && TypeExtMap.find(FullType) == TypeExtMap.end()) {
   TypeExtMap.insert({FullType, Ext});
 }



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


[clang] 2d9c891 - [OpenCL] Fix atomic_fetch_add/sub half overloads

2022-06-17 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-06-17T09:53:45+01:00
New Revision: 2d9c891cd949a4e6f15c35bd565b3d3588819e85

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

LOG: [OpenCL] Fix atomic_fetch_add/sub half overloads

Some of the atomic_fetch_add and atomic_fetch_sub overloads intended
for atomic_half types accidentally had an atomic_float parameter.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 75cea2ffc19c..dc158454556a 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1185,7 +1185,7 @@ let MinVersion = CL20 in {
   defvar extension_fp64 = 
!cast("FuncExtFloatAtomicsFp64" # addrspace # "Add");
 
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
-  [Half, PointerType, addrspace>, Half], 
extension_fp16>;
+  [Half, PointerType, addrspace>, Half], 
extension_fp16>;
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
   [Float, PointerType, addrspace>, Float], 
extension_fp32>;
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,



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


[clang] 7acc88b - [OpenCL] Reword unknown extension pragma diagnostic

2022-06-15 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-06-15T10:54:46+01:00
New Revision: 7acc88be0312c721bc082ed9934e381d297f4707

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

LOG: [OpenCL] Reword unknown extension pragma diagnostic

For newer OpenCL extensions that do not require a pragma, such as
`cl_khr_subgroup_shuffle`, a user could still accidentally attempt to
use a pragma.  This would result in a warning
  "unknown OpenCL extension 'cl_khr_subgroup_shuffle' - ignoring"
which could be mistakenly interpreted as "clang does not support this
extension at all" instead of "clang does not require any pragma for
this extension".

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/test/Headers/opencl-c-header.cl
clang/test/Parser/opencl-pragma.cl
clang/test/SemaOpenCL/extension-begin.cl
clang/test/SemaOpenCL/extension-version.cl

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index dd6bba720ce2..b0abe2aa517e 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -1278,7 +1278,7 @@ def warn_pragma_expected_colon : Warning<
 def warn_pragma_expected_predicate : Warning<
   "expected %select{'enable', 'disable', 'begin' or 'end'|'disable'}0 - 
ignoring">, InGroup;
 def warn_pragma_unknown_extension : Warning<
-  "unknown OpenCL extension %0 - ignoring">, InGroup;
+  "OpenCL extension %0 unknown or does not require pragma - ignoring">, 
InGroup;
 def warn_pragma_unsupported_extension : Warning<
   "unsupported OpenCL extension %0 - ignoring">, InGroup;
 def warn_pragma_extension_is_core : Warning<

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index 455842412fd0..8242798106ac 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -100,7 +100,7 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
 // expected-no-diagnostics
 #else //__OPENCL_C_VERSION__
-// expected-warning@+2{{unknown OpenCL extension 'cl_intel_planar_yuv' - 
ignoring}}
+// expected-warning@+2{{OpenCL extension 'cl_intel_planar_yuv' unknown or does 
not require pragma - ignoring}}
 #endif //__OPENCL_C_VERSION__
 #pragma OPENCL EXTENSION cl_intel_planar_yuv : enable
 

diff  --git a/clang/test/Parser/opencl-pragma.cl 
b/clang/test/Parser/opencl-pragma.cl
index 02f053fb40d9..76e2cdd47442 100644
--- a/clang/test/Parser/opencl-pragma.cl
+++ b/clang/test/Parser/opencl-pragma.cl
@@ -2,7 +2,7 @@
 
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
-#pragma OPENCL EXTENSION cl_no_such_extension : disable /* expected-warning 
{{unknown OpenCL extension 'cl_no_such_extension' - ignoring}} */
+#pragma OPENCL EXTENSION cl_no_such_extension : disable /* expected-warning 
{{OpenCL extension 'cl_no_such_extension' unknown or does not require pragma - 
ignoring}} */
 
 #pragma OPENCL EXTENSION all : disable
 #pragma OPENCL EXTENSION all : enable /* expected-warning {{expected 'disable' 
- ignoring}} */

diff  --git a/clang/test/SemaOpenCL/extension-begin.cl 
b/clang/test/SemaOpenCL/extension-begin.cl
index 9124ceba4e2a..dc8bd769e2bd 100644
--- a/clang/test/SemaOpenCL/extension-begin.cl
+++ b/clang/test/SemaOpenCL/extension-begin.cl
@@ -18,8 +18,8 @@
 
 #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}}
+// expected-warning@-2 {{OpenCL extension 'my_ext' unknown or does not require 
pragma - ignoring}}
+// expected-warning@+2 {{OpenCL extension 'my_ext' unknown or does not require 
pragma - ignoring}}
 #endif // IMPLICIT_INCLUDE
 #pragma OPENCL EXTENSION my_ext : disable
 

diff  --git a/clang/test/SemaOpenCL/extension-version.cl 
b/clang/test/SemaOpenCL/extension-version.cl
index d135970b8b02..4d92eff6ae3a 100644
--- a/clang/test/SemaOpenCL/extension-version.cl
+++ b/clang/test/SemaOpenCL/extension-version.cl
@@ -217,51 +217,51 @@
 // Check that pragmas for the OpenCL 3.0 features are rejected.
 
 #pragma OPENCL EXTENSION __opencl_c_int64 : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_int64' - ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_int64' unknown or does not 
require pragma - ignoring}}
 #pragma OPENCL EXTENSION __opencl_c_3d_image_writes : disable
-//expected-warning@-1{{unknown OpenCL extension '__opencl_c_3d_image_writes' - 
ignoring}}
+//expected-warning@-1{{OpenCL extension '__opencl_c_3d_image_writes' unknown 
or does not 

[clang] a5cf17f - [OpenCL] Expose wg collective functions for CL3 SPIR targets

2022-05-30 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-05-30T10:48:49+01:00
New Revision: a5cf17f8ae752f1b62b40b907bfee4faa3600b21

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

LOG: [OpenCL] Expose wg collective functions for CL3 SPIR targets

Since the SPIR/SPIR-V targets enable all known features, we must
ensure the Work-group Collective Functions feature macro is set for
OpenCL 3.0.

Fixes https://github.com/llvm/llvm-project/issues/55770

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 20048d97bc74..c433b4f7eb1a 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -68,6 +68,7 @@
 #if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
 // For the SPIR and SPIR-V target all features are supported.
 #if defined(__SPIR__) || defined(__SPIRV__)
+#define __opencl_c_work_group_collective_functions 1
 #define __opencl_c_atomic_order_seq_cst 1
 #define __opencl_c_atomic_scope_device 1
 #define __opencl_c_atomic_scope_all_devices 1



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


[clang] 0d7f8d4 - [OpenCL] Remove argument names from async copy builtins

2022-05-25 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-05-25T10:05:25+01:00
New Revision: 0d7f8d42fd170a434006a928a7106b894bdbdd16

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

LOG: [OpenCL] Remove argument names from async copy builtins

This simplifies completeness comparisons against OpenCLBuiltins.td and
also makes the header no longer "claim" the argument name identifiers.

Continues the direction set out in D119560.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 69e2c85610bae..1942da77f5e50 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -12515,141 +12515,141 @@ cl_mem_fence_flags __ovld get_fence(void *ptr);
  * synchronization of source data such as using a
  * barrier before performing the copy.
  */
-event_t __ovld async_work_group_copy(__local char *dst, const __global char 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uchar *dst, const __global uchar 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local short *dst, const __global short 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ushort *dst, const __global 
ushort *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local int *dst, const __global int 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uint *dst, const __global uint 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local long *dst, const __global long 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ulong *dst, const __global ulong 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local float *dst, const __global float 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local char2 *dst, const __global char2 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uchar2 *dst, const __global 
uchar2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local short2 *dst, const __global 
short2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ushort2 *dst, const __global 
ushort2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local int2 *dst, const __global int2 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uint2 *dst, const __global uint2 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local long2 *dst, const __global long2 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ulong2 *dst, const __global 
ulong2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local float2 *dst, const __global 
float2 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local char3 *dst, const __global char3 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uchar3 *dst, const __global 
uchar3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local short3 *dst, const __global 
short3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ushort3 *dst, const __global 
ushort3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local int3 *dst, const __global int3 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uint3 *dst, const __global uint3 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local long3 *dst, const __global long3 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ulong3 *dst, const __global 
ulong3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local float3 *dst, const __global 
float3 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local char4 *dst, const __global char4 
*src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local uchar4 *dst, const __global 
uchar4 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local short4 *dst, const __global 
short4 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local ushort4 *dst, const __global 
ushort4 *src, size_t num_elements, event_t event);
-event_t __ovld async_work_group_copy(__local int4 *dst, const __global int4 
*src, size_t 

[clang] 21c29a8 - [OpenCL] Add cl_khr_subgroup_rotate builtins

2022-05-18 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-05-18T13:02:17+01:00
New Revision: 21c29a8ae053cb436141ee636333c4f816cc20c4

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

LOG: [OpenCL] Add cl_khr_subgroup_rotate builtins

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 4e87afad84bf..20048d97bc74 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -21,6 +21,7 @@
 #define cl_khr_subgroup_shuffle 1
 #define cl_khr_subgroup_shuffle_relative 1
 #define cl_khr_subgroup_clustered_reduce 1
+#define cl_khr_subgroup_rotate 1
 #define cl_khr_extended_bit_ops 1
 #define cl_khr_integer_dot_product 1
 #define __opencl_c_integer_dot_product_input_4x8bit 1

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 8d9af5248195..69e2c85610ba 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -17275,6 +17275,40 @@ int __ovld __cnfn dot_acc_sat_4x8packed_us_int(uint, 
uint, int);
 int __ovld __cnfn dot_acc_sat_4x8packed_su_int(uint, uint, int);
 #endif // __opencl_c_integer_dot_product_input_4x8bit_packed
 
+#if defined(cl_khr_subgroup_rotate)
+char __ovld __conv sub_group_rotate(char, int);
+uchar __ovld __conv sub_group_rotate(uchar, int);
+short __ovld __conv sub_group_rotate(short, int);
+ushort __ovld __conv sub_group_rotate(ushort, int);
+int __ovld __conv sub_group_rotate(int, int);
+uint __ovld __conv sub_group_rotate(uint, int);
+long __ovld __conv sub_group_rotate(long, int);
+ulong __ovld __conv sub_group_rotate(ulong, int);
+float __ovld __conv sub_group_rotate(float, int);
+#if defined(cl_khr_fp64)
+double __ovld __conv sub_group_rotate(double, int);
+#endif // cl_khr_fp64
+#if defined(cl_khr_fp16)
+half __ovld __conv sub_group_rotate(half, int);
+#endif // cl_khr_fp16
+
+char __ovld __conv sub_group_clustered_rotate(char, int, uint);
+uchar __ovld __conv sub_group_clustered_rotate(uchar, int, uint);
+short __ovld __conv sub_group_clustered_rotate(short, int, uint);
+ushort __ovld __conv sub_group_clustered_rotate(ushort, int, uint);
+int __ovld __conv sub_group_clustered_rotate(int, int, uint);
+uint __ovld __conv sub_group_clustered_rotate(uint, int, uint);
+long __ovld __conv sub_group_clustered_rotate(long, int, uint);
+ulong __ovld __conv sub_group_clustered_rotate(ulong, int, uint);
+float __ovld __conv sub_group_clustered_rotate(float, int, uint);
+#if defined(cl_khr_fp64)
+double __ovld __conv sub_group_clustered_rotate(double, int, uint);
+#endif // cl_khr_fp64
+#if defined(cl_khr_fp16)
+half __ovld __conv sub_group_clustered_rotate(half, int, uint);
+#endif // cl_khr_fp16
+#endif // cl_khr_subgroup_rotate
+
 #if defined(cl_intel_subgroups)
 // Intel-Specific Sub Group Functions
 float   __ovld __conv intel_sub_group_shuffle( float , uint );

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 220daf05acf9..75cea2ffc19c 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1845,6 +1845,12 @@ let Extension = 
FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit_p
   def : Builtin<"dot_acc_sat_4x8packed_su_int", [Int, UInt, UInt, Int], 
Attr.Const>;
 }
 
+// Section 48.3 - cl_khr_subgroup_rotate
+let Extension = FunctionExtension<"cl_khr_subgroup_rotate"> in {
+  def : Builtin<"sub_group_rotate", [AGenType1, AGenType1, Int], 
Attr.Convergent>;
+  def : Builtin<"sub_group_clustered_rotate", [AGenType1, AGenType1, Int, 
UInt], Attr.Convergent>;
+}
+
 //
 // Arm extensions.
 let Extension = ArmIntegerDotProductInt8 in {

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index be185ff8dcf1..455842412fd0 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -127,6 +127,9 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #if cl_khr_subgroup_clustered_reduce != 1
 #error "Incorrectly defined cl_khr_subgroup_clustered_reduce"
 #endif
+#if cl_khr_subgroup_rotate != 1
+#error "Incorrectly defined cl_khr_subgroup_rotate"
+#endif
 #if cl_khr_extended_bit_ops != 1
 #error "Incorrectly defined cl_khr_extended_bit_ops"
 #endif
@@ -208,6 +211,9 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #ifdef cl_khr_subgroup_clustered_reduce
 #error "Incorrect cl_khr_subgroup_clustered_reduce define"
 #endif
+#ifdef cl_khr_subgroup_rotate
+#error "Incorrect cl_khr_subgroup_rotate define"
+#endif
 #ifdef 

[clang] b250cca - [OpenCL] Do not guard vload/store_half builtins

2022-05-17 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-05-17T10:57:23+01:00
New Revision: b250cca11d5996ed01d72cb1f933867da0e8d5e0

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

LOG: [OpenCL] Do not guard vload/store_half builtins

The vload*_half* and vstore*_half* builtins do not require the
cl_khr_fp16 extension: pointers to `half` can be declared without the
extension and the _half variants of vload and vstore should be
available without the extension.

This aligns the guards for these builtins for
`-fdeclare-opencl-builtins` with `opencl-c.h`.

Fixes https://github.com/llvm/llvm-project/issues/55275

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/half.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index d0a0d5bdbf4f5..4e87afad84bf7 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -202,6 +202,9 @@ typedef double double8 __attribute__((ext_vector_type(8)));
 typedef double double16 __attribute__((ext_vector_type(16)));
 #endif
 
+// An internal alias for half, for use by OpenCLBuiltins.td.
+#define __half half
+
 #if defined(__OPENCL_CPP_VERSION__)
 #define NULL nullptr
 #elif defined(__OPENCL_C_VERSION__)

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index ece0b8866d942..220daf05acf94 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -352,9 +352,22 @@ def Float : Type<"float", 
QualType<"Context.FloatTy">>;
 let Extension = Fp64TypeExt in {
   def Double: Type<"double",QualType<"Context.DoubleTy">>;
 }
+
+// The half type for builtins that require the cl_khr_fp16 extension.
 let Extension = Fp16TypeExt in {
   def Half  : Type<"half",  QualType<"Context.HalfTy">>;
 }
+
+// Without the cl_khr_fp16 extension, the half type can only be used to declare
+// a pointer.  Define const and non-const pointer types in all address spaces.
+// Use the "__half" alias to allow the TableGen emitter to distinguish the
+// (extensionless) pointee type of these pointer-to-half types from the "half"
+// type defined above that already carries the cl_khr_fp16 extension.
+foreach AS = [PrivateAS, GlobalAS, ConstantAS, LocalAS, GenericAS] in {
+  def "HalfPtr" # AS  : PointerType>, AS>;
+  def "HalfPtrConst" # AS : PointerType>>, AS>;
+}
+
 def Size  : Type<"size_t",QualType<"Context.getSizeType()">>;
 def PtrDiff   : Type<"ptr
diff _t", QualType<"Context.getPointerDiffType()">>;
 def IntPtr: Type<"intptr_t",  QualType<"Context.getIntPtrType()">>;
@@ -877,22 +890,22 @@ defm : VloadVstore<[ConstantAS], 0>;
 
 multiclass VloadVstoreHalf addrspaces, bit defStores> {
   foreach AS = addrspaces in {
-def : Builtin<"vload_half", [Float, Size, PointerType, 
AS>], Attr.Pure>;
+def : Builtin<"vload_half", [Float, Size, !cast("HalfPtrConst" # 
AS)], Attr.Pure>;
 foreach VSize = [2, 3, 4, 8, 16] in {
   foreach name = ["vload_half" # VSize, "vloada_half" # VSize] in {
-def : Builtin, Size, 
PointerType, AS>], Attr.Pure>;
+def : Builtin, Size, 
!cast("HalfPtrConst" # AS)], Attr.Pure>;
   }
 }
 if defStores then {
   foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
 foreach name = ["vstore_half" # rnd] in {
-  def : Builtin]>;
-  def : Builtin]>;
+  def : Builtin("HalfPtr" # 
AS)]>;
+  def : Builtin("HalfPtr" # 
AS)]>;
 }
 foreach VSize = [2, 3, 4, 8, 16] in {
   foreach name = ["vstore_half" # VSize # rnd, "vstorea_half" # VSize 
# rnd] in {
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
+def : Builtin, Size, 
!cast("HalfPtr" # AS)]>;
+def : Builtin, Size, 
!cast("HalfPtr" # AS)]>;
   }
 }
   }

diff  --git a/clang/test/SemaOpenCL/half.cl b/clang/test/SemaOpenCL/half.cl
index e3e558995b21c..d0cd529a8f9af 100644
--- a/clang/test/SemaOpenCL/half.cl
+++ b/clang/test/SemaOpenCL/half.cl
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value 
-triple spir-unknown-unknown
-// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value 
-triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only -Wno-unused-value 
-triple spir-unknown-unknown -fdeclare-opencl-builtins -finclude-default-header 
-DHAVE_BUILTINS
 
 constant float f = 1.0h; // expected-error{{half precision constant requires 
cl_khr_fp16}}
 
@@ -22,6 +22,11 @@ half half_disabled(half *p, // 

[clang] 87a2583 - [OpenCL] Guard read_write images with TypeExtension

2022-04-21 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-04-21T10:52:41+01:00
New Revision: 87a258366e5d4f3786c6c2b9fe5dbeb736def909

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

LOG: [OpenCL] Guard read_write images with TypeExtension

Ensure that any `read_write` image type carries the
`__opencl_c_read_write_images` upon construction of the `ImageType`.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index a7469d684bcc4..ece0b8866d942 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -99,10 +99,8 @@ def FuncExtKhrLocalInt32ExtendedAtomics  : 
FunctionExtension<"cl_khr_local_int32
 def FuncExtKhrInt64BaseAtomics   : 
FunctionExtension<"cl_khr_int64_base_atomics">;
 def FuncExtKhrInt64ExtendedAtomics   : 
FunctionExtension<"cl_khr_int64_extended_atomics">;
 def FuncExtKhrMipmapImage: 
FunctionExtension<"cl_khr_mipmap_image">;
-def FuncExtKhrMipmapImageReadWrite   : 
FunctionExtension<"cl_khr_mipmap_image __opencl_c_read_write_images">;
 def FuncExtKhrMipmapImageWrites  : 
FunctionExtension<"cl_khr_mipmap_image_writes">;
 def FuncExtKhrGlMsaaSharing  : 
FunctionExtension<"cl_khr_gl_msaa_sharing">;
-def FuncExtKhrGlMsaaSharingReadWrite : 
FunctionExtension<"cl_khr_gl_msaa_sharing __opencl_c_read_write_images">;
 
 def FuncExtOpenCLCDeviceEnqueue  : 
FunctionExtension<"__opencl_c_device_enqueue">;
 def FuncExtOpenCLCGenericAddressSpace: 
FunctionExtension<"__opencl_c_generic_address_space">;
@@ -244,9 +242,11 @@ class ImageType :
   let IsConst = _Ty.IsConst;
   let IsVolatile = _Ty.IsVolatile;
   let AddrSpace = _Ty.AddrSpace;
-  // Add TypeExtension for "write_only image3d_t".
+  // Add TypeExtensions for writable "image3d_t" and "read_write" image types.
   let Extension = !cond(
   !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "WO")) : 
TypeExtension<"cl_khr_3d_image_writes">,
+  !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "RW")) : 
TypeExtension<"cl_khr_3d_image_writes __opencl_c_read_write_images">,
+  !eq(_AccessQualifier, "RW") : 
TypeExtension<"__opencl_c_read_write_images">,
   true : _Ty.Extension);
 }
 
@@ -1594,9 +1594,6 @@ multiclass ImageQueryNumMipLevels {
 let Extension = FuncExtKhrMipmapImage in {
   defm : ImageQueryNumMipLevels<"RO">;
   defm : ImageQueryNumMipLevels<"WO">;
-}
-
-let Extension = FuncExtKhrMipmapImageReadWrite in {
   defm : ImageQueryNumMipLevels<"RW">;
 }
 
@@ -1673,9 +1670,6 @@ let Extension = FuncExtKhrGlMsaaSharing in {
   defm : ImageReadMsaa<"RO">;
   defm : ImageQueryMsaa<"RO">;
   defm : ImageQueryMsaa<"WO">;
-}
-
-let Extension = FuncExtKhrGlMsaaSharingReadWrite in {
   defm : ImageReadMsaa<"RW">;
   defm : ImageQueryMsaa<"RW">;
 }



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


[clang] e67b1b0 - [OpenCL] Add missing __opencl_c_atomic_scope_device guards

2022-04-20 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-04-20T11:02:50+01:00
New Revision: e67b1b0ccf520a0168758d116e88f63160812e99

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

LOG: [OpenCL] Add missing __opencl_c_atomic_scope_device guards

Update opencl-c.h after the specification clarification in
https://github.com/KhronosGroup/OpenCL-Docs/pull/775

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 7ea835ae5c2de..8d9af52481957 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -14376,6 +14376,7 @@ bool __ovld atomic_compare_exchange_weak(volatile 
__local atomic_ulong *, __priv
 #endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 
202100)
 #endif
 
+#if defined(__opencl_c_atomic_scope_device)
 #if defined(__opencl_c_generic_address_space)
 bool __ovld atomic_compare_exchange_strong_explicit(volatile atomic_int *, int 
*, int, memory_order, memory_order);
 bool __ovld atomic_compare_exchange_strong_explicit(volatile atomic_uint *, 
uint *, uint, memory_order, memory_order);
@@ -14472,6 +14473,7 @@ bool __ovld 
atomic_compare_exchange_weak_explicit(volatile __local atomic_ulong
 bool __ovld atomic_compare_exchange_weak_explicit(volatile __local 
atomic_ulong *, __private ulong *, ulong, memory_order, memory_order);
 #endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 
202100)
+#endif //defined(__opencl_c_atomic_scope_device)
 
 #if defined(__opencl_c_generic_address_space)
 bool __ovld atomic_compare_exchange_strong_explicit(volatile atomic_int *, int 
*, int, memory_order, memory_order, memory_scope);



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


[clang] f3ee0af - [OpenCL] opencl-c.h: Add const to get_image_num_samples

2022-04-19 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-04-19T10:16:44+01:00
New Revision: f3ee0afc6739bf2990f9d302ff6b28dbb0429e8d

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

LOG: [OpenCL] opencl-c.h: Add const to get_image_num_samples

Align with the `-fdeclare-opencl-builtins` option and other
get_image_* builtins which have the const attribute.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index cee3c680aff2e..7ea835ae5c2de 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -16118,21 +16118,21 @@ size_t __ovld __cnfn get_image_array_size(read_write 
image2d_array_msaa_depth_t)
 * Return the number of samples associated with image
 */
 #if defined(cl_khr_gl_msaa_sharing)
-int __ovld get_image_num_samples(read_only image2d_msaa_t);
-int __ovld get_image_num_samples(read_only image2d_msaa_depth_t);
-int __ovld get_image_num_samples(read_only image2d_array_msaa_t);
-int __ovld get_image_num_samples(read_only image2d_array_msaa_depth_t);
+int __ovld __cnfn get_image_num_samples(read_only image2d_msaa_t);
+int __ovld __cnfn get_image_num_samples(read_only image2d_msaa_depth_t);
+int __ovld __cnfn get_image_num_samples(read_only image2d_array_msaa_t);
+int __ovld __cnfn get_image_num_samples(read_only image2d_array_msaa_depth_t);
 
-int __ovld get_image_num_samples(write_only image2d_msaa_t);
-int __ovld get_image_num_samples(write_only image2d_msaa_depth_t);
-int __ovld get_image_num_samples(write_only image2d_array_msaa_t);
-int __ovld get_image_num_samples(write_only image2d_array_msaa_depth_t);
+int __ovld __cnfn get_image_num_samples(write_only image2d_msaa_t);
+int __ovld __cnfn get_image_num_samples(write_only image2d_msaa_depth_t);
+int __ovld __cnfn get_image_num_samples(write_only image2d_array_msaa_t);
+int __ovld __cnfn get_image_num_samples(write_only image2d_array_msaa_depth_t);
 
 #if defined(__opencl_c_read_write_images)
-int __ovld get_image_num_samples(read_write image2d_msaa_t);
-int __ovld get_image_num_samples(read_write image2d_msaa_depth_t);
-int __ovld get_image_num_samples(read_write image2d_array_msaa_t);
-int __ovld get_image_num_samples(read_write image2d_array_msaa_depth_t);
+int __ovld __cnfn get_image_num_samples(read_write image2d_msaa_t);
+int __ovld __cnfn get_image_num_samples(read_write image2d_msaa_depth_t);
+int __ovld __cnfn get_image_num_samples(read_write image2d_array_msaa_t);
+int __ovld __cnfn get_image_num_samples(read_write image2d_array_msaa_depth_t);
 #endif //defined(__opencl_c_read_write_images)
 #endif
 



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


[clang] bb6f8d9 - [OpenCL] Add device enqueue guards for DSE builtins

2022-04-11 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-04-11T11:27:51+01:00
New Revision: bb6f8d9a93ef0172f227b04c92e7bbb703641a79

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

LOG: [OpenCL] Add device enqueue guards for DSE builtins

Align guards of these builtins with opencl-c.h.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index b64b50867ce59..a7469d684bcc4 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -104,6 +104,7 @@ def FuncExtKhrMipmapImageWrites  : 
FunctionExtension<"cl_khr_mipmap_imag
 def FuncExtKhrGlMsaaSharing  : 
FunctionExtension<"cl_khr_gl_msaa_sharing">;
 def FuncExtKhrGlMsaaSharingReadWrite : 
FunctionExtension<"cl_khr_gl_msaa_sharing __opencl_c_read_write_images">;
 
+def FuncExtOpenCLCDeviceEnqueue  : 
FunctionExtension<"__opencl_c_device_enqueue">;
 def FuncExtOpenCLCGenericAddressSpace: 
FunctionExtension<"__opencl_c_generic_address_space">;
 def FuncExtOpenCLCNamedAddressSpaceBuiltins : 
FunctionExtension<"__opencl_c_named_address_space_builtins">;
 def FuncExtOpenCLCPipes  : 
FunctionExtension<"__opencl_c_pipes">;
@@ -1454,7 +1455,7 @@ let Extension = FuncExtOpenCLCPipes in {
 // Defined in Builtins.def
 
 // --- Table 33 ---
-let MinVersion = CL20 in {
+let Extension = FuncExtOpenCLCDeviceEnqueue in {
   def : Builtin<"enqueue_marker",
   [Int, Queue, UInt, PointerType, GenericAS>, 
PointerType]>;
 

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl 
b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index e3602aa95e2a9..416f5342ef22e 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -73,6 +73,7 @@ typedef struct {int a;} ndrange_t;
 
 // Enable extensions that are enabled in opencl-c-base.h.
 #if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
+#define __opencl_c_device_enqueue 1
 #define __opencl_c_generic_address_space 1
 #define cl_khr_subgroup_extended_types 1
 #define cl_khr_subgroup_ballot 1



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


[clang] 1331ad2 - [OpenCL] Add generic addrspace guards for get_fence

2022-04-08 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-04-08T12:08:10+01:00
New Revision: 1331ad22c31fc2ed6890fa046c1e2333e369251b

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

LOG: [OpenCL] Add generic addrspace guards for get_fence

Align guards of these builtins with opencl-c.h.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index a57b74430f694..b64b50867ce59 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -923,7 +923,7 @@ def : Builtin<"write_mem_fence", [Void, MemFenceFlags]>;
 // OpenCL v3.0 s6.15.10 - Address Space Qualifier Functions.
 // to_global, to_local, to_private are declared in Builtins.def.
 
-let MinVersion = CL20 in {
+let Extension = FuncExtOpenCLCGenericAddressSpace in {
   // The OpenCL 3.0 specification defines these with a "gentype" argument 
indicating any builtin
   // type or user-defined type, which cannot be represented currently.  Hence 
we slightly diverge
   // by providing only the following overloads with a void pointer.



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


[clang] 77c74fd - [OpenCL] Remove argument names from math builtins

2022-04-06 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-04-06T11:43:59+01:00
New Revision: 77c74fd877b27418171693f187b8db865567b8dc

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

LOG: [OpenCL] Remove argument names from math builtins

This simplifies completeness comparisons against OpenCLBuiltins.td and
also makes the header no longer "claim" the argument name identifiers.

Continues the direction set out in D119560.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 71b0fbb3a691e..cee3c680aff2e 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -6362,7 +6362,7 @@ uint __ovld __cnfn get_work_dim(void);
  * dimindx, get_global_size() returns 1.
  * For clEnqueueTask, this always returns 1.
  */
-size_t __ovld __cnfn get_global_size(uint dimindx);
+size_t __ovld __cnfn get_global_size(uint);
 
 /**
  * Returns the unique global work-item ID value for
@@ -6373,7 +6373,7 @@ size_t __ovld __cnfn get_global_size(uint dimindx);
  * other values of dimindx, get_global_id() returns 0.
  * For clEnqueueTask, this returns 0.
  */
-size_t __ovld __cnfn get_global_id(uint dimindx);
+size_t __ovld __cnfn get_global_id(uint);
 
 /**
  * Returns the number of local work-items specified in
@@ -6387,7 +6387,7 @@ size_t __ovld __cnfn get_global_id(uint dimindx);
  * get_local_size() returns 1.
  * For clEnqueueTask, this always returns 1.
  */
-size_t __ovld __cnfn get_local_size(uint dimindx);
+size_t __ovld __cnfn get_local_size(uint);
 
 /**
  * Returns the unique local work-item ID i.e. a work-item
@@ -6397,7 +6397,7 @@ size_t __ovld __cnfn get_local_size(uint dimindx);
  * get_local_id() returns 0.
  * For clEnqueueTask, this returns 0.
  */
-size_t __ovld __cnfn get_local_id(uint dimindx);
+size_t __ovld __cnfn get_local_id(uint);
 
 /**
  * Returns the number of work-groups that will execute a
@@ -6406,7 +6406,7 @@ size_t __ovld __cnfn get_local_id(uint dimindx);
  * For other values of dimindx, get_num_groups() returns 1.
  * For clEnqueueTask, this always returns 1.
  */
-size_t __ovld __cnfn get_num_groups(uint dimindx);
+size_t __ovld __cnfn get_num_groups(uint);
 
 /**
  * get_group_id returns the work-group ID which is a
@@ -6415,7 +6415,7 @@ size_t __ovld __cnfn get_num_groups(uint dimindx);
  * For other values, get_group_id() returns 0.
  * For clEnqueueTask, this returns 0.
  */
-size_t __ovld __cnfn get_group_id(uint dimindx);
+size_t __ovld __cnfn get_group_id(uint);
 
 /**
  * get_global_offset returns the offset values specified in
@@ -6425,10 +6425,10 @@ size_t __ovld __cnfn get_group_id(uint dimindx);
  * For other values, get_global_offset() returns 0.
  * For clEnqueueTask, this returns 0.
  */
-size_t __ovld __cnfn get_global_offset(uint dimindx);
+size_t __ovld __cnfn get_global_offset(uint);
 
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_2_0)
-size_t __ovld get_enqueued_local_size(uint dimindx);
+size_t __ovld get_enqueued_local_size(uint);
 size_t __ovld get_global_linear_id(void);
 size_t __ovld get_local_linear_id(void);
 #endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)
@@ -6594,27 +6594,27 @@ half16 __ovld __cnfn asinpi(half16);
 /**
  * Arc tangent function.
  */
-float __ovld __cnfn atan(float y_over_x);
-float2 __ovld __cnfn atan(float2 y_over_x);
-float3 __ovld __cnfn atan(float3 y_over_x);
-float4 __ovld __cnfn atan(float4 y_over_x);
-float8 __ovld __cnfn atan(float8 y_over_x);
-float16 __ovld __cnfn atan(float16 y_over_x);
+float __ovld __cnfn atan(float);
+float2 __ovld __cnfn atan(float2);
+float3 __ovld __cnfn atan(float3);
+float4 __ovld __cnfn atan(float4);
+float8 __ovld __cnfn atan(float8);
+float16 __ovld __cnfn atan(float16);
 #ifdef cl_khr_fp64
-double __ovld __cnfn atan(double y_over_x);
-double2 __ovld __cnfn atan(double2 y_over_x);
-double3 __ovld __cnfn atan(double3 y_over_x);
-double4 __ovld __cnfn atan(double4 y_over_x);
-double8 __ovld __cnfn atan(double8 y_over_x);
-double16 __ovld __cnfn atan(double16 y_over_x);
+double __ovld __cnfn atan(double);
+double2 __ovld __cnfn atan(double2);
+double3 __ovld __cnfn atan(double3);
+double4 __ovld __cnfn atan(double4);
+double8 __ovld __cnfn atan(double8);
+double16 __ovld __cnfn atan(double16);
 #endif //cl_khr_fp64
 #ifdef cl_khr_fp16
-half __ovld __cnfn atan(half y_over_x);
-half2 __ovld __cnfn atan(half2 y_over_x);
-half3 __ovld __cnfn atan(half3 y_over_x);
-half4 __ovld __cnfn atan(half4 y_over_x);
-half8 __ovld __cnfn atan(half8 y_over_x);
-half16 __ovld __cnfn atan(half16 y_over_x);
+half __ovld __cnfn atan(half);
+half2 __ovld __cnfn atan(half2);
+half3 __ovld __cnfn atan(half3);
+half4 __ovld __cnfn atan(half4);

[clang] 4dfec37 - [OpenCL] Set MinVersion for sub_group_barrier with memory_scope

2022-03-31 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-03-31T16:41:40+01:00
New Revision: 4dfec37037f5f96db8898b79601c7a1d19177027

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

LOG: [OpenCL] Set MinVersion for sub_group_barrier with memory_scope

The memory_scope enum is not available before OpenCL 2.0, so ensure
the sub_group_barrier overload with a memory_scope argument is
restricted to OpenCL 2.0 and above.  This is already the case in
opencl-c.h.

Fixes the issue revealed by https://reviews.llvm.org/D120254

Reported-by: Harald van Dijk (hvdijk)

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 9c1a39cdb1a56..a57b74430f694 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1698,7 +1698,9 @@ let Extension = FuncExtKhrSubgroups in {
 // --- Table 28.2.2 ---
 let Extension = FuncExtKhrSubgroups in {
   def : Builtin<"sub_group_barrier", [Void, MemFenceFlags], Attr.Convergent>;
-  def : Builtin<"sub_group_barrier", [Void, MemFenceFlags, MemoryScope], 
Attr.Convergent>;
+  let MinVersion = CL20 in {
+def : Builtin<"sub_group_barrier", [Void, MemFenceFlags, MemoryScope], 
Attr.Convergent>;
+  }
 }
 
 // --- Table 28.2.4 ---



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


[clang] de30408 - [OpenCL] opencl-c.h: remove a/b/c/i/p/n/v arg names

2022-03-29 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-03-29T10:16:27+01:00
New Revision: de30408b3b0a012f902b8565fa0b7625c1d5fec6

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

LOG: [OpenCL] opencl-c.h: remove a/b/c/i/p/n/v arg names

This simplifies completeness comparisons against OpenCLBuiltins.td and
also makes the header no longer "claim" any single-letter identifiers.

Continues the direction set out in D119560.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 1a5f7183a7f0a..71b0fbb3a691e 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -7121,27 +7121,27 @@ half16 __ovld __cnfn floor(half16);
  * intermediate products shall not occur. Edge case
  * behavior is per the IEEE 754-2008 standard.
  */
-float __ovld __cnfn fma(float a, float b, float c);
-float2 __ovld __cnfn fma(float2 a, float2 b, float2 c);
-float3 __ovld __cnfn fma(float3 a, float3 b, float3 c);
-float4 __ovld __cnfn fma(float4 a, float4 b, float4 c);
-float8 __ovld __cnfn fma(float8 a, float8 b, float8 c);
-float16 __ovld __cnfn fma(float16 a, float16 b, float16 c);
+float __ovld __cnfn fma(float, float, float);
+float2 __ovld __cnfn fma(float2, float2, float2);
+float3 __ovld __cnfn fma(float3, float3, float3);
+float4 __ovld __cnfn fma(float4, float4, float4);
+float8 __ovld __cnfn fma(float8, float8, float8);
+float16 __ovld __cnfn fma(float16, float16, float16);
 #ifdef cl_khr_fp64
-double __ovld __cnfn fma(double a, double b, double c);
-double2 __ovld __cnfn fma(double2 a, double2 b, double2 c);
-double3 __ovld __cnfn fma(double3 a, double3 b, double3 c);
-double4 __ovld __cnfn fma(double4 a, double4 b, double4 c);
-double8 __ovld __cnfn fma(double8 a, double8 b, double8 c);
-double16 __ovld __cnfn fma(double16 a, double16 b, double16 c);
+double __ovld __cnfn fma(double, double, double);
+double2 __ovld __cnfn fma(double2, double2, double2);
+double3 __ovld __cnfn fma(double3, double3, double3);
+double4 __ovld __cnfn fma(double4, double4, double4);
+double8 __ovld __cnfn fma(double8, double8, double8);
+double16 __ovld __cnfn fma(double16, double16, double16);
 #endif //cl_khr_fp64
 #ifdef cl_khr_fp16
-half __ovld __cnfn fma(half a, half b, half c);
-half2 __ovld __cnfn fma(half2 a, half2 b, half2 c);
-half3 __ovld __cnfn fma(half3 a, half3 b, half3 c);
-half4 __ovld __cnfn fma(half4 a, half4 b, half4 c);
-half8 __ovld __cnfn fma(half8 a, half8 b, half8 c);
-half16 __ovld __cnfn fma(half16 a, half16 b, half16 c);
+half __ovld __cnfn fma(half, half, half);
+half2 __ovld __cnfn fma(half2, half2, half2);
+half3 __ovld __cnfn fma(half3, half3, half3);
+half4 __ovld __cnfn fma(half4, half4, half4);
+half8 __ovld __cnfn fma(half8, half8, half8);
+half16 __ovld __cnfn fma(half16, half16, half16);
 #endif //cl_khr_fp16
 
 /**
@@ -7496,42 +7496,42 @@ int16 __ovld __cnfn ilogb(half16);
 /**
  * Multiply x by 2 to the power n.
  */
-float __ovld __cnfn ldexp(float, int n);
-float2 __ovld __cnfn ldexp(float2, int2 n);
-float3 __ovld __cnfn ldexp(float3, int3 n);
-float4 __ovld __cnfn ldexp(float4, int4 n);
-float8 __ovld __cnfn ldexp(float8, int8 n);
-float16 __ovld __cnfn ldexp(float16, int16 n);
-float2 __ovld __cnfn ldexp(float2, int n);
-float3 __ovld __cnfn ldexp(float3, int n);
-float4 __ovld __cnfn ldexp(float4, int n);
-float8 __ovld __cnfn ldexp(float8, int n);
-float16 __ovld __cnfn ldexp(float16, int n);
+float __ovld __cnfn ldexp(float, int);
+float2 __ovld __cnfn ldexp(float2, int2);
+float3 __ovld __cnfn ldexp(float3, int3);
+float4 __ovld __cnfn ldexp(float4, int4);
+float8 __ovld __cnfn ldexp(float8, int8);
+float16 __ovld __cnfn ldexp(float16, int16);
+float2 __ovld __cnfn ldexp(float2, int);
+float3 __ovld __cnfn ldexp(float3, int);
+float4 __ovld __cnfn ldexp(float4, int);
+float8 __ovld __cnfn ldexp(float8, int);
+float16 __ovld __cnfn ldexp(float16, int);
 #ifdef cl_khr_fp64
-double __ovld __cnfn ldexp(double, int n);
-double2 __ovld __cnfn ldexp(double2, int2 n);
-double3 __ovld __cnfn ldexp(double3, int3 n);
-double4 __ovld __cnfn ldexp(double4, int4 n);
-double8 __ovld __cnfn ldexp(double8, int8 n);
-double16 __ovld __cnfn ldexp(double16, int16 n);
-double2 __ovld __cnfn ldexp(double2, int n);
-double3 __ovld __cnfn ldexp(double3, int n);
-double4 __ovld __cnfn ldexp(double4, int n);
-double8 __ovld __cnfn ldexp(double8, int n);
-double16 __ovld __cnfn ldexp(double16, int n);
+double __ovld __cnfn ldexp(double, int);
+double2 __ovld __cnfn ldexp(double2, int2);
+double3 __ovld __cnfn ldexp(double3, int3);
+double4 __ovld __cnfn ldexp(double4, int4);
+double8 __ovld __cnfn ldexp(double8, int8);
+double16 __ovld __cnfn ldexp(double16, int16);
+double2 __ovld __cnfn 

[clang] 73e1888 - [OpenCL] Guard write_only image3d_t with TypeExtension

2022-03-21 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-03-21T12:45:58Z
New Revision: 73e1888e530afefd4a9a774ef9c29bf24baca3d4

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

LOG: [OpenCL] Guard write_only image3d_t with TypeExtension

Ensure that the TypeExtension of an `ImageType` is also taken into
account when generating `OpenCLBuiltins.inc`.

This aligns the handling of the `write_only image3d_t` type for
`-fdeclare-opencl-builtins` with opencl-c.h with respect to the
`cl_khr_3d_image_writes` extension.

Since the `write_only image3d_t` type is not available when the
extension is disabled, this commit does not add a test to
`SemaOpenCL/fdeclare-opencl-builtins.cl`.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index ff23a1c52ff38..9c1a39cdb1a56 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -134,9 +134,6 @@ def FuncExtFloatAtomicsFp64GenericASMinMax: 
FunctionExtension<"cl_ext_float_
 // Not a real extension, but a workaround to add C++ for OpenCL specific 
builtins.
 def FuncExtOpenCLCxx : FunctionExtension<"__cplusplus">;
 
-// Multiple extensions
-def FuncExtKhrMipmapWritesAndWrite3d : 
FunctionExtension<"cl_khr_mipmap_image_writes cl_khr_3d_image_writes">;
-
 // Arm extensions.
 def ArmIntegerDotProductInt8   : 
FunctionExtension<"cl_arm_integer_dot_product_int8">;
 def ArmIntegerDotProductAccumulateInt8 : 
FunctionExtension<"cl_arm_integer_dot_product_accumulate_int8">;
@@ -246,7 +243,10 @@ class ImageType :
   let IsConst = _Ty.IsConst;
   let IsVolatile = _Ty.IsVolatile;
   let AddrSpace = _Ty.AddrSpace;
-  let Extension = _Ty.Extension;
+  // Add TypeExtension for "write_only image3d_t".
+  let Extension = !cond(
+  !and(!eq(_Ty.Name, "image3d_t"), !eq(_AccessQualifier, "WO")) : 
TypeExtension<"cl_khr_3d_image_writes">,
+  true : _Ty.Extension);
 }
 
 // OpenCL enum type (e.g. memory_scope).
@@ -1625,12 +1625,10 @@ let Extension = FuncExtKhrMipmapImageWrites in {
   def : Builtin<"write_imageui", [Void, ImageType, 
VectorType, Int, VectorType]>;
 }
 def : Builtin<"write_imagef", [Void, ImageType, 
VectorType, Int, Float]>;
-let Extension = FuncExtKhrMipmapWritesAndWrite3d in {
-  foreach imgTy = [Image3d] in {
-def : Builtin<"write_imagef", [Void, ImageType, 
VectorType, Int, VectorType]>;
-def : Builtin<"write_imagei", [Void, ImageType, 
VectorType, Int, VectorType]>;
-def : Builtin<"write_imageui", [Void, ImageType, 
VectorType, Int, VectorType]>;
-  }
+foreach imgTy = [Image3d] in {
+  def : Builtin<"write_imagef", [Void, ImageType, 
VectorType, Int, VectorType]>;
+  def : Builtin<"write_imagei", [Void, ImageType, 
VectorType, Int, VectorType]>;
+  def : Builtin<"write_imageui", [Void, ImageType, 
VectorType, Int, VectorType]>;
 }
   }
 }

diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index a2d0cfb0b6ca9..dca9970444a73 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -822,15 +822,24 @@ static void OCL2Qual(Sema , const OpenCLTypeStruct ,
<< "case OCLAQ_None:\n"
<< "  llvm_unreachable(\"Image without access qualifier\");\n";
 for (const auto  : ITE.getValue()) {
+  StringRef Exts =
+  Image->getValueAsDef("Extension")->getValueAsString("ExtName");
   OS << StringSwitch(
 Image->getValueAsString("AccessQualifier"))
 .Case("RO", "case OCLAQ_ReadOnly:\n")
 .Case("WO", "case OCLAQ_WriteOnly:\n")
-.Case("RW", "case OCLAQ_ReadWrite:\n")
- << "  QT.push_back("
+.Case("RW", "case OCLAQ_ReadWrite:\n");
+  if (!Exts.empty()) {
+OS << "";
+EmitMacroChecks(OS, Exts);
+  }
+  OS << "  QT.push_back("
  << Image->getValueAsDef("QTExpr")->getValueAsString("TypeExpr")
- << ");\n"
- << "  break;\n";
+ << ");\n";
+  if (!Exts.empty()) {
+OS << "  }\n";
+  }
+  OS << "  break;\n";
 }
 OS << "  }\n"
<< "  break;\n";



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


[clang] b48e3c8 - [OpenCL] opencl-c.h: Fix incorrect get_image_width guard

2022-02-25 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-25T11:05:56Z
New Revision: b48e3c805c253d0a1194bede81b3f8e225f40824

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

LOG: [OpenCL] opencl-c.h: Fix incorrect get_image_width guard

`cl_khr_3d_image_writes` should not guard `read_only image3d_t`.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 0adf07cc7e3db..9b8461bfccfda 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15715,9 +15715,7 @@ void __ovld write_imageh(read_write image1d_buffer_t, 
int, half4);
 int __ovld __cnfn get_image_width(read_only image1d_t);
 int __ovld __cnfn get_image_width(read_only image1d_buffer_t);
 int __ovld __cnfn get_image_width(read_only image2d_t);
-#ifdef cl_khr_3d_image_writes
 int __ovld __cnfn get_image_width(read_only image3d_t);
-#endif
 int __ovld __cnfn get_image_width(read_only image1d_array_t);
 int __ovld __cnfn get_image_width(read_only image2d_array_t);
 #ifdef cl_khr_depth_images



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


[clang-tools-extra] ba18c36 - [clang-tidy] Remove opencl-c.h inclusion from tests

2022-02-24 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-24T16:28:52Z
New Revision: ba18c360b2f3c25fe9091c7a7931eded374b3cf6

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

LOG: [clang-tidy] Remove opencl-c.h inclusion from tests

After D120254 some clang-tidy tests started failing on release builds.

clang-tidy has been using the `-fdeclare-opencl-builtins` functionality
since this became the default in clang, so there is no need to include
`opencl-c.h`.

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

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp

clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
index a6dbab7b72fce..68f4658a7dc9b 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/altera-id-dependent-backward-branch.cpp
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c --include opencl-c.h
+// RUN: %check_clang_tidy %s altera-id-dependent-backward-branch %t -- 
-header-filter=.* "--" -cl-std=CL1.2 -c
 
 typedef struct ExampleStruct {
   int IDDepField;

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
index 1b6045144cea5..a6b31875e7c72 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/altera-single-work-item-barrier.cpp
@@ -1,7 +1,7 @@
-// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
--include opencl-c.h -DOLDCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
--include opencl-c.h -DNEWCLOLDAOC
-// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c --include opencl-c.h -DOLDCLNEWAOC
-// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c --include opencl-c.h -DNEWCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL1.2 -c 
-DOLDCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLOLDAOC %s 
altera-single-work-item-barrier %t -- -header-filter=.* "--" -cl-std=CL2.0 -c 
-DNEWCLOLDAOC
+// RUN: %check_clang_tidy -check-suffix=OLDCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL1.2 -c -DOLDCLNEWAOC
+// RUN: %check_clang_tidy -check-suffix=NEWCLNEWAOC %s 
altera-single-work-item-barrier %t -- -config='{CheckOptions: [{key: 
altera-single-work-item-barrier.AOCVersion, value: 1701}]}' -header-filter=.* 
"--" -cl-std=CL2.0 -c -DNEWCLNEWAOC
 
 #ifdef OLDCLOLDAOC  // OpenCL 1.2 Altera Offline Compiler < 17.1
 void __kernel error_barrier_no_id(__global int * foo, int size) {



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


[clang] 28cdcf8 - [OpenCL] Handle TypeExtensions in OpenCLBuiltinFileEmitter

2022-02-24 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-24T15:17:24Z
New Revision: 28cdcf8e3c8e6c51d42051b54f67c6920b5d8cf3

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

LOG: [OpenCL] Handle TypeExtensions in OpenCLBuiltinFileEmitter

Until now, any types that had TypeExtensions attached to them were not
guarded with those extensions.  Extend the OpenCLBuiltinFileEmitter
such that all required extensions are emitted for the types of a
builtin function.

The `clang-tblgen -gen-clang-opencl-builtin-tests` emitter will now
produce e.g.:

  #if defined(cl_khr_fp16) && defined(cl_khr_fp64)
  half8 test11802_convert_half8_rtp(double8 arg1) {
return convert_half8_rtp(arg1);
  }
  #endif // TypeExtension

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

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 34ca6cb36738c..a2d0cfb0b6ca9 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -17,6 +17,7 @@
 #include "TableGenBackends.h"
 #include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallSet.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
@@ -293,6 +294,15 @@ class OpenCLBuiltinFileEmitterBase {
   // was emitted.
   std::string emitVersionGuard(const Record *Builtin);
 
+  // Emit an #if guard for all type extensions required for the given type
+  // strings.  Return the corresponding closing #endif, or an empty string
+  // if no extension #if guard was emitted.
+  StringRef
+  emitTypeExtensionGuards(const SmallVectorImpl );
+
+  // Map type strings to type extensions (e.g. "half2" -> "cl_khr_fp16").
+  StringMap TypeExtMap;
+
   // Contains OpenCL builtin functions and related information, stored as
   // Record instances. They are coming from the associated TableGen file.
   RecordKeeper 
@@ -1057,7 +1067,16 @@ void 
OpenCLBuiltinFileEmitterBase::expandTypesInSignature(
 // Insert the Cartesian product of the types and vector sizes.
 for (const auto  : VectorList) {
   for (const auto  : TypeList) {
-ExpandedArg.push_back(getTypeString(Type, Flags, Vector));
+std::string FullType = getTypeString(Type, Flags, Vector);
+ExpandedArg.push_back(FullType);
+
+// If the type requires an extension, add a TypeExtMap entry mapping
+// the full type name to the extension.
+StringRef Ext =
+Arg->getValueAsDef("Extension")->getValueAsString("ExtName");
+if (!Ext.empty() && TypeExtMap.find(FullType) == TypeExtMap.end()) {
+  TypeExtMap.insert({FullType, Ext});
+}
   }
 }
 NumSignatures = std::max(NumSignatures, ExpandedArg.size());
@@ -1141,6 +1160,39 @@ OpenCLBuiltinFileEmitterBase::emitVersionGuard(const 
Record *Builtin) {
   return OptionalEndif;
 }
 
+StringRef OpenCLBuiltinFileEmitterBase::emitTypeExtensionGuards(
+const SmallVectorImpl ) {
+  SmallSet ExtSet;
+
+  // Iterate over all types to gather the set of required TypeExtensions.
+  for (const auto  : Signature) {
+StringRef TypeExt = TypeExtMap.lookup(Ty);
+if (!TypeExt.empty()) {
+  // The TypeExtensions are space-separated in the .td file.
+  SmallVector ExtVec;
+  TypeExt.split(ExtVec, " ");
+  for (const auto Ext : ExtVec) {
+ExtSet.insert(Ext);
+  }
+}
+  }
+
+  // Emit the #if only when at least one extension is required.
+  if (ExtSet.empty())
+return "";
+
+  OS << "#if ";
+  bool isFirst = true;
+  for (const auto Ext : ExtSet) {
+if (!isFirst)
+  OS << " && ";
+OS << "defined(" << Ext << ")";
+isFirst = false;
+  }
+  OS << "\n";
+  return "#endif // TypeExtension\n";
+}
+
 void OpenCLBuiltinTestEmitter::emit() {
   emitSourceFileHeader("OpenCL Builtin exhaustive testing", OS);
 
@@ -1163,6 +1215,8 @@ void OpenCLBuiltinTestEmitter::emit() {
 std::string OptionalVersionEndif = emitVersionGuard(B);
 
 for (const auto  : FTypes) {
+  StringRef OptionalTypeExtEndif = emitTypeExtensionGuards(Signature);
+
   // Emit function declaration.
   OS << Signature[0] << " test" << TestID++ << "_" << Name << "(";
   if (Signature.size() > 1) {
@@ -1189,6 +1243,7 @@ void OpenCLBuiltinTestEmitter::emit() {
 
   // End of function body.
   OS << "}\n";
+  OS << OptionalTypeExtEndif;
 }
 
 OS << OptionalVersionEndif;



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


[clang] 88182e2 - [OpenCL] opencl-c.h: remove arg names for image builtins

2022-02-24 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-24T11:52:32Z
New Revision: 88182e2dfde295a8f6adc9e6148410e86c71680d

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

LOG: [OpenCL] opencl-c.h: remove arg names for image builtins

This simplifies completeness comparisons against OpenCLBuiltins.td and
also makes the header no longer "claim" the identifiers "image",
"image_array", "coord", "sampler", "sample", "gradientX", "gradientY",
"lod", and "color".

Continues the direction set out in D119560.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 172b2c192709..0adf07cc7e3d 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15200,123 +15200,123 @@ half16 __ovld __cnfn shuffle2(half16 x, half16 y, 
ushort16 mask);
  * in the description above are undefined.
  */
 
-float4 __ovld __purefn read_imagef(read_only image2d_t image, sampler_t 
sampler, int2 coord);
-float4 __ovld __purefn read_imagef(read_only image2d_t image, sampler_t 
sampler, float2 coord);
+float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, int2);
+float4 __ovld __purefn read_imagef(read_only image2d_t, sampler_t, float2);
 
-int4 __ovld __purefn read_imagei(read_only image2d_t image, sampler_t sampler, 
int2 coord);
-int4 __ovld __purefn read_imagei(read_only image2d_t image, sampler_t sampler, 
float2 coord);
-uint4 __ovld __purefn read_imageui(read_only image2d_t image, sampler_t 
sampler, int2 coord);
-uint4 __ovld __purefn read_imageui(read_only image2d_t image, sampler_t 
sampler, float2 coord);
+int4 __ovld __purefn read_imagei(read_only image2d_t, sampler_t, int2);
+int4 __ovld __purefn read_imagei(read_only image2d_t, sampler_t, float2);
+uint4 __ovld __purefn read_imageui(read_only image2d_t, sampler_t, int2);
+uint4 __ovld __purefn read_imageui(read_only image2d_t, sampler_t, float2);
 
-float4 __ovld __purefn read_imagef(read_only image3d_t image, sampler_t 
sampler, int4 coord);
-float4 __ovld __purefn read_imagef(read_only image3d_t image, sampler_t 
sampler, float4 coord);
+float4 __ovld __purefn read_imagef(read_only image3d_t, sampler_t, int4);
+float4 __ovld __purefn read_imagef(read_only image3d_t, sampler_t, float4);
 
-int4 __ovld __purefn read_imagei(read_only image3d_t image, sampler_t sampler, 
int4 coord);
-int4 __ovld __purefn read_imagei(read_only image3d_t image, sampler_t sampler, 
float4 coord);
-uint4 __ovld __purefn read_imageui(read_only image3d_t image, sampler_t 
sampler, int4 coord);
-uint4 __ovld __purefn read_imageui(read_only image3d_t image, sampler_t 
sampler, float4 coord);
+int4 __ovld __purefn read_imagei(read_only image3d_t, sampler_t, int4);
+int4 __ovld __purefn read_imagei(read_only image3d_t, sampler_t, float4);
+uint4 __ovld __purefn read_imageui(read_only image3d_t, sampler_t, int4);
+uint4 __ovld __purefn read_imageui(read_only image3d_t, sampler_t, float4);
 
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
-float4 __ovld __purefn read_imagef(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
-float4 __ovld __purefn read_imagef(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
+float4 __ovld __purefn read_imagef(read_only image2d_array_t, sampler_t, int4);
+float4 __ovld __purefn read_imagef(read_only image2d_array_t, sampler_t, 
float4);
 
-int4 __ovld __purefn read_imagei(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
-int4 __ovld __purefn read_imagei(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
-uint4 __ovld __purefn read_imageui(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
-uint4 __ovld __purefn read_imageui(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
+int4 __ovld __purefn read_imagei(read_only image2d_array_t, sampler_t, int4);
+int4 __ovld __purefn read_imagei(read_only image2d_array_t, sampler_t, float4);
+uint4 __ovld __purefn read_imageui(read_only image2d_array_t, sampler_t, int4);
+uint4 __ovld __purefn read_imageui(read_only image2d_array_t, sampler_t, 
float4);
 #endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_1_2)
 
-float4 __ovld __purefn read_imagef(read_only image1d_t image, sampler_t 
sampler, int coord);
-float4 __ovld __purefn read_imagef(read_only image1d_t image, sampler_t 
sampler, float coord);
+float4 __ovld __purefn read_imagef(read_only image1d_t, sampler_t, int);
+float4 __ovld __purefn read_imagef(read_only image1d_t, sampler_t, float);
 
-int4 __ovld __purefn read_imagei(read_only image1d_t image, sampler_t sampler, 
int coord);
-int4 __ovld __purefn read_imagei(read_only image1d_t 

[clang] aa9c2d1 - [OpenCL] Align subgroup builtin guards

2022-02-23 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-23T12:22:09Z
New Revision: aa9c2d19d9b73589d72114d6e0a4fb4ce42b922b

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

LOG: [OpenCL] Align subgroup builtin guards

Until now, subgroup builtins are available with `opencl-c.h` when at
least one of `cl_intel_subgroups`, `cl_khr_subgroups`, or
`__opencl_c_subgroups` is defined.  With `-fdeclare-opencl-builtins`,
subgroup builtins are conditionalized on `cl_khr_subgroups` only.

Align `-fdeclare-opencl-builtins` to `opencl-c.h` by introducing the
internal `__opencl_subgroup_builtins` macro.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 5191c41bcd057..d0a0d5bdbf4f5 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -80,6 +80,11 @@
 #define __opencl_c_named_address_space_builtins 1
 #endif // !defined(__opencl_c_generic_address_space)
 
+#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || 
defined(__opencl_c_subgroups)
+// Internal feature macro to provide subgroup builtins.
+#define __opencl_subgroup_builtins 1
+#endif
+
 // built-in scalar data types:
 
 /**

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 18c1c317e100f..172b2c192709f 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -16282,7 +16282,7 @@ queue_t __ovld get_default_queue(void);
 
 // OpenCL Extension v2.0 s9.17 - Sub-groups
 
-#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups) || 
defined(__opencl_c_subgroups)
+#if defined(__opencl_subgroup_builtins)
 // Shared Sub Group Functions
 uint__ovld get_sub_group_size(void);
 uint__ovld get_max_sub_group_size(void);
@@ -16381,7 +16381,7 @@ double  __ovld __conv 
sub_group_scan_inclusive_min(double x);
 double  __ovld __conv sub_group_scan_inclusive_max(double x);
 #endif //cl_khr_fp64
 
-#endif //cl_khr_subgroups cl_intel_subgroups __opencl_c_subgroups
+#endif // __opencl_subgroup_builtins
 
 #if defined(cl_khr_subgroup_extended_types)
 char __ovld __conv sub_group_broadcast( char value, uint index );

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index e6da5e34f7091..ff23a1c52ff38 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -83,7 +83,7 @@ def AtomicFp64TypeExt : 
TypeExtension<"cl_khr_int64_base_atomics cl_khr_int64_ex
 
 // FunctionExtension definitions.
 def FuncExtNone  : FunctionExtension<"">;
-def FuncExtKhrSubgroups  : 
FunctionExtension<"cl_khr_subgroups">;
+def FuncExtKhrSubgroups  : 
FunctionExtension<"__opencl_subgroup_builtins">;
 def FuncExtKhrSubgroupExtendedTypes  : 
FunctionExtension<"cl_khr_subgroup_extended_types">;
 def FuncExtKhrSubgroupNonUniformVote : 
FunctionExtension<"cl_khr_subgroup_non_uniform_vote">;
 def FuncExtKhrSubgroupBallot : 
FunctionExtension<"cl_khr_subgroup_ballot">;

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl 
b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index d2d7fff02efaa..89a4646839acb 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL -fdeclare-opencl-builtins -finclude-default-header
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER
-// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -DNO_HEADER 
-cl-ext=-cl_intel_subgroups
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header 
-cl-ext=-cl_intel_subgroups
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
 // 

[clang] e7e17b3 - [OpenCL] opencl-c.h: use uint/ulong consistently

2022-02-22 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-22T10:15:40Z
New Revision: e7e17b30d02d4f0035fef92850d529f16849c6f0

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

LOG: [OpenCL] opencl-c.h: use uint/ulong consistently

Most places already seem to use the short spelling instead of
'unsigned int/long', so perform the following substitutions:

  s/unsigned int /uint /g
  s/unsigned long /ulong /g

This simplifies completeness comparisons against OpenCLBuiltins.td.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 6c9c3cacf3ec..18c1c317e100 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -12919,28 +12919,28 @@ void __ovld prefetch(const __global half16 *p, size_t 
num_elements);
  * pointed by p. The function returns old.
  */
 int __ovld atomic_add(volatile __global int *p, int val);
-unsigned int __ovld atomic_add(volatile __global unsigned int *p, unsigned int 
val);
+uint __ovld atomic_add(volatile __global uint *p, uint val);
 int __ovld atomic_add(volatile __local int *p, int val);
-unsigned int __ovld atomic_add(volatile __local unsigned int *p, unsigned int 
val);
+uint __ovld atomic_add(volatile __local uint *p, uint val);
 #ifdef __OPENCL_CPP_VERSION__
 int __ovld atomic_add(volatile int *p, int val);
-unsigned int __ovld atomic_add(volatile unsigned int *p, unsigned int val);
+uint __ovld atomic_add(volatile uint *p, uint val);
 #endif
 
 #if defined(cl_khr_global_int32_base_atomics)
 int __ovld atom_add(volatile __global int *p, int val);
-unsigned int __ovld atom_add(volatile __global unsigned int *p, unsigned int 
val);
+uint __ovld atom_add(volatile __global uint *p, uint val);
 #endif
 #if defined(cl_khr_local_int32_base_atomics)
 int __ovld atom_add(volatile __local int *p, int val);
-unsigned int __ovld atom_add(volatile __local unsigned int *p, unsigned int 
val);
+uint __ovld atom_add(volatile __local uint *p, uint val);
 #endif
 
 #if defined(cl_khr_int64_base_atomics)
 long __ovld atom_add(volatile __global long *p, long val);
-unsigned long __ovld atom_add(volatile __global unsigned long *p, unsigned 
long val);
+ulong __ovld atom_add(volatile __global ulong *p, ulong val);
 long __ovld atom_add(volatile __local long *p, long val);
-unsigned long __ovld atom_add(volatile __local unsigned long *p, unsigned long 
val);
+ulong __ovld atom_add(volatile __local ulong *p, ulong val);
 #endif
 
 /**
@@ -12949,28 +12949,28 @@ unsigned long __ovld atom_add(volatile __local 
unsigned long *p, unsigned long v
  * returns old.
  */
 int __ovld atomic_sub(volatile __global int *p, int val);
-unsigned int __ovld atomic_sub(volatile __global unsigned int *p, unsigned int 
val);
+uint __ovld atomic_sub(volatile __global uint *p, uint val);
 int __ovld atomic_sub(volatile __local int *p, int val);
-unsigned int __ovld atomic_sub(volatile __local unsigned int *p, unsigned int 
val);
+uint __ovld atomic_sub(volatile __local uint *p, uint val);
 #ifdef __OPENCL_CPP_VERSION__
 int __ovld atomic_sub(volatile int *p, int val);
-unsigned int __ovld atomic_sub(volatile unsigned int *p, unsigned int val);
+uint __ovld atomic_sub(volatile uint *p, uint val);
 #endif
 
 #if defined(cl_khr_global_int32_base_atomics)
 int __ovld atom_sub(volatile __global int *p, int val);
-unsigned int __ovld atom_sub(volatile __global unsigned int *p, unsigned int 
val);
+uint __ovld atom_sub(volatile __global uint *p, uint val);
 #endif
 #if defined(cl_khr_local_int32_base_atomics)
 int __ovld atom_sub(volatile __local int *p, int val);
-unsigned int __ovld atom_sub(volatile __local unsigned int *p, unsigned int 
val);
+uint __ovld atom_sub(volatile __local uint *p, uint val);
 #endif
 
 #if defined(cl_khr_int64_base_atomics)
 long __ovld atom_sub(volatile __global long *p, long val);
-unsigned long __ovld atom_sub(volatile __global unsigned long *p, unsigned 
long val);
+ulong __ovld atom_sub(volatile __global ulong *p, ulong val);
 long __ovld atom_sub(volatile __local long *p, long val);
-unsigned long __ovld atom_sub(volatile __local unsigned long *p, unsigned long 
val);
+ulong __ovld atom_sub(volatile __local ulong *p, ulong val);
 #endif
 
 /**
@@ -12979,31 +12979,31 @@ unsigned long __ovld atom_sub(volatile __local 
unsigned long *p, unsigned long v
  * value.
  */
 int __ovld atomic_xchg(volatile __global int *p, int val);
-unsigned int __ovld atomic_xchg(volatile __global unsigned int *p, unsigned 
int val);
+uint __ovld atomic_xchg(volatile __global uint *p, uint val);
 int __ovld atomic_xchg(volatile __local int *p, int val);
-unsigned int __ovld atomic_xchg(volatile __local unsigned int *p, unsigned int 
val);

[clang] 9798b33 - [OpenCL] Guard 64-bit atomic types

2022-02-17 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-17T10:58:52Z
New Revision: 9798b33d1dc14f5334e2cc117e3896510fa57b82

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

LOG: [OpenCL] Guard 64-bit atomic types

Until now, overloads with a 64-bit atomic type argument were always
made available with `-fdeclare-opencl-builtins`.  Ensure these
overloads are only available when both the `cl_khr_int64_base_atomics`
and `cl_khr_int64_extended_atomics` extensions have been enabled, as
required by the OpenCL specification.

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

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 556d1778625e7..e6da5e34f7091 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -78,6 +78,8 @@ class concatExtension 
{
 def NoTypeExt   : TypeExtension<"">;
 def Fp16TypeExt : TypeExtension<"cl_khr_fp16">;
 def Fp64TypeExt : TypeExtension<"cl_khr_fp64">;
+def Atomic64TypeExt : TypeExtension<"cl_khr_int64_base_atomics 
cl_khr_int64_extended_atomics">;
+def AtomicFp64TypeExt : TypeExtension<"cl_khr_int64_base_atomics 
cl_khr_int64_extended_atomics cl_khr_fp64">;
 
 // FunctionExtension definitions.
 def FuncExtNone  : FunctionExtension<"">;
@@ -389,10 +391,14 @@ def NDRange   : TypedefType<"ndrange_t">;
 // OpenCL v2.0 s6.13.11: Atomic integer and floating-point types.
 def AtomicInt : Type<"atomic_int", 
QualType<"Context.getAtomicType(Context.IntTy)">>;
 def AtomicUInt: Type<"atomic_uint", 
QualType<"Context.getAtomicType(Context.UnsignedIntTy)">>;
-def AtomicLong: Type<"atomic_long", 
QualType<"Context.getAtomicType(Context.LongTy)">>;
-def AtomicULong   : Type<"atomic_ulong", 
QualType<"Context.getAtomicType(Context.UnsignedLongTy)">>;
+let Extension = Atomic64TypeExt in {
+  def AtomicLong: Type<"atomic_long", 
QualType<"Context.getAtomicType(Context.LongTy)">>;
+  def AtomicULong   : Type<"atomic_ulong", 
QualType<"Context.getAtomicType(Context.UnsignedLongTy)">>;
+}
 def AtomicFloat   : Type<"atomic_float", 
QualType<"Context.getAtomicType(Context.FloatTy)">>;
-def AtomicDouble  : Type<"atomic_double", 
QualType<"Context.getAtomicType(Context.DoubleTy)">>;
+let Extension = AtomicFp64TypeExt in {
+  def AtomicDouble  : Type<"atomic_double", 
QualType<"Context.getAtomicType(Context.DoubleTy)">>;
+}
 def AtomicHalf: Type<"atomic_half", 
QualType<"Context.getAtomicType(Context.HalfTy)">>;
 def AtomicIntPtr  : Type<"atomic_intptr_t", 
QualType<"Context.getAtomicType(Context.getIntPtrType())">>;
 def AtomicUIntPtr : Type<"atomic_uintptr_t", 
QualType<"Context.getAtomicType(Context.getUIntPtrType())">>;

diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl 
b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index d526c32d65a92..d2d7fff02efaa 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -163,6 +163,25 @@ void test_atomic_fetch_with_address_space(volatile 
__generic atomic_float *a_flo
 }
 #endif // !defined(NO_HEADER) && __OPENCL_C_VERSION__ >= 200
 
+#if !defined(NO_HEADER) && __OPENCL_C_VERSION__ == 200 && 
defined(__opencl_c_generic_address_space)
+
+// Test that overloads that use atomic_double are not available when the fp64
+// extension is disabled.  Test this by counting the number of notes about
+// candidate functions.
+void test_atomic_double_reporting(volatile __generic atomic_int *a) {
+  atomic_init(a);
+  // expected-error@-1{{no matching function for call to 'atomic_init'}}
+#if defined(NO_FP64)
+  // Expecting 5 candidates: int, uint, long, ulong, float
+  // expected-note@-4 5 {{candidate function not viable: requires 2 arguments, 
but 1 was provided}}
+#else
+  // Expecting 6 candidates: int, uint, long, ulong, float, double
+  // expected-note@-7 6 {{candidate function not viable: requires 2 arguments, 
but 1 was provided}}
+#endif
+}
+
+#endif
+
 #if defined(NO_ATOMSCOPE) && __OPENCL_C_VERSION__ >= 300
 // Disable the feature by undefining the feature macro.
 #undef __opencl_c_atomic_scope_device

diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 4795b008dda3c..34ca6cb36738c 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -733,6 +733,20 @@ static std::pair 
isOpenCLBuiltin(llvm::StringRef Name) {
   OS << "} // 

[clang] 6690b7d - [OpenCL] Ensure atomic_init is guarded with extension

2022-02-16 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-16T15:12:23Z
New Revision: 6690b7d3ac9ab6410b7909207552ce4edbe2147b

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

LOG: [OpenCL] Ensure atomic_init is guarded with extension

The named and generic address space overloads for atomic_init added
by 50f8abb9f40a ("[OpenCL] Add OpenCL 3.0 atomics to
-fdeclare-opencl-builtins", 2022-02-11) were not guarded by the
corresponding extensions.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index ab30553005729..556d1778625e7 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1082,8 +1082,10 @@ multiclass OpenCL2Atomics {
   foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
   [AtomicLong, Long], [AtomicULong, ULong],
   [AtomicFloat, Float], [AtomicDouble, Double]] in {
-def : Builtin<"atomic_init",
-[Void, PointerType, addrspace>, 
TypePair[1]]>;
+let Extension = BaseExt in {
+  def : Builtin<"atomic_init",
+  [Void, PointerType, addrspace>, 
TypePair[1]]>;
+}
 defm : BuiltinAtomicExplicit<"atomic_store",
 [Void, PointerType, addrspace>, 
TypePair[1]], BaseExt>;
 defm : BuiltinAtomicExplicit<"atomic_load",



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


[clang] 477bc8e - [OpenCL] Guard atomic_double with cl_khr_int64_*

2022-02-16 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-16T10:07:35Z
New Revision: 477bc8e8b9311fdac4c360b1fe7d29d0d10aac6c

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

LOG: [OpenCL] Guard atomic_double with cl_khr_int64_*

It is necessary to guard atomic_double type according to
https://www.khronos.org/registry/OpenCL/specs/3.0-unified/html/OpenCL_C.html#_footnotedef_54.
Platform that disable cl_khr_int64_base_atomics and
cl_khr_int64_extended_atomics will have compiling errors even if
atomic_double is not used.

Patch by Haonan Yang.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 7a2ddc47c9a1b..bf3f01253df32 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -13832,6 +13832,7 @@ float __ovld atomic_fetch_max_explicit(volatile 
atomic_float *object,
 #endif // defined(__opencl_c_ext_fp32_global_atomic_min_max) &&
\
 defined(__opencl_c_ext_fp32_local_atomic_min_max)
 
+#if defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #if defined(__opencl_c_ext_fp64_global_atomic_min_max)
 double __ovld atomic_fetch_min(volatile __global atomic_double *object,
double operand);
@@ -13882,6 +13883,8 @@ double __ovld atomic_fetch_max_explicit(volatile 
atomic_double *object,
 memory_scope scope);
 #endif // defined(__opencl_c_ext_fp64_global_atomic_min_max) &&
\
 defined(__opencl_c_ext_fp64_local_atomic_min_max)
+#endif // defined(cl_khr_int64_base_atomics) &&
\
+defined(cl_khr_int64_extended_atomics)
 
 #if defined(__opencl_c_ext_fp16_global_atomic_add)
 half __ovld atomic_fetch_add(volatile __global atomic_half *object,
@@ -13985,6 +13988,7 @@ float __ovld atomic_fetch_sub_explicit(volatile 
atomic_float *object,
 #endif // defined(__opencl_c_ext_fp32_global_atomic_add) &&
\
 defined(__opencl_c_ext_fp32_local_atomic_add)
 
+#if defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #if defined(__opencl_c_ext_fp64_global_atomic_add)
 double __ovld atomic_fetch_add(volatile __global atomic_double *object,
double operand);
@@ -14035,6 +14039,8 @@ double __ovld atomic_fetch_sub_explicit(volatile 
atomic_double *object,
 memory_scope scope);
 #endif // defined(__opencl_c_ext_fp64_global_atomic_add) &&
\
 defined(__opencl_c_ext_fp64_local_atomic_add)
+#endif // defined(cl_khr_int64_base_atomics) &&
\
+defined(cl_khr_int64_extended_atomics)
 
 #endif // cl_ext_float_atomics
 



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


[clang] 074451b - [OpenCL] opencl-c.h: fix atomic_fetch_max with addrspace

2022-02-15 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-15T12:12:03Z
New Revision: 074451bd3352e022d015545e9091002d052daaa3

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

LOG: [OpenCL] opencl-c.h: fix atomic_fetch_max with addrspace

Commit 3c7d2f1b67d1 ("[OpenCL] opencl-c.h: add CL 3.0 non-generic
address space atomics", 2021-07-30) added some atomic_fetch_add/sub
overloads with uintptr_t arguments twice.  Instead, they should have
been atomic_fetch_max overloads with non-generic address spaces.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 98c92fd7ef0a3..7a2ddc47c9a1b 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -13424,8 +13424,8 @@ long __ovld atomic_fetch_max(volatile __global 
atomic_long *object, long operand
 long __ovld atomic_fetch_max(volatile __local atomic_long *object, long 
operand);
 ulong __ovld atomic_fetch_max(volatile __global atomic_ulong *object, ulong 
operand);
 ulong __ovld atomic_fetch_max(volatile __local atomic_ulong *object, ulong 
operand);
-uintptr_t __ovld atomic_fetch_add(volatile __global atomic_uintptr_t *object, 
ptr
diff _t operand);
-uintptr_t __ovld atomic_fetch_sub(volatile __local atomic_uintptr_t *object, 
ptr
diff _t operand);
+uintptr_t __ovld atomic_fetch_max(volatile __global atomic_uintptr_t *object, 
uintptr_t operand);
+uintptr_t __ovld atomic_fetch_max(volatile __local atomic_uintptr_t *object, 
uintptr_t operand);
 #endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 
202100)
 #endif
@@ -13543,8 +13543,8 @@ long __ovld atomic_fetch_max_explicit(volatile __global 
atomic_long *object, lon
 long __ovld atomic_fetch_max_explicit(volatile __local atomic_long *object, 
long operand, memory_order order);
 ulong __ovld atomic_fetch_max_explicit(volatile __global atomic_ulong *object, 
ulong operand, memory_order order);
 ulong __ovld atomic_fetch_max_explicit(volatile __local atomic_ulong *object, 
ulong operand, memory_order order);
-uintptr_t __ovld atomic_fetch_add_explicit(volatile __global atomic_uintptr_t 
*object, ptr
diff _t operand, memory_order order);
-uintptr_t __ovld atomic_fetch_sub_explicit(volatile __local atomic_uintptr_t 
*object, ptr
diff _t operand, memory_order order);
+uintptr_t __ovld atomic_fetch_max_explicit(volatile __global atomic_uintptr_t 
*object, uintptr_t operand, memory_order order);
+uintptr_t __ovld atomic_fetch_max_explicit(volatile __local atomic_uintptr_t 
*object, uintptr_t operand, memory_order order);
 #endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 
202100)
 #endif
@@ -13661,8 +13661,8 @@ long __ovld atomic_fetch_max_explicit(volatile __global 
atomic_long *object, lon
 long __ovld atomic_fetch_max_explicit(volatile __local atomic_long *object, 
long operand, memory_order order, memory_scope scope);
 ulong __ovld atomic_fetch_max_explicit(volatile __global atomic_ulong *object, 
ulong operand, memory_order order, memory_scope scope);
 ulong __ovld atomic_fetch_max_explicit(volatile __local atomic_ulong *object, 
ulong operand, memory_order order, memory_scope scope);
-uintptr_t __ovld atomic_fetch_add_explicit(volatile __global atomic_uintptr_t 
*object, ptr
diff _t operand, memory_order order, memory_scope scope);
-uintptr_t __ovld atomic_fetch_sub_explicit(volatile __local atomic_uintptr_t 
*object, ptr
diff _t operand, memory_order order, memory_scope scope);
+uintptr_t __ovld atomic_fetch_max_explicit(volatile __global atomic_uintptr_t 
*object, uintptr_t operand, memory_order order, memory_scope scope);
+uintptr_t __ovld atomic_fetch_max_explicit(volatile __local atomic_uintptr_t 
*object, uintptr_t operand, memory_order order, memory_scope scope);
 #endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif // (__OPENCL_C_VERSION__ >= CL_VERSION_3_0 || __OPENCL_CPP_VERSION__ >= 
202100)
 



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


[clang] 50f8abb - [OpenCL] Add OpenCL 3.0 atomics to -fdeclare-opencl-builtins

2022-02-11 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-11T10:14:14Z
New Revision: 50f8abb9f40a6c4974ec71e760773a711732648f

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

LOG: [OpenCL] Add OpenCL 3.0 atomics to -fdeclare-opencl-builtins

Add the atomic overloads for the `global` and `local` address spaces,
which are new in OpenCL 3.0.  Ensure the preexisting `generic`
overloads are guarded by the generic address space feature macro.

Ensure a subset of the atomic builtins are guarded by the
`__opencl_c_atomic_order_seq_cst` and `__opencl_c_atomic_scope_device`
feature macros, and enable those macros for SPIR/SPIR-V targets in
`opencl-c-base.h`.

Also guard the `cl_ext_float_atomics` builtins with the atomic order
and scope feature macros.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index ad276dc0f6aae..5191c41bcd057 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -67,6 +67,8 @@
 #if (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
 // For the SPIR and SPIR-V target all features are supported.
 #if defined(__SPIR__) || defined(__SPIRV__)
+#define __opencl_c_atomic_order_seq_cst 1
+#define __opencl_c_atomic_scope_device 1
 #define __opencl_c_atomic_scope_all_devices 1
 #define __opencl_c_read_write_images 1
 #endif // defined(__SPIR__)

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 4d36df352d5ec..ab30553005729 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -57,6 +57,23 @@ class FunctionExtension : 
AbstractExtension<_Ext>;
 // disabled.
 class TypeExtension : AbstractExtension<_Ext>;
 
+// Concatenate zero or more space-separated extensions in NewExts to Base and
+// return the resulting FunctionExtension in ret.
+class concatExtension {
+  FunctionExtension ret = FunctionExtension<
+!cond(
+  // Return Base extension if NewExts is empty,
+  !empty(NewExts) : Base.ExtName,
+
+  // otherwise, return NewExts if Base extension is empty,
+  !empty(Base.ExtName) : NewExts,
+
+  // otherwise, concatenate NewExts to Base.
+  true : Base.ExtName # " " # NewExts
+)
+  >;
+}
+
 // TypeExtension definitions.
 def NoTypeExt   : TypeExtension<"">;
 def Fp16TypeExt : TypeExtension<"cl_khr_fp16">;
@@ -1043,40 +1060,57 @@ let Extension = FuncExtOpenCLCxx in {
 // OpenCL v2.0 s6.13.11 - Atomic Functions.
 
 // An atomic builtin with 2 additional _explicit variants.
-multiclass BuiltinAtomicExplicit Types> {
+multiclass BuiltinAtomicExplicit Types, 
FunctionExtension BaseExt> {
   // Without explicit MemoryOrder or MemoryScope.
-  def : Builtin;
+  let Extension = concatExtension.ret in {
+def : Builtin;
+  }
 
   // With an explicit MemoryOrder argument.
-  def : Builtin;
+  let Extension = concatExtension.ret in {
+def : Builtin;
+  }
 
   // With explicit MemoryOrder and MemoryScope arguments.
-  def : Builtin;
+  let Extension = BaseExt in {
+def : Builtin;
+  }
 }
 
 // OpenCL 2.0 atomic functions that have a pointer argument in a given address 
space.
-multiclass OpenCL2Atomics {
+multiclass OpenCL2Atomics {
   foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
   [AtomicLong, Long], [AtomicULong, ULong],
   [AtomicFloat, Float], [AtomicDouble, Double]] in {
 def : Builtin<"atomic_init",
 [Void, PointerType, addrspace>, 
TypePair[1]]>;
 defm : BuiltinAtomicExplicit<"atomic_store",
-[Void, PointerType, addrspace>, 
TypePair[1]]>;
+[Void, PointerType, addrspace>, 
TypePair[1]], BaseExt>;
 defm : BuiltinAtomicExplicit<"atomic_load",
-[TypePair[1], PointerType, addrspace>]>;
+[TypePair[1], PointerType, addrspace>], 
BaseExt>;
 defm : BuiltinAtomicExplicit<"atomic_exchange",
-[TypePair[1], PointerType, addrspace>, 
TypePair[1]]>;
+[TypePair[1], PointerType, addrspace>, 
TypePair[1]], BaseExt>;
 foreach Variant = ["weak", "strong"] in {
-  def : Builtin<"atomic_compare_exchange_" # Variant,
-  [Bool, PointerType, addrspace>,
-   PointerType, TypePair[1]]>;
-  def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
-  [Bool, PointerType, addrspace>,
-   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder]>;
-  def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
-  [Bool, PointerType, addrspace>,
-   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder, MemoryScope]>;
+ 

[clang] 8d37043 - [OpenCL] Refactor cl_ext_float_atomics declarations; NFC

2022-02-10 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-10T09:43:32Z
New Revision: 8d37043520f57e63e032c9d0ba4cba8701a3cd35

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

LOG: [OpenCL] Refactor cl_ext_float_atomics declarations; NFC

Reduce the amount of repetition in the declarations by leveraging more
TableGen constructs.  This is in preparation for adding the OpenCL 3.0
atomics feature optionality.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 60a05f95fbec8..4d36df352d5ec 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -90,27 +90,27 @@ def FuncExtOpenCLCNamedAddressSpaceBuiltins : 
FunctionExtension<"__opencl_c_name
 def FuncExtOpenCLCPipes  : 
FunctionExtension<"__opencl_c_pipes">;
 def FuncExtOpenCLCWGCollectiveFunctions  : 
FunctionExtension<"__opencl_c_work_group_collective_functions">;
 def FuncExtOpenCLCReadWriteImages: 
FunctionExtension<"__opencl_c_read_write_images">;
-def FuncExtFloatAtomicsFp16GlobalLoadStore  : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_global_atomic_load_store">;
-def FuncExtFloatAtomicsFp16LocalLoadStore   : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_local_atomic_load_store">;
-def FuncExtFloatAtomicsFp16GenericLoadStore : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_global_atomic_load_store 
__opencl_c_ext_fp16_local_atomic_load_store">;
-def FuncExtFloatAtomicsFp16GlobalAdd : 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_add">;
-def FuncExtFloatAtomicsFp32GlobalAdd : 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_global_atomic_add">;
-def FuncExtFloatAtomicsFp64GlobalAdd : 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_global_atomic_add">;
-def FuncExtFloatAtomicsFp16LocalAdd  : 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_add">;
-def FuncExtFloatAtomicsFp32LocalAdd  : 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_add">;
-def FuncExtFloatAtomicsFp64LocalAdd  : 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_add">;
-def FuncExtFloatAtomicsFp16GenericAdd: 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_local_atomic_add 
__opencl_c_ext_fp16_global_atomic_add">;
-def FuncExtFloatAtomicsFp32GenericAdd: 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp32_local_atomic_add 
__opencl_c_ext_fp32_global_atomic_add">;
-def FuncExtFloatAtomicsFp64GenericAdd: 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp64_local_atomic_add 
__opencl_c_ext_fp64_global_atomic_add">;
-def FuncExtFloatAtomicsFp16GlobalMinMax  : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_global_atomic_min_max">;
-def FuncExtFloatAtomicsFp32GlobalMinMax  : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp32_global_atomic_min_max">;
-def FuncExtFloatAtomicsFp64GlobalMinMax  : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp64_global_atomic_min_max">;
-def FuncExtFloatAtomicsFp16LocalMinMax   : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_local_atomic_min_max">;
-def FuncExtFloatAtomicsFp32LocalMinMax   : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp32_local_atomic_min_max">;
-def FuncExtFloatAtomicsFp64LocalMinMax   : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp64_local_atomic_min_max">;
-def FuncExtFloatAtomicsFp16GenericMinMax : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_local_atomic_min_max 
__opencl_c_ext_fp16_global_atomic_min_max">;
-def FuncExtFloatAtomicsFp32GenericMinMax : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp32_local_atomic_min_max 
__opencl_c_ext_fp32_global_atomic_min_max">;
-def FuncExtFloatAtomicsFp64GenericMinMax : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp64_local_atomic_min_max 
__opencl_c_ext_fp64_global_atomic_min_max">;
+def FuncExtFloatAtomicsFp16GlobalASLoadStore  : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_global_atomic_load_store">;
+def FuncExtFloatAtomicsFp16LocalASLoadStore   : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_local_atomic_load_store">;
+def FuncExtFloatAtomicsFp16GenericASLoadStore : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_global_atomic_load_store 
__opencl_c_ext_fp16_local_atomic_load_store">;
+def FuncExtFloatAtomicsFp16GlobalASAdd: 
FunctionExtension<"cl_ext_float_atomics __opencl_c_ext_fp16_global_atomic_add">;
+def FuncExtFloatAtomicsFp32GlobalASAdd: 
FunctionExtension<"cl_ext_float_atomics 

[clang] a464444 - [OpenCL][Docs] Update OpenCL 3.0 status info

2022-02-09 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-09T15:12:49Z
New Revision: a46b2888b9d0fcfb712897f0110cadb84d93

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

LOG: [OpenCL][Docs] Update OpenCL 3.0 status info

Update the table to reflect recently committed work.

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index c1202601d48d3..7303c2b4e645b 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -382,17 +382,17 @@ implementation status.
 
+--+-+-+--+--+
 | Feature optionality  | Generic address space 
| :good:`done` | https://reviews.llvm.org/D95778 
and https://reviews.llvm.org/D103401 |
 
+--+-+-+--+--+
-| Feature optionality  | Builtin function overloads with generic 
address space | :good:`done` | 
https://reviews.llvm.org/D105526
 |
+| Feature optionality  | Builtin function overloads with generic 
address space | :good:`done` | 
https://reviews.llvm.org/D105526 and https://reviews.llvm.org/D107769   
 |
 
+--+-+-+--+--+
 | Feature optionality  | Program scope variables in global memory  
| :good:`done` | https://reviews.llvm.org/D103191   
  |
 
+--+-+-+--+--+
 | Feature optionality  | 3D image writes including builtin functions   
| :part:`worked on`| https://reviews.llvm.org/D106260 
(frontend)  |
 
+--+-+-+--+--+
-| Feature optionality  | read_write images including builtin functions 
| :part:`worked on`| https://reviews.llvm.org/D104915 
(frontend) and https://reviews.llvm.org/D107539 (functions) |
+| Feature optionality  | read_write images including builtin functions 
| :good:`done` | https://reviews.llvm.org/D104915 
(frontend) and https://reviews.llvm.org/D107539 (functions) |
 
+--+-+-+--+--+
 | Feature optionality  | C11 atomics memory scopes, ordering and 
builtin function  | :good:`done` | 
https://reviews.llvm.org/D106111
 |
 
+--+-+-+--+--+
-| Feature optionality  | Blocks and Device-side kernel enqueue 
including builtin functions | :none:`unclaimed`|
  |
+| Feature optionality  | Blocks and Device-side kernel enqueue 
including builtin functions | :part:`worked on`| 
https://reviews.llvm.org/D118605
 |
 
+--+-+-+--+--+
 | Feature optionality  | Pipes including builtin functions 
| :good:`done` | https://reviews.llvm.org/D107154 
(frontend) and https://reviews.llvm.org/D105858 

[clang] fe69058 - [OpenCL] Fix atomic_fetch_add/sub with half type

2022-02-09 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-09T10:47:45Z
New Revision: fe690587bedb23dec2753549d4216059a7f894a1

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

LOG: [OpenCL] Fix atomic_fetch_add/sub with half type

An error in the tablegen description affects the declarations
provided by `-fdeclare-opencl-builtins` for `atomic_fetch_add` and
`atomic_fetch_sub`.

The atomic argument should be an atomic_half, not an atomic_float.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 08f8630a67e22..60a05f95fbec8 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1138,7 +1138,7 @@ let MinVersion = CL20 in {
   foreach ModOp = ["add", "sub"] in {
 let Extension = FuncExtFloatAtomicsFp16GlobalAdd in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
-  [Half, PointerType, GlobalAS>, Half]>;
+  [Half, PointerType, GlobalAS>, Half]>;
 }
 let Extension = FuncExtFloatAtomicsFp32GlobalAdd in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
@@ -1150,7 +1150,7 @@ let MinVersion = CL20 in {
 }
 let Extension = FuncExtFloatAtomicsFp16LocalAdd in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
-  [Half, PointerType, LocalAS>, Half]>;
+  [Half, PointerType, LocalAS>, Half]>;
 }
 let Extension = FuncExtFloatAtomicsFp32LocalAdd in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
@@ -1162,7 +1162,7 @@ let MinVersion = CL20 in {
 }
 let Extension = FuncExtFloatAtomicsFp16GenericAdd in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
-  [Half, PointerType, GenericAS>, Half]>;
+  [Half, PointerType, GenericAS>, Half]>;
 }
 let Extension = FuncExtFloatAtomicsFp32GenericAdd in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,



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


[clang] 9b8a93e - [OpenCL] opencl-c.h: remove arg names from arm_dot; NFC

2022-02-08 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-08T13:42:24Z
New Revision: 9b8a93e3b6d36ad4f96c93a6c41ca4b0ef6d3d22

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

LOG: [OpenCL] opencl-c.h: remove arg names from arm_dot; NFC

This simplifies completeness comparisons against OpenCLBuiltins.td.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 6e5733249ee4c..98c92fd7ef0a3 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -18517,23 +18517,23 @@ uint16 __ovld amd_sadw(uint16 src0, uint16 src1, 
uint16 src2);
 #endif // cl_amd_media_ops2
 
 #if defined(cl_arm_integer_dot_product_int8)
-uint __ovld arm_dot(uchar4 a, uchar4 b);
-int __ovld arm_dot(char4 a, char4 b);
+uint __ovld arm_dot(uchar4, uchar4);
+int __ovld arm_dot(char4, char4);
 #endif // defined(cl_arm_integer_dot_product_int8)
 
 #if defined(cl_arm_integer_dot_product_accumulate_int8)
-uint __ovld arm_dot_acc(uchar4 a, uchar4 b, uint c);
-int __ovld arm_dot_acc(char4 a, char4 b, int c);
+uint __ovld arm_dot_acc(uchar4, uchar4, uint);
+int __ovld arm_dot_acc(char4, char4, int);
 #endif // defined(cl_arm_integer_dot_product_accumulate_int8)
 
 #if defined(cl_arm_integer_dot_product_accumulate_int16)
-uint __ovld arm_dot_acc(ushort2 a, ushort2 b, uint c);
-int __ovld arm_dot_acc(short2 a, short2 b, int c);
+uint __ovld arm_dot_acc(ushort2, ushort2, uint);
+int __ovld arm_dot_acc(short2, short2, int);
 #endif // defined(cl_arm_integer_dot_product_accumulate_int16)
 
 #if defined(cl_arm_integer_dot_product_accumulate_saturate_int8)
-uint __ovld arm_dot_acc_sat(uchar4 a, uchar4 b, uint c);
-int __ovld arm_dot_acc_sat(char4 a, char4 b, int c);
+uint __ovld arm_dot_acc_sat(uchar4, uchar4, uint);
+int __ovld arm_dot_acc_sat(char4, char4, int);
 #endif // defined(cl_arm_integer_dot_product_accumulate_saturate_int8)
 
 // Disable any extensions we may have enabled previously.



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


[clang] c15782b - [OpenCL] opencl-c.h: make attribute order consistent; NFC

2022-02-07 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-07T10:54:55Z
New Revision: c15782bcf5c900fc43fd545c9572f77ef92c5f5e

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

LOG: [OpenCL] opencl-c.h: make attribute order consistent; NFC

For most builtins, `__purefn` always comes after `__ovld`, but the
read_image functions did not follow this pattern.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 059a2ec2371bd..6e5733249ee4c 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15427,123 +15427,123 @@ half16 __ovld __cnfn shuffle2(half16 x, half16 y, 
ushort16 mask);
  * in the description above are undefined.
  */
 
-float4 __purefn __ovld read_imagef(read_only image2d_t image, sampler_t 
sampler, int2 coord);
-float4 __purefn __ovld read_imagef(read_only image2d_t image, sampler_t 
sampler, float2 coord);
+float4 __ovld __purefn read_imagef(read_only image2d_t image, sampler_t 
sampler, int2 coord);
+float4 __ovld __purefn read_imagef(read_only image2d_t image, sampler_t 
sampler, float2 coord);
 
-int4 __purefn __ovld read_imagei(read_only image2d_t image, sampler_t sampler, 
int2 coord);
-int4 __purefn __ovld read_imagei(read_only image2d_t image, sampler_t sampler, 
float2 coord);
-uint4 __purefn __ovld read_imageui(read_only image2d_t image, sampler_t 
sampler, int2 coord);
-uint4 __purefn __ovld read_imageui(read_only image2d_t image, sampler_t 
sampler, float2 coord);
+int4 __ovld __purefn read_imagei(read_only image2d_t image, sampler_t sampler, 
int2 coord);
+int4 __ovld __purefn read_imagei(read_only image2d_t image, sampler_t sampler, 
float2 coord);
+uint4 __ovld __purefn read_imageui(read_only image2d_t image, sampler_t 
sampler, int2 coord);
+uint4 __ovld __purefn read_imageui(read_only image2d_t image, sampler_t 
sampler, float2 coord);
 
-float4 __purefn __ovld read_imagef(read_only image3d_t image, sampler_t 
sampler, int4 coord);
-float4 __purefn __ovld read_imagef(read_only image3d_t image, sampler_t 
sampler, float4 coord);
+float4 __ovld __purefn read_imagef(read_only image3d_t image, sampler_t 
sampler, int4 coord);
+float4 __ovld __purefn read_imagef(read_only image3d_t image, sampler_t 
sampler, float4 coord);
 
-int4 __purefn __ovld read_imagei(read_only image3d_t image, sampler_t sampler, 
int4 coord);
-int4 __purefn __ovld read_imagei(read_only image3d_t image, sampler_t sampler, 
float4 coord);
-uint4 __purefn __ovld read_imageui(read_only image3d_t image, sampler_t 
sampler, int4 coord);
-uint4 __purefn __ovld read_imageui(read_only image3d_t image, sampler_t 
sampler, float4 coord);
+int4 __ovld __purefn read_imagei(read_only image3d_t image, sampler_t sampler, 
int4 coord);
+int4 __ovld __purefn read_imagei(read_only image3d_t image, sampler_t sampler, 
float4 coord);
+uint4 __ovld __purefn read_imageui(read_only image3d_t image, sampler_t 
sampler, int4 coord);
+uint4 __ovld __purefn read_imageui(read_only image3d_t image, sampler_t 
sampler, float4 coord);
 
 #if defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= CL_VERSION_1_2)
-float4 __purefn __ovld read_imagef(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
-float4 __purefn __ovld read_imagef(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
+float4 __ovld __purefn read_imagef(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
+float4 __ovld __purefn read_imagef(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
 
-int4 __purefn __ovld read_imagei(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
-int4 __purefn __ovld read_imagei(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
-uint4 __purefn __ovld read_imageui(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
-uint4 __purefn __ovld read_imageui(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
+int4 __ovld __purefn read_imagei(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
+int4 __ovld __purefn read_imagei(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
+uint4 __ovld __purefn read_imageui(read_only image2d_array_t image_array, 
sampler_t sampler, int4 coord);
+uint4 __ovld __purefn read_imageui(read_only image2d_array_t image_array, 
sampler_t sampler, float4 coord);
 #endif // defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_1_2)
 
-float4 __purefn __ovld read_imagef(read_only image1d_t image, sampler_t 
sampler, int coord);
-float4 __purefn __ovld read_imagef(read_only image1d_t image, sampler_t 
sampler, float coord);
+float4 __ovld __purefn 

[clang] 31fa3a4 - [OpenCL] Move OpenCL 2.0 atomics into multiclass; NFC

2022-02-04 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-04T10:17:48Z
New Revision: 31fa3a4d44316fd36e11f92729ea9596ee3bf3f8

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

LOG: [OpenCL] Move OpenCL 2.0 atomics into multiclass; NFC

This is in preparation for adding the OpenCL 3.0 builtins with named
address space arguments.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 516653681331e..08f8630a67e22 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1040,6 +1040,8 @@ let Extension = FuncExtOpenCLCxx in {
   }
 }
 
+// OpenCL v2.0 s6.13.11 - Atomic Functions.
+
 // An atomic builtin with 2 additional _explicit variants.
 multiclass BuiltinAtomicExplicit Types> {
   // Without explicit MemoryOrder or MemoryScope.
@@ -1052,31 +1054,29 @@ multiclass BuiltinAtomicExplicit Types> {
   def : Builtin;
 }
 
-// OpenCL v2.0 s6.13.11 - Atomic Functions.
-let MinVersion = CL20 in {
-  def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, 
MemoryScope]>;
-
+// OpenCL 2.0 atomic functions that have a pointer argument in a given address 
space.
+multiclass OpenCL2Atomics {
   foreach TypePair = [[AtomicInt, Int], [AtomicUInt, UInt],
   [AtomicLong, Long], [AtomicULong, ULong],
   [AtomicFloat, Float], [AtomicDouble, Double]] in {
 def : Builtin<"atomic_init",
-[Void, PointerType, GenericAS>, 
TypePair[1]]>;
+[Void, PointerType, addrspace>, 
TypePair[1]]>;
 defm : BuiltinAtomicExplicit<"atomic_store",
-[Void, PointerType, GenericAS>, 
TypePair[1]]>;
+[Void, PointerType, addrspace>, 
TypePair[1]]>;
 defm : BuiltinAtomicExplicit<"atomic_load",
-[TypePair[1], PointerType, GenericAS>]>;
+[TypePair[1], PointerType, addrspace>]>;
 defm : BuiltinAtomicExplicit<"atomic_exchange",
-[TypePair[1], PointerType, GenericAS>, 
TypePair[1]]>;
+[TypePair[1], PointerType, addrspace>, 
TypePair[1]]>;
 foreach Variant = ["weak", "strong"] in {
   def : Builtin<"atomic_compare_exchange_" # Variant,
-  [Bool, PointerType, GenericAS>,
-   PointerType, TypePair[1]]>;
+  [Bool, PointerType, addrspace>,
+   PointerType, TypePair[1]]>;
   def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
-  [Bool, PointerType, GenericAS>,
-   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder]>;
+  [Bool, PointerType, addrspace>,
+   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder]>;
   def : Builtin<"atomic_compare_exchange_" # Variant # "_explicit",
-  [Bool, PointerType, GenericAS>,
-   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder, MemoryScope]>;
+  [Bool, PointerType, addrspace>,
+   PointerType, TypePair[1], MemoryOrder, 
MemoryOrder, MemoryScope]>;
 }
   }
 
@@ -1085,22 +1085,28 @@ let MinVersion = CL20 in {
   [AtomicUIntPtr, UIntPtr, PtrDiff]] in {
 foreach ModOp = ["add", "sub"] in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
-  [TypePair[1], PointerType, GenericAS>, 
TypePair[2]]>;
+  [TypePair[1], PointerType, addrspace>, 
TypePair[2]]>;
 }
   }
   foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
   [AtomicLong, Long, Long], [AtomicULong, ULong, ULong]] 
in {
 foreach ModOp = ["or", "xor", "and", "min", "max"] in {
   defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
-  [TypePair[1], PointerType, GenericAS>, 
TypePair[2]]>;
+  [TypePair[1], PointerType, addrspace>, 
TypePair[2]]>;
 }
   }
 
   defm : BuiltinAtomicExplicit<"atomic_flag_clear",
-  [Void, PointerType, GenericAS>]>;
+  [Void, PointerType, addrspace>]>;
 
   defm : BuiltinAtomicExplicit<"atomic_flag_test_and_set",
-  [Bool, PointerType, GenericAS>]>;
+  [Bool, PointerType, addrspace>]>;
+}
+
+let MinVersion = CL20 in {
+  def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, 
MemoryScope]>;
+
+  defm : OpenCL2Atomics;
 }
 
 // The functionality added by cl_ext_float_atomics extension



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


[clang] 9694332 - [clang-format] Add missing newline in -style help

2022-02-03 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-03T12:12:29Z
New Revision: 9694332b81dd14a0a2ab5d9ea9977558fd5f53be

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

LOG: [clang-format] Add missing newline in -style help

Added: 


Modified: 
clang/lib/Format/Format.cpp

Removed: 




diff  --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 1ee557079f6c..daa815106049 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -3246,7 +3246,7 @@ const char *StyleOptionHelpDescription =
 ".clang-format file located in one of the parent\n"
 "directories of the source file (or current\n"
 "directory for stdin).\n"
-"Use -style=file: to explicitly specify"
+"Use -style=file: to explicitly specify\n"
 "the configuration file.\n"
 "Use -style=\"{key: value, ...}\" to set specific\n"
 "parameters, e.g.:\n"



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


[clang] d97a4df - [OpenCL] Move most _explicit atomics into multiclass; NFC

2022-02-03 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-03T11:09:41Z
New Revision: d97a4dfea6c2781494f6fe54ce265128f5c08dc2

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

LOG: [OpenCL] Move most _explicit atomics into multiclass; NFC

This will simplify future conditionalization for OpenCL 3.0
optionality of atomic features.

The only set of atomic functions not using the multiclass is
atomic_compare_exchange_strong/weak, as these don't fit the common
pattern due to having 2 MemoryOrder arguments.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index cd704ba2df13d..516653681331e 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1040,6 +1040,18 @@ let Extension = FuncExtOpenCLCxx in {
   }
 }
 
+// An atomic builtin with 2 additional _explicit variants.
+multiclass BuiltinAtomicExplicit Types> {
+  // Without explicit MemoryOrder or MemoryScope.
+  def : Builtin;
+
+  // With an explicit MemoryOrder argument.
+  def : Builtin;
+
+  // With explicit MemoryOrder and MemoryScope arguments.
+  def : Builtin;
+}
+
 // OpenCL v2.0 s6.13.11 - Atomic Functions.
 let MinVersion = CL20 in {
   def : Builtin<"atomic_work_item_fence", [Void, MemFenceFlags, MemoryOrder, 
MemoryScope]>;
@@ -1049,24 +1061,12 @@ let MinVersion = CL20 in {
   [AtomicFloat, Float], [AtomicDouble, Double]] in {
 def : Builtin<"atomic_init",
 [Void, PointerType, GenericAS>, 
TypePair[1]]>;
-def : Builtin<"atomic_store",
+defm : BuiltinAtomicExplicit<"atomic_store",
 [Void, PointerType, GenericAS>, 
TypePair[1]]>;
-def : Builtin<"atomic_store_explicit",
-[Void, PointerType, GenericAS>, TypePair[1], 
MemoryOrder]>;
-def : Builtin<"atomic_store_explicit",
-[Void, PointerType, GenericAS>, TypePair[1], 
MemoryOrder, MemoryScope]>;
-def : Builtin<"atomic_load",
+defm : BuiltinAtomicExplicit<"atomic_load",
 [TypePair[1], PointerType, GenericAS>]>;
-def : Builtin<"atomic_load_explicit",
-[TypePair[1], PointerType, GenericAS>, 
MemoryOrder]>;
-def : Builtin<"atomic_load_explicit",
-[TypePair[1], PointerType, GenericAS>, 
MemoryOrder, MemoryScope]>;
-def : Builtin<"atomic_exchange",
+defm : BuiltinAtomicExplicit<"atomic_exchange",
 [TypePair[1], PointerType, GenericAS>, 
TypePair[1]]>;
-def : Builtin<"atomic_exchange_explicit",
-[TypePair[1], PointerType, GenericAS>, 
TypePair[1], MemoryOrder]>;
-def : Builtin<"atomic_exchange_explicit",
-[TypePair[1], PointerType, GenericAS>, 
TypePair[1], MemoryOrder, MemoryScope]>;
 foreach Variant = ["weak", "strong"] in {
   def : Builtin<"atomic_compare_exchange_" # Variant,
   [Bool, PointerType, GenericAS>,
@@ -1084,249 +1084,125 @@ let MinVersion = CL20 in {
   [AtomicLong, Long, Long], [AtomicULong, ULong, ULong],
   [AtomicUIntPtr, UIntPtr, PtrDiff]] in {
 foreach ModOp = ["add", "sub"] in {
-  def : Builtin<"atomic_fetch_" # ModOp,
+  defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
   [TypePair[1], PointerType, GenericAS>, 
TypePair[2]]>;
-  def : Builtin<"atomic_fetch_" # ModOp # "_explicit",
-  [TypePair[1], PointerType, GenericAS>, 
TypePair[2], MemoryOrder]>;
-  def : Builtin<"atomic_fetch_" # ModOp # "_explicit",
-  [TypePair[1], PointerType, GenericAS>, 
TypePair[2], MemoryOrder, MemoryScope]>;
 }
   }
   foreach TypePair = [[AtomicInt, Int, Int], [AtomicUInt, UInt, UInt],
   [AtomicLong, Long, Long], [AtomicULong, ULong, ULong]] 
in {
 foreach ModOp = ["or", "xor", "and", "min", "max"] in {
-  def : Builtin<"atomic_fetch_" # ModOp,
+  defm : BuiltinAtomicExplicit<"atomic_fetch_" # ModOp,
   [TypePair[1], PointerType, GenericAS>, 
TypePair[2]]>;
-  def : Builtin<"atomic_fetch_" # ModOp # "_explicit",
-  [TypePair[1], PointerType, GenericAS>, 
TypePair[2], MemoryOrder]>;
-  def : Builtin<"atomic_fetch_" # ModOp # "_explicit",
-  [TypePair[1], PointerType, GenericAS>, 
TypePair[2], MemoryOrder, MemoryScope]>;
 }
   }
 
-  def : Builtin<"atomic_flag_clear",
+  defm : BuiltinAtomicExplicit<"atomic_flag_clear",
   [Void, PointerType, GenericAS>]>;
-  def : Builtin<"atomic_flag_clear_explicit",
-  [Void, PointerType, GenericAS>, MemoryOrder]>;
-  def : Builtin<"atomic_flag_clear_explicit",
-  [Void, PointerType, GenericAS>, MemoryOrder, 
MemoryScope]>;
 
-  def : Builtin<"atomic_flag_test_and_set",
+  defm : BuiltinAtomicExplicit<"atomic_flag_test_and_set",
   [Bool, PointerType, GenericAS>]>;
-  def : 

[clang] e0e6f3a - [OpenCL] Test -fdeclare-opencl-builtins with CL3 and CLC++2021

2022-02-02 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-02-02T10:23:02Z
New Revision: e0e6f3a6a2e13ee11b014ca45a48997e78d3efc5

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

LOG: [OpenCL] Test -fdeclare-opencl-builtins with CL3 and CLC++2021

But only test in combination with -finclude-default-header, as the
headerless tests may be dropped soon.

Added: 


Modified: 
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl 
b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
index 8c5863987be6..d1a4f7283726 100644
--- a/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl
@@ -4,8 +4,10 @@
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -DNO_HEADER
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CLC++ -fdeclare-opencl-builtins -finclude-default-header
+// RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CLC++2021 -fdeclare-opencl-builtins 
-finclude-default-header
 // RUN: %clang_cc1 %s -triple spir -verify -pedantic -Wconversion -Werror 
-fsyntax-only -cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header 
-cl-ext=-cl_khr_fp64 -DNO_FP64
 
 // Test the -fdeclare-opencl-builtins option.  This is not a completeness



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


[clang] 8e60992 - [OpenCL] Make generic addrspace optional for -fdeclare-opencl-builtins

2022-01-31 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-01-31T10:21:05Z
New Revision: 8e6099291dcb49b90e59a591ec24c77f348239b6

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

LOG: [OpenCL] Make generic addrspace optional for -fdeclare-opencl-builtins

Currently, -fdeclare-opencl-builtins always adds the generic address
space overloads of e.g. the vload builtin functions in OpenCL 3.0
mode, even when the generic address space feature is disabled.

Guard the generic address space overloads by the
`__opencl_c_generic_address_space` feature instead of by OpenCL
version.

Guard the private, global, and local overloads using the internal
`__opencl_c_named_address_space_builtins` feature.

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

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td
clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index df2f206041c10..cd704ba2df13d 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -85,6 +85,8 @@ def FuncExtKhrMipmapImageWrites  : 
FunctionExtension<"cl_khr_mipmap_imag
 def FuncExtKhrGlMsaaSharing  : 
FunctionExtension<"cl_khr_gl_msaa_sharing">;
 def FuncExtKhrGlMsaaSharingReadWrite : 
FunctionExtension<"cl_khr_gl_msaa_sharing __opencl_c_read_write_images">;
 
+def FuncExtOpenCLCGenericAddressSpace: 
FunctionExtension<"__opencl_c_generic_address_space">;
+def FuncExtOpenCLCNamedAddressSpaceBuiltins : 
FunctionExtension<"__opencl_c_named_address_space_builtins">;
 def FuncExtOpenCLCPipes  : 
FunctionExtension<"__opencl_c_pipes">;
 def FuncExtOpenCLCWGCollectiveFunctions  : 
FunctionExtension<"__opencl_c_work_group_collective_functions">;
 def FuncExtOpenCLCReadWriteImages: 
FunctionExtension<"__opencl_c_read_write_images">;
@@ -591,10 +593,10 @@ multiclass MathWithPointer addrspaces> 
{
   }
 }
 
-let MaxVersion = CL20 in {
+let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
   defm : MathWithPointer<[GlobalAS, LocalAS, PrivateAS]>;
 }
-let MinVersion = CL20 in {
+let Extension = FuncExtOpenCLCGenericAddressSpace in {
   defm : MathWithPointer<[GenericAS]>;
 }
 
@@ -840,10 +842,10 @@ multiclass VloadVstore addrspaces, bit 
defStores> {
   }
 }
 
-let MaxVersion = CL20 in {
+let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
   defm : VloadVstore<[GlobalAS, LocalAS, PrivateAS], 1>;
 }
-let MinVersion = CL20 in {
+let Extension = FuncExtOpenCLCGenericAddressSpace in {
   defm : VloadVstore<[GenericAS], 1>;
 }
 // vload with constant address space is available regardless of version.
@@ -874,10 +876,10 @@ multiclass VloadVstoreHalf addrspaces, 
bit defStores> {
   }
 }
 
-let MaxVersion = CL20 in {
+let Extension = FuncExtOpenCLCNamedAddressSpaceBuiltins in {
   defm : VloadVstoreHalf<[GlobalAS, LocalAS, PrivateAS], 1>;
 }
-let MinVersion = CL20 in {
+let Extension = FuncExtOpenCLCGenericAddressSpace in {
   defm : VloadVstoreHalf<[GenericAS], 1>;
 }
 // vload_half and vloada_half with constant address space are available 
regardless of version.

diff  --git a/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl 
b/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl
index 665297b469f83..f0ebf6e3c0eac 100644
--- a/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl
+++ b/clang/test/CodeGenOpenCL/fdeclare-opencl-builtins.cl
@@ -1,5 +1,12 @@
-// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown 
-cl-std=CL1.2 -finclude-default-header %s | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown 
-cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header %s | FileCheck 
%s
+// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown 
-cl-std=CL1.2 -finclude-default-header %s \
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-NOGAS
+// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown 
-cl-std=CL1.2 -fdeclare-opencl-builtins -finclude-default-header %s \
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-NOGAS
+// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown 
-cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header %s \
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-GAS
+// RUN: %clang_cc1 -emit-llvm -o - -O0 -triple spir-unknown-unknown 
-cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header \
+// RUN: 
-cl-ext=-__opencl_c_generic_address_space,-__opencl_c_pipes,-__opencl_c_device_enqueue
 %s \
+// RUN: | FileCheck %s --check-prefixes CHECK,CHECK-NOGAS
 
 // Test that mix is correctly defined.
 // CHECK-LABEL: @test_float
@@ -32,6 +39,15 @@ kernel void test_mangling() {
   

[clang] bfd8210 - [OpenCL] opencl-c.h: refactor named addrspace builtins

2022-01-28 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-01-28T10:24:47Z
New Revision: bfd8210f6f470d79a78f57ebe02650bbb5a79129

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

LOG: [OpenCL] opencl-c.h: refactor named addrspace builtins

The named address space overloads of builtins that take a pointer
argument are conditionalized on the `__opencl_c_generic_address_space`
feature macro (in a `#else` body).  Introduce an internal feature
macro instead, such that their availability can be controlled in a
single place and independently of the generic address space feature
macro.

This commit does not change the available builtins.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 06b78da63e698..ad276dc0f6aae 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -72,6 +72,12 @@
 #endif // defined(__SPIR__)
 #endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
 
+#if !defined(__opencl_c_generic_address_space)
+// Internal feature macro to provide named (global, local, private) address
+// space overloads for builtin functions that take a pointer argument.
+#define __opencl_c_named_address_space_builtins 1
+#endif // !defined(__opencl_c_generic_address_space)
+
 // built-in scalar data types:
 
 /**

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 8fde2fa298994..059a2ec2371bd 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -7285,7 +7285,9 @@ half4 __ovld fract(half4 x, half4 *iptr);
 half8 __ovld fract(half8 x, half8 *iptr);
 half16 __ovld fract(half16 x, half16 *iptr);
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_address_space_builtins)
 float __ovld fract(float x, __global float *iptr);
 float2 __ovld fract(float2 x, __global float2 *iptr);
 float3 __ovld fract(float3 x, __global float3 *iptr);
@@ -7344,7 +7346,7 @@ half4 __ovld fract(half4 x, __private half4 *iptr);
 half8 __ovld fract(half8 x, __private half8 *iptr);
 half16 __ovld fract(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif //defined(__opencl_c_generic_address_space)
+#endif //defined(__opencl_c_named_address_space_builtins)
 
 /**
  * Extract mantissa and exponent from x. For each
@@ -7375,7 +7377,9 @@ half4 __ovld frexp(half4 x, int4 *exp);
 half8 __ovld frexp(half8 x, int8 *exp);
 half16 __ovld frexp(half16 x, int16 *exp);
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_address_space_builtins)
 float __ovld frexp(float x, __global int *exp);
 float2 __ovld frexp(float2 x, __global int2 *exp);
 float3 __ovld frexp(float3 x, __global int3 *exp);
@@ -7434,7 +7438,7 @@ half4 __ovld frexp(half4 x, __private int4 *exp);
 half8 __ovld frexp(half8 x, __private int8 *exp);
 half16 __ovld frexp(half16 x, __private int16 *exp);
 #endif //cl_khr_fp16
-#endif //defined(__opencl_c_generic_address_space)
+#endif //defined(__opencl_c_named_address_space_builtins)
 
 /**
  * Compute the value of the square root of x^2 + y^2
@@ -7582,7 +7586,9 @@ half4 __ovld lgamma_r(half4 x, int4 *signp);
 half8 __ovld lgamma_r(half8 x, int8 *signp);
 half16 __ovld lgamma_r(half16 x, int16 *signp);
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_address_space_builtins)
 float __ovld lgamma_r(float x, __global int *signp);
 float2 __ovld lgamma_r(float2 x, __global int2 *signp);
 float3 __ovld lgamma_r(float3 x, __global int3 *signp);
@@ -7641,7 +7647,7 @@ half4 __ovld lgamma_r(half4 x, __private int4 *signp);
 half8 __ovld lgamma_r(half8 x, __private int8 *signp);
 half16 __ovld lgamma_r(half16 x, __private int16 *signp);
 #endif //cl_khr_fp16
-#endif //defined(__opencl_c_generic_address_space)
+#endif //defined(__opencl_c_named_address_space_builtins)
 
 /**
  * Compute natural logarithm.
@@ -7888,7 +7894,9 @@ half4 __ovld modf(half4 x, half4 *iptr);
 half8 __ovld modf(half8 x, half8 *iptr);
 half16 __ovld modf(half16 x, half16 *iptr);
 #endif //cl_khr_fp16
-#else
+#endif //defined(__opencl_c_generic_address_space)
+
+#if defined(__opencl_c_named_address_space_builtins)
 float __ovld modf(float x, __global float *iptr);
 float2 __ovld modf(float2 x, __global float2 *iptr);
 float3 __ovld modf(float3 x, __global float3 *iptr);
@@ -7947,7 +7955,7 @@ half4 __ovld modf(half4 x, __private half4 *iptr);
 half8 __ovld modf(half8 x, __private half8 *iptr);
 half16 __ovld modf(half16 x, __private half16 *iptr);
 #endif //cl_khr_fp16
-#endif 

[clang] 35fff20 - [OpenCL] opencl-c.h: add missing read_write image guards

2022-01-27 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-01-27T10:33:12Z
New Revision: 35fff208cad6f271410800998447dc0dd2704085

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

LOG: [OpenCL] opencl-c.h: add missing read_write image guards

The get_image_num_mip_levels overloads that take a read_write image
parameter were missing the __opencl_c_read_write_images guard.

Added: 


Modified: 
clang/lib/Headers/opencl-c.h

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index e65e3634d010d..f7a85f6578858 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -15688,7 +15688,7 @@ half4 __purefn __ovld read_imageh(read_write 
image1d_array_t image, int2 coord);
 half4 __purefn __ovld read_imageh(read_write image2d_array_t image, int4 
coord);
 half4 __purefn __ovld read_imageh(read_write image1d_buffer_t image, int 
coord);
 #endif //cl_khr_fp16
-#endif //defined(__opencl_c_read_write_images
+#endif //defined(__opencl_c_read_write_images)
 
 /**
  * Write color value to location specified by coordinate
@@ -16049,9 +16049,11 @@ int __ovld get_image_num_mip_levels(write_only 
image2d_t image);
 int __ovld get_image_num_mip_levels(write_only image3d_t image);
 #endif
 
+#if defined(__opencl_c_read_write_images)
 int __ovld get_image_num_mip_levels(read_write image1d_t image);
 int __ovld get_image_num_mip_levels(read_write image2d_t image);
 int __ovld get_image_num_mip_levels(read_write image3d_t image);
+#endif //defined(__opencl_c_read_write_images)
 
 int __ovld get_image_num_mip_levels(read_only image1d_array_t image);
 int __ovld get_image_num_mip_levels(read_only image2d_array_t image);
@@ -16063,10 +16065,12 @@ int __ovld get_image_num_mip_levels(write_only 
image2d_array_t image);
 int __ovld get_image_num_mip_levels(write_only image2d_array_depth_t image);
 int __ovld get_image_num_mip_levels(write_only image2d_depth_t image);
 
+#if defined(__opencl_c_read_write_images)
 int __ovld get_image_num_mip_levels(read_write image1d_array_t image);
 int __ovld get_image_num_mip_levels(read_write image2d_array_t image);
 int __ovld get_image_num_mip_levels(read_write image2d_array_depth_t image);
 int __ovld get_image_num_mip_levels(read_write image2d_depth_t image);
+#endif //defined(__opencl_c_read_write_images)
 
 #endif //cl_khr_mipmap_image
 #endif //defined(__OPENCL_CPP_VERSION__) || (__OPENCL_C_VERSION__ >= 
CL_VERSION_2_0)



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


[clang] 91a0b46 - [OpenCL] Make read_write images optional for -fdeclare-opencl-builtins

2022-01-25 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-01-25T11:40:31Z
New Revision: 91a0b464a853821734db8b1c521df03f8e2e56e7

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

LOG: [OpenCL] Make read_write images optional for -fdeclare-opencl-builtins

Ensure any use of a `read_write` image is guarded behind the
`__opencl_c_read_write_images` feature macro.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 7485386c82346..4f63e7bbdcbba 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -68,6 +68,7 @@
 // For the SPIR and SPIR-V target all features are supported.
 #if defined(__SPIR__) || defined(__SPIRV__)
 #define __opencl_c_atomic_scope_all_devices 1
+#define __opencl_c_read_write_images 1
 #endif // defined(__SPIR__)
 #endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
 

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 38debc5aa9fc5..df2f206041c10 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -80,11 +80,14 @@ def FuncExtKhrLocalInt32ExtendedAtomics  : 
FunctionExtension<"cl_khr_local_int32
 def FuncExtKhrInt64BaseAtomics   : 
FunctionExtension<"cl_khr_int64_base_atomics">;
 def FuncExtKhrInt64ExtendedAtomics   : 
FunctionExtension<"cl_khr_int64_extended_atomics">;
 def FuncExtKhrMipmapImage: 
FunctionExtension<"cl_khr_mipmap_image">;
+def FuncExtKhrMipmapImageReadWrite   : 
FunctionExtension<"cl_khr_mipmap_image __opencl_c_read_write_images">;
 def FuncExtKhrMipmapImageWrites  : 
FunctionExtension<"cl_khr_mipmap_image_writes">;
 def FuncExtKhrGlMsaaSharing  : 
FunctionExtension<"cl_khr_gl_msaa_sharing">;
+def FuncExtKhrGlMsaaSharingReadWrite : 
FunctionExtension<"cl_khr_gl_msaa_sharing __opencl_c_read_write_images">;
 
 def FuncExtOpenCLCPipes  : 
FunctionExtension<"__opencl_c_pipes">;
 def FuncExtOpenCLCWGCollectiveFunctions  : 
FunctionExtension<"__opencl_c_work_group_collective_functions">;
+def FuncExtOpenCLCReadWriteImages: 
FunctionExtension<"__opencl_c_read_write_images">;
 def FuncExtFloatAtomicsFp16GlobalLoadStore  : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_global_atomic_load_store">;
 def FuncExtFloatAtomicsFp16LocalLoadStore   : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_local_atomic_load_store">;
 def FuncExtFloatAtomicsFp16GenericLoadStore : 
FunctionExtension<"cl_ext_float_atomics 
__opencl_c_ext_fp16_global_atomic_load_store 
__opencl_c_ext_fp16_local_atomic_load_store">;
@@ -1390,30 +1393,35 @@ foreach coordTy = [Int, Float] in {
 }
 
 // --- Table 23: Sampler-less Read Functions ---
+multiclass ImageReadSamplerless {
+  foreach imgTy = [Image2d, Image1dArray] in {
+def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
+def : Builtin<"read_imagei", [VectorType, ImageType, 
VectorType], Attr.Pure>;
+def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
+  }
+  foreach imgTy = [Image3d, Image2dArray] in {
+def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
+def : Builtin<"read_imagei", [VectorType, ImageType, 
VectorType], Attr.Pure>;
+def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
+  }
+  foreach imgTy = [Image1d, Image1dBuffer] in {
+def : Builtin<"read_imagef", [VectorType, ImageType, Int], Attr.Pure>;
+def : Builtin<"read_imagei", [VectorType, ImageType, 
Int], Attr.Pure>;
+def : Builtin<"read_imageui", [VectorType, ImageType, Int], Attr.Pure>;
+  }
+  def : Builtin<"read_imagef", [Float, ImageType, 
VectorType], Attr.Pure>;
+  def : Builtin<"read_imagef", [Float, ImageType, 
VectorType], Attr.Pure>;
+}
+
 let MinVersion = CL12 in {
-  foreach aQual = ["RO", "RW"] in {
-foreach imgTy = [Image2d, Image1dArray] in {
-  def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
-}
-foreach imgTy = [Image3d, Image2dArray] in {
-  def : Builtin<"read_imagef", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imagei", [VectorType, ImageType, VectorType], Attr.Pure>;
-  def : Builtin<"read_imageui", [VectorType, ImageType, VectorType], Attr.Pure>;
-}
-foreach imgTy = [Image1d, 

[clang] 4b85800 - [OpenCL] Set external linkage for block enqueue kernels

2022-01-12 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-01-12T13:30:09Z
New Revision: 4b85800bfd6ca6c3ecedf68ffbba6c3f2bc9c8ae

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

LOG: [OpenCL] Set external linkage for block enqueue kernels

All kernels can be called from the host as per the SPIR_KERNEL calling
convention.  As such, all kernels should have external linkage, but
block enqueue kernels were created with internal linkage.

Reported-by: Pedro Olsen Ferreira

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

Added: 


Modified: 
clang/lib/CodeGen/TargetInfo.cpp
clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl

Removed: 




diff  --git a/clang/lib/CodeGen/TargetInfo.cpp 
b/clang/lib/CodeGen/TargetInfo.cpp
index 2bb68ebbfa2a4..77203aee9b6c1 100644
--- a/clang/lib/CodeGen/TargetInfo.cpp
+++ b/clang/lib/CodeGen/TargetInfo.cpp
@@ -11417,7 +11417,7 @@ 
TargetCodeGenInfo::createEnqueuedBlockKernel(CodeGenFunction ,
   auto  = CGF.getLLVMContext();
   std::string Name = Invoke->getName().str() + "_kernel";
   auto *FT = llvm::FunctionType::get(llvm::Type::getVoidTy(C), ArgTys, false);
-  auto *F = llvm::Function::Create(FT, llvm::GlobalValue::InternalLinkage, 
Name,
+  auto *F = llvm::Function::Create(FT, llvm::GlobalValue::ExternalLinkage, 
Name,
());
   auto IP = CGF.Builder.saveIP();
   auto *BB = llvm::BasicBlock::Create(C, "entry", F);

diff  --git a/clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl 
b/clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
index afae12f7d25aa..361aca85e84c9 100644
--- a/clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
+++ b/clang/test/CodeGenOpenCL/cl20-device-side-enqueue.cl
@@ -402,28 +402,28 @@ kernel void device_side_enqueue(global int *a, global int 
*b, int i) {
   size = get_kernel_sub_group_count_for_ndrange(ndrange, ^(){});
 }
 
-// COMMON: define internal spir_kernel void [[INVLK1]](i8 addrspace(4)* %0) 
#{{[0-9]+}} {
+// COMMON: define spir_kernel void [[INVLK1]](i8 addrspace(4)* %0) #{{[0-9]+}} 
{
 // COMMON: entry:
 // COMMON:  call spir_func void @__device_side_enqueue_block_invoke(i8 
addrspace(4)* %0)
 // COMMON:  ret void
 // COMMON: }
-// COMMON: define internal spir_kernel void [[INVLK2]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK1]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK2]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK3]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK4]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK5]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK6]](i8 addrspace(4)* %0, i8 
addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) #{{[0-9]+}} {
+// COMMON: define spir_kernel void [[INVLK2]](i8 addrspace(4)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK1]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK2]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK3]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK4]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK5]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK6]](i8 addrspace(4)* %0, i8 
addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3) #{{[0-9]+}} {
 // COMMON: entry:
 // COMMON:  call spir_func void @__device_side_enqueue_block_invoke_9(i8 
addrspace(4)* %0, i8 addrspace(3)* %1, i8 addrspace(3)* %2, i8 addrspace(3)* %3)
 // COMMON:  ret void
 // COMMON: }
-// COMMON: define internal spir_kernel void [[INVGK7]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
+// COMMON: define spir_kernel void [[INVGK7]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)*{{.*}})
 // COMMON: define internal spir_func void [[INVG8]](i8 addrspace(4)*{{.*}})
 // COMMON: define internal spir_func void [[INVG9]](i8 addrspace(4)*{{.*}}, i8 
addrspace(3)* %{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK8]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INV_G_K]](i8 
addrspace(4)*{{.*}}, i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVLK3]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK9]](i8 addrspace(4)*{{.*}}, 
i8 addrspace(3)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK10]](i8 addrspace(4)*{{.*}})
-// COMMON: define internal spir_kernel void [[INVGK11]](i8 addrspace(4)*{{.*}})
+// COMMON: 

[clang] 4b14fc6 - [SPIR-V] Drop double quote from test pattern

2022-01-11 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2022-01-11T16:58:08Z
New Revision: 4b14fc6fe5a7d01fb42a3cdede77c59f03b867af

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

LOG: [SPIR-V] Drop double quote from test pattern

When spirv-link is found, it won't match a leading `"`.  This fixes
the test added by commit dbb8d086377b ("[SPIR-V] Add linking using
spirv-link.", 2022-01-11).

Added: 


Modified: 
clang/test/Driver/spirv-toolchain.cl

Removed: 




diff  --git a/clang/test/Driver/spirv-toolchain.cl 
b/clang/test/Driver/spirv-toolchain.cl
index c2fcb3577259..5c95a5748842 100644
--- a/clang/test/Driver/spirv-toolchain.cl
+++ b/clang/test/Driver/spirv-toolchain.cl
@@ -68,4 +68,4 @@
 // SPLINK: clang{{.*}} "-cc1" "-triple" "spirv64"
 // SPLINK-SAME: "-o" [[BC:".*bc"]]
 // SPLINK: {{llvm-spirv.*"}} [[BC]] "-o" [[SPV2:".*o"]]
-// SPLINK: {{"spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"
+// SPLINK: {{spirv-link.*"}} [[SPV1]] [[SPV2]] "-o" "a.out"



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


[clang] f45d740 - [docs] Fix hyperlink

2021-10-20 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-10-20T10:20:17+01:00
New Revision: f45d7407168d08c4d80216ca13feb1e1c21ad6bb

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

LOG: [docs] Fix hyperlink

Added: 


Modified: 
clang/docs/UsersManual.rst

Removed: 




diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 30da581c6770..68c112c964f2 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -2863,7 +2863,7 @@ clang fully implements all of standard C++98 except for 
exported
 templates (which were removed in C++11), all of standard C++11,
 C++14, and C++17, and most of C++20.
 
-See the `C++ support in Clang ` page
+See the `C++ support in Clang `_ page
 for detailed information on C++ feature support across Clang versions.
 
 Controlling implementation limits



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


[clang] 544d89e - [OpenCL] Add atomic_half type builtins

2021-10-12 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-10-12T10:45:30+01:00
New Revision: 544d89e847d42ce8856296752b0fb279aa89aace

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

LOG: [OpenCL] Add atomic_half type builtins

Add atomic_half types and builtins operating on the types from the
cl_ext_float_atomics extension.

Patch by Haonan Yang.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c.h
clang/lib/Sema/OpenCLBuiltins.td
clang/lib/Sema/Sema.cpp
clang/test/SemaOpenCL/atomic-ops.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 705a3231b577..562e0551ffdc 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -13640,6 +13640,118 @@ uintptr_t __ovld atomic_fetch_sub_explicit(volatile 
__local atomic_uintptr_t *ob
 // The functionality added by cl_ext_float_atomics extension
 #if defined(cl_ext_float_atomics)
 
+#if defined(__opencl_c_ext_fp16_global_atomic_load_store)
+void __ovld atomic_store(volatile __global atomic_half *object, half operand);
+void __ovld atomic_store_explicit(volatile __global atomic_half *object,
+  half operand, memory_order order);
+void __ovld atomic_store_explicit(volatile __global atomic_half *object,
+  half operand, memory_order order,
+  memory_scope scope);
+half __ovld atomic_load(volatile __global atomic_half *object);
+half __ovld atomic_load_explicit(volatile __global atomic_half *object,
+ memory_order order);
+half __ovld atomic_load_explicit(volatile __global atomic_half *object,
+ memory_order order, memory_scope scope);
+half __ovld atomic_exchange(volatile __global atomic_half *object,
+half operand);
+half __ovld atomic_exchange_explicit(volatile __global atomic_half *object,
+ half operand, memory_order order);
+half __ovld atomic_exchange_explicit(volatile __global atomic_half *object,
+ half operand, memory_order order,
+ memory_scope scope);
+#endif // defined(__opencl_c_ext_fp16_global_atomic_load_store)
+
+#if defined(__opencl_c_ext_fp16_local_atomic_load_store)
+void __ovld atomic_store(volatile __local atomic_half *object, half operand);
+void __ovld atomic_store_explicit(volatile __local atomic_half *object,
+  half operand, memory_order order);
+void __ovld atomic_store_explicit(volatile __local atomic_half *object,
+  half operand, memory_order order,
+  memory_scope scope);
+half __ovld atomic_load(volatile __local atomic_half *object);
+half __ovld atomic_load_explicit(volatile __local atomic_half *object,
+ memory_order order);
+half __ovld atomic_load_explicit(volatile __local atomic_half *object,
+ memory_order order, memory_scope scope);
+half __ovld atomic_exchange(volatile __local atomic_half *object, half 
operand);
+half __ovld atomic_exchange_explicit(volatile __local atomic_half *object,
+ half operand, memory_order order);
+half __ovld atomic_exchange_explicit(volatile __local atomic_half *object,
+ half operand, memory_order order,
+ memory_scope scope);
+#endif // defined(__opencl_c_ext_fp16_local_atomic_load_store)
+
+#if defined(__opencl_c_ext_fp16_global_atomic_load_store) &&   
\
+defined(__opencl_c_ext_fp16_local_atomic_load_store)
+void __ovld atomic_store(volatile atomic_half *object, half operand);
+void __ovld atomic_store_explicit(volatile atomic_half *object, half operand,
+  memory_order order);
+void __ovld atomic_store_explicit(volatile atomic_half *object, half operand,
+  memory_order order, memory_scope scope);
+half __ovld atomic_load(volatile atomic_half *object);
+half __ovld atomic_load_explicit(volatile atomic_half *object,
+ memory_order order);
+half __ovld atomic_load_explicit(volatile atomic_half *object,
+ memory_order order, memory_scope scope);
+half __ovld atomic_exchange(volatile atomic_half *object, half operand);
+half __ovld atomic_exchange_explicit(volatile atomic_half *object, half 
operand,
+ memory_order order);
+half __ovld atomic_exchange_explicit(volatile atomic_half *object, half 
operand,
+   

[clang] 4da744a - [OpenCL] Fix as_type3 invalid store creation

2021-09-29 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-09-29T09:40:06+01:00
New Revision: 4da744a20ff58c9b3d8df0e2eb9e8b69d9e5cc3d

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

LOG: [OpenCL] Fix as_type3 invalid store creation

With -fpreserve-vec3-type enabled, a cast was not created when
converting from a non-vec3 type to a vec3 type, even though a
conversion to vec3 was performed.  This resulted in creation of
invalid store instructions.

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

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGenOpenCL/preserve_vec3.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 67c581b46eae7..6bef004987828 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4804,12 +4804,10 @@ Value *ScalarExprEmitter::VisitAsTypeExpr(AsTypeExpr 
*E) {
   // to vec4 if the original type is not vec4, then a shuffle vector to
   // get a vec3.
   if (NumElementsSrc != 3 && NumElementsDst == 3) {
-if (!CGF.CGM.getCodeGenOpts().PreserveVec3Type) {
-  auto *Vec4Ty = llvm::FixedVectorType::get(
-  cast(DstTy)->getElementType(), 4);
-  Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src,
- Vec4Ty);
-}
+auto *Vec4Ty = llvm::FixedVectorType::get(
+cast(DstTy)->getElementType(), 4);
+Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src,
+   Vec4Ty);
 
 Src = ConvertVec3AndVec4(Builder, CGF, Src, 3);
 Src->setName("astype");

diff  --git a/clang/test/CodeGenOpenCL/preserve_vec3.cl 
b/clang/test/CodeGenOpenCL/preserve_vec3.cl
index 2237cf1e27e46..3dc703d320eca 100644
--- a/clang/test/CodeGenOpenCL/preserve_vec3.cl
+++ b/clang/test/CodeGenOpenCL/preserve_vec3.cl
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown 
-fpreserve-vec3-type | FileCheck %s
 
 typedef char char3 __attribute__((ext_vector_type(3)));
+typedef char char8 __attribute__((ext_vector_type(8)));
 typedef short short3 __attribute__((ext_vector_type(3)));
 typedef double double2 __attribute__((ext_vector_type(2)));
 typedef float float3 __attribute__((ext_vector_type(3)));
@@ -38,6 +39,15 @@ void kernel float3_to_double2(global float3 *a, global 
double2 *b) {
   *b = __builtin_astype(*a, double2);
 }
 
+void kernel char8_to_short3(global short3 *a, global char8 *b) {
+  // CHECK-LABEL: spir_kernel void @char8_to_short3
+  // CHECK: %[[IN_BC:.*]] = bitcast <8 x i8> addrspace(1)* %b to <4 x i16> 
addrspace(1)*
+  // CHECK: %[[LOAD_B:.*]] = load <4 x i16>, <4 x i16> addrspace(1)* %[[IN_BC]]
+  // CHECK: %[[ASTYPE:.*]] = shufflevector <4 x i16> %[[LOAD_B]], <4 x i16> 
poison, <3 x i32> 
+  // CHECK: store <3 x i16> %[[ASTYPE]], <3 x i16> addrspace(1)* %a, align 8
+  *a = __builtin_astype(*b, short3);
+}
+
 void from_char3(char3 a, global int *out) {
   // CHECK-LABEL: void @from_char3
   // CHECK: %[[ASTYPE:.*]] = shufflevector <3 x i8> %a, <3 x i8> poison, <4 x 
i32> 
@@ -53,3 +63,19 @@ void from_short3(short3 a, global long *out) {
   // CHECK: store <4 x i16> %[[ASTYPE]], <4 x i16> addrspace(1)* %[[OUT_BC]]
   *out = __builtin_astype(a, long);
 }
+
+void scalar_to_char3(int a, global char3 *out) {
+  // CHECK-LABEL: void @scalar_to_char3
+  // CHECK: %[[IN_BC:.*]] = bitcast i32 %a to <4 x i8>
+  // CHECK: %[[ASTYPE:.*]] = shufflevector <4 x i8> %[[IN_BC]], <4 x i8> 
poison, <3 x i32> 
+  // CHECK: store <3 x i8> %[[ASTYPE]], <3 x i8> addrspace(1)* %out
+  *out = __builtin_astype(a, char3);
+}
+
+void scalar_to_short3(long a, global short3 *out) {
+  // CHECK-LABEL: void @scalar_to_short3
+  // CHECK: %[[IN_BC:.*]] = bitcast i64 %a to <4 x i16>
+  // CHECK: %[[ASTYPE:.*]] = shufflevector <4 x i16> %[[IN_BC]], <4 x i16> 
poison, <3 x i32> 
+  // CHECK: store <3 x i16> %[[ASTYPE]], <3 x i16> addrspace(1)* %out
+  *out = __builtin_astype(a, short3);
+}



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


[clang] d353d1c - [OpenCL] Support cl_ext_float_atomics

2021-09-13 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-09-13T12:12:40+01:00
New Revision: d353d1c50112a1cb315eccdab18ce7bd1563cd06

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

LOG: [OpenCL] Support cl_ext_float_atomics

See https://github.com/KhronosGroup/OpenCL-Docs/pull/552 for initial
specification.

Patch by Haonan Yang.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/Headers/opencl-c-header.cl
clang/test/SemaOpenCL/fdeclare-opencl-builtins.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index f3605c659d952..7cc356015d959 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -25,6 +25,25 @@
 #define cl_khr_integer_dot_product 1
 #define __opencl_c_integer_dot_product_input_4x8bit 1
 #define __opencl_c_integer_dot_product_input_4x8bit_packed 1
+#define cl_ext_float_atomics 1
+#ifdef cl_khr_fp16
+#define __opencl_c_ext_fp16_global_atomic_load_store 1
+#define __opencl_c_ext_fp16_local_atomic_load_store 1
+#define __opencl_c_ext_fp16_global_atomic_add 1
+#define __opencl_c_ext_fp16_local_atomic_add 1
+#define __opencl_c_ext_fp16_global_atomic_min_max 1
+#define __opencl_c_ext_fp16_local_atomic_min_max 1
+#endif
+#ifdef cl_khr_fp64
+#define __opencl_c_ext_fp64_global_atomic_add 1
+#define __opencl_c_ext_fp64_local_atomic_add 1
+#define __opencl_c_ext_fp64_global_atomic_min_max 1
+#define __opencl_c_ext_fp64_local_atomic_min_max 1
+#endif
+#define __opencl_c_ext_fp32_global_atomic_add 1
+#define __opencl_c_ext_fp32_local_atomic_add 1
+#define __opencl_c_ext_fp32_global_atomic_min_max 1
+#define __opencl_c_ext_fp32_local_atomic_min_max 1
 
 #endif // defined(__SPIR__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index bb3ca6aae20a2..e960228594801 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -13637,6 +13637,215 @@ uintptr_t __ovld atomic_fetch_sub_explicit(volatile 
__local atomic_uintptr_t *ob
 #endif //defined(cl_khr_int64_base_atomics) && 
defined(cl_khr_int64_extended_atomics)
 #endif //__OPENCL_C_VERSION__ >= CL_VERSION_3_0
 
+// The functionality added by cl_ext_float_atomics extension
+#if defined(cl_ext_float_atomics)
+
+#if defined(__opencl_c_ext_fp32_global_atomic_min_max)
+float __ovld atomic_fetch_min(volatile __global atomic_float *object,
+  float operand);
+float __ovld atomic_fetch_max(volatile __global atomic_float *object,
+  float operand);
+float __ovld atomic_fetch_min_explicit(volatile __global atomic_float *object,
+   float operand, memory_order order);
+float __ovld atomic_fetch_max_explicit(volatile __global atomic_float *object,
+   float operand, memory_order order);
+float __ovld atomic_fetch_min_explicit(volatile __global atomic_float *object,
+   float operand, memory_order order,
+   memory_scope scope);
+float __ovld atomic_fetch_max_explicit(volatile __global atomic_float *object,
+   float operand, memory_order order,
+   memory_scope scope);
+#endif // defined(__opencl_c_ext_fp32_global_atomic_min_max)
+
+#if defined(__opencl_c_ext_fp32_local_atomic_min_max)
+float __ovld atomic_fetch_min(volatile __local atomic_float *object,
+  float operand);
+float __ovld atomic_fetch_max(volatile __local atomic_float *object,
+  float operand);
+float __ovld atomic_fetch_min_explicit(volatile __local atomic_float *object,
+   float operand, memory_order order);
+float __ovld atomic_fetch_max_explicit(volatile __local atomic_float *object,
+   float operand, memory_order order);
+float __ovld atomic_fetch_min_explicit(volatile __local atomic_float *object,
+   float operand, memory_order order,
+   memory_scope scope);
+float __ovld atomic_fetch_max_explicit(volatile __local atomic_float *object,
+   float operand, memory_order order,
+   memory_scope scope);
+#endif // defined(__opencl_c_ext_fp32_local_atomic_min_max)
+
+#if defined(__opencl_c_ext_fp32_global_atomic_min_max) &&  
\
+defined(__opencl_c_ext_fp32_local_atomic_min_max)

[clang] 7bda1a0 - [OpenCL] Fix as_type(vec3) invalid store creation

2021-08-19 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-08-19T11:57:09+01:00
New Revision: 7bda1a0711c67fde5f9bac5e1c9bd68163659d0e

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

LOG: [OpenCL] Fix as_type(vec3) invalid store creation

With -fpreserve-vec3-type enabled, a cast was not created when
converting from a vec3 type to a non-vec3 type, even though a
conversion to vec4 was performed.  This resulted in creation of
invalid store instructions.

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

Added: 


Modified: 
clang/lib/CodeGen/CGExprScalar.cpp
clang/test/CodeGenOpenCL/preserve_vec3.cl

Removed: 




diff  --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index e47701915f2f..5485b3d363fb 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4785,11 +4785,8 @@ Value *ScalarExprEmitter::VisitAsTypeExpr(AsTypeExpr *E) 
{
   // vector to get a vec4, then a bitcast if the target type is 
diff erent.
   if (NumElementsSrc == 3 && NumElementsDst != 3) {
 Src = ConvertVec3AndVec4(Builder, CGF, Src, 4);
-
-if (!CGF.CGM.getCodeGenOpts().PreserveVec3Type) {
-  Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src,
- DstTy);
-}
+Src = createCastsForTypeOfSameSize(Builder, CGF.CGM.getDataLayout(), Src,
+   DstTy);
 
 Src->setName("astype");
 return Src;

diff  --git a/clang/test/CodeGenOpenCL/preserve_vec3.cl 
b/clang/test/CodeGenOpenCL/preserve_vec3.cl
index 9260af6167e9..2237cf1e27e4 100644
--- a/clang/test/CodeGenOpenCL/preserve_vec3.cl
+++ b/clang/test/CodeGenOpenCL/preserve_vec3.cl
@@ -1,5 +1,8 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown 
-fpreserve-vec3-type | FileCheck %s
 
+typedef char char3 __attribute__((ext_vector_type(3)));
+typedef short short3 __attribute__((ext_vector_type(3)));
+typedef double double2 __attribute__((ext_vector_type(2)));
 typedef float float3 __attribute__((ext_vector_type(3)));
 typedef float float4 __attribute__((ext_vector_type(4)));
 
@@ -25,3 +28,28 @@ void kernel float3_to_float4(global float3 *a, global float4 
*b) {
   // CHECK: store <4 x float> %[[ASTYPE]], <4 x float> addrspace(1)* %b, align 
16
   *b = __builtin_astype(*a, float4);
 }
+
+void kernel float3_to_double2(global float3 *a, global double2 *b) {
+  // CHECK-LABEL: spir_kernel void @float3_to_double2
+  // CHECK: %[[LOAD_A:.*]] = load <3 x float>, <3 x float> addrspace(1)* %a, 
align 16
+  // CHECK: %[[ASTYPE:.*]] = shufflevector <3 x float> %[[LOAD_A]], <3 x 
float> poison, <4 x i32> 
+  // CHECK: %[[OUT_BC:.*]] = bitcast <2 x double> addrspace(1)* %b to <4 x 
float> addrspace(1)*
+  // CHECK: store <4 x float> %[[ASTYPE]], <4 x float> addrspace(1)* 
%[[OUT_BC]], align 16
+  *b = __builtin_astype(*a, double2);
+}
+
+void from_char3(char3 a, global int *out) {
+  // CHECK-LABEL: void @from_char3
+  // CHECK: %[[ASTYPE:.*]] = shufflevector <3 x i8> %a, <3 x i8> poison, <4 x 
i32> 
+  // CHECK: %[[OUT_BC:.*]] = bitcast i32 addrspace(1)* %out to <4 x i8> 
addrspace(1)*
+  // CHECK: store <4 x i8> %[[ASTYPE]], <4 x i8> addrspace(1)* %[[OUT_BC]]
+  *out = __builtin_astype(a, int);
+}
+
+void from_short3(short3 a, global long *out) {
+  // CHECK-LABEL: void @from_short3
+  // CHECK: %[[ASTYPE:.*]] = shufflevector <3 x i16> %a, <3 x i16> poison, <4 
x i32> 
+  // CHECK: %[[OUT_BC:.*]] = bitcast i64 addrspace(1)* %out to <4 x i16> 
addrspace(1)*
+  // CHECK: store <4 x i16> %[[ASTYPE]], <4 x i16> addrspace(1)* %[[OUT_BC]]
+  *out = __builtin_astype(a, long);
+}



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


[clang] 696ad3c - [OpenCL] Tidy up preserve_vec3 test

2021-08-12 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-08-12T14:51:20+01:00
New Revision: 696ad3c491a249f585ba79e0ecf80c5dc003f8f3

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

LOG: [OpenCL] Tidy up preserve_vec3 test

Add CHECK-LABELs and fix string substitution to actually match the
previous definition.

Added: 


Modified: 
clang/test/CodeGenOpenCL/preserve_vec3.cl

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/preserve_vec3.cl 
b/clang/test/CodeGenOpenCL/preserve_vec3.cl
index aefb248e51f49..9260af6167e99 100644
--- a/clang/test/CodeGenOpenCL/preserve_vec3.cl
+++ b/clang/test/CodeGenOpenCL/preserve_vec3.cl
@@ -1,24 +1,27 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown 
-fpreserve-vec3-type  | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple spir-unknown-unknown 
-fpreserve-vec3-type | FileCheck %s
 
 typedef float float3 __attribute__((ext_vector_type(3)));
 typedef float float4 __attribute__((ext_vector_type(4)));
 
 void kernel foo(global float3 *a, global float3 *b) {
+  // CHECK-LABEL: spir_kernel void @foo
   // CHECK: %[[LOAD_A:.*]] = load <3 x float>, <3 x float> addrspace(1)* %a
   // CHECK: store <3 x float> %[[LOAD_A]], <3 x float> addrspace(1)* %b
   *b = *a;
 }
 
 void kernel float4_to_float3(global float3 *a, global float4 *b) {
+  // CHECK-LABEL: spir_kernel void @float4_to_float3
   // CHECK: %[[LOAD_A:.*]] = load <4 x float>, <4 x float> addrspace(1)* %b, 
align 16
   // CHECK: %[[ASTYPE:.*]] = shufflevector <4 x float> %[[LOAD_A]], <4 x 
float> poison, <3 x i32> 
-  // CHECK: store <3 x float> %[[ASTYPE:.*]], <3 x float> addrspace(1)* %a, 
align 16
+  // CHECK: store <3 x float> %[[ASTYPE]], <3 x float> addrspace(1)* %a, align 
16
   *a = __builtin_astype(*b, float3);
 }
 
 void kernel float3_to_float4(global float3 *a, global float4 *b) {
+  // CHECK-LABEL: spir_kernel void @float3_to_float4
   // CHECK: %[[LOAD_A:.*]] = load <3 x float>, <3 x float> addrspace(1)* %a, 
align 16
   // CHECK: %[[ASTYPE:.*]] = shufflevector <3 x float> %[[LOAD_A]], <3 x 
float> poison, <4 x i32> 
-  // CHECK: store <4 x float> %[[ASTYPE:.*]], <4 x float> addrspace(1)* %b, 
align 16
+  // CHECK: store <4 x float> %[[ASTYPE]], <4 x float> addrspace(1)* %b, align 
16
   *b = __builtin_astype(*a, float4);
 }



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


[clang] 5de6b1a - [OpenCL] Make pipes and workgroup optional for -fdeclare-opencl-builtins

2021-08-10 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-08-10T13:01:47+01:00
New Revision: 5de6b1acb5900be80515cf9fa253f8698fc57dca

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

LOG: [OpenCL] Make pipes and workgroup optional for -fdeclare-opencl-builtins

Align guards of these builtins with opencl-c.h.

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index f2ab4169efec8..8de7632deb503 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -83,6 +83,9 @@ def FuncExtKhrMipmapImage: 
FunctionExtension<"cl_khr_mipmap_imag
 def FuncExtKhrMipmapImageWrites  : 
FunctionExtension<"cl_khr_mipmap_image_writes">;
 def FuncExtKhrGlMsaaSharing  : 
FunctionExtension<"cl_khr_gl_msaa_sharing">;
 
+def FuncExtOpenCLCPipes  : 
FunctionExtension<"__opencl_c_pipes">;
+def FuncExtOpenCLCWGCollectiveFunctions  : 
FunctionExtension<"__opencl_c_work_group_collective_functions">;
+
 // Not a real extension, but a workaround to add C++ for OpenCL specific 
builtins.
 def FuncExtOpenCLCxx : FunctionExtension<"__cplusplus">;
 
@@ -1292,7 +1295,7 @@ foreach aQual = ["WO", "RW"] in {
 //
 // OpenCL v2.0 s6.13.15 - Work-group Functions
 // --- Table 26 ---
-let MinVersion = CL20 in {
+let Extension = FuncExtOpenCLCWGCollectiveFunctions in {
   foreach name = ["work_group_all", "work_group_any"] in {
 def : Builtin;
   }
@@ -1317,7 +1320,9 @@ let MinVersion = CL20 in {
 
 // --- Table 28 ---
 // Builtins taking pipe arguments are defined in Builtins.def
-def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>;
+let Extension = FuncExtOpenCLCPipes in {
+  def : Builtin<"is_valid_reserve_id", [Bool, ReserveId]>;
+}
 
 // --- Table 29 ---
 // Defined in Builtins.def



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


[clang] 19bd806 - [OpenCL] Add missing virtual destructor

2021-08-09 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-08-09T13:49:52+01:00
New Revision: 19bd806a1a443e4ce45ccc670861848fb1579022

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

LOG: [OpenCL] Add missing virtual destructor

Followup after f9ffe61fb53f ("[OpenCL] Factor out
OpenCLBuiltinFileEmitterBase; NFC", 2021-08-09) introduced a
-Wnon-virtual-dtor warning.

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 457313f1839f..6cc4bf5fd856 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -238,6 +238,7 @@ class OpenCLBuiltinFileEmitterBase {
 public:
   OpenCLBuiltinFileEmitterBase(RecordKeeper , raw_ostream )
   : Records(Records), OS(OS) {}
+  virtual ~OpenCLBuiltinFileEmitterBase() = default;
 
   // Entrypoint to generate the functions for testing all OpenCL builtin
   // functions.



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


[clang] f9ffe61 - [OpenCL] Factor out OpenCLBuiltinFileEmitterBase; NFC

2021-08-09 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-08-09T11:41:25+01:00
New Revision: f9ffe61fb53f595b7be136c340508c094482fcff

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

LOG: [OpenCL] Factor out OpenCLBuiltinFileEmitterBase; NFC

Factor out functionality that can be shared with a header file emitter
that is to be added in the future.

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index a4cb5b7cacd98..457313f1839fd 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -233,19 +233,17 @@ class BuiltinNameEmitter {
   MapVector SignatureListMap;
 };
 
-// OpenCL builtin test generator.  This class processes the same TableGen input
-// as BuiltinNameEmitter, but generates a .cl file that contains a call to each
-// builtin function described in the .td input.
-class OpenCLBuiltinTestEmitter {
+/// Base class for emitting a file (e.g. header or test) from OpenCLBuiltins.td
+class OpenCLBuiltinFileEmitterBase {
 public:
-  OpenCLBuiltinTestEmitter(RecordKeeper , raw_ostream )
+  OpenCLBuiltinFileEmitterBase(RecordKeeper , raw_ostream )
   : Records(Records), OS(OS) {}
 
   // Entrypoint to generate the functions for testing all OpenCL builtin
   // functions.
-  void emit();
+  virtual void emit() = 0;
 
-private:
+protected:
   struct TypeFlags {
 TypeFlags() : IsConst(false), IsVolatile(false), IsPointer(false) {}
 bool IsConst : 1;
@@ -282,6 +280,18 @@ class OpenCLBuiltinTestEmitter {
   expandTypesInSignature(const std::vector ,
  SmallVectorImpl> );
 
+  // Emit extension enabling pragmas.
+  void emitExtensionSetup();
+
+  // Emit an #if guard for a Builtin's extension.  Return the corresponding
+  // closing #endif, or an empty string if no extension #if guard was emitted.
+  std::string emitExtensionGuard(const Record *Builtin);
+
+  // Emit an #if guard for a Builtin's language version.  Return the
+  // corresponding closing #endif, or an empty string if no version #if guard
+  // was emitted.
+  std::string emitVersionGuard(const Record *Builtin);
+
   // Contains OpenCL builtin functions and related information, stored as
   // Record instances. They are coming from the associated TableGen file.
   RecordKeeper 
@@ -290,6 +300,19 @@ class OpenCLBuiltinTestEmitter {
   raw_ostream 
 };
 
+// OpenCL builtin test generator.  This class processes the same TableGen input
+// as BuiltinNameEmitter, but generates a .cl file that contains a call to each
+// builtin function described in the .td input.
+class OpenCLBuiltinTestEmitter : public OpenCLBuiltinFileEmitterBase {
+public:
+  OpenCLBuiltinTestEmitter(RecordKeeper , raw_ostream )
+  : OpenCLBuiltinFileEmitterBase(Records, OS) {}
+
+  // Entrypoint to generate the functions for testing all OpenCL builtin
+  // functions.
+  void emit() override;
+};
+
 } // namespace
 
 void BuiltinNameEmitter::Emit() {
@@ -923,9 +946,9 @@ static void OCL2Qual(Sema , const OpenCLTypeStruct ,
   OS << "\n} // OCL2Qual\n";
 }
 
-std::string OpenCLBuiltinTestEmitter::getTypeString(const Record *Type,
-TypeFlags Flags,
-int VectorSize) const {
+std::string OpenCLBuiltinFileEmitterBase::getTypeString(const Record *Type,
+TypeFlags Flags,
+int VectorSize) const {
   std::string S;
   if (Type->getValueAsBit("IsConst") || Flags.IsConst) {
 S += "const ";
@@ -970,7 +993,7 @@ std::string OpenCLBuiltinTestEmitter::getTypeString(const 
Record *Type,
   return S;
 }
 
-void OpenCLBuiltinTestEmitter::getTypeLists(
+void OpenCLBuiltinFileEmitterBase::getTypeLists(
 Record *Type, TypeFlags , std::vector ,
 std::vector ) const {
   bool isGenType = Type->isSubClassOf("GenericType");
@@ -1003,7 +1026,7 @@ void OpenCLBuiltinTestEmitter::getTypeLists(
   VectorList.push_back(Type->getValueAsInt("VecWidth"));
 }
 
-void OpenCLBuiltinTestEmitter::expandTypesInSignature(
+void OpenCLBuiltinFileEmitterBase::expandTypesInSignature(
 const std::vector ,
 SmallVectorImpl> ) {
   // Find out if there are any GenTypes in this signature, and if so, calculate
@@ -1044,10 +1067,7 @@ void OpenCLBuiltinTestEmitter::expandTypesInSignature(
   }
 }
 
-void OpenCLBuiltinTestEmitter::emit() {
-  emitSourceFileHeader("OpenCL Builtin exhaustive testing", OS);
-
-  // Enable some extensions for testing.
+void OpenCLBuiltinFileEmitterBase::emitExtensionSetup() {
   OS << R"(
 #pragma 

[clang] 22fdf61 - [OpenCL][Docs] Adding builtins requires adding to both now

2021-08-06 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-08-06T10:21:26+01:00
New Revision: 22fdf617b6103df30ffae6cf469b78036e4ba615

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

LOG: [OpenCL][Docs] Adding builtins requires adding to both now

As we are trying to reach parity between opencl-c.h and
-fdeclare-opencl-builtins, ensure the documentation mentions that new
builtins should be added to both.

Reviewed by: Anastasia Stulova

Added: 


Modified: 
clang/docs/OpenCLSupport.rst

Removed: 




diff  --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 047c73f2834a5..2067596954916 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -252,7 +252,7 @@ with :ref:`-cl-ext ` command-line flags.
 **Library functionality**
 
 If an extension adds functionality that does not modify standard language
-parsing it should not require modifying anything other than header files or
+parsing it should not require modifying anything other than header files and
 ``OpenCLBuiltins.td`` detailed in :ref:`OpenCL builtins `.
 Most commonly such extensions add functionality via libraries (by adding
 non-native types or functions) parsed regularly. Similar to other languages 
this



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


[clang] 92b00ff - [OpenCL] Reduce duplicate defs by using multiclasses; NFC

2021-08-05 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-08-05T11:06:33+01:00
New Revision: 92b00ffe0fb3199515c9267a1fad96d3bf44d1ea

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

LOG: [OpenCL] Reduce duplicate defs by using multiclasses; NFC

Builtin definitions with pointer arguments were duplicated to provide
overloads differing in the pointer argument's address space.

Reduce this duplication by capturing the definitions in multiclasses.
This still results in the same number of builtins in the generated
tables, but the description is more concise now.

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

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index cd704fe395a96..f2ab4169efec8 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -543,9 +543,10 @@ foreach name = ["fma", "mad"] in {
   def : Builtin;
 }
 
-// --- Version dependent ---
-let MaxVersion = CL20 in {
-  foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
+// The following math builtins take pointer arguments.  Which overloads are
+// available depends on whether the generic address space feature is enabled.
+multiclass MathWithPointer addrspaces> {
+  foreach AS = addrspaces in {
 foreach name = ["fract", "modf", "sincos"] in {
   def : Builtin]>;
 }
@@ -561,19 +562,12 @@ let MaxVersion = CL20 in {
 }
   }
 }
+
+let MaxVersion = CL20 in {
+  defm : MathWithPointer<[GlobalAS, LocalAS, PrivateAS]>;
+}
 let MinVersion = CL20 in {
-  foreach name = ["fract", "modf", "sincos"] in {
-def : Builtin]>;
-  }
-  foreach name = ["frexp", "lgamma_r"] in {
-foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, 
GenTypeHalfVecAndScalar] in {
-  def : Builtin]>;
-}  }
-  foreach name = ["remquo"] in {
-foreach Type = [GenTypeFloatVecAndScalar, GenTypeDoubleVecAndScalar, 
GenTypeHalfVecAndScalar] in {
-  def : Builtin]>;
-}
-  }
+  defm : MathWithPointer<[GenericAS]>;
 }
 
 // --- Table 9 ---
@@ -783,10 +777,8 @@ foreach name = ["select"] in {
 // OpenCL v1.1 s6.11.7, v1.2 s6.12.7, v2.0 s6.13.7 - Vector Data Load and 
Store Functions
 // OpenCL Extension v1.1 s9.3.6 and s9.6.6, v1.2 s9.5.6, v2.0 s5.1.6 and 
s6.1.6 - Vector Data Load and Store Functions
 // --- Table 15 ---
-// Variants for OpenCL versions below 2.0, using pointers to the global, local
-// and private address spaces.
-let MaxVersion = CL20 in {
-  foreach AS = [GlobalAS, LocalAS, PrivateAS] in {
+multiclass VloadVstore addrspaces, bit defStores> {
+  foreach AS = addrspaces in {
 foreach VSize = [2, 3, 4, 8, 16] in {
   foreach name = ["vload" # VSize] in {
 def : Builtin, Size, 
PointerType, AS>]>;
@@ -801,116 +793,45 @@ let MaxVersion = CL20 in {
 def : Builtin, Size, 
PointerType, AS>]>;
 def : Builtin, Size, 
PointerType, AS>]>;
   }
-  foreach name = ["vstore" # VSize] in {
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-def : Builtin, Size, 
PointerType]>;
-  }
   foreach name = ["vloada_half" # VSize] in {
 def : Builtin, Size, 
PointerType, AS>]>;
   }
-  foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
-foreach name = ["vstorea_half" # VSize # rnd] in {
-  def : Builtin, Size, 
PointerType]>;
-  def : Builtin, Size, 
PointerType]>;
+  if defStores then {
+foreach name = ["vstore" # VSize] in {
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+  def : Builtin, Size, 
PointerType]>;
+}
+foreach rnd = ["", "_rte", "_rtz", "_rtp", "_rtn"] in {
+  foreach name = ["vstorea_half" # VSize # rnd] in {
+def : Builtin, Size, 
PointerType]>;
+def : Builtin, Size, 
PointerType]>;
+  }
 }
   }
 }
   }
 }
-// Variants for OpenCL versions above 2.0, using 

[clang] 989bede - [OpenCL] Add cl_khr_integer_dot_product

2021-07-23 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-07-23T10:10:16+01:00
New Revision: 989bedec7a6ae95a0db865f23677047f78dc9257

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

LOG: [OpenCL] Add cl_khr_integer_dot_product

Add the builtins defined by Section 42 "Integer dot product" in
the OpenCL Extension Specification.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index ebc4b7a47925..1dc52ec75e03 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -22,6 +22,10 @@
 #define cl_khr_subgroup_shuffle_relative 1
 #define cl_khr_subgroup_clustered_reduce 1
 #define cl_khr_extended_bit_ops 1
+#define cl_khr_integer_dot_product 1
+#define __opencl_c_integer_dot_product_input_4x8bit 1
+#define __opencl_c_integer_dot_product_input_4x8bit_packed 1
+
 #endif // defined(__SPIR__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 5b3cd05d4426..4be57058b33f 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -16251,6 +16251,30 @@ long16 __ovld __cnfn bit_reverse(long16);
 ulong16 __ovld __cnfn bit_reverse(ulong16);
 #endif // cl_khr_extended_bit_ops
 
+#if defined(__opencl_c_integer_dot_product_input_4x8bit)
+uint __ovld __cnfn dot(uchar4, uchar4);
+int __ovld __cnfn dot(char4, char4);
+int __ovld __cnfn dot(uchar4, char4);
+int __ovld __cnfn dot(char4, uchar4);
+
+uint __ovld __cnfn dot_acc_sat(uchar4, uchar4, uint);
+int __ovld __cnfn dot_acc_sat(char4, char4, int);
+int __ovld __cnfn dot_acc_sat(uchar4, char4, int);
+int __ovld __cnfn dot_acc_sat(char4, uchar4, int);
+#endif // __opencl_c_integer_dot_product_input_4x8bit
+
+#if defined(__opencl_c_integer_dot_product_input_4x8bit_packed)
+uint __ovld __cnfn dot_4x8packed_uu_uint(uint, uint);
+int __ovld __cnfn dot_4x8packed_ss_int(uint, uint);
+int __ovld __cnfn dot_4x8packed_us_int(uint, uint);
+int __ovld __cnfn dot_4x8packed_su_int(uint, uint);
+
+uint __ovld __cnfn dot_acc_sat_4x8packed_uu_uint(uint, uint, uint);
+int __ovld __cnfn dot_acc_sat_4x8packed_ss_int(uint, uint, int);
+int __ovld __cnfn dot_acc_sat_4x8packed_us_int(uint, uint, int);
+int __ovld __cnfn dot_acc_sat_4x8packed_su_int(uint, uint, int);
+#endif // __opencl_c_integer_dot_product_input_4x8bit_packed
+
 #if defined(cl_intel_subgroups)
 // Intel-Specific Sub Group Functions
 float   __ovld __conv intel_sub_group_shuffle( float  x, uint c );

diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index 63def2bce8c2..cd704fe395a9 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1749,6 +1749,31 @@ let Extension = FuncExtKhrExtendedBitOps in {
   def : Builtin<"bit_reverse", [AIGenTypeN, AIGenTypeN], Attr.Const>;
 }
 
+// Section 42.3 - cl_khr_integer_dot_product
+let Extension = 
FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit"> in {
+  def : Builtin<"dot", [UInt, VectorType, VectorType], 
Attr.Const>;
+  def : Builtin<"dot", [Int, VectorType, VectorType], 
Attr.Const>;
+  def : Builtin<"dot", [Int, VectorType, VectorType], 
Attr.Const>;
+  def : Builtin<"dot", [Int, VectorType, VectorType], 
Attr.Const>;
+
+  def : Builtin<"dot_acc_sat", [UInt, VectorType, VectorType, UInt], Attr.Const>;
+  def : Builtin<"dot_acc_sat", [Int, VectorType, VectorType, 
Int], Attr.Const>;
+  def : Builtin<"dot_acc_sat", [Int, VectorType, VectorType, Int], Attr.Const>;
+  def : Builtin<"dot_acc_sat", [Int, VectorType, VectorType, Int], Attr.Const>;
+}
+
+let Extension = 
FunctionExtension<"__opencl_c_integer_dot_product_input_4x8bit_packed"> in {
+  def : Builtin<"dot_4x8packed_uu_uint", [UInt, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_4x8packed_ss_int", [Int, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_4x8packed_us_int", [Int, UInt, UInt], Attr.Const>;
+  def : Builtin<"dot_4x8packed_su_int", [Int, UInt, UInt], Attr.Const>;
+
+  def : Builtin<"dot_acc_sat_4x8packed_uu_uint", [UInt, UInt, UInt, UInt], 
Attr.Const>;
+  def : Builtin<"dot_acc_sat_4x8packed_ss_int", [Int, UInt, UInt, Int], 
Attr.Const>;
+  def : Builtin<"dot_acc_sat_4x8packed_us_int", [Int, UInt, UInt, Int], 
Attr.Const>;
+  def : Builtin<"dot_acc_sat_4x8packed_su_int", [Int, UInt, UInt, Int], 
Attr.Const>;
+}
+
 //
 // Arm extensions.
 let Extension = ArmIntegerDotProductInt8 in {

diff  --git a/clang/test/Headers/opencl-c-header.cl 

[clang] 724f0e2 - [OpenCL] Add cl_khr_extended_bit_ops

2021-07-21 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-07-21T10:01:19+01:00
New Revision: 724f0e2abb0ce327d2e82af5a61be25e2d2014ec

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

LOG: [OpenCL] Add cl_khr_extended_bit_ops

Add the builtins defined by Section 40 "Extended Bit Operations" in
the OpenCL Extension Specification.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/lib/Headers/opencl-c.h
clang/lib/Sema/OpenCLBuiltins.td
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index c9c1bda140384..ebc4b7a47925b 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -21,6 +21,7 @@
 #define cl_khr_subgroup_shuffle 1
 #define cl_khr_subgroup_shuffle_relative 1
 #define cl_khr_subgroup_clustered_reduce 1
+#define cl_khr_extended_bit_ops 1
 #endif // defined(__SPIR__)
 #endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 

diff  --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index d50f0b8d2e8f5..5b3cd05d4426d 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -16051,6 +16051,206 @@ double  __ovld sub_group_clustered_reduce_max( double 
value, uint clustersize );
 
 #endif // cl_khr_subgroup_clustered_reduce
 
+#if defined(cl_khr_extended_bit_ops)
+char __ovld __cnfn bitfield_insert(char, char, uint, uint);
+uchar __ovld __cnfn bitfield_insert(uchar, uchar, uint, uint);
+short __ovld __cnfn bitfield_insert(short, short, uint, uint);
+ushort __ovld __cnfn bitfield_insert(ushort, ushort, uint, uint);
+int __ovld __cnfn bitfield_insert(int, int, uint, uint);
+uint __ovld __cnfn bitfield_insert(uint, uint, uint, uint);
+long __ovld __cnfn bitfield_insert(long, long, uint, uint);
+ulong __ovld __cnfn bitfield_insert(ulong, ulong, uint, uint);
+char2 __ovld __cnfn bitfield_insert(char2, char2, uint, uint);
+uchar2 __ovld __cnfn bitfield_insert(uchar2, uchar2, uint, uint);
+short2 __ovld __cnfn bitfield_insert(short2, short2, uint, uint);
+ushort2 __ovld __cnfn bitfield_insert(ushort2, ushort2, uint, uint);
+int2 __ovld __cnfn bitfield_insert(int2, int2, uint, uint);
+uint2 __ovld __cnfn bitfield_insert(uint2, uint2, uint, uint);
+long2 __ovld __cnfn bitfield_insert(long2, long2, uint, uint);
+ulong2 __ovld __cnfn bitfield_insert(ulong2, ulong2, uint, uint);
+char3 __ovld __cnfn bitfield_insert(char3, char3, uint, uint);
+uchar3 __ovld __cnfn bitfield_insert(uchar3, uchar3, uint, uint);
+short3 __ovld __cnfn bitfield_insert(short3, short3, uint, uint);
+ushort3 __ovld __cnfn bitfield_insert(ushort3, ushort3, uint, uint);
+int3 __ovld __cnfn bitfield_insert(int3, int3, uint, uint);
+uint3 __ovld __cnfn bitfield_insert(uint3, uint3, uint, uint);
+long3 __ovld __cnfn bitfield_insert(long3, long3, uint, uint);
+ulong3 __ovld __cnfn bitfield_insert(ulong3, ulong3, uint, uint);
+char4 __ovld __cnfn bitfield_insert(char4, char4, uint, uint);
+uchar4 __ovld __cnfn bitfield_insert(uchar4, uchar4, uint, uint);
+short4 __ovld __cnfn bitfield_insert(short4, short4, uint, uint);
+ushort4 __ovld __cnfn bitfield_insert(ushort4, ushort4, uint, uint);
+int4 __ovld __cnfn bitfield_insert(int4, int4, uint, uint);
+uint4 __ovld __cnfn bitfield_insert(uint4, uint4, uint, uint);
+long4 __ovld __cnfn bitfield_insert(long4, long4, uint, uint);
+ulong4 __ovld __cnfn bitfield_insert(ulong4, ulong4, uint, uint);
+char8 __ovld __cnfn bitfield_insert(char8, char8, uint, uint);
+uchar8 __ovld __cnfn bitfield_insert(uchar8, uchar8, uint, uint);
+short8 __ovld __cnfn bitfield_insert(short8, short8, uint, uint);
+ushort8 __ovld __cnfn bitfield_insert(ushort8, ushort8, uint, uint);
+int8 __ovld __cnfn bitfield_insert(int8, int8, uint, uint);
+uint8 __ovld __cnfn bitfield_insert(uint8, uint8, uint, uint);
+long8 __ovld __cnfn bitfield_insert(long8, long8, uint, uint);
+ulong8 __ovld __cnfn bitfield_insert(ulong8, ulong8, uint, uint);
+char16 __ovld __cnfn bitfield_insert(char16, char16, uint, uint);
+uchar16 __ovld __cnfn bitfield_insert(uchar16, uchar16, uint, uint);
+short16 __ovld __cnfn bitfield_insert(short16, short16, uint, uint);
+ushort16 __ovld __cnfn bitfield_insert(ushort16, ushort16, uint, uint);
+int16 __ovld __cnfn bitfield_insert(int16, int16, uint, uint);
+uint16 __ovld __cnfn bitfield_insert(uint16, uint16, uint, uint);
+long16 __ovld __cnfn bitfield_insert(long16, long16, uint, uint);
+ulong16 __ovld __cnfn bitfield_insert(ulong16, ulong16, uint, uint);
+
+char __ovld __cnfn bitfield_extract_signed(char, uint, uint);
+short __ovld __cnfn bitfield_extract_signed(short, uint, uint);
+int __ovld __cnfn bitfield_extract_signed(int, uint, uint);
+long 

[clang] b77b220 - [NFC] Fix typo in comment

2021-07-02 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-07-02T11:39:17+01:00
New Revision: b77b2201dc1f50f10e724c8c0b63963c5d98bf74

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

LOG: [NFC] Fix typo in comment

Reported-by: Marco Cali 

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index aa69ff88bd747..2b83ff4f78503 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -363,7 +363,7 @@ class AnnotatingParser {
 Left->Previous && Left->Previous->is(tok::l_paren)) {
   // Detect the case where macros are used to generate lambdas or
   // function bodies, e.g.:
-  //   auto my_lambda = MARCO((Type *type, int i) { .. body .. });
+  //   auto my_lambda = MACRO((Type *type, int i) { .. body .. });
   for (FormatToken *Tok = Left; Tok != CurrentToken; Tok = Tok->Next) {
 if (Tok->is(TT_BinaryOperator) &&
 Tok->isOneOf(tok::star, tok::amp, tok::ampamp))



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


[clang] ca964b4 - [OpenCL][NFC] Reorganize ClangOpenCLBuiltinEmitter comments

2021-06-11 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-06-11T10:22:59+01:00
New Revision: ca964b40e6e5d20fb658f2d36238b46a35dd860f

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

LOG: [OpenCL][NFC] Reorganize ClangOpenCLBuiltinEmitter comments

Since 8866793b4e0a ("[OpenCL] Add OpenCL builtin test generator",
2021-06-09) there are two emitters in this file, so move the
file-level comment to the appropriate class.

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 5de034df348e8..a4cb5b7cacd98 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -8,6 +8,37 @@
 //
 
//===--===//
 //
+// These backends consume the definitions of OpenCL builtin functions in
+// clang/lib/Sema/OpenCLBuiltins.td and produce builtin handling code for
+// inclusion in SemaLookup.cpp, or a test file that calls all declared 
builtins.
+//
+//===--===//
+
+#include "TableGenBackends.h"
+#include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
+#include "llvm/TableGen/Error.h"
+#include "llvm/TableGen/Record.h"
+#include "llvm/TableGen/StringMatcher.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+using namespace llvm;
+
+namespace {
+
+// A list of signatures that are shared by one or more builtin functions.
+struct BuiltinTableEntries {
+  SmallVector Names;
+  std::vector> Signatures;
+};
+
 // This tablegen backend emits code for checking whether a function is an
 // OpenCL builtin function. If so, all overloads of this function are
 // added to the LookupResult. The generated include file is used by
@@ -53,33 +84,6 @@
 //One OpenCLTypeStruct can represent multiple types, primarily when using
 //GenTypes.
 //
-//===--===//
-
-#include "TableGenBackends.h"
-#include "llvm/ADT/MapVector.h"
-#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallString.h"
-#include "llvm/ADT/StringExtras.h"
-#include "llvm/ADT/StringMap.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/StringSwitch.h"
-#include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/raw_ostream.h"
-#include "llvm/TableGen/Error.h"
-#include "llvm/TableGen/Record.h"
-#include "llvm/TableGen/StringMatcher.h"
-#include "llvm/TableGen/TableGenBackend.h"
-
-using namespace llvm;
-
-namespace {
-
-// A list of signatures that are shared by one or more builtin functions.
-struct BuiltinTableEntries {
-  SmallVector Names;
-  std::vector> Signatures;
-};
-
 class BuiltinNameEmitter {
 public:
   BuiltinNameEmitter(RecordKeeper , raw_ostream )



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


[clang] c5ffc6f - [OpenCL] Add builtin header test

2021-06-10 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-06-10T10:05:53+01:00
New Revision: c5ffc6f8bd6ae0e187de8b6a0e4300161952ba66

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

LOG: [OpenCL] Add builtin header test

Add a test to verify OpenCL builtin declarations using
OpenCLBuiltins.td.

This test consists of parsing a 60k line generated input file.  The
entire test takes about 60s with a debug build on a decent machine.
Admittedly this is not the fastest test, but doesn't seem excessive
compared to other tests in clang/test/Headers (with one of the tests
taking 85s for example).

RFC: https://lists.llvm.org/pipermail/cfe-dev/2021-April/067973.html

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

Added: 
clang/test/Headers/lit.local.cfg
clang/test/Headers/opencl-builtins.cl

Modified: 


Removed: 




diff  --git a/clang/test/Headers/lit.local.cfg 
b/clang/test/Headers/lit.local.cfg
new file mode 100644
index 0..7774a20d637b1
--- /dev/null
+++ b/clang/test/Headers/lit.local.cfg
@@ -0,0 +1,4 @@
+config.substitutions = list(config.substitutions)
+
+# Enable substituting Clang Sema source directory for TableGen input.
+config.substitutions.append(('%clang_src_sema_dir', 
os.path.join(config.clang_src_dir, 'lib', 'Sema')))

diff  --git a/clang/test/Headers/opencl-builtins.cl 
b/clang/test/Headers/opencl-builtins.cl
new file mode 100644
index 0..68ac2922c2ac4
--- /dev/null
+++ b/clang/test/Headers/opencl-builtins.cl
@@ -0,0 +1,19 @@
+// RUN: clang-tblgen -gen-clang-opencl-builtin-tests 
%clang_src_sema_dir/OpenCLBuiltins.td -o %t.cl
+// RUN: %clang_cc1 -include %s %t.cl -triple spir -verify -fsyntax-only 
-cl-std=CL2.0 -finclude-default-header
+// RUN: %clang_cc1 -include %s %t.cl -triple spir -verify -fsyntax-only 
-cl-std=CL2.0 -fdeclare-opencl-builtins -finclude-default-header
+
+// Generate an OpenCL source file containing a call to each builtin from
+// OpenCLBuiltins.td and then run that generated source file through the
+// frontend.
+//
+// Then test that:
+//  - The generated file can be parsed using opencl-c.h, giving some confidence
+//that OpenCLBuiltins.td does not provide more than what opencl-c.h 
provides
+//(but not vice versa).
+//
+//  - The generated file can be parsed using -fdeclare-opencl-builtins, 
ensuring
+//some internal consistency of declarations in OpenCLBuiltins.td.  For
+//example, addition of builtin declarations that lead to ambiguity during
+//overload resolution will cause this test to fail.
+
+// expected-no-diagnostics



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


[clang] 8866793 - [OpenCL] Add OpenCL builtin test generator

2021-06-09 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-06-09T14:03:58+01:00
New Revision: 8866793b4e0abd31e4f57abf9ba832d691a3a3e1

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

LOG: [OpenCL] Add OpenCL builtin test generator

Add a new clang-tblgen flag `-gen-clang-opencl-builtin-tests` that
generates a .cl file containing calls to every builtin function
defined in the .td input.

This patch does not add any use of the new flag yet, so the only way
to obtain a generated test file is through a manual invocation of
clang-tblgen.  A test making use of this emitter will be added in a
followup commit.

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

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
clang/utils/TableGen/TableGen.cpp
clang/utils/TableGen/TableGenBackends.h

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 91227797a757f..5de034df348e8 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -228,6 +228,64 @@ class BuiltinNameEmitter {
   // same entry ().
   MapVector SignatureListMap;
 };
+
+// OpenCL builtin test generator.  This class processes the same TableGen input
+// as BuiltinNameEmitter, but generates a .cl file that contains a call to each
+// builtin function described in the .td input.
+class OpenCLBuiltinTestEmitter {
+public:
+  OpenCLBuiltinTestEmitter(RecordKeeper , raw_ostream )
+  : Records(Records), OS(OS) {}
+
+  // Entrypoint to generate the functions for testing all OpenCL builtin
+  // functions.
+  void emit();
+
+private:
+  struct TypeFlags {
+TypeFlags() : IsConst(false), IsVolatile(false), IsPointer(false) {}
+bool IsConst : 1;
+bool IsVolatile : 1;
+bool IsPointer : 1;
+StringRef AddrSpace;
+  };
+
+  // Return a string representation of the given type, such that it can be
+  // used as a type in OpenCL C code.
+  std::string getTypeString(const Record *Type, TypeFlags Flags,
+int VectorSize) const;
+
+  // Return the type(s) and vector size(s) for the given type.  For
+  // non-GenericTypes, the resulting vectors will contain 1 element.  For
+  // GenericTypes, the resulting vectors typically contain multiple elements.
+  void getTypeLists(Record *Type, TypeFlags ,
+std::vector ,
+std::vector ) const;
+
+  // Expand the TableGen Records representing a builtin function signature into
+  // one or more function signatures.  Return them as a vector of a vector of
+  // strings, with each string containing an OpenCL C type and optional
+  // qualifiers.
+  //
+  // The Records may contain GenericTypes, which expand into multiple
+  // signatures.  Repeated occurrences of GenericType in a signature expand to
+  // the same types.  For example [char, FGenType, FGenType] expands to:
+  //   [char, float, float]
+  //   [char, float2, float2]
+  //   [char, float3, float3]
+  //   ...
+  void
+  expandTypesInSignature(const std::vector ,
+ SmallVectorImpl> );
+
+  // Contains OpenCL builtin functions and related information, stored as
+  // Record instances. They are coming from the associated TableGen file.
+  RecordKeeper 
+
+  // The output file.
+  raw_ostream 
+};
+
 } // namespace
 
 void BuiltinNameEmitter::Emit() {
@@ -861,7 +919,230 @@ static void OCL2Qual(Sema , const OpenCLTypeStruct ,
   OS << "\n} // OCL2Qual\n";
 }
 
+std::string OpenCLBuiltinTestEmitter::getTypeString(const Record *Type,
+TypeFlags Flags,
+int VectorSize) const {
+  std::string S;
+  if (Type->getValueAsBit("IsConst") || Flags.IsConst) {
+S += "const ";
+  }
+  if (Type->getValueAsBit("IsVolatile") || Flags.IsVolatile) {
+S += "volatile ";
+  }
+
+  auto PrintAddrSpace = [](StringRef AddrSpace) {
+S += StringSwitch(AddrSpace)
+ .Case("clang::LangAS::opencl_private", "__private")
+ .Case("clang::LangAS::opencl_global", "__global")
+ .Case("clang::LangAS::opencl_constant", "__constant")
+ .Case("clang::LangAS::opencl_local", "__local")
+ .Case("clang::LangAS::opencl_generic", "__generic")
+ .Default("__private");
+S += " ";
+  };
+  if (Flags.IsPointer) {
+PrintAddrSpace(Flags.AddrSpace);
+  } else if (Type->getValueAsBit("IsPointer")) {
+PrintAddrSpace(Type->getValueAsString("AddrSpace"));
+  }
+
+  StringRef Acc = Type->getValueAsString("AccessQualifier");
+  if (Acc != "") {
+S += StringSwitch(Acc)
+ .Case("RO", "__read_only ")
+ .Case("WO", 

[clang] d54e7b7 - [OpenCL] Add memory_scope_all_devices

2021-06-08 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-06-08T11:51:12+01:00
New Revision: d54e7b731e662e3ec19c590172c9827e3e184829

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

LOG: [OpenCL] Add memory_scope_all_devices

Add the `memory_scope_all_devices` enum value, which is restricted to
OpenCL 3.0 or newer and the `__opencl_c_atomic_scope_all_devices`
feature.  Also guard `memory_scope_all_svm_devices` accordingly, which
is already available in OpenCL 2.0.

The `__opencl_c_atomic_scope_all_devices` feature is header-only, so
set its define to 1 in `opencl-c-base.h`.  This is done
unconditionally at the moment, as the mechanism for disabling
header-only options hasn't been decided yet.

This patch only adds a negative test for now.  Ideally adding a CL3.0
run line to atomic-ops.cl should suffice as a positive test, but we
cannot do that yet until (at least) generic address spaces and program
scope variables are supported in OpenCL 3.0 mode.

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

Added: 


Modified: 
clang/lib/Headers/opencl-c-base.h
clang/test/Headers/opencl-c-header.cl
clang/test/SemaOpenCL/atomic-ops.cl

Removed: 




diff  --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index 72f8c2576ebd3..c9c1bda140384 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -39,6 +39,14 @@
 #define __opencl_c_images 1
 #endif
 
+// Define header-only feature macros for OpenCL C 3.0.
+#if (__OPENCL_C_VERSION__ == 300)
+// For the SPIR target all features are supported.
+#if defined(__SPIR__)
+#define __opencl_c_atomic_scope_all_devices 1
+#endif // defined(__SPIR__)
+#endif // (__OPENCL_C_VERSION__ == 300)
+
 // built-in scalar data types:
 
 /**
@@ -312,7 +320,12 @@ typedef enum memory_scope {
   memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
   memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,
   memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
+#if defined(__opencl_c_atomic_scope_all_devices)
   memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
+#if (__OPENCL_C_VERSION__ >= CL_VERSION_3_0)
+  memory_scope_all_devices = memory_scope_all_svm_devices,
+#endif // __OPENCL_C_VERSION__ >= CL_VERSION_3_0
+#endif // defined(__opencl_c_atomic_scope_all_devices)
 #if defined(cl_intel_subgroups) || defined(cl_khr_subgroups)
   memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
 #endif

diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index 2ab5c5af1facb..4e4545ef529d5 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -151,7 +151,13 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
 
 // OpenCL C features.
-#if (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)
+#if (__OPENCL_C_VERSION__ == 300)
+
+#if __opencl_c_atomic_scope_all_devices != 1
+#error "Incorrectly defined feature macro __opencl_c_atomic_scope_all_devices"
+#endif
+
+#elif (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)
 
 #ifndef  __opencl_c_pipes
 #error "Feature macro __opencl_c_pipes should be defined"

diff  --git a/clang/test/SemaOpenCL/atomic-ops.cl 
b/clang/test/SemaOpenCL/atomic-ops.cl
index 8d150d0fd9297..728c07540a4bd 100644
--- a/clang/test/SemaOpenCL/atomic-ops.cl
+++ b/clang/test/SemaOpenCL/atomic-ops.cl
@@ -2,6 +2,7 @@
 // RUN:   -fsyntax-only -triple=spir64 -fdeclare-opencl-builtins 
-finclude-default-header
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only \
 // RUN:   -triple=amdgcn-amd-amdhsa -fdeclare-opencl-builtins 
-finclude-default-header
+// TODO: add -cl-std=CL3.0 line when generic and psv are supported.
 
 // Basic parsing/Sema tests for __opencl_atomic_*
 
@@ -161,6 +162,11 @@ void synchscope_checks(atomic_int *Ap, int scope) {
   (void)__opencl_atomic_load(Ap, memory_order_relaxed, 
memory_scope_work_group);
   (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_device);
   (void)__opencl_atomic_load(Ap, memory_order_relaxed, 
memory_scope_all_svm_devices);
+  (void)__opencl_atomic_load(Ap, memory_order_relaxed, 
memory_scope_all_devices);
+#if __OPENCL_C_VERSION__ < CL_VERSION_3_0
+  // expected-error@-2{{use of undeclared identifier 
'memory_scope_all_devices'}}
+  // expected-note@* {{'memory_scope_all_svm_devices' declared here}}
+#endif
   (void)__opencl_atomic_load(Ap, memory_order_relaxed, memory_scope_sub_group);
   (void)__opencl_atomic_load(Ap, memory_order_relaxed, scope);
   (void)__opencl_atomic_load(Ap, memory_order_relaxed, 10);
//expected-error{{synchronization scope argument to atomic operation is 
invalid}}




[clang] 85f5272 - [OpenCL][NFC] Fix typos in test

2021-05-27 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-05-27T16:06:33+01:00
New Revision: 85f5272ffc58d73089bf77f0451b37176aa6b64f

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

LOG: [OpenCL][NFC] Fix typos in test

Added: 


Modified: 
clang/test/Headers/opencl-c-header.cl

Removed: 




diff  --git a/clang/test/Headers/opencl-c-header.cl 
b/clang/test/Headers/opencl-c-header.cl
index f97a089e744a4..2ab5c5af1facb 100644
--- a/clang/test/Headers/opencl-c-header.cl
+++ b/clang/test/Headers/opencl-c-header.cl
@@ -190,46 +190,46 @@ global atomic_int z = ATOMIC_VAR_INIT(99);
 #elif (__OPENCL_C_VERSION__ < 200)
 
 #ifdef  __opencl_c_pipes
-#error "Incorret feature macro __opencl_c_pipes define"
+#error "Incorrect feature macro __opencl_c_pipes define"
 #endif
 #ifdef __opencl_c_generic_address_space
-#error "Incorret feature macro __opencl_c_generic_address_space define"
+#error "Incorrect feature macro __opencl_c_generic_address_space define"
 #endif
 #ifdef __opencl_c_work_group_collective_functions
-#error "Incorret feature macro __opencl_c_work_group_collective_functions 
define"
+#error "Incorrect feature macro __opencl_c_work_group_collective_functions 
define"
 #endif
 #ifdef __opencl_c_atomic_order_acq_rel
-#error "Incorret feature macro __opencl_c_atomic_order_acq_rel define"
+#error "Incorrect feature macro __opencl_c_atomic_order_acq_rel define"
 #endif
 #ifdef __opencl_c_atomic_order_seq_cst
-#error "Incorret feature macro __opencl_c_atomic_order_seq_cst define"
+#error "Incorrect feature macro __opencl_c_atomic_order_seq_cst define"
 #endif
 #ifdef __opencl_c_atomic_scope_device
-#error "Incorret feature macro __opencl_c_atomic_scope_device define"
+#error "Incorrect feature macro __opencl_c_atomic_scope_device define"
 #endif
 #ifdef __opencl_c_atomic_scope_all_devices
-#error "Incorret feature macro __opencl_c_atomic_scope_all_devices define"
+#error "Incorrect feature macro __opencl_c_atomic_scope_all_devices define"
 #endif
 #ifdef __opencl_c_device_enqueue
-#error "Incorret feature macro __opencl_c_device_enqueue define"
+#error "Incorrect feature macro __opencl_c_device_enqueue define"
 #endif
 #ifdef __opencl_c_read_write_images
-#error "Incorret feature macro __opencl_c_read_write_images define"
+#error "Incorrect feature macro __opencl_c_read_write_images define"
 #endif
 #ifdef __opencl_c_program_scope_global_variables
-#error "Incorret feature macro __opencl_c_program_scope_global_variables 
define"
+#error "Incorrect feature macro __opencl_c_program_scope_global_variables 
define"
 #endif
 #ifdef __opencl_c_images
-#error "Incorret feature macro __opencl_c_images define"
+#error "Incorrect feature macro __opencl_c_images define"
 #endif
 #ifdef __opencl_c_3d_image_writes
-#error "Incorret feature macro __opencl_c_3d_image_writes define"
+#error "Incorrect feature macro __opencl_c_3d_image_writes define"
 #endif
 #ifdef __opencl_c_fp64
-#error "Incorret feature macro __opencl_c_fp64 define"
+#error "Incorrect feature macro __opencl_c_fp64 define"
 #endif
 #ifdef __opencl_c_subgroups
-#error "Incorret feature macro __opencl_c_subgroups define"
+#error "Incorrect feature macro __opencl_c_subgroups define"
 #endif
 
 #endif //(defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ == 200)



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


[clang] ba0fe85 - [OpenCL] Include header for atomic-ops test

2021-05-26 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-05-26T12:32:07+01:00
New Revision: ba0fe85ec0e93db44f9babaace84cb9ab29ff5f4

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

LOG: [OpenCL] Include header for atomic-ops test

Avoid duplicating the memory_order and memory_scope enum definitions.

Added: 


Modified: 
clang/test/SemaOpenCL/atomic-ops.cl

Removed: 




diff  --git a/clang/test/SemaOpenCL/atomic-ops.cl 
b/clang/test/SemaOpenCL/atomic-ops.cl
index 302cd79dd8a86..8d150d0fd9297 100644
--- a/clang/test/SemaOpenCL/atomic-ops.cl
+++ b/clang/test/SemaOpenCL/atomic-ops.cl
@@ -1,7 +1,7 @@
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify=expected,spir \
-// RUN:   -fsyntax-only -triple=spir64
+// RUN:   -fsyntax-only -triple=spir64 -fdeclare-opencl-builtins 
-finclude-default-header
 // RUN: %clang_cc1 %s -cl-std=CL2.0 -verify -fsyntax-only \
-// RUN:   -triple=amdgcn-amd-amdhsa
+// RUN:   -triple=amdgcn-amd-amdhsa -fdeclare-opencl-builtins 
-finclude-default-header
 
 // Basic parsing/Sema tests for __opencl_atomic_*
 
@@ -9,27 +9,6 @@
 #pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable
 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
 
-typedef __INTPTR_TYPE__ intptr_t;
-typedef int int8 __attribute__((ext_vector_type(8)));
-
-typedef enum memory_order {
-  memory_order_relaxed = __ATOMIC_RELAXED,
-  memory_order_acquire = __ATOMIC_ACQUIRE,
-  memory_order_release = __ATOMIC_RELEASE,
-  memory_order_acq_rel = __ATOMIC_ACQ_REL,
-  memory_order_seq_cst = __ATOMIC_SEQ_CST
-} memory_order;
-
-typedef enum memory_scope {
-  memory_scope_work_item = __OPENCL_MEMORY_SCOPE_WORK_ITEM,
-  memory_scope_work_group = __OPENCL_MEMORY_SCOPE_WORK_GROUP,
-  memory_scope_device = __OPENCL_MEMORY_SCOPE_DEVICE,
-  memory_scope_all_svm_devices = __OPENCL_MEMORY_SCOPE_ALL_SVM_DEVICES,
-#if defined(cl_intel_subgroups) || defined(cl_khr_subgroups)
-  memory_scope_sub_group = __OPENCL_MEMORY_SCOPE_SUB_GROUP
-#endif
-} memory_scope;
-
 struct S { char c[3]; };
 
 char i8;



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


[clang] 37bc1dc - [NFC] Workaround MSVC2019 32-bit compiler crash

2021-04-27 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-04-27T11:15:47+01:00
New Revision: 37bc1dc9877fc480493c85c6d02709b3015bb5e8

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

LOG: [NFC] Workaround MSVC2019 32-bit compiler crash

As reported on D100492, this restructuring should stop the internal
compiler error from happening.

Fixes PR50128.

Added: 


Modified: 
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
index 1e274389b119b..91227797a757f 100644
--- a/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
@@ -525,17 +525,18 @@ void BuiltinNameEmitter::EmitBuiltinTable() {
 
 for (const auto  : SLM.second.Signatures) {
   StringRef ExtName = 
Overload.first->getValueAsDef("Extension")->getName();
+  unsigned int MinVersion =
+  Overload.first->getValueAsDef("MinVersion")->getValueAsInt("ID");
+  unsigned int MaxVersion =
+  Overload.first->getValueAsDef("MaxVersion")->getValueAsInt("ID");
+
   OS << "  { " << Overload.second << ", "
  << Overload.first->getValueAsListOfDefs("Signature").size() << ", "
  << (Overload.first->getValueAsBit("IsPure")) << ", "
  << (Overload.first->getValueAsBit("IsConst")) << ", "
  << (Overload.first->getValueAsBit("IsConv")) << ", "
  << FunctionExtensionIndex[ExtName] << ", "
- << EncodeVersions(Overload.first->getValueAsDef("MinVersion")
-   ->getValueAsInt("ID"),
-   Overload.first->getValueAsDef("MaxVersion")
-   ->getValueAsInt("ID"))
- << " },\n";
+ << EncodeVersions(MinVersion, MaxVersion) << " },\n";
   Index++;
 }
   }



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


[clang] 18772de - [OpenCL] Add inc/dec/cmpxchg C++ legacy atomics with generic

2021-04-26 Thread Sven van Haastregt via cfe-commits

Author: Sven van Haastregt
Date: 2021-04-26T09:46:11+01:00
New Revision: 18772de1ecb1a23b483e29987ae708ab641b1134

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

LOG: [OpenCL] Add inc/dec/cmpxchg C++ legacy atomics with generic

Mirror the remaining C++ for OpenCL specific builtins from opencl-c.h
to the TableGen builtin functions.

Fixes PR50041 (part 2).

Added: 


Modified: 
clang/lib/Sema/OpenCLBuiltins.td

Removed: 




diff  --git a/clang/lib/Sema/OpenCLBuiltins.td 
b/clang/lib/Sema/OpenCLBuiltins.td
index eb8034ee630c..efb540cd1967 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -1088,6 +1088,12 @@ let Extension = FuncExtOpenCLCxx in {
 "atomic_or", "atomic_xor"] in {
   def : Builtin, GenericAS>, 
Type]>;
 }
+foreach name = ["atomic_inc", "atomic_dec"] in {
+  def : Builtin, GenericAS>]>;
+}
+foreach name = ["atomic_cmpxchg"] in {
+  def : Builtin, GenericAS>, 
Type, Type]>;
+}
   }
 }
 



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


  1   2   3   >