[flang-commits] [flang] 53804e4 - [flang][NFC] Make LEN parameters homogenous
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Jul 7 09:29:41 PDT 2022
Author: Valentin Clement
Date: 2022-07-07T18:29:28+02:00
New Revision: 53804e426d9b552adaa1adb86a2df9014c41d42a
URL: https://github.com/llvm/llvm-project/commit/53804e426d9b552adaa1adb86a2df9014c41d42a
DIFF: https://github.com/llvm/llvm-project/commit/53804e426d9b552adaa1adb86a2df9014c41d42a.diff
LOG: [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 <eschweitz at nvidia.com>
Added:
Modified:
flang/include/flang/Lower/BoxAnalyzer.h
flang/include/flang/Optimizer/Builder/FIRBuilder.h
flang/include/flang/Optimizer/Builder/MutableBox.h
flang/lib/Lower/Bridge.cpp
flang/lib/Lower/ConvertExpr.cpp
flang/lib/Lower/ConvertVariable.cpp
flang/lib/Lower/HostAssociations.cpp
flang/lib/Optimizer/Builder/FIRBuilder.cpp
flang/lib/Optimizer/CodeGen/CodeGen.cpp
Removed:
################################################################################
diff --git a/flang/include/flang/Lower/BoxAnalyzer.h b/flang/include/flang/Lower/BoxAnalyzer.h
index e347d5299c6ac..28ad0d5433b19 100644
--- a/flang/include/flang/Lower/BoxAnalyzer.h
+++ b/flang/include/flang/Lower/BoxAnalyzer.h
@@ -490,7 +490,7 @@ class BoxAnalyzer : public fir::details::matcher<BoxAnalyzer> {
sym.GetType()->characterTypeSpec().length();
if (Fortran::semantics::MaybeIntExpr expr = lenParam.GetExplicit())
return {Fortran::evaluate::AsGenericExpr(std::move(*expr))};
- // For assumed length parameters, the length comes from the initialization
+ // For assumed LEN parameters, the length comes from the initialization
// expression.
if (sym.attrs().test(Fortran::semantics::Attr::PARAMETER))
if (const auto *objectDetails =
diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
index 0617b382612d3..3a1711bbf3d7c 100644
--- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h
+++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h
@@ -445,7 +445,7 @@ getNonDefaultLowerBounds(fir::FirOpBuilder &builder, mlir::Location loc,
/// available without having to read any fir.box values). Empty if \p exv has no
/// LEN parameters or if they are all deferred.
llvm::SmallVector<mlir::Value>
-getNonDeferredLengthParams(const fir::ExtendedValue &exv);
+getNonDeferredLenParams(const fir::ExtendedValue &exv);
//===----------------------------------------------------------------------===//
// String literal helper helpers
diff --git a/flang/include/flang/Optimizer/Builder/MutableBox.h b/flang/include/flang/Optimizer/Builder/MutableBox.h
index 664d6c44be4f2..70523d869b37b 100644
--- a/flang/include/flang/Optimizer/Builder/MutableBox.h
+++ b/flang/include/flang/Optimizer/Builder/MutableBox.h
@@ -98,7 +98,7 @@ MutableBoxReallocation genReallocIfNeeded(fir::FirOpBuilder &builder,
mlir::Location loc,
const fir::MutableBoxValue &box,
mlir::ValueRange shape,
- mlir::ValueRange lengthParams);
+ mlir::ValueRange lenParams);
void finalizeRealloc(fir::FirOpBuilder &builder, mlir::Location loc,
const fir::MutableBoxValue &box, mlir::ValueRange lbounds,
diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp
index edcc440937a44..aaaf22a7c214f 100644
--- a/flang/lib/Lower/Bridge.cpp
+++ b/flang/lib/Lower/Bridge.cpp
@@ -468,7 +468,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
[&](const auto &) -> fir::ExtendedValue {
mlir::Value temp =
allocate(fir::factory::getExtents(loc, *builder, hexv),
- fir::getTypeParams(hexv));
+ fir::factory::getTypeParams(loc, *builder, hexv));
return fir::substBase(hexv, temp);
});
@@ -494,7 +494,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// 3) Perform the assignment.
builder->setInsertionPointAfter(fir::getBase(exv).getDefiningOp());
- mlir::Location loc = getCurrentLocation();
+ mlir::Location loc = genLocation(sym.name());
mlir::Type symType = genType(sym);
if (auto seqTy = symType.dyn_cast<fir::SequenceType>()) {
Fortran::lower::StatementContext stmtCtx;
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index a9651b8fcbe00..eeed0867661ed 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -892,7 +892,7 @@ class ScalarExprLowering {
}
static bool
- isDerivedTypeWithLengthParameters(const Fortran::semantics::Symbol &sym) {
+ isDerivedTypeWithLenParameters(const Fortran::semantics::Symbol &sym) {
if (const Fortran::semantics::DeclTypeSpec *declTy = sym.GetType())
if (const Fortran::semantics::DerivedTypeSpec *derived =
declTy->AsDerived())
@@ -943,7 +943,7 @@ class ScalarExprLowering {
continue;
}
- if (isDerivedTypeWithLengthParameters(sym))
+ if (isDerivedTypeWithLenParameters(sym))
TODO(loc, "component with length parameters in structure constructor");
if (isBuiltinCPtr(sym)) {
@@ -1013,7 +1013,7 @@ class ScalarExprLowering {
if (sym.test(Fortran::semantics::Symbol::Flag::ParentComp))
TODO(loc, "parent component in structure constructor");
- if (isDerivedTypeWithLengthParameters(sym))
+ if (isDerivedTypeWithLenParameters(sym))
TODO(loc, "component with length parameters in structure constructor");
llvm::StringRef name = toStringRef(sym.name());
@@ -2136,7 +2136,7 @@ class ScalarExprLowering {
mlir::Value box = builder.createBox(loc, exv);
return fir::BoxValue(
box, fir::factory::getNonDefaultLowerBounds(builder, loc, exv),
- fir::factory::getNonDeferredLengthParams(exv));
+ fir::factory::getNonDeferredLenParams(exv));
}
/// Generate a call to a Fortran intrinsic or intrinsic module procedure.
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index 1f66594d3f7eb..013ebfd0ac9a1 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -48,7 +48,6 @@ static mlir::Value genScalarValue(Fortran::lower::AbstractConverter &converter,
return fir::getBase(Fortran::lower::createSomeExtendedExpression(
loc, converter, expr, symMap, context));
}
-
/// Does this variable have a default initialization?
static bool hasDefaultInitialization(const Fortran::semantics::Symbol &sym) {
if (sym.has<Fortran::semantics::ObjectEntityDetails>() && sym.size())
@@ -103,6 +102,15 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
llvm::StringRef globalName,
mlir::StringAttr linkage);
+static mlir::Location genLocation(Fortran::lower::AbstractConverter &converter,
+ const Fortran::semantics::Symbol &sym) {
+ // Compiler generated name cannot be used as source location, their name
+ // is not pointing to the source files.
+ if (!sym.test(Fortran::semantics::Symbol::Flag::CompilerCreated))
+ return converter.genLocation(sym.name());
+ return converter.getCurrentLocation();
+}
+
/// Create the global op declaration without any initializer
static fir::GlobalOp declareGlobal(Fortran::lower::AbstractConverter &converter,
const Fortran::lower::pft::Variable &var,
@@ -117,7 +125,7 @@ static fir::GlobalOp declareGlobal(Fortran::lower::AbstractConverter &converter,
linkage == builder.createLinkOnceLinkage())
return defineGlobal(converter, var, globalName, linkage);
const Fortran::semantics::Symbol &sym = var.getSymbol();
- mlir::Location loc = converter.genLocation(sym.name());
+ mlir::Location loc = genLocation(converter, sym);
// Resolve potential host and module association before checking that this
// symbol is an object of a function pointer.
const Fortran::semantics::Symbol &ultimate = sym.GetUltimate();
@@ -371,7 +379,7 @@ static fir::GlobalOp defineGlobal(Fortran::lower::AbstractConverter &converter,
mlir::StringAttr linkage) {
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
const Fortran::semantics::Symbol &sym = var.getSymbol();
- mlir::Location loc = converter.genLocation(sym.name());
+ mlir::Location loc = genLocation(converter, sym);
bool isConst = isConstant(sym);
fir::GlobalOp global = builder.getNamedGlobal(globalName);
mlir::Type symTy = converter.genType(var);
@@ -508,7 +516,7 @@ static void instantiateGlobal(Fortran::lower::AbstractConverter &converter,
assert(!var.isAlias() && "must be handled in instantiateAlias");
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
std::string globalName = Fortran::lower::mangle::mangleName(sym);
- mlir::Location loc = converter.genLocation(sym.name());
+ mlir::Location loc = genLocation(converter, sym);
fir::GlobalOp global = builder.getNamedGlobal(globalName);
mlir::StringAttr linkage = getLinkageAttribute(builder, var);
if (var.isModuleVariable()) {
@@ -780,7 +788,7 @@ static void instantiateAlias(Fortran::lower::AbstractConverter &converter,
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
assert(var.isAlias());
const Fortran::semantics::Symbol &sym = var.getSymbol();
- const mlir::Location loc = converter.genLocation(sym.name());
+ const mlir::Location loc = genLocation(converter, sym);
mlir::IndexType idxTy = builder.getIndexType();
std::size_t aliasOffset = var.getAlias();
mlir::Value store = getAggregateStore(storeMap, var);
@@ -1228,7 +1236,7 @@ void Fortran::lower::mapSymbolAttributes(
mlir::Value preAlloc) {
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
const Fortran::semantics::Symbol &sym = var.getSymbol();
- const mlir::Location loc = converter.genLocation(sym.name());
+ const mlir::Location loc = genLocation(converter, sym);
mlir::IndexType idxTy = builder.getIndexType();
const bool isDeclaredDummy = Fortran::semantics::IsDummy(sym);
// An active dummy from the current entry point.
diff --git a/flang/lib/Lower/HostAssociations.cpp b/flang/lib/Lower/HostAssociations.cpp
index b966b27d8846d..3e23fabe21134 100644
--- a/flang/lib/Lower/HostAssociations.cpp
+++ b/flang/lib/Lower/HostAssociations.cpp
@@ -222,8 +222,7 @@ class CapturedCharacterScalars
};
/// Is \p sym a derived type entity with length parameters ?
-static bool
-isDerivedWithLengthParameters(const Fortran::semantics::Symbol &sym) {
+static bool isDerivedWithLenParameters(const Fortran::semantics::Symbol &sym) {
if (const auto *declTy = sym.GetType())
if (const auto *derived = declTy->AsDerived())
return Fortran::semantics::CountLenParameters(*derived) != 0;
@@ -301,7 +300,7 @@ class CapturedAllocatableAndPointer
nonDeferredLenParams.push_back(readLength());
}
}
- } else if (isDerivedWithLengthParameters(sym)) {
+ } else if (isDerivedWithLenParameters(sym)) {
TODO(loc, "host associated derived type allocatable or pointer with "
"length parameters");
}
@@ -426,7 +425,7 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
const Fortran::semantics::DeclTypeSpec *type = sym.GetType();
bool isPolymorphic = type && type->IsPolymorphic();
return isScalarOrContiguous && !isPolymorphic &&
- !isDerivedWithLengthParameters(sym);
+ !isDerivedWithLenParameters(sym);
}
};
@@ -438,7 +437,7 @@ template <typename T>
typename T::Result
walkCaptureCategories(T visitor, Fortran::lower::AbstractConverter &converter,
const Fortran::semantics::Symbol &sym) {
- if (isDerivedWithLengthParameters(sym))
+ if (isDerivedWithLenParameters(sym))
// Should be boxed.
TODO(converter.genLocation(sym.name()),
"host associated derived type with length parameters");
diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
index 8d53694c8f8ea..6ff94254ec25b 100644
--- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp
+++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp
@@ -715,7 +715,7 @@ fir::factory::getNonDefaultLowerBounds(fir::FirOpBuilder &builder,
}
llvm::SmallVector<mlir::Value>
-fir::factory::getNonDeferredLengthParams(const fir::ExtendedValue &exv) {
+fir::factory::getNonDeferredLenParams(const fir::ExtendedValue &exv) {
return exv.match(
[&](const fir::CharArrayBoxValue &character)
-> llvm::SmallVector<mlir::Value> { return {character.getLen()}; },
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index e53d096806612..ffb0a8dbc4ca1 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -2192,7 +2192,6 @@ struct XArrayCoorOpConversion
operands[coor.lenParamsOffset()]);
offset =
rewriter.create<mlir::LLVM::MulOp>(loc, idxTy, offset, length);
-
} else {
TODO(loc, "compute size of derived type with type parameters");
}
More information about the flang-commits
mailing list