[clang] d61ded1 - [OpenCL] Make -cl-ext a driver option.
Anastasia Stulova via cfe-commits
cfe-commits at lists.llvm.org
Tue May 24 03:35:52 PDT 2022
Author: Anastasia Stulova
Date: 2022-05-24T11:34:19+01:00
New Revision: d61ded1034bb9563c43d048ba0be4eff662e6144
URL: https://github.com/llvm/llvm-project/commit/d61ded1034bb9563c43d048ba0be4eff662e6144
DIFF: https://github.com/llvm/llvm-project/commit/d61ded1034bb9563c43d048ba0be4eff662e6144.diff
LOG: [OpenCL] Make -cl-ext a driver option.
For generic targets such as SPIR-V clang sets all OpenCL
extensions/features as supported by default. However
concrete targets are unlikely to support all extensions
features, which creates a problem when such generic SPIR-V
binary is compiled for a specific target later on.
To allow compile time diagnostics for unsupported features
this flag is now being exposed in the clang driver.
Differential Revision: https://reviews.llvm.org/D125243
Added:
Modified:
clang/docs/OpenCLSupport.rst
clang/docs/UsersManual.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/opencl.cl
Removed:
################################################################################
diff --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst
index 0a4f81cf5ca11..6b05b5df1d0b4 100644
--- a/clang/docs/OpenCLSupport.rst
+++ b/clang/docs/OpenCLSupport.rst
@@ -68,31 +68,6 @@ All the options in this section are frontend-only and therefore if used
with regular clang driver they require frontend forwarding, e.g. ``-cc1``
or ``-Xclang``.
-.. _opencl_cl_ext:
-
-.. option:: -cl-ext
-
-Disables support of OpenCL extensions. All OpenCL targets provide a list
-of extensions that they support. Clang allows to amend this using the ``-cl-ext``
-flag with a comma-separated list of extensions prefixed with ``'+'`` or ``'-'``.
-The syntax: ``-cl-ext=<(['-'|'+']<extension>[,])+>``, where extensions
-can be either one of `the OpenCL published extensions
-<https://www.khronos.org/registry/OpenCL>`_
-or any vendor extension. Alternatively, ``'all'`` can be used to enable
-or disable all known extensions.
-
-Example disabling double support for the 64-bit SPIR target:
-
- .. code-block:: console
-
- $ clang -cc1 -triple spir64-unknown-unknown -cl-ext=-cl_khr_fp64 test.cl
-
-Enabling all extensions except double support in R600 AMD GPU can be done using:
-
- .. code-block:: console
-
- $ clang -cc1 -triple r600-unknown-unknown -cl-ext=-all,+cl_khr_fp16 test.cl
-
.. _opencl_finclude_default_header:
.. option:: -finclude-default-header
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 8eb676650ec61..aaba6dffd2e5b 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -3120,6 +3120,34 @@ compile.
More information about the standard types and functions is provided in :ref:`the
section on the OpenCL Header <opencl_header>`.
+.. _opencl_cl_ext:
+
+.. option:: -cl-ext
+
+Enables/Disables support of OpenCL extensions and optional features. All OpenCL
+targets set a list of extensions that they support. Clang allows to amend this using
+the ``-cl-ext`` flag with a comma-separated list of extensions prefixed with
+``'+'`` or ``'-'``. The syntax: ``-cl-ext=<(['-'|'+']<extension>[,])+>``, where
+extensions can be either one of `the OpenCL published extensions
+<https://www.khronos.org/registry/OpenCL>`_
+or any vendor extension. Alternatively, ``'all'`` can be used to enable
+or disable all known extensions.
+
+Example disabling double support for the 64-bit SPIR-V target:
+
+ .. code-block:: console
+
+ $ clang -target spirv64 -cl-ext=-cl_khr_fp64 test.cl
+
+Enabling all extensions except double support in R600 AMD GPU can be done using:
+
+ .. code-block:: console
+
+ $ clang -target r600 -cl-ext=-all,+cl_khr_fp16 test.cl
+
+Note that some generic targets e.g. SPIR/SPIR-V enable all extensions/features in
+clang by default.
+
OpenCL Targets
--------------
@@ -3167,9 +3195,8 @@ Generic Targets
$ clang -target spir test.cl -emit-llvm -c
$ clang -target spir64 test.cl -emit-llvm -c
- All known OpenCL extensions are supported in the SPIR targets. Clang will
- generate SPIR v1.2 compatible IR for OpenCL versions up to 2.0 and SPIR v2.0
- for OpenCL v2.0 or C++ for OpenCL.
+ Clang will generate SPIR v1.2 compatible IR for OpenCL versions up to 2.0 and
+ SPIR v2.0 for OpenCL v2.0 or C++ for OpenCL.
- x86 is used by some implementations that are x86 compatible and currently
remains for backwards compatibility (with older implementations prior to
@@ -3183,6 +3210,12 @@ Generic Targets
address space map can be added using the :ref:`-ffake-address-space-map
<opencl_fake_address_space_map>` flag.
+ All known OpenCL extensions and features are set to supported in the generic targets,
+ however :option:`-cl-ext` flag can be used to toggle individual extensions and
+ features.
+
+
+
.. _opencl_header:
OpenCL Header
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index f19734172793a..9888144b7e944 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -844,6 +844,7 @@ def bundle : Flag<["-"], "bundle">;
def b : JoinedOrSeparate<["-"], "b">, Flags<[LinkerInput, RenderAsInput]>,
HelpText<"Pass -b <arg> to the linker on AIX (only).">, MetaVarName<"<arg>">,
Group<Link_Group>;
+// OpenCL-only Options
def cl_opt_disable : Flag<["-"], "cl-opt-disable">, Group<opencl_Group>, Flags<[CC1Option]>,
HelpText<"OpenCL only. This option disables all optimizations. By default optimizations are enabled.">;
def cl_strict_aliasing : Flag<["-"], "cl-strict-aliasing">, Group<opencl_Group>, Flags<[CC1Option]>,
@@ -883,6 +884,11 @@ def cl_uniform_work_group_size : Flag<["-"], "cl-uniform-work-group-size">, Grou
MarshallingInfoFlag<CodeGenOpts<"UniformWGSize">>;
def cl_no_stdinc : Flag<["-"], "cl-no-stdinc">, Group<opencl_Group>,
HelpText<"OpenCL only. Disables all standard includes containing non-native compiler types and functions.">;
+def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, Group<opencl_Group>, Flags<[CC1Option]>,
+ HelpText<"OpenCL only. Enable or disable OpenCL extensions/optional features. The argument is a comma-separated "
+ "sequence of one or more extension names, each prefixed by '+' or '-'.">,
+ MarshallingInfoStringVector<TargetOpts<"OpenCLExtensionsAsWritten">>;
+
def client__name : JoinedOrSeparate<["-"], "client_name">;
def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, Unsupported]>;
def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">;
@@ -6130,15 +6136,6 @@ def disable_pragma_debug_crash : Flag<["-"], "disable-pragma-debug-crash">,
} // let Flags = [CC1Option, NoDriverOption]
-//===----------------------------------------------------------------------===//
-// OpenCL Options
-//===----------------------------------------------------------------------===//
-
-def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">,
- HelpText<"OpenCL only. Enable or disable OpenCL extensions. The argument is a comma-separated sequence of one or more extension names, each prefixed by '+' or '-'.">,
- Flags<[CC1Option, NoDriverOption]>,
- MarshallingInfoStringVector<TargetOpts<"OpenCLExtensionsAsWritten">>;
-
//===----------------------------------------------------------------------===//
// CUDA Options
//===----------------------------------------------------------------------===//
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index efaedb6b893d6..bc43bceb8ffbb 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3458,6 +3458,9 @@ static void RenderOpenCLOptions(const ArgList &Args, ArgStringList &CmdArgs,
if (Arg *A = Args.getLastArg(options::OPT_cl_std_EQ)) {
std::string CLStdStr = std::string("-cl-std=") + A->getValue();
CmdArgs.push_back(Args.MakeArgString(CLStdStr));
+ } else if (Arg *A = Args.getLastArg(options::OPT_cl_ext_EQ)) {
+ std::string CLExtStr = std::string("-cl-ext=") + A->getValue();
+ CmdArgs.push_back(Args.MakeArgString(CLExtStr));
}
for (const auto &Arg : ForwardedArguments)
diff --git a/clang/test/Driver/opencl.cl b/clang/test/Driver/opencl.cl
index b6a9b8a324486..ba1ace5081503 100644
--- a/clang/test/Driver/opencl.cl
+++ b/clang/test/Driver/opencl.cl
@@ -21,6 +21,7 @@
// RUN: not %clang -cl-std=invalid -DOPENCL %s 2>&1 | FileCheck --check-prefix=CHECK-INVALID %s
// RUN: %clang -S -### -target spir-unknown-unknown %s 2>&1 | FileCheck --check-prefix=CHECK-W-SPIR-COMPAT %s
// RUN: %clang -S -### -target amdgcn-amd-amdhsa-opencl %s 2>&1 | FileCheck --check-prefix=CHECK-NO-W-SPIR-COMPAT %s
+// RUN: %clang -S -### -cl-ext="+test_ext" %s 2>&1 | FileCheck --check-prefix=CHECK-EXT %s
// CHECK-CL: "-cc1" {{.*}} "-cl-std=CL"
// CHECK-CL10: "-cc1" {{.*}} "-cl-std=CL1.0"
@@ -50,4 +51,6 @@
// CHECK-W-SPIR-COMPAT: "-Wspir-compat"
// CHECK-NO-W-SPIR-COMPAT-NOT: "-Wspir-compat"
+// CHECK-EXT: "-cc1" {{.*}} "-cl-ext=+test_ext"
+
kernel void func(void);
More information about the cfe-commits
mailing list