diff --git a/llvm/bindings/go/llvm/ir.go b/llvm/bindings/go/llvm/ir.go --- a/llvm/bindings/go/llvm/ir.go +++ b/llvm/bindings/go/llvm/ir.go @@ -723,7 +723,7 @@ // Conversion functions. // Return the input value if it is an instance of the specified class, otherwise NULL. -// See llvm::dyn_cast_or_null<>. +// See llvm::dyn_cast_if_present<>. func (v Value) IsAArgument() (rv Value) { rv.C = C.LLVMIsAArgument(v.C); return } func (v Value) IsABasicBlock() (rv Value) { rv.C = C.LLVMIsABasicBlock(v.C); return } func (v Value) IsAInlineAsm() (rv Value) { rv.C = C.LLVMIsAInlineAsm(v.C); return } diff --git a/llvm/docs/ProgrammersManual.rst b/llvm/docs/ProgrammersManual.rst --- a/llvm/docs/ProgrammersManual.rst +++ b/llvm/docs/ProgrammersManual.rst @@ -176,8 +176,8 @@ propagates). This can sometimes be useful, allowing you to combine several null checks into one. -``dyn_cast_or_null<>``: - The ``dyn_cast_or_null<>`` operator works just like the ``dyn_cast<>`` +``dyn_cast_if_present<>``: + The ``dyn_cast_if_present<>`` operator works just like the ``dyn_cast<>`` operator, except that it allows for a null pointer as an argument (which it then propagates). This can sometimes be useful, allowing you to combine several null checks into one. diff --git a/llvm/include/llvm-c/Core.h b/llvm/include/llvm-c/Core.h --- a/llvm/include/llvm-c/Core.h +++ b/llvm/include/llvm-c/Core.h @@ -1764,7 +1764,7 @@ * * If the cast is not valid for the specified type, NULL is returned. * - * @see llvm::dyn_cast_or_null<> + * @see llvm::dyn_cast_if_present<> */ #define LLVM_DECLARE_VALUE_CAST(name) \ LLVMValueRef LLVMIsA##name(LLVMValueRef Val); diff --git a/llvm/include/llvm/Analysis/SparsePropagation.h b/llvm/include/llvm/Analysis/SparsePropagation.h --- a/llvm/include/llvm/Analysis/SparsePropagation.h +++ b/llvm/include/llvm/Analysis/SparsePropagation.h @@ -318,7 +318,7 @@ return; Constant *C = - dyn_cast_or_null(LatticeFunc->GetValueFromLatticeVal( + dyn_cast_if_present(LatticeFunc->GetValueFromLatticeVal( std::move(BCValue), BI->getCondition()->getType())); if (!C || !isa(C)) { // Non-constant values can go either way. @@ -356,8 +356,9 @@ if (SCValue == LatticeFunc->getUndefVal()) return; - Constant *C = dyn_cast_or_null(LatticeFunc->GetValueFromLatticeVal( - std::move(SCValue), SI.getCondition()->getType())); + Constant *C = + dyn_cast_if_present(LatticeFunc->GetValueFromLatticeVal( + std::move(SCValue), SI.getCondition()->getType())); if (!C || !isa(C)) { // All destinations are executable! Succs.assign(TI.getNumSuccessors(), true); diff --git a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h --- a/llvm/include/llvm/CodeGen/GlobalISel/Utils.h +++ b/llvm/include/llvm/CodeGen/GlobalISel/Utils.h @@ -250,7 +250,7 @@ template T *getOpcodeDef(Register Reg, const MachineRegisterInfo &MRI) { MachineInstr *DefMI = getDefIgnoringCopies(Reg, MRI); - return dyn_cast_or_null(DefMI); + return dyn_cast_if_present(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 --- a/llvm/include/llvm/IR/DebugInfoMetadata.h +++ b/llvm/include/llvm/IR/DebugInfoMetadata.h @@ -1018,7 +1018,7 @@ DIType *getClassType() const; DIObjCProperty *getObjCProperty() const { - return dyn_cast_or_null(getExtraData()); + return dyn_cast_if_present(getExtraData()); } uint32_t getVBPtrOffset() const; @@ -1196,33 +1196,33 @@ } Metadata *getRawDataLocation() const { return getOperand(9); } DIVariable *getDataLocation() const { - return dyn_cast_or_null(getRawDataLocation()); + return dyn_cast_if_present(getRawDataLocation()); } DIExpression *getDataLocationExp() const { - return dyn_cast_or_null(getRawDataLocation()); + return dyn_cast_if_present(getRawDataLocation()); } Metadata *getRawAssociated() const { return getOperand(10); } DIVariable *getAssociated() const { - return dyn_cast_or_null(getRawAssociated()); + return dyn_cast_if_present(getRawAssociated()); } DIExpression *getAssociatedExp() const { - return dyn_cast_or_null(getRawAssociated()); + return dyn_cast_if_present(getRawAssociated()); } Metadata *getRawAllocated() const { return getOperand(11); } DIVariable *getAllocated() const { - return dyn_cast_or_null(getRawAllocated()); + return dyn_cast_if_present(getRawAllocated()); } DIExpression *getAllocatedExp() const { - return dyn_cast_or_null(getRawAllocated()); + return dyn_cast_if_present(getRawAllocated()); } Metadata *getRawRank() const { return getOperand(12); } ConstantInt *getRankConst() const { - if (auto *MD = dyn_cast_or_null(getRawRank())) - return dyn_cast_or_null(MD->getValue()); + if (auto *MD = dyn_cast_if_present(getRawRank())) + return dyn_cast_if_present(MD->getValue()); return nullptr; } DIExpression *getRankExp() const { - return dyn_cast_or_null(getRawRank()); + return dyn_cast_if_present(getRawRank()); } Metadata *getRawAnnotations() const { return getOperand(13); } diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h --- a/llvm/include/llvm/IR/InstrTypes.h +++ b/llvm/include/llvm/IR/InstrTypes.h @@ -1394,7 +1394,7 @@ /// 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(getCalledOperand())) + if (auto *F = dyn_cast_if_present(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 --- a/llvm/include/llvm/IR/Metadata.h +++ b/llvm/include/llvm/IR/Metadata.h @@ -501,7 +501,7 @@ /// mdconst::extract <=> cast /// mdconst::extract_or_null <=> cast_or_null /// mdconst::dyn_extract <=> dyn_cast -/// mdconst::dyn_extract_or_null <=> dyn_cast_or_null +/// mdconst::dyn_extract_or_null <=> dyn_cast_if_present /// /// The target of the cast must be a subclass of \a Constant. namespace mdconst { @@ -578,8 +578,8 @@ /// Extract a Value from Metadata, if any. /// -/// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X -/// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a +/// As an analogue to \a dyn_cast_if_present(), extract the \a Value subclass \c +/// X from \c MD, return null if \c MD doesn't contain a \a Value or if the \a /// Value it does contain is of the wrong subclass. template inline std::enable_if_t::value, X *> @@ -591,13 +591,13 @@ /// Extract a Value from Metadata, if any, allowing null. /// -/// As an analogue to \a dyn_cast_or_null(), extract the \a Value subclass \c X -/// from \c MD, return null if \c MD doesn't contain a \a Value or if the \a +/// As an analogue to \a dyn_cast_if_present(), extract the \a Value subclass \c +/// X from \c MD, return null if \c MD doesn't contain a \a Value or if the \a /// Value it does contain is of the wrong subclass, allowing \c MD to be null. template inline std::enable_if_t::value, X *> dyn_extract_or_null(Y &&MD) { - if (auto *V = dyn_cast_or_null(MD)) + if (auto *V = dyn_cast_if_present(MD)) return dyn_cast(V->getValue()); return nullptr; } @@ -1435,11 +1435,11 @@ const MDNode *getDomain() const { if (Node->getNumOperands() < 2) return nullptr; - return dyn_cast_or_null(Node->getOperand(1)); + return dyn_cast_if_present(Node->getOperand(1)); } StringRef getName() const { if (Node->getNumOperands() > 2) - if (MDString *N = dyn_cast_or_null(Node->getOperand(2))) + if (MDString *N = dyn_cast_if_present(Node->getOperand(2))) return N->getString(); return StringRef(); } diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h --- a/llvm/include/llvm/IR/PatternMatch.h +++ b/llvm/include/llvm/IR/PatternMatch.h @@ -239,8 +239,8 @@ } if (V->getType()->isVectorTy()) if (const auto *C = dyn_cast(V)) - if (auto *CI = - dyn_cast_or_null(C->getSplatValue(AllowUndef))) { + if (auto *CI = dyn_cast_if_present( + C->getSplatValue(AllowUndef))) { Res = &CI->getValue(); return true; } @@ -265,7 +265,7 @@ if (V->getType()->isVectorTy()) if (const auto *C = dyn_cast(V)) if (auto *CI = - dyn_cast_or_null(C->getSplatValue(AllowUndef))) { + dyn_cast_if_present(C->getSplatValue(AllowUndef))) { Res = &CI->getValueAPF(); return true; } @@ -337,7 +337,8 @@ return this->isValue(CV->getValue()); if (const auto *VTy = dyn_cast(V->getType())) { if (const auto *C = dyn_cast(V)) { - if (const auto *CV = dyn_cast_or_null(C->getSplatValue())) + if (const auto *CV = + dyn_cast_if_present(C->getSplatValue())) return this->isValue(CV->getValue()); // Number of elements of a scalable vector unknown at compile time @@ -390,7 +391,7 @@ } if (V->getType()->isVectorTy()) if (const auto *C = dyn_cast(V)) - if (auto *CI = dyn_cast_or_null(C->getSplatValue())) + if (auto *CI = dyn_cast_if_present(C->getSplatValue())) if (this->isValue(CI->getValue())) { Res = &CI->getValue(); return true; @@ -416,7 +417,7 @@ } if (V->getType()->isVectorTy()) if (const auto *C = dyn_cast(V)) - if (auto *CI = dyn_cast_or_null( + if (auto *CI = dyn_cast_if_present( C->getSplatValue(/* AllowUndef */ true))) if (this->isValue(CI->getValue())) { Res = &CI->getValue(); @@ -804,7 +805,7 @@ return CFP->isExactlyValue(Val); if (V->getType()->isVectorTy()) if (const auto *C = dyn_cast(V)) - if (auto *CFP = dyn_cast_or_null(C->getSplatValue())) + if (auto *CFP = dyn_cast_if_present(C->getSplatValue())) return CFP->isExactlyValue(Val); return false; } @@ -843,7 +844,7 @@ const auto *CI = dyn_cast(V); if (!CI && V->getType()->isVectorTy()) if (const auto *C = dyn_cast(V)) - CI = dyn_cast_or_null(C->getSplatValue(AllowUndefs)); + CI = dyn_cast_if_present(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 --- a/llvm/include/llvm/IR/Statepoint.h +++ b/llvm/include/llvm/IR/Statepoint.h @@ -114,7 +114,7 @@ /// Returns the function called if this is a wrapping a direct call, and null /// otherwise. Function *getActualCalledFunction() const { - return dyn_cast_or_null(getActualCalledOperand()); + return dyn_cast_if_present(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 --- a/llvm/include/llvm/ProfileData/InstrProfReader.h +++ b/llvm/include/llvm/ProfileData/InstrProfReader.h @@ -288,7 +288,7 @@ RawInstrProfReader(std::unique_ptr DataBuffer, const InstrProfCorrelator *Correlator) : DataBuffer(std::move(DataBuffer)), - Correlator(dyn_cast_or_null>( + Correlator(dyn_cast_if_present>( Correlator)) {} RawInstrProfReader(const RawInstrProfReader &) = delete; RawInstrProfReader &operator=(const RawInstrProfReader &) = delete; diff --git a/llvm/lib/Analysis/CallGraphSCCPass.cpp b/llvm/lib/Analysis/CallGraphSCCPass.cpp --- a/llvm/lib/Analysis/CallGraphSCCPass.cpp +++ b/llvm/lib/Analysis/CallGraphSCCPass.cpp @@ -262,7 +262,7 @@ // 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(*I->first); + auto *Call = dyn_cast_if_present(*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 --- a/llvm/lib/Analysis/ConstantFolding.cpp +++ b/llvm/lib/Analysis/ConstantFolding.cpp @@ -87,7 +87,7 @@ continue; } - auto *ElementCI = dyn_cast_or_null(Element); + auto *ElementCI = dyn_cast_if_present(Element); if (!ElementCI) return ConstantExpr::getBitCast(C, DestTy); @@ -222,7 +222,7 @@ Src = Constant::getNullValue( cast(C->getType())->getElementType()); else - Src = dyn_cast_or_null(Src); + Src = dyn_cast_if_present(Src); if (!Src) // Reject constantexpr elements. return ConstantExpr::getBitCast(C, DestTy); @@ -2397,20 +2397,20 @@ case Intrinsic::x86_sse2_cvtsd2si: case Intrinsic::x86_sse2_cvtsd2si64: if (ConstantFP *FPOp = - dyn_cast_or_null(Op->getAggregateElement(0U))) + dyn_cast_if_present(Op->getAggregateElement(0U))) return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(), /*roundTowardZero=*/false, Ty, - /*IsSigned*/true); + /*IsSigned*/ true); break; case Intrinsic::x86_sse_cvttss2si: case Intrinsic::x86_sse_cvttss2si64: case Intrinsic::x86_sse2_cvttsd2si: case Intrinsic::x86_sse2_cvttsd2si64: if (ConstantFP *FPOp = - dyn_cast_or_null(Op->getAggregateElement(0U))) + dyn_cast_if_present(Op->getAggregateElement(0U))) return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(), /*roundTowardZero=*/true, Ty, - /*IsSigned*/true); + /*IsSigned*/ true); break; } } @@ -2771,40 +2771,40 @@ case Intrinsic::x86_avx512_vcvtsd2si32: case Intrinsic::x86_avx512_vcvtsd2si64: if (ConstantFP *FPOp = - dyn_cast_or_null(Op->getAggregateElement(0U))) + dyn_cast_if_present(Op->getAggregateElement(0U))) return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(), /*roundTowardZero=*/false, Ty, - /*IsSigned*/true); + /*IsSigned*/ true); break; case Intrinsic::x86_avx512_vcvtss2usi32: case Intrinsic::x86_avx512_vcvtss2usi64: case Intrinsic::x86_avx512_vcvtsd2usi32: case Intrinsic::x86_avx512_vcvtsd2usi64: if (ConstantFP *FPOp = - dyn_cast_or_null(Op->getAggregateElement(0U))) + dyn_cast_if_present(Op->getAggregateElement(0U))) return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(), /*roundTowardZero=*/false, Ty, - /*IsSigned*/false); + /*IsSigned*/ false); break; case Intrinsic::x86_avx512_cvttss2si: case Intrinsic::x86_avx512_cvttss2si64: case Intrinsic::x86_avx512_cvttsd2si: case Intrinsic::x86_avx512_cvttsd2si64: if (ConstantFP *FPOp = - dyn_cast_or_null(Op->getAggregateElement(0U))) + dyn_cast_if_present(Op->getAggregateElement(0U))) return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(), /*roundTowardZero=*/true, Ty, - /*IsSigned*/true); + /*IsSigned*/ true); break; case Intrinsic::x86_avx512_cvttss2usi: case Intrinsic::x86_avx512_cvttss2usi64: case Intrinsic::x86_avx512_cvttsd2usi: case Intrinsic::x86_avx512_cvttsd2usi64: if (ConstantFP *FPOp = - dyn_cast_or_null(Op->getAggregateElement(0U))) + dyn_cast_if_present(Op->getAggregateElement(0U))) return ConstantFoldSSEConvertToInt(FPOp->getValueAPF(), /*roundTowardZero=*/true, Ty, - /*IsSigned*/false); + /*IsSigned*/ false); break; } } diff --git a/llvm/lib/Analysis/IVDescriptors.cpp b/llvm/lib/Analysis/IVDescriptors.cpp --- a/llvm/lib/Analysis/IVDescriptors.cpp +++ b/llvm/lib/Analysis/IVDescriptors.cpp @@ -951,7 +951,7 @@ // in the header will be dominated by the original phi, but need to be moved // after the non-phi previous value. SmallPtrSet SeenPhis; - while (auto *PrevPhi = dyn_cast_or_null(Previous)) { + while (auto *PrevPhi = dyn_cast_if_present(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 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -1373,7 +1373,7 @@ // alloca and handle that case. if (I.isArrayAllocation()) { Constant *Size = SimplifiedValues.lookup(I.getArraySize()); - if (auto *AllocSize = dyn_cast_or_null(Size)) { + if (auto *AllocSize = dyn_cast_if_present(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 @@ -1586,7 +1586,7 @@ auto *C = dyn_cast(Arg); if (!C) - C = dyn_cast_or_null(SimplifiedValues.lookup(Arg)); + C = dyn_cast_if_present(SimplifiedValues.lookup(Arg)); Type *RT = CB.getFunctionType()->getReturnType(); SimplifiedValues[&CB] = ConstantInt::get(RT, C ? 1 : 0); @@ -2007,7 +2007,7 @@ SimpleV = simplifyBinOp(I.getOpcode(), CLHS ? CLHS : LHS, CRHS ? CRHS : RHS, DL); - if (Constant *C = dyn_cast_or_null(SimpleV)) + if (Constant *C = dyn_cast_if_present(SimpleV)) SimplifiedValues[&I] = C; if (SimpleV) @@ -2038,7 +2038,7 @@ Value *SimpleV = simplifyFNegInst( COp ? COp : Op, cast(I).getFastMathFlags(), DL); - if (Constant *C = dyn_cast_or_null(SimpleV)) + if (Constant *C = dyn_cast_if_present(SimpleV)) SimplifiedValues[&I] = C; if (SimpleV) @@ -2123,7 +2123,7 @@ for (Value *I : Call.args()) { Constant *C = dyn_cast(I); if (!C) - C = dyn_cast_or_null(SimplifiedValues.lookup(I)); + C = dyn_cast_if_present(SimplifiedValues.lookup(I)); if (!C) return false; // This argument doesn't map to a constant. @@ -2156,7 +2156,7 @@ // Check if this happens to be an indirect function call to a known function // in this inline context. If not, we've done all we can. Value *Callee = Call.getCalledOperand(); - F = dyn_cast_or_null(SimplifiedValues.lookup(Callee)); + F = dyn_cast_if_present(SimplifiedValues.lookup(Callee)); if (!F || F->getFunctionType() != Call.getFunctionType()) { onCallArgumentSetup(Call); @@ -2254,7 +2254,7 @@ if (!FalseC) FalseC = SimplifiedValues.lookup(FalseVal); Constant *CondC = - dyn_cast_or_null(SimplifiedValues.lookup(SI.getCondition())); + dyn_cast_if_present(SimplifiedValues.lookup(SI.getCondition())); if (!CondC) { // Select C, X, X => X @@ -2682,8 +2682,8 @@ if (BranchInst *BI = dyn_cast(TI)) { if (BI->isConditional()) { Value *Cond = BI->getCondition(); - if (ConstantInt *SimpleCond = - dyn_cast_or_null(SimplifiedValues.lookup(Cond))) { + if (ConstantInt *SimpleCond = dyn_cast_if_present( + SimplifiedValues.lookup(Cond))) { BasicBlock *NextBB = BI->getSuccessor(SimpleCond->isZero() ? 1 : 0); BBWorklist.insert(NextBB); KnownSuccessors[BB] = NextBB; @@ -2694,7 +2694,7 @@ } else if (SwitchInst *SI = dyn_cast(TI)) { Value *Cond = SI->getCondition(); if (ConstantInt *SimpleCond = - dyn_cast_or_null(SimplifiedValues.lookup(Cond))) { + dyn_cast_if_present(SimplifiedValues.lookup(Cond))) { BasicBlock *NextBB = SI->findCaseValue(SimpleCond)->getCaseSuccessor(); BBWorklist.insert(NextBB); KnownSuccessors[BB] = NextBB; diff --git a/llvm/lib/Analysis/InstructionSimplify.cpp b/llvm/lib/Analysis/InstructionSimplify.cpp --- a/llvm/lib/Analysis/InstructionSimplify.cpp +++ b/llvm/lib/Analysis/InstructionSimplify.cpp @@ -1031,7 +1031,7 @@ static bool isICmpTrue(ICmpInst::Predicate Pred, Value *LHS, Value *RHS, const SimplifyQuery &Q, unsigned MaxRecurse) { Value *V = simplifyICmpInst(Pred, LHS, RHS, Q, MaxRecurse); - Constant *C = dyn_cast_or_null(V); + Constant *C = dyn_cast_if_present(V); return (C && C->isAllOnesValue()); } diff --git a/llvm/lib/Analysis/LazyValueInfo.cpp b/llvm/lib/Analysis/LazyValueInfo.cpp --- a/llvm/lib/Analysis/LazyValueInfo.cpp +++ b/llvm/lib/Analysis/LazyValueInfo.cpp @@ -1269,9 +1269,8 @@ // Check if Usr can be simplified to a constant. if (auto *CI = dyn_cast(Usr)) { assert(CI->getOperand(0) == Op && "Operand 0 isn't Op"); - if (auto *C = dyn_cast_or_null( - simplifyCastInst(CI->getOpcode(), OpConst, - CI->getDestTy(), DL))) { + if (auto *C = dyn_cast_if_present( + simplifyCastInst(CI->getOpcode(), OpConst, CI->getDestTy(), DL))) { return ValueLatticeElement::getRange(ConstantRange(C->getValue())); } } else if (auto *BO = dyn_cast(Usr)) { @@ -1281,7 +1280,7 @@ "Operand 0 nor Operand 1 isn't a match"); Value *LHS = Op0Match ? OpConst : BO->getOperand(0); Value *RHS = Op1Match ? OpConst : BO->getOperand(1); - if (auto *C = dyn_cast_or_null( + if (auto *C = dyn_cast_if_present( simplifyBinOp(BO->getOpcode(), LHS, RHS, DL))) { return ValueLatticeElement::getRange(ConstantRange(C->getValue())); } diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -2387,7 +2387,7 @@ Accesses.canCheckPtrAtRT(*PtrRtChecking, PSE->getSE(), TheLoop, SymbolicStrides, UncomputablePtr, false); if (!CanDoRTIfNeeded) { - auto *I = dyn_cast_or_null(UncomputablePtr); + auto *I = dyn_cast_if_present(UncomputablePtr); recordAnalysis("CantIdentifyArrayBounds", I) << "cannot identify array bounds"; LLVM_DEBUG(dbgs() << "LAA: We can't vectorize because we can't find " @@ -2422,7 +2422,7 @@ // Check that we found the bounds for the pointer. if (!CanDoRTIfNeeded) { - auto *I = dyn_cast_or_null(UncomputablePtr); + auto *I = dyn_cast_if_present(UncomputablePtr); recordAnalysis("CantCheckMemDepsAtRunTime", I) << "cannot check memory dependencies at runtime"; LLVM_DEBUG(dbgs() << "LAA: Can't vectorize with memory checks\n"); @@ -2497,7 +2497,7 @@ if (Instruction *I = Dep.getSource(*this)) { DebugLoc SourceLoc = I->getDebugLoc(); - if (auto *DD = dyn_cast_or_null(getPointerOperand(I))) + if (auto *DD = dyn_cast_if_present(getPointerOperand(I))) SourceLoc = DD->getDebugLoc(); if (SourceLoc) R << " Memory location is the same as accessed at " diff --git a/llvm/lib/Analysis/LoopCacheAnalysis.cpp b/llvm/lib/Analysis/LoopCacheAnalysis.cpp --- a/llvm/lib/Analysis/LoopCacheAnalysis.cpp +++ b/llvm/lib/Analysis/LoopCacheAnalysis.cpp @@ -244,7 +244,7 @@ int Levels = D->getLevels(); for (int Level = 1; Level <= Levels; ++Level) { const SCEV *Distance = D->getDistance(Level); - const SCEVConstant *SCEVConst = dyn_cast_or_null(Distance); + const SCEVConstant *SCEVConst = dyn_cast_if_present(Distance); if (SCEVConst == nullptr) { LLVM_DEBUG(dbgs().indent(2) << "No temporal reuse: distance unknown\n"); diff --git a/llvm/lib/Analysis/LoopInfo.cpp b/llvm/lib/Analysis/LoopInfo.cpp --- a/llvm/lib/Analysis/LoopInfo.cpp +++ b/llvm/lib/Analysis/LoopInfo.cpp @@ -169,7 +169,8 @@ /// Get the latch condition instruction. ICmpInst *Loop::getLatchCmpInst() const { if (BasicBlock *Latch = getLoopLatch()) - if (BranchInst *BI = dyn_cast_or_null(Latch->getTerminator())) + if (BranchInst *BI = + dyn_cast_if_present(Latch->getTerminator())) if (BI->isConditional()) return dyn_cast(BI->getCondition()); @@ -229,7 +230,7 @@ BasicBlock *Latch = L.getLoopLatch(); assert(Latch && "Expecting valid latch"); - BranchInst *BI = dyn_cast_or_null(Latch->getTerminator()); + BranchInst *BI = dyn_cast_if_present(Latch->getTerminator()); assert(BI && BI->isConditional() && "Expecting conditional latch branch"); ICmpInst *LatchCmpInst = dyn_cast(BI->getCondition()); @@ -409,7 +410,7 @@ if (!getInductionDescriptor(SE, IndDesc)) return false; - ConstantInt *Init = dyn_cast_or_null(IndDesc.getStartValue()); + ConstantInt *Init = dyn_cast_if_present(IndDesc.getStartValue()); if (!Init || !Init->isZero()) return false; diff --git a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp --- a/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp +++ b/llvm/lib/Analysis/MemoryDependenceAnalysis.cpp @@ -900,7 +900,7 @@ bool isInvariantLoad = false; - if (LoadInst *LI = dyn_cast_or_null(QueryInst)) + if (LoadInst *LI = dyn_cast_if_present(QueryInst)) isInvariantLoad = LI->getMetadata(LLVMContext::MD_invariant_load); // Do a binary search to see if we already have an entry for this block in @@ -1043,7 +1043,7 @@ InitialNLPI.AATags = Loc.AATags; bool isInvariantLoad = false; - if (LoadInst *LI = dyn_cast_or_null(QueryInst)) + if (LoadInst *LI = dyn_cast_if_present(QueryInst)) isInvariantLoad = LI->getMetadata(LLVMContext::MD_invariant_load); // Get the NLPI for CacheKey, inserting one into the map if it doesn't diff --git a/llvm/lib/Analysis/MemorySSA.cpp b/llvm/lib/Analysis/MemorySSA.cpp --- a/llvm/lib/Analysis/MemorySSA.cpp +++ b/llvm/lib/Analysis/MemorySSA.cpp @@ -315,13 +315,13 @@ } } - if (auto *CB = dyn_cast_or_null(UseInst)) { + if (auto *CB = dyn_cast_if_present(UseInst)) { ModRefInfo I = AA.getModRefInfo(DefInst, CB); return isModOrRefSet(I); } if (auto *DefLoad = dyn_cast(DefInst)) - if (auto *UseLoad = dyn_cast_or_null(UseInst)) + if (auto *UseLoad = dyn_cast_if_present(UseInst)) return !areLoadsReorderable(UseLoad, DefLoad); ModRefInfo I = AA.getModRefInfo(DefInst, UseLoc); diff --git a/llvm/lib/Analysis/MemorySSAUpdater.cpp b/llvm/lib/Analysis/MemorySSAUpdater.cpp --- a/llvm/lib/Analysis/MemorySSAUpdater.cpp +++ b/llvm/lib/Analysis/MemorySSAUpdater.cpp @@ -86,7 +86,7 @@ // Now try to simplify the ops to avoid placing a phi. // This may return null if we never created a phi yet, that's okay - MemoryPhi *Phi = dyn_cast_or_null(MSSA->getMemoryAccess(BB)); + MemoryPhi *Phi = dyn_cast_if_present(MSSA->getMemoryAccess(BB)); // See if we can avoid the phi by simplifying it. auto *Result = tryRemoveTrivialPhi(Phi, PhiOps); @@ -445,14 +445,14 @@ // We just inserted a phi into this block, so the incoming value will become // the phi anyway, so it does not matter what we pass. for (auto &MP : InsertedPHIs) { - MemoryPhi *Phi = dyn_cast_or_null(MP); + MemoryPhi *Phi = dyn_cast_if_present(MP); if (Phi) MSSA->renamePass(Phi->getBlock(), nullptr, Visited); } // Existing Phi blocks may need renaming too, if an access was previously // optimized and the inserted Defs "covers" the Optimized value. for (const auto &MP : ExistingPhis) { - MemoryPhi *Phi = dyn_cast_or_null(MP); + MemoryPhi *Phi = dyn_cast_if_present(MP); if (Phi) MSSA->renamePass(Phi->getBlock(), nullptr, Visited); } @@ -463,7 +463,7 @@ SmallPtrSet Seen; SmallVector Worklist; for (const auto &Var : Vars) { - MemoryAccess *NewDef = dyn_cast_or_null(Var); + MemoryAccess *NewDef = dyn_cast_if_present(Var); if (!NewDef) continue; // First, see if there is a local def after the operand. @@ -620,7 +620,7 @@ // simplified, it may be a Use rather than a Def, so we cannot use MUD as // template. Calls coming from updateForClonedBlockIntoPred, ensure this. if (Instruction *NewInsn = - dyn_cast_or_null(VMap.lookup(Insn))) { + dyn_cast_if_present(VMap.lookup(Insn))) { MemoryAccess *NewUseOrDef = MSSA->createDefinedAccess( NewInsn, getNewDefiningAccessForClone(MUD->getDefiningAccess(), VMap, diff --git a/llvm/lib/Analysis/MustExecute.cpp b/llvm/lib/Analysis/MustExecute.cpp --- a/llvm/lib/Analysis/MustExecute.cpp +++ b/llvm/lib/Analysis/MustExecute.cpp @@ -141,11 +141,10 @@ return false; auto DL = ExitBlock->getModule()->getDataLayout(); auto *IVStart = LHS->getIncomingValueForBlock(CurLoop->getLoopPreheader()); - auto *SimpleValOrNull = simplifyCmpInst(Cond->getPredicate(), - IVStart, RHS, - {DL, /*TLI*/ nullptr, - DT, /*AC*/ nullptr, BI}); - auto *SimpleCst = dyn_cast_or_null(SimpleValOrNull); + auto *SimpleValOrNull = + simplifyCmpInst(Cond->getPredicate(), IVStart, RHS, + {DL, /*TLI*/ nullptr, DT, /*AC*/ nullptr, BI}); + auto *SimpleCst = dyn_cast_if_present(SimpleValOrNull); if (!SimpleCst) return false; if (ExitBlock == BI->getSuccessor(0)) diff --git a/llvm/lib/Analysis/PHITransAddr.cpp b/llvm/lib/Analysis/PHITransAddr.cpp --- a/llvm/lib/Analysis/PHITransAddr.cpp +++ b/llvm/lib/Analysis/PHITransAddr.cpp @@ -325,7 +325,7 @@ if (MustDominate) // Make sure the value is live in the predecessor. - if (Instruction *Inst = dyn_cast_or_null(Addr)) + if (Instruction *Inst = dyn_cast_if_present(Addr)) if (!DT->dominates(Inst->getParent(), PredBB)) Addr = nullptr; diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp --- a/llvm/lib/Analysis/ScalarEvolution.cpp +++ b/llvm/lib/Analysis/ScalarEvolution.cpp @@ -9457,8 +9457,9 @@ // "ExitWhen". unsigned MaxIterations = MaxBruteForceIterations; // Limit analysis. const DataLayout &DL = getDataLayout(); - for (unsigned IterationNum = 0; IterationNum != MaxIterations;++IterationNum){ - auto *CondVal = dyn_cast_or_null( + for (unsigned IterationNum = 0; IterationNum != MaxIterations; + ++IterationNum) { + auto *CondVal = dyn_cast_if_present( EvaluateExpression(Cond, L, CurrentIterVals, DL, &TLI)); // Couldn't symbolically evaluate. diff --git a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp --- a/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp +++ b/llvm/lib/Analysis/TypeBasedAliasAnalysis.cpp @@ -167,7 +167,7 @@ if (Node->getNumOperands() < 2) return TBAANodeImpl(); - MDNodeTy *P = dyn_cast_or_null(Node->getOperand(1)); + MDNodeTy *P = dyn_cast_if_present(Node->getOperand(1)); if (!P) return TBAANodeImpl(); // Ok, this node has a valid parent. Return it. @@ -220,11 +220,11 @@ } MDNodeTy *getBaseType() const { - return dyn_cast_or_null(Node->getOperand(0)); + return dyn_cast_if_present(Node->getOperand(0)); } MDNodeTy *getAccessType() const { - return dyn_cast_or_null(Node->getOperand(1)); + return dyn_cast_if_present(Node->getOperand(1)); } uint64_t getOffset() const { @@ -323,7 +323,7 @@ ? 0 : mdconst::extract(Operands[2])->getZExtValue(); Offset -= Cur; - MDNode *P = dyn_cast_or_null(Operands[1]); + MDNode *P = dyn_cast_if_present(Operands[1]); if (!P) return TBAAStructTypeNode(); return TBAAStructTypeNode(P); @@ -353,7 +353,7 @@ uint64_t Cur = mdconst::extract(Operands[TheIdx + 1])->getZExtValue(); Offset -= Cur; - MDNode *P = dyn_cast_or_null(Operands[TheIdx]); + MDNode *P = dyn_cast_if_present(Operands[TheIdx]); if (!P) return TBAAStructTypeNode(); return TBAAStructTypeNode(P); diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2019,7 +2019,7 @@ if (!DemandedElts[i]) continue; Constant *Element = CV->getAggregateElement(i); - auto *ElementCI = dyn_cast_or_null(Element); + auto *ElementCI = dyn_cast_if_present(Element); if (!ElementCI) { Known.resetAll(); return; @@ -3069,7 +3069,7 @@ if (!DemandedElts[i]) continue; // If we find a non-ConstantInt, bail out. - auto *Elt = dyn_cast_or_null(CV->getAggregateElement(i)); + auto *Elt = dyn_cast_if_present(CV->getAggregateElement(i)); if (!Elt) return 0; @@ -3603,7 +3603,7 @@ if (auto *CVFVTy = dyn_cast(CV->getType())) { unsigned NumElts = CVFVTy->getNumElements(); for (unsigned i = 0; i != NumElts; ++i) { - auto *CFP = dyn_cast_or_null(CV->getAggregateElement(i)); + auto *CFP = dyn_cast_if_present(CV->getAggregateElement(i)); if (!CFP) return false; if (CFP->getValueAPF().isNegative() && @@ -5147,7 +5147,7 @@ ShiftAmounts.push_back(C); bool Safe = llvm::all_of(ShiftAmounts, [](Constant *C) { - auto *CI = dyn_cast_or_null(C); + auto *CI = dyn_cast_if_present(C); return CI && CI->getValue().ult(C->getType()->getIntegerBitWidth()); }); return !Safe; @@ -5396,10 +5396,10 @@ auto *TI = Dominator->getBlock()->getTerminator(); Value *Cond = nullptr; - if (auto BI = dyn_cast_or_null(TI)) { + if (auto BI = dyn_cast_if_present(TI)) { if (BI->isConditional()) Cond = BI->getCondition(); - } else if (auto SI = dyn_cast_or_null(TI)) { + } else if (auto SI = dyn_cast_if_present(TI)) { Cond = SI->getCondition(); } diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3075,12 +3075,12 @@ /// forward reference record if needed. BasicBlock *LLParser::PerFunctionState::getBB(const std::string &Name, LocTy Loc) { - return dyn_cast_or_null( + return dyn_cast_if_present( getVal(Name, Type::getLabelTy(F.getContext()), Loc)); } BasicBlock *LLParser::PerFunctionState::getBB(unsigned ID, LocTy Loc) { - return dyn_cast_or_null( + return dyn_cast_if_present( getVal(ID, Type::getLabelTy(F.getContext()), Loc)); } @@ -3387,7 +3387,7 @@ if (Label.Kind == ValID::t_LocalID) return error(Label.Loc, "cannot take address of numeric label after " "the function is defined"); - BB = dyn_cast_or_null( + BB = dyn_cast_if_present( F->getValueSymbolTable()->lookup(Label.StrVal)); if (!BB) return error(Label.Loc, "referenced value is not a basic block"); diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -3140,7 +3140,7 @@ BaseType = getTypeByID(BaseTypeID); } - PointerType *OrigPtrTy = dyn_cast_or_null(BaseType); + PointerType *OrigPtrTy = dyn_cast_if_present(BaseType); if (!OrigPtrTy) return error("GEP base operand must be pointer or vector of pointer"); @@ -3172,8 +3172,7 @@ if (Record.size() < 3) return error("Invalid extractelement constexpr record"); unsigned OpTyID = Record[0]; - VectorType *OpTy = - dyn_cast_or_null(getTypeByID(OpTyID)); + VectorType *OpTy = dyn_cast_if_present(getTypeByID(OpTyID)); if (!OpTy) return error("Invalid extractelement constexpr record"); unsigned IdxRecord; @@ -3224,7 +3223,7 @@ case bitc::CST_CODE_CE_SHUFVEC_EX: { // [opty, opval, opval, opval] VectorType *RTy = dyn_cast(CurTy); VectorType *OpTy = - dyn_cast_or_null(getTypeByID(Record[0])); + dyn_cast_if_present(getTypeByID(Record[0])); if (Record.size() < 4 || !RTy || !OpTy) return error("Invalid shufflevector constexpr record"); V = BitcodeConstant::create( @@ -3338,7 +3337,8 @@ if (Record.size() < 3) return error("Invalid inlineasm record"); unsigned OpNum = 0; - auto *FnTy = dyn_cast_or_null(getTypeByID(Record[OpNum])); + auto *FnTy = + dyn_cast_if_present(getTypeByID(Record[OpNum])); ++OpNum; if (!FnTy) return error("Invalid inlineasm record"); @@ -4641,13 +4641,13 @@ MDNode *Scope = nullptr, *IA = nullptr; if (ScopeID) { - Scope = dyn_cast_or_null( + Scope = dyn_cast_if_present( MDLoader->getMetadataFwdRefOrLoad(ScopeID - 1)); if (!Scope) return error("Invalid record"); } if (IAID) { - IA = dyn_cast_or_null( + IA = dyn_cast_if_present( MDLoader->getMetadataFwdRefOrLoad(IAID - 1)); if (!IA) return error("Invalid record"); @@ -5306,9 +5306,9 @@ SwitchInst *SI = SwitchInst::Create(Cond, Default, NumCases); InstructionList.push_back(SI); for (unsigned i = 0, e = NumCases; i != e; ++i) { - ConstantInt *CaseVal = dyn_cast_or_null( - getFnValueByID(Record[3+i*2], OpTy, OpTyID, nullptr)); - BasicBlock *DestBB = getBasicBlock(Record[1+3+i*2]); + ConstantInt *CaseVal = dyn_cast_if_present( + getFnValueByID(Record[3 + i * 2], OpTy, OpTyID, nullptr)); + BasicBlock *DestBB = getBasicBlock(Record[1 + 3 + i * 2]); if (!CaseVal || !DestBB) { delete SI; return error("Invalid record"); @@ -5371,7 +5371,7 @@ return error("Callee is not a pointer"); if (!FTy) { FTyID = getContainedTypeID(CalleeTypeID); - FTy = dyn_cast_or_null(getTypeByID(FTyID)); + FTy = dyn_cast_if_present(getTypeByID(FTyID)); if (!FTy) return error("Callee is not of pointer to function type"); } else if (!CalleeTy->isOpaqueOrPointeeTypeMatches(FTy)) @@ -5451,7 +5451,7 @@ FunctionType *FTy = nullptr; if ((CCInfo >> bitc::CALL_EXPLICIT_TYPE) & 1) { FTyID = Record[OpNum++]; - FTy = dyn_cast_or_null(getTypeByID(FTyID)); + FTy = dyn_cast_if_present(getTypeByID(FTyID)); if (!FTy) return error("Explicit call type is not a function type"); } @@ -5467,7 +5467,7 @@ return error("Callee is not a pointer type"); if (!FTy) { FTyID = getContainedTypeID(CalleeTypeID); - FTy = dyn_cast_or_null(getTypeByID(FTyID)); + FTy = dyn_cast_if_present(getTypeByID(FTyID)); if (!FTy) return error("Callee is not of pointer to function type"); } else if (!OpTy->isOpaqueOrPointeeTypeMatches(FTy)) @@ -6161,7 +6161,7 @@ FunctionType *FTy = nullptr; if ((CCInfo >> bitc::CALL_EXPLICIT_TYPE) & 1) { FTyID = Record[OpNum++]; - FTy = dyn_cast_or_null(getTypeByID(FTyID)); + FTy = dyn_cast_if_present(getTypeByID(FTyID)); if (!FTy) return error("Explicit call type is not a function type"); } @@ -6177,7 +6177,7 @@ return error("Callee is not a pointer type"); if (!FTy) { FTyID = getContainedTypeID(CalleeTypeID); - FTy = dyn_cast_or_null(getTypeByID(FTyID)); + FTy = dyn_cast_if_present(getTypeByID(FTyID)); if (!FTy) return error("Callee is not of pointer to function type"); } else if (!OpTy->isOpaqueOrPointeeTypeMatches(FTy)) @@ -6338,7 +6338,8 @@ if (!A->getParent()) { // We found at least one unresolved value. Nuke them all to avoid leaks. for (unsigned i = ModuleValueListSize, e = ValueList.size(); i != e; ++i){ - if ((A = dyn_cast_or_null(ValueList[i])) && !A->getParent()) { + if ((A = dyn_cast_if_present(ValueList[i])) && + !A->getParent()) { A->replaceAllUsesWith(PoisonValue::get(A->getType())); delete A; } diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp --- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp +++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp @@ -229,14 +229,14 @@ Metadata *BitcodeReaderMetadataList::getMetadataIfResolved(unsigned Idx) { Metadata *MD = lookup(Idx); - if (auto *N = dyn_cast_or_null(MD)) + if (auto *N = dyn_cast_if_present(MD)) if (!N->isResolved()) return nullptr; return MD; } MDNode *BitcodeReaderMetadataList::getMDNodeFwdRefOrNull(unsigned Idx) { - return dyn_cast_or_null(getMetadataFwdRef(Idx)); + return dyn_cast_if_present(getMetadataFwdRef(Idx)); } void BitcodeReaderMetadataList::tryToResolveCycles() { @@ -273,7 +273,7 @@ // Resolve any cycles. for (unsigned I : UnresolvedNodes) { auto &MD = MetadataPtrs[I]; - auto *N = dyn_cast_or_null(MD); + auto *N = dyn_cast_if_present(MD); if (!N) continue; @@ -295,7 +295,7 @@ } Metadata *BitcodeReaderMetadataList::upgradeTypeRef(Metadata *MaybeUUID) { - auto *UUID = dyn_cast_or_null(MaybeUUID); + auto *UUID = dyn_cast_if_present(MaybeUUID); if (LLVM_LIKELY(!UUID)) return MaybeUUID; @@ -309,7 +309,7 @@ } Metadata *BitcodeReaderMetadataList::upgradeTypeRefArray(Metadata *MaybeTuple) { - auto *Tuple = dyn_cast_or_null(MaybeTuple); + auto *Tuple = dyn_cast_if_present(MaybeTuple); if (!Tuple || Tuple->isDistinct()) return MaybeTuple; @@ -326,7 +326,7 @@ } Metadata *BitcodeReaderMetadataList::resolveTypeRefArray(Metadata *MaybeTuple) { - auto *Tuple = dyn_cast_or_null(MaybeTuple); + auto *Tuple = dyn_cast_if_present(MaybeTuple); if (!Tuple || Tuple->isDistinct()) return MaybeTuple; @@ -366,7 +366,7 @@ Temporaries.insert(ID); continue; } - auto *N = dyn_cast_or_null(MD); + auto *N = dyn_cast_if_present(MD); if (N && N->isTemporary()) Temporaries.insert(ID); } @@ -481,9 +481,9 @@ /// Upgrade old-style CU <-> SP pointers to point from SP to CU. void upgradeCUSubprograms() { for (auto CU_SP : CUSubprograms) - if (auto *SPs = dyn_cast_or_null(CU_SP.second)) + if (auto *SPs = dyn_cast_if_present(CU_SP.second)) for (auto &Op : SPs->operands()) - if (auto *SP = dyn_cast_or_null(Op)) + if (auto *SP = dyn_cast_if_present(Op)) SP->replaceUnit(CU_SP.first); CUSubprograms.clear(); } @@ -497,10 +497,11 @@ if (NamedMDNode *CUNodes = TheModule.getNamedMetadata("llvm.dbg.cu")) for (unsigned I = 0, E = CUNodes->getNumOperands(); I != E; ++I) { auto *CU = cast(CUNodes->getOperand(I)); - if (auto *GVs = dyn_cast_or_null(CU->getRawGlobalVariables())) + if (auto *GVs = + dyn_cast_if_present(CU->getRawGlobalVariables())) for (unsigned I = 0; I < GVs->getNumOperands(); I++) if (auto *GV = - dyn_cast_or_null(GVs->getOperand(I))) { + dyn_cast_if_present(GVs->getOperand(I))) { auto *DGVE = DIGlobalVariableExpression::getDistinct( Context, GV, DIExpression::get(Context, {})); GVs->replaceOperandWith(I, DGVE); @@ -1755,7 +1756,7 @@ // Upgrade sp->function mapping to function->sp mapping. if (HasFn) { - if (auto *CMD = dyn_cast_or_null(CUorFn)) + if (auto *CMD = dyn_cast_if_present(CUorFn)) if (auto *F = dyn_cast(CMD->getValue())) { if (F->isMaterializable()) // Defer until materialized; unmaterialized functions may not have @@ -1930,7 +1931,7 @@ AlignInBits = Record[11]; } GlobalVariable *Attach = nullptr; - if (auto *CMD = dyn_cast_or_null(Expr)) { + if (auto *CMD = dyn_cast_if_present(Expr)) { if (auto *GV = dyn_cast(CMD->getValue())) { Attach = GV; Expr = nullptr; @@ -2182,7 +2183,7 @@ if (K == MDKindMap.end()) return error("Invalid ID"); MDNode *MD = - dyn_cast_or_null(getMetadataFwdRefOrLoad(Record[I + 1])); + dyn_cast_if_present(getMetadataFwdRefOrLoad(Record[I + 1])); if (!MD) return error("Invalid metadata attachment: expect fwd ref to MDNode"); GO.addMetadata(K->second, *MD); @@ -2260,7 +2261,7 @@ // Drop the attachment. This used to be legal, but there's no // upgrade path. break; - MDNode *MD = dyn_cast_or_null(Node); + MDNode *MD = dyn_cast_if_present(Node); if (!MD) return error("Invalid metadata attachment"); diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -3042,7 +3042,7 @@ // here, just use the existing code in ConstantFolding. Type *IntT = IntegerType::get(CV->getContext(), DL.getTypeSizeInBits(CV->getType())); - ConstantInt *CI = dyn_cast_or_null(ConstantFoldConstant( + ConstantInt *CI = dyn_cast_if_present(ConstantFoldConstant( ConstantExpr::getBitCast(const_cast(CV), IntT), DL)); if (!CI) { report_fatal_error( @@ -3239,7 +3239,7 @@ if (!AP.GlobalGOTEquivs.count(GOTEquivSym)) return; - const GlobalValue *BaseGV = dyn_cast_or_null(BaseCst); + const GlobalValue *BaseGV = dyn_cast_if_present(BaseCst); if (!BaseGV) return; diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -396,7 +396,7 @@ const DIScope *Scope = SP->getScope(); TypeIndex TI; - if (const auto *Class = dyn_cast_or_null(Scope)) { + if (const auto *Class = dyn_cast_if_present(Scope)) { // If the scope is a DICompositeType, then this must be a method. Member // function types take some special handling, and require access to the // subprogram. @@ -431,7 +431,7 @@ // Add CxxReturnUdt option to functions that return nontrivial record types // or methods that return record types. - if (auto *ReturnDCTy = dyn_cast_or_null(ReturnTy)) + if (auto *ReturnDCTy = dyn_cast_if_present(ReturnTy)) if (isNonTrivial(ReturnDCTy) || ClassTy) FO |= FunctionOptions::CxxReturnUdt; @@ -2064,7 +2064,7 @@ TypeIndex ThisTypeIndex; if (!IsStaticMethod && ReturnAndArgs.size() > Index) { if (const DIDerivedType *PtrTy = - dyn_cast_or_null(ReturnAndArgs[Index])) { + dyn_cast_if_present(ReturnAndArgs[Index])) { if (PtrTy->getTag() == dwarf::DW_TAG_pointer_type) { ThisTypeIndex = getTypeIndexForThisPtr(PtrTy, Ty); Index++; @@ -2222,7 +2222,7 @@ for (const DINode *Element : Ty->getElements()) { // We assume that the frontend provides all members in source declaration // order, which is what MSVC does. - if (auto *Enumerator = dyn_cast_or_null(Element)) { + if (auto *Enumerator = dyn_cast_if_present(Element)) { // FIXME: Is it correct to always emit these as unsigned here? EnumeratorRecord ER(MemberAccess::Public, APSInt(Enumerator->getValue(), true), @@ -2549,8 +2549,8 @@ Member->getOffsetInBits() + MemberInfo.BaseOffset; if (Member->isBitField()) { uint64_t StartBitOffset = MemberOffsetInBits; - if (const auto *CI = - dyn_cast_or_null(Member->getStorageOffsetInBits())) { + if (const auto *CI = dyn_cast_if_present( + Member->getStorageOffsetInBits())) { MemberOffsetInBits = CI->getZExtValue() + MemberInfo.BaseOffset; } StartBitOffset -= MemberOffsetInBits; @@ -3309,11 +3309,11 @@ APSInt Value; if (const ConstantInt *CI = - dyn_cast_or_null(DTy->getConstant())) + dyn_cast_if_present(DTy->getConstant())) Value = APSInt(CI->getValue(), DebugHandlerBase::isUnsignedDIType(DTy->getBaseType())); else if (const ConstantFP *CFP = - dyn_cast_or_null(DTy->getConstant())) + dyn_cast_if_present(DTy->getConstant())) Value = APSInt(CFP->getValueAPF().bitcastToAPInt(), true); else llvm_unreachable("cannot emit a constant without a value"); @@ -3347,7 +3347,7 @@ const DIScope *Scope = DIGV->getScope(); // For static data members, get the scope from the declaration. - if (const auto *MemberDecl = dyn_cast_or_null( + if (const auto *MemberDecl = dyn_cast_if_present( DIGV->getRawStaticDataMemberDeclaration())) Scope = MemberDecl->getScope(); // For static local variables and Fortran, the scoping portion is elided diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp @@ -926,12 +926,14 @@ // When emitting a variant part, wrap each member in // DW_TAG_variant. DIE &Variant = createAndAddDIE(dwarf::DW_TAG_variant, Buffer); - if (const ConstantInt *CI = - dyn_cast_or_null(DDTy->getDiscriminantValue())) { + if (const ConstantInt *CI = dyn_cast_if_present( + DDTy->getDiscriminantValue())) { if (DD->isUnsignedDIType(Discriminator->getBaseType())) - addUInt(Variant, dwarf::DW_AT_discr_value, None, CI->getZExtValue()); + addUInt(Variant, dwarf::DW_AT_discr_value, None, + CI->getZExtValue()); else - addSInt(Variant, dwarf::DW_AT_discr_value, None, CI->getSExtValue()); + addSInt(Variant, dwarf::DW_AT_discr_value, None, + CI->getSExtValue()); } constructMemberDIE(Variant, DDTy); } else { @@ -1538,7 +1540,7 @@ DINodeArray Elements = CTy->getElements(); for (DINode *E : Elements) { // FIXME: Should this really be such a loose cast? - if (auto *Element = dyn_cast_or_null(E)) { + if (auto *Element = dyn_cast_if_present(E)) { if (Element->getTag() == dwarf::DW_TAG_subrange_type) constructSubrangeDIE(Buffer, cast(Element), IdxTy); else if (Element->getTag() == dwarf::DW_TAG_generic_subrange) @@ -1565,7 +1567,7 @@ // Add enumerators to enumeration type. for (const DINode *E : Elements) { - auto *Enum = dyn_cast_or_null(E); + auto *Enum = dyn_cast_if_present(E); if (Enum) { DIE &Enumerator = createAndAddDIE(dwarf::DW_TAG_enumerator, Buffer); StringRef Name = Enum->getName(); @@ -1729,9 +1731,11 @@ // public if the parent is something else. addAccess(StaticMemberDIE, DT->getFlags()); - if (const ConstantInt *CI = dyn_cast_or_null(DT->getConstant())) + if (const ConstantInt *CI = + dyn_cast_if_present(DT->getConstant())) addConstantValue(StaticMemberDIE, CI, Ty); - if (const ConstantFP *CFP = dyn_cast_or_null(DT->getConstant())) + if (const ConstantFP *CFP = + dyn_cast_if_present(DT->getConstant())) addConstantFPValue(StaticMemberDIE, CFP); if (uint32_t AlignInBytes = DT->getAlignInBytes()) diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -5393,8 +5393,8 @@ // non-integral pointers, so in that case bail out now. Type *BaseTy = AddrMode.BaseReg ? AddrMode.BaseReg->getType() : nullptr; Type *ScaleTy = AddrMode.Scale ? AddrMode.ScaledReg->getType() : nullptr; - PointerType *BasePtrTy = dyn_cast_or_null(BaseTy); - PointerType *ScalePtrTy = dyn_cast_or_null(ScaleTy); + PointerType *BasePtrTy = dyn_cast_if_present(BaseTy); + PointerType *ScalePtrTy = dyn_cast_if_present(ScaleTy); if (DL->isNonIntegralPointerType(Addr->getType()) || (BasePtrTy && DL->isNonIntegralPointerType(BasePtrTy)) || (ScalePtrTy && DL->isNonIntegralPointerType(ScalePtrTy)) || @@ -5437,7 +5437,7 @@ // the original IR value was tossed in favor of a constant back when // the AddrMode was created we need to bail out gracefully if widths // do not match instead of extending it. - Instruction *I = dyn_cast_or_null(Result); + Instruction *I = dyn_cast_if_present(Result); if (I && (Result != AddrMode.BaseReg)) I->eraseFromParent(); return Modified; @@ -5546,7 +5546,7 @@ return false; if (isa(C->getType())) C = C->getSplatValue(); - auto *CI = dyn_cast_or_null(C); + auto *CI = dyn_cast_if_present(C); if (!CI || !CI->isZero()) return false; // Scalarize the index if needed. @@ -8153,7 +8153,7 @@ SmallVector VIs; for (Value *V : DVI->getValues()) - if (Instruction *VI = dyn_cast_or_null(V)) + if (Instruction *VI = dyn_cast_if_present(V)) VIs.push_back(VI); // This DVI may depend on multiple instructions, complicating any diff --git a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp --- a/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp @@ -4923,7 +4923,7 @@ } auto CheckEltValue = [&](const Constant *C) { - if (auto *CI = dyn_cast_or_null(C)) + if (auto *CI = dyn_cast_if_present(C)) return !CI->isZero(); return false; }; diff --git a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp --- a/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp +++ b/llvm/lib/CodeGen/GlobalISel/LegalizerHelper.cpp @@ -5710,7 +5710,7 @@ MRI, Reg, [=](const Constant *C) { // Null constant here means an undef. - const ConstantInt *CI = dyn_cast_or_null(C); + const ConstantInt *CI = dyn_cast_if_present(C); return !CI || CI->getValue().urem(BW) != 0; }, /*AllowUndefs*/ true); diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp --- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp +++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp @@ -697,7 +697,7 @@ Align llvm::inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO) { auto PSV = MPO.V.dyn_cast(); - if (auto FSPV = dyn_cast_or_null(PSV)) { + if (auto FSPV = dyn_cast_if_present(PSV)) { MachineFrameInfo &MFI = MF.getFrameInfo(); return commonAlignment(MFI.getObjectAlign(FSPV->getFrameIndex()), MPO.Offset); diff --git a/llvm/lib/CodeGen/LowerEmuTLS.cpp b/llvm/lib/CodeGen/LowerEmuTLS.cpp --- a/llvm/lib/CodeGen/LowerEmuTLS.cpp +++ b/llvm/lib/CodeGen/LowerEmuTLS.cpp @@ -134,7 +134,7 @@ GlobalVariable *EmuTlsTmplVar = nullptr; if (InitValue) { std::string EmuTlsTmplName = ("__emutls_t." + GV->getName()).str(); - EmuTlsTmplVar = dyn_cast_or_null( + EmuTlsTmplVar = dyn_cast_if_present( M.getOrInsertGlobal(EmuTlsTmplName, GVType)); assert(EmuTlsTmplVar && "Failed to create emualted TLS initializer"); EmuTlsTmplVar->setConstant(true); diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -728,7 +728,7 @@ return true; if (!Name.empty()) { - BB = dyn_cast_or_null( + BB = dyn_cast_if_present( MF.getFunction().getValueSymbolTable()->lookup(Name)); if (!BB) return error(Loc, Twine("basic block '") + Name + @@ -2539,7 +2539,7 @@ bool MIParser::parseIRBlock(BasicBlock *&BB, const Function &F) { switch (Token.kind()) { case MIToken::NamedIRBlock: { - BB = dyn_cast_or_null( + BB = dyn_cast_if_present( F.getValueSymbolTable()->lookup(Token.stringValue())); if (!BB) return error(Twine("use of undefined IR block '") + Token.range() + "'"); diff --git a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp --- a/llvm/lib/CodeGen/MIRParser/MIRParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIRParser.cpp @@ -243,7 +243,7 @@ // Parse the block scalar manually so that we can return unique pointer // without having to go trough YAML traits. if (const auto *BSN = - dyn_cast_or_null(In.getCurrentNode())) { + dyn_cast_if_present(In.getCurrentNode())) { SMDiagnostic Error; M = parseAssembly(MemoryBufferRef(BSN->getValue(), Filename), Error, Context, &IRSlots, DataLayoutCallback); @@ -784,7 +784,7 @@ const AllocaInst *Alloca = nullptr; const yaml::StringValue &Name = Object.Name; if (!Name.Value.empty()) { - Alloca = dyn_cast_or_null( + Alloca = dyn_cast_if_present( F.getValueSymbolTable()->lookup(Name.Value)); if (!Alloca) return error(Name.SourceRange.Start, @@ -917,7 +917,7 @@ // FIXME: Support target-specific constant pools return error(YamlConstant.Value.SourceRange.Start, "Can't parse target-specific constant pool entries yet"); - const Constant *Value = dyn_cast_or_null( + const Constant *Value = dyn_cast_if_present( parseConstantValue(YamlConstant.Value.Value, Error, M)); if (!Value) return error(Error, YamlConstant.Value.SourceRange); diff --git a/llvm/lib/CodeGen/MachineFunction.cpp b/llvm/lib/CodeGen/MachineFunction.cpp --- a/llvm/lib/CodeGen/MachineFunction.cpp +++ b/llvm/lib/CodeGen/MachineFunction.cpp @@ -112,7 +112,7 @@ return; auto *Existing = - dyn_cast_or_null(F.getMetadata(LLVMContext::MD_annotation)); + dyn_cast_if_present(F.getMetadata(LLVMContext::MD_annotation)); if (!Existing || Existing->getNumOperands() != 2) return; diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp @@ -11636,32 +11636,32 @@ ConstantSDNode * BuildVectorSDNode::getConstantSplatNode(const APInt &DemandedElts, BitVector *UndefElements) const { - return dyn_cast_or_null( + return dyn_cast_if_present( getSplatValue(DemandedElts, UndefElements)); } ConstantSDNode * BuildVectorSDNode::getConstantSplatNode(BitVector *UndefElements) const { - return dyn_cast_or_null(getSplatValue(UndefElements)); + return dyn_cast_if_present(getSplatValue(UndefElements)); } ConstantFPSDNode * BuildVectorSDNode::getConstantFPSplatNode(const APInt &DemandedElts, BitVector *UndefElements) const { - return dyn_cast_or_null( + return dyn_cast_if_present( getSplatValue(DemandedElts, UndefElements)); } ConstantFPSDNode * BuildVectorSDNode::getConstantFPSplatNode(BitVector *UndefElements) const { - return dyn_cast_or_null(getSplatValue(UndefElements)); + return dyn_cast_if_present(getSplatValue(UndefElements)); } int32_t BuildVectorSDNode::getConstantFPSplatPow2ToLog2Int(BitVector *UndefElements, uint32_t BitWidth) const { if (ConstantFPSDNode *CN = - dyn_cast_or_null(getSplatValue(UndefElements))) { + dyn_cast_if_present(getSplatValue(UndefElements))) { bool IsExact; APSInt IntVal(BitWidth); const APFloat &APF = CN->getValueAPF(); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -300,7 +300,7 @@ static void diagnosePossiblyInvalidConstraint(LLVMContext &Ctx, const Value *V, const Twine &ErrMsg) { - const Instruction *I = dyn_cast_or_null(V); + const Instruction *I = dyn_cast_if_present(V); if (!V) return Ctx.emitError(ErrMsg); @@ -3908,7 +3908,7 @@ if (C && isa(C->getType())) C = C->getSplatValue(); - const auto *CI = dyn_cast_or_null(C); + const auto *CI = dyn_cast_if_present(C); if (CI && CI->isZero()) continue; if (CI && !ElementScalable) { @@ -6878,7 +6878,8 @@ getUnderlyingObjects(ObjectPtr, Allocas); for (const Value *Alloca : Allocas) { - const AllocaInst *LifetimeObject = dyn_cast_or_null(Alloca); + const AllocaInst *LifetimeObject = + dyn_cast_if_present(Alloca); // Could not find an Alloca. if (!LifetimeObject) diff --git a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp --- a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp @@ -576,7 +576,7 @@ SmallSet LPadPointers; if (!UseRegistersForGCPointersInLandingPad) if (const auto *StInvoke = - dyn_cast_or_null(SI.StatepointInstr)) { + dyn_cast_if_present(SI.StatepointInstr)) { LandingPadInst *LPI = StInvoke->getLandingPadInst(); for (const auto *Relocate : SI.GCRelocates) if (Relocate->getOperand(0) == LPI) { diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp --- a/llvm/lib/CodeGen/StackColoring.cpp +++ b/llvm/lib/CodeGen/StackColoring.cpp @@ -1022,7 +1022,7 @@ for (MachineMemOperand *MMO : I.memoperands()) { // We've replaced IR-level uses of the remapped allocas, so we only // need to replace direct uses here. - const AllocaInst *AI = dyn_cast_or_null(MMO->getValue()); + const AllocaInst *AI = dyn_cast_if_present(MMO->getValue()); if (!AI) continue; @@ -1078,7 +1078,7 @@ for (MachineMemOperand *MMO : I.memoperands()) { // Collect MachineMemOperands which reference // FixedStackPseudoSourceValues with old frame indices. - if (const auto *FSV = dyn_cast_or_null( + if (const auto *FSV = dyn_cast_if_present( MMO->getPseudoValue())) { int FI = FSV->getFrameIndex(); auto To = SlotRemap.find(FI); @@ -1101,7 +1101,7 @@ // If this memory location comes from a known stack slot // that is not remapped, we continue checking. // Otherwise, we need to invalidate AA infomation. - const AllocaInst *AI = dyn_cast_or_null(V); + const AllocaInst *AI = dyn_cast_if_present(V); if (AI && MergedAllocas.count(AI)) { MayHaveConflictingAAMD = true; break; diff --git a/llvm/lib/CodeGen/StackSlotColoring.cpp b/llvm/lib/CodeGen/StackSlotColoring.cpp --- a/llvm/lib/CodeGen/StackSlotColoring.cpp +++ b/llvm/lib/CodeGen/StackSlotColoring.cpp @@ -176,8 +176,8 @@ MMOI != EE; ++MMOI) { MachineMemOperand *MMO = *MMOI; if (const FixedStackPseudoSourceValue *FSV = - dyn_cast_or_null( - MMO->getPseudoValue())) { + dyn_cast_if_present( + MMO->getPseudoValue())) { int FI = FSV->getFrameIndex(); if (FI >= 0) SSRefs[FI].push_back(MMO); diff --git a/llvm/lib/CodeGen/TargetLoweringBase.cpp b/llvm/lib/CodeGen/TargetLoweringBase.cpp --- a/llvm/lib/CodeGen/TargetLoweringBase.cpp +++ b/llvm/lib/CodeGen/TargetLoweringBase.cpp @@ -1851,7 +1851,7 @@ Module *M = IRB.GetInsertBlock()->getParent()->getParent(); const char *UnsafeStackPtrVar = "__safestack_unsafe_stack_ptr"; auto UnsafeStackPtr = - dyn_cast_or_null(M->getNamedValue(UnsafeStackPtrVar)); + dyn_cast_if_present(M->getNamedValue(UnsafeStackPtrVar)); Type *StackPtrTy = Type::getInt8PtrTy(M->getContext()); @@ -1942,7 +1942,7 @@ Module &M = *IRB.GetInsertBlock()->getParent()->getParent(); PointerType *PtrTy = Type::getInt8PtrTy(M.getContext()); Constant *C = M.getOrInsertGlobal("__guard_local", PtrTy); - if (GlobalVariable *G = dyn_cast_or_null(C)) + if (GlobalVariable *G = dyn_cast_if_present(C)) G->setVisibility(GlobalValue::HiddenVisibility); return C; } diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp --- a/llvm/lib/CodeGen/WinEHPrepare.cpp +++ b/llvm/lib/CodeGen/WinEHPrepare.cpp @@ -947,8 +947,8 @@ std::vector &BlocksInFunclet = Funclet.second; Instruction *FirstNonPHI = FuncletPadBB->getFirstNonPHI(); auto *FuncletPad = dyn_cast(FirstNonPHI); - auto *CatchPad = dyn_cast_or_null(FuncletPad); - auto *CleanupPad = dyn_cast_or_null(FuncletPad); + auto *CatchPad = dyn_cast_if_present(FuncletPad); + auto *CleanupPad = dyn_cast_if_present(FuncletPad); for (BasicBlock *BB : BlocksInFunclet) { for (Instruction &I : *BB) { diff --git a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp --- a/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFContext.cpp @@ -705,7 +705,7 @@ if (const auto &TUI = getTUIndex()) { if (const auto *R = TUI.getFromHash(Hash)) - return dyn_cast_or_null( + return dyn_cast_if_present( DWOUnits.getUnitForIndexEntry(*R)); return nullptr; } @@ -732,7 +732,7 @@ if (const auto &CUI = getCUIndex()) { if (const auto *R = CUI.getFromHash(Hash)) - return dyn_cast_or_null( + return dyn_cast_if_present( DWOUnits.getUnitForIndexEntry(*R)); return nullptr; } @@ -1045,7 +1045,7 @@ DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint64_t Offset) { parseNormalUnits(); - return dyn_cast_or_null( + return dyn_cast_if_present( NormalUnits.getUnitForOffset(Offset)); } diff --git a/llvm/lib/DebugInfo/PDB/PDBContext.cpp b/llvm/lib/DebugInfo/PDB/PDBContext.cpp --- a/llvm/lib/DebugInfo/PDB/PDBContext.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBContext.cpp @@ -40,9 +40,9 @@ uint32_t Length = 1; std::unique_ptr Symbol = Session->findSymbolByAddress(Address.Address, PDB_SymType::None); - if (auto Func = dyn_cast_or_null(Symbol.get())) { + if (auto Func = dyn_cast_if_present(Symbol.get())) { Length = Func->getLength(); - } else if (auto Data = dyn_cast_or_null(Symbol.get())) { + } else if (auto Data = dyn_cast_if_present(Symbol.get())) { Length = Data->getLength(); } @@ -147,7 +147,7 @@ std::unique_ptr FuncSymbol = Session->findSymbolByAddress(Address, PDB_SymType::Function); - auto *Func = dyn_cast_or_null(FuncSymbol.get()); + auto *Func = dyn_cast_if_present(FuncSymbol.get()); if (NameKind == DINameKind::LinkageName) { // It is not possible to get the mangled linkage name through a @@ -155,7 +155,8 @@ // PDBSymbolPublicSymbol. auto PublicSym = Session->findSymbolByAddress(Address, PDB_SymType::PublicSymbol); - if (auto *PS = dyn_cast_or_null(PublicSym.get())) { + if (auto *PS = + dyn_cast_if_present(PublicSym.get())) { // If we also have a function symbol, prefer the use of public symbol name // only if it refers to the same address. The public symbol uses the // linkage name while the function does not. diff --git a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp --- a/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp +++ b/llvm/lib/DebugInfo/PDB/PDBSymbolTypeFunctionSig.cpp @@ -82,7 +82,8 @@ if (NumArgs == 0) return false; auto Last = SigArguments->getChildAtIndex(NumArgs - 1); - if (auto Builtin = llvm::dyn_cast_or_null(Last.get())) { + if (auto Builtin = + llvm::dyn_cast_if_present(Last.get())) { if (Builtin->getBuiltinType() == PDB_BuiltinType::None) return true; } diff --git a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp --- a/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp +++ b/llvm/lib/DebugInfo/Symbolize/Symbolize.cpp @@ -559,7 +559,8 @@ if (!Bin) return static_cast(nullptr); - if (MachOUniversalBinary *UB = dyn_cast_or_null(Bin)) { + if (MachOUniversalBinary *UB = + dyn_cast_if_present(Bin)) { auto I = ObjectForUBPathAndArch.find(std::make_pair(Path, ArchName)); if (I != ObjectForUBPathAndArch.end()) return I->second.get(); diff --git a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp --- a/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/ExecutionUtils.cpp @@ -24,9 +24,9 @@ namespace orc { CtorDtorIterator::CtorDtorIterator(const GlobalVariable *GV, bool End) - : InitList( - GV ? dyn_cast_or_null(GV->getInitializer()) : nullptr), - I((InitList && End) ? InitList->getNumOperands() : 0) { + : InitList(GV ? dyn_cast_if_present(GV->getInitializer()) + : nullptr), + I((InitList && End) ? InitList->getNumOperands() : 0) { } bool CtorDtorIterator::operator==(const CtorDtorIterator &Other) const { @@ -58,10 +58,10 @@ // Extract function pointer, pulling off any casts. while (FuncC) { - if (Function *F = dyn_cast_or_null(FuncC)) { + if (Function *F = dyn_cast_if_present(FuncC)) { Func = F; break; - } else if (ConstantExpr *CE = dyn_cast_or_null(FuncC)) { + } else if (ConstantExpr *CE = dyn_cast_if_present(FuncC)) { if (CE->isCast()) FuncC = CE->getOperand(0); else diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp --- a/llvm/lib/IR/AsmWriter.cpp +++ b/llvm/lib/IR/AsmWriter.cpp @@ -1096,7 +1096,7 @@ if (Function *F = CI->getCalledFunction()) if (F->isIntrinsic()) for (auto &Op : I.operands()) - if (auto *V = dyn_cast_or_null(Op)) + if (auto *V = dyn_cast_if_present(Op)) if (MDNode *N = dyn_cast(V->getMetadata())) CreateMetadataSlot(N); @@ -1246,7 +1246,7 @@ // Recursively add any MDNodes referenced by operands. for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) - if (const MDNode *Op = dyn_cast_or_null(N->getOperand(i))) + if (const MDNode *Op = dyn_cast_if_present(N->getOperand(i))) CreateMetadataSlot(Op); } @@ -1865,7 +1865,7 @@ MDFieldPrinter Printer(Out, WriterCtx); auto *Count = N->getRawCountNode(); - if (auto *CE = dyn_cast_or_null(Count)) { + if (auto *CE = dyn_cast_if_present(Count)) { auto *CV = cast(CE->getValue()); Printer.printInt("count", CV->getSExtValue(), /* ShouldSkipZero */ false); @@ -1875,7 +1875,7 @@ // A lowerBound of constant 0 should not be skipped, since it is different // from an unspecified lower bound (= nullptr). auto *LBound = N->getRawLowerBound(); - if (auto *LE = dyn_cast_or_null(LBound)) { + if (auto *LE = dyn_cast_if_present(LBound)) { auto *LV = cast(LE->getValue()); Printer.printInt("lowerBound", LV->getSExtValue(), /* ShouldSkipZero */ false); @@ -1883,7 +1883,7 @@ Printer.printMetadata("lowerBound", LBound, /*ShouldSkipNull */ true); auto *UBound = N->getRawUpperBound(); - if (auto *UE = dyn_cast_or_null(UBound)) { + if (auto *UE = dyn_cast_if_present(UBound)) { auto *UV = cast(UE->getValue()); Printer.printInt("upperBound", UV->getSExtValue(), /* ShouldSkipZero */ false); @@ -1891,7 +1891,7 @@ Printer.printMetadata("upperBound", UBound, /*ShouldSkipNull */ true); auto *Stride = N->getRawStride(); - if (auto *SE = dyn_cast_or_null(Stride)) { + if (auto *SE = dyn_cast_if_present(Stride)) { auto *SV = cast(SE->getValue()); Printer.printInt("stride", SV->getSExtValue(), /* ShouldSkipZero */ false); } else @@ -1906,7 +1906,7 @@ MDFieldPrinter Printer(Out, WriterCtx); auto IsConstant = [&](Metadata *Bound) -> bool { - if (auto *BE = dyn_cast_or_null(Bound)) { + if (auto *BE = dyn_cast_if_present(Bound)) { return BE->isConstant() && DIExpression::SignedOrUnsignedConstant::SignedConstant == *BE->isConstant(); @@ -1916,7 +1916,7 @@ auto GetConstant = [&](Metadata *Bound) -> int64_t { assert(IsConstant(Bound) && "Expected constant"); - auto *BE = dyn_cast_or_null(Bound); + auto *BE = dyn_cast_if_present(Bound); return static_cast(BE->getElement(1)); }; @@ -4579,7 +4579,7 @@ if (Function *F = CI->getCalledFunction()) if (F->isIntrinsic()) for (auto &Op : I.operands()) - if (auto *V = dyn_cast_or_null(Op)) + if (auto *V = dyn_cast_if_present(Op)) if (isa(V->getMetadata())) return true; return false; diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -3917,7 +3917,7 @@ // Upgrade from the old version that had an extra offset argument. assert(CI->arg_size() == 4); // Drop nonzero offsets instead of attempting to upgrade them. - if (auto *Offset = dyn_cast_or_null(CI->getArgOperand(1))) + if (auto *Offset = dyn_cast_if_present(CI->getArgOperand(1))) if (Offset->isZeroValue()) { NewCall = Builder.CreateCall( NewFn, @@ -4234,7 +4234,7 @@ if (ModRetainReleaseMarker) { MDNode *Op = ModRetainReleaseMarker->getOperand(0); if (Op) { - MDString *ID = dyn_cast_or_null(Op->getOperand(0)); + MDString *ID = dyn_cast_if_present(Op->getOperand(0)); if (ID) { SmallVector ValueComp; ID->getString().split(ValueComp, "#"); @@ -4388,7 +4388,7 @@ MDNode *Op = ModFlags->getOperand(I); if (Op->getNumOperands() != 3) continue; - MDString *ID = dyn_cast_or_null(Op->getOperand(1)); + MDString *ID = dyn_cast_if_present(Op->getOperand(1)); if (!ID) continue; auto SetBehavior = [&](Module::ModFlagBehavior B) { @@ -4441,7 +4441,7 @@ // section name so that llvm-lto will not complain about mismatching // module flags that is functionally the same. if (ID->getString() == "Objective-C Image Info Section") { - if (auto *Value = dyn_cast_or_null(Op->getOperand(2))) { + if (auto *Value = dyn_cast_if_present(Op->getOperand(2))) { SmallVector ValueComp; Value->getString().split(ValueComp, " "); if (ValueComp.size() != 1) { @@ -4578,12 +4578,12 @@ } static bool isOldLoopArgument(Metadata *MD) { - auto *T = dyn_cast_or_null(MD); + auto *T = dyn_cast_if_present(MD); if (!T) return false; if (T->getNumOperands() < 1) return false; - auto *S = dyn_cast_or_null(T->getOperand(0)); + auto *S = dyn_cast_if_present(T->getOperand(0)); if (!S) return false; return S->getString().startswith("llvm.vectorizer."); @@ -4602,12 +4602,12 @@ } static Metadata *upgradeLoopArgument(Metadata *MD) { - auto *T = dyn_cast_or_null(MD); + auto *T = dyn_cast_if_present(MD); if (!T) return MD; if (T->getNumOperands() < 1) return MD; - auto *OldTag = dyn_cast_or_null(T->getOperand(0)); + auto *OldTag = dyn_cast_if_present(T->getOperand(0)); if (!OldTag) return MD; if (!OldTag->getString().startswith("llvm.vectorizer.")) diff --git a/llvm/lib/IR/BasicBlock.cpp b/llvm/lib/IR/BasicBlock.cpp --- a/llvm/lib/IR/BasicBlock.cpp +++ b/llvm/lib/IR/BasicBlock.cpp @@ -186,7 +186,7 @@ if (!RI || RI == &InstList.front()) return nullptr; - if (auto *CI = dyn_cast_or_null(RI->getPrevNode())) + if (auto *CI = dyn_cast_if_present(RI->getPrevNode())) if (Function *F = CI->getCalledFunction()) if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize) return CI; diff --git a/llvm/lib/IR/ConstantFold.cpp b/llvm/lib/IR/ConstantFold.cpp --- a/llvm/lib/IR/ConstantFold.cpp +++ b/llvm/lib/IR/ConstantFold.cpp @@ -1927,7 +1927,7 @@ return false; } else { auto *CV = cast(Idxs[0]); - CI = dyn_cast_or_null(CV->getSplatValue()); + CI = dyn_cast_if_present(CV->getSplatValue()); if (!CI || !CI->isOne()) return false; } diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -46,7 +46,7 @@ // Equivalent for a vector of -0.0's. if (getType()->isVectorTy()) - if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue())) + if (const auto *SplatCFP = dyn_cast_if_present(getSplatValue())) return SplatCFP->isNegativeZeroValue(); // We've already handled true FP case; any other FP vectors can't represent -0.0. @@ -66,7 +66,7 @@ // Check for constant splat vectors of 1 values. if (getType()->isVectorTy()) - if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue())) + if (const auto *SplatCFP = dyn_cast_if_present(getSplatValue())) return SplatCFP->isZero(); // Otherwise, just use +0.0. @@ -203,7 +203,7 @@ if (auto *VTy = dyn_cast(getType())) { for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) { - auto *CFP = dyn_cast_or_null(getAggregateElement(I)); + auto *CFP = dyn_cast_if_present(getAggregateElement(I)); if (!CFP || !CFP->getValueAPF().isFiniteNonZero()) return false; } @@ -211,7 +211,7 @@ } if (getType()->isVectorTy()) - if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue())) + if (const auto *SplatCFP = dyn_cast_if_present(getSplatValue())) return SplatCFP->isFiniteNonZeroFP(); // It *may* contain finite non-zero, we can't tell. @@ -224,7 +224,7 @@ if (auto *VTy = dyn_cast(getType())) { for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) { - auto *CFP = dyn_cast_or_null(getAggregateElement(I)); + auto *CFP = dyn_cast_if_present(getAggregateElement(I)); if (!CFP || !CFP->getValueAPF().isNormal()) return false; } @@ -232,7 +232,7 @@ } if (getType()->isVectorTy()) - if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue())) + if (const auto *SplatCFP = dyn_cast_if_present(getSplatValue())) return SplatCFP->isNormalFP(); // It *may* contain a normal fp value, we can't tell. @@ -245,7 +245,7 @@ if (auto *VTy = dyn_cast(getType())) { for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) { - auto *CFP = dyn_cast_or_null(getAggregateElement(I)); + auto *CFP = dyn_cast_if_present(getAggregateElement(I)); if (!CFP || !CFP->getValueAPF().getExactInverse(nullptr)) return false; } @@ -253,7 +253,7 @@ } if (getType()->isVectorTy()) - if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue())) + if (const auto *SplatCFP = dyn_cast_if_present(getSplatValue())) return SplatCFP->hasExactInverseFP(); // It *may* have an exact inverse fp value, we can't tell. @@ -266,7 +266,7 @@ if (auto *VTy = dyn_cast(getType())) { for (unsigned I = 0, E = VTy->getNumElements(); I != E; ++I) { - auto *CFP = dyn_cast_or_null(getAggregateElement(I)); + auto *CFP = dyn_cast_if_present(getAggregateElement(I)); if (!CFP || !CFP->isNaN()) return false; } @@ -274,7 +274,7 @@ } if (getType()->isVectorTy()) - if (const auto *SplatCFP = dyn_cast_or_null(getSplatValue())) + if (const auto *SplatCFP = dyn_cast_if_present(getSplatValue())) return SplatCFP->isNaN(); // It *may* be NaN, we can't tell. diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -986,15 +986,15 @@ /*--.. Conversion functions ................................................--*/ -#define LLVM_DEFINE_VALUE_CAST(name) \ - LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \ - return wrap(static_cast(dyn_cast_or_null(unwrap(Val)))); \ +#define LLVM_DEFINE_VALUE_CAST(name) \ + LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \ + return wrap(static_cast(dyn_cast_if_present(unwrap(Val)))); \ } LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST) LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val) { - if (auto *MD = dyn_cast_or_null(unwrap(Val))) + if (auto *MD = dyn_cast_if_present(unwrap(Val))) if (isa(MD->getMetadata()) || isa(MD->getMetadata())) return Val; @@ -1002,7 +1002,7 @@ } LLVMValueRef LLVMIsAMDString(LLVMValueRef Val) { - if (auto *MD = dyn_cast_or_null(unwrap(Val))) + if (auto *MD = dyn_cast_if_present(unwrap(Val))) if (isa(MD->getMetadata())) return Val; return nullptr; diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp --- a/llvm/lib/IR/DIBuilder.cpp +++ b/llvm/lib/IR/DIBuilder.cpp @@ -727,7 +727,7 @@ static void checkGlobalVariableScope(DIScope *Context) { #ifndef NDEBUG if (auto *CT = - dyn_cast_or_null(getNonCompileUnitScope(Context))) + dyn_cast_if_present(getNonCompileUnitScope(Context))) assert(CT->getIdentifier().empty() && "Context of a global variable should not be a type with identifier"); #endif @@ -1128,7 +1128,7 @@ // cycles underneath it. if (T->isResolved()) for (const MDOperand &O : T->operands()) - if (auto *N = dyn_cast_or_null(O)) + if (auto *N = dyn_cast_if_present(O)) trackIfUnresolved(N); } diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -126,7 +126,7 @@ } DISubprogram *llvm::getDISubprogram(const MDNode *Scope) { - if (auto *LocalScope = dyn_cast_or_null(Scope)) + if (auto *LocalScope = dyn_cast_if_present(Scope)) return LocalScope->getSubprogram(); return nullptr; } @@ -384,7 +384,7 @@ static bool isDILocationReachable(SmallPtrSetImpl &Visited, SmallPtrSetImpl &Reachable, Metadata *MD) { - MDNode *N = dyn_cast_or_null(MD); + MDNode *N = dyn_cast_if_present(MD); if (!N) return false; if (isa(N) || Reachable.count(N)) @@ -534,7 +534,7 @@ return M; } - MDNode *mapNode(Metadata *N) { return dyn_cast_or_null(map(N)); } + MDNode *mapNode(Metadata *N) { return dyn_cast_if_present(map(N)); } /// Recursively remap N and all its referenced children. Does a DF post-order /// traversal, so as to remap bottoms up. @@ -698,7 +698,7 @@ continue; } for (auto &I : N->operands()) - if (auto *MDN = dyn_cast_or_null(I)) + if (auto *MDN = dyn_cast_if_present(I)) if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) && !isa(MDN)) ToVisit.push_back(MDN); @@ -772,7 +772,7 @@ // Remap DILocations in llvm.loop attachments. updateLoopMetadataDebugLocations(I, [&](Metadata *MD) -> Metadata * { - if (auto *Loc = dyn_cast_or_null(MD)) + if (auto *Loc = dyn_cast_if_present(MD)) return remapDebugLoc(Loc).get(); return MD; }); diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp --- a/llvm/lib/IR/DebugInfoMetadata.cpp +++ b/llvm/lib/IR/DebugInfoMetadata.cpp @@ -606,7 +606,7 @@ uint32_t DIDerivedType::getVBPtrOffset() const { assert(getTag() == dwarf::DW_TAG_inheritance); if (auto *CM = cast_or_null(getExtraData())) - if (auto *CI = dyn_cast_or_null(CM->getValue())) + if (auto *CI = dyn_cast_if_present(CM->getValue())) return static_cast(CI->getZExtValue()); return 0; } diff --git a/llvm/lib/IR/LLVMContextImpl.h b/llvm/lib/IR/LLVMContextImpl.h --- a/llvm/lib/IR/LLVMContextImpl.h +++ b/llvm/lib/IR/LLVMContextImpl.h @@ -331,8 +331,8 @@ if (Node1 == Node2) return true; - ConstantAsMetadata *MD1 = dyn_cast_or_null(Node1); - ConstantAsMetadata *MD2 = dyn_cast_or_null(Node2); + ConstantAsMetadata *MD1 = dyn_cast_if_present(Node1); + ConstantAsMetadata *MD2 = dyn_cast_if_present(Node2); if (MD1 && MD2) { ConstantInt *CV1 = cast(MD1->getValue()); ConstantInt *CV2 = cast(MD2->getValue()); @@ -379,7 +379,7 @@ } unsigned getHashValue() const { - auto *MD = dyn_cast_or_null(CountNode); + auto *MD = dyn_cast_if_present(CountNode); if (CountNode && MD) return hash_combine(cast(MD->getValue())->getSExtValue(), LowerBound, UpperBound, Stride); @@ -521,7 +521,7 @@ // Otherwise the hash will be stronger than // MDNodeSubsetEqualImpl::isODRMember(). if (Tag == dwarf::DW_TAG_member && Name) - if (auto *CT = dyn_cast_or_null(Scope)) + if (auto *CT = dyn_cast_if_present(Scope)) if (CT->getRawIdentifier()) return hash_combine(Name, Scope); @@ -554,7 +554,7 @@ if (Tag != dwarf::DW_TAG_member || !Name) return false; - auto *CT = dyn_cast_or_null(Scope); + auto *CT = dyn_cast_if_present(Scope); if (!CT || !CT->getRawIdentifier()) return false; @@ -768,7 +768,7 @@ // name. Otherwise the hash will be stronger than // MDNodeSubsetEqualImpl::isDeclarationOfODRMember(). if (!isDefinition() && LinkageName) - if (auto *CT = dyn_cast_or_null(Scope)) + if (auto *CT = dyn_cast_if_present(Scope)) if (CT->getRawIdentifier()) return hash_combine(LinkageName, Scope); @@ -804,7 +804,7 @@ if (IsDefinition || !Scope || !LinkageName) return false; - auto *CT = dyn_cast_or_null(Scope); + auto *CT = dyn_cast_if_present(Scope); if (!CT || !CT->getRawIdentifier()) return false; diff --git a/llvm/lib/IR/Mangler.cpp b/llvm/lib/IR/Mangler.cpp --- a/llvm/lib/IR/Mangler.cpp +++ b/llvm/lib/IR/Mangler.cpp @@ -144,7 +144,8 @@ // Mangle functions with Microsoft calling conventions specially. Only do // this mangling for x86_64 vectorcall and 32-bit x86. - const Function *MSFunc = dyn_cast_or_null(GV->getAliaseeObject()); + const Function *MSFunc = + dyn_cast_if_present(GV->getAliaseeObject()); // Don't add byte count suffixes when '\01' or '?' are in the first // character. diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp --- a/llvm/lib/IR/Metadata.cpp +++ b/llvm/lib/IR/Metadata.cpp @@ -642,7 +642,7 @@ } static bool isOperandUnresolved(Metadata *Op) { - if (auto *N = dyn_cast_or_null(Op)) + if (auto *N = dyn_cast_if_present(Op)) return !N->isResolved(); return false; } @@ -739,7 +739,7 @@ // Resolve all operands. for (const auto &Op : operands()) { - auto *N = dyn_cast_or_null(Op); + auto *N = dyn_cast_if_present(Op); if (!N) continue; @@ -992,7 +992,7 @@ static MDNode *getOrSelfReference(LLVMContext &Context, ArrayRef Ops) { if (!Ops.empty()) - if (MDNode *N = dyn_cast_or_null(Ops[0])) + if (MDNode *N = dyn_cast_if_present(Ops[0])) if (N->getNumOperands() == Ops.size() && N == N->getOperand(0)) { for (unsigned I = 1, E = Ops.size(); I != E; ++I) if (Ops[I] != N->getOperand(I)) diff --git a/llvm/lib/IR/Module.cpp b/llvm/lib/IR/Module.cpp --- a/llvm/lib/IR/Module.cpp +++ b/llvm/lib/IR/Module.cpp @@ -173,7 +173,7 @@ // If it does not exist, return null. // Function *Module::getFunction(StringRef Name) const { - return dyn_cast_or_null(getNamedValue(Name)); + return dyn_cast_if_present(getNamedValue(Name)); } //===----------------------------------------------------------------------===// @@ -190,7 +190,7 @@ GlobalVariable *Module::getGlobalVariable(StringRef Name, bool AllowLocal) const { if (GlobalVariable *Result = - dyn_cast_or_null(getNamedValue(Name))) + dyn_cast_if_present(getNamedValue(Name))) if (AllowLocal || !Result->hasLocalLinkage()) return Result; return nullptr; @@ -206,7 +206,7 @@ StringRef Name, Type *Ty, function_ref CreateGlobalCallback) { // See if we have a definition for the specified global already. - GlobalVariable *GV = dyn_cast_or_null(getNamedValue(Name)); + GlobalVariable *GV = dyn_cast_if_present(getNamedValue(Name)); if (!GV) GV = CreateGlobalCallback(); assert(GV && "The CreateGlobalCallback is expected to create a global"); @@ -238,11 +238,11 @@ // If it does not exist, return null. // GlobalAlias *Module::getNamedAlias(StringRef Name) const { - return dyn_cast_or_null(getNamedValue(Name)); + return dyn_cast_if_present(getNamedValue(Name)); } GlobalIFunc *Module::getNamedIFunc(StringRef Name) const { - return dyn_cast_or_null(getNamedValue(Name)); + return dyn_cast_if_present(getNamedValue(Name)); } /// getNamedMetadata - Return the first NamedMDNode in the module with the @@ -291,7 +291,7 @@ return false; if (!isValidModFlagBehavior(ModFlag.getOperand(0), MFB)) return false; - MDString *K = dyn_cast_or_null(ModFlag.getOperand(1)); + MDString *K = dyn_cast_if_present(ModFlag.getOperand(1)); if (!K) return false; Key = K; @@ -694,7 +694,7 @@ StringRef Module::getStackProtectorGuard() const { Metadata *MD = getModuleFlag("stack-protector-guard"); - if (auto *MDS = dyn_cast_or_null(MD)) + if (auto *MDS = dyn_cast_if_present(MD)) return MDS->getString(); return {}; } @@ -706,7 +706,7 @@ StringRef Module::getStackProtectorGuardReg() const { Metadata *MD = getModuleFlag("stack-protector-guard-reg"); - if (auto *MDS = dyn_cast_or_null(MD)) + if (auto *MDS = dyn_cast_if_present(MD)) return MDS->getString(); return {}; } @@ -718,7 +718,7 @@ StringRef Module::getStackProtectorGuardSymbol() const { Metadata *MD = getModuleFlag("stack-protector-guard-symbol"); - if (auto *MDS = dyn_cast_or_null(MD)) + if (auto *MDS = dyn_cast_if_present(MD)) return MDS->getString(); return {}; } @@ -769,10 +769,10 @@ } static VersionTuple getSDKVersionMD(Metadata *MD) { - auto *CM = dyn_cast_or_null(MD); + auto *CM = dyn_cast_if_present(MD); if (!CM) return {}; - auto *Arr = dyn_cast_or_null(CM->getValue()); + auto *Arr = dyn_cast_if_present(CM->getValue()); if (!Arr) return {}; auto getVersionComponent = [&](unsigned Index) -> Optional { diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp --- a/llvm/lib/IR/ModuleSummaryIndex.cpp +++ b/llvm/lib/IR/ModuleSummaryIndex.cpp @@ -154,7 +154,7 @@ for (auto &GlobalList : *this) { auto GUID = GlobalList.first; for (auto &GlobSummary : GlobalList.second.SummaryList) { - auto *Summary = dyn_cast_or_null(GlobSummary.get()); + auto *Summary = dyn_cast_if_present(GlobSummary.get()); if (!Summary) // Ignore global variable, focus on functions continue; @@ -469,7 +469,7 @@ // Get string representation of function instruction count and flags. static std::string getSummaryAttributes(GlobalValueSummary* GVS) { - auto *FS = dyn_cast_or_null(GVS); + auto *FS = dyn_cast_if_present(GVS); if (!FS) return ""; @@ -640,12 +640,12 @@ Draw(SummaryIt.first, R.getGUID(), R.isWriteOnly() ? -1 : (R.isReadOnly() ? -2 : -3)); - if (auto *AS = dyn_cast_or_null(SummaryIt.second)) { + if (auto *AS = dyn_cast_if_present(SummaryIt.second)) { Draw(SummaryIt.first, AS->getAliaseeGUID(), -4); continue; } - if (auto *FS = dyn_cast_or_null(SummaryIt.second)) + if (auto *FS = dyn_cast_if_present(SummaryIt.second)) for (auto &CGEdge : FS->calls()) Draw(SummaryIt.first, CGEdge.first.getGUID(), static_cast(CGEdge.second.Hotness)); diff --git a/llvm/lib/IR/ProfileSummary.cpp b/llvm/lib/IR/ProfileSummary.cpp --- a/llvm/lib/IR/ProfileSummary.cpp +++ b/llvm/lib/IR/ProfileSummary.cpp @@ -192,21 +192,21 @@ } ProfileSummary *ProfileSummary::getFromMD(Metadata *MD) { - MDTuple *Tuple = dyn_cast_or_null(MD); + MDTuple *Tuple = dyn_cast_if_present(MD); if (!Tuple || Tuple->getNumOperands() < 8 || Tuple->getNumOperands() > 10) return nullptr; unsigned I = 0; auto &FormatMD = Tuple->getOperand(I++); ProfileSummary::Kind SummaryKind; - if (isKeyValuePair(dyn_cast_or_null(FormatMD), "ProfileFormat", + if (isKeyValuePair(dyn_cast_if_present(FormatMD), "ProfileFormat", "SampleProfile")) SummaryKind = PSK_Sample; - else if (isKeyValuePair(dyn_cast_or_null(FormatMD), "ProfileFormat", - "InstrProf")) + else if (isKeyValuePair(dyn_cast_if_present(FormatMD), + "ProfileFormat", "InstrProf")) SummaryKind = PSK_Instr; - else if (isKeyValuePair(dyn_cast_or_null(FormatMD), "ProfileFormat", - "CSInstrProf")) + else if (isKeyValuePair(dyn_cast_if_present(FormatMD), + "ProfileFormat", "CSInstrProf")) SummaryKind = PSK_CSInstr; else return nullptr; diff --git a/llvm/lib/IR/Type.cpp b/llvm/lib/IR/Type.cpp --- a/llvm/lib/IR/Type.cpp +++ b/llvm/lib/IR/Type.cpp @@ -616,7 +616,7 @@ const Constant *C = dyn_cast(V); if (C && V->getType()->isVectorTy()) C = C->getSplatValue(); - const ConstantInt *CU = dyn_cast_or_null(C); + const ConstantInt *CU = dyn_cast_if_present(C); return CU && CU->getZExtValue() < getNumElements(); } diff --git a/llvm/lib/IR/User.cpp b/llvm/lib/IR/User.cpp --- a/llvm/lib/IR/User.cpp +++ b/llvm/lib/IR/User.cpp @@ -33,7 +33,7 @@ setOperand(i, To); Changed = true; } - if (auto DVI = dyn_cast_or_null(this)) { + if (auto DVI = dyn_cast_if_present(this)) { if (is_contained(DVI->location_ops(), From)) { DVI->replaceVariableLocationOp(From, To); Changed = true; diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp --- a/llvm/lib/IR/Value.cpp +++ b/llvm/lib/IR/Value.cpp @@ -969,9 +969,10 @@ // Strip pointer casts to avoid creating unnecessary ptrtoint expression // if the only "reduction" is combining a bitcast + ptrtoint. CstPtr = CstPtr->stripPointerCasts(); - if (auto *CstInt = dyn_cast_or_null(ConstantExpr::getPtrToInt( - const_cast(CstPtr), DL.getIntPtrType(getType()), - /*OnlyIfReduced=*/true))) { + if (auto *CstInt = + dyn_cast_if_present(ConstantExpr::getPtrToInt( + const_cast(CstPtr), DL.getIntPtrType(getType()), + /*OnlyIfReduced=*/true))) { size_t TrailingZeros = CstInt->getValue().countTrailingZeros(); // While the actual alignment may be large, elsewhere we have // an arbitrary upper alignmet limit, so let's clamp to it. diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp --- a/llvm/lib/IR/Verifier.cpp +++ b/llvm/lib/IR/Verifier.cpp @@ -1098,8 +1098,8 @@ if (N.getTag() == dwarf::DW_TAG_set_type) { if (auto *T = N.getRawBaseType()) { - auto *Enum = dyn_cast_or_null(T); - auto *Basic = dyn_cast_or_null(T); + auto *Enum = dyn_cast_if_present(T); + auto *Basic = dyn_cast_if_present(T); CheckDI( (Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type) || (Basic && (Basic->getEncoding() == dwarf::DW_ATE_unsigned || @@ -1261,7 +1261,7 @@ if (auto *Array = N.getRawEnumTypes()) { CheckDI(isa(Array), "invalid enum list", &N, Array); for (Metadata *Op : N.getEnumTypes()->operands()) { - auto *Enum = dyn_cast_or_null(Op); + auto *Enum = dyn_cast_if_present(Op); CheckDI(Enum && Enum->getTag() == dwarf::DW_TAG_enumeration_type, "invalid enum type", &N, N.getEnumTypes(), Op); } @@ -1540,7 +1540,7 @@ for (const MDNode *N : Idents->operands()) { Check(N->getNumOperands() == 1, "incorrect number of operands in llvm.ident metadata", N); - Check(dyn_cast_or_null(N->getOperand(0)), + Check(dyn_cast_if_present(N->getOperand(0)), ("invalid value for llvm.ident metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); @@ -1558,7 +1558,7 @@ for (const MDNode *N : CommandLines->operands()) { Check(N->getNumOperands() == 1, "incorrect number of operands in llvm.commandline metadata", N); - Check(dyn_cast_or_null(N->getOperand(0)), + Check(dyn_cast_if_present(N->getOperand(0)), ("invalid value for llvm.commandline metadata entry operand" "(the operand should be a string)"), N->getOperand(0)); @@ -1613,7 +1613,7 @@ "invalid behavior operand in module flag (unexpected constant)", Op->getOperand(0)); } - MDString *ID = dyn_cast_or_null(Op->getOperand(1)); + MDString *ID = dyn_cast_if_present(Op->getOperand(1)); Check(ID, "invalid ID operand in module flag (expected metadata string)", Op->getOperand(1)); @@ -1712,11 +1712,11 @@ Check(F && isa(F->getValue()->stripPointerCasts()), "expected a Function or null", FuncMDO); }; - auto Node = dyn_cast_or_null(MDO); + auto Node = dyn_cast_if_present(MDO); Check(Node && Node->getNumOperands() == 3, "expected a MDNode triple", MDO); CheckFunction(Node->getOperand(0)); CheckFunction(Node->getOperand(1)); - auto Count = dyn_cast_or_null(Node->getOperand(2)); + auto Count = dyn_cast_if_present(Node->getOperand(2)); Check(Count && Count->getType()->isIntegerTy(), "expected an integer constant", Node->getOperand(2)); } @@ -2721,7 +2721,7 @@ auto VisitDebugLoc = [&](const Instruction &I, const MDNode *Node) { // Be careful about using DILocation here since we might be dealing with // broken code (this is the Verifier after all). - const DILocation *DL = dyn_cast_or_null(Node); + const DILocation *DL = dyn_cast_if_present(Node); if (!DL) return; if (!Seen.insert(DL).second) @@ -2754,7 +2754,7 @@ // The llvm.loop annotations also contain two DILocations. if (auto MD = I.getMetadata(LLVMContext::MD_loop)) for (unsigned i = 1; i < MD->getNumOperands(); ++i) - VisitDebugLoc(I, dyn_cast_or_null(MD->getOperand(i))); + VisitDebugLoc(I, dyn_cast_if_present(MD->getOperand(i))); if (BrokenDebugInfo) return; } @@ -3526,7 +3526,7 @@ Instruction *Next = CI.getNextNode(); // Handle the optional bitcast. - if (BitCastInst *BI = dyn_cast_or_null(Next)) { + if (BitCastInst *BI = dyn_cast_if_present(Next)) { Check(BI->getOperand(0) == RetVal, "bitcast following musttail call must use the call", BI); RetVal = BI; @@ -3534,7 +3534,7 @@ } // Check the return. - ReturnInst *Ret = dyn_cast_or_null(Next); + ReturnInst *Ret = dyn_cast_if_present(Next); Check(Ret, "musttail call must precede a ret with an optional bitcast", &CI); Check(!Ret->getReturnValue() || Ret->getReturnValue() == RetVal || isa(Ret->getReturnValue()), @@ -6016,8 +6016,8 @@ } void Verifier::verifyFragmentExpression(const DbgVariableIntrinsic &I) { - DILocalVariable *V = dyn_cast_or_null(I.getRawVariable()); - DIExpression *E = dyn_cast_or_null(I.getRawExpression()); + DILocalVariable *V = dyn_cast_if_present(I.getRawVariable()); + DIExpression *E = dyn_cast_if_present(I.getRawExpression()); // We don't know whether this intrinsic verified correctly. if (!V || !E || !E->isValid()) @@ -6087,7 +6087,7 @@ } void Verifier::verifyNotEntryValue(const DbgVariableIntrinsic &I) { - DIExpression *E = dyn_cast_or_null(I.getRawExpression()); + DIExpression *E = dyn_cast_if_present(I.getRawExpression()); // We don't know whether this intrinsic verified correctly. if (!E || !E->isValid()) @@ -6479,7 +6479,7 @@ return false; } - auto *Parent = dyn_cast_or_null(MD->getOperand(1)); + auto *Parent = dyn_cast_if_present(MD->getOperand(1)); return Parent && Visited.insert(Parent).second && (IsRootTBAANode(Parent) || IsScalarTBAANodeImpl(Parent, Visited)); } @@ -6564,8 +6564,8 @@ "Old-style TBAA is no longer allowed, use struct-path TBAA instead", &I); - MDNode *BaseNode = dyn_cast_or_null(MD->getOperand(0)); - MDNode *AccessType = dyn_cast_or_null(MD->getOperand(1)); + MDNode *BaseNode = dyn_cast_if_present(MD->getOperand(0)); + MDNode *AccessType = dyn_cast_if_present(MD->getOperand(1)); bool IsNewFormat = isNewFormatTBAATypeNode(AccessType); diff --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp --- a/llvm/lib/LTO/LTO.cpp +++ b/llvm/lib/LTO/LTO.cpp @@ -254,7 +254,7 @@ AddUsedThings(S); // If this is an alias, we also care about any types/etc. that the aliasee // may reference. - if (auto *AS = dyn_cast_or_null(S)) + if (auto *AS = dyn_cast_if_present(S)) AddUsedThings(AS->getBaseObject()); } diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp --- a/llvm/lib/Linker/LinkModules.cpp +++ b/llvm/lib/Linker/LinkModules.cpp @@ -131,7 +131,7 @@ bool ModuleLinker::getComdatLeader(Module &M, StringRef ComdatName, const GlobalVariable *&GVar) { const GlobalValue *GVal = M.getNamedValue(ComdatName); - if (const auto *GA = dyn_cast_or_null(GVal)) { + if (const auto *GA = dyn_cast_if_present(GVal)) { GVal = GA->getAliaseeObject(); if (!GVal) // We cannot resolve the size of the aliasee yet. @@ -139,7 +139,7 @@ "': COMDAT key involves incomputable alias size."); } - GVar = dyn_cast_or_null(GVal); + GVar = dyn_cast_if_present(GVal); if (!GVar) return emitError( "Linking COMDATs named '" + ComdatName + diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -223,7 +223,7 @@ MCDataFragment * MCObjectStreamer::getOrCreateDataFragment(const MCSubtargetInfo *STI) { - MCDataFragment *F = dyn_cast_or_null(getCurrentFragment()); + MCDataFragment *F = dyn_cast_if_present(getCurrentFragment()); if (!F || !canReuseDataFragment(*F, *Assembler, STI)) { F = new MCDataFragment(); insert(F); @@ -291,7 +291,7 @@ // If there is a current fragment, mark the symbol as pointing into it. // Otherwise queue the label and set its fragment pointer when we emit the // next fragment. - auto *F = dyn_cast_or_null(getCurrentFragment()); + auto *F = dyn_cast_if_present(getCurrentFragment()); if (F && !(getAssembler().isBundlingEnabled() && getAssembler().getRelaxAll())) { Symbol->setFragment(F); @@ -325,7 +325,7 @@ MCStreamer::emitLabel(Symbol, Loc); getAssembler().registerSymbol(*Symbol); - auto *DF = dyn_cast_or_null(F); + auto *DF = dyn_cast_if_present(F); Symbol->setOffset(Offset); if (DF) { Symbol->setFragment(F); diff --git a/llvm/lib/MC/MCParser/ELFAsmParser.cpp b/llvm/lib/MC/MCParser/ELFAsmParser.cpp --- a/llvm/lib/MC/MCParser/ELFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/ELFAsmParser.cpp @@ -472,7 +472,8 @@ } return TokError("invalid linked-to symbol"); } - LinkedToSym = dyn_cast_or_null(getContext().lookupSymbol(Name)); + LinkedToSym = + dyn_cast_if_present(getContext().lookupSymbol(Name)); if (!LinkedToSym || !LinkedToSym->isInSection()) return Error(StartLoc, "linked-to symbol is not in a section: " + Name); return false; diff --git a/llvm/lib/MC/MCParser/MasmParser.cpp b/llvm/lib/MC/MCParser/MasmParser.cpp --- a/llvm/lib/MC/MCParser/MasmParser.cpp +++ b/llvm/lib/MC/MCParser/MasmParser.cpp @@ -3515,7 +3515,7 @@ MCSymbol *Sym = getContext().getOrCreateSymbol(Var.Name); const MCConstantExpr *PrevValue = - Sym->isVariable() ? dyn_cast_or_null( + Sym->isVariable() ? dyn_cast_if_present( Sym->getVariableValue(/*SetUsed=*/false)) : nullptr; if (Var.IsText || !PrevValue || PrevValue->getValue() != Value) { diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -778,7 +778,7 @@ if (!Asm.CGProfile.empty()) { MCSection *CGProfileSection = Asm.getContext().getMachOSection( "__LLVM", "__cg_profile", 0, SectionKind::getMetadata()); - MCDataFragment *Frag = dyn_cast_or_null( + MCDataFragment *Frag = dyn_cast_if_present( &*CGProfileSection->getFragmentList().begin()); assert(Frag && "call graph profile section not reserved"); Frag->getContents().clear(); diff --git a/llvm/lib/ObjectYAML/ELFEmitter.cpp b/llvm/lib/ObjectYAML/ELFEmitter.cpp --- a/llvm/lib/ObjectYAML/ELFEmitter.cpp +++ b/llvm/lib/ObjectYAML/ELFEmitter.cpp @@ -979,7 +979,7 @@ Symbols = *Doc.DynamicSymbols; ELFYAML::RawContentSection *RawSec = - dyn_cast_or_null(YAMLSec); + dyn_cast_if_present(YAMLSec); if (RawSec && (RawSec->Content || RawSec->Size)) { bool HasSymbolsDescription = (IsStatic && Doc.Symbols) || (!IsStatic && Doc.DynamicSymbols); @@ -1040,7 +1040,7 @@ SHeader.sh_addralign = YAMLSec ? (uint64_t)YAMLSec->AddressAlign : 1; ELFYAML::RawContentSection *RawSec = - dyn_cast_or_null(YAMLSec); + dyn_cast_if_present(YAMLSec); SHeader.sh_offset = alignToOffset(CBA, SHeader.sh_addralign, YAMLSec ? YAMLSec->Offset : None); @@ -1100,7 +1100,7 @@ YAMLSec ? YAMLSec->Offset : None); ELFYAML::RawContentSection *RawSec = - dyn_cast_or_null(YAMLSec); + dyn_cast_if_present(YAMLSec); if (Doc.DWARF && shouldEmitDWARF(*Doc.DWARF, Name)) { if (RawSec && (RawSec->Content || RawSec->Size)) reportError("cannot specify section '" + Name + diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -1172,7 +1172,8 @@ if (!IRInstrVar->hasInitializer()) return false; - auto *InitVal = dyn_cast_or_null(IRInstrVar->getInitializer()); + auto *InitVal = + dyn_cast_if_present(IRInstrVar->getInitializer()); if (!InitVal) return false; return (InitVal->getZExtValue() & VARIANT_MASK_IR_PROF) != 0; diff --git a/llvm/lib/Support/YAMLTraits.cpp b/llvm/lib/Support/YAMLTraits.cpp --- a/llvm/lib/Support/YAMLTraits.cpp +++ b/llvm/lib/Support/YAMLTraits.cpp @@ -133,7 +133,7 @@ if (EC) return; // CurrentNode can be null if the document is empty. - MapHNode *MN = dyn_cast_or_null(CurrentNode); + MapHNode *MN = dyn_cast_if_present(CurrentNode); if (MN) { MN->ValidKeys.clear(); } @@ -195,7 +195,7 @@ if (EC) return; // CurrentNode can be null if the document is empty. - MapHNode *MN = dyn_cast_or_null(CurrentNode); + MapHNode *MN = dyn_cast_if_present(CurrentNode); if (!MN) return; for (const auto &NN : MN->Mapping) { @@ -420,7 +420,7 @@ auto mapHNode = std::make_unique(N); for (KeyValueNode &KVN : *Map) { Node *KeyNode = KVN.getKey(); - ScalarNode *Key = dyn_cast_or_null(KeyNode); + ScalarNode *Key = dyn_cast_if_present(KeyNode); Node *Value = KVN.getValue(); if (!Key || !Value) { if (!Key) diff --git a/llvm/lib/TableGen/Error.cpp b/llvm/lib/TableGen/Error.cpp --- a/llvm/lib/TableGen/Error.cpp +++ b/llvm/lib/TableGen/Error.cpp @@ -157,8 +157,9 @@ // Check an assertion: Obtain the condition value and be sure it is true. // If not, print a nonfatal error along with the message. void CheckAssert(SMLoc Loc, Init *Condition, Init *Message) { - auto *CondValue = dyn_cast_or_null(Condition->convertInitializerTo( - IntRecTy::get(Condition->getRecordKeeper()))); + auto *CondValue = + dyn_cast_if_present(Condition->convertInitializerTo( + IntRecTy::get(Condition->getRecordKeeper()))); if (!CondValue) PrintError(Loc, "assert condition must of type bit, bits, or int."); else if (!CondValue->getValue()) { diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp --- a/llvm/lib/TableGen/Record.cpp +++ b/llvm/lib/TableGen/Record.cpp @@ -785,7 +785,7 @@ if (DefInit *LHSd = dyn_cast(LHS)) return StringInit::get(RK, LHSd->getAsString()); - if (IntInit *LHSi = dyn_cast_or_null( + if (IntInit *LHSi = dyn_cast_if_present( LHS->convertInitializerTo(IntRecTy::get(RK)))) return StringInit::get(RK, LHSi->getAsString()); @@ -832,7 +832,7 @@ break; case NOT: - if (IntInit *LHSi = dyn_cast_or_null( + if (IntInit *LHSi = dyn_cast_if_present( LHS->convertInitializerTo(IntRecTy::get(RK)))) return IntInit::get(RK, LHSi->getValue() ? 0 : 1); break; @@ -974,7 +974,7 @@ RecordKeeper &RK = List->getRecordKeeper(); if (List->size() == 0) return StringInit::get(RK, ""); - IntInit *Element = dyn_cast_or_null( + IntInit *Element = dyn_cast_if_present( List->getElement(0)->convertInitializerTo(IntRecTy::get(RK))); if (!Element) return nullptr; @@ -982,7 +982,7 @@ for (unsigned I = 1, E = List->size(); I < E; ++I) { Result.append(Delim->getValue()); - IntInit *Element = dyn_cast_or_null( + IntInit *Element = dyn_cast_if_present( List->getElement(I)->convertInitializerTo(IntRecTy::get(RK))); if (!Element) return nullptr; @@ -1100,9 +1100,9 @@ case GE: case GT: { // First see if we have two bit, bits, or int. - IntInit *LHSi = dyn_cast_or_null( + IntInit *LHSi = dyn_cast_if_present( LHS->convertInitializerTo(IntRecTy::get(getRecordKeeper()))); - IntInit *RHSi = dyn_cast_or_null( + IntInit *RHSi = dyn_cast_if_present( RHS->convertInitializerTo(IntRecTy::get(getRecordKeeper()))); if (LHSi && RHSi) { @@ -1171,9 +1171,9 @@ case SHL: case SRA: case SRL: { - IntInit *LHSi = dyn_cast_or_null( + IntInit *LHSi = dyn_cast_if_present( LHS->convertInitializerTo(IntRecTy::get(getRecordKeeper()))); - IntInit *RHSi = dyn_cast_or_null( + IntInit *RHSi = dyn_cast_if_present( RHS->convertInitializerTo(IntRecTy::get(getRecordKeeper()))); if (LHSi && RHSi) { int64_t LHSv = LHSi->getValue(), RHSv = RHSi->getValue(); @@ -1331,7 +1331,7 @@ if (!Include) return nullptr; if (IntInit *IncludeInt = - dyn_cast_or_null(Include->convertInitializerTo( + dyn_cast_if_present(Include->convertInitializerTo( IntRecTy::get(LHS->getRecordKeeper())))) { if (IncludeInt->getValue()) NewList.push_back(Item); @@ -1405,7 +1405,7 @@ } case IF: { - if (IntInit *LHSi = dyn_cast_or_null( + if (IntInit *LHSi = dyn_cast_if_present( LHS->convertInitializerTo(IntRecTy::get(RK)))) { if (LHSi->getValue()) return MHS; @@ -1487,7 +1487,7 @@ Init *lhs = LHS->resolveReferences(R); if (getOpcode() == IF && lhs != LHS) { - if (IntInit *Value = dyn_cast_or_null( + if (IntInit *Value = dyn_cast_if_present( lhs->convertInitializerTo(IntRecTy::get(getRecordKeeper())))) { // Short-circuit if (Value->getValue()) @@ -2165,7 +2165,7 @@ Init *Cond = getCond(i); Init *Val = getVal(i); - if (IntInit *CondI = dyn_cast_or_null( + if (IntInit *CondI = dyn_cast_if_present( Cond->convertInitializerTo(IntRecTy::get(RK)))) { if (CondI->getValue()) return Val->convertInitializerTo(getValType()); diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp --- a/llvm/lib/TableGen/TGParser.cpp +++ b/llvm/lib/TableGen/TGParser.cpp @@ -695,7 +695,7 @@ if (!CurVal) CurVal = ParseValue(nullptr); - IntInit *II = dyn_cast_or_null(CurVal); + IntInit *II = dyn_cast_if_present(CurVal); if (!II) return TokError("expected integer or bitrange"); @@ -715,7 +715,7 @@ Lex.Lex(); // eat Init *I_End = ParseValue(nullptr); - IntInit *II_End = dyn_cast_or_null(I_End); + IntInit *II_End = dyn_cast_if_present(I_End); if (!II_End) { TokError("expected integer value as end of range"); return true; diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp --- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp +++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp @@ -4855,7 +4855,7 @@ SDValue FnOp = Op.getOperand(1); SDValue IncomingFPOp = Op.getOperand(2); GlobalAddressSDNode *GSD = dyn_cast(FnOp); - auto *Fn = dyn_cast_or_null(GSD ? GSD->getGlobal() : nullptr); + auto *Fn = dyn_cast_if_present(GSD ? GSD->getGlobal() : nullptr); if (!Fn) report_fatal_error( "llvm.eh.recoverfp must take a function as the first argument"); @@ -17886,7 +17886,7 @@ Index.getOperand(0).getOpcode() == ISD::STEP_VECTOR) { SDValue RHS = Index.getOperand(1); if (auto *Shift = - dyn_cast_or_null(DAG.getSplatValue(RHS))) { + dyn_cast_if_present(DAG.getSplatValue(RHS))) { int64_t Step = (int64_t)Index.getOperand(0).getConstantOperandVal(1); Stride = Step << Shift->getZExtValue(); } diff --git a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp --- a/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp +++ b/llvm/lib/Target/AArch64/AArch64TargetTransformInfo.cpp @@ -706,7 +706,7 @@ // Check that we have a compare of zero.. auto *SplatValue = - dyn_cast_or_null(getSplatValue(II.getArgOperand(2))); + dyn_cast_if_present(getSplatValue(II.getArgOperand(2))); if (!SplatValue || !SplatValue->isZero()) return None; @@ -1179,7 +1179,7 @@ // Check whether OpIndices is a constant splat value < minimal element count // of result. - auto *SplatValue = dyn_cast_or_null(getSplatValue(OpIndices)); + auto *SplatValue = dyn_cast_if_present(getSplatValue(OpIndices)); if (!SplatValue || SplatValue->getValue().uge(VTy->getElementCount().getKnownMinValue())) return None; @@ -1313,7 +1313,7 @@ Value *DivVec = II.getOperand(2); Value *SplatValue = getSplatValue(DivVec); - ConstantInt *SplatConstantInt = dyn_cast_or_null(SplatValue); + ConstantInt *SplatConstantInt = dyn_cast_if_present(SplatValue); if (!SplatConstantInt) return None; APInt Divisor = SplatConstantInt->getValue(); diff --git a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp --- a/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp +++ b/llvm/lib/Target/AArch64/AsmParser/AArch64AsmParser.cpp @@ -4421,7 +4421,7 @@ SMLoc L = getLoc(); if (check(getParser().parseExpression(Expr), L, "expected expression")) return true; - const MCConstantExpr *Value = dyn_cast_or_null(Expr); + const MCConstantExpr *Value = dyn_cast_if_present(Expr); if (check(!Value, L, "expected constant expression")) return true; Out = Value->getValue(); @@ -6344,7 +6344,7 @@ const MCExpr *Expr = nullptr; if (check(getParser().parseExpression(Expr), L, "expected expression")) return true; - const MCConstantExpr *Value = dyn_cast_or_null(Expr); + const MCConstantExpr *Value = dyn_cast_if_present(Expr); if (check(!Value, L, "expected constant expression")) return true; getTargetStreamer().emitInst(Value->getValue()); diff --git a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULibCalls.cpp @@ -826,8 +826,9 @@ ConstantDataVector *CDV = dyn_cast(opr1); // Now, only Handle vector const whose elements have the same value. - CF = CDV ? dyn_cast_or_null(CDV->getSplatValue()) : nullptr; - CINT = CDV ? dyn_cast_or_null(CDV->getSplatValue()) : nullptr; + CF = CDV ? dyn_cast_if_present(CDV->getSplatValue()) : nullptr; + CINT = + CDV ? dyn_cast_if_present(CDV->getSplatValue()) : nullptr; } // No unsafe math , no constant argument, do nothing @@ -1248,7 +1249,7 @@ CallInst *UI = nullptr; for (User* U : CArgVal->users()) { - CallInst *XI = dyn_cast_or_null(U); + CallInst *XI = dyn_cast_if_present(U); if (!XI || XI == CI || XI->getParent() != CBB) continue; @@ -1367,20 +1368,20 @@ // By default, opr0/opr1/opr3 holds values of float/double type. // If they are not float/double, each function has to its // operand separately. - double opr0=0.0, opr1=0.0, opr2=0.0; - ConstantFP *fpopr0 = dyn_cast_or_null(copr0); - ConstantFP *fpopr1 = dyn_cast_or_null(copr1); - ConstantFP *fpopr2 = dyn_cast_or_null(copr2); + double opr0 = 0.0, opr1 = 0.0, opr2 = 0.0; + ConstantFP *fpopr0 = dyn_cast_if_present(copr0); + ConstantFP *fpopr1 = dyn_cast_if_present(copr1); + ConstantFP *fpopr2 = dyn_cast_if_present(copr2); if (fpopr0) { opr0 = (getArgType(FInfo) == AMDGPULibFunc::F64) - ? fpopr0->getValueAPF().convertToDouble() - : (double)fpopr0->getValueAPF().convertToFloat(); + ? fpopr0->getValueAPF().convertToDouble() + : (double)fpopr0->getValueAPF().convertToFloat(); } if (fpopr1) { opr1 = (getArgType(FInfo) == AMDGPULibFunc::F64) - ? fpopr1->getValueAPF().convertToDouble() - : (double)fpopr1->getValueAPF().convertToFloat(); + ? fpopr1->getValueAPF().convertToDouble() + : (double)fpopr1->getValueAPF().convertToFloat(); } if (fpopr2) { @@ -1522,7 +1523,7 @@ return true; case AMDGPULibFunc::EI_POWN: { - if (ConstantInt *iopr1 = dyn_cast_or_null(copr1)) { + if (ConstantInt *iopr1 = dyn_cast_if_present(copr1)) { double val = (double)iopr1->getSExtValue(); Res0 = pow(opr0, val); return true; @@ -1531,7 +1532,7 @@ } case AMDGPULibFunc::EI_ROOTN: { - if (ConstantInt *iopr1 = dyn_cast_or_null(copr1)) { + if (ConstantInt *iopr1 = dyn_cast_if_present(copr1)) { double val = (double)iopr1->getSExtValue(); Res0 = pow(opr0, 1.0 / val); return true; @@ -1592,15 +1593,15 @@ return false; } } else { - ConstantDataVector *CDV0 = dyn_cast_or_null(copr0); - ConstantDataVector *CDV1 = dyn_cast_or_null(copr1); - ConstantDataVector *CDV2 = dyn_cast_or_null(copr2); + ConstantDataVector *CDV0 = dyn_cast_if_present(copr0); + ConstantDataVector *CDV1 = dyn_cast_if_present(copr1); + ConstantDataVector *CDV2 = dyn_cast_if_present(copr2); for (int i = 0; i < FuncVecSize; ++i) { Constant *celt0 = CDV0 ? CDV0->getElementAsConstant(i) : nullptr; Constant *celt1 = CDV1 ? CDV1->getElementAsConstant(i) : nullptr; Constant *celt2 = CDV2 ? CDV2->getElementAsConstant(i) : nullptr; - if (!evaluateScalarMathFunc(FInfo, DVal0[i], - DVal1[i], celt0, celt1, celt2)) { + if (!evaluateScalarMathFunc(FInfo, DVal0[i], DVal1[i], celt0, celt1, + celt2)) { return false; } } diff --git a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPULibFunc.cpp @@ -946,8 +946,8 @@ Function *AMDGPULibFunc::getFunction(Module *M, const AMDGPULibFunc &fInfo) { std::string FuncName = fInfo.mangle(); - Function *F = dyn_cast_or_null( - M->getValueSymbolTable().lookup(FuncName)); + Function *F = + dyn_cast_if_present(M->getValueSymbolTable().lookup(FuncName)); // check formal with actual types conformance if (F && !F->isDeclaration() @@ -961,8 +961,8 @@ FunctionCallee AMDGPULibFunc::getOrInsertFunction(Module *M, const AMDGPULibFunc &fInfo) { std::string const FuncName = fInfo.mangle(); - Function *F = dyn_cast_or_null( - M->getValueSymbolTable().lookup(FuncName)); + Function *F = + dyn_cast_if_present(M->getValueSymbolTable().lookup(FuncName)); // check formal with actual types conformance if (F && !F->isDeclaration() diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPerfHintAnalysis.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPerfHintAnalysis.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUPerfHintAnalysis.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUPerfHintAnalysis.cpp @@ -258,7 +258,7 @@ } else if (auto *GEP = dyn_cast(&I)) { TargetLoweringBase::AddrMode AM; auto *Ptr = GetPointerBaseWithConstantOffset(GEP, AM.BaseOffs, *DL); - AM.BaseGV = dyn_cast_or_null(const_cast(Ptr)); + AM.BaseGV = dyn_cast_if_present(const_cast(Ptr)); AM.HasBaseReg = !AM.BaseGV; if (TLI->isLegalAddressingMode(*DL, AM, GEP->getResultElementType(), GEP->getPointerAddressSpace())) diff --git a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp --- a/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp +++ b/llvm/lib/Target/AMDGPU/AMDGPUTargetTransformInfo.cpp @@ -735,7 +735,7 @@ switch (Opcode) { case Instruction::Br: { // Branch instruction takes about 4 slots on gfx900. - auto BI = dyn_cast_or_null(I); + auto BI = dyn_cast_if_present(I); if (BI && BI->isUnconditional()) return SCost ? 1 : 4; // Suppose conditional branch takes additional 3 exec manipulations @@ -743,7 +743,7 @@ return CBrCost; } case Instruction::Switch: { - auto SI = dyn_cast_or_null(I); + auto SI = dyn_cast_if_present(I); // Each case (including default) takes 1 cmp + 1 cbr instructions in // average. return (SI ? (SI->getNumCases() + 1) : 4) * (CBrCost + 1); diff --git a/llvm/lib/Target/AMDGPU/R600OpenCLImageTypeLoweringPass.cpp b/llvm/lib/Target/AMDGPU/R600OpenCLImageTypeLoweringPass.cpp --- a/llvm/lib/Target/AMDGPU/R600OpenCLImageTypeLoweringPass.cpp +++ b/llvm/lib/Target/AMDGPU/R600OpenCLImageTypeLoweringPass.cpp @@ -89,7 +89,7 @@ // Validation checks. size_t ExpectNumArgNodeOps = F->arg_size() + 1; for (size_t i = 0; i < NumKernelArgMDNodes; ++i) { - MDNode *ArgNode = dyn_cast_or_null(Node->getOperand(i + 1)); + MDNode *ArgNode = dyn_cast_if_present(Node->getOperand(i + 1)); if (ArgNode->getNumOperands() != ExpectNumArgNodeOps) return nullptr; if (!ArgNode->getOperand(0)) diff --git a/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp b/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp --- a/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp +++ b/llvm/lib/Target/ARM/ARMConstantPoolValue.cpp @@ -181,11 +181,11 @@ } const GlobalValue *ARMConstantPoolConstant::getGV() const { - return dyn_cast_or_null(CVal); + return dyn_cast_if_present(CVal); } const BlockAddress *ARMConstantPoolConstant::getBlockAddress() const { - return dyn_cast_or_null(CVal); + return dyn_cast_if_present(CVal); } int ARMConstantPoolConstant::getExistingMachineCPValue(MachineConstantPool *CP, diff --git a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp --- a/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp +++ b/llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp @@ -1011,7 +1011,7 @@ (Opcode == Instruction::ICmp || Opcode == Instruction::FCmp) && cast(ValTy)->getNumElements() > 1) { FixedVectorType *VecValTy = cast(ValTy); - FixedVectorType *VecCondTy = dyn_cast_or_null(CondTy); + FixedVectorType *VecCondTy = dyn_cast_if_present(CondTy); if (!VecCondTy) VecCondTy = cast(CmpInst::makeCmpResultType(VecValTy)); diff --git a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp --- a/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp +++ b/llvm/lib/Target/ARM/AsmParser/ARMAsmParser.cpp @@ -6334,7 +6334,7 @@ SMLoc L = getParser().getTok().getLoc(); if (check(getParser().parseExpression(Expr), L, "expected expression")) return true; - const MCConstantExpr *Value = dyn_cast_or_null(Expr); + const MCConstantExpr *Value = dyn_cast_if_present(Expr); if (check(!Value, L, "expected constant expression")) return true; Out = Value->getValue(); @@ -11773,7 +11773,7 @@ const MCExpr *Expr; if (getParser().parseExpression(Expr)) return true; - const MCConstantExpr *Value = dyn_cast_or_null(Expr); + const MCConstantExpr *Value = dyn_cast_if_present(Expr); if (!Value) { return Error(Loc, "expected constant expression"); } diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp --- a/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp +++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMELFStreamer.cpp @@ -563,7 +563,8 @@ /// ARM streamer overrides it to add the appropriate mapping symbol ($d) if /// necessary. void emitValueImpl(const MCExpr *Value, unsigned Size, SMLoc Loc) override { - if (const MCSymbolRefExpr *SRE = dyn_cast_or_null(Value)) { + if (const MCSymbolRefExpr *SRE = + dyn_cast_if_present(Value)) { if (SRE->getKind() == MCSymbolRefExpr::VK_ARM_SBREL && !(Size == 4)) { getContext().reportError(Loc, "relocated expression must be 32-bit"); return; @@ -645,7 +646,7 @@ // This is a tentative symbol, it won't really be emitted until it's // actually needed. ElfMappingSymbolInfo *EMS = LastEMSInfo.get(); - auto *DF = dyn_cast_or_null(getCurrentFragment()); + auto *DF = dyn_cast_if_present(getCurrentFragment()); if (!DF) return; EMS->Loc = SMLoc(); diff --git a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp --- a/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp +++ b/llvm/lib/Target/BPF/BPFAbstractMemberAccess.cpp @@ -335,7 +335,7 @@ DINodeArray Elements = CTy->getElements(); uint32_t DimSize = 1; for (uint32_t I = StartDim; I < Elements.size(); ++I) { - if (auto *Element = dyn_cast_or_null(Elements[I])) + if (auto *Element = dyn_cast_if_present(Elements[I])) if (Element->getTag() == dwarf::DW_TAG_subrange_type) { const DISubrange *SR = cast(Element); auto *CI = SR->getCount().dyn_cast(); diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp --- a/llvm/lib/Target/BPF/BTFDebug.cpp +++ b/llvm/lib/Target/BPF/BTFDebug.cpp @@ -681,7 +681,7 @@ // Visit array dimensions. DINodeArray Elements = CTy->getElements(); for (int I = Elements.size() - 1; I >= 0; --I) { - if (auto *Element = dyn_cast_or_null(Elements[I])) + if (auto *Element = dyn_cast_if_present(Elements[I])) if (Element->getTag() == dwarf::DW_TAG_subrange_type) { const DISubrange *SR = cast(Element); auto *CI = SR->getCount().dyn_cast(); @@ -690,8 +690,7 @@ // For struct s { int b; char c[]; }, the c[] will be represented // as an array with Count = -1. auto TypeEntry = - std::make_unique(ElemTypeId, - Count >= 0 ? Count : 0); + std::make_unique(ElemTypeId, Count >= 0 ? Count : 0); if (I == 0) ElemTypeId = addType(std::move(TypeEntry), CTy); else diff --git a/llvm/lib/Target/DirectX/PointerTypeAnalysis.cpp b/llvm/lib/Target/DirectX/PointerTypeAnalysis.cpp --- a/llvm/lib/Target/DirectX/PointerTypeAnalysis.cpp +++ b/llvm/lib/Target/DirectX/PointerTypeAnalysis.cpp @@ -70,7 +70,7 @@ RetTy = nullptr; for (const auto &B : F) { for (const auto &I : B) { - if (const auto *RetInst = dyn_cast_or_null(&I)) { + if (const auto *RetInst = dyn_cast_if_present(&I)) { Type *NewRetTy = classifyPointerType(RetInst->getReturnValue()); if (!RetTy) RetTy = NewRetTy; diff --git a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp --- a/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp +++ b/llvm/lib/Target/Hexagon/HexagonFrameLowering.cpp @@ -1549,7 +1549,7 @@ SmallVector new_memops; for (MachineMemOperand *MMO : memops) { auto *PV = MMO->getPseudoValue(); - if (auto *FS = dyn_cast_or_null(PV)) { + if (auto *FS = dyn_cast_if_present(PV)) { int FI = FS->getFrameIndex(); if (DealignSlots.count(FI)) { auto *NewMMO = MF.getMachineMemOperand( diff --git a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp --- a/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp +++ b/llvm/lib/Target/Hexagon/HexagonISelLowering.cpp @@ -3608,8 +3608,8 @@ if (BO.first.getOpcode() == HexagonISD::CONST32_GP) return false; if (GlobalAddressSDNode *GA = dyn_cast(BO.first)) { - auto &HTM = static_cast(getTargetMachine()); - const auto *GO = dyn_cast_or_null(GA->getGlobal()); + auto &HTM = static_cast(getTargetMachine()); + const auto *GO = dyn_cast_if_present(GA->getGlobal()); return !GO || !HTM.getObjFileLowering()->isGlobalInSmallSection(GO, HTM); } return true; diff --git a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp --- a/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp +++ b/llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp @@ -1865,7 +1865,7 @@ continue; Simplifier::Context C(SI); Value *T = PostSimp.simplify(C); - SelectInst *SelI = dyn_cast_or_null(T); + SelectInst *SelI = dyn_cast_if_present(T); if (SelI != SI) { Value *NewSel = C.materialize(LoopB, SI->getIterator()); SI->replaceAllUsesWith(NewSel); diff --git a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp --- a/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp +++ b/llvm/lib/Target/LoongArch/LoongArchTargetMachine.cpp @@ -75,7 +75,7 @@ // function that reside in TargetOptions. resetTargetOptions(F); auto ABIName = Options.MCOptions.getABIName(); - if (const MDString *ModuleTargetABI = dyn_cast_or_null( + if (const MDString *ModuleTargetABI = dyn_cast_if_present( F.getParent()->getModuleFlag("target-abi"))) { auto TargetABI = LoongArchABI::getTargetABI(ABIName); if (TargetABI != LoongArchABI::ABI_Unknown && diff --git a/llvm/lib/Target/M68k/M68kISelDAGToDAG.cpp b/llvm/lib/Target/M68k/M68kISelDAGToDAG.cpp --- a/llvm/lib/Target/M68k/M68kISelDAGToDAG.cpp +++ b/llvm/lib/Target/M68k/M68kISelDAGToDAG.cpp @@ -134,7 +134,7 @@ bool isPCRelative() const { if (BaseType != Base::RegBase) return false; - if (auto *RegNode = dyn_cast_or_null(BaseReg.getNode())) + if (auto *RegNode = dyn_cast_if_present(BaseReg.getNode())) return RegNode->getReg() == M68k::PC; return false; } diff --git a/llvm/lib/Target/M68k/M68kSubtarget.cpp b/llvm/lib/Target/M68k/M68kSubtarget.cpp --- a/llvm/lib/Target/M68k/M68kSubtarget.cpp +++ b/llvm/lib/Target/M68k/M68kSubtarget.cpp @@ -248,7 +248,7 @@ // If the function is marked as non-lazy, generate an indirect call // which loads from the GOT directly. This avoids run-time overhead // at the cost of eager binding. - auto *F = dyn_cast_or_null(GV); + auto *F = dyn_cast_if_present(GV); if (F && F->hasFnAttribute(Attribute::NonLazyBind)) { return M68kII::MO_GOTPCREL; } diff --git a/llvm/lib/Target/Mips/MipsISelLowering.cpp b/llvm/lib/Target/Mips/MipsISelLowering.cpp --- a/llvm/lib/Target/Mips/MipsISelLowering.cpp +++ b/llvm/lib/Target/Mips/MipsISelLowering.cpp @@ -3122,7 +3122,7 @@ const SDValue TargetAddr = Node->getOperand(0).getOperand(1); StringRef Sym; if (const GlobalAddressSDNode *G = - dyn_cast_or_null(TargetAddr)) { + dyn_cast_if_present(TargetAddr)) { // We must not emit the R_MIPS_JALR relocation against data symbols // since this will cause run-time crashes if the linker replaces the // call instruction with a relative branch to the data symbol. @@ -3132,9 +3132,9 @@ return; } Sym = G->getGlobal()->getName(); - } - else if (const ExternalSymbolSDNode *ES = - dyn_cast_or_null(TargetAddr)) { + } else if (const ExternalSymbolSDNode *ES = + dyn_cast_if_present( + TargetAddr)) { Sym = ES->getSymbol(); } @@ -3178,7 +3178,7 @@ MipsCCState::getSpecialCallingConvForCallee(Callee.getNode(), Subtarget)); const ExternalSymbolSDNode *ES = - dyn_cast_or_null(Callee.getNode()); + dyn_cast_if_present(Callee.getNode()); // There is one case where CALLSEQ_START..CALLSEQ_END can be nested, which // is during the lowering of a call with a byval argument which produces @@ -3505,7 +3505,7 @@ *DAG.getContext()); const ExternalSymbolSDNode *ES = - dyn_cast_or_null(CLI.Callee.getNode()); + dyn_cast_if_present(CLI.Callee.getNode()); CCInfo.AnalyzeCallResult(Ins, RetCC_Mips, CLI.RetTy, ES ? ES->getSymbol() : nullptr); diff --git a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp --- a/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp +++ b/llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp @@ -1419,7 +1419,7 @@ void PPCLinuxAsmPrinter::emitGNUAttributes(Module &M) { // Emit float ABI into GNU attribute Metadata *MD = M.getModuleFlag("float-abi"); - MDString *FloatABI = dyn_cast_or_null(MD); + MDString *FloatABI = dyn_cast_if_present(MD); if (!FloatABI) return; StringRef flt = FloatABI->getString(); diff --git a/llvm/lib/Target/PowerPC/PPCFastISel.cpp b/llvm/lib/Target/PowerPC/PPCFastISel.cpp --- a/llvm/lib/Target/PowerPC/PPCFastISel.cpp +++ b/llvm/lib/Target/PowerPC/PPCFastISel.cpp @@ -2076,7 +2076,7 @@ // If the global has the toc-data attribute then fallback to DAG-ISEL. if (TM.getTargetTriple().isOSAIX()) - if (const GlobalVariable *Var = dyn_cast_or_null(GV)) + if (const GlobalVariable *Var = dyn_cast_if_present(GV)) if (Var->hasAttribute("toc-data")) return false; diff --git a/llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp b/llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp --- a/llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp +++ b/llvm/lib/Target/PowerPC/PPCGenScalarMASSEntries.cpp @@ -128,7 +128,7 @@ TheUsers.push_back(User); for (auto *User : TheUsers) - if (auto *CI = dyn_cast_or_null(User)) { + if (auto *CI = dyn_cast_if_present(User)) { if (isCandidateSafeToLower(*CI)) Changed |= createScalarMASSCall(Iter->second, *CI, Func); } diff --git a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp --- a/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelDAGToDAG.cpp @@ -504,7 +504,8 @@ if (!GA) return false; - const GlobalVariable *GV = dyn_cast_or_null(GA->getGlobal()); + const GlobalVariable *GV = + dyn_cast_if_present(GA->getGlobal()); if (!GV) return false; diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp --- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp @@ -5332,7 +5332,7 @@ // ExternalSymbol's, then we pick up the user-declared version. const Module *Mod = DAG.getMachineFunction().getFunction().getParent(); if (const Function *F = - dyn_cast_or_null(Mod->getNamedValue(SymName))) + dyn_cast_if_present(Mod->getNamedValue(SymName))) return getAIXFuncEntryPointSymbolSDNode(F); // On AIX, direct function calls reference the symbol for the function's diff --git a/llvm/lib/Target/PowerPC/PPCLowerMASSVEntries.cpp b/llvm/lib/Target/PowerPC/PPCLowerMASSVEntries.cpp --- a/llvm/lib/Target/PowerPC/PPCLowerMASSVEntries.cpp +++ b/llvm/lib/Target/PowerPC/PPCLowerMASSVEntries.cpp @@ -108,7 +108,8 @@ return false; if (Constant *Exp = dyn_cast(CI->getArgOperand(1))) - if (ConstantFP *CFP = dyn_cast_or_null(Exp->getSplatValue())) { + if (ConstantFP *CFP = + dyn_cast_if_present(Exp->getSplatValue())) { // If the argument is 0.75 or 0.25 it is cheaper to turn it into pow // intrinsic so that it could be optimzed as sequence of sqrt's. if (!CI->hasNoInfs() || !CI->hasApproxFunc()) diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp --- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp +++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMCExpr.cpp @@ -57,14 +57,15 @@ return nullptr; const MCSymbol *AUIPCSymbol = &AUIPCSRE->getSymbol(); - const auto *DF = dyn_cast_or_null(AUIPCSymbol->getFragment()); + const auto *DF = + dyn_cast_if_present(AUIPCSymbol->getFragment()); if (!DF) return nullptr; uint64_t Offset = AUIPCSymbol->getOffset(); if (DF->getContents().size() == Offset) { - DF = dyn_cast_or_null(DF->getNextNode()); + DF = dyn_cast_if_present(DF->getNextNode()); if (!DF) return nullptr; Offset = 0; diff --git a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp --- a/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp +++ b/llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp @@ -204,7 +204,7 @@ RISCVTargetStreamer &RTS = static_cast(*OutStreamer->getTargetStreamer()); if (const MDString *ModuleTargetABI = - dyn_cast_or_null(M.getModuleFlag("target-abi"))) + dyn_cast_if_present(M.getModuleFlag("target-abi"))) RTS.setTargetABI(RISCVABI::getTargetABI(ModuleTargetABI->getString())); if (TM.getTargetTriple().isOSBinFormatELF()) emitAttributes(); diff --git a/llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp b/llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp --- a/llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVGatherScatterLowering.cpp @@ -107,14 +107,14 @@ unsigned NumElts = cast(StartC->getType())->getNumElements(); // Check that the start value is a strided constant. - auto *StartVal = - dyn_cast_or_null(StartC->getAggregateElement((unsigned)0)); + auto *StartVal = dyn_cast_if_present( + StartC->getAggregateElement((unsigned)0)); if (!StartVal) return std::make_pair(nullptr, nullptr); APInt StrideVal(StartVal->getValue().getBitWidth(), 0); ConstantInt *Prev = StartVal; for (unsigned i = 1; i != NumElts; ++i) { - auto *C = dyn_cast_or_null(StartC->getAggregateElement(i)); + auto *C = dyn_cast_if_present(StartC->getAggregateElement(i)); if (!C) return std::make_pair(nullptr, nullptr); @@ -503,7 +503,7 @@ // Remove any dead phis. while (!MaybeDeadPHIs.empty()) { - if (auto *Phi = dyn_cast_or_null(MaybeDeadPHIs.pop_back_val())) + if (auto *Phi = dyn_cast_if_present(MaybeDeadPHIs.pop_back_val())) RecursivelyDeleteDeadPHINode(Phi); } diff --git a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp --- a/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp +++ b/llvm/lib/Target/RISCV/RISCVTargetMachine.cpp @@ -106,7 +106,7 @@ // function that reside in TargetOptions. resetTargetOptions(F); auto ABIName = Options.MCOptions.getABIName(); - if (const MDString *ModuleTargetABI = dyn_cast_or_null( + if (const MDString *ModuleTargetABI = dyn_cast_if_present( F.getParent()->getModuleFlag("target-abi"))) { auto TargetABI = RISCVABI::getTargetABI(ABIName); if (TargetABI != RISCVABI::ABI_Unknown && diff --git a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp --- a/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp +++ b/llvm/lib/Target/SPIRV/SPIRVCallLowering.cpp @@ -276,7 +276,7 @@ // be sure to emit its type and function declaration here. It will be hoisted // globally later. if (Info.Callee.isGlobal()) { - CF = dyn_cast_or_null(Info.Callee.getGlobal()); + CF = dyn_cast_if_present(Info.Callee.getGlobal()); // TODO: support constexpr casts and indirect calls. if (CF == nullptr) return false; diff --git a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp --- a/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp +++ b/llvm/lib/Target/SystemZ/SystemZTargetTransformInfo.cpp @@ -456,7 +456,7 @@ if (const Constant *C = dyn_cast(Args[1])) { const ConstantInt *CVal = (C->getType()->isVectorTy() - ? dyn_cast_or_null(C->getSplatValue()) + ? dyn_cast_if_present(C->getSplatValue()) : dyn_cast(C)); if (CVal && (CVal->getValue().isPowerOf2() || CVal->getValue().isNegatedPowerOf2())) diff --git a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp --- a/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp +++ b/llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp @@ -424,7 +424,7 @@ // it, returns true. // - Otherwise returns false. // - If the fragment is not a DataFragment, returns false. - if (auto *DF = dyn_cast_or_null(F)) + if (auto *DF = dyn_cast_if_present(F)) return DF != PrevInstPosition.first || DF->getContents().size() != PrevInstPosition.second; @@ -562,7 +562,7 @@ PrevInst = Inst; MCFragment *CF = OS.getCurrentFragment(); PrevInstPosition = std::make_pair(CF, getSizeForInstFragment(CF)); - if (auto *F = dyn_cast_or_null(CF)) + if (auto *F = dyn_cast_if_present(CF)) F->setAllowAutoPadding(CanPadInst); if (!canPadBranches(OS)) diff --git a/llvm/lib/Target/X86/X86FrameLowering.cpp b/llvm/lib/Target/X86/X86FrameLowering.cpp --- a/llvm/lib/Target/X86/X86FrameLowering.cpp +++ b/llvm/lib/Target/X86/X86FrameLowering.cpp @@ -3148,7 +3148,8 @@ MDString *NodeName = dyn_cast(Node->getOperand(0)); ValueAsMetadata *NodeVal = dyn_cast(Node->getOperand(1)); if (!NodeName || !NodeVal) continue; - ConstantInt *ValConst = dyn_cast_or_null(NodeVal->getValue()); + ConstantInt *ValConst = + dyn_cast_if_present(NodeVal->getValue()); if (ValConst && NodeName->getString() == LiteralName) { return ValConst->getZExtValue(); } diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp --- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -93,9 +93,10 @@ /// Return true if this addressing mode is already RIP-relative. bool isRIPRelative() const { - if (BaseType != RegBase) return false; + if (BaseType != RegBase) + return false; if (RegisterSDNode *RegNode = - dyn_cast_or_null(Base_Reg.getNode())) + dyn_cast_if_present(Base_Reg.getNode())) return RegNode->getReg() == X86::RIP; return false; } @@ -385,8 +386,8 @@ // Don't count if the other operand is SP. RegisterSDNode *RegNode; if (OtherOp->getOpcode() == ISD::CopyFromReg && - (RegNode = dyn_cast_or_null( - OtherOp->getOperand(1).getNode()))) + (RegNode = dyn_cast_if_present( + OtherOp->getOperand(1).getNode()))) if ((RegNode->getReg() == X86::ESP) || (RegNode->getReg() == X86::RSP)) continue; diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -27392,7 +27392,7 @@ SDValue FnOp = Op.getOperand(1); SDValue IncomingFPOp = Op.getOperand(2); GlobalAddressSDNode *GSD = dyn_cast(FnOp); - auto *Fn = dyn_cast_or_null(GSD ? GSD->getGlobal() : nullptr); + auto *Fn = dyn_cast_if_present(GSD ? GSD->getGlobal() : nullptr); if (!Fn) report_fatal_error( "llvm.eh.recoverfp must take a function as the first argument"); diff --git a/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp b/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp --- a/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp +++ b/llvm/lib/Target/X86/X86InstCombineIntrinsic.cpp @@ -378,7 +378,7 @@ continue; } - auto *COp = dyn_cast_or_null(CElt); + auto *COp = dyn_cast_if_present(CElt); if (!COp) return nullptr; @@ -627,9 +627,9 @@ // See if we're dealing with constant values. auto *C0 = dyn_cast(Op0); - auto *CI0 = - C0 ? dyn_cast_or_null(C0->getAggregateElement((unsigned)0)) - : nullptr; + auto *CI0 = C0 ? dyn_cast_if_present( + C0->getAggregateElement((unsigned)0)) + : nullptr; // Attempt to constant fold. if (CILength && CIIndex) { @@ -761,12 +761,12 @@ // See if we're dealing with constant values. auto *C0 = dyn_cast(Op0); auto *C1 = dyn_cast(Op1); - auto *CI00 = - C0 ? dyn_cast_or_null(C0->getAggregateElement((unsigned)0)) - : nullptr; - auto *CI10 = - C1 ? dyn_cast_or_null(C1->getAggregateElement((unsigned)0)) - : nullptr; + auto *CI00 = C0 ? dyn_cast_if_present( + C0->getAggregateElement((unsigned)0)) + : nullptr; + auto *CI10 = C1 ? dyn_cast_if_present( + C1->getAggregateElement((unsigned)0)) + : nullptr; // Constant Fold - insert bottom Length bits starting at the Index'th bit. if (CI00 && CI10) { @@ -1469,12 +1469,12 @@ // See if we're dealing with constant values. auto *C1 = dyn_cast(Op1); - auto *CILength = - C1 ? dyn_cast_or_null(C1->getAggregateElement((unsigned)0)) - : nullptr; - auto *CIIndex = - C1 ? dyn_cast_or_null(C1->getAggregateElement((unsigned)1)) - : nullptr; + auto *CILength = C1 ? dyn_cast_if_present( + C1->getAggregateElement((unsigned)0)) + : nullptr; + auto *CIIndex = C1 ? dyn_cast_if_present( + C1->getAggregateElement((unsigned)1)) + : nullptr; // Attempt to simplify to a constant, shuffle vector or EXTRQI call. if (Value *V = simplifyX86extrq(II, Op0, CILength, CIIndex, IC.Builder)) { @@ -1534,9 +1534,9 @@ // See if we're dealing with constant values. auto *C1 = dyn_cast(Op1); - auto *CI11 = - C1 ? dyn_cast_or_null(C1->getAggregateElement((unsigned)1)) - : nullptr; + auto *CI11 = C1 ? dyn_cast_if_present( + C1->getAggregateElement((unsigned)1)) + : nullptr; // Attempt to simplify to a constant, shuffle vector or INSERTQI call. if (CI11) { diff --git a/llvm/lib/Target/X86/X86Subtarget.cpp b/llvm/lib/Target/X86/X86Subtarget.cpp --- a/llvm/lib/Target/X86/X86Subtarget.cpp +++ b/llvm/lib/Target/X86/X86Subtarget.cpp @@ -213,7 +213,7 @@ return X86II::MO_COFFSTUB; } - const Function *F = dyn_cast_or_null(GV); + const Function *F = dyn_cast_if_present(GV); if (isTargetELF()) { if (is64Bit() && F && (CallingConv::X86_RegCall == F->getCallingConv())) diff --git a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp --- a/llvm/lib/Target/X86/X86TargetTransformInfo.cpp +++ b/llvm/lib/Target/X86/X86TargetTransformInfo.cpp @@ -4192,7 +4192,7 @@ const Instruction *I) { // TODO: Handle other cost kinds. if (CostKind != TTI::TCK_RecipThroughput) { - if (auto *SI = dyn_cast_or_null(I)) { + if (auto *SI = dyn_cast_if_present(I)) { // Store instruction with index and scale costs 2 Uops. // Check the preceding GEP to identify non-const indices. if (auto *GEP = dyn_cast(SI->getPointerOperand())) { diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -1956,7 +1956,7 @@ // Special case for CleanupPad: all EH blocks must have the same unwind edge // so we need to create an additional "dispatcher" block. if (auto *CleanupPad = - dyn_cast_or_null(BB.getFirstNonPHI())) { + dyn_cast_if_present(BB.getFirstNonPHI())) { SmallVector Preds(predecessors(&BB)); for (BasicBlock *Pred : Preds) { if (CatchSwitchInst *CS = @@ -1973,7 +1973,7 @@ LandingPadInst *LandingPad = nullptr; PHINode *ReplPHI = nullptr; - if ((LandingPad = dyn_cast_or_null(BB.getFirstNonPHI()))) { + if ((LandingPad = dyn_cast_if_present(BB.getFirstNonPHI()))) { // ehAwareSplitEdge will clone the LandingPad in all the edge blocks. // We replace the original landing pad with a PHINode that will collect the // results from all of them. @@ -2576,7 +2576,7 @@ Value *Storage = DVI->getVariableLocationOp(0); Value *OriginalStorage = Storage; - while (auto *Inst = dyn_cast_or_null(Storage)) { + while (auto *Inst = dyn_cast_if_present(Storage)) { if (auto *LdInst = dyn_cast(Inst)) { Storage = LdInst->getOperand(0); // FIXME: This is a heuristic that works around the fact that diff --git a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp --- a/llvm/lib/Transforms/Coroutines/CoroSplit.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroSplit.cpp @@ -1313,7 +1313,7 @@ // Both operands of the CmpInst are Constant. So that we could evaluate // it immediately to get the destination. auto *ConstResult = - dyn_cast_or_null(ConstantFoldCompareInstOperands( + dyn_cast_if_present(ConstantFoldCompareInstOperands( CondCmp->getPredicate(), Cond0, Cond1, DL)); if (!ConstResult) return false; diff --git a/llvm/lib/Transforms/IPO/Annotation2Metadata.cpp b/llvm/lib/Transforms/IPO/Annotation2Metadata.cpp --- a/llvm/lib/Transforms/IPO/Annotation2Metadata.cpp +++ b/llvm/lib/Transforms/IPO/Annotation2Metadata.cpp @@ -33,7 +33,7 @@ return false; auto *Annotations = M.getGlobalVariable("llvm.global.annotations"); - auto *C = dyn_cast_or_null(Annotations); + auto *C = dyn_cast_if_present(Annotations); if (!C || C->getNumOperands() != 1) return false; diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp --- a/llvm/lib/Transforms/IPO/Attributor.cpp +++ b/llvm/lib/Transforms/IPO/Attributor.cpp @@ -231,7 +231,7 @@ return nullptr; if (!GV->hasInitializer()) return UndefValue::get(&Ty); - return dyn_cast_or_null(getWithType(*GV->getInitializer(), Ty)); + return dyn_cast_if_present(getWithType(*GV->getInitializer(), Ty)); } bool AA::isValidInScope(const Value &V, const Function *Scope) { @@ -1074,7 +1074,7 @@ UsedAssumedInformation)) { if (Values.empty()) return llvm::None; - if (auto *C = dyn_cast_or_null( + if (auto *C = dyn_cast_if_present( AAPotentialValues::getSingleValue(*this, AA, IRP, Values))) return C; } @@ -2010,7 +2010,7 @@ // Do not replace uses in returns if the value is a must-tail call we will // not delete. - if (auto *RI = dyn_cast_or_null(I)) { + if (auto *RI = dyn_cast_if_present(I)) { if (auto *CI = dyn_cast(OldV->stripPointerCasts())) if (CI->isMustTailCall() && !ToBeDeletedInsts.count(CI)) return; @@ -2022,7 +2022,7 @@ } // Do not perform call graph altering changes outside the SCC. - if (auto *CB = dyn_cast_or_null(I)) + if (auto *CB = dyn_cast_if_present(I)) if (CB->isCallee(U)) return; @@ -2080,7 +2080,7 @@ } for (const auto &V : InvokeWithDeadSuccessor) - if (InvokeInst *II = dyn_cast_or_null(V)) { + if (InvokeInst *II = dyn_cast_if_present(V)) { assert(isRunOn(*II->getFunction()) && "Cannot replace an invoke outside the current SCC!"); bool UnwindBBIsDead = II->hasFnAttr(Attribute::NoUnwind); @@ -2113,7 +2113,7 @@ ConstantFoldTerminator(I->getParent()); } for (const auto &V : ToBeChangedToUnreachableInsts) - if (Instruction *I = dyn_cast_or_null(V)) { + if (Instruction *I = dyn_cast_if_present(V)) { LLVM_DEBUG(dbgs() << "[Attributor] Change to unreachable: " << *I << "\n"); assert(isRunOn(*I->getFunction()) && @@ -2123,7 +2123,7 @@ } for (const auto &V : ToBeDeletedInsts) { - if (Instruction *I = dyn_cast_or_null(V)) { + if (Instruction *I = dyn_cast_if_present(V)) { if (auto *CB = dyn_cast(I)) { assert(isRunOn(*I->getFunction()) && "Cannot delete an instruction outside the current SCC!"); diff --git a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp --- a/llvm/lib/Transforms/IPO/AttributorAttributes.cpp +++ b/llvm/lib/Transforms/IPO/AttributorAttributes.cpp @@ -1489,7 +1489,7 @@ // We handle memory intrinsics explicitly, at least the first (= // destination) and second (=source) arguments as we know how they are // accessed. - if (auto *MI = dyn_cast_or_null(getCtxI())) { + if (auto *MI = dyn_cast_if_present(getCtxI())) { ConstantInt *Length = dyn_cast(MI->getLength()); int64_t LengthVal = OffsetAndSize::Unknown; if (Length) @@ -3532,7 +3532,7 @@ /// See AbstractAttribute::updateImpl(...). ChangeStatus updateImpl(Attributor &A) override { Instruction *I = dyn_cast(&getAssociatedValue()); - if (auto *SI = dyn_cast_or_null(I)) { + if (auto *SI = dyn_cast_if_present(I)) { if (!isDeadStore(A, *SI)) return indicatePessimisticFixpoint(); } else { @@ -5495,7 +5495,7 @@ // Check if we need to adjust the insertion point to make sure the IR is // valid. Instruction *IP = dyn_cast(U.getUser()); - if (auto *PHI = dyn_cast_or_null(IP)) + if (auto *PHI = dyn_cast_if_present(IP)) IP = PHI->getIncomingBlock(U)->getTerminator(); if (auto *NewV = manifestReplacementValue(A, IP)) { LLVM_DEBUG(dbgs() << "[ValueSimplify] " << getAssociatedValue() @@ -6040,7 +6040,7 @@ A.getAssumedConstant(V, AA, UsedAssumedInformation); if (!SimpleV) return APInt(64, 0); - if (auto *CI = dyn_cast_or_null(SimpleV.value())) + if (auto *CI = dyn_cast_if_present(SimpleV.value())) return CI->getValue(); return llvm::None; } @@ -9850,7 +9850,7 @@ Function *AnchorScope) const { IRPosition ValIRP = IRPosition::value(V); - if (auto *CB = dyn_cast_or_null(CtxI)) { + if (auto *CB = dyn_cast_if_present(CtxI)) { for (const auto &U : CB->args()) { if (U.get() != &V) continue; @@ -10092,7 +10092,7 @@ bool NoValueYet = !C.has_value(); if (NoValueYet || isa_and_nonnull(*C)) return true; - if (auto *CI = dyn_cast_or_null(*C)) { + if (auto *CI = dyn_cast_if_present(*C)) { if (CI->isZero()) Worklist.push_back({{*SI.getFalseValue(), CtxI}, II.S}); else diff --git a/llvm/lib/Transforms/IPO/CrossDSOCFI.cpp b/llvm/lib/Transforms/IPO/CrossDSOCFI.cpp --- a/llvm/lib/Transforms/IPO/CrossDSOCFI.cpp +++ b/llvm/lib/Transforms/IPO/CrossDSOCFI.cpp @@ -63,7 +63,7 @@ auto TM = dyn_cast(MD->getOperand(1)); if (!TM) return nullptr; - auto C = dyn_cast_or_null(TM->getValue()); + auto C = dyn_cast_if_present(TM->getValue()); if (!C) return nullptr; // We are looking for i64 constants. if (C->getBitWidth() != 64) return nullptr; diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -634,7 +634,7 @@ // because readonly and writeonly vars are internalized in their // source modules. auto IsReadOrWriteOnlyVar = [&](StringRef ModulePath, const ValueInfo &VI) { - auto *GVS = dyn_cast_or_null( + auto *GVS = dyn_cast_if_present( Index.findSummaryInModule(VI, ModulePath)); return GVS && (Index.isReadOnly(GVS) || Index.isWriteOnly(GVS)); }; @@ -1127,7 +1127,7 @@ // Remove declarations from comdats, including available_externally // as this is a declaration for the linker, and will be dropped eventually. // It is illegal for comdats to contain declarations. - auto *GO = dyn_cast_or_null(&GV); + auto *GO = dyn_cast_if_present(&GV); if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) GO->setComdat(nullptr); }; diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp --- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp +++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp @@ -161,7 +161,7 @@ // Bail if there is any other unknown usage. return nullptr; } - return dyn_cast_or_null(StoreValue); + return dyn_cast_if_present(StoreValue); } // A constant stack value is an AllocaInst that has a single constant @@ -566,7 +566,7 @@ InstructionCost getUserBonus(User *U, llvm::TargetTransformInfo &TTI, LoopInfo &LI) { - auto *I = dyn_cast_or_null(U); + auto *I = dyn_cast_if_present(U); // If not an instruction we do not know how to evaluate. // Keep minimum possible cost for now so that it doesnt affect // specialization. diff --git a/llvm/lib/Transforms/IPO/GlobalSplit.cpp b/llvm/lib/Transforms/IPO/GlobalSplit.cpp --- a/llvm/lib/Transforms/IPO/GlobalSplit.cpp +++ b/llvm/lib/Transforms/IPO/GlobalSplit.cpp @@ -45,7 +45,7 @@ return false; // We currently only know how to split ConstantStructs. - auto *Init = dyn_cast_or_null(GV.getInitializer()); + auto *Init = dyn_cast_if_present(GV.getInitializer()); if (!Init) return false; diff --git a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp --- a/llvm/lib/Transforms/IPO/HotColdSplitting.cpp +++ b/llvm/lib/Transforms/IPO/HotColdSplitting.cpp @@ -121,7 +121,7 @@ // preceded by a call to a (possibly warm) noreturn call (e.g. longjmp). if (blockEndsInUnreachable(BB)) { if (auto *CI = - dyn_cast_or_null(BB.getTerminator()->getPrevNode())) + dyn_cast_if_present(BB.getTerminator()->getPrevNode())) if (CI->hasFnAttr(Attribute::NoReturn)) return false; return true; diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp --- a/llvm/lib/Transforms/IPO/IROutliner.cpp +++ b/llvm/lib/Transforms/IPO/IROutliner.cpp @@ -733,7 +733,7 @@ // several locations. auto updateLoopInfoLoc = [&New](Metadata *MD) -> Metadata * { if (DISubprogram *SP = New.getSubprogram()) - if (auto *Loc = dyn_cast_or_null(MD)) + if (auto *Loc = dyn_cast_if_present(MD)) return DILocation::get(New.getContext(), Loc->getLine(), Loc->getColumn(), SP, nullptr); return MD; diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp --- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp +++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp @@ -582,7 +582,7 @@ if (DILocVar->isParameter()) { LLVM_DEBUG(dbgs() << " Parameter: "); LLVM_DEBUG(DILocVar->print(dbgs())); - AllocaInst *AI = dyn_cast_or_null(DDI->getAddress()); + AllocaInst *AI = dyn_cast_if_present(DDI->getAddress()); if (AI) { LLVM_DEBUG(dbgs() << " Processing alloca users: "); LLVM_DEBUG(dbgs() << "\n"); diff --git a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp --- a/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp +++ b/llvm/lib/Transforms/IPO/ThinLTOBitcodeWriter.cpp @@ -280,7 +280,8 @@ // reference the global's section directly. auto HasTypeMetadata = [](const GlobalObject *GO) { if (MDNode *MD = GO->getMetadata(LLVMContext::MD_associated)) - if (auto *AssocVM = dyn_cast_or_null(MD->getOperand(0))) + if (auto *AssocVM = + dyn_cast_if_present(MD->getOperand(0))) if (auto *AssocGO = dyn_cast(AssocVM->getValue())) if (AssocGO->hasMetadata(LLVMContext::MD_type)) return true; @@ -333,7 +334,7 @@ if (auto *F = dyn_cast(GV)) return EligibleVirtualFns.count(F); if (auto *GVar = - dyn_cast_or_null(GV->getAliaseeObject())) + dyn_cast_if_present(GV->getAliaseeObject())) return HasTypeMetadata(GVar); return false; })); @@ -362,7 +363,8 @@ // Remove all globals with type metadata, globals with comdats that live in // MergedM, and aliases pointing to such globals from the thin LTO module. filterModule(&M, [&](const GlobalValue *GV) { - if (auto *GVar = dyn_cast_or_null(GV->getAliaseeObject())) + if (auto *GVar = + dyn_cast_if_present(GV->getAliaseeObject())) if (HasTypeMetadata(GVar)) return false; if (const auto *C = GV->getComdat()) diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -2017,7 +2017,7 @@ // Handle mul by one: if (Constant *CV1 = dyn_cast(Arg1)) if (ConstantInt *Splat = - dyn_cast_or_null(CV1->getSplatValue())) + dyn_cast_if_present(CV1->getSplatValue())) if (Splat->isOne()) return CastInst::CreateIntegerCast(Arg0, II->getType(), /*isSigned=*/!Zext); @@ -2740,7 +2740,8 @@ if (NFI && isIdenticalOrStrongerFence(NFI, &FI)) return eraseInstFromFunction(FI); - if (auto *PFI = dyn_cast_or_null(FI.getPrevNonDebugInstruction())) + if (auto *PFI = + dyn_cast_if_present(FI.getPrevNonDebugInstruction())) if (isIdenticalOrStrongerFence(PFI, &FI)) return eraseInstFromFunction(FI); return nullptr; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp @@ -1668,7 +1668,7 @@ if (isa(CV->getAggregateElement(i))) continue; - auto *CFP = dyn_cast_or_null(CV->getAggregateElement(i)); + auto *CFP = dyn_cast_if_present(CV->getAggregateElement(i)); if (!CFP) return nullptr; diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3953,7 +3953,7 @@ return nullptr; // Can we fold (XShAmt+YShAmt) ? - auto *NewShAmt = dyn_cast_or_null( + auto *NewShAmt = dyn_cast_if_present( simplifyAddInst(XShAmt, YShAmt, /*isNSW=*/false, /*isNUW=*/false, SQ.getWithInstruction(&I))); if (!NewShAmt) @@ -5461,7 +5461,7 @@ const BasicBlock *BB = SI->getParent(); if (!BB) return false; - auto *BI = dyn_cast_or_null(BB->getTerminator()); + auto *BI = dyn_cast_if_present(BB->getTerminator()); if (!BI || BI->getNumSuccessors() != 2) return false; auto *IC = dyn_cast(BI->getCondition()); diff --git a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineShifts.cpp @@ -106,7 +106,7 @@ return nullptr; // Can we fold (ShAmt0+ShAmt1) ? - auto *NewShAmt = dyn_cast_or_null( + auto *NewShAmt = dyn_cast_if_present( simplifyAddInst(ShAmt0, ShAmt1, /*isNSW=*/false, /*isNUW=*/false, SQ.getWithInstruction(Sh0))); if (!NewShAmt) @@ -231,7 +231,7 @@ return nullptr; // Can we simplify (MaskShAmt+ShiftShAmt) ? - auto *SumOfShAmts = dyn_cast_or_null(simplifyAddInst( + auto *SumOfShAmts = dyn_cast_if_present(simplifyAddInst( MaskShAmt, ShiftShAmt, /*IsNSW=*/false, /*IsNUW=*/false, Q)); if (!SumOfShAmts) return nullptr; // Did not simplify. @@ -263,7 +263,7 @@ return nullptr; // Can we simplify (ShiftShAmt-MaskShAmt) ? - auto *ShAmtsDiff = dyn_cast_or_null(simplifySubInst( + auto *ShAmtsDiff = dyn_cast_if_present(simplifySubInst( ShiftShAmt, MaskShAmt, /*IsNSW=*/false, /*IsNUW=*/false, Q)); if (!ShAmtsDiff) return nullptr; // Did not simplify. diff --git a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineVectorOps.cpp @@ -945,7 +945,7 @@ // FIXME: deal with multiple levels of PHI indirection? // Did we find an extraction? - auto *EVI = dyn_cast_or_null(Elt); + auto *EVI = dyn_cast_if_present(Elt); if (!EVI) return NotFound; diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -4370,7 +4370,7 @@ return; auto Track = [](Metadata *ScopeList, auto &Container) { - const auto *MDScopeList = dyn_cast_or_null(ScopeList); + const auto *MDScopeList = dyn_cast_if_present(ScopeList); if (!MDScopeList || !Container.insert(MDScopeList).second) return; for (const auto &MDOperand : MDScopeList->operands()) diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1257,7 +1257,7 @@ // Treat memory accesses to promotable allocas as non-interesting since they // will not cause memory violations. This greatly speeds up the instrumented // executable at -O0. - if (auto AI = dyn_cast_or_null(Ptr)) + if (auto AI = dyn_cast_if_present(Ptr)) if (ClSkipPromotableAllocas && !isInterestingAlloca(*AI)) return true; diff --git a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp --- a/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp +++ b/llvm/lib/Transforms/Instrumentation/BoundsChecking.cpp @@ -112,7 +112,7 @@ template static void insertBoundsCheck(Value *Or, BuilderTy &IRB, GetTrapBBT GetTrapBB) { // check if the comparison is always false - ConstantInt *C = dyn_cast_or_null(Or); + ConstantInt *C = dyn_cast_if_present(Or); if (C) { ++ChecksSkipped; // If non-zero, nothing to do. diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp --- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp @@ -180,7 +180,7 @@ Value *Addr = cast(Store)->getPointerOperand(); Type *Ty = LiveInValue->getType(); IRBuilder<> Builder(InsertPos); - if (auto *AddrInst = dyn_cast_or_null(Addr)) { + if (auto *AddrInst = dyn_cast_if_present(Addr)) { // If isRuntimeCounterRelocationEnabled() is true then the address of // the store instruction is computed with two instructions in // InstrProfiling::getCounterAddress(). We need to copy those @@ -760,7 +760,7 @@ } static uint64_t getIntModuleFlagOrZero(const Module &M, StringRef Flag) { - auto *MD = dyn_cast_or_null(M.getModuleFlag(Flag)); + auto *MD = dyn_cast_if_present(M.getModuleFlag(Flag)); if (!MD) return 0; diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp --- a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp @@ -509,7 +509,7 @@ // Create the variable for the profile file name. void createProfileFileNameVar(Module &M) { const MDString *MemProfFilename = - dyn_cast_or_null(M.getModuleFlag("MemProfProfileFilename")); + dyn_cast_if_present(M.getModuleFlag("MemProfProfileFilename")); if (!MemProfFilename) return; assert(!MemProfFilename->getString().empty() && diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -1826,10 +1826,10 @@ return; Origin = getOrigin(Val); } else { - Shadow = dyn_cast_or_null(getShadow(Val)); + Shadow = dyn_cast_if_present(getShadow(Val)); if (!Shadow) return; - Origin = dyn_cast_or_null(getOrigin(Val)); + Origin = dyn_cast_if_present(getOrigin(Val)); } insertShadowCheck(Shadow, Origin, OrigIns); } diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARC.h b/llvm/lib/Transforms/ObjCARC/ObjCARC.h --- a/llvm/lib/Transforms/ObjCARC/ObjCARC.h +++ b/llvm/lib/Transforms/ObjCARC/ObjCARC.h @@ -91,7 +91,7 @@ static inline MDString *getRVInstMarker(Module &M) { const char *MarkerKey = getRVMarkerModuleFlagStr(); - return dyn_cast_or_null(M.getModuleFlag(MarkerKey)); + return dyn_cast_if_present(M.getModuleFlag(MarkerKey)); } /// Create a call instruction with the correct funclet token. This should be diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp --- a/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCContract.cpp @@ -163,7 +163,7 @@ DependenceKind DK = Class == ARCInstKind::AutoreleaseRV ? RetainAutoreleaseRVDep : RetainAutoreleaseDep; - auto *Retain = dyn_cast_or_null( + auto *Retain = dyn_cast_if_present( findSingleDependency(DK, Arg, Autorelease->getParent(), Autorelease, PA)); if (!Retain || GetBasicARCInstKind(Retain) != ARCInstKind::Retain || diff --git a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp --- a/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp +++ b/llvm/lib/Transforms/ObjCARC/ObjCARCOpts.cpp @@ -2303,7 +2303,7 @@ static CallInst *HasSafePathToPredecessorCall(const Value *Arg, Instruction *Retain, ProvenanceAnalysis &PA) { - auto *Call = dyn_cast_or_null(findSingleDependency( + auto *Call = dyn_cast_if_present(findSingleDependency( CanChangeRetainCount, Arg, Retain->getParent(), Retain, PA)); // Check that the pointer is the return value of the call. @@ -2324,7 +2324,7 @@ FindPredecessorRetainWithSafePath(const Value *Arg, BasicBlock *BB, Instruction *Autorelease, ProvenanceAnalysis &PA) { - auto *Retain = dyn_cast_or_null( + auto *Retain = dyn_cast_if_present( findSingleDependency(CanChangeRetainCount, Arg, BB, Autorelease, PA)); // Check that we found a retain with the same argument. @@ -2344,7 +2344,7 @@ ReturnInst *Ret, ProvenanceAnalysis &PA) { SmallPtrSet DepInsts; - auto *Autorelease = dyn_cast_or_null( + auto *Autorelease = dyn_cast_if_present( findSingleDependency(NeedsPositiveRetainCount, Arg, BB, Ret, PA)); if (!Autorelease) diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -800,7 +800,7 @@ if (I.mayThrow() && !MA) ThrowingBlocks.insert(I.getParent()); - auto *MD = dyn_cast_or_null(MA); + auto *MD = dyn_cast_if_present(MA); if (MD && MemDefs.size() < MemorySSADefsPerBlockLimit && (getLocForWrite(&I) || isMemTerminatorInst(&I))) MemDefs.push_back(MD); diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp b/llvm/lib/Transforms/Scalar/GVN.cpp --- a/llvm/lib/Transforms/Scalar/GVN.cpp +++ b/llvm/lib/Transforms/Scalar/GVN.cpp @@ -1111,7 +1111,7 @@ Value *Address, Type *LoadTy, DominatorTree &DT, AAResults *AA) { - auto *Sel = dyn_cast_or_null(Address); + auto *Sel = dyn_cast_if_present(Address); if (!Sel || DepBB != Sel->getParent()) return None; diff --git a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp --- a/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/IndVarSimplify.cpp @@ -418,7 +418,7 @@ bool Changed = false; for (unsigned i = 0, e = PHIs.size(); i != e; ++i) - if (PHINode *PN = dyn_cast_or_null(&*PHIs[i])) + if (PHINode *PN = dyn_cast_if_present(&*PHIs[i])) Changed |= handleFloatingPointIV(L, PN); // If the loop previously had floating-point IV, ScalarEvolution @@ -2036,9 +2036,9 @@ while (!DeadInsts.empty()) { Value *V = DeadInsts.pop_back_val(); - if (PHINode *PHI = dyn_cast_or_null(V)) + if (PHINode *PHI = dyn_cast_if_present(V)) Changed |= RecursivelyDeleteDeadPHINode(PHI, TLI, MSSAU.get()); - else if (Instruction *Inst = dyn_cast_or_null(V)) + else if (Instruction *Inst = dyn_cast_if_present(V)) Changed |= RecursivelyDeleteTriviallyDeadInstructions(Inst, TLI, MSSAU.get()); } diff --git a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp --- a/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp +++ b/llvm/lib/Transforms/Scalar/InferAddressSpaces.cpp @@ -770,7 +770,7 @@ if (Instruction *I = dyn_cast(V)) { Value *NewV = cloneInstructionWithNewAddressSpace( I, NewAddrSpace, ValueWithNewAddrSpace, PredicatedAS, UndefUsesToFix); - if (Instruction *NewI = dyn_cast_or_null(NewV)) { + if (Instruction *NewI = dyn_cast_if_present(NewV)) { if (NewI->getParent() == nullptr) { NewI->insertBefore(I); NewI->takeName(I); diff --git a/llvm/lib/Transforms/Scalar/JumpThreading.cpp b/llvm/lib/Transforms/Scalar/JumpThreading.cpp --- a/llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ b/llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -2173,7 +2173,7 @@ // If PredPred ends with IndirectBrInst, we can't handle it. if (isa(P->getTerminator())) continue; - if (ConstantInt *CI = dyn_cast_or_null( + if (ConstantInt *CI = dyn_cast_if_present( evaluateOnPredecessorEdge(BB, P, Cond))) { if (CI->isZero()) { ZeroCount++; diff --git a/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp b/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp --- a/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp +++ b/llvm/lib/Transforms/Scalar/LoopInstSimplify.cpp @@ -132,7 +132,7 @@ } if (MSSAU) - if (Instruction *SimpleI = dyn_cast_or_null(V)) + if (Instruction *SimpleI = dyn_cast_if_present(V)) if (MemoryAccess *MA = MSSA->getMemoryAccess(&I)) if (MemoryAccess *ReplacementMA = MSSA->getMemoryAccess(SimpleI)) MA->replaceAllUsesWith(ReplacementMA); diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -2475,7 +2475,7 @@ A = SE.getSignExtendExpr(A, B->getType()); } if (const SCEVConstant *D = - dyn_cast_or_null(getExactSDiv(B, A, SE))) { + dyn_cast_if_present(getExactSDiv(B, A, SE))) { const ConstantInt *C = D->getValue(); // Stride of one or negative one can have reuse with non-addresses. if (C->isOne() || C->isMinusOne()) @@ -2485,7 +2485,8 @@ C->getValue().isMinSignedValue()) goto decline_post_inc; // Check for possible scaled-address reuse. - if (isAddressUse(TTI, UI->getUser(), UI->getOperandValToReplace())) { + if (isAddressUse(TTI, UI->getUser(), + UI->getOperandValToReplace())) { MemAccessTy AccessTy = getAccessType( TTI, UI->getUser(), UI->getOperandValToReplace()); int64_t Scale = C->getSExtValue(); @@ -2727,15 +2728,12 @@ else OldStride = SE.getSignExtendExpr(OldStride, NewStride->getType()); } - if (const SCEVConstant *Factor = - dyn_cast_or_null(getExactSDiv(NewStride, OldStride, - SE, true))) { + if (const SCEVConstant *Factor = dyn_cast_if_present( + getExactSDiv(NewStride, OldStride, SE, true))) { if (Factor->getAPInt().getMinSignedBits() <= 64 && !Factor->isZero()) Factors.insert(Factor->getAPInt().getSExtValue()); - } else if (const SCEVConstant *Factor = - dyn_cast_or_null(getExactSDiv(OldStride, - NewStride, - SE, true))) { + } else if (const SCEVConstant *Factor = dyn_cast_if_present( + getExactSDiv(OldStride, NewStride, SE, true))) { if (Factor->getAPInt().getMinSignedBits() <= 64 && !Factor->isZero()) Factors.insert(Factor->getAPInt().getSExtValue()); } diff --git a/llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp b/llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp --- a/llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp +++ b/llvm/lib/Transforms/Scalar/LowerConstantIntrinsics.cpp @@ -63,7 +63,7 @@ UnsimplifiedUsers.end()); for (auto &VH : Worklist) { - BranchInst *BI = dyn_cast_or_null(VH); + BranchInst *BI = dyn_cast_if_present(VH); if (!BI) continue; if (BI->isUnconditional()) diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp --- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp +++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp @@ -765,7 +765,7 @@ // have been done on the source inside performCallSlotOptzn. if (auto *LoadClobber = dyn_cast( MSSA->getWalker()->getClobberingMemoryAccess(LI))) - return dyn_cast_or_null(LoadClobber->getMemoryInst()); + return dyn_cast_if_present(LoadClobber->getMemoryInst()); return nullptr; }; @@ -1293,7 +1293,7 @@ if (MSSA->isLiveOnEntryDef(Def)) return isa(getUnderlyingObject(V)); - if (auto *II = dyn_cast_or_null(Def->getMemoryInst())) { + if (auto *II = dyn_cast_if_present(Def->getMemoryInst())) { if (II->getIntrinsicID() == Intrinsic::lifetime_start) { auto *LTSize = cast(II->getArgOperand(0)); @@ -1437,7 +1437,7 @@ // The memcpy most post-dom the memset, so limit this to the same basic // block. A non-local generalization is likely not worthwhile. if (auto *MD = dyn_cast(DestClobber)) - if (auto *MDep = dyn_cast_or_null(MD->getMemoryInst())) + if (auto *MDep = dyn_cast_if_present(MD->getMemoryInst())) if (DestClobber->getBlock() == M->getParent()) if (processMemSetMemCpyDependence(M, MDep)) return true; @@ -1535,7 +1535,7 @@ MemoryAccess *Clobber = MSSA->getWalker()->getClobberingMemoryAccess( CallAccess->getDefiningAccess(), Loc); if (auto *MD = dyn_cast(Clobber)) - MDep = dyn_cast_or_null(MD->getMemoryInst()); + MDep = dyn_cast_if_present(MD->getMemoryInst()); // If the byval argument isn't fed by a memcpy, ignore it. If it is fed by // a memcpy, see if we can byval from the source of the memcpy instead of the diff --git a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp --- a/llvm/lib/Transforms/Scalar/NaryReassociate.cpp +++ b/llvm/lib/Transforms/Scalar/NaryReassociate.cpp @@ -282,10 +282,10 @@ m_Value(LHS), m_Value(RHS)); if (match(I, MinMaxMatcher)) { OrigSCEV = SE->getSCEV(I); - if (auto *NewMinMax = dyn_cast_or_null( + if (auto *NewMinMax = dyn_cast_if_present( tryReassociateMinOrMax(I, MinMaxMatcher, LHS, RHS))) return NewMinMax; - if (auto *NewMinMax = dyn_cast_or_null( + if (auto *NewMinMax = dyn_cast_if_present( tryReassociateMinOrMax(I, MinMaxMatcher, RHS, LHS))) return NewMinMax; } diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -1882,7 +1882,7 @@ // something from a previous comparison. for (const auto &Op : CI->operands()) { auto *PI = PredInfo->getPredicateInfoFor(Op); - if (const auto *PBranch = dyn_cast_or_null(PI)) { + if (const auto *PBranch = dyn_cast_if_present(PI)) { if (PI == LastPredInfo) continue; LastPredInfo = PI; @@ -2138,7 +2138,7 @@ // Make sure there will be a leader to find. assert(!CC->definesNoMemory() && "Can't get next leader if there is none"); if (CC->getStoreCount() > 0) { - if (auto *NL = dyn_cast_or_null(CC->getNextLeader().first)) + if (auto *NL = dyn_cast_if_present(CC->getNextLeader().first)) return getMemoryAccess(NL); // Find the store with the minimum DFS number. auto *V = getMinDFSOfRange(make_filter_range( @@ -2269,7 +2269,7 @@ // instructions before. // If it's not a memory use, set the MemoryAccess equivalence - auto *InstMA = dyn_cast_or_null(getMemoryAccess(I)); + auto *InstMA = dyn_cast_if_present(getMemoryAccess(I)); if (InstMA) moveMemoryToNewCongruenceClass(I, InstMA, OldClass, NewClass); ValueToClass[I] = NewClass; @@ -2466,7 +2466,8 @@ if (auto *I = dyn_cast(Cond)) { SmallPtrSet Visited; auto Res = performSymbolicEvaluation(I, Visited); - if (const auto *CE = dyn_cast_or_null(Res.Expr)) { + if (const auto *CE = + dyn_cast_if_present(Res.Expr)) { CondEvaluated = CE->getConstantValue(); addAdditionalUsers(Res, I); } else { @@ -3608,7 +3609,7 @@ // If there is a phi node equivalent, add it if (auto *PN = RealToTemp.lookup(Def)) { auto *PHIE = - dyn_cast_or_null(ValueToExpression.lookup(Def)); + dyn_cast_if_present(ValueToExpression.lookup(Def)); if (PHIE) { VDDef.Def.setInt(false); VDDef.Def.setPointer(PN); @@ -3875,7 +3876,7 @@ for (auto InstNum : BBPair.second) { auto *Inst = InstrFromDFSNum(InstNum); auto *PHI = dyn_cast(Inst); - PHI = PHI ? PHI : dyn_cast_or_null(RealToTemp.lookup(Inst)); + PHI = PHI ? PHI : dyn_cast_if_present(RealToTemp.lookup(Inst)); if (!PHI) continue; auto *BB = BBPair.first; @@ -3958,7 +3959,7 @@ // We ignore void things because we can't get a value from them. if (Def && Def->getType()->isVoidTy()) continue; - auto *DefInst = dyn_cast_or_null(Def); + auto *DefInst = dyn_cast_if_present(Def); if (DefInst && AllTempInstructions.count(DefInst)) { auto *PN = cast(DefInst); diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp --- a/llvm/lib/Transforms/Scalar/SROA.cpp +++ b/llvm/lib/Transforms/Scalar/SROA.cpp @@ -1156,7 +1156,7 @@ UserTy = SI->getValueOperand()->getType(); } - if (IntegerType *UserITy = dyn_cast_or_null(UserTy)) { + if (IntegerType *UserITy = dyn_cast_if_present(UserTy)) { // If the type is larger than the partition, skip it. We only encounter // this for split integer operations where we want to use the type of the // entity causing the split. Also skip if the type is not a byte width @@ -4685,7 +4685,7 @@ SmallPtrSetImpl &DeletedAllocas) { bool Changed = false; while (!DeadInsts.empty()) { - Instruction *I = dyn_cast_or_null(DeadInsts.pop_back_val()); + Instruction *I = dyn_cast_if_present(DeadInsts.pop_back_val()); if (!I) continue; LLVM_DEBUG(dbgs() << "Deleting dead instruction: " << *I << "\n"); diff --git a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp --- a/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp +++ b/llvm/lib/Transforms/Scalar/SeparateConstOffsetFromGEP.cpp @@ -901,7 +901,7 @@ // If we created a GEP with constant index, and the base is loop invariant, // then we swap the first one with it, so LICM can move constant GEP out // later. - auto *FirstGEP = dyn_cast_or_null(FirstResult); + auto *FirstGEP = dyn_cast_if_present(FirstResult); auto *SecondGEP = dyn_cast(ResultPtr); if (isSwapCandidate && isLegalToSwapOperand(FirstGEP, SecondGEP, L)) swapGEPOperand(FirstGEP, SecondGEP); diff --git a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp --- a/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp +++ b/llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp @@ -251,7 +251,7 @@ MemorySSA *MSSA = MSSAU->getMemorySSA(); if (auto *MemUse = - dyn_cast_or_null(MSSA->getMemoryAccess(Inst))) { + dyn_cast_if_present(MSSA->getMemoryAccess(Inst))) { auto *DefiningAccess = MemUse->getDefiningAccess(); // Get the first defining access before the loop. while (L.contains(DefiningAccess->getBlock())) { diff --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp --- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp @@ -187,7 +187,7 @@ // of the value computed by experimental_deoptimize. // I.e., we can not change `ret` to `br` for this block. if (auto *CI = - dyn_cast_or_null(Term->getPrevNonDebugInstruction())) { + dyn_cast_if_present(Term->getPrevNonDebugInstruction())) { if (Function *F = CI->getCalledFunction()) if (Intrinsic::ID ID = F->getIntrinsicID()) if (ID == Intrinsic::experimental_deoptimize) diff --git a/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp b/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp --- a/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp +++ b/llvm/lib/Transforms/Scalar/SpeculativeExecution.cpp @@ -267,7 +267,7 @@ // Debug variable has special operand to check it's not hoisted. if (const auto *DVI = dyn_cast(U)) { return all_of(DVI->location_ops(), [&NotHoisted](Value *V) { - if (const auto *I = dyn_cast_or_null(V)) { + if (const auto *I = dyn_cast_if_present(V)) { if (!NotHoisted.contains(I)) return true; } diff --git a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp --- a/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp +++ b/llvm/lib/Transforms/Scalar/StructurizeCFG.cpp @@ -680,7 +680,7 @@ SimplifyQuery Q(Func->getParent()->getDataLayout()); Q.DT = DT; for (WeakVH VH : AffectedPhis) { - if (auto Phi = dyn_cast_or_null(VH)) { + if (auto Phi = dyn_cast_if_present(VH)) { if (auto NewValue = simplifyInstruction(Phi, Q)) { Phi->replaceAllUsesWith(NewValue); Phi->eraseFromParent(); diff --git a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp --- a/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp +++ b/llvm/lib/Transforms/Utils/AssumeBundleBuilder.cpp @@ -419,7 +419,7 @@ } RetainedKnowledge RK = getKnowledgeFromBundle(cast(*Assume), BOI); - if (auto *Arg = dyn_cast_or_null(RK.WasOn)) { + if (auto *Arg = dyn_cast_if_present(RK.WasOn)) { bool HasSameKindAttr = Arg->hasAttribute(RK.AttrKind); if (HasSameKindAttr) if (!Attribute::isIntAttrKind(RK.AttrKind) || @@ -482,7 +482,7 @@ if (!RK) continue; Builder.addKnowledge(RK); - if (auto *I = dyn_cast_or_null(RK.WasOn)) + if (auto *I = dyn_cast_if_present(RK.WasOn)) if (I->getParent() == InsertPt->getParent() && (InsertPt->comesBefore(I) || InsertPt == I)) InsertPt = I->getNextNode(); diff --git a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp --- a/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp +++ b/llvm/lib/Transforms/Utils/BasicBlockUtils.cpp @@ -169,7 +169,7 @@ bool Changed = false; for (unsigned i = 0, e = PHIs.size(); i != e; ++i) - if (PHINode *PN = dyn_cast_or_null(PHIs[i].operator Value*())) + if (PHINode *PN = dyn_cast_if_present(PHIs[i].operator Value *())) Changed |= RecursivelyDeleteDeadPHINode(PN, TLI, MSSAU); return Changed; @@ -1811,7 +1811,7 @@ for (auto I : DeletionCandidates) { if (I->use_empty()) - if (auto Inst = dyn_cast_or_null(I)) + if (auto Inst = dyn_cast_if_present(I)) Inst->eraseFromParent(); } diff --git a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp --- a/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp +++ b/llvm/lib/Transforms/Utils/CallPromotionUtils.cpp @@ -305,7 +305,7 @@ // Place a clone of the optional bitcast after the new call site. Value *NewRetVal = NewInst; auto Next = OrigInst->getNextNode(); - if (auto *BitCast = dyn_cast_or_null(Next)) { + if (auto *BitCast = dyn_cast_if_present(Next)) { assert(BitCast->getOperand(0) == OrigInst && "bitcast following musttail call must use the call"); auto NewBitCast = BitCast->clone(); @@ -316,7 +316,7 @@ } // Place a clone of the return instruction after the new call site. - ReturnInst *Ret = dyn_cast_or_null(Next); + ReturnInst *Ret = dyn_cast_if_present(Next); assert(Ret && "musttail call must precede a ret with an optional bitcast"); auto NewRet = Ret->clone(); if (Ret->getReturnValue()) diff --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp --- a/llvm/lib/Transforms/Utils/CloneFunction.cpp +++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp @@ -542,7 +542,7 @@ // Or is a known constant in the caller... if (!Cond) { Value *V = VMap.lookup(BI->getCondition()); - Cond = dyn_cast_or_null(V); + Cond = dyn_cast_if_present(V); } // Constant fold to uncond branch! @@ -558,7 +558,7 @@ ConstantInt *Cond = dyn_cast(SI->getCondition()); if (!Cond) { // Or known constant after constant prop in the callee... Value *V = VMap.lookup(SI->getCondition()); - Cond = dyn_cast_or_null(V); + Cond = dyn_cast_if_present(V); } if (Cond) { // Constant fold to uncond branch! SwitchInst::ConstCaseHandle Case = *SI->findCaseValue(Cond); @@ -767,7 +767,7 @@ // Note that we must test the size on each iteration, the worklist can grow. for (unsigned Idx = 0; Idx != Worklist.size(); ++Idx) { const Value *OrigV = Worklist[Idx]; - auto *I = dyn_cast_or_null(VMap.lookup(OrigV)); + auto *I = dyn_cast_if_present(VMap.lookup(OrigV)); if (!I) continue; diff --git a/llvm/lib/Transforms/Utils/CodeExtractor.cpp b/llvm/lib/Transforms/Utils/CodeExtractor.cpp --- a/llvm/lib/Transforms/Utils/CodeExtractor.cpp +++ b/llvm/lib/Transforms/Utils/CodeExtractor.cpp @@ -1611,7 +1611,7 @@ // Loop info metadata may contain line locations. Fix them up. auto updateLoopInfoLoc = [&Ctx, NewSP](Metadata *MD) -> Metadata * { - if (auto *Loc = dyn_cast_or_null(MD)) + if (auto *Loc = dyn_cast_if_present(MD)) return DILocation::get(Ctx, Loc->getLine(), Loc->getColumn(), NewSP, nullptr); return MD; @@ -1855,7 +1855,7 @@ const Function &NewFunc, AssumptionCache *AC) { for (auto AssumeVH : AC->assumptions()) { - auto *I = dyn_cast_or_null(AssumeVH); + auto *I = dyn_cast_if_present(AssumeVH); if (!I) continue; @@ -1867,7 +1867,7 @@ // that were previously in the old function, but that have now been moved // to the new function. for (auto AffectedValVH : AC->assumptionsFor(I->getOperand(0))) { - auto *AffectedCI = dyn_cast_or_null(AffectedValVH); + auto *AffectedCI = dyn_cast_if_present(AffectedValVH); if (!AffectedCI) continue; if (AffectedCI->getFunction() != &OldFunc) diff --git a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp --- a/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp +++ b/llvm/lib/Transforms/Utils/FunctionImportUtils.cpp @@ -264,7 +264,7 @@ // contains summaries from the source modules if they are being imported. // We might have a non-null VI and get here even in that case if the name // matches one in this module (e.g. weak or appending linkage). - auto *GVS = dyn_cast_or_null( + auto *GVS = dyn_cast_if_present( ImportIndex.findSummaryInModule(VI, M.getModuleIdentifier())); if (GVS && (ImportIndex.isReadOnly(GVS) || ImportIndex.isWriteOnly(GVS))) { diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1255,7 +1255,7 @@ // Check that the cloned RetVal exists and is a call, otherwise we cannot // add the attributes on the cloned RetVal. Simplification during inlining // could have transformed the cloned instruction. - auto *NewRetVal = dyn_cast_or_null(VMap.lookup(RetVal)); + auto *NewRetVal = dyn_cast_if_present(VMap.lookup(RetVal)); if (!NewRetVal) continue; // Backward propagation of attributes to the returned value may be incorrect @@ -1549,7 +1549,7 @@ // reference inlined-at locations. auto updateLoopInfoLoc = [&Ctx, &InlinedAtNode, &IANodes](Metadata *MD) -> Metadata * { - if (auto *Loc = dyn_cast_or_null(MD)) + if (auto *Loc = dyn_cast_if_present(MD)) return inlineDebugLoc(Loc, InlinedAtNode, Ctx, IANodes).get(); return MD; }; @@ -1663,7 +1663,7 @@ uint64_t CloneEntryCount = PriorEntryCount - NewEntryCount; for (auto Entry : *VMap) if (isa(Entry.first)) - if (auto *CI = dyn_cast_or_null(Entry.second)) + if (auto *CI = dyn_cast_if_present(Entry.second)) CI->updateProfWeight(CloneEntryCount, PriorEntryCount); } @@ -2027,7 +2027,7 @@ SmallVector OpDefs; for (auto &VH : InlinedFunctionInfo.OperandBundleCallSites) { - CallBase *ICS = dyn_cast_or_null(VH); + CallBase *ICS = dyn_cast_if_present(VH); if (!ICS) continue; // instruction was DCE'd or RAUW'ed to undef @@ -2446,7 +2446,7 @@ // Delete the old return and any preceding bitcast. BasicBlock *CurBB = RI->getParent(); - auto *OldCast = dyn_cast_or_null(RI->getReturnValue()); + auto *OldCast = dyn_cast_if_present(RI->getReturnValue()); RI->eraseFromParent(); if (OldCast) OldCast->eraseFromParent(); diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp --- a/llvm/lib/Transforms/Utils/Local.cpp +++ b/llvm/lib/Transforms/Utils/Local.cpp @@ -1425,7 +1425,7 @@ assert(DII->getNumVariableLocationOps() == 1 && "address of variable must have exactly 1 location operand."); if (auto *AI = - dyn_cast_or_null(DII->getVariableLocationOp(0))) { + dyn_cast_if_present(DII->getVariableLocationOp(0))) { if (Optional FragmentSize = AI->getAllocationSizeInBits(DL)) { return TypeSize::isKnownGE(ValueSize, *FragmentSize); } @@ -1563,7 +1563,7 @@ for (auto &I : Dbgs) { DbgDeclareInst *DDI = I; - AllocaInst *AI = dyn_cast_or_null(DDI->getAddress()); + AllocaInst *AI = dyn_cast_if_present(DDI->getAddress()); // If this is an alloca for a scalar variable, insert a dbg.value // at each load and store to the alloca and erase the dbg.declare. // The dbg.values allow tracking a variable even if it is not @@ -1634,7 +1634,7 @@ for (auto &I : *BB) { if (auto DbgII = dyn_cast(&I)) { for (Value *V : DbgII->location_ops()) - if (auto *Loc = dyn_cast_or_null(V)) + if (auto *Loc = dyn_cast_if_present(V)) DbgValueMap.insert({Loc, DbgII}); } } diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp --- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp +++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp @@ -226,7 +226,7 @@ // identified. Any remaining should be cleaned up below. while (!DeadInsts.empty()) { Value *V = DeadInsts.pop_back_val(); - if (Instruction *Inst = dyn_cast_or_null(V)) + if (Instruction *Inst = dyn_cast_if_present(V)) RecursivelyDeleteTriviallyDeadInstructions(Inst); } } diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp --- a/llvm/lib/Transforms/Utils/LoopUtils.cpp +++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp @@ -1743,7 +1743,7 @@ InstToDuplicate.push_back(I); if (MemoryAccess *MA = MSSA.getMemoryAccess(I)) { - if (auto *MemUse = dyn_cast_or_null(MA)) { + if (auto *MemUse = dyn_cast_if_present(MA)) { // Queue the defining access to check for alias checks. AccessesToCheck.push_back(MemUse->getDefiningAccess()); AccessedLocs.push_back(MemoryLocation::get(I)); diff --git a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp --- a/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp +++ b/llvm/lib/Transforms/Utils/MemoryTaggingSupport.cpp @@ -137,7 +137,7 @@ } if (auto *DVI = dyn_cast(&Inst)) { for (Value *V : DVI->location_ops()) { - if (auto *AI = dyn_cast_or_null(V)) { + if (auto *AI = dyn_cast_if_present(V)) { if (!IsInterestingAlloca(*AI)) continue; AllocaInfo &AInfo = Info.AllocasToInstrument[AI]; diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp --- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp +++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp @@ -104,8 +104,8 @@ // Perform a strict weak ordering on instructions and arguments. static bool valueComesBefore(const Value *A, const Value *B) { - auto *ArgA = dyn_cast_or_null(A); - auto *ArgB = dyn_cast_or_null(B); + auto *ArgA = dyn_cast_if_present(A); + auto *ArgB = dyn_cast_if_present(B); if (ArgA && !ArgB) return true; if (ArgB && !ArgA) @@ -228,8 +228,8 @@ // See if we have real values or uses. If we have real values, we are // guaranteed they are instructions or arguments. No matter what, we are // guaranteed they are in the same block if they are instructions. - auto *ArgA = dyn_cast_or_null(ADef); - auto *ArgB = dyn_cast_or_null(BDef); + auto *ArgA = dyn_cast_if_present(ADef); + auto *ArgB = dyn_cast_if_present(BDef); if (ArgA || ArgB) return valueComesBefore(ArgA, ArgB); @@ -523,7 +523,7 @@ } } for (auto &Assume : AC.assumptions()) { - if (auto *II = dyn_cast_or_null(Assume)) + if (auto *II = dyn_cast_if_present(Assume)) if (DT.isReachableFromEntry(II->getParent())) processAssume(II, II->getParent(), OpsToRename); } diff --git a/llvm/lib/Transforms/Utils/SCCPSolver.cpp b/llvm/lib/Transforms/Utils/SCCPSolver.cpp --- a/llvm/lib/Transforms/Utils/SCCPSolver.cpp +++ b/llvm/lib/Transforms/Utils/SCCPSolver.cpp @@ -128,7 +128,7 @@ private: ConstantInt *getConstantInt(const ValueLatticeElement &IV) const { - return dyn_cast_or_null(getConstant(IV)); + return dyn_cast_if_present(getConstant(IV)); } // pushToWorkList - Helper for markConstant/markOverdefined @@ -661,7 +661,8 @@ if (auto *IBR = dyn_cast(&TI)) { // Casts are folded by visitCastInst. ValueLatticeElement IBRValue = getValueState(IBR->getAddress()); - BlockAddress *Addr = dyn_cast_or_null(getConstant(IBRValue)); + BlockAddress *Addr = + dyn_cast_if_present(getConstant(IBRValue)); if (!Addr) { // Overdefined or unknown condition? // All destinations are executable! if (!IBRValue.isUnknownOrUndef()) @@ -987,7 +988,7 @@ Value *V1 = isConstant(V1State) ? getConstant(V1State) : I.getOperand(0); Value *V2 = isConstant(V2State) ? getConstant(V2State) : I.getOperand(1); Value *R = simplifyBinOp(I.getOpcode(), V1, V2, SimplifyQuery(DL)); - auto *C = dyn_cast_or_null(R); + auto *C = dyn_cast_if_present(R); if (C) { // Conservatively assume that the result may be based on operands that may // be undef. Note that we use mergeInValue to combine the constant with diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp --- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp @@ -280,7 +280,7 @@ static Value *copyFlags(const CallInst &Old, Value *New) { assert(!Old.isMustTailCall() && "do not copy musttail call flags"); assert(!Old.isNoTailCall() && "do not copy notail call flags"); - if (auto *NewCI = dyn_cast_or_null(New)) + if (auto *NewCI = dyn_cast_if_present(New)) NewCI->setTailCallKind(Old.getTailCallKind()); return New; } diff --git a/llvm/lib/Transforms/Utils/SplitModule.cpp b/llvm/lib/Transforms/Utils/SplitModule.cpp --- a/llvm/lib/Transforms/Utils/SplitModule.cpp +++ b/llvm/lib/Transforms/Utils/SplitModule.cpp @@ -91,7 +91,7 @@ static const GlobalObject *getGVPartitioningRoot(const GlobalValue *GV) { const GlobalObject *GO = GV->getAliaseeObject(); - if (const auto *GI = dyn_cast_or_null(GO)) + if (const auto *GI = dyn_cast_if_present(GO)) GO = GI->getResolverFunction(); return GO; } diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp @@ -1042,7 +1042,7 @@ bool LoopVectorizationLegality::isInductionPhi(const Value *V) const { Value *In0 = const_cast(V); - PHINode *PN = dyn_cast_or_null(In0); + PHINode *PN = dyn_cast_if_present(In0); if (!PN) return false; diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6912,7 +6912,7 @@ for (BasicBlock *BB : TheLoop->blocks()) for (Instruction &I : *BB) { Instruction *PtrDef = - dyn_cast_or_null(getLoadStorePointerOperand(&I)); + dyn_cast_if_present(getLoadStorePointerOperand(&I)); if (PtrDef && TheLoop->contains(PtrDef) && getWideningDecision(&I, VF) != CM_GatherScatter) AddrDefs.insert(PtrDef); @@ -8268,7 +8268,7 @@ VPValue *InLoopVal = nullptr; for (unsigned In = 0; In < NumIncoming; In++) { PHINode *PhiOp = - dyn_cast_or_null(Operands[In]->getUnderlyingValue()); + dyn_cast_if_present(Operands[In]->getUnderlyingValue()); if (PhiOp && CM.isInLoopReduction(PhiOp)) { assert(!InLoopVal && "Found more than one in-loop reduction!"); InLoopVal = Operands[In]; @@ -8471,7 +8471,7 @@ // value. Avoid hoisting the insert-element which packs the scalar value into // a vector value, as that happens iff all users use the vector value. for (VPValue *Op : Recipe->operands()) { - auto *PredR = dyn_cast_or_null(Op->getDef()); + auto *PredR = dyn_cast_if_present(Op->getDef()); if (!PredR) continue; auto *RepR = @@ -8901,7 +8901,7 @@ Plan->addVPValue(Instr, VPV); // If the re-used value is a recipe, register the recipe for the // instruction, in case the recipe for Instr needs to be recorded. - if (auto *R = dyn_cast_or_null(VPV->getDef())) + if (auto *R = dyn_cast_if_present(VPV->getDef())) RecipeBuilder.setRecipe(Instr, R); continue; } @@ -8966,7 +8966,8 @@ // Apply Sink-After legal constraints. auto GetReplicateRegion = [](VPRecipeBase *R) -> VPRegionBlock * { - auto *Region = dyn_cast_or_null(R->getParent()->getParent()); + auto *Region = + dyn_cast_if_present(R->getParent()->getParent()); if (Region && Region->isReplicator()) { assert(Region->getNumSuccessors() == 1 && Region->getNumPredecessors() == 1 && "Expected SESE region!"); @@ -9082,7 +9083,7 @@ RecipeBuilder.getRecipe(IG->getInsertPos())); SmallVector StoredValues; for (unsigned i = 0; i < IG->getFactor(); ++i) - if (auto *SI = dyn_cast_or_null(IG->getMember(i))) { + if (auto *SI = dyn_cast_if_present(IG->getMember(i))) { auto *StoreR = cast(RecipeBuilder.getRecipe(SI)); StoredValues.push_back(StoreR->getStoredValue()); diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -6918,14 +6918,14 @@ getInsertIndex(IE1).value_or(Idx2) == Idx2) IE1 = nullptr; else - IE1 = dyn_cast_or_null(GetBaseOperand(IE1)); + IE1 = dyn_cast_if_present(GetBaseOperand(IE1)); } if (IE2) { if ((IE2 != V && !IE2->hasOneUse()) || getInsertIndex(IE2).value_or(Idx1) == Idx1) IE2 = nullptr; else - IE2 = dyn_cast_or_null(GetBaseOperand(IE2)); + IE2 = dyn_cast_if_present(GetBaseOperand(IE2)); } } while (IE1 || IE2); return false; @@ -7124,7 +7124,7 @@ // If found user is an insertelement, do not calculate extract cost but try // to detect it as a final shuffled/identity match. - if (auto *VU = dyn_cast_or_null(EU.User)) { + if (auto *VU = dyn_cast_if_present(EU.User)) { if (auto *FTy = dyn_cast(VU->getType())) { Optional InsertIdx = getInsertIndex(VU); if (InsertIdx) { @@ -11715,7 +11715,7 @@ if (!ShouldVectorizeHor) return false; - auto *Root = dyn_cast_or_null(V); + auto *Root = dyn_cast_if_present(V); if (!Root) return false; diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -1091,10 +1091,10 @@ /// Returns the first defined value as TruncInst, if it is one or nullptr /// otherwise. TruncInst *getTruncInst() { - return dyn_cast_or_null(getVPValue(0)->getUnderlyingValue()); + return dyn_cast_if_present(getVPValue(0)->getUnderlyingValue()); } const TruncInst *getTruncInst() const { - return dyn_cast_or_null(getVPValue(0)->getUnderlyingValue()); + return dyn_cast_if_present(getVPValue(0)->getUnderlyingValue()); } PHINode *getPHINode() { return IV; } @@ -2859,7 +2859,7 @@ static VPBasicBlock *tryToMergeBlockIntoPredecessor(VPBlockBase *Block) { auto *VPBB = dyn_cast(Block); auto *PredVPBB = - dyn_cast_or_null(Block->getSinglePredecessor()); + dyn_cast_if_present(Block->getSinglePredecessor()); if (!VPBB || !PredVPBB || PredVPBB->getNumSuccessors() != 1) return nullptr; diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -86,14 +86,14 @@ #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) void VPValue::print(raw_ostream &OS, VPSlotTracker &SlotTracker) const { - if (const VPRecipeBase *R = dyn_cast_or_null(Def)) + if (const VPRecipeBase *R = dyn_cast_if_present(Def)) R->print(OS, "", SlotTracker); else printAsOperand(OS, SlotTracker); } void VPValue::dump() const { - const VPRecipeBase *Instr = dyn_cast_or_null(this->Def); + const VPRecipeBase *Instr = dyn_cast_if_present(this->Def); VPSlotTracker SlotTracker( (Instr && Instr->getParent()) ? Instr->getParent()->getPlan() : nullptr); print(dbgs(), SlotTracker); @@ -101,7 +101,7 @@ } void VPDef::dump() const { - const VPRecipeBase *Instr = dyn_cast_or_null(this); + const VPRecipeBase *Instr = dyn_cast_if_present(this); VPSlotTracker SlotTracker( (Instr && Instr->getParent()) ? Instr->getParent()->getPlan() : nullptr); print(dbgs(), "", SlotTracker); @@ -1032,7 +1032,8 @@ assert(isa(&VPI) && "Can only handle VPInstructions"); auto *VPInst = cast(&VPI); - auto *Inst = dyn_cast_or_null(VPInst->getUnderlyingValue()); + auto *Inst = + dyn_cast_if_present(VPInst->getUnderlyingValue()); if (!Inst) continue; auto *IG = IAI.getInterleaveGroup(Inst); diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -58,8 +58,8 @@ case VPWidenGEPSC: case VPReductionSC: case VPWidenSelectSC: { - const Instruction *I = - dyn_cast_or_null(getVPSingleValue()->getUnderlyingValue()); + const Instruction *I = dyn_cast_if_present( + getVPSingleValue()->getUnderlyingValue()); (void)I; assert((!I || !I->mayWriteToMemory()) && "underlying instruction may write to memory"); @@ -89,8 +89,8 @@ case VPWidenGEPSC: case VPReductionSC: case VPWidenSelectSC: { - const Instruction *I = - dyn_cast_or_null(getVPSingleValue()->getUnderlyingValue()); + const Instruction *I = dyn_cast_if_present( + getVPSingleValue()->getUnderlyingValue()); (void)I; assert((!I || !I->mayReadFromMemory()) && "underlying instruction may read from memory"); @@ -115,8 +115,8 @@ case VPReductionSC: case VPWidenSelectSC: case VPScalarIVStepsSC: { - const Instruction *I = - dyn_cast_or_null(getVPSingleValue()->getUnderlyingValue()); + const Instruction *I = dyn_cast_if_present( + getVPSingleValue()->getUnderlyingValue()); (void)I; assert((!I || !I->mayHaveSideEffects()) && "underlying instruction has side-effects"); @@ -659,7 +659,7 @@ auto *StepVPV = getStepValue(); if (StepVPV->getDef()) return false; - auto *StepC = dyn_cast_or_null(StepVPV->getLiveInIRValue()); + auto *StepC = dyn_cast_if_present(StepVPV->getLiveInIRValue()); return StepC && StepC->isOne(); } diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -123,7 +123,7 @@ VPBasicBlock *SinkTo; VPValue *C; std::tie(SinkTo, C) = WorkList.pop_back_val(); - auto *SinkCandidate = dyn_cast_or_null(C->Def); + auto *SinkCandidate = dyn_cast_if_present(C->Def); if (!SinkCandidate || SinkCandidate->isUniform() || SinkCandidate->getParent() == SinkTo || SinkCandidate->mayHaveSideEffects() || @@ -229,12 +229,12 @@ if (DeletedRegions.contains(Region1)) continue; auto *MiddleBasicBlock = - dyn_cast_or_null(Region1->getSingleSuccessor()); + dyn_cast_if_present(Region1->getSingleSuccessor()); if (!MiddleBasicBlock || !MiddleBasicBlock->empty()) continue; - auto *Region2 = - dyn_cast_or_null(MiddleBasicBlock->getSingleSuccessor()); + auto *Region2 = dyn_cast_if_present( + MiddleBasicBlock->getSingleSuccessor()); if (!Region2) continue; diff --git a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp --- a/llvm/lib/Transforms/Vectorize/VectorCombine.cpp +++ b/llvm/lib/Transforms/Vectorize/VectorCombine.cpp @@ -632,8 +632,8 @@ // Bail for single insertion if it is a load. // TODO: Handle this once getVectorInstrCost can cost for load/stores. - auto *I0 = dyn_cast_or_null(V0); - auto *I1 = dyn_cast_or_null(V1); + auto *I0 = dyn_cast_if_present(V0); + auto *I1 = dyn_cast_if_present(V1); if ((IsConst0 && I1 && I1->mayReadFromMemory()) || (IsConst1 && I0 && I0->mayReadFromMemory())) return false; diff --git a/llvm/unittests/Analysis/LoopInfoTest.cpp b/llvm/unittests/Analysis/LoopInfoTest.cpp --- a/llvm/unittests/Analysis/LoopInfoTest.cpp +++ b/llvm/unittests/Analysis/LoopInfoTest.cpp @@ -277,7 +277,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -336,7 +336,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -395,7 +395,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -454,7 +454,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -513,7 +513,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -573,7 +573,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ubPlusOne"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -688,7 +688,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_ULT); @@ -745,7 +745,7 @@ EXPECT_EQ(Bounds->getInitialIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_EQ(StepValue, nullptr); ConstantInt *FinalIVValue = dyn_cast(&Bounds->getFinalIVValue()); @@ -867,7 +867,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "indvars.iv.next"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "wide.trip.count"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_NE); @@ -928,7 +928,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -988,7 +988,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -1040,7 +1040,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -1098,7 +1098,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -1169,7 +1169,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc.outer"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -1194,7 +1194,8 @@ dyn_cast(&InnerBounds->getInitialIVValue()); EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(InnerBounds->getStepInst().getName(), "inc"); - StepValue = dyn_cast_or_null(InnerBounds->getStepValue()); + StepValue = + dyn_cast_if_present(InnerBounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(InnerBounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(InnerBounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); @@ -1262,7 +1263,7 @@ EXPECT_TRUE(InitialIVValue && InitialIVValue->isZero()); EXPECT_EQ(Bounds->getStepInst().getName(), "inc"); ConstantInt *StepValue = - dyn_cast_or_null(Bounds->getStepValue()); + dyn_cast_if_present(Bounds->getStepValue()); EXPECT_TRUE(StepValue && StepValue->isOne()); EXPECT_EQ(Bounds->getFinalIVValue().getName(), "ub"); EXPECT_EQ(Bounds->getCanonicalPredicate(), ICmpInst::ICMP_SLT); diff --git a/llvm/unittests/Analysis/MemorySSATest.cpp b/llvm/unittests/Analysis/MemorySSATest.cpp --- a/llvm/unittests/Analysis/MemorySSATest.cpp +++ b/llvm/unittests/Analysis/MemorySSATest.cpp @@ -1024,7 +1024,7 @@ unsigned I = 0; for (StoreInst *V : {SA1, SB1, SA2, SB2, SA3, SB3}) { - MemoryDef *MemDef = dyn_cast_or_null(MSSA.getMemoryAccess(V)); + MemoryDef *MemDef = dyn_cast_if_present(MSSA.getMemoryAccess(V)); EXPECT_EQ(MemDef->isOptimized(), false) << "Store " << I << " is optimized from the start?"; if (V == SA1) @@ -1077,7 +1077,7 @@ unsigned I = 0; for (StoreInst *V : Sts) { - MemoryDef *MemDef = dyn_cast_or_null(MSSA.getMemoryAccess(V)); + MemoryDef *MemDef = dyn_cast_if_present(MSSA.getMemoryAccess(V)); EXPECT_EQ(MemDef->isOptimized(), false) << "Store " << I << " is optimized from the start?"; ++I; @@ -1088,7 +1088,7 @@ I = 0; for (StoreInst *V : Sts) { - MemoryDef *MemDef = dyn_cast_or_null(MSSA.getMemoryAccess(V)); + MemoryDef *MemDef = dyn_cast_if_present(MSSA.getMemoryAccess(V)); EXPECT_EQ(MemDef->isOptimized(), true) << "Store " << I << " was not optimized"; // EXPECT_EQ expands such that if we increment I above, it won't get diff --git a/llvm/unittests/Analysis/VectorFunctionABITest.cpp b/llvm/unittests/Analysis/VectorFunctionABITest.cpp --- a/llvm/unittests/Analysis/VectorFunctionABITest.cpp +++ b/llvm/unittests/Analysis/VectorFunctionABITest.cpp @@ -623,7 +623,7 @@ ret void } )IR"); - auto F = dyn_cast_or_null(M->getNamedValue("call")); + auto F = dyn_cast_if_present(M->getNamedValue("call")); ASSERT_TRUE(F); auto CI = dyn_cast(&F->front().front()); ASSERT_TRUE(CI); diff --git a/llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp b/llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp --- a/llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp +++ b/llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp @@ -95,7 +95,8 @@ .WillOnce(SaveArg<0>(&Arg0)); TestPrinter->getAP()->emitDwarfSymbolReference(Val, false); - const MCSymbolRefExpr *ActualArg0 = dyn_cast_or_null(Arg0); + const MCSymbolRefExpr *ActualArg0 = + dyn_cast_if_present(Arg0); ASSERT_NE(ActualArg0, nullptr); EXPECT_EQ(&(ActualArg0->getSymbol()), Val); } @@ -118,7 +119,8 @@ .WillOnce(SaveArg<0>(&Arg0)); TestPrinter->getAP()->emitDwarfSymbolReference(Val, false); - const MCSymbolRefExpr *ActualArg0 = dyn_cast_or_null(Arg0); + const MCSymbolRefExpr *ActualArg0 = + dyn_cast_if_present(Arg0); ASSERT_NE(ActualArg0, nullptr); EXPECT_EQ(&(ActualArg0->getSymbol()), Val); } @@ -157,7 +159,8 @@ .WillOnce(SaveArg<0>(&Arg0)); TestPrinter->getAP()->emitDwarfStringOffset(Val); - const MCSymbolRefExpr *ActualArg0 = dyn_cast_or_null(Arg0); + const MCSymbolRefExpr *ActualArg0 = + dyn_cast_if_present(Arg0); ASSERT_NE(ActualArg0, nullptr); EXPECT_EQ(&(ActualArg0->getSymbol()), Val.Symbol); } @@ -181,7 +184,8 @@ .WillOnce(SaveArg<0>(&Arg0)); TestPrinter->getAP()->emitDwarfStringOffset(Val); - const MCSymbolRefExpr *ActualArg0 = dyn_cast_or_null(Arg0); + const MCSymbolRefExpr *ActualArg0 = + dyn_cast_if_present(Arg0); ASSERT_NE(ActualArg0, nullptr); EXPECT_EQ(&(ActualArg0->getSymbol()), Val.Symbol); } @@ -220,17 +224,17 @@ .WillOnce(SaveArg<0>(&Arg0)); TestPrinter->getAP()->emitDwarfOffset(Label, Offset); - const MCBinaryExpr *ActualArg0 = dyn_cast_or_null(Arg0); + const MCBinaryExpr *ActualArg0 = dyn_cast_if_present(Arg0); ASSERT_NE(ActualArg0, nullptr); EXPECT_EQ(ActualArg0->getOpcode(), MCBinaryExpr::Add); const MCSymbolRefExpr *ActualLHS = - dyn_cast_or_null(ActualArg0->getLHS()); + dyn_cast_if_present(ActualArg0->getLHS()); ASSERT_NE(ActualLHS, nullptr); EXPECT_EQ(&(ActualLHS->getSymbol()), Label); const MCConstantExpr *ActualRHS = - dyn_cast_or_null(ActualArg0->getRHS()); + dyn_cast_if_present(ActualArg0->getRHS()); ASSERT_NE(ActualRHS, nullptr); EXPECT_EQ(static_cast(ActualRHS->getValue()), Offset); } @@ -244,17 +248,17 @@ .WillOnce(SaveArg<0>(&Arg0)); TestPrinter->getAP()->emitDwarfOffset(Label, Offset); - const MCBinaryExpr *ActualArg0 = dyn_cast_or_null(Arg0); + const MCBinaryExpr *ActualArg0 = dyn_cast_if_present(Arg0); ASSERT_NE(ActualArg0, nullptr); EXPECT_EQ(ActualArg0->getOpcode(), MCBinaryExpr::Add); const MCSymbolRefExpr *ActualLHS = - dyn_cast_or_null(ActualArg0->getLHS()); + dyn_cast_if_present(ActualArg0->getLHS()); ASSERT_NE(ActualLHS, nullptr); EXPECT_EQ(&(ActualLHS->getSymbol()), Label); const MCConstantExpr *ActualRHS = - dyn_cast_or_null(ActualArg0->getRHS()); + dyn_cast_if_present(ActualArg0->getRHS()); ASSERT_NE(ActualRHS, nullptr); EXPECT_EQ(static_cast(ActualRHS->getValue()), Offset); } diff --git a/llvm/unittests/CodeGen/DIETest.cpp b/llvm/unittests/CodeGen/DIETest.cpp --- a/llvm/unittests/CodeGen/DIETest.cpp +++ b/llvm/unittests/CodeGen/DIETest.cpp @@ -99,7 +99,8 @@ .WillOnce(SaveArg<0>(&Arg0)); Tst.emitValue(TestPrinter->getAP(), Form); - const MCSymbolRefExpr *ActualArg0 = dyn_cast_or_null(Arg0); + const MCSymbolRefExpr *ActualArg0 = + dyn_cast_if_present(Arg0); ASSERT_NE(ActualArg0, nullptr); EXPECT_EQ(&(ActualArg0->getSymbol()), Val); } diff --git a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp --- a/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp +++ b/llvm/unittests/Frontend/OpenMPIRBuilderTest.cpp @@ -2985,21 +2985,22 @@ OMPBuilder.createCopyinClauseBlocks(Builder.saveIP(), MasterAddress, PrivAddress, Int32, /*BranchtoEnd*/ true); - BranchInst *EntryBr = dyn_cast_or_null(EntryBB->getTerminator()); + BranchInst *EntryBr = + dyn_cast_if_present(EntryBB->getTerminator()); EXPECT_NE(EntryBr, nullptr); EXPECT_TRUE(EntryBr->isConditional()); BasicBlock *NotMasterBB = EntryBr->getSuccessor(0); BasicBlock *CopyinEnd = EntryBr->getSuccessor(1); - CmpInst *CMP = dyn_cast_or_null(EntryBr->getCondition()); + CmpInst *CMP = dyn_cast_if_present(EntryBr->getCondition()); EXPECT_NE(CMP, nullptr); EXPECT_NE(NotMasterBB, nullptr); EXPECT_NE(CopyinEnd, nullptr); BranchInst *NotMasterBr = - dyn_cast_or_null(NotMasterBB->getTerminator()); + dyn_cast_if_present(NotMasterBB->getTerminator()); EXPECT_NE(NotMasterBr, nullptr); EXPECT_FALSE(NotMasterBr->isConditional()); EXPECT_EQ(CopyinEnd, NotMasterBr->getSuccessor(0)); @@ -4216,9 +4217,9 @@ // Check that the values stored into the local array are privatized reduction // variables. - auto *FirstStored = dyn_cast_or_null( + auto *FirstStored = dyn_cast_if_present( findStoredValue(FirstArrayElemPtr)); - auto *SecondStored = dyn_cast_or_null( + auto *SecondStored = dyn_cast_if_present( findStoredValue(SecondArrayElemPtr)); ASSERT_NE(FirstStored, nullptr); ASSERT_NE(SecondStored, nullptr); @@ -5195,9 +5196,9 @@ ASSERT_EQ(TaskAllocFn->getNumUses(), 2u); CallInst *FirstTaskAllocCall = - dyn_cast_or_null(*TaskAllocFn->users().begin()); + dyn_cast_if_present(*TaskAllocFn->users().begin()); CallInst *SecondTaskAllocCall = - dyn_cast_or_null(*TaskAllocFn->users().begin()++); + dyn_cast_if_present(*TaskAllocFn->users().begin()++); ASSERT_NE(FirstTaskAllocCall, nullptr); ASSERT_NE(SecondTaskAllocCall, nullptr); diff --git a/llvm/unittests/IR/IRBuilderTest.cpp b/llvm/unittests/IR/IRBuilderTest.cpp --- a/llvm/unittests/IR/IRBuilderTest.cpp +++ b/llvm/unittests/IR/IRBuilderTest.cpp @@ -933,7 +933,7 @@ for (auto *IE : CU->getImportedEntities()) Names.push_back(IE->getName()); for (auto *Node : CU->getMacros()) - if (auto *MN = dyn_cast_or_null(Node)) + if (auto *MN = dyn_cast_if_present(Node)) Names.push_back(MN->getName()); return Names; }; diff --git a/llvm/unittests/IR/MetadataTest.cpp b/llvm/unittests/IR/MetadataTest.cpp --- a/llvm/unittests/IR/MetadataTest.cpp +++ b/llvm/unittests/IR/MetadataTest.cpp @@ -1401,17 +1401,18 @@ auto Lower = N->getLowerBound(); ASSERT_TRUE(Lower); ASSERT_TRUE(Lower.is()); - EXPECT_EQ(dyn_cast_or_null(LI), Lower.get()); + EXPECT_EQ(dyn_cast_if_present(LI), Lower.get()); auto Upper = N->getUpperBound(); ASSERT_TRUE(Upper); ASSERT_TRUE(Upper.is()); - EXPECT_EQ(dyn_cast_or_null(UI), Upper.get()); + EXPECT_EQ(dyn_cast_if_present(UI), Upper.get()); auto Stride = N->getStride(); ASSERT_TRUE(Stride); ASSERT_TRUE(Stride.is()); - EXPECT_EQ(dyn_cast_or_null(SI), Stride.get()); + EXPECT_EQ(dyn_cast_if_present(SI), + Stride.get()); EXPECT_EQ(N, DIGenericSubrange::get(Context, nullptr, LI, UI, SI)); diff --git a/llvm/unittests/Transforms/Utils/SSAUpdaterBulkTest.cpp b/llvm/unittests/Transforms/Utils/SSAUpdaterBulkTest.cpp --- a/llvm/unittests/Transforms/Utils/SSAUpdaterBulkTest.cpp +++ b/llvm/unittests/Transforms/Utils/SSAUpdaterBulkTest.cpp @@ -88,17 +88,17 @@ Updater.RewriteAllUses(&DT); // Check how %5 and %6 were rewritten. - PHINode *UpdatePhiA = dyn_cast_or_null(I1->getOperand(0)); + PHINode *UpdatePhiA = dyn_cast_if_present(I1->getOperand(0)); EXPECT_NE(UpdatePhiA, nullptr); EXPECT_EQ(UpdatePhiA->getIncomingValueForBlock(TrueBB), AddOp1); EXPECT_EQ(UpdatePhiA->getIncomingValueForBlock(FalseBB), AddOp2); - EXPECT_EQ(UpdatePhiA, dyn_cast_or_null(I1->getOperand(0))); + EXPECT_EQ(UpdatePhiA, dyn_cast_if_present(I1->getOperand(0))); // Check how %7 was rewritten. - PHINode *UpdatePhiB = dyn_cast_or_null(I3->getOperand(0)); + PHINode *UpdatePhiB = dyn_cast_if_present(I3->getOperand(0)); EXPECT_EQ(UpdatePhiB->getIncomingValueForBlock(TrueBB), SubOp1); EXPECT_EQ(UpdatePhiB->getIncomingValueForBlock(FalseBB), SubOp2); - EXPECT_EQ(UpdatePhiB, dyn_cast_or_null(I3->getOperand(1))); + EXPECT_EQ(UpdatePhiB, dyn_cast_if_present(I3->getOperand(1))); // Check that %8 was kept untouched. EXPECT_EQ(I4->getOperand(0), SubOp1); @@ -187,7 +187,7 @@ EXPECT_EQ(Return->getOperand(0), FirstArg); // I2 should use the new phi. - PHINode *UpdatePhi = dyn_cast_or_null(I2->getOperand(0)); + PHINode *UpdatePhi = dyn_cast_if_present(I2->getOperand(0)); EXPECT_NE(UpdatePhi, nullptr); EXPECT_EQ(UpdatePhi->getIncomingValueForBlock(LoopStartBB), AddOp2); EXPECT_EQ(UpdatePhi->getIncomingValueForBlock(IfBB), UndefValue::get(I32Ty)); diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp --- a/llvm/utils/TableGen/CodeEmitterGen.cpp +++ b/llvm/utils/TableGen/CodeEmitterGen.cpp @@ -269,7 +269,7 @@ CodeGenTarget &Target) { std::string Case; if (const RecordVal *RV = R->getValue("EncodingInfos")) { - if (auto *DI = dyn_cast_or_null(RV->getValue())) { + if (auto *DI = dyn_cast_if_present(RV->getValue())) { const CodeGenHwModes &HWM = Target.getHwModes(); EncodingInfoByHwMode EBM(DI->getDef(), HWM); Case += " switch (HwMode) {\n"; @@ -359,7 +359,7 @@ Record *EncodingDef = R; if (const RecordVal *RV = R->getValue("EncodingInfos")) { - if (auto *DI = dyn_cast_or_null(RV->getValue())) { + if (auto *DI = dyn_cast_if_present(RV->getValue())) { EncodingInfoByHwMode EBM(DI->getDef(), HWM); if (EBM.hasMode(HwMode)) EncodingDef = EBM.get(HwMode); @@ -407,7 +407,7 @@ continue; if (const RecordVal *RV = R->getValue("EncodingInfos")) { - if (DefInit *DI = dyn_cast_or_null(RV->getValue())) { + if (DefInit *DI = dyn_cast_if_present(RV->getValue())) { EncodingInfoByHwMode EBM(DI->getDef(), HWM); for (auto &KV : EBM) { BitsInit *BI = KV.second->getValueAsBitsInit("Inst"); diff --git a/llvm/utils/TableGen/CodeGenInstruction.cpp b/llvm/utils/TableGen/CodeGenInstruction.cpp --- a/llvm/utils/TableGen/CodeGenInstruction.cpp +++ b/llvm/utils/TableGen/CodeGenInstruction.cpp @@ -632,7 +632,7 @@ if (!BI->isComplete()) return false; // Convert the bits init to an integer and use that for the result. - IntInit *II = dyn_cast_or_null( + IntInit *II = dyn_cast_if_present( BI->convertInitializerTo(IntRecTy::get(BI->getRecordKeeper()))); if (!II) return false; diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp --- a/llvm/utils/TableGen/CodeGenRegisters.cpp +++ b/llvm/utils/TableGen/CodeGenRegisters.cpp @@ -786,7 +786,7 @@ Namespace = R->getValueAsString("Namespace"); if (const RecordVal *RV = R->getValue("RegInfos")) - if (DefInit *DI = dyn_cast_or_null(RV->getValue())) + if (DefInit *DI = dyn_cast_if_present(RV->getValue())) RSI = RegSizeInfoByHwMode(DI->getDef(), RegBank.getHwModes()); unsigned Size = R->getValueAsInt("Size"); assert((RSI.hasDefault() || Size != 0 || VTs[0].isSimple()) && diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp --- a/llvm/utils/TableGen/DecoderEmitter.cpp +++ b/llvm/utils/TableGen/DecoderEmitter.cpp @@ -2550,7 +2550,7 @@ if (const RecordVal *RV = NumberedInstruction->TheDef->getValue("EncodingInfos")) { - if (auto *DI = dyn_cast_or_null(RV->getValue())) { + if (auto *DI = dyn_cast_if_present(RV->getValue())) { const CodeGenHwModes &HWM = Target.getHwModes(); EncodingInfoByHwMode EBM(DI->getDef(), HWM); for (auto &KV : EBM) @@ -2568,7 +2568,7 @@ if (const RecordVal *RV = NumberedInstruction->TheDef->getValue("EncodingInfos")) { - if (DefInit *DI = dyn_cast_or_null(RV->getValue())) { + if (DefInit *DI = dyn_cast_if_present(RV->getValue())) { const CodeGenHwModes &HWM = Target.getHwModes(); EncodingInfoByHwMode EBM(DI->getDef(), HWM); for (auto &KV : EBM) { diff --git a/llvm/utils/TableGen/VarLenCodeEmitterGen.cpp b/llvm/utils/TableGen/VarLenCodeEmitterGen.cpp --- a/llvm/utils/TableGen/VarLenCodeEmitterGen.cpp +++ b/llvm/utils/TableGen/VarLenCodeEmitterGen.cpp @@ -201,7 +201,7 @@ continue; if (const RecordVal *RV = R->getValue("EncodingInfos")) { - if (auto *DI = dyn_cast_or_null(RV->getValue())) { + if (auto *DI = dyn_cast_if_present(RV->getValue())) { EncodingInfoByHwMode EBM(DI->getDef(), HWM); for (auto &KV : EBM) { HwModes.insert(KV.first); @@ -344,7 +344,7 @@ Record *EncodingDef = R; if (const RecordVal *RV = R->getValue("EncodingInfos")) { - if (auto *DI = dyn_cast_or_null(RV->getValue())) { + if (auto *DI = dyn_cast_if_present(RV->getValue())) { EncodingInfoByHwMode EBM(DI->getDef(), HWM); if (EBM.hasMode(HwMode)) EncodingDef = EBM.get(HwMode); @@ -392,7 +392,7 @@ CodeGenTarget &Target) { std::string Case; if (const RecordVal *RV = R->getValue("EncodingInfos")) { - if (auto *DI = dyn_cast_or_null(RV->getValue())) { + if (auto *DI = dyn_cast_if_present(RV->getValue())) { const CodeGenHwModes &HWM = Target.getHwModes(); EncodingInfoByHwMode EBM(DI->getDef(), HWM); Case += " switch (HwMode) {\n";