LAA: improve code in getStrideFromPointer (NFC) (#124780)
[llvm-project.git] / flang / lib / Lower / ComponentPath.cpp
blob5bdbca6062e6da6075a4627f9123835c32f39f6d
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 //===----------------------------------------------------------------------===//
9 #include "flang/Lower/ComponentPath.h"
11 static std::function<
12 Fortran::lower::IterationSpace(const Fortran::lower::IterationSpace &)>
13 getIdentityFunc() {
14 return [](const Fortran::lower::IterationSpace &s) { return s; };
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;
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();
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;
48 return false;
51 void Fortran::lower::ComponentPath::resetPC() { pc = getIdentityFunc(); }
53 void Fortran::lower::ComponentPath::setPC(bool isImplicit) {
54 pc = isImplicit ? getIdentityFunc() : getNullaryFunc();
55 resetExtendCoorRef();
58 Fortran::lower::ComponentPath::ExtendRefFunc
59 Fortran::lower::ComponentPath::getExtendCoorRef() const {
60 return hasExtendCoorRef() ? *extendCoorRef : [](mlir::Value v) { return v; };