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" |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 22 | using namespace clang; |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
| 25 | // OpenMP declarative directives. |
| 26 | //===----------------------------------------------------------------------===// |
| 27 | |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 28 | static OpenMPDirectiveKind ParseOpenMPDirectiveKind(Parser &P) { |
| 29 | auto Tok = P.getCurToken(); |
| 30 | auto DKind = |
| 31 | Tok.isAnnotation() |
| 32 | ? OMPD_unknown |
| 33 | : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok)); |
| 34 | if (DKind == OMPD_parallel) { |
| 35 | Tok = P.getPreprocessor().LookAhead(0); |
| 36 | auto SDKind = |
| 37 | Tok.isAnnotation() |
| 38 | ? OMPD_unknown |
| 39 | : getOpenMPDirectiveKind(P.getPreprocessor().getSpelling(Tok)); |
| 40 | if (SDKind == OMPD_for) { |
| 41 | P.ConsumeToken(); |
| 42 | DKind = OMPD_parallel_for; |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 43 | } else if (SDKind == OMPD_sections) { |
| 44 | P.ConsumeToken(); |
| 45 | DKind = OMPD_parallel_sections; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | return DKind; |
| 49 | } |
| 50 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 51 | /// \brief Parsing of declarative OpenMP directives. |
| 52 | /// |
| 53 | /// threadprivate-directive: |
| 54 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 55 | /// |
| 56 | Parser::DeclGroupPtrTy Parser::ParseOpenMPDeclarativeDirective() { |
| 57 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 58 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 59 | |
| 60 | SourceLocation Loc = ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 61 | SmallVector<Expr *, 5> Identifiers; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 62 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 63 | |
| 64 | switch (DKind) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 65 | case OMPD_threadprivate: |
| 66 | ConsumeToken(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 67 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, true)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 68 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 69 | // extra tokens. |
| 70 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 71 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 72 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 73 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 74 | } |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 75 | // Skip the last annot_pragma_openmp_end. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 76 | ConsumeToken(); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 77 | return Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 78 | } |
| 79 | break; |
| 80 | case OMPD_unknown: |
| 81 | Diag(Tok, diag::err_omp_unknown_directive); |
| 82 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 83 | case OMPD_parallel: |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 84 | case OMPD_simd: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 85 | case OMPD_task: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 86 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 87 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 88 | case OMPD_taskwait: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 89 | case OMPD_for: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 90 | case OMPD_sections: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 91 | case OMPD_section: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 92 | case OMPD_single: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 93 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 94 | case OMPD_critical: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 95 | case OMPD_parallel_for: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 96 | case OMPD_parallel_sections: |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 97 | Diag(Tok, diag::err_omp_unexpected_directive) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 98 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 99 | break; |
| 100 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 101 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 102 | return DeclGroupPtrTy(); |
| 103 | } |
| 104 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 105 | /// \brief Parsing of declarative or executable OpenMP directives. |
| 106 | /// |
| 107 | /// threadprivate-directive: |
| 108 | /// annot_pragma_openmp 'threadprivate' simple-variable-list |
| 109 | /// annot_pragma_openmp_end |
| 110 | /// |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 111 | /// executable-directive: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 112 | /// annot_pragma_openmp 'parallel' | 'simd' | 'for' | 'sections' | |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 113 | /// 'section' | 'single' | 'master' | 'critical' [ '(' <name> ')' ] | |
| 114 | /// 'parallel for' | 'parallel sections' | 'task' | 'taskyield' | |
| 115 | /// 'barrier' | 'taskwait' {clause} annot_pragma_openmp_end |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 116 | /// |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 117 | StmtResult |
| 118 | Parser::ParseOpenMPDeclarativeOrExecutableDirective(bool StandAloneAllowed) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 119 | assert(Tok.is(tok::annot_pragma_openmp) && "Not an OpenMP directive!"); |
Alexey Bataev | ee6507d | 2013-11-18 08:17:37 +0000 | [diff] [blame] | 120 | ParenBraceBracketBalancer BalancerRAIIObj(*this); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 121 | SmallVector<Expr *, 5> Identifiers; |
| 122 | SmallVector<OMPClause *, 5> Clauses; |
Alexey Bataev | 4ca40ed | 2014-05-12 04:23:46 +0000 | [diff] [blame] | 123 | SmallVector<llvm::PointerIntPair<OMPClause *, 1, bool>, OMPC_unknown + 1> |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 124 | FirstClauses(OMPC_unknown + 1); |
Alexander Musman | a8e9d2e | 2014-06-03 10:16:47 +0000 | [diff] [blame] | 125 | unsigned ScopeFlags = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 126 | Scope::FnScope | Scope::DeclScope | Scope::OpenMPDirectiveScope; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 127 | SourceLocation Loc = ConsumeToken(), EndLoc; |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 128 | auto DKind = ParseOpenMPDirectiveKind(*this); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 129 | // Name of critical directive. |
| 130 | DeclarationNameInfo DirName; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 131 | StmtResult Directive = StmtError(); |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 132 | bool HasAssociatedStatement = true; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 133 | |
| 134 | switch (DKind) { |
| 135 | case OMPD_threadprivate: |
| 136 | ConsumeToken(); |
| 137 | if (!ParseOpenMPSimpleVarList(OMPD_threadprivate, Identifiers, false)) { |
| 138 | // The last seen token is annot_pragma_openmp_end - need to check for |
| 139 | // extra tokens. |
| 140 | if (Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 141 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 142 | << getOpenMPDirectiveName(OMPD_threadprivate); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 143 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 144 | } |
| 145 | DeclGroupPtrTy Res = |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 146 | Actions.ActOnOpenMPThreadprivateDirective(Loc, Identifiers); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 147 | Directive = Actions.ActOnDeclStmt(Res, Loc, Tok.getLocation()); |
| 148 | } |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 149 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 150 | break; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 151 | case OMPD_taskyield: |
Alexey Bataev | 4d1dfea | 2014-07-18 09:11:51 +0000 | [diff] [blame] | 152 | case OMPD_barrier: |
Alexey Bataev | 2df347a | 2014-07-18 10:17:07 +0000 | [diff] [blame] | 153 | case OMPD_taskwait: |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 154 | if (!StandAloneAllowed) { |
| 155 | Diag(Tok, diag::err_omp_immediate_directive) |
| 156 | << getOpenMPDirectiveName(DKind); |
| 157 | } |
| 158 | HasAssociatedStatement = false; |
Alexey Bataev | 1b59ab5 | 2014-02-27 08:29:12 +0000 | [diff] [blame] | 159 | case OMPD_parallel: |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 160 | case OMPD_simd: |
Alexey Bataev | d3f8dd2 | 2014-06-25 11:44:49 +0000 | [diff] [blame] | 161 | case OMPD_for: |
Alexey Bataev | 1e0498a | 2014-06-26 08:21:58 +0000 | [diff] [blame] | 162 | case OMPD_sections: |
Alexey Bataev | d1e40fb | 2014-06-26 12:05:45 +0000 | [diff] [blame] | 163 | case OMPD_single: |
Alexey Bataev | 4acb859 | 2014-07-07 13:01:15 +0000 | [diff] [blame] | 164 | case OMPD_section: |
Alexander Musman | 80c2289 | 2014-07-17 08:54:58 +0000 | [diff] [blame] | 165 | case OMPD_master: |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 166 | case OMPD_critical: |
Alexey Bataev | 84d0b3e | 2014-07-08 08:12:03 +0000 | [diff] [blame] | 167 | case OMPD_parallel_for: |
Alexey Bataev | 9c2e8ee | 2014-07-11 11:25:16 +0000 | [diff] [blame] | 168 | case OMPD_parallel_sections: |
| 169 | case OMPD_task: { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 170 | ConsumeToken(); |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 171 | // Parse directive name of the 'critical' directive if any. |
| 172 | if (DKind == OMPD_critical) { |
| 173 | BalancedDelimiterTracker T(*this, tok::l_paren, |
| 174 | tok::annot_pragma_openmp_end); |
| 175 | if (!T.consumeOpen()) { |
| 176 | if (Tok.isAnyIdentifier()) { |
| 177 | DirName = |
| 178 | DeclarationNameInfo(Tok.getIdentifierInfo(), Tok.getLocation()); |
| 179 | ConsumeAnyToken(); |
| 180 | } else { |
| 181 | Diag(Tok, diag::err_omp_expected_identifier_for_critical); |
| 182 | } |
| 183 | T.consumeClose(); |
| 184 | } |
| 185 | } |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 186 | |
Alexey Bataev | f29276e | 2014-06-18 04:14:57 +0000 | [diff] [blame] | 187 | if (isOpenMPLoopDirective(DKind)) |
| 188 | ScopeFlags |= Scope::OpenMPLoopDirectiveScope; |
| 189 | if (isOpenMPSimdDirective(DKind)) |
| 190 | ScopeFlags |= Scope::OpenMPSimdDirectiveScope; |
| 191 | ParseScope OMPDirectiveScope(this, ScopeFlags); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 192 | Actions.StartOpenMPDSABlock(DKind, DirName, Actions.getCurScope(), Loc); |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 193 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 194 | while (Tok.isNot(tok::annot_pragma_openmp_end)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 195 | OpenMPClauseKind CKind = Tok.isAnnotation() |
| 196 | ? OMPC_unknown |
| 197 | : getOpenMPClauseKind(PP.getSpelling(Tok)); |
| 198 | OMPClause *Clause = |
| 199 | ParseOpenMPClause(DKind, CKind, !FirstClauses[CKind].getInt()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 200 | FirstClauses[CKind].setInt(true); |
| 201 | if (Clause) { |
| 202 | FirstClauses[CKind].setPointer(Clause); |
| 203 | Clauses.push_back(Clause); |
| 204 | } |
| 205 | |
| 206 | // Skip ',' if any. |
| 207 | if (Tok.is(tok::comma)) |
| 208 | ConsumeToken(); |
| 209 | } |
| 210 | // End location of the directive. |
| 211 | EndLoc = Tok.getLocation(); |
| 212 | // Consume final annot_pragma_openmp_end. |
| 213 | ConsumeToken(); |
| 214 | |
| 215 | StmtResult AssociatedStmt; |
| 216 | bool CreateDirective = true; |
Alexey Bataev | 68446b7 | 2014-07-18 07:47:19 +0000 | [diff] [blame] | 217 | if (HasAssociatedStatement) { |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 218 | // The body is a block scope like in Lambdas and Blocks. |
| 219 | Sema::CompoundScopeRAII CompoundScope(Actions); |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 220 | Actions.ActOnOpenMPRegionStart(DKind, getCurScope()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 221 | Actions.ActOnStartOfCompoundStmt(); |
| 222 | // Parse statement |
| 223 | AssociatedStmt = ParseStatement(); |
| 224 | Actions.ActOnFinishOfCompoundStmt(); |
| 225 | if (!AssociatedStmt.isUsable()) { |
| 226 | Actions.ActOnCapturedRegionError(); |
| 227 | CreateDirective = false; |
| 228 | } else { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 229 | AssociatedStmt = Actions.ActOnCapturedRegionEnd(AssociatedStmt.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 230 | CreateDirective = AssociatedStmt.isUsable(); |
| 231 | } |
| 232 | } |
| 233 | if (CreateDirective) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 234 | Directive = Actions.ActOnOpenMPExecutableDirective( |
Alexander Musman | d9ed09f | 2014-07-21 09:42:05 +0000 | [diff] [blame] | 235 | DKind, DirName, Clauses, AssociatedStmt.get(), Loc, EndLoc); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 236 | |
| 237 | // Exit scope. |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 238 | Actions.EndOpenMPDSABlock(Directive.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 239 | OMPDirectiveScope.Exit(); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 240 | break; |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 241 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 242 | case OMPD_unknown: |
| 243 | Diag(Tok, diag::err_omp_unknown_directive); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 244 | SkipUntil(tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 245 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 246 | } |
| 247 | return Directive; |
| 248 | } |
| 249 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 250 | /// \brief Parses list of simple variables for '#pragma omp threadprivate' |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 251 | /// directive. |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 252 | /// |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 253 | /// simple-variable-list: |
| 254 | /// '(' id-expression {, id-expression} ')' |
| 255 | /// |
| 256 | bool Parser::ParseOpenMPSimpleVarList(OpenMPDirectiveKind Kind, |
| 257 | SmallVectorImpl<Expr *> &VarList, |
| 258 | bool AllowScopeSpecifier) { |
| 259 | VarList.clear(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 260 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 261 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 262 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 263 | getOpenMPDirectiveName(Kind))) |
| 264 | return true; |
| 265 | bool IsCorrect = true; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 266 | bool NoIdentIsFound = true; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 267 | |
| 268 | // Read tokens while ')' or annot_pragma_openmp_end is not found. |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 269 | 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] | 270 | CXXScopeSpec SS; |
| 271 | SourceLocation TemplateKWLoc; |
| 272 | UnqualifiedId Name; |
| 273 | // Read var name. |
| 274 | Token PrevTok = Tok; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 275 | NoIdentIsFound = false; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 276 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 277 | if (AllowScopeSpecifier && getLangOpts().CPlusPlus && |
| 278 | ParseOptionalCXXScopeSpecifier(SS, ParsedType(), false)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 279 | IsCorrect = false; |
| 280 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 281 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 282 | } else if (ParseUnqualifiedId(SS, false, false, false, ParsedType(), |
| 283 | TemplateKWLoc, Name)) { |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 284 | IsCorrect = false; |
| 285 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 286 | StopBeforeMatch); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 287 | } else if (Tok.isNot(tok::comma) && Tok.isNot(tok::r_paren) && |
| 288 | Tok.isNot(tok::annot_pragma_openmp_end)) { |
| 289 | IsCorrect = false; |
| 290 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 291 | StopBeforeMatch); |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 292 | Diag(PrevTok.getLocation(), diag::err_expected) |
| 293 | << tok::identifier |
| 294 | << SourceRange(PrevTok.getLocation(), PrevTokLocation); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 295 | } else { |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 296 | DeclarationNameInfo NameInfo = Actions.GetNameFromUnqualifiedId(Name); |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 297 | ExprResult Res = |
| 298 | Actions.ActOnOpenMPIdExpression(getCurScope(), SS, NameInfo); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 299 | if (Res.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 300 | VarList.push_back(Res.get()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 301 | } |
| 302 | // Consume ','. |
| 303 | if (Tok.is(tok::comma)) { |
| 304 | ConsumeToken(); |
| 305 | } |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 308 | if (NoIdentIsFound) { |
Alp Toker | ec54327 | 2013-12-24 09:48:30 +0000 | [diff] [blame] | 309 | Diag(Tok, diag::err_expected) << tok::identifier; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 310 | IsCorrect = false; |
| 311 | } |
| 312 | |
| 313 | // Parse ')'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 314 | IsCorrect = !T.consumeClose() && IsCorrect; |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 315 | |
| 316 | return !IsCorrect && VarList.empty(); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 317 | } |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 318 | |
| 319 | /// \brief Parsing of OpenMP clauses. |
| 320 | /// |
| 321 | /// clause: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 322 | /// if-clause | final-clause | num_threads-clause | safelen-clause | |
| 323 | /// default-clause | private-clause | firstprivate-clause | shared-clause |
| 324 | /// | linear-clause | aligned-clause | collapse-clause | |
| 325 | /// lastprivate-clause | reduction-clause | proc_bind-clause | |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 326 | /// schedule-clause | copyin-clause | copyprivate-clause | untied-clause | |
| 327 | /// mergeable-clause |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 328 | /// |
| 329 | OMPClause *Parser::ParseOpenMPClause(OpenMPDirectiveKind DKind, |
| 330 | OpenMPClauseKind CKind, bool FirstClause) { |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 331 | OMPClause *Clause = nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 332 | bool ErrorFound = false; |
| 333 | // Check if clause is allowed for the given directive. |
| 334 | if (CKind != OMPC_unknown && !isAllowedClauseForDirective(DKind, CKind)) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 335 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 336 | << getOpenMPDirectiveName(DKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 337 | ErrorFound = true; |
| 338 | } |
| 339 | |
| 340 | switch (CKind) { |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 341 | case OMPC_if: |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 342 | case OMPC_final: |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 343 | case OMPC_num_threads: |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 344 | case OMPC_safelen: |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 345 | case OMPC_collapse: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 346 | // OpenMP [2.5, Restrictions] |
| 347 | // At most one if clause can appear on the directive. |
Alexey Bataev | 568a833 | 2014-03-06 06:15:19 +0000 | [diff] [blame] | 348 | // At most one num_threads clause can appear on the directive. |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 349 | // OpenMP [2.8.1, simd construct, Restrictions] |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 350 | // Only one safelen clause can appear on a simd directive. |
| 351 | // Only one collapse clause can appear on a simd directive. |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 352 | // OpenMP [2.11.1, task Construct, Restrictions] |
| 353 | // At most one if clause can appear on the directive. |
| 354 | // At most one final clause can appear on the directive. |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 355 | if (!FirstClause) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 356 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 357 | << getOpenMPClauseName(CKind); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 358 | } |
| 359 | |
| 360 | Clause = ParseOpenMPSingleExprClause(CKind); |
| 361 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 362 | case OMPC_default: |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 363 | case OMPC_proc_bind: |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 364 | // OpenMP [2.14.3.1, Restrictions] |
| 365 | // Only a single default clause may be specified on a parallel, task or |
| 366 | // teams directive. |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 367 | // OpenMP [2.5, parallel Construct, Restrictions] |
| 368 | // At most one proc_bind clause can appear on the directive. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 369 | if (!FirstClause) { |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 370 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 371 | << getOpenMPClauseName(CKind); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | Clause = ParseOpenMPSimpleClause(CKind); |
| 375 | break; |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 376 | case OMPC_schedule: |
| 377 | // OpenMP [2.7.1, Restrictions, p. 3] |
| 378 | // Only one schedule clause can appear on a loop directive. |
| 379 | if (!FirstClause) { |
| 380 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 381 | << getOpenMPClauseName(CKind); |
| 382 | } |
| 383 | |
| 384 | Clause = ParseOpenMPSingleExprWithArgClause(CKind); |
| 385 | break; |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 386 | case OMPC_ordered: |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 387 | case OMPC_nowait: |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 388 | case OMPC_untied: |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 389 | case OMPC_mergeable: |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 390 | // OpenMP [2.7.1, Restrictions, p. 9] |
| 391 | // Only one ordered clause can appear on a loop directive. |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 392 | // OpenMP [2.7.1, Restrictions, C/C++, p. 4] |
| 393 | // Only one nowait clause can appear on a for directive. |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 394 | if (!FirstClause) { |
| 395 | Diag(Tok, diag::err_omp_more_one_clause) << getOpenMPDirectiveName(DKind) |
| 396 | << getOpenMPClauseName(CKind); |
| 397 | } |
| 398 | |
| 399 | Clause = ParseOpenMPClause(CKind); |
| 400 | break; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 401 | case OMPC_private: |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 402 | case OMPC_firstprivate: |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 403 | case OMPC_lastprivate: |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 404 | case OMPC_shared: |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 405 | case OMPC_reduction: |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 406 | case OMPC_linear: |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 407 | case OMPC_aligned: |
Alexey Bataev | d48bcd8 | 2014-03-31 03:36:38 +0000 | [diff] [blame] | 408 | case OMPC_copyin: |
Alexey Bataev | bae9a79 | 2014-06-27 10:37:06 +0000 | [diff] [blame] | 409 | case OMPC_copyprivate: |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 410 | Clause = ParseOpenMPVarListClause(CKind); |
| 411 | break; |
| 412 | case OMPC_unknown: |
| 413 | Diag(Tok, diag::warn_omp_extra_tokens_at_eol) |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 414 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 415 | SkipUntil(tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 416 | break; |
| 417 | case OMPC_threadprivate: |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 418 | Diag(Tok, diag::err_omp_unexpected_clause) << getOpenMPClauseName(CKind) |
| 419 | << getOpenMPDirectiveName(DKind); |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 420 | SkipUntil(tok::comma, tok::annot_pragma_openmp_end, StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 421 | break; |
| 422 | } |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 423 | return ErrorFound ? nullptr : Clause; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 424 | } |
| 425 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 426 | /// \brief Parsing of OpenMP clauses with single expressions like 'if', |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 427 | /// 'final', 'collapse', 'safelen', 'num_threads', 'simdlen', 'num_teams' or |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 428 | /// 'thread_limit'. |
| 429 | /// |
| 430 | /// if-clause: |
| 431 | /// 'if' '(' expression ')' |
| 432 | /// |
Alexey Bataev | 3778b60 | 2014-07-17 07:32:53 +0000 | [diff] [blame] | 433 | /// final-clause: |
| 434 | /// 'final' '(' expression ')' |
| 435 | /// |
Alexey Bataev | 62c87d2 | 2014-03-21 04:51:18 +0000 | [diff] [blame] | 436 | /// num_threads-clause: |
| 437 | /// 'num_threads' '(' expression ')' |
| 438 | /// |
| 439 | /// safelen-clause: |
| 440 | /// 'safelen' '(' expression ')' |
| 441 | /// |
Alexander Musman | 8bd31e6 | 2014-05-27 15:12:19 +0000 | [diff] [blame] | 442 | /// collapse-clause: |
| 443 | /// 'collapse' '(' expression ')' |
| 444 | /// |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 445 | OMPClause *Parser::ParseOpenMPSingleExprClause(OpenMPClauseKind Kind) { |
| 446 | SourceLocation Loc = ConsumeToken(); |
| 447 | |
| 448 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 449 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 450 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 451 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 452 | |
| 453 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 454 | ExprResult Val(ParseRHSOfBinaryExpression(LHS, prec::Conditional)); |
| 455 | |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 456 | // Parse ')'. |
| 457 | T.consumeClose(); |
| 458 | |
| 459 | if (Val.isInvalid()) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 460 | return nullptr; |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 461 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 462 | return Actions.ActOnOpenMPSingleExprClause( |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 463 | Kind, Val.get(), Loc, T.getOpenLocation(), T.getCloseLocation()); |
Alexey Bataev | aadd52e | 2014-02-13 05:29:23 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 466 | /// \brief Parsing of simple OpenMP clauses like 'default' or 'proc_bind'. |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 467 | /// |
| 468 | /// default-clause: |
| 469 | /// 'default' '(' 'none' | 'shared' ') |
| 470 | /// |
Alexey Bataev | bcbadb6 | 2014-05-06 06:04:14 +0000 | [diff] [blame] | 471 | /// proc_bind-clause: |
| 472 | /// 'proc_bind' '(' 'master' | 'close' | 'spread' ') |
| 473 | /// |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 474 | OMPClause *Parser::ParseOpenMPSimpleClause(OpenMPClauseKind Kind) { |
| 475 | SourceLocation Loc = Tok.getLocation(); |
| 476 | SourceLocation LOpen = ConsumeToken(); |
| 477 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 478 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 479 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 480 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 481 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 482 | |
Alexey Bataev | a55ed26 | 2014-05-28 06:15:33 +0000 | [diff] [blame] | 483 | unsigned Type = getOpenMPSimpleClauseType( |
| 484 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 485 | SourceLocation TypeLoc = Tok.getLocation(); |
| 486 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 487 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 488 | ConsumeAnyToken(); |
| 489 | |
| 490 | // Parse ')'. |
| 491 | T.consumeClose(); |
| 492 | |
| 493 | return Actions.ActOnOpenMPSimpleClause(Kind, Type, TypeLoc, LOpen, Loc, |
| 494 | Tok.getLocation()); |
| 495 | } |
| 496 | |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 497 | /// \brief Parsing of OpenMP clauses like 'ordered'. |
| 498 | /// |
| 499 | /// ordered-clause: |
| 500 | /// 'ordered' |
| 501 | /// |
Alexey Bataev | 236070f | 2014-06-20 11:19:47 +0000 | [diff] [blame] | 502 | /// nowait-clause: |
| 503 | /// 'nowait' |
| 504 | /// |
Alexey Bataev | 7aea99a | 2014-07-17 12:19:31 +0000 | [diff] [blame] | 505 | /// untied-clause: |
| 506 | /// 'untied' |
| 507 | /// |
Alexey Bataev | 74ba3a5 | 2014-07-17 12:47:03 +0000 | [diff] [blame] | 508 | /// mergeable-clause: |
| 509 | /// 'mergeable' |
| 510 | /// |
Alexey Bataev | 142e1fc | 2014-06-20 09:44:06 +0000 | [diff] [blame] | 511 | OMPClause *Parser::ParseOpenMPClause(OpenMPClauseKind Kind) { |
| 512 | SourceLocation Loc = Tok.getLocation(); |
| 513 | ConsumeAnyToken(); |
| 514 | |
| 515 | return Actions.ActOnOpenMPClause(Kind, Loc, Tok.getLocation()); |
| 516 | } |
| 517 | |
| 518 | |
Alexey Bataev | 56dafe8 | 2014-06-20 07:16:17 +0000 | [diff] [blame] | 519 | /// \brief Parsing of OpenMP clauses with single expressions and some additional |
| 520 | /// argument like 'schedule' or 'dist_schedule'. |
| 521 | /// |
| 522 | /// schedule-clause: |
| 523 | /// 'schedule' '(' kind [',' expression ] ')' |
| 524 | /// |
| 525 | OMPClause *Parser::ParseOpenMPSingleExprWithArgClause(OpenMPClauseKind Kind) { |
| 526 | SourceLocation Loc = ConsumeToken(); |
| 527 | SourceLocation CommaLoc; |
| 528 | // Parse '('. |
| 529 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
| 530 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 531 | getOpenMPClauseName(Kind))) |
| 532 | return nullptr; |
| 533 | |
| 534 | ExprResult Val; |
| 535 | unsigned Type = getOpenMPSimpleClauseType( |
| 536 | Kind, Tok.isAnnotation() ? "" : PP.getSpelling(Tok)); |
| 537 | SourceLocation KLoc = Tok.getLocation(); |
| 538 | if (Tok.isNot(tok::r_paren) && Tok.isNot(tok::comma) && |
| 539 | Tok.isNot(tok::annot_pragma_openmp_end)) |
| 540 | ConsumeAnyToken(); |
| 541 | |
| 542 | if (Kind == OMPC_schedule && |
| 543 | (Type == OMPC_SCHEDULE_static || Type == OMPC_SCHEDULE_dynamic || |
| 544 | Type == OMPC_SCHEDULE_guided) && |
| 545 | Tok.is(tok::comma)) { |
| 546 | CommaLoc = ConsumeAnyToken(); |
| 547 | ExprResult LHS(ParseCastExpression(false, false, NotTypeCast)); |
| 548 | Val = ParseRHSOfBinaryExpression(LHS, prec::Conditional); |
| 549 | if (Val.isInvalid()) |
| 550 | return nullptr; |
| 551 | } |
| 552 | |
| 553 | // Parse ')'. |
| 554 | T.consumeClose(); |
| 555 | |
| 556 | return Actions.ActOnOpenMPSingleExprWithArgClause( |
| 557 | Kind, Type, Val.get(), Loc, T.getOpenLocation(), KLoc, CommaLoc, |
| 558 | T.getCloseLocation()); |
| 559 | } |
| 560 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 561 | static bool ParseReductionId(Parser &P, CXXScopeSpec &ReductionIdScopeSpec, |
| 562 | UnqualifiedId &ReductionId) { |
| 563 | SourceLocation TemplateKWLoc; |
| 564 | if (ReductionIdScopeSpec.isEmpty()) { |
| 565 | auto OOK = OO_None; |
| 566 | switch (P.getCurToken().getKind()) { |
| 567 | case tok::plus: |
| 568 | OOK = OO_Plus; |
| 569 | break; |
| 570 | case tok::minus: |
| 571 | OOK = OO_Minus; |
| 572 | break; |
| 573 | case tok::star: |
| 574 | OOK = OO_Star; |
| 575 | break; |
| 576 | case tok::amp: |
| 577 | OOK = OO_Amp; |
| 578 | break; |
| 579 | case tok::pipe: |
| 580 | OOK = OO_Pipe; |
| 581 | break; |
| 582 | case tok::caret: |
| 583 | OOK = OO_Caret; |
| 584 | break; |
| 585 | case tok::ampamp: |
| 586 | OOK = OO_AmpAmp; |
| 587 | break; |
| 588 | case tok::pipepipe: |
| 589 | OOK = OO_PipePipe; |
| 590 | break; |
| 591 | default: |
| 592 | break; |
| 593 | } |
| 594 | if (OOK != OO_None) { |
| 595 | SourceLocation OpLoc = P.ConsumeToken(); |
Alexey Bataev | 23b6942 | 2014-06-18 07:08:49 +0000 | [diff] [blame] | 596 | SourceLocation SymbolLocations[] = {OpLoc, OpLoc, SourceLocation()}; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 597 | ReductionId.setOperatorFunctionId(OpLoc, OOK, SymbolLocations); |
| 598 | return false; |
| 599 | } |
| 600 | } |
| 601 | return P.ParseUnqualifiedId(ReductionIdScopeSpec, /*EnteringContext*/ false, |
| 602 | /*AllowDestructorName*/ false, |
| 603 | /*AllowConstructorName*/ false, ParsedType(), |
| 604 | TemplateKWLoc, ReductionId); |
| 605 | } |
| 606 | |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 607 | /// \brief Parsing of OpenMP clause 'private', 'firstprivate', 'lastprivate', |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 608 | /// 'shared', 'copyin', or 'reduction'. |
| 609 | /// |
| 610 | /// private-clause: |
| 611 | /// 'private' '(' list ')' |
Alexey Bataev | d5af8e4 | 2013-10-01 05:32:34 +0000 | [diff] [blame] | 612 | /// firstprivate-clause: |
| 613 | /// 'firstprivate' '(' list ')' |
Alexander Musman | 1bb328c | 2014-06-04 13:06:39 +0000 | [diff] [blame] | 614 | /// lastprivate-clause: |
| 615 | /// 'lastprivate' '(' list ')' |
Alexey Bataev | 758e55e | 2013-09-06 18:03:48 +0000 | [diff] [blame] | 616 | /// shared-clause: |
| 617 | /// 'shared' '(' list ')' |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 618 | /// linear-clause: |
| 619 | /// 'linear' '(' list [ ':' linear-step ] ')' |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 620 | /// aligned-clause: |
| 621 | /// 'aligned' '(' list [ ':' alignment ] ')' |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 622 | /// reduction-clause: |
| 623 | /// 'reduction' '(' reduction-identifier ':' list ')' |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 624 | /// |
| 625 | OMPClause *Parser::ParseOpenMPVarListClause(OpenMPClauseKind Kind) { |
| 626 | SourceLocation Loc = Tok.getLocation(); |
| 627 | SourceLocation LOpen = ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 628 | SourceLocation ColonLoc = SourceLocation(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 629 | // Optional scope specifier and unqualified id for reduction identifier. |
| 630 | CXXScopeSpec ReductionIdScopeSpec; |
| 631 | UnqualifiedId ReductionId; |
| 632 | bool InvalidReductionId = false; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 633 | // Parse '('. |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 634 | BalancedDelimiterTracker T(*this, tok::l_paren, tok::annot_pragma_openmp_end); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 635 | if (T.expectAndConsume(diag::err_expected_lparen_after, |
| 636 | getOpenMPClauseName(Kind))) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 637 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 638 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 639 | // Handle reduction-identifier for reduction clause. |
| 640 | if (Kind == OMPC_reduction) { |
| 641 | ColonProtectionRAIIObject ColonRAII(*this); |
| 642 | if (getLangOpts().CPlusPlus) { |
| 643 | ParseOptionalCXXScopeSpecifier(ReductionIdScopeSpec, ParsedType(), false); |
| 644 | } |
| 645 | InvalidReductionId = |
| 646 | ParseReductionId(*this, ReductionIdScopeSpec, ReductionId); |
| 647 | if (InvalidReductionId) { |
| 648 | SkipUntil(tok::colon, tok::r_paren, tok::annot_pragma_openmp_end, |
| 649 | StopBeforeMatch); |
| 650 | } |
| 651 | if (Tok.is(tok::colon)) { |
| 652 | ColonLoc = ConsumeToken(); |
| 653 | } else { |
| 654 | Diag(Tok, diag::warn_pragma_expected_colon) << "reduction identifier"; |
| 655 | } |
| 656 | } |
| 657 | |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 658 | SmallVector<Expr *, 5> Vars; |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 659 | bool IsComma = !InvalidReductionId; |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 660 | const bool MayHaveTail = (Kind == OMPC_linear || Kind == OMPC_aligned); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 661 | while (IsComma || (Tok.isNot(tok::r_paren) && Tok.isNot(tok::colon) && |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 662 | Tok.isNot(tok::annot_pragma_openmp_end))) { |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 663 | ColonProtectionRAIIObject ColonRAII(*this, MayHaveTail); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 664 | // Parse variable |
| 665 | ExprResult VarExpr = ParseAssignmentExpression(); |
| 666 | if (VarExpr.isUsable()) { |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 667 | Vars.push_back(VarExpr.get()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 668 | } else { |
| 669 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
Alp Toker | d751fa7 | 2013-12-18 19:10:49 +0000 | [diff] [blame] | 670 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 671 | } |
| 672 | // Skip ',' if any |
| 673 | IsComma = Tok.is(tok::comma); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 674 | if (IsComma) |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 675 | ConsumeToken(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 676 | else if (Tok.isNot(tok::r_paren) && |
| 677 | Tok.isNot(tok::annot_pragma_openmp_end) && |
| 678 | (!MayHaveTail || Tok.isNot(tok::colon))) |
| 679 | Diag(Tok, diag::err_omp_expected_punc) << getOpenMPClauseName(Kind); |
| 680 | } |
| 681 | |
Alexander Musman | f0d76e7 | 2014-05-29 14:36:25 +0000 | [diff] [blame] | 682 | // Parse ':' linear-step (or ':' alignment). |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 683 | Expr *TailExpr = nullptr; |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 684 | const bool MustHaveTail = MayHaveTail && Tok.is(tok::colon); |
| 685 | if (MustHaveTail) { |
| 686 | ColonLoc = Tok.getLocation(); |
| 687 | ConsumeToken(); |
| 688 | ExprResult Tail = ParseAssignmentExpression(); |
| 689 | if (Tail.isUsable()) |
Nikola Smiljanic | 01a7598 | 2014-05-29 10:55:11 +0000 | [diff] [blame] | 690 | TailExpr = Tail.get(); |
Alexander Musman | 8dba664 | 2014-04-22 13:09:42 +0000 | [diff] [blame] | 691 | else |
| 692 | SkipUntil(tok::comma, tok::r_paren, tok::annot_pragma_openmp_end, |
| 693 | StopBeforeMatch); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 694 | } |
| 695 | |
| 696 | // Parse ')'. |
| 697 | T.consumeClose(); |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 698 | if (Vars.empty() || (MustHaveTail && !TailExpr) || InvalidReductionId) |
Craig Topper | 161e4db | 2014-05-21 06:02:52 +0000 | [diff] [blame] | 699 | return nullptr; |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 700 | |
Alexey Bataev | c5e0258 | 2014-06-16 07:08:35 +0000 | [diff] [blame] | 701 | return Actions.ActOnOpenMPVarListClause( |
| 702 | Kind, Vars, TailExpr, Loc, LOpen, ColonLoc, Tok.getLocation(), |
| 703 | ReductionIdScopeSpec, |
| 704 | ReductionId.isValid() ? Actions.GetNameFromUnqualifiedId(ReductionId) |
| 705 | : DeclarationNameInfo()); |
Alexey Bataev | 5ec3eb1 | 2013-07-19 03:13:43 +0000 | [diff] [blame] | 706 | } |
| 707 | |