| 1 |
//===-- Clauses.cpp -- OpenMP clause handling -----------------------------===// |
| 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 |
#include "Clauses.h" |
| 10 |
|
| 11 |
#include "flang/Common/idioms.h" |
| 12 |
#include "flang/Evaluate/expression.h" |
| 13 |
#include "flang/Parser/parse-tree.h" |
| 14 |
#include "flang/Semantics/expression.h" |
| 15 |
#include "flang/Semantics/symbol.h" |
| 16 |
|
| 17 |
#include "llvm/Frontend/OpenMP/OMPConstants.h" |
| 18 |
|
| 19 |
#include <list> |
| 20 |
#include <optional> |
| 21 |
#include <tuple> |
| 22 |
#include <utility> |
| 23 |
#include <variant> |
| 24 |
|
| 25 |
namespace detail { |
| 26 |
template <typename C> |
| 27 |
llvm::omp::Clause getClauseIdForClass(C &&) { |
| 28 |
using namespace Fortran; |
| 29 |
using A = llvm::remove_cvref_t<C>; // A is referenced in OMP.inc |
| 30 |
// The code included below contains a sequence of checks like the following |
| 31 |
// for each OpenMP clause |
| 32 |
// if constexpr (std::is_same_v<A, parser::OmpClause::AcqRel>) |
| 33 |
// return llvm::omp::Clause::OMPC_acq_rel; |
| 34 |
// [...] |
| 35 |
#define GEN_FLANG_CLAUSE_PARSER_KIND_MAP |
| 36 |
#include "llvm/Frontend/OpenMP/OMP.inc" |
| 37 |
} |
| 38 |
} // namespace detail |
| 39 |
|
| 40 |
static llvm::omp::Clause getClauseId(const Fortran::parser::OmpClause &clause) { |
| 41 |
return Fortran::common::visit( |
| 42 |
[](auto &&s) { return detail::getClauseIdForClass(s); }, clause.u); |
| 43 |
} |
| 44 |
|
| 45 |
namespace Fortran::lower::omp { |
| 46 |
using SymbolWithDesignator = std::tuple<semantics::Symbol *, MaybeExpr>; |
| 47 |
|
| 48 |
struct SymbolAndDesignatorExtractor { |
| 49 |
template <typename T> |
| 50 |
static T &&AsRvalueRef(T &&t) { |
| 51 |
return std::move(t); |
| 52 |
} |
| 53 |
template <typename T> |
| 54 |
static T AsRvalueRef(const T &t) { |
| 55 |
return t; |
| 56 |
} |
| 57 |
|
| 58 |
static semantics::Symbol *symbol_addr(const evaluate::SymbolRef &ref) { |
| 59 |
// Symbols cannot be created after semantic checks, so all symbol |
| 60 |
// pointers that are non-null must point to one of those pre-existing |
| 61 |
// objects. Throughout the code, symbols are often pointed to by |
| 62 |
// non-const pointers, so there is no harm in casting the constness |
| 63 |
// away. |
| 64 |
return const_cast<semantics::Symbol *>(&ref.get()); |
| 65 |
} |
| 66 |
|
| 67 |
template <typename T> |
| 68 |
static SymbolWithDesignator visit(T &&) { |
| 69 |
// Use this to see missing overloads: |
| 70 |
// llvm::errs() << "NULL: " << __PRETTY_FUNCTION__ << '\n'; |
| 71 |
return SymbolWithDesignator{}; |
| 72 |
} |
| 73 |
|
| 74 |
template <typename T> |
| 75 |
static SymbolWithDesignator visit(const evaluate::Designator<T> &e) { |
| 76 |
return std::make_tuple(symbol_addr(*e.GetLastSymbol()), |
| 77 |
evaluate::AsGenericExpr(AsRvalueRef(e))); |
| 78 |
} |
| 79 |
|
| 80 |
static SymbolWithDesignator visit(const evaluate::ProcedureDesignator &e) { |
| 81 |
return std::make_tuple(symbol_addr(*e.GetSymbol()), std::nullopt); |
| 82 |
} |
| 83 |
|
| 84 |
template <typename T> |
| 85 |
static SymbolWithDesignator visit(const evaluate::Expr<T> &e) { |
| 86 |
return Fortran::common::visit([](auto &&s) { return visit(s); }, e.u); |
| 87 |
} |
| 88 |
|
| 89 |
static void verify(const SymbolWithDesignator &sd) { |
| 90 |
const semantics::Symbol *symbol = std::get<0>(sd); |
| 91 |
assert(symbol && "Expecting symbol"); |
| 92 |
auto &maybeDsg = std::get<1>(sd); |
| 93 |
if (!maybeDsg) |
| 94 |
return; // Symbol with no designator -> OK |
| 95 |
std::optional<evaluate::DataRef> maybeRef = |
| 96 |
evaluate::ExtractDataRef(*maybeDsg); |
| 97 |
if (maybeRef) { |
| 98 |
if (&maybeRef->GetLastSymbol() == symbol) |
| 99 |
return; // Symbol with a designator for it -> OK |
| 100 |
llvm_unreachable("Expecting designator for given symbol"); |
| 101 |
} else { |
| 102 |
// This could still be a Substring or ComplexPart, but at least Substring |
| 103 |
// is not allowed in OpenMP. |
| 104 |
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
| 105 |
maybeDsg->dump(); |
| 106 |
#endif |
| 107 |
llvm_unreachable("Expecting DataRef designator"); |
| 108 |
} |
| 109 |
} |
| 110 |
}; |
| 111 |
|
| 112 |
SymbolWithDesignator getSymbolAndDesignator(const MaybeExpr &expr) { |
| 113 |
if (!expr) |
| 114 |
return SymbolWithDesignator{}; |
| 115 |
return Fortran::common::visit( |
| 116 |
[](auto &&s) { return SymbolAndDesignatorExtractor::visit(s); }, expr->u); |
| 117 |
} |
| 118 |
|
| 119 |
Object makeObject(const parser::Name &name, |
| 120 |
semantics::SemanticsContext &semaCtx) { |
| 121 |
assert(name.symbol && "Expecting Symbol"); |
| 122 |
return Object{name.symbol, std::nullopt}; |
| 123 |
} |
| 124 |
|
| 125 |
Object makeObject(const parser::Designator &dsg, |
| 126 |
semantics::SemanticsContext &semaCtx) { |
| 127 |
evaluate::ExpressionAnalyzer ea{semaCtx}; |
| 128 |
SymbolWithDesignator sd = getSymbolAndDesignator(ea.Analyze(dsg)); |
| 129 |
SymbolAndDesignatorExtractor::verify(sd); |
| 130 |
return Object{std::get<0>(sd), std::move(std::get<1>(sd))}; |
| 131 |
} |
| 132 |
|
| 133 |
Object makeObject(const parser::StructureComponent &comp, |
| 134 |
semantics::SemanticsContext &semaCtx) { |
| 135 |
evaluate::ExpressionAnalyzer ea{semaCtx}; |
| 136 |
SymbolWithDesignator sd = getSymbolAndDesignator(ea.Analyze(comp)); |
| 137 |
SymbolAndDesignatorExtractor::verify(sd); |
| 138 |
return Object{std::get<0>(sd), std::move(std::get<1>(sd))}; |
| 139 |
} |
| 140 |
|
| 141 |
Object makeObject(const parser::OmpObject &object, |
| 142 |
semantics::SemanticsContext &semaCtx) { |
| 143 |
// If object is a common block, expression analyzer won't be able to |
| 144 |
// do anything. |
| 145 |
if (const auto *name = std::get_if<parser::Name>(&object.u)) { |
| 146 |
assert(name->symbol && "Expecting Symbol"); |
| 147 |
return Object{name->symbol, std::nullopt}; |
| 148 |
} |
| 149 |
// OmpObject is std::variant<Designator, /*common block*/ Name>; |
| 150 |
return makeObject(std::get<parser::Designator>(object.u), semaCtx); |
| 151 |
} |
| 152 |
|
| 153 |
std::optional<Object> getBaseObject(const Object &object, |
| 154 |
semantics::SemanticsContext &semaCtx) { |
| 155 |
// If it's just the symbol, then there is no base. |
| 156 |
if (!object.ref()) |
| 157 |
return std::nullopt; |
| 158 |
|
| 159 |
auto maybeRef = evaluate::ExtractDataRef(*object.ref()); |
| 160 |
if (!maybeRef) |
| 161 |
return std::nullopt; |
| 162 |
|
| 163 |
evaluate::DataRef ref = *maybeRef; |
| 164 |
|
| 165 |
if (std::get_if<evaluate::SymbolRef>(&ref.u)) { |
| 166 |
return std::nullopt; |
| 167 |
} else if (auto *comp = std::get_if<evaluate::Component>(&ref.u)) { |
| 168 |
const evaluate::DataRef &base = comp->base(); |
| 169 |
return Object{ |
| 170 |
SymbolAndDesignatorExtractor::symbol_addr(base.GetLastSymbol()), |
| 171 |
evaluate::AsGenericExpr( |
| 172 |
SymbolAndDesignatorExtractor::AsRvalueRef(base))}; |
| 173 |
} else if (auto *arr = std::get_if<evaluate::ArrayRef>(&ref.u)) { |
| 174 |
const evaluate::NamedEntity &base = arr->base(); |
| 175 |
evaluate::ExpressionAnalyzer ea{semaCtx}; |
| 176 |
if (auto *comp = base.UnwrapComponent()) { |
| 177 |
return Object{SymbolAndDesignatorExtractor::symbol_addr(comp->symbol()), |
| 178 |
ea.Designate(evaluate::DataRef{ |
| 179 |
SymbolAndDesignatorExtractor::AsRvalueRef(*comp)})}; |
| 180 |
} else if (base.UnwrapSymbolRef()) { |
| 181 |
return std::nullopt; |
| 182 |
} |
| 183 |
} else { |
| 184 |
assert(std::holds_alternative<evaluate::CoarrayRef>(ref.u) && |
| 185 |
"Unexpected variant alternative"); |
| 186 |
llvm_unreachable("Coarray reference not supported at the moment"); |
| 187 |
} |
| 188 |
return std::nullopt; |
| 189 |
} |
| 190 |
|
| 191 |
// Helper macros |
| 192 |
#define MAKE_EMPTY_CLASS(cls, from_cls) \ |
| 193 |
cls make(const parser::OmpClause::from_cls &, \ |
| 194 |
semantics::SemanticsContext &) { \ |
| 195 |
static_assert(cls::EmptyTrait::value); \ |
| 196 |
return cls{}; \ |
| 197 |
} \ |
| 198 |
[[maybe_unused]] extern int xyzzy_semicolon_absorber |
| 199 |
|
| 200 |
#define MAKE_INCOMPLETE_CLASS(cls, from_cls) \ |
| 201 |
cls make(const parser::OmpClause::from_cls &, \ |
| 202 |
semantics::SemanticsContext &) { \ |
| 203 |
static_assert(cls::IncompleteTrait::value); \ |
| 204 |
return cls{}; \ |
| 205 |
} \ |
| 206 |
[[maybe_unused]] extern int xyzzy_semicolon_absorber |
| 207 |
|
| 208 |
#define MS(x, y) CLAUSET_SCOPED_ENUM_MEMBER_CONVERT(x, y) |
| 209 |
#define MU(x, y) CLAUSET_UNSCOPED_ENUM_MEMBER_CONVERT(x, y) |
| 210 |
|
| 211 |
namespace clause { |
| 212 |
MAKE_EMPTY_CLASS(AcqRel, AcqRel); |
| 213 |
MAKE_EMPTY_CLASS(Acquire, Acquire); |
| 214 |
MAKE_EMPTY_CLASS(Capture, Capture); |
| 215 |
MAKE_EMPTY_CLASS(Compare, Compare); |
| 216 |
MAKE_EMPTY_CLASS(DynamicAllocators, DynamicAllocators); |
| 217 |
MAKE_EMPTY_CLASS(Full, Full); |
| 218 |
MAKE_EMPTY_CLASS(Inbranch, Inbranch); |
| 219 |
MAKE_EMPTY_CLASS(Mergeable, Mergeable); |
| 220 |
MAKE_EMPTY_CLASS(Nogroup, Nogroup); |
| 221 |
// MAKE_EMPTY_CLASS(NoOpenmp, ); // missing-in-parser |
| 222 |
// MAKE_EMPTY_CLASS(NoOpenmpRoutines, ); // missing-in-parser |
| 223 |
// MAKE_EMPTY_CLASS(NoParallelism, ); // missing-in-parser |
| 224 |
MAKE_EMPTY_CLASS(Notinbranch, Notinbranch); |
| 225 |
MAKE_EMPTY_CLASS(Nowait, Nowait); |
| 226 |
MAKE_EMPTY_CLASS(OmpxAttribute, OmpxAttribute); |
| 227 |
MAKE_EMPTY_CLASS(OmpxBare, OmpxBare); |
| 228 |
MAKE_EMPTY_CLASS(Read, Read); |
| 229 |
MAKE_EMPTY_CLASS(Relaxed, Relaxed); |
| 230 |
MAKE_EMPTY_CLASS(Release, Release); |
| 231 |
MAKE_EMPTY_CLASS(ReverseOffload, ReverseOffload); |
| 232 |
MAKE_EMPTY_CLASS(SeqCst, SeqCst); |
| 233 |
MAKE_EMPTY_CLASS(Simd, Simd); |
| 234 |
MAKE_EMPTY_CLASS(Threads, Threads); |
| 235 |
MAKE_EMPTY_CLASS(UnifiedAddress, UnifiedAddress); |
| 236 |
MAKE_EMPTY_CLASS(UnifiedSharedMemory, UnifiedSharedMemory); |
| 237 |
MAKE_EMPTY_CLASS(Unknown, Unknown); |
| 238 |
MAKE_EMPTY_CLASS(Untied, Untied); |
| 239 |
MAKE_EMPTY_CLASS(Weak, Weak); |
| 240 |
MAKE_EMPTY_CLASS(Write, Write); |
| 241 |
|
| 242 |
// Artificial clauses |
| 243 |
MAKE_EMPTY_CLASS(CancellationConstructType, CancellationConstructType); |
| 244 |
MAKE_EMPTY_CLASS(Depobj, Depobj); |
| 245 |
MAKE_EMPTY_CLASS(Flush, Flush); |
| 246 |
MAKE_EMPTY_CLASS(MemoryOrder, MemoryOrder); |
| 247 |
MAKE_EMPTY_CLASS(Threadprivate, Threadprivate); |
| 248 |
|
| 249 |
MAKE_INCOMPLETE_CLASS(AdjustArgs, AdjustArgs); |
| 250 |
MAKE_INCOMPLETE_CLASS(AppendArgs, AppendArgs); |
| 251 |
MAKE_INCOMPLETE_CLASS(Match, Match); |
| 252 |
// MAKE_INCOMPLETE_CLASS(Otherwise, ); // missing-in-parser |
| 253 |
MAKE_INCOMPLETE_CLASS(When, When); |
| 254 |
|
| 255 |
DefinedOperator makeDefinedOperator(const parser::DefinedOperator &inp, |
| 256 |
semantics::SemanticsContext &semaCtx) { |
| 257 |
CLAUSET_ENUM_CONVERT( // |
| 258 |
convert, parser::DefinedOperator::IntrinsicOperator, |
| 259 |
DefinedOperator::IntrinsicOperator, |
| 260 |
// clang-format off |
| 261 |
MS(Add, Add) |
| 262 |
MS(AND, AND) |
| 263 |
MS(Concat, Concat) |
| 264 |
MS(Divide, Divide) |
| 265 |
MS(EQ, EQ) |
| 266 |
MS(EQV, EQV) |
| 267 |
MS(GE, GE) |
| 268 |
MS(GT, GT) |
| 269 |
MS(NOT, NOT) |
| 270 |
MS(LE, LE) |
| 271 |
MS(LT, LT) |
| 272 |
MS(Multiply, Multiply) |
| 273 |
MS(NE, NE) |
| 274 |
MS(NEQV, NEQV) |
| 275 |
MS(OR, OR) |
| 276 |
MS(Power, Power) |
| 277 |
MS(Subtract, Subtract) |
| 278 |
// clang-format on |
| 279 |
); |
| 280 |
|
| 281 |
return Fortran::common::visit( |
| 282 |
common::visitors{ |
| 283 |
[&](const parser::DefinedOpName &s) { |
| 284 |
return DefinedOperator{ |
| 285 |
DefinedOperator::DefinedOpName{makeObject(s.v, semaCtx)}}; |
| 286 |
}, |
| 287 |
[&](const parser::DefinedOperator::IntrinsicOperator &s) { |
| 288 |
return DefinedOperator{convert(s)}; |
| 289 |
}, |
| 290 |
}, |
| 291 |
inp.u); |
| 292 |
} |
| 293 |
|
| 294 |
ProcedureDesignator |
| 295 |
makeProcedureDesignator(const parser::ProcedureDesignator &inp, |
| 296 |
semantics::SemanticsContext &semaCtx) { |
| 297 |
return ProcedureDesignator{Fortran::common::visit( |
| 298 |
common::visitors{ |
| 299 |
[&](const parser::Name &t) { return makeObject(t, semaCtx); }, |
| 300 |
[&](const parser::ProcComponentRef &t) { |
| 301 |
return makeObject(t.v.thing, semaCtx); |
| 302 |
}, |
| 303 |
}, |
| 304 |
inp.u)}; |
| 305 |
} |
| 306 |
|
| 307 |
ReductionOperator makeReductionOperator(const parser::OmpReductionOperator &inp, |
| 308 |
semantics::SemanticsContext &semaCtx) { |
| 309 |
return Fortran::common::visit( |
| 310 |
common::visitors{ |
| 311 |
[&](const parser::DefinedOperator &s) { |
| 312 |
return ReductionOperator{makeDefinedOperator(s, semaCtx)}; |
| 313 |
}, |
| 314 |
[&](const parser::ProcedureDesignator &s) { |
| 315 |
return ReductionOperator{makeProcedureDesignator(s, semaCtx)}; |
| 316 |
}, |
| 317 |
}, |
| 318 |
inp.u); |
| 319 |
} |
| 320 |
|
| 321 |
// -------------------------------------------------------------------- |
| 322 |
// Actual clauses. Each T (where tomp::T exists in ClauseT) has its "make". |
| 323 |
|
| 324 |
// Absent: missing-in-parser |
| 325 |
// AcqRel: empty |
| 326 |
// Acquire: empty |
| 327 |
// AdjustArgs: incomplete |
| 328 |
|
| 329 |
Affinity make(const parser::OmpClause::Affinity &inp, |
| 330 |
semantics::SemanticsContext &semaCtx) { |
| 331 |
// inp -> empty |
| 332 |
llvm_unreachable("Empty: affinity"); |
| 333 |
} |
| 334 |
|
| 335 |
Align make(const parser::OmpClause::Align &inp, |
| 336 |
semantics::SemanticsContext &semaCtx) { |
| 337 |
// inp -> empty |
| 338 |
llvm_unreachable("Empty: align"); |
| 339 |
} |
| 340 |
|
| 341 |
Aligned make(const parser::OmpClause::Aligned &inp, |
| 342 |
semantics::SemanticsContext &semaCtx) { |
| 343 |
// inp.v -> parser::OmpAlignedClause |
| 344 |
auto &t0 = std::get<parser::OmpObjectList>(inp.v.t); |
| 345 |
auto &t1 = std::get<std::optional<parser::ScalarIntConstantExpr>>(inp.v.t); |
| 346 |
|
| 347 |
return Aligned{{ |
| 348 |
/*Alignment=*/maybeApply(makeExprFn(semaCtx), t1), |
| 349 |
/*List=*/makeObjects(t0, semaCtx), |
| 350 |
}}; |
| 351 |
} |
| 352 |
|
| 353 |
Allocate make(const parser::OmpClause::Allocate &inp, |
| 354 |
semantics::SemanticsContext &semaCtx) { |
| 355 |
// inp.v -> parser::OmpAllocateClause |
| 356 |
using wrapped = parser::OmpAllocateClause; |
| 357 |
auto &t0 = std::get<std::optional<wrapped::AllocateModifier>>(inp.v.t); |
| 358 |
auto &t1 = std::get<parser::OmpObjectList>(inp.v.t); |
| 359 |
|
| 360 |
if (!t0) { |
| 361 |
return Allocate{{/*AllocatorSimpleModifier=*/std::nullopt, |
| 362 |
/*AllocatorComplexModifier=*/std::nullopt, |
| 363 |
/*AlignModifier=*/std::nullopt, |
| 364 |
/*List=*/makeObjects(t1, semaCtx)}}; |
| 365 |
} |
| 366 |
|
| 367 |
using Tuple = decltype(Allocate::t); |
| 368 |
|
| 369 |
return Allocate{Fortran::common::visit( |
| 370 |
common::visitors{ |
| 371 |
// simple-modifier |
| 372 |
[&](const wrapped::AllocateModifier::Allocator &v) -> Tuple { |
| 373 |
return {/*AllocatorSimpleModifier=*/makeExpr(v.v, semaCtx), |
| 374 |
/*AllocatorComplexModifier=*/std::nullopt, |
| 375 |
/*AlignModifier=*/std::nullopt, |
| 376 |
/*List=*/makeObjects(t1, semaCtx)}; |
| 377 |
}, |
| 378 |
// complex-modifier + align-modifier |
| 379 |
[&](const wrapped::AllocateModifier::ComplexModifier &v) -> Tuple { |
| 380 |
auto &s0 = std::get<wrapped::AllocateModifier::Allocator>(v.t); |
| 381 |
auto &s1 = std::get<wrapped::AllocateModifier::Align>(v.t); |
| 382 |
return { |
| 383 |
/*AllocatorSimpleModifier=*/std::nullopt, |
| 384 |
/*AllocatorComplexModifier=*/Allocator{makeExpr(s0.v, semaCtx)}, |
| 385 |
/*AlignModifier=*/Align{makeExpr(s1.v, semaCtx)}, |
| 386 |
/*List=*/makeObjects(t1, semaCtx)}; |
| 387 |
}, |
| 388 |
// align-modifier |
| 389 |
[&](const wrapped::AllocateModifier::Align &v) -> Tuple { |
| 390 |
return {/*AllocatorSimpleModifier=*/std::nullopt, |
| 391 |
/*AllocatorComplexModifier=*/std::nullopt, |
| 392 |
/*AlignModifier=*/Align{makeExpr(v.v, semaCtx)}, |
| 393 |
/*List=*/makeObjects(t1, semaCtx)}; |
| 394 |
}, |
| 395 |
}, |
| 396 |
t0->u)}; |
| 397 |
} |
| 398 |
|
| 399 |
Allocator make(const parser::OmpClause::Allocator &inp, |
| 400 |
semantics::SemanticsContext &semaCtx) { |
| 401 |
// inp.v -> parser::ScalarIntExpr |
| 402 |
return Allocator{/*Allocator=*/makeExpr(inp.v, semaCtx)}; |
| 403 |
} |
| 404 |
|
| 405 |
// AppendArgs: incomplete |
| 406 |
|
| 407 |
At make(const parser::OmpClause::At &inp, |
| 408 |
semantics::SemanticsContext &semaCtx) { |
| 409 |
// inp -> empty |
| 410 |
llvm_unreachable("Empty: at"); |
| 411 |
} |
| 412 |
|
| 413 |
// Never called, but needed for using "make" as a Clause visitor. |
| 414 |
// See comment about "requires" clauses in Clauses.h. |
| 415 |
AtomicDefaultMemOrder make(const parser::OmpClause::AtomicDefaultMemOrder &inp, |
| 416 |
semantics::SemanticsContext &semaCtx) { |
| 417 |
// inp.v -> parser::OmpAtomicDefaultMemOrderClause |
| 418 |
CLAUSET_ENUM_CONVERT( // |
| 419 |
convert, common::OmpAtomicDefaultMemOrderType, |
| 420 |
AtomicDefaultMemOrder::MemoryOrder, |
| 421 |
// clang-format off |
| 422 |
MS(AcqRel, AcqRel) |
| 423 |
MS(Relaxed, Relaxed) |
| 424 |
MS(SeqCst, SeqCst) |
| 425 |
// clang-format on |
| 426 |
); |
| 427 |
|
| 428 |
return AtomicDefaultMemOrder{/*MemoryOrder=*/convert(inp.v.v)}; |
| 429 |
} |
| 430 |
|
| 431 |
Bind make(const parser::OmpClause::Bind &inp, |
| 432 |
semantics::SemanticsContext &semaCtx) { |
| 433 |
// inp -> empty |
| 434 |
llvm_unreachable("Empty: bind"); |
| 435 |
} |
| 436 |
|
| 437 |
// CancellationConstructType: empty |
| 438 |
// Capture: empty |
| 439 |
|
| 440 |
Collapse make(const parser::OmpClause::Collapse &inp, |
| 441 |
semantics::SemanticsContext &semaCtx) { |
| 442 |
// inp.v -> parser::ScalarIntConstantExpr |
| 443 |
return Collapse{/*N=*/makeExpr(inp.v, semaCtx)}; |
| 444 |
} |
| 445 |
|
| 446 |
// Compare: empty |
| 447 |
// Contains: missing-in-parser |
| 448 |
|
| 449 |
Copyin make(const parser::OmpClause::Copyin &inp, |
| 450 |
semantics::SemanticsContext &semaCtx) { |
| 451 |
// inp.v -> parser::OmpObjectList |
| 452 |
return Copyin{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 453 |
} |
| 454 |
|
| 455 |
Copyprivate make(const parser::OmpClause::Copyprivate &inp, |
| 456 |
semantics::SemanticsContext &semaCtx) { |
| 457 |
// inp.v -> parser::OmpObjectList |
| 458 |
return Copyprivate{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 459 |
} |
| 460 |
|
| 461 |
Default make(const parser::OmpClause::Default &inp, |
| 462 |
semantics::SemanticsContext &semaCtx) { |
| 463 |
// inp.v -> parser::OmpDefaultClause |
| 464 |
using wrapped = parser::OmpDefaultClause; |
| 465 |
|
| 466 |
CLAUSET_ENUM_CONVERT( // |
| 467 |
convert, wrapped::Type, Default::DataSharingAttribute, |
| 468 |
// clang-format off |
| 469 |
MS(Firstprivate, Firstprivate) |
| 470 |
MS(None, None) |
| 471 |
MS(Private, Private) |
| 472 |
MS(Shared, Shared) |
| 473 |
// clang-format on |
| 474 |
); |
| 475 |
|
| 476 |
return Default{/*DataSharingAttribute=*/convert(inp.v.v)}; |
| 477 |
} |
| 478 |
|
| 479 |
Defaultmap make(const parser::OmpClause::Defaultmap &inp, |
| 480 |
semantics::SemanticsContext &semaCtx) { |
| 481 |
// inp.v -> parser::OmpDefaultmapClause |
| 482 |
using wrapped = parser::OmpDefaultmapClause; |
| 483 |
|
| 484 |
CLAUSET_ENUM_CONVERT( // |
| 485 |
convert1, wrapped::ImplicitBehavior, Defaultmap::ImplicitBehavior, |
| 486 |
// clang-format off |
| 487 |
MS(Alloc, Alloc) |
| 488 |
MS(To, To) |
| 489 |
MS(From, From) |
| 490 |
MS(Tofrom, Tofrom) |
| 491 |
MS(Firstprivate, Firstprivate) |
| 492 |
MS(None, None) |
| 493 |
MS(Default, Default) |
| 494 |
// MS(, Present) missing-in-parser |
| 495 |
// clang-format on |
| 496 |
); |
| 497 |
|
| 498 |
CLAUSET_ENUM_CONVERT( // |
| 499 |
convert2, wrapped::VariableCategory, Defaultmap::VariableCategory, |
| 500 |
// clang-format off |
| 501 |
MS(Scalar, Scalar) |
| 502 |
MS(Aggregate, Aggregate) |
| 503 |
MS(Pointer, Pointer) |
| 504 |
MS(Allocatable, Allocatable) |
| 505 |
// clang-format on |
| 506 |
); |
| 507 |
|
| 508 |
auto &t0 = std::get<wrapped::ImplicitBehavior>(inp.v.t); |
| 509 |
auto &t1 = std::get<std::optional<wrapped::VariableCategory>>(inp.v.t); |
| 510 |
return Defaultmap{{/*ImplicitBehavior=*/convert1(t0), |
| 511 |
/*VariableCategory=*/maybeApply(convert2, t1)}}; |
| 512 |
} |
| 513 |
|
| 514 |
Depend make(const parser::OmpClause::Depend &inp, |
| 515 |
semantics::SemanticsContext &semaCtx) { |
| 516 |
// inp.v -> parser::OmpDependClause |
| 517 |
using wrapped = parser::OmpDependClause; |
| 518 |
using Variant = decltype(Depend::u); |
| 519 |
// Iteration is the equivalent of parser::OmpDependSinkVec |
| 520 |
using Iteration = Doacross::Vector::value_type; // LoopIterationT |
| 521 |
|
| 522 |
CLAUSET_ENUM_CONVERT( // |
| 523 |
convert1, parser::OmpDependenceType::Type, Depend::TaskDependenceType, |
| 524 |
// clang-format off |
| 525 |
MS(In, In) |
| 526 |
MS(Out, Out) |
| 527 |
MS(Inout, Inout) |
| 528 |
// MS(, Mutexinoutset) // missing-in-parser |
| 529 |
// MS(, Inputset) // missing-in-parser |
| 530 |
// MS(, Depobj) // missing-in-parser |
| 531 |
// clang-format on |
| 532 |
); |
| 533 |
|
| 534 |
return Depend{Fortran::common::visit( // |
| 535 |
common::visitors{ |
| 536 |
// Doacross |
| 537 |
[&](const wrapped::Source &s) -> Variant { |
| 538 |
return Doacross{ |
| 539 |
{/*DependenceType=*/Doacross::DependenceType::Source, |
| 540 |
/*Vector=*/{}}}; |
| 541 |
}, |
| 542 |
// Doacross |
| 543 |
[&](const wrapped::Sink &s) -> Variant { |
| 544 |
using DependLength = parser::OmpDependSinkVecLength; |
| 545 |
auto convert2 = [&](const parser::OmpDependSinkVec &v) { |
| 546 |
auto &t0 = std::get<parser::Name>(v.t); |
| 547 |
auto &t1 = std::get<std::optional<DependLength>>(v.t); |
| 548 |
|
| 549 |
auto convert3 = [&](const DependLength &u) { |
| 550 |
auto &s0 = std::get<parser::DefinedOperator>(u.t); |
| 551 |
auto &s1 = std::get<parser::ScalarIntConstantExpr>(u.t); |
| 552 |
return Iteration::Distance{ |
| 553 |
{makeDefinedOperator(s0, semaCtx), makeExpr(s1, semaCtx)}}; |
| 554 |
}; |
| 555 |
return Iteration{ |
| 556 |
{makeObject(t0, semaCtx), maybeApply(convert3, t1)}}; |
| 557 |
}; |
| 558 |
return Doacross{{/*DependenceType=*/Doacross::DependenceType::Sink, |
| 559 |
/*Vector=*/makeList(s.v, convert2)}}; |
| 560 |
}, |
| 561 |
// Depend::WithLocators |
| 562 |
[&](const wrapped::InOut &s) -> Variant { |
| 563 |
auto &t0 = std::get<parser::OmpDependenceType>(s.t); |
| 564 |
auto &t1 = std::get<std::list<parser::Designator>>(s.t); |
| 565 |
auto convert4 = [&](const parser::Designator &t) { |
| 566 |
return makeObject(t, semaCtx); |
| 567 |
}; |
| 568 |
return Depend::WithLocators{ |
| 569 |
{/*TaskDependenceType=*/convert1(t0.v), |
| 570 |
/*Iterator=*/std::nullopt, |
| 571 |
/*LocatorList=*/makeList(t1, convert4)}}; |
| 572 |
}, |
| 573 |
}, |
| 574 |
inp.v.u)}; |
| 575 |
} |
| 576 |
|
| 577 |
// Depobj: empty |
| 578 |
|
| 579 |
Destroy make(const parser::OmpClause::Destroy &inp, |
| 580 |
semantics::SemanticsContext &semaCtx) { |
| 581 |
// inp -> empty |
| 582 |
llvm_unreachable("Empty: destroy"); |
| 583 |
} |
| 584 |
|
| 585 |
Detach make(const parser::OmpClause::Detach &inp, |
| 586 |
semantics::SemanticsContext &semaCtx) { |
| 587 |
// inp -> empty |
| 588 |
llvm_unreachable("Empty: detach"); |
| 589 |
} |
| 590 |
|
| 591 |
Device make(const parser::OmpClause::Device &inp, |
| 592 |
semantics::SemanticsContext &semaCtx) { |
| 593 |
// inp.v -> parser::OmpDeviceClause |
| 594 |
using wrapped = parser::OmpDeviceClause; |
| 595 |
|
| 596 |
CLAUSET_ENUM_CONVERT( // |
| 597 |
convert, parser::OmpDeviceClause::DeviceModifier, Device::DeviceModifier, |
| 598 |
// clang-format off |
| 599 |
MS(Ancestor, Ancestor) |
| 600 |
MS(Device_Num, DeviceNum) |
| 601 |
// clang-format on |
| 602 |
); |
| 603 |
auto &t0 = std::get<std::optional<wrapped::DeviceModifier>>(inp.v.t); |
| 604 |
auto &t1 = std::get<parser::ScalarIntExpr>(inp.v.t); |
| 605 |
return Device{{/*DeviceModifier=*/maybeApply(convert, t0), |
| 606 |
/*DeviceDescription=*/makeExpr(t1, semaCtx)}}; |
| 607 |
} |
| 608 |
|
| 609 |
DeviceType make(const parser::OmpClause::DeviceType &inp, |
| 610 |
semantics::SemanticsContext &semaCtx) { |
| 611 |
// inp.v -> parser::OmpDeviceTypeClause |
| 612 |
using wrapped = parser::OmpDeviceTypeClause; |
| 613 |
|
| 614 |
CLAUSET_ENUM_CONVERT( // |
| 615 |
convert, wrapped::Type, DeviceType::DeviceTypeDescription, |
| 616 |
// clang-format off |
| 617 |
MS(Any, Any) |
| 618 |
MS(Host, Host) |
| 619 |
MS(Nohost, Nohost) |
| 620 |
// clang-format om |
| 621 |
); |
| 622 |
return DeviceType{/*DeviceTypeDescription=*/convert(inp.v.v)}; |
| 623 |
} |
| 624 |
|
| 625 |
DistSchedule make(const parser::OmpClause::DistSchedule &inp, |
| 626 |
semantics::SemanticsContext &semaCtx) { |
| 627 |
// inp.v -> std::optional<parser::ScalarIntExpr> |
| 628 |
return DistSchedule{{/*Kind=*/DistSchedule::Kind::Static, |
| 629 |
/*ChunkSize=*/maybeApply(makeExprFn(semaCtx), inp.v)}}; |
| 630 |
} |
| 631 |
|
| 632 |
Doacross make(const parser::OmpClause::Doacross &inp, |
| 633 |
semantics::SemanticsContext &semaCtx) { |
| 634 |
// inp -> empty |
| 635 |
llvm_unreachable("Empty: doacross"); |
| 636 |
} |
| 637 |
|
| 638 |
// DynamicAllocators: empty |
| 639 |
|
| 640 |
Enter make(const parser::OmpClause::Enter &inp, |
| 641 |
semantics::SemanticsContext &semaCtx) { |
| 642 |
// inp.v -> parser::OmpObjectList |
| 643 |
return Enter{makeObjects(/*List=*/inp.v, semaCtx)}; |
| 644 |
} |
| 645 |
|
| 646 |
Exclusive make(const parser::OmpClause::Exclusive &inp, |
| 647 |
semantics::SemanticsContext &semaCtx) { |
| 648 |
// inp -> empty |
| 649 |
llvm_unreachable("Empty: exclusive"); |
| 650 |
} |
| 651 |
|
| 652 |
Fail make(const parser::OmpClause::Fail &inp, |
| 653 |
semantics::SemanticsContext &semaCtx) { |
| 654 |
// inp -> empty |
| 655 |
llvm_unreachable("Empty: fail"); |
| 656 |
} |
| 657 |
|
| 658 |
Filter make(const parser::OmpClause::Filter &inp, |
| 659 |
semantics::SemanticsContext &semaCtx) { |
| 660 |
// inp.v -> parser::ScalarIntExpr |
| 661 |
return Filter{/*ThreadNum=*/makeExpr(inp.v, semaCtx)}; |
| 662 |
} |
| 663 |
|
| 664 |
Final make(const parser::OmpClause::Final &inp, |
| 665 |
semantics::SemanticsContext &semaCtx) { |
| 666 |
// inp.v -> parser::ScalarLogicalExpr |
| 667 |
return Final{/*Finalize=*/makeExpr(inp.v, semaCtx)}; |
| 668 |
} |
| 669 |
|
| 670 |
Firstprivate make(const parser::OmpClause::Firstprivate &inp, |
| 671 |
semantics::SemanticsContext &semaCtx) { |
| 672 |
// inp.v -> parser::OmpObjectList |
| 673 |
return Firstprivate{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 674 |
} |
| 675 |
|
| 676 |
// Flush: empty |
| 677 |
|
| 678 |
From make(const parser::OmpClause::From &inp, |
| 679 |
semantics::SemanticsContext &semaCtx) { |
| 680 |
// inp.v -> parser::OmpObjectList |
| 681 |
return From{{/*Expectation=*/std::nullopt, /*Mapper=*/std::nullopt, |
| 682 |
/*Iterator=*/std::nullopt, |
| 683 |
/*LocatorList=*/makeObjects(inp.v, semaCtx)}}; |
| 684 |
} |
| 685 |
|
| 686 |
// Full: empty |
| 687 |
|
| 688 |
Grainsize make(const parser::OmpClause::Grainsize &inp, |
| 689 |
semantics::SemanticsContext &semaCtx) { |
| 690 |
// inp.v -> parser::ScalarIntExpr |
| 691 |
return Grainsize{{/*Prescriptiveness=*/std::nullopt, |
| 692 |
/*GrainSize=*/makeExpr(inp.v, semaCtx)}}; |
| 693 |
} |
| 694 |
|
| 695 |
HasDeviceAddr make(const parser::OmpClause::HasDeviceAddr &inp, |
| 696 |
semantics::SemanticsContext &semaCtx) { |
| 697 |
// inp.v -> parser::OmpObjectList |
| 698 |
return HasDeviceAddr{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 699 |
} |
| 700 |
|
| 701 |
Hint make(const parser::OmpClause::Hint &inp, |
| 702 |
semantics::SemanticsContext &semaCtx) { |
| 703 |
// inp.v -> parser::ConstantExpr |
| 704 |
return Hint{/*HintExpr=*/makeExpr(inp.v, semaCtx)}; |
| 705 |
} |
| 706 |
|
| 707 |
// Holds: missing-in-parser |
| 708 |
|
| 709 |
If make(const parser::OmpClause::If &inp, |
| 710 |
semantics::SemanticsContext &semaCtx) { |
| 711 |
// inp.v -> parser::OmpIfClause |
| 712 |
using wrapped = parser::OmpIfClause; |
| 713 |
|
| 714 |
CLAUSET_ENUM_CONVERT( // |
| 715 |
convert, wrapped::DirectiveNameModifier, llvm::omp::Directive, |
| 716 |
// clang-format off |
| 717 |
MS(Parallel, OMPD_parallel) |
| 718 |
MS(Simd, OMPD_simd) |
| 719 |
MS(Target, OMPD_target) |
| 720 |
MS(TargetData, OMPD_target_data) |
| 721 |
MS(TargetEnterData, OMPD_target_enter_data) |
| 722 |
MS(TargetExitData, OMPD_target_exit_data) |
| 723 |
MS(TargetUpdate, OMPD_target_update) |
| 724 |
MS(Task, OMPD_task) |
| 725 |
MS(Taskloop, OMPD_taskloop) |
| 726 |
MS(Teams, OMPD_teams) |
| 727 |
// clang-format on |
| 728 |
); |
| 729 |
auto &t0 = std::get<std::optional<wrapped::DirectiveNameModifier>>(inp.v.t); |
| 730 |
auto &t1 = std::get<parser::ScalarLogicalExpr>(inp.v.t); |
| 731 |
return If{{/*DirectiveNameModifier=*/maybeApply(convert, t0), |
| 732 |
/*IfExpression=*/makeExpr(t1, semaCtx)}}; |
| 733 |
} |
| 734 |
|
| 735 |
// Inbranch: empty |
| 736 |
|
| 737 |
Inclusive make(const parser::OmpClause::Inclusive &inp, |
| 738 |
semantics::SemanticsContext &semaCtx) { |
| 739 |
// inp -> empty |
| 740 |
llvm_unreachable("Empty: inclusive"); |
| 741 |
} |
| 742 |
|
| 743 |
Indirect make(const parser::OmpClause::Indirect &inp, |
| 744 |
semantics::SemanticsContext &semaCtx) { |
| 745 |
// inp -> empty |
| 746 |
llvm_unreachable("Empty: indirect"); |
| 747 |
} |
| 748 |
|
| 749 |
Init make(const parser::OmpClause::Init &inp, |
| 750 |
semantics::SemanticsContext &semaCtx) { |
| 751 |
// inp -> empty |
| 752 |
llvm_unreachable("Empty: init"); |
| 753 |
} |
| 754 |
|
| 755 |
// Initializer: missing-in-parser |
| 756 |
|
| 757 |
InReduction make(const parser::OmpClause::InReduction &inp, |
| 758 |
semantics::SemanticsContext &semaCtx) { |
| 759 |
// inp.v -> parser::OmpInReductionClause |
| 760 |
auto &t0 = std::get<parser::OmpReductionOperator>(inp.v.t); |
| 761 |
auto &t1 = std::get<parser::OmpObjectList>(inp.v.t); |
| 762 |
return InReduction{ |
| 763 |
{/*ReductionIdentifiers=*/{makeReductionOperator(t0, semaCtx)}, |
| 764 |
/*List=*/makeObjects(t1, semaCtx)}}; |
| 765 |
} |
| 766 |
|
| 767 |
IsDevicePtr make(const parser::OmpClause::IsDevicePtr &inp, |
| 768 |
semantics::SemanticsContext &semaCtx) { |
| 769 |
// inp.v -> parser::OmpObjectList |
| 770 |
return IsDevicePtr{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 771 |
} |
| 772 |
|
| 773 |
Lastprivate make(const parser::OmpClause::Lastprivate &inp, |
| 774 |
semantics::SemanticsContext &semaCtx) { |
| 775 |
// inp.v -> parser::OmpObjectList |
| 776 |
return Lastprivate{{/*LastprivateModifier=*/std::nullopt, |
| 777 |
/*List=*/makeObjects(inp.v, semaCtx)}}; |
| 778 |
} |
| 779 |
|
| 780 |
Linear make(const parser::OmpClause::Linear &inp, |
| 781 |
semantics::SemanticsContext &semaCtx) { |
| 782 |
// inp.v -> parser::OmpLinearClause |
| 783 |
using wrapped = parser::OmpLinearClause; |
| 784 |
|
| 785 |
CLAUSET_ENUM_CONVERT( // |
| 786 |
convert, parser::OmpLinearModifier::Type, Linear::LinearModifier, |
| 787 |
// clang-format off |
| 788 |
MS(Ref, Ref) |
| 789 |
MS(Val, Val) |
| 790 |
MS(Uval, Uval) |
| 791 |
// clang-format on |
| 792 |
); |
| 793 |
|
| 794 |
using Tuple = decltype(Linear::t); |
| 795 |
|
| 796 |
return Linear{Fortran::common::visit( |
| 797 |
common::visitors{ |
| 798 |
[&](const wrapped::WithModifier &s) -> Tuple { |
| 799 |
return { |
| 800 |
/*StepSimpleModifier=*/std::nullopt, |
| 801 |
/*StepComplexModifier=*/maybeApply(makeExprFn(semaCtx), s.step), |
| 802 |
/*LinearModifier=*/convert(s.modifier.v), |
| 803 |
/*List=*/makeList(s.names, makeObjectFn(semaCtx))}; |
| 804 |
}, |
| 805 |
[&](const wrapped::WithoutModifier &s) -> Tuple { |
| 806 |
return { |
| 807 |
/*StepSimpleModifier=*/maybeApply(makeExprFn(semaCtx), s.step), |
| 808 |
/*StepComplexModifier=*/std::nullopt, |
| 809 |
/*LinearModifier=*/std::nullopt, |
| 810 |
/*List=*/makeList(s.names, makeObjectFn(semaCtx))}; |
| 811 |
}, |
| 812 |
}, |
| 813 |
inp.v.u)}; |
| 814 |
} |
| 815 |
|
| 816 |
Link make(const parser::OmpClause::Link &inp, |
| 817 |
semantics::SemanticsContext &semaCtx) { |
| 818 |
// inp.v -> parser::OmpObjectList |
| 819 |
return Link{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 820 |
} |
| 821 |
|
| 822 |
Map make(const parser::OmpClause::Map &inp, |
| 823 |
semantics::SemanticsContext &semaCtx) { |
| 824 |
// inp.v -> parser::OmpMapClause |
| 825 |
|
| 826 |
CLAUSET_ENUM_CONVERT( // |
| 827 |
convert1, parser::OmpMapType::Type, Map::MapType, |
| 828 |
// clang-format off |
| 829 |
MS(To, To) |
| 830 |
MS(From, From) |
| 831 |
MS(Tofrom, Tofrom) |
| 832 |
MS(Alloc, Alloc) |
| 833 |
MS(Release, Release) |
| 834 |
MS(Delete, Delete) |
| 835 |
// clang-format on |
| 836 |
); |
| 837 |
|
| 838 |
// No convert2: MapTypeModifier is not an enum in parser. |
| 839 |
|
| 840 |
auto &t0 = std::get<std::optional<parser::OmpMapType>>(inp.v.t); |
| 841 |
auto &t1 = std::get<parser::OmpObjectList>(inp.v.t); |
| 842 |
|
| 843 |
if (!t0) { |
| 844 |
return Map{{/*MapType=*/std::nullopt, /*MapTypeModifiers=*/std::nullopt, |
| 845 |
/*Mapper=*/std::nullopt, /*Iterator=*/std::nullopt, |
| 846 |
/*LocatorList=*/makeObjects(t1, semaCtx)}}; |
| 847 |
} |
| 848 |
|
| 849 |
auto &s0 = std::get<std::optional<parser::OmpMapType::Always>>(t0->t); |
| 850 |
auto &s1 = std::get<parser::OmpMapType::Type>(t0->t); |
| 851 |
|
| 852 |
std::optional<Map::MapTypeModifiers> maybeList; |
| 853 |
if (s0) |
| 854 |
maybeList = Map::MapTypeModifiers{Map::MapTypeModifier::Always}; |
| 855 |
|
| 856 |
return Map{{/*MapType=*/convert1(s1), |
| 857 |
/*MapTypeModifiers=*/maybeList, |
| 858 |
/*Mapper=*/std::nullopt, /*Iterator=*/std::nullopt, |
| 859 |
/*LocatorList=*/makeObjects(t1, semaCtx)}}; |
| 860 |
} |
| 861 |
|
| 862 |
// Match: incomplete |
| 863 |
// MemoryOrder: empty |
| 864 |
// Mergeable: empty |
| 865 |
|
| 866 |
Message make(const parser::OmpClause::Message &inp, |
| 867 |
semantics::SemanticsContext &semaCtx) { |
| 868 |
// inp -> empty |
| 869 |
llvm_unreachable("Empty: message"); |
| 870 |
} |
| 871 |
|
| 872 |
Nocontext make(const parser::OmpClause::Nocontext &inp, |
| 873 |
semantics::SemanticsContext &semaCtx) { |
| 874 |
// inp.v -> parser::ScalarLogicalExpr |
| 875 |
return Nocontext{/*DoNotUpdateContext=*/makeExpr(inp.v, semaCtx)}; |
| 876 |
} |
| 877 |
|
| 878 |
// Nogroup: empty |
| 879 |
|
| 880 |
Nontemporal make(const parser::OmpClause::Nontemporal &inp, |
| 881 |
semantics::SemanticsContext &semaCtx) { |
| 882 |
// inp.v -> std::list<parser::Name> |
| 883 |
return Nontemporal{/*List=*/makeList(inp.v, makeObjectFn(semaCtx))}; |
| 884 |
} |
| 885 |
|
| 886 |
// NoOpenmp: missing-in-parser |
| 887 |
// NoOpenmpRoutines: missing-in-parser |
| 888 |
// NoParallelism: missing-in-parser |
| 889 |
// Notinbranch: empty |
| 890 |
|
| 891 |
Novariants make(const parser::OmpClause::Novariants &inp, |
| 892 |
semantics::SemanticsContext &semaCtx) { |
| 893 |
// inp.v -> parser::ScalarLogicalExpr |
| 894 |
return Novariants{/*DoNotUseVariant=*/makeExpr(inp.v, semaCtx)}; |
| 895 |
} |
| 896 |
|
| 897 |
// Nowait: empty |
| 898 |
|
| 899 |
NumTasks make(const parser::OmpClause::NumTasks &inp, |
| 900 |
semantics::SemanticsContext &semaCtx) { |
| 901 |
// inp.v -> parser::ScalarIntExpr |
| 902 |
return NumTasks{{/*Prescriptiveness=*/std::nullopt, |
| 903 |
/*NumTasks=*/makeExpr(inp.v, semaCtx)}}; |
| 904 |
} |
| 905 |
|
| 906 |
NumTeams make(const parser::OmpClause::NumTeams &inp, |
| 907 |
semantics::SemanticsContext &semaCtx) { |
| 908 |
// inp.v -> parser::ScalarIntExpr |
| 909 |
return NumTeams{{/*LowerBound=*/std::nullopt, |
| 910 |
/*UpperBound=*/makeExpr(inp.v, semaCtx)}}; |
| 911 |
} |
| 912 |
|
| 913 |
NumThreads make(const parser::OmpClause::NumThreads &inp, |
| 914 |
semantics::SemanticsContext &semaCtx) { |
| 915 |
// inp.v -> parser::ScalarIntExpr |
| 916 |
return NumThreads{/*Nthreads=*/makeExpr(inp.v, semaCtx)}; |
| 917 |
} |
| 918 |
|
| 919 |
// OmpxAttribute: empty |
| 920 |
// OmpxBare: empty |
| 921 |
|
| 922 |
OmpxDynCgroupMem make(const parser::OmpClause::OmpxDynCgroupMem &inp, |
| 923 |
semantics::SemanticsContext &semaCtx) { |
| 924 |
// inp.v -> parser::ScalarIntExpr |
| 925 |
return OmpxDynCgroupMem{makeExpr(inp.v, semaCtx)}; |
| 926 |
} |
| 927 |
|
| 928 |
Order make(const parser::OmpClause::Order &inp, |
| 929 |
semantics::SemanticsContext &semaCtx) { |
| 930 |
// inp.v -> parser::OmpOrderClause |
| 931 |
using wrapped = parser::OmpOrderClause; |
| 932 |
|
| 933 |
CLAUSET_ENUM_CONVERT( // |
| 934 |
convert1, parser::OmpOrderModifier::Kind, Order::OrderModifier, |
| 935 |
// clang-format off |
| 936 |
MS(Reproducible, Reproducible) |
| 937 |
MS(Unconstrained, Unconstrained) |
| 938 |
// clang-format on |
| 939 |
); |
| 940 |
|
| 941 |
CLAUSET_ENUM_CONVERT( // |
| 942 |
convert2, wrapped::Type, Order::Ordering, |
| 943 |
// clang-format off |
| 944 |
MS(Concurrent, Concurrent) |
| 945 |
// clang-format on |
| 946 |
); |
| 947 |
|
| 948 |
auto &t0 = std::get<std::optional<parser::OmpOrderModifier>>(inp.v.t); |
| 949 |
auto &t1 = std::get<wrapped::Type>(inp.v.t); |
| 950 |
|
| 951 |
auto convert3 = [&](const parser::OmpOrderModifier &s) { |
| 952 |
return Fortran::common::visit( |
| 953 |
[&](parser::OmpOrderModifier::Kind k) { return convert1(k); }, s.u); |
| 954 |
}; |
| 955 |
return Order{ |
| 956 |
{/*OrderModifier=*/maybeApply(convert3, t0), /*Ordering=*/convert2(t1)}}; |
| 957 |
} |
| 958 |
|
| 959 |
Ordered make(const parser::OmpClause::Ordered &inp, |
| 960 |
semantics::SemanticsContext &semaCtx) { |
| 961 |
// inp.v -> std::optional<parser::ScalarIntConstantExpr> |
| 962 |
return Ordered{/*N=*/maybeApply(makeExprFn(semaCtx), inp.v)}; |
| 963 |
} |
| 964 |
|
| 965 |
// Otherwise: incomplete, missing-in-parser |
| 966 |
|
| 967 |
Partial make(const parser::OmpClause::Partial &inp, |
| 968 |
semantics::SemanticsContext &semaCtx) { |
| 969 |
// inp.v -> std::optional<parser::ScalarIntConstantExpr> |
| 970 |
return Partial{/*UnrollFactor=*/maybeApply(makeExprFn(semaCtx), inp.v)}; |
| 971 |
} |
| 972 |
|
| 973 |
Priority make(const parser::OmpClause::Priority &inp, |
| 974 |
semantics::SemanticsContext &semaCtx) { |
| 975 |
// inp.v -> parser::ScalarIntExpr |
| 976 |
return Priority{/*PriorityValue=*/makeExpr(inp.v, semaCtx)}; |
| 977 |
} |
| 978 |
|
| 979 |
Private make(const parser::OmpClause::Private &inp, |
| 980 |
semantics::SemanticsContext &semaCtx) { |
| 981 |
// inp.v -> parser::OmpObjectList |
| 982 |
return Private{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 983 |
} |
| 984 |
|
| 985 |
ProcBind make(const parser::OmpClause::ProcBind &inp, |
| 986 |
semantics::SemanticsContext &semaCtx) { |
| 987 |
// inp.v -> parser::OmpProcBindClause |
| 988 |
using wrapped = parser::OmpProcBindClause; |
| 989 |
|
| 990 |
CLAUSET_ENUM_CONVERT( // |
| 991 |
convert, wrapped::Type, ProcBind::AffinityPolicy, |
| 992 |
// clang-format off |
| 993 |
MS(Close, Close) |
| 994 |
MS(Master, Master) |
| 995 |
MS(Spread, Spread) |
| 996 |
MS(Primary, Primary) |
| 997 |
// clang-format on |
| 998 |
); |
| 999 |
return ProcBind{/*AffinityPolicy=*/convert(inp.v.v)}; |
| 1000 |
} |
| 1001 |
|
| 1002 |
// Read: empty |
| 1003 |
|
| 1004 |
Reduction make(const parser::OmpClause::Reduction &inp, |
| 1005 |
semantics::SemanticsContext &semaCtx) { |
| 1006 |
// inp.v -> parser::OmpReductionClause |
| 1007 |
using wrapped = parser::OmpReductionClause; |
| 1008 |
|
| 1009 |
CLAUSET_ENUM_CONVERT( // |
| 1010 |
convert, wrapped::ReductionModifier, Reduction::ReductionModifier, |
| 1011 |
// clang-format off |
| 1012 |
MS(Inscan, Inscan) |
| 1013 |
MS(Task, Task) |
| 1014 |
MS(Default, Default) |
| 1015 |
// clang-format on |
| 1016 |
); |
| 1017 |
|
| 1018 |
auto &t0 = |
| 1019 |
std::get<std::optional<parser::OmpReductionClause::ReductionModifier>>( |
| 1020 |
inp.v.t); |
| 1021 |
auto &t1 = std::get<parser::OmpReductionOperator>(inp.v.t); |
| 1022 |
auto &t2 = std::get<parser::OmpObjectList>(inp.v.t); |
| 1023 |
return Reduction{ |
| 1024 |
{/*ReductionModifier=*/t0 |
| 1025 |
? std::make_optional<Reduction::ReductionModifier>(convert(*t0)) |
| 1026 |
: std::nullopt, |
| 1027 |
/*ReductionIdentifiers=*/{makeReductionOperator(t1, semaCtx)}, |
| 1028 |
/*List=*/makeObjects(t2, semaCtx)}}; |
| 1029 |
} |
| 1030 |
|
| 1031 |
// Relaxed: empty |
| 1032 |
// Release: empty |
| 1033 |
// ReverseOffload: empty |
| 1034 |
|
| 1035 |
Safelen make(const parser::OmpClause::Safelen &inp, |
| 1036 |
semantics::SemanticsContext &semaCtx) { |
| 1037 |
// inp.v -> parser::ScalarIntConstantExpr |
| 1038 |
return Safelen{/*Length=*/makeExpr(inp.v, semaCtx)}; |
| 1039 |
} |
| 1040 |
|
| 1041 |
Schedule make(const parser::OmpClause::Schedule &inp, |
| 1042 |
semantics::SemanticsContext &semaCtx) { |
| 1043 |
// inp.v -> parser::OmpScheduleClause |
| 1044 |
using wrapped = parser::OmpScheduleClause; |
| 1045 |
|
| 1046 |
CLAUSET_ENUM_CONVERT( // |
| 1047 |
convert1, wrapped::ScheduleType, Schedule::Kind, |
| 1048 |
// clang-format off |
| 1049 |
MS(Static, Static) |
| 1050 |
MS(Dynamic, Dynamic) |
| 1051 |
MS(Guided, Guided) |
| 1052 |
MS(Auto, Auto) |
| 1053 |
MS(Runtime, Runtime) |
| 1054 |
// clang-format on |
| 1055 |
); |
| 1056 |
|
| 1057 |
CLAUSET_ENUM_CONVERT( // |
| 1058 |
convert2, parser::OmpScheduleModifierType::ModType, |
| 1059 |
Schedule::OrderingModifier, |
| 1060 |
// clang-format off |
| 1061 |
MS(Monotonic, Monotonic) |
| 1062 |
MS(Nonmonotonic, Nonmonotonic) |
| 1063 |
// clang-format on |
| 1064 |
); |
| 1065 |
|
| 1066 |
CLAUSET_ENUM_CONVERT( // |
| 1067 |
convert3, parser::OmpScheduleModifierType::ModType, |
| 1068 |
Schedule::ChunkModifier, |
| 1069 |
// clang-format off |
| 1070 |
MS(Simd, Simd) |
| 1071 |
// clang-format on |
| 1072 |
); |
| 1073 |
|
| 1074 |
auto &t0 = std::get<std::optional<parser::OmpScheduleModifier>>(inp.v.t); |
| 1075 |
auto &t1 = std::get<wrapped::ScheduleType>(inp.v.t); |
| 1076 |
auto &t2 = std::get<std::optional<parser::ScalarIntExpr>>(inp.v.t); |
| 1077 |
|
| 1078 |
if (!t0) { |
| 1079 |
return Schedule{{/*Kind=*/convert1(t1), /*OrderingModifier=*/std::nullopt, |
| 1080 |
/*ChunkModifier=*/std::nullopt, |
| 1081 |
/*ChunkSize=*/maybeApply(makeExprFn(semaCtx), t2)}}; |
| 1082 |
} |
| 1083 |
|
| 1084 |
// The members of parser::OmpScheduleModifier correspond to OrderingModifier, |
| 1085 |
// and ChunkModifier, but they can appear in any order. |
| 1086 |
auto &m1 = std::get<parser::OmpScheduleModifier::Modifier1>(t0->t); |
| 1087 |
auto &m2 = |
| 1088 |
std::get<std::optional<parser::OmpScheduleModifier::Modifier2>>(t0->t); |
| 1089 |
|
| 1090 |
std::optional<Schedule::OrderingModifier> omod; |
| 1091 |
std::optional<Schedule::ChunkModifier> cmod; |
| 1092 |
|
| 1093 |
if (m1.v.v == parser::OmpScheduleModifierType::ModType::Simd) { |
| 1094 |
// m1 is chunk-modifier |
| 1095 |
cmod = convert3(m1.v.v); |
| 1096 |
if (m2) |
| 1097 |
omod = convert2(m2->v.v); |
| 1098 |
} else { |
| 1099 |
// m1 is ordering-modifier |
| 1100 |
omod = convert2(m1.v.v); |
| 1101 |
if (m2) |
| 1102 |
cmod = convert3(m2->v.v); |
| 1103 |
} |
| 1104 |
|
| 1105 |
return Schedule{{/*Kind=*/convert1(t1), |
| 1106 |
/*OrderingModifier=*/omod, |
| 1107 |
/*ChunkModifier=*/cmod, |
| 1108 |
/*ChunkSize=*/maybeApply(makeExprFn(semaCtx), t2)}}; |
| 1109 |
} |
| 1110 |
|
| 1111 |
// SeqCst: empty |
| 1112 |
|
| 1113 |
Severity make(const parser::OmpClause::Severity &inp, |
| 1114 |
semantics::SemanticsContext &semaCtx) { |
| 1115 |
// inp -> empty |
| 1116 |
llvm_unreachable("Empty: severity"); |
| 1117 |
} |
| 1118 |
|
| 1119 |
Shared make(const parser::OmpClause::Shared &inp, |
| 1120 |
semantics::SemanticsContext &semaCtx) { |
| 1121 |
// inp.v -> parser::OmpObjectList |
| 1122 |
return Shared{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 1123 |
} |
| 1124 |
|
| 1125 |
// Simd: empty |
| 1126 |
|
| 1127 |
Simdlen make(const parser::OmpClause::Simdlen &inp, |
| 1128 |
semantics::SemanticsContext &semaCtx) { |
| 1129 |
// inp.v -> parser::ScalarIntConstantExpr |
| 1130 |
return Simdlen{/*Length=*/makeExpr(inp.v, semaCtx)}; |
| 1131 |
} |
| 1132 |
|
| 1133 |
Sizes make(const parser::OmpClause::Sizes &inp, |
| 1134 |
semantics::SemanticsContext &semaCtx) { |
| 1135 |
// inp.v -> std::list<parser::ScalarIntExpr> |
| 1136 |
return Sizes{/*SizeList=*/makeList(inp.v, makeExprFn(semaCtx))}; |
| 1137 |
} |
| 1138 |
|
| 1139 |
TaskReduction make(const parser::OmpClause::TaskReduction &inp, |
| 1140 |
semantics::SemanticsContext &semaCtx) { |
| 1141 |
// inp.v -> parser::OmpReductionClause |
| 1142 |
auto &t0 = std::get<parser::OmpReductionOperator>(inp.v.t); |
| 1143 |
auto &t1 = std::get<parser::OmpObjectList>(inp.v.t); |
| 1144 |
return TaskReduction{ |
| 1145 |
{/*ReductionIdentifiers=*/{makeReductionOperator(t0, semaCtx)}, |
| 1146 |
/*List=*/makeObjects(t1, semaCtx)}}; |
| 1147 |
} |
| 1148 |
|
| 1149 |
ThreadLimit make(const parser::OmpClause::ThreadLimit &inp, |
| 1150 |
semantics::SemanticsContext &semaCtx) { |
| 1151 |
// inp.v -> parser::ScalarIntExpr |
| 1152 |
return ThreadLimit{/*Threadlim=*/makeExpr(inp.v, semaCtx)}; |
| 1153 |
} |
| 1154 |
|
| 1155 |
// Threadprivate: empty |
| 1156 |
// Threads: empty |
| 1157 |
|
| 1158 |
To make(const parser::OmpClause::To &inp, |
| 1159 |
semantics::SemanticsContext &semaCtx) { |
| 1160 |
// inp.v -> parser::OmpObjectList |
| 1161 |
return To{{/*Expectation=*/std::nullopt, /*Mapper=*/std::nullopt, |
| 1162 |
/*Iterator=*/std::nullopt, |
| 1163 |
/*LocatorList=*/makeObjects(inp.v, semaCtx)}}; |
| 1164 |
} |
| 1165 |
|
| 1166 |
// UnifiedAddress: empty |
| 1167 |
// UnifiedSharedMemory: empty |
| 1168 |
|
| 1169 |
Uniform make(const parser::OmpClause::Uniform &inp, |
| 1170 |
semantics::SemanticsContext &semaCtx) { |
| 1171 |
// inp.v -> std::list<parser::Name> |
| 1172 |
return Uniform{/*ParameterList=*/makeList(inp.v, makeObjectFn(semaCtx))}; |
| 1173 |
} |
| 1174 |
|
| 1175 |
// Unknown: empty |
| 1176 |
// Untied: empty |
| 1177 |
|
| 1178 |
Update make(const parser::OmpClause::Update &inp, |
| 1179 |
semantics::SemanticsContext &semaCtx) { |
| 1180 |
// inp -> empty |
| 1181 |
return Update{/*TaskDependenceType=*/std::nullopt}; |
| 1182 |
} |
| 1183 |
|
| 1184 |
Use make(const parser::OmpClause::Use &inp, |
| 1185 |
semantics::SemanticsContext &semaCtx) { |
| 1186 |
// inp -> empty |
| 1187 |
llvm_unreachable("Empty: use"); |
| 1188 |
} |
| 1189 |
|
| 1190 |
UseDeviceAddr make(const parser::OmpClause::UseDeviceAddr &inp, |
| 1191 |
semantics::SemanticsContext &semaCtx) { |
| 1192 |
// inp.v -> parser::OmpObjectList |
| 1193 |
return UseDeviceAddr{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 1194 |
} |
| 1195 |
|
| 1196 |
UseDevicePtr make(const parser::OmpClause::UseDevicePtr &inp, |
| 1197 |
semantics::SemanticsContext &semaCtx) { |
| 1198 |
// inp.v -> parser::OmpObjectList |
| 1199 |
return UseDevicePtr{/*List=*/makeObjects(inp.v, semaCtx)}; |
| 1200 |
} |
| 1201 |
|
| 1202 |
UsesAllocators make(const parser::OmpClause::UsesAllocators &inp, |
| 1203 |
semantics::SemanticsContext &semaCtx) { |
| 1204 |
// inp -> empty |
| 1205 |
llvm_unreachable("Empty: uses_allocators"); |
| 1206 |
} |
| 1207 |
|
| 1208 |
// Weak: empty |
| 1209 |
// When: incomplete |
| 1210 |
// Write: empty |
| 1211 |
} // namespace clause |
| 1212 |
|
| 1213 |
Clause makeClause(const parser::OmpClause &cls, |
| 1214 |
semantics::SemanticsContext &semaCtx) { |
| 1215 |
return Fortran::common::visit( |
| 1216 |
[&](auto &&s) { |
| 1217 |
return makeClause(getClauseId(cls), clause::make(s, semaCtx), |
| 1218 |
cls.source); |
| 1219 |
}, |
| 1220 |
cls.u); |
| 1221 |
} |
| 1222 |
|
| 1223 |
List<Clause> makeClauses(const parser::OmpClauseList &clauses, |
| 1224 |
semantics::SemanticsContext &semaCtx) { |
| 1225 |
return makeList(clauses.v, [&](const parser::OmpClause &s) { |
| 1226 |
return makeClause(s, semaCtx); |
| 1227 |
}); |
| 1228 |
} |
| 1229 |
|
| 1230 |
bool transferLocations(const List<Clause> &from, List<Clause> &to) { |
| 1231 |
bool allDone = true; |
| 1232 |
|
| 1233 |
for (Clause &clause : to) { |
| 1234 |
if (!clause.source.empty()) |
| 1235 |
continue; |
| 1236 |
auto found = |
| 1237 |
llvm::find_if(from, [&](const Clause &c) { return c.id == clause.id; }); |
| 1238 |
// This is not completely accurate, but should be good enough for now. |
| 1239 |
// It can be improved in the future if necessary, but in cases of |
| 1240 |
// synthesized clauses getting accurate location may be impossible. |
| 1241 |
if (found != from.end()) { |
| 1242 |
clause.source = found->source; |
| 1243 |
} else { |
| 1244 |
// Found a clause that won't have "source". |
| 1245 |
allDone = false; |
| 1246 |
} |
| 1247 |
} |
| 1248 |
|
| 1249 |
return allDone; |
| 1250 |
} |
| 1251 |
|
| 1252 |
} // namespace Fortran::lower::omp |