Skip to content

Commit 2fa6c2b

Browse files
kazutakahiratakbluck
authored andcommitted
[Analysis] Migrate to a new version of getValueProfDataFromInst (llvm#97234)
This patch migrates a use of getValueProfDataFromInst in the indirect call promotion to a new version. Without this patch, getProfitablePromotionCandidates is a little strange in that it takes value profiling data from member variable ValueDataArray while taking its length as a function parameter. This patch rectifies that by teaching the function to refer to ValueDataArray, which is now a SmallVector.
1 parent 2ceb316 commit 2fa6c2b

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

llvm/include/llvm/Analysis/IndirectCallPromotionAnalysis.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Instruction;
2424
class ICallPromotionAnalysis {
2525
private:
2626
// Allocate space to read the profile annotation.
27-
std::unique_ptr<InstrProfValueData[]> ValueDataArray;
27+
SmallVector<InstrProfValueData, 4> ValueDataArray;
2828

2929
// Count is the call count for the direct-call target.
3030
// TotalCount is the total call count for the indirect-call callsite.
@@ -36,7 +36,6 @@ class ICallPromotionAnalysis {
3636
// Returns the number of profitable candidates to promote for the
3737
// current ValueDataArray and the given \p Inst.
3838
uint32_t getProfitablePromotionCandidates(const Instruction *Inst,
39-
uint32_t NumVals,
4039
uint64_t TotalCount);
4140

4241
// Noncopyable
@@ -45,7 +44,7 @@ class ICallPromotionAnalysis {
4544
operator=(const ICallPromotionAnalysis &other) = delete;
4645

4746
public:
48-
ICallPromotionAnalysis();
47+
ICallPromotionAnalysis() = default;
4948

5049
/// Returns reference to array of InstrProfValueData for the given
5150
/// instruction \p I.

llvm/lib/Analysis/IndirectCallPromotionAnalysis.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ cl::opt<unsigned> MaxNumVTableAnnotations(
4949
"icp-max-num-vtables", cl::init(6), cl::Hidden,
5050
cl::desc("Max number of vtables annotated for a vtable load instruction."));
5151

52-
ICallPromotionAnalysis::ICallPromotionAnalysis() {
53-
ValueDataArray = std::make_unique<InstrProfValueData[]>(MaxNumPromotions);
54-
}
55-
5652
bool ICallPromotionAnalysis::isPromotionProfitable(uint64_t Count,
5753
uint64_t TotalCount,
5854
uint64_t RemainingCount) {
@@ -64,19 +60,17 @@ bool ICallPromotionAnalysis::isPromotionProfitable(uint64_t Count,
6460
// the count. Stop at the first target that is not promoted. Returns the
6561
// number of candidates deemed profitable.
6662
uint32_t ICallPromotionAnalysis::getProfitablePromotionCandidates(
67-
const Instruction *Inst, uint32_t NumVals, uint64_t TotalCount) {
68-
ArrayRef<InstrProfValueData> ValueDataRef(ValueDataArray.get(), NumVals);
69-
63+
const Instruction *Inst, uint64_t TotalCount) {
7064
LLVM_DEBUG(dbgs() << " \nWork on callsite " << *Inst
71-
<< " Num_targets: " << NumVals << "\n");
65+
<< " Num_targets: " << ValueDataArray.size() << "\n");
7266

7367
uint32_t I = 0;
7468
uint64_t RemainingCount = TotalCount;
75-
for (; I < MaxNumPromotions && I < NumVals; I++) {
76-
uint64_t Count = ValueDataRef[I].Count;
69+
for (; I < MaxNumPromotions && I < ValueDataArray.size(); I++) {
70+
uint64_t Count = ValueDataArray[I].Count;
7771
assert(Count <= RemainingCount);
7872
LLVM_DEBUG(dbgs() << " Candidate " << I << " Count=" << Count
79-
<< " Target_func: " << ValueDataRef[I].Value << "\n");
73+
<< " Target_func: " << ValueDataArray[I].Value << "\n");
8074

8175
if (!isPromotionProfitable(Count, TotalCount, RemainingCount)) {
8276
LLVM_DEBUG(dbgs() << " Not promote: Cold target.\n");
@@ -90,14 +84,12 @@ uint32_t ICallPromotionAnalysis::getProfitablePromotionCandidates(
9084
MutableArrayRef<InstrProfValueData>
9185
ICallPromotionAnalysis::getPromotionCandidatesForInstruction(
9286
const Instruction *I, uint64_t &TotalCount, uint32_t &NumCandidates) {
93-
uint32_t NumVals;
94-
auto Res = getValueProfDataFromInst(*I, IPVK_IndirectCallTarget,
95-
MaxNumPromotions, NumVals, TotalCount);
96-
if (!Res) {
87+
ValueDataArray = getValueProfDataFromInst(*I, IPVK_IndirectCallTarget,
88+
MaxNumPromotions, TotalCount);
89+
if (ValueDataArray.empty()) {
9790
NumCandidates = 0;
9891
return MutableArrayRef<InstrProfValueData>();
9992
}
100-
ValueDataArray = std::move(Res);
101-
NumCandidates = getProfitablePromotionCandidates(I, NumVals, TotalCount);
102-
return MutableArrayRef<InstrProfValueData>(ValueDataArray.get(), NumVals);
93+
NumCandidates = getProfitablePromotionCandidates(I, TotalCount);
94+
return ValueDataArray;
10395
}

0 commit comments

Comments
 (0)