[llvm] d4b6fcb - [Analysis] llvm::Optional => std::optional
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 13 23:32:32 PST 2022
Author: Fangrui Song
Date: 2022-12-14T07:32:24Z
New Revision: d4b6fcb32e29d0cd834a3c89205fef48fbfc1d2d
URL: https://github.com/llvm/llvm-project/commit/d4b6fcb32e29d0cd834a3c89205fef48fbfc1d2d
DIFF: https://github.com/llvm/llvm-project/commit/d4b6fcb32e29d0cd834a3c89205fef48fbfc1d2d.diff
LOG: [Analysis] llvm::Optional => std::optional
Added:
Modified:
llvm/include/llvm/ADT/PostOrderIterator.h
llvm/include/llvm/Analysis/AliasAnalysis.h
llvm/include/llvm/Analysis/BranchProbabilityInfo.h
llvm/include/llvm/Analysis/CallGraph.h
llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
llvm/include/llvm/Analysis/InlineAdvisor.h
llvm/include/llvm/Analysis/InlineCost.h
llvm/include/llvm/Analysis/InlineSizeEstimatorAnalysis.h
llvm/include/llvm/Analysis/LoopAccessAnalysis.h
llvm/include/llvm/Analysis/LoopCacheAnalysis.h
llvm/include/llvm/Analysis/LoopInfo.h
llvm/include/llvm/Analysis/LoopIterator.h
llvm/include/llvm/Analysis/ModelUnderTrainingRunner.h
llvm/include/llvm/Analysis/MustExecute.h
llvm/include/llvm/Analysis/ObjCARCUtil.h
llvm/include/llvm/Analysis/ProfileSummaryInfo.h
llvm/include/llvm/Analysis/SyntheticCountsUtils.h
llvm/include/llvm/Analysis/TensorSpec.h
llvm/include/llvm/Analysis/Utils/TFUtils.h
llvm/include/llvm/Analysis/ValueLattice.h
llvm/include/llvm/Analysis/ValueTracking.h
llvm/include/llvm/Analysis/VectorUtils.h
llvm/lib/Analysis/AliasAnalysis.cpp
llvm/lib/Analysis/AliasAnalysisSummary.cpp
llvm/lib/Analysis/AliasAnalysisSummary.h
llvm/lib/Analysis/BranchProbabilityInfo.cpp
llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
llvm/lib/Analysis/IRSimilarityIdentifier.cpp
llvm/lib/Analysis/InlineAdvisor.cpp
llvm/lib/Analysis/InlineCost.cpp
llvm/lib/Analysis/InlineOrder.cpp
llvm/lib/Analysis/InstructionSimplify.cpp
llvm/lib/Analysis/LazyValueInfo.cpp
llvm/lib/Analysis/LoopAccessAnalysis.cpp
llvm/lib/Analysis/LoopCacheAnalysis.cpp
llvm/lib/Analysis/LoopInfo.cpp
llvm/lib/Analysis/LoopNestAnalysis.cpp
llvm/lib/Analysis/MemoryBuiltins.cpp
llvm/lib/Analysis/MemorySSA.cpp
llvm/lib/Analysis/ModelUnderTrainingRunner.cpp
llvm/lib/Analysis/MustExecute.cpp
llvm/lib/Analysis/ProfileSummaryInfo.cpp
llvm/lib/Analysis/ReplayInlineAdvisor.cpp
llvm/lib/Analysis/StratifiedSets.h
llvm/lib/Analysis/TFLiteUtils.cpp
llvm/lib/Analysis/TensorSpec.cpp
llvm/lib/Analysis/VFABIDemangling.cpp
llvm/lib/Analysis/ValueTracking.cpp
llvm/lib/Analysis/VectorUtils.cpp
llvm/lib/CodeGen/MachineTraceMetrics.cpp
llvm/lib/Target/AArch64/AArch64StackTagging.cpp
llvm/lib/Transforms/IPO/IROutliner.cpp
llvm/lib/Transforms/IPO/SyntheticCountsPropagation.cpp
llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
llvm/lib/Transforms/Scalar/JumpThreading.cpp
llvm/lib/Transforms/Scalar/LoopDistribute.cpp
llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/lib/Transforms/Utils/ModuleUtils.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
llvm/unittests/ADT/PostOrderIteratorTest.cpp
llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp
llvm/unittests/Analysis/LoopInfoTest.cpp
llvm/unittests/Analysis/ScalarEvolutionTest.cpp
llvm/unittests/Analysis/TensorSpecTest.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ADT/PostOrderIterator.h b/llvm/include/llvm/ADT/PostOrderIterator.h
index d0366045fa095..a80eed78c94d1 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 <iterator>
+#include <optional>
#include <set>
#include <utility>
#include <vector>
@@ -62,7 +62,7 @@ class po_iterator_storage {
public:
// Return true if edge destination should be visited.
template <typename NodeRef>
- bool insertEdge(Optional<NodeRef> From, NodeRef To) {
+ bool insertEdge(std::optional<NodeRef> From, NodeRef To) {
return Visited.insert(To).second;
}
@@ -82,7 +82,8 @@ class po_iterator_storage<SetType, true> {
// 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 <class NodeRef> bool insertEdge(Optional<NodeRef> From, NodeRef To) {
+ template <class NodeRef>
+ bool insertEdge(std::optional<NodeRef> From, NodeRef To) {
return Visited.insert(To).second;
}
@@ -110,7 +111,7 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
SmallVector<std::pair<NodeRef, ChildItTy>, 8> VisitStack;
po_iterator(NodeRef BB) {
- this->insertEdge(Optional<NodeRef>(), BB);
+ this->insertEdge(std::optional<NodeRef>(), BB);
VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
traverseChild();
}
@@ -119,7 +120,7 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
po_iterator(NodeRef BB, SetType &S)
: po_iterator_storage<SetType, ExtStorage>(S) {
- if (this->insertEdge(Optional<NodeRef>(), BB)) {
+ if (this->insertEdge(std::optional<NodeRef>(), BB)) {
VisitStack.push_back(std::make_pair(BB, GT::child_begin(BB)));
traverseChild();
}
@@ -132,7 +133,8 @@ class po_iterator : public po_iterator_storage<SetType, ExtStorage> {
void traverseChild() {
while (VisitStack.back().second != GT::child_end(VisitStack.back().first)) {
NodeRef BB = *VisitStack.back().second++;
- if (this->insertEdge(Optional<NodeRef>(VisitStack.back().first), BB)) {
+ if (this->insertEdge(std::optional<NodeRef>(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 99d10cba6b5bb..1c033d729fb84 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 <cstdint>
#include <functional>
#include <memory>
+#include <optional>
#include <vector>
namespace llvm {
@@ -486,7 +486,7 @@ class AAResults {
/// call-site mod-ref behavior queries. Otherwise it delegates to the specific
/// helpers above.
ModRefInfo getModRefInfo(const Instruction *I,
- const Optional<MemoryLocation> &OptLoc) {
+ const std::optional<MemoryLocation> &OptLoc) {
SimpleAAQueryInfo AAQIP(*this);
return getModRefInfo(I, OptLoc, AAQIP);
}
@@ -577,7 +577,7 @@ class AAResults {
ModRefInfo getModRefInfo(const CatchReturnInst *I, const MemoryLocation &Loc,
AAQueryInfo &AAQI);
ModRefInfo getModRefInfo(const Instruction *I,
- const Optional<MemoryLocation> &OptLoc,
+ const std::optional<MemoryLocation> &OptLoc,
AAQueryInfo &AAQIP);
ModRefInfo callCapturesBefore(const Instruction *I,
const MemoryLocation &MemLoc, DominatorTree *DT,
@@ -626,7 +626,7 @@ class BatchAAResults {
return AA.getModRefInfoMask(Loc, AAQI, IgnoreLocals);
}
ModRefInfo getModRefInfo(const Instruction *I,
- const Optional<MemoryLocation> &OptLoc) {
+ const std::optional<MemoryLocation> &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 0e6e1c774aa49..14d3080b50530 100644
--- a/llvm/include/llvm/Analysis/BranchProbabilityInfo.h
+++ b/llvm/include/llvm/Analysis/BranchProbabilityInfo.h
@@ -359,22 +359,22 @@ class BranchProbabilityInfo {
/// Returns estimated weight for \p BB. std::nullopt if \p BB has no estimated
/// weight.
- Optional<uint32_t> getEstimatedBlockWeight(const BasicBlock *BB) const;
+ std::optional<uint32_t> 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<uint32_t> getEstimatedLoopWeight(const LoopData &L) const;
+ std::optional<uint32_t> getEstimatedLoopWeight(const LoopData &L) const;
/// Return estimated weight for \p Edge. Returns std::nullopt if estimated
/// weight is unknown.
- Optional<uint32_t> getEstimatedEdgeWeight(const LoopEdge &Edge) const;
+ std::optional<uint32_t> 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 <class IterT>
- Optional<uint32_t>
+ std::optional<uint32_t>
getMaxEstimatedEdgeWeight(const LoopBlock &SrcBB,
iterator_range<IterT> Successors) const;
@@ -394,7 +394,7 @@ class BranchProbabilityInfo {
SmallVectorImpl<LoopBlock> &LoopWorkList);
/// Returns block's weight encoded in the IR.
- Optional<uint32_t> getInitialEstimatedBlockWeight(const BasicBlock *BB);
+ std::optional<uint32_t> 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 df38ea424fd9c..3461c692f3a3e 100644
--- a/llvm/include/llvm/Analysis/CallGraph.h
+++ b/llvm/include/llvm/Analysis/CallGraph.h
@@ -175,7 +175,7 @@ class CallGraphNode {
/// 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<Optional<WeakTrackingVH>, CallGraphNode *>;
+ using CallRecord = std::pair<std::optional<WeakTrackingVH>, CallGraphNode *>;
public:
using CalledFunctionsVector = std::vector<CallRecord>;
@@ -243,8 +243,9 @@ class CallGraphNode {
assert(!Call || !Call->getCalledFunction() ||
!Call->getCalledFunction()->isIntrinsic() ||
!Intrinsic::isLeaf(Call->getCalledFunction()->getIntrinsicID()));
- CalledFunctions.emplace_back(
- Call ? Optional<WeakTrackingVH>(Call) : Optional<WeakTrackingVH>(), M);
+ CalledFunctions.emplace_back(Call ? std::optional<WeakTrackingVH>(Call)
+ : std::optional<WeakTrackingVH>(),
+ M);
M->AddRef();
}
diff --git a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
index 56233674971a3..91af95b3f002f 100644
--- a/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
+++ b/llvm/include/llvm/Analysis/IRSimilarityIdentifier.h
@@ -889,7 +889,7 @@ class IRSimilarityCandidate {
/// \param [in] V - the Value to find.
/// \returns The positive number corresponding to the value.
/// \returns std::nullopt if not present.
- Optional<unsigned> getGVN(Value *V) {
+ std::optional<unsigned> getGVN(Value *V) {
assert(V != nullptr && "Value is a nullptr?");
DenseMap<Value *, unsigned>::iterator VNIt = ValueToNumber.find(V);
if (VNIt == ValueToNumber.end())
@@ -901,7 +901,7 @@ class IRSimilarityCandidate {
/// \param [in] Num - the number to find.
/// \returns The Value associated with the number.
/// \returns std::nullopt if not present.
- Optional<Value *> fromGVN(unsigned Num) {
+ std::optional<Value *> fromGVN(unsigned Num) {
DenseMap<unsigned, Value *>::iterator VNIt = NumberToValue.find(Num);
if (VNIt == NumberToValue.end())
return std::nullopt;
@@ -915,7 +915,7 @@ class IRSimilarityCandidate {
/// \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<unsigned> getCanonicalNum(unsigned N) {
+ std::optional<unsigned> getCanonicalNum(unsigned N) {
DenseMap<unsigned, unsigned>::iterator NCIt = NumberToCanonNum.find(N);
if (NCIt == NumberToCanonNum.end())
return std::nullopt;
@@ -928,7 +928,7 @@ class IRSimilarityCandidate {
/// \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<unsigned> fromCanonicalNum(unsigned N) {
+ std::optional<unsigned> fromCanonicalNum(unsigned N) {
DenseMap<unsigned, unsigned>::iterator CNIt = CanonNumToNumber.find(N);
if (CNIt == CanonNumToNumber.end())
return std::nullopt;
@@ -1048,7 +1048,7 @@ class IRSimilarityIdentifier {
// \returns The groups of similarity ranges found in the most recently passed
// set of modules.
- Optional<SimilarityGroupList> &getSimilarity() {
+ std::optional<SimilarityGroupList> &getSimilarity() {
return SimilarityCandidates;
}
@@ -1086,7 +1086,7 @@ class IRSimilarityIdentifier {
/// The SimilarityGroups found with the most recent run of \ref
/// findSimilarity. std::nullopt if there is no recent run.
- Optional<SimilarityGroupList> SimilarityCandidates;
+ std::optional<SimilarityGroupList> SimilarityCandidates;
};
} // end namespace IRSimilarity
diff --git a/llvm/include/llvm/Analysis/InlineAdvisor.h b/llvm/include/llvm/Analysis/InlineAdvisor.h
index 150ae978b2f25..861cf63098927 100644
--- a/llvm/include/llvm/Analysis/InlineAdvisor.h
+++ b/llvm/include/llvm/Analysis/InlineAdvisor.h
@@ -143,8 +143,8 @@ class InlineAdvice {
class DefaultInlineAdvice : public InlineAdvice {
public:
DefaultInlineAdvice(InlineAdvisor *Advisor, CallBase &CB,
- Optional<InlineCost> OIC, OptimizationRemarkEmitter &ORE,
- bool EmitRemarks = true)
+ std::optional<InlineCost> OIC,
+ OptimizationRemarkEmitter &ORE, bool EmitRemarks = true)
: InlineAdvice(Advisor, CB, ORE, OIC.has_value()), OriginalCB(&CB),
OIC(OIC), EmitRemarks(EmitRemarks) {}
@@ -155,7 +155,7 @@ class DefaultInlineAdvice : public InlineAdvice {
private:
CallBase *const OriginalCB;
- Optional<InlineCost> OIC;
+ std::optional<InlineCost> OIC;
bool EmitRemarks;
};
@@ -200,14 +200,14 @@ class InlineAdvisor {
protected:
InlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
- Optional<InlineContext> IC = std::nullopt);
+ std::optional<InlineContext> IC = std::nullopt);
virtual std::unique_ptr<InlineAdvice> getAdviceImpl(CallBase &CB) = 0;
virtual std::unique_ptr<InlineAdvice> getMandatoryAdvice(CallBase &CB,
bool Advice);
Module &M;
FunctionAnalysisManager &FAM;
- const Optional<InlineContext> IC;
+ const std::optional<InlineContext> IC;
const std::string AnnotatedInlinePassName;
std::unique_ptr<ImportedFunctionsInliningStatistics> 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<InlineCost>
+std::optional<InlineCost>
shouldInline(CallBase &CB, function_ref<InlineCost(CallBase &CB)> GetInlineCost,
OptimizationRemarkEmitter &ORE, bool EnableDeferral = true);
diff --git a/llvm/include/llvm/Analysis/InlineCost.h b/llvm/include/llvm/Analysis/InlineCost.h
index bac159f37ddde..0c73df93be2fc 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<CostBenefitPair> CostBenefit = std::nullopt;
+ std::optional<CostBenefitPair> CostBenefit = std::nullopt;
// Trivial constructor, interesting logic in the factory functions below.
InlineCost(int Cost, int Threshold, int StaticBonusApplied,
const char *Reason = nullptr,
- Optional<CostBenefitPair> CostBenefit = std::nullopt)
+ std::optional<CostBenefitPair> CostBenefit = std::nullopt)
: Cost(Cost), Threshold(Threshold),
StaticBonusApplied(StaticBonusApplied), Reason(Reason),
CostBenefit(CostBenefit) {
@@ -124,12 +124,12 @@ class InlineCost {
}
static InlineCost
getAlways(const char *Reason,
- Optional<CostBenefitPair> CostBenefit = std::nullopt) {
+ std::optional<CostBenefitPair> CostBenefit = std::nullopt) {
return InlineCost(AlwaysInlineCost, 0, 0, Reason, CostBenefit);
}
static InlineCost
getNever(const char *Reason,
- Optional<CostBenefitPair> CostBenefit = std::nullopt) {
+ std::optional<CostBenefitPair> CostBenefit = std::nullopt) {
return InlineCost(NeverInlineCost, 0, 0, Reason, CostBenefit);
}
@@ -160,7 +160,7 @@ class InlineCost {
}
/// Get the cost-benefit pair which was computed by cost-benefit analysis
- Optional<CostBenefitPair> getCostBenefit() const { return CostBenefit; }
+ std::optional<CostBenefitPair> 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<int> HintThreshold;
+ std::optional<int> HintThreshold;
/// Threshold to use for cold callees.
- Optional<int> ColdThreshold;
+ std::optional<int> ColdThreshold;
/// Threshold to use when the caller is optimized for size.
- Optional<int> OptSizeThreshold;
+ std::optional<int> OptSizeThreshold;
/// Threshold to use when the caller is optimized for minsize.
- Optional<int> OptMinSizeThreshold;
+ std::optional<int> OptMinSizeThreshold;
/// Threshold to use when the callsite is considered hot.
- Optional<int> HotCallSiteThreshold;
+ std::optional<int> HotCallSiteThreshold;
/// Threshold to use when the callsite is considered hot relative to function
/// entry.
- Optional<int> LocallyHotCallSiteThreshold;
+ std::optional<int> LocallyHotCallSiteThreshold;
/// Threshold to use when the callsite is considered cold.
- Optional<int> ColdCallSiteThreshold;
+ std::optional<int> ColdCallSiteThreshold;
/// Compute inline cost even when the cost has exceeded the threshold.
std::optional<bool> ComputeFullInlineCost;
@@ -239,7 +239,7 @@ struct InlineParams {
std::optional<bool> AllowRecursiveCall = false;
};
-Optional<int> getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind);
+std::optional<int> 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<InlineResult> getAttributeBasedInliningDecision(
+std::optional<InlineResult> getAttributeBasedInliningDecision(
CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI,
function_ref<const TargetLibraryInfo &(Function &)> GetTLI);
@@ -314,7 +314,7 @@ Optional<InlineResult> getAttributeBasedInliningDecision(
/// returns:
/// - std::nullopt, if the inlining cannot happen (is illegal)
/// - an integer, representing the cost.
-Optional<int> getInliningCostEstimate(
+std::optional<int> getInliningCostEstimate(
CallBase &Call, TargetTransformInfo &CalleeTTI,
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,
@@ -323,7 +323,7 @@ Optional<int> getInliningCostEstimate(
/// Get the expanded cost features. The features are returned unconditionally,
/// even if inlining is impossible.
-Optional<InlineCostFeatures> getInliningCostFeatures(
+std::optional<InlineCostFeatures> getInliningCostFeatures(
CallBase &Call, TargetTransformInfo &CalleeTTI,
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
function_ref<BlockFrequencyInfo &(Function &)> GetBFI = nullptr,
diff --git a/llvm/include/llvm/Analysis/InlineSizeEstimatorAnalysis.h b/llvm/include/llvm/Analysis/InlineSizeEstimatorAnalysis.h
index ab2cf52494c01..0aae696a98a92 100644
--- a/llvm/include/llvm/Analysis/InlineSizeEstimatorAnalysis.h
+++ b/llvm/include/llvm/Analysis/InlineSizeEstimatorAnalysis.h
@@ -24,7 +24,7 @@ class InlineSizeEstimatorAnalysis
~InlineSizeEstimatorAnalysis();
static AnalysisKey Key;
- using Result = Optional<size_t>;
+ using Result = std::optional<size_t>;
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 67a7f9ce0bc05..a49e24ada4406 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<int64_t>
+std::optional<int64_t>
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<int> getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB,
- Value *PtrB, const DataLayout &DL,
- ScalarEvolution &SE, bool StrictCheck = false,
- bool CheckType = true);
+std::optional<int> 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 2e4f0c469afee..c9e853b9be8e6 100644
--- a/llvm/include/llvm/Analysis/LoopCacheAnalysis.h
+++ b/llvm/include/llvm/Analysis/LoopCacheAnalysis.h
@@ -73,16 +73,16 @@ class IndexedReference {
/// 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<bool> hasSpacialReuse(const IndexedReference &Other, unsigned CLS,
- AAResults &AA) const;
+ std::optional<bool> 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<bool> hasTemporalReuse(const IndexedReference &Other,
- unsigned MaxDistance, const Loop &L,
- DependenceInfo &DI, AAResults &AA) const;
+ std::optional<bool> 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 @@ class CacheCost {
/// classified to have temporal reuse.
CacheCost(const LoopVectorTy &Loops, const LoopInfo &LI, ScalarEvolution &SE,
TargetTransformInfo &TTI, AAResults &AA, DependenceInfo &DI,
- Optional<unsigned> TRT = std::nullopt);
+ std::optional<unsigned> 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 @@ class CacheCost {
/// classified to have temporal reuse.
static std::unique_ptr<CacheCost>
getCacheCost(Loop &Root, LoopStandardAnalysisResults &AR, DependenceInfo &DI,
- Optional<unsigned> TRT = std::nullopt);
+ std::optional<unsigned> 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 278ad92aaa3ba..b77a335d1ee60 100644
--- a/llvm/include/llvm/Analysis/LoopInfo.h
+++ b/llvm/include/llvm/Analysis/LoopInfo.h
@@ -665,8 +665,8 @@ class LLVM_EXTERNAL_VISIBILITY Loop : public LoopBase<BasicBlock, Loop> {
/// - the final value of the induction variable can be found
///
/// Else None.
- static Optional<Loop::LoopBounds> getBounds(const Loop &L, PHINode &IndVar,
- ScalarEvolution &SE);
+ static std::optional<Loop::LoopBounds>
+ 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 @@ class LLVM_EXTERNAL_VISIBILITY Loop : public LoopBase<BasicBlock, Loop> {
/// Return the struct LoopBounds collected if all struct members are found,
/// else std::nullopt.
- Optional<LoopBounds> getBounds(ScalarEvolution &SE) const;
+ std::optional<LoopBounds> 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<bool> getOptionalBoolLoopAttribute(const Loop *TheLoop,
- StringRef Name);
-
+std::optional<bool> 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<const MDOperand *> findStringMetadataForLoop(const Loop *TheLoop,
- StringRef Name);
+std::optional<const MDOperand *> 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 fa4da4283f55a..360f196a80daf 100644
--- a/llvm/include/llvm/Analysis/LoopIterator.h
+++ b/llvm/include/llvm/Analysis/LoopIterator.h
@@ -192,7 +192,7 @@ template<> class po_iterator_storage<LoopBlocksTraversal, true> {
public:
po_iterator_storage(LoopBlocksTraversal &lbs) : LBT(lbs) {}
// These functions are defined below.
- bool insertEdge(Optional<BasicBlock *> From, BasicBlock *To);
+ bool insertEdge(std::optional<BasicBlock *> From, BasicBlock *To);
void finishPostorder(BasicBlock *BB);
};
@@ -245,7 +245,7 @@ class LoopBlocksTraversal {
};
inline bool po_iterator_storage<LoopBlocksTraversal, true>::insertEdge(
- Optional<BasicBlock *> From, BasicBlock *To) {
+ std::optional<BasicBlock *> From, BasicBlock *To) {
return LBT.visitPreorder(To);
}
diff --git a/llvm/include/llvm/Analysis/ModelUnderTrainingRunner.h b/llvm/include/llvm/Analysis/ModelUnderTrainingRunner.h
index 1c4d5048f232b..7e29bbd2be096 100644
--- a/llvm/include/llvm/Analysis/ModelUnderTrainingRunner.h
+++ b/llvm/include/llvm/Analysis/ModelUnderTrainingRunner.h
@@ -42,7 +42,7 @@ class ModelUnderTrainingRunner final : public MLModelRunner {
return lastEvaluationResult()->getUntypedTensorValue(ExtraOutputIndex + 1);
}
- const Optional<TFModelEvaluator::EvaluationResult> &
+ const std::optional<TFModelEvaluator::EvaluationResult> &
lastEvaluationResult() const {
return LastEvaluationResult;
}
@@ -68,7 +68,7 @@ class ModelUnderTrainingRunner final : public MLModelRunner {
std::unique_ptr<TFModelEvaluator> Evaluator;
const std::vector<TensorSpec> OutputSpecs;
const std::vector<TensorSpec> ExtraOutputsForLogging;
- Optional<TFModelEvaluator::EvaluationResult> LastEvaluationResult;
+ std::optional<TFModelEvaluator::EvaluationResult> LastEvaluationResult;
void *evaluateUntyped() override;
};
diff --git a/llvm/include/llvm/Analysis/MustExecute.h b/llvm/include/llvm/Analysis/MustExecute.h
index 1e49942075554..b83705cb61115 100644
--- a/llvm/include/llvm/Analysis/MustExecute.h
+++ b/llvm/include/llvm/Analysis/MustExecute.h
@@ -528,10 +528,10 @@ struct MustBeExecutedContextExplorer {
///}
/// Map to cache isGuaranteedToTransferExecutionToSuccessor results.
- DenseMap<const BasicBlock *, Optional<bool>> BlockTransferMap;
+ DenseMap<const BasicBlock *, std::optional<bool>> BlockTransferMap;
/// Map to cache containsIrreducibleCFG results.
- DenseMap<const Function*, Optional<bool>> IrreducibleControlMap;
+ DenseMap<const Function *, std::optional<bool>> IrreducibleControlMap;
/// Map from instructions to associated must be executed iterators.
DenseMap<const Instruction *, std::unique_ptr<MustBeExecutedIterator>>
diff --git a/llvm/include/llvm/Analysis/ObjCARCUtil.h b/llvm/include/llvm/Analysis/ObjCARCUtil.h
index 7e27e9aec73f5..62e13eb2a5722 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<Function *> getAttachedARCFunction(const CallBase *CB) {
+inline std::optional<Function *> 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<Function *> Fn = getAttachedARCFunction(CB);
+ std::optional<Function *> 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 9cf8fe3254a5c..292c713f07ca0 100644
--- a/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
+++ b/llvm/include/llvm/Analysis/ProfileSummaryInfo.h
@@ -53,7 +53,7 @@ class ProfileSummaryInfo {
// percentile is above a large threshold.
std::optional<bool> HasLargeWorkingSetSize;
// Compute the threshold for a given cutoff.
- Optional<uint64_t> computeThreshold(int PercentileCutoff) const;
+ std::optional<uint64_t> 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<int, uint64_t> ThresholdCache;
diff --git a/llvm/include/llvm/Analysis/SyntheticCountsUtils.h b/llvm/include/llvm/Analysis/SyntheticCountsUtils.h
index 458b599f2937e..5a6c7dd53c7e5 100644
--- a/llvm/include/llvm/Analysis/SyntheticCountsUtils.h
+++ b/llvm/include/llvm/Analysis/SyntheticCountsUtils.h
@@ -34,7 +34,8 @@ template <typename CallGraphType> class SyntheticCountsUtils {
// 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<Optional<Scaled64>(NodeRef, EdgeRef)>;
+ using GetProfCountTy =
+ function_ref<std::optional<Scaled64>(NodeRef, EdgeRef)>;
using AddCountTy = function_ref<void(NodeRef, Scaled64)>;
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 f8a40a3f20046..3e0db32a22047 100644
--- a/llvm/include/llvm/Analysis/TensorSpec.h
+++ b/llvm/include/llvm/Analysis/TensorSpec.h
@@ -110,8 +110,8 @@ class TensorSpec final {
/// "shape": <array of ints> }
/// For the "type" field, see the C++ primitive types used in
/// TFUTILS_SUPPORTED_TYPES.
-Optional<TensorSpec> getTensorSpecFromJSON(LLVMContext &Ctx,
- const json::Value &Value);
+std::optional<TensorSpec> getTensorSpecFromJSON(LLVMContext &Ctx,
+ const json::Value &Value);
#define TFUTILS_GETDATATYPE_DEF(T, Name) \
template <> TensorType TensorSpec::getDataType<T>();
diff --git a/llvm/include/llvm/Analysis/Utils/TFUtils.h b/llvm/include/llvm/Analysis/Utils/TFUtils.h
index 858f6be9e58a9..04bb8af3a515a 100644
--- a/llvm/include/llvm/Analysis/Utils/TFUtils.h
+++ b/llvm/include/llvm/Analysis/Utils/TFUtils.h
@@ -86,7 +86,7 @@ class TFModelEvaluator final {
/// 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<EvaluationResult> evaluate();
+ std::optional<EvaluationResult> evaluate();
/// Provides access to the input vector.
template <typename T> T *getInput(size_t Index) {
diff --git a/llvm/include/llvm/Analysis/ValueLattice.h b/llvm/include/llvm/Analysis/ValueLattice.h
index cd2d731321c7a..5ae32b5e775e5 100644
--- a/llvm/include/llvm/Analysis/ValueLattice.h
+++ b/llvm/include/llvm/Analysis/ValueLattice.h
@@ -275,7 +275,7 @@ class ValueLatticeElement {
return Range;
}
- Optional<APInt> asConstantInteger() const {
+ std::optional<APInt> asConstantInteger() const {
if (isConstant() && isa<ConstantInt>(getConstant())) {
return cast<ConstantInt>(getConstant())->getValue();
} else if (isConstantRange() && getConstantRange().isSingleElement()) {
diff --git a/llvm/include/llvm/Analysis/ValueTracking.h b/llvm/include/llvm/Analysis/ValueTracking.h
index fa675bbf2e10e..667039e9f39b6 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<bool> isImpliedCondition(const Value *LHS, const Value *RHS,
- const DataLayout &DL, bool LHSIsTrue = true,
- unsigned Depth = 0);
-Optional<bool> isImpliedCondition(const Value *LHS, CmpInst::Predicate RHSPred,
- const Value *RHSOp0, const Value *RHSOp1,
- const DataLayout &DL, bool LHSIsTrue = true,
- unsigned Depth = 0);
+std::optional<bool> isImpliedCondition(const Value *LHS, const Value *RHS,
+ const DataLayout &DL,
+ bool LHSIsTrue = true,
+ unsigned Depth = 0);
+std::optional<bool> 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<bool> isImpliedByDomCondition(const Value *Cond,
- const Instruction *ContextI,
- const DataLayout &DL);
-Optional<bool> isImpliedByDomCondition(CmpInst::Predicate Pred,
- const Value *LHS, const Value *RHS,
- const Instruction *ContextI,
- const DataLayout &DL);
+std::optional<bool> isImpliedByDomCondition(const Value *Cond,
+ const Instruction *ContextI,
+ const DataLayout &DL);
+std::optional<bool> 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<int64_t> isPointerOffset(const Value *Ptr1, const Value *Ptr2,
- const DataLayout &DL);
+std::optional<int64_t> 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 02271d5780c82..b04d08748e242 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<VFInfo> tryDemangleForVFABI(StringRef MangledName, const Module &M);
+std::optional<VFInfo> 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<VFInfo> Shape =
+ const std::optional<VFInfo> 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 1f0494c39d4b6..73de6faf8b18f 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<MemoryLocation> &OptLoc,
+ const std::optional<MemoryLocation> &OptLoc,
AAQueryInfo &AAQIP) {
if (OptLoc == std::nullopt) {
if (const auto *Call = dyn_cast<CallBase>(I))
diff --git a/llvm/lib/Analysis/AliasAnalysisSummary.cpp b/llvm/lib/Analysis/AliasAnalysisSummary.cpp
index 1627c403cc8fa..a91791c0b4d53 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<InstantiatedValue> instantiateInterfaceValue(InterfaceValue IValue,
- CallBase &Call) {
+std::optional<InstantiatedValue>
+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<InstantiatedValue> instantiateInterfaceValue(InterfaceValue IValue,
return std::nullopt;
}
-Optional<InstantiatedRelation>
+std::optional<InstantiatedRelation>
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<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute EAttr,
- CallBase &Call) {
+std::optional<InstantiatedAttr>
+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 10d49f9c0113b..ab337bad22c75 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 <bitset>
+#include <optional>
namespace llvm {
@@ -203,8 +203,8 @@ struct InstantiatedValue {
Value *Val;
unsigned DerefLevel;
};
-Optional<InstantiatedValue> instantiateInterfaceValue(InterfaceValue IValue,
- CallBase &Call);
+std::optional<InstantiatedValue>
+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<InstantiatedRelation>
+std::optional<InstantiatedRelation>
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<InstantiatedAttr> instantiateExternalAttribute(ExternalAttribute EAttr,
- CallBase &Call);
+std::optional<InstantiatedAttr>
+instantiateExternalAttribute(ExternalAttribute EAttr, CallBase &Call);
}
template <> struct DenseMapInfo<cflaa::InstantiatedValue> {
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 1d4159a37b2cc..b99c361cd5e56 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -647,7 +647,7 @@ computeUnlikelySuccessors(const BasicBlock *BB, Loop *L,
}
}
-Optional<uint32_t>
+std::optional<uint32_t>
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<uint32_t>
+std::optional<uint32_t>
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<uint32_t>
+std::optional<uint32_t>
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 <class IterT>
-Optional<uint32_t> BranchProbabilityInfo::getMaxEstimatedEdgeWeight(
+std::optional<uint32_t> BranchProbabilityInfo::getMaxEstimatedEdgeWeight(
const LoopBlock &SrcLoopBB, iterator_range<IterT> Successors) const {
SmallVector<uint32_t, 4> Weights;
- Optional<uint32_t> MaxWeight;
+ std::optional<uint32_t> MaxWeight;
for (const BasicBlock *DstBB : Successors) {
const LoopBlock DstLoopBB = getLoopBlock(DstBB);
auto Weight = getEstimatedEdgeWeight({SrcLoopBB, DstLoopBB});
@@ -767,8 +767,8 @@ void BranchProbabilityInfo::propagateEstimatedBlockWeight(
}
}
-Optional<uint32_t> BranchProbabilityInfo::getInitialEstimatedBlockWeight(
- const BasicBlock *BB) {
+std::optional<uint32_t>
+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<uint32_t> Weight;
+ std::optional<uint32_t> 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 f1719268a6442..0fb6d604bfe2f 100644
--- a/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/DevelopmentModeInlineAdvisor.cpp
@@ -169,7 +169,7 @@ class DevelopmentModeMLInlineAdvisor : public MLInlineAdvisor {
std::unique_ptr<MLInlineAdvice>
getAdviceFromModel(CallBase &CB, OptimizationRemarkEmitter &ORE) override;
- Optional<size_t> getNativeSizeEstimate(const Function &F) const;
+ std::optional<size_t> getNativeSizeEstimate(const Function &F) const;
private:
bool isLogging() const { return !!Logger; }
@@ -179,8 +179,8 @@ class DevelopmentModeMLInlineAdvisor : public MLInlineAdvisor {
const bool IsDoingInference;
std::unique_ptr<TrainingLogger> Logger;
- const Optional<int32_t> InitialNativeSize;
- Optional<int32_t> CurrentNativeSize;
+ const std::optional<int32_t> InitialNativeSize;
+ std::optional<int32_t> CurrentNativeSize;
};
/// A variant of MLInlineAdvice that tracks all non-trivial inlining
@@ -190,8 +190,8 @@ class LoggingMLInlineAdvice : public MLInlineAdvice {
LoggingMLInlineAdvice(DevelopmentModeMLInlineAdvisor *Advisor, CallBase &CB,
OptimizationRemarkEmitter &ORE, bool Recommendation,
TrainingLogger &Logger,
- Optional<size_t> CallerSizeEstimateBefore,
- Optional<size_t> CalleeSizeEstimateBefore,
+ std::optional<size_t> CallerSizeEstimateBefore,
+ std::optional<size_t> CalleeSizeEstimateBefore,
bool DefaultDecision, bool Mandatory = false)
: MLInlineAdvice(Advisor, CB, ORE, Recommendation), Logger(Logger),
CallerSizeEstimateBefore(CallerSizeEstimateBefore),
@@ -257,8 +257,8 @@ class LoggingMLInlineAdvice : public MLInlineAdvice {
static const int64_t NoReward = 0;
TrainingLogger &Logger;
- const Optional<size_t> CallerSizeEstimateBefore;
- const Optional<size_t> CalleeSizeEstimateBefore;
+ const std::optional<size_t> CallerSizeEstimateBefore;
+ const std::optional<size_t> CalleeSizeEstimateBefore;
const int64_t DefaultDecision;
const int64_t Mandatory;
};
@@ -353,7 +353,7 @@ DevelopmentModeMLInlineAdvisor::~DevelopmentModeMLInlineAdvisor() {
Logger->print();
}
-Optional<size_t>
+std::optional<size_t>
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 a681c528e690f..8a11f66b2fe71 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<IRSimilarityAnalysis>(M);
- Optional<SimilarityGroupList> &SimilarityCandidatesOpt = IRSI.getSimilarity();
+ std::optional<SimilarityGroupList> &SimilarityCandidatesOpt =
+ IRSI.getSimilarity();
for (std::vector<IRSimilarityCandidate> &CandVec : *SimilarityCandidatesOpt) {
OS << CandVec.size() << " candidates of length "
diff --git a/llvm/lib/Analysis/InlineAdvisor.cpp b/llvm/lib/Analysis/InlineAdvisor.cpp
index b8e5adc5c61a1..cb21f062f9f4d 100644
--- a/llvm/lib/Analysis/InlineAdvisor.cpp
+++ b/llvm/lib/Analysis/InlineAdvisor.cpp
@@ -130,7 +130,7 @@ void DefaultInlineAdvice::recordInliningImpl() {
Advisor->getAnnotatedInlinePassName());
}
-llvm::Optional<llvm::InlineCost> static getDefaultInlineAdvice(
+std::optional<llvm::InlineCost> 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<InlineCost>
+std::optional<InlineCost>
llvm::shouldInline(CallBase &CB,
function_ref<InlineCost(CallBase &CB)> GetInlineCost,
OptimizationRemarkEmitter &ORE, bool EnableDeferral) {
@@ -514,7 +514,7 @@ void llvm::emitInlinedIntoBasedOnCost(
}
InlineAdvisor::InlineAdvisor(Module &M, FunctionAnalysisManager &FAM,
- Optional<InlineContext> IC)
+ std::optional<InlineContext> 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 ab414f67a22b5..b6f50b8d4dbb9 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -162,7 +162,7 @@ static cl::opt<bool> DisableGEPConstOperand(
cl::desc("Disables evaluation of GetElementPtr with constant operands"));
namespace llvm {
-Optional<int> getStringFnAttrAsInt(const Attribute &Attr) {
+std::optional<int> getStringFnAttrAsInt(const Attribute &Attr) {
if (Attr.isValid()) {
int AttrValue = 0;
if (!Attr.getValueAsString().getAsInteger(10, AttrValue))
@@ -171,11 +171,11 @@ Optional<int> getStringFnAttrAsInt(const Attribute &Attr) {
return std::nullopt;
}
-Optional<int> getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind) {
+std::optional<int> getStringFnAttrAsInt(CallBase &CB, StringRef AttrKind) {
return getStringFnAttrAsInt(CB.getFnAttr(AttrKind));
}
-Optional<int> getStringFnAttrAsInt(Function *F, StringRef AttrKind) {
+std::optional<int> 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<CostBenefitPair> CostBenefit = std::nullopt;
+ std::optional<CostBenefitPair> 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<int> getHotCallSiteThreshold(CallBase &Call,
- BlockFrequencyInfo *CallerBFI);
+ std::optional<int> 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<int> AttrCallThresholdBonus =
+ if (std::optional<int> AttrCallThresholdBonus =
getStringFnAttrAsInt(Call, "call-threshold-bonus"))
Threshold += *AttrCallThresholdBonus;
- if (Optional<int> AttrCallCost =
+ if (std::optional<int> 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<int> AttrCost =
+ if (std::optional<int> AttrCost =
getStringFnAttrAsInt(CandidateCall, "function-inline-cost"))
Cost = *AttrCost;
- if (Optional<int> AttrCostMult = getStringFnAttrAsInt(
+ if (std::optional<int> AttrCostMult = getStringFnAttrAsInt(
CandidateCall,
InlineConstants::FunctionInlineCostMultiplierAttributeName))
Cost *= *AttrCostMult;
- if (Optional<int> AttrThreshold =
+ if (std::optional<int> AttrThreshold =
getStringFnAttrAsInt(CandidateCall, "function-inline-threshold"))
Threshold = *AttrThreshold;
@@ -1053,7 +1053,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
// on the build.
void print(raw_ostream &OS);
- Optional<InstructionCostDetail> getCostDetails(const Instruction *I) {
+ std::optional<InstructionCostDetail> getCostDetails(const Instruction *I) {
if (InstructionCostDetailMap.find(I) != InstructionCostDetailMap.end())
return InstructionCostDetailMap[I];
return std::nullopt;
@@ -1063,7 +1063,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer {
int getThreshold() const { return Threshold; }
int getCost() const { return Cost; }
int getStaticBonusApplied() const { return StaticBonusApplied; }
- Optional<CostBenefitPair> getCostBenefitPair() { return CostBenefit; }
+ std::optional<CostBenefitPair> 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<InstructionCostDetail> Record = ICCA->getCostDetails(I);
+ std::optional<InstructionCostDetail> 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<int>
+std::optional<int>
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<int> B) {
+ auto MinIfValid = [](int A, std::optional<int> B) {
return B ? std::min(A, B.value()) : A;
};
// return max(A, B) if B is valid.
- auto MaxIfValid = [](int A, Optional<int> B) {
+ auto MaxIfValid = [](int A, std::optional<int> 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<int> AttrMaxStackSize = getStringFnAttrAsInt(
+ if (std::optional<int> AttrMaxStackSize = getStringFnAttrAsInt(
Caller, InlineConstants::MaxInlineStackSizeAttributeName))
FinalStackSizeThreshold = *AttrMaxStackSize;
if (AllocatedSize > FinalStackSizeThreshold)
@@ -2829,7 +2829,7 @@ InlineCost llvm::getInlineCost(
GetAssumptionCache, GetTLI, GetBFI, PSI, ORE);
}
-Optional<int> llvm::getInliningCostEstimate(
+std::optional<int> llvm::getInliningCostEstimate(
CallBase &Call, TargetTransformInfo &CalleeTTI,
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
@@ -2854,7 +2854,7 @@ Optional<int> llvm::getInliningCostEstimate(
return CA.getCost();
}
-Optional<InlineCostFeatures> llvm::getInliningCostFeatures(
+std::optional<InlineCostFeatures> llvm::getInliningCostFeatures(
CallBase &Call, TargetTransformInfo &CalleeTTI,
function_ref<AssumptionCache &(Function &)> GetAssumptionCache,
function_ref<BlockFrequencyInfo &(Function &)> GetBFI,
@@ -2867,7 +2867,7 @@ Optional<InlineCostFeatures> llvm::getInliningCostFeatures(
return CFA.features();
}
-Optional<InlineResult> llvm::getAttributeBasedInliningDecision(
+std::optional<InlineResult> llvm::getAttributeBasedInliningDecision(
CallBase &Call, Function *Callee, TargetTransformInfo &CalleeTTI,
function_ref<const TargetLibraryInfo &(Function &)> GetTLI) {
diff --git a/llvm/lib/Analysis/InlineOrder.cpp b/llvm/lib/Analysis/InlineOrder.cpp
index 75f8bb69e3ae2..8d0e49936901d 100644
--- a/llvm/lib/Analysis/InlineOrder.cpp
+++ b/llvm/lib/Analysis/InlineOrder.cpp
@@ -174,7 +174,7 @@ class CostBenefitPriority {
private:
int Cost = INT_MAX;
int StaticBonusApplied = 0;
- Optional<CostBenefitPair> CostBenefit;
+ std::optional<CostBenefitPair> CostBenefit;
};
class MLPriority {
diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp
index ba0c20f00276f..63eee20845200 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<bool> Imp =
+ std::optional<bool> 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<bool> Implied = isImpliedCondition(Op0, Op1, Q.DL)) {
+ if (std::optional<bool> 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<bool> Implied = isImpliedCondition(Op1, Op0, Q.DL)) {
+ if (std::optional<bool> 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<bool> Implied = isImpliedCondition(Op0, Op1, Q.DL, false)) {
+ if (std::optional<bool> 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<bool> Implied = isImpliedCondition(Op1, Op0, Q.DL, false)) {
+ if (std::optional<bool> 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<CallInst>(AssumeVH);
- if (Optional<bool> Imp = isImpliedCondition(Assume->getArgOperand(0),
- Predicate, LHS, RHS, Q.DL))
+ if (std::optional<bool> 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<bool> Imp = isImpliedByDomCondition(Cond, Q.CxtI, Q.DL);
+ std::optional<bool> 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<bool> Imp =
+ if (std::optional<bool> Imp =
isImpliedByDomCondition(Pred, Op0, Op1, Q.CxtI, Q.DL))
return *Imp ? Op0 : Op1;
- if (Optional<bool> Imp =
+ if (std::optional<bool> 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 ba91c35b25a1c..3dbdaeb0a9df9 100644
--- a/llvm/lib/Analysis/LazyValueInfo.cpp
+++ b/llvm/lib/Analysis/LazyValueInfo.cpp
@@ -1358,7 +1358,8 @@ static std::optional<ValueLatticeElement> getEdgeValueLocal(Value *Val,
Value *Op = Usr->getOperand(i);
ValueLatticeElement OpLatticeVal =
getValueFromCondition(Op, Condition, isTrueDest);
- if (Optional<APInt> OpConst = OpLatticeVal.asConstantInteger()) {
+ if (std::optional<APInt> 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 4e688563e6ded..6cddf424bf331 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<int64_t>
-llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy,
- Value *Ptr, const Loop *Lp,
- const ValueToValueMap &StridesMap, bool Assume,
- bool ShouldCheckWrap) {
+std::optional<int64_t> 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<int> llvm::getPointersDiff(Type *ElemTyA, Value *PtrA, Type *ElemTyB,
- Value *PtrB, const DataLayout &DL,
- ScalarEvolution &SE, bool StrictCheck,
- bool CheckType) {
+std::optional<int> 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<PointerType>(PtrA->getType())
->isOpaqueOrPointeeTypeMatches(ElemTyA) && "Wrong PtrA type");
@@ -1560,8 +1561,8 @@ bool llvm::sortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
int Cnt = 1;
bool IsConsecutive = true;
for (auto *Ptr : VL.drop_front()) {
- Optional<int> Diff = getPointersDiff(ElemTy, Ptr0, ElemTy, Ptr, DL, SE,
- /*StrictCheck=*/true);
+ std::optional<int> 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<int> Diff = getPointersDiff(ElemTyA, PtrA, ElemTyB, PtrB, DL, SE,
- /*StrictCheck=*/true, CheckType);
+ std::optional<int> 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 884a018840779..46198f78b6433 100644
--- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp
+++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp
@@ -156,9 +156,9 @@ IndexedReference::IndexedReference(Instruction &StoreOrLoadInst,
<< "\n");
}
-Optional<bool> IndexedReference::hasSpacialReuse(const IndexedReference &Other,
- unsigned CLS,
- AAResults &AA) const {
+std::optional<bool>
+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<bool> IndexedReference::hasSpacialReuse(const IndexedReference &Other,
return InSameCacheLine;
}
-Optional<bool> IndexedReference::hasTemporalReuse(const IndexedReference &Other,
- unsigned MaxDistance,
- const Loop &L,
- DependenceInfo &DI,
- AAResults &AA) const {
+std::optional<bool>
+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<unsigned> TRT)
+ AAResults &AA, DependenceInfo &DI,
+ std::optional<unsigned> 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>
CacheCost::getCacheCost(Loop &Root, LoopStandardAnalysisResults &AR,
- DependenceInfo &DI, Optional<unsigned> TRT) {
+ DependenceInfo &DI, std::optional<unsigned> 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<bool> HasTemporalReuse =
+ std::optional<bool> HasTemporalReuse =
R->hasTemporalReuse(Representative, *TRT, *InnerMostLoop, DI, AA);
- Optional<bool> HasSpacialReuse =
+ std::optional<bool> HasSpacialReuse =
R->hasSpacialReuse(Representative, CLS, AA);
if ((HasTemporalReuse && *HasTemporalReuse) ||
diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp
index 0ffdf4ed76e38..69bcbcb11203f 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> Loop::LoopBounds::getBounds(const Loop &L,
- PHINode &IndVar,
- ScalarEvolution &SE) {
+std::optional<Loop::LoopBounds>
+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::LoopBounds> Loop::getBounds(ScalarEvolution &SE) const {
+std::optional<Loop::LoopBounds> 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<const MDOperand *> llvm::findStringMetadataForLoop(const Loop *TheLoop,
- StringRef Name) {
+std::optional<const MDOperand *>
+llvm::findStringMetadataForLoop(const Loop *TheLoop, StringRef Name) {
MDNode *MD = findOptionMDForLoop(TheLoop, Name);
if (!MD)
return std::nullopt;
@@ -1064,8 +1064,8 @@ Optional<const MDOperand *> llvm::findStringMetadataForLoop(const Loop *TheLoop,
}
}
-Optional<bool> llvm::getOptionalBoolLoopAttribute(const Loop *TheLoop,
- StringRef Name) {
+std::optional<bool> 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 7e80e2596300f..fe6d270b9ac53 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<Loop::LoopBounds> OuterLoopLB) {
+ std::optional<Loop::LoopBounds> OuterLoopLB) {
bool IsAllowed =
isSafeToSpeculativelyExecute(&I) || isa<PHINode>(I) || isa<BranchInst>(I);
diff --git a/llvm/lib/Analysis/MemoryBuiltins.cpp b/llvm/lib/Analysis/MemoryBuiltins.cpp
index 679dd08406780..a0a19b9958b6b 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<bool> Checked = isImpliedByDomCondition(
+ std::optional<bool> 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 14d68ee853f39..5503858125662 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<ListIndex> Previous;
+ std::optional<ListIndex> Previous;
DefPath(const MemoryLocation &Loc, MemoryAccess *First, MemoryAccess *Last,
- Optional<ListIndex> Previous)
+ std::optional<ListIndex> Previous)
: Loc(Loc), First(First), Last(Last), Previous(Previous) {}
DefPath(const MemoryLocation &Loc, MemoryAccess *Init,
- Optional<ListIndex> Previous)
+ std::optional<ListIndex> 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<TerminatedPath>
+ std::optional<TerminatedPath>
getBlockingAccess(const MemoryAccess *StopWhere,
SmallVectorImpl<ListIndex> &PausedSearches,
SmallVectorImpl<ListIndex> &NewPaused,
@@ -720,7 +720,7 @@ class ClobberWalker {
T &curNode() const { return W->Paths[*N]; }
Walker *W = nullptr;
- Optional<ListIndex> N = std::nullopt;
+ std::optional<ListIndex> N = std::nullopt;
};
using def_path_iterator = generic_def_path_iterator<DefPath, ClobberWalker>;
@@ -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<TerminatedPath> Blocker = getBlockingAccess(
+ if (std::optional<TerminatedPath> 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 7c632ade87d95..3892b09e5b63d 100644
--- a/llvm/lib/Analysis/ModelUnderTrainingRunner.cpp
+++ b/llvm/lib/Analysis/ModelUnderTrainingRunner.cpp
@@ -26,7 +26,7 @@ struct LoggedFeatureSpec {
std::optional<std::string> LoggingName;
};
-Optional<std::vector<LoggedFeatureSpec>>
+std::optional<std::vector<LoggedFeatureSpec>>
loadOutputSpecs(LLVMContext &Ctx, StringRef ExpectedDecisionName,
StringRef ModelPath, StringRef SpecFileOverride) {
SmallVector<char, 128> OutputSpecsPath;
diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp
index 8a6318eabecff..5598e33efb831 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 <typename K, typename V, typename FnTy, typename... ArgsTy>
-static V getOrCreateCachedOptional(K Key, DenseMap<K, Optional<V>> &Map,
- FnTy &&Fn, ArgsTy&&... args) {
- Optional<V> &OptVal = Map[Key];
+static V getOrCreateCachedOptional(K Key, DenseMap<K, std::optional<V>> &Map,
+ FnTy &&Fn, ArgsTy &&...args) {
+ std::optional<V> &OptVal = Map[Key];
if (!OptVal)
OptVal = Fn(std::forward<ArgsTy>(args)...);
return OptVal.value();
diff --git a/llvm/lib/Analysis/ProfileSummaryInfo.cpp b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
index ea77b40b9a7c5..c8a2ddf0567b4 100644
--- a/llvm/lib/Analysis/ProfileSummaryInfo.cpp
+++ b/llvm/lib/Analysis/ProfileSummaryInfo.cpp
@@ -265,7 +265,7 @@ void ProfileSummaryInfo::computeThresholds() {
}
}
-Optional<uint64_t>
+std::optional<uint64_t>
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 043dddfdbd1d3..2ca02eb174171 100644
--- a/llvm/lib/Analysis/ReplayInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/ReplayInlineAdvisor.cpp
@@ -123,7 +123,7 @@ std::unique_ptr<InlineAdvice> ReplayInlineAdvisor::getAdviceImpl(CallBase &CB) {
} else {
LLVM_DEBUG(dbgs() << "Replay Inliner: Not Inlined " << Callee << " @ "
<< CallSiteLoc << "\n");
- // A negative inline is conveyed by "None" Optional<InlineCost>
+ // A negative inline is conveyed by "None" std::optional<InlineCost>
return std::make_unique<DefaultInlineAdvice>(this, CB, std::nullopt, ORE,
EmitRemarks);
}
@@ -137,7 +137,7 @@ std::unique_ptr<InlineAdvice> ReplayInlineAdvisor::getAdviceImpl(CallBase &CB) {
EmitRemarks);
else if (ReplaySettings.ReplayFallback ==
ReplayInlinerSettings::Fallback::NeverInline)
- // A negative inline is conveyed by "None" Optional<InlineCost>
+ // A negative inline is conveyed by "None" std::optional<InlineCost>
return std::make_unique<DefaultInlineAdvice>(this, CB, std::nullopt, ORE,
EmitRemarks);
else {
diff --git a/llvm/lib/Analysis/StratifiedSets.h b/llvm/lib/Analysis/StratifiedSets.h
index 4da6d476b1cac..f126e98c071b4 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<StratifiedIndex> because
- /// Optional<StratifiedIndex> would eat up a considerable amount of extra
+ /// This is used instead of std::optional<StratifiedIndex> because
+ /// std::optional<StratifiedIndex> 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 @@ template <typename T> class StratifiedSets {
std::vector<StratifiedLink> Links)
: Values(std::move(Map)), Links(std::move(Links)) {}
- Optional<StratifiedInfo> find(const T &Elem) const {
+ std::optional<StratifiedInfo> find(const T &Elem) const {
auto Iter = Values.find(Elem);
if (Iter == Values.end())
return std::nullopt;
@@ -544,21 +544,21 @@ template <typename T> class StratifiedSetsBuilder {
return true;
}
- Optional<const StratifiedInfo *> get(const T &Val) const {
+ std::optional<const StratifiedInfo *> get(const T &Val) const {
auto Result = Values.find(Val);
if (Result == Values.end())
return std::nullopt;
return &Result->second;
}
- Optional<StratifiedInfo *> get(const T &Val) {
+ std::optional<StratifiedInfo *> get(const T &Val) {
auto Result = Values.find(Val);
if (Result == Values.end())
return std::nullopt;
return &Result->second;
}
- Optional<StratifiedIndex> indexOf(const T &Val) {
+ std::optional<StratifiedIndex> 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 4951012cfcc79..b2862033e9cfb 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::EvaluationResult> TFModelEvaluator::evaluate() {
+std::optional<TFModelEvaluator::EvaluationResult> 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 348f276510fa1..4f7428ded85e0 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<int64_t>())),
ElementSize(ElementSize) {}
-Optional<TensorSpec> getTensorSpecFromJSON(LLVMContext &Ctx,
- const json::Value &Value) {
- auto EmitError = [&](const llvm::Twine &Message) -> Optional<TensorSpec> {
+std::optional<TensorSpec> getTensorSpecFromJSON(LLVMContext &Ctx,
+ const json::Value &Value) {
+ auto EmitError =
+ [&](const llvm::Twine &Message) -> std::optional<TensorSpec> {
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 a0761716f1ab9..1e2d1db4e44b9 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<isa><mask><vlen><parameters>_<scalarname>[(<redirection>)]
-Optional<VFInfo> VFABI::tryDemangleForVFABI(StringRef MangledName,
- const Module &M) {
+std::optional<VFInfo> VFABI::tryDemangleForVFABI(StringRef MangledName,
+ const Module &M) {
const StringRef OriginalName = MangledName;
// Assume there is no custom name <redirection>, and therefore the
// vector name consists of
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index c59cf3fc43145..a77715119a34c 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<bool>
+static std::optional<bool>
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<bool> isImpliedCondMatchingOperands(CmpInst::Predicate LPred,
- CmpInst::Predicate RPred,
- bool AreSwappedOps) {
+static std::optional<bool>
+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<bool> 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<bool> isImpliedCondCommonOperandWithConstants(
+static std::optional<bool> 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<bool> 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<bool> isImpliedCondICmps(const ICmpInst *LHS,
- CmpInst::Predicate RPred,
- const Value *R0, const Value *R1,
- const DataLayout &DL, bool LHSIsTrue,
- unsigned Depth) {
+static std::optional<bool> 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<bool> 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<bool>
+static std::optional<bool>
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<bool> Implication = isImpliedCondition(
+ if (std::optional<bool> Implication = isImpliedCondition(
ALHS, RHSPred, RHSOp0, RHSOp1, DL, LHSIsTrue, Depth + 1))
return Implication;
- if (Optional<bool> Implication = isImpliedCondition(
+ if (std::optional<bool> 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<bool>
+std::optional<bool>
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<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
- const DataLayout &DL, bool LHSIsTrue,
- unsigned Depth) {
+std::optional<bool> 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<bool> 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<bool> Imp =
+ if (std::optional<bool> Imp =
isImpliedCondition(LHS, RHS1, DL, LHSIsTrue, Depth + 1))
if (*Imp == true)
return true;
- if (Optional<bool> Imp =
+ if (std::optional<bool> 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<bool> Imp =
+ if (std::optional<bool> Imp =
isImpliedCondition(LHS, RHS1, DL, LHSIsTrue, Depth + 1))
if (*Imp == false)
return false;
- if (Optional<bool> Imp =
+ if (std::optional<bool> 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<bool> llvm::isImpliedByDomCondition(const Value *Cond,
- const Instruction *ContextI,
- const DataLayout &DL) {
+std::optional<bool> 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<bool> llvm::isImpliedByDomCondition(const Value *Cond,
return std::nullopt;
}
-Optional<bool> llvm::isImpliedByDomCondition(CmpInst::Predicate Pred,
- const Value *LHS, const Value *RHS,
- const Instruction *ContextI,
- const DataLayout &DL) {
+std::optional<bool> 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<int64_t> llvm::isPointerOffset(const Value *Ptr1, const Value *Ptr2,
- const DataLayout &DL) {
+std::optional<int64_t> 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 0a613465f3c1d..ae766378680a0 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<StringRef>(ListAttr.begin(), ListAttr.end())) {
#ifndef NDEBUG
LLVM_DEBUG(dbgs() << "VFABI: adding mapping '" << S << "'\n");
- Optional<VFInfo> Info = VFABI::tryDemangleForVFABI(S, *(CI.getModule()));
+ std::optional<VFInfo> 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 dc6746e22218e..f5311a0a5499e 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 @@ class po_iterator_storage<LoopBounds, true> {
void finishPostorder(const MachineBasicBlock*) {}
- bool insertEdge(Optional<const MachineBasicBlock *> From,
+ bool insertEdge(std::optional<const MachineBasicBlock *> 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 15324c3e95b86..93afbad574b21 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<int64_t> Offset =
+ std::optional<int64_t> 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<int64_t> Offset = isPointerOffset(StartPtr, MSI->getDest(), *DL);
+ std::optional<int64_t> 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 e79fe0521eed7..70ba9731e40b3 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -190,11 +190,12 @@ static void getSortedConstantKeys(std::vector<Value *> &SortedKeys,
Value *OutlinableRegion::findCorrespondingValueIn(const OutlinableRegion &Other,
Value *V) {
- Optional<unsigned> GVN = Candidate->getGVN(V);
+ std::optional<unsigned> GVN = Candidate->getGVN(V);
assert(GVN && "No GVN for incoming value");
- Optional<unsigned> CanonNum = Candidate->getCanonicalNum(*GVN);
- Optional<unsigned> FirstGVN = Other.Candidate->fromCanonicalNum(*CanonNum);
- Optional<Value *> FoundValueOpt = Other.Candidate->fromGVN(*FirstGVN);
+ std::optional<unsigned> CanonNum = Candidate->getCanonicalNum(*GVN);
+ std::optional<unsigned> FirstGVN =
+ Other.Candidate->fromCanonicalNum(*CanonNum);
+ std::optional<Value *> 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<unsigned> GVNOpt = C.getGVN(V);
+ std::optional<unsigned> 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<unsigned> CanonicalNumberOpt = C.getCanonicalNum(InputVal);
+ std::optional<unsigned> CanonicalNumberOpt = C.getCanonicalNum(InputVal);
assert(CanonicalNumberOpt && "Canonical number not found?");
unsigned CanonicalNumber = CanonicalNumberOpt.value();
- Optional<Value *> InputOpt = C.fromGVN(InputVal);
+ std::optional<Value *> 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<unsigned> getGVNForPHINode(OutlinableRegion &Region,
- PHINode *PN,
- DenseSet<BasicBlock *> &Blocks,
- unsigned AggArgIdx) {
+static std::optional<unsigned> getGVNForPHINode(OutlinableRegion &Region,
+ PHINode *PN,
+ DenseSet<BasicBlock *> &Blocks,
+ unsigned AggArgIdx) {
OutlinableGroup &Group = *Region.Parent;
IRSimilarityCandidate &Cand = *Region.Candidate;
BasicBlock *PHIBB = PN->getParent();
@@ -1192,7 +1193,7 @@ static Optional<unsigned> 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<unsigned> OGVN = Cand.getGVN(Incoming);
+ std::optional<unsigned> OGVN = Cand.getGVN(Incoming);
if (!OGVN && Blocks.contains(IncomingBlock)) {
Region.IgnoreRegion = true;
return std::nullopt;
@@ -1244,7 +1245,7 @@ static Optional<unsigned> getGVNForPHINode(OutlinableRegion &Region,
// PHINode to generate a hash value representing this instance of the PHINode.
DenseMap<hash_code, unsigned>::iterator GVNToPHIIt;
DenseMap<unsigned, PHINodeData>::iterator PHIToGVNIt;
- Optional<unsigned> BBGVN = Cand.getGVN(PHIBB);
+ std::optional<unsigned> 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<PHINode>(Output);
- Optional<unsigned> GVN;
+ std::optional<unsigned> 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<unsigned> GVN = Region.Candidate->getGVN(IVal);
+ std::optional<unsigned> GVN = Region.Candidate->getGVN(IVal);
assert(GVN && "No GVN for incoming value");
- Optional<unsigned> CanonNum = Region.Candidate->getCanonicalNum(*GVN);
+ std::optional<unsigned> 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<unsigned> OGVN = Region.Candidate->fromCanonicalNum(OutputCanon);
+ std::optional<unsigned> OGVN =
+ Region.Candidate->fromCanonicalNum(OutputCanon);
assert(OGVN && "Could not find GVN for Canonical Number?");
- Optional<Value *> OV = Region.Candidate->fromGVN(*OGVN);
+ std::optional<Value *> 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 7e71ad6f2de5b..d46f9a6c67575 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<Scaled64> Res;
+ std::optional<Scaled64> Res;
if (!Edge.first)
return Res;
CallBase &CB = *cast<CallBase>(*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<Scaled64>(BBCount);
+ return std::optional<Scaled64>(BBCount);
};
CallGraph CG(M);
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index d157737771210..dd3611371cb10 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<bool> getKnownSign(Value *Op, Instruction *CxtI,
- const DataLayout &DL, AssumptionCache *AC,
- DominatorTree *DT) {
+static std::optional<bool> 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<bool> Sign = getKnownSign(IIOperand, II, DL, &AC, &DT)) {
+ if (std::optional<bool> 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 64492da2f52b2..c3d281e0b9c41 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<bool> Imp = isImpliedCondition(DomCond, &Cmp, DL, TrueBB == CmpBB);
+ std::optional<bool> 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<bool> Impl = isImpliedCondition(SI->getCondition(), Pred, Op,
- RHS, DL, SelectCondIsTrue))
+ if (std::optional<bool> 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 20350ef25cd5d..fbd478cbae62a 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<bool> Res = isImpliedCondition(Op, CondVal, DL, IsAnd);
+ std::optional<bool> 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<bool> Res = isImpliedCondition(TrueVal, B, DL);
+ std::optional<bool> 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<bool> Res = isImpliedCondition(CondVal, B, DL);
+ std::optional<bool> 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<bool> Res = isImpliedCondition(CondVal, B, DL, false);
+ std::optional<bool> 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<bool> Res = isImpliedCondition(FalseVal, B, DL, false);
+ std::optional<bool> 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 4ada263b703f6..6b648f8794cb9 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<bool> Implication =
+ std::optional<bool> 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 13f26ed0f8c11..fbf2ee5487d23 100644
--- a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
@@ -936,7 +936,7 @@ class LoopDistributeForLoop {
/// Check whether the loop metadata is forcing distribution to be
/// enabled/disabled.
void setForced() {
- Optional<const MDOperand *> Value =
+ std::optional<const MDOperand *> 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 aaeb09abf59f7..34b46ad228692 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<int64_t> Offset =
+ std::optional<int64_t> 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<int64_t> Offset = isPointerOffset(StartPtr, MSI->getDest(), DL);
+ std::optional<int64_t> 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 0e4576f807351..1f381be397ab9 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<bool> Enable =
+ std::optional<bool> 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 1b2eb416d603b..fbdc3fd9f9cc2 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<VFInfo> VI = VFABI::tryDemangleForVFABI(VariantMapping, *M);
+ std::optional<VFInfo> 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 7277c734102bf..0836921ea4b52 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<bool> Imp = isImpliedByDomCondition(BI->getCondition(), BI, DL);
+ std::optional<bool> 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 be941786f3082..0c23b299ae68e 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -1289,7 +1289,7 @@ class BoUpSLP {
!LI2->isSimple())
return LookAheadHeuristics::ScoreFail;
- Optional<int> Dist = getPointersDiff(
+ std::optional<int> 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<Value *> VL, const Value *VL0,
Ptr0 = PointerOps[Order.front()];
PtrN = PointerOps[Order.back()];
}
- Optional<int> Diff =
+ std::optional<int> Diff =
getPointersDiff(ScalarTy, Ptr0, ScalarTy, PtrN, DL, SE);
// Check that the sorted loads are consecutive.
if (static_cast<unsigned>(*Diff) == VL.size() - 1)
@@ -3782,7 +3782,7 @@ bool clusterSortPtrAccesses(ArrayRef<Value *> VL, Type *ElemTy,
unsigned Cnt = 1;
for (Value *Ptr : VL.drop_front()) {
bool Found = any_of(Bases, [&](auto &Base) {
- Optional<int> Diff =
+ std::optional<int> Diff =
getPointersDiff(ElemTy, Base.first, ElemTy, Ptr, DL, SE,
/*StrictCheck=*/true);
if (!Diff)
@@ -4743,7 +4743,7 @@ bool BoUpSLP::canFormVector(const SmallVector<StoreInst *, 4> &StoresVec,
Value *S0Ptr = S0->getPointerOperand();
for (unsigned Idx : seq<unsigned>(1, StoresVec.size())) {
StoreInst *SI = StoresVec[Idx];
- Optional<int> Diff =
+ std::optional<int> Diff =
getPointersDiff(S0Ty, S0Ptr, SI->getValueOperand()->getType(),
SI->getPointerOperand(), *DL, *SE,
/*StrictCheck=*/true);
@@ -5751,7 +5751,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
Ptr0 = PointerOps[CurrentOrder.front()];
PtrN = PointerOps[CurrentOrder.back()];
}
- Optional<int> Dist =
+ std::optional<int> Dist =
getPointersDiff(ScalarTy, Ptr0, ScalarTy, PtrN, *DL, *SE);
// Check that the sorted pointer operands are consecutive.
if (static_cast<unsigned>(*Dist) == VL.size() - 1) {
@@ -10959,7 +10959,7 @@ bool SLPVectorizerPass::vectorizeStores(ArrayRef<StoreInst *> Stores,
++IterCnt;
CheckedPairs[Idx].set(K);
CheckedPairs[K].set(Idx);
- Optional<int> Diff = getPointersDiff(
+ std::optional<int> 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 e9ab251f4229a..528d4bcc99833 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<std::set<void *>, false> PIS;
- PIS.insertEdge(Optional<void *>(), Null);
+ PIS.insertEdge(std::optional<void *>(), Null);
ExtSetTy Ext;
po_iterator_storage<ExtSetTy, true> PISExt(Ext);
- PIS.insertEdge(Optional<void *>(), Null);
+ PIS.insertEdge(std::optional<void *>(), Null);
// Test above, but going through po_iterator (which inherits from template
// base)
BasicBlock *NullBB = nullptr;
auto PI = po_end(NullBB);
- PI.insertEdge(Optional<BasicBlock *>(), NullBB);
+ PI.insertEdge(std::optional<BasicBlock *>(), NullBB);
auto PIExt = po_ext_end(NullBB, Ext);
- PIExt.insertEdge(Optional<BasicBlock *>(), NullBB);
+ PIExt.insertEdge(std::optional<BasicBlock *>(), 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 206f6c2eaa8f5..d2ffff15fdd14 100644
--- a/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp
+++ b/llvm/unittests/Analysis/BasicAliasAnalysisTest.cpp
@@ -56,7 +56,7 @@ class BasicAATest : public testing::Test {
}
};
- llvm::Optional<TestAnalyses> Analyses;
+ std::optional<TestAnalyses> Analyses;
TestAnalyses &setupAnalyses() {
assert(F);
diff --git a/llvm/unittests/Analysis/LoopInfoTest.cpp b/llvm/unittests/Analysis/LoopInfoTest.cpp
index c7b69ead72033..126467189d92d 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<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -329,7 +329,7 @@ TEST(LoopInfoTest, LoopWithInverseGuardSuccs) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -388,7 +388,7 @@ TEST(LoopInfoTest, LoopWithSwappedGuardCmp) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -447,7 +447,7 @@ TEST(LoopInfoTest, LoopWithInverseLatchSuccs) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -506,7 +506,7 @@ TEST(LoopInfoTest, LoopWithLatchCmpNE) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -566,7 +566,7 @@ TEST(LoopInfoTest, LoopWithGuardCmpSLE) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -625,7 +625,7 @@ TEST(LoopInfoTest, LoopNonConstantStep) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -681,7 +681,7 @@ TEST(LoopInfoTest, LoopUnsignedBounds) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -740,7 +740,7 @@ TEST(LoopInfoTest, DecreasingLoop) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> 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<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -860,7 +860,7 @@ TEST(LoopInfoTest, ZextIndVar) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -921,7 +921,7 @@ TEST(LoopInfoTest, MultiExitingLoop) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -981,7 +981,7 @@ TEST(LoopInfoTest, MultiExitLoop) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -1033,7 +1033,7 @@ TEST(LoopInfoTest, UnguardedLoop) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -1091,7 +1091,7 @@ TEST(LoopInfoTest, UnguardedLoopWithControlFlow) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -1162,7 +1162,7 @@ TEST(LoopInfoTest, LoopNest) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
@@ -1188,7 +1188,7 @@ TEST(LoopInfoTest, LoopNest) {
L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> InnerBounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> InnerBounds = L->getBounds(SE);
EXPECT_NE(InnerBounds, std::nullopt);
InitialIVValue =
dyn_cast<ConstantInt>(&InnerBounds->getInitialIVValue());
@@ -1255,7 +1255,7 @@ TEST(LoopInfoTest, AuxiliaryIV) {
Loop *L = LI.getLoopFor(Header);
EXPECT_NE(L, nullptr);
- Optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
+ std::optional<Loop::LoopBounds> Bounds = L->getBounds(SE);
EXPECT_NE(Bounds, std::nullopt);
ConstantInt *InitialIVValue =
dyn_cast<ConstantInt>(&Bounds->getInitialIVValue());
diff --git a/llvm/unittests/Analysis/ScalarEvolutionTest.cpp b/llvm/unittests/Analysis/ScalarEvolutionTest.cpp
index c6821fa0675b1..8756e2c66c25a 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<int> {
+ auto
diff = [&SE](const SCEV *LHS, const SCEV *RHS) -> std::optional<int> {
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 4f9575c90051a..09f4ada005e2f 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<TensorSpec> Spec = getTensorSpecFromJSON(Ctx, *Value);
+ std::optional<TensorSpec> Spec = getTensorSpecFromJSON(Ctx, *Value);
EXPECT_TRUE(Spec);
EXPECT_EQ(*Spec, TensorSpec::createSpec<int32_t>("tensor_name", {1, 4}, 2));
}
More information about the llvm-commits
mailing list