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