Skip to content

Commit 90cb2d6

Browse files
authored
Merge pull request #938 from flang-compiler/jpr-host-assoc-review-comments
[NFC] address comments from #907
2 parents 651a3be + fe3cd5d commit 90cb2d6

File tree

6 files changed

+47
-44
lines changed

6 files changed

+47
-44
lines changed

flang/include/flang/Lower/Allocatable.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,16 @@ Fortran::lower::SymbolBox genMutableBoxRead(Fortran::lower::FirOpBuilder &,
9393
/// Update a MutableBoxValue to describe entity \p source (that must be in
9494
/// memory). If \lbounds is not empty, it is used to defined the MutableBoxValue
9595
/// lower bounds, otherwise, the lower bounds from \p source are used.
96-
void associateMutableBoxWithShift(Fortran::lower::FirOpBuilder &,
97-
mlir::Location, const fir::MutableBoxValue &,
98-
const fir::ExtendedValue &source,
99-
mlir::ValueRange lbounds);
96+
void associateMutableBox(Fortran::lower::FirOpBuilder &, mlir::Location,
97+
const fir::MutableBoxValue &,
98+
const fir::ExtendedValue &source,
99+
mlir::ValueRange lbounds);
100100

101101
/// Update a MutableBoxValue to describe the entity designated by the expression
102102
/// \p source. This version takes care of \p source lowering.
103103
/// If \lbounds is not empty, it is used to defined the MutableBoxValue
104104
/// lower bounds, otherwise, the lower bounds from \p source are used.
105-
void associateMutableBoxWithShift(
105+
void associateMutableBox(
106106
Fortran::lower::AbstractConverter &, mlir::Location,
107107
const fir::MutableBoxValue &,
108108
const Fortran::evaluate::Expr<Fortran::evaluate::SomeType> &source,

flang/lib/Lower/Allocatable.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,10 +1110,11 @@ void Fortran::lower::genFinalization(Fortran::lower::FirOpBuilder &builder,
11101110
// MutableBoxValue writing interface implementation
11111111
//===----------------------------------------------------------------------===//
11121112

1113-
void Fortran::lower::associateMutableBoxWithShift(
1114-
Fortran::lower::FirOpBuilder &builder, mlir::Location loc,
1115-
const fir::MutableBoxValue &box, const fir::ExtendedValue &source,
1116-
mlir::ValueRange lbounds) {
1113+
void Fortran::lower::associateMutableBox(Fortran::lower::FirOpBuilder &builder,
1114+
mlir::Location loc,
1115+
const fir::MutableBoxValue &box,
1116+
const fir::ExtendedValue &source,
1117+
mlir::ValueRange lbounds) {
11171118
MutablePropertyWriter writer(builder, loc, box);
11181119
source.match(
11191120
[&](const fir::UnboxedValue &addr) {
@@ -1186,7 +1187,7 @@ isArraySectionWithoutVectorSubscript(const Fortran::lower::SomeExpr &expr) {
11861187
!Fortran::evaluate::HasVectorSubscript(expr);
11871188
}
11881189

1189-
void Fortran::lower::associateMutableBoxWithShift(
1190+
void Fortran::lower::associateMutableBox(
11901191
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
11911192
const fir::MutableBoxValue &box, const Fortran::lower::SomeExpr &source,
11921193
mlir::ValueRange lbounds, Fortran::lower::StatementContext &stmtCtx) {
@@ -1202,7 +1203,7 @@ void Fortran::lower::associateMutableBoxWithShift(
12021203
auto rhs = isArraySectionWithoutVectorSubscript(source)
12031204
? converter.genExprBox(source, stmtCtx, loc)
12041205
: converter.genExprAddr(source, stmtCtx);
1205-
Fortran::lower::associateMutableBoxWithShift(builder, loc, box, rhs, lbounds);
1206+
Fortran::lower::associateMutableBox(builder, loc, box, rhs, lbounds);
12061207
}
12071208

12081209
void Fortran::lower::associateMutableBoxWithRemap(

flang/lib/Lower/Bridge.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,8 +1868,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
18681868
for (const auto &lbExpr : lbExprs)
18691869
lbounds.push_back(
18701870
fir::getBase(genExprValue(toEvExpr(lbExpr), stmtCtx)));
1871-
Fortran::lower::associateMutableBoxWithShift(
1872-
*this, loc, lhs, assign.rhs, lbounds, stmtCtx);
1871+
Fortran::lower::associateMutableBox(*this, loc, lhs, assign.rhs,
1872+
lbounds, stmtCtx);
18731873
},
18741874
[&](const Fortran::evaluate::Assignment::BoundsRemapping
18751875
&boundExprs) {

flang/lib/Lower/ConvertExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,9 @@ class ScalarExprLowering {
652652
},
653653
[&](const fir::MutableBoxValue &toBox) {
654654
if (toBox.isPointer()) {
655-
Fortran::lower::associateMutableBoxWithShift(
656-
converter, loc, toBox, expr.value(), /*lbounds=*/{}, stmtCtx);
655+
Fortran::lower::associateMutableBox(
656+
converter, loc, toBox, expr.value(), /*lbounds=*/llvm::None,
657+
stmtCtx);
657658
return;
658659
}
659660
// For allocatable components, a deep copy is needed.

flang/lib/Lower/HostAssociations.cpp

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@
2828
// mlir tuple (a struct) inside the host containing the addresses and properties
2929
// of variables that are accessed by internal procedures. The address of this
3030
// tuple is passed as an argument by the host when calling internal procedures.
31-
// Internal procedures are propagating this tuple address when calling other
31+
// Internal procedures propagate a reference to this tuple when calling other
3232
// internal procedures of the host.
3333
//
3434
// This file defines how the type of the host tuple is built, how the tuple
3535
// value is created inside the host, and how the host associated variables are
3636
// instantiated inside the internal procedures from the tuple value. The
37-
// CapturedXXX classes are defining each of these three actions for a specific
38-
// kind of variables by providing a `getType`, a `placeInTuple`, and a
37+
// CapturedXXX classes define each of these three actions for a specific
38+
// kind of variables by providing a `getType`, a `instantiateHostTuple`, and a
3939
// `getFromTuple` method. These classes are structured as follow:
4040
//
4141
// class CapturedKindOfVar : public CapturedSymbols<CapturedKindOfVar> {
@@ -45,14 +45,14 @@
4545
// static mlir::Type getType();
4646
// // Build the tuple element value for a host associated variable given its
4747
// // value inside the host. This is called when lowering the host body.
48-
// static void placeInTuple();
48+
// static void instantiateHostTuple();
4949
// // Instantiate a host variable inside an internal procedure given its
5050
// // tuple element value. This is called when lowering internal procedure
5151
// // bodies.
5252
// static void getFromTuple();
5353
// };
5454
//
55-
// If a new kind of variables requires ad-hoc handling, a new CapturedXXX class
55+
// If a new kind of variable requires ad-hoc handling, a new CapturedXXX class
5656
// should be added to handle it, and `walkCaptureCategories` should be updated
5757
// to dispatch this new kind of variable to this new class.
5858

@@ -65,7 +65,7 @@ struct GetTypeInTuple {
6565

6666
/// Struct to be used as argument in walkCaptureCategories when building the
6767
/// tuple element value for a host associated variable.
68-
struct PlaceInTuple {
68+
struct InstantiateHostTuple {
6969
/// walkCaptureCategories returns nothing.
7070
using Result = void;
7171
/// Value of the variable inside the host procedure.
@@ -107,11 +107,11 @@ class CapturedSymbols {
107107
const Fortran::lower::BoxAnalyzer &) {
108108
return SymbolCategory::getType(converter, sym);
109109
}
110-
static void visit(const PlaceInTuple &args,
110+
static void visit(const InstantiateHostTuple &args,
111111
Fortran::lower::AbstractConverter &converter,
112112
const Fortran::semantics::Symbol &sym,
113113
const Fortran::lower::BoxAnalyzer &) {
114-
return SymbolCategory::placeInTuple(args, converter, sym);
114+
return SymbolCategory::instantiateHostTuple(args, converter, sym);
115115
}
116116
static void visit(const GetFromTuple &args,
117117
Fortran::lower::AbstractConverter &converter,
@@ -131,9 +131,9 @@ class CapturedSimpleScalars : public CapturedSymbols<CapturedSimpleScalars> {
131131
return fir::PointerType::get(converter.genType(sym));
132132
}
133133

134-
static void placeInTuple(const PlaceInTuple &args,
135-
Fortran::lower::AbstractConverter &converter,
136-
const Fortran::semantics::Symbol &) {
134+
static void instantiateHostTuple(const InstantiateHostTuple &args,
135+
Fortran::lower::AbstractConverter &converter,
136+
const Fortran::semantics::Symbol &) {
137137
auto &builder = converter.getFirOpBuilder();
138138
auto typeInTuple = fir::dyn_cast_ptrEleTy(args.addrInTuple.getType());
139139
assert(typeInTuple && "addrInTuple must be an address");
@@ -165,9 +165,9 @@ class CapturedCharacterScalars
165165
return fir::BoxCharType::get(&converter.getMLIRContext(), kind);
166166
}
167167

168-
static void placeInTuple(const PlaceInTuple &args,
169-
Fortran::lower::AbstractConverter &converter,
170-
const Fortran::semantics::Symbol &) {
168+
static void instantiateHostTuple(const InstantiateHostTuple &args,
169+
Fortran::lower::AbstractConverter &converter,
170+
const Fortran::semantics::Symbol &) {
171171
auto *charBox = args.hostValue.getCharBox();
172172
assert(charBox && "host value must be a fir::CharBoxValue");
173173
auto &builder = converter.getFirOpBuilder();
@@ -206,9 +206,9 @@ class CapturedAllocatableAndPointer
206206
const Fortran::semantics::Symbol &sym) {
207207
return fir::ReferenceType::get(converter.genType(sym));
208208
}
209-
static void placeInTuple(const PlaceInTuple &args,
210-
Fortran::lower::AbstractConverter &converter,
211-
const Fortran::semantics::Symbol &) {
209+
static void instantiateHostTuple(const InstantiateHostTuple &args,
210+
Fortran::lower::AbstractConverter &converter,
211+
const Fortran::semantics::Symbol &) {
212212
assert(args.hostValue.getBoxOf<fir::MutableBoxValue>() &&
213213
"host value must be a fir::MutableBoxValue");
214214
auto &builder = converter.getFirOpBuilder();
@@ -294,9 +294,9 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
294294
return fir::BoxType::get(fir::PointerType::get(type));
295295
}
296296

297-
static void placeInTuple(const PlaceInTuple &args,
298-
Fortran::lower::AbstractConverter &converter,
299-
const Fortran::semantics::Symbol &sym) {
297+
static void instantiateHostTuple(const InstantiateHostTuple &args,
298+
Fortran::lower::AbstractConverter &converter,
299+
const Fortran::semantics::Symbol &sym) {
300300
auto &builder = converter.getFirOpBuilder();
301301
auto loc = args.loc;
302302
fir::MutableBoxValue boxInTuple(args.addrInTuple, {}, {});
@@ -312,16 +312,17 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
312312
loc, builder.getI1Type(), fir::getBase(args.hostValue));
313313
builder.genIfThenElse(loc, isPresent)
314314
.genThen([&]() {
315-
Fortran::lower::associateMutableBoxWithShift(
316-
builder, loc, boxInTuple, args.hostValue, /*shift*/ llvm::None);
315+
Fortran::lower::associateMutableBox(builder, loc, boxInTuple,
316+
args.hostValue,
317+
/*lbounds=*/llvm::None);
317318
})
318319
.genElse([&]() {
319320
Fortran::lower::disassociateMutableBox(builder, loc, boxInTuple);
320321
})
321322
.end();
322323
} else {
323-
Fortran::lower::associateMutableBoxWithShift(
324-
builder, loc, boxInTuple, args.hostValue, /*shift*/ llvm::None);
324+
Fortran::lower::associateMutableBox(
325+
builder, loc, boxInTuple, args.hostValue, /*lbounds=*/llvm::None);
325326
}
326327
}
327328

@@ -450,9 +451,9 @@ void Fortran::lower::HostAssociations::hostProcedureBindings(
450451
auto off = builder.createIntegerConstant(loc, offTy, indexInTuple);
451452
auto varTy = tupTy.getType(indexInTuple);
452453
auto eleOff = genTupleCoor(builder, loc, varTy, hostTuple, off);
453-
PlaceInTuple placeInTuple{symMap.lookupSymbol(s.value()).toExtendedValue(),
454-
eleOff, loc};
455-
walkCaptureCategories(placeInTuple, converter, *s.value());
454+
InstantiateHostTuple instantiateHostTuple{
455+
symMap.lookupSymbol(s.value()).toExtendedValue(), eleOff, loc};
456+
walkCaptureCategories(instantiateHostTuple, converter, *s.value());
456457
}
457458

458459
converter.bindHostAssocTuple(hostTuple);

flang/lib/Lower/IO.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter,
285285
auto boxType = fir::BoxType::get(fir::PointerType::get(type));
286286
descAddr = builder.createTemporary(loc, boxType);
287287
auto box = fir::MutableBoxValue(descAddr, {}, {});
288-
Fortran::lower::associateMutableBoxWithShift(builder, loc, box, exv,
289-
{});
288+
Fortran::lower::associateMutableBox(builder, loc, box, exv,
289+
/*lbounds=*/llvm::None);
290290
}
291291
descAddr = builder.createConvert(loc, descRefTy, descAddr);
292292
list =

0 commit comments

Comments
 (0)