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