diff --git a/llvm/include/llvm/Transforms/Scalar/Float2Int.h b/llvm/include/llvm/Transforms/Scalar/Float2Int.h index f4bec228ea9633..4da07663e760c1 100644 --- a/llvm/include/llvm/Transforms/Scalar/Float2Int.h +++ b/llvm/include/llvm/Transforms/Scalar/Float2Int.h @@ -42,7 +42,7 @@ class Float2IntPass : public PassInfoMixin { ConstantRange badRange(); ConstantRange unknownRange(); ConstantRange validateRange(ConstantRange R); - Optional calcRange(Instruction *I); + std::optional calcRange(Instruction *I); void walkBackwards(); void walkForwards(); bool validateAndTransform(); diff --git a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h index d8caa99ea0bad3..b996e9e3613efc 100644 --- a/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h +++ b/llvm/include/llvm/Transforms/Scalar/LoopPassManager.h @@ -188,7 +188,7 @@ class PassManager - Optional + std::optional runSinglePass(IRUnitT &IR, PassT &Pass, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U, PassInstrumentation &PI); @@ -394,7 +394,7 @@ class LPMUpdater { }; template -Optional LoopPassManager::runSinglePass( +std::optional LoopPassManager::runSinglePass( IRUnitT &IR, PassT &Pass, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR, LPMUpdater &U, PassInstrumentation &PI) { // Get the loop in case of Loop pass and outermost loop in case of LoopNest diff --git a/llvm/include/llvm/Transforms/Scalar/Scalarizer.h b/llvm/include/llvm/Transforms/Scalar/Scalarizer.h index 5cc67f78e5a20b..80c3f187be8cd8 100644 --- a/llvm/include/llvm/Transforms/Scalar/Scalarizer.h +++ b/llvm/include/llvm/Transforms/Scalar/Scalarizer.h @@ -17,8 +17,8 @@ #ifndef LLVM_TRANSFORMS_SCALAR_SCALARIZER_H #define LLVM_TRANSFORMS_SCALAR_SCALARIZER_H -#include "llvm/ADT/Optional.h" #include "llvm/IR/PassManager.h" +#include namespace llvm { @@ -30,8 +30,8 @@ struct ScalarizerPassOptions { // Scalarizer.cpp. When the cl::opt are specified, they take precedence. // When the cl::opt are not specified, the present optional booleans allow to // override the cl::opt's default values. - llvm::Optional ScalarizeVariableInsertExtract; - llvm::Optional ScalarizeLoadStore; + std::optional ScalarizeVariableInsertExtract; + std::optional ScalarizeLoadStore; }; class ScalarizerPass : public PassInfoMixin { diff --git a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp index 09f11464b01447..a8b37e48d272e0 100644 --- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp +++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp @@ -35,7 +35,6 @@ #include "llvm/Transforms/Scalar/ConstantHoisting.h" #include "llvm/ADT/APInt.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/Statistic.h" @@ -532,8 +531,9 @@ void ConstantHoistingPass::collectConstantCandidates(Function &Fn) { // bit widths (APInt Operator- does not like that). If the value cannot be // represented in uint64 we return an "empty" APInt. This is then interpreted // as the value is not in range. -static Optional calculateOffsetDiff(const APInt &V1, const APInt &V2) { - Optional Res; +static std::optional calculateOffsetDiff(const APInt &V1, + const APInt &V2) { + std::optional Res; unsigned BW = V1.getBitWidth() > V2.getBitWidth() ? V1.getBitWidth() : V2.getBitWidth(); uint64_t LimVal1 = V1.getLimitedValue(); @@ -605,9 +605,8 @@ ConstantHoistingPass::maximizeConstantsInRange(ConstCandVecType::iterator S, LLVM_DEBUG(dbgs() << "Cost: " << Cost << "\n"); for (auto C2 = S; C2 != E; ++C2) { - Optional Diff = calculateOffsetDiff( - C2->ConstInt->getValue(), - ConstCand->ConstInt->getValue()); + std::optional Diff = calculateOffsetDiff( + C2->ConstInt->getValue(), ConstCand->ConstInt->getValue()); if (Diff) { const InstructionCost ImmCosts = TTI->getIntImmCodeSizeCost(Opcode, OpndIdx, Diff.value(), Ty); diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 5df5af9ba364da..777fd5dc64242f 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -1296,7 +1296,7 @@ struct DSEState { // there is no such MemoryDef, return std::nullopt. The returned value may not // (completely) overwrite \p KillingLoc. Currently we bail out when we // encounter an aliasing MemoryUse (read). - Optional + std::optional getDomMemoryDef(MemoryDef *KillingDef, MemoryAccess *StartAccess, const MemoryLocation &KillingLoc, const Value *KillingUndObj, unsigned &ScanLimit, unsigned &WalkerStepLimit, @@ -2082,7 +2082,7 @@ static bool eliminateDeadStores(Function &F, AliasAnalysis &AA, MemorySSA &MSSA, if (State.SkipStores.count(Current)) continue; - Optional MaybeDeadAccess = State.getDomMemoryDef( + std::optional MaybeDeadAccess = State.getDomMemoryDef( KillingDef, Current, KillingLoc, KillingUndObj, ScanLimit, WalkerStepLimit, IsMemTerm, PartialLimit); diff --git a/llvm/lib/Transforms/Scalar/Float2Int.cpp b/llvm/lib/Transforms/Scalar/Float2Int.cpp index 30967cc5efa9d7..f66d1b914b0b99 100644 --- a/llvm/lib/Transforms/Scalar/Float2Int.cpp +++ b/llvm/lib/Transforms/Scalar/Float2Int.cpp @@ -236,7 +236,7 @@ void Float2IntPass::walkBackwards() { // Calculate result range from operand ranges. // Return std::nullopt if the range cannot be calculated yet. -Optional Float2IntPass::calcRange(Instruction *I) { +std::optional Float2IntPass::calcRange(Instruction *I) { SmallVector OpRanges; for (Value *O : I->operands()) { if (Instruction *OI = dyn_cast(O)) { @@ -335,7 +335,7 @@ void Float2IntPass::walkForwards() { Instruction *I = Worklist.back(); Worklist.pop_back(); - if (Optional Range = calcRange(I)) + if (std::optional Range = calcRange(I)) seen(I, *Range); else Worklist.push_front(I); // Reprocess later. diff --git a/llvm/lib/Transforms/Scalar/GVNSink.cpp b/llvm/lib/Transforms/Scalar/GVNSink.cpp index 69cffdbff549b1..6e3328e67387fa 100644 --- a/llvm/lib/Transforms/Scalar/GVNSink.cpp +++ b/llvm/lib/Transforms/Scalar/GVNSink.cpp @@ -599,7 +599,7 @@ class GVNSink { /// The main heuristic function. Analyze the set of instructions pointed to by /// LRI and return a candidate solution if these instructions can be sunk, or /// std::nullopt otherwise. - Optional analyzeInstructionForSinking( + std::optional analyzeInstructionForSinking( LockstepReverseIterator &LRI, unsigned &InstNum, unsigned &MemoryInstNum, ModelledPHISet &NeededPHIs, SmallPtrSetImpl &PHIContents); @@ -639,9 +639,12 @@ class GVNSink { } }; -Optional GVNSink::analyzeInstructionForSinking( - LockstepReverseIterator &LRI, unsigned &InstNum, unsigned &MemoryInstNum, - ModelledPHISet &NeededPHIs, SmallPtrSetImpl &PHIContents) { +std::optional +GVNSink::analyzeInstructionForSinking(LockstepReverseIterator &LRI, + unsigned &InstNum, + unsigned &MemoryInstNum, + ModelledPHISet &NeededPHIs, + SmallPtrSetImpl &PHIContents) { auto Insts = *LRI; LLVM_DEBUG(dbgs() << " -- Analyzing instruction set: [\n"; for (auto *I : Insts) { diff --git a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp index 973e3b4d708c8f..055cfddcd4cc7e 100644 --- a/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp +++ b/llvm/lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp @@ -211,9 +211,9 @@ class InductiveRangeCheck { /// Computes a range for the induction variable (IndVar) in which the range /// check is redundant and can be constant-folded away. The induction /// variable is not required to be the canonical {0,+,1} induction variable. - Optional computeSafeIterationSpace(ScalarEvolution &SE, - const SCEVAddRecExpr *IndVar, - bool IsLatchSigned) const; + std::optional computeSafeIterationSpace(ScalarEvolution &SE, + const SCEVAddRecExpr *IndVar, + bool IsLatchSigned) const; /// Parse out a set of inductive range checks from \p BI and append them to \p /// Checks. @@ -503,8 +503,8 @@ struct LoopStructure { return Result; } - static Optional parseLoopStructure(ScalarEvolution &, Loop &, - const char *&); + static std::optional parseLoopStructure(ScalarEvolution &, + Loop &, const char *&); }; /// This class is used to constrain loops to run within a given iteration space. @@ -554,7 +554,7 @@ class LoopConstrainer { // Compute a safe set of limits for the main loop to run in -- effectively the // intersection of `Range' and the iteration space of the original loop. // Return std::nullopt if unable to compute the set of subranges. - Optional calculateSubRanges(bool IsSignedPredicate) const; + std::optional calculateSubRanges(bool IsSignedPredicate) const; // Clone `OriginalLoop' and return the result in CLResult. The IR after // running `cloneLoop' is well formed except for the PHI nodes in CLResult -- @@ -747,7 +747,7 @@ static bool isSafeIncreasingBound(const SCEV *Start, SE.isLoopEntryGuardedByCond(L, BoundPred, BoundSCEV, Limit)); } -Optional +std::optional LoopStructure::parseLoopStructure(ScalarEvolution &SE, Loop &L, const char *&FailureReason) { if (!L.isLoopSimplifyForm()) { @@ -1061,7 +1061,7 @@ static const SCEV *NoopOrExtend(const SCEV *S, Type *Ty, ScalarEvolution &SE, return Signed ? SE.getNoopOrSignExtend(S, Ty) : SE.getNoopOrZeroExtend(S, Ty); } -Optional +std::optional LoopConstrainer::calculateSubRanges(bool IsSignedPredicate) const { IntegerType *Ty = cast(LatchTakenCount->getType()); @@ -1413,7 +1413,7 @@ bool LoopConstrainer::run() { MainLoopPreheader = Preheader; bool IsSignedPredicate = MainLoopStructure.IsSignedPredicate; - Optional MaybeSR = calculateSubRanges(IsSignedPredicate); + std::optional MaybeSR = calculateSubRanges(IsSignedPredicate); if (!MaybeSR) { LLVM_DEBUG(dbgs() << "irce: could not compute subranges\n"); return false; @@ -1428,7 +1428,7 @@ bool LoopConstrainer::run() { Instruction *InsertPt = OriginalPreheader->getTerminator(); // It would have been better to make `PreLoop' and `PostLoop' - // `Optional's, but `ValueToValueMapTy' does not have a copy + // `std::optional's, but `ValueToValueMapTy' does not have a copy // constructor. ClonedLoop PreLoop, PostLoop; bool NeedsPreLoop = @@ -1581,10 +1581,10 @@ bool LoopConstrainer::run() { /// Computes and returns a range of values for the induction variable (IndVar) /// in which the range check can be safely elided. If it cannot compute such a /// range, returns std::nullopt. -Optional -InductiveRangeCheck::computeSafeIterationSpace( - ScalarEvolution &SE, const SCEVAddRecExpr *IndVar, - bool IsLatchSigned) const { +std::optional +InductiveRangeCheck::computeSafeIterationSpace(ScalarEvolution &SE, + const SCEVAddRecExpr *IndVar, + bool IsLatchSigned) const { // We can deal when types of latch check and range checks don't match in case // if latch check is more narrow. auto *IVType = dyn_cast(IndVar->getType()); @@ -1710,9 +1710,9 @@ InductiveRangeCheck::computeSafeIterationSpace( return InductiveRangeCheck::Range(Begin, End); } -static Optional +static std::optional IntersectSignedRange(ScalarEvolution &SE, - const Optional &R1, + const std::optional &R1, const InductiveRangeCheck::Range &R2) { if (R2.isEmpty(SE, /* IsSigned */ true)) return std::nullopt; @@ -1739,9 +1739,9 @@ IntersectSignedRange(ScalarEvolution &SE, return Ret; } -static Optional +static std::optional IntersectUnsignedRange(ScalarEvolution &SE, - const Optional &R1, + const std::optional &R1, const InductiveRangeCheck::Range &R2) { if (R2.isEmpty(SE, /* IsSigned */ false)) return std::nullopt; @@ -1928,7 +1928,7 @@ bool InductiveRangeCheckElimination::run( PrintRecognizedRangeChecks(errs()); const char *FailureReason = nullptr; - Optional MaybeLoopStructure = + std::optional MaybeLoopStructure = LoopStructure::parseLoopStructure(SE, *L, FailureReason); if (!MaybeLoopStructure) { LLVM_DEBUG(dbgs() << "irce: could not parse loop structure: " @@ -1941,7 +1941,7 @@ bool InductiveRangeCheckElimination::run( const SCEVAddRecExpr *IndVar = cast(SE.getMinusSCEV(SE.getSCEV(LS.IndVarBase), SE.getSCEV(LS.IndVarStep))); - Optional SafeIterRange; + std::optional SafeIterRange; Instruction *ExprInsertPt = Preheader->getTerminator(); SmallVector RangeChecksToEliminate; diff --git a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp index 7a2a34a8d595fc..13f26ed0f8c115 100644 --- a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp @@ -892,7 +892,7 @@ class LoopDistributeForLoop { /// If the optional has a value, it indicates whether distribution was forced /// to be enabled (true) or disabled (false). If the optional has no value /// distribution was not forced either way. - const Optional &isForced() const { return IsForced; } + const std::optional &isForced() const { return IsForced; } private: /// Filter out checks between pointers from the same partition. @@ -963,7 +963,7 @@ class LoopDistributeForLoop { /// If the optional has a value, it indicates whether distribution was forced /// to be enabled (true) or disabled (false). If the optional has no value /// distribution was not forced either way. - Optional IsForced; + std::optional IsForced; }; } // end anonymous namespace diff --git a/llvm/lib/Transforms/Scalar/LoopFuse.cpp b/llvm/lib/Transforms/Scalar/LoopFuse.cpp index 5f64260bf0b8dd..6a4a6ee9aa3c52 100644 --- a/llvm/lib/Transforms/Scalar/LoopFuse.cpp +++ b/llvm/lib/Transforms/Scalar/LoopFuse.cpp @@ -701,7 +701,7 @@ struct LoopFuser { /// have the same TripCount. The second is the difference in the two /// TripCounts. This information can be used later to determine whether or not /// peeling can be performed on either one of the candidates. - std::pair> + std::pair> haveIdenticalTripCounts(const FusionCandidate &FC0, const FusionCandidate &FC1) const { const SCEV *TripCount0 = SE.getBackedgeTakenCount(FC0.L); @@ -743,7 +743,7 @@ struct LoopFuser { return {false, std::nullopt}; } - Optional Difference; + std::optional Difference; int Diff = TC0 - TC1; if (Diff > 0) @@ -860,10 +860,10 @@ struct LoopFuser { // the loops (second value of pair). The difference is not equal to // None iff the loops iterate a constant number of times, and have a // single exit. - std::pair> IdenticalTripCountRes = + std::pair> IdenticalTripCountRes = haveIdenticalTripCounts(*FC0, *FC1); bool SameTripCount = IdenticalTripCountRes.first; - Optional TCDifference = IdenticalTripCountRes.second; + std::optional TCDifference = IdenticalTripCountRes.second; // Here we are checking that FC0 (the first loop) can be peeled, and // both loops have different tripcounts. diff --git a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp index e701ce560a1a30..fadd0707d66be1 100644 --- a/llvm/lib/Transforms/Scalar/LoopPassManager.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPassManager.cpp @@ -87,7 +87,7 @@ LoopPassManager::runWithLoopNestPasses(Loop &L, LoopAnalysisManager &AM, Loop *OuterMostLoop = &L; for (size_t I = 0, E = IsLoopNestPass.size(); I != E; ++I) { - Optional PassPA; + std::optional PassPA; if (!IsLoopNestPass[I]) { // The `I`-th pass is a loop pass. auto &Pass = LoopPasses[LoopPassIndex++]; @@ -157,7 +157,8 @@ LoopPassManager::runWithoutLoopNestPasses(Loop &L, LoopAnalysisManager &AM, // instrumenting callbacks for the passes later. PassInstrumentation PI = AM.getResult(L, AR); for (auto &Pass : LoopPasses) { - Optional PassPA = runSinglePass(L, Pass, AM, AR, U, PI); + std::optional PassPA = + runSinglePass(L, Pass, AM, AR, U, PI); // `PassPA` is `None` means that the before-pass callbacks in // `PassInstrumentation` return false. The pass does not run in this case, diff --git a/llvm/lib/Transforms/Scalar/LoopPredication.cpp b/llvm/lib/Transforms/Scalar/LoopPredication.cpp index 054674d0ba0b01..0492ed5cdb1cad 100644 --- a/llvm/lib/Transforms/Scalar/LoopPredication.cpp +++ b/llvm/lib/Transforms/Scalar/LoopPredication.cpp @@ -271,8 +271,8 @@ class LoopPredication { LoopICmp LatchCheck; bool isSupportedStep(const SCEV* Step); - Optional parseLoopICmp(ICmpInst *ICI); - Optional parseLoopLatchICmp(); + std::optional parseLoopICmp(ICmpInst *ICI); + std::optional parseLoopLatchICmp(); /// Return an insertion point suitable for inserting a safe to speculate /// instruction whose only user will be 'User' which has operands 'Ops'. A @@ -295,16 +295,17 @@ class LoopPredication { ICmpInst::Predicate Pred, const SCEV *LHS, const SCEV *RHS); - Optional widenICmpRangeCheck(ICmpInst *ICI, SCEVExpander &Expander, - Instruction *Guard); - Optional widenICmpRangeCheckIncrementingLoop(LoopICmp LatchCheck, - LoopICmp RangeCheck, - SCEVExpander &Expander, - Instruction *Guard); - Optional widenICmpRangeCheckDecrementingLoop(LoopICmp LatchCheck, - LoopICmp RangeCheck, - SCEVExpander &Expander, - Instruction *Guard); + std::optional widenICmpRangeCheck(ICmpInst *ICI, + SCEVExpander &Expander, + Instruction *Guard); + std::optional + widenICmpRangeCheckIncrementingLoop(LoopICmp LatchCheck, LoopICmp RangeCheck, + SCEVExpander &Expander, + Instruction *Guard); + std::optional + widenICmpRangeCheckDecrementingLoop(LoopICmp LatchCheck, LoopICmp RangeCheck, + SCEVExpander &Expander, + Instruction *Guard); unsigned collectChecks(SmallVectorImpl &Checks, Value *Condition, SCEVExpander &Expander, Instruction *Guard); bool widenGuardConditions(IntrinsicInst *II, SCEVExpander &Expander); @@ -384,8 +385,7 @@ PreservedAnalyses LoopPredicationPass::run(Loop &L, LoopAnalysisManager &AM, return PA; } -Optional -LoopPredication::parseLoopICmp(ICmpInst *ICI) { +std::optional LoopPredication::parseLoopICmp(ICmpInst *ICI) { auto Pred = ICI->getPredicate(); auto *LHS = ICI->getOperand(0); auto *RHS = ICI->getOperand(1); @@ -576,9 +576,9 @@ bool LoopPredication::isLoopInvariantValue(const SCEV* S) { return false; } -Optional LoopPredication::widenICmpRangeCheckIncrementingLoop( - LoopICmp LatchCheck, LoopICmp RangeCheck, - SCEVExpander &Expander, Instruction *Guard) { +std::optional LoopPredication::widenICmpRangeCheckIncrementingLoop( + LoopICmp LatchCheck, LoopICmp RangeCheck, SCEVExpander &Expander, + Instruction *Guard) { auto *Ty = RangeCheck.IV->getType(); // Generate the widened condition for the forward loop: // guardStart u< guardLimit && @@ -625,9 +625,9 @@ Optional LoopPredication::widenICmpRangeCheckIncrementingLoop( return Builder.CreateAnd(FirstIterationCheck, LimitCheck); } -Optional LoopPredication::widenICmpRangeCheckDecrementingLoop( - LoopICmp LatchCheck, LoopICmp RangeCheck, - SCEVExpander &Expander, Instruction *Guard) { +std::optional LoopPredication::widenICmpRangeCheckDecrementingLoop( + LoopICmp LatchCheck, LoopICmp RangeCheck, SCEVExpander &Expander, + Instruction *Guard) { auto *Ty = RangeCheck.IV->getType(); const SCEV *GuardStart = RangeCheck.IV->getStart(); const SCEV *GuardLimit = RangeCheck.Limit; @@ -687,9 +687,9 @@ static void normalizePredicate(ScalarEvolution *SE, Loop *L, /// If ICI can be widened to a loop invariant condition emits the loop /// invariant condition in the loop preheader and return it, otherwise /// returns std::nullopt. -Optional LoopPredication::widenICmpRangeCheck(ICmpInst *ICI, - SCEVExpander &Expander, - Instruction *Guard) { +std::optional +LoopPredication::widenICmpRangeCheck(ICmpInst *ICI, SCEVExpander &Expander, + Instruction *Guard) { LLVM_DEBUG(dbgs() << "Analyzing ICmpInst condition:\n"); LLVM_DEBUG(ICI->dump()); @@ -872,7 +872,7 @@ bool LoopPredication::widenWidenableBranchGuardConditions( return true; } -Optional LoopPredication::parseLoopLatchICmp() { +std::optional LoopPredication::parseLoopLatchICmp() { using namespace PatternMatch; BasicBlock *LoopLatch = L->getLoopLatch(); @@ -939,7 +939,6 @@ Optional LoopPredication::parseLoopLatchICmp() { return Result; } - bool LoopPredication::isLoopProfitableToPredicate() { if (SkipProfitabilityChecks) return true; diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp index cc0ca7ab9717c0..a454c057309224 100644 --- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp +++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp @@ -344,7 +344,7 @@ struct PragmaInfo { /// \returns Optional value, holding the RolledDynamicCost and UnrolledCost. If /// the analysis failed (no benefits expected from the unrolling, or the loop is /// too big to analyze), the returned value is std::nullopt. -static Optional analyzeLoopUnrollCost( +static std::optional analyzeLoopUnrollCost( const Loop *L, unsigned TripCount, DominatorTree &DT, ScalarEvolution &SE, const SmallPtrSetImpl &EphValues, const TargetTransformInfo &TTI, unsigned MaxUnrolledLoopSize, @@ -819,7 +819,7 @@ static std::optional shouldFullUnroll( // The loop isn't that small, but we still can fully unroll it if that // helps to remove a significant number of instructions. // To check that, run additional analysis on the loop. - if (Optional Cost = analyzeLoopUnrollCost( + if (std::optional Cost = analyzeLoopUnrollCost( L, FullUnrollTripCount, DT, SE, EphValues, TTI, UP.Threshold * UP.MaxPercentThresholdBoost / 100, UP.MaxIterationsCountToAnalyze)) { diff --git a/llvm/lib/Transforms/Scalar/MergeICmps.cpp b/llvm/lib/Transforms/Scalar/MergeICmps.cpp index 0c09c0cdb9ee18..bcedb05890af36 100644 --- a/llvm/lib/Transforms/Scalar/MergeICmps.cpp +++ b/llvm/lib/Transforms/Scalar/MergeICmps.cpp @@ -300,9 +300,9 @@ bool BCECmpBlock::doesOtherWork() const { // Visit the given comparison. If this is a comparison between two valid // BCE atoms, returns the comparison. -Optional visitICmp(const ICmpInst *const CmpI, - const ICmpInst::Predicate ExpectedPredicate, - BaseIdentifier &BaseId) { +std::optional visitICmp(const ICmpInst *const CmpI, + const ICmpInst::Predicate ExpectedPredicate, + BaseIdentifier &BaseId) { // The comparison can only be used once: // - For intermediate blocks, as a branch condition. // - For the final block, as an incoming value for the Phi. @@ -330,9 +330,10 @@ Optional visitICmp(const ICmpInst *const CmpI, // Visit the given comparison block. If this is a comparison between two valid // BCE atoms, returns the comparison. -Optional visitCmpBlock(Value *const Val, BasicBlock *const Block, - const BasicBlock *const PhiBlock, - BaseIdentifier &BaseId) { +std::optional visitCmpBlock(Value *const Val, + BasicBlock *const Block, + const BasicBlock *const PhiBlock, + BaseIdentifier &BaseId) { if (Block->empty()) return std::nullopt; auto *const BranchI = dyn_cast(Block->getTerminator()); @@ -368,7 +369,7 @@ Optional visitCmpBlock(Value *const Val, BasicBlock *const Block, return std::nullopt; LLVM_DEBUG(dbgs() << "icmp\n"); - Optional Result = visitICmp(CmpI, ExpectedPredicate, BaseId); + std::optional Result = visitICmp(CmpI, ExpectedPredicate, BaseId); if (!Result) return std::nullopt; @@ -476,7 +477,7 @@ BCECmpChain::BCECmpChain(const std::vector &Blocks, PHINode &Phi, BaseIdentifier BaseId; for (BasicBlock *const Block : Blocks) { assert(Block && "invalid block"); - Optional Comparison = visitCmpBlock( + std::optional Comparison = visitCmpBlock( Phi.getIncomingValueForBlock(Block), Block, Phi.getParent(), BaseId); if (!Comparison) { LLVM_DEBUG(dbgs() << "chain with invalid BCECmpBlock, no merge.\n"); diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp index b42546e05cedf8..907408d0a9e6e5 100644 --- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp +++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp @@ -317,7 +317,7 @@ static void findLiveSetAtInst(Instruction *inst, GCPtrLivenessData &Data, StatepointLiveSetTy &out); // TODO: Once we can get to the GCStrategy, this becomes -// Optional isGCManagedPointer(const Type *Ty) const override { +// std::optional isGCManagedPointer(const Type *Ty) const override { static bool isGCPointerType(Type *T) { if (auto *PT = dyn_cast(T)) diff --git a/llvm/lib/Transforms/Scalar/Scalarizer.cpp b/llvm/lib/Transforms/Scalar/Scalarizer.cpp index 0517d2f32a208b..4aab88b74f1069 100644 --- a/llvm/lib/Transforms/Scalar/Scalarizer.cpp +++ b/llvm/lib/Transforms/Scalar/Scalarizer.cpp @@ -191,7 +191,7 @@ struct VectorLayout { template T getWithDefaultOverride(const cl::opt &ClOption, - const llvm::Optional &DefaultOverride) { + const std::optional &DefaultOverride) { return ClOption.getNumOccurrences() ? ClOption : DefaultOverride.value_or(ClOption); } @@ -235,8 +235,8 @@ class ScalarizerVisitor : public InstVisitor { void replaceUses(Instruction *Op, Value *CV); bool canTransferMetadata(unsigned Kind); void transferMetadataAndIRFlags(Instruction *Op, const ValueVector &CV); - Optional getVectorLayout(Type *Ty, Align Alignment, - const DataLayout &DL); + std::optional getVectorLayout(Type *Ty, Align Alignment, + const DataLayout &DL); bool finish(); template bool splitUnary(Instruction &, const T &); @@ -486,7 +486,7 @@ void ScalarizerVisitor::transferMetadataAndIRFlags(Instruction *Op, // Try to fill in Layout from Ty, returning true on success. Alignment is // the alignment of the vector, or std::nullopt if the ABI default should be // used. -Optional +std::optional ScalarizerVisitor::getVectorLayout(Type *Ty, Align Alignment, const DataLayout &DL) { VectorLayout Layout; @@ -920,7 +920,7 @@ bool ScalarizerVisitor::visitLoadInst(LoadInst &LI) { if (!LI.isSimple()) return false; - Optional Layout = getVectorLayout( + std::optional Layout = getVectorLayout( LI.getType(), LI.getAlign(), LI.getModule()->getDataLayout()); if (!Layout) return false; @@ -946,7 +946,7 @@ bool ScalarizerVisitor::visitStoreInst(StoreInst &SI) { return false; Value *FullValue = SI.getValueOperand(); - Optional Layout = getVectorLayout( + std::optional Layout = getVectorLayout( FullValue->getType(), SI.getAlign(), SI.getModule()->getDataLayout()); if (!Layout) return false; diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp index 25c95d2a44ab59..c9dec06c431625 100644 --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -122,9 +122,10 @@ namespace { struct NonTrivialUnswitchCandidate { Instruction *TI = nullptr; TinyPtrVector Invariants; - Optional Cost; - NonTrivialUnswitchCandidate(Instruction *TI, ArrayRef Invariants, - Optional Cost = std::nullopt) + std::optional Cost; + NonTrivialUnswitchCandidate( + Instruction *TI, ArrayRef Invariants, + std::optional Cost = std::nullopt) : TI(TI), Invariants(Invariants), Cost(Cost){}; }; } // end anonymous namespace.