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