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