[llvm] [ProfileData] Use std::vector for ValueData (NFC) (PR #95194)
Mingming Liu via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 12 11:06:53 PDT 2024
================
@@ -847,19 +847,26 @@ void InstrProfValueSiteRecord::merge(InstrProfValueSiteRecord &Input,
Input.sortByTargetValues();
auto I = ValueData.begin();
auto IE = ValueData.end();
+ std::vector<InstrProfValueData> Merged;
+ Merged.reserve(std::max(ValueData.size(), Input.ValueData.size()));
for (const InstrProfValueData &J : Input.ValueData) {
- while (I != IE && I->Value < J.Value)
+ while (I != IE && I->Value < J.Value) {
+ Merged.push_back(*I);
++I;
+ }
if (I != IE && I->Value == J.Value) {
bool Overflowed;
I->Count = SaturatingMultiplyAdd(J.Count, Weight, I->Count, &Overflowed);
if (Overflowed)
Warn(instrprof_error::counter_overflow);
+ Merged.push_back(*I);
++I;
continue;
}
- ValueData.insert(I, J);
+ Merged.push_back(J);
}
+ Merged.insert(Merged.end(), I, IE);
----------------
minglotus-6 wrote:
nit: I might slightly prefer something like
```
Iter1 = valueData.begin();
Iter2 = Input.ValueData.begin();
while(; Iter1 < valueData.end() && Iter2 < valueData.end();) {
if (Iter1.Value > Iter2.Value)
Merge.push_back(*Iter1);
else if (Iter2.Value > Iter1.Value)
Merge.push_back(*Iter2)
else
sum count and push
}
append the tail to Merged vector
```
https://github.com/llvm/llvm-project/pull/95194
More information about the llvm-commits
mailing list