[llvm] 7021182 - [nfc][llvm] Replace pointer cast functions in PointerUnion by llvm casting functions.

Shraiysh Vaishay via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 17 11:40:57 PDT 2023


Author: Shraiysh Vaishay
Date: 2023-04-17T13:40:51-05:00
New Revision: 7021182d6b43de9488ab70de626192ce70b3a4a6

URL: https://github.com/llvm/llvm-project/commit/7021182d6b43de9488ab70de626192ce70b3a4a6
DIFF: https://github.com/llvm/llvm-project/commit/7021182d6b43de9488ab70de626192ce70b3a4a6.diff

LOG: [nfc][llvm] Replace pointer cast functions in PointerUnion by llvm casting functions.

This patch replaces the uses of PointerUnion.is function by llvm::isa,
PointerUnion.get function by llvm::cast, and PointerUnion.dyn_cast by
llvm::dyn_cast_if_present. This is according to the FIXME in
the definition of the class PointerUnion.

This patch does not remove them as they are being used in other
subprojects.

Reviewed By: mehdi_amini

Differential Revision: https://reviews.llvm.org/D148449

Added: 
    

Modified: 
    llvm/include/llvm/ADT/FunctionExtras.h
    llvm/include/llvm/ADT/PointerUnion.h
    llvm/include/llvm/ADT/TinyPtrVector.h
    llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h
    llvm/include/llvm/CodeGen/MachineMemOperand.h
    llvm/include/llvm/CodeGen/MachineRegisterInfo.h
    llvm/include/llvm/CodeGen/SelectionDAGNodes.h
    llvm/include/llvm/CodeGen/WasmEHFuncInfo.h
    llvm/include/llvm/IR/GetElementPtrTypeIterator.h
    llvm/include/llvm/IR/IntrinsicInst.h
    llvm/include/llvm/IR/Metadata.h
    llvm/include/llvm/Transforms/Utils/Evaluator.h
    llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
    llvm/lib/CodeGen/AsmPrinter/DIE.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
    llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
    llvm/lib/CodeGen/AsmPrinter/WinException.cpp
    llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
    llvm/lib/CodeGen/GlobalISel/Utils.cpp
    llvm/lib/CodeGen/MachineOperand.cpp
    llvm/lib/CodeGen/MachineRegisterInfo.cpp
    llvm/lib/CodeGen/RegisterBankInfo.cpp
    llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
    llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
    llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
    llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
    llvm/lib/CodeGen/WinEHPrepare.cpp
    llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp
    llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
    llvm/lib/IR/DIBuilder.cpp
    llvm/lib/IR/Metadata.cpp
    llvm/lib/IR/Verifier.cpp
    llvm/lib/LTO/LTO.cpp
    llvm/lib/LTO/LTOModule.cpp
    llvm/lib/Object/IRSymtab.cpp
    llvm/lib/Object/ModuleSymbolTable.cpp
    llvm/lib/Target/X86/X86InstructionSelector.cpp
    llvm/lib/Transforms/IPO/LowerTypeTests.cpp
    llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
    llvm/lib/Transforms/Utils/Evaluator.cpp
    llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    llvm/tools/llvm-reduce/ReducerWorkItem.cpp
    llvm/tools/llvm-reduce/deltas/ReduceIRReferences.cpp
    llvm/unittests/ADT/PointerUnionTest.cpp
    llvm/unittests/IR/MetadataTest.cpp
    llvm/utils/TableGen/AsmMatcherEmitter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/FunctionExtras.h b/llvm/include/llvm/ADT/FunctionExtras.h
index 8f04277cdf0e5..53de2cb74253a 100644
--- a/llvm/include/llvm/ADT/FunctionExtras.h
+++ b/llvm/include/llvm/ADT/FunctionExtras.h
@@ -172,16 +172,15 @@ template <typename ReturnT, typename... ParamTs> class UniqueFunctionBase {
   bool isInlineStorage() const { return CallbackAndInlineFlag.getInt(); }
 
   bool isTrivialCallback() const {
-    return CallbackAndInlineFlag.getPointer().template is<TrivialCallback *>();
+    return isa<TrivialCallback *>(CallbackAndInlineFlag.getPointer());
   }
 
   CallPtrT getTrivialCallback() const {
-    return CallbackAndInlineFlag.getPointer().template get<TrivialCallback *>()->CallPtr;
+    return cast<TrivialCallback *>(CallbackAndInlineFlag.getPointer())->CallPtr;
   }
 
   NonTrivialCallbacks *getNonTrivialCallbacks() const {
-    return CallbackAndInlineFlag.getPointer()
-        .template get<NonTrivialCallbacks *>();
+    return cast<NonTrivialCallbacks *>(CallbackAndInlineFlag.getPointer());
   }
 
   CallPtrT getCallPtr() const {

diff  --git a/llvm/include/llvm/ADT/PointerUnion.h b/llvm/include/llvm/ADT/PointerUnion.h
index 061c4000fcb35..db0db1b586660 100644
--- a/llvm/include/llvm/ADT/PointerUnion.h
+++ b/llvm/include/llvm/ADT/PointerUnion.h
@@ -172,9 +172,9 @@ class PointerUnion
   /// If the union is set to the first pointer type get an address pointing to
   /// it.
   First *getAddrOfPtr1() {
-    assert(is<First>() && "Val is not the first pointer");
+    assert(isa<First>(*this) && "Val is not the first pointer");
     assert(
-        PointerLikeTypeTraits<First>::getAsVoidPointer(get<First>()) ==
+        PointerLikeTypeTraits<First>::getAsVoidPointer(cast<First>(*this)) ==
             this->Val.getPointer() &&
         "Can't get the address because PointerLikeTypeTraits changes the ptr");
     return const_cast<First *>(

diff  --git a/llvm/include/llvm/ADT/TinyPtrVector.h b/llvm/include/llvm/ADT/TinyPtrVector.h
index aa87fd66ac20e..fa2bcd8933a0a 100644
--- a/llvm/include/llvm/ADT/TinyPtrVector.h
+++ b/llvm/include/llvm/ADT/TinyPtrVector.h
@@ -43,12 +43,12 @@ class TinyPtrVector {
   TinyPtrVector() = default;
 
   ~TinyPtrVector() {
-    if (VecTy *V = Val.template dyn_cast<VecTy*>())
+    if (VecTy *V = dyn_cast_if_present<VecTy *>(Val))
       delete V;
   }
 
   TinyPtrVector(const TinyPtrVector &RHS) : Val(RHS.Val) {
-    if (VecTy *V = Val.template dyn_cast<VecTy*>())
+    if (VecTy *V = dyn_cast_if_present<VecTy *>(Val))
       Val = new VecTy(*V);
   }
 
@@ -62,20 +62,20 @@ class TinyPtrVector {
 
     // Try to squeeze into the single slot. If it won't fit, allocate a copied
     // vector.
-    if (Val.template is<EltTy>()) {
+    if (isa<EltTy>(Val)) {
       if (RHS.size() == 1)
         Val = RHS.front();
       else
-        Val = new VecTy(*RHS.Val.template get<VecTy*>());
+        Val = new VecTy(*cast<VecTy *>(RHS.Val));
       return *this;
     }
 
     // If we have a full vector allocated, try to re-use it.
-    if (RHS.Val.template is<EltTy>()) {
-      Val.template get<VecTy*>()->clear();
-      Val.template get<VecTy*>()->push_back(RHS.front());
+    if (isa<EltTy>(RHS.Val)) {
+      cast<VecTy *>(Val)->clear();
+      cast<VecTy *>(Val)->push_back(RHS.front());
     } else {
-      *Val.template get<VecTy*>() = *RHS.Val.template get<VecTy*>();
+      *cast<VecTy *>(Val) = *cast<VecTy *>(RHS.Val);
     }
     return *this;
   }
@@ -95,8 +95,8 @@ class TinyPtrVector {
     // 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<VecTy*>()) {
-      if (RHS.Val.template is<EltTy>()) {
+    if (VecTy *V = dyn_cast_if_present<VecTy *>(Val)) {
+      if (isa<EltTy>(RHS.Val)) {
         V->clear();
         V->push_back(RHS.front());
         RHS.Val = EltTy();
@@ -136,18 +136,18 @@ class TinyPtrVector {
   operator ArrayRef<EltTy>() const {
     if (Val.isNull())
       return std::nullopt;
-    if (Val.template is<EltTy>())
+    if (isa<EltTy>(Val))
       return *Val.getAddrOfPtr1();
-    return *Val.template get<VecTy*>();
+    return *cast<VecTy *>(Val);
   }
 
   // implicit conversion operator to MutableArrayRef.
   operator MutableArrayRef<EltTy>() {
     if (Val.isNull())
       return std::nullopt;
-    if (Val.template is<EltTy>())
+    if (isa<EltTy>(Val))
       return *Val.getAddrOfPtr1();
-    return *Val.template get<VecTy*>();
+    return *cast<VecTy *>(Val);
   }
 
   // Implicit conversion to ArrayRef<U> if EltTy* implicitly converts to U*.
@@ -163,7 +163,7 @@ class TinyPtrVector {
     // 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<VecTy*>())
+    if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val))
       return Vec->empty();
     return false;
   }
@@ -171,9 +171,9 @@ class TinyPtrVector {
   unsigned size() const {
     if (empty())
       return 0;
-    if (Val.template is<EltTy>())
+    if (isa<EltTy>(Val))
       return 1;
-    return Val.template get<VecTy*>()->size();
+    return cast<VecTy *>(Val)->size();
   }
 
   using iterator = EltTy *;
@@ -182,17 +182,17 @@ class TinyPtrVector {
   using const_reverse_iterator = std::reverse_iterator<const_iterator>;
 
   iterator begin() {
-    if (Val.template is<EltTy>())
+    if (isa<EltTy>(Val))
       return Val.getAddrOfPtr1();
 
-    return Val.template get<VecTy *>()->begin();
+    return cast<VecTy *>(Val)->begin();
   }
 
   iterator end() {
-    if (Val.template is<EltTy>())
+    if (isa<EltTy>(Val))
       return begin() + (Val.isNull() ? 0 : 1);
 
-    return Val.template get<VecTy *>()->end();
+    return cast<VecTy *>(Val)->end();
   }
 
   const_iterator begin() const {
@@ -216,28 +216,27 @@ class TinyPtrVector {
 
   EltTy operator[](unsigned i) const {
     assert(!Val.isNull() && "can't index into an empty vector");
-    if (Val.template is<EltTy>()) {
+    if (isa<EltTy>(Val)) {
       assert(i == 0 && "tinyvector index out of range");
-      return Val.template get<EltTy>();
+      return cast<EltTy>(Val);
     }
 
-    assert(i < Val.template get<VecTy*>()->size() &&
-           "tinyvector index out of range");
-    return (*Val.template get<VecTy*>())[i];
+    assert(i < cast<VecTy *>(Val)->size() && "tinyvector index out of range");
+    return (*cast<VecTy *>(Val))[i];
   }
 
   EltTy front() const {
     assert(!empty() && "vector empty");
-    if (Val.template is<EltTy>())
-      return Val.template get<EltTy>();
-    return Val.template get<VecTy*>()->front();
+    if (isa<EltTy>(Val))
+      return cast<EltTy>(Val);
+    return cast<VecTy *>(Val)->front();
   }
 
   EltTy back() const {
     assert(!empty() && "vector empty");
-    if (Val.template is<EltTy>())
-      return Val.template get<EltTy>();
-    return Val.template get<VecTy*>()->back();
+    if (isa<EltTy>(Val))
+      return cast<EltTy>(Val);
+    return cast<VecTy *>(Val)->back();
   }
 
   void push_back(EltTy NewVal) {
@@ -249,29 +248,29 @@ class TinyPtrVector {
     }
 
     // If we have a single value, convert to a vector.
-    if (Val.template is<EltTy>()) {
-      EltTy V = Val.template get<EltTy>();
+    if (isa<EltTy>(Val)) {
+      EltTy V = cast<EltTy>(Val);
       Val = new VecTy();
-      Val.template get<VecTy*>()->push_back(V);
+      cast<VecTy *>(Val)->push_back(V);
     }
 
     // Add the new value, we know we have a vector.
-    Val.template get<VecTy*>()->push_back(NewVal);
+    cast<VecTy *>(Val)->push_back(NewVal);
   }
 
   void pop_back() {
     // If we have a single value, convert to empty.
-    if (Val.template is<EltTy>())
+    if (isa<EltTy>(Val))
       Val = (EltTy)nullptr;
-    else if (VecTy *Vec = Val.template get<VecTy*>())
+    else if (VecTy *Vec = cast<VecTy *>(Val))
       Vec->pop_back();
   }
 
   void clear() {
     // If we have a single value, convert to empty.
-    if (Val.template is<EltTy>()) {
+    if (isa<EltTy>(Val)) {
       Val = EltTy();
-    } else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
+    } else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
       // If we have a vector form, just clear it.
       Vec->clear();
     }
@@ -283,10 +282,10 @@ class TinyPtrVector {
     assert(I < end() && "Erasing at past-the-end iterator.");
 
     // If we have a single value, convert to empty.
-    if (Val.template is<EltTy>()) {
+    if (isa<EltTy>(Val)) {
       if (I == begin())
         Val = EltTy();
-    } else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
+    } else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(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 @@ class TinyPtrVector {
     assert(S <= E && "Trying to erase invalid range.");
     assert(E <= end() && "Trying to erase past the end.");
 
-    if (Val.template is<EltTy>()) {
+    if (isa<EltTy>(Val)) {
       if (S == begin() && S != E)
         Val = EltTy();
-    } else if (VecTy *Vec = Val.template dyn_cast<VecTy*>()) {
+    } else if (VecTy *Vec = dyn_cast_if_present<VecTy *>(Val)) {
       return Vec->erase(S, E);
     }
     return end();
@@ -316,15 +315,15 @@ class TinyPtrVector {
       return std::prev(end());
     }
     assert(!Val.isNull() && "Null value with non-end insert iterator.");
-    if (Val.template is<EltTy>()) {
-      EltTy V = Val.template get<EltTy>();
+    if (isa<EltTy>(Val)) {
+      EltTy V = cast<EltTy>(Val);
       assert(I == begin());
       Val = Elt;
       push_back(V);
       return begin();
     }
 
-    return Val.template get<VecTy*>()->insert(I, Elt);
+    return cast<VecTy *>(Val)->insert(I, Elt);
   }
 
   template<typename ItTy>
@@ -343,12 +342,12 @@ class TinyPtrVector {
       }
 
       Val = new VecTy();
-    } else if (Val.template is<EltTy>()) {
-      EltTy V = Val.template get<EltTy>();
+    } else if (isa<EltTy>(Val)) {
+      EltTy V = cast<EltTy>(Val);
       Val = new VecTy();
-      Val.template get<VecTy*>()->push_back(V);
+      cast<VecTy *>(Val)->push_back(V);
     }
-    return Val.template get<VecTy*>()->insert(begin() + Offset, From, To);
+    return cast<VecTy *>(Val)->insert(begin() + Offset, From, To);
   }
 };
 

diff  --git a/llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h b/llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h
index f19d321793e9c..7822ebf2eb099 100644
--- a/llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h
+++ b/llvm/include/llvm/CodeGen/DwarfStringPoolEntry.h
@@ -63,7 +63,7 @@ class DwarfStringPoolEntryRef {
   /// thus specified entry mustn`t be reallocated.
   DwarfStringPoolEntryRef(const StringMapEntry<DwarfStringPoolEntry *> &Entry)
       : MapEntry(&Entry) {
-    assert(MapEntry.get<ByPtrStringEntryPtr>()->second != nullptr);
+    assert(cast<ByPtrStringEntryPtr>(MapEntry)->second != nullptr);
   }
 
   explicit operator bool() const { return !MapEntry.isNull(); }
@@ -85,18 +85,18 @@ class DwarfStringPoolEntryRef {
 
   /// \returns string.
   StringRef getString() const {
-    if (MapEntry.is<ByValStringEntryPtr>())
-      return MapEntry.get<ByValStringEntryPtr>()->first();
+    if (isa<ByValStringEntryPtr>(MapEntry))
+      return cast<ByValStringEntryPtr>(MapEntry)->first();
 
-    return MapEntry.get<ByPtrStringEntryPtr>()->first();
+    return cast<ByPtrStringEntryPtr>(MapEntry)->first();
   }
 
   /// \returns the entire string pool entry for convenience.
   const DwarfStringPoolEntry &getEntry() const {
-    if (MapEntry.is<ByValStringEntryPtr>())
-      return MapEntry.get<ByValStringEntryPtr>()->second;
+    if (isa<ByValStringEntryPtr>(MapEntry))
+      return cast<ByValStringEntryPtr>(MapEntry)->second;
 
-    return *MapEntry.get<ByPtrStringEntryPtr>()->second;
+    return *cast<ByPtrStringEntryPtr>(MapEntry)->second;
   }
 
   bool operator==(const DwarfStringPoolEntryRef &X) const {

diff  --git a/llvm/include/llvm/CodeGen/MachineMemOperand.h b/llvm/include/llvm/CodeGen/MachineMemOperand.h
index 41574d8d556a8..fd5f7f7a115ca 100644
--- a/llvm/include/llvm/CodeGen/MachineMemOperand.h
+++ b/llvm/include/llvm/CodeGen/MachineMemOperand.h
@@ -69,19 +69,19 @@ struct MachinePointerInfo {
     uint8_t ID = 0)
     : V(v), Offset(offset), StackID(ID) {
     if (V) {
-      if (const auto *ValPtr = V.dyn_cast<const Value*>())
+      if (const auto *ValPtr = dyn_cast_if_present<const Value *>(V))
         AddrSpace = ValPtr->getType()->getPointerAddressSpace();
       else
-        AddrSpace = V.get<const PseudoSourceValue*>()->getAddressSpace();
+        AddrSpace = cast<const PseudoSourceValue *>(V)->getAddressSpace();
     }
   }
 
   MachinePointerInfo getWithOffset(int64_t O) const {
     if (V.isNull())
       return MachinePointerInfo(AddrSpace, Offset + O);
-    if (V.is<const Value*>())
-      return MachinePointerInfo(V.get<const Value*>(), Offset + O, StackID);
-    return MachinePointerInfo(V.get<const PseudoSourceValue*>(), Offset + O,
+    if (isa<const Value *>(V))
+      return MachinePointerInfo(cast<const Value *>(V), Offset + O, StackID);
+    return MachinePointerInfo(cast<const PseudoSourceValue *>(V), Offset + O,
                               StackID);
   }
 
@@ -207,10 +207,12 @@ class MachineMemOperand {
   /// 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*>(); }
+  const Value *getValue() const {
+    return dyn_cast_if_present<const Value *>(PtrInfo.V);
+  }
 
   const PseudoSourceValue *getPseudoValue() const {
-    return PtrInfo.V.dyn_cast<const PseudoSourceValue*>();
+    return dyn_cast_if_present<const PseudoSourceValue *>(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
index fc4e5ca756248..aa35928d42c4b 100644
--- a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h
@@ -660,9 +660,9 @@ class MachineRegisterInfo {
   /// 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<const TargetRegisterClass *>() &&
+    assert(isa<const TargetRegisterClass *>(VRegInfo[Reg.id()].first) &&
            "Register class not set, wrong accessor");
-    return VRegInfo[Reg.id()].first.get<const TargetRegisterClass *>();
+    return cast<const TargetRegisterClass *>(VRegInfo[Reg.id()].first);
   }
 
   /// Return the register class of \p Reg, or null if Reg has not been assigned
@@ -678,7 +678,7 @@ class MachineRegisterInfo {
   /// the select pass, using getRegClass is safe.
   const TargetRegisterClass *getRegClassOrNull(Register Reg) const {
     const RegClassOrRegBank &Val = VRegInfo[Reg].first;
-    return Val.dyn_cast<const TargetRegisterClass *>();
+    return dyn_cast_if_present<const TargetRegisterClass *>(Val);
   }
 
   /// Return the register bank of \p Reg, or null if Reg has not been assigned
@@ -687,7 +687,7 @@ class MachineRegisterInfo {
   /// RegisterBankInfo::getRegBankFromRegClass.
   const RegisterBank *getRegBankOrNull(Register Reg) const {
     const RegClassOrRegBank &Val = VRegInfo[Reg].first;
-    return Val.dyn_cast<const RegisterBank *>();
+    return dyn_cast_if_present<const RegisterBank *>(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
index 32745ac660d69..920562a9caed6 100644
--- a/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
+++ b/llvm/include/llvm/CodeGen/SelectionDAGNodes.h
@@ -2942,7 +2942,7 @@ class MachineSDNode : public SDNode {
       return ArrayRef(MemRefs.getAddrOfPtr1(), 1);
 
     // Otherwise we have an actual array.
-    return ArrayRef(MemRefs.get<MachineMemOperand **>(), NumMemRefs);
+    return ArrayRef(cast<MachineMemOperand **>(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
index 60ee6493b1a1f..ab6b897e9f999 100644
--- a/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h
+++ b/llvm/include/llvm/CodeGen/WasmEHFuncInfo.h
@@ -38,14 +38,14 @@ struct WasmEHFuncInfo {
   // Helper functions
   const BasicBlock *getUnwindDest(const BasicBlock *BB) const {
     assert(hasUnwindDest(BB));
-    return SrcToUnwindDest.lookup(BB).get<const BasicBlock *>();
+    return cast<const BasicBlock *>(SrcToUnwindDest.lookup(BB));
   }
   SmallPtrSet<const BasicBlock *, 4> getUnwindSrcs(const BasicBlock *BB) const {
     assert(hasUnwindSrcs(BB));
     const auto &Set = UnwindDestToSrcs.lookup(BB);
     SmallPtrSet<const BasicBlock *, 4> Ret;
     for (const auto P : Set)
-      Ret.insert(P.get<const BasicBlock *>());
+      Ret.insert(cast<const BasicBlock *>(P));
     return Ret;
   }
   void setUnwindDest(const BasicBlock *BB, const BasicBlock *Dest) {
@@ -61,7 +61,7 @@ struct WasmEHFuncInfo {
 
   MachineBasicBlock *getUnwindDest(MachineBasicBlock *MBB) const {
     assert(hasUnwindDest(MBB));
-    return SrcToUnwindDest.lookup(MBB).get<MachineBasicBlock *>();
+    return cast<MachineBasicBlock *>(SrcToUnwindDest.lookup(MBB));
   }
   SmallPtrSet<MachineBasicBlock *, 4>
   getUnwindSrcs(MachineBasicBlock *MBB) const {
@@ -69,7 +69,7 @@ struct WasmEHFuncInfo {
     const auto &Set = UnwindDestToSrcs.lookup(MBB);
     SmallPtrSet<MachineBasicBlock *, 4> Ret;
     for (const auto P : Set)
-      Ret.insert(P.get<MachineBasicBlock *>());
+      Ret.insert(cast<MachineBasicBlock *>(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
index 1fa996229749b..8c6ede96c873b 100644
--- a/llvm/include/llvm/IR/GetElementPtrTypeIterator.h
+++ b/llvm/include/llvm/IR/GetElementPtrTypeIterator.h
@@ -68,9 +68,9 @@ class generic_gep_type_iterator {
   // temporarily not giving this iterator an operator*() to avoid a subtle
   // semantics break.
   Type *getIndexedType() const {
-    if (auto *T = CurTy.dyn_cast<Type *>())
+    if (auto *T = dyn_cast_if_present<Type *>(CurTy))
       return T;
-    return CurTy.get<StructType *>()->getTypeAtIndex(getOperand());
+    return cast<StructType *>(CurTy)->getTypeAtIndex(getOperand());
   }
 
   Value *getOperand() const { return const_cast<Value *>(&**OpIt); }
@@ -108,13 +108,13 @@ class generic_gep_type_iterator {
   // we should provide a more minimal API here that exposes not much more than
   // that.
 
-  bool isStruct() const { return CurTy.is<StructType *>(); }
-  bool isSequential() const { return CurTy.is<Type *>(); }
+  bool isStruct() const { return isa<StructType *>(CurTy); }
+  bool isSequential() const { return isa<Type *>(CurTy); }
 
-  StructType *getStructType() const { return CurTy.get<StructType *>(); }
+  StructType *getStructType() const { return cast<StructType *>(CurTy); }
 
   StructType *getStructTypeOrNull() const {
-    return CurTy.dyn_cast<StructType *>();
+    return dyn_cast_if_present<StructType *>(CurTy);
   }
 };
 

diff  --git a/llvm/include/llvm/IR/IntrinsicInst.h b/llvm/include/llvm/IR/IntrinsicInst.h
index cd9def2f5a717..548d88ebff1cf 100644
--- a/llvm/include/llvm/IR/IntrinsicInst.h
+++ b/llvm/include/llvm/IR/IntrinsicInst.h
@@ -195,29 +195,29 @@ class location_op_iterator
   }
   bool operator==(const location_op_iterator &RHS) const { return I == RHS.I; }
   const Value *operator*() const {
-    ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
-                               ? I.get<ValueAsMetadata *>()
-                               : *I.get<ValueAsMetadata **>();
+    ValueAsMetadata *VAM = isa<ValueAsMetadata *>(I)
+                               ? cast<ValueAsMetadata *>(I)
+                               : *cast<ValueAsMetadata **>(I);
     return VAM->getValue();
   };
   Value *operator*() {
-    ValueAsMetadata *VAM = I.is<ValueAsMetadata *>()
-                               ? I.get<ValueAsMetadata *>()
-                               : *I.get<ValueAsMetadata **>();
+    ValueAsMetadata *VAM = isa<ValueAsMetadata *>(I)
+                               ? cast<ValueAsMetadata *>(I)
+                               : *cast<ValueAsMetadata **>(I);
     return VAM->getValue();
   }
   location_op_iterator &operator++() {
-    if (I.is<ValueAsMetadata *>())
-      I = I.get<ValueAsMetadata *>() + 1;
+    if (isa<ValueAsMetadata *>(I))
+      I = cast<ValueAsMetadata *>(I) + 1;
     else
-      I = I.get<ValueAsMetadata **>() + 1;
+      I = cast<ValueAsMetadata **>(I) + 1;
     return *this;
   }
   location_op_iterator &operator--() {
-    if (I.is<ValueAsMetadata *>())
-      I = I.get<ValueAsMetadata *>() - 1;
+    if (isa<ValueAsMetadata *>(I))
+      I = cast<ValueAsMetadata *>(I) - 1;
     else
-      I = I.get<ValueAsMetadata **>() - 1;
+      I = cast<ValueAsMetadata **>(I) - 1;
     return *this;
   }
 };

diff  --git a/llvm/include/llvm/IR/Metadata.h b/llvm/include/llvm/IR/Metadata.h
index 954681e241564..262a148039a94 100644
--- a/llvm/include/llvm/IR/Metadata.h
+++ b/llvm/include/llvm/IR/Metadata.h
@@ -861,18 +861,18 @@ class ContextAndReplaceableUses {
 
   /// Whether this contains RAUW support.
   bool hasReplaceableUses() const {
-    return Ptr.is<ReplaceableMetadataImpl *>();
+    return isa<ReplaceableMetadataImpl *>(Ptr);
   }
 
   LLVMContext &getContext() const {
     if (hasReplaceableUses())
       return getReplaceableUses()->getContext();
-    return *Ptr.get<LLVMContext *>();
+    return *cast<LLVMContext *>(Ptr);
   }
 
   ReplaceableMetadataImpl *getReplaceableUses() const {
     if (hasReplaceableUses())
-      return Ptr.get<ReplaceableMetadataImpl *>();
+      return cast<ReplaceableMetadataImpl *>(Ptr);
     return nullptr;
   }
 

diff  --git a/llvm/include/llvm/Transforms/Utils/Evaluator.h b/llvm/include/llvm/Transforms/Utils/Evaluator.h
index 6b9b382dbaf4f..5d53773b5d6b6 100644
--- a/llvm/include/llvm/Transforms/Utils/Evaluator.h
+++ b/llvm/include/llvm/Transforms/Utils/Evaluator.h
@@ -55,15 +55,15 @@ class Evaluator {
     ~MutableValue() { clear(); }
 
     Type *getType() const {
-      if (auto *C = Val.dyn_cast<Constant *>())
+      if (auto *C = dyn_cast_if_present<Constant *>(Val))
         return C->getType();
-      return Val.get<MutableAggregate *>()->Ty;
+      return cast<MutableAggregate *>(Val)->Ty;
     }
 
     Constant *toConstant() const {
-      if (auto *C = Val.dyn_cast<Constant *>())
+      if (auto *C = dyn_cast_if_present<Constant *>(Val))
         return C;
-      return Val.get<MutableAggregate *>()->toConstant();
+      return cast<MutableAggregate *>(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
index 5aceb33f00dc7..3494ae0490a1f 100644
--- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
@@ -1719,12 +1719,13 @@ TypeIndex CodeViewDebug::lowerTypeArray(const DICompositeType *Ty) {
     // 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<ConstantInt *>())
+    if (auto *CI = dyn_cast_if_present<ConstantInt *>(Subrange->getCount()))
       Count = CI->getSExtValue();
-    else if (auto *UI = Subrange->getUpperBound().dyn_cast<ConstantInt *>()) {
+    else if (auto *UI = dyn_cast_if_present<ConstantInt *>(
+                 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<ConstantInt *>();
+      auto *LI = dyn_cast_if_present<ConstantInt *>(Subrange->getLowerBound());
       Lowerbound = (LI) ? LI->getSExtValue() : Lowerbound;
       Count = UI->getSExtValue() - Lowerbound + 1;
     }
@@ -3283,7 +3284,7 @@ void CodeViewDebug::emitDebugInfoForGlobals() {
   // 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 *>();
+    const GlobalVariable *GV = cast<const GlobalVariable *>(CVGV.GVInfo);
     MCSymbol *GVSym = Asm->getSymbol(GV);
     OS.AddComment("Symbol subsection for " +
                   Twine(GlobalValue::dropLLVMManglingEscape(GV->getName())));
@@ -3392,7 +3393,7 @@ void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) {
           : getFullyQualifiedName(Scope, DIGV->getName());
 
   if (const GlobalVariable *GV =
-          CVGV.GVInfo.dyn_cast<const GlobalVariable *>()) {
+          dyn_cast_if_present<const GlobalVariable *>(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 @@ void CodeViewDebug::emitDebugInfoForGlobal(const CVGlobalVariable &CVGV) {
     emitNullTerminatedSymbolName(OS, QualifiedName, LengthOfDataRecord);
     endSymbolRecord(DataEnd);
   } else {
-    const DIExpression *DIE = CVGV.GVInfo.get<const DIExpression *>();
+    const DIExpression *DIE = cast<const DIExpression *>(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
index 583da5662a950..619155cafe927 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DIE.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DIE.cpp
@@ -173,9 +173,7 @@ void DIEAbbrevSet::Emit(const AsmPrinter *AP, MCSection *Section) const {
 // DIE Implementation
 //===----------------------------------------------------------------------===//
 
-DIE *DIE::getParent() const {
-  return Owner.dyn_cast<DIE*>();
-}
+DIE *DIE::getParent() const { return dyn_cast_if_present<DIE *>(Owner); }
 
 DIEAbbrev DIE::generateAbbrev() const {
   DIEAbbrev Abbrev(Tag, hasChildren());
@@ -209,7 +207,7 @@ const DIE *DIE::getUnitDie() const {
 DIEUnit *DIE::getUnit() const {
   const DIE *UnitDie = getUnitDie();
   if (UnitDie)
-    return UnitDie->Owner.dyn_cast<DIEUnit*>();
+    return dyn_cast_if_present<DIEUnit *>(UnitDie->Owner);
   return nullptr;
 }
 

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
index 4c65253bf7a14..f0c24f2580088 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp
@@ -958,29 +958,29 @@ static SmallVector<const DIVariable *, 2> dependencies(DbgVariable *Var) {
   for (auto *El : Array->getElements()) {
     if (auto *Subrange = dyn_cast<DISubrange>(El)) {
       if (auto Count = Subrange->getCount())
-        if (auto *Dependency = Count.dyn_cast<DIVariable *>())
+        if (auto *Dependency = dyn_cast_if_present<DIVariable *>(Count))
           Result.push_back(Dependency);
       if (auto LB = Subrange->getLowerBound())
-        if (auto *Dependency = LB.dyn_cast<DIVariable *>())
+        if (auto *Dependency = dyn_cast_if_present<DIVariable *>(LB))
           Result.push_back(Dependency);
       if (auto UB = Subrange->getUpperBound())
-        if (auto *Dependency = UB.dyn_cast<DIVariable *>())
+        if (auto *Dependency = dyn_cast_if_present<DIVariable *>(UB))
           Result.push_back(Dependency);
       if (auto ST = Subrange->getStride())
-        if (auto *Dependency = ST.dyn_cast<DIVariable *>())
+        if (auto *Dependency = dyn_cast_if_present<DIVariable *>(ST))
           Result.push_back(Dependency);
     } else if (auto *GenericSubrange = dyn_cast<DIGenericSubrange>(El)) {
       if (auto Count = GenericSubrange->getCount())
-        if (auto *Dependency = Count.dyn_cast<DIVariable *>())
+        if (auto *Dependency = dyn_cast_if_present<DIVariable *>(Count))
           Result.push_back(Dependency);
       if (auto LB = GenericSubrange->getLowerBound())
-        if (auto *Dependency = LB.dyn_cast<DIVariable *>())
+        if (auto *Dependency = dyn_cast_if_present<DIVariable *>(LB))
           Result.push_back(Dependency);
       if (auto UB = GenericSubrange->getUpperBound())
-        if (auto *Dependency = UB.dyn_cast<DIVariable *>())
+        if (auto *Dependency = dyn_cast_if_present<DIVariable *>(UB))
           Result.push_back(Dependency);
       if (auto ST = GenericSubrange->getStride())
-        if (auto *Dependency = ST.dyn_cast<DIVariable *>())
+        if (auto *Dependency = dyn_cast_if_present<DIVariable *>(ST))
           Result.push_back(Dependency);
     }
   }

diff  --git a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
index c2ff899c04abe..c7c40087a5817 100644
--- a/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/DwarfUnit.cpp
@@ -1362,16 +1362,16 @@ void DwarfUnit::constructSubrangeDIE(DIE &Buffer, const DISubrange *SR,
 
   auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
                                DISubrange::BoundType Bound) -> void {
-    if (auto *BV = Bound.dyn_cast<DIVariable *>()) {
+    if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {
       if (auto *VarDIE = getDIE(BV))
         addDIEEntry(DW_Subrange, Attr, *VarDIE);
-    } else if (auto *BE = Bound.dyn_cast<DIExpression *>()) {
+    } else if (auto *BE = dyn_cast_if_present<DIExpression *>(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<ConstantInt *>()) {
+    } else if (auto *BI = dyn_cast_if_present<ConstantInt *>(Bound)) {
       if (Attr == dwarf::DW_AT_count) {
         if (BI->getSExtValue() != -1)
           addUInt(DW_Subrange, Attr, std::nullopt, BI->getSExtValue());
@@ -1401,10 +1401,10 @@ void DwarfUnit::constructGenericSubrangeDIE(DIE &Buffer,
 
   auto AddBoundTypeEntry = [&](dwarf::Attribute Attr,
                                DIGenericSubrange::BoundType Bound) -> void {
-    if (auto *BV = Bound.dyn_cast<DIVariable *>()) {
+    if (auto *BV = dyn_cast_if_present<DIVariable *>(Bound)) {
       if (auto *VarDIE = getDIE(BV))
         addDIEEntry(DwGenericSubrange, Attr, *VarDIE);
-    } else if (auto *BE = Bound.dyn_cast<DIExpression *>()) {
+    } else if (auto *BE = dyn_cast_if_present<DIExpression *>(Bound)) {
       if (BE->isConstant() &&
           DIExpression::SignedOrUnsignedConstant::SignedConstant ==
               *BE->isConstant()) {
@@ -1463,7 +1463,7 @@ static bool hasVectorBeenPadded(const DICompositeType *CTy) {
   const auto Subrange = cast<DISubrange>(Elements[0]);
   const auto NumVecElements =
       Subrange->getCount()
-          ? Subrange->getCount().get<ConstantInt *>()->getSExtValue()
+          ? cast<ConstantInt *>(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
index 6bfb5a6669aeb..6d6432b61f2d7 100644
--- a/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/WinException.cpp
@@ -638,7 +638,7 @@ void WinException::emitSEHActionsForRange(const WinEHFuncInfo &FuncInfo,
     const SEHUnwindMapEntry &UME = FuncInfo.SEHUnwindMap[State];
     const MCExpr *FilterOrFinally;
     const MCExpr *ExceptOrNull;
-    auto *Handler = UME.Handler.get<MachineBasicBlock *>();
+    auto *Handler = cast<MachineBasicBlock *>(UME.Handler);
     if (UME.IsFinally) {
       FilterOrFinally = create32bitRef(getMCSymbolForMBB(Asm, Handler));
       ExceptOrNull = MCConstantExpr::create(0, Ctx);
@@ -775,8 +775,8 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) {
   if (UnwindMapXData) {
     OS.emitLabel(UnwindMapXData);
     for (const CxxUnwindMapEntry &UME : FuncInfo.CxxUnwindMap) {
-      MCSymbol *CleanupSym =
-          getMCSymbolForMBB(Asm, UME.Cleanup.dyn_cast<MachineBasicBlock *>());
+      MCSymbol *CleanupSym = getMCSymbolForMBB(
+          Asm, dyn_cast_if_present<MachineBasicBlock *>(UME.Cleanup));
       AddComment("ToState");
       OS.emitInt32(UME.ToState);
 
@@ -863,8 +863,8 @@ void WinException::emitCXXFrameHandler3Table(const MachineFunction *MF) {
           FrameAllocOffsetRef = MCConstantExpr::create(0, Asm->OutContext);
         }
 
-        MCSymbol *HandlerSym =
-            getMCSymbolForMBB(Asm, HT.Handler.dyn_cast<MachineBasicBlock *>());
+        MCSymbol *HandlerSym = getMCSymbolForMBB(
+            Asm, dyn_cast_if_present<MachineBasicBlock *>(HT.Handler));
 
         AddComment("Adjectives");
         OS.emitInt32(HT.Adjectives);
@@ -1069,7 +1069,7 @@ void WinException::emitExceptHandlerTable(const MachineFunction *MF) {
 
   assert(!FuncInfo.SEHUnwindMap.empty());
   for (const SEHUnwindMapEntry &UME : FuncInfo.SEHUnwindMap) {
-    auto *Handler = UME.Handler.get<MachineBasicBlock *>();
+    auto *Handler = cast<MachineBasicBlock *>(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 @@ void WinException::emitCLRExceptionTable(const MachineFunction *MF) {
   DenseMap<const MachineBasicBlock *, int> HandlerStates;
   for (int State = 0; State < NumStates; ++State) {
     MachineBasicBlock *HandlerBlock =
-        FuncInfo.ClrEHUnwindMap[State].Handler.get<MachineBasicBlock *>();
+        cast<MachineBasicBlock *>(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 @@ void WinException::emitCLRExceptionTable(const MachineFunction *MF) {
     const MCExpr *ClauseEnd = getOffsetPlusOne(Clause.EndLabel, FuncBeginSym);
 
     const ClrEHUnwindMapEntry &Entry = FuncInfo.ClrEHUnwindMap[Clause.State];
-    MachineBasicBlock *HandlerBlock = Entry.Handler.get<MachineBasicBlock *>();
+    MachineBasicBlock *HandlerBlock = cast<MachineBasicBlock *>(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
index 6d8f5d55ad8ad..e047996f9aa8b 100644
--- a/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/CSEInfo.cpp
@@ -396,9 +396,10 @@ GISelInstProfileBuilder::addNodeIDReg(Register Reg) const {
     addNodeIDRegType(Ty);
 
   if (const RegClassOrRegBank &RCOrRB = MRI.getRegClassOrRegBank(Reg)) {
-    if (const auto *RB = RCOrRB.dyn_cast<const RegisterBank *>())
+    if (const auto *RB = dyn_cast_if_present<const RegisterBank *>(RCOrRB))
       addNodeIDRegType(RB);
-    else if (const auto *RC = RCOrRB.dyn_cast<const TargetRegisterClass *>())
+    else if (const auto *RC =
+                 dyn_cast_if_present<const TargetRegisterClass *>(RCOrRB))
       addNodeIDRegType(RC);
   }
   return *this;

diff  --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 641160f36587e..fb47832bc5fb8 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -711,14 +711,14 @@ bool llvm::isKnownNeverNaN(Register Val, const MachineRegisterInfo &MRI,
 
 Align llvm::inferAlignFromPtrInfo(MachineFunction &MF,
                                   const MachinePointerInfo &MPO) {
-  auto PSV = MPO.V.dyn_cast<const PseudoSourceValue *>();
+  auto PSV = dyn_cast_if_present<const PseudoSourceValue *>(MPO.V);
   if (auto FSPV = dyn_cast_or_null<FixedStackPseudoSourceValue>(PSV)) {
     MachineFrameInfo &MFI = MF.getFrameInfo();
     return commonAlignment(MFI.getObjectAlign(FSPV->getFrameIndex()),
                            MPO.Offset);
   }
 
-  if (const Value *V = MPO.V.dyn_cast<const Value *>()) {
+  if (const Value *V = dyn_cast_if_present<const Value *>(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
index 5a43f69fe7187..63c5eb46d3623 100644
--- a/llvm/lib/CodeGen/MachineOperand.cpp
+++ b/llvm/lib/CodeGen/MachineOperand.cpp
@@ -1027,10 +1027,10 @@ unsigned MachinePointerInfo::getAddrSpace() const { return AddrSpace; }
 /// Offset + Size byte.
 bool MachinePointerInfo::isDereferenceable(unsigned Size, LLVMContext &C,
                                            const DataLayout &DL) const {
-  if (!V.is<const Value *>())
+  if (!isa<const Value *>(V))
     return false;
 
-  const Value *BasePtr = V.get<const Value *>();
+  const Value *BasePtr = cast<const Value *>(V);
   if (BasePtr == nullptr)
     return false;
 
@@ -1075,8 +1075,8 @@ MachineMemOperand::MachineMemOperand(MachinePointerInfo ptrinfo, Flags f,
                                      AtomicOrdering FailureOrdering)
     : PtrInfo(ptrinfo), MemoryType(type), FlagVals(f), BaseAlign(a),
       AAInfo(AAInfo), Ranges(Ranges) {
-  assert((PtrInfo.V.isNull() || PtrInfo.V.is<const PseudoSourceValue *>() ||
-          isa<PointerType>(PtrInfo.V.get<const Value *>()->getType())) &&
+  assert((PtrInfo.V.isNull() || isa<const PseudoSourceValue *>(PtrInfo.V) ||
+          isa<PointerType>(cast<const Value *>(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
index 1ad08e19feae8..377321a165d56 100644
--- a/llvm/lib/CodeGen/MachineRegisterInfo.cpp
+++ b/llvm/lib/CodeGen/MachineRegisterInfo.cpp
@@ -101,13 +101,13 @@ MachineRegisterInfo::constrainRegAttrs(Register Reg,
     const auto RegCB = getRegClassOrRegBank(Reg);
     if (RegCB.isNull())
       setRegClassOrRegBank(Reg, ConstrainingRegCB);
-    else if (RegCB.is<const TargetRegisterClass *>() !=
-             ConstrainingRegCB.is<const TargetRegisterClass *>())
+    else if (isa<const TargetRegisterClass *>(RegCB) !=
+             isa<const TargetRegisterClass *>(ConstrainingRegCB))
       return false;
-    else if (RegCB.is<const TargetRegisterClass *>()) {
+    else if (isa<const TargetRegisterClass *>(RegCB)) {
       if (!::constrainRegClass(
-              *this, Reg, RegCB.get<const TargetRegisterClass *>(),
-              ConstrainingRegCB.get<const TargetRegisterClass *>(), MinNumRegs))
+              *this, Reg, cast<const TargetRegisterClass *>(RegCB),
+              cast<const TargetRegisterClass *>(ConstrainingRegCB), MinNumRegs))
         return false;
     } else if (RegCB != ConstrainingRegCB)
       return false;

diff  --git a/llvm/lib/CodeGen/RegisterBankInfo.cpp b/llvm/lib/CodeGen/RegisterBankInfo.cpp
index 801b82e596739..58f76c29122b0 100644
--- a/llvm/lib/CodeGen/RegisterBankInfo.cpp
+++ b/llvm/lib/CodeGen/RegisterBankInfo.cpp
@@ -87,9 +87,10 @@ RegisterBankInfo::getRegBank(Register Reg, const MachineRegisterInfo &MRI,
   }
 
   const RegClassOrRegBank &RegClassOrBank = MRI.getRegClassOrRegBank(Reg);
-  if (auto *RB = RegClassOrBank.dyn_cast<const RegisterBank *>())
+  if (auto *RB = dyn_cast_if_present<const RegisterBank *>(RegClassOrBank))
     return RB;
-  if (auto *RC = RegClassOrBank.dyn_cast<const TargetRegisterClass *>())
+  if (auto *RC =
+          dyn_cast_if_present<const TargetRegisterClass *>(RegClassOrBank))
     return &getRegBankFromRegClass(*RC, MRI.getType(Reg));
   return nullptr;
 }
@@ -131,10 +132,10 @@ const TargetRegisterClass *RegisterBankInfo::constrainGenericRegister(
 
   // If the register already has a class, fallback to MRI::constrainRegClass.
   auto &RegClassOrBank = MRI.getRegClassOrRegBank(Reg);
-  if (RegClassOrBank.is<const TargetRegisterClass *>())
+  if (isa<const TargetRegisterClass *>(RegClassOrBank))
     return MRI.constrainRegClass(Reg, &RC);
 
-  const RegisterBank *RB = RegClassOrBank.get<const RegisterBank *>();
+  const RegisterBank *RB = cast<const RegisterBank *>(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
index 3dc76c77aad78..023a5a72eb4e1 100644
--- a/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
+++ b/llvm/lib/CodeGen/ScheduleDAGInstrs.cpp
@@ -1026,15 +1026,14 @@ raw_ostream &llvm::operator<<(raw_ostream &OS, const PseudoSourceValue* PSV) {
 
 void ScheduleDAGInstrs::Value2SUsMap::dump() {
   for (const auto &[ValType, SUs] : *this) {
-    if (ValType.is<const Value*>()) {
-      const Value *V = ValType.get<const Value*>();
+    if (isa<const Value *>(ValType)) {
+      const Value *V = cast<const Value *>(ValType);
       if (isa<UndefValue>(V))
         dbgs() << "Unknown";
       else
         V->printAsOperand(dbgs());
-    }
-    else if (ValType.is<const PseudoSourceValue*>())
-      dbgs() << ValType.get<const PseudoSourceValue*>();
+    } else if (isa<const PseudoSourceValue *>(ValType))
+      dbgs() << cast<const PseudoSourceValue *>(ValType);
     else
       llvm_unreachable("Unknown Value type.");
 

diff  --git a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
index 76ebdb471606c..df236c503e4b1 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp
@@ -292,18 +292,18 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
     for (WinEHTryBlockMapEntry &TBME : EHInfo.TryBlockMap) {
       for (WinEHHandlerType &H : TBME.HandlerArray) {
         if (H.Handler)
-          H.Handler = MBBMap[H.Handler.get<const BasicBlock *>()];
+          H.Handler = MBBMap[cast<const BasicBlock *>(H.Handler)];
       }
     }
     for (CxxUnwindMapEntry &UME : EHInfo.CxxUnwindMap)
       if (UME.Cleanup)
-        UME.Cleanup = MBBMap[UME.Cleanup.get<const BasicBlock *>()];
+        UME.Cleanup = MBBMap[cast<const BasicBlock *>(UME.Cleanup)];
     for (SEHUnwindMapEntry &UME : EHInfo.SEHUnwindMap) {
-      const auto *BB = UME.Handler.get<const BasicBlock *>();
+      const auto *BB = cast<const BasicBlock *>(UME.Handler);
       UME.Handler = MBBMap[BB];
     }
     for (ClrEHUnwindMapEntry &CME : EHInfo.ClrEHUnwindMap) {
-      const auto *BB = CME.Handler.get<const BasicBlock *>();
+      const auto *BB = cast<const BasicBlock *>(CME.Handler);
       CME.Handler = MBBMap[BB];
     }
   } else if (Personality == EHPersonality::Wasm_CXX) {
@@ -313,18 +313,18 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
     // Map all BB references in the Wasm EH data to MBBs.
     DenseMap<BBOrMBB, BBOrMBB> SrcToUnwindDest;
     for (auto &KV : EHInfo.SrcToUnwindDest) {
-      const auto *Src = KV.first.get<const BasicBlock *>();
-      const auto *Dest = KV.second.get<const BasicBlock *>();
+      const auto *Src = cast<const BasicBlock *>(KV.first);
+      const auto *Dest = cast<const BasicBlock *>(KV.second);
       SrcToUnwindDest[MBBMap[Src]] = MBBMap[Dest];
     }
     EHInfo.SrcToUnwindDest = std::move(SrcToUnwindDest);
     DenseMap<BBOrMBB, SmallPtrSet<BBOrMBB, 4>> UnwindDestToSrcs;
     for (auto &KV : EHInfo.UnwindDestToSrcs) {
-      const auto *Dest = KV.first.get<const BasicBlock *>();
+      const auto *Dest = cast<const BasicBlock *>(KV.first);
       UnwindDestToSrcs[MBBMap[Dest]] = SmallPtrSet<BBOrMBB, 4>();
       for (const auto P : KV.second)
         UnwindDestToSrcs[MBBMap[Dest]].insert(
-            MBBMap[P.get<const BasicBlock *>()]);
+            MBBMap[cast<const BasicBlock *>(P)]);
     }
     EHInfo.UnwindDestToSrcs = std::move(UnwindDestToSrcs);
   }

diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index c94c0f15bc9f5..14ab62eaa4de6 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -7125,7 +7125,7 @@ static SDValue getMemcpyLoadsAndStores(SelectionDAG &DAG, const SDLoc &dl,
   AAMDNodes NewAAInfo = AAInfo;
   NewAAInfo.TBAA = NewAAInfo.TBAAStruct = nullptr;
 
-  const Value *SrcVal = SrcPtrInfo.V.dyn_cast<const Value *>();
+  const Value *SrcVal = dyn_cast_if_present<const Value *>(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
index 20ce2decaad06..45685f59e1631 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
@@ -119,25 +119,25 @@ class SelectionDAGBuilder {
         : Info(VarLoc), SDNodeOrder(SDNO) {}
 
     DILocalVariable *getVariable(const FunctionVarLocs *Locs) const {
-      if (Info.is<VarLocTy>())
-        return Locs->getDILocalVariable(Info.get<VarLocTy>()->VariableID);
-      return Info.get<DbgValTy>()->getVariable();
+      if (isa<VarLocTy>(Info))
+        return Locs->getDILocalVariable(cast<VarLocTy>(Info)->VariableID);
+      return cast<DbgValTy>(Info)->getVariable();
     }
     DIExpression *getExpression() const {
-      if (Info.is<VarLocTy>())
-        return Info.get<VarLocTy>()->Expr;
-      return Info.get<DbgValTy>()->getExpression();
+      if (isa<VarLocTy>(Info))
+        return cast<VarLocTy>(Info)->Expr;
+      return cast<DbgValTy>(Info)->getExpression();
     }
     Value *getVariableLocationOp(unsigned Idx) const {
       assert(Idx == 0 && "Dangling variadic debug values not supported yet");
-      if (Info.is<VarLocTy>())
-        return Info.get<VarLocTy>()->Values.getVariableLocationOp(Idx);
-      return Info.get<DbgValTy>()->getVariableLocationOp(Idx);
+      if (isa<VarLocTy>(Info))
+        return cast<VarLocTy>(Info)->Values.getVariableLocationOp(Idx);
+      return cast<DbgValTy>(Info)->getVariableLocationOp(Idx);
     }
     DebugLoc getDebugLoc() const {
-      if (Info.is<VarLocTy>())
-        return Info.get<VarLocTy>()->DL;
-      return Info.get<DbgValTy>()->getDebugLoc();
+      if (isa<VarLocTy>(Info))
+        return cast<VarLocTy>(Info)->DL;
+      return cast<DbgValTy>(Info)->getDebugLoc();
     }
     unsigned getSDNodeOrder() const { return SDNodeOrder; }
 

diff  --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp
index 9050f6be48762..11597b1198936 100644
--- a/llvm/lib/CodeGen/WinEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -737,7 +737,7 @@ void llvm::calculateClrEHStateNumbers(const Function *Fn,
   // so visit pads in descendant-most to ancestor-most order.
   for (ClrEHUnwindMapEntry &Entry : llvm::reverse(FuncInfo.ClrEHUnwindMap)) {
     const Instruction *Pad =
-        Entry.Handler.get<const BasicBlock *>()->getFirstNonPHI();
+        cast<const BasicBlock *>(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 @@ void llvm::calculateClrEHStateNumbers(const Function *Fn,
           int UserUnwindState =
               FuncInfo.ClrEHUnwindMap[UserState].TryParentState;
           if (UserUnwindState != -1)
-            UserUnwindDest = FuncInfo.ClrEHUnwindMap[UserUnwindState]
-                                 .Handler.get<const BasicBlock *>();
+            UserUnwindDest = cast<const BasicBlock *>(
+                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
index 4c27dfe7e9bc6..5f82f816dc19d 100644
--- a/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp
+++ b/llvm/lib/DebugInfo/LogicalView/LVReaderHandler.cpp
@@ -41,8 +41,8 @@ Error LVReaderHandler::createReader(StringRef Filename, LVReaders &Readers,
                                     PdbOrObj &Input, StringRef FileFormatName,
                                     StringRef ExePath) {
   auto CreateOneReader = [&]() -> std::unique_ptr<LVReader> {
-    if (Input.is<ObjectFile *>()) {
-      ObjectFile &Obj = *Input.get<ObjectFile *>();
+    if (isa<ObjectFile *>(Input)) {
+      ObjectFile &Obj = *cast<ObjectFile *>(Input);
       if (Obj.isCOFF()) {
         COFFObjectFile *COFF = cast<COFFObjectFile>(&Obj);
         return std::make_unique<LVCodeViewReader>(Filename, FileFormatName,
@@ -51,8 +51,8 @@ Error LVReaderHandler::createReader(StringRef Filename, LVReaders &Readers,
       if (Obj.isELF() || Obj.isMachO())
         return std::make_unique<LVELFReader>(Filename, FileFormatName, Obj, W);
     }
-    if (Input.is<PDBFile *>()) {
-      PDBFile &Pdb = *Input.get<PDBFile *>();
+    if (isa<PDBFile *>(Input)) {
+      PDBFile &Pdb = *cast<PDBFile *>(Input);
       return std::make_unique<LVCodeViewReader>(Filename, FileFormatName, Pdb,
                                                 W, ExePath);
     }
@@ -243,7 +243,7 @@ Error LVReaderHandler::handleObject(LVReaders &Readers, StringRef Filename,
                                     Binary &Binary) {
   if (PdbOrObj Input = dyn_cast<ObjectFile>(&Binary))
     return createReader(Filename, Readers, Input,
-                        Input.get<ObjectFile *>()->getFileFormatName());
+                        cast<ObjectFile *>(Input)->getFileFormatName());
 
   if (MachOUniversalBinary *Fat = dyn_cast<MachOUniversalBinary>(&Binary))
     return handleMach(Readers, Filename, *Fat);

diff  --git a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
index 495b25077737a..29ace036d69b0 100644
--- a/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/InputFile.cpp
@@ -347,32 +347,32 @@ Expected<InputFile> InputFile::open(StringRef Path, bool AllowUnknownFile) {
 
 PDBFile &InputFile::pdb() {
   assert(isPdb());
-  return *PdbOrObj.get<PDBFile *>();
+  return *cast<PDBFile *>(PdbOrObj);
 }
 
 const PDBFile &InputFile::pdb() const {
   assert(isPdb());
-  return *PdbOrObj.get<PDBFile *>();
+  return *cast<PDBFile *>(PdbOrObj);
 }
 
 object::COFFObjectFile &InputFile::obj() {
   assert(isObj());
-  return *PdbOrObj.get<object::COFFObjectFile *>();
+  return *cast<object::COFFObjectFile *>(PdbOrObj);
 }
 
 const object::COFFObjectFile &InputFile::obj() const {
   assert(isObj());
-  return *PdbOrObj.get<object::COFFObjectFile *>();
+  return *cast<object::COFFObjectFile *>(PdbOrObj);
 }
 
 MemoryBuffer &InputFile::unknown() {
   assert(isUnknown());
-  return *PdbOrObj.get<MemoryBuffer *>();
+  return *cast<MemoryBuffer *>(PdbOrObj);
 }
 
 const MemoryBuffer &InputFile::unknown() const {
   assert(isUnknown());
-  return *PdbOrObj.get<MemoryBuffer *>();
+  return *cast<MemoryBuffer *>(PdbOrObj);
 }
 
 StringRef InputFile::getFilePath() const {
@@ -402,13 +402,13 @@ bool InputFile::hasIds() const {
   return pdb().hasPDBIpiStream();
 }
 
-bool InputFile::isPdb() const { return PdbOrObj.is<PDBFile *>(); }
+bool InputFile::isPdb() const { return isa<PDBFile *>(PdbOrObj); }
 
 bool InputFile::isObj() const {
-  return PdbOrObj.is<object::COFFObjectFile *>();
+  return isa<object::COFFObjectFile *>(PdbOrObj);
 }
 
-bool InputFile::isUnknown() const { return PdbOrObj.is<MemoryBuffer *>(); }
+bool InputFile::isUnknown() const { return isa<MemoryBuffer *>(PdbOrObj); }
 
 codeview::LazyRandomTypeCollection &
 InputFile::getOrCreateTypeCollection(TypeCollectionKind Kind) {

diff  --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index b958443f5db2b..1428cebfd6dac 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -582,14 +582,14 @@ DIBuilder::createArrayType(uint64_t Size, uint32_t AlignInBits, DIType *Ty,
       VMContext, dwarf::DW_TAG_array_type, "", nullptr, 0, nullptr, Ty, Size,
       AlignInBits, 0, DINode::FlagZero, Subscripts, 0, nullptr, nullptr, "",
       nullptr,
-      DL.is<DIExpression *>() ? (Metadata *)DL.get<DIExpression *>()
-                              : (Metadata *)DL.get<DIVariable *>(),
-      AS.is<DIExpression *>() ? (Metadata *)AS.get<DIExpression *>()
-                              : (Metadata *)AS.get<DIVariable *>(),
-      AL.is<DIExpression *>() ? (Metadata *)AL.get<DIExpression *>()
-                              : (Metadata *)AL.get<DIVariable *>(),
-      RK.is<DIExpression *>() ? (Metadata *)RK.get<DIExpression *>()
-                              : (Metadata *)RK.get<DIVariable *>());
+      isa<DIExpression *>(DL) ? (Metadata *)cast<DIExpression *>(DL)
+                              : (Metadata *)cast<DIVariable *>(DL),
+      isa<DIExpression *>(AS) ? (Metadata *)cast<DIExpression *>(AS)
+                              : (Metadata *)cast<DIVariable *>(AS),
+      isa<DIExpression *>(AL) ? (Metadata *)cast<DIExpression *>(AL)
+                              : (Metadata *)cast<DIVariable *>(AL),
+      isa<DIExpression *>(RK) ? (Metadata *)cast<DIExpression *>(RK)
+                              : (Metadata *)cast<DIVariable *>(RK));
   trackIfUnresolved(R);
   return R;
 }
@@ -714,8 +714,8 @@ DIGenericSubrange *DIBuilder::getOrCreateGenericSubrange(
     DIGenericSubrange::BoundType CountNode, DIGenericSubrange::BoundType LB,
     DIGenericSubrange::BoundType UB, DIGenericSubrange::BoundType Stride) {
   auto ConvToMetadata = [&](DIGenericSubrange::BoundType Bound) -> Metadata * {
-    return Bound.is<DIExpression *>() ? (Metadata *)Bound.get<DIExpression *>()
-                                      : (Metadata *)Bound.get<DIVariable *>();
+    return isa<DIExpression *>(Bound) ? (Metadata *)cast<DIExpression *>(Bound)
+                                      : (Metadata *)cast<DIVariable *>(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
index bb757269e55f9..cfcfcd762fdc3 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -195,9 +195,9 @@ SmallVector<Metadata *> ReplaceableMetadataImpl::getAllArgListUsers() {
   SmallVector<std::pair<OwnerTy, uint64_t> *> MDUsersWithID;
   for (auto Pair : UseMap) {
     OwnerTy Owner = Pair.second.first;
-    if (!Owner.is<Metadata *>())
+    if (!isa<Metadata *>(Owner))
       continue;
-    Metadata *OwnerMD = Owner.get<Metadata *>();
+    Metadata *OwnerMD = cast<Metadata *>(Owner);
     if (OwnerMD->getMetadataID() == Metadata::DIArgListKind)
       MDUsersWithID.push_back(&UseMap[Pair.first]);
   }
@@ -206,7 +206,7 @@ SmallVector<Metadata *> ReplaceableMetadataImpl::getAllArgListUsers() {
   });
   SmallVector<Metadata *> MDUsers;
   for (auto *UserWithID : MDUsersWithID)
-    MDUsers.push_back(UserWithID->first.get<Metadata *>());
+    MDUsers.push_back(cast<Metadata *>(UserWithID->first));
   return MDUsers;
 }
 
@@ -263,9 +263,9 @@ void ReplaceableMetadataImpl::SalvageDebugInfo(const Constant &C) {
     MetadataTracking::OwnerTy Owner = Pair.second.first;
     if (!Owner)
       continue;
-    if (!Owner.is<Metadata *>())
+    if (!isa<Metadata *>(Owner))
       continue;
-    auto *OwnerMD = dyn_cast<MDNode>(Owner.get<Metadata *>());
+    auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
     if (!OwnerMD)
       continue;
     if (isa<DINode>(OwnerMD)) {
@@ -301,13 +301,13 @@ void ReplaceableMetadataImpl::replaceAllUsesWith(Metadata *MD) {
     }
 
     // Check for MetadataAsValue.
-    if (Owner.is<MetadataAsValue *>()) {
-      Owner.get<MetadataAsValue *>()->handleChangedMetadata(MD);
+    if (isa<MetadataAsValue *>(Owner)) {
+      cast<MetadataAsValue *>(Owner)->handleChangedMetadata(MD);
       continue;
     }
 
     // There's a Metadata owner -- dispatch.
-    Metadata *OwnerMD = Owner.get<Metadata *>();
+    Metadata *OwnerMD = cast<Metadata *>(Owner);
     switch (OwnerMD->getMetadataID()) {
 #define HANDLE_METADATA_LEAF(CLASS)                                            \
   case Metadata::CLASS##Kind:                                                  \
@@ -341,11 +341,11 @@ void ReplaceableMetadataImpl::resolveAllUses(bool ResolveUsers) {
     auto Owner = Pair.second.first;
     if (!Owner)
       continue;
-    if (Owner.is<MetadataAsValue *>())
+    if (isa<MetadataAsValue *>(Owner))
       continue;
 
     // Resolve MDNodes that point at this.
-    auto *OwnerMD = dyn_cast<MDNode>(Owner.get<Metadata *>());
+    auto *OwnerMD = dyn_cast_if_present<MDNode>(cast<Metadata *>(Owner));
     if (!OwnerMD)
       continue;
     if (OwnerMD->isResolved())

diff  --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 28234af2488fd..74edba71c5981 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -1075,8 +1075,8 @@ void Verifier::visitDISubrange(const DISubrange &N) {
               isa<DIVariable>(CBound) || isa<DIExpression>(CBound),
           "Count must be signed constant or DIVariable or DIExpression", &N);
   auto Count = N.getCount();
-  CheckDI(!Count || !Count.is<ConstantInt *>() ||
-              Count.get<ConstantInt *>()->getSExtValue() >= -1,
+  CheckDI(!Count || !isa<ConstantInt *>(Count) ||
+              cast<ConstantInt *>(Count)->getSExtValue() >= -1,
           "invalid subrange count", &N);
   auto *LBound = N.getRawLowerBound();
   CheckDI(!LBound || isa<ConstantAsMetadata>(LBound) ||

diff  --git a/llvm/lib/LTO/LTO.cpp b/llvm/lib/LTO/LTO.cpp
index ff57f30c11af8..15b6e22a683c1 100644
--- a/llvm/lib/LTO/LTO.cpp
+++ b/llvm/lib/LTO/LTO.cpp
@@ -788,7 +788,7 @@ LTO::addRegularLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
     ModuleSymbolTable::Symbol Msym = *MsymI++;
     Skip();
 
-    if (GlobalValue *GV = Msym.dyn_cast<GlobalValue *>()) {
+    if (GlobalValue *GV = dyn_cast_if_present<GlobalValue *>(Msym)) {
       if (Res.Prevailing) {
         if (Sym.isUndefined())
           continue;
@@ -826,7 +826,8 @@ LTO::addRegularLTO(BitcodeModule BM, ArrayRef<InputFile::Symbol> Syms,
           GV->setDLLStorageClass(GlobalValue::DLLStorageClassTypes::
                                  DefaultStorageClass);
       }
-    } else if (auto *AS = Msym.dyn_cast<ModuleSymbolTable::AsmSymbol *>()) {
+    } else if (auto *AS =
+                   dyn_cast_if_present<ModuleSymbolTable::AsmSymbol *>(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
index d94695b7a60e4..87420c7b80f0e 100644
--- a/llvm/lib/LTO/LTOModule.cpp
+++ b/llvm/lib/LTO/LTOModule.cpp
@@ -348,7 +348,7 @@ void LTOModule::addDefinedDataSymbol(ModuleSymbolTable::Symbol Sym) {
     Buffer.c_str();
   }
 
-  const GlobalValue *V = Sym.get<GlobalValue *>();
+  const GlobalValue *V = cast<GlobalValue *>(Sym);
   addDefinedDataSymbol(Buffer, V);
 }
 
@@ -406,7 +406,7 @@ void LTOModule::addDefinedFunctionSymbol(ModuleSymbolTable::Symbol Sym) {
     Buffer.c_str();
   }
 
-  const Function *F = cast<Function>(Sym.get<GlobalValue *>());
+  const Function *F = cast<Function>(cast<GlobalValue *>(Sym));
   addDefinedFunctionSymbol(Buffer, F);
 }
 
@@ -556,7 +556,7 @@ void LTOModule::addPotentialUndefinedSymbol(ModuleSymbolTable::Symbol Sym,
 
   info.name = IterBool.first->first();
 
-  const GlobalValue *decl = Sym.dyn_cast<GlobalValue *>();
+  const GlobalValue *decl = dyn_cast_if_present<GlobalValue *>(Sym);
 
   if (decl->hasExternalWeakLinkage())
     info.attributes = LTO_SYMBOL_DEFINITION_WEAKUNDEF;
@@ -569,7 +569,7 @@ void LTOModule::addPotentialUndefinedSymbol(ModuleSymbolTable::Symbol Sym,
 
 void LTOModule::parseSymbols() {
   for (auto Sym : SymTab.symbols()) {
-    auto *GV = Sym.dyn_cast<GlobalValue *>();
+    auto *GV = dyn_cast_if_present<GlobalValue *>(Sym);
     uint32_t Flags = SymTab.getSymbolFlags(Sym);
     if (Flags & object::BasicSymbolRef::SF_FormatSpecific)
       continue;
@@ -691,7 +691,7 @@ Expected<uint32_t> LTOModule::getMachOCPUSubType() const {
 
 bool LTOModule::hasCtorDtor() const {
   for (auto Sym : SymTab.symbols()) {
-    if (auto *GV = Sym.dyn_cast<GlobalValue *>()) {
+    if (auto *GV = dyn_cast_if_present<GlobalValue *>(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
index 20fee44730803..14db7a10f3109 100644
--- a/llvm/lib/Object/IRSymtab.cpp
+++ b/llvm/lib/Object/IRSymtab.cpp
@@ -259,7 +259,7 @@ Error Builder::addSymbol(const ModuleSymbolTable &Msymtab,
     Sym.Flags |= 1 << storage::Symbol::FB_executable;
 
   Sym.ComdatIndex = -1;
-  auto *GV = Msym.dyn_cast<GlobalValue *>();
+  auto *GV = dyn_cast_if_present<GlobalValue *>(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
index 0d21011193973..0290a819e5de5 100644
--- a/llvm/lib/Object/ModuleSymbolTable.cpp
+++ b/llvm/lib/Object/ModuleSymbolTable.cpp
@@ -174,12 +174,12 @@ void ModuleSymbolTable::CollectAsmSymvers(
 }
 
 void ModuleSymbolTable::printSymbolName(raw_ostream &OS, Symbol S) const {
-  if (S.is<AsmSymbol *>()) {
-    OS << S.get<AsmSymbol *>()->first;
+  if (isa<AsmSymbol *>(S)) {
+    OS << cast<AsmSymbol *>(S)->first;
     return;
   }
 
-  auto *GV = S.get<GlobalValue *>();
+  auto *GV = cast<GlobalValue *>(S);
   if (GV->hasDLLImportStorageClass())
     OS << "__imp_";
 
@@ -187,10 +187,10 @@ void ModuleSymbolTable::printSymbolName(raw_ostream &OS, Symbol S) const {
 }
 
 uint32_t ModuleSymbolTable::getSymbolFlags(Symbol S) const {
-  if (S.is<AsmSymbol *>())
-    return S.get<AsmSymbol *>()->second;
+  if (isa<AsmSymbol *>(S))
+    return cast<AsmSymbol *>(S)->second;
 
-  auto *GV = S.get<GlobalValue *>();
+  auto *GV = cast<GlobalValue *>(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
index 0f95e5c142f98..10637dc05d84f 100644
--- a/llvm/lib/Target/X86/X86InstructionSelector.cpp
+++ b/llvm/lib/Target/X86/X86InstructionSelector.cpp
@@ -247,9 +247,9 @@ bool X86InstructionSelector::selectDebugInstr(MachineInstr &I,
     LLT Ty = MRI.getType(Reg);
     const RegClassOrRegBank &RegClassOrBank = MRI.getRegClassOrRegBank(Reg);
     const TargetRegisterClass *RC =
-        RegClassOrBank.dyn_cast<const TargetRegisterClass *>();
+        dyn_cast_if_present<const TargetRegisterClass *>(RegClassOrBank);
     if (!RC) {
-      const RegisterBank &RB = *RegClassOrBank.get<const RegisterBank *>();
+      const RegisterBank &RB = *cast<const RegisterBank *>(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
index be5db9e250621..9b4b3efd7283e 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -2269,9 +2269,9 @@ bool LowerTypeTestsModule::lower() {
     unsigned MaxUniqueId = 0;
     for (GlobalClassesTy::member_iterator MI = GlobalClasses.member_begin(I);
          MI != GlobalClasses.member_end(); ++MI) {
-      if (auto *MD = MI->dyn_cast<Metadata *>())
+      if (auto *MD = dyn_cast_if_present<Metadata *>(*MI))
         MaxUniqueId = std::max(MaxUniqueId, TypeIdInfo[MD].UniqueId);
-      else if (auto *BF = MI->dyn_cast<ICallBranchFunnel *>())
+      else if (auto *BF = dyn_cast_if_present<ICallBranchFunnel *>(*MI))
         MaxUniqueId = std::max(MaxUniqueId, BF->UniqueId);
     }
     Sets.emplace_back(I, MaxUniqueId);
@@ -2287,12 +2287,12 @@ bool LowerTypeTestsModule::lower() {
     for (GlobalClassesTy::member_iterator MI =
              GlobalClasses.member_begin(S.first);
          MI != GlobalClasses.member_end(); ++MI) {
-      if (MI->is<Metadata *>())
-        TypeIds.push_back(MI->get<Metadata *>());
-      else if (MI->is<GlobalTypeMember *>())
-        Globals.push_back(MI->get<GlobalTypeMember *>());
+      if (isa<Metadata *>(*MI))
+        TypeIds.push_back(cast<Metadata *>(*MI));
+      else if (isa<GlobalTypeMember *>(*MI))
+        Globals.push_back(cast<GlobalTypeMember *>(*MI));
       else
-        ICallBranchFunnels.push_back(MI->get<ICallBranchFunnel *>());
+        ICallBranchFunnels.push_back(cast<ICallBranchFunnel *>(*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
index 25211bf934797..f9ad2d30d07b9 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -471,11 +471,13 @@ struct IndexCall : public PointerUnion<CallsiteInfo *, AllocInfo *> {
 
   IndexCall *operator->() { return this; }
 
+  PointerUnion<CallsiteInfo *, AllocInfo *> getBase() const { return *this; }
+
   void print(raw_ostream &OS) const {
-    if (auto *AI = dyn_cast<AllocInfo *>())
+    if (auto *AI = llvm::dyn_cast_if_present<AllocInfo *>(getBase())) {
       OS << *AI;
-    else {
-      auto *CI = dyn_cast<CallsiteInfo *>();
+    } else {
+      auto *CI = llvm::dyn_cast_if_present<CallsiteInfo *>(getBase());
       assert(CI);
       OS << *CI;
     }
@@ -1185,9 +1187,9 @@ uint64_t ModuleCallsiteContextGraph::getLastStackId(Instruction *Call) {
 }
 
 uint64_t IndexCallsiteContextGraph::getLastStackId(IndexCall &Call) {
-  assert(Call.is<CallsiteInfo *>());
+  assert(isa<CallsiteInfo *>(Call.getBase()));
   CallStack<CallsiteInfo, SmallVector<unsigned>::const_iterator>
-      CallsiteContext(Call.dyn_cast<CallsiteInfo *>());
+      CallsiteContext(dyn_cast_if_present<CallsiteInfo *>(Call.getBase()));
   // Need to convert index into stack id.
   return Index.getStackIdAtIndex(CallsiteContext.back());
 }
@@ -1211,10 +1213,10 @@ std::string IndexCallsiteContextGraph::getLabel(const FunctionSummary *Func,
                                                 unsigned CloneNo) const {
   auto VI = FSToVIMap.find(Func);
   assert(VI != FSToVIMap.end());
-  if (Call.is<AllocInfo *>())
+  if (isa<AllocInfo *>(Call.getBase()))
     return (VI->second.name() + " -> alloc").str();
   else {
-    auto *Callsite = Call.dyn_cast<CallsiteInfo *>();
+    auto *Callsite = dyn_cast_if_present<CallsiteInfo *>(Call.getBase());
     return (VI->second.name() + " -> " +
             getMemProfFuncName(Callsite->Callee.name(),
                                Callsite->Clones[CloneNo]))
@@ -1233,9 +1235,9 @@ ModuleCallsiteContextGraph::getStackIdsWithContextNodesForCall(
 
 std::vector<uint64_t>
 IndexCallsiteContextGraph::getStackIdsWithContextNodesForCall(IndexCall &Call) {
-  assert(Call.is<CallsiteInfo *>());
+  assert(isa<CallsiteInfo *>(Call.getBase()));
   CallStack<CallsiteInfo, SmallVector<unsigned>::const_iterator>
-      CallsiteContext(Call.dyn_cast<CallsiteInfo *>());
+      CallsiteContext(dyn_cast_if_present<CallsiteInfo *>(Call.getBase()));
   return getStackIdsWithContextNodes<CallsiteInfo,
                                      SmallVector<unsigned>::const_iterator>(
       CallsiteContext);
@@ -1456,7 +1458,8 @@ bool ModuleCallsiteContextGraph::calleeMatchesFunc(Instruction *Call,
 
 bool IndexCallsiteContextGraph::calleeMatchesFunc(IndexCall &Call,
                                                   const FunctionSummary *Func) {
-  ValueInfo Callee = Call.dyn_cast<CallsiteInfo *>()->Callee;
+  ValueInfo Callee =
+      dyn_cast_if_present<CallsiteInfo *>(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
index dc58bebd724b0..52e4c9e5edde5 100644
--- a/llvm/lib/Transforms/Utils/Evaluator.cpp
+++ b/llvm/lib/Transforms/Utils/Evaluator.cpp
@@ -121,7 +121,7 @@ isSimpleEnoughValueToCommit(Constant *C,
 }
 
 void Evaluator::MutableValue::clear() {
-  if (auto *Agg = Val.dyn_cast<MutableAggregate *>())
+  if (auto *Agg = dyn_cast_if_present<MutableAggregate *>(Val))
     delete Agg;
   Val = nullptr;
 }
@@ -130,7 +130,7 @@ Constant *Evaluator::MutableValue::read(Type *Ty, APInt Offset,
                                         const DataLayout &DL) const {
   TypeSize TySize = DL.getTypeStoreSize(Ty);
   const MutableValue *V = this;
-  while (const auto *Agg = V->Val.dyn_cast<MutableAggregate *>()) {
+  while (const auto *Agg = dyn_cast_if_present<MutableAggregate *>(V->Val)) {
     Type *AggTy = Agg->Ty;
     std::optional<APInt> Index = DL.getGEPIndexForOffset(AggTy, Offset);
     if (!Index || Index->uge(Agg->Elements.size()) ||
@@ -140,11 +140,11 @@ Constant *Evaluator::MutableValue::read(Type *Ty, APInt Offset,
     V = &Agg->Elements[Index->getZExtValue()];
   }
 
-  return ConstantFoldLoadFromConst(V->Val.get<Constant *>(), Ty, Offset, DL);
+  return ConstantFoldLoadFromConst(cast<Constant *>(V->Val), Ty, Offset, DL);
 }
 
 bool Evaluator::MutableValue::makeMutable() {
-  Constant *C = Val.get<Constant *>();
+  Constant *C = cast<Constant *>(Val);
   Type *Ty = C->getType();
   unsigned NumElements;
   if (auto *VT = dyn_cast<FixedVectorType>(Ty)) {
@@ -171,10 +171,10 @@ bool Evaluator::MutableValue::write(Constant *V, APInt Offset,
   MutableValue *MV = this;
   while (Offset != 0 ||
          !CastInst::isBitOrNoopPointerCastable(Ty, MV->getType(), DL)) {
-    if (MV->Val.is<Constant *>() && !MV->makeMutable())
+    if (isa<Constant *>(MV->Val) && !MV->makeMutable())
       return false;
 
-    MutableAggregate *Agg = MV->Val.get<MutableAggregate *>();
+    MutableAggregate *Agg = cast<MutableAggregate *>(MV->Val);
     Type *AggTy = Agg->Ty;
     std::optional<APInt> 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
index fb36daeacfe1f..254af15523cc4 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -8994,8 +8994,8 @@ std::optional<VPlanPtr> LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
       if (!RecipeOrValue)
         RecipeOrValue = RecipeBuilder.handleReplication(Instr, Range, *Plan);
       // If Instr can be simplified to an existing VPValue, use it.
-      if (RecipeOrValue.is<VPValue *>()) {
-        auto *VPV = RecipeOrValue.get<VPValue *>();
+      if (isa<VPValue *>(RecipeOrValue)) {
+        auto *VPV = cast<VPValue *>(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 @@ std::optional<VPlanPtr> LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
         continue;
       }
       // Otherwise, add the new recipe.
-      VPRecipeBase *Recipe = RecipeOrValue.get<VPRecipeBase *>();
+      VPRecipeBase *Recipe = cast<VPRecipeBase *>(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
index 25382d8ab3d12..77d8b85714976 100644
--- a/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
+++ b/llvm/tools/llvm-reduce/ReducerWorkItem.cpp
@@ -165,7 +165,7 @@ static void cloneMemOperands(MachineInstr &DstMI, MachineInstr &SrcMI,
   for (MachineMemOperand *OldMMO : SrcMI.memoperands()) {
     MachinePointerInfo NewPtrInfo(OldMMO->getPointerInfo());
     if (const PseudoSourceValue *PSV =
-            NewPtrInfo.V.dyn_cast<const PseudoSourceValue *>()) {
+            dyn_cast_if_present<const PseudoSourceValue *>(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
index fe4e13bafd79c..4bb1eb7db1d09 100644
--- a/llvm/tools/llvm-reduce/deltas/ReduceIRReferences.cpp
+++ b/llvm/tools/llvm-reduce/deltas/ReduceIRReferences.cpp
@@ -27,7 +27,7 @@ static void dropIRReferencesFromInstructions(Oracle &O, MachineFunction &MF) {
         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<const Value *>())
+          if (isa<const Value *>(MMO->getPointerInfo().V))
             MMO->setValue(static_cast<const Value *>(nullptr));
         }
 

diff  --git a/llvm/unittests/ADT/PointerUnionTest.cpp b/llvm/unittests/ADT/PointerUnionTest.cpp
index 43ab6a97cffdd..acddb78960149 100644
--- a/llvm/unittests/ADT/PointerUnionTest.cpp
+++ b/llvm/unittests/ADT/PointerUnionTest.cpp
@@ -89,29 +89,29 @@ TEST_F(PointerUnionTest, Null) {
 }
 
 TEST_F(PointerUnionTest, Is) {
-  EXPECT_FALSE(a.is<int *>());
-  EXPECT_TRUE(a.is<float *>());
-  EXPECT_TRUE(b.is<int *>());
-  EXPECT_FALSE(b.is<float *>());
-  EXPECT_TRUE(n.is<int *>());
-  EXPECT_FALSE(n.is<float *>());
-  EXPECT_TRUE(i3.is<int *>());
-  EXPECT_TRUE(f3.is<float *>());
-  EXPECT_TRUE(l3.is<long long *>());
-  EXPECT_TRUE(i4.is<int *>());
-  EXPECT_TRUE(f4.is<float *>());
-  EXPECT_TRUE(l4.is<long long *>());
-  EXPECT_TRUE(d4.is<double *>());
-  EXPECT_TRUE(i4null.is<int *>());
-  EXPECT_TRUE(f4null.is<float *>());
-  EXPECT_TRUE(l4null.is<long long *>());
-  EXPECT_TRUE(d4null.is<double *>());
+  EXPECT_FALSE(isa<int *>(a));
+  EXPECT_TRUE(isa<float *>(a));
+  EXPECT_TRUE(isa<int *>(b));
+  EXPECT_FALSE(isa<float *>(b));
+  EXPECT_TRUE(isa<int *>(n));
+  EXPECT_FALSE(isa<float *>(n));
+  EXPECT_TRUE(isa<int *>(i3));
+  EXPECT_TRUE(isa<float *>(f3));
+  EXPECT_TRUE(isa<long long *>(l3));
+  EXPECT_TRUE(isa<int *>(i4));
+  EXPECT_TRUE(isa<float *>(f4));
+  EXPECT_TRUE(isa<long long *>(l4));
+  EXPECT_TRUE(isa<double *>(d4));
+  EXPECT_TRUE(isa<int *>(i4null));
+  EXPECT_TRUE(isa<float *>(f4null));
+  EXPECT_TRUE(isa<long long *>(l4null));
+  EXPECT_TRUE(isa<double *>(d4null));
 }
 
 TEST_F(PointerUnionTest, Get) {
-  EXPECT_EQ(a.get<float *>(), &f);
-  EXPECT_EQ(b.get<int *>(), &i);
-  EXPECT_EQ(n.get<int *>(), (int *)nullptr);
+  EXPECT_EQ(cast<float *>(a), &f);
+  EXPECT_EQ(cast<int *>(b), &i);
+  EXPECT_EQ(cast<int *>(n), (int *)nullptr);
 }
 
 template<int I> struct alignas(8) Aligned {};
@@ -125,27 +125,27 @@ TEST_F(PointerUnionTest, ManyElements) {
   Aligned<7> a7;
 
   PU8 a = &a0;
-  EXPECT_TRUE(a.is<Aligned<0>*>());
-  EXPECT_FALSE(a.is<Aligned<1>*>());
-  EXPECT_FALSE(a.is<Aligned<2>*>());
-  EXPECT_FALSE(a.is<Aligned<3>*>());
-  EXPECT_FALSE(a.is<Aligned<4>*>());
-  EXPECT_FALSE(a.is<Aligned<5>*>());
-  EXPECT_FALSE(a.is<Aligned<6>*>());
-  EXPECT_FALSE(a.is<Aligned<7>*>());
-  EXPECT_EQ(a.dyn_cast<Aligned<0>*>(), &a0);
+  EXPECT_TRUE(isa<Aligned<0> *>(a));
+  EXPECT_FALSE(isa<Aligned<1> *>(a));
+  EXPECT_FALSE(isa<Aligned<2> *>(a));
+  EXPECT_FALSE(isa<Aligned<3> *>(a));
+  EXPECT_FALSE(isa<Aligned<4> *>(a));
+  EXPECT_FALSE(isa<Aligned<5> *>(a));
+  EXPECT_FALSE(isa<Aligned<6> *>(a));
+  EXPECT_FALSE(isa<Aligned<7> *>(a));
+  EXPECT_EQ(dyn_cast_if_present<Aligned<0> *>(a), &a0);
   EXPECT_EQ(*a.getAddrOfPtr1(), &a0);
 
   a = &a7;
-  EXPECT_FALSE(a.is<Aligned<0>*>());
-  EXPECT_FALSE(a.is<Aligned<1>*>());
-  EXPECT_FALSE(a.is<Aligned<2>*>());
-  EXPECT_FALSE(a.is<Aligned<3>*>());
-  EXPECT_FALSE(a.is<Aligned<4>*>());
-  EXPECT_FALSE(a.is<Aligned<5>*>());
-  EXPECT_FALSE(a.is<Aligned<6>*>());
-  EXPECT_TRUE(a.is<Aligned<7>*>());
-  EXPECT_EQ(a.dyn_cast<Aligned<7>*>(), &a7);
+  EXPECT_FALSE(isa<Aligned<0> *>(a));
+  EXPECT_FALSE(isa<Aligned<1> *>(a));
+  EXPECT_FALSE(isa<Aligned<2> *>(a));
+  EXPECT_FALSE(isa<Aligned<3> *>(a));
+  EXPECT_FALSE(isa<Aligned<4> *>(a));
+  EXPECT_FALSE(isa<Aligned<5> *>(a));
+  EXPECT_FALSE(isa<Aligned<6> *>(a));
+  EXPECT_TRUE(isa<Aligned<7> *>(a));
+  EXPECT_EQ(dyn_cast_if_present<Aligned<7> *>(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
index 04d9443ef1857..5342360109d0d 100644
--- a/llvm/unittests/IR/MetadataTest.cpp
+++ b/llvm/unittests/IR/MetadataTest.cpp
@@ -1420,9 +1420,9 @@ TEST_F(DISubrangeTest, get) {
   auto Lower = N->getLowerBound();
   EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag());
   ASSERT_TRUE(Count);
-  ASSERT_TRUE(Count.is<ConstantInt*>());
-  EXPECT_EQ(5, Count.get<ConstantInt*>()->getSExtValue());
-  EXPECT_EQ(7, Lower.get<ConstantInt *>()->getSExtValue());
+  ASSERT_TRUE(isa<ConstantInt *>(Count));
+  EXPECT_EQ(5, cast<ConstantInt *>(Count)->getSExtValue());
+  EXPECT_EQ(7, cast<ConstantInt *>(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 @@ TEST_F(DISubrangeTest, getEmptyArray) {
   auto Lower = N->getLowerBound();
   EXPECT_EQ(dwarf::DW_TAG_subrange_type, N->getTag());
   ASSERT_TRUE(Count);
-  ASSERT_TRUE(Count.is<ConstantInt*>());
-  EXPECT_EQ(-1, Count.get<ConstantInt*>()->getSExtValue());
-  EXPECT_EQ(0, Lower.get<ConstantInt *>()->getSExtValue());
+  ASSERT_TRUE(isa<ConstantInt *>(Count));
+  EXPECT_EQ(-1, cast<ConstantInt *>(Count)->getSExtValue());
+  EXPECT_EQ(0, cast<ConstantInt *>(Lower)->getSExtValue());
   EXPECT_EQ(N, DISubrange::get(Context, -1, 0));
 }
 
@@ -1454,11 +1454,11 @@ TEST_F(DISubrangeTest, getVariableCount) {
   auto Count = N->getCount();
   auto Lower = N->getLowerBound();
   ASSERT_TRUE(Count);
-  ASSERT_TRUE(Count.is<DIVariable*>());
-  EXPECT_EQ(VlaExpr, Count.get<DIVariable*>());
+  ASSERT_TRUE(isa<DIVariable *>(Count));
+  EXPECT_EQ(VlaExpr, cast<DIVariable *>(Count));
   ASSERT_TRUE(isa<DIVariable>(N->getRawCountNode()));
-  EXPECT_EQ(0, Lower.get<ConstantInt *>()->getSExtValue());
-  EXPECT_EQ("vla_expr", Count.get<DIVariable*>()->getName());
+  EXPECT_EQ(0, cast<ConstantInt *>(Lower)->getSExtValue());
+  EXPECT_EQ("vla_expr", cast<DIVariable *>(Count)->getName());
   EXPECT_EQ(N, DISubrange::get(Context, VlaExpr, 0));
 }
 
@@ -1487,18 +1487,18 @@ TEST_F(DISubrangeTest, fortranAllocatableInt) {
 
   auto Lower = N->getLowerBound();
   ASSERT_TRUE(Lower);
-  ASSERT_TRUE(Lower.is<ConstantInt *>());
-  EXPECT_EQ(cast<ConstantInt>(LI->getValue()), Lower.get<ConstantInt *>());
+  ASSERT_TRUE(isa<ConstantInt *>(Lower));
+  EXPECT_EQ(cast<ConstantInt>(LI->getValue()), cast<ConstantInt *>(Lower));
 
   auto Upper = N->getUpperBound();
   ASSERT_TRUE(Upper);
-  ASSERT_TRUE(Upper.is<ConstantInt *>());
-  EXPECT_EQ(cast<ConstantInt>(UI->getValue()), Upper.get<ConstantInt *>());
+  ASSERT_TRUE(isa<ConstantInt *>(Upper));
+  EXPECT_EQ(cast<ConstantInt>(UI->getValue()), cast<ConstantInt *>(Upper));
 
   auto Stride = N->getStride();
   ASSERT_TRUE(Stride);
-  ASSERT_TRUE(Stride.is<ConstantInt *>());
-  EXPECT_EQ(cast<ConstantInt>(SI->getValue()), Stride.get<ConstantInt *>());
+  ASSERT_TRUE(isa<ConstantInt *>(Stride));
+  EXPECT_EQ(cast<ConstantInt>(SI->getValue()), cast<ConstantInt *>(Stride));
 
   EXPECT_EQ(N, DISubrange::get(Context, nullptr, LI, UI, SI));
 
@@ -1537,18 +1537,18 @@ TEST_F(DISubrangeTest, fortranAllocatableVar) {
 
   auto Lower = N->getLowerBound();
   ASSERT_TRUE(Lower);
-  ASSERT_TRUE(Lower.is<DIVariable *>());
-  EXPECT_EQ(LV, Lower.get<DIVariable *>());
+  ASSERT_TRUE(isa<DIVariable *>(Lower));
+  EXPECT_EQ(LV, cast<DIVariable *>(Lower));
 
   auto Upper = N->getUpperBound();
   ASSERT_TRUE(Upper);
-  ASSERT_TRUE(Upper.is<DIVariable *>());
-  EXPECT_EQ(UV, Upper.get<DIVariable *>());
+  ASSERT_TRUE(isa<DIVariable *>(Upper));
+  EXPECT_EQ(UV, cast<DIVariable *>(Upper));
 
   auto Stride = N->getStride();
   ASSERT_TRUE(Stride);
-  ASSERT_TRUE(Stride.is<DIVariable *>());
-  EXPECT_EQ(SV, Stride.get<DIVariable *>());
+  ASSERT_TRUE(isa<DIVariable *>(Stride));
+  EXPECT_EQ(SV, cast<DIVariable *>(Stride));
 
   EXPECT_EQ(N, DISubrange::get(Context, nullptr, LV, UV, SV));
 
@@ -1575,18 +1575,18 @@ TEST_F(DISubrangeTest, fortranAllocatableExpr) {
 
   auto Lower = N->getLowerBound();
   ASSERT_TRUE(Lower);
-  ASSERT_TRUE(Lower.is<DIExpression *>());
-  EXPECT_EQ(LE, Lower.get<DIExpression *>());
+  ASSERT_TRUE(isa<DIExpression *>(Lower));
+  EXPECT_EQ(LE, cast<DIExpression *>(Lower));
 
   auto Upper = N->getUpperBound();
   ASSERT_TRUE(Upper);
-  ASSERT_TRUE(Upper.is<DIExpression *>());
-  EXPECT_EQ(UE, Upper.get<DIExpression *>());
+  ASSERT_TRUE(isa<DIExpression *>(Upper));
+  EXPECT_EQ(UE, cast<DIExpression *>(Upper));
 
   auto Stride = N->getStride();
   ASSERT_TRUE(Stride);
-  ASSERT_TRUE(Stride.is<DIExpression *>());
-  EXPECT_EQ(SE, Stride.get<DIExpression *>());
+  ASSERT_TRUE(isa<DIExpression *>(Stride));
+  EXPECT_EQ(SE, cast<DIExpression *>(Stride));
 
   EXPECT_EQ(N, DISubrange::get(Context, nullptr, LE, UE, SE));
 
@@ -1617,18 +1617,18 @@ TEST_F(DIGenericSubrangeTest, fortranAssumedRankInt) {
 
   auto Lower = N->getLowerBound();
   ASSERT_TRUE(Lower);
-  ASSERT_TRUE(Lower.is<DIExpression *>());
-  EXPECT_EQ(dyn_cast_or_null<DIExpression>(LI), Lower.get<DIExpression *>());
+  ASSERT_TRUE(isa<DIExpression *>(Lower));
+  EXPECT_EQ(dyn_cast_or_null<DIExpression>(LI), cast<DIExpression *>(Lower));
 
   auto Upper = N->getUpperBound();
   ASSERT_TRUE(Upper);
-  ASSERT_TRUE(Upper.is<DIExpression *>());
-  EXPECT_EQ(dyn_cast_or_null<DIExpression>(UI), Upper.get<DIExpression *>());
+  ASSERT_TRUE(isa<DIExpression *>(Upper));
+  EXPECT_EQ(dyn_cast_or_null<DIExpression>(UI), cast<DIExpression *>(Upper));
 
   auto Stride = N->getStride();
   ASSERT_TRUE(Stride);
-  ASSERT_TRUE(Stride.is<DIExpression *>());
-  EXPECT_EQ(dyn_cast_or_null<DIExpression>(SI), Stride.get<DIExpression *>());
+  ASSERT_TRUE(isa<DIExpression *>(Stride));
+  EXPECT_EQ(dyn_cast_or_null<DIExpression>(SI), cast<DIExpression *>(Stride));
 
   EXPECT_EQ(N, DIGenericSubrange::get(Context, nullptr, LI, UI, SI));
 
@@ -1669,18 +1669,18 @@ TEST_F(DIGenericSubrangeTest, fortranAssumedRankVar) {
 
   auto Lower = N->getLowerBound();
   ASSERT_TRUE(Lower);
-  ASSERT_TRUE(Lower.is<DIVariable *>());
-  EXPECT_EQ(LV, Lower.get<DIVariable *>());
+  ASSERT_TRUE(isa<DIVariable *>(Lower));
+  EXPECT_EQ(LV, cast<DIVariable *>(Lower));
 
   auto Upper = N->getUpperBound();
   ASSERT_TRUE(Upper);
-  ASSERT_TRUE(Upper.is<DIVariable *>());
-  EXPECT_EQ(UV, Upper.get<DIVariable *>());
+  ASSERT_TRUE(isa<DIVariable *>(Upper));
+  EXPECT_EQ(UV, cast<DIVariable *>(Upper));
 
   auto Stride = N->getStride();
   ASSERT_TRUE(Stride);
-  ASSERT_TRUE(Stride.is<DIVariable *>());
-  EXPECT_EQ(SV, Stride.get<DIVariable *>());
+  ASSERT_TRUE(isa<DIVariable *>(Stride));
+  EXPECT_EQ(SV, cast<DIVariable *>(Stride));
 
   EXPECT_EQ(N, DIGenericSubrange::get(Context, nullptr, LV, UV, SV));
 
@@ -1713,18 +1713,18 @@ TEST_F(DIGenericSubrangeTest, useDIBuilder) {
 
   auto Lower = N->getLowerBound();
   ASSERT_TRUE(Lower);
-  ASSERT_TRUE(Lower.is<DIVariable *>());
-  EXPECT_EQ(LV, Lower.get<DIVariable *>());
+  ASSERT_TRUE(isa<DIVariable *>(Lower));
+  EXPECT_EQ(LV, cast<DIVariable *>(Lower));
 
   auto Upper = N->getUpperBound();
   ASSERT_TRUE(Upper);
-  ASSERT_TRUE(Upper.is<DIExpression *>());
-  EXPECT_EQ(UE, Upper.get<DIExpression *>());
+  ASSERT_TRUE(isa<DIExpression *>(Upper));
+  EXPECT_EQ(UE, cast<DIExpression *>(Upper));
 
   auto Stride = N->getStride();
   ASSERT_TRUE(Stride);
-  ASSERT_TRUE(Stride.is<DIExpression *>());
-  EXPECT_EQ(SE, Stride.get<DIExpression *>());
+  ASSERT_TRUE(isa<DIExpression *>(Stride));
+  EXPECT_EQ(SE, cast<DIExpression *>(Stride));
 
   EXPECT_EQ(
       N, DIB.getOrCreateGenericSubrange(DIGenericSubrange::BoundType(nullptr),

diff  --git a/llvm/utils/TableGen/AsmMatcherEmitter.cpp b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
index a1082674ddf15..2fb35e712a758 100644
--- a/llvm/utils/TableGen/AsmMatcherEmitter.cpp
+++ b/llvm/utils/TableGen/AsmMatcherEmitter.cpp
@@ -506,9 +506,9 @@ struct MatchableInfo {
   PointerUnion<const CodeGenInstruction*, const CodeGenInstAlias*> DefRec;
 
   const CodeGenInstruction *getResultInst() const {
-    if (DefRec.is<const CodeGenInstruction*>())
-      return DefRec.get<const CodeGenInstruction*>();
-    return DefRec.get<const CodeGenInstAlias*>()->ResultInst;
+    if (isa<const CodeGenInstruction *>(DefRec))
+      return cast<const CodeGenInstruction *>(DefRec);
+    return cast<const CodeGenInstAlias *>(DefRec)->ResultInst;
   }
 
   /// ResOperands - This is the operand list that should be built for the result
@@ -564,11 +564,11 @@ struct MatchableInfo {
         ConversionFnKind(RHS.ConversionFnKind),
         HasDeprecation(RHS.HasDeprecation),
         UseInstAsmMatchConverter(RHS.UseInstAsmMatchConverter) {
-    assert(!DefRec.is<const CodeGenInstAlias *>());
+    assert(!isa<const CodeGenInstAlias *>(DefRec));
   }
 
   ~MatchableInfo() {
-    delete DefRec.dyn_cast<const CodeGenInstAlias*>();
+    delete dyn_cast_if_present<const CodeGenInstAlias *>(DefRec);
   }
 
   // Two-operand aliases clone from the main matchable, but mark the second
@@ -1614,13 +1614,13 @@ void AsmMatcherInfo::buildInfo() {
       else
         OperandName = Token.substr(1);
 
-      if (II->DefRec.is<const CodeGenInstruction*>())
+      if (isa<const CodeGenInstruction *>(II->DefRec))
         buildInstructionOperandReference(II.get(), OperandName, i);
       else
         buildAliasOperandReference(II.get(), OperandName, Op);
     }
 
-    if (II->DefRec.is<const CodeGenInstruction*>()) {
+    if (isa<const CodeGenInstruction *>(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 @@ void AsmMatcherInfo::
 buildInstructionOperandReference(MatchableInfo *II,
                                  StringRef OperandName,
                                  unsigned AsmOpIdx) {
-  const CodeGenInstruction &CGI = *II->DefRec.get<const CodeGenInstruction*>();
+  const CodeGenInstruction &CGI = *cast<const CodeGenInstruction *>(II->DefRec);
   const CGIOperandList &Operands = CGI.Operands;
   MatchableInfo::AsmOperand *Op = &II->AsmOperands[AsmOpIdx];
 
@@ -1746,7 +1746,7 @@ buildInstructionOperandReference(MatchableInfo *II,
 void AsmMatcherInfo::buildAliasOperandReference(MatchableInfo *II,
                                                 StringRef OperandName,
                                                 MatchableInfo::AsmOperand &Op) {
-  const CodeGenInstAlias &CGA = *II->DefRec.get<const CodeGenInstAlias*>();
+  const CodeGenInstAlias &CGA = *cast<const CodeGenInstAlias *>(II->DefRec);
 
   // Set up the operand class.
   for (unsigned i = 0, e = CGA.ResultOperands.size(); i != e; ++i)
@@ -1819,7 +1819,7 @@ void MatchableInfo::buildInstructionResultOperands() {
 }
 
 void MatchableInfo::buildAliasResultOperands(bool AliasConstraintsAreChecked) {
-  const CodeGenInstAlias &CGA = *DefRec.get<const CodeGenInstAlias*>();
+  const CodeGenInstAlias &CGA = *cast<const CodeGenInstAlias *>(DefRec);
   const CodeGenInstruction *ResultInst = getResultInst();
 
   // Map of:  $reg -> #lastref


        


More information about the llvm-commits mailing list