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