Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 1 | //===--- ParseOpenMP.cpp - OpenMP directives parsing ----------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | /// \file |
| 10 | /// \brief This file implements parsing of all OpenMP directives and clauses. |
| 11 | /// |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Chandler Carruth | 5553d0d | 2014-01-07 11:51:46 +0000 | [diff] [blame] | 14 | #include "RAIIObjectsForParser.h" |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 15 | #include "clang/AST/ASTConsumer.h" |
| 16 | #include "clang/AST/ASTContext.h" |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 17 | #include "clang/AST/StmtOpenMP.h" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 18 | #include "clang/Parse/ParseDiagnostic.h" |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 19 | #include "clang/Parse/Parser.h" |
| 20 | #include "clang/Sema/Scope.h" |
| 21 | #include "llvm/ADT/PointerIntPair.h" |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 22 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 23 | using namespace clang; |
| 24 | |
| 25 | //===----------------------------------------------------------------------===// |
| 26 | // OpenMP declarative directives. |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 29 | namespace { |
| 30 | enum OpenMPDirectiveKindEx { |
| 31 | OMPD_cancellation = OMPD_unknown + 1, |
| 32 | OMPD_data, |
| 33 | OMPD_enter, |
| 34 | OMPD_exit, |
| 35 | OMPD_point, |
| 36 | OMPD_target_enter, |
| 37 | OMPD_target_exit |
| 38 | }; |
| 39 | } // namespace |
| 40 | |
| 41 | // Map token string to extended OMP token kind that are |
| 42 | // OpenMPDirectiveKind + OpenMPDirectiveKindEx. |
| 43 | static unsigned getOpenMPDirectiveKindEx(StringRef S) { |
| 44 | auto DKind = getOpenMPDirectiveKind(S); |
| 45 | if (DKind != OMPD_unknown) |
| 46 | return DKind; |
| 47 | |
| 48 | return llvm::StringSwitch<unsigned>(S) |
| 49 | .Case("cancellation", OMPD_cancellation) |
| 50 | .Case("data", OMPD_data) |
| 51 | .Case("enter", OMPD_enter) |
| 52 | .Case("exit", OMPD_exit) |
| 53 | .Case("point", OMPD_point) |
| 54 | .Default(OMPD_unknown); |
| 55 | } |
| 56 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 57 | static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) { |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 58 | // Array of foldings: F[i][0] F[i][1] ===> F[i][2]. |
| 59 | // E.g.: OMPD_for OMPD_simd ===> OMPD_for_simd |
| 60 | // TODO: add other combined directives in topological order. |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 61 | static const unsigned F[][3] = { |
| 62 | { OMPD_cancellation, OMPD_point, OMPD_cancellation_point }, |
| 63 | { OMPD_target, OMPD_data, OMPD_target_data }, |
| 64 | { OMPD_target, OMPD_enter, OMPD_target_enter }, |
| 65 | { OMPD_target, OMPD_exit, OMPD_target_exit }, |
| 66 | { OMPD_target_enter, OMPD_data, OMPD_target_enter_data }, |
| 67 | { OMPD_target_exit, OMPD_data, OMPD_target_exit_data }, |
| 68 | { OMPD_for, OMPD_simd, OMPD_for_simd }, |
| 69 | { OMPD_parallel, OMPD_for, OMPD_parallel_for }, |
| 70 | { OMPD_parallel_for, OMPD_simd, OMPD_parallel_for_simd }, |
| 71 | { OMPD_parallel, OMPD_sections, OMPD_parallel_sections }, |
| 72 | { OMPD_taskloop, OMPD_simd, OMPD_taskloop_simd }, |
| 73 | { OMPD_target, OMPD_parallel, OMPD_target_parallel }, |
| 74 | { OMPD_target_parallel, OMPD_for, OMPD_target_parallel_for } |
| 75 | }; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 76 | auto Tok = P.getCurToken(); |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 77 | unsigned DKind = |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 78 | Tok.isAnnotation() |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 79 | ? static_cast<unsigned>(OMPD_unknown) |
| 80 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 81 | if (DKind == OMPD_unknown) |
| 82 | return OMPD_unknown; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 83 | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 84 | for (unsigned i = 0; i < llvm::array_lengthof(F); ++i) { |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 85 | if (DKind != F[i][0]) |
| 86 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 87 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 88 | Tok = P.getPreprocessor().LookAhead(0); |
| 89 | unsigned SDKind = |
| 90 | Tok.isAnnotation() |
| 91 | ? static_cast<unsigned>(OMPD_unknown) |
| 92 | : getOpenMPDirectiveKindEx(P.getPreprocessor().getSpelling(Tok)); |
| 93 | if (SDKind == OMPD_unknown) |
| 94 | continue; |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 95 | |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 96 | if (SDKind == F[i][1]) { |
| 97 | P.ConsumeToken(); |
| 98 | DKind = F[i][2]; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 99 | } |
| 100 | } |
Dmitry Polukhin | 8247833 | 2016-02-13 06:53:38 +0000 | [diff] [blame] | 101 | return DKind <= OMPD_unknown ? static_cast<OpenMPDirectiveKind>(DKind) |
| 102 | : OMPD_unknown; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 105 | /// \brief Parsing of declarative OpenMP directives. |
| 106 | /// |
| 107 | /// threadprivate-directive: |
| 108 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 109 | /// |
| 110 | Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { |
| 111 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 112 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 113 | |
| 114 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 115 | SmallVector<Expr *, 5> Identifiers; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 116 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 117 | |
| 118 | switch (DKind) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 119 | case OMPD_threadprivate: |
| 120 | ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 121 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 122 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 123 | // extra tokens. |
| 124 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 125 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 126 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 127 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 128 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 129 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 130 | ConsumeToken(); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 131 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 132 | } |
| 133 | break; |
| 134 | case OMPD_unknown: |
| 135 | Diag(Tok, diag::err_omp_unknown_directive); |
| 136 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 137 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 138 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 139 | case OMPD_task: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 140 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 141 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 142 | case OMPD_taskwait: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 143 | case OMPD_taskgroup: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 144 | case OMPD_flush: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 145 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 146 | case OMPD_for_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 147 | case OMPD_sections: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 148 | case OMPD_section: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 149 | case OMPD_single: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 150 | case OMPD_master: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 151 | case OMPD_ordered: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 152 | case OMPD_critical: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 153 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 154 | case OMPD_parallel_for_simd: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 155 | case OMPD_parallel_sections: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 156 | case OMPD_atomic: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 157 | case OMPD_target: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 158 | case OMPD_teams: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 159 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 160 | case OMPD_cancel: |
Samuel Antao | 5b0688e | 2015-07-22 16:02:46 +0000 | [diff] [blame] | 161 | case OMPD_target_data: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 162 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 163 | case OMPD_target_exit_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 164 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 165 | case OMPD_target_parallel_for: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 166 | case OMPD_taskloop: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 167 | case OMPD_taskloop_simd: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 168 | case OMPD_distribute: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 169 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 170 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 171 | break; |
| 172 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 173 | SkipUntil(tok::annot_pragma_openmp_end); |
David Blaikie | 0403cb1 | 2016-01-15 23:43:25 +0000 | [diff] [blame] | 174 | return nullptr; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 175 | } |
| 176 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 177 | /// \brief Parsing of declarative or executable OpenMP directives. |
| 178 | /// |
| 179 | /// threadprivate-directive: |
| 180 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 181 | /// annot_pragma_openmp_end |
| 182 | /// |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 183 | /// executable-directive: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 184 | /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 185 | /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] | |
| 186 | /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 187 | /// 'barrier' | 'taskwait' | 'flush' | 'ordered' | 'atomic' | |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 188 | /// 'for simd' | 'parallel for simd' | 'target' | 'target data' | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 189 | /// 'taskgroup' | 'teams' | 'taskloop' | 'taskloop simd' | |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 190 | /// 'distribute' | 'target enter data' | 'target exit data' | |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 191 | /// 'target parallel' | 'target parallel for' {clause} |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 192 | /// annot_pragma_openmp_end |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 193 | /// |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 194 | StmtResult Parser::ParseOpenMPDeclarativeOrExecutableDirective( |
| 195 | AllowedContsructsKind Allowed) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 196 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 197 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 198 | SmallVector<Expr *, 5> Identifiers; |
| 199 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 200 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 201 | FirstClauses(OMPC_unknown + 1); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 202 | unsigned ScopeFlags = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 203 | Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 204 | SourceLocation Loc = ConsumeToken(), EndLoc; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 205 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 206 | OpenMPDirectiveKind CancelRegion = OMPD_unknown; |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 207 | // Name of critical directive. |
| 208 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 209 | StmtResult Directive = StmtError(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 210 | bool HasAssociatedStatement = true; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 211 | bool FlushHasClause = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 212 | |
| 213 | switch (DKind) { |
| 214 | case OMPD_threadprivate: |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 215 | if (Allowed != ACK_Any) { |
| 216 | Diag(Tok, diag::err_omp_immediate_directive) |
| 217 | << getOpenMPDirectiveName(DKind) << 0; |
| 218 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 219 | ConsumeToken(); |
| 220 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) { |
| 221 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 222 | // extra tokens. |
| 223 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 224 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 225 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 226 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 227 | } |
| 228 | DeclGroupPtrTy Res = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 229 | Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 230 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 231 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 232 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 233 | break; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 234 | case OMPD_flush: |
| 235 | if (PP.LookAhead(0).is(tok::l_paren)) { |
| 236 | FlushHasClause = true; |
| 237 | // Push copy of the current token back to stream to properly parse |
| 238 | // pseudo-clause OMPFlushClause. |
| 239 | PP.EnterToken(Tok); |
| 240 | } |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 241 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 242 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 243 | case OMPD_taskwait: |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 244 | case OMPD_cancellation_point: |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 245 | case OMPD_cancel: |
Samuel Antao | df67fc4 | 2016-01-19 19:15:56 +0000 | [diff] [blame] | 246 | case OMPD_target_enter_data: |
Samuel Antao | 7259076 | 2016-01-19 20:04:50 +0000 | [diff] [blame] | 247 | case OMPD_target_exit_data: |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 248 | if (Allowed == ACK_StatementsOpenMPNonStandalone) { |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 249 | Diag(Tok, diag::err_omp_immediate_directive) |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 250 | << getOpenMPDirectiveName(DKind) << 0; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 251 | } |
| 252 | HasAssociatedStatement = false; |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 253 | // Fall through for further analysis. |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 254 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 255 | case OMPD_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 256 | case OMPD_for: |
Alexander Musman | f82886e | 2014-09-18 05:12:34 +0000 | [diff] [blame] | 257 | case OMPD_for_simd: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 258 | case OMPD_sections: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 259 | case OMPD_single: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 260 | case OMPD_section: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 261 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 262 | case OMPD_critical: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 263 | case OMPD_parallel_for: |
Alexander Musman | e4e893b | 2014-09-23 09:33:00 +0000 | [diff] [blame] | 264 | case OMPD_parallel_for_simd: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 265 | case OMPD_parallel_sections: |
Alexey Bataev | 9fb6e64 | 2014-07-22 06:45:04 +0000 | [diff] [blame] | 266 | case OMPD_task: |
Alexey Bataev | 0162e45 | 2014-07-22 10:10:35 +0000 | [diff] [blame] | 267 | case OMPD_ordered: |
Alexey Bataev | 0bd520b | 2014-09-19 08:19:49 +0000 | [diff] [blame] | 268 | case OMPD_atomic: |
Alexey Bataev | 13314bf | 2014-10-09 04:18:56 +0000 | [diff] [blame] | 269 | case OMPD_target: |
Alexey Bataev | c30dd2d | 2015-06-18 12:14:09 +0000 | [diff] [blame] | 270 | case OMPD_teams: |
Michael Wong | 65f367f | 2015-07-21 13:44:28 +0000 | [diff] [blame] | 271 | case OMPD_taskgroup: |
Alexey Bataev | 49f6e78 | 2015-12-01 04:18:41 +0000 | [diff] [blame] | 272 | case OMPD_target_data: |
Arpith Chacko Jacob | e955b3d | 2016-01-26 18:48:41 +0000 | [diff] [blame] | 273 | case OMPD_target_parallel: |
Arpith Chacko Jacob | 05bebb5 | 2016-02-03 15:46:42 +0000 | [diff] [blame] | 274 | case OMPD_target_parallel_for: |
Alexey Bataev | 0a6ed84 | 2015-12-03 09:40:15 +0000 | [diff] [blame] | 275 | case OMPD_taskloop: |
Carlo Bertolli | 6200a3d | 2015-12-14 14:51:25 +0000 | [diff] [blame] | 276 | case OMPD_taskloop_simd: |
| 277 | case OMPD_distribute: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 278 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 279 | // Parse directive name of the 'critical' directive if any. |
| 280 | if (DKind == OMPD_critical) { |
| 281 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 282 | tok::annot_pragma_openmp_end); |
| 283 | if (!T.consumeOpen()) { |
| 284 | if (Tok.isAnyIdentifier()) { |
| 285 | DirName = |
| 286 | DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 287 | ConsumeAnyToken(); |
| 288 | } else { |
| 289 | Diag(Tok, diag::err_omp_expected_identifier_for_critical); |
| 290 | } |
| 291 | T.consumeClose(); |
| 292 | } |
Alexey Bataev | 8090987 | 2015-07-02 11:25:17 +0000 | [diff] [blame] | 293 | } else if (DKind == OMPD_cancellation_point || DKind == OMPD_cancel) { |
Alexey Bataev | 6d4ed05 | 2015-07-01 06:57:41 +0000 | [diff] [blame] | 294 | CancelRegion = ParseOpenMPDirectiveKind(*this); |
| 295 | if (Tok.isNot(tok::annot_pragma_openmp_end)) |
| 296 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 297 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 298 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 299 | if (isOpenMPLoopDirective(DKind)) |
| 300 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 301 | if (isOpenMPSimdDirective(DKind)) |
| 302 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 303 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 304 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 305 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 306 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 307 | OpenMPClauseKind CKind = |
| 308 | Tok.isAnnotation() |
| 309 | ? OMPC_unknown |
| 310 | : FlushHasClause ? OMPC_flush |
| 311 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 312 | Actions.StartOpenMPClause(CKind); |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 313 | FlushHasClause = false; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 314 | OMPClause *Clause = |
| 315 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 316 | FirstClauses[CKind].setInt(true); |
| 317 | if (Clause) { |
| 318 | FirstClauses[CKind].setPointer(Clause); |
| 319 | Clauses.push_back(Clause); |
| 320 | } |
| 321 | |
| 322 | // Skip ',' if any. |
| 323 | if (Tok.is(tok::comma)) |
| 324 | ConsumeToken(); |
Alexey Bataev | aac108a | 2015-06-23 04:51:00 +0000 | [diff] [blame] | 325 | Actions.EndOpenMPClause(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 326 | } |
| 327 | // End location of the directive. |
| 328 | EndLoc = Tok.getLocation(); |
| 329 | // Consume final annot_pragma_openmp_end. |
| 330 | ConsumeToken(); |
| 331 | |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 332 | // OpenMP [2.13.8, ordered Construct, Syntax] |
| 333 | // If the depend clause is specified, the ordered construct is a stand-alone |
| 334 | // directive. |
| 335 | if (DKind == OMPD_ordered && FirstClauses[OMPC_depend].getInt()) { |
Alexey Bataev | c4fad65 | 2016-01-13 11:18:54 +0000 | [diff] [blame] | 336 | if (Allowed == ACK_StatementsOpenMPNonStandalone) { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 337 | Diag(Loc, diag::err_omp_immediate_directive) |
| 338 | << getOpenMPDirectiveName(DKind) << 1 |
| 339 | << getOpenMPClauseName(OMPC_depend); |
| 340 | } |
| 341 | HasAssociatedStatement = false; |
| 342 | } |
| 343 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 344 | StmtResult AssociatedStmt; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 345 | if (HasAssociatedStatement) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 346 | // The body is a block scope like in Lambdas and Blocks. |
| 347 | Sema::CompoundScopeRAII CompoundScope(Actions); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 348 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 349 | Actions.ActOnStartOfCompoundStmt(); |
| 350 | // Parse statement |
| 351 | AssociatedStmt = ParseStatement(); |
| 352 | Actions.ActOnFinishOfCompoundStmt(); |
Alexey Bataev | a8d4a543 | 2015-04-02 07:48:16 +0000 | [diff] [blame] | 353 | AssociatedStmt = Actions.ActOnOpenMPRegionEnd(AssociatedStmt, Clauses); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 354 | } |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 355 | Directive = Actions.ActOnOpenMPExecutableDirective( |
| 356 | DKind, DirName, CancelRegion, Clauses, AssociatedStmt.get(), Loc, |
| 357 | EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 358 | |
| 359 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 360 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 361 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 362 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 363 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 364 | case OMPD_unknown: |
| 365 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 366 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 367 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 368 | } |
| 369 | return Directive; |
| 370 | } |
| 371 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 372 | /// \brief Parses list of simple variables for '#pragma omp threadprivate' |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 373 | /// directive. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 374 | /// |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 375 | /// simple-variable-list: |
| 376 | /// '(' id-expression {, id-expression} ')' |
| 377 | /// |
| 378 | bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, |
| 379 | SmallVectorImpl<Expr *> &VarList, |
| 380 | bool AllowScopeSpecifier) { |
| 381 | VarList.clear(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 382 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 383 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 384 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 385 | getOpenMPDirectiveName(Kind))) |
| 386 | return true; |
| 387 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 388 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 389 | |
| 390 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 391 | 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] | 392 | CXXScopeSpec SS; |
| 393 | SourceLocation TemplateKWLoc; |
| 394 | UnqualifiedId Name; |
| 395 | // Read var name. |
| 396 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 397 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 398 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 399 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 400 | ParseOptionalCXXScopeSpecifier(SS, nullptr, false)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 401 | IsCorrect = false; |
| 402 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 403 | StopBeforeMatch); |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 404 | } else if (ParseUnqualifiedId(SS, false, false, false, nullptr, |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 405 | TemplateKWLoc, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 406 | IsCorrect = false; |
| 407 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 408 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 409 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 410 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 411 | IsCorrect = false; |
| 412 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 413 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 414 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 415 | << tok::identifier |
| 416 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 417 | } else { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 418 | DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 419 | ExprResult Res = |
| 420 | Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 421 | if (Res.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 422 | VarList.push_back(Res.get()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 423 | } |
| 424 | // Consume ','. |
| 425 | if (Tok.is(tok::comma)) { |
| 426 | ConsumeToken(); |
| 427 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 430 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 431 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 432 | IsCorrect = false; |
| 433 | } |
| 434 | |
| 435 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 436 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 437 | |
| 438 | return !IsCorrect && VarList.empty(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 439 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 440 | |
| 441 | /// \brief Parsing of OpenMP clauses. |
| 442 | /// |
| 443 | /// clause: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 444 | /// if-clause | final-clause | num_threads-clause | safelen-clause | |
| 445 | /// default-clause | private-clause | firstprivate-clause | shared-clause |
| 446 | /// | linear-clause | aligned-clause | collapse-clause | |
| 447 | /// lastprivate-clause | reduction-clause | proc_bind-clause | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 448 | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 449 | /// mergeable-clause | flush-clause | read-clause | write-clause | |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 450 | /// update-clause | capture-clause | seq_cst-clause | device-clause | |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 451 | /// simdlen-clause | threads-clause | simd-clause | num_teams-clause | |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 452 | /// thread_limit-clause | priority-clause | grainsize-clause | |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 453 | /// nogroup-clause | num_tasks-clause | hint-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 454 | /// |
| 455 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 456 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 457 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 458 | bool ErrorFound = false; |
| 459 | // Check if clause is allowed for the given directive. |
| 460 | if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 461 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 462 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 463 | ErrorFound = true; |
| 464 | } |
| 465 | |
| 466 | switch (CKind) { |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 467 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 468 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 469 | case OMPC_safelen: |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 470 | case OMPC_simdlen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 471 | case OMPC_collapse: |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 472 | case OMPC_ordered: |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 473 | case OMPC_device: |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 474 | case OMPC_num_teams: |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 475 | case OMPC_thread_limit: |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 476 | case OMPC_priority: |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 477 | case OMPC_grainsize: |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 478 | case OMPC_num_tasks: |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 479 | case OMPC_hint: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 480 | // OpenMP [2.5, Restrictions] |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 481 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 482 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 483 | // Only one safelen clause can appear on a simd directive. |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 484 | // Only one simdlen clause can appear on a simd directive. |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 485 | // Only one collapse clause can appear on a simd directive. |
Michael Wong | e710d54 | 2015-08-07 16:16:36 +0000 | [diff] [blame] | 486 | // OpenMP [2.9.1, target data construct, Restrictions] |
| 487 | // At most one device clause can appear on the directive. |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 488 | // OpenMP [2.11.1, task Construct, Restrictions] |
| 489 | // At most one if clause can appear on the directive. |
| 490 | // At most one final clause can appear on the directive. |
Kelvin Li | 099bb8c | 2015-11-24 20:50:12 +0000 | [diff] [blame] | 491 | // OpenMP [teams Construct, Restrictions] |
| 492 | // At most one num_teams clause can appear on the directive. |
Kelvin Li | a15fb1a | 2015-11-27 18:47:36 +0000 | [diff] [blame] | 493 | // At most one thread_limit clause can appear on the directive. |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 494 | // OpenMP [2.9.1, task Construct, Restrictions] |
| 495 | // At most one priority clause can appear on the directive. |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 496 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 497 | // At most one grainsize clause can appear on the directive. |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 498 | // OpenMP [2.9.2, taskloop Construct, Restrictions] |
| 499 | // At most one num_tasks clause can appear on the directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 500 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 501 | Diag(Tok, diag::err_omp_more_one_clause) |
| 502 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 503 | ErrorFound = true; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Alexey Bataev | 10e775f | 2015-07-30 11:36:16 +0000 | [diff] [blame] | 506 | if (CKind == OMPC_ordered && PP.LookAhead(/*N=*/0).isNot(tok::l_paren)) |
| 507 | Clause = ParseOpenMPClause(CKind); |
| 508 | else |
| 509 | Clause = ParseOpenMPSingleExprClause(CKind); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 510 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 511 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 512 | case OMPC_proc_bind: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 513 | // OpenMP [2.14.3.1, Restrictions] |
| 514 | // Only a single default clause may be specified on a parallel, task or |
| 515 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 516 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 517 | // At most one proc_bind clause can appear on the directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 518 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 519 | Diag(Tok, diag::err_omp_more_one_clause) |
| 520 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 521 | ErrorFound = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 522 | } |
| 523 | |
| 524 | Clause = ParseOpenMPSimpleClause(CKind); |
| 525 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 526 | case OMPC_schedule: |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 527 | case OMPC_dist_schedule: |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 528 | case OMPC_defaultmap: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 529 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 530 | // Only one schedule clause can appear on a loop directive. |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 531 | // OpenMP [2.10.4, Restrictions, p. 106] |
| 532 | // At most one defaultmap clause can appear on the directive. |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 533 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 534 | Diag(Tok, diag::err_omp_more_one_clause) |
| 535 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 536 | ErrorFound = true; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 539 | case OMPC_if: |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 540 | Clause = ParseOpenMPSingleExprWithArgClause(CKind); |
| 541 | break; |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 542 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 543 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 544 | case OMPC_mergeable: |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 545 | case OMPC_read: |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 546 | case OMPC_write: |
Alexey Bataev | 67a4f22 | 2014-07-23 10:25:33 +0000 | [diff] [blame] | 547 | case OMPC_update: |
Alexey Bataev | 459dec0 | 2014-07-24 06:46:57 +0000 | [diff] [blame] | 548 | case OMPC_capture: |
Alexey Bataev | 82bad8b | 2014-07-24 08:55:34 +0000 | [diff] [blame] | 549 | case OMPC_seq_cst: |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 550 | case OMPC_threads: |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 551 | case OMPC_simd: |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 552 | case OMPC_nogroup: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 553 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 554 | // Only one ordered clause can appear on a loop directive. |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 555 | // OpenMP [2.7.1, Restrictions, C/C++, p. 4] |
| 556 | // Only one nowait clause can appear on a for directive. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 557 | if (!FirstClause) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 558 | Diag(Tok, diag::err_omp_more_one_clause) |
| 559 | << getOpenMPDirectiveName(DKind) << getOpenMPClauseName(CKind) << 0; |
Alexey Bataev | dea4761 | 2014-07-23 07:46:59 +0000 | [diff] [blame] | 560 | ErrorFound = true; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | Clause = ParseOpenMPClause(CKind); |
| 564 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 565 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 566 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 567 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 568 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 569 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 570 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 571 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 572 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 573 | case OMPC_copyprivate: |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 574 | case OMPC_flush: |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 575 | case OMPC_depend: |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 576 | case OMPC_map: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 577 | Clause = ParseOpenMPVarListClause(DKind, CKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 578 | break; |
| 579 | case OMPC_unknown: |
| 580 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 581 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 582 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 583 | break; |
| 584 | case OMPC_threadprivate: |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 585 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 586 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 587 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 588 | break; |
| 589 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 590 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 591 | } |
| 592 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 593 | /// \brief Parsing of OpenMP clauses with single expressions like 'final', |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 594 | /// 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams', |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 595 | /// 'thread_limit', 'simdlen', 'priority', 'grainsize', 'num_tasks' or 'hint'. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 596 | /// |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 597 | /// final-clause: |
| 598 | /// 'final' '(' expression ')' |
| 599 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 600 | /// num_threads-clause: |
| 601 | /// 'num_threads' '(' expression ')' |
| 602 | /// |
| 603 | /// safelen-clause: |
| 604 | /// 'safelen' '(' expression ')' |
| 605 | /// |
Alexey Bataev | 66b15b5 | 2015-08-21 11:14:16 +0000 | [diff] [blame] | 606 | /// simdlen-clause: |
| 607 | /// 'simdlen' '(' expression ')' |
| 608 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 609 | /// collapse-clause: |
| 610 | /// 'collapse' '(' expression ')' |
| 611 | /// |
Alexey Bataev | a056935 | 2015-12-01 10:17:31 +0000 | [diff] [blame] | 612 | /// priority-clause: |
| 613 | /// 'priority' '(' expression ')' |
| 614 | /// |
Alexey Bataev | 1fd4aed | 2015-12-07 12:52:51 +0000 | [diff] [blame] | 615 | /// grainsize-clause: |
| 616 | /// 'grainsize' '(' expression ')' |
| 617 | /// |
Alexey Bataev | 382967a | 2015-12-08 12:06:20 +0000 | [diff] [blame] | 618 | /// num_tasks-clause: |
| 619 | /// 'num_tasks' '(' expression ')' |
| 620 | /// |
Alexey Bataev | 28c7541 | 2015-12-15 08:19:24 +0000 | [diff] [blame] | 621 | /// hint-clause: |
| 622 | /// 'hint' '(' expression ')' |
| 623 | /// |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 624 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { |
| 625 | SourceLocation Loc = ConsumeToken(); |
| 626 | |
| 627 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 628 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 629 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 630 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 631 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 632 | SourceLocation ELoc = Tok.getLocation(); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 633 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 634 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 635 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 636 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 637 | // Parse ')'. |
| 638 | T.consumeClose(); |
| 639 | |
| 640 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 641 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 642 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 643 | return Actions.ActOnOpenMPSingleExprClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 644 | Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation()); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 645 | } |
| 646 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 647 | /// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 648 | /// |
| 649 | /// default-clause: |
| 650 | /// 'default' '(' 'none' | 'shared' ') |
| 651 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 652 | /// proc_bind-clause: |
| 653 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 654 | /// |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 655 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) { |
| 656 | SourceLocation Loc = Tok.getLocation(); |
| 657 | SourceLocation LOpen = ConsumeToken(); |
| 658 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 659 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 660 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 661 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 662 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 663 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 664 | unsigned Type = getOpenMPSimpleClauseType( |
| 665 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 666 | SourceLocation TypeLoc = Tok.getLocation(); |
| 667 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 668 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 669 | ConsumeAnyToken(); |
| 670 | |
| 671 | // Parse ')'. |
| 672 | T.consumeClose(); |
| 673 | |
| 674 | return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, |
| 675 | Tok.getLocation()); |
| 676 | } |
| 677 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 678 | /// \brief Parsing of OpenMP clauses like 'ordered'. |
| 679 | /// |
| 680 | /// ordered-clause: |
| 681 | /// 'ordered' |
| 682 | /// |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 683 | /// nowait-clause: |
| 684 | /// 'nowait' |
| 685 | /// |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 686 | /// untied-clause: |
| 687 | /// 'untied' |
| 688 | /// |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 689 | /// mergeable-clause: |
| 690 | /// 'mergeable' |
| 691 | /// |
Alexey Bataev | f98b00c | 2014-07-23 02:27:21 +0000 | [diff] [blame] | 692 | /// read-clause: |
| 693 | /// 'read' |
| 694 | /// |
Alexey Bataev | 346265e | 2015-09-25 10:37:12 +0000 | [diff] [blame] | 695 | /// threads-clause: |
| 696 | /// 'threads' |
| 697 | /// |
Alexey Bataev | d14d1e6 | 2015-09-28 06:39:35 +0000 | [diff] [blame] | 698 | /// simd-clause: |
| 699 | /// 'simd' |
| 700 | /// |
Alexey Bataev | b825de1 | 2015-12-07 10:51:44 +0000 | [diff] [blame] | 701 | /// nogroup-clause: |
| 702 | /// 'nogroup' |
| 703 | /// |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 704 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) { |
| 705 | SourceLocation Loc = Tok.getLocation(); |
| 706 | ConsumeAnyToken(); |
| 707 | |
| 708 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 709 | } |
| 710 | |
| 711 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 712 | /// \brief Parsing of OpenMP clauses with single expressions and some additional |
| 713 | /// argument like 'schedule' or 'dist_schedule'. |
| 714 | /// |
| 715 | /// schedule-clause: |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 716 | /// 'schedule' '(' [ modifier [ ',' modifier ] ':' ] kind [',' expression ] |
| 717 | /// ')' |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 718 | /// |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 719 | /// if-clause: |
| 720 | /// 'if' '(' [ directive-name-modifier ':' ] expression ')' |
| 721 | /// |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 722 | /// defaultmap: |
| 723 | /// 'defaultmap' '(' modifier ':' kind ')' |
| 724 | /// |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 725 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) { |
| 726 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 727 | SourceLocation DelimLoc; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 728 | // Parse '('. |
| 729 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 730 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 731 | getOpenMPClauseName(Kind))) |
| 732 | return nullptr; |
| 733 | |
| 734 | ExprResult Val; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 735 | SmallVector<unsigned, 4> Arg; |
| 736 | SmallVector<SourceLocation, 4> KLoc; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 737 | if (Kind == OMPC_schedule) { |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 738 | enum { Modifier1, Modifier2, ScheduleKind, NumberOfElements }; |
| 739 | Arg.resize(NumberOfElements); |
| 740 | KLoc.resize(NumberOfElements); |
| 741 | Arg[Modifier1] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 742 | Arg[Modifier2] = OMPC_SCHEDULE_MODIFIER_unknown; |
| 743 | Arg[ScheduleKind] = OMPC_SCHEDULE_unknown; |
| 744 | auto KindModifier = getOpenMPSimpleClauseType( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 745 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 746 | if (KindModifier > OMPC_SCHEDULE_unknown) { |
| 747 | // Parse 'modifier' |
| 748 | Arg[Modifier1] = KindModifier; |
| 749 | KLoc[Modifier1] = Tok.getLocation(); |
| 750 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 751 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 752 | ConsumeAnyToken(); |
| 753 | if (Tok.is(tok::comma)) { |
| 754 | // Parse ',' 'modifier' |
| 755 | ConsumeAnyToken(); |
| 756 | KindModifier = getOpenMPSimpleClauseType( |
| 757 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 758 | Arg[Modifier2] = KindModifier > OMPC_SCHEDULE_unknown |
| 759 | ? KindModifier |
Aaron Ballman | ad8a104 | 2015-12-28 15:52:46 +0000 | [diff] [blame] | 760 | : (unsigned)OMPC_SCHEDULE_unknown; |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 761 | KLoc[Modifier2] = Tok.getLocation(); |
| 762 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 763 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 764 | ConsumeAnyToken(); |
| 765 | } |
| 766 | // Parse ':' |
| 767 | if (Tok.is(tok::colon)) |
| 768 | ConsumeAnyToken(); |
| 769 | else |
| 770 | Diag(Tok, diag::warn_pragma_expected_colon) << "schedule modifier"; |
| 771 | KindModifier = getOpenMPSimpleClauseType( |
| 772 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 773 | } |
| 774 | Arg[ScheduleKind] = KindModifier; |
| 775 | KLoc[ScheduleKind] = Tok.getLocation(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 776 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 777 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 778 | ConsumeAnyToken(); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 779 | if ((Arg[ScheduleKind] == OMPC_SCHEDULE_static || |
| 780 | Arg[ScheduleKind] == OMPC_SCHEDULE_dynamic || |
| 781 | Arg[ScheduleKind] == OMPC_SCHEDULE_guided) && |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 782 | Tok.is(tok::comma)) |
| 783 | DelimLoc = ConsumeAnyToken(); |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 784 | } else if (Kind == OMPC_dist_schedule) { |
| 785 | Arg.push_back(getOpenMPSimpleClauseType( |
| 786 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 787 | KLoc.push_back(Tok.getLocation()); |
| 788 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 789 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 790 | ConsumeAnyToken(); |
| 791 | if (Arg.back() == OMPC_DIST_SCHEDULE_static && Tok.is(tok::comma)) |
| 792 | DelimLoc = ConsumeAnyToken(); |
Arpith Chacko Jacob | 3cf8904 | 2016-01-26 16:37:23 +0000 | [diff] [blame] | 793 | } else if (Kind == OMPC_defaultmap) { |
| 794 | // Get a defaultmap modifier |
| 795 | Arg.push_back(getOpenMPSimpleClauseType( |
| 796 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 797 | KLoc.push_back(Tok.getLocation()); |
| 798 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 799 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 800 | ConsumeAnyToken(); |
| 801 | // Parse ':' |
| 802 | if (Tok.is(tok::colon)) |
| 803 | ConsumeAnyToken(); |
| 804 | else if (Arg.back() != OMPC_DEFAULTMAP_MODIFIER_unknown) |
| 805 | Diag(Tok, diag::warn_pragma_expected_colon) << "defaultmap modifier"; |
| 806 | // Get a defaultmap kind |
| 807 | Arg.push_back(getOpenMPSimpleClauseType( |
| 808 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok))); |
| 809 | KLoc.push_back(Tok.getLocation()); |
| 810 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 811 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 812 | ConsumeAnyToken(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 813 | } else { |
| 814 | assert(Kind == OMPC_if); |
Alexey Bataev | 6402bca | 2015-12-28 07:25:51 +0000 | [diff] [blame] | 815 | KLoc.push_back(Tok.getLocation()); |
| 816 | Arg.push_back(ParseOpenMPDirectiveKind(*this)); |
| 817 | if (Arg.back() != OMPD_unknown) { |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 818 | ConsumeToken(); |
| 819 | if (Tok.is(tok::colon)) |
| 820 | DelimLoc = ConsumeToken(); |
| 821 | else |
| 822 | Diag(Tok, diag::warn_pragma_expected_colon) |
| 823 | << "directive name modifier"; |
| 824 | } |
| 825 | } |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 826 | |
Carlo Bertolli | b4adf55 | 2016-01-15 18:50:31 +0000 | [diff] [blame] | 827 | bool NeedAnExpression = (Kind == OMPC_schedule && DelimLoc.isValid()) || |
| 828 | (Kind == OMPC_dist_schedule && DelimLoc.isValid()) || |
| 829 | Kind == OMPC_if; |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 830 | if (NeedAnExpression) { |
| 831 | SourceLocation ELoc = Tok.getLocation(); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 832 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 833 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 834 | Val = Actions.ActOnFinishFullExpr(Val.get(), ELoc); |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 835 | } |
| 836 | |
| 837 | // Parse ')'. |
| 838 | T.consumeClose(); |
| 839 | |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 840 | if (NeedAnExpression && Val.isInvalid()) |
| 841 | return nullptr; |
| 842 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 843 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 844 | Kind, Arg, Val.get(), Loc, T.getOpenLocation(), KLoc, DelimLoc, |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 845 | T.getCloseLocation()); |
| 846 | } |
| 847 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 848 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 849 | UnqualifiedId &ReductionId) { |
| 850 | SourceLocation TemplateKWLoc; |
| 851 | if (ReductionIdScopeSpec.isEmpty()) { |
| 852 | auto OOK = OO_None; |
| 853 | switch (P.getCurToken().getKind()) { |
| 854 | case tok::plus: |
| 855 | OOK = OO_Plus; |
| 856 | break; |
| 857 | case tok::minus: |
| 858 | OOK = OO_Minus; |
| 859 | break; |
| 860 | case tok::star: |
| 861 | OOK = OO_Star; |
| 862 | break; |
| 863 | case tok::amp: |
| 864 | OOK = OO_Amp; |
| 865 | break; |
| 866 | case tok::pipe: |
| 867 | OOK = OO_Pipe; |
| 868 | break; |
| 869 | case tok::caret: |
| 870 | OOK = OO_Caret; |
| 871 | break; |
| 872 | case tok::ampamp: |
| 873 | OOK = OO_AmpAmp; |
| 874 | break; |
| 875 | case tok::pipepipe: |
| 876 | OOK = OO_PipePipe; |
| 877 | break; |
| 878 | default: |
| 879 | break; |
| 880 | } |
| 881 | if (OOK != OO_None) { |
| 882 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 883 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 884 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 885 | return false; |
| 886 | } |
| 887 | } |
| 888 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 889 | /*AllowDestructorName*/ false, |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 890 | /*AllowConstructorName*/ false, nullptr, |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 891 | TemplateKWLoc, ReductionId); |
| 892 | } |
| 893 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 894 | /// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 895 | /// 'shared', 'copyin', 'copyprivate', 'flush' or 'reduction'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 896 | /// |
| 897 | /// private-clause: |
| 898 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 899 | /// firstprivate-clause: |
| 900 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 901 | /// lastprivate-clause: |
| 902 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 903 | /// shared-clause: |
| 904 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 905 | /// linear-clause: |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 906 | /// 'linear' '(' linear-list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 907 | /// aligned-clause: |
| 908 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 909 | /// reduction-clause: |
| 910 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 911 | /// copyprivate-clause: |
| 912 | /// 'copyprivate' '(' list ')' |
| 913 | /// flush-clause: |
| 914 | /// 'flush' '(' list ')' |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 915 | /// depend-clause: |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 916 | /// 'depend' '(' in | out | inout : list | source ')' |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 917 | /// map-clause: |
| 918 | /// 'map' '(' [ [ always , ] |
| 919 | /// to | from | tofrom | alloc | release | delete ':' ] list ')'; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 920 | /// |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 921 | /// For 'linear' clause linear-list may have the following forms: |
| 922 | /// list |
| 923 | /// modifier(list) |
| 924 | /// where modifier is 'val' (C) or 'ref', 'val' or 'uval'(C++). |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 925 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPDirectiveKind DKind, |
| 926 | OpenMPClauseKind Kind) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 927 | SourceLocation Loc = Tok.getLocation(); |
| 928 | SourceLocation LOpen = ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 929 | SourceLocation ColonLoc = SourceLocation(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 930 | // Optional scope specifier and unqualified id for reduction identifier. |
| 931 | CXXScopeSpec ReductionIdScopeSpec; |
| 932 | UnqualifiedId ReductionId; |
| 933 | bool InvalidReductionId = false; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 934 | OpenMPDependClauseKind DepKind = OMPC_DEPEND_unknown; |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 935 | // OpenMP 4.1 [2.15.3.7, linear Clause] |
| 936 | // If no modifier is specified it is assumed to be val. |
| 937 | OpenMPLinearClauseKind LinearModifier = OMPC_LINEAR_val; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 938 | OpenMPMapClauseKind MapType = OMPC_MAP_unknown; |
| 939 | OpenMPMapClauseKind MapTypeModifier = OMPC_MAP_unknown; |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 940 | bool MapTypeIsImplicit = false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 941 | bool MapTypeModifierSpecified = false; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 942 | SourceLocation DepLinMapLoc; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 943 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 944 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 945 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 946 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 947 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 948 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 949 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 950 | bool NeedRParenForLinear = false; |
| 951 | BalancedDelimiterTracker LinearT(*this, tok::l_paren, |
| 952 | tok::annot_pragma_openmp_end); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 953 | // Handle reduction-identifier for reduction clause. |
| 954 | if (Kind == OMPC_reduction) { |
| 955 | ColonProtectionRAIIObject ColonRAII(*this); |
| 956 | if (getLangOpts().CPlusPlus) { |
David Blaikie | efdccaa | 2016-01-15 23:43:34 +0000 | [diff] [blame] | 957 | ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, nullptr, false); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 958 | } |
| 959 | InvalidReductionId = |
| 960 | ParseReductionId(*this, ReductionIdScopeSpec, ReductionId); |
| 961 | if (InvalidReductionId) { |
| 962 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 963 | StopBeforeMatch); |
| 964 | } |
| 965 | if (Tok.is(tok::colon)) { |
| 966 | ColonLoc = ConsumeToken(); |
| 967 | } else { |
| 968 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 969 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 970 | } else if (Kind == OMPC_depend) { |
| 971 | // Handle dependency type for depend clause. |
| 972 | ColonProtectionRAIIObject ColonRAII(*this); |
| 973 | DepKind = static_cast<OpenMPDependClauseKind>(getOpenMPSimpleClauseType( |
| 974 | Kind, Tok.is(tok::identifier) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 975 | DepLinMapLoc = Tok.getLocation(); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 976 | |
| 977 | if (DepKind == OMPC_DEPEND_unknown) { |
| 978 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 979 | StopBeforeMatch); |
| 980 | } else { |
| 981 | ConsumeToken(); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 982 | // Special processing for depend(source) clause. |
| 983 | if (DKind == OMPD_ordered && DepKind == OMPC_DEPEND_source) { |
| 984 | // Parse ')'. |
| 985 | T.consumeClose(); |
| 986 | return Actions.ActOnOpenMPVarListClause( |
| 987 | Kind, llvm::None, /*TailExpr=*/nullptr, Loc, LOpen, |
| 988 | /*ColonLoc=*/SourceLocation(), Tok.getLocation(), |
| 989 | ReductionIdScopeSpec, DeclarationNameInfo(), DepKind, |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 990 | LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit, |
| 991 | DepLinMapLoc); |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 992 | } |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 993 | } |
| 994 | if (Tok.is(tok::colon)) { |
| 995 | ColonLoc = ConsumeToken(); |
| 996 | } else { |
Alexey Bataev | eb48235 | 2015-12-18 05:05:56 +0000 | [diff] [blame] | 997 | Diag(Tok, DKind == OMPD_ordered ? diag::warn_pragma_expected_colon_r_paren |
| 998 | : diag::warn_pragma_expected_colon) |
| 999 | << "dependency type"; |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1000 | } |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1001 | } else if (Kind == OMPC_linear) { |
| 1002 | // Try to parse modifier if any. |
| 1003 | if (Tok.is(tok::identifier) && PP.LookAhead(0).is(tok::l_paren)) { |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1004 | LinearModifier = static_cast<OpenMPLinearClauseKind>( |
Alexey Bataev | 1185e19 | 2015-08-20 12:15:57 +0000 | [diff] [blame] | 1005 | getOpenMPSimpleClauseType(Kind, PP.getSpelling(Tok))); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1006 | DepLinMapLoc = ConsumeToken(); |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1007 | LinearT.consumeOpen(); |
| 1008 | NeedRParenForLinear = true; |
| 1009 | } |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1010 | } else if (Kind == OMPC_map) { |
| 1011 | // Handle map type for map clause. |
| 1012 | ColonProtectionRAIIObject ColonRAII(*this); |
| 1013 | |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame^] | 1014 | /// The map clause modifier token can be either a identifier or the C++ |
| 1015 | /// delete keyword. |
| 1016 | auto IsMapClauseModifierToken = [](const Token &Tok) { |
| 1017 | return Tok.isOneOf(tok::identifier, tok::kw_delete); |
| 1018 | }; |
| 1019 | |
| 1020 | // The first identifier may be a list item, a map-type or a |
| 1021 | // map-type-modifier. The map modifier can also be delete which has the same |
| 1022 | // spelling of the C++ delete keyword. |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1023 | MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType( |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame^] | 1024 | Kind, IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1025 | DepLinMapLoc = Tok.getLocation(); |
| 1026 | bool ColonExpected = false; |
| 1027 | |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame^] | 1028 | if (IsMapClauseModifierToken(Tok)) { |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1029 | if (PP.LookAhead(0).is(tok::colon)) { |
| 1030 | MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType( |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame^] | 1031 | Kind, IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1032 | if (MapType == OMPC_MAP_unknown) { |
| 1033 | Diag(Tok, diag::err_omp_unknown_map_type); |
| 1034 | } else if (MapType == OMPC_MAP_always) { |
| 1035 | Diag(Tok, diag::err_omp_map_type_missing); |
| 1036 | } |
| 1037 | ConsumeToken(); |
| 1038 | } else if (PP.LookAhead(0).is(tok::comma)) { |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame^] | 1039 | if (IsMapClauseModifierToken(PP.LookAhead(1)) && |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1040 | PP.LookAhead(2).is(tok::colon)) { |
| 1041 | MapTypeModifier = |
| 1042 | static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType( |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame^] | 1043 | Kind, |
| 1044 | IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1045 | if (MapTypeModifier != OMPC_MAP_always) { |
| 1046 | Diag(Tok, diag::err_omp_unknown_map_type_modifier); |
| 1047 | MapTypeModifier = OMPC_MAP_unknown; |
| 1048 | } else { |
| 1049 | MapTypeModifierSpecified = true; |
| 1050 | } |
| 1051 | |
| 1052 | ConsumeToken(); |
| 1053 | ConsumeToken(); |
| 1054 | |
| 1055 | MapType = static_cast<OpenMPMapClauseKind>(getOpenMPSimpleClauseType( |
Samuel Antao | f91b163 | 2016-02-27 00:01:58 +0000 | [diff] [blame^] | 1056 | Kind, IsMapClauseModifierToken(Tok) ? PP.getSpelling(Tok) : "")); |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1057 | if (MapType == OMPC_MAP_unknown || MapType == OMPC_MAP_always) { |
| 1058 | Diag(Tok, diag::err_omp_unknown_map_type); |
| 1059 | } |
| 1060 | ConsumeToken(); |
| 1061 | } else { |
| 1062 | MapType = OMPC_MAP_tofrom; |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1063 | MapTypeIsImplicit = true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1064 | } |
| 1065 | } else { |
| 1066 | MapType = OMPC_MAP_tofrom; |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1067 | MapTypeIsImplicit = true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1068 | } |
| 1069 | } else { |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 1070 | MapType = OMPC_MAP_tofrom; |
| 1071 | MapTypeIsImplicit = true; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1072 | } |
| 1073 | |
| 1074 | if (Tok.is(tok::colon)) { |
| 1075 | ColonLoc = ConsumeToken(); |
| 1076 | } else if (ColonExpected) { |
| 1077 | Diag(Tok, diag::warn_pragma_expected_colon) << "map type"; |
| 1078 | } |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1079 | } |
| 1080 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1081 | SmallVector<Expr *, 5> Vars; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1082 | bool IsComma = |
| 1083 | ((Kind != OMPC_reduction) && (Kind != OMPC_depend) && |
| 1084 | (Kind != OMPC_map)) || |
| 1085 | ((Kind == OMPC_reduction) && !InvalidReductionId) || |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 1086 | ((Kind == OMPC_map) && (MapType != OMPC_MAP_unknown) && |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1087 | (!MapTypeModifierSpecified || |
| 1088 | (MapTypeModifierSpecified && MapTypeModifier == OMPC_MAP_always))) || |
| 1089 | ((Kind == OMPC_depend) && DepKind != OMPC_DEPEND_unknown); |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1090 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1091 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1092 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1093 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1094 | // Parse variable |
Kaelyn Takata | 1586782 | 2014-11-21 18:48:04 +0000 | [diff] [blame] | 1095 | ExprResult VarExpr = |
| 1096 | Actions.CorrectDelayedTyposInExpr(ParseAssignmentExpression()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1097 | if (VarExpr.isUsable()) { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1098 | Vars.push_back(VarExpr.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1099 | } else { |
| 1100 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 1101 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1102 | } |
| 1103 | // Skip ',' if any |
| 1104 | IsComma = Tok.is(tok::comma); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1105 | if (IsComma) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1106 | ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1107 | else if (Tok.isNot(tok::r_paren) && |
| 1108 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 1109 | (!MayHaveTail || Tok.isNot(tok::colon))) |
Alexey Bataev | 6125da9 | 2014-07-21 11:26:11 +0000 | [diff] [blame] | 1110 | Diag(Tok, diag::err_omp_expected_punc) |
| 1111 | << ((Kind == OMPC_flush) ? getOpenMPDirectiveName(OMPD_flush) |
| 1112 | : getOpenMPClauseName(Kind)) |
| 1113 | << (Kind == OMPC_flush); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1114 | } |
| 1115 | |
Alexey Bataev | 182227b | 2015-08-20 10:54:39 +0000 | [diff] [blame] | 1116 | // Parse ')' for linear clause with modifier. |
| 1117 | if (NeedRParenForLinear) |
| 1118 | LinearT.consumeClose(); |
| 1119 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 1120 | // Parse ':' linear-step (or ':' alignment). |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1121 | Expr *TailExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1122 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 1123 | if (MustHaveTail) { |
| 1124 | ColonLoc = Tok.getLocation(); |
Alexey Bataev | 6b8046a | 2015-09-03 07:23:48 +0000 | [diff] [blame] | 1125 | SourceLocation ELoc = ConsumeToken(); |
| 1126 | ExprResult Tail = ParseAssignmentExpression(); |
| 1127 | Tail = Actions.ActOnFinishFullExpr(Tail.get(), ELoc); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1128 | if (Tail.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 1129 | TailExpr = Tail.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 1130 | else |
| 1131 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 1132 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | // Parse ')'. |
| 1136 | T.consumeClose(); |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1137 | if ((Kind == OMPC_depend && DepKind != OMPC_DEPEND_unknown && Vars.empty()) || |
Samuel Antao | 5de996e | 2016-01-22 20:21:36 +0000 | [diff] [blame] | 1138 | (Kind != OMPC_depend && Kind != OMPC_map && Vars.empty()) || |
| 1139 | (MustHaveTail && !TailExpr) || InvalidReductionId) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 1140 | return nullptr; |
Kelvin Li | 0bff7af | 2015-11-23 05:32:03 +0000 | [diff] [blame] | 1141 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1142 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 1143 | return Actions.ActOnOpenMPVarListClause( |
| 1144 | Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(), |
| 1145 | ReductionIdScopeSpec, |
| 1146 | ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId) |
Alexey Bataev | 1c2cfbc | 2015-06-23 14:25:19 +0000 | [diff] [blame] | 1147 | : DeclarationNameInfo(), |
Samuel Antao | 23abd72 | 2016-01-19 20:40:49 +0000 | [diff] [blame] | 1148 | DepKind, LinearModifier, MapTypeModifier, MapType, MapTypeIsImplicit, |
| 1149 | DepLinMapLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 1150 | } |
| 1151 | |