[llvm] c178ed3 - Transforms/Utils: llvm::Optional => std::optional
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 12 00:29:12 PST 2022
Author: Fangrui Song
Date: 2022-12-12T08:29:05Z
New Revision: c178ed33bd82151f21abc3c0015c671b33556999
URL: https://github.com/llvm/llvm-project/commit/c178ed33bd82151f21abc3c0015c671b33556999
DIFF: https://github.com/llvm/llvm-project/commit/c178ed33bd82151f21abc3c0015c671b33556999.diff
LOG: Transforms/Utils: llvm::Optional => std::optional
Added:
Modified:
llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h
llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
llvm/include/llvm/Transforms/Utils/LoopPeel.h
llvm/include/llvm/Transforms/Utils/LoopUtils.h
llvm/include/llvm/Transforms/Utils/PredicateInfo.h
llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h
llvm/include/llvm/Transforms/Utils/UnrollLoop.h
llvm/lib/Transforms/Scalar/LoopDistribute.cpp
llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp
llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
llvm/lib/Transforms/Scalar/NewGVN.cpp
llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp
llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
llvm/lib/Transforms/Utils/Local.cpp
llvm/lib/Transforms/Utils/LoopPeel.cpp
llvm/lib/Transforms/Utils/LoopUnroll.cpp
llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/lib/Transforms/Utils/PredicateInfo.cpp
llvm/lib/Transforms/Utils/SCCPSolver.cpp
llvm/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
llvm/lib/Transforms/Utils/ValueMapper.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h b/llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h
index 6afe7ecd2a5de..8d8c2f254f02f 100644
--- a/llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h
+++ b/llvm/include/llvm/Transforms/Scalar/LoopUnrollPass.h
@@ -9,10 +9,10 @@
#ifndef LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
#define LLVM_TRANSFORMS_SCALAR_LOOPUNROLLPASS_H
-#include "llvm/ADT/Optional.h"
#include "llvm/Analysis/LoopAnalysisManager.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Support/CommandLine.h"
+#include <optional>
namespace llvm {
@@ -59,12 +59,12 @@ class LoopFullUnrollPass : public PassInfoMixin<LoopFullUnrollPass> {
/// additional setters and then pass it to LoopUnrollPass.
///
struct LoopUnrollOptions {
- Optional<bool> AllowPartial;
- Optional<bool> AllowPeeling;
- Optional<bool> AllowRuntime;
- Optional<bool> AllowUpperBound;
- Optional<bool> AllowProfileBasedPeeling;
- Optional<unsigned> FullUnrollMaxCount;
+ std::optional<bool> AllowPartial;
+ std::optional<bool> AllowPeeling;
+ std::optional<bool> AllowRuntime;
+ std::optional<bool> AllowUpperBound;
+ std::optional<bool> AllowProfileBasedPeeling;
+ std::optional<unsigned> FullUnrollMaxCount;
int OptLevel;
/// If false, use a cost model to determine whether unrolling of a loop is
diff --git a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
index 9d921496ff107..3b2fe817c04cf 100644
--- a/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/BasicBlockUtils.h
@@ -581,7 +581,7 @@ BasicBlock *CreateControlFlowHub(
DomTreeUpdater *DTU, SmallVectorImpl<BasicBlock *> &GuardBlocks,
const SetVector<BasicBlock *> &Predecessors,
const SetVector<BasicBlock *> &Successors, const StringRef Prefix,
- Optional<unsigned> MaxControlFlowBooleans = std::nullopt);
+ std::optional<unsigned> MaxControlFlowBooleans = std::nullopt);
} // end namespace llvm
diff --git a/llvm/include/llvm/Transforms/Utils/LoopPeel.h b/llvm/include/llvm/Transforms/Utils/LoopPeel.h
index cd7499dfbf1b4..7dffaa4d3d9c3 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopPeel.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopPeel.h
@@ -26,8 +26,8 @@ bool peelLoop(Loop *L, unsigned PeelCount, LoopInfo *LI, ScalarEvolution *SE,
TargetTransformInfo::PeelingPreferences
gatherPeelingPreferences(Loop *L, ScalarEvolution &SE,
const TargetTransformInfo &TTI,
- Optional<bool> UserAllowPeeling,
- Optional<bool> UserAllowProfileBasedPeeling,
+ std::optional<bool> UserAllowPeeling,
+ std::optional<bool> UserAllowProfileBasedPeeling,
bool UnrollingSpecficValues = false);
void computePeelCount(Loop *L, unsigned LoopSize,
diff --git a/llvm/include/llvm/Transforms/Utils/LoopUtils.h b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
index 4f9c97708a5eb..0580cecfc7926 100644
--- a/llvm/include/llvm/Transforms/Utils/LoopUtils.h
+++ b/llvm/include/llvm/Transforms/Utils/LoopUtils.h
@@ -226,7 +226,7 @@ SmallVector<Instruction *, 8> findDefsUsedOutsideOfLoop(Loop *L);
/// "llvm.loop.vectorize.scalable.enable") for a loop and use it to construct a
/// ElementCount. If the metadata "llvm.loop.vectorize.width" cannot be found
/// then std::nullopt is returned.
-Optional<ElementCount>
+std::optional<ElementCount>
getOptionalElementCountLoopAttribute(const Loop *TheLoop);
/// Create a new loop identifier for a loop created from a loop transformation.
@@ -253,7 +253,7 @@ getOptionalElementCountLoopAttribute(const Loop *TheLoop);
/// @p OrigLoopID: The original identifier can be reused.
/// nullptr : The new loop has no attributes.
/// MDNode* : A new unique loop identifier.
-Optional<MDNode *>
+std::optional<MDNode *>
makeFollowupLoopID(MDNode *OrigLoopID, ArrayRef<StringRef> FollowupAttrs,
const char *InheritOptionsAttrsPrefix = "",
bool AlwaysNew = false);
@@ -311,7 +311,7 @@ void addStringMetadataToLoop(Loop *TheLoop, const char *MDString,
/// initialized with weight of loop's latch leading to the exit.
/// Returns 0 when the count is estimated to be 0, or std::nullopt when a
/// meaningful estimate can not be made.
-Optional<unsigned>
+std::optional<unsigned>
getLoopEstimatedTripCount(Loop *L,
unsigned *EstimatedLoopInvocationWeight = nullptr);
@@ -541,10 +541,10 @@ struct IVConditionInfo {
/// If the branch condition of the header is partially invariant, return a pair
/// containing the instructions to duplicate and a boolean Constant to update
/// the condition in the loops created for the true or false successors.
-Optional<IVConditionInfo> hasPartialIVCondition(const Loop &L,
- unsigned MSSAThreshold,
- const MemorySSA &MSSA,
- AAResults &AA);
+std::optional<IVConditionInfo> hasPartialIVCondition(const Loop &L,
+ unsigned MSSAThreshold,
+ const MemorySSA &MSSA,
+ AAResults &AA);
} // end namespace llvm
diff --git a/llvm/include/llvm/Transforms/Utils/PredicateInfo.h b/llvm/include/llvm/Transforms/Utils/PredicateInfo.h
index e57e598b69180..d2224b61103c9 100644
--- a/llvm/include/llvm/Transforms/Utils/PredicateInfo.h
+++ b/llvm/include/llvm/Transforms/Utils/PredicateInfo.h
@@ -103,7 +103,7 @@ class PredicateBase : public ilist_node<PredicateBase> {
}
/// Fetch condition in the form of PredicateConstraint, if possible.
- Optional<PredicateConstraint> getConstraint() const;
+ std::optional<PredicateConstraint> getConstraint() const;
protected:
PredicateBase(PredicateType PT, Value *Op, Value *Condition)
diff --git a/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h b/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h
index 978339617c2ed..90a5ffc5b4fa0 100644
--- a/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h
+++ b/llvm/include/llvm/Transforms/Utils/SimplifyLibCalls.h
@@ -89,9 +89,9 @@ class FortifiedLibCallSimplifier {
/// parameter. These are used by an implementation to opt-into stricter
/// checking.
bool isFortifiedCallFoldable(CallInst *CI, unsigned ObjSizeOp,
- Optional<unsigned> SizeOp = std::nullopt,
- Optional<unsigned> StrOp = std::nullopt,
- Optional<unsigned> FlagsOp = std::nullopt);
+ std::optional<unsigned> SizeOp = std::nullopt,
+ std::optional<unsigned> StrOp = std::nullopt,
+ std::optional<unsigned> FlagsOp = std::nullopt);
};
/// LibCallSimplifier - This class implements a collection of optimizations
diff --git a/llvm/include/llvm/Transforms/Utils/UnrollLoop.h b/llvm/include/llvm/Transforms/Utils/UnrollLoop.h
index b4f2c59f3f694..4f3010965b591 100644
--- a/llvm/include/llvm/Transforms/Utils/UnrollLoop.h
+++ b/llvm/include/llvm/Transforms/Utils/UnrollLoop.h
@@ -121,9 +121,10 @@ TargetTransformInfo::UnrollingPreferences gatherUnrollingPreferences(
Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI,
BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
llvm::OptimizationRemarkEmitter &ORE, int OptLevel,
- Optional<unsigned> UserThreshold, Optional<unsigned> UserCount,
- Optional<bool> UserAllowPartial, Optional<bool> UserRuntime,
- Optional<bool> UserUpperBound, Optional<unsigned> UserFullUnrollMaxCount);
+ std::optional<unsigned> UserThreshold, std::optional<unsigned> UserCount,
+ std::optional<bool> UserAllowPartial, std::optional<bool> UserRuntime,
+ std::optional<bool> UserUpperBound,
+ std::optional<unsigned> UserFullUnrollMaxCount);
InstructionCost ApproximateLoopSize(const Loop *L, unsigned &NumCalls,
bool &NotDuplicatable, bool &Convergent, const TargetTransformInfo &TTI,
diff --git a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
index 434bee101ae75..7a2a34a8d595f 100644
--- a/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDistribute.cpp
@@ -593,7 +593,7 @@ class InstPartitionContainer {
/// Assign new LoopIDs for the partition's cloned loop.
void setNewLoopID(MDNode *OrigLoopID, InstPartition *Part) {
- Optional<MDNode *> PartitionID = makeFollowupLoopID(
+ std::optional<MDNode *> PartitionID = makeFollowupLoopID(
OrigLoopID,
{LLVMLoopDistributeFollowupAll,
Part->hasDepCycle() ? LLVMLoopDistributeFollowupSequential
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp
index 00d8b8866e36f..e51b24e849e8a 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollAndJamPass.cpp
@@ -368,7 +368,7 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,
// To assign the loop id of the epilogue, assign it before unrolling it so it
// is applied to every inner loop of the epilogue. We later apply the loop ID
// for the jammed inner loop.
- Optional<MDNode *> NewInnerEpilogueLoopID = makeFollowupLoopID(
+ std::optional<MDNode *> NewInnerEpilogueLoopID = makeFollowupLoopID(
OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll,
LLVMLoopUnrollAndJamFollowupRemainderInner});
if (NewInnerEpilogueLoopID)
@@ -398,14 +398,14 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,
// Assign new loop attributes.
if (EpilogueOuterLoop) {
- Optional<MDNode *> NewOuterEpilogueLoopID = makeFollowupLoopID(
+ std::optional<MDNode *> NewOuterEpilogueLoopID = makeFollowupLoopID(
OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll,
LLVMLoopUnrollAndJamFollowupRemainderOuter});
if (NewOuterEpilogueLoopID)
EpilogueOuterLoop->setLoopID(NewOuterEpilogueLoopID.value());
}
- Optional<MDNode *> NewInnerLoopID =
+ std::optional<MDNode *> NewInnerLoopID =
makeFollowupLoopID(OrigOuterLoopID, {LLVMLoopUnrollAndJamFollowupAll,
LLVMLoopUnrollAndJamFollowupInner});
if (NewInnerLoopID)
@@ -414,7 +414,7 @@ tryToUnrollAndJamLoop(Loop *L, DominatorTree &DT, LoopInfo *LI,
SubLoop->setLoopID(OrigSubLoopID);
if (UnrollResult == LoopUnrollResult::PartiallyUnrolled) {
- Optional<MDNode *> NewOuterLoopID = makeFollowupLoopID(
+ std::optional<MDNode *> NewOuterLoopID = makeFollowupLoopID(
OrigOuterLoopID,
{LLVMLoopUnrollAndJamFollowupAll, LLVMLoopUnrollAndJamFollowupOuter});
if (NewOuterLoopID) {
diff --git a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
index 84705570dee39..cc0ca7ab9717c 100644
--- a/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp
@@ -185,9 +185,10 @@ TargetTransformInfo::UnrollingPreferences llvm::gatherUnrollingPreferences(
Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI,
BlockFrequencyInfo *BFI, ProfileSummaryInfo *PSI,
OptimizationRemarkEmitter &ORE, int OptLevel,
- Optional<unsigned> UserThreshold, Optional<unsigned> UserCount,
- Optional<bool> UserAllowPartial, Optional<bool> UserRuntime,
- Optional<bool> UserUpperBound, Optional<unsigned> UserFullUnrollMaxCount) {
+ std::optional<unsigned> UserThreshold, std::optional<unsigned> UserCount,
+ std::optional<bool> UserAllowPartial, std::optional<bool> UserRuntime,
+ std::optional<bool> UserUpperBound,
+ std::optional<unsigned> UserFullUnrollMaxCount) {
TargetTransformInfo::UnrollingPreferences UP;
// Set up the defaults
@@ -1119,17 +1120,20 @@ bool llvm::computeUnrollCount(
return ExplicitUnroll;
}
-static LoopUnrollResult tryToUnrollLoop(
- Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
- const TargetTransformInfo &TTI, AssumptionCache &AC,
- OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI,
- ProfileSummaryInfo *PSI, bool PreserveLCSSA, int OptLevel,
- bool OnlyWhenForced, bool ForgetAllSCEV, Optional<unsigned> ProvidedCount,
- Optional<unsigned> ProvidedThreshold, Optional<bool> ProvidedAllowPartial,
- Optional<bool> ProvidedRuntime, Optional<bool> ProvidedUpperBound,
- Optional<bool> ProvidedAllowPeeling,
- Optional<bool> ProvidedAllowProfileBasedPeeling,
- Optional<unsigned> ProvidedFullUnrollMaxCount) {
+static LoopUnrollResult
+tryToUnrollLoop(Loop *L, DominatorTree &DT, LoopInfo *LI, ScalarEvolution &SE,
+ const TargetTransformInfo &TTI, AssumptionCache &AC,
+ OptimizationRemarkEmitter &ORE, BlockFrequencyInfo *BFI,
+ ProfileSummaryInfo *PSI, bool PreserveLCSSA, int OptLevel,
+ bool OnlyWhenForced, bool ForgetAllSCEV,
+ std::optional<unsigned> ProvidedCount,
+ std::optional<unsigned> ProvidedThreshold,
+ std::optional<bool> ProvidedAllowPartial,
+ std::optional<bool> ProvidedRuntime,
+ std::optional<bool> ProvidedUpperBound,
+ std::optional<bool> ProvidedAllowPeeling,
+ std::optional<bool> ProvidedAllowProfileBasedPeeling,
+ std::optional<unsigned> ProvidedFullUnrollMaxCount) {
LLVM_DEBUG(dbgs() << "Loop Unroll: F["
<< L->getHeader()->getParent()->getName() << "] Loop %"
<< L->getHeader()->getName() << "\n");
@@ -1321,7 +1325,7 @@ static LoopUnrollResult tryToUnrollLoop(
return LoopUnrollResult::Unmodified;
if (RemainderLoop) {
- Optional<MDNode *> RemainderLoopID =
+ std::optional<MDNode *> RemainderLoopID =
makeFollowupLoopID(OrigLoopID, {LLVMLoopUnrollFollowupAll,
LLVMLoopUnrollFollowupRemainder});
if (RemainderLoopID)
@@ -1329,7 +1333,7 @@ static LoopUnrollResult tryToUnrollLoop(
}
if (UnrollResult != LoopUnrollResult::FullyUnrolled) {
- Optional<MDNode *> NewLoopID =
+ std::optional<MDNode *> NewLoopID =
makeFollowupLoopID(OrigLoopID, {LLVMLoopUnrollFollowupAll,
LLVMLoopUnrollFollowupUnrolled});
if (NewLoopID) {
@@ -1367,25 +1371,25 @@ class LoopUnroll : public LoopPass {
/// Otherwise, forgetAllLoops and rebuild when needed next.
bool ForgetAllSCEV;
- Optional<unsigned> ProvidedCount;
- Optional<unsigned> ProvidedThreshold;
- Optional<bool> ProvidedAllowPartial;
- Optional<bool> ProvidedRuntime;
- Optional<bool> ProvidedUpperBound;
- Optional<bool> ProvidedAllowPeeling;
- Optional<bool> ProvidedAllowProfileBasedPeeling;
- Optional<unsigned> ProvidedFullUnrollMaxCount;
+ std::optional<unsigned> ProvidedCount;
+ std::optional<unsigned> ProvidedThreshold;
+ std::optional<bool> ProvidedAllowPartial;
+ std::optional<bool> ProvidedRuntime;
+ std::optional<bool> ProvidedUpperBound;
+ std::optional<bool> ProvidedAllowPeeling;
+ std::optional<bool> ProvidedAllowProfileBasedPeeling;
+ std::optional<unsigned> ProvidedFullUnrollMaxCount;
LoopUnroll(int OptLevel = 2, bool OnlyWhenForced = false,
bool ForgetAllSCEV = false,
- Optional<unsigned> Threshold = std::nullopt,
- Optional<unsigned> Count = std::nullopt,
- Optional<bool> AllowPartial = std::nullopt,
- Optional<bool> Runtime = std::nullopt,
- Optional<bool> UpperBound = std::nullopt,
- Optional<bool> AllowPeeling = std::nullopt,
- Optional<bool> AllowProfileBasedPeeling = std::nullopt,
- Optional<unsigned> ProvidedFullUnrollMaxCount = std::nullopt)
+ std::optional<unsigned> Threshold = std::nullopt,
+ std::optional<unsigned> Count = std::nullopt,
+ std::optional<bool> AllowPartial = std::nullopt,
+ std::optional<bool> Runtime = std::nullopt,
+ std::optional<bool> UpperBound = std::nullopt,
+ std::optional<bool> AllowPeeling = std::nullopt,
+ std::optional<bool> AllowProfileBasedPeeling = std::nullopt,
+ std::optional<unsigned> ProvidedFullUnrollMaxCount = std::nullopt)
: LoopPass(ID), OptLevel(OptLevel), OnlyWhenForced(OnlyWhenForced),
ForgetAllSCEV(ForgetAllSCEV), ProvidedCount(std::move(Count)),
ProvidedThreshold(Threshold), ProvidedAllowPartial(AllowPartial),
@@ -1457,12 +1461,12 @@ Pass *llvm::createLoopUnrollPass(int OptLevel, bool OnlyWhenForced,
// callers.
return new LoopUnroll(
OptLevel, OnlyWhenForced, ForgetAllSCEV,
- Threshold == -1 ? std::nullopt : Optional<unsigned>(Threshold),
- Count == -1 ? std::nullopt : Optional<unsigned>(Count),
- AllowPartial == -1 ? std::nullopt : Optional<bool>(AllowPartial),
- Runtime == -1 ? std::nullopt : Optional<bool>(Runtime),
- UpperBound == -1 ? std::nullopt : Optional<bool>(UpperBound),
- AllowPeeling == -1 ? std::nullopt : Optional<bool>(AllowPeeling));
+ Threshold == -1 ? std::nullopt : std::optional<unsigned>(Threshold),
+ Count == -1 ? std::nullopt : std::optional<unsigned>(Count),
+ AllowPartial == -1 ? std::nullopt : std::optional<bool>(AllowPartial),
+ Runtime == -1 ? std::nullopt : std::optional<bool>(Runtime),
+ UpperBound == -1 ? std::nullopt : std::optional<bool>(UpperBound),
+ AllowPeeling == -1 ? std::nullopt : std::optional<bool>(AllowPeeling));
}
Pass *llvm::createSimpleLoopUnrollPass(int OptLevel, bool OnlyWhenForced,
@@ -1611,7 +1615,7 @@ PreservedAnalyses LoopUnrollPass::run(Function &F,
// Check if the profile summary indicates that the profiled application
// has a huge working set size, in which case we disable peeling to avoid
// bloating it further.
- Optional<bool> LocalAllowPeeling = UnrollOpts.AllowPeeling;
+ std::optional<bool> LocalAllowPeeling = UnrollOpts.AllowPeeling;
if (PSI && PSI->hasHugeWorkingSetSize())
LocalAllowPeeling = false;
std::string LoopName = std::string(L.getName());
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp
index afa346ea320e8..1ec5bc1a39d86 100644
--- a/llvm/lib/Transforms/Scalar/NewGVN.cpp
+++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp
@@ -1563,7 +1563,7 @@ NewGVN::performSymbolicPredicateInfoEvaluation(IntrinsicInst *I) const {
LLVM_DEBUG(dbgs() << "Found predicate info from instruction !\n");
- const Optional<PredicateConstraint> &Constraint = PI->getConstraint();
+ const std::optional<PredicateConstraint> &Constraint = PI->getConstraint();
if (!Constraint)
return ExprResult::none();
diff --git a/llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp b/llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp
index eeed11c0b533f..9e08954ef6433 100644
--- a/llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp
+++ b/llvm/lib/Transforms/Scalar/WarnMissedTransforms.cpp
@@ -48,7 +48,7 @@ static void warnAboutLeftoverTransformations(Loop *L,
if (hasVectorizeTransformation(L) == TM_ForcedByUser) {
LLVM_DEBUG(dbgs() << "Leftover vectorization transformation\n");
- Optional<ElementCount> VectorizeWidth =
+ std::optional<ElementCount> VectorizeWidth =
getOptionalElementCountLoopAttribute(L);
std::optional<int> InterleaveCount =
getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
index 9876681a19245..871d742e38135 100644
--- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
+++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp
@@ -1903,7 +1903,7 @@ convertToGuardPredicates(SmallVectorImpl<BasicBlock *> &GuardBlocks,
SmallVectorImpl<WeakVH> &DeletionCandidates,
const BBSetVector &Incoming,
const BBSetVector &Outgoing, const StringRef Prefix,
- Optional<unsigned> MaxControlFlowBooleans) {
+ std::optional<unsigned> MaxControlFlowBooleans) {
BBPredicates GuardPredicates;
auto F = Incoming.front()->getParent();
@@ -1928,7 +1928,7 @@ convertToGuardPredicates(SmallVectorImpl<BasicBlock *> &GuardBlocks,
BasicBlock *llvm::CreateControlFlowHub(
DomTreeUpdater *DTU, SmallVectorImpl<BasicBlock *> &GuardBlocks,
const BBSetVector &Incoming, const BBSetVector &Outgoing,
- const StringRef Prefix, Optional<unsigned> MaxControlFlowBooleans) {
+ const StringRef Prefix, std::optional<unsigned> MaxControlFlowBooleans) {
if (Outgoing.size() < 2)
return Outgoing.front();
diff --git a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
index fcdf31db28f4d..60012a71ed10d 100644
--- a/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
+++ b/llvm/lib/Transforms/Utils/BypassSlowDivision.cpp
@@ -86,7 +86,7 @@ class FastDivInsertionTask {
QuotRemPair createDivRemPhiNodes(QuotRemWithBB &LHS, QuotRemWithBB &RHS,
BasicBlock *PhiBB);
Value *insertOperandRuntimeCheck(Value *Op1, Value *Op2);
- Optional<QuotRemPair> insertFastDivAndRem();
+ std::optional<QuotRemPair> insertFastDivAndRem();
bool isSignedOp() {
return SlowDivOrRem->getOpcode() == Instruction::SDiv ||
@@ -160,7 +160,7 @@ Value *FastDivInsertionTask::getReplacement(DivCacheTy &Cache) {
if (CacheI == Cache.end()) {
// If previous instance does not exist, try to insert fast div.
- Optional<QuotRemPair> OptResult = insertFastDivAndRem();
+ std::optional<QuotRemPair> OptResult = insertFastDivAndRem();
// Bail out if insertFastDivAndRem has failed.
if (!OptResult)
return nullptr;
@@ -349,7 +349,7 @@ Value *FastDivInsertionTask::insertOperandRuntimeCheck(Value *Op1, Value *Op2) {
/// Substitutes the div/rem instruction with code that checks the value of the
/// operands and uses a shorter-faster div/rem instruction when possible.
-Optional<QuotRemPair> FastDivInsertionTask::insertFastDivAndRem() {
+std::optional<QuotRemPair> FastDivInsertionTask::insertFastDivAndRem() {
Value *Dividend = SlowDivOrRem->getOperand(0);
Value *Divisor = SlowDivOrRem->getOperand(1);
diff --git a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
index 2ff5aec8f8496..55bc74c00abd7 100644
--- a/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
+++ b/llvm/lib/Transforms/Utils/CodeMoverUtils.cpp
@@ -60,7 +60,7 @@ class ControlConditions {
/// \p BB from \p Dominator. If \p MaxLookup is non-zero, it limits the
/// number of conditions to collect. Return std::nullopt if not all conditions
/// are collected successfully, or we hit the limit.
- static const Optional<ControlConditions>
+ static const std::optional<ControlConditions>
collectControlConditions(const BasicBlock &BB, const BasicBlock &Dominator,
const DominatorTree &DT,
const PostDominatorTree &PDT,
@@ -105,9 +105,12 @@ static bool domTreeLevelBefore(DominatorTree *DT, const Instruction *InstA,
return DA->getLevel() < DB->getLevel();
}
-const Optional<ControlConditions> ControlConditions::collectControlConditions(
- const BasicBlock &BB, const BasicBlock &Dominator, const DominatorTree &DT,
- const PostDominatorTree &PDT, unsigned MaxLookup) {
+const std::optional<ControlConditions>
+ControlConditions::collectControlConditions(const BasicBlock &BB,
+ const BasicBlock &Dominator,
+ const DominatorTree &DT,
+ const PostDominatorTree &PDT,
+ unsigned MaxLookup) {
assert(DT.dominates(&Dominator, &BB) && "Expecting Dominator to dominate BB");
ControlConditions Conditions;
@@ -249,13 +252,13 @@ bool llvm::isControlFlowEquivalent(const BasicBlock &BB0, const BasicBlock &BB1,
<< " and " << BB1.getName() << " is "
<< CommonDominator->getName() << "\n");
- const Optional<ControlConditions> BB0Conditions =
+ const std::optional<ControlConditions> BB0Conditions =
ControlConditions::collectControlConditions(BB0, *CommonDominator, DT,
PDT);
if (BB0Conditions == std::nullopt)
return false;
- const Optional<ControlConditions> BB1Conditions =
+ const std::optional<ControlConditions> BB1Conditions =
ControlConditions::collectControlConditions(BB1, *CommonDominator, DT,
PDT);
if (BB1Conditions == std::nullopt)
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index af75fe11ad452..90e48f272655f 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -3030,9 +3030,9 @@ struct BitPart {
///
/// Because we pass around references into \c BPS, we must use a container that
/// does not invalidate internal references (std::map instead of DenseMap).
-static const Optional<BitPart> &
+static const std::optional<BitPart> &
collectBitParts(Value *V, bool MatchBSwaps, bool MatchBitReversals,
- std::map<Value *, Optional<BitPart>> &BPS, int Depth,
+ std::map<Value *, std::optional<BitPart>> &BPS, int Depth,
bool &FoundRoot) {
auto I = BPS.find(V);
if (I != BPS.end())
@@ -3282,7 +3282,7 @@ bool llvm::recognizeBSwapOrBitReverseIdiom(
// Try to find all the pieces corresponding to the bswap.
bool FoundRoot = false;
- std::map<Value *, Optional<BitPart>> BPS;
+ std::map<Value *, std::optional<BitPart>> BPS;
const auto &Res =
collectBitParts(I, MatchBSwaps, MatchBitReversals, BPS, 0, FoundRoot);
if (!Res)
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index 0c24c22c2d74e..d370d6c7fa214 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -161,7 +161,7 @@ class PhiAnalyzer {
// Calculate the sufficient minimum number of iterations of the loop to peel
// such that phi instructions become determined (subject to allowable limits)
- Optional<unsigned> calculateIterationsToPeel();
+ std::optional<unsigned> calculateIterationsToPeel();
protected:
using PeelCounter = std::optional<unsigned>;
@@ -253,7 +253,7 @@ PhiAnalyzer::PeelCounter PhiAnalyzer::calculate(const Value &V) {
return Unknown;
}
-Optional<unsigned> PhiAnalyzer::calculateIterationsToPeel() {
+std::optional<unsigned> PhiAnalyzer::calculateIterationsToPeel() {
unsigned Iterations = 0;
for (auto &PHI : L.getHeader()->phis()) {
PeelCounter ToInvariance = calculate(PHI);
@@ -265,7 +265,7 @@ Optional<unsigned> PhiAnalyzer::calculateIterationsToPeel() {
}
}
assert((Iterations <= MaxIterations) && "bad result in phi analysis");
- return Iterations ? Optional<unsigned>(Iterations) : std::nullopt;
+ return Iterations ? std::optional<unsigned>(Iterations) : std::nullopt;
}
} // unnamed namespace
@@ -570,7 +570,7 @@ void llvm::computePeelCount(Loop *L, unsigned LoopSize,
if (L->getHeader()->getParent()->hasProfileData()) {
if (violatesLegacyMultiExitLoopCheck(L))
return;
- Optional<unsigned> EstimatedTripCount = getLoopEstimatedTripCount(L);
+ std::optional<unsigned> EstimatedTripCount = getLoopEstimatedTripCount(L);
if (!EstimatedTripCount)
return;
@@ -808,10 +808,12 @@ static void cloneLoopBlocks(
LVMap[KV.first] = KV.second;
}
-TargetTransformInfo::PeelingPreferences llvm::gatherPeelingPreferences(
- Loop *L, ScalarEvolution &SE, const TargetTransformInfo &TTI,
- Optional<bool> UserAllowPeeling,
- Optional<bool> UserAllowProfileBasedPeeling, bool UnrollingSpecficValues) {
+TargetTransformInfo::PeelingPreferences
+llvm::gatherPeelingPreferences(Loop *L, ScalarEvolution &SE,
+ const TargetTransformInfo &TTI,
+ std::optional<bool> UserAllowPeeling,
+ std::optional<bool> UserAllowProfileBasedPeeling,
+ bool UnrollingSpecficValues) {
TargetTransformInfo::PeelingPreferences PP;
// Set the default values.
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index da8d3756a00b2..984a0010bed01 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -699,7 +699,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
};
auto WillExit = [&](const ExitInfo &Info, unsigned i, unsigned j,
- bool IsLatch) -> Optional<bool> {
+ bool IsLatch) -> std::optional<bool> {
if (CompletelyUnroll) {
if (PreserveOnlyFirst) {
if (i == 0)
@@ -739,7 +739,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
// The branch destination.
unsigned j = (i + 1) % e;
bool IsLatch = Pair.first == LatchBlock;
- Optional<bool> KnownWillExit = WillExit(Info, i, j, IsLatch);
+ std::optional<bool> KnownWillExit = WillExit(Info, i, j, IsLatch);
if (!KnownWillExit)
continue;
diff --git a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
index 0d1ed73d1ed42..f063438c7c41f 100644
--- a/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnrollRuntime.cpp
@@ -400,7 +400,7 @@ CloneLoopBlocks(Loop *L, Value *NewIter, const bool UseEpilogRemainder,
if (UnrollRemainder)
return NewLoop;
- Optional<MDNode *> NewLoopID = makeFollowupLoopID(
+ std::optional<MDNode *> NewLoopID = makeFollowupLoopID(
LoopID, {LLVMLoopUnrollFollowupAll, LLVMLoopUnrollFollowupRemainder});
if (NewLoopID) {
NewLoop->setLoopID(NewLoopID.value());
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index 9ada3a2dbe2a5..0e4576f807351 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -247,7 +247,7 @@ void llvm::addStringMetadataToLoop(Loop *TheLoop, const char *StringMD,
TheLoop->setLoopID(NewLoopID);
}
-Optional<ElementCount>
+std::optional<ElementCount>
llvm::getOptionalElementCountLoopAttribute(const Loop *TheLoop) {
std::optional<int> Width =
getOptionalIntLoopAttribute(TheLoop, "llvm.loop.vectorize.width");
@@ -261,7 +261,7 @@ llvm::getOptionalElementCountLoopAttribute(const Loop *TheLoop) {
return std::nullopt;
}
-Optional<MDNode *> llvm::makeFollowupLoopID(
+std::optional<MDNode *> llvm::makeFollowupLoopID(
MDNode *OrigLoopID, ArrayRef<StringRef> FollowupOptions,
const char *InheritOptionsExceptPrefix, bool AlwaysNew) {
if (!OrigLoopID) {
@@ -396,7 +396,7 @@ TransformationMode llvm::hasVectorizeTransformation(const Loop *L) {
if (Enable == false)
return TM_SuppressedByUser;
- Optional<ElementCount> VectorizeWidth =
+ std::optional<ElementCount> VectorizeWidth =
getOptionalElementCountLoopAttribute(L);
std::optional<int> InterleaveCount =
getOptionalIntLoopAttribute(L, "llvm.loop.interleave.count");
@@ -782,9 +782,9 @@ static BranchInst *getExpectedExitLoopLatchBranch(Loop *L) {
/// Return the estimated trip count for any exiting branch which dominates
/// the loop latch.
-static Optional<uint64_t>
-getEstimatedTripCount(BranchInst *ExitingBranch, Loop *L,
- uint64_t &OrigExitWeight) {
+static std::optional<uint64_t> getEstimatedTripCount(BranchInst *ExitingBranch,
+ Loop *L,
+ uint64_t &OrigExitWeight) {
// To estimate the number of times the loop body was executed, we want to
// know the number of times the backedge was taken, vs. the number of times
// we exited the loop.
@@ -808,7 +808,7 @@ getEstimatedTripCount(BranchInst *ExitingBranch, Loop *L,
return ExitCount + 1;
}
-Optional<unsigned>
+std::optional<unsigned>
llvm::getLoopEstimatedTripCount(Loop *L,
unsigned *EstimatedLoopInvocationWeight) {
// Currently we take the estimate exit count only from the loop latch,
@@ -817,8 +817,8 @@ llvm::getLoopEstimatedTripCount(Loop *L,
// TODO: incorporate information from other exits
if (BranchInst *LatchBranch = getExpectedExitLoopLatchBranch(L)) {
uint64_t ExitWeight;
- if (Optional<uint64_t> EstTripCount =
- getEstimatedTripCount(LatchBranch, L, ExitWeight)) {
+ if (std::optional<uint64_t> EstTripCount =
+ getEstimatedTripCount(LatchBranch, L, ExitWeight)) {
if (EstimatedLoopInvocationWeight)
*EstimatedLoopInvocationWeight = ExitWeight;
return *EstTripCount;
@@ -1477,7 +1477,7 @@ void llvm::setProfileInfoAfterUnrolling(Loop *OrigLoop, Loop *UnrolledLoop,
// Get number of iterations in the original scalar loop.
unsigned OrigLoopInvocationWeight = 0;
- Optional<unsigned> OrigAverageTripCount =
+ std::optional<unsigned> OrigAverageTripCount =
getLoopEstimatedTripCount(OrigLoop, &OrigLoopInvocationWeight);
if (!OrigAverageTripCount)
return;
@@ -1704,10 +1704,9 @@ Value *llvm::addDiffRuntimeChecks(
return MemoryRuntimeCheck;
}
-Optional<IVConditionInfo> llvm::hasPartialIVCondition(const Loop &L,
- unsigned MSSAThreshold,
- const MemorySSA &MSSA,
- AAResults &AA) {
+std::optional<IVConditionInfo>
+llvm::hasPartialIVCondition(const Loop &L, unsigned MSSAThreshold,
+ const MemorySSA &MSSA, AAResults &AA) {
auto *TI = dyn_cast<BranchInst>(L.getHeader()->getTerminator());
if (!TI || !TI->isConditional())
return {};
@@ -1764,7 +1763,7 @@ Optional<IVConditionInfo> llvm::hasPartialIVCondition(const Loop &L,
[&L, &AA, &AccessedLocs, &ExitingBlocks, &InstToDuplicate,
MSSAThreshold](BasicBlock *Succ, BasicBlock *Header,
SmallVector<MemoryAccess *, 4> AccessesToCheck)
- -> Optional<IVConditionInfo> {
+ -> std::optional<IVConditionInfo> {
IVConditionInfo Info;
// First, collect all blocks in the loop that are on a patch from Succ
// to the header.
diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
index 9a1f33410a7b1..1f16ba78bdb08 100644
--- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp
+++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp
@@ -783,7 +783,7 @@ PredicateInfo::~PredicateInfo() {
}
}
-Optional<PredicateConstraint> PredicateBase::getConstraint() const {
+std::optional<PredicateConstraint> PredicateBase::getConstraint() const {
switch (Type) {
case PT_Assume:
case PT_Branch: {
diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
index eed366c41deb5..437d2884e3f2f 100644
--- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -1558,7 +1558,8 @@ void SCCPInstVisitor::handleCallResult(CallBase &CB) {
const auto *PI = getPredicateInfoFor(&CB);
assert(PI && "Missing predicate info for ssa.copy");
- const Optional<PredicateConstraint> &Constraint = PI->getConstraint();
+ const std::optional<PredicateConstraint> &Constraint =
+ PI->getConstraint();
if (!Constraint) {
mergeInValue(ValueState[&CB], &CB, CopyOfVal);
return;
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index fecf2b109bb49..a9b883094ab20 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3139,7 +3139,7 @@ static ConstantInt *getKnownValueOnEdge(Value *V, BasicBlock *From,
/// If we have a conditional branch on something for which we know the constant
/// value in predecessors (e.g. a phi node in the current block), thread edges
/// from the predecessor to their ultimate destination.
-static Optional<bool>
+static std::optional<bool>
FoldCondBranchOnValueKnownInPredecessorImpl(BranchInst *BI, DomTreeUpdater *DTU,
const DataLayout &DL,
AssumptionCache *AC) {
@@ -3283,7 +3283,7 @@ static bool FoldCondBranchOnValueKnownInPredecessor(BranchInst *BI,
DomTreeUpdater *DTU,
const DataLayout &DL,
AssumptionCache *AC) {
- Optional<bool> Result;
+ std::optional<bool> Result;
bool EverChanged = false;
do {
// Note that None means "we changed things, but recurse further."
diff --git a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
index 9f0ad99f3220a..a7fe065c989f0 100644
--- a/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
@@ -1035,12 +1035,13 @@ class WidenIV {
// context.
DenseMap<DefUserPair, ConstantRange> PostIncRangeInfos;
- Optional<ConstantRange> getPostIncRangeInfo(Value *Def,
- Instruction *UseI) {
+ std::optional<ConstantRange> getPostIncRangeInfo(Value *Def,
+ Instruction *UseI) {
DefUserPair Key(Def, UseI);
auto It = PostIncRangeInfos.find(Key);
- return It == PostIncRangeInfos.end() ? Optional<ConstantRange>(std::nullopt)
- : Optional<ConstantRange>(It->second);
+ return It == PostIncRangeInfos.end()
+ ? std::optional<ConstantRange>(std::nullopt)
+ : std::optional<ConstantRange>(It->second);
}
void calculatePostIncRanges(PHINode *OrigPhi);
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 061ddd7432163..610d005db79a0 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -3746,12 +3746,9 @@ void LibCallSimplifier::eraseFromParent(Instruction *I) {
// Fortified Library Call Optimizations
//===----------------------------------------------------------------------===//
-bool
-FortifiedLibCallSimplifier::isFortifiedCallFoldable(CallInst *CI,
- unsigned ObjSizeOp,
- Optional<unsigned> SizeOp,
- Optional<unsigned> StrOp,
- Optional<unsigned> FlagOp) {
+bool FortifiedLibCallSimplifier::isFortifiedCallFoldable(
+ CallInst *CI, unsigned ObjSizeOp, std::optional<unsigned> SizeOp,
+ std::optional<unsigned> StrOp, std::optional<unsigned> FlagOp) {
// If this function takes a flag argument, the implementation may use it to
// perform extra checks. Don't fold into the non-checking variant.
if (FlagOp) {
diff --git a/llvm/lib/Transforms/Utils/ValueMapper.cpp b/llvm/lib/Transforms/Utils/ValueMapper.cpp
index 0d2e415260242..341783b870430 100644
--- a/llvm/lib/Transforms/Utils/ValueMapper.cpp
+++ b/llvm/lib/Transforms/Utils/ValueMapper.cpp
@@ -180,7 +180,7 @@ class Mapper {
Value *mapBlockAddress(const BlockAddress &BA);
/// Map metadata that doesn't require visiting operands.
- Optional<Metadata *> mapSimpleMetadata(const Metadata *MD);
+ std::optional<Metadata *> mapSimpleMetadata(const Metadata *MD);
Metadata *mapToMetadata(const Metadata *Key, Metadata *Val);
Metadata *mapToSelf(const Metadata *MD);
@@ -272,7 +272,7 @@ class MDNodeMapper {
/// \return std::nullopt if \c Op is an unmapped uniqued \a MDNode.
/// \post getMappedOp(Op) only returns std::nullopt if this returns
/// std::nullopt.
- Optional<Metadata *> tryToMapOperand(const Metadata *Op);
+ std::optional<Metadata *> tryToMapOperand(const Metadata *Op);
/// Map a distinct node.
///
@@ -284,7 +284,7 @@ class MDNodeMapper {
MDNode *mapDistinctNode(const MDNode &N);
/// Get a previously mapped node.
- Optional<Metadata *> getMappedOp(const Metadata *Op) const;
+ std::optional<Metadata *> getMappedOp(const Metadata *Op) const;
/// Create a post-order traversal of an unmapped uniqued node subgraph.
///
@@ -558,11 +558,11 @@ Metadata *Mapper::mapToSelf(const Metadata *MD) {
return mapToMetadata(MD, const_cast<Metadata *>(MD));
}
-Optional<Metadata *> MDNodeMapper::tryToMapOperand(const Metadata *Op) {
+std::optional<Metadata *> MDNodeMapper::tryToMapOperand(const Metadata *Op) {
if (!Op)
return nullptr;
- if (Optional<Metadata *> MappedOp = M.mapSimpleMetadata(Op)) {
+ if (std::optional<Metadata *> MappedOp = M.mapSimpleMetadata(Op)) {
#ifndef NDEBUG
if (auto *CMD = dyn_cast<ConstantAsMetadata>(Op))
assert((!*MappedOp || M.getVM().count(CMD->getValue()) ||
@@ -606,7 +606,7 @@ static ConstantAsMetadata *wrapConstantAsMetadata(const ConstantAsMetadata &CMD,
return MappedV ? ConstantAsMetadata::getConstant(MappedV) : nullptr;
}
-Optional<Metadata *> MDNodeMapper::getMappedOp(const Metadata *Op) const {
+std::optional<Metadata *> MDNodeMapper::getMappedOp(const Metadata *Op) const {
if (!Op)
return nullptr;
@@ -704,7 +704,7 @@ MDNode *MDNodeMapper::visitOperands(UniquedGraph &G, MDNode::op_iterator &I,
MDNode::op_iterator E, bool &HasChanged) {
while (I != E) {
Metadata *Op = *I++; // Increment even on early return.
- if (Optional<Metadata *> MappedOp = tryToMapOperand(Op)) {
+ if (std::optional<Metadata *> MappedOp = tryToMapOperand(Op)) {
// Check if the operand changes.
HasChanged |= Op != *MappedOp;
continue;
@@ -757,7 +757,7 @@ void MDNodeMapper::mapNodesInPOT(UniquedGraph &G) {
// Clone the uniqued node and remap the operands.
TempMDNode ClonedN = D.Placeholder ? std::move(D.Placeholder) : N->clone();
remapOperands(*ClonedN, [this, &D, &G](Metadata *Old) {
- if (Optional<Metadata *> MappedOp = getMappedOp(Old))
+ if (std::optional<Metadata *> MappedOp = getMappedOp(Old))
return *MappedOp;
(void)D;
assert(G.Info[Old].ID > D.ID && "Expected a forward reference");
@@ -796,7 +796,7 @@ Metadata *MDNodeMapper::map(const MDNode &N) {
N.isUniqued() ? mapTopLevelUniquedNode(N) : mapDistinctNode(N);
while (!DistinctWorklist.empty())
remapOperands(*DistinctWorklist.pop_back_val(), [this](Metadata *Old) {
- if (Optional<Metadata *> MappedOp = tryToMapOperand(Old))
+ if (std::optional<Metadata *> MappedOp = tryToMapOperand(Old))
return *MappedOp;
return mapTopLevelUniquedNode(*cast<MDNode>(Old));
});
@@ -825,7 +825,7 @@ Metadata *MDNodeMapper::mapTopLevelUniquedNode(const MDNode &FirstN) {
return *getMappedOp(&FirstN);
}
-Optional<Metadata *> Mapper::mapSimpleMetadata(const Metadata *MD) {
+std::optional<Metadata *> Mapper::mapSimpleMetadata(const Metadata *MD) {
// If the value already exists in the map, use it.
if (std::optional<Metadata *> NewMD = getVM().getMappedMD(MD))
return *NewMD;
@@ -855,7 +855,7 @@ Metadata *Mapper::mapMetadata(const Metadata *MD) {
assert(MD && "Expected valid metadata");
assert(!isa<LocalAsMetadata>(MD) && "Unexpected local metadata");
- if (Optional<Metadata *> NewMD = mapSimpleMetadata(MD))
+ if (std::optional<Metadata *> NewMD = mapSimpleMetadata(MD))
return *NewMD;
return MDNodeMapper(*this).map(*cast<MDNode>(MD));
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index f3d26507fc350..f366c31a5bbe6 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -410,7 +410,7 @@ static Optional<unsigned> getSmallBestKnownTC(ScalarEvolution &SE, Loop *L) {
// Check if there is an expected trip count available from profile data.
if (LoopVectorizeWithBlockFrequency)
if (auto EstimatedTC = getLoopEstimatedTripCount(L))
- return EstimatedTC;
+ return *EstimatedTC;
// Check if upper bound estimate is known.
if (unsigned ExpectedTC = SE.getSmallConstantMaxTripCount(L))
@@ -7683,7 +7683,7 @@ void LoopVectorizationPlanner::executePlan(ElementCount BestVF, unsigned BestUF,
// replace the vectorizer-specific hints below).
MDNode *OrigLoopID = OrigLoop->getLoopID();
- Optional<MDNode *> VectorizedLoopID =
+ std::optional<MDNode *> VectorizedLoopID =
makeFollowupLoopID(OrigLoopID, {LLVMLoopVectorizeFollowupAll,
LLVMLoopVectorizeFollowupVectorized});
@@ -10541,7 +10541,7 @@ bool LoopVectorizePass::processLoop(Loop *L) {
checkMixedPrecision(L, ORE);
}
- Optional<MDNode *> RemainderLoopID =
+ std::optional<MDNode *> RemainderLoopID =
makeFollowupLoopID(OrigLoopID, {LLVMLoopVectorizeFollowupAll,
LLVMLoopVectorizeFollowupEpilogue});
if (RemainderLoopID) {
More information about the llvm-commits
mailing list