Skip to content

Commit 53804e4

Browse files
[flang][NFC] Make LEN parameters homogenous
This patch is part of the upstreaming effort from fir-dev branch. This is the last patch for the upstreaming effort. Reviewed By: jeanPerier Differential Revision: https://reviews.llvm.org/D129187 Co-authored-by: Eric Schweitz <[email protected]>
1 parent 91fe9e6 commit 53804e4

File tree

9 files changed

+28
-22
lines changed

9 files changed

+28
-22
lines changed

flang/include/flang/Lower/BoxAnalyzer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class BoxAnalyzer : public fir::details::matcher<BoxAnalyzer> {
490490
sym.GetType()->characterTypeSpec().length();
491491
if (Fortran::semantics::MaybeIntExpr expr = lenParam.GetExplicit())
492492
return {Fortran::evaluate::AsGenericExpr(std::move(*expr))};
493-
// For assumed length parameters, the length comes from the initialization
493+
// For assumed LEN parameters, the length comes from the initialization
494494
// expression.
495495
if (sym.attrs().test(Fortran::semantics::Attr::PARAMETER))
496496
if (const auto *objectDetails =

flang/include/flang/Optimizer/Builder/FIRBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc,
445445
/// available without having to read any fir.box values). Empty if \p exv has no
446446
/// LEN parameters or if they are all deferred.
447447
llvm::SmallVector<mlir::Value>
448-
getNonDeferredLengthParams(const fir::ExtendedValue &exv);
448+
getNonDeferredLenParams(const fir::ExtendedValue &exv);
449449

450450
//===----------------------------------------------------------------------===//
451451
// String literal helper helpers

flang/include/flang/Optimizer/Builder/MutableBox.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ MutableBoxReallocation genReallocIfNeeded(fir::FirOpBuilder &builder,
9898
mlir::Location loc,
9999
const fir::MutableBoxValue &box,
100100
mlir::ValueRange shape,
101-
mlir::ValueRange lengthParams);
101+
mlir::ValueRange lenParams);
102102

103103
void finalizeRealloc(fir::FirOpBuilder &builder, mlir::Location loc,
104104
const fir::MutableBoxValue &box, mlir::ValueRange lbounds,

flang/lib/Lower/Bridge.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
468468
[&](const auto &) -> fir::ExtendedValue {
469469
mlir::Value temp =
470470
allocate(fir::factory::getExtents(loc, *builder, hexv),
471-
fir::getTypeParams(hexv));
471+
fir::factory::getTypeParams(loc, *builder, hexv));
472472
return fir::substBase(hexv, temp);
473473
});
474474

@@ -494,7 +494,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
494494

495495
// 3) Perform the assignment.
496496
builder->setInsertionPointAfter(fir::getBase(exv).getDefiningOp());
497-
mlir::Location loc = getCurrentLocation();
497+
mlir::Location loc = genLocation(sym.name());
498498
mlir::Type symType = genType(sym);
499499
if (auto seqTy = symType.dyn_cast<fir::SequenceType>()) {
500500
Fortran::lower::StatementContext stmtCtx;

flang/lib/Lower/ConvertExpr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ class ScalarExprLowering {
892892
}
893893

894894
static bool
895-
isDerivedTypeWithLengthParameters(const Fortran::semantics::Symbol &sym) {
895+
isDerivedTypeWithLenParameters(const Fortran::semantics::Symbol &sym) {
896896
if (const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType())
897897
if (const Fortran::semantics::DerivedTypeSpec *derived =
898898
declTy->AsDerived())
@@ -943,7 +943,7 @@ class ScalarExprLowering {
943943
continue;
944944
}
945945

946-
if (isDerivedTypeWithLengthParameters(sym))
946+
if (isDerivedTypeWithLenParameters(sym))
947947
TODO(loc, "component with length parameters in structure constructor");
948948

949949
if (isBuiltinCPtr(sym)) {
@@ -1013,7 +1013,7 @@ class ScalarExprLowering {
10131013
if (sym.test(Fortran::semantics::Symbol::Flag::ParentComp))
10141014
TODO(loc, "parent component in structure constructor");
10151015

1016-
if (isDerivedTypeWithLengthParameters(sym))
1016+
if (isDerivedTypeWithLenParameters(sym))
10171017
TODO(loc, "component with length parameters in structure constructor");
10181018

10191019
llvm::StringRef name = toStringRef(sym.name());
@@ -2136,7 +2136,7 @@ class ScalarExprLowering {
21362136
mlir::Value box = builder.createBox(loc, exv);
21372137
return fir::BoxValue(
21382138
box, fir::factory::getNonDefaultLowerBounds(builder, loc, exv),
2139-
fir::factory::getNonDeferredLengthParams(exv));
2139+
fir::factory::getNonDeferredLenParams(exv));
21402140
}
21412141

21422142
/// Generate a call to a Fortran intrinsic or intrinsic module procedure.

flang/lib/Lower/ConvertVariable.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ static mlir::Value genScalarValue(Fortran::lower::AbstractConverter &converter,
4848
return fir::getBase(Fortran::lower::createSomeExtendedExpression(
4949
loc, converter, expr, symMap, context));
5050
}
51-
5251
/// Does this variable have a default initialization?
5352
static bool hasDefaultInitialization(const Fortran::semantics::Symbol &sym) {
5453
if (sym.has<Fortran::semantics::ObjectEntityDetails>() && sym.size())
@@ -103,6 +102,15 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
103102
llvm::StringRef globalName,
104103
mlir::StringAttr linkage);
105104

105+
static mlir::Location genLocation(Fortran::lower::AbstractConverter &converter,
106+
const Fortran::semantics::Symbol &sym) {
107+
// Compiler generated name cannot be used as source location, their name
108+
// is not pointing to the source files.
109+
if (!sym.test(Fortran::semantics::Symbol::Flag::CompilerCreated))
110+
return converter.genLocation(sym.name());
111+
return converter.getCurrentLocation();
112+
}
113+
106114
/// Create the global op declaration without any initializer
107115
static fir::GlobalOp declareGlobal(Fortran::lower::AbstractConverter &converter,
108116
const Fortran::lower::pft::Variable &var,
@@ -117,7 +125,7 @@ static fir::GlobalOp declareGlobal(Fortran::lower::AbstractConverter &converter,
117125
linkage == builder.createLinkOnceLinkage())
118126
return defineGlobal(converter, var, globalName, linkage);
119127
const Fortran::semantics::Symbol &sym = var.getSymbol();
120-
mlir::Location loc = converter.genLocation(sym.name());
128+
mlir::Location loc = genLocation(converter, sym);
121129
// Resolve potential host and module association before checking that this
122130
// symbol is an object of a function pointer.
123131
const Fortran::semantics::Symbol &ultimate = sym.GetUltimate();
@@ -371,7 +379,7 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
371379
mlir::StringAttr linkage) {
372380
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
373381
const Fortran::semantics::Symbol &sym = var.getSymbol();
374-
mlir::Location loc = converter.genLocation(sym.name());
382+
mlir::Location loc = genLocation(converter, sym);
375383
bool isConst = isConstant(sym);
376384
fir::GlobalOp global = builder.getNamedGlobal(globalName);
377385
mlir::Type symTy = converter.genType(var);
@@ -508,7 +516,7 @@ static void instantiateGlobal(Fortran::lower::AbstractConverter &converter,
508516
assert(!var.isAlias() && "must be handled in instantiateAlias");
509517
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
510518
std::string globalName = Fortran::lower::mangle::mangleName(sym);
511-
mlir::Location loc = converter.genLocation(sym.name());
519+
mlir::Location loc = genLocation(converter, sym);
512520
fir::GlobalOp global = builder.getNamedGlobal(globalName);
513521
mlir::StringAttr linkage = getLinkageAttribute(builder, var);
514522
if (var.isModuleVariable()) {
@@ -780,7 +788,7 @@ static void instantiateAlias(Fortran::lower::AbstractConverter &converter,
780788
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
781789
assert(var.isAlias());
782790
const Fortran::semantics::Symbol &sym = var.getSymbol();
783-
const mlir::Location loc = converter.genLocation(sym.name());
791+
const mlir::Location loc = genLocation(converter, sym);
784792
mlir::IndexType idxTy = builder.getIndexType();
785793
std::size_t aliasOffset = var.getAlias();
786794
mlir::Value store = getAggregateStore(storeMap, var);
@@ -1228,7 +1236,7 @@ void Fortran::lower::mapSymbolAttributes(
12281236
mlir::Value preAlloc) {
12291237
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
12301238
const Fortran::semantics::Symbol &sym = var.getSymbol();
1231-
const mlir::Location loc = converter.genLocation(sym.name());
1239+
const mlir::Location loc = genLocation(converter, sym);
12321240
mlir::IndexType idxTy = builder.getIndexType();
12331241
const bool isDeclaredDummy = Fortran::semantics::IsDummy(sym);
12341242
// An active dummy from the current entry point.

flang/lib/Lower/HostAssociations.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,7 @@ class CapturedCharacterScalars
222222
};
223223

224224
/// Is \p sym a derived type entity with length parameters ?
225-
static bool
226-
isDerivedWithLengthParameters(const Fortran::semantics::Symbol &sym) {
225+
static bool isDerivedWithLenParameters(const Fortran::semantics::Symbol &sym) {
227226
if (const auto *declTy = sym.GetType())
228227
if (const auto *derived = declTy->AsDerived())
229228
return Fortran::semantics::CountLenParameters(*derived) != 0;
@@ -301,7 +300,7 @@ class CapturedAllocatableAndPointer
301300
nonDeferredLenParams.push_back(readLength());
302301
}
303302
}
304-
} else if (isDerivedWithLengthParameters(sym)) {
303+
} else if (isDerivedWithLenParameters(sym)) {
305304
TODO(loc, "host associated derived type allocatable or pointer with "
306305
"length parameters");
307306
}
@@ -426,7 +425,7 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
426425
const Fortran::semantics::DeclTypeSpec *type = sym.GetType();
427426
bool isPolymorphic = type && type->IsPolymorphic();
428427
return isScalarOrContiguous && !isPolymorphic &&
429-
!isDerivedWithLengthParameters(sym);
428+
!isDerivedWithLenParameters(sym);
430429
}
431430
};
432431

@@ -438,7 +437,7 @@ template <typename T>
438437
typename T::Result
439438
walkCaptureCategories(T visitor, Fortran::lower::AbstractConverter &converter,
440439
const Fortran::semantics::Symbol &sym) {
441-
if (isDerivedWithLengthParameters(sym))
440+
if (isDerivedWithLenParameters(sym))
442441
// Should be boxed.
443442
TODO(converter.genLocation(sym.name()),
444443
"host associated derived type with length parameters");

flang/lib/Optimizer/Builder/FIRBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ fir::factory::getNonDefaultLowerBounds(fir::FirOpBuilder &builder,
715715
}
716716

717717
llvm::SmallVector<mlir::Value>
718-
fir::factory::getNonDeferredLengthParams(const fir::ExtendedValue &exv) {
718+
fir::factory::getNonDeferredLenParams(const fir::ExtendedValue &exv) {
719719
return exv.match(
720720
[&](const fir::CharArrayBoxValue &character)
721721
-> llvm::SmallVector<mlir::Value> { return {character.getLen()}; },

flang/lib/Optimizer/CodeGen/CodeGen.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2192,7 +2192,6 @@ struct XArrayCoorOpConversion
21922192
operands[coor.lenParamsOffset()]);
21932193
offset =
21942194
rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, offset, length);
2195-
21962195
} else {
21972196
TODO(loc, "compute size of derived type with type parameters");
21982197
}

0 commit comments

Comments
 (0)