Skip to content

Commit 583d492

Browse files
committed
[flang][hlfir] Lower vector subscripted RHS designators
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
1 parent bdc9914 commit 583d492

File tree

5 files changed

+479
-47
lines changed

5 files changed

+479
-47
lines changed

flang/include/flang/Optimizer/Builder/HLFIRTools.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace hlfir {
2727

2828
class AssociateOp;
2929
class ElementalOp;
30+
class ElementalAddrOp;
3031
class YieldElementOp;
3132

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

394+
/// Clone an hlfir.elemental_addr into an hlfir.elemental value.
395+
hlfir::ElementalOp cloneToElementalOp(mlir::Location loc,
396+
fir::FirOpBuilder &builder,
397+
hlfir::ElementalAddrOp elementalAddrOp);
398+
393399
} // namespace hlfir
394400

395401
#endif // FORTRAN_OPTIMIZER_BUILDER_HLFIRTOOLS_H

flang/lib/Lower/Bridge.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
29942994
Fortran::common::visitors{
29952995
// [1] Plain old assignment.
29962996
[&](const Fortran::evaluate::Assignment::Intrinsic &) {
2997+
if (Fortran::evaluate::HasVectorSubscript(assign.lhs))
2998+
TODO(loc, "assignment to vector subscripted entity");
29972999
Fortran::lower::StatementContext stmtCtx;
29983000
hlfir::Entity rhs = Fortran::lower::convertExprToHLFIR(
29993001
loc, *this, assign.rhs, localSymbols, stmtCtx);

0 commit comments

Comments
 (0)