| 1 | //===-- ComponentPath.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 | #include "flang/Lower/ComponentPath.h" |
| 10 | |
| 11 | static std::function< |
| 12 | Fortran::lower::IterationSpace(const Fortran::lower::IterationSpace &)> |
| 13 | getIdentityFunc() { |
| 14 | return [](const Fortran::lower::IterationSpace &s) { return s; }; |
| 15 | } |
| 16 | |
| 17 | static std::function< |
| 18 | Fortran::lower::IterationSpace(const Fortran::lower::IterationSpace &)> |
| 19 | getNullaryFunc() { |
| 20 | return [](const Fortran::lower::IterationSpace &s) { |
| 21 | Fortran::lower::IterationSpace newIters(s); |
| 22 | newIters.clearIndices(); |
| 23 | return newIters; |
| 24 | }; |
| 25 | } |
| 26 | |
| 27 | void Fortran::lower::ComponentPath::clear() { |
| 28 | reversePath.clear(); |
| 29 | substring = nullptr; |
| 30 | applied = false; |
| 31 | prefixComponents.clear(); |
| 32 | trips.clear(); |
| 33 | suffixComponents.clear(); |
| 34 | pc = getIdentityFunc(); |
| 35 | } |
| 36 | |
| 37 | bool Fortran::lower::isRankedArrayAccess(const Fortran::evaluate::ArrayRef &x) { |
| 38 | for (const Fortran::evaluate::Subscript &sub : x.subscript()) { |
| 39 | if (Fortran::common::visit( |
| 40 | Fortran::common::visitors{ |
| 41 | [&](const Fortran::evaluate::Triplet &) { return true; }, |
| 42 | [&](const Fortran::evaluate::IndirectSubscriptIntegerExpr &e) { |
| 43 | return e.value().Rank() > 0; |
| 44 | }}, |
| 45 | sub.u)) |
| 46 | return true; |
| 47 | } |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | void Fortran::lower::ComponentPath::resetPC() { pc = getIdentityFunc(); } |
| 52 | |
| 53 | void Fortran::lower::ComponentPath::setPC(bool isImplicit) { |
| 54 | pc = isImplicit ? getIdentityFunc() : getNullaryFunc(); |
| 55 | resetExtendCoorRef(); |
| 56 | } |
| 57 | |
| 58 | Fortran::lower::ComponentPath::ExtendRefFunc |
| 59 | Fortran::lower::ComponentPath::getExtendCoorRef() const { |
| 60 | return hasExtendCoorRef() ? *extendCoorRef : [](mlir::Value v) { return v; }; |
| 61 | } |
| 62 | |