[llvm-branch-commits] [clang] e123cd6 - [OpenCL] Refactor of targets OpenCL option settings
Author: Anton Zabaznov Date: 2021-01-25T19:50:23+03:00 New Revision: e123cd674c0209c80bc6225bb9e3a2d1d2ee418b URL: https://github.com/llvm/llvm-project/commit/e123cd674c0209c80bc6225bb9e3a2d1d2ee418b DIFF: https://github.com/llvm/llvm-project/commit/e123cd674c0209c80bc6225bb9e3a2d1d2ee418b.diff LOG: [OpenCL] Refactor of targets OpenCL option settings Currently, there is some refactoring needed in existing interface of OpenCL option settings to support OpenCL C 3.0. The problem is that OpenCL extensions and features are not only determined by the target platform but also by the OpenCL version. Also, there are core extensions/features which are supported unconditionally in specific OpenCL C version. In fact, these rules are not being followed for all targets. For example, there are some targets (as nvptx and r600) which don't support OpenCL C 2.0 core features (nvptx.languageOptsOpenCL.cl, r600.languageOptsOpenCL.cl). After the change there will be explicit differentiation between optional core and core OpenCL features which allows giving diagnostics if target doesn't support any of necessary core features for specific OpenCL version. This patch also eliminates `OpenCLOptions` instance duplication from `TargetOptions`. `OpenCLOptions` instance should take place in `Sema` as it's going to be modified during parsing. Removing this duplication will also allow to generally simplify `OpenCLOptions` class for parsing purposes. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D92277 Added: clang/lib/Basic/OpenCLOptions.cpp Modified: clang/include/clang/Basic/OpenCLExtensions.def clang/include/clang/Basic/OpenCLOptions.h clang/include/clang/Basic/TargetInfo.h clang/include/clang/Basic/TargetOptions.h clang/lib/Basic/CMakeLists.txt clang/lib/Basic/Targets.cpp clang/lib/Basic/Targets/AMDGPU.h clang/lib/Basic/Targets/NVPTX.h clang/lib/Basic/Targets/SPIR.h clang/lib/Basic/Targets/X86.h clang/lib/Frontend/InitPreprocessor.cpp clang/lib/Parse/ParsePragma.cpp clang/lib/Sema/Sema.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/test/Misc/nvptx.languageOptsOpenCL.cl clang/test/Misc/r600.languageOptsOpenCL.cl Removed: diff --git a/clang/include/clang/Basic/OpenCLExtensions.def b/clang/include/clang/Basic/OpenCLExtensions.def index 9353be1753b0..801916c3ab94 100644 --- a/clang/include/clang/Basic/OpenCLExtensions.def +++ b/clang/include/clang/Basic/OpenCLExtensions.def @@ -10,19 +10,25 @@ // //===--===// -// Macro OPENCLEXT or OPENCLEXT_INTERNAL can be defined to enumerate the +// Macro OPENCLEXTNAME or OPENCL_GENERIC_EXTENSION can be defined to enumerate all // OpenCL extensions listed in this file. // -// If the extensions are to be enumerated without the supported OpenCL version, -// define OPENCLEXT(ext) where ext is the name of the extension. -// -// If the extensions are to be enumerated with supported OpenCL version, -// define OPENCLEXT_INTERNAL(ext, avail, core) where +// If extensions are to be enumerated with information about whether +// an extension is core or optional core and minimum OpenCL version +// when an extension becomes available, +// define OPENCL_GENERIC_EXTENSION(ext, avail, core, opt) where // ext - name of the extension or optional core feature. // avail - minimum OpenCL version supporting it. -// core - minimum OpenCL version when the extension becomes optional core -// feature or core feature. ~0U indicates not a core feature or an -// optional core feature. +// core - OpenCL versions mask when the extension becomes core feature. +// 0U indicates not a core feature. +// opt - OpenCL versions mask when the extension becomes optional core +// feature. 0U indicates not a optional core feature. +// +// If extensions are to be enumerated without any information, +// define OPENCLEXTNAME(ext) where ext is the name of the extension. +// +// Difference between optional core feature and core feature is that the +// later is unconditionally supported in specific OpenCL version. // // As per The OpenCL Extension Specification, Section 1.2, in this file, an // extension is defined if and only it either: @@ -32,63 +38,72 @@ // For such an extension, a preprocessor #define that matches the extension // name must be created and a #pragma is required if and only if the // compilation flow is impacted, e.g. due to a diff erence of syntax or -// semantics in the language compared to the core standard. +// semantics in the language compared to the core standard. #pragma directive +// has no effect for optional core and core features. -#ifndef OPENCLEXT_INTERNAL -#ifndef OPENCLEXT -#pragma error "macro OPENCLEXT or OPENCLEXT_INTERNAL is required"
[llvm-branch-commits] [clang] 6efead1 - [OpenCL] Add support of __opencl_c_3d_image_writes feature macro
Author: Anton Zabaznov Date: 2021-08-02T17:22:59+03:00 New Revision: 6efead14f49f62e526d01bdfbeab2a7da847af4e URL: https://github.com/llvm/llvm-project/commit/6efead14f49f62e526d01bdfbeab2a7da847af4e DIFF: https://github.com/llvm/llvm-project/commit/6efead14f49f62e526d01bdfbeab2a7da847af4e.diff LOG: [OpenCL] Add support of __opencl_c_3d_image_writes feature macro This feature requires support of __opencl_c_images, so diagnostics for that is provided as well. Also, ensure that cl_khr_3d_image_writes feature macro is set to the same value. Reviewed By: Anastasia Differential Revision: https://reviews.llvm.org/D106260 (cherry picked from commit f16a4fcbe510d17b3f361d446eaf223208ded2bd) Added: Modified: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Basic/OpenCLOptions.cpp clang/lib/Basic/Targets/AMDGPU.h clang/lib/Sema/SemaType.cpp clang/test/Misc/opencl-c-3.0.incorrect_options.cl clang/test/SemaOpenCL/unsupported-image.cl Removed: diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 108f1796415c8..c57b8eca7deb1 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10100,8 +10100,6 @@ def err_opencl_requires_extension : Error< def ext_opencl_double_without_pragma : Extension< "Clang permits use of type 'double' regardless pragma if 'cl_khr_fp64' is" " supported">; -def err_opencl_double_requires_extension : Error< -"use of type 'double' requires %select{cl_khr_fp64|cl_khr_fp64 and __opencl_c_fp64}0 support">; def warn_opencl_generic_address_space_arg : Warning< "passing non-generic address space pointer to %0" " may cause dynamic conversion affecting performance">, diff --git a/clang/lib/Basic/OpenCLOptions.cpp b/clang/lib/Basic/OpenCLOptions.cpp index 2e215b185f662..f4f474fade4db 100644 --- a/clang/lib/Basic/OpenCLOptions.cpp +++ b/clang/lib/Basic/OpenCLOptions.cpp @@ -111,7 +111,8 @@ bool OpenCLOptions::diagnoseUnsupportedFeatureDependencies( // Feature pairs. First feature in a pair requires the second one to be // supported. static const llvm::StringMap DependentFeaturesMap = { - {"__opencl_c_read_write_images", "__opencl_c_images"}}; + {"__opencl_c_read_write_images", "__opencl_c_images"}, + {"__opencl_c_3d_image_writes", "__opencl_c_images"}}; auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts(); @@ -130,7 +131,8 @@ bool OpenCLOptions::diagnoseFeatureExtensionDifferences( const TargetInfo &TI, DiagnosticsEngine &Diags) { // Extensions and equivalent feature pairs. static const llvm::StringMap FeatureExtensionMap = { - {"cl_khr_fp64", "__opencl_c_fp64"}}; + {"cl_khr_fp64", "__opencl_c_fp64"}, + {"cl_khr_3d_image_writes", "__opencl_c_3d_image_writes"}}; auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts(); diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h index 244a6e0446905..2e580ecf24259 100644 --- a/clang/lib/Basic/Targets/AMDGPU.h +++ b/clang/lib/Basic/Targets/AMDGPU.h @@ -310,9 +310,12 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public TargetInfo { Opts["cl_khr_mipmap_image"] = true; Opts["cl_khr_mipmap_image_writes"] = true; Opts["cl_khr_subgroups"] = true; - Opts["cl_khr_3d_image_writes"] = true; Opts["cl_amd_media_ops"] = true; Opts["cl_amd_media_ops2"] = true; + + Opts["__opencl_c_images"] = true; + Opts["__opencl_c_3d_image_writes"] = true; + Opts["cl_khr_3d_image_writes"] = true; } } diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index b78331cdfe919..bca21b351c919 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1525,18 +1525,20 @@ static QualType ConvertDeclSpecToType(TypeProcessingState &state) { break; case DeclSpec::TST_float: Result = Context.FloatTy; break; case DeclSpec::TST_double: +if (DS.getTypeSpecWidth() == TypeSpecifierWidth::Long) + Result = Context.LongDoubleTy; +else + Result = Context.DoubleTy; if (S.getLangOpts().OpenCL) { if (!S.getOpenCLOptions().isSupported("cl_khr_fp64", S.getLangOpts())) -S.Diag(DS.getTypeSpecTypeLoc(), - diag::err_opencl_double_requires_extension) -<< (S.getLangOpts().OpenCLVersion >= 300); +S.Diag(DS.getTypeSpecTypeLoc(), diag::err_opencl_requires_extension) +<< 0 << Result +<< (S.getLangOpts().OpenCLVersion == 300 +? "cl_khr_fp64 and __opencl_c_fp64" +: "cl_khr_fp64"); else if (!S.getOpenCLOptions().isAvailableOption("cl_khr_fp64", S.getLangOpts())) S.Diag(DS.getTypeSpecTypeLoc(), diag::ext_opencl_double_without_pragma); } -if (DS.getTypeSpecWidth() ==
[llvm-branch-commits] [clang] 568767b - [OpenCL] Add support of __opencl_c_pipes feature macro.
Author: Anton Zabaznov Date: 2021-08-02T18:35:51+03:00 New Revision: 568767b3b632bcb65690d8f7476ac6f333fbb38b URL: https://github.com/llvm/llvm-project/commit/568767b3b632bcb65690d8f7476ac6f333fbb38b DIFF: https://github.com/llvm/llvm-project/commit/568767b3b632bcb65690d8f7476ac6f333fbb38b.diff LOG: [OpenCL] Add support of __opencl_c_pipes feature macro. 'pipe' keyword is introduced in OpenCL C 2.0: so do checks for OpenCL C version while parsing and then later on check for language options to construct actual pipe. This feature requires support of __opencl_c_generic_address_space, so diagnostics for that is provided as well. This is the same patch as in D106748 but with a tiny fix in checking of diagnostic messages. Also added tests when program scope global variables are not supported. This is squashed cherry pick of D107154 and D107176 Added: Modified: clang/include/clang/Basic/LangOptions.def clang/lib/Basic/OpenCLOptions.cpp clang/lib/Basic/TargetInfo.cpp clang/lib/Frontend/CompilerInvocation.cpp clang/lib/Parse/ParseDecl.cpp clang/lib/Sema/Sema.cpp clang/test/CodeGenOpenCL/address-spaces-mangling.cl clang/test/CodeGenOpenCL/address-spaces.cl clang/test/CodeGenOpenCL/pipe_types.cl clang/test/CodeGenOpenCL/pipe_types_mangling.cl clang/test/Misc/opencl-c-3.0.incorrect_options.cl clang/test/SemaOpenCL/invalid-pipes-cl1.2.cl clang/test/SemaOpenCL/invalid-pipes-cl2.0.cl clang/test/SemaOpenCL/storageclass.cl Removed: diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def index 08b8d8851afa8..74deba6ef7fba 100644 --- a/clang/include/clang/Basic/LangOptions.def +++ b/clang/include/clang/Basic/LangOptions.def @@ -224,7 +224,7 @@ LANGOPT(OpenCLVersion , 32, 0, "OpenCL C version") LANGOPT(OpenCLCPlusPlus , 1, 0, "C++ for OpenCL") LANGOPT(OpenCLCPlusPlusVersion , 32, 0, "C++ for OpenCL version") LANGOPT(OpenCLGenericAddressSpace, 1, 0, "OpenCL generic keyword") -LANGOPT(OpenCLPipe , 1, 0, "OpenCL pipe keyword") +LANGOPT(OpenCLPipes , 1, 0, "OpenCL pipes language constructs and built-ins") LANGOPT(NativeHalfType, 1, 0, "Native half type support") LANGOPT(NativeHalfArgsAndReturns, 1, 0, "Native half args and returns") LANGOPT(HalfArgsAndReturns, 1, 0, "half args and returns") diff --git a/clang/lib/Basic/OpenCLOptions.cpp b/clang/lib/Basic/OpenCLOptions.cpp index f4f474fade4db..b7408f39bdab4 100644 --- a/clang/lib/Basic/OpenCLOptions.cpp +++ b/clang/lib/Basic/OpenCLOptions.cpp @@ -112,7 +112,8 @@ bool OpenCLOptions::diagnoseUnsupportedFeatureDependencies( // supported. static const llvm::StringMap DependentFeaturesMap = { {"__opencl_c_read_write_images", "__opencl_c_images"}, - {"__opencl_c_3d_image_writes", "__opencl_c_images"}}; + {"__opencl_c_3d_image_writes", "__opencl_c_images"}, + {"__opencl_c_pipes", "__opencl_c_generic_address_space"}}; auto OpenCLFeaturesMap = TI.getSupportedOpenCLOpts(); diff --git a/clang/lib/Basic/TargetInfo.cpp b/clang/lib/Basic/TargetInfo.cpp index b647a2fb8a679..5f8e04c2bd6c4 100644 --- a/clang/lib/Basic/TargetInfo.cpp +++ b/clang/lib/Basic/TargetInfo.cpp @@ -400,14 +400,18 @@ void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) { // OpenCL C v3.0 s6.7.5 - The generic address space requires support for // OpenCL C 2.0 or OpenCL C 3.0 with the __opencl_c_generic_address_space // feature -// FIXME: OpenCLGenericAddressSpace is also defined in setLangDefaults() +// OpenCL C v3.0 s6.2.1 - OpenCL pipes require support of OpenCL C 2.0 +// or later and __opencl_c_pipes feature +// FIXME: These language options are also defined in setLangDefaults() // for OpenCL C 2.0 but with no access to target capabilities. Target -// should be immutable once created and thus this language option needs +// should be immutable once created and thus these language options need // to be defined only once. -if (Opts.OpenCLVersion >= 300) { +if (Opts.OpenCLVersion == 300) { const auto &OpenCLFeaturesMap = getSupportedOpenCLOpts(); Opts.OpenCLGenericAddressSpace = hasFeatureEnabled( OpenCLFeaturesMap, "__opencl_c_generic_address_space"); + Opts.OpenCLPipes = + hasFeatureEnabled(OpenCLFeaturesMap, "__opencl_c_pipes"); } } diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index d545e9358f048..33e5f3e99c458 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -3173,7 +3173,7 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, Opts.ZVector = 0; Opts.setDefaultFPContractMode(LangOptions::FPM_On); Opts.OpenCLCPlusPlus = Opts.CPlusPlus; -Opts.OpenCLPipe =