1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
//===-- flang/Parser/openmp-utils.cpp -------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// Common OpenMP utilities.
//
//===----------------------------------------------------------------------===//
#include "flang/Parser/openmp-utils.h"
#include "flang/Common/indirection.h"
#include "flang/Common/template.h"
#include "flang/Common/visit.h"
#include <tuple>
#include <type_traits>
#include <variant>
namespace Fortran::parser::omp {
const OmpObjectList *GetOmpObjectList(const OmpClause &clause) {
// Clauses with OmpObjectList as its data member
using MemberObjectListClauses = std::tuple<OmpClause::Copyin,
OmpClause::Copyprivate, OmpClause::Exclusive, OmpClause::Firstprivate,
OmpClause::HasDeviceAddr, OmpClause::Inclusive, OmpClause::IsDevicePtr,
OmpClause::Link, OmpClause::Private, OmpClause::Shared,
OmpClause::UseDeviceAddr, OmpClause::UseDevicePtr>;
// Clauses with OmpObjectList in the tuple
using TupleObjectListClauses = std::tuple<OmpClause::AdjustArgs,
OmpClause::Affinity, OmpClause::Aligned, OmpClause::Allocate,
OmpClause::Enter, OmpClause::From, OmpClause::InReduction,
OmpClause::Lastprivate, OmpClause::Linear, OmpClause::Map,
OmpClause::Reduction, OmpClause::TaskReduction, OmpClause::To>;
// TODO:: Generate the tuples using TableGen.
return common::visit(
common::visitors{
[&](const OmpClause::Depend &x) -> const OmpObjectList * {
if (auto *taskDep{std::get_if<OmpDependClause::TaskDep>(&x.v.u)}) {
return &std::get<OmpObjectList>(taskDep->t);
} else {
return nullptr;
}
},
[&](const auto &x) -> const OmpObjectList * {
using Ty = std::decay_t<decltype(x)>;
if constexpr (common::HasMember<Ty, MemberObjectListClauses>) {
return &x.v;
} else if constexpr (common::HasMember<Ty,
TupleObjectListClauses>) {
return &std::get<OmpObjectList>(x.v.t);
} else {
return nullptr;
}
},
},
clause.u);
}
const BlockConstruct *GetFortranBlockConstruct(
const ExecutionPartConstruct &epc) {
// ExecutionPartConstruct -> ExecutableConstruct
// -> Indirection<BlockConstruct>
if (auto *ec{std::get_if<ExecutableConstruct>(&epc.u)}) {
if (auto *ind{std::get_if<common::Indirection<BlockConstruct>>(&ec->u)}) {
return &ind->value();
}
}
return nullptr;
}
} // namespace Fortran::parser::omp
|