Skip to content

Commit 90f1143

Browse files
authored
[LLVM 17] Bring missing LLVM 16 patches to LLVM 17 (intel#655)
This PR adds missing patches from https://github.com/intel/opencl-clang/tree/ocl-open-160/patches/clang
1 parent 7e2ee77 commit 90f1143

4 files changed

Lines changed: 238 additions & 0 deletions
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
From 1ca45b5f5725a447ded14c0096df39f2751c4e9a Mon Sep 17 00:00:00 2001
2+
From: Haonan Yang <haonan.yang@intel.com>
3+
Date: Fri, 25 Feb 2022 10:36:57 +0800
4+
Subject: [PATCH] Remove __IMAGE_SUPPORT__ macro for SPIR
5+
6+
Signed-off-by: Haonan Yang <haonan.yang@intel.com>
7+
8+
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
9+
index 208c6a8db159..33c8409eaf12 100644
10+
--- a/clang/lib/Frontend/InitPreprocessor.cpp
11+
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
12+
@@ -1288,9 +1288,6 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
13+
// OpenCL definitions.
14+
if (LangOpts.OpenCL) {
15+
InitializeOpenCLFeatureTestMacros(TI, LangOpts, Builder);
16+
-
17+
- if (TI.getTriple().isSPIR() || TI.getTriple().isSPIRV())
18+
- Builder.defineMacro("__IMAGE_SUPPORT__");
19+
}
20+
21+
if (TI.hasInt128Type() && LangOpts.CPlusPlus && LangOpts.GNUMode) {
22+
diff --git a/clang/test/Preprocessor/predefined-macros.c b/clang/test/Preprocessor/predefined-macros.c
23+
index d77b699674af..4dd02c3cfde4 100644
24+
--- a/clang/test/Preprocessor/predefined-macros.c
25+
+++ b/clang/test/Preprocessor/predefined-macros.c
26+
@@ -210,28 +210,24 @@
27+
28+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir-unknown-unknown \
29+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR
30+
-// CHECK-SPIR-DAG: #define __IMAGE_SUPPORT__ 1
31+
// CHECK-SPIR-DAG: #define __SPIR__ 1
32+
// CHECK-SPIR-DAG: #define __SPIR32__ 1
33+
// CHECK-SPIR-NOT: #define __SPIR64__ 1
34+
35+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spir64-unknown-unknown \
36+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIR64
37+
-// CHECK-SPIR64-DAG: #define __IMAGE_SUPPORT__ 1
38+
// CHECK-SPIR64-DAG: #define __SPIR__ 1
39+
// CHECK-SPIR64-DAG: #define __SPIR64__ 1
40+
// CHECK-SPIR64-NOT: #define __SPIR32__ 1
41+
42+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv32-unknown-unknown \
43+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV32
44+
-// CHECK-SPIRV32-DAG: #define __IMAGE_SUPPORT__ 1
45+
// CHECK-SPIRV32-DAG: #define __SPIRV__ 1
46+
// CHECK-SPIRV32-DAG: #define __SPIRV32__ 1
47+
// CHECK-SPIRV32-NOT: #define __SPIRV64__ 1
48+
49+
// RUN: %clang_cc1 %s -E -dM -o - -x cl -triple spirv64-unknown-unknown \
50+
// RUN: | FileCheck -match-full-lines %s --check-prefix=CHECK-SPIRV64
51+
-// CHECK-SPIRV64-DAG: #define __IMAGE_SUPPORT__ 1
52+
// CHECK-SPIRV64-DAG: #define __SPIRV__ 1
53+
// CHECK-SPIRV64-DAG: #define __SPIRV64__ 1
54+
// CHECK-SPIRV64-NOT: #define __SPIRV32__ 1
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
From a60b8f468119065f8a6cb4a16598263cb00de0b5 Mon Sep 17 00:00:00 2001
2+
From: Sven van Haastregt <sven.vanhaastregt@arm.com>
3+
Date: Mon, 16 Jan 2023 11:32:12 +0000
4+
Subject: [PATCH] [OpenCL] Allow undefining header-only features
5+
6+
`opencl-c-base.h` always defines 5 particular feature macros for
7+
SPIR-V, making it impossible to disable those features.
8+
9+
To allow disabling any of those features, let the header recognize
10+
`__undef_<feature>` macros. The user can then pass the
11+
`-D__undef_<feature>` flag on the command line to disable a specific
12+
feature. The __undef macro could potentially also be set from
13+
`-cl-ext=-feature`, but for now only change the header and only
14+
provide __undef macros for the 5 features that are always enabled in
15+
`opencl-c-base.h`.
16+
17+
Differential Revision: https://reviews.llvm.org/D141297
18+
19+
diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h
20+
index fad2f9c0272b..84a2d834aa3c 100644
21+
--- a/clang/lib/Headers/opencl-c-base.h
22+
+++ b/clang/lib/Headers/opencl-c-base.h
23+
@@ -93,6 +93,24 @@
24+
#undef __opencl_c_read_write_images
25+
#endif
26+
27+
+// Undefine any feature macros that have been explicitly disabled using
28+
+// an __undef_<feature> macro.
29+
+#ifdef __undef___opencl_c_work_group_collective_functions
30+
+#undef __opencl_c_work_group_collective_functions
31+
+#endif
32+
+#ifdef __undef___opencl_c_atomic_order_seq_cst
33+
+#undef __opencl_c_atomic_order_seq_cst
34+
+#endif
35+
+#ifdef __undef___opencl_c_atomic_scope_device
36+
+#undef __opencl_c_atomic_scope_device
37+
+#endif
38+
+#ifdef __undef___opencl_c_atomic_scope_all_devices
39+
+#undef __opencl_c_atomic_scope_all_devices
40+
+#endif
41+
+#ifdef __undef___opencl_c_read_write_images
42+
+#undef __opencl_c_read_write_images
43+
+#endif
44+
+
45+
#endif // (__OPENCL_CPP_VERSION__ == 202100 || __OPENCL_C_VERSION__ == 300)
46+
47+
#if !defined(__opencl_c_generic_address_space)
48+
diff --git a/clang/test/SemaOpenCL/features.cl b/clang/test/SemaOpenCL/features.cl
49+
index 3f59b4ea3b5a..7006fb5d181a 100644
50+
--- a/clang/test/SemaOpenCL/features.cl
51+
+++ b/clang/test/SemaOpenCL/features.cl
52+
@@ -35,6 +35,15 @@
53+
// RUN: -D__undef___opencl_c_read_write_images=1 \
54+
// RUN: | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
55+
56+
+// For OpenCL C 3.0, header-only features can be disabled using macros.
57+
+// RUN: %clang_cc1 -triple spir-unknown-unknown %s -E -dM -o - -x cl -cl-std=CL3.0 -fdeclare-opencl-builtins -finclude-default-header \
58+
+// RUN: -D__undef___opencl_c_work_group_collective_functions=1 \
59+
+// RUN: -D__undef___opencl_c_atomic_order_seq_cst=1 \
60+
+// RUN: -D__undef___opencl_c_atomic_scope_device=1 \
61+
+// RUN: -D__undef___opencl_c_atomic_scope_all_devices=1 \
62+
+// RUN: -D__undef___opencl_c_read_write_images=1 \
63+
+// RUN: | FileCheck %s --check-prefix=NO-HEADERONLY-FEATURES
64+
+
65+
// Note that __opencl_c_int64 is always defined assuming
66+
// always compiling for FULL OpenCL profile
67+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
From 62267fec4a0d74472bc64695597f2477cc8c11df Mon Sep 17 00:00:00 2001
2+
From: FirstName LastName <your@email.com>
3+
Date: Wed, 5 Apr 2023 17:02:38 +0200
4+
Subject: [PATCH] Enable use of GNU C extension - const statement expression as array size
5+
6+
This patch partially reverts the commit:
7+
llvm/llvm-project@6781fee
8+
9+
For backward compatibility, we still need to support the
10+
expressions like:
11+
```
12+
const int size = ({ false; }) ? 0 : 1;
13+
float array[size];
14+
```
15+
https://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html
16+
17+
---
18+
clang/lib/Sema/SemaType.cpp | 3 ++-
19+
1 file changed, 2 insertions(+), 1 deletion(-)
20+
21+
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
22+
index ab47e9f03..8cb26be44 100644
23+
--- a/clang/lib/Sema/SemaType.cpp
24+
+++ b/clang/lib/Sema/SemaType.cpp
25+
@@ -2330,7 +2330,8 @@ static ExprResult checkArraySize(Sema &S, Expr *&ArraySize,
26+
} Diagnoser(VLADiag, VLAIsError);
27+
28+
ExprResult R =
29+
- S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser);
30+
+ S.VerifyIntegerConstantExpression(ArraySize, &SizeVal, Diagnoser,
31+
+ S.LangOpts.OpenCL ? Sema::AllowFold : Sema::NoFold);
32+
if (Diagnoser.IsVLA)
33+
return ExprResult();
34+
return R;
35+
--
36+
2.34.1
37+
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
From da6a0b7af29a222b2e16a10155b49d4fafe967f3 Mon Sep 17 00:00:00 2001
2+
From: Sven van Haastregt <sven.vanhaastregt@arm.com>
3+
Date: Mon, 20 May 2024 09:37:53 +0200
4+
Subject: [PATCH] [OpenCL] Add cl_khr_kernel_clock builtins (#91950)
5+
6+
---
7+
clang/lib/Headers/opencl-c-base.h | 4 ++++
8+
clang/lib/Headers/opencl-c.h | 15 +++++++++++++++
9+
clang/lib/Sema/OpenCLBuiltins.td | 14 ++++++++++++++
10+
3 files changed, 33 insertions(+)
11+
12+
diff --git a/clang/lib/Headers/opencl-c-base.h b/clang/lib/Headers/opencl-c-base.h
13+
index 2494f6213fc5..786678b9d8a7 100644
14+
--- a/clang/lib/Headers/opencl-c-base.h
15+
+++ b/clang/lib/Headers/opencl-c-base.h
16+
@@ -46,6 +46,10 @@
17+
#define __opencl_c_ext_fp32_global_atomic_min_max 1
18+
#define __opencl_c_ext_fp32_local_atomic_min_max 1
19+
#define __opencl_c_ext_image_raw10_raw12 1
20+
+#define cl_khr_kernel_clock 1
21+
+#define __opencl_c_kernel_clock_scope_device 1
22+
+#define __opencl_c_kernel_clock_scope_work_group 1
23+
+#define __opencl_c_kernel_clock_scope_sub_group 1
24+
25+
#endif // defined(__SPIR__) || defined(__SPIRV__)
26+
#endif // (defined(__OPENCL_CPP_VERSION__) || __OPENCL_C_VERSION__ >= 200)
27+
diff --git a/clang/lib/Headers/opencl-c.h b/clang/lib/Headers/opencl-c.h
28+
index 288bb18bc654..20719b74b6b8 100644
29+
--- a/clang/lib/Headers/opencl-c.h
30+
+++ b/clang/lib/Headers/opencl-c.h
31+
@@ -17314,6 +17314,21 @@ half __ovld __conv sub_group_clustered_rotate(half, int, uint);
32+
#endif // cl_khr_fp16
33+
#endif // cl_khr_subgroup_rotate
34+
35+
+#if defined(cl_khr_kernel_clock)
36+
+#if defined(__opencl_c_kernel_clock_scope_device)
37+
+ulong __ovld clock_read_device();
38+
+uint2 __ovld clock_read_hilo_device();
39+
+#endif // __opencl_c_kernel_clock_scope_device
40+
+#if defined(__opencl_c_kernel_clock_scope_work_group)
41+
+ulong __ovld clock_read_work_group();
42+
+uint2 __ovld clock_read_hilo_work_group();
43+
+#endif // __opencl_c_kernel_clock_scope_work_group
44+
+#if defined(__opencl_c_kernel_clock_scope_sub_group)
45+
+ulong __ovld clock_read_sub_group();
46+
+uint2 __ovld clock_read_hilo_sub_group();
47+
+#endif // __opencl_c_kernel_clock_scope_sub_group
48+
+#endif // cl_khr_kernel_clock
49+
+
50+
#if defined(cl_intel_subgroups)
51+
// Intel-Specific Sub Group Functions
52+
float __ovld __conv intel_sub_group_shuffle( float , uint );
53+
diff --git a/clang/lib/Sema/OpenCLBuiltins.td b/clang/lib/Sema/OpenCLBuiltins.td
54+
index a7bdfe20b982..4da61429fcce 100644
55+
--- a/clang/lib/Sema/OpenCLBuiltins.td
56+
+++ b/clang/lib/Sema/OpenCLBuiltins.td
57+
@@ -1852,6 +1852,20 @@ let Extension = FunctionExtension<"cl_khr_subgroup_rotate"> in {
58+
def : Builtin<"sub_group_clustered_rotate", [AGenType1, AGenType1, Int, UInt], Attr.Convergent>;
59+
}
60+
61+
+// cl_khr_kernel_clock
62+
+let Extension = FunctionExtension<"cl_khr_kernel_clock __opencl_c_kernel_clock_scope_device"> in {
63+
+ def : Builtin<"clock_read_device", [ULong]>;
64+
+ def : Builtin<"clock_read_hilo_device", [VectorType<UInt, 2>]>;
65+
+}
66+
+let Extension = FunctionExtension<"cl_khr_kernel_clock __opencl_c_kernel_clock_scope_work_group"> in {
67+
+ def : Builtin<"clock_read_work_group", [ULong]>;
68+
+ def : Builtin<"clock_read_hilo_work_group", [VectorType<UInt, 2>]>;
69+
+}
70+
+let Extension = FunctionExtension<"cl_khr_kernel_clock __opencl_c_kernel_clock_scope_sub_group"> in {
71+
+ def : Builtin<"clock_read_sub_group", [ULong]>;
72+
+ def : Builtin<"clock_read_hilo_sub_group", [VectorType<UInt, 2>]>;
73+
+}
74+
+
75+
//--------------------------------------------------------------------
76+
// Arm extensions.
77+
let Extension = ArmIntegerDotProductInt8 in {
78+
--
79+
2.39.1
80+

0 commit comments

Comments
 (0)