Skip to content

Commit 153231e

Browse files
committed
Respond to review comments.
Also remove the special handling of constants, which is no longer needed.
1 parent 124bba4 commit 153231e

File tree

5 files changed

+315
-314
lines changed

5 files changed

+315
-314
lines changed

flang/include/flang/Lower/ConvertExpr.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,24 @@ createSomeArrayTempValue(AbstractConverter &converter,
169169
const evaluate::Expr<evaluate::SomeType> &expr,
170170
SymMap &symMap, StatementContext &stmtCtx);
171171

172+
// Lambda to reload the dynamically allocated pointers to a lazy buffer and its
173+
// extents. This is used to introduce these ssa-values in a place that will
174+
// dominate any/all subsequent uses after the loop that created the lazy buffer.
175+
using LoadLazyBufferLambda =
176+
std::function<std::pair<fir::ExtendedValue, mlir::Value>(
177+
fir::FirOpBuilder &)>;
178+
179+
// Creating a lazy array temporary returns a pair of values. The first is an
180+
// extended value which is a pointer to the buffer, of array type, with the
181+
// appropriate dynamic extents. The second argument is a continuation to reload
182+
// the buffer at some future point in the code gen.
183+
using CreateLazyArrayResult =
184+
std::pair<fir::ExtendedValue, LoadLazyBufferLambda>;
185+
172186
/// Like createSomeArrayTempValue, but the temporary buffer is allocated lazily
173187
/// (inside the loops instead of before the loops). This can be useful if a
174188
/// loop's bounds are functions of other loop indices, for example.
175-
std::pair<fir::ExtendedValue,
176-
std::function<
177-
std::pair<fir::ExtendedValue, mlir::Value>(fir::FirOpBuilder &)>>
189+
CreateLazyArrayResult
178190
createLazyArrayTempValue(AbstractConverter &converter,
179191
const evaluate::Expr<evaluate::SomeType> &expr,
180192
mlir::Value var, mlir::Value shapeBuffer,

flang/lib/Lower/ConvertExpr.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2819,11 +2819,7 @@ class ScalarArrayExprLowering {
28192819
}
28202820
template <typename A>
28212821
ExtValue gen(const Fortran::evaluate::Constant<A> &x) {
2822-
auto insPt = builder.saveInsertionPoint();
2823-
builder.setInsertionPoint(expSpace.getOuterLoop());
2824-
auto result = asScalar(x);
2825-
builder.restoreInsertionPoint(insPt);
2826-
return result;
2822+
return asScalar(x);
28272823
}
28282824
ExtValue gen(const Fortran::evaluate::ProcedureDesignator &x) {
28292825
return asScalar(x);
@@ -3307,9 +3303,7 @@ class ArrayExprLowering {
33073303
return fir::ArrayBoxValue(tempRes, dest.getExtents());
33083304
}
33093305

3310-
static std::pair<ExtValue, std::function<std::pair<ExtValue, mlir::Value>(
3311-
fir::FirOpBuilder &)>>
3312-
lowerLazyArrayExpression(
3306+
static Fortran::lower::CreateLazyArrayResult lowerLazyArrayExpression(
33133307
Fortran::lower::AbstractConverter &converter,
33143308
Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx,
33153309
const Fortran::evaluate::Expr<Fortran::evaluate::SomeType> &expr,
@@ -3321,9 +3315,7 @@ class ArrayExprLowering {
33213315
/// Lower the expression \p expr into a buffer that is created on demand. The
33223316
/// variable containing the pointer to the buffer is \p var and the variable
33233317
/// containing the shape of the buffer is \p shapeBuffer.
3324-
std::pair<ExtValue, std::function<std::pair<ExtValue, mlir::Value>(
3325-
fir::FirOpBuilder &)>>
3326-
lowerLazyArrayExpression(
3318+
Fortran::lower::CreateLazyArrayResult lowerLazyArrayExpression(
33273319
const Fortran::evaluate::Expr<Fortran::evaluate::SomeType> &expr,
33283320
mlir::Value var, mlir::Value shapeBuffer) {
33293321
auto loc = getLoc();
@@ -6070,10 +6062,7 @@ fir::ExtendedValue Fortran::lower::createSomeArrayTempValue(
60706062
expr);
60716063
}
60726064

6073-
std::pair<fir::ExtendedValue,
6074-
std::function<
6075-
std::pair<fir::ExtendedValue, mlir::Value>(fir::FirOpBuilder &)>>
6076-
Fortran::lower::createLazyArrayTempValue(
6065+
Fortran::lower::CreateLazyArrayResult Fortran::lower::createLazyArrayTempValue(
60776066
Fortran::lower::AbstractConverter &converter,
60786067
const Fortran::evaluate::Expr<Fortran::evaluate::SomeType> &expr,
60796068
mlir::Value var, mlir::Value shapeBuffer, Fortran::lower::SymMap &symMap,

flang/test/Lower/forall-2.f90

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -80,39 +80,39 @@ subroutine slice_with_explicit_iters
8080
! CHECK: %[[VAL_8:.*]] = constant 1 : index
8181
! CHECK: %[[VAL_9:.*]] = fir.shape %[[VAL_1]], %[[VAL_2]] : (index, index) -> !fir.shape<2>
8282
! CHECK: %[[VAL_10:.*]] = fir.array_load %[[VAL_3]](%[[VAL_9]]) : (!fir.ref<!fir.array<10x10xi32>>, !fir.shape<2>) -> !fir.array<10x10xi32>
83-
! CHECK: %[[VAL_11:.*]] = constant 1 : i64
84-
! CHECK: %[[VAL_12:.*]] = constant 1 : i64
85-
! CHECK: %[[VAL_13:.*]] = fir.do_loop %[[VAL_14:.*]] = %[[VAL_5]] to %[[VAL_7]] step %[[VAL_8]] unordered iter_args(%[[VAL_15:.*]] = %[[VAL_10]]) -> (!fir.array<10x10xi32>) {
86-
! CHECK: %[[VAL_16:.*]] = fir.convert %[[VAL_14]] : (index) -> i32
87-
! CHECK: fir.store %[[VAL_16]] to %[[VAL_0]] : !fir.ref<i32>
88-
! CHECK: %[[VAL_17:.*]] = constant 1 : i64
89-
! CHECK: %[[VAL_18:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
90-
! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (i32) -> i64
91-
! CHECK: %[[VAL_20:.*]] = constant 1 : i64
92-
! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_20]] : (i64) -> index
93-
! CHECK: %[[VAL_22:.*]] = constant 0 : index
94-
! CHECK: %[[VAL_23:.*]] = fir.convert %[[VAL_17]] : (i64) -> index
95-
! CHECK: %[[VAL_24:.*]] = fir.convert %[[VAL_19]] : (i64) -> index
96-
! CHECK: %[[VAL_25:.*]] = subi %[[VAL_24]], %[[VAL_23]] : index
97-
! CHECK: %[[VAL_26:.*]] = addi %[[VAL_25]], %[[VAL_21]] : index
98-
! CHECK: %[[VAL_27:.*]] = divi_signed %[[VAL_26]], %[[VAL_21]] : index
99-
! CHECK: %[[VAL_28:.*]] = cmpi sgt, %[[VAL_27]], %[[VAL_22]] : index
100-
! CHECK: %[[VAL_29:.*]] = select %[[VAL_28]], %[[VAL_27]], %[[VAL_22]] : index
101-
! CHECK: %[[VAL_30:.*]] = constant 1 : index
102-
! CHECK: %[[VAL_31:.*]] = constant 0 : index
103-
! CHECK: %[[VAL_32:.*]] = subi %[[VAL_29]], %[[VAL_30]] : index
104-
! CHECK: %[[VAL_33:.*]] = fir.do_loop %[[VAL_34:.*]] = %[[VAL_31]] to %[[VAL_32]] step %[[VAL_30]] unordered iter_args(%[[VAL_35:.*]] = %[[VAL_15]]) -> (!fir.array<10x10xi32>) {
105-
! CHECK: %[[VAL_36:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
106-
! CHECK: %[[VAL_37:.*]] = constant 0 : i32
107-
! CHECK: %[[VAL_38:.*]] = subi %[[VAL_37]], %[[VAL_36]] : i32
108-
! CHECK: %[[VAL_39:.*]] = fir.convert %[[VAL_11]] : (i64) -> index
109-
! CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_12]] : (i64) -> index
110-
! CHECK: %[[VAL_41:.*]] = muli %[[VAL_34]], %[[VAL_40]] : index
111-
! CHECK: %[[VAL_42:.*]] = addi %[[VAL_39]], %[[VAL_41]] : index
83+
! CHECK: %[[VAL_11:.*]] = fir.do_loop %[[VAL_12:.*]] = %[[VAL_5]] to %[[VAL_7]] step %[[VAL_8]] unordered iter_args(%[[VAL_13:.*]] = %[[VAL_10]]) -> (!fir.array<10x10xi32>) {
84+
! CHECK: %[[VAL_14:.*]] = fir.convert %[[VAL_12]] : (index) -> i32
85+
! CHECK: fir.store %[[VAL_14]] to %[[VAL_0]] : !fir.ref<i32>
86+
! CHECK: %[[VAL_15:.*]] = constant 1 : i64
87+
! CHECK: %[[VAL_16:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
88+
! CHECK: %[[VAL_17:.*]] = fir.convert %[[VAL_16]] : (i32) -> i64
89+
! CHECK: %[[VAL_18:.*]] = constant 1 : i64
90+
! CHECK: %[[VAL_19:.*]] = fir.convert %[[VAL_18]] : (i64) -> index
91+
! CHECK: %[[VAL_20:.*]] = constant 0 : index
92+
! CHECK: %[[VAL_21:.*]] = fir.convert %[[VAL_15]] : (i64) -> index
93+
! CHECK: %[[VAL_22:.*]] = fir.convert %[[VAL_17]] : (i64) -> index
94+
! CHECK: %[[VAL_23:.*]] = subi %[[VAL_22]], %[[VAL_21]] : index
95+
! CHECK: %[[VAL_24:.*]] = addi %[[VAL_23]], %[[VAL_19]] : index
96+
! CHECK: %[[VAL_25:.*]] = divi_signed %[[VAL_24]], %[[VAL_19]] : index
97+
! CHECK: %[[VAL_26:.*]] = cmpi sgt, %[[VAL_25]], %[[VAL_20]] : index
98+
! CHECK: %[[VAL_27:.*]] = select %[[VAL_26]], %[[VAL_25]], %[[VAL_20]] : index
99+
! CHECK: %[[VAL_28:.*]] = constant 1 : index
100+
! CHECK: %[[VAL_29:.*]] = constant 0 : index
101+
! CHECK: %[[VAL_30:.*]] = subi %[[VAL_27]], %[[VAL_28]] : index
102+
! CHECK: %[[VAL_31:.*]] = fir.do_loop %[[VAL_32:.*]] = %[[VAL_29]] to %[[VAL_30]] step %[[VAL_28]] unordered iter_args(%[[VAL_33:.*]] = %[[VAL_13]]) -> (!fir.array<10x10xi32>) {
103+
! CHECK: %[[VAL_34:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
104+
! CHECK: %[[VAL_35:.*]] = constant 0 : i32
105+
! CHECK: %[[VAL_36:.*]] = subi %[[VAL_35]], %[[VAL_34]] : i32
106+
! CHECK: %[[VAL_37:.*]] = constant 1 : i64
107+
! CHECK: %[[VAL_38:.*]] = fir.convert %[[VAL_37]] : (i64) -> index
108+
! CHECK: %[[VAL_39:.*]] = constant 1 : i64
109+
! CHECK: %[[VAL_40:.*]] = fir.convert %[[VAL_39]] : (i64) -> index
110+
! CHECK: %[[VAL_41:.*]] = muli %[[VAL_32]], %[[VAL_40]] : index
111+
! CHECK: %[[VAL_42:.*]] = addi %[[VAL_38]], %[[VAL_41]] : index
112112
! CHECK: %[[VAL_43:.*]] = fir.load %[[VAL_0]] : !fir.ref<i32>
113113
! CHECK: %[[VAL_44:.*]] = fir.convert %[[VAL_43]] : (i32) -> i64
114114
! CHECK: %[[VAL_45:.*]] = fir.convert %[[VAL_44]] : (i64) -> index
115-
! CHECK: %[[VAL_46:.*]] = fir.array_update %[[VAL_35]], %[[VAL_38]], %[[VAL_42]], %[[VAL_45]] {Fortran.offsets} : (!fir.array<10x10xi32>, i32, index, index) -> !fir.array<10x10xi32>
115+
! CHECK: %[[VAL_46:.*]] = fir.array_update %[[VAL_33]], %[[VAL_36]], %[[VAL_42]], %[[VAL_45]] {Fortran.offsets} : (!fir.array<10x10xi32>, i32, index, index) -> !fir.array<10x10xi32>
116116
! CHECK: fir.result %[[VAL_46]] : !fir.array<10x10xi32>
117117
! CHECK: }
118118
! CHECK: fir.result %[[VAL_47:.*]] : !fir.array<10x10xi32>

0 commit comments

Comments
 (0)