Skip to content

[flang] Migrate away from std::nullopt (NFC) #145928

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang/include/flang/Lower/AbstractConverter.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class AbstractConverter {
/// Generate the type from a category and kind and length parameters.
virtual mlir::Type
genType(Fortran::common::TypeCategory tc, int kind,
llvm::ArrayRef<std::int64_t> lenParameters = std::nullopt) = 0;
llvm::ArrayRef<std::int64_t> lenParameters = {}) = 0;
/// Generate the type from a DerivedTypeSpec.
virtual mlir::Type genType(const Fortran::semantics::DerivedTypeSpec &) = 0;
/// Generate the type from a Variable
Expand Down
4 changes: 2 additions & 2 deletions flang/include/flang/Optimizer/Builder/FIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -537,14 +537,14 @@ class FirOpBuilder : public mlir::OpBuilder, public mlir::OpBuilder::Listener {
/// Create an IfOp with no "else" region, and no result values.
/// Usage: genIfThen(loc, cdt).genThen(lambda).end();
IfBuilder genIfThen(mlir::Location loc, mlir::Value cdt) {
auto op = create<fir::IfOp>(loc, std::nullopt, cdt, false);
auto op = create<fir::IfOp>(loc, mlir::TypeRange(), cdt, false);
return IfBuilder(op, *this);
}

/// Create an IfOp with an "else" region, and no result values.
/// Usage: genIfThenElse(loc, cdt).genThen(lambda).genElse(lambda).end();
IfBuilder genIfThenElse(mlir::Location loc, mlir::Value cdt) {
auto op = create<fir::IfOp>(loc, std::nullopt, cdt, true);
auto op = create<fir::IfOp>(loc, mlir::TypeRange(), cdt, true);
return IfBuilder(op, *this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class KindMapping {
/// of 6 KindTy must be passed. The kinds must be the given in the following
/// order: CHARACTER, COMPLEX, DOUBLE PRECISION, INTEGER, LOGICAL, and REAL.
explicit KindMapping(mlir::MLIRContext *context, llvm::StringRef map,
llvm::ArrayRef<KindTy> defs = std::nullopt);
llvm::ArrayRef<KindTy> defs = {});
explicit KindMapping(mlir::MLIRContext *context, llvm::StringRef map,
llvm::StringRef defs)
: KindMapping{context, map, toDefaultKinds(defs)} {}
Expand Down
25 changes: 12 additions & 13 deletions flang/lib/Lower/Allocatable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1041,19 +1041,19 @@ createMutableProperties(Fortran::lower::AbstractConverter &converter,
baseAddrTy = boxType.getEleTy();
// Allocate and set a variable to hold the address.
// It will be set to null in setUnallocatedStatus.
mutableProperties.addr = builder.allocateLocal(
loc, baseAddrTy, name + ".addr", "",
/*shape=*/std::nullopt, /*typeparams=*/std::nullopt);
mutableProperties.addr =
builder.allocateLocal(loc, baseAddrTy, name + ".addr", "",
/*shape=*/{}, /*typeparams=*/{});
// Allocate variables to hold lower bounds and extents.
int rank = sym.Rank();
mlir::Type idxTy = builder.getIndexType();
for (decltype(rank) i = 0; i < rank; ++i) {
mlir::Value lboundVar = builder.allocateLocal(
loc, idxTy, name + ".lb" + std::to_string(i), "",
/*shape=*/std::nullopt, /*typeparams=*/std::nullopt);
mlir::Value extentVar = builder.allocateLocal(
loc, idxTy, name + ".ext" + std::to_string(i), "",
/*shape=*/std::nullopt, /*typeparams=*/std::nullopt);
mlir::Value lboundVar =
builder.allocateLocal(loc, idxTy, name + ".lb" + std::to_string(i), "",
/*shape=*/{}, /*typeparams=*/{});
mlir::Value extentVar =
builder.allocateLocal(loc, idxTy, name + ".ext" + std::to_string(i), "",
/*shape=*/{}, /*typeparams=*/{});
mutableProperties.lbounds.emplace_back(lboundVar);
mutableProperties.extents.emplace_back(extentVar);
}
Expand All @@ -1068,10 +1068,9 @@ createMutableProperties(Fortran::lower::AbstractConverter &converter,
if (record.getNumLenParams() != 0)
TODO(loc, "deferred length type parameters.");
if (fir::isa_char(eleTy) && nonDeferredParams.empty()) {
mlir::Value lenVar =
builder.allocateLocal(loc, builder.getCharacterLengthType(),
name + ".len", "", /*shape=*/std::nullopt,
/*typeparams=*/std::nullopt);
mlir::Value lenVar = builder.allocateLocal(
loc, builder.getCharacterLengthType(), name + ".len", "", /*shape=*/{},
/*typeparams=*/{});
mutableProperties.deferredParams.emplace_back(lenVar);
}
return mutableProperties;
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
}
mlir::Type genType(Fortran::common::TypeCategory tc) override final {
return Fortran::lower::getFIRType(
&getMLIRContext(), tc, bridge.getDefaultKinds().GetDefaultKind(tc),
std::nullopt);
&getMLIRContext(), tc, bridge.getDefaultKinds().GetDefaultKind(tc), {});
}

Fortran::lower::TypeConstructionStack &
Expand Down
10 changes: 4 additions & 6 deletions flang/lib/Lower/CallInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1338,15 +1338,13 @@ class Fortran::lower::CallInterfaceImpl {
getConverter().getFoldingContext(), toEvExpr(*expr)));
return std::nullopt;
}
void addFirOperand(
mlir::Type type, int entityPosition, Property p,
llvm::ArrayRef<mlir::NamedAttribute> attributes = std::nullopt) {
void addFirOperand(mlir::Type type, int entityPosition, Property p,
llvm::ArrayRef<mlir::NamedAttribute> attributes = {}) {
interface.inputs.emplace_back(
FirPlaceHolder{type, entityPosition, p, attributes});
}
void
addFirResult(mlir::Type type, int entityPosition, Property p,
llvm::ArrayRef<mlir::NamedAttribute> attributes = std::nullopt) {
void addFirResult(mlir::Type type, int entityPosition, Property p,
llvm::ArrayRef<mlir::NamedAttribute> attributes = {}) {
interface.outputs.emplace_back(
FirPlaceHolder{type, entityPosition, p, attributes});
}
Expand Down
7 changes: 3 additions & 4 deletions flang/lib/Lower/ConvertConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,8 @@ class DenseGlobalBuilder {
auto attrTc = TC == Fortran::common::TypeCategory::Logical
? Fortran::common::TypeCategory::Integer
: TC;
attributeElementType = Fortran::lower::getFIRType(
builder.getContext(), attrTc, KIND, std::nullopt);
attributeElementType =
Fortran::lower::getFIRType(builder.getContext(), attrTc, KIND, {});
for (auto element : constant.values())
attributes.push_back(
convertToAttribute<TC, KIND>(builder, element, attributeElementType));
Expand Down Expand Up @@ -230,8 +230,7 @@ static mlir::Value genScalarLit(
TC == Fortran::common::TypeCategory::Unsigned) {
// MLIR requires constants to be signless
mlir::Type ty = Fortran::lower::getFIRType(
builder.getContext(), Fortran::common::TypeCategory::Integer, KIND,
std::nullopt);
builder.getContext(), Fortran::common::TypeCategory::Integer, KIND, {});
if (KIND == 16) {
auto bigInt = llvm::APInt(ty.getIntOrFloatBitWidth(),
TC == Fortran::common::TypeCategory::Unsigned
Expand Down
14 changes: 7 additions & 7 deletions flang/lib/Lower/ConvertExprToHLFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,7 @@ struct BinaryOp<Fortran::evaluate::Divide<
hlfir::Entity lhs, hlfir::Entity rhs) {
mlir::Type ty = Fortran::lower::getFIRType(
builder.getContext(), Fortran::common::TypeCategory::Complex, KIND,
/*params=*/std::nullopt);
/*params=*/{});
return hlfir::EntityWithAttributes{
fir::genDivC(builder, loc, ty, lhs, rhs)};
}
Expand All @@ -1078,7 +1078,7 @@ struct BinaryOp<Fortran::evaluate::Power<Fortran::evaluate::Type<TC, KIND>>> {
fir::FirOpBuilder &builder, const Op &,
hlfir::Entity lhs, hlfir::Entity rhs) {
mlir::Type ty = Fortran::lower::getFIRType(builder.getContext(), TC, KIND,
/*params=*/std::nullopt);
/*params=*/{});
return hlfir::EntityWithAttributes{fir::genPow(builder, loc, ty, lhs, rhs)};
}
};
Expand All @@ -1092,7 +1092,7 @@ struct BinaryOp<
fir::FirOpBuilder &builder, const Op &,
hlfir::Entity lhs, hlfir::Entity rhs) {
mlir::Type ty = Fortran::lower::getFIRType(builder.getContext(), TC, KIND,
/*params=*/std::nullopt);
/*params=*/{});
return hlfir::EntityWithAttributes{fir::genPow(builder, loc, ty, lhs, rhs)};
}
};
Expand Down Expand Up @@ -1416,7 +1416,7 @@ struct UnaryOp<Fortran::evaluate::Negate<
// Like LLVM, integer negation is the binary op "0 - value"
mlir::Type type = Fortran::lower::getFIRType(
builder.getContext(), Fortran::common::TypeCategory::Integer, KIND,
/*params=*/std::nullopt);
/*params=*/{});
mlir::Value zero = builder.createIntegerConstant(loc, type, 0);
return hlfir::EntityWithAttributes{
builder.create<mlir::arith::SubIOp>(loc, zero, lhs)};
Expand Down Expand Up @@ -1517,7 +1517,7 @@ struct UnaryOp<
return hlfir::convertCharacterKind(loc, builder, lhs, KIND);
}
mlir::Type type = Fortran::lower::getFIRType(builder.getContext(), TC1,
KIND, /*params=*/std::nullopt);
KIND, /*params=*/{});
mlir::Value res = builder.convertWithSemantics(loc, type, lhs);
return hlfir::EntityWithAttributes{res};
}
Expand Down Expand Up @@ -1661,7 +1661,7 @@ class HlfirBuilder {
} else {
elementType =
Fortran::lower::getFIRType(builder.getContext(), R::category, R::kind,
/*params=*/std::nullopt);
/*params=*/{});
}
mlir::Value shape = hlfir::genShape(loc, builder, left);
auto genKernel = [&op, &left, &unaryOp](
Expand Down Expand Up @@ -1699,7 +1699,7 @@ class HlfirBuilder {
// Elemental expression.
mlir::Type elementType =
Fortran::lower::getFIRType(builder.getContext(), R::category, R::kind,
/*params=*/std::nullopt);
/*params=*/{});
// TODO: "merge" shape, get cst shape from front-end if possible.
mlir::Value shape;
if (left.isArray()) {
Expand Down
17 changes: 8 additions & 9 deletions flang/lib/Lower/ConvertVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1289,9 +1289,8 @@ instantiateAggregateStore(Fortran::lower::AbstractConverter &converter,
auto size = std::get<1>(var.getInterval());
fir::SequenceType::Shape shape(1, size);
auto seqTy = fir::SequenceType::get(shape, i8Ty);
mlir::Value local =
builder.allocateLocal(loc, seqTy, aggName, "", std::nullopt, std::nullopt,
/*target=*/false);
mlir::Value local = builder.allocateLocal(loc, seqTy, aggName, "", {}, {},
/*target=*/false);
insertAggregateStore(storeMap, var, local);
}

Expand Down Expand Up @@ -1839,8 +1838,8 @@ static void genDeclareSymbol(Fortran::lower::AbstractConverter &converter,
Fortran::lower::SymMap &symMap,
const Fortran::semantics::Symbol &sym,
mlir::Value base, mlir::Value len = {},
llvm::ArrayRef<mlir::Value> shape = std::nullopt,
llvm::ArrayRef<mlir::Value> lbounds = std::nullopt,
llvm::ArrayRef<mlir::Value> shape = {},
llvm::ArrayRef<mlir::Value> lbounds = {},
bool force = false) {
// In HLFIR, procedure dummy symbols are not added with an hlfir.declare
// because they are "values", and hlfir.declare is intended for variables. It
Expand Down Expand Up @@ -2008,8 +2007,8 @@ genAllocatableOrPointerDeclare(Fortran::lower::AbstractConverter &converter,
explictLength = box.nonDeferredLenParams()[0];
}
genDeclareSymbol(converter, symMap, sym, base, explictLength,
/*shape=*/std::nullopt,
/*lbounds=*/std::nullopt, force);
/*shape=*/{},
/*lbounds=*/{}, force);
}

/// Map a procedure pointer
Expand All @@ -2018,8 +2017,8 @@ static void genProcPointer(Fortran::lower::AbstractConverter &converter,
const Fortran::semantics::Symbol &sym,
mlir::Value addr, bool force = false) {
genDeclareSymbol(converter, symMap, sym, addr, mlir::Value{},
/*shape=*/std::nullopt,
/*lbounds=*/std::nullopt, force);
/*shape=*/{},
/*lbounds=*/{}, force);
}

/// Map a symbol represented with a runtime descriptor to its FIR fir.box and
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Lower/HostAssociations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
}

if (canReadCapturedBoxValue(converter, sym)) {
fir::BoxValue boxValue(box, lbounds, /*explicitParams=*/std::nullopt);
fir::BoxValue boxValue(box, lbounds, /*explicitParams=*/{});
bindCapturedSymbol(sym,
fir::factory::readBoxValue(builder, loc, boxValue),
converter, args.symMap);
Expand All @@ -470,7 +470,7 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
box = builder.create<mlir::arith::SelectOp>(loc, isPresent, box,
absentBox);
}
fir::BoxValue boxValue(box, lbounds, /*explicitParams=*/std::nullopt);
fir::BoxValue boxValue(box, lbounds, /*explicitParams=*/{});
bindCapturedSymbol(sym, boxValue, converter, args.symMap);
}
}
Expand Down
6 changes: 2 additions & 4 deletions flang/lib/Lower/Mangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ std::string Fortran::lower::mangle::mangleName(
// Mangle external procedure without any scope prefix.
if (!keepExternalInScope &&
Fortran::semantics::IsExternal(ultimateSymbol))
return fir::NameUniquer::doProcedure(std::nullopt, std::nullopt,
symbolName);
return fir::NameUniquer::doProcedure({}, {}, symbolName);
// A separate module procedure must be mangled according to its
// declaration scope, not its definition scope.
const Fortran::semantics::Symbol *interface = &ultimateSymbol;
Expand All @@ -142,8 +141,7 @@ std::string Fortran::lower::mangle::mangleName(
}
// Otherwise, this is an external procedure, with or without an
// explicit EXTERNAL attribute. Mangle it without any prefix.
return fir::NameUniquer::doProcedure(std::nullopt, std::nullopt,
symbolName);
return fir::NameUniquer::doProcedure({}, {}, symbolName);
},
[&](const Fortran::semantics::ObjectEntityDetails &) {
return mangleObject();
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Builder/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ fir::factory::CharacterExprHelper::createCharacterTemp(mlir::Type type,
if (typeLen == fir::CharacterType::unknownLen())
lenParams.push_back(len);
auto ref = builder.allocateLocal(loc, charTy, "", ".chrtmp",
/*shape=*/std::nullopt, lenParams);
/*shape=*/{}, lenParams);
return {ref, len};
}

Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Builder/MutableBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ mlir::Value fir::factory::createUnallocatedBox(
auto zero = builder.createIntegerConstant(loc, builder.getIndexType(), 0);
llvm::SmallVector<mlir::Value> extents(seqTy.getDimension(), zero);
shape = builder.createShape(
loc, fir::ArrayBoxValue{nullAddr, extents, /*lbounds=*/std::nullopt});
loc, fir::ArrayBoxValue{nullAddr, extents, /*lbounds=*/{}});
}
// Provide dummy length parameters if they are dynamic. If a length parameter
// is deferred. It is set to zero here and will be set on allocation.
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Optimizer/CodeGen/TypeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ LLVMTypeConverter::LLVMTypeConverter(mlir::ModuleOp module, bool applyTBAA,
/*isPacked=*/false);
});
addConversion([&](mlir::NoneType none) {
return mlir::LLVM::LLVMStructType::getLiteral(
none.getContext(), std::nullopt, /*isPacked=*/false);
return mlir::LLVM::LLVMStructType::getLiteral(none.getContext(), {},
/*isPacked=*/false);
});
addConversion([&](fir::DummyScopeType dscope) {
// DummyScopeType values must not have any uses after PreCGRewrite.
Expand Down
Loading