-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm] Use dyn_cast_if_present instead of dyn_cast_or_null (NFC) #75733
[llvm] Use dyn_cast_if_present instead of dyn_cast_or_null (NFC) #75733
Conversation
Note that dyn_cast_and_nonnull has been soft-deprecated since: commit f156b51 Author: bzcheeseman <12992886+bzcheeseman@users.noreply.github.com> Date: Sat Apr 16 11:34:08 2022 -0700
@llvm/pr-subscribers-compiler-rt-sanitizer @llvm/pr-subscribers-backend-arm Author: Kazu Hirata (kazutakahirata) ChangesNote that dyn_cast_and_nonnull has been soft-deprecated since: commit f156b51 Patch is 300.00 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/75733.diff 212 Files Affected:
diff --git a/llvm/include/llvm/Analysis/SparsePropagation.h b/llvm/include/llvm/Analysis/SparsePropagation.h
index d5805a7314757f..1d58b82d57ff08 100644
--- a/llvm/include/llvm/Analysis/SparsePropagation.h
+++ b/llvm/include/llvm/Analysis/SparsePropagation.h
@@ -318,7 +318,7 @@ void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::getFeasibleSuccessors(
return;
Constant *C =
- dyn_cast_or_null<Constant>(LatticeFunc->GetValueFromLatticeVal(
+ dyn_cast_if_present<Constant>(LatticeFunc->GetValueFromLatticeVal(
std::move(BCValue), BI->getCondition()->getType()));
if (!C || !isa<ConstantInt>(C)) {
// Non-constant values can go either way.
@@ -356,8 +356,9 @@ void SparseSolver<LatticeKey, LatticeVal, KeyInfo>::getFeasibleSuccessors(
if (SCValue == LatticeFunc->getUndefVal())
return;
- Constant *C = dyn_cast_or_null<Constant>(LatticeFunc->GetValueFromLatticeVal(
- std::move(SCValue), SI.getCondition()->getType()));
+ Constant *C =
+ dyn_cast_if_present<Constant>(LatticeFunc->GetValueFromLatticeVal(
+ std::move(SCValue), SI.getCondition()->getType()));
if (!C || !isa<ConstantInt>(C)) {
// All destinations are executable!
Succs.assign(TI.getNumSuccessors(), true);
diff --git a/llvm/include/llvm/CodeGen/BasicTTIImpl.h b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
index 5e7bdcdf72a49f..6528281be426e6 100644
--- a/llvm/include/llvm/CodeGen/BasicTTIImpl.h
+++ b/llvm/include/llvm/CodeGen/BasicTTIImpl.h
@@ -1730,7 +1730,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
if (FOp) {
if (ICA.getID() == Intrinsic::vp_load) {
Align Alignment;
- if (auto *VPI = dyn_cast_or_null<VPIntrinsic>(ICA.getInst()))
+ if (auto *VPI = dyn_cast_if_present<VPIntrinsic>(ICA.getInst()))
Alignment = VPI->getPointerAlignment().valueOrOne();
unsigned AS = 0;
if (ICA.getArgs().size() > 1)
@@ -1742,7 +1742,7 @@ class BasicTTIImplBase : public TargetTransformInfoImplCRTPBase<T> {
}
if (ICA.getID() == Intrinsic::vp_store) {
Align Alignment;
- if (auto *VPI = dyn_cast_or_null<VPIntrinsic>(ICA.getInst()))
+ if (auto *VPI = dyn_cast_if_present<VPIntrinsic>(ICA.getInst()))
Alignment = VPI->getPointerAlignment().valueOrOne();
unsigned AS = 0;
if (ICA.getArgs().size() >= 2)
diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
index ffb6e53a0363f9..ef81a1a3ea0221 100644
--- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
+++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h
@@ -254,7 +254,7 @@ Register getSrcRegIgnoringCopies(Register Reg, const MachineRegisterInfo &MRI);
template <class T>
T *getOpcodeDef(Register Reg, const MachineRegisterInfo &MRI) {
MachineInstr *DefMI = getDefIgnoringCopies(Reg, MRI);
- return dyn_cast_or_null<T>(DefMI);
+ return dyn_cast_if_present<T>(DefMI);
}
/// Returns an APFloat from Val converted to the appropriate size.
diff --git a/llvm/include/llvm/IR/DebugInfoMetadata.h b/llvm/include/llvm/IR/DebugInfoMetadata.h
index f521862b1a54c2..c0cabf6927387d 100644
--- a/llvm/include/llvm/IR/DebugInfoMetadata.h
+++ b/llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -1066,7 +1066,7 @@ class DIDerivedType : public DIType {
DIType *getClassType() const;
DIObjCProperty *getObjCProperty() const {
- return dyn_cast_or_null<DIObjCProperty>(getExtraData());
+ return dyn_cast_if_present<DIObjCProperty>(getExtraData());
}
uint32_t getVBPtrOffset() const;
@@ -1244,33 +1244,33 @@ class DICompositeType : public DIType {
}
Metadata *getRawDataLocation() const { return getOperand(9); }
DIVariable *getDataLocation() const {
- return dyn_cast_or_null<DIVariable>(getRawDataLocation());
+ return dyn_cast_if_present<DIVariable>(getRawDataLocation());
}
DIExpression *getDataLocationExp() const {
- return dyn_cast_or_null<DIExpression>(getRawDataLocation());
+ return dyn_cast_if_present<DIExpression>(getRawDataLocation());
}
Metadata *getRawAssociated() const { return getOperand(10); }
DIVariable *getAssociated() const {
- return dyn_cast_or_null<DIVariable>(getRawAssociated());
+ return dyn_cast_if_present<DIVariable>(getRawAssociated());
}
DIExpression *getAssociatedExp() const {
- return dyn_cast_or_null<DIExpression>(getRawAssociated());
+ return dyn_cast_if_present<DIExpression>(getRawAssociated());
}
Metadata *getRawAllocated() const { return getOperand(11); }
DIVariable *getAllocated() const {
- return dyn_cast_or_null<DIVariable>(getRawAllocated());
+ return dyn_cast_if_present<DIVariable>(getRawAllocated());
}
DIExpression *getAllocatedExp() const {
- return dyn_cast_or_null<DIExpression>(getRawAllocated());
+ return dyn_cast_if_present<DIExpression>(getRawAllocated());
}
Metadata *getRawRank() const { return getOperand(12); }
ConstantInt *getRankConst() const {
- if (auto *MD = dyn_cast_or_null<ConstantAsMetadata>(getRawRank()))
- return dyn_cast_or_null<ConstantInt>(MD->getValue());
+ if (auto *MD = dyn_cast_if_present<ConstantAsMetadata>(getRawRank()))
+ return dyn_cast_if_present<ConstantInt>(MD->getValue());
return nullptr;
}
DIExpression *getRankExp() const {
- return dyn_cast_or_null<DIExpression>(getRawRank());
+ return dyn_cast_if_present<DIExpression>(getRawRank());
}
Metadata *getRawAnnotations() const { return getOperand(13); }
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 6eba902fa04165..e6ca678aecc951 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1479,7 +1479,7 @@ class CallBase : public Instruction {
/// Returns the function called, or null if this is an indirect function
/// invocation or the function signature does not match the call signature.
Function *getCalledFunction() const {
- if (auto *F = dyn_cast_or_null<Function>(getCalledOperand()))
+ if (auto *F = dyn_cast_if_present<Function>(getCalledOperand()))
if (F->getValueType() == getFunctionType())
return F;
return nullptr;
diff --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index 4498423c4c460d..8a727c9b7429f5 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -683,7 +683,7 @@ dyn_extract(Y &&MD) {
template <class X, class Y>
inline std::enable_if_t<detail::IsValidPointer<X, Y>::value, X *>
dyn_extract_or_null(Y &&MD) {
- if (auto *V = dyn_cast_or_null<ConstantAsMetadata>(MD))
+ if (auto *V = dyn_cast_if_present<ConstantAsMetadata>(MD))
return dyn_cast<X>(V->getValue());
return nullptr;
}
@@ -1539,11 +1539,11 @@ class AliasScopeNode {
const MDNode *getDomain() const {
if (Node->getNumOperands() < 2)
return nullptr;
- return dyn_cast_or_null<MDNode>(Node->getOperand(1));
+ return dyn_cast_if_present<MDNode>(Node->getOperand(1));
}
StringRef getName() const {
if (Node->getNumOperands() > 2)
- if (MDString *N = dyn_cast_or_null<MDString>(Node->getOperand(2)))
+ if (MDString *N = dyn_cast_if_present<MDString>(Node->getOperand(2)))
return N->getString();
return StringRef();
}
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 096d1688af3f72..39c28d68dde5a7 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -239,8 +239,8 @@ struct apint_match {
}
if (V->getType()->isVectorTy())
if (const auto *C = dyn_cast<Constant>(V))
- if (auto *CI =
- dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowUndef))) {
+ if (auto *CI = dyn_cast_if_present<ConstantInt>(
+ C->getSplatValue(AllowUndef))) {
Res = &CI->getValue();
return true;
}
@@ -265,7 +265,7 @@ struct apfloat_match {
if (V->getType()->isVectorTy())
if (const auto *C = dyn_cast<Constant>(V))
if (auto *CI =
- dyn_cast_or_null<ConstantFP>(C->getSplatValue(AllowUndef))) {
+ dyn_cast_if_present<ConstantFP>(C->getSplatValue(AllowUndef))) {
Res = &CI->getValueAPF();
return true;
}
@@ -337,7 +337,8 @@ struct cstval_pred_ty : public Predicate {
return this->isValue(CV->getValue());
if (const auto *VTy = dyn_cast<VectorType>(V->getType())) {
if (const auto *C = dyn_cast<Constant>(V)) {
- if (const auto *CV = dyn_cast_or_null<ConstantVal>(C->getSplatValue()))
+ if (const auto *CV =
+ dyn_cast_if_present<ConstantVal>(C->getSplatValue()))
return this->isValue(CV->getValue());
// Number of elements of a scalable vector unknown at compile time
@@ -390,7 +391,7 @@ template <typename Predicate> struct api_pred_ty : public Predicate {
}
if (V->getType()->isVectorTy())
if (const auto *C = dyn_cast<Constant>(V))
- if (auto *CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue()))
+ if (auto *CI = dyn_cast_if_present<ConstantInt>(C->getSplatValue()))
if (this->isValue(CI->getValue())) {
Res = &CI->getValue();
return true;
@@ -416,7 +417,7 @@ template <typename Predicate> struct apf_pred_ty : public Predicate {
}
if (V->getType()->isVectorTy())
if (const auto *C = dyn_cast<Constant>(V))
- if (auto *CI = dyn_cast_or_null<ConstantFP>(
+ if (auto *CI = dyn_cast_if_present<ConstantFP>(
C->getSplatValue(/* AllowUndef */ true)))
if (this->isValue(CI->getValue())) {
Res = &CI->getValue();
@@ -812,7 +813,7 @@ struct specific_fpval {
return CFP->isExactlyValue(Val);
if (V->getType()->isVectorTy())
if (const auto *C = dyn_cast<Constant>(V))
- if (auto *CFP = dyn_cast_or_null<ConstantFP>(C->getSplatValue()))
+ if (auto *CFP = dyn_cast_if_present<ConstantFP>(C->getSplatValue()))
return CFP->isExactlyValue(Val);
return false;
}
@@ -851,7 +852,7 @@ template <bool AllowUndefs> struct specific_intval {
const auto *CI = dyn_cast<ConstantInt>(V);
if (!CI && V->getType()->isVectorTy())
if (const auto *C = dyn_cast<Constant>(V))
- CI = dyn_cast_or_null<ConstantInt>(C->getSplatValue(AllowUndefs));
+ CI = dyn_cast_if_present<ConstantInt>(C->getSplatValue(AllowUndefs));
return CI && APInt::isSameValue(CI->getValue(), Val);
}
diff --git a/llvm/include/llvm/IR/Statepoint.h b/llvm/include/llvm/IR/Statepoint.h
index 21c4a3eaa5ac2d..97f26b00b617c8 100644
--- a/llvm/include/llvm/IR/Statepoint.h
+++ b/llvm/include/llvm/IR/Statepoint.h
@@ -114,7 +114,7 @@ class GCStatepointInst : public CallBase {
/// Returns the function called if this is a wrapping a direct call, and null
/// otherwise.
Function *getActualCalledFunction() const {
- return dyn_cast_or_null<Function>(getActualCalledOperand());
+ return dyn_cast_if_present<Function>(getActualCalledOperand());
}
/// Return the type of the value returned by the call underlying the
diff --git a/llvm/include/llvm/ProfileData/InstrProfReader.h b/llvm/include/llvm/ProfileData/InstrProfReader.h
index ff50dfde0e7938..9471963cfba2ee 100644
--- a/llvm/include/llvm/ProfileData/InstrProfReader.h
+++ b/llvm/include/llvm/ProfileData/InstrProfReader.h
@@ -349,7 +349,7 @@ class RawInstrProfReader : public InstrProfReader {
const InstrProfCorrelator *Correlator,
std::function<void(Error)> Warn)
: DataBuffer(std::move(DataBuffer)),
- Correlator(dyn_cast_or_null<const InstrProfCorrelatorImpl<IntPtrT>>(
+ Correlator(dyn_cast_if_present<const InstrProfCorrelatorImpl<IntPtrT>>(
Correlator)),
Warn(Warn) {}
RawInstrProfReader(const RawInstrProfReader &) = delete;
diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp b/llvm/lib/Analysis/CallGraphSCCPass.cpp
index 307dddd51ece05..66ce1ea7e5c003 100644
--- a/llvm/lib/Analysis/CallGraphSCCPass.cpp
+++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp
@@ -263,7 +263,7 @@ bool CGPassManager::RefreshCallGraph(const CallGraphSCC &CurSCC, CallGraph &CG,
// If this call site is null, then the function pass deleted the call
// entirely and the WeakTrackingVH nulled it out.
- auto *Call = dyn_cast_or_null<CallBase>(*I->first);
+ auto *Call = dyn_cast_if_present<CallBase>(*I->first);
if (!Call ||
// If we've already seen this call site, then the FunctionPass RAUW'd
// one call with another, which resulted in two "uses" in the edge
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 90da3390eab324..6b57fdf4e5c464 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -87,7 +87,7 @@ static Constant *foldConstVectorToAPInt(APInt &Result, Type *DestTy,
continue;
}
- auto *ElementCI = dyn_cast_or_null<ConstantInt>(Element);
+ auto *ElementCI = dyn_cast_if_present<ConstantInt>(Element);
if (!ElementCI)
return ConstantExpr::getBitCast(C, DestTy);
@@ -222,7 +222,7 @@ Constant *FoldBitCast(Constant *C, Type *DestTy, const DataLayout &DL) {
Src = Constant::getNullValue(
cast<VectorType>(C->getType())->getElementType());
else
- Src = dyn_cast_or_null<ConstantInt>(Src);
+ Src = dyn_cast_if_present<ConstantInt>(Src);
if (!Src) // Reject constantexpr elements.
return ConstantExpr::getBitCast(C, DestTy);
@@ -2490,7 +2490,7 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
case Intrinsic::x86_sse2_cvtsd2si:
case Intrinsic::x86_sse2_cvtsd2si64:
if (ConstantFP *FPOp =
- dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
+ dyn_cast_if_present<ConstantFP>(Op->getAggregateElement(0U)))
return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
/*roundTowardZero=*/false, Ty,
/*IsSigned*/true);
@@ -2500,7 +2500,7 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
case Intrinsic::x86_sse2_cvttsd2si:
case Intrinsic::x86_sse2_cvttsd2si64:
if (ConstantFP *FPOp =
- dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
+ dyn_cast_if_present<ConstantFP>(Op->getAggregateElement(0U)))
return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
/*roundTowardZero=*/true, Ty,
/*IsSigned*/true);
@@ -2882,7 +2882,7 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
case Intrinsic::x86_avx512_vcvtsd2si32:
case Intrinsic::x86_avx512_vcvtsd2si64:
if (ConstantFP *FPOp =
- dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
+ dyn_cast_if_present<ConstantFP>(Op->getAggregateElement(0U)))
return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
/*roundTowardZero=*/false, Ty,
/*IsSigned*/true);
@@ -2892,7 +2892,7 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
case Intrinsic::x86_avx512_vcvtsd2usi32:
case Intrinsic::x86_avx512_vcvtsd2usi64:
if (ConstantFP *FPOp =
- dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
+ dyn_cast_if_present<ConstantFP>(Op->getAggregateElement(0U)))
return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
/*roundTowardZero=*/false, Ty,
/*IsSigned*/false);
@@ -2902,7 +2902,7 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
case Intrinsic::x86_avx512_cvttsd2si:
case Intrinsic::x86_avx512_cvttsd2si64:
if (ConstantFP *FPOp =
- dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
+ dyn_cast_if_present<ConstantFP>(Op->getAggregateElement(0U)))
return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
/*roundTowardZero=*/true, Ty,
/*IsSigned*/true);
@@ -2912,7 +2912,7 @@ static Constant *ConstantFoldScalarCall2(StringRef Name,
case Intrinsic::x86_avx512_cvttsd2usi:
case Intrinsic::x86_avx512_cvttsd2usi64:
if (ConstantFP *FPOp =
- dyn_cast_or_null<ConstantFP>(Op->getAggregateElement(0U)))
+ dyn_cast_if_present<ConstantFP>(Op->getAggregateElement(0U)))
return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(),
/*roundTowardZero=*/true, Ty,
/*IsSigned*/false);
diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp
index 1aa324c6b5f380..2c08425893aa54 100644
--- a/llvm/lib/Analysis/IVDescriptors.cpp
+++ b/llvm/lib/Analysis/IVDescriptors.cpp
@@ -974,7 +974,7 @@ bool RecurrenceDescriptor::isFixedOrderRecurrence(PHINode *Phi, Loop *TheLoop,
// in the header will be dominated by the original phi, but need to be moved
// after the non-phi previous value.
SmallPtrSet<PHINode *, 4> SeenPhis;
- while (auto *PrevPhi = dyn_cast_or_null<PHINode>(Previous)) {
+ while (auto *PrevPhi = dyn_cast_if_present<PHINode>(Previous)) {
if (PrevPhi->getParent() != Phi->getParent())
return false;
if (!SeenPhis.insert(PrevPhi).second)
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 7096e06d925ade..e083430f18acfd 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -1458,7 +1458,7 @@ bool CallAnalyzer::visitAlloca(AllocaInst &I) {
// alloca and handle that case.
if (I.isArrayAllocation()) {
Constant *Size = SimplifiedValues.lookup(I.getArraySize());
- if (auto *AllocSize = dyn_cast_or_null<ConstantInt>(Size)) {
+ if (auto *AllocSize = dyn_cast_if_present<ConstantInt>(Size)) {
// Sometimes a dynamic alloca could be converted into a static alloca
// after this constant prop, and become a huge static alloca on an
// unconditional CFG path. Avoid inlining if this is going to happen above
@@ -1671,7 +1671,7 @@ bool CallAnalyzer::simplifyIntrinsicCallIsConstant(CallBase &CB) {
auto *C = dyn_cast<Constant>(Arg);
if (!C)
- C = dyn_cast_or_null<Constant>(SimplifiedValues.lookup(Arg));
+ C = dyn_cast_if_present<Constant>(SimplifiedValues.lookup(Arg));
Type *RT = CB.getFunctionType()->getReturnType();
SimplifiedValues[&CB] = ConstantInt::get(RT, C ? 1 : 0);
@@ -1686,7 +1686,7 @@ bool CallAnalyzer::simplifyIntrinsicCallObjectSize(CallBase &CB) {
Value *V = lowerObjectSizeCall(&cast<IntrinsicInst>(CB), DL, nullptr,
/*MustSucceed=*/true);
- Constant *C = dyn_cast_or_null<Constant>(V);
+ Constant *C = dyn_cast_if_present<Constant>(V);
if (C)
SimplifiedValues[&CB] = C;
return C;
@@ -2120,7 +2120,7 @@ bool CallAnalyzer::visitBinaryOperator(BinaryOperator &I) {
SimpleV =
simplifyBinOp(I.getOpcode(), CLHS ? CLHS : LHS, CRHS ? CRHS : RHS, DL);
- if (Constant *C = dyn_cast_or_null<Constant>(SimpleV))
+ if (Constant *C = dyn_cast_if_present<Constant>(SimpleV))
SimplifiedValues[&I] = C;
if (SimpleV)
@@ -2151,7 +2151,7 @@ bool CallAnalyzer::visitFNeg(UnaryOperator &I) {
Value *SimpleV = simplifyFNegInst(
COp ? COp : Op, cast<FPMathOperator>(I).getFastMathFlags(), DL);
- if (Constant *C = dyn_cast_or_null<Constant>(SimpleV))
+ if (Constant *C = dyn_cast_if_present<Constant>(SimpleV))
SimplifiedValues[&I] = C;
if (SimpleV)
@@ -2236,7 +2236,7 @@ bool CallAnalyzer::simplifyCallSite(Function *F, CallBase &Call) {
for (Value *I : Call.args()) {
Constant *C = dyn_cast<Constant>(I);
if (!C)
- C = dyn_cast_or_null<Constant>(SimplifiedValues.lookup(I));
+ C = dyn_cast_if_present<Constant>(SimplifiedValues.lookup(I));
if (!C)
return false; // This argument doesn't map to a constant.
@@ -2269,7 +2269,7 @@ bool CallAnalyzer::visitCallB...
[truncated]
|
You can test this locally with the following command:git-clang-format --diff ea979b24b0a755c9839e32dd716078ea816a0508 b7c203ef24b9671c47c31a84bc11b8c845841ac5 -- llvm/include/llvm/Analysis/SparsePropagation.h llvm/include/llvm/CodeGen/BasicTTIImpl.h llvm/include/llvm/CodeGen/GlobalISel/Utils.h llvm/include/llvm/IR/DebugInfoMetadata.h llvm/include/llvm/IR/InstrTypes.h llvm/include/llvm/IR/Metadata.h llvm/include/llvm/IR/PatternMatch.h llvm/include/llvm/IR/Statepoint.h llvm/include/llvm/ProfileData/InstrProfReader.h llvm/lib/Analysis/CallGraphSCCPass.cpp llvm/lib/Analysis/ConstantFolding.cpp llvm/lib/Analysis/IVDescriptors.cpp llvm/lib/Analysis/InlineCost.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/MemoryDependenceAnalysis.cpp llvm/lib/Analysis/MemorySSA.cpp llvm/lib/Analysis/MemorySSAUpdater.cpp llvm/lib/Analysis/MustExecute.cpp llvm/lib/Analysis/PHITransAddr.cpp llvm/lib/Analysis/ScalarEvolution.cpp llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp llvm/lib/Analysis/ValueTracking.cpp llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Reader/MetadataLoader.cpp llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp llvm/lib/CodeGen/CodeGenPrepare.cpp llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp llvm/lib/CodeGen/GlobalISel/Utils.cpp llvm/lib/CodeGen/LowerEmuTLS.cpp llvm/lib/CodeGen/MIRParser/MIParser.cpp llvm/lib/CodeGen/MIRParser/MIRParser.cpp llvm/lib/CodeGen/MachineFunction.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp llvm/lib/CodeGen/StackColoring.cpp llvm/lib/CodeGen/StackFrameLayoutAnalysisPass.cpp llvm/lib/CodeGen/StackSlotColoring.cpp llvm/lib/CodeGen/TargetLoweringBase.cpp llvm/lib/CodeGen/WinEHPrepare.cpp llvm/lib/DebugInfo/DWARF/DWARFContext.cpp llvm/lib/DebugInfo/PDB/PDBContext.cpp llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp llvm/lib/DebugInfo/Symbolize/Symbolize.cpp llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/AutoUpgrade.cpp llvm/lib/IR/BasicBlock.cpp llvm/lib/IR/ConstantFold.cpp llvm/lib/IR/Constants.cpp llvm/lib/IR/Core.cpp llvm/lib/IR/DIBuilder.cpp llvm/lib/IR/DebugInfo.cpp llvm/lib/IR/DebugInfoMetadata.cpp llvm/lib/IR/LLVMContextImpl.h llvm/lib/IR/Mangler.cpp llvm/lib/IR/Metadata.cpp llvm/lib/IR/Module.cpp llvm/lib/IR/ModuleSummaryIndex.cpp llvm/lib/IR/ProfileSummary.cpp llvm/lib/IR/Type.cpp llvm/lib/IR/User.cpp llvm/lib/IR/Value.cpp llvm/lib/IR/Verifier.cpp llvm/lib/LTO/LTO.cpp llvm/lib/Linker/LinkModules.cpp llvm/lib/MC/MCObjectStreamer.cpp llvm/lib/MC/MCParser/ELFAsmParser.cpp llvm/lib/MC/MCParser/MasmParser.cpp llvm/lib/MC/MachObjectWriter.cpp llvm/lib/Object/ArchiveWriter.cpp llvm/lib/ObjectYAML/ELFEmitter.cpp llvm/lib/ProfileData/InstrProf.cpp llvm/lib/Support/YAMLTraits.cpp llvm/lib/TableGen/Error.cpp llvm/lib/TableGen/Record.cpp llvm/lib/TableGen/TGParser.cpp llvm/lib/Target/AArch64/AArch64ISelLowering.cpp llvm/lib/Target/AArch64/AArch64MachineFunctionInfo.cpp llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp llvm/lib/Target/AMDGPU/AMDGPUCodeGenPrepare.cpp llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp llvm/lib/Target/AMDGPU/AMDGPUPerfHintAnalysis.cpp llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp llvm/lib/Target/AMDGPU/R600OpenCLImageTypeLoweringPass.cpp llvm/lib/Target/ARM/ARMConstantPoolValue.cpp llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp llvm/lib/Target/BPF/BTFDebug.cpp llvm/lib/Target/DirectX/DirectXIRPasses/PointerTypeAnalysis.cpp llvm/lib/Target/Hexagon/HexagonISelLowering.cpp llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp llvm/lib/Target/Mips/MipsISelLowering.cpp llvm/lib/Target/NVPTX/NVPTXLowerUnreachable.cpp llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp llvm/lib/Target/PowerPC/PPCFastISel.cpp llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp llvm/lib/Target/PowerPC/PPCISelLowering.cpp llvm/lib/Target/PowerPC/PPCLowerMASSVEntries.cpp llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp llvm/lib/Target/RISCV/RISCVTargetMachine.cpp llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp llvm/lib/Target/X86/X86FrameLowering.cpp llvm/lib/Target/X86/X86ISelDAGToDAG.cpp llvm/lib/Target/X86/X86ISelLowering.cpp llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp llvm/lib/Target/X86/X86Subtarget.cpp llvm/lib/Target/X86/X86TargetTransformInfo.cpp llvm/lib/Transforms/Coroutines/CoroFrame.cpp llvm/lib/Transforms/Coroutines/CoroSplit.cpp llvm/lib/Transforms/IPO/Annotation2Metadata.cpp llvm/lib/Transforms/IPO/Attributor.cpp llvm/lib/Transforms/IPO/AttributorAttributes.cpp llvm/lib/Transforms/IPO/CrossDSOCFI.cpp llvm/lib/Transforms/IPO/FunctionImport.cpp llvm/lib/Transforms/IPO/FunctionSpecialization.cpp llvm/lib/Transforms/IPO/GlobalSplit.cpp llvm/lib/Transforms/IPO/HotColdSplitting.cpp llvm/lib/Transforms/IPO/IROutliner.cpp llvm/lib/Transforms/IPO/MergeFunctions.cpp llvm/lib/Transforms/IPO/OpenMPOpt.cpp llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp llvm/lib/Transforms/InstCombine/InstructionCombining.cpp llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp llvm/lib/Transforms/Instrumentation/MemProfiler.cpp llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp llvm/lib/Transforms/ObjCARC/ObjCARC.h llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp llvm/lib/Transforms/Scalar/ConstraintElimination.cpp llvm/lib/Transforms/Scalar/CorrelatedValuePropagation.cpp llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp llvm/lib/Transforms/Scalar/IndVarSimplify.cpp llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp llvm/lib/Transforms/Scalar/JumpThreading.cpp llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp llvm/lib/Transforms/Scalar/NaryReassociate.cpp llvm/lib/Transforms/Scalar/NewGVN.cpp llvm/lib/Transforms/Scalar/SROA.cpp llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp llvm/lib/Transforms/Scalar/StructurizeCFG.cpp llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp llvm/lib/Transforms/Utils/BasicBlockUtils.cpp llvm/lib/Transforms/Utils/CallPromotionUtils.cpp llvm/lib/Transforms/Utils/CloneFunction.cpp llvm/lib/Transforms/Utils/CodeExtractor.cpp llvm/lib/Transforms/Utils/FunctionImportUtils.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/lib/Transforms/Utils/Local.cpp llvm/lib/Transforms/Utils/LoopUnroll.cpp llvm/lib/Transforms/Utils/LoopUtils.cpp llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp llvm/lib/Transforms/Utils/PredicateInfo.cpp llvm/lib/Transforms/Utils/SCCPSolver.cpp llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp llvm/lib/Transforms/Utils/SplitModule.cpp llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp llvm/lib/Transforms/Vectorize/LoopVectorize.cpp llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp llvm/lib/Transforms/Vectorize/VPlan.cpp llvm/lib/Transforms/Vectorize/VPlan.h llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp llvm/lib/Transforms/Vectorize/VectorCombine.cpp llvm/tools/llvm-reduce/deltas/ReduceDIMetadata.cpp llvm/tools/llvm-reduce/deltas/ReduceOpcodes.cpp llvm/unittests/Analysis/LoopInfoTest.cpp llvm/unittests/Analysis/MemorySSATest.cpp llvm/unittests/Analysis/VectorFunctionABITest.cpp llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp llvm/unittests/CodeGen/DIETest.cpp llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp llvm/unittests/IR/IRBuilderTest.cpp llvm/unittests/IR/MetadataTest.cpp llvm/unittests/Support/Casting.cpp llvm/unittests/Transforms/Utils/SSAUpdaterBulkTest.cpp llvm/utils/TableGen/CodeEmitterGen.cpp llvm/utils/TableGen/CodeGenInstAlias.cpp llvm/utils/TableGen/CodeGenRegisters.cpp llvm/utils/TableGen/DecoderEmitter.cpp llvm/utils/TableGen/VarLenCodeEmitterGen.cpp View the diff from clang-format here.diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
index b538f7e590..ee58f498c2 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -3327,8 +3327,8 @@ void SelectionDAGBuilder::visitUnreachable(const UnreachableInst &I) {
// We may be able to ignore unreachable behind a noreturn call.
if (DAG.getTarget().Options.NoTrapAfterNoreturn) {
if (const CallInst *Call = dyn_cast_if_present<CallInst>(I.getPrevNode())) {
- if (Call->doesNotReturn())
- return;
+ if (Call->doesNotReturn())
+ return;
}
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't agree that we should use the if_present
style APIs in places that work specifically on pointers, where nonnull
is a lot clearer than present
.
This has been controversial: https://discourse.llvm.org/t/psa-swapping-out-or-null-with-if-present/65018/12 I agree with the group of people that prefer |
Can this be closed? |
Note that dyn_cast_and_nonnull has been soft-deprecated since:
commit f156b51
Author: bzcheeseman 12992886+bzcheeseman@users.noreply.github.com
Date: Sat Apr 16 11:34:08 2022 -0700