diff --git a/flang/include/flang/Lower/BoxAnalyzer.h b/flang/include/flang/Lower/BoxAnalyzer.h index 07588e8410c96..52cded8b219d8 100644 --- a/flang/include/flang/Lower/BoxAnalyzer.h +++ b/flang/include/flang/Lower/BoxAnalyzer.h @@ -77,7 +77,7 @@ struct ScalarDynamicChar : ScalarSym { ScalarDynamicChar(const Fortran::semantics::Symbol &sym) : ScalarSym{sym}, len{FromBox{}} {} - llvm::Optional charLen() const { + std::optional charLen() const { if (auto *l = std::get_if(&len)) return {*l}; return std::nullopt; @@ -318,8 +318,8 @@ class BoxAnalyzer : public fir::details::matcher { [](const auto &x) { return x.staticSize(); }); } - llvm::Optional getCharLenConst() const { - using A = llvm::Optional; + std::optional getCharLenConst() const { + using A = std::optional; return match( [](const ScalarStaticChar &x) -> A { return {x.charLen()}; }, [](const StaticArrayStaticChar &x) -> A { return {x.charLen()}; }, @@ -327,8 +327,8 @@ class BoxAnalyzer : public fir::details::matcher { [](const auto &) -> A { return std::nullopt; }); } - llvm::Optional getCharLenExpr() const { - using A = llvm::Optional; + std::optional getCharLenExpr() const { + using A = std::optional; return match([](const ScalarDynamicChar &x) { return x.charLen(); }, [](const StaticArrayDynamicChar &x) { return x.charLen(); }, [](const DynamicArrayDynamicChar &x) { return x.charLen(); }, @@ -472,9 +472,9 @@ class BoxAnalyzer : public fir::details::matcher { } // Get the constant LEN of a CHARACTER, if it exists. - llvm::Optional + std::optional charLenConstant(const Fortran::semantics::Symbol &sym) { - if (llvm::Optional expr = charLenVariable(sym)) + if (std::optional expr = charLenVariable(sym)) if (std::optional asInt = Fortran::evaluate::ToInt64(*expr)) { // Length is max(0, *asInt) (F2018 7.4.4.2 point 5.). if (*asInt < 0) @@ -485,7 +485,7 @@ class BoxAnalyzer : public fir::details::matcher { } // Get the `SomeExpr` that describes the CHARACTER's LEN. - llvm::Optional + std::optional charLenVariable(const Fortran::semantics::Symbol &sym) { const Fortran::semantics::ParamValue &lenParam = sym.GetType()->characterTypeSpec().length(); diff --git a/flang/include/flang/Lower/ComponentPath.h b/flang/include/flang/Lower/ComponentPath.h index fb8395ba008d4..69960bad4e056 100644 --- a/flang/include/flang/Lower/ComponentPath.h +++ b/flang/include/flang/Lower/ComponentPath.h @@ -69,7 +69,7 @@ class ComponentPath { /// This optional continuation allows the generation of those dereferences. /// These accesses are always on Fortran entities of record types, which are /// implicitly in-memory objects. - llvm::Optional extendCoorRef = std::nullopt; + std::optional extendCoorRef = std::nullopt; private: void setPC(bool isImplicit); diff --git a/flang/include/flang/Lower/ConvertCall.h b/flang/include/flang/Lower/ConvertCall.h index 33008a17457f5..9336468ec2217 100644 --- a/flang/include/flang/Lower/ConvertCall.h +++ b/flang/include/flang/Lower/ConvertCall.h @@ -32,7 +32,7 @@ fir::ExtendedValue genCallOpAndResult( mlir::Location loc, Fortran::lower::AbstractConverter &converter, Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx, Fortran::lower::CallerInterface &caller, mlir::FunctionType callSiteType, - llvm::Optional resultType); + std::optional resultType); /// If \p arg is the address of a function with a denoted host-association tuple /// argument, then return the host-associations tuple value of the current @@ -42,11 +42,10 @@ mlir::Value argumentHostAssocs(Fortran::lower::AbstractConverter &converter, /// Lower a ProcedureRef to HLFIR. If this is a function call, return the /// lowered result value. Return nothing otherwise. -llvm::Optional convertCallToHLFIR( +std::optional convertCallToHLFIR( mlir::Location loc, Fortran::lower::AbstractConverter &converter, - const evaluate::ProcedureRef &procRef, - llvm::Optional resultType, Fortran::lower::SymMap &symMap, - Fortran::lower::StatementContext &stmtCtx); + const evaluate::ProcedureRef &procRef, std::optional resultType, + Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx); } // namespace Fortran::lower #endif // FORTRAN_LOWER_CONVERTCALL_H diff --git a/flang/include/flang/Lower/ConvertExpr.h b/flang/include/flang/Lower/ConvertExpr.h index bf681e9a96924..e8b388bd0b7f9 100644 --- a/flang/include/flang/Lower/ConvertExpr.h +++ b/flang/include/flang/Lower/ConvertExpr.h @@ -176,7 +176,7 @@ void createArrayOfPointerAssignment( AbstractConverter &converter, const SomeExpr &lhs, const SomeExpr &rhs, ExplicitIterSpace &explicitIterSpace, ImplicitIterSpace &implicitIterSpace, const llvm::SmallVector &lbounds, - llvm::Optional> ubounds, SymMap &symMap, + std::optional> ubounds, SymMap &symMap, StatementContext &stmtCtx); /// Lower an array expression with "parallel" semantics. Such a rhs expression diff --git a/flang/include/flang/Lower/CustomIntrinsicCall.h b/flang/include/flang/Lower/CustomIntrinsicCall.h index 9ae84fd62362a..bb7e599a4f496 100644 --- a/flang/include/flang/Lower/CustomIntrinsicCall.h +++ b/flang/include/flang/Lower/CustomIntrinsicCall.h @@ -54,7 +54,7 @@ using OperandPrepare = std::function; /// preparation was done. An absent optional means the argument is statically /// present. An mlir::Value means the presence must be checked at runtime, and /// that the value contains the "is present" boolean value. -using OperandPresent = std::function(std::size_t)>; +using OperandPresent = std::function(std::size_t)>; /// Type of the callback to generate an argument reference after the call /// preparation was done. For optional arguments, the utility guarantees @@ -77,7 +77,7 @@ using OperandGetter = std::function; void prepareCustomIntrinsicArgument( const Fortran::evaluate::ProcedureRef &procRef, const Fortran::evaluate::SpecificIntrinsic &intrinsic, - llvm::Optional retTy, + std::optional retTy, const OperandPrepare &prepareOptionalArgument, const OperandPrepare &prepareOtherArgument, AbstractConverter &converter); @@ -90,7 +90,7 @@ void prepareCustomIntrinsicArgument( /// not generate any implicit loop nest on its own). fir::ExtendedValue lowerCustomIntrinsic(fir::FirOpBuilder &builder, mlir::Location loc, - llvm::StringRef name, llvm::Optional retTy, + llvm::StringRef name, std::optional retTy, const OperandPresent &isPresentCheck, const OperandGetter &getOperand, std::size_t numOperands, Fortran::lower::StatementContext &stmtCtx); diff --git a/flang/include/flang/Lower/IntrinsicCall.h b/flang/include/flang/Lower/IntrinsicCall.h index cd7c7a622cd05..0d404fe9b43b4 100644 --- a/flang/include/flang/Lower/IntrinsicCall.h +++ b/flang/include/flang/Lower/IntrinsicCall.h @@ -29,7 +29,7 @@ class StatementContext; /// Returned mlir::Value is the returned Fortran intrinsic value. fir::ExtendedValue genIntrinsicCall(fir::FirOpBuilder &, mlir::Location, llvm::StringRef name, - llvm::Optional resultType, + std::optional resultType, llvm::ArrayRef args, StatementContext &); diff --git a/flang/include/flang/Lower/IterationSpace.h b/flang/include/flang/Lower/IterationSpace.h index a7de970b4c74b..1c413a5f0c115 100644 --- a/flang/include/flang/Lower/IterationSpace.h +++ b/flang/include/flang/Lower/IterationSpace.h @@ -445,7 +445,7 @@ class ExplicitIterSpace { } /// `load` must be a LHS array_load. Returns `std::nullopt` on error. - llvm::Optional findArgPosition(fir::ArrayLoadOp load); + std::optional findArgPosition(fir::ArrayLoadOp load); bool isLHS(fir::ArrayLoadOp load) { return findArgPosition(load).has_value(); @@ -466,7 +466,7 @@ class ExplicitIterSpace { llvm_unreachable("inner argument value was not found"); } - llvm::Optional getLhsLoad(size_t i) { + std::optional getLhsLoad(size_t i) { assert(i < lhsBases.size()); if (lhsBases[counter]) return findBinding(*lhsBases[counter]); @@ -542,7 +542,7 @@ class ExplicitIterSpace { // A stack of lists of front-end symbols. llvm::SmallVector> symbolStack; - llvm::SmallVector> lhsBases; + llvm::SmallVector> lhsBases; llvm::SmallVector> rhsBases; llvm::DenseMap loadBindings; @@ -553,9 +553,9 @@ class ExplicitIterSpace { StatementContext stmtCtx; llvm::SmallVector innerArgs; llvm::SmallVector initialArgs; - llvm::Optional outerLoop; + std::optional outerLoop; llvm::SmallVector> loopStack; - llvm::Optional> loopCleanup; + std::optional> loopCleanup; std::size_t forallContextOpen = 0; std::size_t counter = 0; }; diff --git a/flang/include/flang/Lower/Runtime.h b/flang/include/flang/Lower/Runtime.h index da01d1a87cccd..1c4b98f084e1e 100644 --- a/flang/include/flang/Lower/Runtime.h +++ b/flang/include/flang/Lower/Runtime.h @@ -78,9 +78,9 @@ void genPointerAssociateRemapping(fir::FirOpBuilder &, mlir::Location, mlir::Value genCpuTime(fir::FirOpBuilder &, mlir::Location); void genDateAndTime(fir::FirOpBuilder &, mlir::Location, - llvm::Optional date, - llvm::Optional time, - llvm::Optional zone, mlir::Value values); + std::optional date, + std::optional time, + std::optional zone, mlir::Value values); void genRandomInit(fir::FirOpBuilder &, mlir::Location, mlir::Value repeatable, mlir::Value imageDistinct); diff --git a/flang/include/flang/Lower/SymbolMap.h b/flang/include/flang/Lower/SymbolMap.h index f3450f5b23564..f65e55168edf4 100644 --- a/flang/include/flang/Lower/SymbolMap.h +++ b/flang/include/flang/Lower/SymbolMap.h @@ -349,7 +349,7 @@ class SymMap { symbolMapStack.back().try_emplace(sym, definingOp); } - llvm::Optional + std::optional lookupVariableDefinition(semantics::SymbolRef sym); private: diff --git a/flang/include/flang/Optimizer/Builder/FIRBuilder.h b/flang/include/flang/Optimizer/Builder/FIRBuilder.h index b44d9faf6fe23..682b45746bd35 100644 --- a/flang/include/flang/Optimizer/Builder/FIRBuilder.h +++ b/flang/include/flang/Optimizer/Builder/FIRBuilder.h @@ -596,8 +596,8 @@ mlir::Value createZeroValue(fir::FirOpBuilder &builder, mlir::Location loc, mlir::Type type); /// Get the integer constants of triplet and compute the extent. -llvm::Optional -getExtentFromTriplet(mlir::Value lb, mlir::Value ub, mlir::Value stride); +std::optional getExtentFromTriplet(mlir::Value lb, mlir::Value ub, + mlir::Value stride); /// Generate max(\p value, 0) where \p value is a scalar integer. mlir::Value genMaxWithZero(fir::FirOpBuilder &builder, mlir::Location loc, diff --git a/flang/include/flang/Optimizer/Builder/HLFIRTools.h b/flang/include/flang/Optimizer/Builder/HLFIRTools.h index cb37484a934e0..e2886f6058ace 100644 --- a/flang/include/flang/Optimizer/Builder/HLFIRTools.h +++ b/flang/include/flang/Optimizer/Builder/HLFIRTools.h @@ -163,7 +163,7 @@ class EntityWithAttributes : public Entity { /// In that case, a cleanup function is provided to generate the finalization /// code after the end of the fir::ExtendedValue use. using CleanupFunction = std::function; -std::pair> +std::pair> translateToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder, Entity entity); diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index b17d197ff98b5..0e9e94503ad89 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -133,7 +133,7 @@ static void parseCodeGenArgs(Fortran::frontend::CodeGenOptions &opts, if (const llvm::opt::Arg *A = args.getLastArg(clang::driver::options::OPT_mrelocation_model)) { llvm::StringRef ModelName = A->getValue(); - auto RM = llvm::StringSwitch>(ModelName) + auto RM = llvm::StringSwitch>(ModelName) .Case("static", llvm::Reloc::Static) .Case("pic", llvm::Reloc::PIC_) .Case("dynamic-no-pic", llvm::Reloc::DynamicNoPIC) diff --git a/flang/lib/Lower/Bridge.cpp b/flang/lib/Lower/Bridge.cpp index c5551ff0810e2..9f10ec59a988a 100644 --- a/flang/lib/Lower/Bridge.cpp +++ b/flang/lib/Lower/Bridge.cpp @@ -823,7 +823,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { Fortran::lower::SymbolBox lookupSymbol(const Fortran::semantics::Symbol &sym) { if (bridge.getLoweringOptions().getLowerToHighLevelFIR()) { - if (llvm::Optional var = + if (std::optional var = localSymbols.lookupVariableDefinition(sym)) { auto exv = hlfir::translateToExtendedValue(toLocation(), *builder, *var); @@ -1098,7 +1098,7 @@ class FirConverter : public Fortran::lower::AbstractConverter { assert(stmt.typedCall && "Call was not analyzed"); mlir::Value res{}; if (bridge.getLoweringOptions().getLowerToHighLevelFIR()) { - llvm::Optional resultType = std::nullopt; + std::optional resultType = std::nullopt; if (stmt.typedCall->hasAlternateReturns()) resultType = builder->getIndexType(); auto hlfirRes = Fortran::lower::convertCallToHLFIR( @@ -2544,8 +2544,8 @@ class FirConverter : public Fortran::lower::AbstractConverter { void genArrayAssignment( const Fortran::evaluate::Assignment &assign, Fortran::lower::StatementContext &localStmtCtx, - llvm::Optional> lbounds = std::nullopt, - llvm::Optional> ubounds = std::nullopt) { + std::optional> lbounds = std::nullopt, + std::optional> ubounds = std::nullopt) { Fortran::lower::StatementContext &stmtCtx = explicitIterationSpace() @@ -2697,8 +2697,8 @@ class FirConverter : public Fortran::lower::AbstractConverter { : genExprAddr(assign.rhs, stmtCtx); const bool lhsIsWholeAllocatable = Fortran::lower::isWholeAllocatable(assign.lhs); - llvm::Optional lhsRealloc; - llvm::Optional lhsMutableBox; + std::optional lhsRealloc; + std::optional lhsMutableBox; auto lhs = [&]() -> fir::ExtendedValue { if (lhsIsWholeAllocatable) { lhsMutableBox = genExprMutableBox(loc, assign.lhs); diff --git a/flang/lib/Lower/CallInterface.cpp b/flang/lib/Lower/CallInterface.cpp index 41be1b0eabcdc..2034c7c6055e1 100644 --- a/flang/lib/Lower/CallInterface.cpp +++ b/flang/lib/Lower/CallInterface.cpp @@ -686,7 +686,7 @@ class Fortran::lower::CallInterfaceImpl { interface.side().getHostAssociatedTuple(), emptyValue()}); } - static llvm::Optional getResultDynamicType( + static std::optional getResultDynamicType( const Fortran::evaluate::characteristics::Procedure &procedure) { if (const std::optional &result = procedure.functionResult) @@ -714,7 +714,7 @@ class Fortran::lower::CallInterfaceImpl { // array function with assumed length (f18 forbides defining such // interfaces). Hence, passing the length is most likely useless, but stick // with ifort/nag/xlf interface here. - if (llvm::Optional type = + if (std::optional type = getResultDynamicType(procedure)) return type->category() == Fortran::common::TypeCategory::Character; return false; @@ -987,7 +987,7 @@ class Fortran::lower::CallInterfaceImpl { proc.procedure.value(); mlir::Type funcType = getProcedureDesignatorType(&procedure, interface.converter); - llvm::Optional resultTy = + std::optional resultTy = getResultDynamicType(procedure); if (resultTy && mustPassLengthWithDummyProcedure(procedure)) { // The result length of dummy procedures that are character functions must diff --git a/flang/lib/Lower/ConvertCall.cpp b/flang/lib/Lower/ConvertCall.cpp index 926f6ce207dd6..70905d591e6ec 100644 --- a/flang/lib/Lower/ConvertCall.cpp +++ b/flang/lib/Lower/ConvertCall.cpp @@ -103,7 +103,7 @@ fir::ExtendedValue Fortran::lower::genCallOpAndResult( mlir::Location loc, Fortran::lower::AbstractConverter &converter, Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx, Fortran::lower::CallerInterface &caller, mlir::FunctionType callSiteType, - llvm::Optional resultType) { + std::optional resultType) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); using PassBy = Fortran::lower::CallerInterface::PassEntityBy; // Handle cases where caller must allocate the result or a fir.box for it. @@ -137,7 +137,7 @@ fir::ExtendedValue Fortran::lower::genCallOpAndResult( return fir::factory::genMaxWithZero(builder, loc, convertExpr); }; llvm::SmallVector resultLengths; - auto allocatedResult = [&]() -> llvm::Optional { + auto allocatedResult = [&]() -> std::optional { llvm::SmallVector extents; llvm::SmallVector lengths; if (!caller.callerAllocateResult()) @@ -514,7 +514,7 @@ class CallBuilder { bool handleDynamicOptional; }; using PreparedActualArguments = - llvm::SmallVector>; + llvm::SmallVector>; using PassBy = Fortran::lower::CallerInterface::PassEntityBy; public: @@ -523,9 +523,9 @@ class CallBuilder { Fortran::lower::StatementContext &stmtCtx) : converter{converter}, symMap{symMap}, stmtCtx{stmtCtx}, loc{loc} {} - llvm::Optional + std::optional gen(const Fortran::evaluate::ProcedureRef &procRef, - llvm::Optional resultType) { + std::optional resultType) { mlir::Location loc = getLoc(); if (auto *specific = procRef.proc().GetSpecificIntrinsic()) { if (isElementalProcWithArrayArgs(procRef)) @@ -571,10 +571,10 @@ class CallBuilder { } private: - llvm::Optional + std::optional genUserCall(PreparedActualArguments &loweredActuals, Fortran::lower::CallerInterface &caller, - llvm::Optional resultType, + std::optional resultType, mlir::FunctionType callSiteType) { mlir::Location loc = getLoc(); fir::FirOpBuilder &builder = getBuilder(); @@ -667,10 +667,10 @@ class CallBuilder { return extendedValueToHlfirEntity(result, ".tmp.func_result"); } - llvm::Optional + std::optional genElementalUserCall(PreparedActualArguments &loweredActuals, Fortran::lower::CallerInterface &caller, - llvm::Optional resultType, + std::optional resultType, mlir::FunctionType callSiteType, bool isImpure) { mlir::Location loc = getLoc(); fir::FirOpBuilder &builder = getBuilder(); @@ -747,7 +747,7 @@ class CallBuilder { hlfir::EntityWithAttributes genIntrinsicRef(const Fortran::evaluate::ProcedureRef &procRef, - llvm::Optional resultType, + std::optional resultType, const Fortran::evaluate::SpecificIntrinsic &intrinsic) { mlir::Location loc = getLoc(); if (Fortran::lower::intrinsicRequiresCustomOptionalHandling( @@ -822,10 +822,9 @@ class CallBuilder { }; } // namespace -llvm::Optional Fortran::lower::convertCallToHLFIR( +std::optional Fortran::lower::convertCallToHLFIR( mlir::Location loc, Fortran::lower::AbstractConverter &converter, - const evaluate::ProcedureRef &procRef, - llvm::Optional resultType, Fortran::lower::SymMap &symMap, - Fortran::lower::StatementContext &stmtCtx) { + const evaluate::ProcedureRef &procRef, std::optional resultType, + Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx) { return CallBuilder(loc, converter, symMap, stmtCtx).gen(procRef, resultType); } diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp index bbac1d8967e5e..74147db962f9a 100644 --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -1838,8 +1838,8 @@ class ScalarExprLowering { /// Generate a call to a Fortran intrinsic or intrinsic module procedure. ExtValue genIntrinsicRef( const Fortran::evaluate::ProcedureRef &procRef, - llvm::Optional resultType, - llvm::Optional intrinsic = + std::optional resultType, + std::optional intrinsic = std::nullopt) { llvm::SmallVector operands; @@ -1849,7 +1849,7 @@ class ScalarExprLowering { mlir::Location loc = getLoc(); if (intrinsic && Fortran::lower::intrinsicRequiresCustomOptionalHandling( procRef, *intrinsic, converter)) { - using ExvAndPresence = std::pair>; + using ExvAndPresence = std::pair>; llvm::SmallVector operands; auto prepareOptionalArg = [&](const Fortran::lower::SomeExpr &expr) { ExtValue optionalArg = lowerIntrinsicArgumentAsInquired(expr); @@ -1870,7 +1870,7 @@ class ScalarExprLowering { return genLoad(operands[i].first); return operands[i].first; }; - auto isPresent = [&](std::size_t i) -> llvm::Optional { + auto isPresent = [&](std::size_t i) -> std::optional { return operands[i].second; }; return Fortran::lower::lowerCustomIntrinsic( @@ -2045,7 +2045,7 @@ class ScalarExprLowering { /// Lower a non-elemental procedure reference and read allocatable and pointer /// results into normal values. ExtValue genProcedureRef(const Fortran::evaluate::ProcedureRef &procRef, - llvm::Optional resultType) { + std::optional resultType) { ExtValue res = genRawProcedureRef(procRef, resultType); // In most contexts, pointers and allocatable do not appear as allocatable // or pointer variable on the caller side (see 8.5.3 note 1 for @@ -2130,7 +2130,7 @@ class ScalarExprLowering { bool argMayBeModifiedByCall; // Optional boolean value that, if present and false, prevents // the copy-out and temp deallocation. - llvm::Optional restrictCopyAndFreeAtRuntime; + std::optional restrictCopyAndFreeAtRuntime; }; using CopyOutPairs = llvm::SmallVector; @@ -2153,7 +2153,7 @@ class ScalarExprLowering { ExtValue genCopyIn(const ExtValue &actualArg, const Fortran::lower::CallerInterface::PassedEntity &arg, CopyOutPairs ©OutPairs, - llvm::Optional restrictCopyAtRuntime, + std::optional restrictCopyAtRuntime, bool byValue) { const bool doCopyOut = !byValue && arg.mayBeModifiedByCall(); llvm::StringRef tempName = byValue ? ".copy" : ".copyinout"; @@ -2409,7 +2409,7 @@ class ScalarExprLowering { /// If the actual argument may be dynamically absent, return an additional /// boolean mlir::Value that if true means that the actual argument is /// present. - std::pair> + std::pair> prepareActualToBaseAddressLike( const Fortran::lower::SomeExpr &expr, const Fortran::lower::CallerInterface::PassedEntity &arg, @@ -2432,7 +2432,7 @@ class ScalarExprLowering { expr, converter.getFoldingContext()))); const bool needsCopy = isStaticConstantByValue || variableNeedsCopy; auto [argAddr, isPresent] = - [&]() -> std::pair> { + [&]() -> std::pair> { if (!actualArgIsVariable && !needsCopy) // Actual argument is not a variable. Make sure a variable address is // not passed. @@ -2502,7 +2502,7 @@ class ScalarExprLowering { /// Lower a non-elemental procedure reference. ExtValue genRawProcedureRef(const Fortran::evaluate::ProcedureRef &procRef, - llvm::Optional resultType) { + std::optional resultType) { mlir::Location loc = getLoc(); if (isElementalProcWithArrayArgs(procRef)) fir::emitFatalError(loc, "trying to lower elemental procedure with array " @@ -2752,7 +2752,7 @@ class ScalarExprLowering { } ExtValue genval(const Fortran::evaluate::ProcedureRef &procRef) { - llvm::Optional resTy; + std::optional resTy; if (procRef.hasAlternateReturns()) resTy = builder.getIndexType(); return genProcedureRef(procRef, resTy); @@ -3158,7 +3158,7 @@ class ArrayExprLowering { Fortran::lower::ExplicitIterSpace &explicitSpace, Fortran::lower::ImplicitIterSpace &implicitSpace, const llvm::SmallVector &lbounds, - llvm::Optional> ubounds) { + std::optional> ubounds) { ArrayExprLowering ael(converter, stmtCtx, symMap, ConstituentSemantics::CopyInCopyOut, &explicitSpace, &implicitSpace); @@ -3177,7 +3177,7 @@ class ArrayExprLowering { void lowerArrayOfPointerAssignment( const Fortran::lower::SomeExpr &lhs, const Fortran::lower::SomeExpr &rhs, const llvm::SmallVector &lbounds, - llvm::Optional> ubounds) { + std::optional> ubounds) { setPointerAssignmentBounds(lbounds, ubounds); if (rhs.Rank() == 0 || (Fortran::evaluate::UnwrapWholeSymbolOrComponentDataRef(rhs) && @@ -4418,8 +4418,8 @@ class ArrayExprLowering { // A reference to a Fortran elemental intrinsic or intrinsic module procedure. CC genElementalIntrinsicProcRef( const Fortran::evaluate::ProcedureRef &procRef, - llvm::Optional retTy, - llvm::Optional intrinsic = + std::optional retTy, + std::optional intrinsic = std::nullopt) { llvm::SmallVector operands; @@ -4431,7 +4431,7 @@ class ArrayExprLowering { mlir::Location loc = getLoc(); if (intrinsic && Fortran::lower::intrinsicRequiresCustomOptionalHandling( procRef, *intrinsic, converter)) { - using CcPairT = std::pair>; + using CcPairT = std::pair>; llvm::SmallVector operands; auto prepareOptionalArg = [&](const Fortran::lower::SomeExpr &expr) { if (expr.Rank() == 0) { @@ -4461,7 +4461,7 @@ class ArrayExprLowering { auto getArgument = [&](std::size_t i) -> ExtValue { return operands[i].first(iters); }; - auto isPresent = [&](std::size_t i) -> llvm::Optional { + auto isPresent = [&](std::size_t i) -> std::optional { return operands[i].second; }; return Fortran::lower::lowerCustomIntrinsic( @@ -4534,7 +4534,7 @@ class ArrayExprLowering { /// Lower a procedure reference to a user-defined elemental procedure. CC genElementalUserDefinedProcRef( const Fortran::evaluate::ProcedureRef &procRef, - llvm::Optional retTy) { + std::optional retTy) { using PassBy = Fortran::lower::CallerInterface::PassEntityBy; // 10.1.4 p5. Impure elemental procedures must be called in element order. @@ -4752,7 +4752,7 @@ class ArrayExprLowering { /// Generate a procedure reference. This code is shared for both functions and /// subroutines, the difference being reflected by `retTy`. CC genProcRef(const Fortran::evaluate::ProcedureRef &procRef, - llvm::Optional retTy) { + std::optional retTy) { mlir::Location loc = getLoc(); setLoweredProcRef(&procRef); @@ -6135,7 +6135,7 @@ class ArrayExprLowering { // Any temps created in the loop body must be freed inside the loop body. stmtCtx.pushScope(); - llvm::Optional charLen; + std::optional charLen; for (const Fortran::evaluate::ArrayConstructorValue &acv : x.values()) { auto [exv, copyNeeded] = std::visit( [&](const auto &v) { @@ -6219,7 +6219,7 @@ class ArrayExprLowering { mlir::Type eleRefTy = builder.getRefType(eleTy); // Populate the buffer with the elements, growing as necessary. - llvm::Optional charLen; + std::optional charLen; for (const auto &expr : x) { auto [exv, copyNeeded] = std::visit( [&](const auto &e) { @@ -6983,7 +6983,7 @@ class ArrayExprLowering { void setPointerAssignmentBounds( const llvm::SmallVector &lbs, - llvm::Optional> ubs) { + std::optional> ubs) { lbounds = lbs; ubounds = ubs; } @@ -6998,9 +6998,9 @@ class ArrayExprLowering { bool elementCtx = false; Fortran::lower::SymMap &symMap; /// The continuation to generate code to update the destination. - llvm::Optional ccStoreToDest; - llvm::Optional)>> ccPrelude; - llvm::Optional)>> + std::optional ccStoreToDest; + std::optional)>> ccPrelude; + std::optional)>> ccLoadDest; /// The destination is the loaded array into which the results will be /// merged. @@ -7016,8 +7016,8 @@ class ArrayExprLowering { ConstituentSemantics semant = ConstituentSemantics::RefTransparent; /// `lbounds`, `ubounds` are used in POINTER value assignments, which may only /// occur in an explicit iteration space. - llvm::Optional> lbounds; - llvm::Optional> ubounds; + std::optional> lbounds; + std::optional> ubounds; // Can the array expression be evaluated in any order? // Will be set to false if any of the expression parts prevent this. bool unordered = true; @@ -7125,7 +7125,7 @@ void Fortran::lower::createArrayOfPointerAssignment( Fortran::lower::ExplicitIterSpace &explicitSpace, Fortran::lower::ImplicitIterSpace &implicitSpace, const llvm::SmallVector &lbounds, - llvm::Optional> ubounds, + std::optional> ubounds, Fortran::lower::SymMap &symMap, Fortran::lower::StatementContext &stmtCtx) { LLVM_DEBUG(lhs.AsFortran(llvm::dbgs() << "defining pointer: ") << '\n'; rhs.AsFortran(llvm::dbgs() << "assign expression: ") @@ -7404,7 +7404,7 @@ void Fortran::lower::createArrayMergeStores( builder.setInsertionPointAfter(esp.getOuterLoop()); // Gen the fir.array_merge_store ops for all LHS arrays. for (auto i : llvm::enumerate(esp.getOuterLoop().getResults())) - if (llvm::Optional ldOpt = esp.getLhsLoad(i.index())) { + if (std::optional ldOpt = esp.getLhsLoad(i.index())) { fir::ArrayLoadOp load = *ldOpt; builder.create(loc, load, i.value(), load.getMemref(), load.getSlice(), diff --git a/flang/lib/Lower/ConvertExprToHLFIR.cpp b/flang/lib/Lower/ConvertExprToHLFIR.cpp index 35d4047722f36..4b1a54268d028 100644 --- a/flang/lib/Lower/ConvertExprToHLFIR.cpp +++ b/flang/lib/Lower/ConvertExprToHLFIR.cpp @@ -121,7 +121,7 @@ class HlfirDesignatorBuilder { fir::FortranVariableOpInterface gen(const Fortran::evaluate::SymbolRef &symbolRef) { - if (llvm::Optional varDef = + if (std::optional varDef = getSymMap().lookupVariableDefinition(symbolRef)) return *varDef; TODO(getLoc(), "lowering symbol to HLFIR"); diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp index b7931ae9c0080..ad586cab7c4f3 100644 --- a/flang/lib/Lower/ConvertVariable.cpp +++ b/flang/lib/Lower/ConvertVariable.cpp @@ -1281,9 +1281,9 @@ lowerExplicitCharLen(Fortran::lower::AbstractConverter &converter, return mlir::Value{}; fir::FirOpBuilder &builder = converter.getFirOpBuilder(); mlir::Type lenTy = builder.getCharacterLengthType(); - if (llvm::Optional len = box.getCharLenConst()) + if (std::optional len = box.getCharLenConst()) return builder.createIntegerConstant(loc, lenTy, *len); - if (llvm::Optional lenExpr = box.getCharLenExpr()) + if (std::optional lenExpr = box.getCharLenExpr()) // If the length expression is negative, the length is zero. See F2018 // 7.4.4.2 point 5. return fir::factory::genMaxWithZero( @@ -1703,14 +1703,14 @@ void Fortran::lower::mapSymbolAttributes( if (arg.getType().isa()) std::tie(addr, len) = charHelp.createUnboxChar(arg); } - if (llvm::Optional cstLen = ba.getCharLenConst()) { + if (std::optional cstLen = ba.getCharLenConst()) { // Static length len = builder.createIntegerConstant(loc, idxTy, *cstLen); } else { // Dynamic length if (genUnusedEntryPointBox()) return; - if (llvm::Optional charLenExpr = + if (std::optional charLenExpr = ba.getCharLenExpr()) { // Explicit length mlir::Value rawLen = genValue(*charLenExpr); diff --git a/flang/lib/Lower/CustomIntrinsicCall.cpp b/flang/lib/Lower/CustomIntrinsicCall.cpp index b4fb1463a01dd..9b35625125aaa 100644 --- a/flang/lib/Lower/CustomIntrinsicCall.cpp +++ b/flang/lib/Lower/CustomIntrinsicCall.cpp @@ -66,7 +66,7 @@ bool Fortran::lower::intrinsicRequiresCustomOptionalHandling( static void prepareMinOrMaxArguments( const Fortran::evaluate::ProcedureRef &procRef, const Fortran::evaluate::SpecificIntrinsic &intrinsic, - llvm::Optional retTy, + std::optional retTy, const Fortran::lower::OperandPrepare &prepareOptionalArgument, const Fortran::lower::OperandPrepare &prepareOtherArgument, Fortran::lower::AbstractConverter &converter) { @@ -96,7 +96,7 @@ static void prepareMinOrMaxArguments( static fir::ExtendedValue lowerMinOrMax(fir::FirOpBuilder &builder, mlir::Location loc, - llvm::StringRef name, llvm::Optional retTy, + llvm::StringRef name, std::optional retTy, const Fortran::lower::OperandPresent &isPresentCheck, const Fortran::lower::OperandGetter &getOperand, std::size_t numOperands, @@ -112,7 +112,7 @@ lowerMinOrMax(fir::FirOpBuilder &builder, mlir::Location loc, builder, loc, name, resultType, args, stmtCtx)); for (std::size_t opIndex = 2; opIndex < numOperands; ++opIndex) { - if (llvm::Optional isPresentRuntimeCheck = + if (std::optional isPresentRuntimeCheck = isPresentCheck(opIndex)) { // Argument is dynamically optional. extremum = @@ -145,7 +145,7 @@ lowerMinOrMax(fir::FirOpBuilder &builder, mlir::Location loc, static void prepareIshftcArguments( const Fortran::evaluate::ProcedureRef &procRef, const Fortran::evaluate::SpecificIntrinsic &intrinsic, - llvm::Optional retTy, + std::optional retTy, const Fortran::lower::OperandPrepare &prepareOptionalArgument, const Fortran::lower::OperandPrepare &prepareOtherArgument, Fortran::lower::AbstractConverter &converter) { @@ -167,7 +167,7 @@ static void prepareIshftcArguments( static fir::ExtendedValue lowerIshftc(fir::FirOpBuilder &builder, mlir::Location loc, - llvm::StringRef name, llvm::Optional retTy, + llvm::StringRef name, std::optional retTy, const Fortran::lower::OperandPresent &isPresentCheck, const Fortran::lower::OperandGetter &getOperand, std::size_t numOperands, @@ -205,7 +205,7 @@ lowerIshftc(fir::FirOpBuilder &builder, mlir::Location loc, void Fortran::lower::prepareCustomIntrinsicArgument( const Fortran::evaluate::ProcedureRef &procRef, const Fortran::evaluate::SpecificIntrinsic &intrinsic, - llvm::Optional retTy, + std::optional retTy, const OperandPrepare &prepareOptionalArgument, const OperandPrepare &prepareOtherArgument, AbstractConverter &converter) { llvm::StringRef name = intrinsic.name; @@ -221,7 +221,7 @@ void Fortran::lower::prepareCustomIntrinsicArgument( fir::ExtendedValue Fortran::lower::lowerCustomIntrinsic( fir::FirOpBuilder &builder, mlir::Location loc, llvm::StringRef name, - llvm::Optional retTy, const OperandPresent &isPresentCheck, + std::optional retTy, const OperandPresent &isPresentCheck, const OperandGetter &getOperand, std::size_t numOperands, Fortran::lower::StatementContext &stmtCtx) { if (name == "min" || name == "max") diff --git a/flang/lib/Lower/HostAssociations.cpp b/flang/lib/Lower/HostAssociations.cpp index 90a43bca29a87..a4ab3b905f1f6 100644 --- a/flang/lib/Lower/HostAssociations.cpp +++ b/flang/lib/Lower/HostAssociations.cpp @@ -293,7 +293,7 @@ class CapturedAllocatableAndPointer llvm::SmallVector nonDeferredLenParams; if (ba.isChar()) { mlir::IndexType idxTy = builder.getIndexType(); - if (llvm::Optional len = ba.getCharLenConst()) { + if (std::optional len = ba.getCharLenConst()) { nonDeferredLenParams.push_back( builder.createIntegerConstant(loc, idxTy, *len)); } else if (Fortran::semantics::IsAssumedLengthCharacter(sym) || diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp index d1e9af5d0d8d8..0b075cd51e0ed 100644 --- a/flang/lib/Lower/IO.cpp +++ b/flang/lib/Lower/IO.cpp @@ -114,7 +114,7 @@ namespace { /// and an IOMSG specifier variable may be set to a description of a condition. struct ConditionSpecInfo { const Fortran::lower::SomeExpr *ioStatExpr{}; - llvm::Optional ioMsg; + std::optional ioMsg; bool hasErr{}; bool hasEnd{}; bool hasEor{}; @@ -1337,7 +1337,7 @@ constexpr bool isDataTransferInternal( /// If the variable `var` is an array or of a KIND other than the default /// (normally 1), then a descriptor is required by the runtime IO API. This /// condition holds even in F77 sources. -static llvm::Optional getVariableBufferRequiredDescriptor( +static std::optional getVariableBufferRequiredDescriptor( Fortran::lower::AbstractConverter &converter, mlir::Location loc, const Fortran::parser::Variable &var, Fortran::lower::StatementContext &stmtCtx) { @@ -1354,7 +1354,7 @@ static llvm::Optional getVariableBufferRequiredDescriptor( } template -static llvm::Optional +static std::optional maybeGetInternalIODescriptor(Fortran::lower::AbstractConverter &converter, mlir::Location loc, const A &stmt, Fortran::lower::StatementContext &stmtCtx) { @@ -1367,7 +1367,7 @@ maybeGetInternalIODescriptor(Fortran::lower::AbstractConverter &converter, return std::nullopt; } template <> -inline llvm::Optional +inline std::optional maybeGetInternalIODescriptor( Fortran::lower::AbstractConverter &, mlir::Location loc, const Fortran::parser::PrintStmt &, Fortran::lower::StatementContext &) { @@ -1878,7 +1878,7 @@ void genBeginDataTransferCallArgs( const A &stmt, mlir::FunctionType ioFuncTy, bool isFormatted, bool isListOrNml, [[maybe_unused]] bool isInternal, [[maybe_unused]] bool isAsync, - const llvm::Optional &descRef, ConditionSpecInfo &csi, + const std::optional &descRef, ConditionSpecInfo &csi, Fortran::lower::StatementContext &stmtCtx) { fir::FirOpBuilder &builder = converter.getFirOpBuilder(); auto maybeGetFormatArgs = [&]() { @@ -1955,7 +1955,7 @@ genDataTransferStmt(Fortran::lower::AbstractConverter &converter, const bool isFormatted = isDataTransferFormatted(stmt); const bool isList = isFormatted ? isDataTransferList(stmt) : false; const bool isInternal = isDataTransferInternal(stmt); - llvm::Optional descRef = + std::optional descRef = isInternal ? maybeGetInternalIODescriptor(converter, loc, stmt, stmtCtx) : std::nullopt; const bool isInternalWithDesc = descRef.has_value(); diff --git a/flang/lib/Lower/IntrinsicCall.cpp b/flang/lib/Lower/IntrinsicCall.cpp index f6bc94cec47ac..1ee096f197c19 100644 --- a/flang/lib/Lower/IntrinsicCall.cpp +++ b/flang/lib/Lower/IntrinsicCall.cpp @@ -422,7 +422,7 @@ struct IntrinsicLibrary { /// Generate FIR for call to Fortran intrinsic \p name with arguments \p arg /// and expected result type \p resultType. fir::ExtendedValue genIntrinsicCall(llvm::StringRef name, - llvm::Optional resultType, + std::optional resultType, llvm::ArrayRef arg); /// Search a runtime function that is associated to the generic intrinsic name @@ -615,7 +615,7 @@ struct IntrinsicLibrary { template fir::ExtendedValue outlineInExtendedWrapper(GeneratorType, llvm::StringRef name, - llvm::Optional resultType, + std::optional resultType, llvm::ArrayRef args); template @@ -1770,7 +1770,7 @@ static void checkPrecisionLoss(llvm::StringRef name, } /// Helpers to get function type from arguments and result type. -static mlir::FunctionType getFunctionType(llvm::Optional resultType, +static mlir::FunctionType getFunctionType(std::optional resultType, llvm::ArrayRef arguments, fir::FirOpBuilder &builder) { llvm::SmallVector argTypes; @@ -1921,7 +1921,7 @@ IntrinsicLibrary::genElementalCall( static fir::ExtendedValue invokeHandler(IntrinsicLibrary::ElementalGenerator generator, const IntrinsicHandler &handler, - llvm::Optional resultType, + std::optional resultType, llvm::ArrayRef args, bool outline, IntrinsicLibrary &lib) { assert(resultType && "expect elemental intrinsic to be functions"); @@ -1932,7 +1932,7 @@ invokeHandler(IntrinsicLibrary::ElementalGenerator generator, static fir::ExtendedValue invokeHandler(IntrinsicLibrary::ExtendedGenerator generator, const IntrinsicHandler &handler, - llvm::Optional resultType, + std::optional resultType, llvm::ArrayRef args, bool outline, IntrinsicLibrary &lib) { assert(resultType && "expect intrinsic function"); @@ -1948,7 +1948,7 @@ invokeHandler(IntrinsicLibrary::ExtendedGenerator generator, static fir::ExtendedValue invokeHandler(IntrinsicLibrary::SubroutineGenerator generator, const IntrinsicHandler &handler, - llvm::Optional resultType, + std::optional resultType, llvm::ArrayRef args, bool outline, IntrinsicLibrary &lib) { if (handler.isElemental) @@ -1963,7 +1963,7 @@ invokeHandler(IntrinsicLibrary::SubroutineGenerator generator, fir::ExtendedValue IntrinsicLibrary::genIntrinsicCall(llvm::StringRef specificName, - llvm::Optional resultType, + std::optional resultType, llvm::ArrayRef args) { llvm::StringRef name = genericName(specificName); if (const IntrinsicHandler *handler = findIntrinsicHandler(name)) { @@ -2133,7 +2133,7 @@ IntrinsicLibrary::outlineInWrapper(GeneratorType generator, template fir::ExtendedValue IntrinsicLibrary::outlineInExtendedWrapper( GeneratorType generator, llvm::StringRef name, - llvm::Optional resultType, + std::optional resultType, llvm::ArrayRef args) { if (hasAbsentOptional(args)) TODO(loc, "cannot outline call to intrinsic " + llvm::Twine(name) + @@ -3108,7 +3108,7 @@ IntrinsicLibrary::genCshift(mlir::Type resultType, // DATE_AND_TIME void IntrinsicLibrary::genDateAndTime(llvm::ArrayRef args) { assert(args.size() == 4 && "date_and_time has 4 args"); - llvm::SmallVector> charArgs(3); + llvm::SmallVector> charArgs(3); for (unsigned i = 0; i < 3; ++i) if (const fir::CharBoxValue *charBox = args[i].getCharBox()) charArgs[i] = *charBox; @@ -5323,7 +5323,7 @@ Fortran::lower::ArgLoweringRule Fortran::lower::lowerIntrinsicArgumentAs( fir::ExtendedValue Fortran::lower::genIntrinsicCall(fir::FirOpBuilder &builder, mlir::Location loc, llvm::StringRef name, - llvm::Optional resultType, + std::optional resultType, llvm::ArrayRef args, Fortran::lower::StatementContext &stmtCtx) { return IntrinsicLibrary{builder, loc, &stmtCtx}.genIntrinsicCall( diff --git a/flang/lib/Lower/IterationSpace.cpp b/flang/lib/Lower/IterationSpace.cpp index c41aa0ef0eecd..dab15f301081c 100644 --- a/flang/lib/Lower/IterationSpace.cpp +++ b/flang/lib/Lower/IterationSpace.cpp @@ -861,11 +861,11 @@ void Fortran::lower::ExplicitIterSpace::conditionalCleanup() { } } -llvm::Optional +std::optional Fortran::lower::ExplicitIterSpace::findArgPosition(fir::ArrayLoadOp load) { if (lhsBases[counter]) { auto ld = loadBindings.find(*lhsBases[counter]); - llvm::Optional optPos; + std::optional optPos; if (ld != loadBindings.end() && ld->second == load) optPos = static_cast(0u); assert(optPos.has_value() && "load does not correspond to lhs"); @@ -918,7 +918,7 @@ Fortran::lower::operator<<(llvm::raw_ostream &s, u); }; s << "LHS bases:\n"; - for (const llvm::Optional &u : + for (const std::optional &u : e.lhsBases) if (u) dump(*u); diff --git a/flang/lib/Lower/Mangler.cpp b/flang/lib/Lower/Mangler.cpp index 0aec674411559..b4030a05e7697 100644 --- a/flang/lib/Lower/Mangler.cpp +++ b/flang/lib/Lower/Mangler.cpp @@ -40,7 +40,7 @@ moduleNames(const Fortran::semantics::Symbol &symbol) { return result; } -static llvm::Optional +static std::optional hostName(const Fortran::semantics::Symbol &symbol) { const Fortran::semantics::Scope &scope = symbol.owner(); if (scope.kind() == Fortran::semantics::Scope::Kind::Subprogram) { @@ -120,7 +120,7 @@ Fortran::lower::mangle::mangleName(const Fortran::semantics::Symbol &symbol, [&](const Fortran::semantics::ObjectEntityDetails &) { llvm::SmallVector modNames = moduleNames(ultimateSymbol); - llvm::Optional optHost = hostName(ultimateSymbol); + std::optional optHost = hostName(ultimateSymbol); if (Fortran::semantics::IsNamedConstant(ultimateSymbol)) return fir::NameUniquer::doConstant(modNames, optHost, symbolName); @@ -129,7 +129,7 @@ Fortran::lower::mangle::mangleName(const Fortran::semantics::Symbol &symbol, [&](const Fortran::semantics::NamelistDetails &) { llvm::SmallVector modNames = moduleNames(ultimateSymbol); - llvm::Optional optHost = hostName(ultimateSymbol); + std::optional optHost = hostName(ultimateSymbol); return fir::NameUniquer::doNamelistGroup(modNames, optHost, symbolName); }, @@ -158,7 +158,7 @@ std::string Fortran::lower::mangle::mangleName( derivedType.typeSymbol().GetUltimate(); llvm::StringRef symbolName = toStringRef(ultimateSymbol.name()); llvm::SmallVector modNames = moduleNames(ultimateSymbol); - llvm::Optional optHost = hostName(ultimateSymbol); + std::optional optHost = hostName(ultimateSymbol); llvm::SmallVector kinds; for (const auto ¶m : Fortran::semantics::OrderParameterDeclarations(ultimateSymbol)) { diff --git a/flang/lib/Lower/Runtime.cpp b/flang/lib/Lower/Runtime.cpp index e0dfdf5696a81..e68b1318b15cc 100644 --- a/flang/lib/Lower/Runtime.cpp +++ b/flang/lib/Lower/Runtime.cpp @@ -227,17 +227,17 @@ mlir::Value Fortran::lower::genCpuTime(fir::FirOpBuilder &builder, void Fortran::lower::genDateAndTime(fir::FirOpBuilder &builder, mlir::Location loc, - llvm::Optional date, - llvm::Optional time, - llvm::Optional zone, + std::optional date, + std::optional time, + std::optional zone, mlir::Value values) { mlir::func::FuncOp callee = fir::runtime::getRuntimeFunc(loc, builder); mlir::FunctionType funcTy = callee.getFunctionType(); mlir::Type idxTy = builder.getIndexType(); mlir::Value zero; - auto splitArg = [&](llvm::Optional arg, - mlir::Value &buffer, mlir::Value &len) { + auto splitArg = [&](std::optional arg, mlir::Value &buffer, + mlir::Value &len) { if (arg) { buffer = arg->getBuffer(); len = arg->getLen(); diff --git a/flang/lib/Lower/SymbolMap.cpp b/flang/lib/Lower/SymbolMap.cpp index ff0c75f12db25..f61071150df87 100644 --- a/flang/lib/Lower/SymbolMap.cpp +++ b/flang/lib/Lower/SymbolMap.cpp @@ -92,7 +92,7 @@ Fortran::lower::SymMap::lookupImpliedDo(Fortran::lower::SymMap::AcDoVar var) { return {}; } -llvm::Optional +std::optional Fortran::lower::SymMap::lookupVariableDefinition(semantics::SymbolRef symRef) { Fortran::semantics::SymbolRef sym = symRef.get().GetUltimate(); for (auto jmap = symbolMapStack.rbegin(), jend = symbolMapStack.rend(); diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp index a82c218f49644..0c5bf47e2978a 100644 --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -1139,7 +1139,7 @@ static void genComponentByComponentAssignment(fir::FirOpBuilder &builder, auto fieldRefType = builder.getRefType(lFieldTy); mlir::Value toCoor = builder.create( loc, fieldRefType, fir::getBase(lhs), field); - llvm::Optional outerLoop; + std::optional outerLoop; if (auto sequenceType = lFieldTy.dyn_cast()) { // Create loops to assign array components elements by elements. // Note that, since these are components, they either do not overlap, @@ -1331,11 +1331,11 @@ mlir::Value fir::factory::createZeroValue(fir::FirOpBuilder &builder, "numeric or logical type"); } -llvm::Optional +std::optional fir::factory::getExtentFromTriplet(mlir::Value lb, mlir::Value ub, mlir::Value stride) { - std::function(mlir::Value)> getConstantValue = - [&](mlir::Value value) -> llvm::Optional { + std::function(mlir::Value)> getConstantValue = + [&](mlir::Value value) -> std::optional { if (auto valInt = fir::getIntIfConstant(value)) return *valInt; auto *definingOp = value.getDefiningOp(); diff --git a/flang/lib/Optimizer/Builder/HLFIRTools.cpp b/flang/lib/Optimizer/Builder/HLFIRTools.cpp index 818347e375eb0..fb018c740590a 100644 --- a/flang/lib/Optimizer/Builder/HLFIRTools.cpp +++ b/flang/lib/Optimizer/Builder/HLFIRTools.cpp @@ -70,7 +70,7 @@ getExplicitTypeParams(fir::FortranVariableOpInterface var) { return res; } -std::pair> +std::pair> hlfir::translateToExtendedValue(mlir::Location loc, fir::FirOpBuilder &builder, hlfir::Entity entity) { if (auto variable = entity.getIfVariableInterface()) diff --git a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp index b19bb5efb0851..223a8bc11aa9b 100644 --- a/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp +++ b/flang/lib/Optimizer/CodeGen/TargetRewrite.cpp @@ -65,7 +65,7 @@ struct FixupTy { Codes code; std::size_t index; std::size_t second{}; - llvm::Optional> finalizer{}; + std::optional> finalizer{}; }; // namespace /// Target-specific rewriting of the FIR. This is a prerequisite pass to code @@ -215,7 +215,7 @@ class TargetRewrite : public fir::impl::TargetRewritePassBase { } // Determine the rewrite function, `wrap`, for the result value. - llvm::Optional> wrap; + std::optional> wrap; if (fnTy.getResults().size() == 1) { mlir::Type ty = fnTy.getResult(0); llvm::TypeSwitch(ty) diff --git a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp index 2111f502aa3d8..6c0077713861b 100644 --- a/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp +++ b/flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp @@ -363,7 +363,7 @@ static unsigned getCharacterKind(mlir::Type t) { return hlfir::getFortranElementType(t).cast().getFKind(); } -static llvm::Optional +static std::optional getCharacterLengthIfStatic(mlir::Type t) { if (auto charType = hlfir::getFortranElementType(t).dyn_cast()) diff --git a/flang/lib/Optimizer/Support/InternalNames.cpp b/flang/lib/Optimizer/Support/InternalNames.cpp index 3c455e1bc57ef..29596998bc0c4 100644 --- a/flang/lib/Optimizer/Support/InternalNames.cpp +++ b/flang/lib/Optimizer/Support/InternalNames.cpp @@ -37,7 +37,7 @@ static std::string doModules(llvm::ArrayRef mods) { } static std::string doModulesHost(llvm::ArrayRef mods, - llvm::Optional host) { + std::optional host) { std::string result = doModules(mods); if (host) result.append("F").append(host->lower()); @@ -49,9 +49,9 @@ convertToStringRef(llvm::ArrayRef from) { return {from.begin(), from.end()}; } -inline llvm::Optional -convertToStringRef(const llvm::Optional &from) { - llvm::Optional to; +inline std::optional +convertToStringRef(const std::optional &from) { + std::optional to; if (from) to = *from; return to; @@ -111,7 +111,7 @@ std::string fir::NameUniquer::doBlockData(llvm::StringRef name) { std::string fir::NameUniquer::doConstant(llvm::ArrayRef modules, - llvm::Optional host, + std::optional host, llvm::StringRef name) { std::string result = prefix(); result.append(doModulesHost(modules, host)).append("EC"); @@ -120,7 +120,7 @@ fir::NameUniquer::doConstant(llvm::ArrayRef modules, std::string fir::NameUniquer::doDispatchTable(llvm::ArrayRef modules, - llvm::Optional host, + std::optional host, llvm::StringRef name, llvm::ArrayRef kinds) { std::string result = prefix(); @@ -135,7 +135,7 @@ std::string fir::NameUniquer::doGenerated(llvm::StringRef name) { std::string fir::NameUniquer::doIntrinsicTypeDescriptor( llvm::ArrayRef modules, - llvm::Optional host, IntrinsicType type, + std::optional host, IntrinsicType type, std::int64_t kind) { const char *name = nullptr; switch (type) { @@ -163,7 +163,7 @@ std::string fir::NameUniquer::doIntrinsicTypeDescriptor( std::string fir::NameUniquer::doProcedure(llvm::ArrayRef modules, - llvm::Optional host, + std::optional host, llvm::StringRef name) { std::string result = prefix(); result.append(doModulesHost(modules, host)).append("P"); @@ -171,7 +171,7 @@ fir::NameUniquer::doProcedure(llvm::ArrayRef modules, } std::string fir::NameUniquer::doType(llvm::ArrayRef modules, - llvm::Optional host, + std::optional host, llvm::StringRef name, llvm::ArrayRef kinds) { std::string result = prefix(); @@ -181,7 +181,7 @@ std::string fir::NameUniquer::doType(llvm::ArrayRef modules, std::string fir::NameUniquer::doTypeDescriptor(llvm::ArrayRef modules, - llvm::Optional host, + std::optional host, llvm::StringRef name, llvm::ArrayRef kinds) { std::string result = prefix(); @@ -190,7 +190,7 @@ fir::NameUniquer::doTypeDescriptor(llvm::ArrayRef modules, } std::string fir::NameUniquer::doTypeDescriptor( - llvm::ArrayRef modules, llvm::Optional host, + llvm::ArrayRef modules, std::optional host, llvm::StringRef name, llvm::ArrayRef kinds) { auto rmodules = convertToStringRef(modules); auto rhost = convertToStringRef(host); @@ -199,7 +199,7 @@ std::string fir::NameUniquer::doTypeDescriptor( std::string fir::NameUniquer::doVariable(llvm::ArrayRef modules, - llvm::Optional host, + std::optional host, llvm::StringRef name) { std::string result = prefix(); result.append(doModulesHost(modules, host)).append("E"); @@ -208,7 +208,7 @@ fir::NameUniquer::doVariable(llvm::ArrayRef modules, std::string fir::NameUniquer::doNamelistGroup(llvm::ArrayRef modules, - llvm::Optional host, + std::optional host, llvm::StringRef name) { std::string result = prefix(); result.append(doModulesHost(modules, host)).append("G"); @@ -225,7 +225,7 @@ std::pair fir::NameUniquer::deconstruct(llvm::StringRef uniq) { if (uniq.startswith("_Q")) { llvm::SmallVector modules; - llvm::Optional host; + std::optional host; std::string name; llvm::SmallVector kinds; NameKind nk = NameKind::NOT_UNIQUED; @@ -348,7 +348,7 @@ static std::string getDerivedTypeObjectName(llvm::StringRef mangledTypeName, llvm::SmallVector modules; for (const std::string &mod : result.second.modules) modules.push_back(mod); - llvm::Optional host; + std::optional host; if (result.second.host) host = *result.second.host; return fir::NameUniquer::doVariable(modules, host, varName); diff --git a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp index 998b063f7d1a2..9fde5652c828d 100644 --- a/flang/lib/Optimizer/Transforms/AffinePromotion.cpp +++ b/flang/lib/Optimizer/Transforms/AffinePromotion.cpp @@ -169,7 +169,7 @@ namespace { /// final number of symbols and dimensions of the affine map. Integer set if /// possible is in Optional IntegerSet. struct AffineIfCondition { - using MaybeAffineExpr = llvm::Optional; + using MaybeAffineExpr = std::optional; explicit AffineIfCondition(mlir::Value fc) : firCondition(fc) { if (auto condDef = firCondition.getDefiningOp()) @@ -248,7 +248,7 @@ struct AffineIfCondition { dimCount, symCount, {constraintPair->first}, {constraintPair->second}); } - llvm::Optional> + std::optional> constraint(mlir::arith::CmpIPredicate predicate, mlir::AffineExpr basic) { switch (predicate) { case mlir::arith::CmpIPredicate::slt: @@ -267,7 +267,7 @@ struct AffineIfCondition { } llvm::SmallVector affineArgs; - llvm::Optional integerSet; + std::optional integerSet; mlir::Value firCondition; unsigned symCount{0u}; unsigned dimCount{0u}; @@ -330,7 +330,7 @@ static mlir::AffineMap createArrayIndexAffineMap(unsigned dimensions, return mlir::AffineMap::get(dimensions, dimensions * 3, index); } -static Optional constantIntegerLike(const mlir::Value value) { +static std::optional constantIntegerLike(const mlir::Value value) { if (auto definition = value.getDefiningOp()) if (auto stepAttr = definition.getValue().dyn_cast()) return stepAttr.getInt(); diff --git a/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp b/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp index 51e8561dee380..9aad37062ad0d 100644 --- a/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp +++ b/flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp @@ -48,8 +48,8 @@ class LoadStoreForwarding { // FIXME: This algorithm has a bug. It ignores escaping references between a // store and a load. - llvm::Optional findStoreToForward(ReadOp loadOp, - std::vector &&storeOps) { + std::optional findStoreToForward(ReadOp loadOp, + std::vector &&storeOps) { llvm::SmallVector candidateSet; for (auto storeOp : storeOps) @@ -59,7 +59,7 @@ class LoadStoreForwarding { if (candidateSet.empty()) return {}; - llvm::Optional nearestStore; + std::optional nearestStore; for (auto candidate : candidateSet) { auto nearerThan = [&](WriteOp otherStore) { if (candidate == otherStore) @@ -86,8 +86,8 @@ class LoadStoreForwarding { return nearestStore; } - llvm::Optional findReadForWrite(WriteOp storeOp, - std::vector &&loadOps) { + std::optional findReadForWrite(WriteOp storeOp, + std::vector &&loadOps) { for (auto &loadOp : loadOps) { if (domInfo->dominates(storeOp, loadOp)) return loadOp; diff --git a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp index 5628f0c7999df..05ddcfe1abc94 100644 --- a/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp +++ b/flang/lib/Optimizer/Transforms/SimplifyIntrinsics.cpp @@ -510,7 +510,7 @@ static unsigned getDimCount(mlir::Value val) { /// be reliably found. /// We expect that the argument is a result of fir.convert /// with the destination type of !fir.box. -static llvm::Optional getArgElementType(mlir::Value val) { +static std::optional getArgElementType(mlir::Value val) { mlir::Operation *defOp; do { defOp = val.getDefiningOp();