1 //===-- lib/Parser/openmp-parsers.cpp -------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 9 // Top-level grammar specification for OpenMP. 10 // See OpenMP-4.5-grammar.txt for documentation. 11 12 #include "basic-parsers.h" 13 #include "expr-parsers.h" 14 #include "misc-parsers.h" 15 #include "stmt-parser.h" 16 #include "token-parsers.h" 17 #include "type-parser-implementation.h" 18 #include "flang/Parser/parse-tree.h" 19 20 // OpenMP Directives and Clauses 21 namespace Fortran::parser { 22 23 constexpr auto startOmpLine = skipStuffBeforeStatement >> "!$OMP "_sptok; 24 constexpr auto endOmpLine = space >> endOfLine; 25 26 // OpenMP Clauses 27 // 2.15.3.1 DEFAULT (PRIVATE | FIRSTPRIVATE | SHARED | NONE) 28 TYPE_PARSER(construct<OmpDefaultClause>( 29 "PRIVATE" >> pure(OmpDefaultClause::Type::Private) || 30 "FIRSTPRIVATE" >> pure(OmpDefaultClause::Type::Firstprivate) || 31 "SHARED" >> pure(OmpDefaultClause::Type::Shared) || 32 "NONE" >> pure(OmpDefaultClause::Type::None))) 33 34 // 2.5 PROC_BIND (MASTER | CLOSE | SPREAD) 35 TYPE_PARSER(construct<OmpProcBindClause>( 36 "CLOSE" >> pure(OmpProcBindClause::Type::Close) || 37 "MASTER" >> pure(OmpProcBindClause::Type::Master) || 38 "SPREAD" >> pure(OmpProcBindClause::Type::Spread))) 39 40 // 2.15.5.1 MAP ([ [ALWAYS[,]] map-type : ] variable-name-list) 41 // map-type -> TO | FROM | TOFROM | ALLOC | RELEASE | DELETE 42 TYPE_PARSER(construct<OmpMapType>( 43 maybe("ALWAYS" >> construct<OmpMapType::Always>() / maybe(","_tok)), 44 ("TO"_id >> pure(OmpMapType::Type::To) || 45 "FROM" >> pure(OmpMapType::Type::From) || 46 "TOFROM" >> pure(OmpMapType::Type::Tofrom) || 47 "ALLOC" >> pure(OmpMapType::Type::Alloc) || 48 "RELEASE" >> pure(OmpMapType::Type::Release) || 49 "DELETE" >> pure(OmpMapType::Type::Delete)) / 50 ":")) 51 52 TYPE_PARSER(construct<OmpMapClause>( 53 maybe(Parser<OmpMapType>{}), Parser<OmpObjectList>{})) 54 55 // 2.15.5.2 defaultmap -> DEFAULTMAP (TOFROM:SCALAR) 56 TYPE_PARSER(construct<OmpDefaultmapClause>( 57 construct<OmpDefaultmapClause::ImplicitBehavior>( 58 "TOFROM" >> pure(OmpDefaultmapClause::ImplicitBehavior::Tofrom)), 59 maybe(":" >> construct<OmpDefaultmapClause::VariableCategory>("SCALAR" >> 60 pure(OmpDefaultmapClause::VariableCategory::Scalar))))) 61 62 // 2.7.1 SCHEDULE ([modifier1 [, modifier2]:]kind[, chunk_size]) 63 // Modifier -> MONITONIC | NONMONOTONIC | SIMD 64 // kind -> STATIC | DYNAMIC | GUIDED | AUTO | RUNTIME 65 // chunk_size -> ScalarIntExpr 66 TYPE_PARSER(construct<OmpScheduleModifierType>( 67 "MONOTONIC" >> pure(OmpScheduleModifierType::ModType::Monotonic) || 68 "NONMONOTONIC" >> pure(OmpScheduleModifierType::ModType::Nonmonotonic) || 69 "SIMD" >> pure(OmpScheduleModifierType::ModType::Simd))) 70 71 TYPE_PARSER(construct<OmpScheduleModifier>(Parser<OmpScheduleModifierType>{}, 72 maybe("," >> Parser<OmpScheduleModifierType>{}) / ":")) 73 74 TYPE_PARSER(construct<OmpScheduleClause>(maybe(Parser<OmpScheduleModifier>{}), 75 "STATIC" >> pure(OmpScheduleClause::ScheduleType::Static) || 76 "DYNAMIC" >> pure(OmpScheduleClause::ScheduleType::Dynamic) || 77 "GUIDED" >> pure(OmpScheduleClause::ScheduleType::Guided) || 78 "AUTO" >> pure(OmpScheduleClause::ScheduleType::Auto) || 79 "RUNTIME" >> pure(OmpScheduleClause::ScheduleType::Runtime), 80 maybe("," >> scalarIntExpr))) 81 82 // 2.12 IF (directive-name-modifier: scalar-logical-expr) 83 TYPE_PARSER(construct<OmpIfClause>( 84 maybe( 85 ("PARALLEL" >> pure(OmpIfClause::DirectiveNameModifier::Parallel) || 86 "TARGET ENTER DATA" >> 87 pure(OmpIfClause::DirectiveNameModifier::TargetEnterData) || 88 "TARGET EXIT DATA" >> 89 pure(OmpIfClause::DirectiveNameModifier::TargetExitData) || 90 "TARGET DATA" >> 91 pure(OmpIfClause::DirectiveNameModifier::TargetData) || 92 "TARGET UPDATE" >> 93 pure(OmpIfClause::DirectiveNameModifier::TargetUpdate) || 94 "TARGET" >> pure(OmpIfClause::DirectiveNameModifier::Target) || 95 "TASK"_id >> pure(OmpIfClause::DirectiveNameModifier::Task) || 96 "TASKLOOP" >> pure(OmpIfClause::DirectiveNameModifier::Taskloop)) / 97 ":"), 98 scalarLogicalExpr)) 99 100 // 2.15.3.6 REDUCTION (reduction-identifier: variable-name-list) 101 TYPE_PARSER(construct<OmpReductionOperator>(Parser<DefinedOperator>{}) || 102 construct<OmpReductionOperator>(Parser<ProcedureDesignator>{})) 103 104 TYPE_PARSER(construct<OmpReductionClause>( 105 Parser<OmpReductionOperator>{} / ":", nonemptyList(designator))) 106 107 // OMP 5.0 2.11.4 ALLOCATE ([allocator:] variable-name-list) 108 TYPE_PARSER(construct<OmpAllocateClause>( 109 maybe(construct<OmpAllocateClause::Allocator>(scalarIntExpr) / ":"), 110 Parser<OmpObjectList>{})) 111 112 // 2.13.9 DEPEND (SOURCE | SINK : vec | (IN | OUT | INOUT) : list 113 TYPE_PARSER(construct<OmpDependSinkVecLength>( 114 Parser<DefinedOperator>{}, scalarIntConstantExpr)) 115 116 TYPE_PARSER( 117 construct<OmpDependSinkVec>(name, maybe(Parser<OmpDependSinkVecLength>{}))) 118 119 TYPE_PARSER( 120 construct<OmpDependenceType>("IN"_id >> pure(OmpDependenceType::Type::In) || 121 "INOUT" >> pure(OmpDependenceType::Type::Inout) || 122 "OUT" >> pure(OmpDependenceType::Type::Out))) 123 124 TYPE_CONTEXT_PARSER("Omp Depend clause"_en_US, 125 construct<OmpDependClause>(construct<OmpDependClause::Sink>( 126 "SINK :" >> nonemptyList(Parser<OmpDependSinkVec>{}))) || 127 construct<OmpDependClause>( 128 construct<OmpDependClause::Source>("SOURCE"_tok)) || 129 construct<OmpDependClause>(construct<OmpDependClause::InOut>( 130 Parser<OmpDependenceType>{}, ":" >> nonemptyList(designator)))) 131 132 // 2.15.3.7 LINEAR (linear-list: linear-step) 133 // linear-list -> list | modifier(list) 134 // linear-modifier -> REF | VAL | UVAL 135 TYPE_PARSER( 136 construct<OmpLinearModifier>("REF" >> pure(OmpLinearModifier::Type::Ref) || 137 "VAL" >> pure(OmpLinearModifier::Type::Val) || 138 "UVAL" >> pure(OmpLinearModifier::Type::Uval))) 139 140 TYPE_CONTEXT_PARSER("Omp LINEAR clause"_en_US, 141 construct<OmpLinearClause>( 142 construct<OmpLinearClause>(construct<OmpLinearClause::WithModifier>( 143 Parser<OmpLinearModifier>{}, parenthesized(nonemptyList(name)), 144 maybe(":" >> scalarIntConstantExpr))) || 145 construct<OmpLinearClause>(construct<OmpLinearClause::WithoutModifier>( 146 nonemptyList(name), maybe(":" >> scalarIntConstantExpr))))) 147 148 // 2.8.1 ALIGNED (list: alignment) 149 TYPE_PARSER(construct<OmpAlignedClause>( 150 nonemptyList(name), maybe(":" >> scalarIntConstantExpr))) 151 152 TYPE_PARSER( 153 construct<OmpObject>(designator) || construct<OmpObject>("/" >> name / "/")) 154 155 TYPE_PARSER( 156 "ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) || 157 "ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) || 158 "ALIGNED" >> 159 construct<OmpClause>(parenthesized(Parser<OmpAlignedClause>{})) || 160 "ALLOCATE" >> 161 construct<OmpClause>(parenthesized(Parser<OmpAllocateClause>{})) || 162 "COLLAPSE" >> construct<OmpClause>(construct<OmpClause::Collapse>( 163 parenthesized(scalarIntConstantExpr))) || 164 "COPYIN" >> construct<OmpClause>(construct<OmpClause::Copyin>( 165 parenthesized(Parser<OmpObjectList>{}))) || 166 "COPYPRIVATE" >> construct<OmpClause>(construct<OmpClause::Copyprivate>( 167 (parenthesized(Parser<OmpObjectList>{})))) || 168 "DEFAULT"_id >> 169 construct<OmpClause>(parenthesized(Parser<OmpDefaultClause>{})) || 170 "DEFAULTMAP" >> 171 construct<OmpClause>(parenthesized(Parser<OmpDefaultmapClause>{})) || 172 "DEPEND" >> 173 construct<OmpClause>(parenthesized(Parser<OmpDependClause>{})) || 174 "DEVICE" >> construct<OmpClause>(construct<OmpClause::Device>( 175 parenthesized(scalarIntExpr))) || 176 "DIST_SCHEDULE" >> 177 construct<OmpClause>(construct<OmpDistScheduleClause>( 178 parenthesized("STATIC" >> maybe("," >> scalarIntExpr)))) || 179 "FINAL" >> construct<OmpClause>(construct<OmpClause::Final>( 180 parenthesized(scalarLogicalExpr))) || 181 "FIRSTPRIVATE" >> construct<OmpClause>(construct<OmpClause::Firstprivate>( 182 parenthesized(Parser<OmpObjectList>{}))) || 183 "FROM" >> construct<OmpClause>(construct<OmpClause::From>( 184 parenthesized(Parser<OmpObjectList>{}))) || 185 "GRAINSIZE" >> construct<OmpClause>(construct<OmpClause::Grainsize>( 186 parenthesized(scalarIntExpr))) || 187 "HINT" >> construct<OmpClause>( 188 construct<OmpClause::Hint>(parenthesized(constantExpr))) || 189 "IF" >> construct<OmpClause>(parenthesized(Parser<OmpIfClause>{})) || 190 "INBRANCH" >> construct<OmpClause>(construct<OmpClause::Inbranch>()) || 191 "IS_DEVICE_PTR" >> construct<OmpClause>(construct<OmpClause::IsDevicePtr>( 192 parenthesized(nonemptyList(name)))) || 193 "LASTPRIVATE" >> construct<OmpClause>(construct<OmpClause::Lastprivate>( 194 parenthesized(Parser<OmpObjectList>{}))) || 195 "LINEAR" >> 196 construct<OmpClause>(parenthesized(Parser<OmpLinearClause>{})) || 197 "LINK" >> construct<OmpClause>(construct<OmpClause::Link>( 198 parenthesized(Parser<OmpObjectList>{}))) || 199 "MAP" >> construct<OmpClause>(parenthesized(Parser<OmpMapClause>{})) || 200 "MERGEABLE" >> construct<OmpClause>(construct<OmpClause::Mergeable>()) || 201 "NOGROUP" >> construct<OmpClause>(construct<OmpClause::Nogroup>()) || 202 "NOTINBRANCH" >> 203 construct<OmpClause>(construct<OmpClause::Notinbranch>()) || 204 "NOWAIT" >> construct<OmpClause>(construct<OmpNowait>()) || 205 "NUM_TASKS" >> construct<OmpClause>(construct<OmpClause::NumTasks>( 206 parenthesized(scalarIntExpr))) || 207 "NUM_TEAMS" >> construct<OmpClause>(construct<OmpClause::NumTeams>( 208 parenthesized(scalarIntExpr))) || 209 "NUM_THREADS" >> construct<OmpClause>(construct<OmpClause::NumThreads>( 210 parenthesized(scalarIntExpr))) || 211 "ORDERED" >> construct<OmpClause>(construct<OmpClause::Ordered>( 212 maybe(parenthesized(scalarIntConstantExpr)))) || 213 "PRIORITY" >> construct<OmpClause>(construct<OmpClause::Priority>( 214 parenthesized(scalarIntExpr))) || 215 "PRIVATE" >> construct<OmpClause>(construct<OmpClause::Private>( 216 parenthesized(Parser<OmpObjectList>{}))) || 217 "PROC_BIND" >> 218 construct<OmpClause>(parenthesized(Parser<OmpProcBindClause>{})) || 219 "REDUCTION" >> 220 construct<OmpClause>(parenthesized(Parser<OmpReductionClause>{})) || 221 "RELAXED" >> construct<OmpClause>(construct<OmpClause::Relaxed>()) || 222 "RELEASE" >> construct<OmpClause>(construct<OmpClause::Release>()) || 223 "SAFELEN" >> construct<OmpClause>(construct<OmpClause::Safelen>( 224 parenthesized(scalarIntConstantExpr))) || 225 "SCHEDULE" >> 226 construct<OmpClause>(parenthesized(Parser<OmpScheduleClause>{})) || 227 "SEQ_CST" >> construct<OmpClause>(construct<OmpClause::SeqCst>()) || 228 "SHARED" >> construct<OmpClause>(construct<OmpClause::Shared>( 229 parenthesized(Parser<OmpObjectList>{}))) || 230 "SIMD"_id >> construct<OmpClause>(construct<OmpClause::Simd>()) || 231 "SIMDLEN" >> construct<OmpClause>(construct<OmpClause::Simdlen>( 232 parenthesized(scalarIntConstantExpr))) || 233 "THREADS" >> construct<OmpClause>(construct<OmpClause::Threads>()) || 234 "THREAD_LIMIT" >> construct<OmpClause>(construct<OmpClause::ThreadLimit>( 235 parenthesized(scalarIntExpr))) || 236 "TO" >> construct<OmpClause>(construct<OmpClause::To>( 237 parenthesized(Parser<OmpObjectList>{}))) || 238 "USE_DEVICE_PTR" >> construct<OmpClause>(construct<OmpClause::UseDevicePtr>( 239 parenthesized(nonemptyList(name)))) || 240 "UNIFORM" >> construct<OmpClause>(construct<OmpClause::Uniform>( 241 parenthesized(nonemptyList(name)))) || 242 "UNTIED" >> construct<OmpClause>(construct<OmpClause::Untied>())) 243 244 // [Clause, [Clause], ...] 245 TYPE_PARSER(sourced(construct<OmpClauseList>( 246 many(maybe(","_tok) >> sourced(Parser<OmpClause>{}))))) 247 248 // 2.1 (variable | /common-block | array-sections) 249 TYPE_PARSER(construct<OmpObjectList>(nonemptyList(Parser<OmpObject>{}))) 250 251 // Omp directives enclosing do loop 252 TYPE_PARSER(sourced(construct<OmpLoopDirective>(first( 253 "DISTRIBUTE PARALLEL DO SIMD" >> 254 pure(llvm::omp::Directive::OMPD_distribute_parallel_do_simd), 255 "DISTRIBUTE PARALLEL DO" >> 256 pure(llvm::omp::Directive::OMPD_distribute_parallel_do), 257 "DISTRIBUTE SIMD" >> pure(llvm::omp::Directive::OMPD_distribute_simd), 258 "DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_distribute), 259 "DO SIMD" >> pure(llvm::omp::Directive::OMPD_do_simd), 260 "DO" >> pure(llvm::omp::Directive::OMPD_do), 261 "PARALLEL DO SIMD" >> pure(llvm::omp::Directive::OMPD_parallel_do_simd), 262 "PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_parallel_do), 263 "SIMD" >> pure(llvm::omp::Directive::OMPD_simd), 264 "TARGET PARALLEL DO SIMD" >> 265 pure(llvm::omp::Directive::OMPD_target_parallel_do_simd), 266 "TARGET PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_target_parallel_do), 267 "TARGET SIMD" >> pure(llvm::omp::Directive::OMPD_target_simd), 268 "TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD" >> 269 pure(llvm::omp::Directive:: 270 OMPD_target_teams_distribute_parallel_do_simd), 271 "TARGET TEAMS DISTRIBUTE PARALLEL DO" >> 272 pure(llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do), 273 "TARGET TEAMS DISTRIBUTE SIMD" >> 274 pure(llvm::omp::Directive::OMPD_target_teams_distribute_simd), 275 "TARGET TEAMS DISTRIBUTE" >> 276 pure(llvm::omp::Directive::OMPD_target_teams_distribute), 277 "TASKLOOP SIMD" >> pure(llvm::omp::Directive::OMPD_taskloop_simd), 278 "TASKLOOP" >> pure(llvm::omp::Directive::OMPD_taskloop), 279 "TEAMS DISTRIBUTE PARALLEL DO SIMD" >> 280 pure(llvm::omp::Directive::OMPD_teams_distribute_parallel_do_simd), 281 "TEAMS DISTRIBUTE PARALLEL DO" >> 282 pure(llvm::omp::Directive::OMPD_teams_distribute_parallel_do), 283 "TEAMS DISTRIBUTE SIMD" >> 284 pure(llvm::omp::Directive::OMPD_teams_distribute_simd), 285 "TEAMS DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_teams_distribute))))) 286 287 TYPE_PARSER(sourced(construct<OmpBeginLoopDirective>( 288 sourced(Parser<OmpLoopDirective>{}), Parser<OmpClauseList>{}))) 289 290 // 2.14.1 construct-type-clause -> PARALLEL | SECTIONS | DO | TASKGROUP 291 TYPE_PARSER(sourced(construct<OmpCancelType>( 292 first("PARALLEL" >> pure(OmpCancelType::Type::Parallel), 293 "SECTIONS" >> pure(OmpCancelType::Type::Sections), 294 "DO" >> pure(OmpCancelType::Type::Do), 295 "TASKGROUP" >> pure(OmpCancelType::Type::Taskgroup))))) 296 297 // 2.14.2 Cancellation Point construct 298 TYPE_PARSER(sourced(construct<OpenMPCancellationPointConstruct>( 299 verbatim("CANCELLATION POINT"_tok), Parser<OmpCancelType>{}))) 300 301 // 2.14.1 Cancel construct 302 TYPE_PARSER(sourced(construct<OpenMPCancelConstruct>(verbatim("CANCEL"_tok), 303 Parser<OmpCancelType>{}, maybe("IF" >> parenthesized(scalarLogicalExpr))))) 304 305 // 2.17.7 Atomic construct/2.17.8 Flush construct [OpenMP 5.0] 306 // memory-order-clause -> 307 // seq_cst 308 // acq_rel 309 // release 310 // acquire 311 // relaxed 312 TYPE_PARSER(sourced(construct<OmpMemoryOrderClause>( 313 sourced("SEQ_CST" >> construct<OmpClause>(construct<OmpClause::SeqCst>()) || 314 "ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) || 315 "RELEASE" >> construct<OmpClause>(construct<OmpClause::Release>()) || 316 "ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) || 317 "RELAXED" >> construct<OmpClause>(construct<OmpClause::Relaxed>()))))) 318 319 TYPE_PARSER(sourced(construct<OpenMPFlushConstruct>(verbatim("FLUSH"_tok), 320 maybe(Parser<OmpMemoryOrderClause>{}), 321 maybe(parenthesized(Parser<OmpObjectList>{}))))) 322 323 // Simple Standalone Directives 324 TYPE_PARSER(sourced(construct<OmpSimpleStandaloneDirective>(first( 325 "BARRIER" >> pure(llvm::omp::Directive::OMPD_barrier), 326 "ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), 327 "TARGET ENTER DATA" >> pure(llvm::omp::Directive::OMPD_target_enter_data), 328 "TARGET EXIT DATA" >> pure(llvm::omp::Directive::OMPD_target_exit_data), 329 "TARGET UPDATE" >> pure(llvm::omp::Directive::OMPD_target_update), 330 "TASKWAIT" >> pure(llvm::omp::Directive::OMPD_taskwait), 331 "TASKYIELD" >> pure(llvm::omp::Directive::OMPD_taskyield))))) 332 333 TYPE_PARSER(sourced(construct<OpenMPSimpleStandaloneConstruct>( 334 Parser<OmpSimpleStandaloneDirective>{}, Parser<OmpClauseList>{}))) 335 336 // Standalone Constructs 337 TYPE_PARSER( 338 sourced(construct<OpenMPStandaloneConstruct>( 339 Parser<OpenMPSimpleStandaloneConstruct>{}) || 340 construct<OpenMPStandaloneConstruct>(Parser<OpenMPFlushConstruct>{}) || 341 construct<OpenMPStandaloneConstruct>(Parser<OpenMPCancelConstruct>{}) || 342 construct<OpenMPStandaloneConstruct>( 343 Parser<OpenMPCancellationPointConstruct>{})) / 344 endOfLine) 345 346 // Directives enclosing structured-block 347 TYPE_PARSER(construct<OmpBlockDirective>(first( 348 "MASTER" >> pure(llvm::omp::Directive::OMPD_master), 349 "ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), 350 "PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare), 351 "PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel), 352 "SINGLE" >> pure(llvm::omp::Directive::OMPD_single), 353 "TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data), 354 "TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel), 355 "TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams), 356 "TARGET" >> pure(llvm::omp::Directive::OMPD_target), 357 "TASK"_id >> pure(llvm::omp::Directive::OMPD_task), 358 "TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup), 359 "TEAMS" >> pure(llvm::omp::Directive::OMPD_teams), 360 "WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare)))) 361 362 TYPE_PARSER(sourced(construct<OmpBeginBlockDirective>( 363 sourced(Parser<OmpBlockDirective>{}), Parser<OmpClauseList>{}))) 364 365 TYPE_PARSER(construct<OmpReductionInitializerClause>( 366 "INITIALIZER" >> parenthesized("OMP_PRIV =" >> expr))) 367 368 // 2.16 Declare Reduction Construct 369 TYPE_PARSER(sourced(construct<OpenMPDeclareReductionConstruct>( 370 verbatim("DECLARE REDUCTION"_tok), 371 "(" >> Parser<OmpReductionOperator>{} / ":", 372 nonemptyList(Parser<DeclarationTypeSpec>{}) / ":", 373 Parser<OmpReductionCombiner>{} / ")", 374 maybe(Parser<OmpReductionInitializerClause>{})))) 375 376 // declare-target with list 377 TYPE_PARSER(sourced(construct<OmpDeclareTargetWithList>( 378 parenthesized(Parser<OmpObjectList>{})))) 379 380 // declare-target with clause 381 TYPE_PARSER( 382 sourced(construct<OmpDeclareTargetWithClause>(Parser<OmpClauseList>{}))) 383 384 // declare-target-specifier 385 TYPE_PARSER( 386 construct<OmpDeclareTargetSpecifier>(Parser<OmpDeclareTargetWithList>{}) || 387 construct<OmpDeclareTargetSpecifier>(Parser<OmpDeclareTargetWithClause>{})) 388 389 // 2.10.6 Declare Target Construct 390 TYPE_PARSER(sourced(construct<OpenMPDeclareTargetConstruct>( 391 verbatim("DECLARE TARGET"_tok), Parser<OmpDeclareTargetSpecifier>{}))) 392 393 TYPE_PARSER(construct<OmpReductionCombiner>(Parser<AssignmentStmt>{}) || 394 construct<OmpReductionCombiner>( 395 construct<OmpReductionCombiner::FunctionCombiner>( 396 construct<Call>(Parser<ProcedureDesignator>{}, 397 parenthesized(optionalList(actualArgSpec)))))) 398 399 // 2.17.7 atomic -> ATOMIC [clause [,]] atomic-clause [[,] clause] | 400 // ATOMIC [clause] 401 // clause -> memory-order-clause | HINT(hint-expression) 402 // memory-order-clause -> SEQ_CST | ACQ_REL | RELEASE | ACQUIRE | RELAXED 403 // atomic-clause -> READ | WRITE | UPDATE | CAPTURE 404 405 // OMP END ATOMIC 406 TYPE_PARSER(construct<OmpEndAtomic>(startOmpLine >> "END ATOMIC"_tok)) 407 408 // OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] READ [MEMORY-ORDER-CLAUSE-LIST] 409 TYPE_PARSER("ATOMIC" >> 410 construct<OmpAtomicRead>(Parser<OmpClauseList>{} / maybe(","_tok), 411 verbatim("READ"_tok), Parser<OmpClauseList>{} / endOmpLine, 412 statement(assignmentStmt), maybe(Parser<OmpEndAtomic>{} / endOmpLine))) 413 414 // OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] CAPTURE [MEMORY-ORDER-CLAUSE-LIST] 415 TYPE_PARSER("ATOMIC" >> 416 construct<OmpAtomicCapture>(Parser<OmpClauseList>{} / maybe(","_tok), 417 verbatim("CAPTURE"_tok), Parser<OmpClauseList>{} / endOmpLine, 418 statement(assignmentStmt), statement(assignmentStmt), 419 Parser<OmpEndAtomic>{} / endOmpLine)) 420 421 // OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] UPDATE [MEMORY-ORDER-CLAUSE-LIST] 422 TYPE_PARSER("ATOMIC" >> 423 construct<OmpAtomicUpdate>(Parser<OmpClauseList>{} / maybe(","_tok), 424 verbatim("UPDATE"_tok), Parser<OmpClauseList>{} / endOmpLine, 425 statement(assignmentStmt), maybe(Parser<OmpEndAtomic>{} / endOmpLine))) 426 427 // OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] 428 TYPE_PARSER(construct<OmpAtomic>(verbatim("ATOMIC"_tok), 429 Parser<OmpClauseList>{} / endOmpLine, statement(assignmentStmt), 430 maybe(Parser<OmpEndAtomic>{} / endOmpLine))) 431 432 // OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] WRITE [MEMORY-ORDER-CLAUSE-LIST] 433 TYPE_PARSER("ATOMIC" >> 434 construct<OmpAtomicWrite>(Parser<OmpClauseList>{} / maybe(","_tok), 435 verbatim("WRITE"_tok), Parser<OmpClauseList>{} / endOmpLine, 436 statement(assignmentStmt), maybe(Parser<OmpEndAtomic>{} / endOmpLine))) 437 438 // Atomic Construct 439 TYPE_PARSER(construct<OpenMPAtomicConstruct>(Parser<OmpAtomicRead>{}) || 440 construct<OpenMPAtomicConstruct>(Parser<OmpAtomicCapture>{}) || 441 construct<OpenMPAtomicConstruct>(Parser<OmpAtomicWrite>{}) || 442 construct<OpenMPAtomicConstruct>(Parser<OmpAtomicUpdate>{}) || 443 construct<OpenMPAtomicConstruct>(Parser<OmpAtomic>{})) 444 445 // 2.13.2 OMP CRITICAL 446 TYPE_PARSER(startOmpLine >> 447 sourced(construct<OmpEndCriticalDirective>( 448 verbatim("END CRITICAL"_tok), maybe(parenthesized(name)))) / 449 endOmpLine) 450 TYPE_PARSER(sourced(construct<OmpCriticalDirective>(verbatim("CRITICAL"_tok), 451 maybe(parenthesized(name)), maybe(Parser<OmpClause>{}))) / 452 endOmpLine) 453 454 TYPE_PARSER(construct<OpenMPCriticalConstruct>( 455 Parser<OmpCriticalDirective>{}, block, Parser<OmpEndCriticalDirective>{})) 456 457 // 2.8.2 Declare Simd construct 458 TYPE_PARSER( 459 sourced(construct<OpenMPDeclareSimdConstruct>(verbatim("DECLARE SIMD"_tok), 460 maybe(parenthesized(name)), Parser<OmpClauseList>{}))) 461 462 // 2.15.2 Threadprivate directive 463 TYPE_PARSER(sourced(construct<OpenMPThreadprivate>( 464 verbatim("THREADPRIVATE"_tok), parenthesized(Parser<OmpObjectList>{})))) 465 466 // Declarative constructs 467 TYPE_PARSER(startOmpLine >> 468 sourced(construct<OpenMPDeclarativeConstruct>( 469 Parser<OpenMPDeclareReductionConstruct>{}) || 470 construct<OpenMPDeclarativeConstruct>( 471 Parser<OpenMPDeclareSimdConstruct>{}) || 472 construct<OpenMPDeclarativeConstruct>( 473 Parser<OpenMPDeclareTargetConstruct>{}) || 474 construct<OpenMPDeclarativeConstruct>(Parser<OpenMPThreadprivate>{})) / 475 endOmpLine) 476 477 // Block Construct 478 TYPE_PARSER(construct<OpenMPBlockConstruct>( 479 Parser<OmpBeginBlockDirective>{} / endOmpLine, block, 480 Parser<OmpEndBlockDirective>{} / endOmpLine)) 481 482 // OMP SECTIONS Directive 483 TYPE_PARSER(construct<OmpSectionsDirective>(first( 484 "SECTIONS" >> pure(llvm::omp::Directive::OMPD_sections), 485 "PARALLEL SECTIONS" >> pure(llvm::omp::Directive::OMPD_parallel_sections)))) 486 487 // OMP BEGIN and END SECTIONS Directive 488 TYPE_PARSER(sourced(construct<OmpBeginSectionsDirective>( 489 sourced(Parser<OmpSectionsDirective>{}), Parser<OmpClauseList>{}))) 490 TYPE_PARSER( 491 startOmpLine >> sourced(construct<OmpEndSectionsDirective>( 492 sourced("END"_tok >> Parser<OmpSectionsDirective>{}), 493 Parser<OmpClauseList>{}))) 494 495 // OMP SECTION-BLOCK 496 TYPE_PARSER(maybe(startOmpLine >> "SECTION"_tok / endOmpLine) >> 497 construct<OmpSectionBlocks>( 498 nonemptySeparated(block, startOmpLine >> "SECTION"_tok / endOmpLine))) 499 500 // OMP SECTIONS (2.7.2), PARALLEL SECTIONS (2.11.2) 501 TYPE_PARSER(construct<OpenMPSectionsConstruct>( 502 Parser<OmpBeginSectionsDirective>{} / endOmpLine, 503 Parser<OmpSectionBlocks>{}, Parser<OmpEndSectionsDirective>{} / endOmpLine)) 504 505 TYPE_CONTEXT_PARSER("OpenMP construct"_en_US, 506 startOmpLine >> 507 first(construct<OpenMPConstruct>(Parser<OpenMPSectionsConstruct>{}), 508 construct<OpenMPConstruct>(Parser<OpenMPLoopConstruct>{}), 509 construct<OpenMPConstruct>(Parser<OpenMPBlockConstruct>{}), 510 // OpenMPBlockConstruct is attempted before 511 // OpenMPStandaloneConstruct to resolve !$OMP ORDERED 512 construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}), 513 construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}), 514 construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{}))) 515 516 // END OMP Block directives 517 TYPE_PARSER( 518 startOmpLine >> sourced(construct<OmpEndBlockDirective>( 519 sourced("END"_tok >> Parser<OmpBlockDirective>{}), 520 Parser<OmpClauseList>{}))) 521 522 // END OMP Loop directives 523 TYPE_PARSER( 524 startOmpLine >> sourced(construct<OmpEndLoopDirective>( 525 sourced("END"_tok >> Parser<OmpLoopDirective>{}), 526 Parser<OmpClauseList>{}))) 527 528 TYPE_PARSER(construct<OpenMPLoopConstruct>( 529 Parser<OmpBeginLoopDirective>{} / endOmpLine)) 530 } // namespace Fortran::parser 531