From: Anastasia Stulova Date: Tue, 24 May 2022 10:26:43 +0000 (+0100) Subject: [OpenCL] Make -cl-ext a driver option. X-Git-Tag: upstream/15.0.7~6888 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d61ded1034bb9563c43d048ba0be4eff662e6144;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/clang/docs/OpenCLSupport.rst b/clang/docs/OpenCLSupport.rst index 0a4f81c..6b05b5d 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=<(['-'|'+'][,])+>``, where extensions -can be either one of `the OpenCL published extensions -`_ -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 8eb6766..aaba6df 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_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=<(['-'|'+'][,])+>``, where +extensions can be either one of `the OpenCL published extensions +`_ +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 ` 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 f197341..9888144 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 to the linker on AIX (only).">, MetaVarName<"">, Group; +// OpenCL-only Options def cl_opt_disable : Flag<["-"], "cl-opt-disable">, 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, Flags<[CC1Option]>, @@ -883,6 +884,11 @@ def cl_uniform_work_group_size : Flag<["-"], "cl-uniform-work-group-size">, Grou MarshallingInfoFlag>; def cl_no_stdinc : Flag<["-"], "cl-no-stdinc">, Group, HelpText<"OpenCL only. Disables all standard includes containing non-native compiler types and functions.">; +def cl_ext_EQ : CommaJoined<["-"], "cl-ext=">, 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>; + def client__name : JoinedOrSeparate<["-"], "client_name">; def combine : Flag<["-", "--"], "combine">, Flags<[NoXarchOption, Unsupported]>; def compatibility__version : JoinedOrSeparate<["-"], "compatibility_version">; @@ -6131,15 +6137,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>; - -//===----------------------------------------------------------------------===// // CUDA Options //===----------------------------------------------------------------------===// diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index efaedb6..bc43bce 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 b6a9b8a..ba1ace5 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);