[clang] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-17 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

Is there something else needed on my side to get that PR merged?

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


[clang] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/92126

>From c8798839ee93caa9e5a3db6d770801a4c22010c8 Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 14 May 2024 16:08:26 +0200
Subject: [PATCH] libclc: remove __attribute__((assume)) for clspv targets

Instead add a proper attribute in clang, and add convert it to
function metadata to keep the information in the IR.
The goal is to remove the dependency on __attribute__((assume)) that
should have not be there in the first place.

Ref https://github.com/llvm/llvm-project/pull/84934
---
 clang/docs/ReleaseNotes.rst|  4 
 clang/include/clang/Basic/Attr.td  |  7 +++
 clang/include/clang/Basic/AttrDocs.td  | 14 ++
 clang/lib/CodeGen/CodeGenFunction.cpp  |  5 +
 clang/test/CodeGen/clspv_libclc_builtin.c  |  6 ++
 ...pragma-attribute-supported-attributes-list.test |  1 +
 libclc/generic/include/clc/clcfunc.h   |  3 +--
 7 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/clspv_libclc_builtin.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 49ab222bec405..1cec6fb93a344 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -393,6 +393,10 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- The ``clspv_libclc_builtin`` attribute has been added to allow clspv
+  (`OpenCL-C to Vulkan SPIR-V compiler `_) to 
identify functions coming from libclc
+  (`OpenCL-C builtin library `_).
+
 Improvements to Clang's diagnostics
 ---
 - Clang now applies syntax highlighting to the code snippets it
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..38ee8356583be 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4561,3 +4561,10 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def ClspvLibclcBuiltin: InheritableAttr {
+  let Spellings = [Clang<"clspv_libclc_builtin">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [ClspvLibclcBuiltinDoc];
+  let SimpleHandler = 1;
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f351822ac74bd..b48aaf65558ac 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8087,3 +8087,17 @@ requirement:
   }
   }];
 }
+
+def ClspvLibclcBuiltinDoc : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Attribute used by `clspv`_ (OpenCL-C to Vulkan SPIR-V compiler) to identify 
functions coming from `libclc`_ (OpenCL-C builtin library).
+
+.. code-block:: c
+
+  void __attribute__((clspv_libclc_builtin)) libclc_builtin() {}
+
+.. _`clspv`: https://github.com/google/clspv
+.. _`libclc`: https://libclc.llvm.org
+}];
+}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9f16fcb438557..4c4f368ddeba1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -979,6 +979,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 EmitKernelMetadata(FD, Fn);
   }
 
+  if (FD && FD->hasAttr()) {
+Fn->setMetadata("clspv_libclc_builtin",
+llvm::MDNode::get(getLLVMContext(), {}));
+  }
+
   // If we are checking function types, emit a function type signature as
   // prologue data.
   if (FD && SanOpts.has(SanitizerKind::Function)) {
diff --git a/clang/test/CodeGen/clspv_libclc_builtin.c 
b/clang/test/CodeGen/clspv_libclc_builtin.c
new file mode 100644
index 0..ada2555c79e5b
--- /dev/null
+++ b/clang/test/CodeGen/clspv_libclc_builtin.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple spir -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: @foo()
+// CHECK-SAME: !clspv_libclc_builtin
+
+void __attribute__((clspv_libclc_builtin)) foo() {}
diff --git a/clang/test/Misc/pragma-attribute-supported-attributes-list.test 
b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
index 318bfb2df2a7a..fd0e6d71baa80 100644
--- a/clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ b/clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -48,6 +48,7 @@
 // CHECK-NEXT: Capability (SubjectMatchRule_record, 
SubjectMatchRule_type_alias)
 // CHECK-NEXT: CarriesDependency (SubjectMatchRule_variable_is_parameter, 
SubjectMatchRule_objc_method, SubjectMatchRule_function)
 // CHECK-NEXT: Cleanup (SubjectMatchRule_variable_is_local)
+// CHECK-NEXT: ClspvLibclcBuiltin (SubjectMatchRule_function)
 // CHECK-NEXT: CmseNSEntry (SubjectMatchRule_function)
 // CHECK-NEXT: Cold (SubjectMatchRule_function)
 // 

[clang] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/92126

>From 4ce295d3dbd7a5b723cdf410d2023eb59120d27a Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 14 May 2024 16:08:26 +0200
Subject: [PATCH] libclc: remove __attribute__((assume)) for clspv targets

Instead add a proper attribute in clang, and add convert it to
function metadata to keep the information in the IR.
The goal is to remove the dependency on __attribute__((assume)) that
should have not be there in the first place.

Ref https://github.com/llvm/llvm-project/pull/84934
---
 clang/docs/ReleaseNotes.rst   |  4 
 clang/include/clang/Basic/Attr.td |  7 +++
 clang/include/clang/Basic/AttrDocs.td | 14 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  5 +
 clang/test/CodeGen/clspv_libclc_builtin.c |  6 ++
 libclc/generic/include/clc/clcfunc.h  |  3 +--
 6 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/clspv_libclc_builtin.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 49ab222bec405..1cec6fb93a344 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -393,6 +393,10 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- The ``clspv_libclc_builtin`` attribute has been added to allow clspv
+  (`OpenCL-C to Vulkan SPIR-V compiler `_) to 
identify functions coming from libclc
+  (`OpenCL-C builtin library `_).
+
 Improvements to Clang's diagnostics
 ---
 - Clang now applies syntax highlighting to the code snippets it
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..38ee8356583be 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4561,3 +4561,10 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def ClspvLibclcBuiltin: InheritableAttr {
+  let Spellings = [Clang<"clspv_libclc_builtin">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [ClspvLibclcBuiltinDoc];
+  let SimpleHandler = 1;
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f351822ac74bd..b48aaf65558ac 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8087,3 +8087,17 @@ requirement:
   }
   }];
 }
+
+def ClspvLibclcBuiltinDoc : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Attribute used by `clspv`_ (OpenCL-C to Vulkan SPIR-V compiler) to identify 
functions coming from `libclc`_ (OpenCL-C builtin library).
+
+.. code-block:: c
+
+  void __attribute__((clspv_libclc_builtin)) libclc_builtin() {}
+
+.. _`clspv`: https://github.com/google/clspv
+.. _`libclc`: https://libclc.llvm.org
+}];
+}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9f16fcb438557..4c4f368ddeba1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -979,6 +979,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 EmitKernelMetadata(FD, Fn);
   }
 
+  if (FD && FD->hasAttr()) {
+Fn->setMetadata("clspv_libclc_builtin",
+llvm::MDNode::get(getLLVMContext(), {}));
+  }
+
   // If we are checking function types, emit a function type signature as
   // prologue data.
   if (FD && SanOpts.has(SanitizerKind::Function)) {
diff --git a/clang/test/CodeGen/clspv_libclc_builtin.c 
b/clang/test/CodeGen/clspv_libclc_builtin.c
new file mode 100644
index 0..ada2555c79e5b
--- /dev/null
+++ b/clang/test/CodeGen/clspv_libclc_builtin.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple spir -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: @foo()
+// CHECK-SAME: !clspv_libclc_builtin
+
+void __attribute__((clspv_libclc_builtin)) foo() {}
diff --git a/libclc/generic/include/clc/clcfunc.h 
b/libclc/generic/include/clc/clcfunc.h
index ad9eb23f29333..086d780b97085 100644
--- a/libclc/generic/include/clc/clcfunc.h
+++ b/libclc/generic/include/clc/clcfunc.h
@@ -7,8 +7,7 @@
 #if defined(CLC_SPIRV) || defined(CLC_SPIRV64)
 #define _CLC_DEF
 #elif defined(CLC_CLSPV) || defined(CLC_CLSPV64)
-#define _CLC_DEF   
\
-  __attribute__((noinline)) __attribute__((assume("clspv_libclc_builtin")))
+#define _CLC_DEF __attribute__((noinline)) 
__attribute__((clspv_libclc_builtin))
 #else
 #define _CLC_DEF __attribute__((always_inline))
 #endif

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


[clang] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/92126

>From df793384bdb689b3b74ca83102a539a1db623e9f Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 14 May 2024 16:08:26 +0200
Subject: [PATCH] libclc: remove __attribute__((assume)) for clspv targets

Instead add a proper attribute in clang, and add convert it to
function metadata to keep the information in the IR.
The goal is to remove the dependency on __attribute__((assume)) that
should have not be there in the first place.

Ref https://github.com/llvm/llvm-project/pull/84934
---
 clang/docs/ReleaseNotes.rst   |  4 
 clang/include/clang/Basic/Attr.td |  7 +++
 clang/include/clang/Basic/AttrDocs.td | 14 ++
 clang/lib/CodeGen/CodeGenFunction.cpp |  5 +
 clang/test/CodeGen/clspv_libclc_builtin.c |  6 ++
 libclc/generic/include/clc/clcfunc.h  |  3 +--
 6 files changed, 37 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/clspv_libclc_builtin.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 49ab222bec405..2ba25e5a01846 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -393,6 +393,10 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- The ``clspv_libclc_builtin`` attribute has been added to allow clspv
+  (`OpenCL-C to Vulkan SPIR-V compiler `_).
+
 Improvements to Clang's diagnostics
 ---
 - Clang now applies syntax highlighting to the code snippets it
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..38ee8356583be 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4561,3 +4561,10 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def ClspvLibclcBuiltin: InheritableAttr {
+  let Spellings = [Clang<"clspv_libclc_builtin">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [ClspvLibclcBuiltinDoc];
+  let SimpleHandler = 1;
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f351822ac74bd..b48aaf65558ac 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8087,3 +8087,17 @@ requirement:
   }
   }];
 }
+
+def ClspvLibclcBuiltinDoc : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Attribute used by `clspv`_ (OpenCL-C to Vulkan SPIR-V compiler) to identify 
functions coming from `libclc`_ (OpenCL-C builtin library).
+
+.. code-block:: c
+
+  void __attribute__((clspv_libclc_builtin)) libclc_builtin() {}
+
+.. _`clspv`: https://github.com/google/clspv
+.. _`libclc`: https://libclc.llvm.org
+}];
+}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9f16fcb438557..4c4f368ddeba1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -979,6 +979,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 EmitKernelMetadata(FD, Fn);
   }
 
+  if (FD && FD->hasAttr()) {
+Fn->setMetadata("clspv_libclc_builtin",
+llvm::MDNode::get(getLLVMContext(), {}));
+  }
+
   // If we are checking function types, emit a function type signature as
   // prologue data.
   if (FD && SanOpts.has(SanitizerKind::Function)) {
diff --git a/clang/test/CodeGen/clspv_libclc_builtin.c 
b/clang/test/CodeGen/clspv_libclc_builtin.c
new file mode 100644
index 0..ada2555c79e5b
--- /dev/null
+++ b/clang/test/CodeGen/clspv_libclc_builtin.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple spir -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: @foo()
+// CHECK-SAME: !clspv_libclc_builtin
+
+void __attribute__((clspv_libclc_builtin)) foo() {}
diff --git a/libclc/generic/include/clc/clcfunc.h 
b/libclc/generic/include/clc/clcfunc.h
index ad9eb23f29333..086d780b97085 100644
--- a/libclc/generic/include/clc/clcfunc.h
+++ b/libclc/generic/include/clc/clcfunc.h
@@ -7,8 +7,7 @@
 #if defined(CLC_SPIRV) || defined(CLC_SPIRV64)
 #define _CLC_DEF
 #elif defined(CLC_CLSPV) || defined(CLC_CLSPV64)
-#define _CLC_DEF   
\
-  __attribute__((noinline)) __attribute__((assume("clspv_libclc_builtin")))
+#define _CLC_DEF __attribute__((noinline)) 
__attribute__((clspv_libclc_builtin))
 #else
 #define _CLC_DEF __attribute__((always_inline))
 #endif

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


[clang] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/92126

>From 05fd8c24146a5237c7c4cc425beb205524429ba7 Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 14 May 2024 16:08:26 +0200
Subject: [PATCH] libclc: remove __attribute__((assume)) for clspv targets

Instead add a proper attribute in clang, and add convert it to
function metadata to keep the information in the IR.
The goal is to remove the dependency on __attribute__((assume)) that
should have not be there in the first place.

Ref https://github.com/llvm/llvm-project/pull/84934
---
 clang/docs/ReleaseNotes.rst   | 2 ++
 clang/include/clang/Basic/Attr.td | 7 +++
 clang/include/clang/Basic/AttrDocs.td | 7 +++
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 +
 clang/test/CodeGen/clspv_libclc_builtin.c | 6 ++
 libclc/generic/include/clc/clcfunc.h  | 3 +--
 6 files changed, 28 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGen/clspv_libclc_builtin.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 49ab222bec405..6fc8a5771a9a8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -393,6 +393,8 @@ Attribute Changes in Clang
 - Clang now warns that the ``exclude_from_explicit_instantiation`` attribute
   is ignored when applied to a local class or a member thereof.
 
+- The ``clspv_libclc_builtin`` attribute has been added to allow clspv to 
identified functions coming from libclc.
+
 Improvements to Clang's diagnostics
 ---
 - Clang now applies syntax highlighting to the code snippets it
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..38ee8356583be 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4561,3 +4561,10 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def ClspvLibclcBuiltin: InheritableAttr {
+  let Spellings = [Clang<"clspv_libclc_builtin">];
+  let Subjects = SubjectList<[Function]>;
+  let Documentation = [ClspvLibclcBuiltinDoc];
+  let SimpleHandler = 1;
+}
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index f351822ac74bd..1d4ba5b602a01 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -8087,3 +8087,10 @@ requirement:
   }
   }];
 }
+
+def ClspvLibclcBuiltinDoc : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+Attribute used by clspv to identified functions coming from libclc.
+}];
+}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9f16fcb438557..4c4f368ddeba1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -979,6 +979,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 EmitKernelMetadata(FD, Fn);
   }
 
+  if (FD && FD->hasAttr()) {
+Fn->setMetadata("clspv_libclc_builtin",
+llvm::MDNode::get(getLLVMContext(), {}));
+  }
+
   // If we are checking function types, emit a function type signature as
   // prologue data.
   if (FD && SanOpts.has(SanitizerKind::Function)) {
diff --git a/clang/test/CodeGen/clspv_libclc_builtin.c 
b/clang/test/CodeGen/clspv_libclc_builtin.c
new file mode 100644
index 0..ada2555c79e5b
--- /dev/null
+++ b/clang/test/CodeGen/clspv_libclc_builtin.c
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -triple spir -emit-llvm %s -o - | FileCheck %s
+
+// CHECK: @foo()
+// CHECK-SAME: !clspv_libclc_builtin
+
+void __attribute__((clspv_libclc_builtin)) foo() {}
diff --git a/libclc/generic/include/clc/clcfunc.h 
b/libclc/generic/include/clc/clcfunc.h
index ad9eb23f29333..086d780b97085 100644
--- a/libclc/generic/include/clc/clcfunc.h
+++ b/libclc/generic/include/clc/clcfunc.h
@@ -7,8 +7,7 @@
 #if defined(CLC_SPIRV) || defined(CLC_SPIRV64)
 #define _CLC_DEF
 #elif defined(CLC_CLSPV) || defined(CLC_CLSPV64)
-#define _CLC_DEF   
\
-  __attribute__((noinline)) __attribute__((assume("clspv_libclc_builtin")))
+#define _CLC_DEF __attribute__((noinline)) 
__attribute__((clspv_libclc_builtin))
 #else
 #define _CLC_DEF __attribute__((always_inline))
 #endif

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


[clang] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-14 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@erichkeane, I don't know what you expect for the release note, where should I 
write something?

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


[clang] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-14 Thread Romaric Jodin via cfe-commits


@@ -4561,3 +4561,9 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def ClspvLibclcBuiltin: DeclOrStmtAttr {
+  let Spellings = [Clang<"clspv_libclc_builtin">];
+  let Documentation = [Undocumented];

rjodinchr wrote:

What should be the documentation category?

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


[clang] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-14 Thread Romaric Jodin via cfe-commits


@@ -4561,3 +4561,9 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def ClspvLibclcBuiltin: DeclOrStmtAttr {
+  let Spellings = [Clang<"clspv_libclc_builtin">];
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;

rjodinchr wrote:

I have never dealt with clang attribute implementation, so I have no idea 
whether `DeclOrStmtAttr` or `InheritableAttr` should be used. I'll change it 
for `InheritableAttr`.

https://github.com/llvm/llvm-project/pull/92126
___
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 Romaric Jodin via cfe-commits

rjodinchr wrote:

Here is the PR ready for review: https://github.com/llvm/llvm-project/pull/92126

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] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/92126

>From 41e2a5c3fd693fad20e2f76d1a39a1ac9468a33b Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 14 May 2024 16:08:26 +0200
Subject: [PATCH] libclc: remove __attribute__((assume)) for clspv targets

Instead add a proper attribute in clang, and add convert it to
function metadata to keep the information in the IR.
The goal is to remove the dependency on __attribute__((assume)) that
should have not be there in the first place.

Ref https://github.com/llvm/llvm-project/pull/84934
---
 clang/include/clang/Basic/Attr.td | 6 ++
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 +
 libclc/generic/include/clc/clcfunc.h  | 3 +--
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..0970110ee581d 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4561,3 +4561,9 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def ClspvLibclcBuiltin: DeclOrStmtAttr {
+  let Spellings = [Clang<"clspv_libclc_builtin">];
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9f16fcb438557..4c4f368ddeba1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -979,6 +979,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 EmitKernelMetadata(FD, Fn);
   }
 
+  if (FD && FD->hasAttr()) {
+Fn->setMetadata("clspv_libclc_builtin",
+llvm::MDNode::get(getLLVMContext(), {}));
+  }
+
   // If we are checking function types, emit a function type signature as
   // prologue data.
   if (FD && SanOpts.has(SanitizerKind::Function)) {
diff --git a/libclc/generic/include/clc/clcfunc.h 
b/libclc/generic/include/clc/clcfunc.h
index ad9eb23f29333..086d780b97085 100644
--- a/libclc/generic/include/clc/clcfunc.h
+++ b/libclc/generic/include/clc/clcfunc.h
@@ -7,8 +7,7 @@
 #if defined(CLC_SPIRV) || defined(CLC_SPIRV64)
 #define _CLC_DEF
 #elif defined(CLC_CLSPV) || defined(CLC_CLSPV64)
-#define _CLC_DEF   
\
-  __attribute__((noinline)) __attribute__((assume("clspv_libclc_builtin")))
+#define _CLC_DEF __attribute__((noinline)) 
__attribute__((clspv_libclc_builtin))
 #else
 #define _CLC_DEF __attribute__((always_inline))
 #endif

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


[clang] [libclc] libclc: remove __attribute__((assume)) for clspv targets (PR #92126)

2024-05-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr created 
https://github.com/llvm/llvm-project/pull/92126

Instead add a proper attribute in clang, and add convert it to function 
metadata to keep the information in the IR. The goal is to remove the 
dependency on __attribute__((assume)) that should have not be there in the 
first place.

Ref https://github.com/llvm/llvm-project/pull/84934

>From 4dc2646a51a05abe7cfb539325dbd57d507dfceb Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 14 May 2024 16:08:26 +0200
Subject: [PATCH] libclc: remove __attribute__((assume)) for clspv targets

Instead add a proper attribute in clang, and add convert it to
function metadata to keep the information in the IR.
The goal is to remove the dependency on __attribute__((assume)) that
should have not be there in the first place.

Ref https://github.com/llvm/llvm-project/pull/84934
---
 clang/include/clang/Basic/Attr.td | 6 ++
 clang/lib/CodeGen/CodeGenFunction.cpp | 5 +
 libclc/generic/include/clc/clcfunc.h  | 2 +-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 52552ba488560..0970110ee581d 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4561,3 +4561,9 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def ClspvLibclcBuiltin: DeclOrStmtAttr {
+  let Spellings = [Clang<"clspv_libclc_builtin">];
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 9f16fcb438557..4c4f368ddeba1 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -979,6 +979,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 EmitKernelMetadata(FD, Fn);
   }
 
+  if (FD && FD->hasAttr()) {
+Fn->setMetadata("clspv_libclc_builtin",
+llvm::MDNode::get(getLLVMContext(), {}));
+  }
+
   // If we are checking function types, emit a function type signature as
   // prologue data.
   if (FD && SanOpts.has(SanitizerKind::Function)) {
diff --git a/libclc/generic/include/clc/clcfunc.h 
b/libclc/generic/include/clc/clcfunc.h
index ad9eb23f29333..59f45c27019d6 100644
--- a/libclc/generic/include/clc/clcfunc.h
+++ b/libclc/generic/include/clc/clcfunc.h
@@ -8,7 +8,7 @@
 #define _CLC_DEF
 #elif defined(CLC_CLSPV) || defined(CLC_CLSPV64)
 #define _CLC_DEF   
\
-  __attribute__((noinline)) __attribute__((assume("clspv_libclc_builtin")))
+  __attribute__((noinline)) __attribute__((clspv_libclc_builtin))
 #else
 #define _CLC_DEF __attribute__((always_inline))
 #endif

___
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 Romaric Jodin via cfe-commits

rjodinchr wrote:

I'll make a PR for clspv then

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] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-05-14 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

Alright with those changes, everything should be fine for `clspv`:
```
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index dc87a8c6f022..056f22b56001 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -4506,3 +4506,9 @@ def CodeAlign: StmtAttr {
 static constexpr int MaximumAlignment = 4096;
   }];
 }
+
+def ClspvLibclcBuiltin: DeclOrStmtAttr {
+  let Spellings = [Clang<"clspv_libclc_builtin">];
+  let Documentation = [Undocumented];
+  let SimpleHandler = 1;
+}
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp 
b/clang/lib/CodeGen/CodeGenFunction.cpp
index 86a6ddd80cc1..b0e3b96cd59d 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -973,6 +973,11 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, 
QualType RetTy,
 EmitKernelMetadata(FD, Fn);
   }

+  if (FD && FD->hasAttr()) {
+Fn->setMetadata("clspv_libclc_builtin",
+llvm::MDNode::get(getLLVMContext(), {}));
+  }
+
   // If we are checking function types, emit a function type signature as
   // prologue data.
   if (FD && SanOpts.has(SanitizerKind::Function)) {
diff --git a/libclc/generic/include/clc/clcfunc.h 
b/libclc/generic/include/clc/clcfunc.h
index ad9eb23f2933..59f45c27019d 100644
--- a/libclc/generic/include/clc/clcfunc.h
+++ b/libclc/generic/include/clc/clcfunc.h
@@ -8,7 +8,7 @@
 #define _CLC_DEF
 #elif defined(CLC_CLSPV) || defined(CLC_CLSPV64)
 #define _CLC_DEF   
\
-  __attribute__((noinline)) __attribute__((assume("clspv_libclc_builtin")))
+  __attribute__((noinline)) __attribute__((clspv_libclc_builtin))
 #else
 #define _CLC_DEF __attribute__((always_inline))
 #endif
 ```
 @Sirraide, would you add those (or similar if you feel that changes are 
needed) directly to that PR?

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] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-05-14 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

This is the first time I'm trying to add an attribute, and I think I am missing 
something.
I am adding this part in `Attr.td`:
```
def ClspvLibclcBuiltin: DeclOrStmtAttr {
  let Spellings = [Clang<"clspv_libclc_builtin">];
  let Documentation = [Undocumented];
  let SimpleHandler = 1;
}
```
It allows the source to be parsed, but then I don't see the attribute in the 
LLVM IR generated for libclc.

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] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-05-13 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

It is only to tag functions. I guess the name would be `clspv_libclc_builtin` 
(https://github.com/llvm/llvm-project/blob/main/libclc/generic/include/clc/clcfunc.h#L11).

I've started to test with such a solution to make sure everything works on 
clspv side, but I need more time.

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] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-05-12 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

> > It has nothing to do with OpenMP. The goal was just to get something in the 
> > llvm IR that we could check for. The `assume` attribute allows us to pass a 
> > string that we can then check in a llvm pass.
> 
> Could you investigate whether 'annotate' would do what you want? IIRC, the 
> point of it is to just pass a string onto the AST/IR.

At the moment, I did not manage to have annotation working. It's because 
annotation is an indirect link to the function. Thus it does not stick around 
when I link modules.

Maybe the easiest way would be to add a real attribute for clspv?

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] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-05-08 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

It has nothing to do with OpenMP.
The goal was just to get something in the llvm IR that we could check for. The 
`assume` attribute allows us to pass a string that we can then check in a llvm 
pass.


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] [libclc] [llvm] [openmp] [Clang] `__attribute__((assume))` refactor (PR #84934)

2024-05-08 Thread Romaric Jodin via cfe-commits

rjodinchr 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/google/clspv uses the assume attribute. The goal is to be 
able to put a mark on libclc functions to have a specific lowering in `clspv`.
I'm not against removing the attribute, but we will have to find another way to 
do that for `clspv`. Do you know something we could use to get rid of the 
assume attribute?

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


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-10 Thread Romaric Jodin via cfe-commits

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


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


[libclc] [libclc] Fix a couple of issues preventing in-tree builds (PR #87505)

2024-04-08 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

> > ```
> >   set( spv_suffix ${arch_suffix}.spv )
> >   add_custom_command( OUTPUT "${spv_suffix}"
> > COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" 
> > ${builtins_opt_lib_tgt}
> > DEPENDS ${builtins_link_lib_tgt} )
> > ```
> > 
> > 
> > 
> >   
> > 
> > 
> >   
> > 
> > 
> > 
> >   
> > I think that ought to be `DEPENDS ${builtins_opt_lib_tgt}`. Do you need me 
> > to send a PR for that?
> 
> Hmm yes you might be right. Just to confirm, does that fix the problem for 
> you?
> 
> I can't be sure but it seems like that was a problem before 
> [61efea7](https://github.com/llvm/llvm-project/commit/61efea7142e904e6492e1ce0566ec23d9d221c1e)
>  when I last touched it, as least from a simple reading of the CMake.

I think the issue is not coming from the DEPENDS but from the source.
```
- COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" ${builtins_opt_lib_tgt}
+ COMMAND ${LLVM_SPIRV} ${spvflags} -o "${spv_suffix}" ${builtins_link_lib_tgt}
```

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


[libclc] [llvm] [libclc] Refactor build system to allow in-tree builds (PR #87622)

2024-04-05 Thread Romaric Jodin via cfe-commits


@@ -358,3 +399,7 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
 endif()
   endforeach( d )
 endforeach( t )
+
+if( NOT LIBCLC_STANDALONE_BUILD )
+  add_subdirectory( test )

rjodinchr wrote:

There is no `CMakeLists.txt` in `/llvm/libclc/test`.

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


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

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


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66902

>From c5f3c0a72bf5b52f7f92df3bcc00a7c5b9001a5c Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: update gen_convert.cl for clspv

Add a clspv switch in gen_convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.
---
 libclc/CMakeLists.txt |  15 +++-
 libclc/generic/lib/gen_convert.py | 129 --
 2 files changed, 116 insertions(+), 28 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index fa1d8e4adbcc4f..18f77940e76669 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -174,6 +174,12 @@ add_custom_command(
DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 
+add_custom_command(
+   OUTPUT clspv-convert.cl
+   COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
+   DEPENDS ${script_loc} )
+add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -218,11 +224,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
-   set( rel_files convert.cl )
-   set( objects convert.cl )
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL 
"clspv" AND
NOT ${ARCH} STREQUAL "clspv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
+   set( rel_files clspv-convert.cl )
+   set( objects clspv-convert.cl )
endif()
else()
set( rel_files )
@@ -286,6 +295,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# multiple invocations
add_dependencies( builtins.link.${arch_suffix}
generate_convert.cl )
+   add_dependencies( builtins.link.${arch_suffix}
+   clspv-generate_convert.cl )
# CMake will turn this include into absolute path
target_include_directories( builtins.link.${arch_suffix} PRIVATE
"generic/include" )
diff --git a/libclc/generic/lib/gen_convert.py 
b/libclc/generic/lib/gen_convert.py
index 612a9184f4b271..21fc8ebc80d156 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2013 Victor Oliveira 
 # Copyright (c) 2013 Jesse Towner 
+# Copyright (c) 2024 Romaric Jodin 
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,16 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import argparse
+
+parser = argparse.ArgumentParser()
+parser.add_argument(
+"--clspv", action="store_true", help="Generate the clspv variant of the 
code"
+)
+args = parser.parse_args()
+
+clspv = args.clspv
+
 types = [
 "char",
 "uchar",
@@ -251,13 +262,19 @@ def generate_default_conversion(src, dst, mode):
 print("#endif")
 
 
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handled natively
+if not clspv:
+for src in types:
+for dst in types:
+generate_default_conversion(src, dst, "")
 
 for src in int_types:
 for dst in int_types:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are handled
+# natively
+if clspv and mode == "_rte":
+continue
 generate_default_conversion(src, dst, mode)
 
 #
@@ -304,21 +321,38 @@ def generate_saturated_conversion(src, dst, size):
 
 elif src in float_types:
 
-# Conversion from float to int
-print(
-"""  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
-  return y;""".format(
-SRC=src,
-

[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits


@@ -307,8 +320,8 @@ def generate_saturated_conversion(src, dst, size):
 # Conversion from float to int
 print(
 """  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
+  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
+  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC}{N}){DST_MAX}){BS});

rjodinchr wrote:

Yes this change was intended.
It is not a standalone bugfix as for all C platforms, this should be the same. 
But with Vulkan SPIR-V it leads to issues with zeros, infs & nans, where 
comparisons are unspecified (if I remember correctly).
I understand that changing the default path might get a bit more dangerous 
there, so I have added a if statement for it as well.

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


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits


@@ -26,6 +27,12 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import sys
+
+clspv = False
+if len(sys.argv) == 2 and sys.argv[1] == "--clspv":
+clspv = True
+

rjodinchr wrote:

I wanted to avoid the dependency on argparse to be added. But Python version 
not having it by default are getting very old and unsupported so I guess it's 
definitely better to use it.

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


[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66902

>From 79427445538b3abeda08224e48484ddac1342243 Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: update gen_convert.cl for clspv

Add a clspv switch in gen_convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.
---
 libclc/CMakeLists.txt |  15 +++-
 libclc/generic/lib/gen_convert.py | 131 --
 2 files changed, 118 insertions(+), 28 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index fa1d8e4adbcc4f..18f77940e76669 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -174,6 +174,12 @@ add_custom_command(
DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 
+add_custom_command(
+   OUTPUT clspv-convert.cl
+   COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
+   DEPENDS ${script_loc} )
+add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -218,11 +224,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
-   set( rel_files convert.cl )
-   set( objects convert.cl )
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL 
"clspv" AND
NOT ${ARCH} STREQUAL "clspv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
+   set( rel_files clspv-convert.cl )
+   set( objects clspv-convert.cl )
endif()
else()
set( rel_files )
@@ -286,6 +295,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# multiple invocations
add_dependencies( builtins.link.${arch_suffix}
generate_convert.cl )
+   add_dependencies( builtins.link.${arch_suffix}
+   clspv-generate_convert.cl )
# CMake will turn this include into absolute path
target_include_directories( builtins.link.${arch_suffix} PRIVATE
"generic/include" )
diff --git a/libclc/generic/lib/gen_convert.py 
b/libclc/generic/lib/gen_convert.py
index 612a9184f4b271..2bcc68c434c348 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2013 Victor Oliveira 
 # Copyright (c) 2013 Jesse Towner 
+# Copyright (c) 2024 Romaric Jodin 
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,18 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import argparse
+
+parser = argparse.ArgumentParser()
+parser.add_argument(
+'--clspv',
+action='store_true',
+help="Generate the clspv variant of the code"
+)
+args = parser.parse_args()
+
+clspv = args.clspv
+
 types = [
 "char",
 "uchar",
@@ -251,13 +264,19 @@ def generate_default_conversion(src, dst, mode):
 print("#endif")
 
 
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handled natively
+if not clspv:
+for src in types:
+for dst in types:
+generate_default_conversion(src, dst, "")
 
 for src in int_types:
 for dst in int_types:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are handled
+# natively
+if clspv and mode == "_rte":
+continue
 generate_default_conversion(src, dst, mode)
 
 #
@@ -304,21 +323,38 @@ def generate_saturated_conversion(src, dst, size):
 
 elif src in float_types:
 
-# Conversion from float to int
-print(
-"""  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
-  return y;""".format(
-SRC=src,
-

[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66902

>From 8d2b49e198feb8ec3d836b871178b14c161c4d5d Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: update gen_convert.cl for clspv

Add a clspv switch in gen_convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.

I did not use python argparse to avoid adding the dependency on it.
---
 libclc/CMakeLists.txt | 15 +-
 libclc/generic/lib/gen_convert.py | 84 +--
 2 files changed, 83 insertions(+), 16 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index fa1d8e4adbcc4f..18f77940e76669 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -174,6 +174,12 @@ add_custom_command(
DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 
+add_custom_command(
+   OUTPUT clspv-convert.cl
+   COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
+   DEPENDS ${script_loc} )
+add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -218,11 +224,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
-   set( rel_files convert.cl )
-   set( objects convert.cl )
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL 
"clspv" AND
NOT ${ARCH} STREQUAL "clspv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
+   set( rel_files clspv-convert.cl )
+   set( objects clspv-convert.cl )
endif()
else()
set( rel_files )
@@ -286,6 +295,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# multiple invocations
add_dependencies( builtins.link.${arch_suffix}
generate_convert.cl )
+   add_dependencies( builtins.link.${arch_suffix}
+   clspv-generate_convert.cl )
# CMake will turn this include into absolute path
target_include_directories( builtins.link.${arch_suffix} PRIVATE
"generic/include" )
diff --git a/libclc/generic/lib/gen_convert.py 
b/libclc/generic/lib/gen_convert.py
index 612a9184f4b271..768f0200999b79 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2013 Victor Oliveira 
 # Copyright (c) 2013 Jesse Towner 
+# Copyright (c) 2024 Romaric Jodin 
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,12 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import sys
+
+clspv = False
+if len(sys.argv) == 2 and sys.argv[1] == "--clspv":
+clspv = True
+
 types = [
 "char",
 "uchar",
@@ -251,13 +258,19 @@ def generate_default_conversion(src, dst, mode):
 print("#endif")
 
 
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handle natively
+if not clspv:
+for src in types:
+for dst in types:
+generate_default_conversion(src, dst, "")
 
 for src in int_types:
 for dst in int_types:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are handle
+# natively
+if clspv and mode == "_rte":
+continue
 generate_default_conversion(src, dst, mode)
 
 #
@@ -307,8 +320,8 @@ def generate_saturated_conversion(src, dst, size):
 # Conversion from float to int
 print(
 """  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
+  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
+  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC}{N}){DST_MAX}){BS});
   

[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66902

>From a6146bbc90d198d62d516bf09a41034f36f7866c Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: update gen_convert.cl for clspv

Add a clspv switch in gen_convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.

I did not use python argparse to avoid adding the dependency on it.
---
 libclc/CMakeLists.txt | 15 +-
 libclc/generic/lib/gen_convert.py | 77 +--
 2 files changed, 75 insertions(+), 17 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index fa1d8e4adbcc4f..18f77940e76669 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -174,6 +174,12 @@ add_custom_command(
DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 
+add_custom_command(
+   OUTPUT clspv-convert.cl
+   COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
+   DEPENDS ${script_loc} )
+add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -218,11 +224,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
-   set( rel_files convert.cl )
-   set( objects convert.cl )
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL 
"clspv" AND
NOT ${ARCH} STREQUAL "clspv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
+   set( rel_files clspv-convert.cl )
+   set( objects clspv-convert.cl )
endif()
else()
set( rel_files )
@@ -286,6 +295,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# multiple invocations
add_dependencies( builtins.link.${arch_suffix}
generate_convert.cl )
+   add_dependencies( builtins.link.${arch_suffix}
+   clspv-generate_convert.cl )
# CMake will turn this include into absolute path
target_include_directories( builtins.link.${arch_suffix} PRIVATE
"generic/include" )
diff --git a/libclc/generic/lib/gen_convert.py 
b/libclc/generic/lib/gen_convert.py
index 612a9184f4b271..afdb589536c969 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2013 Victor Oliveira 
 # Copyright (c) 2013 Jesse Towner 
+# Copyright (c) 2024 Romaric Jodin 
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,12 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import sys
+
+clspv = False
+if len(sys.argv) == 2 and sys.argv[1] == '--clspv':
+clspv = True
+
 types = [
 "char",
 "uchar",
@@ -250,14 +257,19 @@ def generate_default_conversion(src, dst, mode):
 if close_conditional:
 print("#endif")
 
-
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handle natively
+if not clspv:
+for src in types:
+for dst in types:
+generate_default_conversion(src, dst, "")
 
 for src in int_types:
 for dst in int_types:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are handle
+# natively
+if clspv and mode == "_rte":
+continue
 generate_default_conversion(src, dst, mode)
 
 #
@@ -307,8 +319,8 @@ def generate_saturated_conversion(src, dst, size):
 # Conversion from float to int
 print(
 """  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
+  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
+  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= 

[libclc] libclc: clspv: update gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

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


[libclc] libclc: clspv: create gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

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


[libclc] libclc: clspv: create gen_convert.cl for clspv (PR #66902)

2024-03-14 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66902

>From 5614f89c90cf865c88fbcf95d707e34dfeb18a19 Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: update gen_convert.cl for clspv

Add a clspv switch in gen_convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.

I did not use python argparse to avoid adding the dependency on it.
---
 libclc/CMakeLists.txt | 15 +-
 libclc/generic/lib/gen_convert.py | 77 +--
 2 files changed, 75 insertions(+), 17 deletions(-)

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index fa1d8e4adbcc4f..18f77940e76669 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -174,6 +174,12 @@ add_custom_command(
DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 
+add_custom_command(
+   OUTPUT clspv-convert.cl
+   COMMAND ${Python3_EXECUTABLE} ${script_loc} --clspv > clspv-convert.cl
+   DEPENDS ${script_loc} )
+add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -218,11 +224,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
-   set( rel_files convert.cl )
-   set( objects convert.cl )
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL 
"clspv" AND
NOT ${ARCH} STREQUAL "clspv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
+   set( rel_files clspv-convert.cl )
+   set( objects clspv-convert.cl )
endif()
else()
set( rel_files )
@@ -286,6 +295,8 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# multiple invocations
add_dependencies( builtins.link.${arch_suffix}
generate_convert.cl )
+   add_dependencies( builtins.link.${arch_suffix}
+   clspv-generate_convert.cl )
# CMake will turn this include into absolute path
target_include_directories( builtins.link.${arch_suffix} PRIVATE
"generic/include" )
diff --git a/libclc/generic/lib/gen_convert.py 
b/libclc/generic/lib/gen_convert.py
index 612a9184f4b271..afdb589536c969 100644
--- a/libclc/generic/lib/gen_convert.py
+++ b/libclc/generic/lib/gen_convert.py
@@ -2,6 +2,7 @@
 #
 # Copyright (c) 2013 Victor Oliveira 
 # Copyright (c) 2013 Jesse Towner 
+# Copyright (c) 2024 Romaric Jodin 
 #
 # Permission is hereby granted, free of charge, to any person obtaining a copy
 # of this software and associated documentation files (the "Software"), to deal
@@ -26,6 +27,12 @@
 #
 # convert_<_sat><_roundingMode>()
 
+import sys
+
+clspv = False
+if len(sys.argv) == 2 and sys.argv[1] == '--clspv':
+clspv = True
+
 types = [
 "char",
 "uchar",
@@ -250,14 +257,19 @@ def generate_default_conversion(src, dst, mode):
 if close_conditional:
 print("#endif")
 
-
-for src in types:
-for dst in types:
-generate_default_conversion(src, dst, "")
+# Do not generate default conversion for clspv as they are handle natively
+if not clspv:
+for src in types:
+for dst in types:
+generate_default_conversion(src, dst, "")
 
 for src in int_types:
 for dst in int_types:
 for mode in rounding_modes:
+# Do not generate "_rte" conversion for clspv as they are handle
+# natively
+if clspv and mode == "_rte":
+continue
 generate_default_conversion(src, dst, mode)
 
 #
@@ -307,8 +319,8 @@ def generate_saturated_conversion(src, dst, size):
 # Conversion from float to int
 print(
 """  {DST}{N} y = convert_{DST}{N}(x);
-  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
-  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
+  y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
+  y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= 

[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-11-15 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@AnastasiaStulova Could you please take a look? thanks

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-11-03 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

What is the next step to get this PR merged?

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-10-24 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@arsenm?

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-10-18 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@arsenm could you have another look at this PR?
Thank you

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-10-02 Thread Romaric Jodin via cfe-commits


@@ -5612,6 +5612,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
,
   BundleList);
 EmitBlock(Cont);
   }
+  if (CI->getCalledFunction() && CI->getCalledFunction()->hasName() &&
+  CI->getCalledFunction()->getName().startswith("_Z4sqrt")) {

rjodinchr wrote:

@arsenm ?

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-25 Thread Romaric Jodin via cfe-commits


@@ -5612,6 +5612,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
,
   BundleList);
 EmitBlock(Cont);
   }
+  if (CI->getCalledFunction() && CI->getCalledFunction()->hasName() &&
+  CI->getCalledFunction()->getName().startswith("_Z4sqrt")) {

rjodinchr wrote:

Using a custom `ext_vector_type` in OpenCL feels like an undefined behaviour. I 
don't see anything about it in the specification.
Am I missing something?

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-25 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@arsenm Could you review this PR again please?

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


[libclc] libclc: clspv: create gen_convert.cl for clspv (PR #66902)

2023-09-21 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66902

>From 67e347f9987b48652daaaceb4a51041f7b9a1430 Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: create gen_convert.cl for clspv

Create clspv own convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.

Here are the differences between this new gen_convert.cl and the one in generic:

```
4a5
> # Copyright (c) 2023 Romaric Jodin 
144a146
>Copyright (c) 2023 Romaric Jodin 
254,257d255
< for src in types:
< for dst in types:
< generate_default_conversion(src, dst, "")
<
260a259,260
> if mode == "_rte":
> continue
310,311c310,311
<   y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
<   y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
---
>   y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
>   y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC}{N}){DST_MAX}){BS});
435c435
< print("  {SRC}{N} y = convert_{SRC}{N}(r);".format(SRC=src, N=size))
---
> print("  {SRC}{N} y = convert_{SRC}{N}_sat(r);".format(SRC=src, 
> N=size))
450a451,457
> print("  {BOOL}{N} c = convert_{BOOL}{N}(abs_y > 
> abs_x);".format(BOOL=bool_type[dst], N=size))
> if sizeof_type[src] >= 4 and src in int_types:
> print(
> "  c = c || convert_{BOOL}{N}(({SRC}{N}){SRC_MAX} == 
> x);".format(
> BOOL=bool_type[dst], N=size, SRC=src, 
> SRC_MAX=limit_max[src]
> )
> )
452,453c459,460
< "  return select(r, nextafter(r, sign(r) * 
({DST}{N})-INFINITY), convert_{BOOL}{N}(abs_y > abs_x));".format(
< DST=dst, N=size, BOOL=bool_type[dst]
---
> "  return select(r, nextafter(r, sign(r) * 
> ({DST}{N})-INFINITY), c);".format(
> DST=dst, N=size, BOOL=bool_type[dst], SRC=src
462a470,476
> print("  {BOOL}{N} c = convert_{BOOL}{N}(y > 
> x);".format(BOOL=bool_type[dst], N=size))
> if sizeof_type[src] >= 4 and src in int_types:
> print(
> "  c = c || convert_{BOOL}{N}(({SRC}{N}){SRC_MAX} == 
> x);".format(
> BOOL=bool_type[dst], N=size, SRC=src, 
> SRC_MAX=limit_max[src]
> )
> )
464,465c478,479
< "  return select(r, nextafter(r, ({DST}{N})-INFINITY), 
convert_{BOOL}{N}(y > x));".format(
< DST=dst, N=size, BOOL=bool_type[dst]
---
> "  return select(r, nextafter(r, ({DST}{N})-INFINITY), 
> c);".format(
> DST=dst, N=size, BOOL=bool_type[dst], SRC=src
486a501,502
> if mode == "_rte":
> continue
```
---
 libclc/CMakeLists.txt   |  16 +-
 libclc/clspv/lib/gen_convert.py | 508 
 2 files changed, 522 insertions(+), 2 deletions(-)
 create mode 100644 libclc/clspv/lib/gen_convert.py

diff --git a/libclc/CMakeLists.txt b/libclc/CMakeLists.txt
index 9daef8265c16f26..00f97e616a9f583 100644
--- a/libclc/CMakeLists.txt
+++ b/libclc/CMakeLists.txt
@@ -176,6 +176,13 @@ add_custom_command(
DEPENDS ${script_loc} )
 add_custom_target( "generate_convert.cl" DEPENDS convert.cl )
 
+file( TO_CMAKE_PATH ${CMAKE_SOURCE_DIR}/clspv/lib/gen_convert.py script_loc )
+add_custom_command(
+   OUTPUT clspv-convert.cl
+   COMMAND ${Python3_EXECUTABLE} ${script_loc} > clspv-convert.cl
+   DEPENDS ${script_loc} )
+add_custom_target( "clspv-generate_convert.cl" DEPENDS clspv-convert.cl )
+
 enable_testing()
 
 foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
@@ -220,11 +227,14 @@ foreach( t ${LIBCLC_TARGETS_TO_BUILD} )
# Add the generated convert.cl here to prevent adding
# the one listed in SOURCES
if( NOT ${ARCH} STREQUAL "spirv" AND NOT ${ARCH} STREQUAL "spirv64" )
-   set( rel_files convert.cl )
-   set( objects convert.cl )
if( NOT ENABLE_RUNTIME_SUBNORMAL AND NOT ${ARCH} STREQUAL 
"clspv" AND
NOT ${ARCH} STREQUAL "clspv64" )
+   set( rel_files convert.cl )
+   set( objects convert.cl )
list( APPEND rel_files 
generic/lib/subnormal_use_default.ll )
+   elseif(${ARCH} STREQUAL "clspv" OR ${ARCH} STREQUAL "clspv64")
+   set( 

[libclc] libclc: clspv: create gen_convert.cl for clspv (PR #66902)

2023-09-20 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@kpet @alan-baker could you review this PR please?

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


[libclc] libclc: clspv: create gen_convert.cl for clspv (PR #66902)

2023-09-20 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr created 
https://github.com/llvm/llvm-project/pull/66902

Create clspv own convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions needed to have 
the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and TYPE_MIN. Depending on 
the platform the behaviour can vary, but most of them just do not convert 
correctly those 2 values.

Because of that, we also need to avoid having explicit function for simple 
conversions because it allows llvm to optimise the code, thus removing some of 
the added checks that are in fact needed.

Here are the differences between this new gen_convert.cl and the one in generic:

```
4a5
> # Copyright (c) 2023 Romaric Jodin 
144a146
>Copyright (c) 2023 Romaric Jodin 
254,257d255
< for src in types:
< for dst in types:
< generate_default_conversion(src, dst, "")
<
260a259,260
> if mode == "_rte":
> continue
310,311c310,311
<   y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
<   y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
---
>   y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
>   y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC}{N}){DST_MAX}){BS});
435c435
< print("  {SRC}{N} y = convert_{SRC}{N}(r);".format(SRC=src, N=size))
---
> print("  {SRC}{N} y = convert_{SRC}{N}_sat(r);".format(SRC=src, 
> N=size))
450a451,457
> print("  {BOOL}{N} c = convert_{BOOL}{N}(abs_y > 
> abs_x);".format(BOOL=bool_type[dst], N=size))
> if sizeof_type[src] >= 4 and src in int_types:
> print(
> "  c = c || convert_{BOOL}{N}(({SRC}{N}){SRC_MAX} == 
> x);".format(
> BOOL=bool_type[dst], N=size, SRC=src, 
> SRC_MAX=limit_max[src]
> )
> )
452,453c459,460
< "  return select(r, nextafter(r, sign(r) * 
({DST}{N})-INFINITY), convert_{BOOL}{N}(abs_y > abs_x));".format(
< DST=dst, N=size, BOOL=bool_type[dst]
---
> "  return select(r, nextafter(r, sign(r) * 
> ({DST}{N})-INFINITY), c);".format(
> DST=dst, N=size, BOOL=bool_type[dst], SRC=src
462a470,476
> print("  {BOOL}{N} c = convert_{BOOL}{N}(y > 
> x);".format(BOOL=bool_type[dst], N=size))
> if sizeof_type[src] >= 4 and src in int_types:
> print(
> "  c = c || convert_{BOOL}{N}(({SRC}{N}){SRC_MAX} == 
> x);".format(
> BOOL=bool_type[dst], N=size, SRC=src, 
> SRC_MAX=limit_max[src]
> )
> )
464,465c478,479
< "  return select(r, nextafter(r, ({DST}{N})-INFINITY), 
convert_{BOOL}{N}(y > x));".format(
< DST=dst, N=size, BOOL=bool_type[dst]
---
> "  return select(r, nextafter(r, ({DST}{N})-INFINITY), 
> c);".format(
> DST=dst, N=size, BOOL=bool_type[dst], SRC=src
486a501,502
> if mode == "_rte":
> continue
```

>From 2a2355d86133ab5e7d0819e80ced0dbe5ea0fb6a Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Tue, 18 Jul 2023 09:30:09 +0200
Subject: [PATCH] libclc: clspv: create gen_convert.cl for clspv

Create clspv own convert.cl
This is needed as Vulkan SPIR-V does not respect the assumptions
needed to have the generic convert.cl compliant on many platforms.

It is needed because of the conversion of TYPE_MAX and
TYPE_MIN. Depending on the platform the behaviour can vary, but most
of them just do not convert correctly those 2 values.

Because of that, we also need to avoid having explicit function for
simple conversions because it allows llvm to optimise the code, thus
removing some of the added checks that are in fact needed.

Here are the differences between this new gen_convert.cl and the one in generic:

```
4a5
> # Copyright (c) 2023 Romaric Jodin 
144a146
>Copyright (c) 2023 Romaric Jodin 
254,257d255
< for src in types:
< for dst in types:
< generate_default_conversion(src, dst, "")
<
260a259,260
> if mode == "_rte":
> continue
310,311c310,311
<   y = select(y, ({DST}{N}){DST_MIN}, {BP}(x < ({SRC}{N}){DST_MIN}){BS});
<   y = select(y, ({DST}{N}){DST_MAX}, {BP}(x > ({SRC}{N}){DST_MAX}){BS});
---
>   y = select(y, ({DST}{N}){DST_MIN}, {BP}(x <= ({SRC}{N}){DST_MIN}){BS});
>   y = select(y, ({DST}{N}){DST_MAX}, {BP}(x >= ({SRC}{N}){DST_MAX}){BS});
435c435
< print("  {SRC}{N} y = convert_{SRC}{N}(r);".format(SRC=src, N=size))
---
> print("  {SRC}{N} y = convert_{SRC}{N}_sat(r);".format(SRC=src, 
> N=size))
450a451,457
> print("  {BOOL}{N} c = convert_{BOOL}{N}(abs_y > 
> abs_x);".format(BOOL=bool_type[dst], N=size))
> if sizeof_type[src] >= 4 and src in int_types:
> print(
> "  c = c || 

[libclc] libclc: generic: add half implementation for erf/erfc (PR #66901)

2023-09-20 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@kpet @alan-baker could you review this PR please?

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


[libclc] libclc: generic: add half implementation for erf/erfc (PR #66901)

2023-09-20 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr created 
https://github.com/llvm/llvm-project/pull/66901

libclc does not have a half implementation for erf/erfc
Add one based on the float implementation by extending the input and truncating 
the output.

>From 64826c23cfaef764c9a60600a2c0e96244c95cf6 Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Mon, 21 Aug 2023 10:55:44 +0200
Subject: [PATCH] libclc: generic: add half implementation for erf/erfc

libclc does not have a half implementation for erf/erfc
Add one based on the float implementation by extending the input and
truncating the output.
---
 libclc/generic/lib/math/erf.cl  | 12 
 libclc/generic/lib/math/erfc.cl | 12 
 2 files changed, 24 insertions(+)

diff --git a/libclc/generic/lib/math/erf.cl b/libclc/generic/lib/math/erf.cl
index 3dc82d926e863a6..2c395ce1a75267b 100644
--- a/libclc/generic/lib/math/erf.cl
+++ b/libclc/generic/lib/math/erf.cl
@@ -399,4 +399,16 @@ _CLC_OVERLOAD _CLC_DEF double erf(double y) {
 
 _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, erf, double);
 
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF half erf(half h) {
+return (half)erf((float)h);
+}
+
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, erf, half);
+
+#endif
+
 #endif
diff --git a/libclc/generic/lib/math/erfc.cl b/libclc/generic/lib/math/erfc.cl
index c322f8691b3828a..cd35ea8def7b6a8 100644
--- a/libclc/generic/lib/math/erfc.cl
+++ b/libclc/generic/lib/math/erfc.cl
@@ -410,4 +410,16 @@ _CLC_OVERLOAD _CLC_DEF double erfc(double x) {
 
 _CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, double, erfc, double);
 
+#ifdef cl_khr_fp16
+
+#pragma OPENCL EXTENSION cl_khr_fp16 : enable
+
+_CLC_OVERLOAD _CLC_DEF half erfc(half h) {
+return (half)erfc((float)h);
+}
+
+_CLC_UNARY_VECTORIZE(_CLC_OVERLOAD _CLC_DEF, half, erfc, half);
+
+#endif
+
 #endif

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-20 Thread Romaric Jodin via cfe-commits

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-18 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66651

>From b6df142239256e979a70896f324f9ed3547c640c Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Mon, 18 Sep 2023 09:34:56 +0200
Subject: [PATCH 1/2] Revert "clang/OpenCL: Add inline implementations of sqrt
 in builtin header"

This reverts commit 15e0fe0b6122e32657b98daf74a1fce028d2e5bf.
---
 clang/lib/Headers/opencl-c-base.h   |  58 ---
 clang/lib/Headers/opencl-c.h|  26 +++
 clang/lib/Sema/OpenCLBuiltins.td|   5 +-
 clang/test/CodeGenOpenCL/sqrt-fpmath.cl | 201 
 4 files changed, 27 insertions(+), 263 deletions(-)
 delete mode 100644 clang/test/CodeGenOpenCL/sqrt-fpmath.cl

diff --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index d56e5ceae652ad5..2494f6213fc5695 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -819,64 +819,6 @@ int printf(__constant const char* st, ...) 
__attribute__((format(printf, 1, 2)))
 
 #endif // cl_intel_device_side_avc_motion_estimation
 
-/**
- * Compute square root.
- *
- * Provide inline implementations using the builtin so that we get appropriate
- * !fpmath based on -cl-fp32-correctly-rounded-divide-sqrt, attached to
- * llvm.sqrt. The implementation should still provide an external definition.
- */
-#define __ovld __attribute__((overloadable))
-#define __cnfn __attribute__((const))
-
-inline float __ovld __cnfn sqrt(float __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float2 __ovld __cnfn sqrt(float2 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float3 __ovld __cnfn sqrt(float3 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float4 __ovld __cnfn sqrt(float4 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float8 __ovld __cnfn sqrt(float8 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float16 __ovld __cnfn sqrt(float16 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-// We only really want to define the float variants here. However
-// -fdeclare-opencl-builtins will not work if some overloads are already
- // provided in the base header, so provide all overloads here.
-
-#ifdef cl_khr_fp64
-double __ovld __cnfn sqrt(double);
-double2 __ovld __cnfn sqrt(double2);
-double3 __ovld __cnfn sqrt(double3);
-double4 __ovld __cnfn sqrt(double4);
-double8 __ovld __cnfn sqrt(double8);
-double16 __ovld __cnfn sqrt(double16);
-#endif //cl_khr_fp64
-#ifdef cl_khr_fp16
-half __ovld __cnfn sqrt(half);
-half2 __ovld __cnfn sqrt(half2);
-half3 __ovld __cnfn sqrt(half3);
-half4 __ovld __cnfn sqrt(half4);
-half8 __ovld __cnfn sqrt(half8);
-half16 __ovld __cnfn sqrt(half16);
-#endif //cl_khr_fp16
-
-#undef __cnfn
-#undef __ovld
-
 // Disable any extensions we may have enabled previously.
 #pragma OPENCL EXTENSION all : disable
 
diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 1efbbf8f8ee6a01..288bb18bc654ebc 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -8496,6 +8496,32 @@ half8 __ovld __cnfn sinpi(half8);
 half16 __ovld __cnfn sinpi(half16);
 #endif //cl_khr_fp16
 
+/**
+ * Compute square root.
+ */
+float __ovld __cnfn sqrt(float);
+float2 __ovld __cnfn sqrt(float2);
+float3 __ovld __cnfn sqrt(float3);
+float4 __ovld __cnfn sqrt(float4);
+float8 __ovld __cnfn sqrt(float8);
+float16 __ovld __cnfn sqrt(float16);
+#ifdef cl_khr_fp64
+double __ovld __cnfn sqrt(double);
+double2 __ovld __cnfn sqrt(double2);
+double3 __ovld __cnfn sqrt(double3);
+double4 __ovld __cnfn sqrt(double4);
+double8 __ovld __cnfn sqrt(double8);
+double16 __ovld __cnfn sqrt(double16);
+#endif //cl_khr_fp64
+#ifdef cl_khr_fp16
+half __ovld __cnfn sqrt(half);
+half2 __ovld __cnfn sqrt(half2);
+half3 __ovld __cnfn sqrt(half3);
+half4 __ovld __cnfn sqrt(half4);
+half8 __ovld __cnfn sqrt(half8);
+half16 __ovld __cnfn sqrt(half16);
+#endif //cl_khr_fp16
+
 /**
  * Compute tangent.
  */
diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index 9db450281912d2f..0cceba090bd8f26 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -563,15 +563,12 @@ foreach name = ["acos", "acosh", "acospi",
 "log", "log2", "log10", "log1p", "logb",
 "rint", "round", "rsqrt",
 "sin", "sinh", "sinpi",
+"sqrt",
 "tan", "tanh", "tanpi",
 "tgamma", "trunc",
 "lgamma"] in {
 def : Builtin;
 }
-
-// sqrt is handled in opencl-c-base.h to handle
-// -cl-fp32-correctly-rounded-divide-sqrt.
-
 foreach name = ["nan"] in {
   def : Builtin;
   def : Builtin;
diff --git a/clang/test/CodeGenOpenCL/sqrt-fpmath.cl 
b/clang/test/CodeGenOpenCL/sqrt-fpmath.cl
deleted file mode 100644
index df30085cba2e7d5..000
--- a/clang/test/CodeGenOpenCL/sqrt-fpmath.cl
+++ /dev/null
@@ -1,201 +0,0 @@
-// Test that float variants of 

[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-18 Thread Romaric Jodin via cfe-commits


@@ -5612,6 +5612,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
,
   BundleList);
 EmitBlock(Cont);
   }
+  if (CI->getCalledFunction() && CI->getCalledFunction()->hasName() &&
+  CI->getCalledFunction()->getName().contains("Z4sqrt")) {

rjodinchr wrote:

the language is checked by `SetSqrtFPAccuracy`. I'll have a look at a better 
match for the name

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-18 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr updated 
https://github.com/llvm/llvm-project/pull/66651

>From b6df142239256e979a70896f324f9ed3547c640c Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Mon, 18 Sep 2023 09:34:56 +0200
Subject: [PATCH 1/2] Revert "clang/OpenCL: Add inline implementations of sqrt
 in builtin header"

This reverts commit 15e0fe0b6122e32657b98daf74a1fce028d2e5bf.
---
 clang/lib/Headers/opencl-c-base.h   |  58 ---
 clang/lib/Headers/opencl-c.h|  26 +++
 clang/lib/Sema/OpenCLBuiltins.td|   5 +-
 clang/test/CodeGenOpenCL/sqrt-fpmath.cl | 201 
 4 files changed, 27 insertions(+), 263 deletions(-)
 delete mode 100644 clang/test/CodeGenOpenCL/sqrt-fpmath.cl

diff --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index d56e5ceae652ad5..2494f6213fc5695 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -819,64 +819,6 @@ int printf(__constant const char* st, ...) 
__attribute__((format(printf, 1, 2)))
 
 #endif // cl_intel_device_side_avc_motion_estimation
 
-/**
- * Compute square root.
- *
- * Provide inline implementations using the builtin so that we get appropriate
- * !fpmath based on -cl-fp32-correctly-rounded-divide-sqrt, attached to
- * llvm.sqrt. The implementation should still provide an external definition.
- */
-#define __ovld __attribute__((overloadable))
-#define __cnfn __attribute__((const))
-
-inline float __ovld __cnfn sqrt(float __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float2 __ovld __cnfn sqrt(float2 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float3 __ovld __cnfn sqrt(float3 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float4 __ovld __cnfn sqrt(float4 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float8 __ovld __cnfn sqrt(float8 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float16 __ovld __cnfn sqrt(float16 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-// We only really want to define the float variants here. However
-// -fdeclare-opencl-builtins will not work if some overloads are already
- // provided in the base header, so provide all overloads here.
-
-#ifdef cl_khr_fp64
-double __ovld __cnfn sqrt(double);
-double2 __ovld __cnfn sqrt(double2);
-double3 __ovld __cnfn sqrt(double3);
-double4 __ovld __cnfn sqrt(double4);
-double8 __ovld __cnfn sqrt(double8);
-double16 __ovld __cnfn sqrt(double16);
-#endif //cl_khr_fp64
-#ifdef cl_khr_fp16
-half __ovld __cnfn sqrt(half);
-half2 __ovld __cnfn sqrt(half2);
-half3 __ovld __cnfn sqrt(half3);
-half4 __ovld __cnfn sqrt(half4);
-half8 __ovld __cnfn sqrt(half8);
-half16 __ovld __cnfn sqrt(half16);
-#endif //cl_khr_fp16
-
-#undef __cnfn
-#undef __ovld
-
 // Disable any extensions we may have enabled previously.
 #pragma OPENCL EXTENSION all : disable
 
diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 1efbbf8f8ee6a01..288bb18bc654ebc 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -8496,6 +8496,32 @@ half8 __ovld __cnfn sinpi(half8);
 half16 __ovld __cnfn sinpi(half16);
 #endif //cl_khr_fp16
 
+/**
+ * Compute square root.
+ */
+float __ovld __cnfn sqrt(float);
+float2 __ovld __cnfn sqrt(float2);
+float3 __ovld __cnfn sqrt(float3);
+float4 __ovld __cnfn sqrt(float4);
+float8 __ovld __cnfn sqrt(float8);
+float16 __ovld __cnfn sqrt(float16);
+#ifdef cl_khr_fp64
+double __ovld __cnfn sqrt(double);
+double2 __ovld __cnfn sqrt(double2);
+double3 __ovld __cnfn sqrt(double3);
+double4 __ovld __cnfn sqrt(double4);
+double8 __ovld __cnfn sqrt(double8);
+double16 __ovld __cnfn sqrt(double16);
+#endif //cl_khr_fp64
+#ifdef cl_khr_fp16
+half __ovld __cnfn sqrt(half);
+half2 __ovld __cnfn sqrt(half2);
+half3 __ovld __cnfn sqrt(half3);
+half4 __ovld __cnfn sqrt(half4);
+half8 __ovld __cnfn sqrt(half8);
+half16 __ovld __cnfn sqrt(half16);
+#endif //cl_khr_fp16
+
 /**
  * Compute tangent.
  */
diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index 9db450281912d2f..0cceba090bd8f26 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -563,15 +563,12 @@ foreach name = ["acos", "acosh", "acospi",
 "log", "log2", "log10", "log1p", "logb",
 "rint", "round", "rsqrt",
 "sin", "sinh", "sinpi",
+"sqrt",
 "tan", "tanh", "tanpi",
 "tgamma", "trunc",
 "lgamma"] in {
 def : Builtin;
 }
-
-// sqrt is handled in opencl-c-base.h to handle
-// -cl-fp32-correctly-rounded-divide-sqrt.
-
 foreach name = ["nan"] in {
   def : Builtin;
   def : Builtin;
diff --git a/clang/test/CodeGenOpenCL/sqrt-fpmath.cl 
b/clang/test/CodeGenOpenCL/sqrt-fpmath.cl
deleted file mode 100644
index df30085cba2e7d5..000
--- a/clang/test/CodeGenOpenCL/sqrt-fpmath.cl
+++ /dev/null
@@ -1,201 +0,0 @@
-// Test that float variants of 

[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-18 Thread Romaric Jodin via cfe-commits

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-18 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@alan-baker @arsenm @AnastasiaStulova 
Could you review this PR please?
Thank you

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-18 Thread Romaric Jodin via cfe-commits

https://github.com/rjodinchr created 
https://github.com/llvm/llvm-project/pull/66651

This is reverting the previous implementation to avoid adding inline function 
in opencl headers.
This was breaking clspv flow google/clspv#1231, while 
https://reviews.llvm.org/D156743 mentioned that just decoring the call node 
with `!pfmath` was enough.
This PR is implementing this idea.
The test has been updated with this implementation.


>From b6df142239256e979a70896f324f9ed3547c640c Mon Sep 17 00:00:00 2001
From: Romaric Jodin 
Date: Mon, 18 Sep 2023 09:34:56 +0200
Subject: [PATCH 1/2] Revert "clang/OpenCL: Add inline implementations of sqrt
 in builtin header"

This reverts commit 15e0fe0b6122e32657b98daf74a1fce028d2e5bf.
---
 clang/lib/Headers/opencl-c-base.h   |  58 ---
 clang/lib/Headers/opencl-c.h|  26 +++
 clang/lib/Sema/OpenCLBuiltins.td|   5 +-
 clang/test/CodeGenOpenCL/sqrt-fpmath.cl | 201 
 4 files changed, 27 insertions(+), 263 deletions(-)
 delete mode 100644 clang/test/CodeGenOpenCL/sqrt-fpmath.cl

diff --git a/clang/lib/Headers/opencl-c-base.h 
b/clang/lib/Headers/opencl-c-base.h
index d56e5ceae652ad5..2494f6213fc5695 100644
--- a/clang/lib/Headers/opencl-c-base.h
+++ b/clang/lib/Headers/opencl-c-base.h
@@ -819,64 +819,6 @@ int printf(__constant const char* st, ...) 
__attribute__((format(printf, 1, 2)))
 
 #endif // cl_intel_device_side_avc_motion_estimation
 
-/**
- * Compute square root.
- *
- * Provide inline implementations using the builtin so that we get appropriate
- * !fpmath based on -cl-fp32-correctly-rounded-divide-sqrt, attached to
- * llvm.sqrt. The implementation should still provide an external definition.
- */
-#define __ovld __attribute__((overloadable))
-#define __cnfn __attribute__((const))
-
-inline float __ovld __cnfn sqrt(float __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float2 __ovld __cnfn sqrt(float2 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float3 __ovld __cnfn sqrt(float3 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float4 __ovld __cnfn sqrt(float4 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float8 __ovld __cnfn sqrt(float8 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-inline float16 __ovld __cnfn sqrt(float16 __x) {
-  return __builtin_elementwise_sqrt(__x);
-}
-
-// We only really want to define the float variants here. However
-// -fdeclare-opencl-builtins will not work if some overloads are already
- // provided in the base header, so provide all overloads here.
-
-#ifdef cl_khr_fp64
-double __ovld __cnfn sqrt(double);
-double2 __ovld __cnfn sqrt(double2);
-double3 __ovld __cnfn sqrt(double3);
-double4 __ovld __cnfn sqrt(double4);
-double8 __ovld __cnfn sqrt(double8);
-double16 __ovld __cnfn sqrt(double16);
-#endif //cl_khr_fp64
-#ifdef cl_khr_fp16
-half __ovld __cnfn sqrt(half);
-half2 __ovld __cnfn sqrt(half2);
-half3 __ovld __cnfn sqrt(half3);
-half4 __ovld __cnfn sqrt(half4);
-half8 __ovld __cnfn sqrt(half8);
-half16 __ovld __cnfn sqrt(half16);
-#endif //cl_khr_fp16
-
-#undef __cnfn
-#undef __ovld
-
 // Disable any extensions we may have enabled previously.
 #pragma OPENCL EXTENSION all : disable
 
diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
index 1efbbf8f8ee6a01..288bb18bc654ebc 100644
--- a/clang/lib/Headers/opencl-c.h
+++ b/clang/lib/Headers/opencl-c.h
@@ -8496,6 +8496,32 @@ half8 __ovld __cnfn sinpi(half8);
 half16 __ovld __cnfn sinpi(half16);
 #endif //cl_khr_fp16
 
+/**
+ * Compute square root.
+ */
+float __ovld __cnfn sqrt(float);
+float2 __ovld __cnfn sqrt(float2);
+float3 __ovld __cnfn sqrt(float3);
+float4 __ovld __cnfn sqrt(float4);
+float8 __ovld __cnfn sqrt(float8);
+float16 __ovld __cnfn sqrt(float16);
+#ifdef cl_khr_fp64
+double __ovld __cnfn sqrt(double);
+double2 __ovld __cnfn sqrt(double2);
+double3 __ovld __cnfn sqrt(double3);
+double4 __ovld __cnfn sqrt(double4);
+double8 __ovld __cnfn sqrt(double8);
+double16 __ovld __cnfn sqrt(double16);
+#endif //cl_khr_fp64
+#ifdef cl_khr_fp16
+half __ovld __cnfn sqrt(half);
+half2 __ovld __cnfn sqrt(half2);
+half3 __ovld __cnfn sqrt(half3);
+half4 __ovld __cnfn sqrt(half4);
+half8 __ovld __cnfn sqrt(half8);
+half16 __ovld __cnfn sqrt(half16);
+#endif //cl_khr_fp16
+
 /**
  * Compute tangent.
  */
diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
index 9db450281912d2f..0cceba090bd8f26 100644
--- a/clang/lib/Sema/OpenCLBuiltins.td
+++ b/clang/lib/Sema/OpenCLBuiltins.td
@@ -563,15 +563,12 @@ foreach name = ["acos", "acosh", "acospi",
 "log", "log2", "log10", "log1p", "logb",
 "rint", "round", "rsqrt",
 "sin", "sinh", "sinpi",
+"sqrt",
 "tan", "tanh", "tanpi",
 "tgamma", "trunc",
 "lgamma"] in {
 def : Builtin;
 }
-
-// sqrt is handled in opencl-c-base.h to handle
-//