Index: clang/docs/OpenCLSupport.rst =================================================================== --- clang/docs/OpenCLSupport.rst +++ clang/docs/OpenCLSupport.rst @@ -111,6 +111,8 @@ Note that this is a frontend-only flag and therefore it requires the use of flags that forward options to the frontend e.g. ``-cc1`` or ``-Xclang``. +.. _opencl_builtins: + OpenCL builtins --------------- @@ -153,6 +155,80 @@ inserted using ``InsertOCLBuiltinDeclarationsFromTable`` and overload resolution takes place. +OpenCL Extensions and Features +------------------------------ + +Clang implements various extensions to OpenCL kernel languages. + +New functionality is accepted as soon as the documentation is detailed to the +level sufficient to be implemented. There should be an evidence that the +extension is designed with implementation feasibility in consideration and +assessment of complexity for C/C++ based compilers. Alternatively, the +documentation can be accepted in a format of a draft that can be further +refined during the implementation. + +Implementation guidelines +^^^^^^^^^^^^^^^^^^^^^^^^^ + +This section explains how to extend clang with the new functionality. + +**Parsing functionality** + +If an extension modifies the standard parsing it needs to be added to +the clang frontend source code. This also means that the associated macro +indicating the presence of the extension should be added to clang. + +The default flow for adding a new extension into the frontend is to +modify `OpenCLExtensions.def +`_ + +This will add the macro automatically and also add a field in the target +options ``clang::TargetOptions::OpenCLFeaturesMap`` to control the exposure +of the new extension during the compilation. + +Note that by default targets like `SPIR` or `X86` expose all the OpenCL +extensions. For all other targets the configuration has to be made explicitly. + +Note that the target extension support performed by clang can be overridden +with :ref:`-cl-ext ` command-line flags. + +**Library functionality** + +If an extension adds functionality that does not modify standard language +parsing it should not require modifying anything other than header files or +``OpenCLBuiltins.td`` detailed in :ref:``. +Most commonly such extensions add functionality via libraries (by adding +non-native types or functions) parsed regularly. Similar to other languages this +is the most common way to add new functionality. + +Clang has standard headers where new types and functions are being added, +for more details refer to +:ref:`the section on the OpenCL Header `. The macros indicating +the presence of such extensions can be added in the standard header files +conditioned on target specific predefined macros or/and language version +predefined macros. + +**Pragmas** + +Some extensions alter standard parsing dynamically via pragmas. + +Clang provides a mechanism to add the standard extension pragma +``OPENCL EXTENSION`` by setting a dedicated flag in the extension list entry of +``OpenCLExtensions.def``. Note that there is no default behavior for the +standard extension pragmas as it is not specified (for the standards up to and +including version 3.0) in a sufficient level of detail and, therefore, +there is no default functionality provided by clang. + +Pragmas without detailed information of their behavior (e.g. an explanation of +changes it triggers in the parsing) should not be added to clang. Moreover, the +pragmas should provide useful functionality to the user. + +Note that some legacy extensions (published prior to OpenCL 3.0) still +provide some non-conformant functionality for pragmas e.g. add diagnostics on +the use of types or functions. This functionality is not guaranteed to remain in +future releases. However, any future changes should not affect backward +compatibility. + .. _opencl_addrsp: Address spaces attribute