[llvm] [llvm] Migrate away from PointerUnion::{is, get, dyn_cast} (NFC) (PR #115626)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 9 18:44:12 PST 2024
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/115626
>From f05da9e5ece69c47f872b35d6718a3df2d1f9f7c Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Mon, 14 Oct 2024 10:56:26 -0700
Subject: [PATCH 1/2] [llvm] Migrate away from PointerUnion::{is,get,dyn_cast}
(NFC)
Note that PointerUnion::{is,get,dyn_cast} have been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa<T>, cast<T> and the llvm::dyn_cast<T>
---
llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp | 4 ++--
llvm/lib/CodeGen/GlobalISel/Utils.cpp | 4 ++--
llvm/lib/IR/DIBuilder.cpp | 4 ++--
llvm/lib/IR/DebugInfo.cpp | 6 +++---
llvm/lib/IR/Metadata.cpp | 10 +++++-----
llvm/lib/SandboxIR/Tracker.cpp | 12 ++++++------
llvm/lib/Transforms/Scalar/SROA.cpp | 8 +++-----
llvm/lib/Transforms/Utils/Local.cpp | 4 ++--
8 files changed, 25 insertions(+), 27 deletions(-)
diff --git a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
index 59257fd6aadd52..a83f5322b18df4 100644
--- a/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
+++ b/llvm/lib/CodeGen/AssignmentTrackingAnalysis.cpp
@@ -1052,9 +1052,9 @@ class AssignmentTrackingLowering {
if (Source.isNull())
OS << "null";
else if (isa<DbgAssignIntrinsic *>(Source))
- OS << Source.get<DbgAssignIntrinsic *>();
+ OS << cast<DbgAssignIntrinsic *>(Source);
else
- OS << Source.get<DbgVariableRecord *>();
+ OS << cast<DbgVariableRecord *>(Source);
OS << ")";
}
diff --git a/llvm/lib/CodeGen/GlobalISel/Utils.cpp b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
index 5cee07461d7e22..45807a6818ee5e 100644
--- a/llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -214,8 +214,8 @@ bool llvm::canReplaceReg(Register DstReg, Register SrcReg,
// Otherwise match if the Src is already a regclass that is covered by the Dst
// RegBank.
- return DstRBC.is<const RegisterBank *>() && MRI.getRegClassOrNull(SrcReg) &&
- DstRBC.get<const RegisterBank *>()->covers(
+ return isa<const RegisterBank *>(DstRBC) && MRI.getRegClassOrNull(SrcReg) &&
+ cast<const RegisterBank *>(DstRBC)->covers(
*MRI.getRegClassOrNull(SrcReg));
}
diff --git a/llvm/lib/IR/DIBuilder.cpp b/llvm/lib/IR/DIBuilder.cpp
index 665eda28c7d871..9d38497cd12cce 100644
--- a/llvm/lib/IR/DIBuilder.cpp
+++ b/llvm/lib/IR/DIBuilder.cpp
@@ -1033,8 +1033,8 @@ DbgInstPtr DIBuilder::insertDbgValueIntrinsic(Value *V,
DbgInstPtr DVI = insertDbgValueIntrinsic(
V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr,
InsertBefore);
- if (DVI.is<Instruction *>())
- cast<CallInst>(DVI.get<Instruction *>())->setTailCall();
+ if (isa<Instruction *>(DVI))
+ cast<CallInst>(cast<Instruction *>(DVI))->setTailCall();
return DVI;
}
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index e20a0f053481ed..165591805aae51 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -2099,10 +2099,10 @@ static void emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest,
AddrExpr, VarRec.DL);
(void)Assign;
LLVM_DEBUG(if (!Assign.isNull()) {
- if (Assign.is<DbgRecord *>())
- errs() << " > INSERT: " << *Assign.get<DbgRecord *>() << "\n";
+ if (isa<DbgRecord *>(Assign))
+ errs() << " > INSERT: " << *cast<DbgRecord *>(Assign) << "\n";
else
- errs() << " > INSERT: " << *Assign.get<Instruction *>() << "\n";
+ errs() << " > INSERT: " << *cast<Instruction *>(Assign) << "\n";
});
}
diff --git a/llvm/lib/IR/Metadata.cpp b/llvm/lib/IR/Metadata.cpp
index 28f2ca550f5ec9..15d67383309de6 100644
--- a/llvm/lib/IR/Metadata.cpp
+++ b/llvm/lib/IR/Metadata.cpp
@@ -274,7 +274,7 @@ ReplaceableMetadataImpl::getAllDbgVariableRecordUsers() {
OwnerTy Owner = Pair.second.first;
if (Owner.isNull())
continue;
- if (!Owner.is<DebugValueUser *>())
+ if (!isa<DebugValueUser *>(Owner))
continue;
DVRUsersWithID.push_back(&UseMap[Pair.first]);
}
@@ -288,7 +288,7 @@ ReplaceableMetadataImpl::getAllDbgVariableRecordUsers() {
});
SmallVector<DbgVariableRecord *> DVRUsers;
for (auto UserWithID : DVRUsersWithID)
- DVRUsers.push_back(UserWithID->first.get<DebugValueUser *>()->getUser());
+ DVRUsers.push_back(cast<DebugValueUser *>(UserWithID->first)->getUser());
return DVRUsers;
}
@@ -396,8 +396,8 @@ void ReplaceableMetadataImpl::replaceAllUsesWith(Metadata *MD) {
continue;
}
- if (Owner.is<DebugValueUser *>()) {
- Owner.get<DebugValueUser *>()->handleChangedValue(Pair.first, MD);
+ if (isa<DebugValueUser *>(Owner)) {
+ cast<DebugValueUser *>(Owner)->handleChangedValue(Pair.first, MD);
continue;
}
@@ -436,7 +436,7 @@ void ReplaceableMetadataImpl::resolveAllUses(bool ResolveUsers) {
auto Owner = Pair.second.first;
if (!Owner)
continue;
- if (!Owner.is<Metadata *>())
+ if (!isa<Metadata *>(Owner))
continue;
// Resolve MDNodes that point at this.
diff --git a/llvm/lib/SandboxIR/Tracker.cpp b/llvm/lib/SandboxIR/Tracker.cpp
index abcad39330094d..e4f84dee07e4da 100644
--- a/llvm/lib/SandboxIR/Tracker.cpp
+++ b/llvm/lib/SandboxIR/Tracker.cpp
@@ -111,10 +111,10 @@ void EraseFromParent::accept() {
void EraseFromParent::revert(Tracker &Tracker) {
// Place the bottom-most instruction first.
auto [Operands, BotLLVMI] = InstrData[0];
- if (auto *NextLLVMI = NextLLVMIOrBB.dyn_cast<llvm::Instruction *>()) {
+ if (auto *NextLLVMI = dyn_cast<llvm::Instruction *>(NextLLVMIOrBB)) {
BotLLVMI->insertBefore(NextLLVMI);
} else {
- auto *LLVMBB = NextLLVMIOrBB.get<llvm::BasicBlock *>();
+ auto *LLVMBB = cast<llvm::BasicBlock *>(NextLLVMIOrBB);
BotLLVMI->insertInto(LLVMBB, LLVMBB->end());
}
for (auto [OpNum, Op] : enumerate(Operands))
@@ -145,10 +145,10 @@ RemoveFromParent::RemoveFromParent(Instruction *RemovedI) : RemovedI(RemovedI) {
}
void RemoveFromParent::revert(Tracker &Tracker) {
- if (auto *NextI = NextInstrOrBB.dyn_cast<Instruction *>()) {
+ if (auto *NextI = dyn_cast<Instruction *>(NextInstrOrBB)) {
RemovedI->insertBefore(NextI);
} else {
- auto *BB = NextInstrOrBB.get<BasicBlock *>();
+ auto *BB = cast<BasicBlock *>(NextInstrOrBB);
RemovedI->insertInto(BB, BB->end());
}
}
@@ -199,10 +199,10 @@ MoveInstr::MoveInstr(Instruction *MovedI) : MovedI(MovedI) {
}
void MoveInstr::revert(Tracker &Tracker) {
- if (auto *NextI = NextInstrOrBB.dyn_cast<Instruction *>()) {
+ if (auto *NextI = dyn_cast<Instruction *>(NextInstrOrBB)) {
MovedI->moveBefore(NextI);
} else {
- auto *BB = NextInstrOrBB.get<BasicBlock *>();
+ auto *BB = cast<BasicBlock *>(NextInstrOrBB);
MovedI->moveBefore(*BB, BB->end());
}
}
diff --git a/llvm/lib/Transforms/Scalar/SROA.cpp b/llvm/lib/Transforms/Scalar/SROA.cpp
index 4a23e2bee5ba25..d80af26451ac75 100644
--- a/llvm/lib/Transforms/Scalar/SROA.cpp
+++ b/llvm/lib/Transforms/Scalar/SROA.cpp
@@ -5166,11 +5166,9 @@ insertNewDbgInst(DIBuilder &DIB, DbgAssignIntrinsic *Orig, AllocaInst *NewAddr,
DIAssignID::getDistinct(NewAddr->getContext()));
}
- Instruction *NewAssign =
- DIB.insertDbgAssign(NewAddr, Orig->getValue(), Orig->getVariable(),
- NewFragmentExpr, NewAddr, NewAddrExpr,
- Orig->getDebugLoc())
- .get<Instruction *>();
+ Instruction *NewAssign = cast<Instruction *>(DIB.insertDbgAssign(
+ NewAddr, Orig->getValue(), Orig->getVariable(), NewFragmentExpr, NewAddr,
+ NewAddrExpr, Orig->getDebugLoc()));
LLVM_DEBUG(dbgs() << "Created new assign intrinsic: " << *NewAssign << "\n");
(void)NewAssign;
}
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index 768765b6c1e632..509b6d62265517 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -1696,7 +1696,7 @@ static void insertDbgValueOrDbgVariableRecord(DIBuilder &Builder, Value *DV,
if (!UseNewDbgInfoFormat) {
auto DbgVal = Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
(Instruction *)nullptr);
- DbgVal.get<Instruction *>()->insertBefore(Instr);
+ cast<Instruction *>(DbgVal)->insertBefore(Instr);
} else {
// RemoveDIs: if we're using the new debug-info format, allocate a
// DbgVariableRecord directly instead of a dbg.value intrinsic.
@@ -1713,7 +1713,7 @@ static void insertDbgValueOrDbgVariableRecordAfter(
if (!UseNewDbgInfoFormat) {
auto DbgVal = Builder.insertDbgValueIntrinsic(DV, DIVar, DIExpr, NewLoc,
(Instruction *)nullptr);
- DbgVal.get<Instruction *>()->insertAfter(&*Instr);
+ cast<Instruction *>(DbgVal)->insertAfter(&*Instr);
} else {
// RemoveDIs: if we're using the new debug-info format, allocate a
// DbgVariableRecord directly instead of a dbg.value intrinsic.
>From bb018e1029508d0f50de517653418c5774cd22de Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Sat, 9 Nov 2024 18:43:58 -0800
Subject: [PATCH 2/2] Trigger build
More information about the llvm-commits
mailing list