Skip to content

Commit d6d9a8b

Browse files
clementvaljeanPerierschweitzpgi
committed
[flang] Lower more array expression
This patch adds more lowering for array expressions. This patch is part of the upstreaming effort from fir-dev branch. Reviewed By: PeteSteinfeld Differential Revision: https://reviews.llvm.org/D121952 Co-authored-by: Jean Perier <[email protected]> Co-authored-by: Eric Schweitz <[email protected]>
1 parent 1ebf1af commit d6d9a8b

File tree

2 files changed

+1214
-5
lines changed

2 files changed

+1214
-5
lines changed

flang/lib/Lower/ConvertExpr.cpp

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4506,14 +4506,34 @@ class ArrayExprLowering {
45064506
TODO(getLoc(), "genarr ComplexConstructor<KIND>");
45074507
}
45084508

4509+
/// Fortran's concatenation operator `//`.
45094510
template <int KIND>
45104511
CC genarr(const Fortran::evaluate::Concat<KIND> &x) {
4511-
TODO(getLoc(), "genarr Concat<KIND>");
4512+
mlir::Location loc = getLoc();
4513+
auto lf = genarr(x.left());
4514+
auto rf = genarr(x.right());
4515+
return [=](IterSpace iters) -> ExtValue {
4516+
auto lhs = lf(iters);
4517+
auto rhs = rf(iters);
4518+
const fir::CharBoxValue *lchr = lhs.getCharBox();
4519+
const fir::CharBoxValue *rchr = rhs.getCharBox();
4520+
if (lchr && rchr) {
4521+
return fir::factory::CharacterExprHelper{builder, loc}
4522+
.createConcatenate(*lchr, *rchr);
4523+
}
4524+
TODO(loc, "concat on unexpected extended values");
4525+
return mlir::Value{};
4526+
};
45124527
}
45134528

45144529
template <int KIND>
45154530
CC genarr(const Fortran::evaluate::SetLength<KIND> &x) {
4516-
TODO(getLoc(), "genarr SetLength<KIND>");
4531+
auto lf = genarr(x.left());
4532+
mlir::Value rhs = fir::getBase(asScalar(x.right()));
4533+
return [=](IterSpace iters) -> ExtValue {
4534+
mlir::Value lhs = fir::getBase(lf(iters));
4535+
return fir::CharBoxValue{lhs, rhs};
4536+
};
45174537
}
45184538

45194539
template <typename A>
@@ -5707,8 +5727,32 @@ class ArrayExprLowering {
57075727
};
57085728
}
57095729

5730+
/// Lower a component path with or without rank.
5731+
/// Example: <code>array%baz%qux%waldo</code>
57105732
CC genarr(const Fortran::evaluate::Component &x, ComponentPath &components) {
5711-
TODO(getLoc(), "genarr Component");
5733+
if (explicitSpaceIsActive()) {
5734+
if (x.base().Rank() == 0 && x.Rank() > 0)
5735+
components.reversePath.push_back(ImplicitSubscripts{});
5736+
if (fir::ArrayLoadOp load = explicitSpace->findBinding(&x))
5737+
return applyPathToArrayLoad(load, components);
5738+
} else {
5739+
if (x.base().Rank() == 0)
5740+
return genImplicitArrayAccess(x, components);
5741+
}
5742+
bool atEnd = pathIsEmpty(components);
5743+
if (!getLastSym(x).test(Fortran::semantics::Symbol::Flag::ParentComp))
5744+
// Skip parent components; their components are placed directly in the
5745+
// object.
5746+
components.reversePath.push_back(&x);
5747+
auto result = genarr(x.base(), components);
5748+
if (components.applied)
5749+
return result;
5750+
if (atEnd)
5751+
return genAsScalar(x);
5752+
mlir::Location loc = getLoc();
5753+
return [=](IterSpace) -> ExtValue {
5754+
fir::emitFatalError(loc, "reached component with path");
5755+
};
57125756
}
57135757

57145758
/// Array reference with subscripts. If this has rank > 0, this is a form
@@ -5910,7 +5954,8 @@ class ArrayExprLowering {
59105954

59115955
CC genarr(const Fortran::evaluate::ComplexPart &x,
59125956
ComponentPath &components) {
5913-
TODO(getLoc(), "genarr ComplexPart");
5957+
components.reversePath.push_back(&x);
5958+
return genarr(x.complex(), components);
59145959
}
59155960

59165961
CC genarr(const Fortran::evaluate::StaticDataObject::Pointer &,
@@ -5920,7 +5965,9 @@ class ArrayExprLowering {
59205965

59215966
/// Substrings (see 9.4.1)
59225967
CC genarr(const Fortran::evaluate::Substring &x, ComponentPath &components) {
5923-
TODO(getLoc(), "genarr Substring");
5968+
components.substring = &x;
5969+
return std::visit([&](const auto &v) { return genarr(v, components); },
5970+
x.parent());
59245971
}
59255972

59265973
/// Base case of generating an array reference,

0 commit comments

Comments
 (0)