[PATCH 1/3] CL++ (OpenCL++) provisional implementation
Adam Strzelecki
ono at java.pl
Sun May 18 16:29:13 PDT 2014
This defines C++11 mode OpenCL counterpart standards: cl++, CL++1.1 and CL++1.2,
cl++ language with cl++, clpp or clxx source file name extensions.
This makes possible to produce SPIR LL output from C++ code and use it to
create OpenCL SPIR compatible kernels.
---
include/clang/Driver/Types.def | 1 +
include/clang/Frontend/FrontendOptions.h | 1 +
include/clang/Frontend/LangStandards.def | 11 +++++++++++
lib/Driver/Types.cpp | 3 +++
lib/Frontend/CompilerInvocation.cpp | 21 ++++++++++++++++++---
lib/Frontend/FrontendActions.cpp | 1 +
6 files changed, 35 insertions(+), 3 deletions(-)
diff --git a/include/clang/Driver/Types.def b/include/clang/Driver/Types.def
index 3209679..f71393f 100644
--- a/include/clang/Driver/Types.def
+++ b/include/clang/Driver/Types.def
@@ -42,6 +42,7 @@
TYPE("cpp-output", PP_C, INVALID, "i", "u")
TYPE("c", C, PP_C, "c", "u")
TYPE("cl", CL, PP_C, "cl", "u")
+TYPE("cl++", CLXX, PP_CXX, "clpp", "u")
TYPE("cuda", CUDA, PP_CXX, "cpp", "u")
TYPE("objective-c-cpp-output", PP_ObjC, INVALID, "mi", "u")
TYPE("objc-cpp-output", PP_ObjC_Alias, INVALID, "mi", "u")
diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h
index e87da8d..08a6e0c 100644
--- a/include/clang/Frontend/FrontendOptions.h
+++ b/include/clang/Frontend/FrontendOptions.h
@@ -70,6 +70,7 @@ enum InputKind {
IK_PreprocessedObjC,
IK_PreprocessedObjCXX,
IK_OpenCL,
+ IK_OpenCLXX,
IK_CUDA,
IK_AST,
IK_LLVM_IR
diff --git a/include/clang/Frontend/LangStandards.def b/include/clang/Frontend/LangStandards.def
index 7b2516b..c61fceb 100644
--- a/include/clang/Frontend/LangStandards.def
+++ b/include/clang/Frontend/LangStandards.def
@@ -126,6 +126,17 @@ LANGSTANDARD(opencl12, "CL1.2",
"OpenCL 1.2",
LineComment | C99 | Digraphs | HexFloat)
+// OpenCL++ (provisional)
+LANGSTANDARD(openclxx, "cl++",
+ "OpenCL 1.0",
+ LineComment | CPlusPlus | CPlusPlus11 | Digraphs | HexFloat)
+LANGSTANDARD(openclxx11, "CL++1.1",
+ "OpenCL 1.1",
+ LineComment | CPlusPlus | CPlusPlus11 | Digraphs | HexFloat)
+LANGSTANDARD(openclxx12, "CL++1.2",
+ "OpenCL 1.2",
+ LineComment | CPlusPlus | CPlusPlus11 | Digraphs | HexFloat)
+
// CUDA
LANGSTANDARD(cuda, "cuda",
"NVIDIA CUDA(tm)",
diff --git a/lib/Driver/Types.cpp b/lib/Driver/Types.cpp
index 3538dbc..f6b0a61 100644
--- a/lib/Driver/Types.cpp
+++ b/lib/Driver/Types.cpp
@@ -85,6 +85,7 @@ bool types::isAcceptedByClang(ID Id) {
case TY_Asm:
case TY_C: case TY_PP_C:
case TY_CL:
+ case TY_CLXX:
case TY_CUDA:
case TY_ObjC: case TY_PP_ObjC: case TY_PP_ObjC_Alias:
case TY_CXX: case TY_PP_CXX:
@@ -150,6 +151,8 @@ types::ID types::lookupTypeForExtension(const char *Ext) {
.Case("cc", TY_CXX)
.Case("CC", TY_CXX)
.Case("cl", TY_CL)
+ .Case("cl++", TY_CLXX)
+ .Case("clpp", TY_CLXX)
.Case("cp", TY_CXX)
.Case("cu", TY_CUDA)
.Case("hh", TY_CXXHeader)
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index 6aeb9c6..9cdbd96 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -875,6 +875,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
DashX = llvm::StringSwitch<InputKind>(A->getValue())
.Case("c", IK_C)
.Case("cl", IK_OpenCL)
+ .Case("cl++", IK_OpenCLXX)
.Case("cuda", IK_CUDA)
.Case("c++", IK_CXX)
.Case("objective-c", IK_ObjC)
@@ -1081,6 +1082,9 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
case IK_OpenCL:
LangStd = LangStandard::lang_opencl;
break;
+ case IK_OpenCLXX:
+ LangStd = LangStandard::lang_openclxx;
+ break;
case IK_CUDA:
LangStd = LangStandard::lang_cuda;
break;
@@ -1114,15 +1118,18 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK,
Opts.ImplicitInt = Std.hasImplicitInt();
// Set OpenCL Version.
- if (LangStd == LangStandard::lang_opencl) {
+ if (LangStd == LangStandard::lang_opencl ||
+ LangStd == LangStandard::lang_openclxx) {
Opts.OpenCL = 1;
Opts.OpenCLVersion = 100;
}
- else if (LangStd == LangStandard::lang_opencl11) {
+ else if (LangStd == LangStandard::lang_opencl11 ||
+ LangStd == LangStandard::lang_openclxx11) {
Opts.OpenCL = 1;
Opts.OpenCLVersion = 110;
}
- else if (LangStd == LangStandard::lang_opencl12) {
+ else if (LangStd == LangStandard::lang_opencl12 ||
+ LangStd == LangStandard::lang_openclxx12) {
Opts.OpenCL = 1;
Opts.OpenCLVersion = 120;
}
@@ -1218,6 +1225,11 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
Diags.Report(diag::err_drv_argument_not_allowed_with)
<< A->getAsString(Args) << "OpenCL";
break;
+ case IK_OpenCLXX:
+ if (!Std.isCPlusPlus())
+ Diags.Report(diag::err_drv_argument_not_allowed_with)
+ << A->getAsString(Args) << "OpenCL++";
+ break;
case IK_CUDA:
if (!Std.isCPlusPlus())
Diags.Report(diag::err_drv_argument_not_allowed_with)
@@ -1237,6 +1249,9 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
.Case("CL", LangStandard::lang_opencl)
.Case("CL1.1", LangStandard::lang_opencl11)
.Case("CL1.2", LangStandard::lang_opencl12)
+ .Case("CL++", LangStandard::lang_openclxx)
+ .Case("CL++1.1", LangStandard::lang_openclxx11)
+ .Case("CL++1.2", LangStandard::lang_openclxx12)
.Default(LangStandard::lang_unspecified);
if (OpenCLLangStd == LangStandard::lang_unspecified) {
diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp
index 4cafa23..44c9504 100644
--- a/lib/Frontend/FrontendActions.cpp
+++ b/lib/Frontend/FrontendActions.cpp
@@ -659,6 +659,7 @@ void PrintPreambleAction::ExecuteAction() {
case IK_ObjC:
case IK_ObjCXX:
case IK_OpenCL:
+ case IK_OpenCLXX:
case IK_CUDA:
break;
--
1.8.5.2 (Apple Git-48)
More information about the cfe-commits
mailing list