-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm] Migrate away from PointerUnion::dyn_cast (NFC) #123692
[llvm] Migrate away from PointerUnion::dyn_cast (NFC) #123692
Conversation
Note that PointerUnion::dyn_cast has 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/pr-subscribers-llvm-transforms @llvm/pr-subscribers-vectorizers Author: Kazu Hirata (kazutakahirata) ChangesNote that PointerUnion::dyn_cast has been soft deprecated in // FIXME: Replace the uses of is(), get() and dyn_cast() with Full diff: /~https://github.com/llvm/llvm-project/pull/123692.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index 988e912b2de838..9e23888d8cb835 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -3542,7 +3542,7 @@ void ModuleCallsiteContextGraph::updateAllocationCall(
void IndexCallsiteContextGraph::updateAllocationCall(CallInfo &Call,
AllocationType AllocType) {
- auto *AI = Call.call().dyn_cast<AllocInfo *>();
+ auto *AI = dyn_cast_if_present<AllocInfo *>(Call.call());
assert(AI);
assert(AI->Versions.size() > Call.cloneNo());
AI->Versions[Call.cloneNo()] = (uint8_t)AllocType;
@@ -3560,7 +3560,7 @@ ModuleCallsiteContextGraph::getAllocationCallType(const CallInfo &Call) const {
AllocationType
IndexCallsiteContextGraph::getAllocationCallType(const CallInfo &Call) const {
- const auto *AI = Call.call().dyn_cast<AllocInfo *>();
+ const auto *AI = dyn_cast_if_present<AllocInfo *>(Call.call());
assert(AI->Versions.size() > Call.cloneNo());
return (AllocationType)AI->Versions[Call.cloneNo()];
}
@@ -3579,7 +3579,7 @@ void ModuleCallsiteContextGraph::updateCall(CallInfo &CallerCall,
void IndexCallsiteContextGraph::updateCall(CallInfo &CallerCall,
FuncInfo CalleeFunc) {
- auto *CI = CallerCall.call().dyn_cast<CallsiteInfo *>();
+ auto *CI = dyn_cast_if_present<CallsiteInfo *>(CallerCall.call());
assert(CI &&
"Caller cannot be an allocation which should not have profiled calls");
assert(CI->Clones.size() > CallerCall.cloneNo());
@@ -3617,10 +3617,11 @@ IndexCallsiteContextGraph::cloneFunctionForCallsite(
// The next clone number is the current size of versions array.
// Confirm this matches the CloneNo provided by the caller, which is based on
// the number of function clones we have.
- assert(CloneNo ==
- (isa<AllocInfo *>(Call.call())
- ? Call.call().dyn_cast<AllocInfo *>()->Versions.size()
- : Call.call().dyn_cast<CallsiteInfo *>()->Clones.size()));
+ assert(
+ CloneNo ==
+ (isa<AllocInfo *>(Call.call())
+ ? dyn_cast_if_present<AllocInfo *>(Call.call())->Versions.size()
+ : dyn_cast_if_present<CallsiteInfo *>(Call.call())->Clones.size()));
// Walk all the instructions in this function. Create a new version for
// each (by adding an entry to the Versions/Clones summary array), and copy
// over the version being called for the function clone being cloned here.
@@ -3630,13 +3631,13 @@ IndexCallsiteContextGraph::cloneFunctionForCallsite(
for (auto &Inst : CallsWithMetadataInFunc) {
// This map always has the initial version in it.
assert(Inst.cloneNo() == 0);
- if (auto *AI = Inst.call().dyn_cast<AllocInfo *>()) {
+ if (auto *AI = dyn_cast_if_present<AllocInfo *>(Inst.call())) {
assert(AI->Versions.size() == CloneNo);
// We assign the allocation type later (in updateAllocationCall), just add
// an entry for it here.
AI->Versions.push_back(0);
} else {
- auto *CI = Inst.call().dyn_cast<CallsiteInfo *>();
+ auto *CI = dyn_cast_if_present<CallsiteInfo *>(Inst.call());
assert(CI && CI->Clones.size() == CloneNo);
// We assign the clone number later (in updateCall), just add an entry for
// it here.
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index ad4855d908747e..05af64075e0534 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -10354,7 +10354,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
SameNodesEstimated = false;
if (!E2 && InVectors.size() == 1) {
unsigned VF = E1.getVectorFactor();
- if (Value *V1 = InVectors.front().dyn_cast<Value *>()) {
+ if (Value *V1 = dyn_cast_if_present<Value *>(InVectors.front())) {
VF = std::max(VF,
cast<FixedVectorType>(V1->getType())->getNumElements());
} else {
@@ -10370,7 +10370,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
auto P = InVectors.front();
Cost += createShuffle(&E1, E2, Mask);
unsigned VF = Mask.size();
- if (Value *V1 = P.dyn_cast<Value *>()) {
+ if (Value *V1 = dyn_cast_if_present<Value *>(P)) {
VF = std::max(VF,
getNumElements(V1->getType()));
} else {
@@ -10435,7 +10435,8 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
ArrayRef<int> Mask) {
ShuffleCostBuilder Builder(TTI);
SmallVector<int> CommonMask(Mask);
- Value *V1 = P1.dyn_cast<Value *>(), *V2 = P2.dyn_cast<Value *>();
+ Value *V1 = dyn_cast_if_present<Value *>(P1);
+ Value *V2 = dyn_cast_if_present<Value *>(P2);
unsigned CommonVF = Mask.size();
InstructionCost ExtraCost = 0;
auto GetNodeMinBWAffectedCost = [&](const TreeEntry &E,
@@ -10870,7 +10871,7 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
transformMaskAfterShuffle(CommonMask, CommonMask);
VF = std::max<unsigned>(VF, CommonMask.size());
} else if (const auto *InTE =
- InVectors.front().dyn_cast<const TreeEntry *>()) {
+ dyn_cast_if_present<const TreeEntry *>(InVectors.front())) {
VF = std::max(VF, InTE->getVectorFactor());
} else {
VF = std::max(
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think any of these need dyn_cast_if_present.
@@ -3542,7 +3542,7 @@ void ModuleCallsiteContextGraph::updateAllocationCall( | |||
|
|||
void IndexCallsiteContextGraph::updateAllocationCall(CallInfo &Call, | |||
AllocationType AllocType) { | |||
auto *AI = Call.call().dyn_cast<AllocInfo *>(); | |||
auto *AI = dyn_cast_if_present<AllocInfo *>(Call.call()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the following assert, this should be just cast<>.
@@ -3560,7 +3560,7 @@ ModuleCallsiteContextGraph::getAllocationCallType(const CallInfo &Call) const { | |||
|
|||
AllocationType | |||
IndexCallsiteContextGraph::getAllocationCallType(const CallInfo &Call) const { | |||
const auto *AI = Call.call().dyn_cast<AllocInfo *>(); | |||
const auto *AI = dyn_cast_if_present<AllocInfo *>(Call.call()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, directly dereferenced.
@@ -3579,7 +3579,7 @@ void ModuleCallsiteContextGraph::updateCall(CallInfo &CallerCall, | |||
|
|||
void IndexCallsiteContextGraph::updateCall(CallInfo &CallerCall, | |||
FuncInfo CalleeFunc) { | |||
auto *CI = CallerCall.call().dyn_cast<CallsiteInfo *>(); | |||
auto *CI = dyn_cast_if_present<CallsiteInfo *>(CallerCall.call()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also has an assert.
assert(AI->Versions.size() == CloneNo); | ||
// We assign the allocation type later (in updateAllocationCall), just add | ||
// an entry for it here. | ||
AI->Versions.push_back(0); | ||
} else { | ||
auto *CI = Inst.call().dyn_cast<CallsiteInfo *>(); | ||
auto *CI = dyn_cast_if_present<CallsiteInfo *>(Inst.call()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be cast<> which implies above can be dyn_cast<>.
@nikic Thank you for pointing out the opportunities to call |
Note that PointerUnion::dyn_cast has been soft deprecated in
PointerUnion.h:
// FIXME: Replace the uses of is(), get() and dyn_cast() with
// isa, cast and the llvm::dyn_cast