diff --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h --- a/llvm/include/llvm/ADT/FunctionExtras.h +++ b/llvm/include/llvm/ADT/FunctionExtras.h @@ -172,16 +172,15 @@ bool isInlineStorage() const { return CallbackAndInlineFlag.getInt(); } bool isTrivialCallback() const { - return CallbackAndInlineFlag.getPointer().template is(); + return isa(CallbackAndInlineFlag.getPointer()); } CallPtrT getTrivialCallback() const { - return CallbackAndInlineFlag.getPointer().template get()->CallPtr; + return cast(CallbackAndInlineFlag.getPointer())->CallPtr; } NonTrivialCallbacks *getNonTrivialCallbacks() const { - return CallbackAndInlineFlag.getPointer() - .template get(); + return cast(CallbackAndInlineFlag.getPointer()); } CallPtrT getCallPtr() const { diff --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h --- a/llvm/include/llvm/ADT/PointerUnion.h +++ b/llvm/include/llvm/ADT/PointerUnion.h @@ -172,9 +172,9 @@ /// If the union is set to the first pointer type get an address pointing to /// it. First *getAddrOfPtr1() { - assert(is() && "Val is not the first pointer"); + assert(isa(*this) && "Val is not the first pointer"); assert( - PointerLikeTypeTraits::getAsVoidPointer(get()) == + PointerLikeTypeTraits::getAsVoidPointer(cast(*this)) == this->Val.getPointer() && "Can't get the address because PointerLikeTypeTraits changes the ptr"); return const_cast( diff --git a/llvm/include/llvm/ADT/TinyPtrVector.h b/llvm/include/llvm/ADT/TinyPtrVector.h --- a/llvm/include/llvm/ADT/TinyPtrVector.h +++ b/llvm/include/llvm/ADT/TinyPtrVector.h @@ -43,12 +43,12 @@ TinyPtrVector() = default; ~TinyPtrVector() { - if (VecTy *V = Val.template dyn_cast()) + if (VecTy *V = dyn_cast_if_present(Val)) delete V; } TinyPtrVector(const TinyPtrVector &RHS) : Val(RHS.Val) { - if (VecTy *V = Val.template dyn_cast()) + if (VecTy *V = dyn_cast_if_present(Val)) Val = new VecTy(*V); } @@ -62,20 +62,20 @@ // Try to squeeze into the single slot. If it won't fit, allocate a copied // vector. - if (Val.template is()) { + if (isa(Val)) { if (RHS.size() == 1) Val = RHS.front(); else - Val = new VecTy(*RHS.Val.template get()); + Val = new VecTy(*cast(RHS.Val)); return *this; } // If we have a full vector allocated, try to re-use it. - if (RHS.Val.template is()) { - Val.template get()->clear(); - Val.template get()->push_back(RHS.front()); + if (isa(RHS.Val)) { + cast(Val)->clear(); + cast(Val)->push_back(RHS.front()); } else { - *Val.template get() = *RHS.Val.template get(); + *cast(Val) = *cast(RHS.Val); } return *this; } @@ -95,8 +95,8 @@ // If this vector has been allocated on the heap, re-use it if cheap. If it // would require more copying, just delete it and we'll steal the other // side. - if (VecTy *V = Val.template dyn_cast()) { - if (RHS.Val.template is()) { + if (VecTy *V = dyn_cast_if_present(Val)) { + if (isa(RHS.Val)) { V->clear(); V->push_back(RHS.front()); RHS.Val = EltTy(); @@ -136,18 +136,18 @@ operator ArrayRef() const { if (Val.isNull()) return std::nullopt; - if (Val.template is()) + if (isa(Val)) return *Val.getAddrOfPtr1(); - return *Val.template get(); + return *cast(Val); } // implicit conversion operator to MutableArrayRef. operator MutableArrayRef() { if (Val.isNull()) return std::nullopt; - if (Val.template is()) + if (isa(Val)) return *Val.getAddrOfPtr1(); - return *Val.template get(); + return *cast(Val); } // Implicit conversion to ArrayRef if EltTy* implicitly converts to U*. @@ -163,7 +163,7 @@ // This vector can be empty if it contains no element, or if it // contains a pointer to an empty vector. if (Val.isNull()) return true; - if (VecTy *Vec = Val.template dyn_cast()) + if (VecTy *Vec = dyn_cast_if_present(Val)) return Vec->empty(); return false; } @@ -171,9 +171,9 @@ unsigned size() const { if (empty()) return 0; - if (Val.template is()) + if (isa(Val)) return 1; - return Val.template get()->size(); + return cast(Val)->size(); } using iterator = EltTy *; @@ -182,17 +182,17 @@ using const_reverse_iterator = std::reverse_iterator; iterator begin() { - if (Val.template is()) + if (isa(Val)) return Val.getAddrOfPtr1(); - return Val.template get()->begin(); + return cast(Val)->begin(); } iterator end() { - if (Val.template is()) + if (isa(Val)) return begin() + (Val.isNull() ? 0 : 1); - return Val.template get()->end(); + return cast(Val)->end(); } const_iterator begin() const { @@ -216,28 +216,27 @@ EltTy operator[](unsigned i) const { assert(!Val.isNull() && "can't index into an empty vector"); - if (Val.template is()) { + if (isa(Val)) { assert(i == 0 && "tinyvector index out of range"); - return Val.template get(); + return cast(Val); } - assert(i < Val.template get()->size() && - "tinyvector index out of range"); - return (*Val.template get())[i]; + assert(i < cast(Val)->size() && "tinyvector index out of range"); + return (*cast(Val))[i]; } EltTy front() const { assert(!empty() && "vector empty"); - if (Val.template is()) - return Val.template get(); - return Val.template get()->front(); + if (isa(Val)) + return cast(Val); + return cast(Val)->front(); } EltTy back() const { assert(!empty() && "vector empty"); - if (Val.template is()) - return Val.template get(); - return Val.template get()->back(); + if (isa(Val)) + return cast(Val); + return cast(Val)->back(); } void push_back(EltTy NewVal) { @@ -249,29 +248,29 @@ } // If we have a single value, convert to a vector. - if (Val.template is()) { - EltTy V = Val.template get(); + if (isa(Val)) { + EltTy V = cast(Val); Val = new VecTy(); - Val.template get()->push_back(V); + cast(Val)->push_back(V); } // Add the new value, we know we have a vector. - Val.template get()->push_back(NewVal); + cast(Val)->push_back(NewVal); } void pop_back() { // If we have a single value, convert to empty. - if (Val.template is()) + if (isa(Val)) Val = (EltTy)nullptr; - else if (VecTy *Vec = Val.template get()) + else if (VecTy *Vec = cast(Val)) Vec->pop_back(); } void clear() { // If we have a single value, convert to empty. - if (Val.template is()) { + if (isa(Val)) { Val = EltTy(); - } else if (VecTy *Vec = Val.template dyn_cast()) { + } else if (VecTy *Vec = dyn_cast_if_present(Val)) { // If we have a vector form, just clear it. Vec->clear(); } @@ -283,10 +282,10 @@ assert(I < end() && "Erasing at past-the-end iterator."); // If we have a single value, convert to empty. - if (Val.template is()) { + if (isa(Val)) { if (I == begin()) Val = EltTy(); - } else if (VecTy *Vec = Val.template dyn_cast()) { + } else if (VecTy *Vec = dyn_cast_if_present(Val)) { // multiple items in a vector; just do the erase, there is no // benefit to collapsing back to a pointer return Vec->erase(I); @@ -299,10 +298,10 @@ assert(S <= E && "Trying to erase invalid range."); assert(E <= end() && "Trying to erase past the end."); - if (Val.template is()) { + if (isa(Val)) { if (S == begin() && S != E) Val = EltTy(); - } else if (VecTy *Vec = Val.template dyn_cast()) { + } else if (VecTy *Vec = dyn_cast_if_present(Val)) { return Vec->erase(S, E); } return end(); @@ -316,15 +315,15 @@ return std::prev(end()); } assert(!Val.isNull() && "Null value with non-end insert iterator."); - if (Val.template is()) { - EltTy V = Val.template get(); + if (isa(Val)) { + EltTy V = cast(Val); assert(I == begin()); Val = Elt; push_back(V); return begin(); } - return Val.template get()->insert(I, Elt); + return cast(Val)->insert(I, Elt); } template @@ -343,12 +342,12 @@ } Val = new VecTy(); - } else if (Val.template is()) { - EltTy V = Val.template get(); + } else if (isa(Val)) { + EltTy V = cast(Val); Val = new VecTy(); - Val.template get()->push_back(V); + cast(Val)->push_back(V); } - return Val.template get()->insert(begin() + Offset, From, To); + return cast(Val)->insert(begin() + Offset, From, To); } }; diff --git a/llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h b/llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h --- a/llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h +++ b/llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h @@ -63,7 +63,7 @@ /// thus specified entry mustn`t be reallocated. DwarfStringPoolEntryRef(const StringMapEntry &Entry) : MapEntry(&Entry) { - assert(MapEntry.get()->second != nullptr); + assert(cast(MapEntry)->second != nullptr); } explicit operator bool() const { return !MapEntry.isNull(); } @@ -85,18 +85,18 @@ /// \returns string. StringRef getString() const { - if (MapEntry.is()) - return MapEntry.get()->first(); + if (isa(MapEntry)) + return cast(MapEntry)->first(); - return MapEntry.get()->first(); + return cast(MapEntry)->first(); } /// \returns the entire string pool entry for convenience. const DwarfStringPoolEntry &getEntry() const { - if (MapEntry.is()) - return MapEntry.get()->second; + if (isa(MapEntry)) + return cast(MapEntry)->second; - return *MapEntry.get()->second; + return *cast(MapEntry)->second; } bool operator==(const DwarfStringPoolEntryRef &X) const { diff --git a/llvm/include/llvm/CodeGen/MachineMemOperand.h b/llvm/include/llvm/CodeGen/MachineMemOperand.h --- a/llvm/include/llvm/CodeGen/MachineMemOperand.h +++ b/llvm/include/llvm/CodeGen/MachineMemOperand.h @@ -69,19 +69,19 @@ uint8_t ID = 0) : V(v), Offset(offset), StackID(ID) { if (V) { - if (const auto *ValPtr = V.dyn_cast()) + if (const auto *ValPtr = dyn_cast_if_present(V)) AddrSpace = ValPtr->getType()->getPointerAddressSpace(); else - AddrSpace = V.get()->getAddressSpace(); + AddrSpace = cast(V)->getAddressSpace(); } } MachinePointerInfo getWithOffset(int64_t O) const { if (V.isNull()) return MachinePointerInfo(AddrSpace, Offset + O); - if (V.is()) - return MachinePointerInfo(V.get(), Offset + O, StackID); - return MachinePointerInfo(V.get(), Offset + O, + if (isa(V)) + return MachinePointerInfo(cast(V), Offset + O, StackID); + return MachinePointerInfo(cast(V), Offset + O, StackID); } @@ -207,10 +207,12 @@ /// other PseudoSourceValue member functions which return objects which stand /// for frame/stack pointer relative references and other special references /// which are not representable in the high-level IR. - const Value *getValue() const { return PtrInfo.V.dyn_cast(); } + const Value *getValue() const { + return dyn_cast_if_present(PtrInfo.V); + } const PseudoSourceValue *getPseudoValue() const { - return PtrInfo.V.dyn_cast(); + return dyn_cast_if_present(PtrInfo.V); } const void *getOpaqueValue() const { return PtrInfo.V.getOpaqueValue(); } diff --git a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h --- a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h @@ -660,9 +660,9 @@ /// This shouldn't be used directly unless \p Reg has a register class. /// \see getRegClassOrNull when this might happen. const TargetRegisterClass *getRegClass(Register Reg) const { - assert(VRegInfo[Reg.id()].first.is() && + assert(isa(VRegInfo[Reg.id()].first) && "Register class not set, wrong accessor"); - return VRegInfo[Reg.id()].first.get(); + return cast(VRegInfo[Reg.id()].first); } /// Return the register class of \p Reg, or null if Reg has not been assigned @@ -678,7 +678,7 @@ /// the select pass, using getRegClass is safe. const TargetRegisterClass *getRegClassOrNull(Register Reg) const { const RegClassOrRegBank &Val = VRegInfo[Reg].first; - return Val.dyn_cast(); + return dyn_cast_if_present(Val); } /// Return the register bank of \p Reg, or null if Reg has not been assigned @@ -687,7 +687,7 @@ /// RegisterBankInfo::getRegBankFromRegClass. const RegisterBank *getRegBankOrNull(Register Reg) const { const RegClassOrRegBank &Val = VRegInfo[Reg].first; - return Val.dyn_cast(); + return dyn_cast_if_present(Val); } /// Return the register bank or register class of \p Reg. diff --git a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h --- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h +++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h @@ -2942,7 +2942,7 @@ return ArrayRef(MemRefs.getAddrOfPtr1(), 1); // Otherwise we have an actual array. - return ArrayRef(MemRefs.get(), NumMemRefs); + return ArrayRef(cast(MemRefs), NumMemRefs); } mmo_iterator memoperands_begin() const { return memoperands().begin(); } mmo_iterator memoperands_end() const { return memoperands().end(); } diff --git a/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h b/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h --- a/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h +++ b/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h @@ -38,14 +38,14 @@ // Helper functions const BasicBlock *getUnwindDest(const BasicBlock *BB) const { assert(hasUnwindDest(BB)); - return SrcToUnwindDest.lookup(BB).get(); + return cast(SrcToUnwindDest.lookup(BB)); } SmallPtrSet getUnwindSrcs(const BasicBlock *BB) const { assert(hasUnwindSrcs(BB)); const auto &Set = UnwindDestToSrcs.lookup(BB); SmallPtrSet Ret; for (const auto P : Set) - Ret.insert(P.get()); + Ret.insert(cast(P)); return Ret; } void setUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) { @@ -61,7 +61,7 @@ MachineBasicBlock *getUnwindDest(MachineBasicBlock *MBB) const { assert(hasUnwindDest(MBB)); - return SrcToUnwindDest.lookup(MBB).get(); + return cast(SrcToUnwindDest.lookup(MBB)); } SmallPtrSet getUnwindSrcs(MachineBasicBlock *MBB) const { @@ -69,7 +69,7 @@ const auto &Set = UnwindDestToSrcs.lookup(MBB); SmallPtrSet Ret; for (const auto P : Set) - Ret.insert(P.get()); + Ret.insert(cast(P)); return Ret; } void setUnwindDest(MachineBasicBlock *MBB, MachineBasicBlock *Dest) { diff --git a/llvm/include/llvm/IR/GetElementPtrTypeIterator.h b/llvm/include/llvm/IR/GetElementPtrTypeIterator.h --- a/llvm/include/llvm/IR/GetElementPtrTypeIterator.h +++ b/llvm/include/llvm/IR/GetElementPtrTypeIterator.h @@ -68,9 +68,9 @@ // temporarily not giving this iterator an operator*() to avoid a subtle // semantics break. Type *getIndexedType() const { - if (auto *T = CurTy.dyn_cast()) + if (auto *T = dyn_cast_if_present(CurTy)) return T; - return CurTy.get()->getTypeAtIndex(getOperand()); + return cast(CurTy)->getTypeAtIndex(getOperand()); } Value *getOperand() const { return const_cast(&**OpIt); } @@ -108,13 +108,13 @@ // we should provide a more minimal API here that exposes not much more than // that. - bool isStruct() const { return CurTy.is(); } - bool isSequential() const { return CurTy.is(); } + bool isStruct() const { return isa(CurTy); } + bool isSequential() const { return isa(CurTy); } - StructType *getStructType() const { return CurTy.get(); } + StructType *getStructType() const { return cast(CurTy); } StructType *getStructTypeOrNull() const { - return CurTy.dyn_cast(); + return dyn_cast_if_present(CurTy); } }; diff --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h --- a/llvm/include/llvm/IR/IntrinsicInst.h +++ b/llvm/include/llvm/IR/IntrinsicInst.h @@ -195,29 +195,29 @@ } bool operator==(const location_op_iterator &RHS) const { return I == RHS.I; } const Value *operator*() const { - ValueAsMetadata *VAM = I.is() - ? I.get() - : *I.get(); + ValueAsMetadata *VAM = isa(I) + ? cast(I) + : *cast(I); return VAM->getValue(); }; Value *operator*() { - ValueAsMetadata *VAM = I.is() - ? I.get() - : *I.get(); + ValueAsMetadata *VAM = isa(I) + ? cast(I) + : *cast(I); return VAM->getValue(); } location_op_iterator &operator++() { - if (I.is()) - I = I.get() + 1; + if (isa(I)) + I = cast(I) + 1; else - I = I.get() + 1; + I = cast(I) + 1; return *this; } location_op_iterator &operator--() { - if (I.is()) - I = I.get() - 1; + if (isa(I)) + I = cast(I) - 1; else - I = I.get() - 1; + I = cast(I) - 1; return *this; } }; 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 @@ -861,18 +861,18 @@ /// Whether this contains RAUW support. bool hasReplaceableUses() const { - return Ptr.is(); + return isa(Ptr); } LLVMContext &getContext() const { if (hasReplaceableUses()) return getReplaceableUses()->getContext(); - return *Ptr.get(); + return *cast(Ptr); } ReplaceableMetadataImpl *getReplaceableUses() const { if (hasReplaceableUses()) - return Ptr.get(); + return cast(Ptr); return nullptr; } diff --git a/llvm/include/llvm/Transforms/Utils/Evaluator.h b/llvm/include/llvm/Transforms/Utils/Evaluator.h --- a/llvm/include/llvm/Transforms/Utils/Evaluator.h +++ b/llvm/include/llvm/Transforms/Utils/Evaluator.h @@ -55,15 +55,15 @@ ~MutableValue() { clear(); } Type *getType() const { - if (auto *C = Val.dyn_cast()) + if (auto *C = dyn_cast_if_present(Val)) return C->getType(); - return Val.get()->Ty; + return cast(Val)->Ty; } Constant *toConstant() const { - if (auto *C = Val.dyn_cast()) + if (auto *C = dyn_cast_if_present(Val)) return C; - return Val.get()->toConstant(); + return cast(Val)->toConstant(); } Constant *read(Type *Ty, APInt Offset, const DataLayout &DL) const; 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 @@ -1719,12 +1719,13 @@ // Otherwise, if it has an upperboud, use (upperbound - lowerbound + 1), // where lowerbound is from the LowerBound field of the Subrange, // or the language default lowerbound if that field is unspecified. - if (auto *CI = Subrange->getCount().dyn_cast()) + if (auto *CI = dyn_cast_if_present(Subrange->getCount())) Count = CI->getSExtValue(); - else if (auto *UI = Subrange->getUpperBound().dyn_cast()) { + else if (auto *UI = dyn_cast_if_present( + Subrange->getUpperBound())) { // Fortran uses 1 as the default lowerbound; other languages use 0. int64_t Lowerbound = (moduleIsInFortran()) ? 1 : 0; - auto *LI = Subrange->getLowerBound().dyn_cast(); + auto *LI = dyn_cast_if_present(Subrange->getLowerBound()); Lowerbound = (LI) ? LI->getSExtValue() : Lowerbound; Count = UI->getSExtValue() - Lowerbound + 1; } @@ -3283,7 +3284,7 @@ // Second, emit each global that is in a comdat into its own .debug$S // section along with its own symbol substream. for (const CVGlobalVariable &CVGV : ComdatVariables) { - const GlobalVariable *GV = CVGV.GVInfo.get(); + const GlobalVariable *GV = cast(CVGV.GVInfo); MCSymbol *GVSym = Asm->getSymbol(GV); OS.AddComment("Symbol subsection for " + Twine(GlobalValue::dropLLVMManglingEscape(GV->getName()))); @@ -3392,7 +3393,7 @@ : getFullyQualifiedName(Scope, DIGV->getName()); if (const GlobalVariable *GV = - CVGV.GVInfo.dyn_cast()) { + dyn_cast_if_present(CVGV.GVInfo)) { // DataSym record, see SymbolRecord.h for more info. Thread local data // happens to have the same format as global data. MCSymbol *GVSym = Asm->getSymbol(GV); @@ -3419,7 +3420,7 @@ emitNullTerminatedSymbolName(OS, QualifiedName, LengthOfDataRecord); endSymbolRecord(DataEnd); } else { - const DIExpression *DIE = CVGV.GVInfo.get(); + const DIExpression *DIE = cast(CVGV.GVInfo); assert(DIE->isConstant() && "Global constant variables must contain a constant expression."); diff --git a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp @@ -173,9 +173,7 @@ // DIE Implementation //===----------------------------------------------------------------------===// -DIE *DIE::getParent() const { - return Owner.dyn_cast(); -} +DIE *DIE::getParent() const { return dyn_cast_if_present(Owner); } DIEAbbrev DIE::generateAbbrev() const { DIEAbbrev Abbrev(Tag, hasChildren()); @@ -209,7 +207,7 @@ DIEUnit *DIE::getUnit() const { const DIE *UnitDie = getUnitDie(); if (UnitDie) - return UnitDie->Owner.dyn_cast(); + return dyn_cast_if_present(UnitDie->Owner); return nullptr; } diff --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp --- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp @@ -958,29 +958,29 @@ for (auto *El : Array->getElements()) { if (auto *Subrange = dyn_cast(El)) { if (auto Count = Subrange->getCount()) - if (auto *Dependency = Count.dyn_cast()) + if (auto *Dependency = dyn_cast_if_present(Count)) Result.push_back(Dependency); if (auto LB = Subrange->getLowerBound()) - if (auto *Dependency = LB.dyn_cast()) + if (auto *Dependency = dyn_cast_if_present(LB)) Result.push_back(Dependency); if (auto UB = Subrange->getUpperBound()) - if (auto *Dependency = UB.dyn_cast()) + if (auto *Dependency = dyn_cast_if_present(UB)) Result.push_back(Dependency); if (auto ST = Subrange->getStride()) - if (auto *Dependency = ST.dyn_cast()) + if (auto *Dependency = dyn_cast_if_present(ST)) Result.push_back(Dependency); } else if (auto *GenericSubrange = dyn_cast(El)) { if (auto Count = GenericSubrange->getCount()) - if (auto *Dependency = Count.dyn_cast()) + if (auto *Dependency = dyn_cast_if_present(Count)) Result.push_back(Dependency); if (auto LB = GenericSubrange->getLowerBound()) - if (auto *Dependency = LB.dyn_cast()) + if (auto *Dependency = dyn_cast_if_present(LB)) Result.push_back(Dependency); if (auto UB = GenericSubrange->getUpperBound()) - if (auto *Dependency = UB.dyn_cast()) + if (auto *Dependency = dyn_cast_if_present(UB)) Result.push_back(Dependency); if (auto ST = GenericSubrange->getStride()) - if (auto *Dependency = ST.dyn_cast()) + if (auto *Dependency = dyn_cast_if_present(ST)) Result.push_back(Dependency); } } 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 @@ -1362,16 +1362,16 @@ auto AddBoundTypeEntry = [&](dwarf::Attribute Attr, DISubrange::BoundType Bound) -> void { - if (auto *BV = Bound.dyn_cast()) { + if (auto *BV = dyn_cast_if_present(Bound)) { if (auto *VarDIE = getDIE(BV)) addDIEEntry(DW_Subrange, Attr, *VarDIE); - } else if (auto *BE = Bound.dyn_cast()) { + } else if (auto *BE = dyn_cast_if_present(Bound)) { DIELoc *Loc = new (DIEValueAllocator) DIELoc; DIEDwarfExpression DwarfExpr(*Asm, getCU(), *Loc); DwarfExpr.setMemoryLocationKind(); DwarfExpr.addExpression(BE); addBlock(DW_Subrange, Attr, DwarfExpr.finalize()); - } else if (auto *BI = Bound.dyn_cast()) { + } else if (auto *BI = dyn_cast_if_present(Bound)) { if (Attr == dwarf::DW_AT_count) { if (BI->getSExtValue() != -1) addUInt(DW_Subrange, Attr, std::nullopt, BI->getSExtValue()); @@ -1401,10 +1401,10 @@ auto AddBoundTypeEntry = [&](dwarf::Attribute Attr, DIGenericSubrange::BoundType Bound) -> void { - if (auto *BV = Bound.dyn_cast()) { + if (auto *BV = dyn_cast_if_present(Bound)) { if (auto *VarDIE = getDIE(BV)) addDIEEntry(DwGenericSubrange, Attr, *VarDIE); - } else if (auto *BE = Bound.dyn_cast()) { + } else if (auto *BE = dyn_cast_if_present(Bound)) { if (BE->isConstant() && DIExpression::SignedOrUnsignedConstant::SignedConstant == *BE->isConstant()) { @@ -1463,7 +1463,7 @@ const auto Subrange = cast(Elements[0]); const auto NumVecElements = Subrange->getCount() - ? Subrange->getCount().get()->getSExtValue() + ? cast(Subrange->getCount())->getSExtValue() : 0; // Ensure we found the element count and that the actual size is wide diff --git a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp --- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp @@ -638,7 +638,7 @@ const SEHUnwindMapEntry &UME = FuncInfo.SEHUnwindMap[State]; const MCExpr *FilterOrFinally; const MCExpr *ExceptOrNull; - auto *Handler = UME.Handler.get(); + auto *Handler = cast(UME.Handler); if (UME.IsFinally) { FilterOrFinally = create32bitRef(getMCSymbolForMBB(Asm, Handler)); ExceptOrNull = MCConstantExpr::create(0, Ctx); @@ -775,8 +775,8 @@ if (UnwindMapXData) { OS.emitLabel(UnwindMapXData); for (const CxxUnwindMapEntry &UME : FuncInfo.CxxUnwindMap) { - MCSymbol *CleanupSym = - getMCSymbolForMBB(Asm, UME.Cleanup.dyn_cast()); + MCSymbol *CleanupSym = getMCSymbolForMBB( + Asm, dyn_cast_if_present(UME.Cleanup)); AddComment("ToState"); OS.emitInt32(UME.ToState); @@ -863,8 +863,8 @@ FrameAllocOffsetRef = MCConstantExpr::create(0, Asm->OutContext); } - MCSymbol *HandlerSym = - getMCSymbolForMBB(Asm, HT.Handler.dyn_cast()); + MCSymbol *HandlerSym = getMCSymbolForMBB( + Asm, dyn_cast_if_present(HT.Handler)); AddComment("Adjectives"); OS.emitInt32(HT.Adjectives); @@ -1069,7 +1069,7 @@ assert(!FuncInfo.SEHUnwindMap.empty()); for (const SEHUnwindMapEntry &UME : FuncInfo.SEHUnwindMap) { - auto *Handler = UME.Handler.get(); + auto *Handler = cast(UME.Handler); const MCSymbol *ExceptOrFinally = UME.IsFinally ? getMCSymbolForMBB(Asm, Handler) : Handler->getSymbol(); // -1 is usually the base state for "unwind to caller", but for @@ -1140,7 +1140,7 @@ DenseMap HandlerStates; for (int State = 0; State < NumStates; ++State) { MachineBasicBlock *HandlerBlock = - FuncInfo.ClrEHUnwindMap[State].Handler.get(); + cast(FuncInfo.ClrEHUnwindMap[State].Handler); HandlerStates[HandlerBlock] = State; // Use this loop through all handlers to verify our assumption (used in // the MinEnclosingState computation) that enclosing funclets have lower @@ -1301,7 +1301,7 @@ const MCExpr *ClauseEnd = getOffsetPlusOne(Clause.EndLabel, FuncBeginSym); const ClrEHUnwindMapEntry &Entry = FuncInfo.ClrEHUnwindMap[Clause.State]; - MachineBasicBlock *HandlerBlock = Entry.Handler.get(); + MachineBasicBlock *HandlerBlock = cast(Entry.Handler); MCSymbol *BeginSym = getMCSymbolForMBB(Asm, HandlerBlock); const MCExpr *HandlerBegin = getOffset(BeginSym, FuncBeginSym); MCSymbol *EndSym = EndSymbolMap[Clause.State]; diff --git a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp --- a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp +++ b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp @@ -396,9 +396,10 @@ addNodeIDRegType(Ty); if (const RegClassOrRegBank &RCOrRB = MRI.getRegClassOrRegBank(Reg)) { - if (const auto *RB = RCOrRB.dyn_cast()) + if (const auto *RB = dyn_cast_if_present(RCOrRB)) addNodeIDRegType(RB); - else if (const auto *RC = RCOrRB.dyn_cast()) + else if (const auto *RC = + dyn_cast_if_present(RCOrRB)) addNodeIDRegType(RC); } return *this; 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 @@ -711,14 +711,14 @@ Align llvm::inferAlignFromPtrInfo(MachineFunction &MF, const MachinePointerInfo &MPO) { - auto PSV = MPO.V.dyn_cast(); + auto PSV = dyn_cast_if_present(MPO.V); if (auto FSPV = dyn_cast_or_null(PSV)) { MachineFrameInfo &MFI = MF.getFrameInfo(); return commonAlignment(MFI.getObjectAlign(FSPV->getFrameIndex()), MPO.Offset); } - if (const Value *V = MPO.V.dyn_cast()) { + if (const Value *V = dyn_cast_if_present(MPO.V)) { const Module *M = MF.getFunction().getParent(); return V->getPointerAlignment(M->getDataLayout()); } diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp --- a/llvm/lib/CodeGen/MachineOperand.cpp +++ b/llvm/lib/CodeGen/MachineOperand.cpp @@ -1027,10 +1027,10 @@ /// Offset + Size byte. bool MachinePointerInfo::isDereferenceable(unsigned Size, LLVMContext &C, const DataLayout &DL) const { - if (!V.is()) + if (!isa(V)) return false; - const Value *BasePtr = V.get(); + const Value *BasePtr = cast(V); if (BasePtr == nullptr) return false; @@ -1075,8 +1075,8 @@ AtomicOrdering FailureOrdering) : PtrInfo(ptrinfo), MemoryType(type), FlagVals(f), BaseAlign(a), AAInfo(AAInfo), Ranges(Ranges) { - assert((PtrInfo.V.isNull() || PtrInfo.V.is() || - isa(PtrInfo.V.get()->getType())) && + assert((PtrInfo.V.isNull() || isa(PtrInfo.V) || + isa(cast(PtrInfo.V)->getType())) && "invalid pointer value"); assert((isLoad() || isStore()) && "Not a load/store!"); diff --git a/llvm/lib/CodeGen/MachineRegisterInfo.cpp b/llvm/lib/CodeGen/MachineRegisterInfo.cpp --- a/llvm/lib/CodeGen/MachineRegisterInfo.cpp +++ b/llvm/lib/CodeGen/MachineRegisterInfo.cpp @@ -101,13 +101,13 @@ const auto RegCB = getRegClassOrRegBank(Reg); if (RegCB.isNull()) setRegClassOrRegBank(Reg, ConstrainingRegCB); - else if (RegCB.is() != - ConstrainingRegCB.is()) + else if (isa(RegCB) != + isa(ConstrainingRegCB)) return false; - else if (RegCB.is()) { + else if (isa(RegCB)) { if (!::constrainRegClass( - *this, Reg, RegCB.get(), - ConstrainingRegCB.get(), MinNumRegs)) + *this, Reg, cast(RegCB), + cast(ConstrainingRegCB), MinNumRegs)) return false; } else if (RegCB != ConstrainingRegCB) return false; diff --git a/llvm/lib/CodeGen/RegisterBankInfo.cpp b/llvm/lib/CodeGen/RegisterBankInfo.cpp --- a/llvm/lib/CodeGen/RegisterBankInfo.cpp +++ b/llvm/lib/CodeGen/RegisterBankInfo.cpp @@ -87,9 +87,10 @@ } const RegClassOrRegBank &RegClassOrBank = MRI.getRegClassOrRegBank(Reg); - if (auto *RB = RegClassOrBank.dyn_cast()) + if (auto *RB = dyn_cast_if_present(RegClassOrBank)) return RB; - if (auto *RC = RegClassOrBank.dyn_cast()) + if (auto *RC = + dyn_cast_if_present(RegClassOrBank)) return &getRegBankFromRegClass(*RC, MRI.getType(Reg)); return nullptr; } @@ -131,10 +132,10 @@ // If the register already has a class, fallback to MRI::constrainRegClass. auto &RegClassOrBank = MRI.getRegClassOrRegBank(Reg); - if (RegClassOrBank.is()) + if (isa(RegClassOrBank)) return MRI.constrainRegClass(Reg, &RC); - const RegisterBank *RB = RegClassOrBank.get(); + const RegisterBank *RB = cast(RegClassOrBank); // Otherwise, all we can do is ensure the bank covers the class, and set it. if (RB && !RB->covers(RC)) return nullptr; diff --git a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp --- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp +++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp @@ -1026,15 +1026,14 @@ void ScheduleDAGInstrs::Value2SUsMap::dump() { for (const auto &[ValType, SUs] : *this) { - if (ValType.is()) { - const Value *V = ValType.get(); + if (isa(ValType)) { + const Value *V = cast(ValType); if (isa(V)) dbgs() << "Unknown"; else V->printAsOperand(dbgs()); - } - else if (ValType.is()) - dbgs() << ValType.get(); + } else if (isa(ValType)) + dbgs() << cast(ValType); else llvm_unreachable("Unknown Value type."); diff --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp --- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp @@ -292,18 +292,18 @@ for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) { for (WinEHHandlerType &H : TBME.HandlerArray) { if (H.Handler) - H.Handler = MBBMap[H.Handler.get()]; + H.Handler = MBBMap[cast(H.Handler)]; } } for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap) if (UME.Cleanup) - UME.Cleanup = MBBMap[UME.Cleanup.get()]; + UME.Cleanup = MBBMap[cast(UME.Cleanup)]; for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap) { - const auto *BB = UME.Handler.get(); + const auto *BB = cast(UME.Handler); UME.Handler = MBBMap[BB]; } for (ClrEHUnwindMapEntry &CME : EHInfo.ClrEHUnwindMap) { - const auto *BB = CME.Handler.get(); + const auto *BB = cast(CME.Handler); CME.Handler = MBBMap[BB]; } } else if (Personality == EHPersonality::Wasm_CXX) { @@ -313,18 +313,18 @@ // Map all BB references in the Wasm EH data to MBBs. DenseMap SrcToUnwindDest; for (auto &KV : EHInfo.SrcToUnwindDest) { - const auto *Src = KV.first.get(); - const auto *Dest = KV.second.get(); + const auto *Src = cast(KV.first); + const auto *Dest = cast(KV.second); SrcToUnwindDest[MBBMap[Src]] = MBBMap[Dest]; } EHInfo.SrcToUnwindDest = std::move(SrcToUnwindDest); DenseMap> UnwindDestToSrcs; for (auto &KV : EHInfo.UnwindDestToSrcs) { - const auto *Dest = KV.first.get(); + const auto *Dest = cast(KV.first); UnwindDestToSrcs[MBBMap[Dest]] = SmallPtrSet(); for (const auto P : KV.second) UnwindDestToSrcs[MBBMap[Dest]].insert( - MBBMap[P.get()]); + MBBMap[cast(P)]); } EHInfo.UnwindDestToSrcs = std::move(UnwindDestToSrcs); } 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 @@ -7125,7 +7125,7 @@ AAMDNodes NewAAInfo = AAInfo; NewAAInfo.TBAA = NewAAInfo.TBAAStruct = nullptr; - const Value *SrcVal = SrcPtrInfo.V.dyn_cast(); + const Value *SrcVal = dyn_cast_if_present(SrcPtrInfo.V); bool isConstant = AA && SrcVal && AA->pointsToConstantMemory(MemoryLocation(SrcVal, Size, AAInfo)); diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h @@ -119,25 +119,25 @@ : Info(VarLoc), SDNodeOrder(SDNO) {} DILocalVariable *getVariable(const FunctionVarLocs *Locs) const { - if (Info.is()) - return Locs->getDILocalVariable(Info.get()->VariableID); - return Info.get()->getVariable(); + if (isa(Info)) + return Locs->getDILocalVariable(cast(Info)->VariableID); + return cast(Info)->getVariable(); } DIExpression *getExpression() const { - if (Info.is()) - return Info.get()->Expr; - return Info.get()->getExpression(); + if (isa(Info)) + return cast(Info)->Expr; + return cast(Info)->getExpression(); } Value *getVariableLocationOp(unsigned Idx) const { assert(Idx == 0 && "Dangling variadic debug values not supported yet"); - if (Info.is()) - return Info.get()->Values.getVariableLocationOp(Idx); - return Info.get()->getVariableLocationOp(Idx); + if (isa(Info)) + return cast(Info)->Values.getVariableLocationOp(Idx); + return cast(Info)->getVariableLocationOp(Idx); } DebugLoc getDebugLoc() const { - if (Info.is()) - return Info.get()->DL; - return Info.get()->getDebugLoc(); + if (isa(Info)) + return cast(Info)->DL; + return cast(Info)->getDebugLoc(); } unsigned getSDNodeOrder() const { return SDNodeOrder; } 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 @@ -737,7 +737,7 @@ // so visit pads in descendant-most to ancestor-most order. for (ClrEHUnwindMapEntry &Entry : llvm::reverse(FuncInfo.ClrEHUnwindMap)) { const Instruction *Pad = - Entry.Handler.get()->getFirstNonPHI(); + cast(Entry.Handler)->getFirstNonPHI(); // For most pads, the TryParentState is the state associated with the // unwind dest of exceptional exits from it. const BasicBlock *UnwindDest; @@ -773,8 +773,8 @@ int UserUnwindState = FuncInfo.ClrEHUnwindMap[UserState].TryParentState; if (UserUnwindState != -1) - UserUnwindDest = FuncInfo.ClrEHUnwindMap[UserUnwindState] - .Handler.get(); + UserUnwindDest = cast( + FuncInfo.ClrEHUnwindMap[UserUnwindState].Handler); } // Not having an unwind dest for this user might indicate that it diff --git a/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp b/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp --- a/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp +++ b/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp @@ -41,8 +41,8 @@ PdbOrObj &Input, StringRef FileFormatName, StringRef ExePath) { auto CreateOneReader = [&]() -> std::unique_ptr { - if (Input.is()) { - ObjectFile &Obj = *Input.get(); + if (isa(Input)) { + ObjectFile &Obj = *cast(Input); if (Obj.isCOFF()) { COFFObjectFile *COFF = cast(&Obj); return std::make_unique(Filename, FileFormatName, @@ -51,8 +51,8 @@ if (Obj.isELF() || Obj.isMachO()) return std::make_unique(Filename, FileFormatName, Obj, W); } - if (Input.is()) { - PDBFile &Pdb = *Input.get(); + if (isa(Input)) { + PDBFile &Pdb = *cast(Input); return std::make_unique(Filename, FileFormatName, Pdb, W, ExePath); } @@ -243,7 +243,7 @@ Binary &Binary) { if (PdbOrObj Input = dyn_cast(&Binary)) return createReader(Filename, Readers, Input, - Input.get()->getFileFormatName()); + cast(Input)->getFileFormatName()); if (MachOUniversalBinary *Fat = dyn_cast(&Binary)) return handleMach(Readers, Filename, *Fat); diff --git a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp --- a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp +++ b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp @@ -347,32 +347,32 @@ PDBFile &InputFile::pdb() { assert(isPdb()); - return *PdbOrObj.get(); + return *cast(PdbOrObj); } const PDBFile &InputFile::pdb() const { assert(isPdb()); - return *PdbOrObj.get(); + return *cast(PdbOrObj); } object::COFFObjectFile &InputFile::obj() { assert(isObj()); - return *PdbOrObj.get(); + return *cast(PdbOrObj); } const object::COFFObjectFile &InputFile::obj() const { assert(isObj()); - return *PdbOrObj.get(); + return *cast(PdbOrObj); } MemoryBuffer &InputFile::unknown() { assert(isUnknown()); - return *PdbOrObj.get(); + return *cast(PdbOrObj); } const MemoryBuffer &InputFile::unknown() const { assert(isUnknown()); - return *PdbOrObj.get(); + return *cast(PdbOrObj); } StringRef InputFile::getFilePath() const { @@ -402,13 +402,13 @@ return pdb().hasPDBIpiStream(); } -bool InputFile::isPdb() const { return PdbOrObj.is(); } +bool InputFile::isPdb() const { return isa(PdbOrObj); } bool InputFile::isObj() const { - return PdbOrObj.is(); + return isa(PdbOrObj); } -bool InputFile::isUnknown() const { return PdbOrObj.is(); } +bool InputFile::isUnknown() const { return isa(PdbOrObj); } codeview::LazyRandomTypeCollection & InputFile::getOrCreateTypeCollection(TypeCollectionKind Kind) { 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 @@ -582,14 +582,14 @@ VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, DINode::FlagZero, Subscripts, 0, nullptr, nullptr, "", nullptr, - DL.is() ? (Metadata *)DL.get() - : (Metadata *)DL.get(), - AS.is() ? (Metadata *)AS.get() - : (Metadata *)AS.get(), - AL.is() ? (Metadata *)AL.get() - : (Metadata *)AL.get(), - RK.is() ? (Metadata *)RK.get() - : (Metadata *)RK.get()); + isa(DL) ? (Metadata *)cast(DL) + : (Metadata *)cast(DL), + isa(AS) ? (Metadata *)cast(AS) + : (Metadata *)cast(AS), + isa(AL) ? (Metadata *)cast(AL) + : (Metadata *)cast(AL), + isa(RK) ? (Metadata *)cast(RK) + : (Metadata *)cast(RK)); trackIfUnresolved(R); return R; } @@ -714,8 +714,8 @@ DIGenericSubrange::BoundType CountNode, DIGenericSubrange::BoundType LB, DIGenericSubrange::BoundType UB, DIGenericSubrange::BoundType Stride) { auto ConvToMetadata = [&](DIGenericSubrange::BoundType Bound) -> Metadata * { - return Bound.is() ? (Metadata *)Bound.get() - : (Metadata *)Bound.get(); + return isa(Bound) ? (Metadata *)cast(Bound) + : (Metadata *)cast(Bound); }; return DIGenericSubrange::get(VMContext, ConvToMetadata(CountNode), ConvToMetadata(LB), ConvToMetadata(UB), 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 @@ -195,9 +195,9 @@ SmallVector *> MDUsersWithID; for (auto Pair : UseMap) { OwnerTy Owner = Pair.second.first; - if (!Owner.is()) + if (!isa(Owner)) continue; - Metadata *OwnerMD = Owner.get(); + Metadata *OwnerMD = cast(Owner); if (OwnerMD->getMetadataID() == Metadata::DIArgListKind) MDUsersWithID.push_back(&UseMap[Pair.first]); } @@ -206,7 +206,7 @@ }); SmallVector MDUsers; for (auto *UserWithID : MDUsersWithID) - MDUsers.push_back(UserWithID->first.get()); + MDUsers.push_back(cast(UserWithID->first)); return MDUsers; } @@ -263,9 +263,9 @@ MetadataTracking::OwnerTy Owner = Pair.second.first; if (!Owner) continue; - if (!Owner.is()) + if (!isa(Owner)) continue; - auto *OwnerMD = dyn_cast(Owner.get()); + auto *OwnerMD = dyn_cast_if_present(cast(Owner)); if (!OwnerMD) continue; if (isa(OwnerMD)) { @@ -301,13 +301,13 @@ } // Check for MetadataAsValue. - if (Owner.is()) { - Owner.get()->handleChangedMetadata(MD); + if (isa(Owner)) { + cast(Owner)->handleChangedMetadata(MD); continue; } // There's a Metadata owner -- dispatch. - Metadata *OwnerMD = Owner.get(); + Metadata *OwnerMD = cast(Owner); switch (OwnerMD->getMetadataID()) { #define HANDLE_METADATA_LEAF(CLASS) \ case Metadata::CLASS##Kind: \ @@ -341,11 +341,11 @@ auto Owner = Pair.second.first; if (!Owner) continue; - if (Owner.is()) + if (isa(Owner)) continue; // Resolve MDNodes that point at this. - auto *OwnerMD = dyn_cast(Owner.get()); + auto *OwnerMD = dyn_cast_if_present(cast(Owner)); if (!OwnerMD) continue; if (OwnerMD->isResolved()) 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 @@ -1075,8 +1075,8 @@ isa(CBound) || isa(CBound), "Count must be signed constant or DIVariable or DIExpression", &N); auto Count = N.getCount(); - CheckDI(!Count || !Count.is() || - Count.get()->getSExtValue() >= -1, + CheckDI(!Count || !isa(Count) || + cast(Count)->getSExtValue() >= -1, "invalid subrange count", &N); auto *LBound = N.getRawLowerBound(); CheckDI(!LBound || isa(LBound) || 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 @@ -788,7 +788,7 @@ ModuleSymbolTable::Symbol Msym = *MsymI++; Skip(); - if (GlobalValue *GV = Msym.dyn_cast()) { + if (GlobalValue *GV = dyn_cast_if_present(Msym)) { if (Res.Prevailing) { if (Sym.isUndefined()) continue; @@ -826,7 +826,8 @@ GV->setDLLStorageClass(GlobalValue::DLLStorageClassTypes:: DefaultStorageClass); } - } else if (auto *AS = Msym.dyn_cast()) { + } else if (auto *AS = + dyn_cast_if_present(Msym)) { // Collect non-prevailing symbols. if (!Res.Prevailing) NonPrevailingAsmSymbols.insert(AS->first); diff --git a/llvm/lib/LTO/LTOModule.cpp b/llvm/lib/LTO/LTOModule.cpp --- a/llvm/lib/LTO/LTOModule.cpp +++ b/llvm/lib/LTO/LTOModule.cpp @@ -348,7 +348,7 @@ Buffer.c_str(); } - const GlobalValue *V = Sym.get(); + const GlobalValue *V = cast(Sym); addDefinedDataSymbol(Buffer, V); } @@ -406,7 +406,7 @@ Buffer.c_str(); } - const Function *F = cast(Sym.get()); + const Function *F = cast(cast(Sym)); addDefinedFunctionSymbol(Buffer, F); } @@ -556,7 +556,7 @@ info.name = IterBool.first->first(); - const GlobalValue *decl = Sym.dyn_cast(); + const GlobalValue *decl = dyn_cast_if_present(Sym); if (decl->hasExternalWeakLinkage()) info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF; @@ -569,7 +569,7 @@ void LTOModule::parseSymbols() { for (auto Sym : SymTab.symbols()) { - auto *GV = Sym.dyn_cast(); + auto *GV = dyn_cast_if_present(Sym); uint32_t Flags = SymTab.getSymbolFlags(Sym); if (Flags & object::BasicSymbolRef::SF_FormatSpecific) continue; @@ -691,7 +691,7 @@ bool LTOModule::hasCtorDtor() const { for (auto Sym : SymTab.symbols()) { - if (auto *GV = Sym.dyn_cast()) { + if (auto *GV = dyn_cast_if_present(Sym)) { StringRef Name = GV->getName(); if (Name.consume_front("llvm.global_")) { if (Name.equals("ctors") || Name.equals("dtors")) diff --git a/llvm/lib/Object/IRSymtab.cpp b/llvm/lib/Object/IRSymtab.cpp --- a/llvm/lib/Object/IRSymtab.cpp +++ b/llvm/lib/Object/IRSymtab.cpp @@ -259,7 +259,7 @@ Sym.Flags |= 1 << storage::Symbol::FB_executable; Sym.ComdatIndex = -1; - auto *GV = Msym.dyn_cast(); + auto *GV = dyn_cast_if_present(Msym); if (!GV) { // Undefined module asm symbols act as GC roots and are implicitly used. if (Flags & object::BasicSymbolRef::SF_Undefined) diff --git a/llvm/lib/Object/ModuleSymbolTable.cpp b/llvm/lib/Object/ModuleSymbolTable.cpp --- a/llvm/lib/Object/ModuleSymbolTable.cpp +++ b/llvm/lib/Object/ModuleSymbolTable.cpp @@ -174,12 +174,12 @@ } void ModuleSymbolTable::printSymbolName(raw_ostream &OS, Symbol S) const { - if (S.is()) { - OS << S.get()->first; + if (isa(S)) { + OS << cast(S)->first; return; } - auto *GV = S.get(); + auto *GV = cast(S); if (GV->hasDLLImportStorageClass()) OS << "__imp_"; @@ -187,10 +187,10 @@ } uint32_t ModuleSymbolTable::getSymbolFlags(Symbol S) const { - if (S.is()) - return S.get()->second; + if (isa(S)) + return cast(S)->second; - auto *GV = S.get(); + auto *GV = cast(S); uint32_t Res = BasicSymbolRef::SF_None; if (GV->isDeclarationForLinker()) diff --git a/llvm/lib/Target/X86/X86InstructionSelector.cpp b/llvm/lib/Target/X86/X86InstructionSelector.cpp --- a/llvm/lib/Target/X86/X86InstructionSelector.cpp +++ b/llvm/lib/Target/X86/X86InstructionSelector.cpp @@ -247,9 +247,9 @@ LLT Ty = MRI.getType(Reg); const RegClassOrRegBank &RegClassOrBank = MRI.getRegClassOrRegBank(Reg); const TargetRegisterClass *RC = - RegClassOrBank.dyn_cast(); + dyn_cast_if_present(RegClassOrBank); if (!RC) { - const RegisterBank &RB = *RegClassOrBank.get(); + const RegisterBank &RB = *cast(RegClassOrBank); RC = getRegClass(Ty, RB); if (!RC) { LLVM_DEBUG( diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp --- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp +++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp @@ -2269,9 +2269,9 @@ unsigned MaxUniqueId = 0; for (GlobalClassesTy::member_iterator MI = GlobalClasses.member_begin(I); MI != GlobalClasses.member_end(); ++MI) { - if (auto *MD = MI->dyn_cast()) + if (auto *MD = dyn_cast_if_present(*MI)) MaxUniqueId = std::max(MaxUniqueId, TypeIdInfo[MD].UniqueId); - else if (auto *BF = MI->dyn_cast()) + else if (auto *BF = dyn_cast_if_present(*MI)) MaxUniqueId = std::max(MaxUniqueId, BF->UniqueId); } Sets.emplace_back(I, MaxUniqueId); @@ -2287,12 +2287,12 @@ for (GlobalClassesTy::member_iterator MI = GlobalClasses.member_begin(S.first); MI != GlobalClasses.member_end(); ++MI) { - if (MI->is()) - TypeIds.push_back(MI->get()); - else if (MI->is()) - Globals.push_back(MI->get()); + if (isa(*MI)) + TypeIds.push_back(cast(*MI)); + else if (isa(*MI)) + Globals.push_back(cast(*MI)); else - ICallBranchFunnels.push_back(MI->get()); + ICallBranchFunnels.push_back(cast(*MI)); } // Order type identifiers by unique ID for determinism. This ordering is diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp --- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp +++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp @@ -471,11 +471,13 @@ IndexCall *operator->() { return this; } + PointerUnion getBase() const { return *this; } + void print(raw_ostream &OS) const { - if (auto *AI = dyn_cast()) + if (auto *AI = llvm::dyn_cast_if_present(getBase())) { OS << *AI; - else { - auto *CI = dyn_cast(); + } else { + auto *CI = llvm::dyn_cast_if_present(getBase()); assert(CI); OS << *CI; } @@ -1185,9 +1187,9 @@ } uint64_t IndexCallsiteContextGraph::getLastStackId(IndexCall &Call) { - assert(Call.is()); + assert(isa(Call.getBase())); CallStack::const_iterator> - CallsiteContext(Call.dyn_cast()); + CallsiteContext(dyn_cast_if_present(Call.getBase())); // Need to convert index into stack id. return Index.getStackIdAtIndex(CallsiteContext.back()); } @@ -1211,10 +1213,10 @@ unsigned CloneNo) const { auto VI = FSToVIMap.find(Func); assert(VI != FSToVIMap.end()); - if (Call.is()) + if (isa(Call.getBase())) return (VI->second.name() + " -> alloc").str(); else { - auto *Callsite = Call.dyn_cast(); + auto *Callsite = dyn_cast_if_present(Call.getBase()); return (VI->second.name() + " -> " + getMemProfFuncName(Callsite->Callee.name(), Callsite->Clones[CloneNo])) @@ -1233,9 +1235,9 @@ std::vector IndexCallsiteContextGraph::getStackIdsWithContextNodesForCall(IndexCall &Call) { - assert(Call.is()); + assert(isa(Call.getBase())); CallStack::const_iterator> - CallsiteContext(Call.dyn_cast()); + CallsiteContext(dyn_cast_if_present(Call.getBase())); return getStackIdsWithContextNodes::const_iterator>( CallsiteContext); @@ -1456,7 +1458,8 @@ bool IndexCallsiteContextGraph::calleeMatchesFunc(IndexCall &Call, const FunctionSummary *Func) { - ValueInfo Callee = Call.dyn_cast()->Callee; + ValueInfo Callee = + dyn_cast_if_present(Call.getBase())->Callee; // If there is no summary list then this is a call to an externally defined // symbol. AliasSummary *Alias = diff --git a/llvm/lib/Transforms/Utils/Evaluator.cpp b/llvm/lib/Transforms/Utils/Evaluator.cpp --- a/llvm/lib/Transforms/Utils/Evaluator.cpp +++ b/llvm/lib/Transforms/Utils/Evaluator.cpp @@ -121,7 +121,7 @@ } void Evaluator::MutableValue::clear() { - if (auto *Agg = Val.dyn_cast()) + if (auto *Agg = dyn_cast_if_present(Val)) delete Agg; Val = nullptr; } @@ -130,7 +130,7 @@ const DataLayout &DL) const { TypeSize TySize = DL.getTypeStoreSize(Ty); const MutableValue *V = this; - while (const auto *Agg = V->Val.dyn_cast()) { + while (const auto *Agg = dyn_cast_if_present(V->Val)) { Type *AggTy = Agg->Ty; std::optional Index = DL.getGEPIndexForOffset(AggTy, Offset); if (!Index || Index->uge(Agg->Elements.size()) || @@ -140,11 +140,11 @@ V = &Agg->Elements[Index->getZExtValue()]; } - return ConstantFoldLoadFromConst(V->Val.get(), Ty, Offset, DL); + return ConstantFoldLoadFromConst(cast(V->Val), Ty, Offset, DL); } bool Evaluator::MutableValue::makeMutable() { - Constant *C = Val.get(); + Constant *C = cast(Val); Type *Ty = C->getType(); unsigned NumElements; if (auto *VT = dyn_cast(Ty)) { @@ -171,10 +171,10 @@ MutableValue *MV = this; while (Offset != 0 || !CastInst::isBitOrNoopPointerCastable(Ty, MV->getType(), DL)) { - if (MV->Val.is() && !MV->makeMutable()) + if (isa(MV->Val) && !MV->makeMutable()) return false; - MutableAggregate *Agg = MV->Val.get(); + MutableAggregate *Agg = cast(MV->Val); Type *AggTy = Agg->Ty; std::optional Index = DL.getGEPIndexForOffset(AggTy, Offset); if (!Index || Index->uge(Agg->Elements.size()) || 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 @@ -8994,8 +8994,8 @@ if (!RecipeOrValue) RecipeOrValue = RecipeBuilder.handleReplication(Instr, Range, *Plan); // If Instr can be simplified to an existing VPValue, use it. - if (RecipeOrValue.is()) { - auto *VPV = RecipeOrValue.get(); + if (isa(RecipeOrValue)) { + auto *VPV = cast(RecipeOrValue); 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. @@ -9004,7 +9004,7 @@ continue; } // Otherwise, add the new recipe. - VPRecipeBase *Recipe = RecipeOrValue.get(); + VPRecipeBase *Recipe = cast(RecipeOrValue); for (auto *Def : Recipe->definedValues()) { auto *UV = Def->getUnderlyingValue(); Plan->addVPValue(UV, Def); diff --git a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp --- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp +++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp @@ -165,7 +165,7 @@ for (MachineMemOperand *OldMMO : SrcMI.memoperands()) { MachinePointerInfo NewPtrInfo(OldMMO->getPointerInfo()); if (const PseudoSourceValue *PSV = - NewPtrInfo.V.dyn_cast()) { + dyn_cast_if_present(NewPtrInfo.V)) { switch (PSV->kind()) { case PseudoSourceValue::Stack: NewPtrInfo.V = PSVMgr.getStack(); diff --git a/llvm/tools/llvm-reduce/deltas/ReduceIRReferences.cpp b/llvm/tools/llvm-reduce/deltas/ReduceIRReferences.cpp --- a/llvm/tools/llvm-reduce/deltas/ReduceIRReferences.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceIRReferences.cpp @@ -27,7 +27,7 @@ for (MachineMemOperand *MMO : MI.memoperands()) { // Leave behind pseudo source values. // TODO: Removing all MemOperand values is a further reduction step. - if (MMO->getPointerInfo().V.is()) + if (isa(MMO->getPointerInfo().V)) MMO->setValue(static_cast(nullptr)); } diff --git a/llvm/unittests/ADT/PointerUnionTest.cpp b/llvm/unittests/ADT/PointerUnionTest.cpp --- a/llvm/unittests/ADT/PointerUnionTest.cpp +++ b/llvm/unittests/ADT/PointerUnionTest.cpp @@ -89,29 +89,29 @@ } TEST_F(PointerUnionTest, Is) { - EXPECT_FALSE(a.is()); - EXPECT_TRUE(a.is()); - EXPECT_TRUE(b.is()); - EXPECT_FALSE(b.is()); - EXPECT_TRUE(n.is()); - EXPECT_FALSE(n.is()); - EXPECT_TRUE(i3.is()); - EXPECT_TRUE(f3.is()); - EXPECT_TRUE(l3.is()); - EXPECT_TRUE(i4.is()); - EXPECT_TRUE(f4.is()); - EXPECT_TRUE(l4.is()); - EXPECT_TRUE(d4.is()); - EXPECT_TRUE(i4null.is()); - EXPECT_TRUE(f4null.is()); - EXPECT_TRUE(l4null.is()); - EXPECT_TRUE(d4null.is()); + EXPECT_FALSE(isa(a)); + EXPECT_TRUE(isa(a)); + EXPECT_TRUE(isa(b)); + EXPECT_FALSE(isa(b)); + EXPECT_TRUE(isa(n)); + EXPECT_FALSE(isa(n)); + EXPECT_TRUE(isa(i3)); + EXPECT_TRUE(isa(f3)); + EXPECT_TRUE(isa(l3)); + EXPECT_TRUE(isa(i4)); + EXPECT_TRUE(isa(f4)); + EXPECT_TRUE(isa(l4)); + EXPECT_TRUE(isa(d4)); + EXPECT_TRUE(isa(i4null)); + EXPECT_TRUE(isa(f4null)); + EXPECT_TRUE(isa(l4null)); + EXPECT_TRUE(isa(d4null)); } TEST_F(PointerUnionTest, Get) { - EXPECT_EQ(a.get(), &f); - EXPECT_EQ(b.get(), &i); - EXPECT_EQ(n.get(), (int *)nullptr); + EXPECT_EQ(cast(a), &f); + EXPECT_EQ(cast(b), &i); + EXPECT_EQ(cast(n), (int *)nullptr); } template struct alignas(8) Aligned {}; @@ -125,27 +125,27 @@ Aligned<7> a7; PU8 a = &a0; - EXPECT_TRUE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_EQ(a.dyn_cast*>(), &a0); + EXPECT_TRUE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_EQ(dyn_cast_if_present *>(a), &a0); EXPECT_EQ(*a.getAddrOfPtr1(), &a0); a = &a7; - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_FALSE(a.is*>()); - EXPECT_TRUE(a.is*>()); - EXPECT_EQ(a.dyn_cast*>(), &a7); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_FALSE(isa *>(a)); + EXPECT_TRUE(isa *>(a)); + EXPECT_EQ(dyn_cast_if_present *>(a), &a7); EXPECT_TRUE(a == PU8(&a7)); EXPECT_TRUE(a != PU8(&a0)); 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 @@ -1420,9 +1420,9 @@ auto Lower = N->getLowerBound(); EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag()); ASSERT_TRUE(Count); - ASSERT_TRUE(Count.is()); - EXPECT_EQ(5, Count.get()->getSExtValue()); - EXPECT_EQ(7, Lower.get()->getSExtValue()); + ASSERT_TRUE(isa(Count)); + EXPECT_EQ(5, cast(Count)->getSExtValue()); + EXPECT_EQ(7, cast(Lower)->getSExtValue()); EXPECT_EQ(N, DISubrange::get(Context, 5, 7)); EXPECT_EQ(DISubrange::get(Context, 5, 0), DISubrange::get(Context, 5)); @@ -1436,9 +1436,9 @@ auto Lower = N->getLowerBound(); EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag()); ASSERT_TRUE(Count); - ASSERT_TRUE(Count.is()); - EXPECT_EQ(-1, Count.get()->getSExtValue()); - EXPECT_EQ(0, Lower.get()->getSExtValue()); + ASSERT_TRUE(isa(Count)); + EXPECT_EQ(-1, cast(Count)->getSExtValue()); + EXPECT_EQ(0, cast(Lower)->getSExtValue()); EXPECT_EQ(N, DISubrange::get(Context, -1, 0)); } @@ -1454,11 +1454,11 @@ auto Count = N->getCount(); auto Lower = N->getLowerBound(); ASSERT_TRUE(Count); - ASSERT_TRUE(Count.is()); - EXPECT_EQ(VlaExpr, Count.get()); + ASSERT_TRUE(isa(Count)); + EXPECT_EQ(VlaExpr, cast(Count)); ASSERT_TRUE(isa(N->getRawCountNode())); - EXPECT_EQ(0, Lower.get()->getSExtValue()); - EXPECT_EQ("vla_expr", Count.get()->getName()); + EXPECT_EQ(0, cast(Lower)->getSExtValue()); + EXPECT_EQ("vla_expr", cast(Count)->getName()); EXPECT_EQ(N, DISubrange::get(Context, VlaExpr, 0)); } @@ -1487,18 +1487,18 @@ auto Lower = N->getLowerBound(); ASSERT_TRUE(Lower); - ASSERT_TRUE(Lower.is()); - EXPECT_EQ(cast(LI->getValue()), Lower.get()); + ASSERT_TRUE(isa(Lower)); + EXPECT_EQ(cast(LI->getValue()), cast(Lower)); auto Upper = N->getUpperBound(); ASSERT_TRUE(Upper); - ASSERT_TRUE(Upper.is()); - EXPECT_EQ(cast(UI->getValue()), Upper.get()); + ASSERT_TRUE(isa(Upper)); + EXPECT_EQ(cast(UI->getValue()), cast(Upper)); auto Stride = N->getStride(); ASSERT_TRUE(Stride); - ASSERT_TRUE(Stride.is()); - EXPECT_EQ(cast(SI->getValue()), Stride.get()); + ASSERT_TRUE(isa(Stride)); + EXPECT_EQ(cast(SI->getValue()), cast(Stride)); EXPECT_EQ(N, DISubrange::get(Context, nullptr, LI, UI, SI)); @@ -1537,18 +1537,18 @@ auto Lower = N->getLowerBound(); ASSERT_TRUE(Lower); - ASSERT_TRUE(Lower.is()); - EXPECT_EQ(LV, Lower.get()); + ASSERT_TRUE(isa(Lower)); + EXPECT_EQ(LV, cast(Lower)); auto Upper = N->getUpperBound(); ASSERT_TRUE(Upper); - ASSERT_TRUE(Upper.is()); - EXPECT_EQ(UV, Upper.get()); + ASSERT_TRUE(isa(Upper)); + EXPECT_EQ(UV, cast(Upper)); auto Stride = N->getStride(); ASSERT_TRUE(Stride); - ASSERT_TRUE(Stride.is()); - EXPECT_EQ(SV, Stride.get()); + ASSERT_TRUE(isa(Stride)); + EXPECT_EQ(SV, cast(Stride)); EXPECT_EQ(N, DISubrange::get(Context, nullptr, LV, UV, SV)); @@ -1575,18 +1575,18 @@ auto Lower = N->getLowerBound(); ASSERT_TRUE(Lower); - ASSERT_TRUE(Lower.is()); - EXPECT_EQ(LE, Lower.get()); + ASSERT_TRUE(isa(Lower)); + EXPECT_EQ(LE, cast(Lower)); auto Upper = N->getUpperBound(); ASSERT_TRUE(Upper); - ASSERT_TRUE(Upper.is()); - EXPECT_EQ(UE, Upper.get()); + ASSERT_TRUE(isa(Upper)); + EXPECT_EQ(UE, cast(Upper)); auto Stride = N->getStride(); ASSERT_TRUE(Stride); - ASSERT_TRUE(Stride.is()); - EXPECT_EQ(SE, Stride.get()); + ASSERT_TRUE(isa(Stride)); + EXPECT_EQ(SE, cast(Stride)); EXPECT_EQ(N, DISubrange::get(Context, nullptr, LE, UE, SE)); @@ -1617,18 +1617,18 @@ auto Lower = N->getLowerBound(); ASSERT_TRUE(Lower); - ASSERT_TRUE(Lower.is()); - EXPECT_EQ(dyn_cast_or_null(LI), Lower.get()); + ASSERT_TRUE(isa(Lower)); + EXPECT_EQ(dyn_cast_or_null(LI), cast(Lower)); auto Upper = N->getUpperBound(); ASSERT_TRUE(Upper); - ASSERT_TRUE(Upper.is()); - EXPECT_EQ(dyn_cast_or_null(UI), Upper.get()); + ASSERT_TRUE(isa(Upper)); + EXPECT_EQ(dyn_cast_or_null(UI), cast(Upper)); auto Stride = N->getStride(); ASSERT_TRUE(Stride); - ASSERT_TRUE(Stride.is()); - EXPECT_EQ(dyn_cast_or_null(SI), Stride.get()); + ASSERT_TRUE(isa(Stride)); + EXPECT_EQ(dyn_cast_or_null(SI), cast(Stride)); EXPECT_EQ(N, DIGenericSubrange::get(Context, nullptr, LI, UI, SI)); @@ -1669,18 +1669,18 @@ auto Lower = N->getLowerBound(); ASSERT_TRUE(Lower); - ASSERT_TRUE(Lower.is()); - EXPECT_EQ(LV, Lower.get()); + ASSERT_TRUE(isa(Lower)); + EXPECT_EQ(LV, cast(Lower)); auto Upper = N->getUpperBound(); ASSERT_TRUE(Upper); - ASSERT_TRUE(Upper.is()); - EXPECT_EQ(UV, Upper.get()); + ASSERT_TRUE(isa(Upper)); + EXPECT_EQ(UV, cast(Upper)); auto Stride = N->getStride(); ASSERT_TRUE(Stride); - ASSERT_TRUE(Stride.is()); - EXPECT_EQ(SV, Stride.get()); + ASSERT_TRUE(isa(Stride)); + EXPECT_EQ(SV, cast(Stride)); EXPECT_EQ(N, DIGenericSubrange::get(Context, nullptr, LV, UV, SV)); @@ -1713,18 +1713,18 @@ auto Lower = N->getLowerBound(); ASSERT_TRUE(Lower); - ASSERT_TRUE(Lower.is()); - EXPECT_EQ(LV, Lower.get()); + ASSERT_TRUE(isa(Lower)); + EXPECT_EQ(LV, cast(Lower)); auto Upper = N->getUpperBound(); ASSERT_TRUE(Upper); - ASSERT_TRUE(Upper.is()); - EXPECT_EQ(UE, Upper.get()); + ASSERT_TRUE(isa(Upper)); + EXPECT_EQ(UE, cast(Upper)); auto Stride = N->getStride(); ASSERT_TRUE(Stride); - ASSERT_TRUE(Stride.is()); - EXPECT_EQ(SE, Stride.get()); + ASSERT_TRUE(isa(Stride)); + EXPECT_EQ(SE, cast(Stride)); EXPECT_EQ( N, DIB.getOrCreateGenericSubrange(DIGenericSubrange::BoundType(nullptr), diff --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp --- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp +++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp @@ -506,9 +506,9 @@ PointerUnion DefRec; const CodeGenInstruction *getResultInst() const { - if (DefRec.is()) - return DefRec.get(); - return DefRec.get()->ResultInst; + if (isa(DefRec)) + return cast(DefRec); + return cast(DefRec)->ResultInst; } /// ResOperands - This is the operand list that should be built for the result @@ -564,11 +564,11 @@ ConversionFnKind(RHS.ConversionFnKind), HasDeprecation(RHS.HasDeprecation), UseInstAsmMatchConverter(RHS.UseInstAsmMatchConverter) { - assert(!DefRec.is()); + assert(!isa(DefRec)); } ~MatchableInfo() { - delete DefRec.dyn_cast(); + delete dyn_cast_if_present(DefRec); } // Two-operand aliases clone from the main matchable, but mark the second @@ -1614,13 +1614,13 @@ else OperandName = Token.substr(1); - if (II->DefRec.is()) + if (isa(II->DefRec)) buildInstructionOperandReference(II.get(), OperandName, i); else buildAliasOperandReference(II.get(), OperandName, Op); } - if (II->DefRec.is()) { + if (isa(II->DefRec)) { II->buildInstructionResultOperands(); // If the instruction has a two-operand alias, build up the // matchable here. We'll add them in bulk at the end to avoid @@ -1683,7 +1683,7 @@ buildInstructionOperandReference(MatchableInfo *II, StringRef OperandName, unsigned AsmOpIdx) { - const CodeGenInstruction &CGI = *II->DefRec.get(); + const CodeGenInstruction &CGI = *cast(II->DefRec); const CGIOperandList &Operands = CGI.Operands; MatchableInfo::AsmOperand *Op = &II->AsmOperands[AsmOpIdx]; @@ -1746,7 +1746,7 @@ void AsmMatcherInfo::buildAliasOperandReference(MatchableInfo *II, StringRef OperandName, MatchableInfo::AsmOperand &Op) { - const CodeGenInstAlias &CGA = *II->DefRec.get(); + const CodeGenInstAlias &CGA = *cast(II->DefRec); // Set up the operand class. for (unsigned i = 0, e = CGA.ResultOperands.size(); i != e; ++i) @@ -1819,7 +1819,7 @@ } void MatchableInfo::buildAliasResultOperands(bool AliasConstraintsAreChecked) { - const CodeGenInstAlias &CGA = *DefRec.get(); + const CodeGenInstAlias &CGA = *cast(DefRec); const CodeGenInstruction *ResultInst = getResultInst(); // Map of: $reg -> #lastref