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