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>{} / ":", Parser<OmpObjectList>{})) 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" >> construct<OmpClause>(construct<OmpClause::Allocate>( 161 parenthesized(Parser<OmpAllocateClause>{}))) || 162 "ALLOCATOR" >> construct<OmpClause>(construct<OmpClause::Allocator>( 163 parenthesized(scalarIntExpr))) || 164 "COLLAPSE" >> construct<OmpClause>(construct<OmpClause::Collapse>( 165 parenthesized(scalarIntConstantExpr))) || 166 "COPYIN" >> construct<OmpClause>(construct<OmpClause::Copyin>( 167 parenthesized(Parser<OmpObjectList>{}))) || 168 "COPYPRIVATE" >> construct<OmpClause>(construct<OmpClause::Copyprivate>( 169 (parenthesized(Parser<OmpObjectList>{})))) || 170 "DEFAULT"_id >> construct<OmpClause>(construct<OmpClause::Default>( 171 parenthesized(Parser<OmpDefaultClause>{}))) || 172 "DEFAULTMAP" >> 173 construct<OmpClause>(parenthesized(Parser<OmpDefaultmapClause>{})) || 174 "DEPEND" >> 175 construct<OmpClause>(parenthesized(Parser<OmpDependClause>{})) || 176 "DEVICE" >> construct<OmpClause>(construct<OmpClause::Device>( 177 parenthesized(scalarIntExpr))) || 178 "DIST_SCHEDULE" >> 179 construct<OmpClause>(construct<OmpClause::DistSchedule>( 180 parenthesized("STATIC" >> maybe("," >> scalarIntExpr)))) || 181 "FINAL" >> construct<OmpClause>(construct<OmpClause::Final>( 182 parenthesized(scalarLogicalExpr))) || 183 "FIRSTPRIVATE" >> construct<OmpClause>(construct<OmpClause::Firstprivate>( 184 parenthesized(Parser<OmpObjectList>{}))) || 185 "FROM" >> construct<OmpClause>(construct<OmpClause::From>( 186 parenthesized(Parser<OmpObjectList>{}))) || 187 "GRAINSIZE" >> construct<OmpClause>(construct<OmpClause::Grainsize>( 188 parenthesized(scalarIntExpr))) || 189 "HINT" >> construct<OmpClause>( 190 construct<OmpClause::Hint>(parenthesized(constantExpr))) || 191 "IF" >> construct<OmpClause>(parenthesized(Parser<OmpIfClause>{})) || 192 "INBRANCH" >> construct<OmpClause>(construct<OmpClause::Inbranch>()) || 193 "IS_DEVICE_PTR" >> construct<OmpClause>(construct<OmpClause::IsDevicePtr>( 194 parenthesized(nonemptyList(name)))) || 195 "LASTPRIVATE" >> construct<OmpClause>(construct<OmpClause::Lastprivate>( 196 parenthesized(Parser<OmpObjectList>{}))) || 197 "LINEAR" >> 198 construct<OmpClause>(parenthesized(Parser<OmpLinearClause>{})) || 199 "LINK" >> construct<OmpClause>(construct<OmpClause::Link>( 200 parenthesized(Parser<OmpObjectList>{}))) || 201 "MAP" >> construct<OmpClause>(parenthesized(Parser<OmpMapClause>{})) || 202 "MERGEABLE" >> construct<OmpClause>(construct<OmpClause::Mergeable>()) || 203 "NOGROUP" >> construct<OmpClause>(construct<OmpClause::Nogroup>()) || 204 "NOTINBRANCH" >> 205 construct<OmpClause>(construct<OmpClause::Notinbranch>()) || 206 "NOWAIT" >> construct<OmpClause>(construct<OmpClause::Nowait>()) || 207 "NUM_TASKS" >> construct<OmpClause>(construct<OmpClause::NumTasks>( 208 parenthesized(scalarIntExpr))) || 209 "NUM_TEAMS" >> construct<OmpClause>(construct<OmpClause::NumTeams>( 210 parenthesized(scalarIntExpr))) || 211 "NUM_THREADS" >> construct<OmpClause>(construct<OmpClause::NumThreads>( 212 parenthesized(scalarIntExpr))) || 213 "ORDERED" >> construct<OmpClause>(construct<OmpClause::Ordered>( 214 maybe(parenthesized(scalarIntConstantExpr)))) || 215 "PRIORITY" >> construct<OmpClause>(construct<OmpClause::Priority>( 216 parenthesized(scalarIntExpr))) || 217 "PRIVATE" >> construct<OmpClause>(construct<OmpClause::Private>( 218 parenthesized(Parser<OmpObjectList>{}))) || 219 "PROC_BIND" >> construct<OmpClause>(construct<OmpClause::ProcBind>( 220 parenthesized(Parser<OmpProcBindClause>{}))) || 221 "REDUCTION" >> construct<OmpClause>(construct<OmpClause::Reduction>( 222 parenthesized(Parser<OmpReductionClause>{}))) || 223 "TASK_REDUCTION" >> 224 construct<OmpClause>(construct<OmpClause::TaskReduction>( 225 parenthesized(Parser<OmpReductionClause>{}))) || 226 "RELAXED" >> construct<OmpClause>(construct<OmpClause::Relaxed>()) || 227 "RELEASE" >> construct<OmpClause>(construct<OmpClause::Release>()) || 228 "SAFELEN" >> construct<OmpClause>(construct<OmpClause::Safelen>( 229 parenthesized(scalarIntConstantExpr))) || 230 "SCHEDULE" >> 231 construct<OmpClause>(parenthesized(Parser<OmpScheduleClause>{})) || 232 "SEQ_CST" >> construct<OmpClause>(construct<OmpClause::SeqCst>()) || 233 "SHARED" >> construct<OmpClause>(construct<OmpClause::Shared>( 234 parenthesized(Parser<OmpObjectList>{}))) || 235 "SIMD"_id >> construct<OmpClause>(construct<OmpClause::Simd>()) || 236 "SIMDLEN" >> construct<OmpClause>(construct<OmpClause::Simdlen>( 237 parenthesized(scalarIntConstantExpr))) || 238 "THREADS" >> construct<OmpClause>(construct<OmpClause::Threads>()) || 239 "THREAD_LIMIT" >> construct<OmpClause>(construct<OmpClause::ThreadLimit>( 240 parenthesized(scalarIntExpr))) || 241 "TO" >> construct<OmpClause>(construct<OmpClause::To>( 242 parenthesized(Parser<OmpObjectList>{}))) || 243 "USE_DEVICE_PTR" >> construct<OmpClause>(construct<OmpClause::UseDevicePtr>( 244 parenthesized(nonemptyList(name)))) || 245 "UNIFORM" >> construct<OmpClause>(construct<OmpClause::Uniform>( 246 parenthesized(nonemptyList(name)))) || 247 "UNTIED" >> construct<OmpClause>(construct<OmpClause::Untied>())) 248 249 // [Clause, [Clause], ...] 250 TYPE_PARSER(sourced(construct<OmpClauseList>( 251 many(maybe(","_tok) >> sourced(Parser<OmpClause>{}))))) 252 253 // 2.1 (variable | /common-block | array-sections) 254 TYPE_PARSER(construct<OmpObjectList>(nonemptyList(Parser<OmpObject>{}))) 255 256 // Omp directives enclosing do loop 257 TYPE_PARSER(sourced(construct<OmpLoopDirective>(first( 258 "DISTRIBUTE PARALLEL DO SIMD" >> 259 pure(llvm::omp::Directive::OMPD_distribute_parallel_do_simd), 260 "DISTRIBUTE PARALLEL DO" >> 261 pure(llvm::omp::Directive::OMPD_distribute_parallel_do), 262 "DISTRIBUTE SIMD" >> pure(llvm::omp::Directive::OMPD_distribute_simd), 263 "DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_distribute), 264 "DO SIMD" >> pure(llvm::omp::Directive::OMPD_do_simd), 265 "DO" >> pure(llvm::omp::Directive::OMPD_do), 266 "PARALLEL DO SIMD" >> pure(llvm::omp::Directive::OMPD_parallel_do_simd), 267 "PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_parallel_do), 268 "SIMD" >> pure(llvm::omp::Directive::OMPD_simd), 269 "TARGET PARALLEL DO SIMD" >> 270 pure(llvm::omp::Directive::OMPD_target_parallel_do_simd), 271 "TARGET PARALLEL DO" >> pure(llvm::omp::Directive::OMPD_target_parallel_do), 272 "TARGET SIMD" >> pure(llvm::omp::Directive::OMPD_target_simd), 273 "TARGET TEAMS DISTRIBUTE PARALLEL DO SIMD" >> 274 pure(llvm::omp::Directive:: 275 OMPD_target_teams_distribute_parallel_do_simd), 276 "TARGET TEAMS DISTRIBUTE PARALLEL DO" >> 277 pure(llvm::omp::Directive::OMPD_target_teams_distribute_parallel_do), 278 "TARGET TEAMS DISTRIBUTE SIMD" >> 279 pure(llvm::omp::Directive::OMPD_target_teams_distribute_simd), 280 "TARGET TEAMS DISTRIBUTE" >> 281 pure(llvm::omp::Directive::OMPD_target_teams_distribute), 282 "TASKLOOP SIMD" >> pure(llvm::omp::Directive::OMPD_taskloop_simd), 283 "TASKLOOP" >> pure(llvm::omp::Directive::OMPD_taskloop), 284 "TEAMS DISTRIBUTE PARALLEL DO SIMD" >> 285 pure(llvm::omp::Directive::OMPD_teams_distribute_parallel_do_simd), 286 "TEAMS DISTRIBUTE PARALLEL DO" >> 287 pure(llvm::omp::Directive::OMPD_teams_distribute_parallel_do), 288 "TEAMS DISTRIBUTE SIMD" >> 289 pure(llvm::omp::Directive::OMPD_teams_distribute_simd), 290 "TEAMS DISTRIBUTE" >> pure(llvm::omp::Directive::OMPD_teams_distribute))))) 291 292 TYPE_PARSER(sourced(construct<OmpBeginLoopDirective>( 293 sourced(Parser<OmpLoopDirective>{}), Parser<OmpClauseList>{}))) 294 295 // 2.14.1 construct-type-clause -> PARALLEL | SECTIONS | DO | TASKGROUP 296 TYPE_PARSER(sourced(construct<OmpCancelType>( 297 first("PARALLEL" >> pure(OmpCancelType::Type::Parallel), 298 "SECTIONS" >> pure(OmpCancelType::Type::Sections), 299 "DO" >> pure(OmpCancelType::Type::Do), 300 "TASKGROUP" >> pure(OmpCancelType::Type::Taskgroup))))) 301 302 // 2.14.2 Cancellation Point construct 303 TYPE_PARSER(sourced(construct<OpenMPCancellationPointConstruct>( 304 verbatim("CANCELLATION POINT"_tok), Parser<OmpCancelType>{}))) 305 306 // 2.14.1 Cancel construct 307 TYPE_PARSER(sourced(construct<OpenMPCancelConstruct>(verbatim("CANCEL"_tok), 308 Parser<OmpCancelType>{}, maybe("IF" >> parenthesized(scalarLogicalExpr))))) 309 310 // 2.17.7 Atomic construct/2.17.8 Flush construct [OpenMP 5.0] 311 // memory-order-clause -> 312 // seq_cst 313 // acq_rel 314 // release 315 // acquire 316 // relaxed 317 TYPE_PARSER(sourced(construct<OmpMemoryOrderClause>( 318 sourced("SEQ_CST" >> construct<OmpClause>(construct<OmpClause::SeqCst>()) || 319 "ACQ_REL" >> construct<OmpClause>(construct<OmpClause::AcqRel>()) || 320 "RELEASE" >> construct<OmpClause>(construct<OmpClause::Release>()) || 321 "ACQUIRE" >> construct<OmpClause>(construct<OmpClause::Acquire>()) || 322 "RELAXED" >> construct<OmpClause>(construct<OmpClause::Relaxed>()))))) 323 324 // 2.17.7 Atomic construct 325 // atomic-clause -> memory-order-clause | HINT(hint-expression) 326 TYPE_PARSER(sourced(construct<OmpAtomicClause>( 327 construct<OmpAtomicClause>(Parser<OmpMemoryOrderClause>{}) || 328 construct<OmpAtomicClause>("HINT" >> 329 sourced(construct<OmpClause>( 330 construct<OmpClause::Hint>(parenthesized(constantExpr)))))))) 331 332 // atomic-clause-list -> [atomic-clause, [atomic-clause], ...] 333 TYPE_PARSER(sourced(construct<OmpAtomicClauseList>( 334 many(maybe(","_tok) >> sourced(Parser<OmpAtomicClause>{}))))) 335 336 TYPE_PARSER(sourced(construct<OpenMPFlushConstruct>(verbatim("FLUSH"_tok), 337 many(maybe(","_tok) >> sourced(Parser<OmpMemoryOrderClause>{})), 338 maybe(parenthesized(Parser<OmpObjectList>{}))))) 339 340 // Simple Standalone Directives 341 TYPE_PARSER(sourced(construct<OmpSimpleStandaloneDirective>(first( 342 "BARRIER" >> pure(llvm::omp::Directive::OMPD_barrier), 343 "ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), 344 "TARGET ENTER DATA" >> pure(llvm::omp::Directive::OMPD_target_enter_data), 345 "TARGET EXIT DATA" >> pure(llvm::omp::Directive::OMPD_target_exit_data), 346 "TARGET UPDATE" >> pure(llvm::omp::Directive::OMPD_target_update), 347 "TASKWAIT" >> pure(llvm::omp::Directive::OMPD_taskwait), 348 "TASKYIELD" >> pure(llvm::omp::Directive::OMPD_taskyield))))) 349 350 TYPE_PARSER(sourced(construct<OpenMPSimpleStandaloneConstruct>( 351 Parser<OmpSimpleStandaloneDirective>{}, Parser<OmpClauseList>{}))) 352 353 // Standalone Constructs 354 TYPE_PARSER( 355 sourced(construct<OpenMPStandaloneConstruct>( 356 Parser<OpenMPSimpleStandaloneConstruct>{}) || 357 construct<OpenMPStandaloneConstruct>(Parser<OpenMPFlushConstruct>{}) || 358 construct<OpenMPStandaloneConstruct>(Parser<OpenMPCancelConstruct>{}) || 359 construct<OpenMPStandaloneConstruct>( 360 Parser<OpenMPCancellationPointConstruct>{})) / 361 endOfLine) 362 363 // Directives enclosing structured-block 364 TYPE_PARSER(construct<OmpBlockDirective>(first( 365 "MASTER" >> pure(llvm::omp::Directive::OMPD_master), 366 "ORDERED" >> pure(llvm::omp::Directive::OMPD_ordered), 367 "PARALLEL WORKSHARE" >> pure(llvm::omp::Directive::OMPD_parallel_workshare), 368 "PARALLEL" >> pure(llvm::omp::Directive::OMPD_parallel), 369 "SINGLE" >> pure(llvm::omp::Directive::OMPD_single), 370 "TARGET DATA" >> pure(llvm::omp::Directive::OMPD_target_data), 371 "TARGET PARALLEL" >> pure(llvm::omp::Directive::OMPD_target_parallel), 372 "TARGET TEAMS" >> pure(llvm::omp::Directive::OMPD_target_teams), 373 "TARGET" >> pure(llvm::omp::Directive::OMPD_target), 374 "TASK"_id >> pure(llvm::omp::Directive::OMPD_task), 375 "TASKGROUP" >> pure(llvm::omp::Directive::OMPD_taskgroup), 376 "TEAMS" >> pure(llvm::omp::Directive::OMPD_teams), 377 "WORKSHARE" >> pure(llvm::omp::Directive::OMPD_workshare)))) 378 379 TYPE_PARSER(sourced(construct<OmpBeginBlockDirective>( 380 sourced(Parser<OmpBlockDirective>{}), Parser<OmpClauseList>{}))) 381 382 TYPE_PARSER(construct<OmpReductionInitializerClause>( 383 "INITIALIZER" >> parenthesized("OMP_PRIV =" >> expr))) 384 385 // 2.16 Declare Reduction Construct 386 TYPE_PARSER(sourced(construct<OpenMPDeclareReductionConstruct>( 387 verbatim("DECLARE REDUCTION"_tok), 388 "(" >> Parser<OmpReductionOperator>{} / ":", 389 nonemptyList(Parser<DeclarationTypeSpec>{}) / ":", 390 Parser<OmpReductionCombiner>{} / ")", 391 maybe(Parser<OmpReductionInitializerClause>{})))) 392 393 // declare-target with list 394 TYPE_PARSER(sourced(construct<OmpDeclareTargetWithList>( 395 parenthesized(Parser<OmpObjectList>{})))) 396 397 // declare-target with clause 398 TYPE_PARSER( 399 sourced(construct<OmpDeclareTargetWithClause>(Parser<OmpClauseList>{}))) 400 401 // declare-target-specifier 402 TYPE_PARSER( 403 construct<OmpDeclareTargetSpecifier>(Parser<OmpDeclareTargetWithList>{}) || 404 construct<OmpDeclareTargetSpecifier>(Parser<OmpDeclareTargetWithClause>{})) 405 406 // 2.10.6 Declare Target Construct 407 TYPE_PARSER(sourced(construct<OpenMPDeclareTargetConstruct>( 408 verbatim("DECLARE TARGET"_tok), Parser<OmpDeclareTargetSpecifier>{}))) 409 410 TYPE_PARSER(construct<OmpReductionCombiner>(Parser<AssignmentStmt>{}) || 411 construct<OmpReductionCombiner>( 412 construct<OmpReductionCombiner::FunctionCombiner>( 413 construct<Call>(Parser<ProcedureDesignator>{}, 414 parenthesized(optionalList(actualArgSpec)))))) 415 416 // 2.17.7 atomic -> ATOMIC [clause [,]] atomic-clause [[,] clause] | 417 // ATOMIC [clause] 418 // clause -> memory-order-clause | HINT(hint-expression) 419 // memory-order-clause -> SEQ_CST | ACQ_REL | RELEASE | ACQUIRE | RELAXED 420 // atomic-clause -> READ | WRITE | UPDATE | CAPTURE 421 422 // OMP END ATOMIC 423 TYPE_PARSER(construct<OmpEndAtomic>(startOmpLine >> "END ATOMIC"_tok)) 424 425 // OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] READ [MEMORY-ORDER-CLAUSE-LIST] 426 TYPE_PARSER("ATOMIC" >> 427 construct<OmpAtomicRead>(Parser<OmpAtomicClauseList>{} / maybe(","_tok), 428 verbatim("READ"_tok), Parser<OmpAtomicClauseList>{} / endOmpLine, 429 statement(assignmentStmt), maybe(Parser<OmpEndAtomic>{} / endOmpLine))) 430 431 // OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] CAPTURE [MEMORY-ORDER-CLAUSE-LIST] 432 TYPE_PARSER("ATOMIC" >> 433 construct<OmpAtomicCapture>(Parser<OmpAtomicClauseList>{} / maybe(","_tok), 434 verbatim("CAPTURE"_tok), Parser<OmpAtomicClauseList>{} / endOmpLine, 435 statement(assignmentStmt), statement(assignmentStmt), 436 Parser<OmpEndAtomic>{} / endOmpLine)) 437 438 // OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] UPDATE [MEMORY-ORDER-CLAUSE-LIST] 439 TYPE_PARSER("ATOMIC" >> 440 construct<OmpAtomicUpdate>(Parser<OmpAtomicClauseList>{} / maybe(","_tok), 441 verbatim("UPDATE"_tok), Parser<OmpAtomicClauseList>{} / endOmpLine, 442 statement(assignmentStmt), maybe(Parser<OmpEndAtomic>{} / endOmpLine))) 443 444 // OMP ATOMIC [atomic-clause-list] 445 TYPE_PARSER(construct<OmpAtomic>(verbatim("ATOMIC"_tok), 446 Parser<OmpAtomicClauseList>{} / endOmpLine, statement(assignmentStmt), 447 maybe(Parser<OmpEndAtomic>{} / endOmpLine))) 448 449 // OMP ATOMIC [MEMORY-ORDER-CLAUSE-LIST] WRITE [MEMORY-ORDER-CLAUSE-LIST] 450 TYPE_PARSER("ATOMIC" >> 451 construct<OmpAtomicWrite>(Parser<OmpAtomicClauseList>{} / maybe(","_tok), 452 verbatim("WRITE"_tok), Parser<OmpAtomicClauseList>{} / endOmpLine, 453 statement(assignmentStmt), maybe(Parser<OmpEndAtomic>{} / endOmpLine))) 454 455 // Atomic Construct 456 TYPE_PARSER(construct<OpenMPAtomicConstruct>(Parser<OmpAtomicRead>{}) || 457 construct<OpenMPAtomicConstruct>(Parser<OmpAtomicCapture>{}) || 458 construct<OpenMPAtomicConstruct>(Parser<OmpAtomicWrite>{}) || 459 construct<OpenMPAtomicConstruct>(Parser<OmpAtomicUpdate>{}) || 460 construct<OpenMPAtomicConstruct>(Parser<OmpAtomic>{})) 461 462 // 2.13.2 OMP CRITICAL 463 TYPE_PARSER(startOmpLine >> 464 sourced(construct<OmpEndCriticalDirective>( 465 verbatim("END CRITICAL"_tok), maybe(parenthesized(name)))) / 466 endOmpLine) 467 TYPE_PARSER(sourced(construct<OmpCriticalDirective>(verbatim("CRITICAL"_tok), 468 maybe(parenthesized(name)), maybe(Parser<OmpClause>{}))) / 469 endOmpLine) 470 471 TYPE_PARSER(construct<OpenMPCriticalConstruct>( 472 Parser<OmpCriticalDirective>{}, block, Parser<OmpEndCriticalDirective>{})) 473 474 // 2.11.3 Executable Allocate directive 475 TYPE_PARSER( 476 sourced(construct<OpenMPExecutableAllocate>(verbatim("ALLOCATE"_tok), 477 maybe(parenthesized(Parser<OmpObjectList>{})), Parser<OmpClauseList>{}, 478 maybe(nonemptyList(Parser<OpenMPDeclarativeAllocate>{})) / endOmpLine, 479 statement(allocateStmt)))) 480 481 // 2.8.2 Declare Simd construct 482 TYPE_PARSER( 483 sourced(construct<OpenMPDeclareSimdConstruct>(verbatim("DECLARE SIMD"_tok), 484 maybe(parenthesized(name)), Parser<OmpClauseList>{}))) 485 486 // 2.15.2 Threadprivate directive 487 TYPE_PARSER(sourced(construct<OpenMPThreadprivate>( 488 verbatim("THREADPRIVATE"_tok), parenthesized(Parser<OmpObjectList>{})))) 489 490 // 2.11.3 Declarative Allocate directive 491 TYPE_PARSER( 492 sourced(construct<OpenMPDeclarativeAllocate>(verbatim("ALLOCATE"_tok), 493 parenthesized(Parser<OmpObjectList>{}), Parser<OmpClauseList>{})) / 494 lookAhead(endOmpLine / !statement(allocateStmt))) 495 496 // Declarative constructs 497 TYPE_PARSER(startOmpLine >> 498 sourced(construct<OpenMPDeclarativeConstruct>( 499 Parser<OpenMPDeclareReductionConstruct>{}) || 500 construct<OpenMPDeclarativeConstruct>( 501 Parser<OpenMPDeclareSimdConstruct>{}) || 502 construct<OpenMPDeclarativeConstruct>( 503 Parser<OpenMPDeclareTargetConstruct>{}) || 504 construct<OpenMPDeclarativeConstruct>( 505 Parser<OpenMPDeclarativeAllocate>{}) || 506 construct<OpenMPDeclarativeConstruct>(Parser<OpenMPThreadprivate>{})) / 507 endOmpLine) 508 509 // Block Construct 510 TYPE_PARSER(construct<OpenMPBlockConstruct>( 511 Parser<OmpBeginBlockDirective>{} / endOmpLine, block, 512 Parser<OmpEndBlockDirective>{} / endOmpLine)) 513 514 // OMP SECTIONS Directive 515 TYPE_PARSER(construct<OmpSectionsDirective>(first( 516 "SECTIONS" >> pure(llvm::omp::Directive::OMPD_sections), 517 "PARALLEL SECTIONS" >> pure(llvm::omp::Directive::OMPD_parallel_sections)))) 518 519 // OMP BEGIN and END SECTIONS Directive 520 TYPE_PARSER(sourced(construct<OmpBeginSectionsDirective>( 521 sourced(Parser<OmpSectionsDirective>{}), Parser<OmpClauseList>{}))) 522 TYPE_PARSER( 523 startOmpLine >> sourced(construct<OmpEndSectionsDirective>( 524 sourced("END"_tok >> Parser<OmpSectionsDirective>{}), 525 Parser<OmpClauseList>{}))) 526 527 // OMP SECTION-BLOCK 528 TYPE_PARSER(maybe(startOmpLine >> "SECTION"_tok / endOmpLine) >> 529 construct<OmpSectionBlocks>( 530 nonemptySeparated(block, startOmpLine >> "SECTION"_tok / endOmpLine))) 531 532 // OMP SECTIONS (2.7.2), PARALLEL SECTIONS (2.11.2) 533 TYPE_PARSER(construct<OpenMPSectionsConstruct>( 534 Parser<OmpBeginSectionsDirective>{} / endOmpLine, 535 Parser<OmpSectionBlocks>{}, Parser<OmpEndSectionsDirective>{} / endOmpLine)) 536 537 TYPE_CONTEXT_PARSER("OpenMP construct"_en_US, 538 startOmpLine >> 539 first(construct<OpenMPConstruct>(Parser<OpenMPSectionsConstruct>{}), 540 construct<OpenMPConstruct>(Parser<OpenMPLoopConstruct>{}), 541 construct<OpenMPConstruct>(Parser<OpenMPBlockConstruct>{}), 542 // OpenMPBlockConstruct is attempted before 543 // OpenMPStandaloneConstruct to resolve !$OMP ORDERED 544 construct<OpenMPConstruct>(Parser<OpenMPStandaloneConstruct>{}), 545 construct<OpenMPConstruct>(Parser<OpenMPAtomicConstruct>{}), 546 construct<OpenMPConstruct>(Parser<OpenMPExecutableAllocate>{}), 547 construct<OpenMPConstruct>(Parser<OpenMPDeclarativeAllocate>{}), 548 construct<OpenMPConstruct>(Parser<OpenMPCriticalConstruct>{}))) 549 550 // END OMP Block directives 551 TYPE_PARSER( 552 startOmpLine >> sourced(construct<OmpEndBlockDirective>( 553 sourced("END"_tok >> Parser<OmpBlockDirective>{}), 554 Parser<OmpClauseList>{}))) 555 556 // END OMP Loop directives 557 TYPE_PARSER( 558 startOmpLine >> sourced(construct<OmpEndLoopDirective>( 559 sourced("END"_tok >> Parser<OmpLoopDirective>{}), 560 Parser<OmpClauseList>{}))) 561 562 TYPE_PARSER(construct<OpenMPLoopConstruct>( 563 Parser<OmpBeginLoopDirective>{} / endOmpLine)) 564 } // namespace Fortran::parser 565