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