Skip to content

Commit c092158

Browse files
[flang] Use std::optional instead of llvm::Optional (NFC)
This patch replaces (llvm::|)Optional< with std::optional<. I'll post a separate patch to remove #include "llvm/ADT/Optional.h". This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
1 parent 4d4d478 commit c092158

34 files changed

+157
-159
lines changed

flang/include/flang/Lower/BoxAnalyzer.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct ScalarDynamicChar : ScalarSym {
7777
ScalarDynamicChar(const Fortran::semantics::Symbol &sym)
7878
: ScalarSym{sym}, len{FromBox{}} {}
7979

80-
llvm::Optional<Fortran::lower::SomeExpr> charLen() const {
80+
std::optional<Fortran::lower::SomeExpr> charLen() const {
8181
if (auto *l = std::get_if<Fortran::lower::SomeExpr>(&len))
8282
return {*l};
8383
return std::nullopt;
@@ -318,17 +318,17 @@ class BoxAnalyzer : public fir::details::matcher<BoxAnalyzer> {
318318
[](const auto &x) { return x.staticSize(); });
319319
}
320320

321-
llvm::Optional<int64_t> getCharLenConst() const {
322-
using A = llvm::Optional<int64_t>;
321+
std::optional<int64_t> getCharLenConst() const {
322+
using A = std::optional<int64_t>;
323323
return match(
324324
[](const ScalarStaticChar &x) -> A { return {x.charLen()}; },
325325
[](const StaticArrayStaticChar &x) -> A { return {x.charLen()}; },
326326
[](const DynamicArrayStaticChar &x) -> A { return {x.charLen()}; },
327327
[](const auto &) -> A { return std::nullopt; });
328328
}
329329

330-
llvm::Optional<Fortran::lower::SomeExpr> getCharLenExpr() const {
331-
using A = llvm::Optional<Fortran::lower::SomeExpr>;
330+
std::optional<Fortran::lower::SomeExpr> getCharLenExpr() const {
331+
using A = std::optional<Fortran::lower::SomeExpr>;
332332
return match([](const ScalarDynamicChar &x) { return x.charLen(); },
333333
[](const StaticArrayDynamicChar &x) { return x.charLen(); },
334334
[](const DynamicArrayDynamicChar &x) { return x.charLen(); },
@@ -472,9 +472,9 @@ class BoxAnalyzer : public fir::details::matcher<BoxAnalyzer> {
472472
}
473473

474474
// Get the constant LEN of a CHARACTER, if it exists.
475-
llvm::Optional<int64_t>
475+
std::optional<int64_t>
476476
charLenConstant(const Fortran::semantics::Symbol &sym) {
477-
if (llvm::Optional<Fortran::lower::SomeExpr> expr = charLenVariable(sym))
477+
if (std::optional<Fortran::lower::SomeExpr> expr = charLenVariable(sym))
478478
if (std::optional<int64_t> asInt = Fortran::evaluate::ToInt64(*expr)) {
479479
// Length is max(0, *asInt) (F2018 7.4.4.2 point 5.).
480480
if (*asInt < 0)
@@ -485,7 +485,7 @@ class BoxAnalyzer : public fir::details::matcher<BoxAnalyzer> {
485485
}
486486

487487
// Get the `SomeExpr` that describes the CHARACTER's LEN.
488-
llvm::Optional<Fortran::lower::SomeExpr>
488+
std::optional<Fortran::lower::SomeExpr>
489489
charLenVariable(const Fortran::semantics::Symbol &sym) {
490490
const Fortran::semantics::ParamValue &lenParam =
491491
sym.GetType()->characterTypeSpec().length();

flang/include/flang/Lower/ComponentPath.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ComponentPath {
6969
/// This optional continuation allows the generation of those dereferences.
7070
/// These accesses are always on Fortran entities of record types, which are
7171
/// implicitly in-memory objects.
72-
llvm::Optional<ExtendRefFunc> extendCoorRef = std::nullopt;
72+
std::optional<ExtendRefFunc> extendCoorRef = std::nullopt;
7373

7474
private:
7575
void setPC(bool isImplicit);

flang/include/flang/Lower/ConvertCall.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fir::ExtendedValue genCallOpAndResult(
3232
mlir::Location loc, Fortran::lower::AbstractConverter &converter,
3333
Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx,
3434
Fortran::lower::CallerInterface &caller, mlir::FunctionType callSiteType,
35-
llvm::Optional<mlir::Type> resultType);
35+
std::optional<mlir::Type> resultType);
3636

3737
/// If \p arg is the address of a function with a denoted host-association tuple
3838
/// argument, then return the host-associations tuple value of the current
@@ -42,11 +42,10 @@ mlir::Value argumentHostAssocs(Fortran::lower::AbstractConverter &converter,
4242

4343
/// Lower a ProcedureRef to HLFIR. If this is a function call, return the
4444
/// lowered result value. Return nothing otherwise.
45-
llvm::Optional<hlfir::EntityWithAttributes> convertCallToHLFIR(
45+
std::optional<hlfir::EntityWithAttributes> convertCallToHLFIR(
4646
mlir::Location loc, Fortran::lower::AbstractConverter &converter,
47-
const evaluate::ProcedureRef &procRef,
48-
llvm::Optional<mlir::Type> resultType, Fortran::lower::SymMap &symMap,
49-
Fortran::lower::StatementContext &stmtCtx);
47+
const evaluate::ProcedureRef &procRef, std::optional<mlir::Type> resultType,
48+
Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx);
5049

5150
} // namespace Fortran::lower
5251
#endif // FORTRAN_LOWER_CONVERTCALL_H

flang/include/flang/Lower/ConvertExpr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ void createArrayOfPointerAssignment(
176176
AbstractConverter &converter, const SomeExpr &lhs, const SomeExpr &rhs,
177177
ExplicitIterSpace &explicitIterSpace, ImplicitIterSpace &implicitIterSpace,
178178
const llvm::SmallVector<mlir::Value> &lbounds,
179-
llvm::Optional<llvm::SmallVector<mlir::Value>> ubounds, SymMap &symMap,
179+
std::optional<llvm::SmallVector<mlir::Value>> ubounds, SymMap &symMap,
180180
StatementContext &stmtCtx);
181181

182182
/// Lower an array expression with "parallel" semantics. Such a rhs expression

flang/include/flang/Lower/CustomIntrinsicCall.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ using OperandPrepare = std::function<void(const Fortran::lower::SomeExpr &)>;
5454
/// preparation was done. An absent optional means the argument is statically
5555
/// present. An mlir::Value means the presence must be checked at runtime, and
5656
/// that the value contains the "is present" boolean value.
57-
using OperandPresent = std::function<llvm::Optional<mlir::Value>(std::size_t)>;
57+
using OperandPresent = std::function<std::optional<mlir::Value>(std::size_t)>;
5858

5959
/// Type of the callback to generate an argument reference after the call
6060
/// preparation was done. For optional arguments, the utility guarantees
@@ -77,7 +77,7 @@ using OperandGetter = std::function<fir::ExtendedValue(std::size_t)>;
7777
void prepareCustomIntrinsicArgument(
7878
const Fortran::evaluate::ProcedureRef &procRef,
7979
const Fortran::evaluate::SpecificIntrinsic &intrinsic,
80-
llvm::Optional<mlir::Type> retTy,
80+
std::optional<mlir::Type> retTy,
8181
const OperandPrepare &prepareOptionalArgument,
8282
const OperandPrepare &prepareOtherArgument, AbstractConverter &converter);
8383

@@ -90,7 +90,7 @@ void prepareCustomIntrinsicArgument(
9090
/// not generate any implicit loop nest on its own).
9191
fir::ExtendedValue
9292
lowerCustomIntrinsic(fir::FirOpBuilder &builder, mlir::Location loc,
93-
llvm::StringRef name, llvm::Optional<mlir::Type> retTy,
93+
llvm::StringRef name, std::optional<mlir::Type> retTy,
9494
const OperandPresent &isPresentCheck,
9595
const OperandGetter &getOperand, std::size_t numOperands,
9696
Fortran::lower::StatementContext &stmtCtx);

flang/include/flang/Lower/IntrinsicCall.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class StatementContext;
2929
/// Returned mlir::Value is the returned Fortran intrinsic value.
3030
fir::ExtendedValue genIntrinsicCall(fir::FirOpBuilder &, mlir::Location,
3131
llvm::StringRef name,
32-
llvm::Optional<mlir::Type> resultType,
32+
std::optional<mlir::Type> resultType,
3333
llvm::ArrayRef<fir::ExtendedValue> args,
3434
StatementContext &);
3535

flang/include/flang/Lower/IterationSpace.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ class ExplicitIterSpace {
445445
}
446446

447447
/// `load` must be a LHS array_load. Returns `std::nullopt` on error.
448-
llvm::Optional<size_t> findArgPosition(fir::ArrayLoadOp load);
448+
std::optional<size_t> findArgPosition(fir::ArrayLoadOp load);
449449

450450
bool isLHS(fir::ArrayLoadOp load) {
451451
return findArgPosition(load).has_value();
@@ -466,7 +466,7 @@ class ExplicitIterSpace {
466466
llvm_unreachable("inner argument value was not found");
467467
}
468468

469-
llvm::Optional<fir::ArrayLoadOp> getLhsLoad(size_t i) {
469+
std::optional<fir::ArrayLoadOp> getLhsLoad(size_t i) {
470470
assert(i < lhsBases.size());
471471
if (lhsBases[counter])
472472
return findBinding(*lhsBases[counter]);
@@ -542,7 +542,7 @@ class ExplicitIterSpace {
542542

543543
// A stack of lists of front-end symbols.
544544
llvm::SmallVector<llvm::SmallVector<FrontEndSymbol>> symbolStack;
545-
llvm::SmallVector<llvm::Optional<ArrayBases>> lhsBases;
545+
llvm::SmallVector<std::optional<ArrayBases>> lhsBases;
546546
llvm::SmallVector<llvm::SmallVector<ArrayBases>> rhsBases;
547547
llvm::DenseMap<ArrayBases, fir::ArrayLoadOp> loadBindings;
548548

@@ -553,9 +553,9 @@ class ExplicitIterSpace {
553553
StatementContext stmtCtx;
554554
llvm::SmallVector<mlir::Value> innerArgs;
555555
llvm::SmallVector<mlir::Value> initialArgs;
556-
llvm::Optional<fir::DoLoopOp> outerLoop;
556+
std::optional<fir::DoLoopOp> outerLoop;
557557
llvm::SmallVector<llvm::SmallVector<fir::DoLoopOp>> loopStack;
558-
llvm::Optional<std::function<void(fir::FirOpBuilder &)>> loopCleanup;
558+
std::optional<std::function<void(fir::FirOpBuilder &)>> loopCleanup;
559559
std::size_t forallContextOpen = 0;
560560
std::size_t counter = 0;
561561
};

flang/include/flang/Lower/Runtime.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ void genPointerAssociateRemapping(fir::FirOpBuilder &, mlir::Location,
7878

7979
mlir::Value genCpuTime(fir::FirOpBuilder &, mlir::Location);
8080
void genDateAndTime(fir::FirOpBuilder &, mlir::Location,
81-
llvm::Optional<fir::CharBoxValue> date,
82-
llvm::Optional<fir::CharBoxValue> time,
83-
llvm::Optional<fir::CharBoxValue> zone, mlir::Value values);
81+
std::optional<fir::CharBoxValue> date,
82+
std::optional<fir::CharBoxValue> time,
83+
std::optional<fir::CharBoxValue> zone, mlir::Value values);
8484

8585
void genRandomInit(fir::FirOpBuilder &, mlir::Location, mlir::Value repeatable,
8686
mlir::Value imageDistinct);

flang/include/flang/Lower/SymbolMap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ class SymMap {
349349
symbolMapStack.back().try_emplace(sym, definingOp);
350350
}
351351

352-
llvm::Optional<fir::FortranVariableOpInterface>
352+
std::optional<fir::FortranVariableOpInterface>
353353
lookupVariableDefinition(semantics::SymbolRef sym);
354354

355355
private:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,8 @@ mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc,
596596
mlir::Type type);
597597

598598
/// Get the integer constants of triplet and compute the extent.
599-
llvm::Optional<std::int64_t>
600-
getExtentFromTriplet(mlir::Value lb, mlir::Value ub, mlir::Value stride);
599+
std::optional<std::int64_t> getExtentFromTriplet(mlir::Value lb, mlir::Value ub,
600+
mlir::Value stride);
601601

602602
/// Generate max(\p value, 0) where \p value is a scalar integer.
603603
mlir::Value genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc,

0 commit comments

Comments
 (0)