From 6bdbcbb3d91ba48e418c8e854c9cacd8f5d24e2f Mon Sep 17 00:00:00 2001 From: Anastasia Stulova Date: Fri, 19 Feb 2016 18:30:11 +0000 Subject: [OpenCL] Generate metadata for opencl_unroll_hint attribute Add support for opencl_unroll_hint attribute from OpenCL v2.0 s6.11.5. Reusing most of metadata generation from CGLoopInfo helper class. The code is based on Khronos OpenCL compiler: https://github.com/KhronosGroup/SPIR/tree/spirv-1.0 Patch by Liu Yaxun (Sam)! Differential Revision: http://reviews.llvm.org/D16686 llvm-svn: 261350 --- clang/lib/Parse/ParseDecl.cpp | 4 ++-- clang/lib/Parse/ParseStmt.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'clang/lib/Parse') diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index 64f00bfcfa5..24db6814b81 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -670,7 +670,7 @@ void Parser::ParseBorlandTypeAttributes(ParsedAttributes &attrs) { } } -void Parser::ParseOpenCLAttributes(ParsedAttributes &attrs) { +void Parser::ParseOpenCLKernelAttributes(ParsedAttributes &attrs) { // Treat these like attributes while (Tok.is(tok::kw___kernel)) { IdentifierInfo *AttrName = Tok.getIdentifierInfo(); @@ -3098,7 +3098,7 @@ void Parser::ParseDeclarationSpecifiers(DeclSpec &DS, // OpenCL single token adornments. case tok::kw___kernel: - ParseOpenCLAttributes(DS.getAttributes()); + ParseOpenCLKernelAttributes(DS.getAttributes()); continue; // Nullability type specifiers. diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp index 71904f0cc22..085319f9bdd 100644 --- a/clang/lib/Parse/ParseStmt.cpp +++ b/clang/lib/Parse/ParseStmt.cpp @@ -107,6 +107,8 @@ Parser::ParseStatementOrDeclaration(StmtVector &Stmts, ParsedAttributesWithRange Attrs(AttrFactory); MaybeParseCXX11Attributes(Attrs, nullptr, /*MightBeObjCMessageSend*/ true); + if (!MaybeParseOpenCLUnrollHintAttribute(Attrs)) + return StmtError(); StmtResult Res = ParseStatementOrDeclarationAfterAttributes( Stmts, Allowed, TrailingElseLoc, Attrs); @@ -2208,3 +2210,19 @@ void Parser::ParseMicrosoftIfExistsStatement(StmtVector &Stmts) { } Braces.consumeClose(); } + +bool Parser::ParseOpenCLUnrollHintAttribute(ParsedAttributes &Attrs) { + MaybeParseGNUAttributes(Attrs); + + if (Attrs.empty()) + return true; + + if (Attrs.getList()->getKind() != AttributeList::AT_OpenCLUnrollHint) + return true; + + if (!(Tok.is(tok::kw_for) || Tok.is(tok::kw_while) || Tok.is(tok::kw_do))) { + Diag(Tok, diag::err_opencl_unroll_hint_on_non_loop); + return false; + } + return true; +} -- cgit v1.2.3