From: Pirama Arumuga Nainar Date: Thu, 9 Jun 2016 23:34:20 +0000 (+0000) Subject: RenderScript support in the Frontend X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1ba5b9cd943eebb42266eb11b787c47af78b4287;p=clang RenderScript support in the Frontend Summary: Create a new Frontend LangOpt to specify the renderscript language. It is enabled by the "-x renderscript" option from the driver. Add a "kernel" function attribute only for RenderScript (an "ignored attribute" warning is generated otherwise). Make the NativeHalfType and NativeHalfArgsAndReturns LangOpts be implied by the RenderScript LangOpt. Reviewers: rsmith Subscribers: cfe-commits, srhines Differential Revision: http://reviews.llvm.org/D21198 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272342 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/Attr.td b/include/clang/Basic/Attr.td index e90c124cbd..0187f829f0 100644 --- a/include/clang/Basic/Attr.td +++ b/include/clang/Basic/Attr.td @@ -728,6 +728,12 @@ def OpenCLNoSVM : Attr { let ASTNode = 0; } +def Kernel : Attr { + let Spellings = [GNU<"kernel">]; + let Subjects = SubjectList<[Function]>; + let Documentation = [Undocumented]; +} + def Deprecated : InheritableAttr { let Spellings = [GCC<"deprecated">, Declspec<"deprecated">, CXX11<"","deprecated", 201309>]; diff --git a/include/clang/Basic/LangOptions.def b/include/clang/Basic/LangOptions.def index d3a85b76fe..0f67ed3a3b 100644 --- a/include/clang/Basic/LangOptions.def +++ b/include/clang/Basic/LangOptions.def @@ -185,6 +185,7 @@ LANGOPT(CUDA , 1, 0, "CUDA") LANGOPT(OpenMP , 32, 0, "OpenMP support and version of OpenMP (31, 40 or 45)") LANGOPT(OpenMPUseTLS , 1, 0, "Use TLS for threadprivates or runtime calls") LANGOPT(OpenMPIsDevice , 1, 0, "Generate code only for OpenMP target device") +LANGOPT(RenderScript , 1, 0, "RenderScript") LANGOPT(CUDAIsDevice , 1, 0, "compiling for CUDA device") LANGOPT(CUDAAllowVariadicFunctions, 1, 0, "allowing variadic functions in CUDA device code") diff --git a/include/clang/Frontend/FrontendOptions.h b/include/clang/Frontend/FrontendOptions.h index 1ae662a480..d49d8de6f5 100644 --- a/include/clang/Frontend/FrontendOptions.h +++ b/include/clang/Frontend/FrontendOptions.h @@ -74,6 +74,7 @@ enum InputKind { IK_OpenCL, IK_CUDA, IK_PreprocessedCuda, + IK_RenderScript, IK_AST, IK_LLVM_IR }; diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp index a948653ee7..b217db96c7 100644 --- a/lib/Frontend/CompilerInvocation.cpp +++ b/lib/Frontend/CompilerInvocation.cpp @@ -1292,6 +1292,7 @@ static InputKind ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args, .Case("objective-c++-header", IK_ObjCXX) .Cases("ast", "pcm", IK_AST) .Case("ir", IK_LLVM_IR) + .Case("renderscript", IK_RenderScript) .Default(IK_None); if (DashX == IK_None) Diags.Report(diag::err_drv_invalid_value) @@ -1495,6 +1496,9 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, case IK_PreprocessedObjCXX: LangStd = LangStandard::lang_gnucxx98; break; + case IK_RenderScript: + LangStd = LangStandard::lang_c99; + break; } } @@ -1537,6 +1541,12 @@ void CompilerInvocation::setLangDefaults(LangOptions &Opts, InputKind IK, Opts.CUDA = IK == IK_CUDA || IK == IK_PreprocessedCuda || LangStd == LangStandard::lang_cuda; + Opts.RenderScript = IK == IK_RenderScript; + if (Opts.RenderScript) { + Opts.NativeHalfType = 1; + Opts.NativeHalfArgsAndReturns = 1; + } + // OpenCL and C++ both have bool, true, false keywords. Opts.Bool = Opts.OpenCL || Opts.CPlusPlus; diff --git a/lib/Frontend/FrontendActions.cpp b/lib/Frontend/FrontendActions.cpp index 21dd37d43c..dd5479ca71 100644 --- a/lib/Frontend/FrontendActions.cpp +++ b/lib/Frontend/FrontendActions.cpp @@ -735,6 +735,7 @@ void PrintPreambleAction::ExecuteAction() { case IK_PreprocessedObjCXX: case IK_AST: case IK_LLVM_IR: + case IK_RenderScript: // We can't do anything with these. return; } diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index f4cce2febd..e99876b10b 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -4185,6 +4185,17 @@ static void handleTypeTagForDatatypeAttr(Sema &S, Decl *D, Attr.getAttributeSpellingListIndex())); } +static void handleKernelAttr(Sema &S, Decl *D, const AttributeList &Attr) { + if (S.LangOpts.RenderScript) { + D->addAttr(::new (S.Context) + KernelAttr(Attr.getRange(), S.Context, + Attr.getAttributeSpellingListIndex())); + } else { + S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << "kernel"; + } +} + + //===----------------------------------------------------------------------===// // Checker-specific attribute handlers. //===----------------------------------------------------------------------===// @@ -5914,6 +5925,10 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, case AttributeList::AT_TypeTagForDatatype: handleTypeTagForDatatypeAttr(S, D, Attr); break; + + case AttributeList::AT_Kernel: + handleKernelAttr(S, D, Attr); + break; } } diff --git a/test/CodeGen/fp16-ops.c b/test/CodeGen/fp16-ops.c index 7cd08a03d6..c96727f3d3 100644 --- a/test/CodeGen/fp16-ops.c +++ b/test/CodeGen/fp16-ops.c @@ -7,6 +7,8 @@ // RUN: | FileCheck %s --check-prefix=NATIVE-HALF // RUN: %clang_cc1 -emit-llvm -o - -triple aarch64-none-linux-gnueabi -fnative-half-type %s \ // RUN: | FileCheck %s --check-prefix=NATIVE-HALF +// RUN: %clang_cc1 -emit-llvm -o - -x renderscript %s \ +// RUN: | FileCheck %s --check-prefix=NATIVE-HALF typedef unsigned cond_t; volatile cond_t test; diff --git a/test/Sema/renderscript.rs b/test/Sema/renderscript.rs new file mode 100644 index 0000000000..c6ffb4df1c --- /dev/null +++ b/test/Sema/renderscript.rs @@ -0,0 +1,20 @@ +// RUN: %clang_cc1 -fsyntax-only -verify -x renderscript -D__RENDERSCRIPT__ %s +// RUN: %clang_cc1 -fsyntax-only -verify -x c %s + +#ifndef __RENDERSCRIPT__ +// expected-warning@+2 {{kernel attribute ignored}} +#endif +void __attribute__((kernel)) kernel(); + +// expected-warning@+1 {{'kernel' attribute only applies to functions}} +int __attribute__((kernel)) global; + +#ifndef __RENDERSCRIPT__ +// expected-error@+2 {{function return value cannot have __fp16 type; did you forget * ?}} +#endif +__fp16 fp16_return(); + +#ifndef __RENDERSCRIPT__ +// expected-error@+2 {{parameters cannot have __fp16 type; did you forget * ?}} +#endif +void fp16_arg(__fp16 p);