[llvm] [memprof] Migrate away from PointerUnion::dyn_cast (NFC) (PR #123716)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 09:53:03 PST 2025
https://github.com/kazutakahirata updated https://github.com/llvm/llvm-project/pull/123716
>From ac42dbbeaba20c7af0b4faf3fa7a01d316451ec6 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 21 Jan 2025 01:01:41 -0800
Subject: [PATCH 1/5] [memprof] Migrate away from PointerUnion::dyn_cast (NFC)
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>
Literal migration would result in dyn_cast_if_present (see the
definition of PointerUnion::dyn_cast), but this patch uses dyn_cast
because we expect the arguments to be nonnull. Note that all these
cases have assert and/or dereferences just after dyn_cast, implying
that the return value from dyn_cast must be nonnull.
This patch uses cast<CallsiteInfo *> instead of
dyn_cast<CallsiteInfo *> in one place where we know that the argument
satisfies isa<CallsiteInfo *> because of the "if" condition.
---
.../Transforms/IPO/MemProfContextDisambiguation.cpp | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index 988e912b2de838..51a2e891ff0cf5 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<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<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<CallsiteInfo *>(CallerCall.call());
assert(CI &&
"Caller cannot be an allocation which should not have profiled calls");
assert(CI->Clones.size() > CallerCall.cloneNo());
@@ -3630,13 +3630,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<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 = cast<CallsiteInfo *>(Inst.call());
assert(CI && CI->Clones.size() == CloneNo);
// We assign the clone number later (in updateCall), just add an entry for
// it here.
>From 65436a451f56e157cf58af362fee0718626988ef Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 21 Jan 2025 01:44:36 -0800
Subject: [PATCH 2/5] Update
llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Co-authored-by: Nikita Popov <github at npopov.com>
---
llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index 51a2e891ff0cf5..d373079ddd6d27 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 = dyn_cast<AllocInfo *>(Call.call());
+ auto *AI = cast<AllocInfo *>(Call.call());
assert(AI);
assert(AI->Versions.size() > Call.cloneNo());
AI->Versions[Call.cloneNo()] = (uint8_t)AllocType;
>From b2de3a9e6d6c27d973fb2dab565a673f371fbb81 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 21 Jan 2025 01:44:47 -0800
Subject: [PATCH 3/5] Update
llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Co-authored-by: Nikita Popov <github at npopov.com>
---
llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index d373079ddd6d27..7f6c12dc6a11dd 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -3560,7 +3560,7 @@ ModuleCallsiteContextGraph::getAllocationCallType(const CallInfo &Call) const {
AllocationType
IndexCallsiteContextGraph::getAllocationCallType(const CallInfo &Call) const {
- const auto *AI = dyn_cast<AllocInfo *>(Call.call());
+ const auto *AI = cast<AllocInfo *>(Call.call());
assert(AI->Versions.size() > Call.cloneNo());
return (AllocationType)AI->Versions[Call.cloneNo()];
}
>From dae5f7d840e2407741c55d1dd24b05a664396bb7 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 21 Jan 2025 01:44:57 -0800
Subject: [PATCH 4/5] Update
llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
Co-authored-by: Nikita Popov <github at npopov.com>
---
llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
index 7f6c12dc6a11dd..3ae32b681d4a2c 100644
--- a/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
+++ b/llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp
@@ -3579,7 +3579,7 @@ void ModuleCallsiteContextGraph::updateCall(CallInfo &CallerCall,
void IndexCallsiteContextGraph::updateCall(CallInfo &CallerCall,
FuncInfo CalleeFunc) {
- auto *CI = dyn_cast<CallsiteInfo *>(CallerCall.call());
+ auto *CI = cast<CallsiteInfo *>(CallerCall.call());
assert(CI &&
"Caller cannot be an allocation which should not have profiled calls");
assert(CI->Clones.size() > CallerCall.cloneNo());
>From a0cd2d155da0b379145aaef8f17934eae89d82af Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 21 Jan 2025 09:52:48 -0800
Subject: [PATCH 5/5] Trigger build
More information about the llvm-commits
mailing list