Skip to content

Commit

Permalink
[flang][hlfir] Lower vector subscripted RHS designators
Browse files Browse the repository at this point in the history
Lower vector subscripted designators as values when they appear outside
of the assignment left-hand side and input IO contexts.

This matches Fortran semantics where vector subscripted designators cannot
be written to outside of the two contexts mentioned above: they are
passed/taken by value where they appear.

This patch uses the added hlfir.element_addr to lower vector designators
in lowering. But when reaching the end of the designator lowering, the
hlfir.element_addr is turned into an hlfir.elemental when lowering is
not asking for the hlfir.elemental_addr.

This approach allows lowering vector subscripted in the same way in
while visiting the designator, and only adapt to the context at the
edge.

The part where lowering uses the hlfir.elemental_addr will be
done in further patch as it requires lowering assignments in the
new hlfir.region_assign op, and there is not codegen yet for these
new operations.

Differential Revision: https://reviews.llvm.org/D149480
  • Loading branch information
jeanPerier committed May 3, 2023
1 parent bdc9914 commit 583d492
Show file tree
Hide file tree
Showing 5 changed files with 479 additions and 47 deletions.
6 changes: 6 additions & 0 deletions flang/include/flang/Optimizer/Builder/HLFIRTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ namespace hlfir {

class AssociateOp;
class ElementalOp;
class ElementalAddrOp;
class YieldElementOp;

/// Is this an SSA value type for the value of a Fortran procedure
Expand Down Expand Up @@ -390,6 +391,11 @@ std::pair<fir::ExtendedValue, std::optional<hlfir::CleanupFunction>>
convertToBox(mlir::Location loc, fir::FirOpBuilder &builder,
const hlfir::Entity &entity, mlir::Type targetType);

/// Clone an hlfir.elemental_addr into an hlfir.elemental value.
hlfir::ElementalOp cloneToElementalOp(mlir::Location loc,
fir::FirOpBuilder &builder,
hlfir::ElementalAddrOp elementalAddrOp);

} // namespace hlfir

#endif // FORTRAN_OPTIMIZER_BUILDER_HLFIRTOOLS_H
2 changes: 2 additions & 0 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2994,6 +2994,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
Fortran::common::visitors{
// [1] Plain old assignment.
[&](const Fortran::evaluate::Assignment::Intrinsic &) {
if (Fortran::evaluate::HasVectorSubscript(assign.lhs))
TODO(loc, "assignment to vector subscripted entity");
Fortran::lower::StatementContext stmtCtx;
hlfir::Entity rhs = Fortran::lower::convertExprToHLFIR(
loc, *this, assign.rhs, localSymbols, stmtCtx);
Expand Down

0 comments on commit 583d492

Please sign in to comment.