mirror of
https://github.com/RPCS3/llvm.git
synced 2026-07-21 03:05:26 -04:00
llvm-profdata: Reduce memory usage by using Error callback rather than member
Reduces llvm-profdata memory usage on a large profile from 7.8GB to 5.1GB. The ProfData API now supports reporting all the errors/warnings rather than only the first, though llvm-profdata ignores everything after the first for now to preserve existing behavior. (if there's a desire for other behavior, happy to implement that - but might be as well left for a separate patch) Reviewers: davidxl Differential Revision: https://reviews.llvm.org/D35149 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307516 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -176,14 +176,16 @@ void InstrProfWriter::setOutputSparse(bool Sparse) {
|
||||
this->Sparse = Sparse;
|
||||
}
|
||||
|
||||
Error InstrProfWriter::addRecord(NamedInstrProfRecord &&I, uint64_t Weight) {
|
||||
void InstrProfWriter::addRecord(NamedInstrProfRecord &&I, uint64_t Weight,
|
||||
function_ref<void(Error)> Warn) {
|
||||
auto Name = I.Name;
|
||||
auto Hash = I.Hash;
|
||||
return addRecord(Name, Hash, std::move(I), Weight);
|
||||
addRecord(Name, Hash, std::move(I), Weight, Warn);
|
||||
}
|
||||
|
||||
Error InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,
|
||||
InstrProfRecord &&I, uint64_t Weight) {
|
||||
void InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,
|
||||
InstrProfRecord &&I, uint64_t Weight,
|
||||
function_ref<void(Error)> Warn) {
|
||||
auto &ProfileDataMap = FunctionData[Name];
|
||||
|
||||
bool NewFunc;
|
||||
@@ -192,27 +194,28 @@ Error InstrProfWriter::addRecord(StringRef Name, uint64_t Hash,
|
||||
ProfileDataMap.insert(std::make_pair(Hash, InstrProfRecord()));
|
||||
InstrProfRecord &Dest = Where->second;
|
||||
|
||||
auto MapWarn = [&](instrprof_error E) {
|
||||
Warn(make_error<InstrProfError>(E));
|
||||
};
|
||||
|
||||
if (NewFunc) {
|
||||
// We've never seen a function with this name and hash, add it.
|
||||
Dest = std::move(I);
|
||||
if (Weight > 1)
|
||||
Dest.scale(Weight);
|
||||
Dest.scale(Weight, MapWarn);
|
||||
} else {
|
||||
// We're updating a function we've seen before.
|
||||
Dest.merge(I, Weight);
|
||||
Dest.merge(I, Weight, MapWarn);
|
||||
}
|
||||
|
||||
Dest.sortValueData();
|
||||
|
||||
return Dest.takeError();
|
||||
}
|
||||
|
||||
Error InstrProfWriter::mergeRecordsFromWriter(InstrProfWriter &&IPW) {
|
||||
void InstrProfWriter::mergeRecordsFromWriter(InstrProfWriter &&IPW,
|
||||
function_ref<void(Error)> Warn) {
|
||||
for (auto &I : IPW.FunctionData)
|
||||
for (auto &Func : I.getValue())
|
||||
if (Error E = addRecord(I.getKey(), Func.first, std::move(Func.second)))
|
||||
return E;
|
||||
return Error::success();
|
||||
addRecord(I.getKey(), Func.first, std::move(Func.second), 1, Warn);
|
||||
}
|
||||
|
||||
bool InstrProfWriter::shouldEncodeData(const ProfilingData &PD) {
|
||||
|
||||
Reference in New Issue
Block a user