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