aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorKazu Hirata <kazu@google.com>2022-12-02 19:43:04 -0800
committerKazu Hirata <kazu@google.com>2022-12-02 19:43:04 -0800
commit19aff0f37dd68ee51e78b764c0ce629ae73d1eef (patch)
tree07403086631814ae1ff7742c8c6dac4fb67b5088 /llvm/lib/Analysis/ValueTracking.cpp
parentfef3a16aeab660d0789c592985993bd68b51f517 (diff)
downloadllvm-19aff0f37dd68ee51e78b764c0ce629ae73d1eef.zip
llvm-19aff0f37dd68ee51e78b764c0ce629ae73d1eef.tar.gz
llvm-19aff0f37dd68ee51e78b764c0ce629ae73d1eef.tar.bz2
[Analysis] Use std::nullopt instead of None (NFC)
This patch mechanically replaces None with std::nullopt where the compiler would warn if None were deprecated. The intent is to reduce the amount of manual work required in migrating from Optional to std::optional. This is part of an effort to migrate from llvm::Optional to std::optional: https://discourse.llvm.org/t/deprecating-llvm-optional-x-hasvalue-getvalue-getvalueor/63716
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp42
1 files changed, 21 insertions, 21 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index f29b0f8..878177e 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -2750,7 +2750,7 @@ static std::optional<std::pair<Value*, Value*>>
getInvertibleOperands(const Operator *Op1,
const Operator *Op2) {
if (Op1->getOpcode() != Op2->getOpcode())
- return None;
+ return std::nullopt;
auto getOperands = [&](unsigned OpNum) -> auto {
return std::make_pair(Op1->getOperand(OpNum), Op2->getOperand(OpNum));
@@ -2844,7 +2844,7 @@ getInvertibleOperands(const Operator *Op1,
return std::make_pair(Start1, Start2);
}
}
- return None;
+ return std::nullopt;
}
/// Return true if V2 == V1 + X, where X is known non-zero.
@@ -6664,21 +6664,21 @@ isImpliedCondOperands(CmpInst::Predicate Pred, const Value *ALHS,
const DataLayout &DL, unsigned Depth) {
switch (Pred) {
default:
- return None;
+ return std::nullopt;
case CmpInst::ICMP_SLT:
case CmpInst::ICMP_SLE:
if (isTruePredicate(CmpInst::ICMP_SLE, BLHS, ALHS, DL, Depth) &&
isTruePredicate(CmpInst::ICMP_SLE, ARHS, BRHS, DL, Depth))
return true;
- return None;
+ return std::nullopt;
case CmpInst::ICMP_ULT:
case CmpInst::ICMP_ULE:
if (isTruePredicate(CmpInst::ICMP_ULE, BLHS, ALHS, DL, Depth) &&
isTruePredicate(CmpInst::ICMP_ULE, ARHS, BRHS, DL, Depth))
return true;
- return None;
+ return std::nullopt;
}
}
@@ -6707,7 +6707,7 @@ static Optional<bool> isImpliedCondMatchingOperands(CmpInst::Predicate LPred,
if (CmpInst::isImpliedFalseByMatchingCmp(LPred, RPred))
return false;
- return None;
+ return std::nullopt;
}
/// Return true if "icmp LPred X, LC" implies "icmp RPred X, RC" is true.
@@ -6724,7 +6724,7 @@ static Optional<bool> isImpliedCondCommonOperandWithConstants(
return false;
if (Difference.isEmptySet())
return true;
- return None;
+ return std::nullopt;
}
/// Return true if LHS implies RHS (expanded to its components as "R0 RPred R1")
@@ -6757,7 +6757,7 @@ static Optional<bool> isImpliedCondICmps(const ICmpInst *LHS,
if (LPred == RPred)
return isImpliedCondOperands(LPred, L0, L1, R0, R1, DL, Depth);
- return None;
+ return std::nullopt;
}
/// Return true if LHS implies RHS is true. Return false if LHS implies RHS is
@@ -6788,9 +6788,9 @@ isImpliedCondAndOr(const Instruction *LHS, CmpInst::Predicate RHSPred,
if (Optional<bool> Implication = isImpliedCondition(
ARHS, RHSPred, RHSOp0, RHSOp1, DL, LHSIsTrue, Depth + 1))
return Implication;
- return None;
+ return std::nullopt;
}
- return None;
+ return std::nullopt;
}
Optional<bool>
@@ -6799,12 +6799,12 @@ llvm::isImpliedCondition(const Value *LHS, CmpInst::Predicate RHSPred,
const DataLayout &DL, bool LHSIsTrue, unsigned Depth) {
// Bail out when we hit the limit.
if (Depth == MaxAnalysisRecursionDepth)
- return None;
+ return std::nullopt;
// A mismatch occurs when we compare a scalar cmp to a vector cmp, for
// example.
if (RHSOp0->getType()->isVectorTy() != LHS->getType()->isVectorTy())
- return None;
+ return std::nullopt;
assert(LHS->getType()->isIntOrIntVectorTy(1) &&
"Expected integer type only!");
@@ -6825,7 +6825,7 @@ llvm::isImpliedCondition(const Value *LHS, CmpInst::Predicate RHSPred,
return isImpliedCondAndOr(LHSI, RHSPred, RHSOp0, RHSOp1, DL, LHSIsTrue,
Depth);
}
- return None;
+ return std::nullopt;
}
Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
@@ -6841,7 +6841,7 @@ Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
LHSIsTrue, Depth);
if (Depth == MaxAnalysisRecursionDepth)
- return None;
+ return std::nullopt;
// LHS ==> (RHS1 || RHS2) if LHS ==> RHS1 or LHS ==> RHS2
// LHS ==> !(RHS1 && RHS2) if LHS ==> !RHS1 or LHS ==> !RHS2
@@ -6867,7 +6867,7 @@ Optional<bool> llvm::isImpliedCondition(const Value *LHS, const Value *RHS,
return false;
}
- return None;
+ return std::nullopt;
}
// Returns a pair (Condition, ConditionIsTrue), where Condition is a branch
@@ -6908,7 +6908,7 @@ Optional<bool> llvm::isImpliedByDomCondition(const Value *Cond,
auto PredCond = getDomPredecessorCondition(ContextI);
if (PredCond.first)
return isImpliedCondition(PredCond.first, Cond, DL, PredCond.second);
- return None;
+ return std::nullopt;
}
Optional<bool> llvm::isImpliedByDomCondition(CmpInst::Predicate Pred,
@@ -6919,7 +6919,7 @@ Optional<bool> llvm::isImpliedByDomCondition(CmpInst::Predicate Pred,
if (PredCond.first)
return isImpliedCondition(PredCond.first, Pred, LHS, RHS, DL,
PredCond.second);
- return None;
+ return std::nullopt;
}
static void setLimitsForBinOp(const BinaryOperator &BO, APInt &Lower,
@@ -7335,7 +7335,7 @@ getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL) {
for (unsigned i = Idx, e = GEP->getNumOperands(); i != e; ++i, ++GTI) {
ConstantInt *OpC = dyn_cast<ConstantInt>(GEP->getOperand(i));
if (!OpC)
- return None;
+ return std::nullopt;
if (OpC->isZero())
continue; // No offset.
@@ -7349,7 +7349,7 @@ getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL) {
// vector. Multiply the index by the ElementSize.
TypeSize Size = DL.getTypeAllocSize(GTI.getIndexedType());
if (Size.isScalable())
- return None;
+ return std::nullopt;
Offset += Size.getFixedSize() * OpC->getSExtValue();
}
@@ -7377,7 +7377,7 @@ Optional<int64_t> llvm::isPointerOffset(const Value *Ptr1, const Value *Ptr2,
// handle no other case.
if (!GEP1 || !GEP2 || GEP1->getOperand(0) != GEP2->getOperand(0) ||
GEP1->getSourceElementType() != GEP2->getSourceElementType())
- return None;
+ return std::nullopt;
// Skip any common indices and track the GEP types.
unsigned Idx = 1;
@@ -7388,7 +7388,7 @@ Optional<int64_t> llvm::isPointerOffset(const Value *Ptr1, const Value *Ptr2,
auto IOffset1 = getOffsetFromIndex(GEP1, Idx, DL);
auto IOffset2 = getOffsetFromIndex(GEP2, Idx, DL);
if (!IOffset1 || !IOffset2)
- return None;
+ return std::nullopt;
return *IOffset2 - *IOffset1 + Offset2.getSExtValue() -
Offset1.getSExtValue();
}