[OpenCL] Add supported OpenCL extensions to target info.
Add supported OpenCL extensions to target info. It serves as default values to save the users of the burden setting each supported extensions and optional core features in command line.
Differential Revision: http://reviews.llvm.org/D19484
llvm-svn: 269431
diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 4ca67ac..b1b12e4 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -1999,17 +1999,6 @@
Builder.defineMacro("__HAS_FMAF__");
if (hasLDEXPF)
Builder.defineMacro("__HAS_LDEXPF__");
- if (hasFP64 && Opts.OpenCL)
- Builder.defineMacro("cl_khr_fp64");
- if (Opts.OpenCL) {
- if (GPU >= GK_NORTHERN_ISLANDS) {
- Builder.defineMacro("cl_khr_byte_addressable_store");
- Builder.defineMacro("cl_khr_global_int32_base_atomics");
- Builder.defineMacro("cl_khr_global_int32_extended_atomics");
- Builder.defineMacro("cl_khr_local_int32_base_atomics");
- Builder.defineMacro("cl_khr_local_int32_extended_atomics");
- }
- }
}
BuiltinVaListKind getBuiltinVaListKind() const override {
@@ -2097,6 +2086,31 @@
return true;
}
+
+ void setSupportedOpenCLOpts() {
+ auto &Opts = getSupportedOpenCLOpts();
+ Opts.cl_clang_storage_class_specifiers = 1;
+ Opts.cl_khr_gl_sharing = 1;
+ Opts.cl_khr_gl_event = 1;
+ Opts.cl_khr_d3d10_sharing = 1;
+ Opts.cl_khr_subgroups = 1;
+
+ if (hasFP64)
+ Opts.cl_khr_fp64 = 1;
+ if (GPU >= GK_NORTHERN_ISLANDS) {
+ Opts.cl_khr_byte_addressable_store = 1;
+ Opts.cl_khr_global_int32_base_atomics = 1;
+ Opts.cl_khr_global_int32_extended_atomics = 1;
+ Opts.cl_khr_local_int32_base_atomics = 1;
+ Opts.cl_khr_local_int32_extended_atomics = 1;
+ }
+ if (GPU >= GK_SOUTHERN_ISLANDS)
+ Opts.cl_khr_fp16 = 1;
+ Opts.cl_khr_int64_base_atomics = 1;
+ Opts.cl_khr_int64_extended_atomics = 1;
+ Opts.cl_khr_3d_image_writes = 1;
+ Opts.cl_khr_gl_msaa_sharing = 1;
+ }
};
const Builtin::Info AMDGPUTargetInfo::BuiltinInfo[] = {
@@ -2716,6 +2730,10 @@
bool hasSjLjLowering() const override {
return true;
}
+
+ void setSupportedOpenCLOpts() {
+ getSupportedOpenCLOpts().setAll();
+ }
};
bool X86TargetInfo::setFPMath(StringRef Name) {
@@ -7858,6 +7876,12 @@
CallingConv getDefaultCallingConv(CallingConvMethodType MT) const override {
return CC_SpirFunction;
}
+
+ void setSupportedOpenCLOpts() {
+ // Assume all OpenCL extensions and optional core features are supported
+ // for SPIR since it is a generic target.
+ getSupportedOpenCLOpts().setAll();
+ }
};
class SPIR32TargetInfo : public SPIRTargetInfo {
@@ -8458,5 +8482,7 @@
if (!Target->handleTargetFeatures(Opts->Features, Diags))
return nullptr;
+ Target->setSupportedOpenCLOpts();
+
return Target.release();
}
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp
index 1c7793e..5d38d5f 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -938,6 +938,15 @@
Builder.defineMacro("__CUDA_ARCH__");
}
+ // OpenCL definitions.
+ if (LangOpts.OpenCL) {
+#define OPENCLEXT(Ext) \
+ if (TI.getSupportedOpenCLOpts().is_##Ext##_supported( \
+ LangOpts.OpenCLVersion)) \
+ Builder.defineMacro(#Ext);
+#include "clang/Basic/OpenCLExtensions.def"
+ }
+
// Get other target #defines.
TI.getTargetDefines(LangOpts, Builder);
}
diff --git a/clang/lib/Parse/ParsePragma.cpp b/clang/lib/Parse/ParsePragma.cpp
index 6024a62..9e9a749 100644
--- a/clang/lib/Parse/ParsePragma.cpp
+++ b/clang/lib/Parse/ParsePragma.cpp
@@ -468,14 +468,24 @@
ConsumeToken(); // The annotation token.
OpenCLOptions &f = Actions.getOpenCLOptions();
+ auto CLVer = getLangOpts().OpenCLVersion;
+ auto &Supp = getTargetInfo().getSupportedOpenCLOpts();
// OpenCL 1.1 9.1: "The all variant sets the behavior for all extensions,
// overriding all previously issued extension directives, but only if the
// behavior is set to disable."
if (state == 0 && ename->isStr("all")) {
-#define OPENCLEXT(nm) f.nm = 0;
+#define OPENCLEXT(nm) \
+ if (Supp.is_##nm##_supported_extension(CLVer)) \
+ f.nm = 0;
#include "clang/Basic/OpenCLExtensions.def"
}
-#define OPENCLEXT(nm) else if (ename->isStr(#nm)) { f.nm = state; }
+#define OPENCLEXT(nm) else if (ename->isStr(#nm)) \
+ if (Supp.is_##nm##_supported_extension(CLVer)) \
+ f.nm = state; \
+ else if (Supp.is_##nm##_supported_core(CLVer)) \
+ PP.Diag(NameLoc, diag::warn_pragma_extension_is_core) << ename; \
+ else \
+ PP.Diag(NameLoc, diag::warn_pragma_unsupported_extension) << ename;
#include "clang/Basic/OpenCLExtensions.def"
else {
PP.Diag(NameLoc, diag::warn_pragma_unknown_extension) << ename;
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index d8d10b6..35e303e 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -207,8 +207,14 @@
addImplicitTypedef("size_t", Context.getSizeType());
}
- // Initialize predefined OpenCL types.
+ // Initialize predefined OpenCL types and supported optional core features.
if (getLangOpts().OpenCL) {
+#define OPENCLEXT(Ext) \
+ if (Context.getTargetInfo().getSupportedOpenCLOpts().is_##Ext##_supported_core( \
+ getLangOpts().OpenCLVersion)) \
+ getOpenCLOptions().Ext = 1;
+#include "clang/Basic/OpenCLExtensions.def"
+
addImplicitTypedef("sampler_t", Context.OCLSamplerTy);
addImplicitTypedef("event_t", Context.OCLEventTy);
if (getLangOpts().OpenCLVersion >= 200) {