From: Fangrui Song Date: Wed, 14 Dec 2022 07:32:24 +0000 (+0000) Subject: [Analysis] llvm::Optional => std::optional X-Git-Tag: upstream/17.0.6~23902 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d4b6fcb32e29d0cd834a3c89205fef48fbfc1d2d;p=platform%2Fupstream%2Fllvm.git [Analysis] llvm::Optional => std::optional --- diff --git a/llvm/include/llvm/ADT/PostOrderIterator.h b/llvm/include/llvm/ADT/PostOrderIterator.h index d036604..a80eed7 100644 --- a/llvm/include/llvm/ADT/PostOrderIterator.h +++ b/llvm/include/llvm/ADT/PostOrderIterator.h @@ -17,11 +17,11 @@ #define LLVM_ADT_POSTORDERITERATOR_H #include "llvm/ADT/GraphTraits.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/iterator_range.h" #include +#include #include #include #include @@ -62,7 +62,7 @@ class po_iterator_storage { public: // Return true if edge destination should be visited. template - bool insertEdge(Optional From, NodeRef To) { + bool insertEdge(std::optional From, NodeRef To) { return Visited.insert(To).second; } @@ -82,7 +82,8 @@ public: // Return true if edge destination should be visited, called with From = 0 for // the root node. // Graph edges can be pruned by specializing this function. - template bool insertEdge(Optional From, NodeRef To) { + template + bool insertEdge(std::optional From, NodeRef To) { return Visited.insert(To).second; } @@ -110,7 +111,7 @@ private: SmallVector, 8> VisitStack; po_iterator(NodeRef BB) { - this->insertEdge(Optional(), BB); + this->insertEdge(std::optional(), BB); VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB))); traverseChild(); } @@ -119,7 +120,7 @@ private: po_iterator(NodeRef BB, SetType &S) : po_iterator_storage(S) { - if (this->insertEdge(Optional(), BB)) { + if (this->insertEdge(std::optional(), BB)) { VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB))); traverseChild(); } @@ -132,7 +133,8 @@ private: void traverseChild() { while (VisitStack.back().second != GT::child_end(VisitStack.back().first)) { NodeRef BB = *VisitStack.back().second++; - if (this->insertEdge(Optional(VisitStack.back().first), BB)) { + if (this->insertEdge(std::optional(VisitStack.back().first), + BB)) { // If the block is not visited... VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB))); } diff --git a/llvm/include/llvm/Analysis/AliasAnalysis.h b/llvm/include/llvm/Analysis/AliasAnalysis.h index 99d10cb..1c033d7 100644 --- a/llvm/include/llvm/Analysis/AliasAnalysis.h +++ b/llvm/include/llvm/Analysis/AliasAnalysis.h @@ -38,7 +38,6 @@ #define LLVM_ANALYSIS_ALIASANALYSIS_H #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/Sequence.h" #include "llvm/ADT/SmallVector.h" #include "llvm/Analysis/MemoryLocation.h" @@ -48,6 +47,7 @@ #include #include #include +#include #include namespace llvm { @@ -486,7 +486,7 @@ public: /// call-site mod-ref behavior queries. Otherwise it delegates to the specific /// helpers above. ModRefInfo getModRefInfo(const Instruction *I, - const Optional &OptLoc) { + const std::optional &OptLoc) { SimpleAAQueryInfo AAQIP(*this); return getModRefInfo(I, OptLoc, AAQIP); } @@ -577,7 +577,7 @@ public: ModRefInfo getModRefInfo(const CatchReturnInst *I, const MemoryLocation &Loc, AAQueryInfo &AAQI); ModRefInfo getModRefInfo(const Instruction *I, - const Optional &OptLoc, + const std::optional &OptLoc, AAQueryInfo &AAQIP); ModRefInfo callCapturesBefore(const Instruction *I, const MemoryLocation &MemLoc, DominatorTree *DT, @@ -626,7 +626,7 @@ public: return AA.getModRefInfoMask(Loc, AAQI, IgnoreLocals); } ModRefInfo getModRefInfo(const Instruction *I, - const Optional &OptLoc) { + const std::optional &OptLoc) { return AA.getModRefInfo(I, OptLoc, AAQI); } ModRefInfo getModRefInfo(const Instruction *I, const CallBase *Call2) { diff --git a/llvm/include/llvm/Analysis/BranchProbabilityInfo.h b/llvm/include/llvm/Analysis/BranchProbabilityInfo.h index 0e6e1c7..14d3080 100644 --- a/llvm/include/llvm/Analysis/BranchProbabilityInfo.h +++ b/llvm/include/llvm/Analysis/BranchProbabilityInfo.h @@ -359,22 +359,22 @@ private: /// Returns estimated weight for \p BB. std::nullopt if \p BB has no estimated /// weight. - Optional getEstimatedBlockWeight(const BasicBlock *BB) const; + std::optional getEstimatedBlockWeight(const BasicBlock *BB) const; /// Returns estimated weight to enter \p L. In other words it is weight of /// loop's header block not scaled by trip count. Returns std::nullopt if \p L /// has no no estimated weight. - Optional getEstimatedLoopWeight(const LoopData &L) const; + std::optional getEstimatedLoopWeight(const LoopData &L) const; /// Return estimated weight for \p Edge. Returns std::nullopt if estimated /// weight is unknown. - Optional getEstimatedEdgeWeight(const LoopEdge &Edge) const; + std::optional getEstimatedEdgeWeight(const LoopEdge &Edge) const; /// Iterates over all edges leading from \p SrcBB to \p Successors and /// returns maximum of all estimated weights. If at least one edge has unknown /// estimated weight std::nullopt is returned. template - Optional + std::optional getMaxEstimatedEdgeWeight(const LoopBlock &SrcBB, iterator_range Successors) const; @@ -394,7 +394,7 @@ private: SmallVectorImpl &LoopWorkList); /// Returns block's weight encoded in the IR. - Optional getInitialEstimatedBlockWeight(const BasicBlock *BB); + std::optional getInitialEstimatedBlockWeight(const BasicBlock *BB); // Computes estimated weights for all blocks in \p F. void computeEestimateBlockWeight(const Function &F, DominatorTree *DT, diff --git a/llvm/include/llvm/Analysis/CallGraph.h b/llvm/include/llvm/Analysis/CallGraph.h index df38ea4..3461c69 100644 --- a/llvm/include/llvm/Analysis/CallGraph.h +++ b/llvm/include/llvm/Analysis/CallGraph.h @@ -175,7 +175,7 @@ public: /// first field and it is not supposed to be `nullptr`. /// Reference edges, for example, are used for connecting broker function /// caller to the callback function for callback call sites. - using CallRecord = std::pair, CallGraphNode *>; + using CallRecord = std::pair, CallGraphNode *>; public: using CalledFunctionsVector = std::vector; @@ -243,8 +243,9 @@ public: assert(!Call || !Call->getCalledFunction() || !Call->getCalledFunction()->isIntrinsic() || !Intrinsic::isLeaf(Call->getCalledFunction()->getIntrinsicID())); - CalledFunctions.emplace_back( - Call ? Optional(Call) : Optional(), M); + CalledFunctions.emplace_back(Call ? std::optional(Call) + : std::optional(), + M); M->AddRef(); } diff --git a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h index 5623367..91af95b 100644 --- a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h +++ b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h @@ -889,7 +889,7 @@ public: /// \param [in] V - the Value to find. /// \returns The positive number corresponding to the value. /// \returns std::nullopt if not present. - Optional getGVN(Value *V) { + std::optional getGVN(Value *V) { assert(V != nullptr && "Value is a nullptr?"); DenseMap::iterator VNIt = ValueToNumber.find(V); if (VNIt == ValueToNumber.end()) @@ -901,7 +901,7 @@ public: /// \param [in] Num - the number to find. /// \returns The Value associated with the number. /// \returns std::nullopt if not present. - Optional fromGVN(unsigned Num) { + std::optional fromGVN(unsigned Num) { DenseMap::iterator VNIt = NumberToValue.find(Num); if (VNIt == NumberToValue.end()) return std::nullopt; @@ -915,7 +915,7 @@ public: /// \param N - The global value number to find the canonical number for. /// \returns An optional containing the value, and std::nullopt if it could /// not be found. - Optional getCanonicalNum(unsigned N) { + std::optional getCanonicalNum(unsigned N) { DenseMap::iterator NCIt = NumberToCanonNum.find(N); if (NCIt == NumberToCanonNum.end()) return std::nullopt; @@ -928,7 +928,7 @@ public: /// \param N - The canonical number to find the global vlaue number for. /// \returns An optional containing the value, and std::nullopt if it could /// not be found. - Optional fromCanonicalNum(unsigned N) { + std::optional fromCanonicalNum(unsigned N) { DenseMap::iterator CNIt = CanonNumToNumber.find(N); if (CNIt == CanonNumToNumber.end()) return std::nullopt; @@ -1048,7 +1048,7 @@ public: // \returns The groups of similarity ranges found in the most recently passed // set of modules. - Optional &getSimilarity() { + std::optional &getSimilarity() { return SimilarityCandidates; } @@ -1086,7 +1086,7 @@ private: /// The SimilarityGroups found with the most recent run of \ref /// findSimilarity. std::nullopt if there is no recent run. - Optional SimilarityCandidates; + std::optional SimilarityCandidates; }; } // end namespace IRSimilarity diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h b/llvm/include/llvm/Analysis/InlineAdvisor.h index 150ae97..861cf63 100644 --- a/llvm/include/llvm/Analysis/InlineAdvisor.h +++ b/llvm/include/llvm/Analysis/InlineAdvisor.h @@ -143,8 +143,8 @@ private: class DefaultInlineAdvice : public InlineAdvice { public: DefaultInlineAdvice(InlineAdvisor *Advisor, CallBase &CB, - Optional OIC, OptimizationRemarkEmitter &ORE, - bool EmitRemarks = true) + std::optional OIC, + OptimizationRemarkEmitter &ORE, bool EmitRemarks = true) : InlineAdvice(Advisor, CB, ORE, OIC.has_value()), OriginalCB(&CB), OIC(OIC), EmitRemarks(EmitRemarks) {} @@ -155,7 +155,7 @@ private: private: CallBase *const OriginalCB; - Optional OIC; + std::optional OIC; bool EmitRemarks; }; @@ -200,14 +200,14 @@ public: protected: InlineAdvisor(Module &M, FunctionAnalysisManager &FAM, - Optional IC = std::nullopt); + std::optional IC = std::nullopt); virtual std::unique_ptr getAdviceImpl(CallBase &CB) = 0; virtual std::unique_ptr getMandatoryAdvice(CallBase &CB, bool Advice); Module &M; FunctionAnalysisManager &FAM; - const Optional IC; + const std::optional IC; const std::string AnnotatedInlinePassName; std::unique_ptr ImportedFunctionsStats; @@ -295,7 +295,7 @@ getDevelopmentModeAdvisor(Module &M, ModuleAnalysisManager &MAM, /// CallSite. If we return the cost, we will emit an optimisation remark later /// using that cost, so we won't do so from this function. Return std::nullopt /// if inlining should not be attempted. -Optional +std::optional shouldInline(CallBase &CB, function_ref GetInlineCost, OptimizationRemarkEmitter &ORE, bool EnableDeferral = true); diff --git a/llvm/include/llvm/Analysis/InlineCost.h b/llvm/include/llvm/Analysis/InlineCost.h index bac159f..0c73df9 100644 --- a/llvm/include/llvm/Analysis/InlineCost.h +++ b/llvm/include/llvm/Analysis/InlineCost.h @@ -103,12 +103,12 @@ class InlineCost { const char *Reason = nullptr; /// The cost-benefit pair computed by cost-benefit analysis. - Optional CostBenefit = std::nullopt; + std::optional CostBenefit = std::nullopt; // Trivial constructor, interesting logic in the factory functions below. InlineCost(int Cost, int Threshold, int StaticBonusApplied, const char *Reason = nullptr, - Optional CostBenefit = std::nullopt) + std::optional CostBenefit = std::nullopt) : Cost(Cost), Threshold(Threshold), StaticBonusApplied(StaticBonusApplied), Reason(Reason), CostBenefit(CostBenefit) { @@ -124,12 +124,12 @@ public: } static InlineCost getAlways(const char *Reason, - Optional CostBenefit = std::nullopt) { + std::optional CostBenefit = std::nullopt) { return InlineCost(AlwaysInlineCost, 0, 0, Reason, CostBenefit); } static InlineCost getNever(const char *Reason, - Optional CostBenefit = std::nullopt) { + std::optional CostBenefit = std::nullopt) { return InlineCost(NeverInlineCost, 0, 0, Reason, CostBenefit); } @@ -160,7 +160,7 @@ public: } /// Get the cost-benefit pair which was computed by cost-benefit analysis - Optional getCostBenefit() const { return CostBenefit; } + std::optional getCostBenefit() const { return CostBenefit; } /// Get the reason of Always or Never. const char *getReason() const { @@ -208,26 +208,26 @@ struct InlineParams { int DefaultThreshold = -1; /// Threshold to use for callees with inline hint. - Optional HintThreshold; + std::optional HintThreshold; /// Threshold to use for cold callees. - Optional ColdThreshold; + std::optional ColdThreshold; /// Threshold to use when the caller is optimized for size. - Optional OptSizeThreshold; + std::optional OptSizeThreshold; /// Threshold to use when the caller is optimized for minsize. - Optional OptMinSizeThreshold; + std::optional OptMinSizeThreshold; /// Threshold to use when the callsite is considered hot. - Optional HotCallSiteThreshold; + std::optional HotCallSiteThreshold; /// Threshold to use when the callsite is considered hot relative to function /// entry. - Optional LocallyHotCallSiteThreshold; + std::optional LocallyHotCallSiteThreshold; /// Threshold to use when the callsite is considered cold. - Optional ColdCallSiteThreshold; + std::optional ColdCallSiteThreshold; /// Compute inline cost even when the cost has exceeded the threshold. std::optional ComputeFullInlineCost; @@ -239,7 +239,7 @@ struct InlineParams { std::optional AllowRecursiveCall = false; }; -Optional getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind); +std::optional getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind); /// Generate the parameters to tune the inline cost analysis based only on the /// commandline options. @@ -302,7 +302,7 @@ getInlineCost(CallBase &Call, Function *Callee, const InlineParams &Params, /// directives or incompatibilities detectable without needing callee traversal. /// Otherwise returns std::nullopt, meaning that inlining should be decided /// based on other criteria (e.g. cost modeling). -Optional getAttributeBasedInliningDecision( +std::optional getAttributeBasedInliningDecision( CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI, function_ref GetTLI); @@ -314,7 +314,7 @@ Optional getAttributeBasedInliningDecision( /// returns: /// - std::nullopt, if the inlining cannot happen (is illegal) /// - an integer, representing the cost. -Optional getInliningCostEstimate( +std::optional getInliningCostEstimate( CallBase &Call, TargetTransformInfo &CalleeTTI, function_ref GetAssumptionCache, function_ref GetBFI = nullptr, @@ -323,7 +323,7 @@ Optional getInliningCostEstimate( /// Get the expanded cost features. The features are returned unconditionally, /// even if inlining is impossible. -Optional getInliningCostFeatures( +std::optional getInliningCostFeatures( CallBase &Call, TargetTransformInfo &CalleeTTI, function_ref GetAssumptionCache, function_ref GetBFI = nullptr, diff --git a/llvm/include/llvm/Analysis/InlineSizeEstimatorAnalysis.h b/llvm/include/llvm/Analysis/InlineSizeEstimatorAnalysis.h index ab2cf52..0aae696 100644 --- a/llvm/include/llvm/Analysis/InlineSizeEstimatorAnalysis.h +++ b/llvm/include/llvm/Analysis/InlineSizeEstimatorAnalysis.h @@ -24,7 +24,7 @@ public: ~InlineSizeEstimatorAnalysis(); static AnalysisKey Key; - using Result = Optional; + using Result = std::optional; Result run(const Function &F, FunctionAnalysisManager &FAM); static bool isEvaluatorRequested(); diff --git a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h index 67a7f9c..a49e24a 100644 --- a/llvm/include/llvm/Analysis/LoopAccessAnalysis.h +++ b/llvm/include/llvm/Analysis/LoopAccessAnalysis.h @@ -730,7 +730,7 @@ const SCEV *replaceSymbolicStrideSCEV(PredicatedScalarEvolution &PSE, /// to \p PtrToStride and therefore add further predicates to \p PSE. /// The \p Assume parameter indicates if we are allowed to make additional /// run-time assumptions. -Optional +std::optional getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr, const Loop *Lp, const ValueToValueMap &StridesMap = ValueToValueMap(), @@ -741,10 +741,11 @@ getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr, /// is a simple API that does not depend on the analysis pass. /// \param StrictCheck Ensure that the calculated distance matches the /// type-based one after all the bitcasts removal in the provided pointers. -Optional getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB, - Value *PtrB, const DataLayout &DL, - ScalarEvolution &SE, bool StrictCheck = false, - bool CheckType = true); +std::optional getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB, + Value *PtrB, const DataLayout &DL, + ScalarEvolution &SE, + bool StrictCheck = false, + bool CheckType = true); /// Attempt to sort the pointers in \p VL and return the sorted indices /// in \p SortedIndices, if reordering is required. diff --git a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h index 2e4f0c4..c9e853b 100644 --- a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h +++ b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h @@ -73,16 +73,16 @@ public: /// are/aren't in the same cache line of size \p CLS. Two references are in /// the same chace line iff the distance between them in the innermost /// dimension is less than the cache line size. Return std::nullopt if unsure. - Optional hasSpacialReuse(const IndexedReference &Other, unsigned CLS, - AAResults &AA) const; + std::optional hasSpacialReuse(const IndexedReference &Other, + unsigned CLS, AAResults &AA) const; /// Return true if the current object and the indexed reference \p Other /// have distance smaller than \p MaxDistance in the dimension associated with /// the given loop \p L. Return false if the distance is not smaller than \p /// MaxDistance and std::nullopt if unsure. - Optional hasTemporalReuse(const IndexedReference &Other, - unsigned MaxDistance, const Loop &L, - DependenceInfo &DI, AAResults &AA) const; + std::optional hasTemporalReuse(const IndexedReference &Other, + unsigned MaxDistance, const Loop &L, + DependenceInfo &DI, AAResults &AA) const; /// Compute the cost of the reference w.r.t. the given loop \p L when it is /// considered in the innermost position in the loop nest. @@ -200,7 +200,7 @@ public: /// classified to have temporal reuse. CacheCost(const LoopVectorTy &Loops, const LoopInfo &LI, ScalarEvolution &SE, TargetTransformInfo &TTI, AAResults &AA, DependenceInfo &DI, - Optional TRT = std::nullopt); + std::optional TRT = std::nullopt); /// Create a CacheCost for the loop nest rooted by \p Root. /// The optional parameter \p TRT can be used to specify the max. distance @@ -208,7 +208,7 @@ public: /// classified to have temporal reuse. static std::unique_ptr getCacheCost(Loop &Root, LoopStandardAnalysisResults &AR, DependenceInfo &DI, - Optional TRT = std::nullopt); + std::optional TRT = std::nullopt); /// Return the estimated cost of loop \p L if the given loop is part of the /// loop nest associated with this object. Return -1 otherwise. diff --git a/llvm/include/llvm/Analysis/LoopInfo.h b/llvm/include/llvm/Analysis/LoopInfo.h index 278ad92..b77a335 100644 --- a/llvm/include/llvm/Analysis/LoopInfo.h +++ b/llvm/include/llvm/Analysis/LoopInfo.h @@ -665,8 +665,8 @@ public: /// - the final value of the induction variable can be found /// /// Else None. - static Optional getBounds(const Loop &L, PHINode &IndVar, - ScalarEvolution &SE); + static std::optional + getBounds(const Loop &L, PHINode &IndVar, ScalarEvolution &SE); /// Get the initial value of the loop induction variable. Value &getInitialIVValue() const { return InitialIVValue; } @@ -751,7 +751,7 @@ public: /// Return the struct LoopBounds collected if all struct members are found, /// else std::nullopt. - Optional getBounds(ScalarEvolution &SE) const; + std::optional getBounds(ScalarEvolution &SE) const; /// Return the loop induction variable if found, else return nullptr. /// An instruction is considered as the loop induction variable if @@ -1327,9 +1327,9 @@ MDNode *findOptionMDForLoopID(MDNode *LoopID, StringRef Name); /// found, return nullptr. MDNode *findOptionMDForLoop(const Loop *TheLoop, StringRef Name); -Optional getOptionalBoolLoopAttribute(const Loop *TheLoop, - StringRef Name); - +std::optional getOptionalBoolLoopAttribute(const Loop *TheLoop, + StringRef Name); + /// Returns true if Name is applied to TheLoop and enabled. bool getBooleanLoopAttribute(const Loop *TheLoop, StringRef Name); @@ -1346,8 +1346,8 @@ int getIntLoopAttribute(const Loop *TheLoop, StringRef Name, int Default = 0); /// If it has a value (e.g. {"llvm.distribute", 1} return the value as an /// operand or null otherwise. If the string metadata is not found return /// Optional's not-a-value. -Optional findStringMetadataForLoop(const Loop *TheLoop, - StringRef Name); +std::optional findStringMetadataForLoop(const Loop *TheLoop, + StringRef Name); /// Look for the loop attribute that requires progress within the loop. /// Note: Most consumers probably want "isMustProgress" which checks diff --git a/llvm/include/llvm/Analysis/LoopIterator.h b/llvm/include/llvm/Analysis/LoopIterator.h index fa4da4283..360f196 100644 --- a/llvm/include/llvm/Analysis/LoopIterator.h +++ b/llvm/include/llvm/Analysis/LoopIterator.h @@ -192,7 +192,7 @@ template<> class po_iterator_storage { public: po_iterator_storage(LoopBlocksTraversal &lbs) : LBT(lbs) {} // These functions are defined below. - bool insertEdge(Optional From, BasicBlock *To); + bool insertEdge(std::optional From, BasicBlock *To); void finishPostorder(BasicBlock *BB); }; @@ -245,7 +245,7 @@ public: }; inline bool po_iterator_storage::insertEdge( - Optional From, BasicBlock *To) { + std::optional From, BasicBlock *To) { return LBT.visitPreorder(To); } diff --git a/llvm/include/llvm/Analysis/ModelUnderTrainingRunner.h b/llvm/include/llvm/Analysis/ModelUnderTrainingRunner.h index 1c4d504..7e29bbd 100644 --- a/llvm/include/llvm/Analysis/ModelUnderTrainingRunner.h +++ b/llvm/include/llvm/Analysis/ModelUnderTrainingRunner.h @@ -42,7 +42,7 @@ public: return lastEvaluationResult()->getUntypedTensorValue(ExtraOutputIndex + 1); } - const Optional & + const std::optional & lastEvaluationResult() const { return LastEvaluationResult; } @@ -68,7 +68,7 @@ private: std::unique_ptr Evaluator; const std::vector OutputSpecs; const std::vector ExtraOutputsForLogging; - Optional LastEvaluationResult; + std::optional LastEvaluationResult; void *evaluateUntyped() override; }; diff --git a/llvm/include/llvm/Analysis/MustExecute.h b/llvm/include/llvm/Analysis/MustExecute.h index 1e49942..b83705c 100644 --- a/llvm/include/llvm/Analysis/MustExecute.h +++ b/llvm/include/llvm/Analysis/MustExecute.h @@ -528,10 +528,10 @@ private: ///} /// Map to cache isGuaranteedToTransferExecutionToSuccessor results. - DenseMap> BlockTransferMap; + DenseMap> BlockTransferMap; /// Map to cache containsIrreducibleCFG results. - DenseMap> IrreducibleControlMap; + DenseMap> IrreducibleControlMap; /// Map from instructions to associated must be executed iterators. DenseMap> diff --git a/llvm/include/llvm/Analysis/ObjCARCUtil.h b/llvm/include/llvm/Analysis/ObjCARCUtil.h index 7e27e9a..62e13eb 100644 --- a/llvm/include/llvm/Analysis/ObjCARCUtil.h +++ b/llvm/include/llvm/Analysis/ObjCARCUtil.h @@ -40,7 +40,7 @@ inline bool hasAttachedCallOpBundle(const CallBase *CB) { /// This function returns operand bundle clang_arc_attachedcall's argument, /// which is the address of the ARC runtime function. -inline Optional getAttachedARCFunction(const CallBase *CB) { +inline std::optional getAttachedARCFunction(const CallBase *CB) { auto B = CB->getOperandBundle(LLVMContext::OB_clang_arc_attachedcall); if (!B) return std::nullopt; @@ -58,7 +58,7 @@ inline bool isRetainOrClaimRV(ARCInstKind Kind) { /// have the operand bundle or the operand is null. Otherwise it returns either /// RetainRV or UnsafeClaimRV. inline ARCInstKind getAttachedARCFunctionKind(const CallBase *CB) { - Optional Fn = getAttachedARCFunction(CB); + std::optional Fn = getAttachedARCFunction(CB); if (!Fn) return ARCInstKind::None; auto FnClass = GetFunctionClass(*Fn); diff --git a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h index 9cf8fe3..292c713 100644 --- a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h +++ b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h @@ -53,7 +53,7 @@ private: // percentile is above a large threshold. std::optional HasLargeWorkingSetSize; // Compute the threshold for a given cutoff. - Optional computeThreshold(int PercentileCutoff) const; + std::optional computeThreshold(int PercentileCutoff) const; // The map that caches the threshold values. The keys are the percentile // cutoff values and the values are the corresponding threshold values. mutable DenseMap ThresholdCache; diff --git a/llvm/include/llvm/Analysis/SyntheticCountsUtils.h b/llvm/include/llvm/Analysis/SyntheticCountsUtils.h index 458b599..5a6c7dd 100644 --- a/llvm/include/llvm/Analysis/SyntheticCountsUtils.h +++ b/llvm/include/llvm/Analysis/SyntheticCountsUtils.h @@ -34,7 +34,8 @@ public: // Not all EdgeRef have information about the source of the edge. Hence // NodeRef corresponding to the source of the EdgeRef is explicitly passed. - using GetProfCountTy = function_ref(NodeRef, EdgeRef)>; + using GetProfCountTy = + function_ref(NodeRef, EdgeRef)>; using AddCountTy = function_ref; static void propagate(const CallGraphType &CG, GetProfCountTy GetProfCount, diff --git a/llvm/include/llvm/Analysis/TensorSpec.h b/llvm/include/llvm/Analysis/TensorSpec.h index f8a40a3..3e0db32a 100644 --- a/llvm/include/llvm/Analysis/TensorSpec.h +++ b/llvm/include/llvm/Analysis/TensorSpec.h @@ -110,8 +110,8 @@ private: /// "shape": } /// For the "type" field, see the C++ primitive types used in /// TFUTILS_SUPPORTED_TYPES. -Optional getTensorSpecFromJSON(LLVMContext &Ctx, - const json::Value &Value); +std::optional getTensorSpecFromJSON(LLVMContext &Ctx, + const json::Value &Value); #define TFUTILS_GETDATATYPE_DEF(T, Name) \ template <> TensorType TensorSpec::getDataType(); diff --git a/llvm/include/llvm/Analysis/Utils/TFUtils.h b/llvm/include/llvm/Analysis/Utils/TFUtils.h index 858f6be..04bb8af 100644 --- a/llvm/include/llvm/Analysis/Utils/TFUtils.h +++ b/llvm/include/llvm/Analysis/Utils/TFUtils.h @@ -86,7 +86,7 @@ public: /// evaluation fails or the model is invalid, or an EvaluationResult /// otherwise. The inputs are assumed to have been already provided via /// getInput(). When returning std::nullopt, it also invalidates this object. - Optional evaluate(); + std::optional evaluate(); /// Provides access to the input vector. template T *getInput(size_t Index) { diff --git a/llvm/include/llvm/Analysis/ValueLattice.h b/llvm/include/llvm/Analysis/ValueLattice.h index cd2d731..5ae32b5 100644 --- a/llvm/include/llvm/Analysis/ValueLattice.h +++ b/llvm/include/llvm/Analysis/ValueLattice.h @@ -275,7 +275,7 @@ public: return Range; } - Optional asConstantInteger() const { + std::optional asConstantInteger() const { if (isConstant() && isa(getConstant())) { return cast(getConstant())->getValue(); } else if (isConstantRange() && getConstantRange().isSingleElement()) { diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h index fa675bb..667039e 100644 --- a/llvm/include/llvm/Analysis/ValueTracking.h +++ b/llvm/include/llvm/Analysis/ValueTracking.h @@ -822,29 +822,32 @@ bool matchSimpleRecurrence(const BinaryOperator *I, PHINode *&P, Value *&Start, /// T | T | F /// F | T | T /// (A) -Optional isImpliedCondition(const Value *LHS, const Value *RHS, - const DataLayout &DL, bool LHSIsTrue = true, - unsigned Depth = 0); -Optional isImpliedCondition(const Value *LHS, CmpInst::Predicate RHSPred, - const Value *RHSOp0, const Value *RHSOp1, - const DataLayout &DL, bool LHSIsTrue = true, - unsigned Depth = 0); +std::optional isImpliedCondition(const Value *LHS, const Value *RHS, + const DataLayout &DL, + bool LHSIsTrue = true, + unsigned Depth = 0); +std::optional isImpliedCondition(const Value *LHS, + CmpInst::Predicate RHSPred, + const Value *RHSOp0, const Value *RHSOp1, + const DataLayout &DL, + bool LHSIsTrue = true, + unsigned Depth = 0); /// Return the boolean condition value in the context of the given instruction /// if it is known based on dominating conditions. -Optional isImpliedByDomCondition(const Value *Cond, - const Instruction *ContextI, - const DataLayout &DL); -Optional isImpliedByDomCondition(CmpInst::Predicate Pred, - const Value *LHS, const Value *RHS, - const Instruction *ContextI, - const DataLayout &DL); +std::optional isImpliedByDomCondition(const Value *Cond, + const Instruction *ContextI, + const DataLayout &DL); +std::optional isImpliedByDomCondition(CmpInst::Predicate Pred, + const Value *LHS, const Value *RHS, + const Instruction *ContextI, + const DataLayout &DL); /// If Ptr1 is provably equal to Ptr2 plus a constant offset, return that /// offset. For example, Ptr1 might be &A[42], and Ptr2 might be &A[40]. In /// this case offset would be -8. -Optional isPointerOffset(const Value *Ptr1, const Value *Ptr2, - const DataLayout &DL); +std::optional isPointerOffset(const Value *Ptr1, const Value *Ptr2, + const DataLayout &DL); } // end namespace llvm #endif // LLVM_ANALYSIS_VALUETRACKING_H diff --git a/llvm/include/llvm/Analysis/VectorUtils.h b/llvm/include/llvm/Analysis/VectorUtils.h index 02271d5..b04d087 100644 --- a/llvm/include/llvm/Analysis/VectorUtils.h +++ b/llvm/include/llvm/Analysis/VectorUtils.h @@ -164,7 +164,8 @@ static constexpr char const *_LLVM_Scalarize_ = "_LLVM_Scalarize_"; /// name. At the moment, this parameter is needed only to retrieve the /// Vectorization Factor of scalable vector functions from their /// respective IR declarations. -Optional tryDemangleForVFABI(StringRef MangledName, const Module &M); +std::optional tryDemangleForVFABI(StringRef MangledName, + const Module &M); /// This routine mangles the given VectorName according to the LangRef /// specification for vector-function-abi-variant attribute and is specific to @@ -230,7 +231,7 @@ class VFDatabase { if (ListOfStrings.empty()) return; for (const auto &MangledName : ListOfStrings) { - const Optional Shape = + const std::optional Shape = VFABI::tryDemangleForVFABI(MangledName, *(CI.getModule())); // A match is found via scalar and vector names, and also by // ensuring that the variant described in the attribute has a diff --git a/llvm/lib/Analysis/AliasAnalysis.cpp b/llvm/lib/Analysis/AliasAnalysis.cpp index 1f0494c..73de6fa 100644 --- a/llvm/lib/Analysis/AliasAnalysis.cpp +++ b/llvm/lib/Analysis/AliasAnalysis.cpp @@ -599,7 +599,7 @@ ModRefInfo AAResults::getModRefInfo(const AtomicRMWInst *RMW, } ModRefInfo AAResults::getModRefInfo(const Instruction *I, - const Optional &OptLoc, + const std::optional &OptLoc, AAQueryInfo &AAQIP) { if (OptLoc == std::nullopt) { if (const auto *Call = dyn_cast(I)) diff --git a/llvm/lib/Analysis/AliasAnalysisSummary.cpp b/llvm/lib/Analysis/AliasAnalysisSummary.cpp index 1627c40..a91791c 100644 --- a/llvm/lib/Analysis/AliasAnalysisSummary.cpp +++ b/llvm/lib/Analysis/AliasAnalysisSummary.cpp @@ -73,8 +73,8 @@ AliasAttrs getExternallyVisibleAttrs(AliasAttrs Attr) { return Attr & AliasAttrs(ExternalAttrMask); } -Optional instantiateInterfaceValue(InterfaceValue IValue, - CallBase &Call) { +std::optional +instantiateInterfaceValue(InterfaceValue IValue, CallBase &Call) { auto Index = IValue.Index; auto *V = (Index == 0) ? &Call : Call.getArgOperand(Index - 1); if (V->getType()->isPointerTy()) @@ -82,7 +82,7 @@ Optional instantiateInterfaceValue(InterfaceValue IValue, return std::nullopt; } -Optional +std::optional instantiateExternalRelation(ExternalRelation ERelation, CallBase &Call) { auto From = instantiateInterfaceValue(ERelation.From, Call); if (!From) @@ -93,8 +93,8 @@ instantiateExternalRelation(ExternalRelation ERelation, CallBase &Call) { return InstantiatedRelation{*From, *To, ERelation.Offset}; } -Optional instantiateExternalAttribute(ExternalAttribute EAttr, - CallBase &Call) { +std::optional +instantiateExternalAttribute(ExternalAttribute EAttr, CallBase &Call) { auto Value = instantiateInterfaceValue(EAttr.IValue, Call); if (!Value) return std::nullopt; diff --git a/llvm/lib/Analysis/AliasAnalysisSummary.h b/llvm/lib/Analysis/AliasAnalysisSummary.h index 10d49f9..ab337ba 100644 --- a/llvm/lib/Analysis/AliasAnalysisSummary.h +++ b/llvm/lib/Analysis/AliasAnalysisSummary.h @@ -35,9 +35,9 @@ #define LLVM_ANALYSIS_ALIASANALYSISSUMMARY_H #include "llvm/ADT/DenseMapInfo.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/SmallVector.h" #include +#include namespace llvm { @@ -203,8 +203,8 @@ struct InstantiatedValue { Value *Val; unsigned DerefLevel; }; -Optional instantiateInterfaceValue(InterfaceValue IValue, - CallBase &Call); +std::optional +instantiateInterfaceValue(InterfaceValue IValue, CallBase &Call); inline bool operator==(InstantiatedValue LHS, InstantiatedValue RHS) { return LHS.Val == RHS.Val && LHS.DerefLevel == RHS.DerefLevel; @@ -232,7 +232,7 @@ struct InstantiatedRelation { InstantiatedValue From, To; int64_t Offset; }; -Optional +std::optional instantiateExternalRelation(ExternalRelation ERelation, CallBase &Call); /// This is the result of instantiating ExternalAttribute at a particular @@ -241,8 +241,8 @@ struct InstantiatedAttr { InstantiatedValue IValue; AliasAttrs Attr; }; -Optional instantiateExternalAttribute(ExternalAttribute EAttr, - CallBase &Call); +std::optional +instantiateExternalAttribute(ExternalAttribute EAttr, CallBase &Call); } template <> struct DenseMapInfo { diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp index 1d4159a..b99c361 100644 --- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp +++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp @@ -647,7 +647,7 @@ computeUnlikelySuccessors(const BasicBlock *BB, Loop *L, } } -Optional +std::optional BranchProbabilityInfo::getEstimatedBlockWeight(const BasicBlock *BB) const { auto WeightIt = EstimatedBlockWeight.find(BB); if (WeightIt == EstimatedBlockWeight.end()) @@ -655,7 +655,7 @@ BranchProbabilityInfo::getEstimatedBlockWeight(const BasicBlock *BB) const { return WeightIt->second; } -Optional +std::optional BranchProbabilityInfo::getEstimatedLoopWeight(const LoopData &L) const { auto WeightIt = EstimatedLoopWeight.find(L); if (WeightIt == EstimatedLoopWeight.end()) @@ -663,7 +663,7 @@ BranchProbabilityInfo::getEstimatedLoopWeight(const LoopData &L) const { return WeightIt->second; } -Optional +std::optional BranchProbabilityInfo::getEstimatedEdgeWeight(const LoopEdge &Edge) const { // For edges entering a loop take weight of a loop rather than an individual // block in the loop. @@ -673,10 +673,10 @@ BranchProbabilityInfo::getEstimatedEdgeWeight(const LoopEdge &Edge) const { } template -Optional BranchProbabilityInfo::getMaxEstimatedEdgeWeight( +std::optional BranchProbabilityInfo::getMaxEstimatedEdgeWeight( const LoopBlock &SrcLoopBB, iterator_range Successors) const { SmallVector Weights; - Optional MaxWeight; + std::optional MaxWeight; for (const BasicBlock *DstBB : Successors) { const LoopBlock DstLoopBB = getLoopBlock(DstBB); auto Weight = getEstimatedEdgeWeight({SrcLoopBB, DstLoopBB}); @@ -767,8 +767,8 @@ void BranchProbabilityInfo::propagateEstimatedBlockWeight( } } -Optional BranchProbabilityInfo::getInitialEstimatedBlockWeight( - const BasicBlock *BB) { +std::optional +BranchProbabilityInfo::getInitialEstimatedBlockWeight(const BasicBlock *BB) { // Returns true if \p BB has call marked with "NoReturn" attribute. auto hasNoReturn = [&](const BasicBlock *BB) { for (const auto &I : reverse(*BB)) @@ -895,7 +895,7 @@ bool BranchProbabilityInfo::calcEstimatedHeuristics(const BasicBlock *BB) { uint64_t TotalWeight = 0; // Go over all successors of BB and put their weights into SuccWeights. for (const BasicBlock *SuccBB : successors(BB)) { - Optional Weight; + std::optional Weight; const LoopBlock SuccLoopBB = getLoopBlock(SuccBB); const LoopEdge Edge{LoopBB, SuccLoopBB}; diff --git a/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp b/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp index f171926..0fb6d60 100644 --- a/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp +++ b/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp @@ -169,7 +169,7 @@ public: std::unique_ptr getAdviceFromModel(CallBase &CB, OptimizationRemarkEmitter &ORE) override; - Optional getNativeSizeEstimate(const Function &F) const; + std::optional getNativeSizeEstimate(const Function &F) const; private: bool isLogging() const { return !!Logger; } @@ -179,8 +179,8 @@ private: const bool IsDoingInference; std::unique_ptr Logger; - const Optional InitialNativeSize; - Optional CurrentNativeSize; + const std::optional InitialNativeSize; + std::optional CurrentNativeSize; }; /// A variant of MLInlineAdvice that tracks all non-trivial inlining @@ -190,8 +190,8 @@ public: LoggingMLInlineAdvice(DevelopmentModeMLInlineAdvisor *Advisor, CallBase &CB, OptimizationRemarkEmitter &ORE, bool Recommendation, TrainingLogger &Logger, - Optional CallerSizeEstimateBefore, - Optional CalleeSizeEstimateBefore, + std::optional CallerSizeEstimateBefore, + std::optional CalleeSizeEstimateBefore, bool DefaultDecision, bool Mandatory = false) : MLInlineAdvice(Advisor, CB, ORE, Recommendation), Logger(Logger), CallerSizeEstimateBefore(CallerSizeEstimateBefore), @@ -257,8 +257,8 @@ private: static const int64_t NoReward = 0; TrainingLogger &Logger; - const Optional CallerSizeEstimateBefore; - const Optional CalleeSizeEstimateBefore; + const std::optional CallerSizeEstimateBefore; + const std::optional CalleeSizeEstimateBefore; const int64_t DefaultDecision; const int64_t Mandatory; }; @@ -353,7 +353,7 @@ DevelopmentModeMLInlineAdvisor::~DevelopmentModeMLInlineAdvisor() { Logger->print(); } -Optional +std::optional DevelopmentModeMLInlineAdvisor::getNativeSizeEstimate(const Function &F) const { if (!InlineSizeEstimatorAnalysis::isEvaluatorRequested()) return std::nullopt; diff --git a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp index a681c52..8a11f66 100644 --- a/llvm/lib/Analysis/IRSimilarityIdentifier.cpp +++ b/llvm/lib/Analysis/IRSimilarityIdentifier.cpp @@ -1264,7 +1264,8 @@ IRSimilarityIdentifier IRSimilarityAnalysis::run(Module &M, PreservedAnalyses IRSimilarityAnalysisPrinterPass::run(Module &M, ModuleAnalysisManager &AM) { IRSimilarityIdentifier &IRSI = AM.getResult(M); - Optional &SimilarityCandidatesOpt = IRSI.getSimilarity(); + std::optional &SimilarityCandidatesOpt = + IRSI.getSimilarity(); for (std::vector &CandVec : *SimilarityCandidatesOpt) { OS << CandVec.size() << " candidates of length " diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp index b8e5adc..cb21f06 100644 --- a/llvm/lib/Analysis/InlineAdvisor.cpp +++ b/llvm/lib/Analysis/InlineAdvisor.cpp @@ -130,7 +130,7 @@ void DefaultInlineAdvice::recordInliningImpl() { Advisor->getAnnotatedInlinePassName()); } -llvm::Optional static getDefaultInlineAdvice( +std::optional static getDefaultInlineAdvice( CallBase &CB, FunctionAnalysisManager &FAM, const InlineParams &Params) { Function &Caller = *CB.getCaller(); ProfileSummaryInfo *PSI = @@ -366,7 +366,7 @@ void llvm::setInlineRemark(CallBase &CB, StringRef Message) { /// CallSite. If we return the cost, we will emit an optimisation remark later /// using that cost, so we won't do so from this function. Return std::nullopt /// if inlining should not be attempted. -Optional +std::optional llvm::shouldInline(CallBase &CB, function_ref GetInlineCost, OptimizationRemarkEmitter &ORE, bool EnableDeferral) { @@ -514,7 +514,7 @@ void llvm::emitInlinedIntoBasedOnCost( } InlineAdvisor::InlineAdvisor(Module &M, FunctionAnalysisManager &FAM, - Optional IC) + std::optional IC) : M(M), FAM(FAM), IC(IC), AnnotatedInlinePassName((IC && AnnotateInlinePhase) ? llvm::AnnotateInlinePassName(*IC) diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index ab414f6..b6f50b8d 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -162,7 +162,7 @@ static cl::opt DisableGEPConstOperand( cl::desc("Disables evaluation of GetElementPtr with constant operands")); namespace llvm { -Optional getStringFnAttrAsInt(const Attribute &Attr) { +std::optional getStringFnAttrAsInt(const Attribute &Attr) { if (Attr.isValid()) { int AttrValue = 0; if (!Attr.getValueAsString().getAsInteger(10, AttrValue)) @@ -171,11 +171,11 @@ Optional getStringFnAttrAsInt(const Attribute &Attr) { return std::nullopt; } -Optional getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind) { +std::optional getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind) { return getStringFnAttrAsInt(CB.getFnAttr(AttrKind)); } -Optional getStringFnAttrAsInt(Function *F, StringRef AttrKind) { +std::optional getStringFnAttrAsInt(Function *F, StringRef AttrKind) { return getStringFnAttrAsInt(F->getFnAttribute(AttrKind)); } @@ -584,7 +584,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { bool DecidedByCostBenefit = false; // The cost-benefit pair computed by cost-benefit analysis. - Optional CostBenefit = std::nullopt; + std::optional CostBenefit = std::nullopt; bool SingleBB = true; @@ -605,8 +605,8 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { /// analysis. void updateThreshold(CallBase &Call, Function &Callee); /// Return a higher threshold if \p Call is a hot callsite. - Optional getHotCallSiteThreshold(CallBase &Call, - BlockFrequencyInfo *CallerBFI); + std::optional getHotCallSiteThreshold(CallBase &Call, + BlockFrequencyInfo *CallerBFI); /// Handle a capped 'int' increment for Cost. void addCost(int64_t Inc) { @@ -630,11 +630,11 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { } bool onCallBaseVisitStart(CallBase &Call) override { - if (Optional AttrCallThresholdBonus = + if (std::optional AttrCallThresholdBonus = getStringFnAttrAsInt(Call, "call-threshold-bonus")) Threshold += *AttrCallThresholdBonus; - if (Optional AttrCallCost = + if (std::optional AttrCallCost = getStringFnAttrAsInt(Call, "call-inline-cost")) { addCost(*AttrCallCost); // Prevent further processing of the call since we want to override its @@ -932,16 +932,16 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { else if (NumVectorInstructions <= NumInstructions / 2) Threshold -= VectorBonus / 2; - if (Optional AttrCost = + if (std::optional AttrCost = getStringFnAttrAsInt(CandidateCall, "function-inline-cost")) Cost = *AttrCost; - if (Optional AttrCostMult = getStringFnAttrAsInt( + if (std::optional AttrCostMult = getStringFnAttrAsInt( CandidateCall, InlineConstants::FunctionInlineCostMultiplierAttributeName)) Cost *= *AttrCostMult; - if (Optional AttrThreshold = + if (std::optional AttrThreshold = getStringFnAttrAsInt(CandidateCall, "function-inline-threshold")) Threshold = *AttrThreshold; @@ -1053,7 +1053,7 @@ public: // on the build. void print(raw_ostream &OS); - Optional getCostDetails(const Instruction *I) { + std::optional getCostDetails(const Instruction *I) { if (InstructionCostDetailMap.find(I) != InstructionCostDetailMap.end()) return InstructionCostDetailMap[I]; return std::nullopt; @@ -1063,7 +1063,7 @@ public: int getThreshold() const { return Threshold; } int getCost() const { return Cost; } int getStaticBonusApplied() const { return StaticBonusApplied; } - Optional getCostBenefitPair() { return CostBenefit; } + std::optional getCostBenefitPair() { return CostBenefit; } bool wasDecidedByCostBenefit() const { return DecidedByCostBenefit; } bool wasDecidedByCostThreshold() const { return DecidedByCostThreshold; } }; @@ -1294,7 +1294,7 @@ void InlineCostAnnotationWriter::emitInstructionAnnot( // The cost of inlining of the given instruction is printed always. // The threshold delta is printed only when it is non-zero. It happens // when we decided to give a bonus at a particular instruction. - Optional Record = ICCA->getCostDetails(I); + std::optional Record = ICCA->getCostDetails(I); if (!Record) OS << "; No analysis for the instruction"; else { @@ -1781,7 +1781,7 @@ bool InlineCostCallAnalyzer::isColdCallSite(CallBase &Call, return CallSiteFreq < CallerEntryFreq * ColdProb; } -Optional +std::optional InlineCostCallAnalyzer::getHotCallSiteThreshold(CallBase &Call, BlockFrequencyInfo *CallerBFI) { @@ -1819,12 +1819,12 @@ void InlineCostCallAnalyzer::updateThreshold(CallBase &Call, Function &Callee) { Function *Caller = Call.getCaller(); // return min(A, B) if B is valid. - auto MinIfValid = [](int A, Optional B) { + auto MinIfValid = [](int A, std::optional B) { return B ? std::min(A, B.value()) : A; }; // return max(A, B) if B is valid. - auto MaxIfValid = [](int A, Optional B) { + auto MaxIfValid = [](int A, std::optional B) { return B ? std::max(A, B.value()) : A; }; @@ -2734,7 +2734,7 @@ InlineResult CallAnalyzer::analyze() { // The command line option overrides a limit set in the function attributes. size_t FinalStackSizeThreshold = StackSizeThreshold; if (!StackSizeThreshold.getNumOccurrences()) - if (Optional AttrMaxStackSize = getStringFnAttrAsInt( + if (std::optional AttrMaxStackSize = getStringFnAttrAsInt( Caller, InlineConstants::MaxInlineStackSizeAttributeName)) FinalStackSizeThreshold = *AttrMaxStackSize; if (AllocatedSize > FinalStackSizeThreshold) @@ -2829,7 +2829,7 @@ InlineCost llvm::getInlineCost( GetAssumptionCache, GetTLI, GetBFI, PSI, ORE); } -Optional llvm::getInliningCostEstimate( +std::optional llvm::getInliningCostEstimate( CallBase &Call, TargetTransformInfo &CalleeTTI, function_ref GetAssumptionCache, function_ref GetBFI, @@ -2854,7 +2854,7 @@ Optional llvm::getInliningCostEstimate( return CA.getCost(); } -Optional llvm::getInliningCostFeatures( +std::optional llvm::getInliningCostFeatures( CallBase &Call, TargetTransformInfo &CalleeTTI, function_ref GetAssumptionCache, function_ref GetBFI, @@ -2867,7 +2867,7 @@ Optional llvm::getInliningCostFeatures( return CFA.features(); } -Optional llvm::getAttributeBasedInliningDecision( +std::optional llvm::getAttributeBasedInliningDecision( CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI, function_ref GetTLI) { diff --git a/llvm/lib/Analysis/InlineOrder.cpp b/llvm/lib/Analysis/InlineOrder.cpp index 75f8bb6..8d0e499 100644 --- a/llvm/lib/Analysis/InlineOrder.cpp +++ b/llvm/lib/Analysis/InlineOrder.cpp @@ -174,7 +174,7 @@ public: private: int Cost = INT_MAX; int StaticBonusApplied = 0; - Optional CostBenefit; + std::optional CostBenefit; }; class MLPriority { diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp index ba0c20f..63eee20 100644 --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -752,7 +752,7 @@ static Value *simplifyByDomEq(unsigned Opcode, Value *Op0, Value *Op1, if (MaxRecurse != RecursionLimit) return nullptr; - Optional Imp = + std::optional Imp = isImpliedByDomCondition(CmpInst::ICMP_EQ, Op0, Op1, Q.CxtI, Q.DL); if (Imp && *Imp) { Type *Ty = Op0->getType(); @@ -2217,7 +2217,7 @@ static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, return Constant::getNullValue(Op0->getType()); if (Op0->getType()->isIntOrIntVectorTy(1)) { - if (Optional Implied = isImpliedCondition(Op0, Op1, Q.DL)) { + if (std::optional Implied = isImpliedCondition(Op0, Op1, Q.DL)) { // If Op0 is true implies Op1 is true, then Op0 is a subset of Op1. if (*Implied == true) return Op0; @@ -2225,7 +2225,7 @@ static Value *simplifyAndInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, if (*Implied == false) return ConstantInt::getFalse(Op0->getType()); } - if (Optional Implied = isImpliedCondition(Op1, Op0, Q.DL)) { + if (std::optional Implied = isImpliedCondition(Op1, Op0, Q.DL)) { // If Op1 is true implies Op0 is true, then Op1 is a subset of Op0. if (Implied.value()) return Op1; @@ -2479,7 +2479,8 @@ static Value *simplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, return V; if (Op0->getType()->isIntOrIntVectorTy(1)) { - if (Optional Implied = isImpliedCondition(Op0, Op1, Q.DL, false)) { + if (std::optional Implied = + isImpliedCondition(Op0, Op1, Q.DL, false)) { // If Op0 is false implies Op1 is false, then Op1 is a subset of Op0. if (*Implied == false) return Op0; @@ -2487,7 +2488,8 @@ static Value *simplifyOrInst(Value *Op0, Value *Op1, const SimplifyQuery &Q, if (*Implied == true) return ConstantInt::getTrue(Op0->getType()); } - if (Optional Implied = isImpliedCondition(Op1, Op0, Q.DL, false)) { + if (std::optional Implied = + isImpliedCondition(Op1, Op0, Q.DL, false)) { // If Op1 is false implies Op0 is false, then Op0 is a subset of Op1. if (*Implied == false) return Op1; @@ -3616,8 +3618,8 @@ static Value *simplifyICmpWithDominatingAssume(CmpInst::Predicate Predicate, continue; CallInst *Assume = cast(AssumeVH); - if (Optional Imp = isImpliedCondition(Assume->getArgOperand(0), - Predicate, LHS, RHS, Q.DL)) + if (std::optional Imp = isImpliedCondition( + Assume->getArgOperand(0), Predicate, LHS, RHS, Q.DL)) if (isValidAssumeForContext(Assume, Q.CxtI, Q.DT)) return ConstantInt::get(getCompareTy(LHS), *Imp); } @@ -4647,7 +4649,7 @@ static Value *simplifySelectInst(Value *Cond, Value *TrueVal, Value *FalseVal, if (Value *V = foldSelectWithBinaryOp(Cond, TrueVal, FalseVal)) return V; - Optional Imp = isImpliedByDomCondition(Cond, Q.CxtI, Q.DL); + std::optional Imp = isImpliedByDomCondition(Cond, Q.CxtI, Q.DL); if (Imp) return *Imp ? TrueVal : FalseVal; @@ -6049,10 +6051,10 @@ static Value *simplifyBinaryIntrinsic(Function *F, Value *Op0, Value *Op1, if (isICmpTrue(Pred, Op1, Op0, Q.getWithoutUndef(), RecursionLimit)) return Op1; - if (Optional Imp = + if (std::optional Imp = isImpliedByDomCondition(Pred, Op0, Op1, Q.CxtI, Q.DL)) return *Imp ? Op0 : Op1; - if (Optional Imp = + if (std::optional Imp = isImpliedByDomCondition(Pred, Op1, Op0, Q.CxtI, Q.DL)) return *Imp ? Op1 : Op0; diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp index ba91c35..3dbdaeb 100644 --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -1358,7 +1358,8 @@ static std::optional getEdgeValueLocal(Value *Val, Value *Op = Usr->getOperand(i); ValueLatticeElement OpLatticeVal = getValueFromCondition(Op, Condition, isTrueDest); - if (Optional OpConst = OpLatticeVal.asConstantInteger()) { + if (std::optional OpConst = + OpLatticeVal.asConstantInteger()) { Result = constantFoldUser(Usr, Op, *OpConst, DL); break; } diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp index 4e68856..6cddf42 100644 --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -1366,11 +1366,11 @@ static bool isNoWrapAddRec(Value *Ptr, const SCEVAddRecExpr *AR, } /// Check whether the access through \p Ptr has a constant stride. -Optional -llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, - Value *Ptr, const Loop *Lp, - const ValueToValueMap &StridesMap, bool Assume, - bool ShouldCheckWrap) { +std::optional llvm::getPtrStride(PredicatedScalarEvolution &PSE, + Type *AccessTy, Value *Ptr, + const Loop *Lp, + const ValueToValueMap &StridesMap, + bool Assume, bool ShouldCheckWrap) { Type *Ty = Ptr->getType(); assert(Ty->isPointerTy() && "Unexpected non-ptr"); @@ -1477,10 +1477,11 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, return Stride; } -Optional llvm::getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB, - Value *PtrB, const DataLayout &DL, - ScalarEvolution &SE, bool StrictCheck, - bool CheckType) { +std::optional llvm::getPointersDiff(Type *ElemTyA, Value *PtrA, + Type *ElemTyB, Value *PtrB, + const DataLayout &DL, + ScalarEvolution &SE, bool StrictCheck, + bool CheckType) { assert(PtrA && PtrB && "Expected non-nullptr pointers."); assert(cast(PtrA->getType()) ->isOpaqueOrPointeeTypeMatches(ElemTyA) && "Wrong PtrA type"); @@ -1560,8 +1561,8 @@ bool llvm::sortPtrAccesses(ArrayRef VL, Type *ElemTy, int Cnt = 1; bool IsConsecutive = true; for (auto *Ptr : VL.drop_front()) { - Optional Diff = getPointersDiff(ElemTy, Ptr0, ElemTy, Ptr, DL, SE, - /*StrictCheck=*/true); + std::optional Diff = getPointersDiff(ElemTy, Ptr0, ElemTy, Ptr, DL, SE, + /*StrictCheck=*/true); if (!Diff) return false; @@ -1596,8 +1597,9 @@ bool llvm::isConsecutiveAccess(Value *A, Value *B, const DataLayout &DL, return false; Type *ElemTyA = getLoadStoreType(A); Type *ElemTyB = getLoadStoreType(B); - Optional Diff = getPointersDiff(ElemTyA, PtrA, ElemTyB, PtrB, DL, SE, - /*StrictCheck=*/true, CheckType); + std::optional Diff = + getPointersDiff(ElemTyA, PtrA, ElemTyB, PtrB, DL, SE, + /*StrictCheck=*/true, CheckType); return Diff && *Diff == 1; } diff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp index 884a018..46198f7 100644 --- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp +++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp @@ -156,9 +156,9 @@ IndexedReference::IndexedReference(Instruction &StoreOrLoadInst, << "\n"); } -Optional IndexedReference::hasSpacialReuse(const IndexedReference &Other, - unsigned CLS, - AAResults &AA) const { +std::optional +IndexedReference::hasSpacialReuse(const IndexedReference &Other, unsigned CLS, + AAResults &AA) const { assert(IsValid && "Expecting a valid reference"); if (BasePointer != Other.getBasePointer() && !isAliased(Other, AA)) { @@ -211,11 +211,10 @@ Optional IndexedReference::hasSpacialReuse(const IndexedReference &Other, return InSameCacheLine; } -Optional IndexedReference::hasTemporalReuse(const IndexedReference &Other, - unsigned MaxDistance, - const Loop &L, - DependenceInfo &DI, - AAResults &AA) const { +std::optional +IndexedReference::hasTemporalReuse(const IndexedReference &Other, + unsigned MaxDistance, const Loop &L, + DependenceInfo &DI, AAResults &AA) const { assert(IsValid && "Expecting a valid reference"); if (BasePointer != Other.getBasePointer() && !isAliased(Other, AA)) { @@ -557,7 +556,8 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const CacheCost &CC) { CacheCost::CacheCost(const LoopVectorTy &Loops, const LoopInfo &LI, ScalarEvolution &SE, TargetTransformInfo &TTI, - AAResults &AA, DependenceInfo &DI, Optional TRT) + AAResults &AA, DependenceInfo &DI, + std::optional TRT) : Loops(Loops), TRT(TRT.value_or(TemporalReuseThreshold)), LI(LI), SE(SE), TTI(TTI), AA(AA), DI(DI) { assert(!Loops.empty() && "Expecting a non-empty loop vector."); @@ -573,7 +573,7 @@ CacheCost::CacheCost(const LoopVectorTy &Loops, const LoopInfo &LI, std::unique_ptr CacheCost::getCacheCost(Loop &Root, LoopStandardAnalysisResults &AR, - DependenceInfo &DI, Optional TRT) { + DependenceInfo &DI, std::optional TRT) { if (!Root.isOutermost()) { LLVM_DEBUG(dbgs() << "Expecting the outermost loop in a loop nest\n"); return nullptr; @@ -648,9 +648,9 @@ bool CacheCost::populateReferenceGroups(ReferenceGroupsTy &RefGroups) const { // when in actuality, depending on the array size, the first example // should have a cost closer to 2x the second due to the two cache // access per iteration from opposite ends of the array - Optional HasTemporalReuse = + std::optional HasTemporalReuse = R->hasTemporalReuse(Representative, *TRT, *InnerMostLoop, DI, AA); - Optional HasSpacialReuse = + std::optional HasSpacialReuse = R->hasSpacialReuse(Representative, CLS, AA); if ((HasTemporalReuse && *HasTemporalReuse) || diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp index 0ffdf4e..69bcbcb 100644 --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -198,9 +198,9 @@ static Value *findFinalIVValue(const Loop &L, const PHINode &IndVar, return nullptr; } -Optional Loop::LoopBounds::getBounds(const Loop &L, - PHINode &IndVar, - ScalarEvolution &SE) { +std::optional +Loop::LoopBounds::getBounds(const Loop &L, PHINode &IndVar, + ScalarEvolution &SE) { InductionDescriptor IndDesc; if (!InductionDescriptor::isInductionPHI(&IndVar, &L, &SE, IndDesc)) return std::nullopt; @@ -284,7 +284,7 @@ Direction Loop::LoopBounds::getDirection() const { return Direction::Unknown; } -Optional Loop::getBounds(ScalarEvolution &SE) const { +std::optional Loop::getBounds(ScalarEvolution &SE) const { if (PHINode *IndVar = getInductionVariable(SE)) return LoopBounds::getBounds(*this, *IndVar, SE); @@ -1049,8 +1049,8 @@ MDNode *llvm::findOptionMDForLoop(const Loop *TheLoop, StringRef Name) { /// If it has a value (e.g. {"llvm.distribute", 1} return the value as an /// operand or null otherwise. If the string metadata is not found return /// Optional's not-a-value. -Optional llvm::findStringMetadataForLoop(const Loop *TheLoop, - StringRef Name) { +std::optional +llvm::findStringMetadataForLoop(const Loop *TheLoop, StringRef Name) { MDNode *MD = findOptionMDForLoop(TheLoop, Name); if (!MD) return std::nullopt; @@ -1064,8 +1064,8 @@ Optional llvm::findStringMetadataForLoop(const Loop *TheLoop, } } -Optional llvm::getOptionalBoolLoopAttribute(const Loop *TheLoop, - StringRef Name) { +std::optional llvm::getOptionalBoolLoopAttribute(const Loop *TheLoop, + StringRef Name) { MDNode *MD = findOptionMDForLoop(TheLoop, Name); if (!MD) return std::nullopt; diff --git a/llvm/lib/Analysis/LoopNestAnalysis.cpp b/llvm/lib/Analysis/LoopNestAnalysis.cpp index 7e80e25..fe6d270 100644 --- a/llvm/lib/Analysis/LoopNestAnalysis.cpp +++ b/llvm/lib/Analysis/LoopNestAnalysis.cpp @@ -84,7 +84,7 @@ static CmpInst *getInnerLoopGuardCmp(const Loop &InnerLoop) { static bool checkSafeInstruction(const Instruction &I, const CmpInst *InnerLoopGuardCmp, const CmpInst *OuterLoopLatchCmp, - Optional OuterLoopLB) { + std::optional OuterLoopLB) { bool IsAllowed = isSafeToSpeculativelyExecute(&I) || isa(I) || isa(I); diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp index 679dd08..a0a19b9 100644 --- a/llvm/lib/Analysis/MemoryBuiltins.cpp +++ b/llvm/lib/Analysis/MemoryBuiltins.cpp @@ -905,7 +905,7 @@ SizeOffsetType ObjectSizeOffsetVisitor::findLoadSizeOffset( // Is the error status of posix_memalign correctly checked? If not it // would be incorrect to assume it succeeds and load doesn't see the // previous value. - Optional Checked = isImpliedByDomCondition( + std::optional Checked = isImpliedByDomCondition( ICmpInst::ICMP_EQ, CB, ConstantInt::get(CB->getType(), 0), &Load, DL); if (!Checked || !*Checked) return Unknown(); diff --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp index 14d68ee..5503858 100644 --- a/llvm/lib/Analysis/MemorySSA.cpp +++ b/llvm/lib/Analysis/MemorySSA.cpp @@ -503,14 +503,14 @@ class ClobberWalker { // First. Also note that First and Last are inclusive. MemoryAccess *First; MemoryAccess *Last; - Optional Previous; + std::optional Previous; DefPath(const MemoryLocation &Loc, MemoryAccess *First, MemoryAccess *Last, - Optional Previous) + std::optional Previous) : Loc(Loc), First(First), Last(Last), Previous(Previous) {} DefPath(const MemoryLocation &Loc, MemoryAccess *Init, - Optional Previous) + std::optional Previous) : DefPath(Loc, Init, Init, Previous) {} }; @@ -622,7 +622,7 @@ class ClobberWalker { /// If this returns std::nullopt, NewPaused is a vector of searches that /// terminated at StopWhere. Otherwise, NewPaused is left in an unspecified /// state. - Optional + std::optional getBlockingAccess(const MemoryAccess *StopWhere, SmallVectorImpl &PausedSearches, SmallVectorImpl &NewPaused, @@ -720,7 +720,7 @@ class ClobberWalker { T &curNode() const { return W->Paths[*N]; } Walker *W = nullptr; - Optional N = std::nullopt; + std::optional N = std::nullopt; }; using def_path_iterator = generic_def_path_iterator; @@ -809,7 +809,7 @@ class ClobberWalker { // FIXME: This is broken, because the Blocker may be reported to be // liveOnEntry, and we'll happily wait for that to disappear (read: never) // For the moment, this is fine, since we do nothing with blocker info. - if (Optional Blocker = getBlockingAccess( + if (std::optional Blocker = getBlockingAccess( Target, PausedSearches, NewPaused, TerminatedPaths)) { // Find the node we started at. We can't search based on N->Last, since diff --git a/llvm/lib/Analysis/ModelUnderTrainingRunner.cpp b/llvm/lib/Analysis/ModelUnderTrainingRunner.cpp index 7c632ad..3892b09 100644 --- a/llvm/lib/Analysis/ModelUnderTrainingRunner.cpp +++ b/llvm/lib/Analysis/ModelUnderTrainingRunner.cpp @@ -26,7 +26,7 @@ struct LoggedFeatureSpec { std::optional LoggingName; }; -Optional> +std::optional> loadOutputSpecs(LLVMContext &Ctx, StringRef ExpectedDecisionName, StringRef ModelPath, StringRef SpecFileOverride) { SmallVector OutputSpecsPath; diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp index 8a6318e..5598e33 100644 --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -498,9 +498,9 @@ bool llvm::mayContainIrreducibleControl(const Function &F, const LoopInfo *LI) { /// Lookup \p Key in \p Map and return the result, potentially after /// initializing the optional through \p Fn(\p args). template -static V getOrCreateCachedOptional(K Key, DenseMap> &Map, - FnTy &&Fn, ArgsTy&&... args) { - Optional &OptVal = Map[Key]; +static V getOrCreateCachedOptional(K Key, DenseMap> &Map, + FnTy &&Fn, ArgsTy &&...args) { + std::optional &OptVal = Map[Key]; if (!OptVal) OptVal = Fn(std::forward(args)...); return OptVal.value(); diff --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp index ea77b40..c8a2ddf 100644 --- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp +++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp @@ -265,7 +265,7 @@ void ProfileSummaryInfo::computeThresholds() { } } -Optional +std::optional ProfileSummaryInfo::computeThreshold(int PercentileCutoff) const { if (!hasProfileSummary()) return std::nullopt; diff --git a/llvm/lib/Analysis/ReplayInlineAdvisor.cpp b/llvm/lib/Analysis/ReplayInlineAdvisor.cpp index 043dddf..2ca02eb 100644 --- a/llvm/lib/Analysis/ReplayInlineAdvisor.cpp +++ b/llvm/lib/Analysis/ReplayInlineAdvisor.cpp @@ -123,7 +123,7 @@ std::unique_ptr ReplayInlineAdvisor::getAdviceImpl(CallBase &CB) { } else { LLVM_DEBUG(dbgs() << "Replay Inliner: Not Inlined " << Callee << " @ " << CallSiteLoc << "\n"); - // A negative inline is conveyed by "None" Optional + // A negative inline is conveyed by "None" std::optional return std::make_unique(this, CB, std::nullopt, ORE, EmitRemarks); } @@ -137,7 +137,7 @@ std::unique_ptr ReplayInlineAdvisor::getAdviceImpl(CallBase &CB) { EmitRemarks); else if (ReplaySettings.ReplayFallback == ReplayInlinerSettings::Fallback::NeverInline) - // A negative inline is conveyed by "None" Optional + // A negative inline is conveyed by "None" std::optional return std::make_unique(this, CB, std::nullopt, ORE, EmitRemarks); else { diff --git a/llvm/lib/Analysis/StratifiedSets.h b/llvm/lib/Analysis/StratifiedSets.h index 4da6d47..f126e98 100644 --- a/llvm/lib/Analysis/StratifiedSets.h +++ b/llvm/lib/Analysis/StratifiedSets.h @@ -39,8 +39,8 @@ struct StratifiedLink { /// This is a value used to signify "does not exist" where the /// StratifiedIndex type is used. /// - /// This is used instead of Optional because - /// Optional would eat up a considerable amount of extra + /// This is used instead of std::optional because + /// std::optional would eat up a considerable amount of extra /// memory, after struct padding/alignment is taken into account. static const StratifiedIndex SetSentinel; @@ -91,7 +91,7 @@ public: std::vector Links) : Values(std::move(Map)), Links(std::move(Links)) {} - Optional find(const T &Elem) const { + std::optional find(const T &Elem) const { auto Iter = Values.find(Elem); if (Iter == Values.end()) return std::nullopt; @@ -544,21 +544,21 @@ private: return true; } - Optional get(const T &Val) const { + std::optional get(const T &Val) const { auto Result = Values.find(Val); if (Result == Values.end()) return std::nullopt; return &Result->second; } - Optional get(const T &Val) { + std::optional get(const T &Val) { auto Result = Values.find(Val); if (Result == Values.end()) return std::nullopt; return &Result->second; } - Optional indexOf(const T &Val) { + std::optional indexOf(const T &Val) { auto MaybeVal = get(Val); if (!MaybeVal) return std::nullopt; diff --git a/llvm/lib/Analysis/TFLiteUtils.cpp b/llvm/lib/Analysis/TFLiteUtils.cpp index 4951012..b286203 100644 --- a/llvm/lib/Analysis/TFLiteUtils.cpp +++ b/llvm/lib/Analysis/TFLiteUtils.cpp @@ -208,7 +208,7 @@ bool TFModelEvaluatorImpl::checkReportAndInvalidate(const TfLiteTensor *Tensor, return IsValid; } -Optional TFModelEvaluator::evaluate() { +std::optional TFModelEvaluator::evaluate() { if (!isValid()) return std::nullopt; return EvaluationResult(Impl->evaluate()); diff --git a/llvm/lib/Analysis/TensorSpec.cpp b/llvm/lib/Analysis/TensorSpec.cpp index 348f276..4f7428d 100644 --- a/llvm/lib/Analysis/TensorSpec.cpp +++ b/llvm/lib/Analysis/TensorSpec.cpp @@ -64,9 +64,10 @@ TensorSpec::TensorSpec(const std::string &Name, int Port, TensorType Type, std::multiplies())), ElementSize(ElementSize) {} -Optional getTensorSpecFromJSON(LLVMContext &Ctx, - const json::Value &Value) { - auto EmitError = [&](const llvm::Twine &Message) -> Optional { +std::optional getTensorSpecFromJSON(LLVMContext &Ctx, + const json::Value &Value) { + auto EmitError = + [&](const llvm::Twine &Message) -> std::optional { std::string S; llvm::raw_string_ostream OS(S); OS << Value; diff --git a/llvm/lib/Analysis/VFABIDemangling.cpp b/llvm/lib/Analysis/VFABIDemangling.cpp index a076171..1e2d1db 100644 --- a/llvm/lib/Analysis/VFABIDemangling.cpp +++ b/llvm/lib/Analysis/VFABIDemangling.cpp @@ -314,8 +314,8 @@ ElementCount getECFromSignature(FunctionType *Signature) { // Format of the ABI name: // _ZGV_[()] -Optional VFABI::tryDemangleForVFABI(StringRef MangledName, - const Module &M) { +std::optional VFABI::tryDemangleForVFABI(StringRef MangledName, + const Module &M) { const StringRef OriginalName = MangledName; // Assume there is no custom name , and therefore the // vector name consists of diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index c59cf3f..a777151 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -6732,7 +6732,7 @@ static bool isTruePredicate(CmpInst::Predicate Pred, const Value *LHS, /// Return true if "icmp Pred BLHS BRHS" is true whenever "icmp Pred /// ALHS ARHS" is true. Otherwise, return std::nullopt. -static Optional +static std::optional isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS, const Value *ARHS, const Value *BLHS, const Value *BRHS, const DataLayout &DL, unsigned Depth) { @@ -6769,9 +6769,9 @@ static bool areMatchingOperands(const Value *L0, const Value *L1, const Value *R /// Return true if "icmp1 LPred X, Y" implies "icmp2 RPred X, Y" is true. /// Return false if "icmp1 LPred X, Y" implies "icmp2 RPred X, Y" is false. /// Otherwise, return std::nullopt if we can't infer anything. -static Optional isImpliedCondMatchingOperands(CmpInst::Predicate LPred, - CmpInst::Predicate RPred, - bool AreSwappedOps) { +static std::optional +isImpliedCondMatchingOperands(CmpInst::Predicate LPred, + CmpInst::Predicate RPred, bool AreSwappedOps) { // Canonicalize the predicate as if the operands were not commuted. if (AreSwappedOps) RPred = ICmpInst::getSwappedPredicate(RPred); @@ -6787,7 +6787,7 @@ static Optional isImpliedCondMatchingOperands(CmpInst::Predicate LPred, /// Return true if "icmp LPred X, LC" implies "icmp RPred X, RC" is true. /// Return false if "icmp LPred X, LC" implies "icmp RPred X, RC" is false. /// Otherwise, return std::nullopt if we can't infer anything. -static Optional isImpliedCondCommonOperandWithConstants( +static std::optional isImpliedCondCommonOperandWithConstants( CmpInst::Predicate LPred, const APInt &LC, CmpInst::Predicate RPred, const APInt &RC) { ConstantRange DomCR = ConstantRange::makeExactICmpRegion(LPred, LC); @@ -6804,11 +6804,11 @@ static Optional isImpliedCondCommonOperandWithConstants( /// Return true if LHS implies RHS (expanded to its components as "R0 RPred R1") /// is true. Return false if LHS implies RHS is false. Otherwise, return /// std::nullopt if we can't infer anything. -static Optional isImpliedCondICmps(const ICmpInst *LHS, - CmpInst::Predicate RPred, - const Value *R0, const Value *R1, - const DataLayout &DL, bool LHSIsTrue, - unsigned Depth) { +static std::optional isImpliedCondICmps(const ICmpInst *LHS, + CmpInst::Predicate RPred, + const Value *R0, const Value *R1, + const DataLayout &DL, + bool LHSIsTrue, unsigned Depth) { Value *L0 = LHS->getOperand(0); Value *L1 = LHS->getOperand(1); @@ -6838,7 +6838,7 @@ static Optional isImpliedCondICmps(const ICmpInst *LHS, /// false. Otherwise, return std::nullopt if we can't infer anything. We /// expect the RHS to be an icmp and the LHS to be an 'and', 'or', or a 'select' /// instruction. -static Optional +static std::optional isImpliedCondAndOr(const Instruction *LHS, CmpInst::Predicate RHSPred, const Value *RHSOp0, const Value *RHSOp1, const DataLayout &DL, bool LHSIsTrue, unsigned Depth) { @@ -6857,10 +6857,10 @@ isImpliedCondAndOr(const Instruction *LHS, CmpInst::Predicate RHSPred, if ((!LHSIsTrue && match(LHS, m_LogicalOr(m_Value(ALHS), m_Value(ARHS)))) || (LHSIsTrue && match(LHS, m_LogicalAnd(m_Value(ALHS), m_Value(ARHS))))) { // FIXME: Make this non-recursion. - if (Optional Implication = isImpliedCondition( + if (std::optional Implication = isImpliedCondition( ALHS, RHSPred, RHSOp0, RHSOp1, DL, LHSIsTrue, Depth + 1)) return Implication; - if (Optional Implication = isImpliedCondition( + if (std::optional Implication = isImpliedCondition( ARHS, RHSPred, RHSOp0, RHSOp1, DL, LHSIsTrue, Depth + 1)) return Implication; return std::nullopt; @@ -6868,7 +6868,7 @@ isImpliedCondAndOr(const Instruction *LHS, CmpInst::Predicate RHSPred, return std::nullopt; } -Optional +std::optional llvm::isImpliedCondition(const Value *LHS, CmpInst::Predicate RHSPred, const Value *RHSOp0, const Value *RHSOp1, const DataLayout &DL, bool LHSIsTrue, unsigned Depth) { @@ -6903,9 +6903,9 @@ llvm::isImpliedCondition(const Value *LHS, CmpInst::Predicate RHSPred, return std::nullopt; } -Optional llvm::isImpliedCondition(const Value *LHS, const Value *RHS, - const DataLayout &DL, bool LHSIsTrue, - unsigned Depth) { +std::optional llvm::isImpliedCondition(const Value *LHS, const Value *RHS, + const DataLayout &DL, + bool LHSIsTrue, unsigned Depth) { // LHS ==> RHS by definition if (LHS == RHS) return LHSIsTrue; @@ -6922,21 +6922,21 @@ Optional llvm::isImpliedCondition(const Value *LHS, const Value *RHS, // LHS ==> !(RHS1 && RHS2) if LHS ==> !RHS1 or LHS ==> !RHS2 const Value *RHS1, *RHS2; if (match(RHS, m_LogicalOr(m_Value(RHS1), m_Value(RHS2)))) { - if (Optional Imp = + if (std::optional Imp = isImpliedCondition(LHS, RHS1, DL, LHSIsTrue, Depth + 1)) if (*Imp == true) return true; - if (Optional Imp = + if (std::optional Imp = isImpliedCondition(LHS, RHS2, DL, LHSIsTrue, Depth + 1)) if (*Imp == true) return true; } if (match(RHS, m_LogicalAnd(m_Value(RHS1), m_Value(RHS2)))) { - if (Optional Imp = + if (std::optional Imp = isImpliedCondition(LHS, RHS1, DL, LHSIsTrue, Depth + 1)) if (*Imp == false) return false; - if (Optional Imp = + if (std::optional Imp = isImpliedCondition(LHS, RHS2, DL, LHSIsTrue, Depth + 1)) if (*Imp == false) return false; @@ -6976,9 +6976,9 @@ getDomPredecessorCondition(const Instruction *ContextI) { return {PredCond, TrueBB == ContextBB}; } -Optional llvm::isImpliedByDomCondition(const Value *Cond, - const Instruction *ContextI, - const DataLayout &DL) { +std::optional llvm::isImpliedByDomCondition(const Value *Cond, + const Instruction *ContextI, + const DataLayout &DL) { assert(Cond->getType()->isIntOrIntVectorTy(1) && "Condition must be bool"); auto PredCond = getDomPredecessorCondition(ContextI); if (PredCond.first) @@ -6986,10 +6986,11 @@ Optional llvm::isImpliedByDomCondition(const Value *Cond, return std::nullopt; } -Optional llvm::isImpliedByDomCondition(CmpInst::Predicate Pred, - const Value *LHS, const Value *RHS, - const Instruction *ContextI, - const DataLayout &DL) { +std::optional llvm::isImpliedByDomCondition(CmpInst::Predicate Pred, + const Value *LHS, + const Value *RHS, + const Instruction *ContextI, + const DataLayout &DL) { auto PredCond = getDomPredecessorCondition(ContextI); if (PredCond.first) return isImpliedCondition(PredCond.first, Pred, LHS, RHS, DL, @@ -7431,8 +7432,9 @@ getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL) { return Offset; } -Optional llvm::isPointerOffset(const Value *Ptr1, const Value *Ptr2, - const DataLayout &DL) { +std::optional llvm::isPointerOffset(const Value *Ptr1, + const Value *Ptr2, + const DataLayout &DL) { APInt Offset1(DL.getIndexTypeSizeInBits(Ptr1->getType()), 0); APInt Offset2(DL.getIndexTypeSizeInBits(Ptr2->getType()), 0); Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(DL, Offset1, true); diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp index 0a61346..ae76637 100644 --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -1543,7 +1543,8 @@ void VFABI::getVectorVariantNames( for (const auto &S : SetVector(ListAttr.begin(), ListAttr.end())) { #ifndef NDEBUG LLVM_DEBUG(dbgs() << "VFABI: adding mapping '" << S << "'\n"); - Optional Info = VFABI::tryDemangleForVFABI(S, *(CI.getModule())); + std::optional Info = + VFABI::tryDemangleForVFABI(S, *(CI.getModule())); assert(Info && "Invalid name for a VFABI variant."); assert(CI.getModule()->getFunction(Info.value().VectorName) && "Vector function is missing."); diff --git a/llvm/lib/CodeGen/MachineTraceMetrics.cpp b/llvm/lib/CodeGen/MachineTraceMetrics.cpp index dc6746e..f5311a0 100644 --- a/llvm/lib/CodeGen/MachineTraceMetrics.cpp +++ b/llvm/lib/CodeGen/MachineTraceMetrics.cpp @@ -9,7 +9,6 @@ #include "llvm/CodeGen/MachineTraceMetrics.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" -#include "llvm/ADT/Optional.h" #include "llvm/ADT/PostOrderIterator.h" #include "llvm/ADT/SmallPtrSet.h" #include "llvm/ADT/SmallVector.h" @@ -449,7 +448,7 @@ public: void finishPostorder(const MachineBasicBlock*) {} - bool insertEdge(Optional From, + bool insertEdge(std::optional From, const MachineBasicBlock *To) { // Skip already visited To blocks. MachineTraceMetrics::TraceBlockInfo &TBI = LB.Blocks[To->getNumber()]; diff --git a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp index 15324c3..93afbad 100644 --- a/llvm/lib/Target/AArch64/AArch64StackTagging.cpp +++ b/llvm/lib/Target/AArch64/AArch64StackTagging.cpp @@ -379,7 +379,7 @@ Instruction *AArch64StackTagging::collectInitializers(Instruction *StartInst, break; // Check to see if this store is to a constant offset from the start ptr. - Optional Offset = + std::optional Offset = isPointerOffset(StartPtr, NextStore->getPointerOperand(), *DL); if (!Offset) break; @@ -397,7 +397,8 @@ Instruction *AArch64StackTagging::collectInitializers(Instruction *StartInst, break; // Check to see if this store is to a constant offset from the start ptr. - Optional Offset = isPointerOffset(StartPtr, MSI->getDest(), *DL); + std::optional Offset = + isPointerOffset(StartPtr, MSI->getDest(), *DL); if (!Offset) break; diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp index e79fe05..70ba973 100644 --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -190,11 +190,12 @@ static void getSortedConstantKeys(std::vector &SortedKeys, Value *OutlinableRegion::findCorrespondingValueIn(const OutlinableRegion &Other, Value *V) { - Optional GVN = Candidate->getGVN(V); + std::optional GVN = Candidate->getGVN(V); assert(GVN && "No GVN for incoming value"); - Optional CanonNum = Candidate->getCanonicalNum(*GVN); - Optional FirstGVN = Other.Candidate->fromCanonicalNum(*CanonNum); - Optional FoundValueOpt = Other.Candidate->fromGVN(*FirstGVN); + std::optional CanonNum = Candidate->getCanonicalNum(*GVN); + std::optional FirstGVN = + Other.Candidate->fromCanonicalNum(*CanonNum); + std::optional FoundValueOpt = Other.Candidate->fromGVN(*FirstGVN); return FoundValueOpt.value_or(nullptr); } @@ -562,7 +563,7 @@ collectRegionsConstants(OutlinableRegion &Region, // assigned by the IRSimilarityCandidate, has been seen before, we check if // the the number has been found to be not the same value in each instance. for (Value *V : ID.OperVals) { - Optional GVNOpt = C.getGVN(V); + std::optional GVNOpt = C.getGVN(V); assert(GVNOpt && "Expected a GVN for operand?"); unsigned GVN = GVNOpt.value(); @@ -957,11 +958,11 @@ findExtractedInputToOverallInputMapping(OutlinableRegion &Region, // we find argument locations for the canonical value numbering. This // numbering overrides any discovered location for the extracted code. for (unsigned InputVal : InputGVNs) { - Optional CanonicalNumberOpt = C.getCanonicalNum(InputVal); + std::optional CanonicalNumberOpt = C.getCanonicalNum(InputVal); assert(CanonicalNumberOpt && "Canonical number not found?"); unsigned CanonicalNumber = CanonicalNumberOpt.value(); - Optional InputOpt = C.fromGVN(InputVal); + std::optional InputOpt = C.fromGVN(InputVal); assert(InputOpt && "Global value number not found?"); Value *Input = InputOpt.value(); @@ -1174,10 +1175,10 @@ static hash_code encodePHINodeData(PHINodeData &PND) { /// \param AggArgIdx - The argument \p PN will be stored into. /// \returns An optional holding the assigned canonical number, or std::nullopt /// if there is some attribute of the PHINode blocking it from being used. -static Optional getGVNForPHINode(OutlinableRegion &Region, - PHINode *PN, - DenseSet &Blocks, - unsigned AggArgIdx) { +static std::optional getGVNForPHINode(OutlinableRegion &Region, + PHINode *PN, + DenseSet &Blocks, + unsigned AggArgIdx) { OutlinableGroup &Group = *Region.Parent; IRSimilarityCandidate &Cand = *Region.Candidate; BasicBlock *PHIBB = PN->getParent(); @@ -1192,7 +1193,7 @@ static Optional getGVNForPHINode(OutlinableRegion &Region, // are trying to analyze, meaning, that if it was outlined, we would be // adding an extra input. We ignore this case for now, and so ignore the // region. - Optional OGVN = Cand.getGVN(Incoming); + std::optional OGVN = Cand.getGVN(Incoming); if (!OGVN && Blocks.contains(IncomingBlock)) { Region.IgnoreRegion = true; return std::nullopt; @@ -1244,7 +1245,7 @@ static Optional getGVNForPHINode(OutlinableRegion &Region, // PHINode to generate a hash value representing this instance of the PHINode. DenseMap::iterator GVNToPHIIt; DenseMap::iterator PHIToGVNIt; - Optional BBGVN = Cand.getGVN(PHIBB); + std::optional BBGVN = Cand.getGVN(PHIBB); assert(BBGVN && "Could not find GVN for the incoming block!"); BBGVN = Cand.getCanonicalNum(BBGVN.value()); @@ -1364,7 +1365,7 @@ findExtractedOutputToOverallOutputMapping(OutlinableRegion &Region, // TODO: Adapt to the extra input from the PHINode. PHINode *PN = dyn_cast(Output); - Optional GVN; + std::optional GVN; if (PN && !BlocksInRegion.contains(PN->getParent())) { // Values outside the region can be combined into PHINode when we // have multiple exits. We collect both of these into a list to identify @@ -1657,9 +1658,9 @@ static void findCanonNumsForPHI( IVal = findOutputMapping(OutputMappings, IVal); // Find and add the canonical number for the incoming value. - Optional GVN = Region.Candidate->getGVN(IVal); + std::optional GVN = Region.Candidate->getGVN(IVal); assert(GVN && "No GVN for incoming value"); - Optional CanonNum = Region.Candidate->getCanonicalNum(*GVN); + std::optional CanonNum = Region.Candidate->getCanonicalNum(*GVN); assert(CanonNum && "No Canonical Number for GVN"); CanonNums.push_back(std::make_pair(*CanonNum, IBlock)); } @@ -2511,9 +2512,10 @@ static Value *findOutputValueInRegion(OutlinableRegion &Region, assert(It->second.second.size() > 0 && "PHINode does not have any values!"); OutputCanon = *It->second.second.begin(); } - Optional OGVN = Region.Candidate->fromCanonicalNum(OutputCanon); + std::optional OGVN = + Region.Candidate->fromCanonicalNum(OutputCanon); assert(OGVN && "Could not find GVN for Canonical Number?"); - Optional OV = Region.Candidate->fromGVN(*OGVN); + std::optional OV = Region.Candidate->fromGVN(*OGVN); assert(OV && "Could not find value for GVN?"); return *OV; } diff --git a/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp b/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp index 7e71ad6..d46f9a6 100644 --- a/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp +++ b/llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp @@ -101,7 +101,7 @@ PreservedAnalyses SyntheticCountsPropagation::run(Module &M, // parameter. auto GetCallSiteProfCount = [&](const CallGraphNode *, const CallGraphNode::CallRecord &Edge) { - Optional Res; + std::optional Res; if (!Edge.first) return Res; CallBase &CB = *cast(*Edge.first); @@ -115,7 +115,7 @@ PreservedAnalyses SyntheticCountsPropagation::run(Module &M, Scaled64 BBCount(BFI.getBlockFreq(CSBB).getFrequency(), 0); BBCount /= EntryFreq; BBCount *= Counts[Caller]; - return Optional(BBCount); + return std::optional(BBCount); }; CallGraph CG(M); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index d157737..dd36113 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -820,9 +820,10 @@ InstCombinerImpl::foldIntrinsicWithOverflowCommon(IntrinsicInst *II) { return nullptr; } -static Optional getKnownSign(Value *Op, Instruction *CxtI, - const DataLayout &DL, AssumptionCache *AC, - DominatorTree *DT) { +static std::optional getKnownSign(Value *Op, Instruction *CxtI, + const DataLayout &DL, + AssumptionCache *AC, + DominatorTree *DT) { KnownBits Known = computeKnownBits(Op, DL, 0, AC, CxtI, DT); if (Known.isNonNegative()) return false; @@ -1274,7 +1275,7 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) { if (match(IIOperand, m_Select(m_Value(), m_Neg(m_Value(X)), m_Deferred(X)))) return replaceOperand(*II, 0, X); - if (Optional Sign = getKnownSign(IIOperand, II, DL, &AC, &DT)) { + if (std::optional Sign = getKnownSign(IIOperand, II, DL, &AC, &DT)) { // abs(x) -> x if x >= 0 if (!*Sign) return replaceInstUsesWith(*II, IIOperand); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 64492da..c3d281e 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1480,7 +1480,8 @@ Instruction *InstCombinerImpl::foldICmpWithDominatingICmp(ICmpInst &Cmp) { return nullptr; // Try to simplify this compare to T/F based on the dominating condition. - Optional Imp = isImpliedCondition(DomCond, &Cmp, DL, TrueBB == CmpBB); + std::optional Imp = + isImpliedCondition(DomCond, &Cmp, DL, TrueBB == CmpBB); if (Imp) return replaceInstUsesWith(Cmp, ConstantInt::get(Cmp.getType(), *Imp)); @@ -3672,8 +3673,8 @@ Instruction *InstCombinerImpl::foldSelectICmp(ICmpInst::Predicate Pred, auto SimplifyOp = [&](Value *Op, bool SelectCondIsTrue) -> Value * { if (Value *Res = simplifyICmpInst(Pred, Op, RHS, SQ)) return Res; - if (Optional Impl = isImpliedCondition(SI->getCondition(), Pred, Op, - RHS, DL, SelectCondIsTrue)) + if (std::optional Impl = isImpliedCondition( + SI->getCondition(), Pred, Op, RHS, DL, SelectCondIsTrue)) return ConstantInt::get(I.getType(), *Impl); return nullptr; }; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp index 20350ef..fbd478c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp @@ -2502,7 +2502,7 @@ Instruction *InstCombinerImpl::foldAndOrOfSelectUsingImpliedCond(Value *Op, assert(Op->getType()->isIntOrIntVectorTy(1) && "Op must be either i1 or vector of i1."); - Optional Res = isImpliedCondition(Op, CondVal, DL, IsAnd); + std::optional Res = isImpliedCondition(Op, CondVal, DL, IsAnd); if (!Res) return nullptr; @@ -2932,13 +2932,13 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { // if c implies that b is false. if (match(CondVal, m_LogicalOr(m_Value(A), m_Value(B))) && match(FalseVal, m_Zero())) { - Optional Res = isImpliedCondition(TrueVal, B, DL); + std::optional Res = isImpliedCondition(TrueVal, B, DL); if (Res && *Res == false) return replaceOperand(SI, 0, A); } if (match(TrueVal, m_LogicalOr(m_Value(A), m_Value(B))) && match(FalseVal, m_Zero())) { - Optional Res = isImpliedCondition(CondVal, B, DL); + std::optional Res = isImpliedCondition(CondVal, B, DL); if (Res && *Res == false) return replaceOperand(SI, 1, A); } @@ -2947,13 +2947,13 @@ Instruction *InstCombinerImpl::foldSelectOfBools(SelectInst &SI) { // if c = false implies that b = true if (match(TrueVal, m_One()) && match(FalseVal, m_LogicalAnd(m_Value(A), m_Value(B)))) { - Optional Res = isImpliedCondition(CondVal, B, DL, false); + std::optional Res = isImpliedCondition(CondVal, B, DL, false); if (Res && *Res == true) return replaceOperand(SI, 2, A); } if (match(CondVal, m_LogicalAnd(m_Value(A), m_Value(B))) && match(TrueVal, m_One())) { - Optional Res = isImpliedCondition(FalseVal, B, DL, false); + std::optional Res = isImpliedCondition(FalseVal, B, DL, false); if (Res && *Res == true) return replaceOperand(SI, 0, A); } diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp index 4ada263..6b648f8 100644 --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -1274,7 +1274,7 @@ bool JumpThreadingPass::processImpliedCondition(BasicBlock *BB) { return false; bool CondIsTrue = PBI->getSuccessor(0) == CurrentBB; - Optional Implication = + std::optional Implication = isImpliedCondition(PBI->getCondition(), Cond, DL, CondIsTrue); // If the branch condition of BB (which is Cond) and CurrentPred are diff --git a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp index 13f26ed..fbf2ee5 100644 --- a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp +++ b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp @@ -936,7 +936,7 @@ private: /// Check whether the loop metadata is forcing distribution to be /// enabled/disabled. void setForced() { - Optional Value = + std::optional Value = findStringMetadataForLoop(L, "llvm.loop.distribute.enable"); if (!Value) return; diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp index aaeb09a..34b46ad 100644 --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -462,7 +462,7 @@ Instruction *MemCpyOptPass::tryMergingIntoMemset(Instruction *StartInst, break; // Check to see if this store is to a constant offset from the start ptr. - Optional Offset = + std::optional Offset = isPointerOffset(StartPtr, NextStore->getPointerOperand(), DL); if (!Offset) break; @@ -476,7 +476,8 @@ Instruction *MemCpyOptPass::tryMergingIntoMemset(Instruction *StartInst, break; // Check to see if this store is to a constant offset from the start ptr. - Optional Offset = isPointerOffset(StartPtr, MSI->getDest(), DL); + std::optional Offset = + isPointerOffset(StartPtr, MSI->getDest(), DL); if (!Offset) break; diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp index 0e4576f..1f381be 100644 --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -390,7 +390,7 @@ TransformationMode llvm::hasUnrollAndJamTransformation(const Loop *L) { } TransformationMode llvm::hasVectorizeTransformation(const Loop *L) { - Optional Enable = + std::optional Enable = getOptionalBoolLoopAttribute(L, "llvm.loop.vectorize.enable"); if (Enable == false) diff --git a/llvm/lib/Transforms/Utils/ModuleUtils.cpp b/llvm/lib/Transforms/Utils/ModuleUtils.cpp index 1b2eb41..fbdc3fd 100644 --- a/llvm/lib/Transforms/Utils/ModuleUtils.cpp +++ b/llvm/lib/Transforms/Utils/ModuleUtils.cpp @@ -272,7 +272,7 @@ void VFABI::setVectorVariantNames(CallInst *CI, #ifndef NDEBUG for (const std::string &VariantMapping : VariantMappings) { LLVM_DEBUG(dbgs() << "VFABI: adding mapping '" << VariantMapping << "'\n"); - Optional VI = VFABI::tryDemangleForVFABI(VariantMapping, *M); + std::optional VI = VFABI::tryDemangleForVFABI(VariantMapping, *M); assert(VI && "Cannot add an invalid VFABI name."); assert(M->getNamedValue(VI.value().VectorName) && "Cannot add variant to attribute: " diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 7277c73..0836921 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -7169,7 +7169,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) { // If this basic block has dominating predecessor blocks and the dominating // blocks' conditions imply BI's condition, we know the direction of BI. - Optional Imp = isImpliedByDomCondition(BI->getCondition(), BI, DL); + std::optional Imp = isImpliedByDomCondition(BI->getCondition(), BI, DL); if (Imp) { // Turn this into a branch on constant. auto *OldCond = BI->getCondition(); diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index be94178..0c23b29 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -1289,7 +1289,7 @@ public: !LI2->isSimple()) return LookAheadHeuristics::ScoreFail; - Optional Dist = getPointersDiff( + std::optional Dist = getPointersDiff( LI1->getType(), LI1->getPointerOperand(), LI2->getType(), LI2->getPointerOperand(), DL, SE, /*StrictCheck=*/true); if (!Dist || *Dist == 0) { @@ -3734,7 +3734,7 @@ static LoadsState canVectorizeLoads(ArrayRef VL, const Value *VL0, Ptr0 = PointerOps[Order.front()]; PtrN = PointerOps[Order.back()]; } - Optional Diff = + std::optional Diff = getPointersDiff(ScalarTy, Ptr0, ScalarTy, PtrN, DL, SE); // Check that the sorted loads are consecutive. if (static_cast(*Diff) == VL.size() - 1) @@ -3782,7 +3782,7 @@ bool clusterSortPtrAccesses(ArrayRef VL, Type *ElemTy, unsigned Cnt = 1; for (Value *Ptr : VL.drop_front()) { bool Found = any_of(Bases, [&](auto &Base) { - Optional Diff = + std::optional Diff = getPointersDiff(ElemTy, Base.first, ElemTy, Ptr, DL, SE, /*StrictCheck=*/true); if (!Diff) @@ -4743,7 +4743,7 @@ bool BoUpSLP::canFormVector(const SmallVector &StoresVec, Value *S0Ptr = S0->getPointerOperand(); for (unsigned Idx : seq(1, StoresVec.size())) { StoreInst *SI = StoresVec[Idx]; - Optional Diff = + std::optional Diff = getPointersDiff(S0Ty, S0Ptr, SI->getValueOperand()->getType(), SI->getPointerOperand(), *DL, *SE, /*StrictCheck=*/true); @@ -5751,7 +5751,7 @@ void BoUpSLP::buildTree_rec(ArrayRef VL, unsigned Depth, Ptr0 = PointerOps[CurrentOrder.front()]; PtrN = PointerOps[CurrentOrder.back()]; } - Optional Dist = + std::optional Dist = getPointersDiff(ScalarTy, Ptr0, ScalarTy, PtrN, *DL, *SE); // Check that the sorted pointer operands are consecutive. if (static_cast(*Dist) == VL.size() - 1) { @@ -10959,7 +10959,7 @@ bool SLPVectorizerPass::vectorizeStores(ArrayRef Stores, ++IterCnt; CheckedPairs[Idx].set(K); CheckedPairs[K].set(Idx); - Optional Diff = getPointersDiff( + std::optional Diff = getPointersDiff( Stores[K]->getValueOperand()->getType(), Stores[K]->getPointerOperand(), Stores[Idx]->getValueOperand()->getType(), Stores[Idx]->getPointerOperand(), *DL, *SE, /*StrictCheck=*/true); diff --git a/llvm/unittests/ADT/PostOrderIteratorTest.cpp b/llvm/unittests/ADT/PostOrderIteratorTest.cpp index e9ab251..528d4bc 100644 --- a/llvm/unittests/ADT/PostOrderIteratorTest.cpp +++ b/llvm/unittests/ADT/PostOrderIteratorTest.cpp @@ -22,18 +22,18 @@ TEST(PostOrderIteratorTest, Compiles) { // Tests that template specializations are kept up to date void *Null = nullptr; po_iterator_storage, false> PIS; - PIS.insertEdge(Optional(), Null); + PIS.insertEdge(std::optional(), Null); ExtSetTy Ext; po_iterator_storage PISExt(Ext); - PIS.insertEdge(Optional(), Null); + PIS.insertEdge(std::optional(), Null); // Test above, but going through po_iterator (which inherits from template // base) BasicBlock *NullBB = nullptr; auto PI = po_end(NullBB); - PI.insertEdge(Optional(), NullBB); + PI.insertEdge(std::optional(), NullBB); auto PIExt = po_ext_end(NullBB, Ext); - PIExt.insertEdge(Optional(), NullBB); + PIExt.insertEdge(std::optional(), NullBB); } // Test post-order and reverse post-order traversals for simple graph type. diff --git a/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp b/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp index 206f6c2..d2ffff1 100644 --- a/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp +++ b/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp @@ -56,7 +56,7 @@ protected: } }; - llvm::Optional Analyses; + std::optional Analyses; TestAnalyses &setupAnalyses() { assert(F); diff --git a/llvm/unittests/Analysis/LoopInfoTest.cpp b/llvm/unittests/Analysis/LoopInfoTest.cpp index c7b69ea..1264671 100644 --- a/llvm/unittests/Analysis/LoopInfoTest.cpp +++ b/llvm/unittests/Analysis/LoopInfoTest.cpp @@ -270,7 +270,7 @@ TEST(LoopInfoTest, CanonicalLoop) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -329,7 +329,7 @@ TEST(LoopInfoTest, LoopWithInverseGuardSuccs) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -388,7 +388,7 @@ TEST(LoopInfoTest, LoopWithSwappedGuardCmp) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -447,7 +447,7 @@ TEST(LoopInfoTest, LoopWithInverseLatchSuccs) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -506,7 +506,7 @@ TEST(LoopInfoTest, LoopWithLatchCmpNE) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -566,7 +566,7 @@ TEST(LoopInfoTest, LoopWithGuardCmpSLE) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -625,7 +625,7 @@ TEST(LoopInfoTest, LoopNonConstantStep) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -681,7 +681,7 @@ TEST(LoopInfoTest, LoopUnsignedBounds) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -740,7 +740,7 @@ TEST(LoopInfoTest, DecreasingLoop) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); EXPECT_EQ(Bounds->getInitialIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); @@ -800,7 +800,7 @@ TEST(LoopInfoTest, CannotFindDirection) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -860,7 +860,7 @@ TEST(LoopInfoTest, ZextIndVar) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -921,7 +921,7 @@ TEST(LoopInfoTest, MultiExitingLoop) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -981,7 +981,7 @@ TEST(LoopInfoTest, MultiExitLoop) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -1033,7 +1033,7 @@ TEST(LoopInfoTest, UnguardedLoop) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -1091,7 +1091,7 @@ TEST(LoopInfoTest, UnguardedLoopWithControlFlow) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -1162,7 +1162,7 @@ TEST(LoopInfoTest, LoopNest) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); @@ -1188,7 +1188,7 @@ TEST(LoopInfoTest, LoopNest) { L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional InnerBounds = L->getBounds(SE); + std::optional InnerBounds = L->getBounds(SE); EXPECT_NE(InnerBounds, std::nullopt); InitialIVValue = dyn_cast(&InnerBounds->getInitialIVValue()); @@ -1255,7 +1255,7 @@ TEST(LoopInfoTest, AuxiliaryIV) { Loop *L = LI.getLoopFor(Header); EXPECT_NE(L, nullptr); - Optional Bounds = L->getBounds(SE); + std::optional Bounds = L->getBounds(SE); EXPECT_NE(Bounds, std::nullopt); ConstantInt *InitialIVValue = dyn_cast(&Bounds->getInitialIVValue()); diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp index c6821fa..8756e2c 100644 --- a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp +++ b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp @@ -1148,7 +1148,7 @@ TEST_F(ScalarEvolutionsTest, SCEVComputeConstantDifference) { auto *ScevXB = SE.getSCEV(getInstructionByName(F, "xb")); // {%pp,+,1} auto *ScevIVNext = SE.getSCEV(getInstructionByName(F, "iv.next")); // {1,+,1} - auto diff = [&SE](const SCEV *LHS, const SCEV *RHS) -> Optional { + auto diff = [&SE](const SCEV *LHS, const SCEV *RHS) -> std::optional { auto ConstantDiffOrNone = computeConstantDifference(SE, LHS, RHS); if (!ConstantDiffOrNone) return std::nullopt; diff --git a/llvm/unittests/Analysis/TensorSpecTest.cpp b/llvm/unittests/Analysis/TensorSpecTest.cpp index 4f9575c..09f4ada 100644 --- a/llvm/unittests/Analysis/TensorSpecTest.cpp +++ b/llvm/unittests/Analysis/TensorSpecTest.cpp @@ -25,7 +25,7 @@ TEST(TensorSpecTest, JSONParsing) { })"); EXPECT_TRUE(!!Value); LLVMContext Ctx; - Optional Spec = getTensorSpecFromJSON(Ctx, *Value); + std::optional Spec = getTensorSpecFromJSON(Ctx, *Value); EXPECT_TRUE(Spec); EXPECT_EQ(*Spec, TensorSpec::createSpec("tensor_name", {1, 4}, 2)); }