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