Skip to content

[flang] Migrate away from ArrayRef(std::nullopt_t) #149337

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
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
24 changes: 11 additions & 13 deletions flang/lib/Lower/Bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -810,11 +810,11 @@ class FirConverter : public Fortran::lower::AbstractConverter {
fir::ExtendedValue read = fir::factory::genMutableBoxRead(
*builder, loc, box, /*mayBePolymorphic=*/false);
if (auto read_arr_box = read.getBoxOf<fir::ArrayBoxValue>()) {
fir::factory::genInlinedAllocation(
*builder, loc, *new_box, read_arr_box->getLBounds(),
read_arr_box->getExtents(),
/*lenParams=*/std::nullopt, name,
/*mustBeHeap=*/true);
fir::factory::genInlinedAllocation(*builder, loc, *new_box,
read_arr_box->getLBounds(),
read_arr_box->getExtents(),
/*lenParams=*/{}, name,
/*mustBeHeap=*/true);
} else if (auto read_char_arr_box =
read.getBoxOf<fir::CharArrayBoxValue>()) {
fir::factory::genInlinedAllocation(
Expand All @@ -825,8 +825,8 @@ class FirConverter : public Fortran::lower::AbstractConverter {
} else if (auto read_char_box =
read.getBoxOf<fir::CharBoxValue>()) {
fir::factory::genInlinedAllocation(*builder, loc, *new_box,
/*lbounds=*/std::nullopt,
/*extents=*/std::nullopt,
/*lbounds=*/{},
/*extents=*/{},
read_char_box->getLen(), name,
/*mustBeHeap=*/true);
} else {
Expand Down Expand Up @@ -4590,8 +4590,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
// the static type of the LHS.
if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
assign.rhs))
return fir::factory::createUnallocatedBox(*builder, loc, lhsBoxType,
std::nullopt);
return fir::factory::createUnallocatedBox(*builder, loc, lhsBoxType, {});
hlfir::Entity rhs = Fortran::lower::convertExprToHLFIR(
loc, *this, assign.rhs, localSymbols, rhsContext);
// Create pointer descriptor value from the RHS.
Expand Down Expand Up @@ -5199,7 +5198,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
"LEN parameters");
lhsRealloc = fir::factory::genReallocIfNeeded(
*builder, loc, *lhsMutableBox,
/*shape=*/std::nullopt, lengthParams);
/*shape=*/{}, lengthParams);
return lhsRealloc->newValue;
}
return genExprAddr(assign.lhs, stmtCtx);
Expand Down Expand Up @@ -5271,7 +5270,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
if (lhsIsWholeAllocatable) {
assert(lhsRealloc.has_value());
fir::factory::finalizeRealloc(*builder, loc, *lhsMutableBox,
/*lbounds=*/std::nullopt,
/*lbounds=*/{},
/*takeLboundsIfRealloc=*/false,
*lhsRealloc);
}
Expand Down Expand Up @@ -6059,8 +6058,7 @@ class FirConverter : public Fortran::lower::AbstractConverter {
mlir::func::FuncOp func = fir::FirOpBuilder::createFunction(
mlir::UnknownLoc::get(context), getModuleOp(),
fir::NameUniquer::doGenerated("Sham"),
mlir::FunctionType::get(context, std::nullopt, std::nullopt),
symbolTable);
mlir::FunctionType::get(context, {}, {}), symbolTable);
func.addEntryBlock();
CHECK(!builder && "Expected builder to be uninitialized");
builder = new fir::FirOpBuilder(func, bridge.getKindMap(), symbolTable);
Expand Down
5 changes: 2 additions & 3 deletions flang/lib/Lower/ConvertCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,7 @@ Fortran::lower::genCallOpAndResult(
auto *context = builder.getContext();
if (mlir::isa<fir::BoxProcType>(snd) &&
mlir::isa<mlir::FunctionType>(fst.getType())) {
auto funcTy =
mlir::FunctionType::get(context, std::nullopt, std::nullopt);
auto funcTy = mlir::FunctionType::get(context, {}, {});
auto boxProcTy = builder.getBoxProcType(funcTy);
if (mlir::Value host = argumentHostAssocs(converter, fst)) {
cast = builder.create<fir::EmboxProcOp>(
Expand Down Expand Up @@ -1714,7 +1713,7 @@ void prepareUserCallArguments(
/*nonDeferredParams=*/mlir::ValueRange{},
/*mutableProperties=*/{});
fir::factory::associateMutableBox(builder, loc, ptrBox, actualExv,
/*lbounds=*/std::nullopt);
/*lbounds=*/{});
caller.placeInput(arg, irBox);
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions flang/lib/Lower/ConvertConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ static mlir::Value genStructureComponentInit(
"allocatable component value that is not NULL");
} else {
// Handle NULL() initialization
mlir::Value componentValue{fir::factory::createUnallocatedBox(
builder, loc, componentTy, std::nullopt)};
mlir::Value componentValue{
fir::factory::createUnallocatedBox(builder, loc, componentTy, {})};
componentValue = builder.createConvert(loc, componentTy, componentValue);

return builder.create<fir::InsertValueOp>(
Expand Down
7 changes: 3 additions & 4 deletions flang/lib/Lower/ConvertExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ absentBoxToUnallocatedBox(fir::FirOpBuilder &builder, mlir::Location loc,
mlir::Type boxType = box.getType();
assert(mlir::isa<fir::BoxType>(boxType) && "argument must be a fir.box");
mlir::Value emptyBox =
fir::factory::createUnallocatedBox(builder, loc, boxType, std::nullopt);
fir::factory::createUnallocatedBox(builder, loc, boxType, {});
auto safeToReadBox =
builder.create<mlir::arith::SelectOp>(loc, isPresent, box, emptyBox);
return fir::substBase(exv, safeToReadBox);
Expand Down Expand Up @@ -2663,8 +2663,7 @@ class ScalarExprLowering {
/*nonDeferredParams=*/mlir::ValueRange{},
/*mutableProperties=*/{});
Fortran::lower::associateMutableBox(converter, loc, pointer, *expr,
/*lbounds=*/std::nullopt,
stmtCtx);
/*lbounds=*/{}, stmtCtx);
caller.placeInput(arg, irBox);
continue;
}
Expand Down Expand Up @@ -6186,7 +6185,7 @@ class ArrayExprLowering {
mlir::FunctionType memcpyType() {
auto ptrTy = mlir::LLVM::LLVMPointerType::get(builder.getContext());
llvm::SmallVector<mlir::Type> args = {ptrTy, ptrTy, builder.getI64Type()};
return mlir::FunctionType::get(builder.getContext(), args, std::nullopt);
return mlir::FunctionType::get(builder.getContext(), args, {});
}

/// Create a call to the LLVM memcpy intrinsic.
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Lower/ConvertExprToHLFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1945,7 +1945,7 @@ class HlfirBuilder {
fir::emitFatalError(loc, "pointer component designator could not be "
"lowered to mutable box");
Fortran::lower::associateMutableBox(converter, loc, *toBox, expr,
/*lbounds=*/std::nullopt, stmtCtx);
/*lbounds=*/{}, stmtCtx);
continue;
}

Expand Down
11 changes: 5 additions & 6 deletions flang/lib/Lower/ConvertVariable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,8 @@ mlir::Value Fortran::lower::genInitialDataTarget(
fir::FirOpBuilder &builder = converter.getFirOpBuilder();
if (Fortran::evaluate::UnwrapExpr<Fortran::evaluate::NullPointer>(
initialTarget))
return fir::factory::createUnallocatedBox(
builder, loc, boxType,
/*nonDeferredParams=*/std::nullopt);
return fir::factory::createUnallocatedBox(builder, loc, boxType,
/*nonDeferredParams=*/{});
// Pointer initial data target, and NULL(mold).
for (const auto &sym : Fortran::evaluate::CollectSymbols(initialTarget)) {
// Derived type component symbols should not be instantiated as objects
Expand Down Expand Up @@ -354,8 +353,8 @@ static mlir::Value genComponentDefaultInit(
// From a standard point of view, pointer without initialization do not
// need to be disassociated, but for sanity and simplicity, do it in
// global constructor since this has no runtime cost.
componentValue = fir::factory::createUnallocatedBox(
builder, loc, componentTy, std::nullopt);
componentValue =
fir::factory::createUnallocatedBox(builder, loc, componentTy, {});
} else if (Fortran::lower::hasDefaultInitialization(component)) {
// Component type has default initialization.
componentValue = genDefaultInitializerValue(converter, loc, component,
Expand Down Expand Up @@ -554,7 +553,7 @@ fir::GlobalOp Fortran::lower::defineGlobal(
createGlobalInitialization(builder, global, [&](fir::FirOpBuilder &b) {
mlir::Value box = fir::factory::createUnallocatedBox(
b, loc, symTy,
/*nonDeferredParams=*/std::nullopt,
/*nonDeferredParams=*/{},
/*typeSourceBox=*/{}, getAllocatorIdxFromDataAttr(dataAttr));
b.create<fir::HasValueOp>(loc, box);
});
Expand Down
6 changes: 3 additions & 3 deletions flang/lib/Lower/HostAssociations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,15 +410,15 @@ class CapturedArrays : public CapturedSymbols<CapturedArrays> {
.genThen([&]() {
fir::factory::associateMutableBox(builder, loc, boxInTuple,
args.hostValue,
/*lbounds=*/std::nullopt);
/*lbounds=*/{});
})
.genElse([&]() {
fir::factory::disassociateMutableBox(builder, loc, boxInTuple);
})
.end();
} else {
fir::factory::associateMutableBox(
builder, loc, boxInTuple, args.hostValue, /*lbounds=*/std::nullopt);
fir::factory::associateMutableBox(builder, loc, boxInTuple,
args.hostValue, /*lbounds=*/{});
}
}

Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Lower/IO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ getNamelistGroup(Fortran::lower::AbstractConverter &converter,
descAddr = builder.createTemporary(loc, boxType);
fir::MutableBoxValue box = fir::MutableBoxValue(descAddr, {}, {});
fir::factory::associateMutableBox(builder, loc, box, exv,
/*lbounds=*/std::nullopt);
/*lbounds=*/{});
}
descAddr = builder.createConvert(loc, descRefTy, descAddr);
list = builder.create<fir::InsertValueOp>(loc, listTy, list, descAddr,
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Builder/HLFIRTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1403,7 +1403,7 @@ hlfir::Entity hlfir::createStackTempFromMold(mlir::Location loc,
builder.createTemporary(loc, sequenceType, tmpName, extents, lenParams);
} else {
alloc = builder.createTemporary(loc, mold.getFortranElementType(), tmpName,
/*shape=*/std::nullopt, lenParams);
/*shape=*/{}, lenParams);
}
auto declareOp =
builder.create<hlfir::DeclareOp>(loc, alloc, tmpName, shape, lenParams,
Expand Down
13 changes: 5 additions & 8 deletions flang/lib/Optimizer/Builder/LowLevelIntrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,24 @@ mlir::func::FuncOp fir::factory::getRealloc(fir::FirOpBuilder &builder) {
mlir::func::FuncOp
fir::factory::getLlvmGetRounding(fir::FirOpBuilder &builder) {
auto int32Ty = builder.getIntegerType(32);
auto funcTy =
mlir::FunctionType::get(builder.getContext(), std::nullopt, {int32Ty});
auto funcTy = mlir::FunctionType::get(builder.getContext(), {}, {int32Ty});
return builder.createFunction(builder.getUnknownLoc(), "llvm.get.rounding",
funcTy);
}

mlir::func::FuncOp
fir::factory::getLlvmSetRounding(fir::FirOpBuilder &builder) {
auto int32Ty = builder.getIntegerType(32);
auto funcTy =
mlir::FunctionType::get(builder.getContext(), {int32Ty}, std::nullopt);
auto funcTy = mlir::FunctionType::get(builder.getContext(), {int32Ty}, {});
return builder.createFunction(builder.getUnknownLoc(), "llvm.set.rounding",
funcTy);
}

mlir::func::FuncOp
fir::factory::getLlvmInitTrampoline(fir::FirOpBuilder &builder) {
auto ptrTy = builder.getRefType(builder.getIntegerType(8));
auto funcTy = mlir::FunctionType::get(builder.getContext(),
{ptrTy, ptrTy, ptrTy}, std::nullopt);
auto funcTy =
mlir::FunctionType::get(builder.getContext(), {ptrTy, ptrTy, ptrTy}, {});
return builder.createFunction(builder.getUnknownLoc(), "llvm.init.trampoline",
funcTy);
}
Expand Down Expand Up @@ -90,8 +88,7 @@ mlir::func::FuncOp fir::factory::getFeenableexcept(fir::FirOpBuilder &builder) {

mlir::func::FuncOp fir::factory::getFegetexcept(fir::FirOpBuilder &builder) {
auto int32Ty = builder.getIntegerType(32);
auto funcTy =
mlir::FunctionType::get(builder.getContext(), std::nullopt, {int32Ty});
auto funcTy = mlir::FunctionType::get(builder.getContext(), {}, {int32Ty});
return builder.createFunction(builder.getUnknownLoc(), "fegetexcept", funcTy);
}

Expand Down
28 changes: 14 additions & 14 deletions flang/lib/Optimizer/Builder/MutableBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,23 +521,23 @@ void fir::factory::associateMutableBox(fir::FirOpBuilder &builder,
mlir::Value sourceBox;
if (auto *polyBox = source.getBoxOf<fir::PolymorphicValue>())
sourceBox = polyBox->getSourceBox();
writer.updateMutableBox(p.getAddr(), /*lbounds=*/std::nullopt,
/*extents=*/std::nullopt,
/*lengths=*/std::nullopt, sourceBox);
writer.updateMutableBox(p.getAddr(), /*lbounds=*/{},
/*extents=*/{},
/*lengths=*/{}, sourceBox);
},
[&](const fir::UnboxedValue &addr) {
writer.updateMutableBox(addr, /*lbounds=*/std::nullopt,
/*extents=*/std::nullopt,
/*lengths=*/std::nullopt);
writer.updateMutableBox(addr, /*lbounds=*/{},
/*extents=*/{},
/*lengths=*/{});
},
[&](const fir::CharBoxValue &ch) {
writer.updateMutableBox(ch.getAddr(), /*lbounds=*/std::nullopt,
/*extents=*/std::nullopt, {ch.getLen()});
writer.updateMutableBox(ch.getAddr(), /*lbounds=*/{},
/*extents=*/{}, {ch.getLen()});
},
[&](const fir::ArrayBoxValue &arr) {
writer.updateMutableBox(arr.getAddr(),
lbounds.empty() ? arr.getLBounds() : lbounds,
arr.getExtents(), /*lengths=*/std::nullopt);
arr.getExtents(), /*lengths=*/{});
},
[&](const fir::CharArrayBoxValue &arr) {
writer.updateMutableBox(arr.getAddr(),
Expand Down Expand Up @@ -634,19 +634,19 @@ void fir::factory::associateMutableBoxWithRemap(
source.match(
[&](const fir::PolymorphicValue &p) {
writer.updateMutableBox(cast(p.getAddr()), lbounds, extents,
/*lengths=*/std::nullopt);
/*lengths=*/{});
},
[&](const fir::UnboxedValue &addr) {
writer.updateMutableBox(cast(addr), lbounds, extents,
/*lengths=*/std::nullopt);
/*lengths=*/{});
},
[&](const fir::CharBoxValue &ch) {
writer.updateMutableBox(cast(ch.getAddr()), lbounds, extents,
{ch.getLen()});
},
[&](const fir::ArrayBoxValue &arr) {
writer.updateMutableBox(cast(arr.getAddr()), lbounds, extents,
/*lengths=*/std::nullopt);
/*lengths=*/{});
},
[&](const fir::CharArrayBoxValue &arr) {
writer.updateMutableBox(cast(arr.getAddr()), lbounds, extents,
Expand Down Expand Up @@ -755,8 +755,8 @@ static mlir::Value allocateAndInitNewStorage(fir::FirOpBuilder &builder,
// there is no way to know here if a derived type needs it or not. But the
// information is available at compile time and could be reflected here
// somehow.
mlir::Value irBox = createNewFirBox(builder, loc, box, newStorage,
std::nullopt, extents, lengths);
mlir::Value irBox =
createNewFirBox(builder, loc, box, newStorage, {}, extents, lengths);
fir::runtime::genDerivedTypeInitialize(builder, loc, irBox);
}
return newStorage;
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/Dialect/FIROps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4448,7 +4448,7 @@ llvm::LogicalResult fir::UnboxProcOp::verify() {

void fir::IfOp::build(mlir::OpBuilder &builder, mlir::OperationState &result,
mlir::Value cond, bool withElseRegion) {
build(builder, result, std::nullopt, cond, withElseRegion);
build(builder, result, {}, cond, withElseRegion);
}

void fir::IfOp::build(mlir::OpBuilder &builder, mlir::OperationState &result,
Expand Down
2 changes: 1 addition & 1 deletion flang/lib/Optimizer/HLFIR/Transforms/BufferizeHLFIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ struct SetLengthOpConversion
llvm::StringRef tmpName{".tmp"};
llvm::SmallVector<mlir::Value, 1> lenParams{adaptor.getLength()};
auto alloca = builder.createTemporary(loc, charType, tmpName,
/*shape=*/std::nullopt, lenParams);
/*shape=*/{}, lenParams);
auto declareOp = builder.create<hlfir::DeclareOp>(
loc, alloca, tmpName, /*shape=*/mlir::Value{}, lenParams,
/*dummy_scope=*/nullptr, fir::FortranVariableFlagsAttr{});
Expand Down
2 changes: 1 addition & 1 deletion flang/unittests/Optimizer/Builder/CharacterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct CharacterTest : public testing::Test {
moduleOp = builder.create<mlir::ModuleOp>(loc);
builder.setInsertionPointToStart(moduleOp->getBody());
mlir::func::FuncOp func = builder.create<mlir::func::FuncOp>(
loc, "func1", builder.getFunctionType(std::nullopt, std::nullopt));
loc, "func1", builder.getFunctionType({}, {}));
auto *entryBlock = func.addEntryBlock();
builder.setInsertionPointToStart(entryBlock);

Expand Down
2 changes: 1 addition & 1 deletion flang/unittests/Optimizer/Builder/ComplexTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct ComplexTest : public testing::Test {
moduleOp = builder.create<mlir::ModuleOp>(loc);
builder.setInsertionPointToStart(moduleOp->getBody());
mlir::func::FuncOp func = builder.create<mlir::func::FuncOp>(
loc, "func1", builder.getFunctionType(std::nullopt, std::nullopt));
loc, "func1", builder.getFunctionType({}, {}));
auto *entryBlock = func.addEntryBlock();
builder.setInsertionPointToStart(entryBlock);

Expand Down
5 changes: 2 additions & 3 deletions flang/unittests/Optimizer/Builder/FIRBuilderTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct FIRBuilderTest : public testing::Test {
moduleOp = builder.create<mlir::ModuleOp>(loc);
builder.setInsertionPointToStart(moduleOp->getBody());
mlir::func::FuncOp func = builder.create<mlir::func::FuncOp>(
loc, "func1", builder.getFunctionType(std::nullopt, std::nullopt));
loc, "func1", builder.getFunctionType({}, {}));
auto *entryBlock = func.addEntryBlock();
builder.setInsertionPointToStart(entryBlock);

Expand Down Expand Up @@ -176,8 +176,7 @@ TEST_F(FIRBuilderTest, getNamedFunction) {
auto func2 = builder.getNamedFunction("func2");
EXPECT_EQ(nullptr, func2);
auto loc = builder.getUnknownLoc();
func2 = builder.createFunction(
loc, "func2", builder.getFunctionType(std::nullopt, std::nullopt));
func2 = builder.createFunction(loc, "func2", builder.getFunctionType({}, {}));
auto func2query = builder.getNamedFunction("func2");
EXPECT_EQ(func2, func2query);
}
Expand Down
2 changes: 1 addition & 1 deletion flang/unittests/Optimizer/Builder/HLFIRToolsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ struct HLFIRToolsTest : public testing::Test {
moduleOp = builder.create<mlir::ModuleOp>(loc);
builder.setInsertionPointToStart(moduleOp->getBody());
mlir::func::FuncOp func = builder.create<mlir::func::FuncOp>(
loc, "func1", builder.getFunctionType(std::nullopt, std::nullopt));
loc, "func1", builder.getFunctionType({}, {}));
auto *entryBlock = func.addEntryBlock();
builder.setInsertionPointToStart(entryBlock);

Expand Down
Loading
Loading