Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1 | //===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements parsing of all OpenMP directives and clauses. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 14 | #include "RAIIObjectsForParser.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 16 | #include "clang/AST/StmtOpenMP.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 17 | #include "clang/Parse/ParseDiagnostic.h" |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 18 | #include "clang/Parse/Parser.h" |
| 19 | #include "clang/Sema/Scope.h" |
| 20 | #include "llvm/ADT/PointerIntPair.h" |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 21 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | // OpenMP declarative directives. |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 28 | namespace { |
| 29 | enum OpenMPDirectiveKindEx { |
| 30 | OMPD_cancellation = OMPD_unknown + 1, |
| 31 | OMPD_data, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 32 | OMPD_declare, |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 33 | OMPD_end, |
| 34 | OMPD_end_declare, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 35 | OMPD_enter, |
| 36 | OMPD_exit, |
| 37 | OMPD_point, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 38 | OMPD_reduction, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 39 | OMPD_target_enter, |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 40 | OMPD_target_exit, |
| 41 | OMPD_update, |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 42 | OMPD_distribute_parallel, |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 43 | OMPD_teams_distribute_parallel, |
| 44 | OMPD_target_teams_distribute_parallel |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 45 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 46 | |
| 47 | class ThreadprivateListParserHelper final { |
| 48 | SmallVector<Expr *, 4> Identifiers; |
| 49 | Parser *P; |
| 50 | |
| 51 | public: |
| 52 | ThreadprivateListParserHelper(Parser *P) : P(P) {} |
| 53 | void operator()(CXXScopeSpec &SS, DeclarationNameInfo NameInfo) { |
| 54 | ExprResult Res = |
| 55 | P->getActions().ActOnOpenMPIdExpression(P->getCurScope(), SS, NameInfo); |
| 56 | if (Res.isUsable()) |
| 57 | Identifiers.push_back(Res.get()); |
| 58 | } |
| 59 | llvm::ArrayRef<Expr *> getIdentifiers() const { return Identifiers; } |
| 60 | }; |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 61 | } // namespace |
| 62 | |
| 63 | // Map token string to extended OMP token kind that are |
| 64 | // OpenMPDirectiveKind + OpenMPDirectiveKindEx. |
| 65 | static unsigned getOpenMPDirectiveKindEx(StringRef S) { |
| 66 | auto DKind = getOpenMPDirectiveKind(S); |
| 67 | if (DKind != OMPD_unknown) |
| 68 | return DKind; |
| 69 | |
| 70 | return llvm::StringSwitch<unsigned>(S) |
| 71 | .Case("cancellation", OMPD_cancellation) |
| 72 | .Case("data", OMPD_data) |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 73 | .Case("declare", OMPD_declare) |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 74 | .Case("end", OMPD_end) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 75 | .Case("enter", OMPD_enter) |
| 76 | .Case("exit", OMPD_exit) |
| 77 | .Case("point", OMPD_point) |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 78 | .Case("reduction", OMPD_reduction) |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 79 | .Case("update", OMPD_update) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 80 | .Default(OMPD_unknown); |
| 81 | } |
| 82 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 83 | static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 84 | // Array of foldings: F[i][0] F[i][1] ===> F[i][2]. |
| 85 | // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd |
| 86 | // TODO: add other combined directives in topological order. |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 87 | static const unsigned F[][3] = { |
| 88 | { OMPD_cancellation, OMPD_point, OMPD_cancellation_point }, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 89 | { OMPD_declare, OMPD_reduction, OMPD_declare_reduction }, |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 90 | { OMPD_declare, OMPD_simd, OMPD_declare_simd }, |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 91 | { OMPD_declare, OMPD_target, OMPD_declare_target }, |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 92 | { OMPD_distribute, OMPD_parallel, OMPD_distribute_parallel }, |
| 93 | { OMPD_distribute_parallel, OMPD_for, OMPD_distribute_parallel_for }, |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 94 | { OMPD_distribute_parallel_for, OMPD_simd, |
| 95 | OMPD_distribute_parallel_for_simd }, |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 96 | { OMPD_distribute, OMPD_simd, OMPD_distribute_simd }, |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 97 | { OMPD_end, OMPD_declare, OMPD_end_declare }, |
| 98 | { OMPD_end_declare, OMPD_target, OMPD_end_declare_target }, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 99 | { OMPD_target, OMPD_data, OMPD_target_data }, |
| 100 | { OMPD_target, OMPD_enter, OMPD_target_enter }, |
| 101 | { OMPD_target, OMPD_exit, OMPD_target_exit }, |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 102 | { OMPD_target, OMPD_update, OMPD_target_update }, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 103 | { OMPD_target_enter, OMPD_data, OMPD_target_enter_data }, |
| 104 | { OMPD_target_exit, OMPD_data, OMPD_target_exit_data }, |
| 105 | { OMPD_for, OMPD_simd, OMPD_for_simd }, |
| 106 | { OMPD_parallel, OMPD_for, OMPD_parallel_for }, |
| 107 | { OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd }, |
| 108 | { OMPD_parallel, OMPD_sections, OMPD_parallel_sections }, |
| 109 | { OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd }, |
| 110 | { OMPD_target, OMPD_parallel, OMPD_target_parallel }, |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 111 | { OMPD_target, OMPD_simd, OMPD_target_simd }, |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 112 | { OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for }, |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 113 | { OMPD_target_parallel_for, OMPD_simd, OMPD_target_parallel_for_simd }, |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 114 | { OMPD_teams, OMPD_distribute, OMPD_teams_distribute }, |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 115 | { OMPD_teams_distribute, OMPD_simd, OMPD_teams_distribute_simd }, |
| 116 | { OMPD_teams_distribute, OMPD_parallel, OMPD_teams_distribute_parallel }, |
| 117 | { OMPD_teams_distribute_parallel, OMPD_for, OMPD_teams_distribute_parallel_for }, |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 118 | { OMPD_teams_distribute_parallel_for, OMPD_simd, OMPD_teams_distribute_parallel_for_simd }, |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 119 | { OMPD_target, OMPD_teams, OMPD_target_teams }, |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 120 | { OMPD_target_teams, OMPD_distribute, OMPD_target_teams_distribute }, |
| 121 | { OMPD_target_teams_distribute, OMPD_parallel, OMPD_target_teams_distribute_parallel }, |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 122 | { OMPD_target_teams_distribute, OMPD_simd, OMPD_target_teams_distribute_simd }, |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 123 | { OMPD_target_teams_distribute_parallel, OMPD_for, OMPD_target_teams_distribute_parallel_for }, |
| 124 | { OMPD_target_teams_distribute_parallel_for, OMPD_simd, OMPD_target_teams_distribute_parallel_for_simd } |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 125 | }; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 126 | enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 }; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 127 | auto Tok = P.getCurToken(); |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 128 | unsigned DKind = |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 129 | Tok.isAnnotation() |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 130 | ? static_cast<unsigned>(OMPD_unknown) |
| 131 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 132 | if (DKind == OMPD_unknown) |
| 133 | return OMPD_unknown; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 134 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 135 | for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) { |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 136 | if (DKind != F[i][0]) |
| 137 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 138 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 139 | Tok = P.getPreprocessor().LookAhead(0); |
| 140 | unsigned SDKind = |
| 141 | Tok.isAnnotation() |
| 142 | ? static_cast<unsigned>(OMPD_unknown) |
| 143 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 144 | if (SDKind == OMPD_unknown) |
| 145 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 146 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 147 | if (SDKind == F[i][1]) { |
| 148 | P.ConsumeToken(); |
| 149 | DKind = F[i][2]; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 150 | } |
| 151 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 152 | return DKind < OMPD_unknown ? static_cast<OpenMPDirectiveKind>(DKind) |
| 153 | : OMPD_unknown; |
| 154 | } |
| 155 | |
| 156 | static DeclarationName parseOpenMPReductionId(Parser &P) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 157 | Token Tok = P.getCurToken(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 158 | Sema &Actions = P.getActions(); |
| 159 | OverloadedOperatorKind OOK = OO_None; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 160 | // Allow to use 'operator' keyword for C++ operators |
| 161 | bool WithOperator = false; |
| 162 | if (Tok.is(tok::kw_operator)) { |
| 163 | P.ConsumeToken(); |
| 164 | Tok = P.getCurToken(); |
| 165 | WithOperator = true; |
| 166 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 167 | switch (Tok.getKind()) { |
| 168 | case tok::plus: // '+' |
| 169 | OOK = OO_Plus; |
| 170 | break; |
| 171 | case tok::minus: // '-' |
| 172 | OOK = OO_Minus; |
| 173 | break; |
| 174 | case tok::star: // '*' |
| 175 | OOK = OO_Star; |
| 176 | break; |
| 177 | case tok::amp: // '&' |
| 178 | OOK = OO_Amp; |
| 179 | break; |
| 180 | case tok::pipe: // '|' |
| 181 | OOK = OO_Pipe; |
| 182 | break; |
| 183 | case tok::caret: // '^' |
| 184 | OOK = OO_Caret; |
| 185 | break; |
| 186 | case tok::ampamp: // '&&' |
| 187 | OOK = OO_AmpAmp; |
| 188 | break; |
| 189 | case tok::pipepipe: // '||' |
| 190 | OOK = OO_PipePipe; |
| 191 | break; |
| 192 | case tok::identifier: // identifier |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 193 | if (!WithOperator) |
| 194 | break; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 195 | default: |
| 196 | P.Diag(Tok.getLocation(), diag::err_omp_expected_reduction_identifier); |
| 197 | P.SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 198 | Parser::StopBeforeMatch); |
| 199 | return DeclarationName(); |
| 200 | } |
| 201 | P.ConsumeToken(); |
| 202 | auto &DeclNames = Actions.getASTContext().DeclarationNames; |
| 203 | return OOK == OO_None ? DeclNames.getIdentifier(Tok.getIdentifierInfo()) |
| 204 | : DeclNames.getCXXOperatorName(OOK); |
| 205 | } |
| 206 | |
| 207 | /// \brief Parse 'omp declare reduction' construct. |
| 208 | /// |
| 209 | /// declare-reduction-directive: |
| 210 | /// annot_pragma_openmp 'declare' 'reduction' |
| 211 | /// '(' <reduction_id> ':' <type> {',' <type>} ':' <expression> ')' |
| 212 | /// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> ')'] |
| 213 | /// annot_pragma_openmp_end |
| 214 | /// <reduction_id> is either a base language identifier or one of the following |
| 215 | /// operators: '+', '-', '*', '&', '|', '^', '&&' and '||'. |
| 216 | /// |
| 217 | Parser::DeclGroupPtrTy |
| 218 | Parser::ParseOpenMPDeclareReductionDirective(AccessSpecifier AS) { |
| 219 | // Parse '('. |
| 220 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 221 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 222 | getOpenMPDirectiveName(OMPD_declare_reduction))) { |
| 223 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 224 | return DeclGroupPtrTy(); |
| 225 | } |
| 226 | |
| 227 | DeclarationName Name = parseOpenMPReductionId(*this); |
| 228 | if (Name.isEmpty() && Tok.is(tok::annot_pragma_openmp_end)) |
| 229 | return DeclGroupPtrTy(); |
| 230 | |
| 231 | // Consume ':'. |
| 232 | bool IsCorrect = !ExpectAndConsume(tok::colon); |
| 233 | |
| 234 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 235 | return DeclGroupPtrTy(); |
| 236 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 237 | IsCorrect = IsCorrect && !Name.isEmpty(); |
| 238 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 239 | if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) { |
| 240 | Diag(Tok.getLocation(), diag::err_expected_type); |
| 241 | IsCorrect = false; |
| 242 | } |
| 243 | |
| 244 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 245 | return DeclGroupPtrTy(); |
| 246 | |
| 247 | SmallVector<std::pair<QualType, SourceLocation>, 8> ReductionTypes; |
| 248 | // Parse list of types until ':' token. |
| 249 | do { |
| 250 | ColonProtectionRAIIObject ColonRAII(*this); |
| 251 | SourceRange Range; |
| 252 | TypeResult TR = ParseTypeName(&Range, Declarator::PrototypeContext, AS); |
| 253 | if (TR.isUsable()) { |
| 254 | auto ReductionType = |
| 255 | Actions.ActOnOpenMPDeclareReductionType(Range.getBegin(), TR); |
| 256 | if (!ReductionType.isNull()) { |
| 257 | ReductionTypes.push_back( |
| 258 | std::make_pair(ReductionType, Range.getBegin())); |
| 259 | } |
| 260 | } else { |
| 261 | SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end, |
| 262 | StopBeforeMatch); |
| 263 | } |
| 264 | |
| 265 | if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) |
| 266 | break; |
| 267 | |
| 268 | // Consume ','. |
| 269 | if (ExpectAndConsume(tok::comma)) { |
| 270 | IsCorrect = false; |
| 271 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 272 | Diag(Tok.getLocation(), diag::err_expected_type); |
| 273 | return DeclGroupPtrTy(); |
| 274 | } |
| 275 | } |
| 276 | } while (Tok.isNot(tok::annot_pragma_openmp_end)); |
| 277 | |
| 278 | if (ReductionTypes.empty()) { |
| 279 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 280 | return DeclGroupPtrTy(); |
| 281 | } |
| 282 | |
| 283 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 284 | return DeclGroupPtrTy(); |
| 285 | |
| 286 | // Consume ':'. |
| 287 | if (ExpectAndConsume(tok::colon)) |
| 288 | IsCorrect = false; |
| 289 | |
| 290 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 291 | Diag(Tok.getLocation(), diag::err_expected_expression); |
| 292 | return DeclGroupPtrTy(); |
| 293 | } |
| 294 | |
| 295 | DeclGroupPtrTy DRD = Actions.ActOnOpenMPDeclareReductionDirectiveStart( |
| 296 | getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes, AS); |
| 297 | |
| 298 | // Parse <combiner> expression and then parse initializer if any for each |
| 299 | // correct type. |
| 300 | unsigned I = 0, E = ReductionTypes.size(); |
| 301 | for (auto *D : DRD.get()) { |
| 302 | TentativeParsingAction TPA(*this); |
| 303 | ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope | |
| 304 | Scope::OpenMPDirectiveScope); |
| 305 | // Parse <combiner> expression. |
| 306 | Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D); |
| 307 | ExprResult CombinerResult = |
| 308 | Actions.ActOnFinishFullExpr(ParseAssignmentExpression().get(), |
| 309 | D->getLocation(), /*DiscardedValue=*/true); |
| 310 | Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.get()); |
| 311 | |
| 312 | if (CombinerResult.isInvalid() && Tok.isNot(tok::r_paren) && |
| 313 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 314 | TPA.Commit(); |
| 315 | IsCorrect = false; |
| 316 | break; |
| 317 | } |
| 318 | IsCorrect = !T.consumeClose() && IsCorrect && CombinerResult.isUsable(); |
| 319 | ExprResult InitializerResult; |
| 320 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 321 | // Parse <initializer> expression. |
| 322 | if (Tok.is(tok::identifier) && |
| 323 | Tok.getIdentifierInfo()->isStr("initializer")) |
| 324 | ConsumeToken(); |
| 325 | else { |
| 326 | Diag(Tok.getLocation(), diag::err_expected) << "'initializer'"; |
| 327 | TPA.Commit(); |
| 328 | IsCorrect = false; |
| 329 | break; |
| 330 | } |
| 331 | // Parse '('. |
| 332 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 333 | tok::annot_pragma_openmp_end); |
| 334 | IsCorrect = |
| 335 | !T.expectAndConsume(diag::err_expected_lparen_after, "initializer") && |
| 336 | IsCorrect; |
| 337 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 338 | ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope | |
| 339 | Scope::OpenMPDirectiveScope); |
| 340 | // Parse expression. |
| 341 | Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(), D); |
| 342 | InitializerResult = Actions.ActOnFinishFullExpr( |
| 343 | ParseAssignmentExpression().get(), D->getLocation(), |
| 344 | /*DiscardedValue=*/true); |
| 345 | Actions.ActOnOpenMPDeclareReductionInitializerEnd( |
| 346 | D, InitializerResult.get()); |
| 347 | if (InitializerResult.isInvalid() && Tok.isNot(tok::r_paren) && |
| 348 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 349 | TPA.Commit(); |
| 350 | IsCorrect = false; |
| 351 | break; |
| 352 | } |
| 353 | IsCorrect = |
| 354 | !T.consumeClose() && IsCorrect && !InitializerResult.isInvalid(); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | ++I; |
| 359 | // Revert parsing if not the last type, otherwise accept it, we're done with |
| 360 | // parsing. |
| 361 | if (I != E) |
| 362 | TPA.Revert(); |
| 363 | else |
| 364 | TPA.Commit(); |
| 365 | } |
| 366 | return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD, |
| 367 | IsCorrect); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 370 | namespace { |
| 371 | /// RAII that recreates function context for correct parsing of clauses of |
| 372 | /// 'declare simd' construct. |
| 373 | /// OpenMP, 2.8.2 declare simd Construct |
| 374 | /// The expressions appearing in the clauses of this directive are evaluated in |
| 375 | /// the scope of the arguments of the function declaration or definition. |
| 376 | class FNContextRAII final { |
| 377 | Parser &P; |
| 378 | Sema::CXXThisScopeRAII *ThisScope; |
| 379 | Parser::ParseScope *TempScope; |
| 380 | Parser::ParseScope *FnScope; |
| 381 | bool HasTemplateScope = false; |
| 382 | bool HasFunScope = false; |
| 383 | FNContextRAII() = delete; |
| 384 | FNContextRAII(const FNContextRAII &) = delete; |
| 385 | FNContextRAII &operator=(const FNContextRAII &) = delete; |
| 386 | |
| 387 | public: |
| 388 | FNContextRAII(Parser &P, Parser::DeclGroupPtrTy Ptr) : P(P) { |
| 389 | Decl *D = *Ptr.get().begin(); |
| 390 | NamedDecl *ND = dyn_cast<NamedDecl>(D); |
| 391 | RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext()); |
| 392 | Sema &Actions = P.getActions(); |
| 393 | |
| 394 | // Allow 'this' within late-parsed attributes. |
| 395 | ThisScope = new Sema::CXXThisScopeRAII(Actions, RD, /*TypeQuals=*/0, |
| 396 | ND && ND->isCXXInstanceMember()); |
| 397 | |
| 398 | // If the Decl is templatized, add template parameters to scope. |
| 399 | HasTemplateScope = D->isTemplateDecl(); |
| 400 | TempScope = |
| 401 | new Parser::ParseScope(&P, Scope::TemplateParamScope, HasTemplateScope); |
| 402 | if (HasTemplateScope) |
| 403 | Actions.ActOnReenterTemplateScope(Actions.getCurScope(), D); |
| 404 | |
| 405 | // If the Decl is on a function, add function parameters to the scope. |
| 406 | HasFunScope = D->isFunctionOrFunctionTemplate(); |
| 407 | FnScope = new Parser::ParseScope(&P, Scope::FnScope | Scope::DeclScope, |
| 408 | HasFunScope); |
| 409 | if (HasFunScope) |
| 410 | Actions.ActOnReenterFunctionContext(Actions.getCurScope(), D); |
| 411 | } |
| 412 | ~FNContextRAII() { |
| 413 | if (HasFunScope) { |
| 414 | P.getActions().ActOnExitFunctionContext(); |
| 415 | FnScope->Exit(); // Pop scope, and remove Decls from IdResolver |
| 416 | } |
| 417 | if (HasTemplateScope) |
| 418 | TempScope->Exit(); |
| 419 | delete FnScope; |
| 420 | delete TempScope; |
| 421 | delete ThisScope; |
| 422 | } |
| 423 | }; |
| 424 | } // namespace |
| 425 | |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 426 | /// Parses clauses for 'declare simd' directive. |
| 427 | /// clause: |
| 428 | /// 'inbranch' | 'notinbranch' |
| 429 | /// 'simdlen' '(' <expr> ')' |
| 430 | /// { 'uniform' '(' <argument_list> ')' } |
| 431 | /// { 'aligned '(' <argument_list> [ ':' <alignment> ] ')' } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 432 | /// { 'linear '(' <argument_list> [ ':' <step> ] ')' } |
| 433 | static bool parseDeclareSimdClauses( |
| 434 | Parser &P, OMPDeclareSimdDeclAttr::BranchStateTy &BS, ExprResult &SimdLen, |
| 435 | SmallVectorImpl<Expr *> &Uniforms, SmallVectorImpl<Expr *> &Aligneds, |
| 436 | SmallVectorImpl<Expr *> &Alignments, SmallVectorImpl<Expr *> &Linears, |
| 437 | SmallVectorImpl<unsigned> &LinModifiers, SmallVectorImpl<Expr *> &Steps) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 438 | SourceRange BSRange; |
| 439 | const Token &Tok = P.getCurToken(); |
| 440 | bool IsError = false; |
| 441 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 442 | if (Tok.isNot(tok::identifier)) |
| 443 | break; |
| 444 | OMPDeclareSimdDeclAttr::BranchStateTy Out; |
| 445 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 446 | StringRef ClauseName = II->getName(); |
| 447 | // Parse 'inranch|notinbranch' clauses. |
| 448 | if (OMPDeclareSimdDeclAttr::ConvertStrToBranchStateTy(ClauseName, Out)) { |
| 449 | if (BS != OMPDeclareSimdDeclAttr::BS_Undefined && BS != Out) { |
| 450 | P.Diag(Tok, diag::err_omp_declare_simd_inbranch_notinbranch) |
| 451 | << ClauseName |
| 452 | << OMPDeclareSimdDeclAttr::ConvertBranchStateTyToStr(BS) << BSRange; |
| 453 | IsError = true; |
| 454 | } |
| 455 | BS = Out; |
| 456 | BSRange = SourceRange(Tok.getLocation(), Tok.getEndLoc()); |
| 457 | P.ConsumeToken(); |
| 458 | } else if (ClauseName.equals("simdlen")) { |
| 459 | if (SimdLen.isUsable()) { |
| 460 | P.Diag(Tok, diag::err_omp_more_one_clause) |
| 461 | << getOpenMPDirectiveName(OMPD_declare_simd) << ClauseName << 0; |
| 462 | IsError = true; |
| 463 | } |
| 464 | P.ConsumeToken(); |
| 465 | SourceLocation RLoc; |
| 466 | SimdLen = P.ParseOpenMPParensExpr(ClauseName, RLoc); |
| 467 | if (SimdLen.isInvalid()) |
| 468 | IsError = true; |
| 469 | } else { |
| 470 | OpenMPClauseKind CKind = getOpenMPClauseKind(ClauseName); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 471 | if (CKind == OMPC_uniform || CKind == OMPC_aligned || |
| 472 | CKind == OMPC_linear) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 473 | Parser::OpenMPVarListDataTy Data; |
| 474 | auto *Vars = &Uniforms; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 475 | if (CKind == OMPC_aligned) |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 476 | Vars = &Aligneds; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 477 | else if (CKind == OMPC_linear) |
| 478 | Vars = &Linears; |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 479 | |
| 480 | P.ConsumeToken(); |
| 481 | if (P.ParseOpenMPVarList(OMPD_declare_simd, |
| 482 | getOpenMPClauseKind(ClauseName), *Vars, Data)) |
| 483 | IsError = true; |
| 484 | if (CKind == OMPC_aligned) |
| 485 | Alignments.append(Aligneds.size() - Alignments.size(), Data.TailExpr); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 486 | else if (CKind == OMPC_linear) { |
| 487 | if (P.getActions().CheckOpenMPLinearModifier(Data.LinKind, |
| 488 | Data.DepLinMapLoc)) |
| 489 | Data.LinKind = OMPC_LINEAR_val; |
| 490 | LinModifiers.append(Linears.size() - LinModifiers.size(), |
| 491 | Data.LinKind); |
| 492 | Steps.append(Linears.size() - Steps.size(), Data.TailExpr); |
| 493 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 494 | } else |
| 495 | // TODO: add parsing of other clauses. |
| 496 | break; |
| 497 | } |
| 498 | // Skip ',' if any. |
| 499 | if (Tok.is(tok::comma)) |
| 500 | P.ConsumeToken(); |
| 501 | } |
| 502 | return IsError; |
| 503 | } |
| 504 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 505 | /// Parse clauses for '#pragma omp declare simd'. |
| 506 | Parser::DeclGroupPtrTy |
| 507 | Parser::ParseOMPDeclareSimdClauses(Parser::DeclGroupPtrTy Ptr, |
| 508 | CachedTokens &Toks, SourceLocation Loc) { |
| 509 | PP.EnterToken(Tok); |
| 510 | PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true); |
| 511 | // Consume the previously pushed token. |
| 512 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
| 513 | |
| 514 | FNContextRAII FnContext(*this, Ptr); |
| 515 | OMPDeclareSimdDeclAttr::BranchStateTy BS = |
| 516 | OMPDeclareSimdDeclAttr::BS_Undefined; |
| 517 | ExprResult Simdlen; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 518 | SmallVector<Expr *, 4> Uniforms; |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 519 | SmallVector<Expr *, 4> Aligneds; |
| 520 | SmallVector<Expr *, 4> Alignments; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 521 | SmallVector<Expr *, 4> Linears; |
| 522 | SmallVector<unsigned, 4> LinModifiers; |
| 523 | SmallVector<Expr *, 4> Steps; |
| 524 | bool IsError = |
| 525 | parseDeclareSimdClauses(*this, BS, Simdlen, Uniforms, Aligneds, |
| 526 | Alignments, Linears, LinModifiers, Steps); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 527 | // Need to check for extra tokens. |
| 528 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 529 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 530 | << getOpenMPDirectiveName(OMPD_declare_simd); |
| 531 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 532 | ConsumeAnyToken(); |
| 533 | } |
| 534 | // Skip the last annot_pragma_openmp_end. |
| 535 | SourceLocation EndLoc = ConsumeToken(); |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 536 | if (!IsError) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 537 | return Actions.ActOnOpenMPDeclareSimdDirective( |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 538 | Ptr, BS, Simdlen.get(), Uniforms, Aligneds, Alignments, Linears, |
| 539 | LinModifiers, Steps, SourceRange(Loc, EndLoc)); |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 540 | } |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 541 | return Ptr; |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 542 | } |
| 543 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 544 | /// \brief Parsing of declarative OpenMP directives. |
| 545 | /// |
| 546 | /// threadprivate-directive: |
| 547 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 548 | /// annot_pragma_openmp_end |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 549 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 550 | /// declare-reduction-directive: |
| 551 | /// annot_pragma_openmp 'declare' 'reduction' [...] |
| 552 | /// annot_pragma_openmp_end |
| 553 | /// |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 554 | /// declare-simd-directive: |
| 555 | /// annot_pragma_openmp 'declare simd' {<clause> [,]} |
| 556 | /// annot_pragma_openmp_end |
| 557 | /// <function declaration/definition> |
| 558 | /// |
| 559 | Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( |
| 560 | AccessSpecifier &AS, ParsedAttributesWithRange &Attrs, |
| 561 | DeclSpec::TST TagType, Decl *Tag) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 562 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 563 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 564 | |
| 565 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 566 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 567 | |
| 568 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 569 | case OMPD_threadprivate: { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 570 | ConsumeToken(); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 571 | ThreadprivateListParserHelper Helper(this); |
| 572 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 573 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 574 | // extra tokens. |
| 575 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 576 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 577 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 578 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 579 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 580 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 581 | ConsumeToken(); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 582 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, |
| 583 | Helper.getIdentifiers()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 584 | } |
| 585 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 586 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 587 | case OMPD_declare_reduction: |
| 588 | ConsumeToken(); |
| 589 | if (auto Res = ParseOpenMPDeclareReductionDirective(AS)) { |
| 590 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 591 | // extra tokens. |
| 592 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 593 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 594 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 595 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 596 | ConsumeAnyToken(); |
| 597 | } |
| 598 | // Skip the last annot_pragma_openmp_end. |
| 599 | ConsumeToken(); |
| 600 | return Res; |
| 601 | } |
| 602 | break; |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 603 | case OMPD_declare_simd: { |
| 604 | // The syntax is: |
| 605 | // { #pragma omp declare simd } |
| 606 | // <function-declaration-or-definition> |
| 607 | // |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 608 | ConsumeToken(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 609 | CachedTokens Toks; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 610 | while(Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 611 | Toks.push_back(Tok); |
| 612 | ConsumeAnyToken(); |
| 613 | } |
| 614 | Toks.push_back(Tok); |
| 615 | ConsumeAnyToken(); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 616 | |
| 617 | DeclGroupPtrTy Ptr; |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 618 | if (Tok.is(tok::annot_pragma_openmp)) |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 619 | Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, TagType, Tag); |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 620 | else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 621 | // Here we expect to see some function declaration. |
| 622 | if (AS == AS_none) { |
| 623 | assert(TagType == DeclSpec::TST_unspecified); |
| 624 | MaybeParseCXX11Attributes(Attrs); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 625 | ParsingDeclSpec PDS(*this); |
| 626 | Ptr = ParseExternalDeclaration(Attrs, &PDS); |
| 627 | } else { |
| 628 | Ptr = |
| 629 | ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag); |
| 630 | } |
| 631 | } |
| 632 | if (!Ptr) { |
| 633 | Diag(Loc, diag::err_omp_decl_in_declare_simd); |
| 634 | return DeclGroupPtrTy(); |
| 635 | } |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 636 | return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 637 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 638 | case OMPD_declare_target: { |
| 639 | SourceLocation DTLoc = ConsumeAnyToken(); |
| 640 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 641 | // OpenMP 4.5 syntax with list of entities. |
| 642 | llvm::SmallSetVector<const NamedDecl*, 16> SameDirectiveDecls; |
| 643 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 644 | OMPDeclareTargetDeclAttr::MapTypeTy MT = |
| 645 | OMPDeclareTargetDeclAttr::MT_To; |
| 646 | if (Tok.is(tok::identifier)) { |
| 647 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 648 | StringRef ClauseName = II->getName(); |
| 649 | // Parse 'to|link' clauses. |
| 650 | if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName, |
| 651 | MT)) { |
| 652 | Diag(Tok, diag::err_omp_declare_target_unexpected_clause) |
| 653 | << ClauseName; |
| 654 | break; |
| 655 | } |
| 656 | ConsumeToken(); |
| 657 | } |
| 658 | auto Callback = [this, MT, &SameDirectiveDecls]( |
| 659 | CXXScopeSpec &SS, DeclarationNameInfo NameInfo) { |
| 660 | Actions.ActOnOpenMPDeclareTargetName(getCurScope(), SS, NameInfo, MT, |
| 661 | SameDirectiveDecls); |
| 662 | }; |
| 663 | if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback, true)) |
| 664 | break; |
| 665 | |
| 666 | // Consume optional ','. |
| 667 | if (Tok.is(tok::comma)) |
| 668 | ConsumeToken(); |
| 669 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 670 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 671 | ConsumeAnyToken(); |
| 672 | return DeclGroupPtrTy(); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 673 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 674 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 675 | // Skip the last annot_pragma_openmp_end. |
| 676 | ConsumeAnyToken(); |
| 677 | |
| 678 | if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc)) |
| 679 | return DeclGroupPtrTy(); |
| 680 | |
| 681 | DKind = ParseOpenMPDirectiveKind(*this); |
| 682 | while (DKind != OMPD_end_declare_target && DKind != OMPD_declare_target && |
| 683 | Tok.isNot(tok::eof) && Tok.isNot(tok::r_brace)) { |
| 684 | ParsedAttributesWithRange attrs(AttrFactory); |
| 685 | MaybeParseCXX11Attributes(attrs); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 686 | ParseExternalDeclaration(attrs); |
| 687 | if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) { |
| 688 | TentativeParsingAction TPA(*this); |
| 689 | ConsumeToken(); |
| 690 | DKind = ParseOpenMPDirectiveKind(*this); |
| 691 | if (DKind != OMPD_end_declare_target) |
| 692 | TPA.Revert(); |
| 693 | else |
| 694 | TPA.Commit(); |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | if (DKind == OMPD_end_declare_target) { |
| 699 | ConsumeAnyToken(); |
| 700 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 701 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 702 | << getOpenMPDirectiveName(OMPD_end_declare_target); |
| 703 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 704 | } |
| 705 | // Skip the last annot_pragma_openmp_end. |
| 706 | ConsumeAnyToken(); |
| 707 | } else { |
| 708 | Diag(Tok, diag::err_expected_end_declare_target); |
| 709 | Diag(DTLoc, diag::note_matching) << "'#pragma omp declare target'"; |
| 710 | } |
| 711 | Actions.ActOnFinishOpenMPDeclareTargetDirective(); |
| 712 | return DeclGroupPtrTy(); |
| 713 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 714 | case OMPD_unknown: |
| 715 | Diag(Tok, diag::err_omp_unknown_directive); |
| 716 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 717 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 718 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 719 | case OMPD_task: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 720 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 721 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 722 | case OMPD_taskwait: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 723 | case OMPD_taskgroup: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 724 | case OMPD_flush: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 725 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 726 | case OMPD_for_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 727 | case OMPD_sections: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 728 | case OMPD_section: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 729 | case OMPD_single: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 730 | case OMPD_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 731 | case OMPD_ordered: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 732 | case OMPD_critical: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 733 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 734 | case OMPD_parallel_for_simd: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 735 | case OMPD_parallel_sections: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 736 | case OMPD_atomic: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 737 | case OMPD_target: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 738 | case OMPD_teams: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 739 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 740 | case OMPD_cancel: |
Samuel Antao | 5b0688e | 2015-07-22 16:02:46 +0000 | [diff] [blame] | 741 | case OMPD_target_data: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 742 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 743 | case OMPD_target_exit_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 744 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 745 | case OMPD_target_parallel_for: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 746 | case OMPD_taskloop: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 747 | case OMPD_taskloop_simd: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 748 | case OMPD_distribute: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 749 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 750 | case OMPD_target_update: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 751 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 752 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 753 | case OMPD_distribute_simd: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 754 | case OMPD_target_parallel_for_simd: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 755 | case OMPD_target_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 756 | case OMPD_teams_distribute: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 757 | case OMPD_teams_distribute_simd: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 758 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 759 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 760 | case OMPD_target_teams: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 761 | case OMPD_target_teams_distribute: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 762 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 763 | case OMPD_target_teams_distribute_parallel_for_simd: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 764 | case OMPD_target_teams_distribute_simd: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 765 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 766 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 767 | break; |
| 768 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 769 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 770 | ConsumeAnyToken(); |
| 771 | ConsumeAnyToken(); |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 772 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 773 | } |
| 774 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 775 | /// \brief Parsing of declarative or executable OpenMP directives. |
| 776 | /// |
| 777 | /// threadprivate-directive: |
| 778 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 779 | /// annot_pragma_openmp_end |
| 780 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 781 | /// declare-reduction-directive: |
| 782 | /// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':' |
| 783 | /// <type> {',' <type>} ':' <expression> ')' ['initializer' '(' |
| 784 | /// ('omp_priv' '=' <expression>|<function_call>) ')'] |
| 785 | /// annot_pragma_openmp_end |
| 786 | /// |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 787 | /// executable-directive: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 788 | /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 789 | /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] | |
| 790 | /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 791 | /// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 792 | /// 'for simd' | 'parallel for simd' | 'target' | 'target data' | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 793 | /// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 794 | /// 'distribute' | 'target enter data' | 'target exit data' | |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 795 | /// 'target parallel' | 'target parallel for' | |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 796 | /// 'target update' | 'distribute parallel for' | |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 797 | /// 'distribute paralle for simd' | 'distribute simd' | |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 798 | /// 'target parallel for simd' | 'target simd' | |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 799 | /// 'teams distribute' | 'teams distribute simd' | |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 800 | /// 'teams distribute parallel for simd' | |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 801 | /// 'teams distribute parallel for' | 'target teams' | |
| 802 | /// 'target teams distribute' | |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 803 | /// 'target teams distribute parallel for' | |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 804 | /// 'target teams distribute parallel for simd' | |
| 805 | /// 'target teams distribute simd' {clause} |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 806 | /// annot_pragma_openmp_end |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 807 | /// |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 808 | StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( |
| 809 | AllowedContsructsKind Allowed) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 810 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 811 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 812 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 813 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 814 | FirstClauses(OMPC_unknown + 1); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 815 | unsigned ScopeFlags = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 816 | Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 817 | SourceLocation Loc = ConsumeToken(), EndLoc; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 818 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 819 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 820 | // Name of critical directive. |
| 821 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 822 | StmtResult Directive = StmtError(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 823 | bool HasAssociatedStatement = true; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 824 | bool FlushHasClause = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 825 | |
| 826 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 827 | case OMPD_threadprivate: { |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 828 | if (Allowed != ACK_Any) { |
| 829 | Diag(Tok, diag::err_omp_immediate_directive) |
| 830 | << getOpenMPDirectiveName(DKind) << 0; |
| 831 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 832 | ConsumeToken(); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 833 | ThreadprivateListParserHelper Helper(this); |
| 834 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Helper, false)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 835 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 836 | // extra tokens. |
| 837 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 838 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 839 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 840 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 841 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 842 | DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective( |
| 843 | Loc, Helper.getIdentifiers()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 844 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 845 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 846 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 847 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 848 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 849 | case OMPD_declare_reduction: |
| 850 | ConsumeToken(); |
| 851 | if (auto Res = ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) { |
| 852 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 853 | // extra tokens. |
| 854 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 855 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 856 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 857 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 858 | ConsumeAnyToken(); |
| 859 | } |
| 860 | ConsumeAnyToken(); |
| 861 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 862 | } else |
| 863 | SkipUntil(tok::annot_pragma_openmp_end); |
| 864 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 865 | case OMPD_flush: |
| 866 | if (PP.LookAhead(0).is(tok::l_paren)) { |
| 867 | FlushHasClause = true; |
| 868 | // Push copy of the current token back to stream to properly parse |
| 869 | // pseudo-clause OMPFlushClause. |
| 870 | PP.EnterToken(Tok); |
| 871 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 872 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 873 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 874 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 875 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 876 | case OMPD_cancel: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 877 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 878 | case OMPD_target_exit_data: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 879 | case OMPD_target_update: |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 880 | if (Allowed == ACK_StatementsOpenMPNonStandalone) { |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 881 | Diag(Tok, diag::err_omp_immediate_directive) |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 882 | << getOpenMPDirectiveName(DKind) << 0; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 883 | } |
| 884 | HasAssociatedStatement = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 885 | // Fall through for further analysis. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 886 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 887 | case OMPD_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 888 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 889 | case OMPD_for_simd: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 890 | case OMPD_sections: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 891 | case OMPD_single: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 892 | case OMPD_section: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 893 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 894 | case OMPD_critical: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 895 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 896 | case OMPD_parallel_for_simd: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 897 | case OMPD_parallel_sections: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 898 | case OMPD_task: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 899 | case OMPD_ordered: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 900 | case OMPD_atomic: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 901 | case OMPD_target: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 902 | case OMPD_teams: |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 903 | case OMPD_taskgroup: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 904 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 905 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 906 | case OMPD_target_parallel_for: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 907 | case OMPD_taskloop: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 908 | case OMPD_taskloop_simd: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 909 | case OMPD_distribute: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 910 | case OMPD_distribute_parallel_for: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 911 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 912 | case OMPD_distribute_simd: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 913 | case OMPD_target_parallel_for_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 914 | case OMPD_target_simd: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 915 | case OMPD_teams_distribute: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 916 | case OMPD_teams_distribute_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 917 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 918 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 919 | case OMPD_target_teams: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 920 | case OMPD_target_teams_distribute: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 921 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 922 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 923 | case OMPD_target_teams_distribute_simd: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 924 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 925 | // Parse directive name of the 'critical' directive if any. |
| 926 | if (DKind == OMPD_critical) { |
| 927 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 928 | tok::annot_pragma_openmp_end); |
| 929 | if (!T.consumeOpen()) { |
| 930 | if (Tok.isAnyIdentifier()) { |
| 931 | DirName = |
| 932 | DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 933 | ConsumeAnyToken(); |
| 934 | } else { |
| 935 | Diag(Tok, diag::err_omp_expected_identifier_for_critical); |
| 936 | } |
| 937 | T.consumeClose(); |
| 938 | } |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 939 | } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 940 | CancelRegion = ParseOpenMPDirectiveKind(*this); |
| 941 | if (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 942 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 943 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 944 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 945 | if (isOpenMPLoopDirective(DKind)) |
| 946 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 947 | if (isOpenMPSimdDirective(DKind)) |
| 948 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 949 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 950 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 951 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 952 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 953 | OpenMPClauseKind CKind = |
| 954 | Tok.isAnnotation() |
| 955 | ? OMPC_unknown |
| 956 | : FlushHasClause ? OMPC_flush |
| 957 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 958 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 959 | FlushHasClause = false; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 960 | OMPClause *Clause = |
| 961 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 962 | FirstClauses[CKind].setInt(true); |
| 963 | if (Clause) { |
| 964 | FirstClauses[CKind].setPointer(Clause); |
| 965 | Clauses.push_back(Clause); |
| 966 | } |
| 967 | |
| 968 | // Skip ',' if any. |
| 969 | if (Tok.is(tok::comma)) |
| 970 | ConsumeToken(); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 971 | Actions.EndOpenMPClause(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 972 | } |
| 973 | // End location of the directive. |
| 974 | EndLoc = Tok.getLocation(); |
| 975 | // Consume final annot_pragma_openmp_end. |
| 976 | ConsumeToken(); |
| 977 | |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 978 | // OpenMP [2.13.8, ordered Construct, Syntax] |
| 979 | // If the depend clause is specified, the ordered construct is a stand-alone |
| 980 | // directive. |
| 981 | if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) { |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 982 | if (Allowed == ACK_StatementsOpenMPNonStandalone) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 983 | Diag(Loc, diag::err_omp_immediate_directive) |
| 984 | << getOpenMPDirectiveName(DKind) << 1 |
| 985 | << getOpenMPClauseName(OMPC_depend); |
| 986 | } |
| 987 | HasAssociatedStatement = false; |
| 988 | } |
| 989 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 990 | StmtResult AssociatedStmt; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 991 | if (HasAssociatedStatement) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 992 | // The body is a block scope like in Lambdas and Blocks. |
| 993 | Sema::CompoundScopeRAII CompoundScope(Actions); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 994 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 995 | Actions.ActOnStartOfCompoundStmt(); |
| 996 | // Parse statement |
| 997 | AssociatedStmt = ParseStatement(); |
| 998 | Actions.ActOnFinishOfCompoundStmt(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 999 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1000 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1001 | Directive = Actions.ActOnOpenMPExecutableDirective( |
| 1002 | DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc, |
| 1003 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1004 | |
| 1005 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1006 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1007 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1008 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1009 | } |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1010 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1011 | case OMPD_declare_target: |
| 1012 | case OMPD_end_declare_target: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1013 | Diag(Tok, diag::err_omp_unexpected_directive) |
| 1014 | << getOpenMPDirectiveName(DKind); |
| 1015 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1016 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1017 | case OMPD_unknown: |
| 1018 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1019 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1020 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1021 | } |
| 1022 | return Directive; |
| 1023 | } |
| 1024 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1025 | // Parses simple list: |
| 1026 | // simple-variable-list: |
| 1027 | // '(' id-expression {, id-expression} ')' |
| 1028 | // |
| 1029 | bool Parser::ParseOpenMPSimpleVarList( |
| 1030 | OpenMPDirectiveKind Kind, |
| 1031 | const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> & |
| 1032 | Callback, |
| 1033 | bool AllowScopeSpecifier) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1034 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1035 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1036 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1037 | getOpenMPDirectiveName(Kind))) |
| 1038 | return true; |
| 1039 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1040 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1041 | |
| 1042 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1043 | while (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1044 | CXXScopeSpec SS; |
| 1045 | SourceLocation TemplateKWLoc; |
| 1046 | UnqualifiedId Name; |
| 1047 | // Read var name. |
| 1048 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1049 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1050 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1051 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 1052 | ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1053 | IsCorrect = false; |
| 1054 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1055 | StopBeforeMatch); |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 1056 | } else if (ParseUnqualifiedId(SS, false, false, false, nullptr, |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1057 | TemplateKWLoc, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1058 | IsCorrect = false; |
| 1059 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1060 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1061 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 1062 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1063 | IsCorrect = false; |
| 1064 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1065 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1066 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 1067 | << tok::identifier |
| 1068 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1069 | } else { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1070 | Callback(SS, Actions.GetNameFromUnqualifiedId(Name)); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1071 | } |
| 1072 | // Consume ','. |
| 1073 | if (Tok.is(tok::comma)) { |
| 1074 | ConsumeToken(); |
| 1075 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1076 | } |
| 1077 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1078 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 1079 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1080 | IsCorrect = false; |
| 1081 | } |
| 1082 | |
| 1083 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1084 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1085 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1086 | return !IsCorrect; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1087 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1088 | |
| 1089 | /// \brief Parsing of OpenMP clauses. |
| 1090 | /// |
| 1091 | /// clause: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1092 | /// if-clause | final-clause | num_threads-clause | safelen-clause | |
| 1093 | /// default-clause | private-clause | firstprivate-clause | shared-clause |
| 1094 | /// | linear-clause | aligned-clause | collapse-clause | |
| 1095 | /// lastprivate-clause | reduction-clause | proc_bind-clause | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 1096 | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 1097 | /// mergeable-clause | flush-clause | read-clause | write-clause | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1098 | /// update-clause | capture-clause | seq_cst-clause | device-clause | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1099 | /// simdlen-clause | threads-clause | simd-clause | num_teams-clause | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1100 | /// thread_limit-clause | priority-clause | grainsize-clause | |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1101 | /// nogroup-clause | num_tasks-clause | hint-clause | to-clause | |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 1102 | /// from-clause | is_device_ptr-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1103 | /// |
| 1104 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 1105 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1106 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1107 | bool ErrorFound = false; |
| 1108 | // Check if clause is allowed for the given directive. |
| 1109 | if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1110 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 1111 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1112 | ErrorFound = true; |
| 1113 | } |
| 1114 | |
| 1115 | switch (CKind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1116 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1117 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1118 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1119 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1120 | case OMPC_collapse: |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1121 | case OMPC_ordered: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1122 | case OMPC_device: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1123 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1124 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1125 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1126 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1127 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1128 | case OMPC_hint: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1129 | // OpenMP [2.5, Restrictions] |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 1130 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1131 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1132 | // Only one safelen clause can appear on a simd directive. |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1133 | // Only one simdlen clause can appear on a simd directive. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1134 | // Only one collapse clause can appear on a simd directive. |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 1135 | // OpenMP [2.9.1, target data construct, Restrictions] |
| 1136 | // At most one device clause can appear on the directive. |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1137 | // OpenMP [2.11.1, task Construct, Restrictions] |
| 1138 | // At most one if clause can appear on the directive. |
| 1139 | // At most one final clause can appear on the directive. |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 1140 | // OpenMP [teams Construct, Restrictions] |
| 1141 | // At most one num_teams clause can appear on the directive. |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 1142 | // At most one thread_limit clause can appear on the directive. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1143 | // OpenMP [2.9.1, task Construct, Restrictions] |
| 1144 | // At most one priority clause can appear on the directive. |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1145 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 1146 | // At most one grainsize clause can appear on the directive. |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1147 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 1148 | // At most one num_tasks clause can appear on the directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1149 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1150 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1151 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1152 | ErrorFound = true; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1153 | } |
| 1154 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 1155 | if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren)) |
| 1156 | Clause = ParseOpenMPClause(CKind); |
| 1157 | else |
| 1158 | Clause = ParseOpenMPSingleExprClause(CKind); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1159 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1160 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1161 | case OMPC_proc_bind: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1162 | // OpenMP [2.14.3.1, Restrictions] |
| 1163 | // Only a single default clause may be specified on a parallel, task or |
| 1164 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1165 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 1166 | // At most one proc_bind clause can appear on the directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1167 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1168 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1169 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1170 | ErrorFound = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | Clause = ParseOpenMPSimpleClause(CKind); |
| 1174 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1175 | case OMPC_schedule: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1176 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1177 | case OMPC_defaultmap: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1178 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 1179 | // Only one schedule clause can appear on a loop directive. |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1180 | // OpenMP [2.10.4, Restrictions, p. 106] |
| 1181 | // At most one defaultmap clause can appear on the directive. |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1182 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1183 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1184 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1185 | ErrorFound = true; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1188 | case OMPC_if: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1189 | Clause = ParseOpenMPSingleExprWithArgClause(CKind); |
| 1190 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1191 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 1192 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 1193 | case OMPC_mergeable: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 1194 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1195 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 1196 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 1197 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 1198 | case OMPC_seq_cst: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 1199 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1200 | case OMPC_simd: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 1201 | case OMPC_nogroup: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1202 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 1203 | // Only one ordered clause can appear on a loop directive. |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1204 | // OpenMP [2.7.1, Restrictions, C/C++, p. 4] |
| 1205 | // Only one nowait clause can appear on a for directive. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1206 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1207 | Diag(Tok, diag::err_omp_more_one_clause) |
| 1208 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 1209 | ErrorFound = true; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | Clause = ParseOpenMPClause(CKind); |
| 1213 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1214 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1215 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1216 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1217 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1218 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1219 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1220 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 1221 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1222 | case OMPC_copyprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1223 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1224 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1225 | case OMPC_map: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 1226 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1227 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 1228 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 1229 | case OMPC_is_device_ptr: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1230 | Clause = ParseOpenMPVarListClause(DKind, CKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1231 | break; |
| 1232 | case OMPC_unknown: |
| 1233 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1234 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1235 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1236 | break; |
| 1237 | case OMPC_threadprivate: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1238 | case OMPC_uniform: |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1239 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 1240 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1241 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1242 | break; |
| 1243 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1244 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1245 | } |
| 1246 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1247 | /// Parses simple expression in parens for single-expression clauses of OpenMP |
| 1248 | /// constructs. |
| 1249 | /// \param RLoc Returned location of right paren. |
| 1250 | ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName, |
| 1251 | SourceLocation &RLoc) { |
| 1252 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 1253 | if (T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data())) |
| 1254 | return ExprError(); |
| 1255 | |
| 1256 | SourceLocation ELoc = Tok.getLocation(); |
| 1257 | ExprResult LHS(ParseCastExpression( |
| 1258 | /*isUnaryExpression=*/false, /*isAddressOfOperand=*/false, NotTypeCast)); |
| 1259 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
| 1260 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc); |
| 1261 | |
| 1262 | // Parse ')'. |
| 1263 | T.consumeClose(); |
| 1264 | |
| 1265 | RLoc = T.getCloseLocation(); |
| 1266 | return Val; |
| 1267 | } |
| 1268 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1269 | /// \brief Parsing of OpenMP clauses with single expressions like 'final', |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1270 | /// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams', |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1271 | /// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1272 | /// |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 1273 | /// final-clause: |
| 1274 | /// 'final' '(' expression ')' |
| 1275 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 1276 | /// num_threads-clause: |
| 1277 | /// 'num_threads' '(' expression ')' |
| 1278 | /// |
| 1279 | /// safelen-clause: |
| 1280 | /// 'safelen' '(' expression ')' |
| 1281 | /// |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 1282 | /// simdlen-clause: |
| 1283 | /// 'simdlen' '(' expression ')' |
| 1284 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 1285 | /// collapse-clause: |
| 1286 | /// 'collapse' '(' expression ')' |
| 1287 | /// |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 1288 | /// priority-clause: |
| 1289 | /// 'priority' '(' expression ')' |
| 1290 | /// |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 1291 | /// grainsize-clause: |
| 1292 | /// 'grainsize' '(' expression ')' |
| 1293 | /// |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 1294 | /// num_tasks-clause: |
| 1295 | /// 'num_tasks' '(' expression ')' |
| 1296 | /// |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 1297 | /// hint-clause: |
| 1298 | /// 'hint' '(' expression ')' |
| 1299 | /// |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1300 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { |
| 1301 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1302 | SourceLocation LLoc = Tok.getLocation(); |
| 1303 | SourceLocation RLoc; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1304 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1305 | ExprResult Val = ParseOpenMPParensExpr(getOpenMPClauseName(Kind), RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1306 | |
| 1307 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1308 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1309 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1310 | return Actions.ActOnOpenMPSingleExprClause(Kind, Val.get(), Loc, LLoc, RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 1311 | } |
| 1312 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1313 | /// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1314 | /// |
| 1315 | /// default-clause: |
| 1316 | /// 'default' '(' 'none' | 'shared' ') |
| 1317 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 1318 | /// proc_bind-clause: |
| 1319 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 1320 | /// |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1321 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) { |
| 1322 | SourceLocation Loc = Tok.getLocation(); |
| 1323 | SourceLocation LOpen = ConsumeToken(); |
| 1324 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1325 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1326 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1327 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1328 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1329 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1330 | unsigned Type = getOpenMPSimpleClauseType( |
| 1331 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1332 | SourceLocation TypeLoc = Tok.getLocation(); |
| 1333 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1334 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1335 | ConsumeAnyToken(); |
| 1336 | |
| 1337 | // Parse ')'. |
| 1338 | T.consumeClose(); |
| 1339 | |
| 1340 | return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, |
| 1341 | Tok.getLocation()); |
| 1342 | } |
| 1343 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1344 | /// \brief Parsing of OpenMP clauses like 'ordered'. |
| 1345 | /// |
| 1346 | /// ordered-clause: |
| 1347 | /// 'ordered' |
| 1348 | /// |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 1349 | /// nowait-clause: |
| 1350 | /// 'nowait' |
| 1351 | /// |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 1352 | /// untied-clause: |
| 1353 | /// 'untied' |
| 1354 | /// |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 1355 | /// mergeable-clause: |
| 1356 | /// 'mergeable' |
| 1357 | /// |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 1358 | /// read-clause: |
| 1359 | /// 'read' |
| 1360 | /// |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 1361 | /// threads-clause: |
| 1362 | /// 'threads' |
| 1363 | /// |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 1364 | /// simd-clause: |
| 1365 | /// 'simd' |
| 1366 | /// |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 1367 | /// nogroup-clause: |
| 1368 | /// 'nogroup' |
| 1369 | /// |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 1370 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) { |
| 1371 | SourceLocation Loc = Tok.getLocation(); |
| 1372 | ConsumeAnyToken(); |
| 1373 | |
| 1374 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 1375 | } |
| 1376 | |
| 1377 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1378 | /// \brief Parsing of OpenMP clauses with single expressions and some additional |
| 1379 | /// argument like 'schedule' or 'dist_schedule'. |
| 1380 | /// |
| 1381 | /// schedule-clause: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1382 | /// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ] |
| 1383 | /// ')' |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1384 | /// |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1385 | /// if-clause: |
| 1386 | /// 'if' '(' [ directive-name-modifier ':' ] expression ')' |
| 1387 | /// |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1388 | /// defaultmap: |
| 1389 | /// 'defaultmap' '(' modifier ':' kind ')' |
| 1390 | /// |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1391 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) { |
| 1392 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1393 | SourceLocation DelimLoc; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1394 | // Parse '('. |
| 1395 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 1396 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1397 | getOpenMPClauseName(Kind))) |
| 1398 | return nullptr; |
| 1399 | |
| 1400 | ExprResult Val; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1401 | SmallVector<unsigned, 4> Arg; |
| 1402 | SmallVector<SourceLocation, 4> KLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1403 | if (Kind == OMPC_schedule) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1404 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 1405 | Arg.resize(NumberOfElements); |
| 1406 | KLoc.resize(NumberOfElements); |
| 1407 | Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 1408 | Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 1409 | Arg[ScheduleKind] = OMPC_SCHEDULE_unknown; |
| 1410 | auto KindModifier = getOpenMPSimpleClauseType( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1411 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1412 | if (KindModifier > OMPC_SCHEDULE_unknown) { |
| 1413 | // Parse 'modifier' |
| 1414 | Arg[Modifier1] = KindModifier; |
| 1415 | KLoc[Modifier1] = Tok.getLocation(); |
| 1416 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1417 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1418 | ConsumeAnyToken(); |
| 1419 | if (Tok.is(tok::comma)) { |
| 1420 | // Parse ',' 'modifier' |
| 1421 | ConsumeAnyToken(); |
| 1422 | KindModifier = getOpenMPSimpleClauseType( |
| 1423 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 1424 | Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown |
| 1425 | ? KindModifier |
Aaron Ballman | ad8a104 | 2015-12-28 15:52:46 +0000 | [diff] [blame] | 1426 | : (unsigned)OMPC_SCHEDULE_unknown; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1427 | KLoc[Modifier2] = Tok.getLocation(); |
| 1428 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1429 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1430 | ConsumeAnyToken(); |
| 1431 | } |
| 1432 | // Parse ':' |
| 1433 | if (Tok.is(tok::colon)) |
| 1434 | ConsumeAnyToken(); |
| 1435 | else |
| 1436 | Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier"; |
| 1437 | KindModifier = getOpenMPSimpleClauseType( |
| 1438 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 1439 | } |
| 1440 | Arg[ScheduleKind] = KindModifier; |
| 1441 | KLoc[ScheduleKind] = Tok.getLocation(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1442 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1443 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1444 | ConsumeAnyToken(); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1445 | if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static || |
| 1446 | Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic || |
| 1447 | Arg[ScheduleKind] == OMPC_SCHEDULE_guided) && |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1448 | Tok.is(tok::comma)) |
| 1449 | DelimLoc = ConsumeAnyToken(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1450 | } else if (Kind == OMPC_dist_schedule) { |
| 1451 | Arg.push_back(getOpenMPSimpleClauseType( |
| 1452 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 1453 | KLoc.push_back(Tok.getLocation()); |
| 1454 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1455 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1456 | ConsumeAnyToken(); |
| 1457 | if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma)) |
| 1458 | DelimLoc = ConsumeAnyToken(); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 1459 | } else if (Kind == OMPC_defaultmap) { |
| 1460 | // Get a defaultmap modifier |
| 1461 | Arg.push_back(getOpenMPSimpleClauseType( |
| 1462 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 1463 | KLoc.push_back(Tok.getLocation()); |
| 1464 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1465 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1466 | ConsumeAnyToken(); |
| 1467 | // Parse ':' |
| 1468 | if (Tok.is(tok::colon)) |
| 1469 | ConsumeAnyToken(); |
| 1470 | else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown) |
| 1471 | Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier"; |
| 1472 | // Get a defaultmap kind |
| 1473 | Arg.push_back(getOpenMPSimpleClauseType( |
| 1474 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 1475 | KLoc.push_back(Tok.getLocation()); |
| 1476 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1477 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1478 | ConsumeAnyToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1479 | } else { |
| 1480 | assert(Kind == OMPC_if); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1481 | KLoc.push_back(Tok.getLocation()); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 1482 | TentativeParsingAction TPA(*this); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 1483 | Arg.push_back(ParseOpenMPDirectiveKind(*this)); |
| 1484 | if (Arg.back() != OMPD_unknown) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1485 | ConsumeToken(); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 1486 | if (Tok.is(tok::colon) && getLangOpts().OpenMP > 40) { |
| 1487 | TPA.Commit(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1488 | DelimLoc = ConsumeToken(); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 1489 | } else { |
| 1490 | TPA.Revert(); |
| 1491 | Arg.back() = OMPD_unknown; |
| 1492 | } |
| 1493 | } else |
| 1494 | TPA.Revert(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1495 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1496 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 1497 | bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) || |
| 1498 | (Kind == OMPC_dist_schedule && DelimLoc.isValid()) || |
| 1499 | Kind == OMPC_if; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1500 | if (NeedAnExpression) { |
| 1501 | SourceLocation ELoc = Tok.getLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1502 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 1503 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1504 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | // Parse ')'. |
| 1508 | T.consumeClose(); |
| 1509 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1510 | if (NeedAnExpression && Val.isInvalid()) |
| 1511 | return nullptr; |
| 1512 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1513 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1514 | Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 1515 | T.getCloseLocation()); |
| 1516 | } |
| 1517 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1518 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 1519 | UnqualifiedId &ReductionId) { |
| 1520 | SourceLocation TemplateKWLoc; |
| 1521 | if (ReductionIdScopeSpec.isEmpty()) { |
| 1522 | auto OOK = OO_None; |
| 1523 | switch (P.getCurToken().getKind()) { |
| 1524 | case tok::plus: |
| 1525 | OOK = OO_Plus; |
| 1526 | break; |
| 1527 | case tok::minus: |
| 1528 | OOK = OO_Minus; |
| 1529 | break; |
| 1530 | case tok::star: |
| 1531 | OOK = OO_Star; |
| 1532 | break; |
| 1533 | case tok::amp: |
| 1534 | OOK = OO_Amp; |
| 1535 | break; |
| 1536 | case tok::pipe: |
| 1537 | OOK = OO_Pipe; |
| 1538 | break; |
| 1539 | case tok::caret: |
| 1540 | OOK = OO_Caret; |
| 1541 | break; |
| 1542 | case tok::ampamp: |
| 1543 | OOK = OO_AmpAmp; |
| 1544 | break; |
| 1545 | case tok::pipepipe: |
| 1546 | OOK = OO_PipePipe; |
| 1547 | break; |
| 1548 | default: |
| 1549 | break; |
| 1550 | } |
| 1551 | if (OOK != OO_None) { |
| 1552 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 1553 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1554 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 1555 | return false; |
| 1556 | } |
| 1557 | } |
| 1558 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 1559 | /*AllowDestructorName*/ false, |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 1560 | /*AllowConstructorName*/ false, nullptr, |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1561 | TemplateKWLoc, ReductionId); |
| 1562 | } |
| 1563 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1564 | /// Parses clauses with list. |
| 1565 | bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, |
| 1566 | OpenMPClauseKind Kind, |
| 1567 | SmallVectorImpl<Expr *> &Vars, |
| 1568 | OpenMPVarListDataTy &Data) { |
| 1569 | UnqualifiedId UnqualifiedReductionId; |
| 1570 | bool InvalidReductionId = false; |
| 1571 | bool MapTypeModifierSpecified = false; |
| 1572 | |
| 1573 | // Parse '('. |
| 1574 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 1575 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1576 | getOpenMPClauseName(Kind))) |
| 1577 | return true; |
| 1578 | |
| 1579 | bool NeedRParenForLinear = false; |
| 1580 | BalancedDelimiterTracker LinearT(*this, tok::l_paren, |
| 1581 | tok::annot_pragma_openmp_end); |
| 1582 | // Handle reduction-identifier for reduction clause. |
| 1583 | if (Kind == OMPC_reduction) { |
| 1584 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1585 | if (getLangOpts().CPlusPlus) |
| 1586 | ParseOptionalCXXScopeSpecifier(Data.ReductionIdScopeSpec, |
| 1587 | /*ObjectType=*/nullptr, |
| 1588 | /*EnteringContext=*/false); |
| 1589 | InvalidReductionId = ParseReductionId(*this, Data.ReductionIdScopeSpec, |
| 1590 | UnqualifiedReductionId); |
| 1591 | if (InvalidReductionId) { |
| 1592 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1593 | StopBeforeMatch); |
| 1594 | } |
| 1595 | if (Tok.is(tok::colon)) |
| 1596 | Data.ColonLoc = ConsumeToken(); |
| 1597 | else |
| 1598 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 1599 | if (!InvalidReductionId) |
| 1600 | Data.ReductionId = |
| 1601 | Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId); |
| 1602 | } else if (Kind == OMPC_depend) { |
| 1603 | // Handle dependency type for depend clause. |
| 1604 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1605 | Data.DepKind = |
| 1606 | static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType( |
| 1607 | Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : "")); |
| 1608 | Data.DepLinMapLoc = Tok.getLocation(); |
| 1609 | |
| 1610 | if (Data.DepKind == OMPC_DEPEND_unknown) { |
| 1611 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1612 | StopBeforeMatch); |
| 1613 | } else { |
| 1614 | ConsumeToken(); |
| 1615 | // Special processing for depend(source) clause. |
| 1616 | if (DKind == OMPD_ordered && Data.DepKind == OMPC_DEPEND_source) { |
| 1617 | // Parse ')'. |
| 1618 | T.consumeClose(); |
| 1619 | return false; |
| 1620 | } |
| 1621 | } |
| 1622 | if (Tok.is(tok::colon)) |
| 1623 | Data.ColonLoc = ConsumeToken(); |
| 1624 | else { |
| 1625 | Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren |
| 1626 | : diag::warn_pragma_expected_colon) |
| 1627 | << "dependency type"; |
| 1628 | } |
| 1629 | } else if (Kind == OMPC_linear) { |
| 1630 | // Try to parse modifier if any. |
| 1631 | if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) { |
| 1632 | Data.LinKind = static_cast<OpenMPLinearClauseKind>( |
| 1633 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
| 1634 | Data.DepLinMapLoc = ConsumeToken(); |
| 1635 | LinearT.consumeOpen(); |
| 1636 | NeedRParenForLinear = true; |
| 1637 | } |
| 1638 | } else if (Kind == OMPC_map) { |
| 1639 | // Handle map type for map clause. |
| 1640 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1641 | |
| 1642 | /// The map clause modifier token can be either a identifier or the C++ |
| 1643 | /// delete keyword. |
| 1644 | auto &&IsMapClauseModifierToken = [](const Token &Tok) -> bool { |
| 1645 | return Tok.isOneOf(tok::identifier, tok::kw_delete); |
| 1646 | }; |
| 1647 | |
| 1648 | // The first identifier may be a list item, a map-type or a |
| 1649 | // map-type-modifier. The map modifier can also be delete which has the same |
| 1650 | // spelling of the C++ delete keyword. |
| 1651 | Data.MapType = |
| 1652 | IsMapClauseModifierToken(Tok) |
| 1653 | ? static_cast<OpenMPMapClauseKind>( |
| 1654 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))) |
| 1655 | : OMPC_MAP_unknown; |
| 1656 | Data.DepLinMapLoc = Tok.getLocation(); |
| 1657 | bool ColonExpected = false; |
| 1658 | |
| 1659 | if (IsMapClauseModifierToken(Tok)) { |
| 1660 | if (PP.LookAhead(0).is(tok::colon)) { |
| 1661 | if (Data.MapType == OMPC_MAP_unknown) |
| 1662 | Diag(Tok, diag::err_omp_unknown_map_type); |
| 1663 | else if (Data.MapType == OMPC_MAP_always) |
| 1664 | Diag(Tok, diag::err_omp_map_type_missing); |
| 1665 | ConsumeToken(); |
| 1666 | } else if (PP.LookAhead(0).is(tok::comma)) { |
| 1667 | if (IsMapClauseModifierToken(PP.LookAhead(1)) && |
| 1668 | PP.LookAhead(2).is(tok::colon)) { |
| 1669 | Data.MapTypeModifier = Data.MapType; |
| 1670 | if (Data.MapTypeModifier != OMPC_MAP_always) { |
| 1671 | Diag(Tok, diag::err_omp_unknown_map_type_modifier); |
| 1672 | Data.MapTypeModifier = OMPC_MAP_unknown; |
| 1673 | } else |
| 1674 | MapTypeModifierSpecified = true; |
| 1675 | |
| 1676 | ConsumeToken(); |
| 1677 | ConsumeToken(); |
| 1678 | |
| 1679 | Data.MapType = |
| 1680 | IsMapClauseModifierToken(Tok) |
| 1681 | ? static_cast<OpenMPMapClauseKind>( |
| 1682 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))) |
| 1683 | : OMPC_MAP_unknown; |
| 1684 | if (Data.MapType == OMPC_MAP_unknown || |
| 1685 | Data.MapType == OMPC_MAP_always) |
| 1686 | Diag(Tok, diag::err_omp_unknown_map_type); |
| 1687 | ConsumeToken(); |
| 1688 | } else { |
| 1689 | Data.MapType = OMPC_MAP_tofrom; |
| 1690 | Data.IsMapTypeImplicit = true; |
| 1691 | } |
| 1692 | } else { |
| 1693 | Data.MapType = OMPC_MAP_tofrom; |
| 1694 | Data.IsMapTypeImplicit = true; |
| 1695 | } |
| 1696 | } else { |
| 1697 | Data.MapType = OMPC_MAP_tofrom; |
| 1698 | Data.IsMapTypeImplicit = true; |
| 1699 | } |
| 1700 | |
| 1701 | if (Tok.is(tok::colon)) |
| 1702 | Data.ColonLoc = ConsumeToken(); |
| 1703 | else if (ColonExpected) |
| 1704 | Diag(Tok, diag::warn_pragma_expected_colon) << "map type"; |
| 1705 | } |
| 1706 | |
| 1707 | bool IsComma = |
| 1708 | (Kind != OMPC_reduction && Kind != OMPC_depend && Kind != OMPC_map) || |
| 1709 | (Kind == OMPC_reduction && !InvalidReductionId) || |
| 1710 | (Kind == OMPC_map && Data.MapType != OMPC_MAP_unknown && |
| 1711 | (!MapTypeModifierSpecified || |
| 1712 | Data.MapTypeModifier == OMPC_MAP_always)) || |
| 1713 | (Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown); |
| 1714 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
| 1715 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
| 1716 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
| 1717 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
| 1718 | // Parse variable |
| 1719 | ExprResult VarExpr = |
| 1720 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
| 1721 | if (VarExpr.isUsable()) |
| 1722 | Vars.push_back(VarExpr.get()); |
| 1723 | else { |
| 1724 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1725 | StopBeforeMatch); |
| 1726 | } |
| 1727 | // Skip ',' if any |
| 1728 | IsComma = Tok.is(tok::comma); |
| 1729 | if (IsComma) |
| 1730 | ConsumeToken(); |
| 1731 | else if (Tok.isNot(tok::r_paren) && |
| 1732 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 1733 | (!MayHaveTail || Tok.isNot(tok::colon))) |
| 1734 | Diag(Tok, diag::err_omp_expected_punc) |
| 1735 | << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush) |
| 1736 | : getOpenMPClauseName(Kind)) |
| 1737 | << (Kind == OMPC_flush); |
| 1738 | } |
| 1739 | |
| 1740 | // Parse ')' for linear clause with modifier. |
| 1741 | if (NeedRParenForLinear) |
| 1742 | LinearT.consumeClose(); |
| 1743 | |
| 1744 | // Parse ':' linear-step (or ':' alignment). |
| 1745 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 1746 | if (MustHaveTail) { |
| 1747 | Data.ColonLoc = Tok.getLocation(); |
| 1748 | SourceLocation ELoc = ConsumeToken(); |
| 1749 | ExprResult Tail = ParseAssignmentExpression(); |
| 1750 | Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc); |
| 1751 | if (Tail.isUsable()) |
| 1752 | Data.TailExpr = Tail.get(); |
| 1753 | else |
| 1754 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1755 | StopBeforeMatch); |
| 1756 | } |
| 1757 | |
| 1758 | // Parse ')'. |
| 1759 | T.consumeClose(); |
| 1760 | if ((Kind == OMPC_depend && Data.DepKind != OMPC_DEPEND_unknown && |
| 1761 | Vars.empty()) || |
| 1762 | (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) || |
| 1763 | (MustHaveTail && !Data.TailExpr) || InvalidReductionId) |
| 1764 | return true; |
| 1765 | return false; |
| 1766 | } |
| 1767 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1768 | /// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1769 | /// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1770 | /// |
| 1771 | /// private-clause: |
| 1772 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 1773 | /// firstprivate-clause: |
| 1774 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 1775 | /// lastprivate-clause: |
| 1776 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1777 | /// shared-clause: |
| 1778 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1779 | /// linear-clause: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1780 | /// 'linear' '(' linear-list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1781 | /// aligned-clause: |
| 1782 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1783 | /// reduction-clause: |
| 1784 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1785 | /// copyprivate-clause: |
| 1786 | /// 'copyprivate' '(' list ')' |
| 1787 | /// flush-clause: |
| 1788 | /// 'flush' '(' list ')' |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1789 | /// depend-clause: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1790 | /// 'depend' '(' in | out | inout : list | source ')' |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1791 | /// map-clause: |
| 1792 | /// 'map' '(' [ [ always , ] |
| 1793 | /// to | from | tofrom | alloc | release | delete ':' ] list ')'; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 1794 | /// to-clause: |
| 1795 | /// 'to' '(' list ')' |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 1796 | /// from-clause: |
| 1797 | /// 'from' '(' list ')' |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 1798 | /// use_device_ptr-clause: |
| 1799 | /// 'use_device_ptr' '(' list ')' |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 1800 | /// is_device_ptr-clause: |
| 1801 | /// 'is_device_ptr' '(' list ')' |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1802 | /// |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1803 | /// For 'linear' clause linear-list may have the following forms: |
| 1804 | /// list |
| 1805 | /// modifier(list) |
| 1806 | /// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++). |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1807 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, |
| 1808 | OpenMPClauseKind Kind) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1809 | SourceLocation Loc = Tok.getLocation(); |
| 1810 | SourceLocation LOpen = ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1811 | SmallVector<Expr *, 4> Vars; |
| 1812 | OpenMPVarListDataTy Data; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1813 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1814 | if (ParseOpenMPVarList(DKind, Kind, Vars, Data)) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1815 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1816 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1817 | return Actions.ActOnOpenMPVarListClause( |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1818 | Kind, Vars, Data.TailExpr, Loc, LOpen, Data.ColonLoc, Tok.getLocation(), |
| 1819 | Data.ReductionIdScopeSpec, Data.ReductionId, Data.DepKind, Data.LinKind, |
| 1820 | Data.MapTypeModifier, Data.MapType, Data.IsMapTypeImplicit, |
| 1821 | Data.DepLinMapLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1822 | } |
| 1823 | |