mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-20 19:42:54 +02:00
d02fba9580
The InstrProfWriter already stores the name and hash of the record in the nested maps it uses for lookup while merging - this data is duplicated in the value within the maps. Refactor the InstrProfRecord to use a nested struct for the counters themselves so that InstrProfWriter can use this nested struct alone without the name or hash duplicated there. This work is incomplete, but enough to demonstrate the value (around a 50% decrease in memory usage for a large test case (10GB -> 5GB)). Though most of that decrease is probably from removing the SoftInstrProfError as well, but I haven't implemented a replacement for it yet. (it needs to go with the counters, because the operations on the counters - merging, etc, are where the failures are - unlike the name/hash which are totally unused by those counter-related operations and thus easy to split out) Ongoing discussion about removing SoftInstrProfError as a field of the InstrProfRecord is happening on the thread that added it - including the possibility of moving back towards an earlier version of that proposed patch that passed SoftInstrProfError through the various APIs, rather than as a member of InstrProfRecord. Reviewers: davidxl Differential Revision: https://reviews.llvm.org/D34838 llvm-svn: 307298
103 lines
2.9 KiB
C++
103 lines
2.9 KiB
C++
//===- ProfileCommon.h - Common profiling APIs. -----------------*- C++ -*-===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file contains data structures and functions common to both instrumented
|
|
// and sample profiling.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LLVM_PROFILEDATA_PROFILECOMMON_H
|
|
#define LLVM_PROFILEDATA_PROFILECOMMON_H
|
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
|
#include "llvm/IR/ProfileSummary.h"
|
|
#include "llvm/ProfileData/InstrProf.h"
|
|
#include "llvm/Support/Error.h"
|
|
#include <algorithm>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace llvm {
|
|
|
|
namespace sampleprof {
|
|
|
|
class FunctionSamples;
|
|
|
|
} // end namespace sampleprof
|
|
|
|
inline const char *getHotSectionPrefix() { return ".hot"; }
|
|
inline const char *getUnlikelySectionPrefix() { return ".unlikely"; }
|
|
|
|
class ProfileSummaryBuilder {
|
|
private:
|
|
/// We keep track of the number of times a count (block count or samples)
|
|
/// appears in the profile. The map is kept sorted in the descending order of
|
|
/// counts.
|
|
std::map<uint64_t, uint32_t, std::greater<uint64_t>> CountFrequencies;
|
|
std::vector<uint32_t> DetailedSummaryCutoffs;
|
|
|
|
protected:
|
|
SummaryEntryVector DetailedSummary;
|
|
uint64_t TotalCount = 0;
|
|
uint64_t MaxCount = 0;
|
|
uint64_t MaxFunctionCount = 0;
|
|
uint32_t NumCounts = 0;
|
|
uint32_t NumFunctions = 0;
|
|
|
|
ProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
|
|
: DetailedSummaryCutoffs(std::move(Cutoffs)) {}
|
|
~ProfileSummaryBuilder() = default;
|
|
|
|
inline void addCount(uint64_t Count);
|
|
void computeDetailedSummary();
|
|
|
|
public:
|
|
/// \brief A vector of useful cutoff values for detailed summary.
|
|
static const ArrayRef<uint32_t> DefaultCutoffs;
|
|
};
|
|
|
|
class InstrProfSummaryBuilder final : public ProfileSummaryBuilder {
|
|
uint64_t MaxInternalBlockCount = 0;
|
|
|
|
inline void addEntryCount(uint64_t Count);
|
|
inline void addInternalCount(uint64_t Count);
|
|
|
|
public:
|
|
InstrProfSummaryBuilder(std::vector<uint32_t> Cutoffs)
|
|
: ProfileSummaryBuilder(std::move(Cutoffs)) {}
|
|
|
|
void addRecord(const InstrProfRecord &);
|
|
std::unique_ptr<ProfileSummary> getSummary();
|
|
};
|
|
|
|
class SampleProfileSummaryBuilder final : public ProfileSummaryBuilder {
|
|
public:
|
|
SampleProfileSummaryBuilder(std::vector<uint32_t> Cutoffs)
|
|
: ProfileSummaryBuilder(std::move(Cutoffs)) {}
|
|
|
|
void addRecord(const sampleprof::FunctionSamples &FS);
|
|
std::unique_ptr<ProfileSummary> getSummary();
|
|
};
|
|
|
|
/// This is called when a count is seen in the profile.
|
|
void ProfileSummaryBuilder::addCount(uint64_t Count) {
|
|
TotalCount += Count;
|
|
if (Count > MaxCount)
|
|
MaxCount = Count;
|
|
NumCounts++;
|
|
CountFrequencies[Count]++;
|
|
}
|
|
|
|
} // end namespace llvm
|
|
|
|
#endif // LLVM_PROFILEDATA_PROFILECOMMON_H
|