Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1 | //===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | /// \file |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 9 | /// This file implements parsing of all OpenMP directives and clauses. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 10 | /// |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 13 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 14 | #include "clang/AST/StmtOpenMP.h" |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 15 | #include "clang/Basic/OpenMPKinds.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 16 | #include "clang/Parse/ParseDiagnostic.h" |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 17 | #include "clang/Parse/Parser.h" |
Vassil Vassilev | 11ad339 | 2017-03-23 15:11:07 +0000 | [diff] [blame] | 18 | #include "clang/Parse/RAIIObjectsForParser.h" |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 19 | #include "clang/Sema/Scope.h" |
| 20 | #include "llvm/ADT/PointerIntPair.h" |
Alexey Bataev | 4513e93f | 2019-10-10 15:15:26 +0000 | [diff] [blame] | 21 | #include "llvm/ADT/UniqueVector.h" |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 22 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 23 | using namespace clang; |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 24 | using namespace llvm::omp; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 25 | |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | // OpenMP declarative directives. |
| 28 | //===----------------------------------------------------------------------===// |
| 29 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 30 | namespace { |
| 31 | enum OpenMPDirectiveKindEx { |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 32 | OMPD_cancellation = unsigned(OMPD_unknown) + 1, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 33 | OMPD_data, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 34 | OMPD_declare, |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 35 | OMPD_end, |
| 36 | OMPD_end_declare, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 37 | OMPD_enter, |
| 38 | OMPD_exit, |
| 39 | OMPD_point, |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 40 | OMPD_reduction, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 41 | OMPD_target_enter, |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 42 | OMPD_target_exit, |
| 43 | OMPD_update, |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 44 | OMPD_distribute_parallel, |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 45 | OMPD_teams_distribute_parallel, |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 46 | OMPD_target_teams_distribute_parallel, |
| 47 | OMPD_mapper, |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 48 | OMPD_variant, |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 49 | }; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 50 | |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 51 | // Helper to unify the enum class OpenMPDirectiveKind with its extension |
| 52 | // the OpenMPDirectiveKindEx enum which allows to use them together as if they |
| 53 | // are unsigned values. |
| 54 | struct OpenMPDirectiveKindExWrapper { |
| 55 | OpenMPDirectiveKindExWrapper(unsigned Value) : Value(Value) {} |
| 56 | OpenMPDirectiveKindExWrapper(OpenMPDirectiveKind DK) : Value(unsigned(DK)) {} |
| 57 | bool operator==(OpenMPDirectiveKind V) const { return Value == unsigned(V); } |
| 58 | bool operator!=(OpenMPDirectiveKind V) const { return Value != unsigned(V); } |
| 59 | bool operator<(OpenMPDirectiveKind V) const { return Value < unsigned(V); } |
| 60 | operator unsigned() const { return Value; } |
| 61 | operator OpenMPDirectiveKind() const { return OpenMPDirectiveKind(Value); } |
| 62 | unsigned Value; |
| 63 | }; |
| 64 | |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 65 | class DeclDirectiveListParserHelper final { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 66 | SmallVector<Expr *, 4> Identifiers; |
| 67 | Parser *P; |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 68 | OpenMPDirectiveKind Kind; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 69 | |
| 70 | public: |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 71 | DeclDirectiveListParserHelper(Parser *P, OpenMPDirectiveKind Kind) |
| 72 | : P(P), Kind(Kind) {} |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 73 | void operator()(CXXScopeSpec &SS, DeclarationNameInfo NameInfo) { |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 74 | ExprResult Res = P->getActions().ActOnOpenMPIdExpression( |
| 75 | P->getCurScope(), SS, NameInfo, Kind); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 76 | if (Res.isUsable()) |
| 77 | Identifiers.push_back(Res.get()); |
| 78 | } |
| 79 | llvm::ArrayRef<Expr *> getIdentifiers() const { return Identifiers; } |
| 80 | }; |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 81 | } // namespace |
| 82 | |
| 83 | // Map token string to extended OMP token kind that are |
| 84 | // OpenMPDirectiveKind + OpenMPDirectiveKindEx. |
| 85 | static unsigned getOpenMPDirectiveKindEx(StringRef S) { |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 86 | OpenMPDirectiveKindExWrapper DKind = getOpenMPDirectiveKind(S); |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 87 | if (DKind != OMPD_unknown) |
| 88 | return DKind; |
| 89 | |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 90 | return llvm::StringSwitch<OpenMPDirectiveKindExWrapper>(S) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 91 | .Case("cancellation", OMPD_cancellation) |
| 92 | .Case("data", OMPD_data) |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 93 | .Case("declare", OMPD_declare) |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 94 | .Case("end", OMPD_end) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 95 | .Case("enter", OMPD_enter) |
| 96 | .Case("exit", OMPD_exit) |
| 97 | .Case("point", OMPD_point) |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 98 | .Case("reduction", OMPD_reduction) |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 99 | .Case("update", OMPD_update) |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 100 | .Case("mapper", OMPD_mapper) |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 101 | .Case("variant", OMPD_variant) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 102 | .Default(OMPD_unknown); |
| 103 | } |
| 104 | |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 105 | static OpenMPDirectiveKindExWrapper parseOpenMPDirectiveKind(Parser &P) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 106 | // Array of foldings: F[i][0] F[i][1] ===> F[i][2]. |
| 107 | // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd |
| 108 | // TODO: add other combined directives in topological order. |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 109 | static const OpenMPDirectiveKindExWrapper F[][3] = { |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 110 | {OMPD_cancellation, OMPD_point, OMPD_cancellation_point}, |
| 111 | {OMPD_declare, OMPD_reduction, OMPD_declare_reduction}, |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 112 | {OMPD_declare, OMPD_mapper, OMPD_declare_mapper}, |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 113 | {OMPD_declare, OMPD_simd, OMPD_declare_simd}, |
| 114 | {OMPD_declare, OMPD_target, OMPD_declare_target}, |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 115 | {OMPD_declare, OMPD_variant, OMPD_declare_variant}, |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 116 | {OMPD_distribute, OMPD_parallel, OMPD_distribute_parallel}, |
| 117 | {OMPD_distribute_parallel, OMPD_for, OMPD_distribute_parallel_for}, |
| 118 | {OMPD_distribute_parallel_for, OMPD_simd, |
| 119 | OMPD_distribute_parallel_for_simd}, |
| 120 | {OMPD_distribute, OMPD_simd, OMPD_distribute_simd}, |
| 121 | {OMPD_end, OMPD_declare, OMPD_end_declare}, |
| 122 | {OMPD_end_declare, OMPD_target, OMPD_end_declare_target}, |
| 123 | {OMPD_target, OMPD_data, OMPD_target_data}, |
| 124 | {OMPD_target, OMPD_enter, OMPD_target_enter}, |
| 125 | {OMPD_target, OMPD_exit, OMPD_target_exit}, |
| 126 | {OMPD_target, OMPD_update, OMPD_target_update}, |
| 127 | {OMPD_target_enter, OMPD_data, OMPD_target_enter_data}, |
| 128 | {OMPD_target_exit, OMPD_data, OMPD_target_exit_data}, |
| 129 | {OMPD_for, OMPD_simd, OMPD_for_simd}, |
| 130 | {OMPD_parallel, OMPD_for, OMPD_parallel_for}, |
| 131 | {OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd}, |
| 132 | {OMPD_parallel, OMPD_sections, OMPD_parallel_sections}, |
| 133 | {OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd}, |
| 134 | {OMPD_target, OMPD_parallel, OMPD_target_parallel}, |
| 135 | {OMPD_target, OMPD_simd, OMPD_target_simd}, |
| 136 | {OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for}, |
| 137 | {OMPD_target_parallel_for, OMPD_simd, OMPD_target_parallel_for_simd}, |
| 138 | {OMPD_teams, OMPD_distribute, OMPD_teams_distribute}, |
| 139 | {OMPD_teams_distribute, OMPD_simd, OMPD_teams_distribute_simd}, |
| 140 | {OMPD_teams_distribute, OMPD_parallel, OMPD_teams_distribute_parallel}, |
| 141 | {OMPD_teams_distribute_parallel, OMPD_for, |
| 142 | OMPD_teams_distribute_parallel_for}, |
| 143 | {OMPD_teams_distribute_parallel_for, OMPD_simd, |
| 144 | OMPD_teams_distribute_parallel_for_simd}, |
| 145 | {OMPD_target, OMPD_teams, OMPD_target_teams}, |
| 146 | {OMPD_target_teams, OMPD_distribute, OMPD_target_teams_distribute}, |
| 147 | {OMPD_target_teams_distribute, OMPD_parallel, |
| 148 | OMPD_target_teams_distribute_parallel}, |
| 149 | {OMPD_target_teams_distribute, OMPD_simd, |
| 150 | OMPD_target_teams_distribute_simd}, |
| 151 | {OMPD_target_teams_distribute_parallel, OMPD_for, |
| 152 | OMPD_target_teams_distribute_parallel_for}, |
| 153 | {OMPD_target_teams_distribute_parallel_for, OMPD_simd, |
Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 154 | OMPD_target_teams_distribute_parallel_for_simd}, |
Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 155 | {OMPD_master, OMPD_taskloop, OMPD_master_taskloop}, |
Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 156 | {OMPD_master_taskloop, OMPD_simd, OMPD_master_taskloop_simd}, |
Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 157 | {OMPD_parallel, OMPD_master, OMPD_parallel_master}, |
Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 158 | {OMPD_parallel_master, OMPD_taskloop, OMPD_parallel_master_taskloop}, |
| 159 | {OMPD_parallel_master_taskloop, OMPD_simd, |
| 160 | OMPD_parallel_master_taskloop_simd}}; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 161 | enum { CancellationPoint = 0, DeclareReduction = 1, TargetData = 2 }; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 162 | Token Tok = P.getCurToken(); |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 163 | OpenMPDirectiveKindExWrapper DKind = |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 164 | Tok.isAnnotation() |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 165 | ? static_cast<unsigned>(OMPD_unknown) |
| 166 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 167 | if (DKind == OMPD_unknown) |
| 168 | return OMPD_unknown; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 169 | |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 170 | for (unsigned I = 0; I < llvm::array_lengthof(F); ++I) { |
| 171 | if (DKind != F[I][0]) |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 172 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 173 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 174 | Tok = P.getPreprocessor().LookAhead(0); |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 175 | OpenMPDirectiveKindExWrapper SDKind = |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 176 | Tok.isAnnotation() |
| 177 | ? static_cast<unsigned>(OMPD_unknown) |
| 178 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 179 | if (SDKind == OMPD_unknown) |
| 180 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 181 | |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 182 | if (SDKind == F[I][1]) { |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 183 | P.ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 184 | DKind = F[I][2]; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 185 | } |
| 186 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 187 | return DKind < OMPD_unknown ? static_cast<OpenMPDirectiveKind>(DKind) |
| 188 | : OMPD_unknown; |
| 189 | } |
| 190 | |
| 191 | static DeclarationName parseOpenMPReductionId(Parser &P) { |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 192 | Token Tok = P.getCurToken(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 193 | Sema &Actions = P.getActions(); |
| 194 | OverloadedOperatorKind OOK = OO_None; |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 195 | // Allow to use 'operator' keyword for C++ operators |
| 196 | bool WithOperator = false; |
| 197 | if (Tok.is(tok::kw_operator)) { |
| 198 | P.ConsumeToken(); |
| 199 | Tok = P.getCurToken(); |
| 200 | WithOperator = true; |
| 201 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 202 | switch (Tok.getKind()) { |
| 203 | case tok::plus: // '+' |
| 204 | OOK = OO_Plus; |
| 205 | break; |
| 206 | case tok::minus: // '-' |
| 207 | OOK = OO_Minus; |
| 208 | break; |
| 209 | case tok::star: // '*' |
| 210 | OOK = OO_Star; |
| 211 | break; |
| 212 | case tok::amp: // '&' |
| 213 | OOK = OO_Amp; |
| 214 | break; |
| 215 | case tok::pipe: // '|' |
| 216 | OOK = OO_Pipe; |
| 217 | break; |
| 218 | case tok::caret: // '^' |
| 219 | OOK = OO_Caret; |
| 220 | break; |
| 221 | case tok::ampamp: // '&&' |
| 222 | OOK = OO_AmpAmp; |
| 223 | break; |
| 224 | case tok::pipepipe: // '||' |
| 225 | OOK = OO_PipePipe; |
| 226 | break; |
| 227 | case tok::identifier: // identifier |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 228 | if (!WithOperator) |
| 229 | break; |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 230 | LLVM_FALLTHROUGH; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 231 | default: |
| 232 | P.Diag(Tok.getLocation(), diag::err_omp_expected_reduction_identifier); |
| 233 | P.SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 234 | Parser::StopBeforeMatch); |
| 235 | return DeclarationName(); |
| 236 | } |
| 237 | P.ConsumeToken(); |
| 238 | auto &DeclNames = Actions.getASTContext().DeclarationNames; |
| 239 | return OOK == OO_None ? DeclNames.getIdentifier(Tok.getIdentifierInfo()) |
| 240 | : DeclNames.getCXXOperatorName(OOK); |
| 241 | } |
| 242 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 243 | /// Parse 'omp declare reduction' construct. |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 244 | /// |
| 245 | /// declare-reduction-directive: |
| 246 | /// annot_pragma_openmp 'declare' 'reduction' |
| 247 | /// '(' <reduction_id> ':' <type> {',' <type>} ':' <expression> ')' |
| 248 | /// ['initializer' '(' ('omp_priv' '=' <expression>)|<function_call> ')'] |
| 249 | /// annot_pragma_openmp_end |
| 250 | /// <reduction_id> is either a base language identifier or one of the following |
| 251 | /// operators: '+', '-', '*', '&', '|', '^', '&&' and '||'. |
| 252 | /// |
| 253 | Parser::DeclGroupPtrTy |
| 254 | Parser::ParseOpenMPDeclareReductionDirective(AccessSpecifier AS) { |
| 255 | // Parse '('. |
| 256 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 257 | if (T.expectAndConsume( |
| 258 | diag::err_expected_lparen_after, |
| 259 | getOpenMPDirectiveName(OMPD_declare_reduction).data())) { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 260 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 261 | return DeclGroupPtrTy(); |
| 262 | } |
| 263 | |
| 264 | DeclarationName Name = parseOpenMPReductionId(*this); |
| 265 | if (Name.isEmpty() && Tok.is(tok::annot_pragma_openmp_end)) |
| 266 | return DeclGroupPtrTy(); |
| 267 | |
| 268 | // Consume ':'. |
| 269 | bool IsCorrect = !ExpectAndConsume(tok::colon); |
| 270 | |
| 271 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 272 | return DeclGroupPtrTy(); |
| 273 | |
Alexey Bataev | a839ddd | 2016-03-17 10:19:46 +0000 | [diff] [blame] | 274 | IsCorrect = IsCorrect && !Name.isEmpty(); |
| 275 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 276 | if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) { |
| 277 | Diag(Tok.getLocation(), diag::err_expected_type); |
| 278 | IsCorrect = false; |
| 279 | } |
| 280 | |
| 281 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 282 | return DeclGroupPtrTy(); |
| 283 | |
| 284 | SmallVector<std::pair<QualType, SourceLocation>, 8> ReductionTypes; |
| 285 | // Parse list of types until ':' token. |
| 286 | do { |
| 287 | ColonProtectionRAIIObject ColonRAII(*this); |
| 288 | SourceRange Range; |
Faisal Vali | 421b2d1 | 2017-12-29 05:41:00 +0000 | [diff] [blame] | 289 | TypeResult TR = |
| 290 | ParseTypeName(&Range, DeclaratorContext::PrototypeContext, AS); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 291 | if (TR.isUsable()) { |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 292 | QualType ReductionType = |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 293 | Actions.ActOnOpenMPDeclareReductionType(Range.getBegin(), TR); |
| 294 | if (!ReductionType.isNull()) { |
| 295 | ReductionTypes.push_back( |
| 296 | std::make_pair(ReductionType, Range.getBegin())); |
| 297 | } |
| 298 | } else { |
| 299 | SkipUntil(tok::comma, tok::colon, tok::annot_pragma_openmp_end, |
| 300 | StopBeforeMatch); |
| 301 | } |
| 302 | |
| 303 | if (Tok.is(tok::colon) || Tok.is(tok::annot_pragma_openmp_end)) |
| 304 | break; |
| 305 | |
| 306 | // Consume ','. |
| 307 | if (ExpectAndConsume(tok::comma)) { |
| 308 | IsCorrect = false; |
| 309 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 310 | Diag(Tok.getLocation(), diag::err_expected_type); |
| 311 | return DeclGroupPtrTy(); |
| 312 | } |
| 313 | } |
| 314 | } while (Tok.isNot(tok::annot_pragma_openmp_end)); |
| 315 | |
| 316 | if (ReductionTypes.empty()) { |
| 317 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 318 | return DeclGroupPtrTy(); |
| 319 | } |
| 320 | |
| 321 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 322 | return DeclGroupPtrTy(); |
| 323 | |
| 324 | // Consume ':'. |
| 325 | if (ExpectAndConsume(tok::colon)) |
| 326 | IsCorrect = false; |
| 327 | |
| 328 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 329 | Diag(Tok.getLocation(), diag::err_expected_expression); |
| 330 | return DeclGroupPtrTy(); |
| 331 | } |
| 332 | |
| 333 | DeclGroupPtrTy DRD = Actions.ActOnOpenMPDeclareReductionDirectiveStart( |
| 334 | getCurScope(), Actions.getCurLexicalContext(), Name, ReductionTypes, AS); |
| 335 | |
| 336 | // Parse <combiner> expression and then parse initializer if any for each |
| 337 | // correct type. |
| 338 | unsigned I = 0, E = ReductionTypes.size(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 339 | for (Decl *D : DRD.get()) { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 340 | TentativeParsingAction TPA(*this); |
| 341 | ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope | |
Momchil Velikov | 57c681f | 2017-08-10 15:43:06 +0000 | [diff] [blame] | 342 | Scope::CompoundStmtScope | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 343 | Scope::OpenMPDirectiveScope); |
| 344 | // Parse <combiner> expression. |
| 345 | Actions.ActOnOpenMPDeclareReductionCombinerStart(getCurScope(), D); |
| 346 | ExprResult CombinerResult = |
| 347 | Actions.ActOnFinishFullExpr(ParseAssignmentExpression().get(), |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 348 | D->getLocation(), /*DiscardedValue*/ false); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 349 | Actions.ActOnOpenMPDeclareReductionCombinerEnd(D, CombinerResult.get()); |
| 350 | |
| 351 | if (CombinerResult.isInvalid() && Tok.isNot(tok::r_paren) && |
| 352 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 353 | TPA.Commit(); |
| 354 | IsCorrect = false; |
| 355 | break; |
| 356 | } |
| 357 | IsCorrect = !T.consumeClose() && IsCorrect && CombinerResult.isUsable(); |
| 358 | ExprResult InitializerResult; |
| 359 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 360 | // Parse <initializer> expression. |
| 361 | if (Tok.is(tok::identifier) && |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 362 | Tok.getIdentifierInfo()->isStr("initializer")) { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 363 | ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 364 | } else { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 365 | Diag(Tok.getLocation(), diag::err_expected) << "'initializer'"; |
| 366 | TPA.Commit(); |
| 367 | IsCorrect = false; |
| 368 | break; |
| 369 | } |
| 370 | // Parse '('. |
| 371 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 372 | tok::annot_pragma_openmp_end); |
| 373 | IsCorrect = |
| 374 | !T.expectAndConsume(diag::err_expected_lparen_after, "initializer") && |
| 375 | IsCorrect; |
| 376 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 377 | ParseScope OMPDRScope(this, Scope::FnScope | Scope::DeclScope | |
Momchil Velikov | 57c681f | 2017-08-10 15:43:06 +0000 | [diff] [blame] | 378 | Scope::CompoundStmtScope | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 379 | Scope::OpenMPDirectiveScope); |
| 380 | // Parse expression. |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 381 | VarDecl *OmpPrivParm = |
| 382 | Actions.ActOnOpenMPDeclareReductionInitializerStart(getCurScope(), |
| 383 | D); |
| 384 | // Check if initializer is omp_priv <init_expr> or something else. |
| 385 | if (Tok.is(tok::identifier) && |
| 386 | Tok.getIdentifierInfo()->isStr("omp_priv")) { |
Alexey Bataev | 3c676e3 | 2019-11-12 11:19:26 -0500 | [diff] [blame] | 387 | ConsumeToken(); |
| 388 | ParseOpenMPReductionInitializerForDecl(OmpPrivParm); |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 389 | } else { |
| 390 | InitializerResult = Actions.ActOnFinishFullExpr( |
| 391 | ParseAssignmentExpression().get(), D->getLocation(), |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 392 | /*DiscardedValue*/ false); |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 393 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 394 | Actions.ActOnOpenMPDeclareReductionInitializerEnd( |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 395 | D, InitializerResult.get(), OmpPrivParm); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 396 | if (InitializerResult.isInvalid() && Tok.isNot(tok::r_paren) && |
| 397 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 398 | TPA.Commit(); |
| 399 | IsCorrect = false; |
| 400 | break; |
| 401 | } |
| 402 | IsCorrect = |
| 403 | !T.consumeClose() && IsCorrect && !InitializerResult.isInvalid(); |
| 404 | } |
| 405 | } |
| 406 | |
| 407 | ++I; |
| 408 | // Revert parsing if not the last type, otherwise accept it, we're done with |
| 409 | // parsing. |
| 410 | if (I != E) |
| 411 | TPA.Revert(); |
| 412 | else |
| 413 | TPA.Commit(); |
| 414 | } |
| 415 | return Actions.ActOnOpenMPDeclareReductionDirectiveEnd(getCurScope(), DRD, |
| 416 | IsCorrect); |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 419 | void Parser::ParseOpenMPReductionInitializerForDecl(VarDecl *OmpPrivParm) { |
| 420 | // Parse declarator '=' initializer. |
| 421 | // If a '==' or '+=' is found, suggest a fixit to '='. |
| 422 | if (isTokenEqualOrEqualTypo()) { |
| 423 | ConsumeToken(); |
| 424 | |
| 425 | if (Tok.is(tok::code_completion)) { |
| 426 | Actions.CodeCompleteInitializer(getCurScope(), OmpPrivParm); |
| 427 | Actions.FinalizeDeclaration(OmpPrivParm); |
| 428 | cutOffParsing(); |
| 429 | return; |
| 430 | } |
| 431 | |
Alexey Bataev | 3c676e3 | 2019-11-12 11:19:26 -0500 | [diff] [blame] | 432 | PreferredType.enterVariableInit(Tok.getLocation(), OmpPrivParm); |
| 433 | ExprResult Init = ParseAssignmentExpression(); |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 434 | |
| 435 | if (Init.isInvalid()) { |
| 436 | SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 437 | Actions.ActOnInitializerError(OmpPrivParm); |
| 438 | } else { |
| 439 | Actions.AddInitializerToDecl(OmpPrivParm, Init.get(), |
| 440 | /*DirectInit=*/false); |
| 441 | } |
| 442 | } else if (Tok.is(tok::l_paren)) { |
| 443 | // Parse C++ direct initializer: '(' expression-list ')' |
| 444 | BalancedDelimiterTracker T(*this, tok::l_paren); |
| 445 | T.consumeOpen(); |
| 446 | |
| 447 | ExprVector Exprs; |
| 448 | CommaLocsTy CommaLocs; |
| 449 | |
Ilya Biryukov | 2fab235 | 2018-08-30 13:08:03 +0000 | [diff] [blame] | 450 | SourceLocation LParLoc = T.getOpenLocation(); |
Ilya Biryukov | ff2a997 | 2019-02-26 11:01:50 +0000 | [diff] [blame] | 451 | auto RunSignatureHelp = [this, OmpPrivParm, LParLoc, &Exprs]() { |
| 452 | QualType PreferredType = Actions.ProduceConstructorSignatureHelp( |
| 453 | getCurScope(), OmpPrivParm->getType()->getCanonicalTypeInternal(), |
| 454 | OmpPrivParm->getLocation(), Exprs, LParLoc); |
| 455 | CalledSignatureHelp = true; |
| 456 | return PreferredType; |
| 457 | }; |
| 458 | if (ParseExpressionList(Exprs, CommaLocs, [&] { |
| 459 | PreferredType.enterFunctionArgument(Tok.getLocation(), |
| 460 | RunSignatureHelp); |
| 461 | })) { |
| 462 | if (PP.isCodeCompletionReached() && !CalledSignatureHelp) |
| 463 | RunSignatureHelp(); |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 464 | Actions.ActOnInitializerError(OmpPrivParm); |
| 465 | SkipUntil(tok::r_paren, tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 466 | } else { |
| 467 | // Match the ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 468 | SourceLocation RLoc = Tok.getLocation(); |
| 469 | if (!T.consumeClose()) |
| 470 | RLoc = T.getCloseLocation(); |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 471 | |
| 472 | assert(!Exprs.empty() && Exprs.size() - 1 == CommaLocs.size() && |
| 473 | "Unexpected number of commas!"); |
| 474 | |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 475 | ExprResult Initializer = |
| 476 | Actions.ActOnParenListExpr(T.getOpenLocation(), RLoc, Exprs); |
Alexey Bataev | 070f43a | 2017-09-06 14:49:58 +0000 | [diff] [blame] | 477 | Actions.AddInitializerToDecl(OmpPrivParm, Initializer.get(), |
| 478 | /*DirectInit=*/true); |
| 479 | } |
| 480 | } else if (getLangOpts().CPlusPlus11 && Tok.is(tok::l_brace)) { |
| 481 | // Parse C++0x braced-init-list. |
| 482 | Diag(Tok, diag::warn_cxx98_compat_generalized_initializer_lists); |
| 483 | |
| 484 | ExprResult Init(ParseBraceInitializer()); |
| 485 | |
| 486 | if (Init.isInvalid()) { |
| 487 | Actions.ActOnInitializerError(OmpPrivParm); |
| 488 | } else { |
| 489 | Actions.AddInitializerToDecl(OmpPrivParm, Init.get(), |
| 490 | /*DirectInit=*/true); |
| 491 | } |
| 492 | } else { |
| 493 | Actions.ActOnUninitializedDecl(OmpPrivParm); |
| 494 | } |
| 495 | } |
| 496 | |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 497 | /// Parses 'omp declare mapper' directive. |
| 498 | /// |
| 499 | /// declare-mapper-directive: |
| 500 | /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifier> ':'] |
| 501 | /// <type> <var> ')' [<clause>[[,] <clause>] ... ] |
| 502 | /// annot_pragma_openmp_end |
| 503 | /// <mapper-identifier> and <var> are base language identifiers. |
| 504 | /// |
| 505 | Parser::DeclGroupPtrTy |
| 506 | Parser::ParseOpenMPDeclareMapperDirective(AccessSpecifier AS) { |
| 507 | bool IsCorrect = true; |
| 508 | // Parse '(' |
| 509 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 510 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 511 | getOpenMPDirectiveName(OMPD_declare_mapper).data())) { |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 512 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 513 | return DeclGroupPtrTy(); |
| 514 | } |
| 515 | |
| 516 | // Parse <mapper-identifier> |
| 517 | auto &DeclNames = Actions.getASTContext().DeclarationNames; |
| 518 | DeclarationName MapperId; |
| 519 | if (PP.LookAhead(0).is(tok::colon)) { |
| 520 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_default)) { |
| 521 | Diag(Tok.getLocation(), diag::err_omp_mapper_illegal_identifier); |
| 522 | IsCorrect = false; |
| 523 | } else { |
| 524 | MapperId = DeclNames.getIdentifier(Tok.getIdentifierInfo()); |
| 525 | } |
| 526 | ConsumeToken(); |
| 527 | // Consume ':'. |
| 528 | ExpectAndConsume(tok::colon); |
| 529 | } else { |
| 530 | // If no mapper identifier is provided, its name is "default" by default |
| 531 | MapperId = |
| 532 | DeclNames.getIdentifier(&Actions.getASTContext().Idents.get("default")); |
| 533 | } |
| 534 | |
| 535 | if (!IsCorrect && Tok.is(tok::annot_pragma_openmp_end)) |
| 536 | return DeclGroupPtrTy(); |
| 537 | |
| 538 | // Parse <type> <var> |
| 539 | DeclarationName VName; |
| 540 | QualType MapperType; |
| 541 | SourceRange Range; |
| 542 | TypeResult ParsedType = parseOpenMPDeclareMapperVarDecl(Range, VName, AS); |
| 543 | if (ParsedType.isUsable()) |
| 544 | MapperType = |
| 545 | Actions.ActOnOpenMPDeclareMapperType(Range.getBegin(), ParsedType); |
| 546 | if (MapperType.isNull()) |
| 547 | IsCorrect = false; |
| 548 | if (!IsCorrect) { |
| 549 | SkipUntil(tok::annot_pragma_openmp_end, Parser::StopBeforeMatch); |
| 550 | return DeclGroupPtrTy(); |
| 551 | } |
| 552 | |
| 553 | // Consume ')'. |
| 554 | IsCorrect &= !T.consumeClose(); |
| 555 | if (!IsCorrect) { |
| 556 | SkipUntil(tok::annot_pragma_openmp_end, Parser::StopBeforeMatch); |
| 557 | return DeclGroupPtrTy(); |
| 558 | } |
| 559 | |
| 560 | // Enter scope. |
| 561 | OMPDeclareMapperDecl *DMD = Actions.ActOnOpenMPDeclareMapperDirectiveStart( |
| 562 | getCurScope(), Actions.getCurLexicalContext(), MapperId, MapperType, |
| 563 | Range.getBegin(), VName, AS); |
| 564 | DeclarationNameInfo DirName; |
| 565 | SourceLocation Loc = Tok.getLocation(); |
| 566 | unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope | |
| 567 | Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope; |
| 568 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
| 569 | Actions.StartOpenMPDSABlock(OMPD_declare_mapper, DirName, getCurScope(), Loc); |
| 570 | |
| 571 | // Add the mapper variable declaration. |
| 572 | Actions.ActOnOpenMPDeclareMapperDirectiveVarDecl( |
| 573 | DMD, getCurScope(), MapperType, Range.getBegin(), VName); |
| 574 | |
| 575 | // Parse map clauses. |
| 576 | SmallVector<OMPClause *, 6> Clauses; |
| 577 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 578 | OpenMPClauseKind CKind = Tok.isAnnotation() |
| 579 | ? OMPC_unknown |
| 580 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 581 | Actions.StartOpenMPClause(CKind); |
| 582 | OMPClause *Clause = |
| 583 | ParseOpenMPClause(OMPD_declare_mapper, CKind, Clauses.size() == 0); |
| 584 | if (Clause) |
| 585 | Clauses.push_back(Clause); |
| 586 | else |
| 587 | IsCorrect = false; |
| 588 | // Skip ',' if any. |
| 589 | if (Tok.is(tok::comma)) |
| 590 | ConsumeToken(); |
| 591 | Actions.EndOpenMPClause(); |
| 592 | } |
| 593 | if (Clauses.empty()) { |
| 594 | Diag(Tok, diag::err_omp_expected_clause) |
| 595 | << getOpenMPDirectiveName(OMPD_declare_mapper); |
| 596 | IsCorrect = false; |
| 597 | } |
| 598 | |
| 599 | // Exit scope. |
| 600 | Actions.EndOpenMPDSABlock(nullptr); |
| 601 | OMPDirectiveScope.Exit(); |
| 602 | |
| 603 | DeclGroupPtrTy DGP = |
| 604 | Actions.ActOnOpenMPDeclareMapperDirectiveEnd(DMD, getCurScope(), Clauses); |
| 605 | if (!IsCorrect) |
| 606 | return DeclGroupPtrTy(); |
| 607 | return DGP; |
| 608 | } |
| 609 | |
| 610 | TypeResult Parser::parseOpenMPDeclareMapperVarDecl(SourceRange &Range, |
| 611 | DeclarationName &Name, |
| 612 | AccessSpecifier AS) { |
| 613 | // Parse the common declaration-specifiers piece. |
| 614 | Parser::DeclSpecContext DSC = Parser::DeclSpecContext::DSC_type_specifier; |
| 615 | DeclSpec DS(AttrFactory); |
| 616 | ParseSpecifierQualifierList(DS, AS, DSC); |
| 617 | |
| 618 | // Parse the declarator. |
| 619 | DeclaratorContext Context = DeclaratorContext::PrototypeContext; |
| 620 | Declarator DeclaratorInfo(DS, Context); |
| 621 | ParseDeclarator(DeclaratorInfo); |
| 622 | Range = DeclaratorInfo.getSourceRange(); |
| 623 | if (DeclaratorInfo.getIdentifier() == nullptr) { |
| 624 | Diag(Tok.getLocation(), diag::err_omp_mapper_expected_declarator); |
| 625 | return true; |
| 626 | } |
| 627 | Name = Actions.GetNameForDeclarator(DeclaratorInfo).getName(); |
| 628 | |
| 629 | return Actions.ActOnOpenMPDeclareMapperVarDecl(getCurScope(), DeclaratorInfo); |
| 630 | } |
| 631 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 632 | namespace { |
| 633 | /// RAII that recreates function context for correct parsing of clauses of |
| 634 | /// 'declare simd' construct. |
| 635 | /// OpenMP, 2.8.2 declare simd Construct |
| 636 | /// The expressions appearing in the clauses of this directive are evaluated in |
| 637 | /// the scope of the arguments of the function declaration or definition. |
| 638 | class FNContextRAII final { |
| 639 | Parser &P; |
| 640 | Sema::CXXThisScopeRAII *ThisScope; |
| 641 | Parser::ParseScope *TempScope; |
| 642 | Parser::ParseScope *FnScope; |
| 643 | bool HasTemplateScope = false; |
| 644 | bool HasFunScope = false; |
| 645 | FNContextRAII() = delete; |
| 646 | FNContextRAII(const FNContextRAII &) = delete; |
| 647 | FNContextRAII &operator=(const FNContextRAII &) = delete; |
| 648 | |
| 649 | public: |
| 650 | FNContextRAII(Parser &P, Parser::DeclGroupPtrTy Ptr) : P(P) { |
| 651 | Decl *D = *Ptr.get().begin(); |
| 652 | NamedDecl *ND = dyn_cast<NamedDecl>(D); |
| 653 | RecordDecl *RD = dyn_cast_or_null<RecordDecl>(D->getDeclContext()); |
| 654 | Sema &Actions = P.getActions(); |
| 655 | |
| 656 | // Allow 'this' within late-parsed attributes. |
Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 657 | ThisScope = new Sema::CXXThisScopeRAII(Actions, RD, Qualifiers(), |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 658 | ND && ND->isCXXInstanceMember()); |
| 659 | |
| 660 | // If the Decl is templatized, add template parameters to scope. |
| 661 | HasTemplateScope = D->isTemplateDecl(); |
| 662 | TempScope = |
| 663 | new Parser::ParseScope(&P, Scope::TemplateParamScope, HasTemplateScope); |
| 664 | if (HasTemplateScope) |
| 665 | Actions.ActOnReenterTemplateScope(Actions.getCurScope(), D); |
| 666 | |
| 667 | // If the Decl is on a function, add function parameters to the scope. |
| 668 | HasFunScope = D->isFunctionOrFunctionTemplate(); |
Momchil Velikov | 57c681f | 2017-08-10 15:43:06 +0000 | [diff] [blame] | 669 | FnScope = new Parser::ParseScope( |
| 670 | &P, Scope::FnScope | Scope::DeclScope | Scope::CompoundStmtScope, |
| 671 | HasFunScope); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 672 | if (HasFunScope) |
| 673 | Actions.ActOnReenterFunctionContext(Actions.getCurScope(), D); |
| 674 | } |
| 675 | ~FNContextRAII() { |
| 676 | if (HasFunScope) { |
| 677 | P.getActions().ActOnExitFunctionContext(); |
| 678 | FnScope->Exit(); // Pop scope, and remove Decls from IdResolver |
| 679 | } |
| 680 | if (HasTemplateScope) |
| 681 | TempScope->Exit(); |
| 682 | delete FnScope; |
| 683 | delete TempScope; |
| 684 | delete ThisScope; |
| 685 | } |
| 686 | }; |
| 687 | } // namespace |
| 688 | |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 689 | /// Parses clauses for 'declare simd' directive. |
| 690 | /// clause: |
| 691 | /// 'inbranch' | 'notinbranch' |
| 692 | /// 'simdlen' '(' <expr> ')' |
| 693 | /// { 'uniform' '(' <argument_list> ')' } |
| 694 | /// { 'aligned '(' <argument_list> [ ':' <alignment> ] ')' } |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 695 | /// { 'linear '(' <argument_list> [ ':' <step> ] ')' } |
| 696 | static bool parseDeclareSimdClauses( |
| 697 | Parser &P, OMPDeclareSimdDeclAttr::BranchStateTy &BS, ExprResult &SimdLen, |
| 698 | SmallVectorImpl<Expr *> &Uniforms, SmallVectorImpl<Expr *> &Aligneds, |
| 699 | SmallVectorImpl<Expr *> &Alignments, SmallVectorImpl<Expr *> &Linears, |
| 700 | SmallVectorImpl<unsigned> &LinModifiers, SmallVectorImpl<Expr *> &Steps) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 701 | SourceRange BSRange; |
| 702 | const Token &Tok = P.getCurToken(); |
| 703 | bool IsError = false; |
| 704 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 705 | if (Tok.isNot(tok::identifier)) |
| 706 | break; |
| 707 | OMPDeclareSimdDeclAttr::BranchStateTy Out; |
| 708 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 709 | StringRef ClauseName = II->getName(); |
| 710 | // Parse 'inranch|notinbranch' clauses. |
| 711 | if (OMPDeclareSimdDeclAttr::ConvertStrToBranchStateTy(ClauseName, Out)) { |
| 712 | if (BS != OMPDeclareSimdDeclAttr::BS_Undefined && BS != Out) { |
| 713 | P.Diag(Tok, diag::err_omp_declare_simd_inbranch_notinbranch) |
| 714 | << ClauseName |
| 715 | << OMPDeclareSimdDeclAttr::ConvertBranchStateTyToStr(BS) << BSRange; |
| 716 | IsError = true; |
| 717 | } |
| 718 | BS = Out; |
| 719 | BSRange = SourceRange(Tok.getLocation(), Tok.getEndLoc()); |
| 720 | P.ConsumeToken(); |
| 721 | } else if (ClauseName.equals("simdlen")) { |
| 722 | if (SimdLen.isUsable()) { |
| 723 | P.Diag(Tok, diag::err_omp_more_one_clause) |
| 724 | << getOpenMPDirectiveName(OMPD_declare_simd) << ClauseName << 0; |
| 725 | IsError = true; |
| 726 | } |
| 727 | P.ConsumeToken(); |
| 728 | SourceLocation RLoc; |
| 729 | SimdLen = P.ParseOpenMPParensExpr(ClauseName, RLoc); |
| 730 | if (SimdLen.isInvalid()) |
| 731 | IsError = true; |
| 732 | } else { |
| 733 | OpenMPClauseKind CKind = getOpenMPClauseKind(ClauseName); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 734 | if (CKind == OMPC_uniform || CKind == OMPC_aligned || |
| 735 | CKind == OMPC_linear) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 736 | Parser::OpenMPVarListDataTy Data; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 737 | SmallVectorImpl<Expr *> *Vars = &Uniforms; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 738 | if (CKind == OMPC_aligned) |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 739 | Vars = &Aligneds; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 740 | else if (CKind == OMPC_linear) |
| 741 | Vars = &Linears; |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 742 | |
| 743 | P.ConsumeToken(); |
| 744 | if (P.ParseOpenMPVarList(OMPD_declare_simd, |
| 745 | getOpenMPClauseKind(ClauseName), *Vars, Data)) |
| 746 | IsError = true; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 747 | if (CKind == OMPC_aligned) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 748 | Alignments.append(Aligneds.size() - Alignments.size(), Data.TailExpr); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 749 | } else if (CKind == OMPC_linear) { |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 750 | if (P.getActions().CheckOpenMPLinearModifier( |
| 751 | static_cast<OpenMPLinearClauseKind>(Data.ExtraModifier), |
| 752 | Data.DepLinMapLastLoc)) |
| 753 | Data.ExtraModifier = OMPC_LINEAR_val; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 754 | LinModifiers.append(Linears.size() - LinModifiers.size(), |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 755 | Data.ExtraModifier); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 756 | Steps.append(Linears.size() - Steps.size(), Data.TailExpr); |
| 757 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 758 | } else |
| 759 | // TODO: add parsing of other clauses. |
| 760 | break; |
| 761 | } |
| 762 | // Skip ',' if any. |
| 763 | if (Tok.is(tok::comma)) |
| 764 | P.ConsumeToken(); |
| 765 | } |
| 766 | return IsError; |
| 767 | } |
| 768 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 769 | /// Parse clauses for '#pragma omp declare simd'. |
| 770 | Parser::DeclGroupPtrTy |
| 771 | Parser::ParseOMPDeclareSimdClauses(Parser::DeclGroupPtrTy Ptr, |
| 772 | CachedTokens &Toks, SourceLocation Loc) { |
Ilya Biryukov | 929af67 | 2019-05-17 09:32:05 +0000 | [diff] [blame] | 773 | PP.EnterToken(Tok, /*IsReinject*/ true); |
| 774 | PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true, |
| 775 | /*IsReinject*/ true); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 776 | // Consume the previously pushed token. |
| 777 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 778 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 779 | |
| 780 | FNContextRAII FnContext(*this, Ptr); |
| 781 | OMPDeclareSimdDeclAttr::BranchStateTy BS = |
| 782 | OMPDeclareSimdDeclAttr::BS_Undefined; |
| 783 | ExprResult Simdlen; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 784 | SmallVector<Expr *, 4> Uniforms; |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 785 | SmallVector<Expr *, 4> Aligneds; |
| 786 | SmallVector<Expr *, 4> Alignments; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 787 | SmallVector<Expr *, 4> Linears; |
| 788 | SmallVector<unsigned, 4> LinModifiers; |
| 789 | SmallVector<Expr *, 4> Steps; |
| 790 | bool IsError = |
| 791 | parseDeclareSimdClauses(*this, BS, Simdlen, Uniforms, Aligneds, |
| 792 | Alignments, Linears, LinModifiers, Steps); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 793 | // Need to check for extra tokens. |
| 794 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 795 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 796 | << getOpenMPDirectiveName(OMPD_declare_simd); |
| 797 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 798 | ConsumeAnyToken(); |
| 799 | } |
| 800 | // Skip the last annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 801 | SourceLocation EndLoc = ConsumeAnnotationToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 802 | if (IsError) |
| 803 | return Ptr; |
| 804 | return Actions.ActOnOpenMPDeclareSimdDirective( |
| 805 | Ptr, BS, Simdlen.get(), Uniforms, Aligneds, Alignments, Linears, |
| 806 | LinModifiers, Steps, SourceRange(Loc, EndLoc)); |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 807 | } |
| 808 | |
Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 809 | /// Parse optional 'score' '(' <expr> ')' ':'. |
| 810 | static ExprResult parseContextScore(Parser &P) { |
| 811 | ExprResult ScoreExpr; |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 812 | Sema::OMPCtxStringType Buffer; |
Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 813 | StringRef SelectorName = |
| 814 | P.getPreprocessor().getSpelling(P.getCurToken(), Buffer); |
Alexey Bataev | dcec2ac | 2019-11-05 15:33:18 -0500 | [diff] [blame] | 815 | if (!SelectorName.equals("score")) |
Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 816 | return ScoreExpr; |
Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 817 | (void)P.ConsumeToken(); |
| 818 | SourceLocation RLoc; |
| 819 | ScoreExpr = P.ParseOpenMPParensExpr(SelectorName, RLoc); |
| 820 | // Parse ':' |
| 821 | if (P.getCurToken().is(tok::colon)) |
| 822 | (void)P.ConsumeAnyToken(); |
| 823 | else |
| 824 | P.Diag(P.getCurToken(), diag::warn_pragma_expected_colon) |
| 825 | << "context selector score clause"; |
| 826 | return ScoreExpr; |
| 827 | } |
| 828 | |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 829 | /// Parse context selector for 'implementation' selector set: |
Alexey Bataev | 1c9e173 | 2019-10-04 15:58:45 +0000 | [diff] [blame] | 830 | /// 'vendor' '(' [ 'score' '(' <score _expr> ')' ':' ] <vendor> { ',' <vendor> } |
| 831 | /// ')' |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 832 | static void |
| 833 | parseImplementationSelector(Parser &P, SourceLocation Loc, |
| 834 | llvm::StringMap<SourceLocation> &UsedCtx, |
| 835 | SmallVectorImpl<Sema::OMPCtxSelectorData> &Data) { |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 836 | const Token &Tok = P.getCurToken(); |
| 837 | // Parse inner context selector set name, if any. |
| 838 | if (!Tok.is(tok::identifier)) { |
| 839 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 840 | << "implementation"; |
| 841 | // Skip until either '}', ')', or end of directive. |
| 842 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 843 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 844 | ; |
| 845 | return; |
| 846 | } |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 847 | Sema::OMPCtxStringType Buffer; |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 848 | StringRef CtxSelectorName = P.getPreprocessor().getSpelling(Tok, Buffer); |
Alexey Bataev | 70d2e54 | 2019-10-08 17:47:52 +0000 | [diff] [blame] | 849 | auto Res = UsedCtx.try_emplace(CtxSelectorName, Tok.getLocation()); |
| 850 | if (!Res.second) { |
| 851 | // OpenMP 5.0, 2.3.2 Context Selectors, Restrictions. |
| 852 | // Each trait-selector-name can only be specified once. |
| 853 | P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_ctx_mutiple_use) |
| 854 | << CtxSelectorName << "implementation"; |
| 855 | P.Diag(Res.first->getValue(), diag::note_omp_declare_variant_ctx_used_here) |
| 856 | << CtxSelectorName; |
| 857 | } |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 858 | OpenMPContextSelectorKind CSKind = getOpenMPContextSelector(CtxSelectorName); |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 859 | (void)P.ConsumeToken(); |
| 860 | switch (CSKind) { |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 861 | case OMP_CTX_vendor: { |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 862 | // Parse '('. |
| 863 | BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end); |
| 864 | (void)T.expectAndConsume(diag::err_expected_lparen_after, |
| 865 | CtxSelectorName.data()); |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 866 | ExprResult Score = parseContextScore(P); |
| 867 | llvm::UniqueVector<Sema::OMPCtxStringType> Vendors; |
Alexey Bataev | 1c9e173 | 2019-10-04 15:58:45 +0000 | [diff] [blame] | 868 | do { |
| 869 | // Parse <vendor>. |
| 870 | StringRef VendorName; |
| 871 | if (Tok.is(tok::identifier)) { |
| 872 | Buffer.clear(); |
| 873 | VendorName = P.getPreprocessor().getSpelling(P.getCurToken(), Buffer); |
| 874 | (void)P.ConsumeToken(); |
Alexey Bataev | 303657a | 2019-10-08 19:44:16 +0000 | [diff] [blame] | 875 | if (!VendorName.empty()) |
Alexey Bataev | 4513e93f | 2019-10-10 15:15:26 +0000 | [diff] [blame] | 876 | Vendors.insert(VendorName); |
Alexey Bataev | 1c9e173 | 2019-10-04 15:58:45 +0000 | [diff] [blame] | 877 | } else { |
| 878 | P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_item_expected) |
| 879 | << "vendor identifier" |
| 880 | << "vendor" |
| 881 | << "implementation"; |
| 882 | } |
Alexey Bataev | 1c9e173 | 2019-10-04 15:58:45 +0000 | [diff] [blame] | 883 | if (!P.TryConsumeToken(tok::comma) && Tok.isNot(tok::r_paren)) { |
| 884 | P.Diag(Tok, diag::err_expected_punc) |
| 885 | << (VendorName.empty() ? "vendor name" : VendorName); |
| 886 | } |
| 887 | } while (Tok.is(tok::identifier)); |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 888 | // Parse ')'. |
| 889 | (void)T.consumeClose(); |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 890 | if (!Vendors.empty()) |
| 891 | Data.emplace_back(OMP_CTX_SET_implementation, CSKind, Score, Vendors); |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 892 | break; |
| 893 | } |
Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 894 | case OMP_CTX_kind: |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 895 | case OMP_CTX_unknown: |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 896 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 897 | << "implementation"; |
| 898 | // Skip until either '}', ')', or end of directive. |
| 899 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 900 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 901 | ; |
| 902 | return; |
| 903 | } |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 904 | } |
| 905 | |
Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 906 | /// Parse context selector for 'device' selector set: |
| 907 | /// 'kind' '(' <kind> { ',' <kind> } ')' |
| 908 | static void |
| 909 | parseDeviceSelector(Parser &P, SourceLocation Loc, |
| 910 | llvm::StringMap<SourceLocation> &UsedCtx, |
| 911 | SmallVectorImpl<Sema::OMPCtxSelectorData> &Data) { |
| 912 | const Token &Tok = P.getCurToken(); |
| 913 | // Parse inner context selector set name, if any. |
| 914 | if (!Tok.is(tok::identifier)) { |
| 915 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 916 | << "device"; |
| 917 | // Skip until either '}', ')', or end of directive. |
| 918 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 919 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 920 | ; |
| 921 | return; |
| 922 | } |
| 923 | Sema::OMPCtxStringType Buffer; |
| 924 | StringRef CtxSelectorName = P.getPreprocessor().getSpelling(Tok, Buffer); |
| 925 | auto Res = UsedCtx.try_emplace(CtxSelectorName, Tok.getLocation()); |
| 926 | if (!Res.second) { |
| 927 | // OpenMP 5.0, 2.3.2 Context Selectors, Restrictions. |
| 928 | // Each trait-selector-name can only be specified once. |
| 929 | P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_ctx_mutiple_use) |
| 930 | << CtxSelectorName << "device"; |
| 931 | P.Diag(Res.first->getValue(), diag::note_omp_declare_variant_ctx_used_here) |
| 932 | << CtxSelectorName; |
| 933 | } |
| 934 | OpenMPContextSelectorKind CSKind = getOpenMPContextSelector(CtxSelectorName); |
| 935 | (void)P.ConsumeToken(); |
| 936 | switch (CSKind) { |
| 937 | case OMP_CTX_kind: { |
| 938 | // Parse '('. |
| 939 | BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end); |
| 940 | (void)T.expectAndConsume(diag::err_expected_lparen_after, |
| 941 | CtxSelectorName.data()); |
| 942 | llvm::UniqueVector<Sema::OMPCtxStringType> Kinds; |
| 943 | do { |
| 944 | // Parse <kind>. |
| 945 | StringRef KindName; |
| 946 | if (Tok.is(tok::identifier)) { |
| 947 | Buffer.clear(); |
| 948 | KindName = P.getPreprocessor().getSpelling(P.getCurToken(), Buffer); |
| 949 | SourceLocation SLoc = P.getCurToken().getLocation(); |
| 950 | (void)P.ConsumeToken(); |
| 951 | if (llvm::StringSwitch<bool>(KindName) |
| 952 | .Case("host", false) |
| 953 | .Case("nohost", false) |
| 954 | .Case("cpu", false) |
| 955 | .Case("gpu", false) |
| 956 | .Case("fpga", false) |
| 957 | .Default(true)) { |
| 958 | P.Diag(SLoc, diag::err_omp_wrong_device_kind_trait) << KindName; |
| 959 | } else { |
| 960 | Kinds.insert(KindName); |
| 961 | } |
| 962 | } else { |
| 963 | P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_item_expected) |
| 964 | << "'host', 'nohost', 'cpu', 'gpu', or 'fpga'" |
| 965 | << "kind" |
| 966 | << "device"; |
| 967 | } |
| 968 | if (!P.TryConsumeToken(tok::comma) && Tok.isNot(tok::r_paren)) { |
| 969 | P.Diag(Tok, diag::err_expected_punc) |
| 970 | << (KindName.empty() ? "kind of device" : KindName); |
| 971 | } |
| 972 | } while (Tok.is(tok::identifier)); |
| 973 | // Parse ')'. |
| 974 | (void)T.consumeClose(); |
| 975 | if (!Kinds.empty()) |
| 976 | Data.emplace_back(OMP_CTX_SET_device, CSKind, ExprResult(), Kinds); |
| 977 | break; |
| 978 | } |
| 979 | case OMP_CTX_vendor: |
| 980 | case OMP_CTX_unknown: |
| 981 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 982 | << "device"; |
| 983 | // Skip until either '}', ')', or end of directive. |
| 984 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 985 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 986 | ; |
| 987 | return; |
| 988 | } |
| 989 | } |
| 990 | |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 991 | /// Parses clauses for 'declare variant' directive. |
| 992 | /// clause: |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 993 | /// <selector_set_name> '=' '{' <context_selectors> '}' |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 994 | /// [ ',' <selector_set_name> '=' '{' <context_selectors> '}' ] |
| 995 | bool Parser::parseOpenMPContextSelectors( |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 996 | SourceLocation Loc, SmallVectorImpl<Sema::OMPCtxSelectorData> &Data) { |
Alexey Bataev | 5d154c3 | 2019-10-08 15:56:43 +0000 | [diff] [blame] | 997 | llvm::StringMap<SourceLocation> UsedCtxSets; |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 998 | do { |
| 999 | // Parse inner context selector set name. |
| 1000 | if (!Tok.is(tok::identifier)) { |
| 1001 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_no_ctx_selector) |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 1002 | << getOpenMPClauseName(OMPC_match); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1003 | return true; |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1004 | } |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1005 | Sema::OMPCtxStringType Buffer; |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 1006 | StringRef CtxSelectorSetName = PP.getSpelling(Tok, Buffer); |
Alexey Bataev | 5d154c3 | 2019-10-08 15:56:43 +0000 | [diff] [blame] | 1007 | auto Res = UsedCtxSets.try_emplace(CtxSelectorSetName, Tok.getLocation()); |
| 1008 | if (!Res.second) { |
| 1009 | // OpenMP 5.0, 2.3.2 Context Selectors, Restrictions. |
| 1010 | // Each trait-set-selector-name can only be specified once. |
| 1011 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_ctx_set_mutiple_use) |
| 1012 | << CtxSelectorSetName; |
| 1013 | Diag(Res.first->getValue(), |
| 1014 | diag::note_omp_declare_variant_ctx_set_used_here) |
| 1015 | << CtxSelectorSetName; |
| 1016 | } |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1017 | // Parse '='. |
| 1018 | (void)ConsumeToken(); |
| 1019 | if (Tok.isNot(tok::equal)) { |
| 1020 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_equal_expected) |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 1021 | << CtxSelectorSetName; |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1022 | return true; |
| 1023 | } |
| 1024 | (void)ConsumeToken(); |
| 1025 | // TBD: add parsing of known context selectors. |
| 1026 | // Unknown selector - just ignore it completely. |
| 1027 | { |
| 1028 | // Parse '{'. |
| 1029 | BalancedDelimiterTracker TBr(*this, tok::l_brace, |
| 1030 | tok::annot_pragma_openmp_end); |
| 1031 | if (TBr.expectAndConsume(diag::err_expected_lbrace_after, "=")) |
| 1032 | return true; |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1033 | OpenMPContextSelectorSetKind CSSKind = |
| 1034 | getOpenMPContextSelectorSet(CtxSelectorSetName); |
Alexey Bataev | 70d2e54 | 2019-10-08 17:47:52 +0000 | [diff] [blame] | 1035 | llvm::StringMap<SourceLocation> UsedCtx; |
| 1036 | do { |
| 1037 | switch (CSSKind) { |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1038 | case OMP_CTX_SET_implementation: |
| 1039 | parseImplementationSelector(*this, Loc, UsedCtx, Data); |
Alexey Bataev | 70d2e54 | 2019-10-08 17:47:52 +0000 | [diff] [blame] | 1040 | break; |
Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 1041 | case OMP_CTX_SET_device: |
| 1042 | parseDeviceSelector(*this, Loc, UsedCtx, Data); |
| 1043 | break; |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1044 | case OMP_CTX_SET_unknown: |
Alexey Bataev | 70d2e54 | 2019-10-08 17:47:52 +0000 | [diff] [blame] | 1045 | // Skip until either '}', ')', or end of directive. |
| 1046 | while (!SkipUntil(tok::r_brace, tok::r_paren, |
| 1047 | tok::annot_pragma_openmp_end, StopBeforeMatch)) |
| 1048 | ; |
| 1049 | break; |
| 1050 | } |
| 1051 | const Token PrevTok = Tok; |
| 1052 | if (!TryConsumeToken(tok::comma) && Tok.isNot(tok::r_brace)) |
| 1053 | Diag(Tok, diag::err_omp_expected_comma_brace) |
| 1054 | << (PrevTok.isAnnotation() ? "context selector trait" |
| 1055 | : PP.getSpelling(PrevTok)); |
| 1056 | } while (Tok.is(tok::identifier)); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1057 | // Parse '}'. |
| 1058 | (void)TBr.consumeClose(); |
| 1059 | } |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1060 | // Consume ',' |
| 1061 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1062 | (void)ExpectAndConsume(tok::comma); |
| 1063 | } while (Tok.isAnyIdentifier()); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1064 | return false; |
| 1065 | } |
| 1066 | |
| 1067 | /// Parse clauses for '#pragma omp declare variant ( variant-func-id ) clause'. |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1068 | void Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr, |
| 1069 | CachedTokens &Toks, |
| 1070 | SourceLocation Loc) { |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1071 | PP.EnterToken(Tok, /*IsReinject*/ true); |
| 1072 | PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true, |
| 1073 | /*IsReinject*/ true); |
| 1074 | // Consume the previously pushed token. |
| 1075 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
| 1076 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
| 1077 | |
| 1078 | FNContextRAII FnContext(*this, Ptr); |
| 1079 | // Parse function declaration id. |
| 1080 | SourceLocation RLoc; |
| 1081 | // Parse with IsAddressOfOperand set to true to parse methods as DeclRefExprs |
| 1082 | // instead of MemberExprs. |
Alexey Bataev | 02d04d5 | 2019-12-10 16:12:53 -0500 | [diff] [blame] | 1083 | ExprResult AssociatedFunction; |
| 1084 | { |
| 1085 | // Do not mark function as is used to prevent its emission if this is the |
| 1086 | // only place where it is used. |
| 1087 | EnterExpressionEvaluationContext Unevaluated( |
| 1088 | Actions, Sema::ExpressionEvaluationContext::Unevaluated); |
| 1089 | AssociatedFunction = ParseOpenMPParensExpr( |
| 1090 | getOpenMPDirectiveName(OMPD_declare_variant), RLoc, |
| 1091 | /*IsAddressOfOperand=*/true); |
| 1092 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1093 | if (!AssociatedFunction.isUsable()) { |
| 1094 | if (!Tok.is(tok::annot_pragma_openmp_end)) |
| 1095 | while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch)) |
| 1096 | ; |
| 1097 | // Skip the last annot_pragma_openmp_end. |
| 1098 | (void)ConsumeAnnotationToken(); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1099 | return; |
| 1100 | } |
| 1101 | Optional<std::pair<FunctionDecl *, Expr *>> DeclVarData = |
| 1102 | Actions.checkOpenMPDeclareVariantFunction( |
| 1103 | Ptr, AssociatedFunction.get(), SourceRange(Loc, Tok.getLocation())); |
| 1104 | |
| 1105 | // Parse 'match'. |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 1106 | OpenMPClauseKind CKind = Tok.isAnnotation() |
| 1107 | ? OMPC_unknown |
| 1108 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1109 | if (CKind != OMPC_match) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1110 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_wrong_clause) |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 1111 | << getOpenMPClauseName(OMPC_match); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1112 | while (!SkipUntil(tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 1113 | ; |
| 1114 | // Skip the last annot_pragma_openmp_end. |
| 1115 | (void)ConsumeAnnotationToken(); |
| 1116 | return; |
| 1117 | } |
| 1118 | (void)ConsumeToken(); |
| 1119 | // Parse '('. |
| 1120 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 1121 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1122 | getOpenMPClauseName(OMPC_match))) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1123 | while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch)) |
| 1124 | ; |
| 1125 | // Skip the last annot_pragma_openmp_end. |
| 1126 | (void)ConsumeAnnotationToken(); |
| 1127 | return; |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1130 | // Parse inner context selectors. |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1131 | SmallVector<Sema::OMPCtxSelectorData, 4> Data; |
| 1132 | if (!parseOpenMPContextSelectors(Loc, Data)) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1133 | // Parse ')'. |
| 1134 | (void)T.consumeClose(); |
| 1135 | // Need to check for extra tokens. |
| 1136 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1137 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1138 | << getOpenMPDirectiveName(OMPD_declare_variant); |
| 1139 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1140 | } |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1141 | |
| 1142 | // Skip last tokens. |
| 1143 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1144 | ConsumeAnyToken(); |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1145 | if (DeclVarData.hasValue()) |
| 1146 | Actions.ActOnOpenMPDeclareVariantDirective( |
| 1147 | DeclVarData.getValue().first, DeclVarData.getValue().second, |
| 1148 | SourceRange(Loc, Tok.getLocation()), Data); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1149 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1150 | (void)ConsumeAnnotationToken(); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1153 | /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
| 1154 | /// |
| 1155 | /// default-clause: |
| 1156 | /// 'default' '(' 'none' | 'shared' ') |
| 1157 | /// |
| 1158 | /// proc_bind-clause: |
| 1159 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 1160 | /// |
| 1161 | /// device_type-clause: |
| 1162 | /// 'device_type' '(' 'host' | 'nohost' | 'any' )' |
| 1163 | namespace { |
| 1164 | struct SimpleClauseData { |
| 1165 | unsigned Type; |
| 1166 | SourceLocation Loc; |
| 1167 | SourceLocation LOpen; |
| 1168 | SourceLocation TypeLoc; |
| 1169 | SourceLocation RLoc; |
| 1170 | SimpleClauseData(unsigned Type, SourceLocation Loc, SourceLocation LOpen, |
| 1171 | SourceLocation TypeLoc, SourceLocation RLoc) |
| 1172 | : Type(Type), Loc(Loc), LOpen(LOpen), TypeLoc(TypeLoc), RLoc(RLoc) {} |
| 1173 | }; |
| 1174 | } // anonymous namespace |
| 1175 | |
| 1176 | static Optional<SimpleClauseData> |
| 1177 | parseOpenMPSimpleClause(Parser &P, OpenMPClauseKind Kind) { |
| 1178 | const Token &Tok = P.getCurToken(); |
| 1179 | SourceLocation Loc = Tok.getLocation(); |
| 1180 | SourceLocation LOpen = P.ConsumeToken(); |
| 1181 | // Parse '('. |
| 1182 | BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end); |
| 1183 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1184 | getOpenMPClauseName(Kind))) |
| 1185 | return llvm::None; |
| 1186 | |
| 1187 | unsigned Type = getOpenMPSimpleClauseType( |
| 1188 | Kind, Tok.isAnnotation() ? "" : P.getPreprocessor().getSpelling(Tok)); |
| 1189 | SourceLocation TypeLoc = Tok.getLocation(); |
| 1190 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1191 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1192 | P.ConsumeAnyToken(); |
| 1193 | |
| 1194 | // Parse ')'. |
| 1195 | SourceLocation RLoc = Tok.getLocation(); |
| 1196 | if (!T.consumeClose()) |
| 1197 | RLoc = T.getCloseLocation(); |
| 1198 | |
| 1199 | return SimpleClauseData(Type, Loc, LOpen, TypeLoc, RLoc); |
| 1200 | } |
| 1201 | |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1202 | Parser::DeclGroupPtrTy Parser::ParseOMPDeclareTargetClauses() { |
| 1203 | // OpenMP 4.5 syntax with list of entities. |
| 1204 | Sema::NamedDeclSetType SameDirectiveDecls; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1205 | SmallVector<std::tuple<OMPDeclareTargetDeclAttr::MapTypeTy, SourceLocation, |
| 1206 | NamedDecl *>, |
| 1207 | 4> |
| 1208 | DeclareTargetDecls; |
| 1209 | OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any; |
| 1210 | SourceLocation DeviceTypeLoc; |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1211 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1212 | OMPDeclareTargetDeclAttr::MapTypeTy MT = OMPDeclareTargetDeclAttr::MT_To; |
| 1213 | if (Tok.is(tok::identifier)) { |
| 1214 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1215 | StringRef ClauseName = II->getName(); |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1216 | bool IsDeviceTypeClause = |
| 1217 | getLangOpts().OpenMP >= 50 && |
| 1218 | getOpenMPClauseKind(ClauseName) == OMPC_device_type; |
| 1219 | // Parse 'to|link|device_type' clauses. |
| 1220 | if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName, MT) && |
| 1221 | !IsDeviceTypeClause) { |
| 1222 | Diag(Tok, diag::err_omp_declare_target_unexpected_clause) |
| 1223 | << ClauseName << (getLangOpts().OpenMP >= 50 ? 1 : 0); |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1224 | break; |
| 1225 | } |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1226 | // Parse 'device_type' clause and go to next clause if any. |
| 1227 | if (IsDeviceTypeClause) { |
| 1228 | Optional<SimpleClauseData> DevTypeData = |
| 1229 | parseOpenMPSimpleClause(*this, OMPC_device_type); |
| 1230 | if (DevTypeData.hasValue()) { |
| 1231 | if (DeviceTypeLoc.isValid()) { |
| 1232 | // We already saw another device_type clause, diagnose it. |
| 1233 | Diag(DevTypeData.getValue().Loc, |
| 1234 | diag::warn_omp_more_one_device_type_clause); |
| 1235 | } |
| 1236 | switch(static_cast<OpenMPDeviceType>(DevTypeData.getValue().Type)) { |
| 1237 | case OMPC_DEVICE_TYPE_any: |
| 1238 | DT = OMPDeclareTargetDeclAttr::DT_Any; |
| 1239 | break; |
| 1240 | case OMPC_DEVICE_TYPE_host: |
| 1241 | DT = OMPDeclareTargetDeclAttr::DT_Host; |
| 1242 | break; |
| 1243 | case OMPC_DEVICE_TYPE_nohost: |
| 1244 | DT = OMPDeclareTargetDeclAttr::DT_NoHost; |
| 1245 | break; |
| 1246 | case OMPC_DEVICE_TYPE_unknown: |
| 1247 | llvm_unreachable("Unexpected device_type"); |
| 1248 | } |
| 1249 | DeviceTypeLoc = DevTypeData.getValue().Loc; |
| 1250 | } |
| 1251 | continue; |
| 1252 | } |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1253 | ConsumeToken(); |
| 1254 | } |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1255 | auto &&Callback = [this, MT, &DeclareTargetDecls, &SameDirectiveDecls]( |
| 1256 | CXXScopeSpec &SS, DeclarationNameInfo NameInfo) { |
| 1257 | NamedDecl *ND = Actions.lookupOpenMPDeclareTargetName( |
| 1258 | getCurScope(), SS, NameInfo, SameDirectiveDecls); |
| 1259 | if (ND) |
| 1260 | DeclareTargetDecls.emplace_back(MT, NameInfo.getLoc(), ND); |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1261 | }; |
| 1262 | if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback, |
| 1263 | /*AllowScopeSpecifier=*/true)) |
| 1264 | break; |
| 1265 | |
| 1266 | // Consume optional ','. |
| 1267 | if (Tok.is(tok::comma)) |
| 1268 | ConsumeToken(); |
| 1269 | } |
| 1270 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1271 | ConsumeAnyToken(); |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1272 | for (auto &MTLocDecl : DeclareTargetDecls) { |
| 1273 | OMPDeclareTargetDeclAttr::MapTypeTy MT; |
| 1274 | SourceLocation Loc; |
| 1275 | NamedDecl *ND; |
| 1276 | std::tie(MT, Loc, ND) = MTLocDecl; |
| 1277 | // device_type clause is applied only to functions. |
| 1278 | Actions.ActOnOpenMPDeclareTargetName( |
| 1279 | ND, Loc, MT, isa<VarDecl>(ND) ? OMPDeclareTargetDeclAttr::DT_Any : DT); |
| 1280 | } |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1281 | SmallVector<Decl *, 4> Decls(SameDirectiveDecls.begin(), |
| 1282 | SameDirectiveDecls.end()); |
| 1283 | if (Decls.empty()) |
| 1284 | return DeclGroupPtrTy(); |
| 1285 | return Actions.BuildDeclaratorGroup(Decls); |
| 1286 | } |
| 1287 | |
| 1288 | void Parser::ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind DKind, |
| 1289 | SourceLocation DTLoc) { |
| 1290 | if (DKind != OMPD_end_declare_target) { |
| 1291 | Diag(Tok, diag::err_expected_end_declare_target); |
| 1292 | Diag(DTLoc, diag::note_matching) << "'#pragma omp declare target'"; |
| 1293 | return; |
| 1294 | } |
| 1295 | ConsumeAnyToken(); |
| 1296 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1297 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1298 | << getOpenMPDirectiveName(OMPD_end_declare_target); |
| 1299 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1300 | } |
| 1301 | // Skip the last annot_pragma_openmp_end. |
| 1302 | ConsumeAnyToken(); |
| 1303 | } |
| 1304 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1305 | /// Parsing of declarative OpenMP directives. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1306 | /// |
| 1307 | /// threadprivate-directive: |
| 1308 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1309 | /// annot_pragma_openmp_end |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1310 | /// |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1311 | /// allocate-directive: |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1312 | /// annot_pragma_openmp 'allocate' simple-variable-list [<clause>] |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1313 | /// annot_pragma_openmp_end |
| 1314 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1315 | /// declare-reduction-directive: |
| 1316 | /// annot_pragma_openmp 'declare' 'reduction' [...] |
| 1317 | /// annot_pragma_openmp_end |
| 1318 | /// |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1319 | /// declare-mapper-directive: |
| 1320 | /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':'] |
| 1321 | /// <type> <var> ')' [<clause>[[,] <clause>] ... ] |
| 1322 | /// annot_pragma_openmp_end |
| 1323 | /// |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1324 | /// declare-simd-directive: |
| 1325 | /// annot_pragma_openmp 'declare simd' {<clause> [,]} |
| 1326 | /// annot_pragma_openmp_end |
| 1327 | /// <function declaration/definition> |
| 1328 | /// |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1329 | /// requires directive: |
| 1330 | /// annot_pragma_openmp 'requires' <clause> [[[,] <clause>] ... ] |
| 1331 | /// annot_pragma_openmp_end |
| 1332 | /// |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1333 | Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( |
| 1334 | AccessSpecifier &AS, ParsedAttributesWithRange &Attrs, |
| 1335 | DeclSpec::TST TagType, Decl *Tag) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1336 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | 8035bb4 | 2019-12-13 16:05:30 -0500 | [diff] [blame] | 1337 | ParsingOpenMPDirectiveRAII DirScope(*this); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1338 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1339 | |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1340 | SourceLocation Loc = ConsumeAnnotationToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1341 | OpenMPDirectiveKind DKind = parseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1342 | |
| 1343 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1344 | case OMPD_threadprivate: { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1345 | ConsumeToken(); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1346 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1347 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1348 | /*AllowScopeSpecifier=*/true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1349 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1350 | // extra tokens. |
| 1351 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1352 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1353 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1354 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1355 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1356 | // Skip the last annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1357 | ConsumeAnnotationToken(); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1358 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, |
| 1359 | Helper.getIdentifiers()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1360 | } |
| 1361 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1362 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1363 | case OMPD_allocate: { |
| 1364 | ConsumeToken(); |
| 1365 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1366 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1367 | /*AllowScopeSpecifier=*/true)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1368 | SmallVector<OMPClause *, 1> Clauses; |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1369 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1370 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, |
| 1371 | OMPC_unknown + 1> |
| 1372 | FirstClauses(OMPC_unknown + 1); |
| 1373 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1374 | OpenMPClauseKind CKind = |
| 1375 | Tok.isAnnotation() ? OMPC_unknown |
| 1376 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1377 | Actions.StartOpenMPClause(CKind); |
| 1378 | OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind, |
| 1379 | !FirstClauses[CKind].getInt()); |
| 1380 | SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, |
| 1381 | StopBeforeMatch); |
| 1382 | FirstClauses[CKind].setInt(true); |
| 1383 | if (Clause != nullptr) |
| 1384 | Clauses.push_back(Clause); |
| 1385 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 1386 | Actions.EndOpenMPClause(); |
| 1387 | break; |
| 1388 | } |
| 1389 | // Skip ',' if any. |
| 1390 | if (Tok.is(tok::comma)) |
| 1391 | ConsumeToken(); |
| 1392 | Actions.EndOpenMPClause(); |
| 1393 | } |
| 1394 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1395 | // extra tokens. |
| 1396 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1397 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1398 | << getOpenMPDirectiveName(DKind); |
| 1399 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1400 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1401 | } |
| 1402 | // Skip the last annot_pragma_openmp_end. |
| 1403 | ConsumeAnnotationToken(); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1404 | return Actions.ActOnOpenMPAllocateDirective(Loc, Helper.getIdentifiers(), |
| 1405 | Clauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1406 | } |
| 1407 | break; |
| 1408 | } |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1409 | case OMPD_requires: { |
| 1410 | SourceLocation StartLoc = ConsumeToken(); |
| 1411 | SmallVector<OMPClause *, 5> Clauses; |
| 1412 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
| 1413 | FirstClauses(OMPC_unknown + 1); |
| 1414 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
Ilya Biryukov | ff2a997 | 2019-02-26 11:01:50 +0000 | [diff] [blame] | 1415 | Diag(Tok, diag::err_omp_expected_clause) |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1416 | << getOpenMPDirectiveName(OMPD_requires); |
| 1417 | break; |
| 1418 | } |
| 1419 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1420 | OpenMPClauseKind CKind = Tok.isAnnotation() |
| 1421 | ? OMPC_unknown |
| 1422 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1423 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1424 | OMPClause *Clause = ParseOpenMPClause(OMPD_requires, CKind, |
| 1425 | !FirstClauses[CKind].getInt()); |
| 1426 | SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, |
| 1427 | StopBeforeMatch); |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1428 | FirstClauses[CKind].setInt(true); |
| 1429 | if (Clause != nullptr) |
| 1430 | Clauses.push_back(Clause); |
| 1431 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 1432 | Actions.EndOpenMPClause(); |
| 1433 | break; |
| 1434 | } |
| 1435 | // Skip ',' if any. |
| 1436 | if (Tok.is(tok::comma)) |
| 1437 | ConsumeToken(); |
| 1438 | Actions.EndOpenMPClause(); |
| 1439 | } |
| 1440 | // Consume final annot_pragma_openmp_end |
| 1441 | if (Clauses.size() == 0) { |
| 1442 | Diag(Tok, diag::err_omp_expected_clause) |
| 1443 | << getOpenMPDirectiveName(OMPD_requires); |
| 1444 | ConsumeAnnotationToken(); |
| 1445 | return nullptr; |
| 1446 | } |
| 1447 | ConsumeAnnotationToken(); |
| 1448 | return Actions.ActOnOpenMPRequiresDirective(StartLoc, Clauses); |
| 1449 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1450 | case OMPD_declare_reduction: |
| 1451 | ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1452 | if (DeclGroupPtrTy Res = ParseOpenMPDeclareReductionDirective(AS)) { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1453 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1454 | // extra tokens. |
| 1455 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1456 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1457 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 1458 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1459 | ConsumeAnyToken(); |
| 1460 | } |
| 1461 | // Skip the last annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1462 | ConsumeAnnotationToken(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1463 | return Res; |
| 1464 | } |
| 1465 | break; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1466 | case OMPD_declare_mapper: { |
| 1467 | ConsumeToken(); |
| 1468 | if (DeclGroupPtrTy Res = ParseOpenMPDeclareMapperDirective(AS)) { |
| 1469 | // Skip the last annot_pragma_openmp_end. |
| 1470 | ConsumeAnnotationToken(); |
| 1471 | return Res; |
| 1472 | } |
| 1473 | break; |
| 1474 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1475 | case OMPD_declare_variant: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1476 | case OMPD_declare_simd: { |
| 1477 | // The syntax is: |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1478 | // { #pragma omp declare {simd|variant} } |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1479 | // <function-declaration-or-definition> |
| 1480 | // |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1481 | CachedTokens Toks; |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1482 | Toks.push_back(Tok); |
| 1483 | ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1484 | while(Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1485 | Toks.push_back(Tok); |
| 1486 | ConsumeAnyToken(); |
| 1487 | } |
| 1488 | Toks.push_back(Tok); |
| 1489 | ConsumeAnyToken(); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1490 | |
| 1491 | DeclGroupPtrTy Ptr; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1492 | if (Tok.is(tok::annot_pragma_openmp)) { |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1493 | Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, TagType, Tag); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1494 | } else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1495 | // Here we expect to see some function declaration. |
| 1496 | if (AS == AS_none) { |
| 1497 | assert(TagType == DeclSpec::TST_unspecified); |
| 1498 | MaybeParseCXX11Attributes(Attrs); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1499 | ParsingDeclSpec PDS(*this); |
| 1500 | Ptr = ParseExternalDeclaration(Attrs, &PDS); |
| 1501 | } else { |
| 1502 | Ptr = |
| 1503 | ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag); |
| 1504 | } |
| 1505 | } |
| 1506 | if (!Ptr) { |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1507 | Diag(Loc, diag::err_omp_decl_in_declare_simd_variant) |
| 1508 | << (DKind == OMPD_declare_simd ? 0 : 1); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1509 | return DeclGroupPtrTy(); |
| 1510 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1511 | if (DKind == OMPD_declare_simd) |
| 1512 | return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc); |
| 1513 | assert(DKind == OMPD_declare_variant && |
| 1514 | "Expected declare variant directive only"); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1515 | ParseOMPDeclareVariantClauses(Ptr, Toks, Loc); |
| 1516 | return Ptr; |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1517 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1518 | case OMPD_declare_target: { |
| 1519 | SourceLocation DTLoc = ConsumeAnyToken(); |
| 1520 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1521 | return ParseOMPDeclareTargetClauses(); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1522 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1523 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1524 | // Skip the last annot_pragma_openmp_end. |
| 1525 | ConsumeAnyToken(); |
| 1526 | |
| 1527 | if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc)) |
| 1528 | return DeclGroupPtrTy(); |
| 1529 | |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1530 | llvm::SmallVector<Decl *, 4> Decls; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1531 | DKind = parseOpenMPDirectiveKind(*this); |
Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 1532 | while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) && |
| 1533 | Tok.isNot(tok::r_brace)) { |
Alexey Bataev | 502ec49 | 2017-10-03 20:00:00 +0000 | [diff] [blame] | 1534 | DeclGroupPtrTy Ptr; |
| 1535 | // Here we expect to see some function declaration. |
| 1536 | if (AS == AS_none) { |
| 1537 | assert(TagType == DeclSpec::TST_unspecified); |
| 1538 | MaybeParseCXX11Attributes(Attrs); |
| 1539 | ParsingDeclSpec PDS(*this); |
| 1540 | Ptr = ParseExternalDeclaration(Attrs, &PDS); |
| 1541 | } else { |
| 1542 | Ptr = |
| 1543 | ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag); |
| 1544 | } |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1545 | if (Ptr) { |
| 1546 | DeclGroupRef Ref = Ptr.get(); |
| 1547 | Decls.append(Ref.begin(), Ref.end()); |
| 1548 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1549 | if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) { |
| 1550 | TentativeParsingAction TPA(*this); |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1551 | ConsumeAnnotationToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1552 | DKind = parseOpenMPDirectiveKind(*this); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1553 | if (DKind != OMPD_end_declare_target) |
| 1554 | TPA.Revert(); |
| 1555 | else |
| 1556 | TPA.Commit(); |
| 1557 | } |
| 1558 | } |
| 1559 | |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1560 | ParseOMPEndDeclareTargetDirective(DKind, DTLoc); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1561 | Actions.ActOnFinishOpenMPDeclareTargetDirective(); |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 1562 | return Actions.BuildDeclaratorGroup(Decls); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1563 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1564 | case OMPD_unknown: |
| 1565 | Diag(Tok, diag::err_omp_unknown_directive); |
| 1566 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1567 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1568 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1569 | case OMPD_task: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1570 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1571 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1572 | case OMPD_taskwait: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1573 | case OMPD_taskgroup: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1574 | case OMPD_flush: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1575 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1576 | case OMPD_for_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1577 | case OMPD_sections: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1578 | case OMPD_section: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1579 | case OMPD_single: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1580 | case OMPD_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1581 | case OMPD_ordered: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1582 | case OMPD_critical: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1583 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1584 | case OMPD_parallel_for_simd: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1585 | case OMPD_parallel_sections: |
cchen | 47d6094 | 2019-12-05 13:43:48 -0500 | [diff] [blame] | 1586 | case OMPD_parallel_master: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1587 | case OMPD_atomic: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1588 | case OMPD_target: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1589 | case OMPD_teams: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1590 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1591 | case OMPD_cancel: |
Samuel Antao | 5b0688e | 2015-07-22 16:02:46 +0000 | [diff] [blame] | 1592 | case OMPD_target_data: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1593 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1594 | case OMPD_target_exit_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1595 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1596 | case OMPD_target_parallel_for: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1597 | case OMPD_taskloop: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1598 | case OMPD_taskloop_simd: |
Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 1599 | case OMPD_master_taskloop: |
Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 1600 | case OMPD_master_taskloop_simd: |
Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 1601 | case OMPD_parallel_master_taskloop: |
Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 1602 | case OMPD_parallel_master_taskloop_simd: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1603 | case OMPD_distribute: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1604 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1605 | case OMPD_target_update: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1606 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1607 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1608 | case OMPD_distribute_simd: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1609 | case OMPD_target_parallel_for_simd: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1610 | case OMPD_target_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1611 | case OMPD_teams_distribute: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1612 | case OMPD_teams_distribute_simd: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1613 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1614 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1615 | case OMPD_target_teams: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1616 | case OMPD_target_teams_distribute: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1617 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1618 | case OMPD_target_teams_distribute_parallel_for_simd: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1619 | case OMPD_target_teams_distribute_simd: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1620 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | 96dae81 | 2018-02-16 18:36:44 +0000 | [diff] [blame] | 1621 | << 1 << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1622 | break; |
| 1623 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1624 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1625 | ConsumeAnyToken(); |
| 1626 | ConsumeAnyToken(); |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1627 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1630 | /// Parsing of declarative or executable OpenMP directives. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1631 | /// |
| 1632 | /// threadprivate-directive: |
| 1633 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 1634 | /// annot_pragma_openmp_end |
| 1635 | /// |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1636 | /// allocate-directive: |
| 1637 | /// annot_pragma_openmp 'allocate' simple-variable-list |
| 1638 | /// annot_pragma_openmp_end |
| 1639 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1640 | /// declare-reduction-directive: |
| 1641 | /// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':' |
| 1642 | /// <type> {',' <type>} ':' <expression> ')' ['initializer' '(' |
| 1643 | /// ('omp_priv' '=' <expression>|<function_call>) ')'] |
| 1644 | /// annot_pragma_openmp_end |
| 1645 | /// |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1646 | /// declare-mapper-directive: |
| 1647 | /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':'] |
| 1648 | /// <type> <var> ')' [<clause>[[,] <clause>] ... ] |
| 1649 | /// annot_pragma_openmp_end |
| 1650 | /// |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1651 | /// executable-directive: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1652 | /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1653 | /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] | |
cchen | 47d6094 | 2019-12-05 13:43:48 -0500 | [diff] [blame] | 1654 | /// 'parallel for' | 'parallel sections' | 'parallel master' | 'task' | |
| 1655 | /// 'taskyield' | 'barrier' | 'taskwait' | 'flush' | 'ordered' | |
| 1656 | /// 'atomic' | 'for simd' | 'parallel for simd' | 'target' | 'target |
| 1657 | /// data' | 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | |
| 1658 | /// 'master taskloop' | 'master taskloop simd' | 'parallel master |
| 1659 | /// taskloop' | 'parallel master taskloop simd' | 'distribute' | 'target |
| 1660 | /// enter data' | 'target exit data' | 'target parallel' | 'target |
| 1661 | /// parallel for' | 'target update' | 'distribute parallel for' | |
| 1662 | /// 'distribute paralle for simd' | 'distribute simd' | 'target parallel |
| 1663 | /// for simd' | 'target simd' | 'teams distribute' | 'teams distribute |
| 1664 | /// simd' | 'teams distribute parallel for simd' | 'teams distribute |
| 1665 | /// parallel for' | 'target teams' | 'target teams distribute' | 'target |
| 1666 | /// teams distribute parallel for' | 'target teams distribute parallel |
| 1667 | /// for simd' | 'target teams distribute simd' {clause} |
Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 1668 | /// annot_pragma_openmp_end |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1669 | /// |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1670 | StmtResult |
| 1671 | Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1672 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | 8035bb4 | 2019-12-13 16:05:30 -0500 | [diff] [blame] | 1673 | ParsingOpenMPDirectiveRAII DirScope(*this); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1674 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1675 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1676 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1677 | FirstClauses(OMPC_unknown + 1); |
Momchil Velikov | 57c681f | 2017-08-10 15:43:06 +0000 | [diff] [blame] | 1678 | unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope | |
| 1679 | Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope; |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1680 | SourceLocation Loc = ConsumeAnnotationToken(), EndLoc; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1681 | OpenMPDirectiveKind DKind = parseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1682 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1683 | // Name of critical directive. |
| 1684 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1685 | StmtResult Directive = StmtError(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1686 | bool HasAssociatedStatement = true; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1687 | bool FlushHasClause = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1688 | |
| 1689 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1690 | case OMPD_threadprivate: { |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1691 | // FIXME: Should this be permitted in C++? |
| 1692 | if ((StmtCtx & ParsedStmtContext::AllowDeclarationsInC) == |
| 1693 | ParsedStmtContext()) { |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 1694 | Diag(Tok, diag::err_omp_immediate_directive) |
| 1695 | << getOpenMPDirectiveName(DKind) << 0; |
| 1696 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1697 | ConsumeToken(); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1698 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1699 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1700 | /*AllowScopeSpecifier=*/false)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1701 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1702 | // extra tokens. |
| 1703 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1704 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1705 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1706 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1707 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1708 | DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective( |
| 1709 | Loc, Helper.getIdentifiers()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1710 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 1711 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1712 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1713 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1714 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1715 | case OMPD_allocate: { |
| 1716 | // FIXME: Should this be permitted in C++? |
| 1717 | if ((StmtCtx & ParsedStmtContext::AllowDeclarationsInC) == |
| 1718 | ParsedStmtContext()) { |
| 1719 | Diag(Tok, diag::err_omp_immediate_directive) |
| 1720 | << getOpenMPDirectiveName(DKind) << 0; |
| 1721 | } |
| 1722 | ConsumeToken(); |
| 1723 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1724 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1725 | /*AllowScopeSpecifier=*/false)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1726 | SmallVector<OMPClause *, 1> Clauses; |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1727 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1728 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, |
| 1729 | OMPC_unknown + 1> |
| 1730 | FirstClauses(OMPC_unknown + 1); |
| 1731 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1732 | OpenMPClauseKind CKind = |
| 1733 | Tok.isAnnotation() ? OMPC_unknown |
| 1734 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1735 | Actions.StartOpenMPClause(CKind); |
| 1736 | OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind, |
| 1737 | !FirstClauses[CKind].getInt()); |
| 1738 | SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, |
| 1739 | StopBeforeMatch); |
| 1740 | FirstClauses[CKind].setInt(true); |
| 1741 | if (Clause != nullptr) |
| 1742 | Clauses.push_back(Clause); |
| 1743 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 1744 | Actions.EndOpenMPClause(); |
| 1745 | break; |
| 1746 | } |
| 1747 | // Skip ',' if any. |
| 1748 | if (Tok.is(tok::comma)) |
| 1749 | ConsumeToken(); |
| 1750 | Actions.EndOpenMPClause(); |
| 1751 | } |
| 1752 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1753 | // extra tokens. |
| 1754 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1755 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1756 | << getOpenMPDirectiveName(DKind); |
| 1757 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1758 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1759 | } |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1760 | DeclGroupPtrTy Res = Actions.ActOnOpenMPAllocateDirective( |
| 1761 | Loc, Helper.getIdentifiers(), Clauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1762 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 1763 | } |
| 1764 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1765 | break; |
| 1766 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1767 | case OMPD_declare_reduction: |
| 1768 | ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1769 | if (DeclGroupPtrTy Res = |
| 1770 | ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1771 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1772 | // extra tokens. |
| 1773 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1774 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1775 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 1776 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1777 | ConsumeAnyToken(); |
| 1778 | } |
| 1779 | ConsumeAnyToken(); |
| 1780 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1781 | } else { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1782 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1783 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1784 | break; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1785 | case OMPD_declare_mapper: { |
| 1786 | ConsumeToken(); |
| 1787 | if (DeclGroupPtrTy Res = |
| 1788 | ParseOpenMPDeclareMapperDirective(/*AS=*/AS_none)) { |
| 1789 | // Skip the last annot_pragma_openmp_end. |
| 1790 | ConsumeAnnotationToken(); |
| 1791 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 1792 | } else { |
| 1793 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1794 | } |
| 1795 | break; |
| 1796 | } |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1797 | case OMPD_flush: |
| 1798 | if (PP.LookAhead(0).is(tok::l_paren)) { |
| 1799 | FlushHasClause = true; |
| 1800 | // Push copy of the current token back to stream to properly parse |
| 1801 | // pseudo-clause OMPFlushClause. |
Ilya Biryukov | 929af67 | 2019-05-17 09:32:05 +0000 | [diff] [blame] | 1802 | PP.EnterToken(Tok, /*IsReinject*/ true); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1803 | } |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 1804 | LLVM_FALLTHROUGH; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1805 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1806 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1807 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1808 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1809 | case OMPD_cancel: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1810 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1811 | case OMPD_target_exit_data: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1812 | case OMPD_target_update: |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1813 | if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) == |
| 1814 | ParsedStmtContext()) { |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1815 | Diag(Tok, diag::err_omp_immediate_directive) |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1816 | << getOpenMPDirectiveName(DKind) << 0; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1817 | } |
| 1818 | HasAssociatedStatement = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1819 | // Fall through for further analysis. |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 1820 | LLVM_FALLTHROUGH; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1821 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1822 | case OMPD_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1823 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1824 | case OMPD_for_simd: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1825 | case OMPD_sections: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1826 | case OMPD_single: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1827 | case OMPD_section: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1828 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1829 | case OMPD_critical: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1830 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1831 | case OMPD_parallel_for_simd: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1832 | case OMPD_parallel_sections: |
cchen | 47d6094 | 2019-12-05 13:43:48 -0500 | [diff] [blame] | 1833 | case OMPD_parallel_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1834 | case OMPD_task: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1835 | case OMPD_ordered: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1836 | case OMPD_atomic: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1837 | case OMPD_target: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1838 | case OMPD_teams: |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1839 | case OMPD_taskgroup: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1840 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1841 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1842 | case OMPD_target_parallel_for: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1843 | case OMPD_taskloop: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1844 | case OMPD_taskloop_simd: |
Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 1845 | case OMPD_master_taskloop: |
Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 1846 | case OMPD_master_taskloop_simd: |
Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 1847 | case OMPD_parallel_master_taskloop: |
Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 1848 | case OMPD_parallel_master_taskloop_simd: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1849 | case OMPD_distribute: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1850 | case OMPD_distribute_parallel_for: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1851 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1852 | case OMPD_distribute_simd: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1853 | case OMPD_target_parallel_for_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1854 | case OMPD_target_simd: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1855 | case OMPD_teams_distribute: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1856 | case OMPD_teams_distribute_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1857 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1858 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1859 | case OMPD_target_teams: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1860 | case OMPD_target_teams_distribute: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1861 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1862 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 1863 | case OMPD_target_teams_distribute_simd: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1864 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1865 | // Parse directive name of the 'critical' directive if any. |
| 1866 | if (DKind == OMPD_critical) { |
| 1867 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 1868 | tok::annot_pragma_openmp_end); |
| 1869 | if (!T.consumeOpen()) { |
| 1870 | if (Tok.isAnyIdentifier()) { |
| 1871 | DirName = |
| 1872 | DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 1873 | ConsumeAnyToken(); |
| 1874 | } else { |
| 1875 | Diag(Tok, diag::err_omp_expected_identifier_for_critical); |
| 1876 | } |
| 1877 | T.consumeClose(); |
| 1878 | } |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1879 | } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) { |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1880 | CancelRegion = parseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1881 | if (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1882 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1883 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1884 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1885 | if (isOpenMPLoopDirective(DKind)) |
| 1886 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 1887 | if (isOpenMPSimdDirective(DKind)) |
| 1888 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 1889 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1890 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1891 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1892 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1893 | OpenMPClauseKind CKind = |
| 1894 | Tok.isAnnotation() |
| 1895 | ? OMPC_unknown |
| 1896 | : FlushHasClause ? OMPC_flush |
| 1897 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1898 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1899 | FlushHasClause = false; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1900 | OMPClause *Clause = |
| 1901 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1902 | FirstClauses[CKind].setInt(true); |
| 1903 | if (Clause) { |
| 1904 | FirstClauses[CKind].setPointer(Clause); |
| 1905 | Clauses.push_back(Clause); |
| 1906 | } |
| 1907 | |
| 1908 | // Skip ',' if any. |
| 1909 | if (Tok.is(tok::comma)) |
| 1910 | ConsumeToken(); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1911 | Actions.EndOpenMPClause(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1912 | } |
| 1913 | // End location of the directive. |
| 1914 | EndLoc = Tok.getLocation(); |
| 1915 | // Consume final annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1916 | ConsumeAnnotationToken(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1917 | |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1918 | // OpenMP [2.13.8, ordered Construct, Syntax] |
| 1919 | // If the depend clause is specified, the ordered construct is a stand-alone |
| 1920 | // directive. |
| 1921 | if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) { |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1922 | if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) == |
| 1923 | ParsedStmtContext()) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1924 | Diag(Loc, diag::err_omp_immediate_directive) |
| 1925 | << getOpenMPDirectiveName(DKind) << 1 |
| 1926 | << getOpenMPClauseName(OMPC_depend); |
| 1927 | } |
| 1928 | HasAssociatedStatement = false; |
| 1929 | } |
| 1930 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1931 | StmtResult AssociatedStmt; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1932 | if (HasAssociatedStatement) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1933 | // The body is a block scope like in Lambdas and Blocks. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1934 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Richard Smith | 6eb9b9e | 2018-02-03 00:44:57 +0000 | [diff] [blame] | 1935 | // FIXME: We create a bogus CompoundStmt scope to hold the contents of |
| 1936 | // the captured region. Code elsewhere assumes that any FunctionScopeInfo |
| 1937 | // should have at least one compound statement scope within it. |
| 1938 | AssociatedStmt = (Sema::CompoundScopeRAII(Actions), ParseStatement()); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1939 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 1940 | } else if (DKind == OMPD_target_update || DKind == OMPD_target_enter_data || |
| 1941 | DKind == OMPD_target_exit_data) { |
Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 1942 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Richard Smith | 6eb9b9e | 2018-02-03 00:44:57 +0000 | [diff] [blame] | 1943 | AssociatedStmt = (Sema::CompoundScopeRAII(Actions), |
| 1944 | Actions.ActOnCompoundStmt(Loc, Loc, llvm::None, |
| 1945 | /*isStmtExpr=*/false)); |
Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 1946 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1947 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1948 | Directive = Actions.ActOnOpenMPExecutableDirective( |
| 1949 | DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc, |
| 1950 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1951 | |
| 1952 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1953 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1954 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1955 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1956 | } |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1957 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1958 | case OMPD_declare_target: |
| 1959 | case OMPD_end_declare_target: |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1960 | case OMPD_requires: |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1961 | case OMPD_declare_variant: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1962 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | 96dae81 | 2018-02-16 18:36:44 +0000 | [diff] [blame] | 1963 | << 1 << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1964 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1965 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1966 | case OMPD_unknown: |
| 1967 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1968 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1969 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1970 | } |
| 1971 | return Directive; |
| 1972 | } |
| 1973 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1974 | // Parses simple list: |
| 1975 | // simple-variable-list: |
| 1976 | // '(' id-expression {, id-expression} ')' |
| 1977 | // |
| 1978 | bool Parser::ParseOpenMPSimpleVarList( |
| 1979 | OpenMPDirectiveKind Kind, |
| 1980 | const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> & |
| 1981 | Callback, |
| 1982 | bool AllowScopeSpecifier) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1983 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1984 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1985 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 1986 | getOpenMPDirectiveName(Kind).data())) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1987 | return true; |
| 1988 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1989 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1990 | |
| 1991 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1992 | 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] | 1993 | CXXScopeSpec SS; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1994 | UnqualifiedId Name; |
| 1995 | // Read var name. |
| 1996 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1997 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1998 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1999 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 2000 | ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2001 | IsCorrect = false; |
| 2002 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2003 | StopBeforeMatch); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 2004 | } else if (ParseUnqualifiedId(SS, false, false, false, false, nullptr, |
Richard Smith | c08b693 | 2018-04-27 02:00:13 +0000 | [diff] [blame] | 2005 | nullptr, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2006 | IsCorrect = false; |
| 2007 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2008 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2009 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 2010 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 2011 | IsCorrect = false; |
| 2012 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2013 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2014 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 2015 | << tok::identifier |
| 2016 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2017 | } else { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 2018 | Callback(SS, Actions.GetNameFromUnqualifiedId(Name)); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2019 | } |
| 2020 | // Consume ','. |
| 2021 | if (Tok.is(tok::comma)) { |
| 2022 | ConsumeToken(); |
| 2023 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2024 | } |
| 2025 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2026 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2027 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2028 | IsCorrect = false; |
| 2029 | } |
| 2030 | |
| 2031 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2032 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2033 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 2034 | return !IsCorrect; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2035 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2036 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2037 | /// Parsing of OpenMP clauses. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2038 | /// |
| 2039 | /// clause: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2040 | /// if-clause | final-clause | num_threads-clause | safelen-clause | |
| 2041 | /// default-clause | private-clause | firstprivate-clause | shared-clause |
| 2042 | /// | linear-clause | aligned-clause | collapse-clause | |
| 2043 | /// lastprivate-clause | reduction-clause | proc_bind-clause | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 2044 | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 2045 | /// mergeable-clause | flush-clause | read-clause | write-clause | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2046 | /// update-clause | capture-clause | seq_cst-clause | device-clause | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 2047 | /// simdlen-clause | threads-clause | simd-clause | num_teams-clause | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2048 | /// thread_limit-clause | priority-clause | grainsize-clause | |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 2049 | /// nogroup-clause | num_tasks-clause | hint-clause | to-clause | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2050 | /// from-clause | is_device_ptr-clause | task_reduction-clause | |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2051 | /// in_reduction-clause | allocator-clause | allocate-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2052 | /// |
| 2053 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 2054 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2055 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2056 | bool ErrorFound = false; |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2057 | bool WrongDirective = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2058 | // Check if clause is allowed for the given directive. |
Alexey Bataev | d08c056 | 2019-11-19 12:07:54 -0500 | [diff] [blame] | 2059 | if (CKind != OMPC_unknown && |
| 2060 | !isAllowedClauseForDirective(DKind, CKind, getLangOpts().OpenMP)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 2061 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 2062 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2063 | ErrorFound = true; |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2064 | WrongDirective = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2065 | } |
| 2066 | |
| 2067 | switch (CKind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2068 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 2069 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 2070 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2071 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2072 | case OMPC_collapse: |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2073 | case OMPC_ordered: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 2074 | case OMPC_device: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 2075 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 2076 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2077 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2078 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 2079 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2080 | case OMPC_hint: |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2081 | case OMPC_allocator: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2082 | // OpenMP [2.5, Restrictions] |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 2083 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 2084 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2085 | // Only one safelen clause can appear on a simd directive. |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2086 | // Only one simdlen clause can appear on a simd directive. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2087 | // Only one collapse clause can appear on a simd directive. |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 2088 | // OpenMP [2.9.1, target data construct, Restrictions] |
| 2089 | // At most one device clause can appear on the directive. |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2090 | // OpenMP [2.11.1, task Construct, Restrictions] |
| 2091 | // At most one if clause can appear on the directive. |
| 2092 | // At most one final clause can appear on the directive. |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 2093 | // OpenMP [teams Construct, Restrictions] |
| 2094 | // At most one num_teams clause can appear on the directive. |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 2095 | // At most one thread_limit clause can appear on the directive. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2096 | // OpenMP [2.9.1, task Construct, Restrictions] |
| 2097 | // At most one priority clause can appear on the directive. |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2098 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 2099 | // At most one grainsize clause can appear on the directive. |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 2100 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 2101 | // At most one num_tasks clause can appear on the directive. |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2102 | // OpenMP [2.11.3, allocate Directive, Restrictions] |
| 2103 | // At most one allocator clause can appear on the directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2104 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2105 | Diag(Tok, diag::err_omp_more_one_clause) |
| 2106 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2107 | ErrorFound = true; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2108 | } |
| 2109 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2110 | if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren)) |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2111 | Clause = ParseOpenMPClause(CKind, WrongDirective); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2112 | else |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2113 | Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2114 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2115 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2116 | case OMPC_proc_bind: |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 2117 | case OMPC_atomic_default_mem_order: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2118 | // OpenMP [2.14.3.1, Restrictions] |
| 2119 | // Only a single default clause may be specified on a parallel, task or |
| 2120 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2121 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 2122 | // At most one proc_bind clause can appear on the directive. |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 2123 | // OpenMP [5.0, Requires directive, Restrictions] |
| 2124 | // At most one atomic_default_mem_order clause can appear |
| 2125 | // on the directive |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2126 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2127 | Diag(Tok, diag::err_omp_more_one_clause) |
| 2128 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2129 | ErrorFound = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2130 | } |
| 2131 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2132 | Clause = ParseOpenMPSimpleClause(CKind, WrongDirective); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2133 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2134 | case OMPC_schedule: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2135 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2136 | case OMPC_defaultmap: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2137 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 2138 | // Only one schedule clause can appear on a loop directive. |
cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2139 | // OpenMP 4.5 [2.10.4, Restrictions, p. 106] |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2140 | // At most one defaultmap clause can appear on the directive. |
cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2141 | if ((getLangOpts().OpenMP < 50 || CKind != OMPC_defaultmap) && |
| 2142 | !FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2143 | Diag(Tok, diag::err_omp_more_one_clause) |
| 2144 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2145 | ErrorFound = true; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2146 | } |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 2147 | LLVM_FALLTHROUGH; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2148 | case OMPC_if: |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2149 | Clause = ParseOpenMPSingleExprWithArgClause(CKind, WrongDirective); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2150 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2151 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 2152 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 2153 | case OMPC_mergeable: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 2154 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2155 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 2156 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 2157 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 2158 | case OMPC_seq_cst: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2159 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2160 | case OMPC_simd: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 2161 | case OMPC_nogroup: |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2162 | case OMPC_unified_address: |
Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 2163 | case OMPC_unified_shared_memory: |
Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 2164 | case OMPC_reverse_offload: |
Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 2165 | case OMPC_dynamic_allocators: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2166 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 2167 | // Only one ordered clause can appear on a loop directive. |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2168 | // OpenMP [2.7.1, Restrictions, C/C++, p. 4] |
| 2169 | // Only one nowait clause can appear on a for directive. |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2170 | // OpenMP [5.0, Requires directive, Restrictions] |
| 2171 | // Each of the requires clauses can appear at most once on the directive. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2172 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2173 | Diag(Tok, diag::err_omp_more_one_clause) |
| 2174 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2175 | ErrorFound = true; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2176 | } |
| 2177 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2178 | Clause = ParseOpenMPClause(CKind, WrongDirective); |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2179 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2180 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2181 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2182 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2183 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2184 | case OMPC_reduction: |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 2185 | case OMPC_task_reduction: |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2186 | case OMPC_in_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2187 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 2188 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 2189 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2190 | case OMPC_copyprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2191 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2192 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2193 | case OMPC_map: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 2194 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 2195 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 2196 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 2197 | case OMPC_is_device_ptr: |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2198 | case OMPC_allocate: |
Alexey Bataev | b6e7084 | 2019-12-16 15:54:17 -0500 | [diff] [blame] | 2199 | case OMPC_nontemporal: |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2200 | Clause = ParseOpenMPVarListClause(DKind, CKind, WrongDirective); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2201 | break; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2202 | case OMPC_device_type: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2203 | case OMPC_unknown: |
| 2204 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 2205 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2206 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2207 | break; |
| 2208 | case OMPC_threadprivate: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2209 | case OMPC_uniform: |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 2210 | case OMPC_match: |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2211 | if (!WrongDirective) |
| 2212 | Diag(Tok, diag::err_omp_unexpected_clause) |
| 2213 | << getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2214 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2215 | break; |
| 2216 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2217 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2218 | } |
| 2219 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2220 | /// Parses simple expression in parens for single-expression clauses of OpenMP |
| 2221 | /// constructs. |
| 2222 | /// \param RLoc Returned location of right paren. |
| 2223 | ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName, |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 2224 | SourceLocation &RLoc, |
| 2225 | bool IsAddressOfOperand) { |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2226 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 2227 | if (T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data())) |
| 2228 | return ExprError(); |
| 2229 | |
| 2230 | SourceLocation ELoc = Tok.getLocation(); |
| 2231 | ExprResult LHS(ParseCastExpression( |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 2232 | /*isUnaryExpression=*/false, IsAddressOfOperand, NotTypeCast)); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2233 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 2234 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc, /*DiscardedValue*/ false); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2235 | |
| 2236 | // Parse ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2237 | RLoc = Tok.getLocation(); |
| 2238 | if (!T.consumeClose()) |
| 2239 | RLoc = T.getCloseLocation(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2240 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2241 | return Val; |
| 2242 | } |
| 2243 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2244 | /// Parsing of OpenMP clauses with single expressions like 'final', |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2245 | /// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams', |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2246 | /// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2247 | /// |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2248 | /// final-clause: |
| 2249 | /// 'final' '(' expression ')' |
| 2250 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 2251 | /// num_threads-clause: |
| 2252 | /// 'num_threads' '(' expression ')' |
| 2253 | /// |
| 2254 | /// safelen-clause: |
| 2255 | /// 'safelen' '(' expression ')' |
| 2256 | /// |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2257 | /// simdlen-clause: |
| 2258 | /// 'simdlen' '(' expression ')' |
| 2259 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2260 | /// collapse-clause: |
| 2261 | /// 'collapse' '(' expression ')' |
| 2262 | /// |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2263 | /// priority-clause: |
| 2264 | /// 'priority' '(' expression ')' |
| 2265 | /// |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2266 | /// grainsize-clause: |
| 2267 | /// 'grainsize' '(' expression ')' |
| 2268 | /// |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 2269 | /// num_tasks-clause: |
| 2270 | /// 'num_tasks' '(' expression ')' |
| 2271 | /// |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2272 | /// hint-clause: |
| 2273 | /// 'hint' '(' expression ')' |
| 2274 | /// |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2275 | /// allocator-clause: |
| 2276 | /// 'allocator' '(' expression ')' |
| 2277 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2278 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind, |
| 2279 | bool ParseOnly) { |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2280 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2281 | SourceLocation LLoc = Tok.getLocation(); |
| 2282 | SourceLocation RLoc; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2283 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2284 | ExprResult Val = ParseOpenMPParensExpr(getOpenMPClauseName(Kind), RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2285 | |
| 2286 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2287 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2288 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2289 | if (ParseOnly) |
| 2290 | return nullptr; |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2291 | return Actions.ActOnOpenMPSingleExprClause(Kind, Val.get(), Loc, LLoc, RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2292 | } |
| 2293 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2294 | /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2295 | /// |
| 2296 | /// default-clause: |
| 2297 | /// 'default' '(' 'none' | 'shared' ') |
| 2298 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2299 | /// proc_bind-clause: |
| 2300 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 2301 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2302 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind, |
| 2303 | bool ParseOnly) { |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2304 | llvm::Optional<SimpleClauseData> Val = parseOpenMPSimpleClause(*this, Kind); |
| 2305 | if (!Val || ParseOnly) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2306 | return nullptr; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2307 | return Actions.ActOnOpenMPSimpleClause( |
| 2308 | Kind, Val.getValue().Type, Val.getValue().TypeLoc, Val.getValue().LOpen, |
| 2309 | Val.getValue().Loc, Val.getValue().RLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2310 | } |
| 2311 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2312 | /// Parsing of OpenMP clauses like 'ordered'. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2313 | /// |
| 2314 | /// ordered-clause: |
| 2315 | /// 'ordered' |
| 2316 | /// |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2317 | /// nowait-clause: |
| 2318 | /// 'nowait' |
| 2319 | /// |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 2320 | /// untied-clause: |
| 2321 | /// 'untied' |
| 2322 | /// |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 2323 | /// mergeable-clause: |
| 2324 | /// 'mergeable' |
| 2325 | /// |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 2326 | /// read-clause: |
| 2327 | /// 'read' |
| 2328 | /// |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2329 | /// threads-clause: |
| 2330 | /// 'threads' |
| 2331 | /// |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2332 | /// simd-clause: |
| 2333 | /// 'simd' |
| 2334 | /// |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 2335 | /// nogroup-clause: |
| 2336 | /// 'nogroup' |
| 2337 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2338 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind, bool ParseOnly) { |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2339 | SourceLocation Loc = Tok.getLocation(); |
| 2340 | ConsumeAnyToken(); |
| 2341 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2342 | if (ParseOnly) |
| 2343 | return nullptr; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2344 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 2345 | } |
| 2346 | |
| 2347 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2348 | /// Parsing of OpenMP clauses with single expressions and some additional |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2349 | /// argument like 'schedule' or 'dist_schedule'. |
| 2350 | /// |
| 2351 | /// schedule-clause: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2352 | /// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ] |
| 2353 | /// ')' |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2354 | /// |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2355 | /// if-clause: |
| 2356 | /// 'if' '(' [ directive-name-modifier ':' ] expression ')' |
| 2357 | /// |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2358 | /// defaultmap: |
| 2359 | /// 'defaultmap' '(' modifier ':' kind ')' |
| 2360 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2361 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind, |
| 2362 | bool ParseOnly) { |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2363 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2364 | SourceLocation DelimLoc; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2365 | // Parse '('. |
| 2366 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 2367 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 2368 | getOpenMPClauseName(Kind))) |
| 2369 | return nullptr; |
| 2370 | |
| 2371 | ExprResult Val; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2372 | SmallVector<unsigned, 4> Arg; |
| 2373 | SmallVector<SourceLocation, 4> KLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2374 | if (Kind == OMPC_schedule) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2375 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 2376 | Arg.resize(NumberOfElements); |
| 2377 | KLoc.resize(NumberOfElements); |
| 2378 | Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 2379 | Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 2380 | Arg[ScheduleKind] = OMPC_SCHEDULE_unknown; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2381 | unsigned KindModifier = getOpenMPSimpleClauseType( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2382 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2383 | if (KindModifier > OMPC_SCHEDULE_unknown) { |
| 2384 | // Parse 'modifier' |
| 2385 | Arg[Modifier1] = KindModifier; |
| 2386 | KLoc[Modifier1] = Tok.getLocation(); |
| 2387 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2388 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2389 | ConsumeAnyToken(); |
| 2390 | if (Tok.is(tok::comma)) { |
| 2391 | // Parse ',' 'modifier' |
| 2392 | ConsumeAnyToken(); |
| 2393 | KindModifier = getOpenMPSimpleClauseType( |
| 2394 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 2395 | Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown |
| 2396 | ? KindModifier |
Aaron Ballman | ad8a104 | 2015-12-28 15:52:46 +0000 | [diff] [blame] | 2397 | : (unsigned)OMPC_SCHEDULE_unknown; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2398 | KLoc[Modifier2] = Tok.getLocation(); |
| 2399 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2400 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2401 | ConsumeAnyToken(); |
| 2402 | } |
| 2403 | // Parse ':' |
| 2404 | if (Tok.is(tok::colon)) |
| 2405 | ConsumeAnyToken(); |
| 2406 | else |
| 2407 | Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier"; |
| 2408 | KindModifier = getOpenMPSimpleClauseType( |
| 2409 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 2410 | } |
| 2411 | Arg[ScheduleKind] = KindModifier; |
| 2412 | KLoc[ScheduleKind] = Tok.getLocation(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2413 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2414 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2415 | ConsumeAnyToken(); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2416 | if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static || |
| 2417 | Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic || |
| 2418 | Arg[ScheduleKind] == OMPC_SCHEDULE_guided) && |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2419 | Tok.is(tok::comma)) |
| 2420 | DelimLoc = ConsumeAnyToken(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2421 | } else if (Kind == OMPC_dist_schedule) { |
| 2422 | Arg.push_back(getOpenMPSimpleClauseType( |
| 2423 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 2424 | KLoc.push_back(Tok.getLocation()); |
| 2425 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2426 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2427 | ConsumeAnyToken(); |
| 2428 | if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma)) |
| 2429 | DelimLoc = ConsumeAnyToken(); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2430 | } else if (Kind == OMPC_defaultmap) { |
| 2431 | // Get a defaultmap modifier |
cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2432 | unsigned Modifier = getOpenMPSimpleClauseType( |
| 2433 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 2434 | // Set defaultmap modifier to unknown if it is either scalar, aggregate, or |
| 2435 | // pointer |
| 2436 | if (Modifier < OMPC_DEFAULTMAP_MODIFIER_unknown) |
| 2437 | Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown; |
| 2438 | Arg.push_back(Modifier); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2439 | KLoc.push_back(Tok.getLocation()); |
| 2440 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2441 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2442 | ConsumeAnyToken(); |
| 2443 | // Parse ':' |
| 2444 | if (Tok.is(tok::colon)) |
| 2445 | ConsumeAnyToken(); |
| 2446 | else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown) |
| 2447 | Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier"; |
| 2448 | // Get a defaultmap kind |
| 2449 | Arg.push_back(getOpenMPSimpleClauseType( |
| 2450 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 2451 | KLoc.push_back(Tok.getLocation()); |
| 2452 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2453 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2454 | ConsumeAnyToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2455 | } else { |
| 2456 | assert(Kind == OMPC_if); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2457 | KLoc.push_back(Tok.getLocation()); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2458 | TentativeParsingAction TPA(*this); |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 2459 | auto DK = parseOpenMPDirectiveKind(*this); |
| 2460 | Arg.push_back(DK); |
| 2461 | if (DK != OMPD_unknown) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2462 | ConsumeToken(); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2463 | if (Tok.is(tok::colon) && getLangOpts().OpenMP > 40) { |
| 2464 | TPA.Commit(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2465 | DelimLoc = ConsumeToken(); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2466 | } else { |
| 2467 | TPA.Revert(); |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 2468 | Arg.back() = unsigned(OMPD_unknown); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2469 | } |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2470 | } else { |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2471 | TPA.Revert(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2472 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2473 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2474 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2475 | bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) || |
| 2476 | (Kind == OMPC_dist_schedule && DelimLoc.isValid()) || |
| 2477 | Kind == OMPC_if; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2478 | if (NeedAnExpression) { |
| 2479 | SourceLocation ELoc = Tok.getLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2480 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 2481 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 2482 | Val = |
| 2483 | Actions.ActOnFinishFullExpr(Val.get(), ELoc, /*DiscardedValue*/ false); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | // Parse ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2487 | SourceLocation RLoc = Tok.getLocation(); |
| 2488 | if (!T.consumeClose()) |
| 2489 | RLoc = T.getCloseLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2490 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2491 | if (NeedAnExpression && Val.isInvalid()) |
| 2492 | return nullptr; |
| 2493 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2494 | if (ParseOnly) |
| 2495 | return nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2496 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2497 | Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, RLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2498 | } |
| 2499 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2500 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 2501 | UnqualifiedId &ReductionId) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2502 | if (ReductionIdScopeSpec.isEmpty()) { |
| 2503 | auto OOK = OO_None; |
| 2504 | switch (P.getCurToken().getKind()) { |
| 2505 | case tok::plus: |
| 2506 | OOK = OO_Plus; |
| 2507 | break; |
| 2508 | case tok::minus: |
| 2509 | OOK = OO_Minus; |
| 2510 | break; |
| 2511 | case tok::star: |
| 2512 | OOK = OO_Star; |
| 2513 | break; |
| 2514 | case tok::amp: |
| 2515 | OOK = OO_Amp; |
| 2516 | break; |
| 2517 | case tok::pipe: |
| 2518 | OOK = OO_Pipe; |
| 2519 | break; |
| 2520 | case tok::caret: |
| 2521 | OOK = OO_Caret; |
| 2522 | break; |
| 2523 | case tok::ampamp: |
| 2524 | OOK = OO_AmpAmp; |
| 2525 | break; |
| 2526 | case tok::pipepipe: |
| 2527 | OOK = OO_PipePipe; |
| 2528 | break; |
| 2529 | default: |
| 2530 | break; |
| 2531 | } |
| 2532 | if (OOK != OO_None) { |
| 2533 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2534 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2535 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 2536 | return false; |
| 2537 | } |
| 2538 | } |
| 2539 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 2540 | /*AllowDestructorName*/ false, |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 2541 | /*AllowConstructorName*/ false, |
| 2542 | /*AllowDeductionGuide*/ false, |
Richard Smith | c08b693 | 2018-04-27 02:00:13 +0000 | [diff] [blame] | 2543 | nullptr, nullptr, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2544 | } |
| 2545 | |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2546 | /// Checks if the token is a valid map-type-modifier. |
| 2547 | static OpenMPMapModifierKind isMapModifier(Parser &P) { |
| 2548 | Token Tok = P.getCurToken(); |
| 2549 | if (!Tok.is(tok::identifier)) |
| 2550 | return OMPC_MAP_MODIFIER_unknown; |
| 2551 | |
| 2552 | Preprocessor &PP = P.getPreprocessor(); |
| 2553 | OpenMPMapModifierKind TypeModifier = static_cast<OpenMPMapModifierKind>( |
| 2554 | getOpenMPSimpleClauseType(OMPC_map, PP.getSpelling(Tok))); |
| 2555 | return TypeModifier; |
| 2556 | } |
| 2557 | |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2558 | /// Parse the mapper modifier in map, to, and from clauses. |
| 2559 | bool Parser::parseMapperModifier(OpenMPVarListDataTy &Data) { |
| 2560 | // Parse '('. |
| 2561 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::colon); |
| 2562 | if (T.expectAndConsume(diag::err_expected_lparen_after, "mapper")) { |
| 2563 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2564 | StopBeforeMatch); |
| 2565 | return true; |
| 2566 | } |
| 2567 | // Parse mapper-identifier |
| 2568 | if (getLangOpts().CPlusPlus) |
| 2569 | ParseOptionalCXXScopeSpecifier(Data.ReductionOrMapperIdScopeSpec, |
| 2570 | /*ObjectType=*/nullptr, |
| 2571 | /*EnteringContext=*/false); |
| 2572 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_default)) { |
| 2573 | Diag(Tok.getLocation(), diag::err_omp_mapper_illegal_identifier); |
| 2574 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2575 | StopBeforeMatch); |
| 2576 | return true; |
| 2577 | } |
| 2578 | auto &DeclNames = Actions.getASTContext().DeclarationNames; |
| 2579 | Data.ReductionOrMapperId = DeclarationNameInfo( |
| 2580 | DeclNames.getIdentifier(Tok.getIdentifierInfo()), Tok.getLocation()); |
| 2581 | ConsumeToken(); |
| 2582 | // Parse ')'. |
| 2583 | return T.consumeClose(); |
| 2584 | } |
| 2585 | |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2586 | /// Parse map-type-modifiers in map clause. |
| 2587 | /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2588 | /// where, map-type-modifier ::= always | close | mapper(mapper-identifier) |
| 2589 | bool Parser::parseMapTypeModifiers(OpenMPVarListDataTy &Data) { |
| 2590 | while (getCurToken().isNot(tok::colon)) { |
| 2591 | OpenMPMapModifierKind TypeModifier = isMapModifier(*this); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2592 | if (TypeModifier == OMPC_MAP_MODIFIER_always || |
| 2593 | TypeModifier == OMPC_MAP_MODIFIER_close) { |
| 2594 | Data.MapTypeModifiers.push_back(TypeModifier); |
| 2595 | Data.MapTypeModifiersLoc.push_back(Tok.getLocation()); |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2596 | ConsumeToken(); |
| 2597 | } else if (TypeModifier == OMPC_MAP_MODIFIER_mapper) { |
| 2598 | Data.MapTypeModifiers.push_back(TypeModifier); |
| 2599 | Data.MapTypeModifiersLoc.push_back(Tok.getLocation()); |
| 2600 | ConsumeToken(); |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2601 | if (parseMapperModifier(Data)) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2602 | return true; |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2603 | } else { |
| 2604 | // For the case of unknown map-type-modifier or a map-type. |
| 2605 | // Map-type is followed by a colon; the function returns when it |
| 2606 | // encounters a token followed by a colon. |
| 2607 | if (Tok.is(tok::comma)) { |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2608 | Diag(Tok, diag::err_omp_map_type_modifier_missing); |
| 2609 | ConsumeToken(); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2610 | continue; |
| 2611 | } |
| 2612 | // Potential map-type token as it is followed by a colon. |
| 2613 | if (PP.LookAhead(0).is(tok::colon)) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2614 | return false; |
| 2615 | Diag(Tok, diag::err_omp_unknown_map_type_modifier); |
| 2616 | ConsumeToken(); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2617 | } |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2618 | if (getCurToken().is(tok::comma)) |
| 2619 | ConsumeToken(); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2620 | } |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2621 | return false; |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /// Checks if the token is a valid map-type. |
| 2625 | static OpenMPMapClauseKind isMapType(Parser &P) { |
| 2626 | Token Tok = P.getCurToken(); |
| 2627 | // The map-type token can be either an identifier or the C++ delete keyword. |
| 2628 | if (!Tok.isOneOf(tok::identifier, tok::kw_delete)) |
| 2629 | return OMPC_MAP_unknown; |
| 2630 | Preprocessor &PP = P.getPreprocessor(); |
| 2631 | OpenMPMapClauseKind MapType = static_cast<OpenMPMapClauseKind>( |
| 2632 | getOpenMPSimpleClauseType(OMPC_map, PP.getSpelling(Tok))); |
| 2633 | return MapType; |
| 2634 | } |
| 2635 | |
| 2636 | /// Parse map-type in map clause. |
| 2637 | /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) |
Ilya Biryukov | ff2a997 | 2019-02-26 11:01:50 +0000 | [diff] [blame] | 2638 | /// where, map-type ::= to | from | tofrom | alloc | release | delete |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2639 | static void parseMapType(Parser &P, Parser::OpenMPVarListDataTy &Data) { |
| 2640 | Token Tok = P.getCurToken(); |
| 2641 | if (Tok.is(tok::colon)) { |
| 2642 | P.Diag(Tok, diag::err_omp_map_type_missing); |
| 2643 | return; |
| 2644 | } |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2645 | Data.ExtraModifier = isMapType(P); |
| 2646 | if (Data.ExtraModifier == OMPC_MAP_unknown) |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2647 | P.Diag(Tok, diag::err_omp_unknown_map_type); |
| 2648 | P.ConsumeToken(); |
| 2649 | } |
| 2650 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2651 | /// Parses clauses with list. |
| 2652 | bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, |
| 2653 | OpenMPClauseKind Kind, |
| 2654 | SmallVectorImpl<Expr *> &Vars, |
| 2655 | OpenMPVarListDataTy &Data) { |
| 2656 | UnqualifiedId UnqualifiedReductionId; |
| 2657 | bool InvalidReductionId = false; |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2658 | bool IsInvalidMapperModifier = false; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2659 | |
| 2660 | // Parse '('. |
| 2661 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 2662 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 2663 | getOpenMPClauseName(Kind))) |
| 2664 | return true; |
| 2665 | |
| 2666 | bool NeedRParenForLinear = false; |
| 2667 | BalancedDelimiterTracker LinearT(*this, tok::l_paren, |
| 2668 | tok::annot_pragma_openmp_end); |
| 2669 | // Handle reduction-identifier for reduction clause. |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2670 | if (Kind == OMPC_reduction || Kind == OMPC_task_reduction || |
| 2671 | Kind == OMPC_in_reduction) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2672 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2673 | if (getLangOpts().CPlusPlus) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2674 | ParseOptionalCXXScopeSpecifier(Data.ReductionOrMapperIdScopeSpec, |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2675 | /*ObjectType=*/nullptr, |
| 2676 | /*EnteringContext=*/false); |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2677 | InvalidReductionId = ParseReductionId( |
| 2678 | *this, Data.ReductionOrMapperIdScopeSpec, UnqualifiedReductionId); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2679 | if (InvalidReductionId) { |
| 2680 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2681 | StopBeforeMatch); |
| 2682 | } |
| 2683 | if (Tok.is(tok::colon)) |
| 2684 | Data.ColonLoc = ConsumeToken(); |
| 2685 | else |
| 2686 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 2687 | if (!InvalidReductionId) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2688 | Data.ReductionOrMapperId = |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2689 | Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId); |
| 2690 | } else if (Kind == OMPC_depend) { |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2691 | // Handle dependency type for depend clause. |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2692 | ColonProtectionRAIIObject ColonRAII(*this); |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2693 | Data.ExtraModifier = getOpenMPSimpleClauseType( |
| 2694 | Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""); |
| 2695 | Data.DepLinMapLastLoc = Tok.getLocation(); |
| 2696 | if (Data.ExtraModifier == OMPC_DEPEND_unknown) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2697 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2698 | StopBeforeMatch); |
| 2699 | } else { |
| 2700 | ConsumeToken(); |
| 2701 | // Special processing for depend(source) clause. |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2702 | if (DKind == OMPD_ordered && Data.ExtraModifier == OMPC_DEPEND_source) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2703 | // Parse ')'. |
| 2704 | T.consumeClose(); |
| 2705 | return false; |
| 2706 | } |
| 2707 | } |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2708 | if (Tok.is(tok::colon)) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2709 | Data.ColonLoc = ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2710 | } else { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2711 | Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren |
| 2712 | : diag::warn_pragma_expected_colon) |
| 2713 | << "dependency type"; |
| 2714 | } |
| 2715 | } else if (Kind == OMPC_linear) { |
| 2716 | // Try to parse modifier if any. |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2717 | Data.ExtraModifier = OMPC_LINEAR_val; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2718 | if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) { |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2719 | Data.ExtraModifier = getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)); |
| 2720 | Data.DepLinMapLastLoc = ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2721 | LinearT.consumeOpen(); |
| 2722 | NeedRParenForLinear = true; |
| 2723 | } |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2724 | } else if (Kind == OMPC_lastprivate) { |
| 2725 | // Try to parse modifier if any. |
| 2726 | Data.ExtraModifier = OMPC_LASTPRIVATE_unknown; |
| 2727 | // Conditional modifier allowed only in OpenMP 5.0 and not supported in |
| 2728 | // distribute and taskloop based directives. |
| 2729 | if ((getLangOpts().OpenMP >= 50 && !isOpenMPDistributeDirective(DKind) && |
| 2730 | !isOpenMPTaskLoopDirective(DKind)) && |
| 2731 | Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::colon)) { |
| 2732 | Data.ExtraModifier = getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)); |
| 2733 | Data.DepLinMapLastLoc = Tok.getLocation(); |
| 2734 | if (Data.ExtraModifier == OMPC_LASTPRIVATE_unknown) { |
| 2735 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2736 | StopBeforeMatch); |
| 2737 | } else { |
| 2738 | ConsumeToken(); |
| 2739 | } |
| 2740 | assert(Tok.is(tok::colon) && "Expected colon."); |
| 2741 | Data.ColonLoc = ConsumeToken(); |
| 2742 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2743 | } else if (Kind == OMPC_map) { |
| 2744 | // Handle map type for map clause. |
| 2745 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2746 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2747 | // The first identifier may be a list item, a map-type or a |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2748 | // map-type-modifier. The map-type can also be delete which has the same |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2749 | // spelling of the C++ delete keyword. |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2750 | Data.ExtraModifier = OMPC_MAP_unknown; |
| 2751 | Data.DepLinMapLastLoc = Tok.getLocation(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2752 | |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2753 | // Check for presence of a colon in the map clause. |
| 2754 | TentativeParsingAction TPA(*this); |
| 2755 | bool ColonPresent = false; |
| 2756 | if (SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2757 | StopBeforeMatch)) { |
| 2758 | if (Tok.is(tok::colon)) |
| 2759 | ColonPresent = true; |
| 2760 | } |
| 2761 | TPA.Revert(); |
| 2762 | // Only parse map-type-modifier[s] and map-type if a colon is present in |
| 2763 | // the map clause. |
| 2764 | if (ColonPresent) { |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2765 | IsInvalidMapperModifier = parseMapTypeModifiers(Data); |
| 2766 | if (!IsInvalidMapperModifier) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2767 | parseMapType(*this, Data); |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2768 | else |
| 2769 | SkipUntil(tok::colon, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2770 | } |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2771 | if (Data.ExtraModifier == OMPC_MAP_unknown) { |
| 2772 | Data.ExtraModifier = OMPC_MAP_tofrom; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2773 | Data.IsMapTypeImplicit = true; |
| 2774 | } |
| 2775 | |
| 2776 | if (Tok.is(tok::colon)) |
| 2777 | Data.ColonLoc = ConsumeToken(); |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 2778 | } else if (Kind == OMPC_to || Kind == OMPC_from) { |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2779 | if (Tok.is(tok::identifier)) { |
| 2780 | bool IsMapperModifier = false; |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 2781 | if (Kind == OMPC_to) { |
| 2782 | auto Modifier = static_cast<OpenMPToModifierKind>( |
| 2783 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
| 2784 | if (Modifier == OMPC_TO_MODIFIER_mapper) |
| 2785 | IsMapperModifier = true; |
| 2786 | } else { |
| 2787 | auto Modifier = static_cast<OpenMPFromModifierKind>( |
| 2788 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
| 2789 | if (Modifier == OMPC_FROM_MODIFIER_mapper) |
| 2790 | IsMapperModifier = true; |
| 2791 | } |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2792 | if (IsMapperModifier) { |
| 2793 | // Parse the mapper modifier. |
| 2794 | ConsumeToken(); |
| 2795 | IsInvalidMapperModifier = parseMapperModifier(Data); |
| 2796 | if (Tok.isNot(tok::colon)) { |
| 2797 | if (!IsInvalidMapperModifier) |
| 2798 | Diag(Tok, diag::warn_pragma_expected_colon) << ")"; |
| 2799 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2800 | StopBeforeMatch); |
| 2801 | } |
| 2802 | // Consume ':'. |
| 2803 | if (Tok.is(tok::colon)) |
| 2804 | ConsumeToken(); |
| 2805 | } |
| 2806 | } |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2807 | } else if (Kind == OMPC_allocate) { |
| 2808 | // Handle optional allocator expression followed by colon delimiter. |
| 2809 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2810 | TentativeParsingAction TPA(*this); |
| 2811 | ExprResult Tail = |
| 2812 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
| 2813 | Tail = Actions.ActOnFinishFullExpr(Tail.get(), T.getOpenLocation(), |
| 2814 | /*DiscardedValue=*/false); |
| 2815 | if (Tail.isUsable()) { |
| 2816 | if (Tok.is(tok::colon)) { |
| 2817 | Data.TailExpr = Tail.get(); |
| 2818 | Data.ColonLoc = ConsumeToken(); |
| 2819 | TPA.Commit(); |
| 2820 | } else { |
| 2821 | // colon not found, no allocator specified, parse only list of |
| 2822 | // variables. |
| 2823 | TPA.Revert(); |
| 2824 | } |
| 2825 | } else { |
| 2826 | // Parsing was unsuccessfull, revert and skip to the end of clause or |
| 2827 | // directive. |
| 2828 | TPA.Revert(); |
| 2829 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2830 | StopBeforeMatch); |
| 2831 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2832 | } |
| 2833 | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2834 | bool IsComma = |
| 2835 | (Kind != OMPC_reduction && Kind != OMPC_task_reduction && |
| 2836 | Kind != OMPC_in_reduction && Kind != OMPC_depend && Kind != OMPC_map) || |
| 2837 | (Kind == OMPC_reduction && !InvalidReductionId) || |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2838 | (Kind == OMPC_map && Data.ExtraModifier != OMPC_MAP_unknown) || |
| 2839 | (Kind == OMPC_depend && Data.ExtraModifier != OMPC_DEPEND_unknown); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2840 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
| 2841 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
| 2842 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
| 2843 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
| 2844 | // Parse variable |
| 2845 | ExprResult VarExpr = |
| 2846 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2847 | if (VarExpr.isUsable()) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2848 | Vars.push_back(VarExpr.get()); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2849 | } else { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2850 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2851 | StopBeforeMatch); |
| 2852 | } |
| 2853 | // Skip ',' if any |
| 2854 | IsComma = Tok.is(tok::comma); |
| 2855 | if (IsComma) |
| 2856 | ConsumeToken(); |
| 2857 | else if (Tok.isNot(tok::r_paren) && |
| 2858 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 2859 | (!MayHaveTail || Tok.isNot(tok::colon))) |
| 2860 | Diag(Tok, diag::err_omp_expected_punc) |
| 2861 | << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush) |
| 2862 | : getOpenMPClauseName(Kind)) |
| 2863 | << (Kind == OMPC_flush); |
| 2864 | } |
| 2865 | |
| 2866 | // Parse ')' for linear clause with modifier. |
| 2867 | if (NeedRParenForLinear) |
| 2868 | LinearT.consumeClose(); |
| 2869 | |
| 2870 | // Parse ':' linear-step (or ':' alignment). |
| 2871 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 2872 | if (MustHaveTail) { |
| 2873 | Data.ColonLoc = Tok.getLocation(); |
| 2874 | SourceLocation ELoc = ConsumeToken(); |
| 2875 | ExprResult Tail = ParseAssignmentExpression(); |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 2876 | Tail = |
| 2877 | Actions.ActOnFinishFullExpr(Tail.get(), ELoc, /*DiscardedValue*/ false); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2878 | if (Tail.isUsable()) |
| 2879 | Data.TailExpr = Tail.get(); |
| 2880 | else |
| 2881 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2882 | StopBeforeMatch); |
| 2883 | } |
| 2884 | |
| 2885 | // Parse ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2886 | Data.RLoc = Tok.getLocation(); |
| 2887 | if (!T.consumeClose()) |
| 2888 | Data.RLoc = T.getCloseLocation(); |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2889 | return (Kind == OMPC_depend && Data.ExtraModifier != OMPC_DEPEND_unknown && |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2890 | Vars.empty()) || |
| 2891 | (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) || |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2892 | (MustHaveTail && !Data.TailExpr) || InvalidReductionId || |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2893 | IsInvalidMapperModifier; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2894 | } |
| 2895 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2896 | /// Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2897 | /// 'shared', 'copyin', 'copyprivate', 'flush', 'reduction', 'task_reduction' or |
| 2898 | /// 'in_reduction'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2899 | /// |
| 2900 | /// private-clause: |
| 2901 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2902 | /// firstprivate-clause: |
| 2903 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2904 | /// lastprivate-clause: |
| 2905 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2906 | /// shared-clause: |
| 2907 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2908 | /// linear-clause: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 2909 | /// 'linear' '(' linear-list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 2910 | /// aligned-clause: |
| 2911 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2912 | /// reduction-clause: |
| 2913 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 2914 | /// task_reduction-clause: |
| 2915 | /// 'task_reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2916 | /// in_reduction-clause: |
| 2917 | /// 'in_reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2918 | /// copyprivate-clause: |
| 2919 | /// 'copyprivate' '(' list ')' |
| 2920 | /// flush-clause: |
| 2921 | /// 'flush' '(' list ')' |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2922 | /// depend-clause: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 2923 | /// 'depend' '(' in | out | inout : list | source ')' |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2924 | /// map-clause: |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2925 | /// 'map' '(' [ [ always [,] ] [ close [,] ] |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2926 | /// [ mapper '(' mapper-identifier ')' [,] ] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2927 | /// to | from | tofrom | alloc | release | delete ':' ] list ')'; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 2928 | /// to-clause: |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2929 | /// 'to' '(' [ mapper '(' mapper-identifier ')' ':' ] list ')' |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 2930 | /// from-clause: |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 2931 | /// 'from' '(' [ mapper '(' mapper-identifier ')' ':' ] list ')' |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 2932 | /// use_device_ptr-clause: |
| 2933 | /// 'use_device_ptr' '(' list ')' |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 2934 | /// is_device_ptr-clause: |
| 2935 | /// 'is_device_ptr' '(' list ')' |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2936 | /// allocate-clause: |
| 2937 | /// 'allocate' '(' [ allocator ':' ] list ')' |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2938 | /// |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 2939 | /// For 'linear' clause linear-list may have the following forms: |
| 2940 | /// list |
| 2941 | /// modifier(list) |
| 2942 | /// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++). |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 2943 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2944 | OpenMPClauseKind Kind, |
| 2945 | bool ParseOnly) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2946 | SourceLocation Loc = Tok.getLocation(); |
| 2947 | SourceLocation LOpen = ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2948 | SmallVector<Expr *, 4> Vars; |
| 2949 | OpenMPVarListDataTy Data; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2950 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2951 | if (ParseOpenMPVarList(DKind, Kind, Vars, Data)) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2952 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2953 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2954 | if (ParseOnly) |
| 2955 | return nullptr; |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2956 | OMPVarListLocTy Locs(Loc, LOpen, Data.RLoc); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2957 | return Actions.ActOnOpenMPVarListClause( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2958 | Kind, Vars, Data.TailExpr, Locs, Data.ColonLoc, |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2959 | Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId, |
| 2960 | Data.ExtraModifier, Data.MapTypeModifiers, Data.MapTypeModifiersLoc, |
| 2961 | Data.IsMapTypeImplicit, Data.DepLinMapLastLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2962 | } |
| 2963 | |