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); |
Alexey Bataev | 1fcc9b6 | 2020-01-02 15:49:08 -0500 | [diff] [blame] | 433 | ExprResult Init = ParseInitializer(); |
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 | 3732f4e | 2019-12-24 16:02:58 -0500 | [diff] [blame] | 738 | if (CKind == OMPC_aligned) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 739 | Vars = &Aligneds; |
Alexey Bataev | 3732f4e | 2019-12-24 16:02:58 -0500 | [diff] [blame] | 740 | } else if (CKind == OMPC_linear) { |
| 741 | Data.ExtraModifier = OMPC_LINEAR_val; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 742 | Vars = &Linears; |
Alexey Bataev | 3732f4e | 2019-12-24 16:02:58 -0500 | [diff] [blame] | 743 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 744 | |
| 745 | P.ConsumeToken(); |
| 746 | if (P.ParseOpenMPVarList(OMPD_declare_simd, |
| 747 | getOpenMPClauseKind(ClauseName), *Vars, Data)) |
| 748 | IsError = true; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 749 | if (CKind == OMPC_aligned) { |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 750 | Alignments.append(Aligneds.size() - Alignments.size(), Data.TailExpr); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 751 | } else if (CKind == OMPC_linear) { |
Alexey Bataev | 3732f4e | 2019-12-24 16:02:58 -0500 | [diff] [blame] | 752 | assert(0 <= Data.ExtraModifier && |
| 753 | Data.ExtraModifier <= OMPC_LINEAR_unknown && |
| 754 | "Unexpected linear modifier."); |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 755 | if (P.getActions().CheckOpenMPLinearModifier( |
| 756 | static_cast<OpenMPLinearClauseKind>(Data.ExtraModifier), |
| 757 | Data.DepLinMapLastLoc)) |
| 758 | Data.ExtraModifier = OMPC_LINEAR_val; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 759 | LinModifiers.append(Linears.size() - LinModifiers.size(), |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 760 | Data.ExtraModifier); |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 761 | Steps.append(Linears.size() - Steps.size(), Data.TailExpr); |
| 762 | } |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 763 | } else |
| 764 | // TODO: add parsing of other clauses. |
| 765 | break; |
| 766 | } |
| 767 | // Skip ',' if any. |
| 768 | if (Tok.is(tok::comma)) |
| 769 | P.ConsumeToken(); |
| 770 | } |
| 771 | return IsError; |
| 772 | } |
| 773 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 774 | /// Parse clauses for '#pragma omp declare simd'. |
| 775 | Parser::DeclGroupPtrTy |
| 776 | Parser::ParseOMPDeclareSimdClauses(Parser::DeclGroupPtrTy Ptr, |
| 777 | CachedTokens &Toks, SourceLocation Loc) { |
Ilya Biryukov | 929af67 | 2019-05-17 09:32:05 +0000 | [diff] [blame] | 778 | PP.EnterToken(Tok, /*IsReinject*/ true); |
| 779 | PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true, |
| 780 | /*IsReinject*/ true); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 781 | // Consume the previously pushed token. |
| 782 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 783 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 784 | |
| 785 | FNContextRAII FnContext(*this, Ptr); |
| 786 | OMPDeclareSimdDeclAttr::BranchStateTy BS = |
| 787 | OMPDeclareSimdDeclAttr::BS_Undefined; |
| 788 | ExprResult Simdlen; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 789 | SmallVector<Expr *, 4> Uniforms; |
Alexey Bataev | d93d376 | 2016-04-12 09:35:56 +0000 | [diff] [blame] | 790 | SmallVector<Expr *, 4> Aligneds; |
| 791 | SmallVector<Expr *, 4> Alignments; |
Alexey Bataev | ecba70f | 2016-04-12 11:02:11 +0000 | [diff] [blame] | 792 | SmallVector<Expr *, 4> Linears; |
| 793 | SmallVector<unsigned, 4> LinModifiers; |
| 794 | SmallVector<Expr *, 4> Steps; |
| 795 | bool IsError = |
| 796 | parseDeclareSimdClauses(*this, BS, Simdlen, Uniforms, Aligneds, |
| 797 | Alignments, Linears, LinModifiers, Steps); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 798 | // Need to check for extra tokens. |
| 799 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 800 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 801 | << getOpenMPDirectiveName(OMPD_declare_simd); |
| 802 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 803 | ConsumeAnyToken(); |
| 804 | } |
| 805 | // Skip the last annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 806 | SourceLocation EndLoc = ConsumeAnnotationToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 807 | if (IsError) |
| 808 | return Ptr; |
| 809 | return Actions.ActOnOpenMPDeclareSimdDirective( |
| 810 | Ptr, BS, Simdlen.get(), Uniforms, Aligneds, Alignments, Linears, |
| 811 | LinModifiers, Steps, SourceRange(Loc, EndLoc)); |
Alexey Bataev | 20dfd77 | 2016-04-04 10:12:15 +0000 | [diff] [blame] | 812 | } |
| 813 | |
Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 814 | /// Parse optional 'score' '(' <expr> ')' ':'. |
| 815 | static ExprResult parseContextScore(Parser &P) { |
| 816 | ExprResult ScoreExpr; |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 817 | Sema::OMPCtxStringType Buffer; |
Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 818 | StringRef SelectorName = |
| 819 | P.getPreprocessor().getSpelling(P.getCurToken(), Buffer); |
Alexey Bataev | dcec2ac | 2019-11-05 15:33:18 -0500 | [diff] [blame] | 820 | if (!SelectorName.equals("score")) |
Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 821 | return ScoreExpr; |
Alexey Bataev | a15a141 | 2019-10-02 18:19:02 +0000 | [diff] [blame] | 822 | (void)P.ConsumeToken(); |
| 823 | SourceLocation RLoc; |
| 824 | ScoreExpr = P.ParseOpenMPParensExpr(SelectorName, RLoc); |
| 825 | // Parse ':' |
| 826 | if (P.getCurToken().is(tok::colon)) |
| 827 | (void)P.ConsumeAnyToken(); |
| 828 | else |
| 829 | P.Diag(P.getCurToken(), diag::warn_pragma_expected_colon) |
| 830 | << "context selector score clause"; |
| 831 | return ScoreExpr; |
| 832 | } |
| 833 | |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 834 | /// Parse context selector for 'implementation' selector set: |
Alexey Bataev | 1c9e173 | 2019-10-04 15:58:45 +0000 | [diff] [blame] | 835 | /// 'vendor' '(' [ 'score' '(' <score _expr> ')' ':' ] <vendor> { ',' <vendor> } |
| 836 | /// ')' |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 837 | static void |
| 838 | parseImplementationSelector(Parser &P, SourceLocation Loc, |
| 839 | llvm::StringMap<SourceLocation> &UsedCtx, |
| 840 | SmallVectorImpl<Sema::OMPCtxSelectorData> &Data) { |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 841 | const Token &Tok = P.getCurToken(); |
| 842 | // Parse inner context selector set name, if any. |
| 843 | if (!Tok.is(tok::identifier)) { |
| 844 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 845 | << "implementation"; |
| 846 | // Skip until either '}', ')', or end of directive. |
| 847 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 848 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 849 | ; |
| 850 | return; |
| 851 | } |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 852 | Sema::OMPCtxStringType Buffer; |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 853 | StringRef CtxSelectorName = P.getPreprocessor().getSpelling(Tok, Buffer); |
Alexey Bataev | 70d2e54 | 2019-10-08 17:47:52 +0000 | [diff] [blame] | 854 | auto Res = UsedCtx.try_emplace(CtxSelectorName, Tok.getLocation()); |
| 855 | if (!Res.second) { |
| 856 | // OpenMP 5.0, 2.3.2 Context Selectors, Restrictions. |
| 857 | // Each trait-selector-name can only be specified once. |
| 858 | P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_ctx_mutiple_use) |
| 859 | << CtxSelectorName << "implementation"; |
| 860 | P.Diag(Res.first->getValue(), diag::note_omp_declare_variant_ctx_used_here) |
| 861 | << CtxSelectorName; |
| 862 | } |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 863 | OpenMPContextSelectorKind CSKind = getOpenMPContextSelector(CtxSelectorName); |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 864 | (void)P.ConsumeToken(); |
| 865 | switch (CSKind) { |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 866 | case OMP_CTX_vendor: { |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 867 | // Parse '('. |
| 868 | BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end); |
| 869 | (void)T.expectAndConsume(diag::err_expected_lparen_after, |
| 870 | CtxSelectorName.data()); |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 871 | ExprResult Score = parseContextScore(P); |
| 872 | llvm::UniqueVector<Sema::OMPCtxStringType> Vendors; |
Alexey Bataev | 1c9e173 | 2019-10-04 15:58:45 +0000 | [diff] [blame] | 873 | do { |
| 874 | // Parse <vendor>. |
| 875 | StringRef VendorName; |
| 876 | if (Tok.is(tok::identifier)) { |
| 877 | Buffer.clear(); |
| 878 | VendorName = P.getPreprocessor().getSpelling(P.getCurToken(), Buffer); |
| 879 | (void)P.ConsumeToken(); |
Alexey Bataev | 303657a | 2019-10-08 19:44:16 +0000 | [diff] [blame] | 880 | if (!VendorName.empty()) |
Alexey Bataev | 4513e93f | 2019-10-10 15:15:26 +0000 | [diff] [blame] | 881 | Vendors.insert(VendorName); |
Alexey Bataev | 1c9e173 | 2019-10-04 15:58:45 +0000 | [diff] [blame] | 882 | } else { |
| 883 | P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_item_expected) |
| 884 | << "vendor identifier" |
| 885 | << "vendor" |
| 886 | << "implementation"; |
| 887 | } |
Alexey Bataev | 1c9e173 | 2019-10-04 15:58:45 +0000 | [diff] [blame] | 888 | if (!P.TryConsumeToken(tok::comma) && Tok.isNot(tok::r_paren)) { |
| 889 | P.Diag(Tok, diag::err_expected_punc) |
| 890 | << (VendorName.empty() ? "vendor name" : VendorName); |
| 891 | } |
| 892 | } while (Tok.is(tok::identifier)); |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 893 | // Parse ')'. |
| 894 | (void)T.consumeClose(); |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 895 | if (!Vendors.empty()) |
| 896 | Data.emplace_back(OMP_CTX_SET_implementation, CSKind, Score, Vendors); |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 897 | break; |
| 898 | } |
Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 899 | case OMP_CTX_kind: |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 900 | case OMP_CTX_unknown: |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 901 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 902 | << "implementation"; |
| 903 | // Skip until either '}', ')', or end of directive. |
| 904 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 905 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 906 | ; |
| 907 | return; |
| 908 | } |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 909 | } |
| 910 | |
Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 911 | /// Parse context selector for 'device' selector set: |
| 912 | /// 'kind' '(' <kind> { ',' <kind> } ')' |
| 913 | static void |
| 914 | parseDeviceSelector(Parser &P, SourceLocation Loc, |
| 915 | llvm::StringMap<SourceLocation> &UsedCtx, |
| 916 | SmallVectorImpl<Sema::OMPCtxSelectorData> &Data) { |
| 917 | const Token &Tok = P.getCurToken(); |
| 918 | // Parse inner context selector set name, if any. |
| 919 | if (!Tok.is(tok::identifier)) { |
| 920 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 921 | << "device"; |
| 922 | // Skip until either '}', ')', or end of directive. |
| 923 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 924 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 925 | ; |
| 926 | return; |
| 927 | } |
| 928 | Sema::OMPCtxStringType Buffer; |
| 929 | StringRef CtxSelectorName = P.getPreprocessor().getSpelling(Tok, Buffer); |
| 930 | auto Res = UsedCtx.try_emplace(CtxSelectorName, Tok.getLocation()); |
| 931 | if (!Res.second) { |
| 932 | // OpenMP 5.0, 2.3.2 Context Selectors, Restrictions. |
| 933 | // Each trait-selector-name can only be specified once. |
| 934 | P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_ctx_mutiple_use) |
| 935 | << CtxSelectorName << "device"; |
| 936 | P.Diag(Res.first->getValue(), diag::note_omp_declare_variant_ctx_used_here) |
| 937 | << CtxSelectorName; |
| 938 | } |
| 939 | OpenMPContextSelectorKind CSKind = getOpenMPContextSelector(CtxSelectorName); |
| 940 | (void)P.ConsumeToken(); |
| 941 | switch (CSKind) { |
| 942 | case OMP_CTX_kind: { |
| 943 | // Parse '('. |
| 944 | BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end); |
| 945 | (void)T.expectAndConsume(diag::err_expected_lparen_after, |
| 946 | CtxSelectorName.data()); |
| 947 | llvm::UniqueVector<Sema::OMPCtxStringType> Kinds; |
| 948 | do { |
| 949 | // Parse <kind>. |
| 950 | StringRef KindName; |
| 951 | if (Tok.is(tok::identifier)) { |
| 952 | Buffer.clear(); |
| 953 | KindName = P.getPreprocessor().getSpelling(P.getCurToken(), Buffer); |
| 954 | SourceLocation SLoc = P.getCurToken().getLocation(); |
| 955 | (void)P.ConsumeToken(); |
| 956 | if (llvm::StringSwitch<bool>(KindName) |
| 957 | .Case("host", false) |
| 958 | .Case("nohost", false) |
| 959 | .Case("cpu", false) |
| 960 | .Case("gpu", false) |
| 961 | .Case("fpga", false) |
| 962 | .Default(true)) { |
| 963 | P.Diag(SLoc, diag::err_omp_wrong_device_kind_trait) << KindName; |
| 964 | } else { |
| 965 | Kinds.insert(KindName); |
| 966 | } |
| 967 | } else { |
| 968 | P.Diag(Tok.getLocation(), diag::err_omp_declare_variant_item_expected) |
| 969 | << "'host', 'nohost', 'cpu', 'gpu', or 'fpga'" |
| 970 | << "kind" |
| 971 | << "device"; |
| 972 | } |
| 973 | if (!P.TryConsumeToken(tok::comma) && Tok.isNot(tok::r_paren)) { |
| 974 | P.Diag(Tok, diag::err_expected_punc) |
| 975 | << (KindName.empty() ? "kind of device" : KindName); |
| 976 | } |
| 977 | } while (Tok.is(tok::identifier)); |
| 978 | // Parse ')'. |
| 979 | (void)T.consumeClose(); |
| 980 | if (!Kinds.empty()) |
| 981 | Data.emplace_back(OMP_CTX_SET_device, CSKind, ExprResult(), Kinds); |
| 982 | break; |
| 983 | } |
| 984 | case OMP_CTX_vendor: |
| 985 | case OMP_CTX_unknown: |
| 986 | P.Diag(Tok.getLocation(), diag::warn_omp_declare_variant_cs_name_expected) |
| 987 | << "device"; |
| 988 | // Skip until either '}', ')', or end of directive. |
| 989 | while (!P.SkipUntil(tok::r_brace, tok::r_paren, |
| 990 | tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 991 | ; |
| 992 | return; |
| 993 | } |
| 994 | } |
| 995 | |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 996 | /// Parses clauses for 'declare variant' directive. |
| 997 | /// clause: |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 998 | /// <selector_set_name> '=' '{' <context_selectors> '}' |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 999 | /// [ ',' <selector_set_name> '=' '{' <context_selectors> '}' ] |
| 1000 | bool Parser::parseOpenMPContextSelectors( |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1001 | SourceLocation Loc, SmallVectorImpl<Sema::OMPCtxSelectorData> &Data) { |
Alexey Bataev | 5d154c3 | 2019-10-08 15:56:43 +0000 | [diff] [blame] | 1002 | llvm::StringMap<SourceLocation> UsedCtxSets; |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1003 | do { |
| 1004 | // Parse inner context selector set name. |
| 1005 | if (!Tok.is(tok::identifier)) { |
| 1006 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_no_ctx_selector) |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 1007 | << getOpenMPClauseName(OMPC_match); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1008 | return true; |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1009 | } |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1010 | Sema::OMPCtxStringType Buffer; |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 1011 | StringRef CtxSelectorSetName = PP.getSpelling(Tok, Buffer); |
Alexey Bataev | 5d154c3 | 2019-10-08 15:56:43 +0000 | [diff] [blame] | 1012 | auto Res = UsedCtxSets.try_emplace(CtxSelectorSetName, Tok.getLocation()); |
| 1013 | if (!Res.second) { |
| 1014 | // OpenMP 5.0, 2.3.2 Context Selectors, Restrictions. |
| 1015 | // Each trait-set-selector-name can only be specified once. |
| 1016 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_ctx_set_mutiple_use) |
| 1017 | << CtxSelectorSetName; |
| 1018 | Diag(Res.first->getValue(), |
| 1019 | diag::note_omp_declare_variant_ctx_set_used_here) |
| 1020 | << CtxSelectorSetName; |
| 1021 | } |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1022 | // Parse '='. |
| 1023 | (void)ConsumeToken(); |
| 1024 | if (Tok.isNot(tok::equal)) { |
| 1025 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_equal_expected) |
Alexey Bataev | 9ff3474 | 2019-09-25 19:43:37 +0000 | [diff] [blame] | 1026 | << CtxSelectorSetName; |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1027 | return true; |
| 1028 | } |
| 1029 | (void)ConsumeToken(); |
| 1030 | // TBD: add parsing of known context selectors. |
| 1031 | // Unknown selector - just ignore it completely. |
| 1032 | { |
| 1033 | // Parse '{'. |
| 1034 | BalancedDelimiterTracker TBr(*this, tok::l_brace, |
| 1035 | tok::annot_pragma_openmp_end); |
| 1036 | if (TBr.expectAndConsume(diag::err_expected_lbrace_after, "=")) |
| 1037 | return true; |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1038 | OpenMPContextSelectorSetKind CSSKind = |
| 1039 | getOpenMPContextSelectorSet(CtxSelectorSetName); |
Alexey Bataev | 70d2e54 | 2019-10-08 17:47:52 +0000 | [diff] [blame] | 1040 | llvm::StringMap<SourceLocation> UsedCtx; |
| 1041 | do { |
| 1042 | switch (CSSKind) { |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1043 | case OMP_CTX_SET_implementation: |
| 1044 | parseImplementationSelector(*this, Loc, UsedCtx, Data); |
Alexey Bataev | 70d2e54 | 2019-10-08 17:47:52 +0000 | [diff] [blame] | 1045 | break; |
Alexey Bataev | 4e8231b | 2019-11-05 15:13:30 -0500 | [diff] [blame] | 1046 | case OMP_CTX_SET_device: |
| 1047 | parseDeviceSelector(*this, Loc, UsedCtx, Data); |
| 1048 | break; |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1049 | case OMP_CTX_SET_unknown: |
Alexey Bataev | 70d2e54 | 2019-10-08 17:47:52 +0000 | [diff] [blame] | 1050 | // Skip until either '}', ')', or end of directive. |
| 1051 | while (!SkipUntil(tok::r_brace, tok::r_paren, |
| 1052 | tok::annot_pragma_openmp_end, StopBeforeMatch)) |
| 1053 | ; |
| 1054 | break; |
| 1055 | } |
| 1056 | const Token PrevTok = Tok; |
| 1057 | if (!TryConsumeToken(tok::comma) && Tok.isNot(tok::r_brace)) |
| 1058 | Diag(Tok, diag::err_omp_expected_comma_brace) |
| 1059 | << (PrevTok.isAnnotation() ? "context selector trait" |
| 1060 | : PP.getSpelling(PrevTok)); |
| 1061 | } while (Tok.is(tok::identifier)); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1062 | // Parse '}'. |
| 1063 | (void)TBr.consumeClose(); |
| 1064 | } |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1065 | // Consume ',' |
| 1066 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1067 | (void)ExpectAndConsume(tok::comma); |
| 1068 | } while (Tok.isAnyIdentifier()); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1069 | return false; |
| 1070 | } |
| 1071 | |
| 1072 | /// Parse clauses for '#pragma omp declare variant ( variant-func-id ) clause'. |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1073 | void Parser::ParseOMPDeclareVariantClauses(Parser::DeclGroupPtrTy Ptr, |
| 1074 | CachedTokens &Toks, |
| 1075 | SourceLocation Loc) { |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1076 | PP.EnterToken(Tok, /*IsReinject*/ true); |
| 1077 | PP.EnterTokenStream(Toks, /*DisableMacroExpansion=*/true, |
| 1078 | /*IsReinject*/ true); |
| 1079 | // Consume the previously pushed token. |
| 1080 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
| 1081 | ConsumeAnyToken(/*ConsumeCodeCompletionTok=*/true); |
| 1082 | |
| 1083 | FNContextRAII FnContext(*this, Ptr); |
| 1084 | // Parse function declaration id. |
| 1085 | SourceLocation RLoc; |
| 1086 | // Parse with IsAddressOfOperand set to true to parse methods as DeclRefExprs |
| 1087 | // instead of MemberExprs. |
Alexey Bataev | 02d04d5 | 2019-12-10 16:12:53 -0500 | [diff] [blame] | 1088 | ExprResult AssociatedFunction; |
| 1089 | { |
| 1090 | // Do not mark function as is used to prevent its emission if this is the |
| 1091 | // only place where it is used. |
| 1092 | EnterExpressionEvaluationContext Unevaluated( |
| 1093 | Actions, Sema::ExpressionEvaluationContext::Unevaluated); |
| 1094 | AssociatedFunction = ParseOpenMPParensExpr( |
| 1095 | getOpenMPDirectiveName(OMPD_declare_variant), RLoc, |
| 1096 | /*IsAddressOfOperand=*/true); |
| 1097 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1098 | if (!AssociatedFunction.isUsable()) { |
| 1099 | if (!Tok.is(tok::annot_pragma_openmp_end)) |
| 1100 | while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch)) |
| 1101 | ; |
| 1102 | // Skip the last annot_pragma_openmp_end. |
| 1103 | (void)ConsumeAnnotationToken(); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1104 | return; |
| 1105 | } |
| 1106 | Optional<std::pair<FunctionDecl *, Expr *>> DeclVarData = |
| 1107 | Actions.checkOpenMPDeclareVariantFunction( |
| 1108 | Ptr, AssociatedFunction.get(), SourceRange(Loc, Tok.getLocation())); |
| 1109 | |
| 1110 | // Parse 'match'. |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 1111 | OpenMPClauseKind CKind = Tok.isAnnotation() |
| 1112 | ? OMPC_unknown |
| 1113 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1114 | if (CKind != OMPC_match) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1115 | Diag(Tok.getLocation(), diag::err_omp_declare_variant_wrong_clause) |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 1116 | << getOpenMPClauseName(OMPC_match); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1117 | while (!SkipUntil(tok::annot_pragma_openmp_end, Parser::StopBeforeMatch)) |
| 1118 | ; |
| 1119 | // Skip the last annot_pragma_openmp_end. |
| 1120 | (void)ConsumeAnnotationToken(); |
| 1121 | return; |
| 1122 | } |
| 1123 | (void)ConsumeToken(); |
| 1124 | // Parse '('. |
| 1125 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 1126 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1127 | getOpenMPClauseName(OMPC_match))) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1128 | while (!SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch)) |
| 1129 | ; |
| 1130 | // Skip the last annot_pragma_openmp_end. |
| 1131 | (void)ConsumeAnnotationToken(); |
| 1132 | return; |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1135 | // Parse inner context selectors. |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1136 | SmallVector<Sema::OMPCtxSelectorData, 4> Data; |
| 1137 | if (!parseOpenMPContextSelectors(Loc, Data)) { |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1138 | // Parse ')'. |
| 1139 | (void)T.consumeClose(); |
| 1140 | // Need to check for extra tokens. |
| 1141 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1142 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1143 | << getOpenMPDirectiveName(OMPD_declare_variant); |
| 1144 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1145 | } |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1146 | |
| 1147 | // Skip last tokens. |
| 1148 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1149 | ConsumeAnyToken(); |
Alexey Bataev | fde11e9 | 2019-11-07 11:03:10 -0500 | [diff] [blame] | 1150 | if (DeclVarData.hasValue()) |
| 1151 | Actions.ActOnOpenMPDeclareVariantDirective( |
| 1152 | DeclVarData.getValue().first, DeclVarData.getValue().second, |
| 1153 | SourceRange(Loc, Tok.getLocation()), Data); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1154 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1155 | (void)ConsumeAnnotationToken(); |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1156 | } |
| 1157 | |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1158 | /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
| 1159 | /// |
| 1160 | /// default-clause: |
| 1161 | /// 'default' '(' 'none' | 'shared' ') |
| 1162 | /// |
| 1163 | /// proc_bind-clause: |
| 1164 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 1165 | /// |
| 1166 | /// device_type-clause: |
| 1167 | /// 'device_type' '(' 'host' | 'nohost' | 'any' )' |
| 1168 | namespace { |
| 1169 | struct SimpleClauseData { |
| 1170 | unsigned Type; |
| 1171 | SourceLocation Loc; |
| 1172 | SourceLocation LOpen; |
| 1173 | SourceLocation TypeLoc; |
| 1174 | SourceLocation RLoc; |
| 1175 | SimpleClauseData(unsigned Type, SourceLocation Loc, SourceLocation LOpen, |
| 1176 | SourceLocation TypeLoc, SourceLocation RLoc) |
| 1177 | : Type(Type), Loc(Loc), LOpen(LOpen), TypeLoc(TypeLoc), RLoc(RLoc) {} |
| 1178 | }; |
| 1179 | } // anonymous namespace |
| 1180 | |
| 1181 | static Optional<SimpleClauseData> |
| 1182 | parseOpenMPSimpleClause(Parser &P, OpenMPClauseKind Kind) { |
| 1183 | const Token &Tok = P.getCurToken(); |
| 1184 | SourceLocation Loc = Tok.getLocation(); |
| 1185 | SourceLocation LOpen = P.ConsumeToken(); |
| 1186 | // Parse '('. |
| 1187 | BalancedDelimiterTracker T(P, tok::l_paren, tok::annot_pragma_openmp_end); |
| 1188 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 1189 | getOpenMPClauseName(Kind))) |
| 1190 | return llvm::None; |
| 1191 | |
| 1192 | unsigned Type = getOpenMPSimpleClauseType( |
| 1193 | Kind, Tok.isAnnotation() ? "" : P.getPreprocessor().getSpelling(Tok)); |
| 1194 | SourceLocation TypeLoc = Tok.getLocation(); |
| 1195 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 1196 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1197 | P.ConsumeAnyToken(); |
| 1198 | |
| 1199 | // Parse ')'. |
| 1200 | SourceLocation RLoc = Tok.getLocation(); |
| 1201 | if (!T.consumeClose()) |
| 1202 | RLoc = T.getCloseLocation(); |
| 1203 | |
| 1204 | return SimpleClauseData(Type, Loc, LOpen, TypeLoc, RLoc); |
| 1205 | } |
| 1206 | |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1207 | Parser::DeclGroupPtrTy Parser::ParseOMPDeclareTargetClauses() { |
| 1208 | // OpenMP 4.5 syntax with list of entities. |
| 1209 | Sema::NamedDeclSetType SameDirectiveDecls; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1210 | SmallVector<std::tuple<OMPDeclareTargetDeclAttr::MapTypeTy, SourceLocation, |
| 1211 | NamedDecl *>, |
| 1212 | 4> |
| 1213 | DeclareTargetDecls; |
| 1214 | OMPDeclareTargetDeclAttr::DevTypeTy DT = OMPDeclareTargetDeclAttr::DT_Any; |
| 1215 | SourceLocation DeviceTypeLoc; |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1216 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1217 | OMPDeclareTargetDeclAttr::MapTypeTy MT = OMPDeclareTargetDeclAttr::MT_To; |
| 1218 | if (Tok.is(tok::identifier)) { |
| 1219 | IdentifierInfo *II = Tok.getIdentifierInfo(); |
| 1220 | StringRef ClauseName = II->getName(); |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1221 | bool IsDeviceTypeClause = |
| 1222 | getLangOpts().OpenMP >= 50 && |
| 1223 | getOpenMPClauseKind(ClauseName) == OMPC_device_type; |
| 1224 | // Parse 'to|link|device_type' clauses. |
| 1225 | if (!OMPDeclareTargetDeclAttr::ConvertStrToMapTypeTy(ClauseName, MT) && |
| 1226 | !IsDeviceTypeClause) { |
| 1227 | Diag(Tok, diag::err_omp_declare_target_unexpected_clause) |
| 1228 | << ClauseName << (getLangOpts().OpenMP >= 50 ? 1 : 0); |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1229 | break; |
| 1230 | } |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1231 | // Parse 'device_type' clause and go to next clause if any. |
| 1232 | if (IsDeviceTypeClause) { |
| 1233 | Optional<SimpleClauseData> DevTypeData = |
| 1234 | parseOpenMPSimpleClause(*this, OMPC_device_type); |
| 1235 | if (DevTypeData.hasValue()) { |
| 1236 | if (DeviceTypeLoc.isValid()) { |
| 1237 | // We already saw another device_type clause, diagnose it. |
| 1238 | Diag(DevTypeData.getValue().Loc, |
| 1239 | diag::warn_omp_more_one_device_type_clause); |
| 1240 | } |
| 1241 | switch(static_cast<OpenMPDeviceType>(DevTypeData.getValue().Type)) { |
| 1242 | case OMPC_DEVICE_TYPE_any: |
| 1243 | DT = OMPDeclareTargetDeclAttr::DT_Any; |
| 1244 | break; |
| 1245 | case OMPC_DEVICE_TYPE_host: |
| 1246 | DT = OMPDeclareTargetDeclAttr::DT_Host; |
| 1247 | break; |
| 1248 | case OMPC_DEVICE_TYPE_nohost: |
| 1249 | DT = OMPDeclareTargetDeclAttr::DT_NoHost; |
| 1250 | break; |
| 1251 | case OMPC_DEVICE_TYPE_unknown: |
| 1252 | llvm_unreachable("Unexpected device_type"); |
| 1253 | } |
| 1254 | DeviceTypeLoc = DevTypeData.getValue().Loc; |
| 1255 | } |
| 1256 | continue; |
| 1257 | } |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1258 | ConsumeToken(); |
| 1259 | } |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1260 | auto &&Callback = [this, MT, &DeclareTargetDecls, &SameDirectiveDecls]( |
| 1261 | CXXScopeSpec &SS, DeclarationNameInfo NameInfo) { |
| 1262 | NamedDecl *ND = Actions.lookupOpenMPDeclareTargetName( |
| 1263 | getCurScope(), SS, NameInfo, SameDirectiveDecls); |
| 1264 | if (ND) |
| 1265 | DeclareTargetDecls.emplace_back(MT, NameInfo.getLoc(), ND); |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1266 | }; |
| 1267 | if (ParseOpenMPSimpleVarList(OMPD_declare_target, Callback, |
| 1268 | /*AllowScopeSpecifier=*/true)) |
| 1269 | break; |
| 1270 | |
| 1271 | // Consume optional ','. |
| 1272 | if (Tok.is(tok::comma)) |
| 1273 | ConsumeToken(); |
| 1274 | } |
| 1275 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1276 | ConsumeAnyToken(); |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 1277 | for (auto &MTLocDecl : DeclareTargetDecls) { |
| 1278 | OMPDeclareTargetDeclAttr::MapTypeTy MT; |
| 1279 | SourceLocation Loc; |
| 1280 | NamedDecl *ND; |
| 1281 | std::tie(MT, Loc, ND) = MTLocDecl; |
| 1282 | // device_type clause is applied only to functions. |
| 1283 | Actions.ActOnOpenMPDeclareTargetName( |
| 1284 | ND, Loc, MT, isa<VarDecl>(ND) ? OMPDeclareTargetDeclAttr::DT_Any : DT); |
| 1285 | } |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1286 | SmallVector<Decl *, 4> Decls(SameDirectiveDecls.begin(), |
| 1287 | SameDirectiveDecls.end()); |
| 1288 | if (Decls.empty()) |
| 1289 | return DeclGroupPtrTy(); |
| 1290 | return Actions.BuildDeclaratorGroup(Decls); |
| 1291 | } |
| 1292 | |
| 1293 | void Parser::ParseOMPEndDeclareTargetDirective(OpenMPDirectiveKind DKind, |
| 1294 | SourceLocation DTLoc) { |
| 1295 | if (DKind != OMPD_end_declare_target) { |
| 1296 | Diag(Tok, diag::err_expected_end_declare_target); |
| 1297 | Diag(DTLoc, diag::note_matching) << "'#pragma omp declare target'"; |
| 1298 | return; |
| 1299 | } |
| 1300 | ConsumeAnyToken(); |
| 1301 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1302 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1303 | << getOpenMPDirectiveName(OMPD_end_declare_target); |
| 1304 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1305 | } |
| 1306 | // Skip the last annot_pragma_openmp_end. |
| 1307 | ConsumeAnyToken(); |
| 1308 | } |
| 1309 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1310 | /// Parsing of declarative OpenMP directives. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1311 | /// |
| 1312 | /// threadprivate-directive: |
| 1313 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1314 | /// annot_pragma_openmp_end |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1315 | /// |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1316 | /// allocate-directive: |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1317 | /// annot_pragma_openmp 'allocate' simple-variable-list [<clause>] |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1318 | /// annot_pragma_openmp_end |
| 1319 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1320 | /// declare-reduction-directive: |
| 1321 | /// annot_pragma_openmp 'declare' 'reduction' [...] |
| 1322 | /// annot_pragma_openmp_end |
| 1323 | /// |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1324 | /// declare-mapper-directive: |
| 1325 | /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':'] |
| 1326 | /// <type> <var> ')' [<clause>[[,] <clause>] ... ] |
| 1327 | /// annot_pragma_openmp_end |
| 1328 | /// |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1329 | /// declare-simd-directive: |
| 1330 | /// annot_pragma_openmp 'declare simd' {<clause> [,]} |
| 1331 | /// annot_pragma_openmp_end |
| 1332 | /// <function declaration/definition> |
| 1333 | /// |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1334 | /// requires directive: |
| 1335 | /// annot_pragma_openmp 'requires' <clause> [[[,] <clause>] ... ] |
| 1336 | /// annot_pragma_openmp_end |
| 1337 | /// |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1338 | Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl( |
| 1339 | AccessSpecifier &AS, ParsedAttributesWithRange &Attrs, |
| 1340 | DeclSpec::TST TagType, Decl *Tag) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1341 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | 8035bb4 | 2019-12-13 16:05:30 -0500 | [diff] [blame] | 1342 | ParsingOpenMPDirectiveRAII DirScope(*this); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1343 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1344 | |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1345 | SourceLocation Loc = ConsumeAnnotationToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1346 | OpenMPDirectiveKind DKind = parseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1347 | |
| 1348 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1349 | case OMPD_threadprivate: { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1350 | ConsumeToken(); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1351 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1352 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1353 | /*AllowScopeSpecifier=*/true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1354 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1355 | // extra tokens. |
| 1356 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1357 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1358 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1359 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1360 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1361 | // Skip the last annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1362 | ConsumeAnnotationToken(); |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1363 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, |
| 1364 | Helper.getIdentifiers()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1365 | } |
| 1366 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1367 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1368 | case OMPD_allocate: { |
| 1369 | ConsumeToken(); |
| 1370 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1371 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1372 | /*AllowScopeSpecifier=*/true)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1373 | SmallVector<OMPClause *, 1> Clauses; |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1374 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1375 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, |
| 1376 | OMPC_unknown + 1> |
| 1377 | FirstClauses(OMPC_unknown + 1); |
| 1378 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1379 | OpenMPClauseKind CKind = |
| 1380 | Tok.isAnnotation() ? OMPC_unknown |
| 1381 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1382 | Actions.StartOpenMPClause(CKind); |
| 1383 | OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind, |
| 1384 | !FirstClauses[CKind].getInt()); |
| 1385 | SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, |
| 1386 | StopBeforeMatch); |
| 1387 | FirstClauses[CKind].setInt(true); |
| 1388 | if (Clause != nullptr) |
| 1389 | Clauses.push_back(Clause); |
| 1390 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 1391 | Actions.EndOpenMPClause(); |
| 1392 | break; |
| 1393 | } |
| 1394 | // Skip ',' if any. |
| 1395 | if (Tok.is(tok::comma)) |
| 1396 | ConsumeToken(); |
| 1397 | Actions.EndOpenMPClause(); |
| 1398 | } |
| 1399 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1400 | // extra tokens. |
| 1401 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1402 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1403 | << getOpenMPDirectiveName(DKind); |
| 1404 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1405 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1406 | } |
| 1407 | // Skip the last annot_pragma_openmp_end. |
| 1408 | ConsumeAnnotationToken(); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1409 | return Actions.ActOnOpenMPAllocateDirective(Loc, Helper.getIdentifiers(), |
| 1410 | Clauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1411 | } |
| 1412 | break; |
| 1413 | } |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1414 | case OMPD_requires: { |
| 1415 | SourceLocation StartLoc = ConsumeToken(); |
| 1416 | SmallVector<OMPClause *, 5> Clauses; |
| 1417 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
| 1418 | FirstClauses(OMPC_unknown + 1); |
| 1419 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
Ilya Biryukov | ff2a997 | 2019-02-26 11:01:50 +0000 | [diff] [blame] | 1420 | Diag(Tok, diag::err_omp_expected_clause) |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1421 | << getOpenMPDirectiveName(OMPD_requires); |
| 1422 | break; |
| 1423 | } |
| 1424 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1425 | OpenMPClauseKind CKind = Tok.isAnnotation() |
| 1426 | ? OMPC_unknown |
| 1427 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1428 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1429 | OMPClause *Clause = ParseOpenMPClause(OMPD_requires, CKind, |
| 1430 | !FirstClauses[CKind].getInt()); |
| 1431 | SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, |
| 1432 | StopBeforeMatch); |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1433 | FirstClauses[CKind].setInt(true); |
| 1434 | if (Clause != nullptr) |
| 1435 | Clauses.push_back(Clause); |
| 1436 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 1437 | Actions.EndOpenMPClause(); |
| 1438 | break; |
| 1439 | } |
| 1440 | // Skip ',' if any. |
| 1441 | if (Tok.is(tok::comma)) |
| 1442 | ConsumeToken(); |
| 1443 | Actions.EndOpenMPClause(); |
| 1444 | } |
| 1445 | // Consume final annot_pragma_openmp_end |
| 1446 | if (Clauses.size() == 0) { |
| 1447 | Diag(Tok, diag::err_omp_expected_clause) |
| 1448 | << getOpenMPDirectiveName(OMPD_requires); |
| 1449 | ConsumeAnnotationToken(); |
| 1450 | return nullptr; |
| 1451 | } |
| 1452 | ConsumeAnnotationToken(); |
| 1453 | return Actions.ActOnOpenMPRequiresDirective(StartLoc, Clauses); |
| 1454 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1455 | case OMPD_declare_reduction: |
| 1456 | ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1457 | if (DeclGroupPtrTy Res = ParseOpenMPDeclareReductionDirective(AS)) { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1458 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1459 | // extra tokens. |
| 1460 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1461 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1462 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 1463 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1464 | ConsumeAnyToken(); |
| 1465 | } |
| 1466 | // Skip the last annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1467 | ConsumeAnnotationToken(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1468 | return Res; |
| 1469 | } |
| 1470 | break; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1471 | case OMPD_declare_mapper: { |
| 1472 | ConsumeToken(); |
| 1473 | if (DeclGroupPtrTy Res = ParseOpenMPDeclareMapperDirective(AS)) { |
| 1474 | // Skip the last annot_pragma_openmp_end. |
| 1475 | ConsumeAnnotationToken(); |
| 1476 | return Res; |
| 1477 | } |
| 1478 | break; |
| 1479 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1480 | case OMPD_declare_variant: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1481 | case OMPD_declare_simd: { |
| 1482 | // The syntax is: |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1483 | // { #pragma omp declare {simd|variant} } |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1484 | // <function-declaration-or-definition> |
| 1485 | // |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 1486 | CachedTokens Toks; |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1487 | Toks.push_back(Tok); |
| 1488 | ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 1489 | while(Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1490 | Toks.push_back(Tok); |
| 1491 | ConsumeAnyToken(); |
| 1492 | } |
| 1493 | Toks.push_back(Tok); |
| 1494 | ConsumeAnyToken(); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1495 | |
| 1496 | DeclGroupPtrTy Ptr; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1497 | if (Tok.is(tok::annot_pragma_openmp)) { |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1498 | Ptr = ParseOpenMPDeclarativeDirectiveWithExtDecl(AS, Attrs, TagType, Tag); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1499 | } else if (Tok.isNot(tok::r_brace) && !isEofOrEom()) { |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1500 | // Here we expect to see some function declaration. |
| 1501 | if (AS == AS_none) { |
| 1502 | assert(TagType == DeclSpec::TST_unspecified); |
| 1503 | MaybeParseCXX11Attributes(Attrs); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1504 | ParsingDeclSpec PDS(*this); |
| 1505 | Ptr = ParseExternalDeclaration(Attrs, &PDS); |
| 1506 | } else { |
| 1507 | Ptr = |
| 1508 | ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag); |
| 1509 | } |
| 1510 | } |
| 1511 | if (!Ptr) { |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1512 | Diag(Loc, diag::err_omp_decl_in_declare_simd_variant) |
| 1513 | << (DKind == OMPD_declare_simd ? 0 : 1); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1514 | return DeclGroupPtrTy(); |
| 1515 | } |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1516 | if (DKind == OMPD_declare_simd) |
| 1517 | return ParseOMPDeclareSimdClauses(Ptr, Toks, Loc); |
| 1518 | assert(DKind == OMPD_declare_variant && |
| 1519 | "Expected declare variant directive only"); |
Alexey Bataev | 0736f7f | 2019-09-18 16:24:31 +0000 | [diff] [blame] | 1520 | ParseOMPDeclareVariantClauses(Ptr, Toks, Loc); |
| 1521 | return Ptr; |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1522 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1523 | case OMPD_declare_target: { |
| 1524 | SourceLocation DTLoc = ConsumeAnyToken(); |
| 1525 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1526 | return ParseOMPDeclareTargetClauses(); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1527 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1528 | |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1529 | // Skip the last annot_pragma_openmp_end. |
| 1530 | ConsumeAnyToken(); |
| 1531 | |
| 1532 | if (!Actions.ActOnStartOpenMPDeclareTargetDirective(DTLoc)) |
| 1533 | return DeclGroupPtrTy(); |
| 1534 | |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1535 | llvm::SmallVector<Decl *, 4> Decls; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1536 | DKind = parseOpenMPDirectiveKind(*this); |
Kelvin Li | bc38e63 | 2018-09-10 02:07:09 +0000 | [diff] [blame] | 1537 | while (DKind != OMPD_end_declare_target && Tok.isNot(tok::eof) && |
| 1538 | Tok.isNot(tok::r_brace)) { |
Alexey Bataev | 502ec49 | 2017-10-03 20:00:00 +0000 | [diff] [blame] | 1539 | DeclGroupPtrTy Ptr; |
| 1540 | // Here we expect to see some function declaration. |
| 1541 | if (AS == AS_none) { |
| 1542 | assert(TagType == DeclSpec::TST_unspecified); |
| 1543 | MaybeParseCXX11Attributes(Attrs); |
| 1544 | ParsingDeclSpec PDS(*this); |
| 1545 | Ptr = ParseExternalDeclaration(Attrs, &PDS); |
| 1546 | } else { |
| 1547 | Ptr = |
| 1548 | ParseCXXClassMemberDeclarationWithPragmas(AS, Attrs, TagType, Tag); |
| 1549 | } |
Alexey Bataev | 4f4bf7c | 2018-03-15 15:47:20 +0000 | [diff] [blame] | 1550 | if (Ptr) { |
| 1551 | DeclGroupRef Ref = Ptr.get(); |
| 1552 | Decls.append(Ref.begin(), Ref.end()); |
| 1553 | } |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1554 | if (Tok.isAnnotation() && Tok.is(tok::annot_pragma_openmp)) { |
| 1555 | TentativeParsingAction TPA(*this); |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1556 | ConsumeAnnotationToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1557 | DKind = parseOpenMPDirectiveKind(*this); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1558 | if (DKind != OMPD_end_declare_target) |
| 1559 | TPA.Revert(); |
| 1560 | else |
| 1561 | TPA.Commit(); |
| 1562 | } |
| 1563 | } |
| 1564 | |
Kelvin Li | e050275 | 2018-11-21 20:15:57 +0000 | [diff] [blame] | 1565 | ParseOMPEndDeclareTargetDirective(DKind, DTLoc); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1566 | Actions.ActOnFinishOpenMPDeclareTargetDirective(); |
Alexey Bataev | 34f8a70 | 2018-03-28 14:28:54 +0000 | [diff] [blame] | 1567 | return Actions.BuildDeclaratorGroup(Decls); |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1568 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1569 | case OMPD_unknown: |
| 1570 | Diag(Tok, diag::err_omp_unknown_directive); |
| 1571 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1572 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1573 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1574 | case OMPD_task: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1575 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1576 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1577 | case OMPD_taskwait: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1578 | case OMPD_taskgroup: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1579 | case OMPD_flush: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1580 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1581 | case OMPD_for_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1582 | case OMPD_sections: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1583 | case OMPD_section: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1584 | case OMPD_single: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1585 | case OMPD_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1586 | case OMPD_ordered: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1587 | case OMPD_critical: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1588 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1589 | case OMPD_parallel_for_simd: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1590 | case OMPD_parallel_sections: |
cchen | 47d6094 | 2019-12-05 13:43:48 -0500 | [diff] [blame] | 1591 | case OMPD_parallel_master: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1592 | case OMPD_atomic: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1593 | case OMPD_target: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1594 | case OMPD_teams: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1595 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1596 | case OMPD_cancel: |
Samuel Antao | 5b0688e | 2015-07-22 16:02:46 +0000 | [diff] [blame] | 1597 | case OMPD_target_data: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1598 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1599 | case OMPD_target_exit_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1600 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1601 | case OMPD_target_parallel_for: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1602 | case OMPD_taskloop: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1603 | case OMPD_taskloop_simd: |
Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 1604 | case OMPD_master_taskloop: |
Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 1605 | case OMPD_master_taskloop_simd: |
Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 1606 | case OMPD_parallel_master_taskloop: |
Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 1607 | case OMPD_parallel_master_taskloop_simd: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1608 | case OMPD_distribute: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1609 | case OMPD_end_declare_target: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1610 | case OMPD_target_update: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1611 | case OMPD_distribute_parallel_for: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1612 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1613 | case OMPD_distribute_simd: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1614 | case OMPD_target_parallel_for_simd: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1615 | case OMPD_target_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1616 | case OMPD_teams_distribute: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1617 | case OMPD_teams_distribute_simd: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1618 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1619 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1620 | case OMPD_target_teams: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1621 | case OMPD_target_teams_distribute: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1622 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1623 | case OMPD_target_teams_distribute_parallel_for_simd: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1624 | case OMPD_target_teams_distribute_simd: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1625 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | 96dae81 | 2018-02-16 18:36:44 +0000 | [diff] [blame] | 1626 | << 1 << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1627 | break; |
| 1628 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1629 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1630 | ConsumeAnyToken(); |
| 1631 | ConsumeAnyToken(); |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 1632 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1633 | } |
| 1634 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 1635 | /// Parsing of declarative or executable OpenMP directives. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1636 | /// |
| 1637 | /// threadprivate-directive: |
| 1638 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 1639 | /// annot_pragma_openmp_end |
| 1640 | /// |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1641 | /// allocate-directive: |
| 1642 | /// annot_pragma_openmp 'allocate' simple-variable-list |
| 1643 | /// annot_pragma_openmp_end |
| 1644 | /// |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1645 | /// declare-reduction-directive: |
| 1646 | /// annot_pragma_openmp 'declare' 'reduction' '(' <reduction_id> ':' |
| 1647 | /// <type> {',' <type>} ':' <expression> ')' ['initializer' '(' |
| 1648 | /// ('omp_priv' '=' <expression>|<function_call>) ')'] |
| 1649 | /// annot_pragma_openmp_end |
| 1650 | /// |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1651 | /// declare-mapper-directive: |
| 1652 | /// annot_pragma_openmp 'declare' 'mapper' '(' [<mapper-identifer> ':'] |
| 1653 | /// <type> <var> ')' [<clause>[[,] <clause>] ... ] |
| 1654 | /// annot_pragma_openmp_end |
| 1655 | /// |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1656 | /// executable-directive: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1657 | /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1658 | /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] | |
cchen | 47d6094 | 2019-12-05 13:43:48 -0500 | [diff] [blame] | 1659 | /// 'parallel for' | 'parallel sections' | 'parallel master' | 'task' | |
| 1660 | /// 'taskyield' | 'barrier' | 'taskwait' | 'flush' | 'ordered' | |
| 1661 | /// 'atomic' | 'for simd' | 'parallel for simd' | 'target' | 'target |
| 1662 | /// data' | 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | |
| 1663 | /// 'master taskloop' | 'master taskloop simd' | 'parallel master |
| 1664 | /// taskloop' | 'parallel master taskloop simd' | 'distribute' | 'target |
| 1665 | /// enter data' | 'target exit data' | 'target parallel' | 'target |
| 1666 | /// parallel for' | 'target update' | 'distribute parallel for' | |
| 1667 | /// 'distribute paralle for simd' | 'distribute simd' | 'target parallel |
| 1668 | /// for simd' | 'target simd' | 'teams distribute' | 'teams distribute |
| 1669 | /// simd' | 'teams distribute parallel for simd' | 'teams distribute |
| 1670 | /// parallel for' | 'target teams' | 'target teams distribute' | 'target |
| 1671 | /// teams distribute parallel for' | 'target teams distribute parallel |
| 1672 | /// for simd' | 'target teams distribute simd' {clause} |
Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 1673 | /// annot_pragma_openmp_end |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1674 | /// |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1675 | StmtResult |
| 1676 | Parser::ParseOpenMPDeclarativeOrExecutableDirective(ParsedStmtContext StmtCtx) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1677 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | 8035bb4 | 2019-12-13 16:05:30 -0500 | [diff] [blame] | 1678 | ParsingOpenMPDirectiveRAII DirScope(*this); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 1679 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1680 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 1681 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1682 | FirstClauses(OMPC_unknown + 1); |
Momchil Velikov | 57c681f | 2017-08-10 15:43:06 +0000 | [diff] [blame] | 1683 | unsigned ScopeFlags = Scope::FnScope | Scope::DeclScope | |
| 1684 | Scope::CompoundStmtScope | Scope::OpenMPDirectiveScope; |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1685 | SourceLocation Loc = ConsumeAnnotationToken(), EndLoc; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1686 | OpenMPDirectiveKind DKind = parseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1687 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1688 | // Name of critical directive. |
| 1689 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1690 | StmtResult Directive = StmtError(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1691 | bool HasAssociatedStatement = true; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1692 | bool FlushHasClause = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1693 | |
| 1694 | switch (DKind) { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1695 | case OMPD_threadprivate: { |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1696 | // FIXME: Should this be permitted in C++? |
| 1697 | if ((StmtCtx & ParsedStmtContext::AllowDeclarationsInC) == |
| 1698 | ParsedStmtContext()) { |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 1699 | Diag(Tok, diag::err_omp_immediate_directive) |
| 1700 | << getOpenMPDirectiveName(DKind) << 0; |
| 1701 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1702 | ConsumeToken(); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1703 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1704 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1705 | /*AllowScopeSpecifier=*/false)) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1706 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1707 | // extra tokens. |
| 1708 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1709 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1710 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1711 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1712 | } |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1713 | DeclGroupPtrTy Res = Actions.ActOnOpenMPThreadprivateDirective( |
| 1714 | Loc, Helper.getIdentifiers()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1715 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 1716 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1717 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1718 | break; |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1719 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1720 | case OMPD_allocate: { |
| 1721 | // FIXME: Should this be permitted in C++? |
| 1722 | if ((StmtCtx & ParsedStmtContext::AllowDeclarationsInC) == |
| 1723 | ParsedStmtContext()) { |
| 1724 | Diag(Tok, diag::err_omp_immediate_directive) |
| 1725 | << getOpenMPDirectiveName(DKind) << 0; |
| 1726 | } |
| 1727 | ConsumeToken(); |
| 1728 | DeclDirectiveListParserHelper Helper(this, DKind); |
| 1729 | if (!ParseOpenMPSimpleVarList(DKind, Helper, |
| 1730 | /*AllowScopeSpecifier=*/false)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1731 | SmallVector<OMPClause *, 1> Clauses; |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1732 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1733 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, |
| 1734 | OMPC_unknown + 1> |
| 1735 | FirstClauses(OMPC_unknown + 1); |
| 1736 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1737 | OpenMPClauseKind CKind = |
| 1738 | Tok.isAnnotation() ? OMPC_unknown |
| 1739 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 1740 | Actions.StartOpenMPClause(CKind); |
| 1741 | OMPClause *Clause = ParseOpenMPClause(OMPD_allocate, CKind, |
| 1742 | !FirstClauses[CKind].getInt()); |
| 1743 | SkipUntil(tok::comma, tok::identifier, tok::annot_pragma_openmp_end, |
| 1744 | StopBeforeMatch); |
| 1745 | FirstClauses[CKind].setInt(true); |
| 1746 | if (Clause != nullptr) |
| 1747 | Clauses.push_back(Clause); |
| 1748 | if (Tok.is(tok::annot_pragma_openmp_end)) { |
| 1749 | Actions.EndOpenMPClause(); |
| 1750 | break; |
| 1751 | } |
| 1752 | // Skip ',' if any. |
| 1753 | if (Tok.is(tok::comma)) |
| 1754 | ConsumeToken(); |
| 1755 | Actions.EndOpenMPClause(); |
| 1756 | } |
| 1757 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1758 | // extra tokens. |
| 1759 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1760 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1761 | << getOpenMPDirectiveName(DKind); |
| 1762 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
| 1763 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1764 | } |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 1765 | DeclGroupPtrTy Res = Actions.ActOnOpenMPAllocateDirective( |
| 1766 | Loc, Helper.getIdentifiers(), Clauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 1767 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 1768 | } |
| 1769 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1770 | break; |
| 1771 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1772 | case OMPD_declare_reduction: |
| 1773 | ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1774 | if (DeclGroupPtrTy Res = |
| 1775 | ParseOpenMPDeclareReductionDirective(/*AS=*/AS_none)) { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1776 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 1777 | // extra tokens. |
| 1778 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 1779 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
| 1780 | << getOpenMPDirectiveName(OMPD_declare_reduction); |
| 1781 | while (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1782 | ConsumeAnyToken(); |
| 1783 | } |
| 1784 | ConsumeAnyToken(); |
| 1785 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1786 | } else { |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1787 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1788 | } |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 1789 | break; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 1790 | case OMPD_declare_mapper: { |
| 1791 | ConsumeToken(); |
| 1792 | if (DeclGroupPtrTy Res = |
| 1793 | ParseOpenMPDeclareMapperDirective(/*AS=*/AS_none)) { |
| 1794 | // Skip the last annot_pragma_openmp_end. |
| 1795 | ConsumeAnnotationToken(); |
| 1796 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 1797 | } else { |
| 1798 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1799 | } |
| 1800 | break; |
| 1801 | } |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1802 | case OMPD_flush: |
| 1803 | if (PP.LookAhead(0).is(tok::l_paren)) { |
| 1804 | FlushHasClause = true; |
| 1805 | // Push copy of the current token back to stream to properly parse |
| 1806 | // pseudo-clause OMPFlushClause. |
Ilya Biryukov | 929af67 | 2019-05-17 09:32:05 +0000 | [diff] [blame] | 1807 | PP.EnterToken(Tok, /*IsReinject*/ true); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1808 | } |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 1809 | LLVM_FALLTHROUGH; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1810 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 1811 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 1812 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1813 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1814 | case OMPD_cancel: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 1815 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 1816 | case OMPD_target_exit_data: |
Samuel Antao | 686c70c | 2016-05-26 17:30:50 +0000 | [diff] [blame] | 1817 | case OMPD_target_update: |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1818 | if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) == |
| 1819 | ParsedStmtContext()) { |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1820 | Diag(Tok, diag::err_omp_immediate_directive) |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1821 | << getOpenMPDirectiveName(DKind) << 0; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1822 | } |
| 1823 | HasAssociatedStatement = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1824 | // Fall through for further analysis. |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 1825 | LLVM_FALLTHROUGH; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 1826 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1827 | case OMPD_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 1828 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 1829 | case OMPD_for_simd: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 1830 | case OMPD_sections: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 1831 | case OMPD_single: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 1832 | case OMPD_section: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 1833 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1834 | case OMPD_critical: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 1835 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 1836 | case OMPD_parallel_for_simd: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 1837 | case OMPD_parallel_sections: |
cchen | 47d6094 | 2019-12-05 13:43:48 -0500 | [diff] [blame] | 1838 | case OMPD_parallel_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 1839 | case OMPD_task: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 1840 | case OMPD_ordered: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 1841 | case OMPD_atomic: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 1842 | case OMPD_target: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 1843 | case OMPD_teams: |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 1844 | case OMPD_taskgroup: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 1845 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 1846 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 1847 | case OMPD_target_parallel_for: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 1848 | case OMPD_taskloop: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 1849 | case OMPD_taskloop_simd: |
Alexey Bataev | 60e51c4 | 2019-10-10 20:13:02 +0000 | [diff] [blame] | 1850 | case OMPD_master_taskloop: |
Alexey Bataev | b8552ab | 2019-10-18 16:47:35 +0000 | [diff] [blame] | 1851 | case OMPD_master_taskloop_simd: |
Alexey Bataev | 5bbcead | 2019-10-14 17:17:41 +0000 | [diff] [blame] | 1852 | case OMPD_parallel_master_taskloop: |
Alexey Bataev | 14a388f | 2019-10-25 10:27:13 -0400 | [diff] [blame] | 1853 | case OMPD_parallel_master_taskloop_simd: |
Carlo Bertolli | 9925f15 | 2016-06-27 14:55:37 +0000 | [diff] [blame] | 1854 | case OMPD_distribute: |
Kelvin Li | 4a39add | 2016-07-05 05:00:15 +0000 | [diff] [blame] | 1855 | case OMPD_distribute_parallel_for: |
Kelvin Li | 787f3fc | 2016-07-06 04:45:38 +0000 | [diff] [blame] | 1856 | case OMPD_distribute_parallel_for_simd: |
Kelvin Li | a579b91 | 2016-07-14 02:54:56 +0000 | [diff] [blame] | 1857 | case OMPD_distribute_simd: |
Kelvin Li | 986330c | 2016-07-20 22:57:10 +0000 | [diff] [blame] | 1858 | case OMPD_target_parallel_for_simd: |
Kelvin Li | 0253287 | 2016-08-05 14:37:37 +0000 | [diff] [blame] | 1859 | case OMPD_target_simd: |
Kelvin Li | 4e325f7 | 2016-10-25 12:50:55 +0000 | [diff] [blame] | 1860 | case OMPD_teams_distribute: |
Kelvin Li | 579e41c | 2016-11-30 23:51:03 +0000 | [diff] [blame] | 1861 | case OMPD_teams_distribute_simd: |
Kelvin Li | 7ade93f | 2016-12-09 03:24:30 +0000 | [diff] [blame] | 1862 | case OMPD_teams_distribute_parallel_for_simd: |
Kelvin Li | bf594a5 | 2016-12-17 05:48:59 +0000 | [diff] [blame] | 1863 | case OMPD_teams_distribute_parallel_for: |
Kelvin Li | 83c451e | 2016-12-25 04:52:54 +0000 | [diff] [blame] | 1864 | case OMPD_target_teams: |
Kelvin Li | 80e8f56 | 2016-12-29 22:16:30 +0000 | [diff] [blame] | 1865 | case OMPD_target_teams_distribute: |
Kelvin Li | 1851df5 | 2017-01-03 05:23:48 +0000 | [diff] [blame] | 1866 | case OMPD_target_teams_distribute_parallel_for: |
Kelvin Li | da68118 | 2017-01-10 18:08:18 +0000 | [diff] [blame] | 1867 | case OMPD_target_teams_distribute_parallel_for_simd: |
| 1868 | case OMPD_target_teams_distribute_simd: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1869 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1870 | // Parse directive name of the 'critical' directive if any. |
| 1871 | if (DKind == OMPD_critical) { |
| 1872 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 1873 | tok::annot_pragma_openmp_end); |
| 1874 | if (!T.consumeOpen()) { |
| 1875 | if (Tok.isAnyIdentifier()) { |
| 1876 | DirName = |
| 1877 | DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 1878 | ConsumeAnyToken(); |
| 1879 | } else { |
| 1880 | Diag(Tok, diag::err_omp_expected_identifier_for_critical); |
| 1881 | } |
| 1882 | T.consumeClose(); |
| 1883 | } |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 1884 | } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) { |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 1885 | CancelRegion = parseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 1886 | if (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 1887 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 1888 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1889 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 1890 | if (isOpenMPLoopDirective(DKind)) |
| 1891 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 1892 | if (isOpenMPSimdDirective(DKind)) |
| 1893 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 1894 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1895 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1896 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1897 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1898 | OpenMPClauseKind CKind = |
| 1899 | Tok.isAnnotation() |
| 1900 | ? OMPC_unknown |
| 1901 | : FlushHasClause ? OMPC_flush |
| 1902 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1903 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1904 | FlushHasClause = false; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1905 | OMPClause *Clause = |
| 1906 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1907 | FirstClauses[CKind].setInt(true); |
| 1908 | if (Clause) { |
| 1909 | FirstClauses[CKind].setPointer(Clause); |
| 1910 | Clauses.push_back(Clause); |
| 1911 | } |
| 1912 | |
| 1913 | // Skip ',' if any. |
| 1914 | if (Tok.is(tok::comma)) |
| 1915 | ConsumeToken(); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 1916 | Actions.EndOpenMPClause(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1917 | } |
| 1918 | // End location of the directive. |
| 1919 | EndLoc = Tok.getLocation(); |
| 1920 | // Consume final annot_pragma_openmp_end. |
Richard Smith | af3b325 | 2017-05-18 19:21:48 +0000 | [diff] [blame] | 1921 | ConsumeAnnotationToken(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1922 | |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1923 | // OpenMP [2.13.8, ordered Construct, Syntax] |
| 1924 | // If the depend clause is specified, the ordered construct is a stand-alone |
| 1925 | // directive. |
| 1926 | if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) { |
Richard Smith | a6e8d5e | 2019-02-15 00:27:53 +0000 | [diff] [blame] | 1927 | if ((StmtCtx & ParsedStmtContext::AllowStandaloneOpenMPDirectives) == |
| 1928 | ParsedStmtContext()) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 1929 | Diag(Loc, diag::err_omp_immediate_directive) |
| 1930 | << getOpenMPDirectiveName(DKind) << 1 |
| 1931 | << getOpenMPClauseName(OMPC_depend); |
| 1932 | } |
| 1933 | HasAssociatedStatement = false; |
| 1934 | } |
| 1935 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1936 | StmtResult AssociatedStmt; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 1937 | if (HasAssociatedStatement) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1938 | // The body is a block scope like in Lambdas and Blocks. |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 1939 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Richard Smith | 6eb9b9e | 2018-02-03 00:44:57 +0000 | [diff] [blame] | 1940 | // FIXME: We create a bogus CompoundStmt scope to hold the contents of |
| 1941 | // the captured region. Code elsewhere assumes that any FunctionScopeInfo |
| 1942 | // should have at least one compound statement scope within it. |
| 1943 | AssociatedStmt = (Sema::CompoundScopeRAII(Actions), ParseStatement()); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 1944 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 1945 | } else if (DKind == OMPD_target_update || DKind == OMPD_target_enter_data || |
| 1946 | DKind == OMPD_target_exit_data) { |
Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 1947 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Richard Smith | 6eb9b9e | 2018-02-03 00:44:57 +0000 | [diff] [blame] | 1948 | AssociatedStmt = (Sema::CompoundScopeRAII(Actions), |
| 1949 | Actions.ActOnCompoundStmt(Loc, Loc, llvm::None, |
| 1950 | /*isStmtExpr=*/false)); |
Alexey Bataev | 7828b25 | 2017-11-21 17:08:48 +0000 | [diff] [blame] | 1951 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1952 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1953 | Directive = Actions.ActOnOpenMPExecutableDirective( |
| 1954 | DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc, |
| 1955 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1956 | |
| 1957 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 1958 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1959 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1960 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 1961 | } |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1962 | case OMPD_declare_simd: |
Dmitry Polukhin | 0b0da29 | 2016-04-06 11:38:59 +0000 | [diff] [blame] | 1963 | case OMPD_declare_target: |
| 1964 | case OMPD_end_declare_target: |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 1965 | case OMPD_requires: |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 1966 | case OMPD_declare_variant: |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1967 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | 96dae81 | 2018-02-16 18:36:44 +0000 | [diff] [blame] | 1968 | << 1 << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 587e1de | 2016-03-30 10:43:55 +0000 | [diff] [blame] | 1969 | SkipUntil(tok::annot_pragma_openmp_end); |
| 1970 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1971 | case OMPD_unknown: |
| 1972 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1973 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1974 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1975 | } |
| 1976 | return Directive; |
| 1977 | } |
| 1978 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 1979 | // Parses simple list: |
| 1980 | // simple-variable-list: |
| 1981 | // '(' id-expression {, id-expression} ')' |
| 1982 | // |
| 1983 | bool Parser::ParseOpenMPSimpleVarList( |
| 1984 | OpenMPDirectiveKind Kind, |
| 1985 | const llvm::function_ref<void(CXXScopeSpec &, DeclarationNameInfo)> & |
| 1986 | Callback, |
| 1987 | bool AllowScopeSpecifier) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1988 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1989 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1990 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 1991 | getOpenMPDirectiveName(Kind).data())) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1992 | return true; |
| 1993 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1994 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1995 | |
| 1996 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 1997 | 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] | 1998 | CXXScopeSpec SS; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1999 | UnqualifiedId Name; |
| 2000 | // Read var name. |
| 2001 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2002 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2003 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2004 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 2005 | ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) { |
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); |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 2009 | } else if (ParseUnqualifiedId(SS, false, false, false, false, nullptr, |
Richard Smith | c08b693 | 2018-04-27 02:00:13 +0000 | [diff] [blame] | 2010 | nullptr, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 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); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2014 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 2015 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 2016 | IsCorrect = false; |
| 2017 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2018 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2019 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 2020 | << tok::identifier |
| 2021 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2022 | } else { |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 2023 | Callback(SS, Actions.GetNameFromUnqualifiedId(Name)); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2024 | } |
| 2025 | // Consume ','. |
| 2026 | if (Tok.is(tok::comma)) { |
| 2027 | ConsumeToken(); |
| 2028 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2029 | } |
| 2030 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2031 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 2032 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2033 | IsCorrect = false; |
| 2034 | } |
| 2035 | |
| 2036 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2037 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2038 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 2039 | return !IsCorrect; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2040 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2041 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2042 | /// Parsing of OpenMP clauses. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2043 | /// |
| 2044 | /// clause: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2045 | /// if-clause | final-clause | num_threads-clause | safelen-clause | |
| 2046 | /// default-clause | private-clause | firstprivate-clause | shared-clause |
| 2047 | /// | linear-clause | aligned-clause | collapse-clause | |
| 2048 | /// lastprivate-clause | reduction-clause | proc_bind-clause | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 2049 | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 2050 | /// mergeable-clause | flush-clause | read-clause | write-clause | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2051 | /// update-clause | capture-clause | seq_cst-clause | device-clause | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 2052 | /// simdlen-clause | threads-clause | simd-clause | num_teams-clause | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2053 | /// thread_limit-clause | priority-clause | grainsize-clause | |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 2054 | /// nogroup-clause | num_tasks-clause | hint-clause | to-clause | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2055 | /// from-clause | is_device_ptr-clause | task_reduction-clause | |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2056 | /// in_reduction-clause | allocator-clause | allocate-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2057 | /// |
| 2058 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 2059 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2060 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2061 | bool ErrorFound = false; |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2062 | bool WrongDirective = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2063 | // Check if clause is allowed for the given directive. |
Alexey Bataev | d08c056 | 2019-11-19 12:07:54 -0500 | [diff] [blame] | 2064 | if (CKind != OMPC_unknown && |
| 2065 | !isAllowedClauseForDirective(DKind, CKind, getLangOpts().OpenMP)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 2066 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 2067 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2068 | ErrorFound = true; |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2069 | WrongDirective = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
| 2072 | switch (CKind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2073 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 2074 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 2075 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2076 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2077 | case OMPC_collapse: |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2078 | case OMPC_ordered: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 2079 | case OMPC_device: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 2080 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 2081 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2082 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2083 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 2084 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2085 | case OMPC_hint: |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2086 | case OMPC_allocator: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2087 | // OpenMP [2.5, Restrictions] |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 2088 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 2089 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2090 | // Only one safelen clause can appear on a simd directive. |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2091 | // Only one simdlen clause can appear on a simd directive. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2092 | // Only one collapse clause can appear on a simd directive. |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 2093 | // OpenMP [2.9.1, target data construct, Restrictions] |
| 2094 | // At most one device clause can appear on the directive. |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2095 | // OpenMP [2.11.1, task Construct, Restrictions] |
| 2096 | // At most one if clause can appear on the directive. |
| 2097 | // At most one final clause can appear on the directive. |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 2098 | // OpenMP [teams Construct, Restrictions] |
| 2099 | // At most one num_teams clause can appear on the directive. |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 2100 | // At most one thread_limit clause can appear on the directive. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2101 | // OpenMP [2.9.1, task Construct, Restrictions] |
| 2102 | // At most one priority clause can appear on the directive. |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2103 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 2104 | // At most one grainsize clause can appear on the directive. |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 2105 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 2106 | // At most one num_tasks clause can appear on the directive. |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2107 | // OpenMP [2.11.3, allocate Directive, Restrictions] |
| 2108 | // At most one allocator clause can appear on the directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2109 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2110 | Diag(Tok, diag::err_omp_more_one_clause) |
| 2111 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2112 | ErrorFound = true; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2115 | if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren)) |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2116 | Clause = ParseOpenMPClause(CKind, WrongDirective); |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 2117 | else |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2118 | Clause = ParseOpenMPSingleExprClause(CKind, WrongDirective); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2119 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2120 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2121 | case OMPC_proc_bind: |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 2122 | case OMPC_atomic_default_mem_order: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2123 | // OpenMP [2.14.3.1, Restrictions] |
| 2124 | // Only a single default clause may be specified on a parallel, task or |
| 2125 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2126 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 2127 | // At most one proc_bind clause can appear on the directive. |
Patrick Lyster | 7a2a27c | 2018-11-02 12:18:11 +0000 | [diff] [blame] | 2128 | // OpenMP [5.0, Requires directive, Restrictions] |
| 2129 | // At most one atomic_default_mem_order clause can appear |
| 2130 | // on the directive |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2131 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2132 | Diag(Tok, diag::err_omp_more_one_clause) |
| 2133 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2134 | ErrorFound = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2135 | } |
| 2136 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2137 | Clause = ParseOpenMPSimpleClause(CKind, WrongDirective); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2138 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2139 | case OMPC_schedule: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2140 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2141 | case OMPC_defaultmap: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2142 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 2143 | // Only one schedule clause can appear on a loop directive. |
cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2144 | // OpenMP 4.5 [2.10.4, Restrictions, p. 106] |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2145 | // At most one defaultmap clause can appear on the directive. |
cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2146 | if ((getLangOpts().OpenMP < 50 || CKind != OMPC_defaultmap) && |
| 2147 | !FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2148 | Diag(Tok, diag::err_omp_more_one_clause) |
| 2149 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2150 | ErrorFound = true; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2151 | } |
Galina Kistanova | 474f2ce | 2017-06-01 21:26:38 +0000 | [diff] [blame] | 2152 | LLVM_FALLTHROUGH; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2153 | case OMPC_if: |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2154 | Clause = ParseOpenMPSingleExprWithArgClause(CKind, WrongDirective); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2155 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2156 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 2157 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 2158 | case OMPC_mergeable: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 2159 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2160 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 2161 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 2162 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 2163 | case OMPC_seq_cst: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2164 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2165 | case OMPC_simd: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 2166 | case OMPC_nogroup: |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2167 | case OMPC_unified_address: |
Patrick Lyster | 4a370b9 | 2018-10-01 13:47:43 +0000 | [diff] [blame] | 2168 | case OMPC_unified_shared_memory: |
Patrick Lyster | 6bdf63b | 2018-10-03 20:07:58 +0000 | [diff] [blame] | 2169 | case OMPC_reverse_offload: |
Patrick Lyster | 3fe9e39 | 2018-10-11 14:41:10 +0000 | [diff] [blame] | 2170 | case OMPC_dynamic_allocators: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2171 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 2172 | // Only one ordered clause can appear on a loop directive. |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2173 | // OpenMP [2.7.1, Restrictions, C/C++, p. 4] |
| 2174 | // Only one nowait clause can appear on a for directive. |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2175 | // OpenMP [5.0, Requires directive, Restrictions] |
| 2176 | // 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] | 2177 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2178 | Diag(Tok, diag::err_omp_more_one_clause) |
| 2179 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 2180 | ErrorFound = true; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2181 | } |
| 2182 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2183 | Clause = ParseOpenMPClause(CKind, WrongDirective); |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2184 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2185 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2186 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2187 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2188 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2189 | case OMPC_reduction: |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 2190 | case OMPC_task_reduction: |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2191 | case OMPC_in_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2192 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 2193 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 2194 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 2195 | case OMPC_copyprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2196 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2197 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2198 | case OMPC_map: |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 2199 | case OMPC_to: |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 2200 | case OMPC_from: |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 2201 | case OMPC_use_device_ptr: |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 2202 | case OMPC_is_device_ptr: |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2203 | case OMPC_allocate: |
Alexey Bataev | b6e7084 | 2019-12-16 15:54:17 -0500 | [diff] [blame] | 2204 | case OMPC_nontemporal: |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2205 | Clause = ParseOpenMPVarListClause(DKind, CKind, WrongDirective); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2206 | break; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2207 | case OMPC_device_type: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2208 | case OMPC_unknown: |
| 2209 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 2210 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2211 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2212 | break; |
| 2213 | case OMPC_threadprivate: |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2214 | case OMPC_uniform: |
Alexey Bataev | dba792c | 2019-09-23 18:13:31 +0000 | [diff] [blame] | 2215 | case OMPC_match: |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2216 | if (!WrongDirective) |
| 2217 | Diag(Tok, diag::err_omp_unexpected_clause) |
| 2218 | << getOpenMPClauseName(CKind) << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 2219 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2220 | break; |
| 2221 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2222 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2225 | /// Parses simple expression in parens for single-expression clauses of OpenMP |
| 2226 | /// constructs. |
| 2227 | /// \param RLoc Returned location of right paren. |
| 2228 | ExprResult Parser::ParseOpenMPParensExpr(StringRef ClauseName, |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 2229 | SourceLocation &RLoc, |
| 2230 | bool IsAddressOfOperand) { |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2231 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 2232 | if (T.expectAndConsume(diag::err_expected_lparen_after, ClauseName.data())) |
| 2233 | return ExprError(); |
| 2234 | |
| 2235 | SourceLocation ELoc = Tok.getLocation(); |
| 2236 | ExprResult LHS(ParseCastExpression( |
Alexey Bataev | d158cf6 | 2019-09-13 20:18:17 +0000 | [diff] [blame] | 2237 | /*isUnaryExpression=*/false, IsAddressOfOperand, NotTypeCast)); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2238 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 2239 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc, /*DiscardedValue*/ false); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2240 | |
| 2241 | // Parse ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2242 | RLoc = Tok.getLocation(); |
| 2243 | if (!T.consumeClose()) |
| 2244 | RLoc = T.getCloseLocation(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2245 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2246 | return Val; |
| 2247 | } |
| 2248 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2249 | /// Parsing of OpenMP clauses with single expressions like 'final', |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2250 | /// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams', |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2251 | /// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2252 | /// |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 2253 | /// final-clause: |
| 2254 | /// 'final' '(' expression ')' |
| 2255 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 2256 | /// num_threads-clause: |
| 2257 | /// 'num_threads' '(' expression ')' |
| 2258 | /// |
| 2259 | /// safelen-clause: |
| 2260 | /// 'safelen' '(' expression ')' |
| 2261 | /// |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 2262 | /// simdlen-clause: |
| 2263 | /// 'simdlen' '(' expression ')' |
| 2264 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 2265 | /// collapse-clause: |
| 2266 | /// 'collapse' '(' expression ')' |
| 2267 | /// |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 2268 | /// priority-clause: |
| 2269 | /// 'priority' '(' expression ')' |
| 2270 | /// |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 2271 | /// grainsize-clause: |
| 2272 | /// 'grainsize' '(' expression ')' |
| 2273 | /// |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 2274 | /// num_tasks-clause: |
| 2275 | /// 'num_tasks' '(' expression ')' |
| 2276 | /// |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 2277 | /// hint-clause: |
| 2278 | /// 'hint' '(' expression ')' |
| 2279 | /// |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2280 | /// allocator-clause: |
| 2281 | /// 'allocator' '(' expression ')' |
| 2282 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2283 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind, |
| 2284 | bool ParseOnly) { |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2285 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2286 | SourceLocation LLoc = Tok.getLocation(); |
| 2287 | SourceLocation RLoc; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2288 | |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2289 | ExprResult Val = ParseOpenMPParensExpr(getOpenMPClauseName(Kind), RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2290 | |
| 2291 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2292 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2293 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2294 | if (ParseOnly) |
| 2295 | return nullptr; |
Alexey Bataev | 2af33e3 | 2016-04-07 12:45:37 +0000 | [diff] [blame] | 2296 | return Actions.ActOnOpenMPSingleExprClause(Kind, Val.get(), Loc, LLoc, RLoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 2297 | } |
| 2298 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2299 | /// Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2300 | /// |
| 2301 | /// default-clause: |
| 2302 | /// 'default' '(' 'none' | 'shared' ') |
| 2303 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 2304 | /// proc_bind-clause: |
| 2305 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 2306 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2307 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind, |
| 2308 | bool ParseOnly) { |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2309 | llvm::Optional<SimpleClauseData> Val = parseOpenMPSimpleClause(*this, Kind); |
| 2310 | if (!Val || ParseOnly) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2311 | return nullptr; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 2312 | return Actions.ActOnOpenMPSimpleClause( |
| 2313 | Kind, Val.getValue().Type, Val.getValue().TypeLoc, Val.getValue().LOpen, |
| 2314 | Val.getValue().Loc, Val.getValue().RLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2317 | /// Parsing of OpenMP clauses like 'ordered'. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2318 | /// |
| 2319 | /// ordered-clause: |
| 2320 | /// 'ordered' |
| 2321 | /// |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 2322 | /// nowait-clause: |
| 2323 | /// 'nowait' |
| 2324 | /// |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 2325 | /// untied-clause: |
| 2326 | /// 'untied' |
| 2327 | /// |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 2328 | /// mergeable-clause: |
| 2329 | /// 'mergeable' |
| 2330 | /// |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 2331 | /// read-clause: |
| 2332 | /// 'read' |
| 2333 | /// |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 2334 | /// threads-clause: |
| 2335 | /// 'threads' |
| 2336 | /// |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 2337 | /// simd-clause: |
| 2338 | /// 'simd' |
| 2339 | /// |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 2340 | /// nogroup-clause: |
| 2341 | /// 'nogroup' |
| 2342 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2343 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind, bool ParseOnly) { |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2344 | SourceLocation Loc = Tok.getLocation(); |
| 2345 | ConsumeAnyToken(); |
| 2346 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2347 | if (ParseOnly) |
| 2348 | return nullptr; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 2349 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 2350 | } |
| 2351 | |
| 2352 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2353 | /// Parsing of OpenMP clauses with single expressions and some additional |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2354 | /// argument like 'schedule' or 'dist_schedule'. |
| 2355 | /// |
| 2356 | /// schedule-clause: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2357 | /// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ] |
| 2358 | /// ')' |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2359 | /// |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2360 | /// if-clause: |
| 2361 | /// 'if' '(' [ directive-name-modifier ':' ] expression ')' |
| 2362 | /// |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2363 | /// defaultmap: |
| 2364 | /// 'defaultmap' '(' modifier ':' kind ')' |
| 2365 | /// |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2366 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind, |
| 2367 | bool ParseOnly) { |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2368 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2369 | SourceLocation DelimLoc; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2370 | // Parse '('. |
| 2371 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 2372 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 2373 | getOpenMPClauseName(Kind))) |
| 2374 | return nullptr; |
| 2375 | |
| 2376 | ExprResult Val; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2377 | SmallVector<unsigned, 4> Arg; |
| 2378 | SmallVector<SourceLocation, 4> KLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2379 | if (Kind == OMPC_schedule) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2380 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 2381 | Arg.resize(NumberOfElements); |
| 2382 | KLoc.resize(NumberOfElements); |
| 2383 | Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 2384 | Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 2385 | Arg[ScheduleKind] = OMPC_SCHEDULE_unknown; |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2386 | unsigned KindModifier = getOpenMPSimpleClauseType( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2387 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2388 | if (KindModifier > OMPC_SCHEDULE_unknown) { |
| 2389 | // Parse 'modifier' |
| 2390 | Arg[Modifier1] = KindModifier; |
| 2391 | KLoc[Modifier1] = Tok.getLocation(); |
| 2392 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2393 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2394 | ConsumeAnyToken(); |
| 2395 | if (Tok.is(tok::comma)) { |
| 2396 | // Parse ',' 'modifier' |
| 2397 | ConsumeAnyToken(); |
| 2398 | KindModifier = getOpenMPSimpleClauseType( |
| 2399 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 2400 | Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown |
| 2401 | ? KindModifier |
Aaron Ballman | ad8a104 | 2015-12-28 15:52:46 +0000 | [diff] [blame] | 2402 | : (unsigned)OMPC_SCHEDULE_unknown; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2403 | KLoc[Modifier2] = Tok.getLocation(); |
| 2404 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2405 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2406 | ConsumeAnyToken(); |
| 2407 | } |
| 2408 | // Parse ':' |
| 2409 | if (Tok.is(tok::colon)) |
| 2410 | ConsumeAnyToken(); |
| 2411 | else |
| 2412 | Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier"; |
| 2413 | KindModifier = getOpenMPSimpleClauseType( |
| 2414 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 2415 | } |
| 2416 | Arg[ScheduleKind] = KindModifier; |
| 2417 | KLoc[ScheduleKind] = Tok.getLocation(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2418 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2419 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2420 | ConsumeAnyToken(); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2421 | if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static || |
| 2422 | Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic || |
| 2423 | Arg[ScheduleKind] == OMPC_SCHEDULE_guided) && |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2424 | Tok.is(tok::comma)) |
| 2425 | DelimLoc = ConsumeAnyToken(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2426 | } else if (Kind == OMPC_dist_schedule) { |
| 2427 | Arg.push_back(getOpenMPSimpleClauseType( |
| 2428 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 2429 | KLoc.push_back(Tok.getLocation()); |
| 2430 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2431 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2432 | ConsumeAnyToken(); |
| 2433 | if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma)) |
| 2434 | DelimLoc = ConsumeAnyToken(); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2435 | } else if (Kind == OMPC_defaultmap) { |
| 2436 | // Get a defaultmap modifier |
cchen | e06f3e0 | 2019-11-15 13:02:06 -0500 | [diff] [blame] | 2437 | unsigned Modifier = getOpenMPSimpleClauseType( |
| 2438 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 2439 | // Set defaultmap modifier to unknown if it is either scalar, aggregate, or |
| 2440 | // pointer |
| 2441 | if (Modifier < OMPC_DEFAULTMAP_MODIFIER_unknown) |
| 2442 | Modifier = OMPC_DEFAULTMAP_MODIFIER_unknown; |
| 2443 | Arg.push_back(Modifier); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 2444 | KLoc.push_back(Tok.getLocation()); |
| 2445 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2446 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2447 | ConsumeAnyToken(); |
| 2448 | // Parse ':' |
| 2449 | if (Tok.is(tok::colon)) |
| 2450 | ConsumeAnyToken(); |
| 2451 | else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown) |
| 2452 | Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier"; |
| 2453 | // Get a defaultmap kind |
| 2454 | Arg.push_back(getOpenMPSimpleClauseType( |
| 2455 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 2456 | KLoc.push_back(Tok.getLocation()); |
| 2457 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 2458 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 2459 | ConsumeAnyToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2460 | } else { |
| 2461 | assert(Kind == OMPC_if); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 2462 | KLoc.push_back(Tok.getLocation()); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2463 | TentativeParsingAction TPA(*this); |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 2464 | auto DK = parseOpenMPDirectiveKind(*this); |
| 2465 | Arg.push_back(DK); |
| 2466 | if (DK != OMPD_unknown) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2467 | ConsumeToken(); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2468 | if (Tok.is(tok::colon) && getLangOpts().OpenMP > 40) { |
| 2469 | TPA.Commit(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2470 | DelimLoc = ConsumeToken(); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2471 | } else { |
| 2472 | TPA.Revert(); |
Johannes Doerfert | eb3e81f | 2019-11-04 22:00:49 -0600 | [diff] [blame] | 2473 | Arg.back() = unsigned(OMPD_unknown); |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2474 | } |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2475 | } else { |
Alexey Bataev | 2a6de8c | 2016-12-20 12:10:05 +0000 | [diff] [blame] | 2476 | TPA.Revert(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2477 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2478 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2479 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 2480 | bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) || |
| 2481 | (Kind == OMPC_dist_schedule && DelimLoc.isValid()) || |
| 2482 | Kind == OMPC_if; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2483 | if (NeedAnExpression) { |
| 2484 | SourceLocation ELoc = Tok.getLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2485 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 2486 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 2487 | Val = |
| 2488 | Actions.ActOnFinishFullExpr(Val.get(), ELoc, /*DiscardedValue*/ false); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | // Parse ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2492 | SourceLocation RLoc = Tok.getLocation(); |
| 2493 | if (!T.consumeClose()) |
| 2494 | RLoc = T.getCloseLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2495 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 2496 | if (NeedAnExpression && Val.isInvalid()) |
| 2497 | return nullptr; |
| 2498 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2499 | if (ParseOnly) |
| 2500 | return nullptr; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2501 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2502 | Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, RLoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 2503 | } |
| 2504 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2505 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 2506 | UnqualifiedId &ReductionId) { |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2507 | if (ReductionIdScopeSpec.isEmpty()) { |
| 2508 | auto OOK = OO_None; |
| 2509 | switch (P.getCurToken().getKind()) { |
| 2510 | case tok::plus: |
| 2511 | OOK = OO_Plus; |
| 2512 | break; |
| 2513 | case tok::minus: |
| 2514 | OOK = OO_Minus; |
| 2515 | break; |
| 2516 | case tok::star: |
| 2517 | OOK = OO_Star; |
| 2518 | break; |
| 2519 | case tok::amp: |
| 2520 | OOK = OO_Amp; |
| 2521 | break; |
| 2522 | case tok::pipe: |
| 2523 | OOK = OO_Pipe; |
| 2524 | break; |
| 2525 | case tok::caret: |
| 2526 | OOK = OO_Caret; |
| 2527 | break; |
| 2528 | case tok::ampamp: |
| 2529 | OOK = OO_AmpAmp; |
| 2530 | break; |
| 2531 | case tok::pipepipe: |
| 2532 | OOK = OO_PipePipe; |
| 2533 | break; |
| 2534 | default: |
| 2535 | break; |
| 2536 | } |
| 2537 | if (OOK != OO_None) { |
| 2538 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 2539 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2540 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 2541 | return false; |
| 2542 | } |
| 2543 | } |
| 2544 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 2545 | /*AllowDestructorName*/ false, |
Richard Smith | 3584515 | 2017-02-07 01:37:30 +0000 | [diff] [blame] | 2546 | /*AllowConstructorName*/ false, |
| 2547 | /*AllowDeductionGuide*/ false, |
Richard Smith | c08b693 | 2018-04-27 02:00:13 +0000 | [diff] [blame] | 2548 | nullptr, nullptr, ReductionId); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2549 | } |
| 2550 | |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2551 | /// Checks if the token is a valid map-type-modifier. |
| 2552 | static OpenMPMapModifierKind isMapModifier(Parser &P) { |
| 2553 | Token Tok = P.getCurToken(); |
| 2554 | if (!Tok.is(tok::identifier)) |
| 2555 | return OMPC_MAP_MODIFIER_unknown; |
| 2556 | |
| 2557 | Preprocessor &PP = P.getPreprocessor(); |
| 2558 | OpenMPMapModifierKind TypeModifier = static_cast<OpenMPMapModifierKind>( |
| 2559 | getOpenMPSimpleClauseType(OMPC_map, PP.getSpelling(Tok))); |
| 2560 | return TypeModifier; |
| 2561 | } |
| 2562 | |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2563 | /// Parse the mapper modifier in map, to, and from clauses. |
| 2564 | bool Parser::parseMapperModifier(OpenMPVarListDataTy &Data) { |
| 2565 | // Parse '('. |
| 2566 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::colon); |
| 2567 | if (T.expectAndConsume(diag::err_expected_lparen_after, "mapper")) { |
| 2568 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2569 | StopBeforeMatch); |
| 2570 | return true; |
| 2571 | } |
| 2572 | // Parse mapper-identifier |
| 2573 | if (getLangOpts().CPlusPlus) |
| 2574 | ParseOptionalCXXScopeSpecifier(Data.ReductionOrMapperIdScopeSpec, |
| 2575 | /*ObjectType=*/nullptr, |
| 2576 | /*EnteringContext=*/false); |
| 2577 | if (Tok.isNot(tok::identifier) && Tok.isNot(tok::kw_default)) { |
| 2578 | Diag(Tok.getLocation(), diag::err_omp_mapper_illegal_identifier); |
| 2579 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2580 | StopBeforeMatch); |
| 2581 | return true; |
| 2582 | } |
| 2583 | auto &DeclNames = Actions.getASTContext().DeclarationNames; |
| 2584 | Data.ReductionOrMapperId = DeclarationNameInfo( |
| 2585 | DeclNames.getIdentifier(Tok.getIdentifierInfo()), Tok.getLocation()); |
| 2586 | ConsumeToken(); |
| 2587 | // Parse ')'. |
| 2588 | return T.consumeClose(); |
| 2589 | } |
| 2590 | |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2591 | /// Parse map-type-modifiers in map clause. |
| 2592 | /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2593 | /// where, map-type-modifier ::= always | close | mapper(mapper-identifier) |
| 2594 | bool Parser::parseMapTypeModifiers(OpenMPVarListDataTy &Data) { |
| 2595 | while (getCurToken().isNot(tok::colon)) { |
| 2596 | OpenMPMapModifierKind TypeModifier = isMapModifier(*this); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2597 | if (TypeModifier == OMPC_MAP_MODIFIER_always || |
| 2598 | TypeModifier == OMPC_MAP_MODIFIER_close) { |
| 2599 | Data.MapTypeModifiers.push_back(TypeModifier); |
| 2600 | Data.MapTypeModifiersLoc.push_back(Tok.getLocation()); |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2601 | ConsumeToken(); |
| 2602 | } else if (TypeModifier == OMPC_MAP_MODIFIER_mapper) { |
| 2603 | Data.MapTypeModifiers.push_back(TypeModifier); |
| 2604 | Data.MapTypeModifiersLoc.push_back(Tok.getLocation()); |
| 2605 | ConsumeToken(); |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2606 | if (parseMapperModifier(Data)) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2607 | return true; |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2608 | } else { |
| 2609 | // For the case of unknown map-type-modifier or a map-type. |
| 2610 | // Map-type is followed by a colon; the function returns when it |
| 2611 | // encounters a token followed by a colon. |
| 2612 | if (Tok.is(tok::comma)) { |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2613 | Diag(Tok, diag::err_omp_map_type_modifier_missing); |
| 2614 | ConsumeToken(); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2615 | continue; |
| 2616 | } |
| 2617 | // Potential map-type token as it is followed by a colon. |
| 2618 | if (PP.LookAhead(0).is(tok::colon)) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2619 | return false; |
| 2620 | Diag(Tok, diag::err_omp_unknown_map_type_modifier); |
| 2621 | ConsumeToken(); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2622 | } |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2623 | if (getCurToken().is(tok::comma)) |
| 2624 | ConsumeToken(); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2625 | } |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2626 | return false; |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2627 | } |
| 2628 | |
| 2629 | /// Checks if the token is a valid map-type. |
| 2630 | static OpenMPMapClauseKind isMapType(Parser &P) { |
| 2631 | Token Tok = P.getCurToken(); |
| 2632 | // The map-type token can be either an identifier or the C++ delete keyword. |
| 2633 | if (!Tok.isOneOf(tok::identifier, tok::kw_delete)) |
| 2634 | return OMPC_MAP_unknown; |
| 2635 | Preprocessor &PP = P.getPreprocessor(); |
| 2636 | OpenMPMapClauseKind MapType = static_cast<OpenMPMapClauseKind>( |
| 2637 | getOpenMPSimpleClauseType(OMPC_map, PP.getSpelling(Tok))); |
| 2638 | return MapType; |
| 2639 | } |
| 2640 | |
| 2641 | /// Parse map-type in map clause. |
| 2642 | /// map([ [map-type-modifier[,] [map-type-modifier[,] ...] map-type : ] list) |
Ilya Biryukov | ff2a997 | 2019-02-26 11:01:50 +0000 | [diff] [blame] | 2643 | /// where, map-type ::= to | from | tofrom | alloc | release | delete |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2644 | static void parseMapType(Parser &P, Parser::OpenMPVarListDataTy &Data) { |
| 2645 | Token Tok = P.getCurToken(); |
| 2646 | if (Tok.is(tok::colon)) { |
| 2647 | P.Diag(Tok, diag::err_omp_map_type_missing); |
| 2648 | return; |
| 2649 | } |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2650 | Data.ExtraModifier = isMapType(P); |
| 2651 | if (Data.ExtraModifier == OMPC_MAP_unknown) |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2652 | P.Diag(Tok, diag::err_omp_unknown_map_type); |
| 2653 | P.ConsumeToken(); |
| 2654 | } |
| 2655 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2656 | /// Parses clauses with list. |
| 2657 | bool Parser::ParseOpenMPVarList(OpenMPDirectiveKind DKind, |
| 2658 | OpenMPClauseKind Kind, |
| 2659 | SmallVectorImpl<Expr *> &Vars, |
| 2660 | OpenMPVarListDataTy &Data) { |
| 2661 | UnqualifiedId UnqualifiedReductionId; |
| 2662 | bool InvalidReductionId = false; |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2663 | bool IsInvalidMapperModifier = false; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2664 | |
| 2665 | // Parse '('. |
| 2666 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 2667 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 2668 | getOpenMPClauseName(Kind))) |
| 2669 | return true; |
| 2670 | |
| 2671 | bool NeedRParenForLinear = false; |
| 2672 | BalancedDelimiterTracker LinearT(*this, tok::l_paren, |
| 2673 | tok::annot_pragma_openmp_end); |
| 2674 | // Handle reduction-identifier for reduction clause. |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2675 | if (Kind == OMPC_reduction || Kind == OMPC_task_reduction || |
| 2676 | Kind == OMPC_in_reduction) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2677 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2678 | if (getLangOpts().CPlusPlus) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2679 | ParseOptionalCXXScopeSpecifier(Data.ReductionOrMapperIdScopeSpec, |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2680 | /*ObjectType=*/nullptr, |
| 2681 | /*EnteringContext=*/false); |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2682 | InvalidReductionId = ParseReductionId( |
| 2683 | *this, Data.ReductionOrMapperIdScopeSpec, UnqualifiedReductionId); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2684 | if (InvalidReductionId) { |
| 2685 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2686 | StopBeforeMatch); |
| 2687 | } |
| 2688 | if (Tok.is(tok::colon)) |
| 2689 | Data.ColonLoc = ConsumeToken(); |
| 2690 | else |
| 2691 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 2692 | if (!InvalidReductionId) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2693 | Data.ReductionOrMapperId = |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2694 | Actions.GetNameFromUnqualifiedId(UnqualifiedReductionId); |
| 2695 | } else if (Kind == OMPC_depend) { |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2696 | // Handle dependency type for depend clause. |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2697 | ColonProtectionRAIIObject ColonRAII(*this); |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2698 | Data.ExtraModifier = getOpenMPSimpleClauseType( |
| 2699 | Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : ""); |
| 2700 | Data.DepLinMapLastLoc = Tok.getLocation(); |
| 2701 | if (Data.ExtraModifier == OMPC_DEPEND_unknown) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2702 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2703 | StopBeforeMatch); |
| 2704 | } else { |
| 2705 | ConsumeToken(); |
| 2706 | // Special processing for depend(source) clause. |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2707 | if (DKind == OMPD_ordered && Data.ExtraModifier == OMPC_DEPEND_source) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2708 | // Parse ')'. |
| 2709 | T.consumeClose(); |
| 2710 | return false; |
| 2711 | } |
| 2712 | } |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2713 | if (Tok.is(tok::colon)) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2714 | Data.ColonLoc = ConsumeToken(); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2715 | } else { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2716 | Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren |
| 2717 | : diag::warn_pragma_expected_colon) |
| 2718 | << "dependency type"; |
| 2719 | } |
| 2720 | } else if (Kind == OMPC_linear) { |
| 2721 | // Try to parse modifier if any. |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2722 | Data.ExtraModifier = OMPC_LINEAR_val; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2723 | if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) { |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2724 | Data.ExtraModifier = getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)); |
| 2725 | Data.DepLinMapLastLoc = ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2726 | LinearT.consumeOpen(); |
| 2727 | NeedRParenForLinear = true; |
| 2728 | } |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2729 | } else if (Kind == OMPC_lastprivate) { |
| 2730 | // Try to parse modifier if any. |
| 2731 | Data.ExtraModifier = OMPC_LASTPRIVATE_unknown; |
| 2732 | // Conditional modifier allowed only in OpenMP 5.0 and not supported in |
| 2733 | // distribute and taskloop based directives. |
| 2734 | if ((getLangOpts().OpenMP >= 50 && !isOpenMPDistributeDirective(DKind) && |
| 2735 | !isOpenMPTaskLoopDirective(DKind)) && |
| 2736 | Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::colon)) { |
| 2737 | Data.ExtraModifier = getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok)); |
| 2738 | Data.DepLinMapLastLoc = Tok.getLocation(); |
| 2739 | if (Data.ExtraModifier == OMPC_LASTPRIVATE_unknown) { |
| 2740 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2741 | StopBeforeMatch); |
| 2742 | } else { |
| 2743 | ConsumeToken(); |
| 2744 | } |
| 2745 | assert(Tok.is(tok::colon) && "Expected colon."); |
| 2746 | Data.ColonLoc = ConsumeToken(); |
| 2747 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2748 | } else if (Kind == OMPC_map) { |
| 2749 | // Handle map type for map clause. |
| 2750 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2751 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2752 | // 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] | 2753 | // 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] | 2754 | // spelling of the C++ delete keyword. |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2755 | Data.ExtraModifier = OMPC_MAP_unknown; |
| 2756 | Data.DepLinMapLastLoc = Tok.getLocation(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2757 | |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2758 | // Check for presence of a colon in the map clause. |
| 2759 | TentativeParsingAction TPA(*this); |
| 2760 | bool ColonPresent = false; |
| 2761 | if (SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2762 | StopBeforeMatch)) { |
| 2763 | if (Tok.is(tok::colon)) |
| 2764 | ColonPresent = true; |
| 2765 | } |
| 2766 | TPA.Revert(); |
| 2767 | // Only parse map-type-modifier[s] and map-type if a colon is present in |
| 2768 | // the map clause. |
| 2769 | if (ColonPresent) { |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2770 | IsInvalidMapperModifier = parseMapTypeModifiers(Data); |
| 2771 | if (!IsInvalidMapperModifier) |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2772 | parseMapType(*this, Data); |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2773 | else |
| 2774 | SkipUntil(tok::colon, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2775 | } |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2776 | if (Data.ExtraModifier == OMPC_MAP_unknown) { |
| 2777 | Data.ExtraModifier = OMPC_MAP_tofrom; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2778 | Data.IsMapTypeImplicit = true; |
| 2779 | } |
| 2780 | |
| 2781 | if (Tok.is(tok::colon)) |
| 2782 | Data.ColonLoc = ConsumeToken(); |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 2783 | } else if (Kind == OMPC_to || Kind == OMPC_from) { |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2784 | if (Tok.is(tok::identifier)) { |
| 2785 | bool IsMapperModifier = false; |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 2786 | if (Kind == OMPC_to) { |
| 2787 | auto Modifier = static_cast<OpenMPToModifierKind>( |
| 2788 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
| 2789 | if (Modifier == OMPC_TO_MODIFIER_mapper) |
| 2790 | IsMapperModifier = true; |
| 2791 | } else { |
| 2792 | auto Modifier = static_cast<OpenMPFromModifierKind>( |
| 2793 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
| 2794 | if (Modifier == OMPC_FROM_MODIFIER_mapper) |
| 2795 | IsMapperModifier = true; |
| 2796 | } |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2797 | if (IsMapperModifier) { |
| 2798 | // Parse the mapper modifier. |
| 2799 | ConsumeToken(); |
| 2800 | IsInvalidMapperModifier = parseMapperModifier(Data); |
| 2801 | if (Tok.isNot(tok::colon)) { |
| 2802 | if (!IsInvalidMapperModifier) |
| 2803 | Diag(Tok, diag::warn_pragma_expected_colon) << ")"; |
| 2804 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2805 | StopBeforeMatch); |
| 2806 | } |
| 2807 | // Consume ':'. |
| 2808 | if (Tok.is(tok::colon)) |
| 2809 | ConsumeToken(); |
| 2810 | } |
| 2811 | } |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2812 | } else if (Kind == OMPC_allocate) { |
| 2813 | // Handle optional allocator expression followed by colon delimiter. |
| 2814 | ColonProtectionRAIIObject ColonRAII(*this); |
| 2815 | TentativeParsingAction TPA(*this); |
| 2816 | ExprResult Tail = |
| 2817 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
| 2818 | Tail = Actions.ActOnFinishFullExpr(Tail.get(), T.getOpenLocation(), |
| 2819 | /*DiscardedValue=*/false); |
| 2820 | if (Tail.isUsable()) { |
| 2821 | if (Tok.is(tok::colon)) { |
| 2822 | Data.TailExpr = Tail.get(); |
| 2823 | Data.ColonLoc = ConsumeToken(); |
| 2824 | TPA.Commit(); |
| 2825 | } else { |
| 2826 | // colon not found, no allocator specified, parse only list of |
| 2827 | // variables. |
| 2828 | TPA.Revert(); |
| 2829 | } |
| 2830 | } else { |
| 2831 | // Parsing was unsuccessfull, revert and skip to the end of clause or |
| 2832 | // directive. |
| 2833 | TPA.Revert(); |
| 2834 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2835 | StopBeforeMatch); |
| 2836 | } |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2839 | bool IsComma = |
| 2840 | (Kind != OMPC_reduction && Kind != OMPC_task_reduction && |
| 2841 | Kind != OMPC_in_reduction && Kind != OMPC_depend && Kind != OMPC_map) || |
| 2842 | (Kind == OMPC_reduction && !InvalidReductionId) || |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2843 | (Kind == OMPC_map && Data.ExtraModifier != OMPC_MAP_unknown) || |
| 2844 | (Kind == OMPC_depend && Data.ExtraModifier != OMPC_DEPEND_unknown); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2845 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
| 2846 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
| 2847 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
| 2848 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
| 2849 | // Parse variable |
| 2850 | ExprResult VarExpr = |
| 2851 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2852 | if (VarExpr.isUsable()) { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2853 | Vars.push_back(VarExpr.get()); |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2854 | } else { |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2855 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2856 | StopBeforeMatch); |
| 2857 | } |
| 2858 | // Skip ',' if any |
| 2859 | IsComma = Tok.is(tok::comma); |
| 2860 | if (IsComma) |
| 2861 | ConsumeToken(); |
| 2862 | else if (Tok.isNot(tok::r_paren) && |
| 2863 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 2864 | (!MayHaveTail || Tok.isNot(tok::colon))) |
| 2865 | Diag(Tok, diag::err_omp_expected_punc) |
| 2866 | << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush) |
| 2867 | : getOpenMPClauseName(Kind)) |
| 2868 | << (Kind == OMPC_flush); |
| 2869 | } |
| 2870 | |
| 2871 | // Parse ')' for linear clause with modifier. |
| 2872 | if (NeedRParenForLinear) |
| 2873 | LinearT.consumeClose(); |
| 2874 | |
| 2875 | // Parse ':' linear-step (or ':' alignment). |
| 2876 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 2877 | if (MustHaveTail) { |
| 2878 | Data.ColonLoc = Tok.getLocation(); |
| 2879 | SourceLocation ELoc = ConsumeToken(); |
| 2880 | ExprResult Tail = ParseAssignmentExpression(); |
Aaron Ballman | fb6deeb | 2019-01-04 16:58:14 +0000 | [diff] [blame] | 2881 | Tail = |
| 2882 | Actions.ActOnFinishFullExpr(Tail.get(), ELoc, /*DiscardedValue*/ false); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2883 | if (Tail.isUsable()) |
| 2884 | Data.TailExpr = Tail.get(); |
| 2885 | else |
| 2886 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 2887 | StopBeforeMatch); |
| 2888 | } |
| 2889 | |
| 2890 | // Parse ')'. |
Alexey Bataev | dbc72c9 | 2018-07-06 19:35:42 +0000 | [diff] [blame] | 2891 | Data.RLoc = Tok.getLocation(); |
| 2892 | if (!T.consumeClose()) |
| 2893 | Data.RLoc = T.getCloseLocation(); |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2894 | return (Kind == OMPC_depend && Data.ExtraModifier != OMPC_DEPEND_unknown && |
Alexey Bataev | 61908f65 | 2018-04-23 19:53:05 +0000 | [diff] [blame] | 2895 | Vars.empty()) || |
| 2896 | (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) || |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2897 | (MustHaveTail && !Data.TailExpr) || InvalidReductionId || |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2898 | IsInvalidMapperModifier; |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2899 | } |
| 2900 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2901 | /// Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2902 | /// 'shared', 'copyin', 'copyprivate', 'flush', 'reduction', 'task_reduction' or |
| 2903 | /// 'in_reduction'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2904 | /// |
| 2905 | /// private-clause: |
| 2906 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 2907 | /// firstprivate-clause: |
| 2908 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 2909 | /// lastprivate-clause: |
| 2910 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 2911 | /// shared-clause: |
| 2912 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 2913 | /// linear-clause: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 2914 | /// 'linear' '(' linear-list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 2915 | /// aligned-clause: |
| 2916 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2917 | /// reduction-clause: |
| 2918 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 169d96a | 2017-07-18 20:17:46 +0000 | [diff] [blame] | 2919 | /// task_reduction-clause: |
| 2920 | /// 'task_reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | fa312f3 | 2017-07-21 18:48:21 +0000 | [diff] [blame] | 2921 | /// in_reduction-clause: |
| 2922 | /// 'in_reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 2923 | /// copyprivate-clause: |
| 2924 | /// 'copyprivate' '(' list ')' |
| 2925 | /// flush-clause: |
| 2926 | /// 'flush' '(' list ')' |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2927 | /// depend-clause: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 2928 | /// 'depend' '(' in | out | inout : list | source ')' |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2929 | /// map-clause: |
Kelvin Li | ef57943 | 2018-12-18 22:18:41 +0000 | [diff] [blame] | 2930 | /// 'map' '(' [ [ always [,] ] [ close [,] ] |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2931 | /// [ mapper '(' mapper-identifier ')' [,] ] |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 2932 | /// to | from | tofrom | alloc | release | delete ':' ] list ')'; |
Samuel Antao | 661c090 | 2016-05-26 17:39:58 +0000 | [diff] [blame] | 2933 | /// to-clause: |
Michael Kruse | 01f670d | 2019-02-22 22:29:42 +0000 | [diff] [blame] | 2934 | /// 'to' '(' [ mapper '(' mapper-identifier ')' ':' ] list ')' |
Samuel Antao | ec172c6 | 2016-05-26 17:49:04 +0000 | [diff] [blame] | 2935 | /// from-clause: |
Michael Kruse | 0336c75 | 2019-02-25 20:34:15 +0000 | [diff] [blame] | 2936 | /// 'from' '(' [ mapper '(' mapper-identifier ')' ':' ] list ')' |
Carlo Bertolli | 2404b17 | 2016-07-13 15:37:16 +0000 | [diff] [blame] | 2937 | /// use_device_ptr-clause: |
| 2938 | /// 'use_device_ptr' '(' list ')' |
Carlo Bertolli | 70594e9 | 2016-07-13 17:16:49 +0000 | [diff] [blame] | 2939 | /// is_device_ptr-clause: |
| 2940 | /// 'is_device_ptr' '(' list ')' |
Alexey Bataev | e04483e | 2019-03-27 14:14:31 +0000 | [diff] [blame] | 2941 | /// allocate-clause: |
| 2942 | /// 'allocate' '(' [ allocator ':' ] list ')' |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2943 | /// |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 2944 | /// For 'linear' clause linear-list may have the following forms: |
| 2945 | /// list |
| 2946 | /// modifier(list) |
| 2947 | /// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++). |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 2948 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2949 | OpenMPClauseKind Kind, |
| 2950 | bool ParseOnly) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2951 | SourceLocation Loc = Tok.getLocation(); |
| 2952 | SourceLocation LOpen = ConsumeToken(); |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2953 | SmallVector<Expr *, 4> Vars; |
| 2954 | OpenMPVarListDataTy Data; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 2955 | |
Alexey Bataev | e48a5fc | 2016-04-12 05:28:34 +0000 | [diff] [blame] | 2956 | if (ParseOpenMPVarList(DKind, Kind, Vars, Data)) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 2957 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2958 | |
Alexey Bataev | f3c832a | 2018-01-09 19:21:04 +0000 | [diff] [blame] | 2959 | if (ParseOnly) |
| 2960 | return nullptr; |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2961 | OMPVarListLocTy Locs(Loc, LOpen, Data.RLoc); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 2962 | return Actions.ActOnOpenMPVarListClause( |
Michael Kruse | 4304e9d | 2019-02-19 16:38:20 +0000 | [diff] [blame] | 2963 | Kind, Vars, Data.TailExpr, Locs, Data.ColonLoc, |
Alexey Bataev | 93dc40d | 2019-12-20 11:04:57 -0500 | [diff] [blame] | 2964 | Data.ReductionOrMapperIdScopeSpec, Data.ReductionOrMapperId, |
| 2965 | Data.ExtraModifier, Data.MapTypeModifiers, Data.MapTypeModifiersLoc, |
| 2966 | Data.IsMapTypeImplicit, Data.DepLinMapLastLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 2967 | } |
| 2968 | |