Skip to content

Commit cac3f5e

Browse files
[memprof] Add simplify_type (NFC) (#123556)
IndexCall is a simple wrapper around: PointerUnion<CallsiteInfo *, AllocInfo *> Now, because we don't have CastInfo for IndexCall, we would have to use getBase like so: dyn_cast_if_present<CallsiteInfo *>(Call.getBase()) This patch adds simplify_type<IndexCall>, which in turn enables CastInfo for IndexCall, so we can drop getBase like so:: dyn_cast_if_present<CallsiteInfo *>(Call)
1 parent 0fbec1e commit cac3f5e

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -821,19 +821,31 @@ struct IndexCall : public PointerUnion<CallsiteInfo *, AllocInfo *> {
821821

822822
IndexCall *operator->() { return this; }
823823

824-
PointerUnion<CallsiteInfo *, AllocInfo *> getBase() const { return *this; }
825-
826824
void print(raw_ostream &OS) const {
827-
if (auto *AI = llvm::dyn_cast_if_present<AllocInfo *>(getBase())) {
825+
PointerUnion<CallsiteInfo *, AllocInfo *> Base = *this;
826+
if (auto *AI = llvm::dyn_cast_if_present<AllocInfo *>(Base)) {
828827
OS << *AI;
829828
} else {
830-
auto *CI = llvm::dyn_cast_if_present<CallsiteInfo *>(getBase());
829+
auto *CI = llvm::dyn_cast_if_present<CallsiteInfo *>(Base);
831830
assert(CI);
832831
OS << *CI;
833832
}
834833
}
835834
};
835+
} // namespace
836+
837+
namespace llvm {
838+
template <> struct simplify_type<IndexCall> {
839+
using SimpleType = PointerUnion<CallsiteInfo *, AllocInfo *>;
840+
static SimpleType getSimplifiedValue(IndexCall &Val) { return Val; }
841+
};
842+
template <> struct simplify_type<const IndexCall> {
843+
using SimpleType = const PointerUnion<CallsiteInfo *, AllocInfo *>;
844+
static SimpleType getSimplifiedValue(const IndexCall &Val) { return Val; }
845+
};
846+
} // namespace llvm
836847

848+
namespace {
837849
/// CRTP derived class for graphs built from summary index (ThinLTO).
838850
class IndexCallsiteContextGraph
839851
: public CallsiteContextGraph<IndexCallsiteContextGraph, FunctionSummary,
@@ -1877,9 +1889,9 @@ uint64_t ModuleCallsiteContextGraph::getLastStackId(Instruction *Call) {
18771889
}
18781890

18791891
uint64_t IndexCallsiteContextGraph::getLastStackId(IndexCall &Call) {
1880-
assert(isa<CallsiteInfo *>(Call.getBase()));
1892+
assert(isa<CallsiteInfo *>(Call));
18811893
CallStack<CallsiteInfo, SmallVector<unsigned>::const_iterator>
1882-
CallsiteContext(dyn_cast_if_present<CallsiteInfo *>(Call.getBase()));
1894+
CallsiteContext(dyn_cast_if_present<CallsiteInfo *>(Call));
18831895
// Need to convert index into stack id.
18841896
return Index.getStackIdAtIndex(CallsiteContext.back());
18851897
}
@@ -1911,10 +1923,10 @@ std::string IndexCallsiteContextGraph::getLabel(const FunctionSummary *Func,
19111923
unsigned CloneNo) const {
19121924
auto VI = FSToVIMap.find(Func);
19131925
assert(VI != FSToVIMap.end());
1914-
if (isa<AllocInfo *>(Call.getBase()))
1926+
if (isa<AllocInfo *>(Call))
19151927
return (VI->second.name() + " -> alloc").str();
19161928
else {
1917-
auto *Callsite = dyn_cast_if_present<CallsiteInfo *>(Call.getBase());
1929+
auto *Callsite = dyn_cast_if_present<CallsiteInfo *>(Call);
19181930
return (VI->second.name() + " -> " +
19191931
getMemProfFuncName(Callsite->Callee.name(),
19201932
Callsite->Clones[CloneNo]))
@@ -1933,9 +1945,9 @@ ModuleCallsiteContextGraph::getStackIdsWithContextNodesForCall(
19331945

19341946
std::vector<uint64_t>
19351947
IndexCallsiteContextGraph::getStackIdsWithContextNodesForCall(IndexCall &Call) {
1936-
assert(isa<CallsiteInfo *>(Call.getBase()));
1948+
assert(isa<CallsiteInfo *>(Call));
19371949
CallStack<CallsiteInfo, SmallVector<unsigned>::const_iterator>
1938-
CallsiteContext(dyn_cast_if_present<CallsiteInfo *>(Call.getBase()));
1950+
CallsiteContext(dyn_cast_if_present<CallsiteInfo *>(Call));
19391951
return getStackIdsWithContextNodes<CallsiteInfo,
19401952
SmallVector<unsigned>::const_iterator>(
19411953
CallsiteContext);
@@ -2696,8 +2708,7 @@ bool IndexCallsiteContextGraph::findProfiledCalleeThroughTailCalls(
26962708

26972709
const FunctionSummary *
26982710
IndexCallsiteContextGraph::getCalleeFunc(IndexCall &Call) {
2699-
ValueInfo Callee =
2700-
dyn_cast_if_present<CallsiteInfo *>(Call.getBase())->Callee;
2711+
ValueInfo Callee = dyn_cast_if_present<CallsiteInfo *>(Call)->Callee;
27012712
if (Callee.getSummaryList().empty())
27022713
return nullptr;
27032714
return dyn_cast<FunctionSummary>(Callee.getSummaryList()[0]->getBaseObject());
@@ -2707,8 +2718,7 @@ bool IndexCallsiteContextGraph::calleeMatchesFunc(
27072718
IndexCall &Call, const FunctionSummary *Func,
27082719
const FunctionSummary *CallerFunc,
27092720
std::vector<std::pair<IndexCall, FunctionSummary *>> &FoundCalleeChain) {
2710-
ValueInfo Callee =
2711-
dyn_cast_if_present<CallsiteInfo *>(Call.getBase())->Callee;
2721+
ValueInfo Callee = dyn_cast_if_present<CallsiteInfo *>(Call)->Callee;
27122722
// If there is no summary list then this is a call to an externally defined
27132723
// symbol.
27142724
AliasSummary *Alias =
@@ -2751,10 +2761,8 @@ bool IndexCallsiteContextGraph::calleeMatchesFunc(
27512761
}
27522762

27532763
bool IndexCallsiteContextGraph::sameCallee(IndexCall &Call1, IndexCall &Call2) {
2754-
ValueInfo Callee1 =
2755-
dyn_cast_if_present<CallsiteInfo *>(Call1.getBase())->Callee;
2756-
ValueInfo Callee2 =
2757-
dyn_cast_if_present<CallsiteInfo *>(Call2.getBase())->Callee;
2764+
ValueInfo Callee1 = dyn_cast_if_present<CallsiteInfo *>(Call1)->Callee;
2765+
ValueInfo Callee2 = dyn_cast_if_present<CallsiteInfo *>(Call2)->Callee;
27582766
return Callee1 == Callee2;
27592767
}
27602768

@@ -3610,7 +3618,7 @@ IndexCallsiteContextGraph::cloneFunctionForCallsite(
36103618
// Confirm this matches the CloneNo provided by the caller, which is based on
36113619
// the number of function clones we have.
36123620
assert(CloneNo ==
3613-
(isa<AllocInfo *>(Call.call().getBase())
3621+
(isa<AllocInfo *>(Call.call())
36143622
? Call.call().dyn_cast<AllocInfo *>()->Versions.size()
36153623
: Call.call().dyn_cast<CallsiteInfo *>()->Clones.size()));
36163624
// Walk all the instructions in this function. Create a new version for

0 commit comments

Comments
 (0)