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