55 uint64_t
tell() {
return OS.tell(); }
56 void write(uint64_t V) {
LE.write<uint64_t>(V); }
62 using namespace support;
66 for (
int K = 0; K < NItems; K++) {
67 FDOStream.
seek(P[K].Pos);
68 for (
int I = 0;
I < P[K].
N;
I++)
73 std::string &
Data = SOStream.
str();
74 for (
int K = 0; K < NItems; K++) {
75 for (
int I = 0;
I < P[K].
N;
I++) {
76 uint64_t Bytes = endian::byte_swap<uint64_t, little>(P[K].
D[
I]);
77 Data.replace(P[K].Pos +
I *
sizeof(uint64_t),
sizeof(uint64_t),
78 (
const char *)&Bytes,
sizeof(uint64_t));
112 static std::pair<offset_type, offset_type>
114 using namespace support;
122 for (
const auto &ProfileData : *V) {
124 M +=
sizeof(uint64_t);
125 M +=
sizeof(uint64_t);
126 M += ProfRecord.
Counts.size() *
sizeof(uint64_t);
129 M += ValueProfData::getSize(ProfileData.second);
133 return std::make_pair(N, M);
141 using namespace support;
144 for (
const auto &ProfileData : *V) {
151 LE.write<uint64_t>(ProfileData.first);
152 LE.write<uint64_t>(ProfRecord.
Counts.size());
153 for (uint64_t
I : ProfRecord.
Counts)
154 LE.write<uint64_t>(
I);
157 std::unique_ptr<ValueProfData> VDataPtr =
158 ValueProfData::serializeFrom(ProfileData.second);
160 VDataPtr->swapBytesFromHost(ValueProfDataEndianness);
161 Out.
write((
const char *)VDataPtr.get(), S);
180 this->Sparse = Sparse;
195 auto Hash =
Other.Hash;
196 Other.accumulateCounts(FuncLevelOverlap.
Test);
197 if (FunctionData.find(
Name) == FunctionData.end()) {
205 auto &ProfileDataMap = FunctionData[
Name];
208 std::tie(Where, NewFunc) =
221 Dest.
overlap(
Other, Overlap, FuncLevelOverlap, ValueCutoff);
227 auto &ProfileDataMap = FunctionData[
Name];
231 std::tie(Where, NewFunc) =
236 Warn(make_error<InstrProfError>(
E));
243 Dest.
scale(Weight, MapWarn);
246 Dest.
merge(
I, Weight, MapWarn);
254 for (
auto &
I : IPW.FunctionData)
255 for (
auto &Func :
I.getValue())
256 addRecord(
I.getKey(), Func.first, std::move(Func.second), 1, Warn);
262 for (
const auto &Func : PD) {
272 using namespace IndexedInstrProf;
283 for (
unsigned I = 0;
I < Res.size();
I++)
288 using namespace IndexedInstrProf;
293 InfoObj->SummaryBuilder = &ISB;
295 InfoObj->CSSummaryBuilder = &CSISB;
298 for (
const auto &
I : FunctionData)
299 if (shouldEncodeData(
I.getValue()))
300 Generator.insert(
I.getKey(), &
I.getValue());
306 Header.
Version |= VARIANT_MASK_IR_PROF;
308 Header.
Version |= VARIANT_MASK_IR_PROF;
309 Header.
Version |= VARIANT_MASK_CSIR_PROF;
319 for (
int I = 0;
I < N - 1;
I++)
320 OS.
write(reinterpret_cast<uint64_t *>(&Header)[
I]);
323 uint64_t HashTableStartFieldOffset = OS.
tell();
329 uint32_t SummarySize = Summary::getSize(Summary::NumKinds, NumEntries);
331 uint64_t SummaryOffset = OS.
tell();
332 for (
unsigned I = 0; I < SummarySize /
sizeof(uint64_t); I++)
334 uint64_t CSSummaryOffset = 0;
335 uint64_t CSSummarySize = 0;
337 CSSummaryOffset = OS.
tell();
338 CSSummarySize = SummarySize /
sizeof(uint64_t);
339 for (
unsigned I = 0; I < CSSummarySize; I++)
344 uint64_t HashTableStart = Generator.
Emit(OS.
OS, *InfoObj);
347 std::unique_ptr<IndexedInstrProf::Summary> TheSummary =
351 std::unique_ptr<ProfileSummary> PS = ISB.
getSummary();
353 InfoObj->SummaryBuilder =
nullptr;
356 std::unique_ptr<IndexedInstrProf::Summary> TheCSSummary =
nullptr;
359 std::unique_ptr<ProfileSummary> CSPS = CSISB.
getSummary();
362 InfoObj->CSSummaryBuilder =
nullptr;
367 {HashTableStartFieldOffset, &HashTableStart, 1},
369 {SummaryOffset,
reinterpret_cast<uint64_t *
>(TheSummary.get()),
370 (
int)(SummarySize /
sizeof(uint64_t))},
371 {CSSummaryOffset,
reinterpret_cast<uint64_t *
>(TheCSSummary.get()),
372 (
int)CSSummarySize}};
374 OS.
patch(PatchItems,
sizeof(PatchItems) /
sizeof(*PatchItems));
394 #define VALUE_PROF_KIND(Enumerator, Value, Descr) #Enumerator, 403 OS <<
"# Func Hash:\n" << Hash <<
"\n";
404 OS <<
"# Num Counters:\n" << Func.
Counts.size() <<
"\n";
405 OS <<
"# Counter Values:\n";
406 for (uint64_t Count : Func.
Counts)
410 if (!NumValueKinds) {
416 for (
uint32_t VK = 0; VK < IPVK_Last + 1; VK++) {
420 OS <<
"# ValueKind = " << ValueProfKindStr[VK] <<
":\n" << VK <<
"\n";
421 OS <<
"# NumValueSites:\n" << NS <<
"\n";
425 std::unique_ptr<InstrProfValueData[]> VD = Func.
getValueForSite(VK, S);
427 if (VK == IPVK_IndirectCallTarget)
429 << VD[
I].Count <<
"\n";
431 OS << VD[
I].Value <<
":" << VD[
I].Count <<
"\n";
441 OS <<
"# IR level Instrumentation Flag\n:ir\n";
443 OS <<
"# CSIR level Instrumentation Flag\n:csir\n";
447 using RecordType = std::pair<StringRef, FuncPair>;
450 for (
const auto &
I : FunctionData) {
451 if (shouldEncodeData(
I.getValue())) {
454 for (
const auto &Func :
I.getValue())
455 OrderedFuncData.
push_back(std::make_pair(
I.getKey(), Func));
459 llvm::sort(OrderedFuncData, [](
const RecordType &A,
const RecordType &
B) {
460 return std::tie(A.first, A.second.first) <
461 std::tie(B.first, B.second.first);
464 for (
const auto &record : OrderedFuncData) {
466 const FuncPair &Func = record.second;
void setValueProfDataEndianness(support::endianness Endianness)
const InstrProfWriter::ProfilingData *const data_type
static const char * ValueProfKindStr[]
void overlap(InstrProfRecord &Other, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap, uint64_t ValueCutoff)
Compute the overlap b/w this IntrprofRecord and Other.
void addOneMismatch(const CountSumOrPercent &MismatchFunc)
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
void merge(InstrProfRecord &Other, uint64_t Weight, function_ref< void(instrprof_error)> Warn)
Merge the counts in Other into this one.
uint64_t NumCutoffEntries
void sortValueData()
Sort value profile data (per site) by count.
This class represents lattice values for constants.
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
ProfOStream(raw_string_ostream &STR)
Defines facilities for reading and writing on-disk hash tables.
uint32_t getNumValueDataForSite(uint32_t ValueKind, uint32_t Site) const
Return the number of value data collected for ValueKind at profiling site: Site.
void setEntry(uint32_t I, const ProfileSummaryEntry &E)
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
void push_back(const T &Elt)
InstrProfWriter(bool Sparse=false)
const std::string NameFilter
An efficient, type-erasing, non-owning reference to a callable.
std::unique_ptr< Summary > allocSummary(uint32_t TotalSize)
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
block Block Frequency true
uint64_t getMaxInternalCount()
void addRecord(const InstrProfRecord &)
uint32_t getNumValueSites(uint32_t ValueKind) const
Return the number of instrumented sites for ValueKind.
static void setSummary(IndexedInstrProf::Summary *TheSummary, ProfileSummary &PS)
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type N)
const InstrProfWriter::ProfilingData *const data_type_ref
void addRecord(NamedInstrProfRecord &&I, uint64_t Weight, function_ref< void(Error)> Warn)
Add function counts for the given function.
void scale(uint64_t Weight, function_ref< void(instrprof_error)> Warn)
Scale up profile counts (including value profile data) by Weight.
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
uint64_t NumSummaryFields
uint64_t getMaxFunctionCount()
LLVM_NODISCARD size_t size() const
size - Get the string size.
SummaryEntryVector & getDetailedSummary()
void mergeRecordsFromWriter(InstrProfWriter &&IPW, function_ref< void(Error)> Warn)
Merge existing function counts from the given writer.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void setOutputSparse(bool Sparse)
static hash_value_type ComputeHash(key_type_ref K)
size_t size() const
size - Get the array size.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
InstrProfSummaryBuilder * CSSummaryBuilder
uint32_t getNumValueKinds() const
Return the number of value profile kinds with non-zero number of profile sites.
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
static bool hasCSFlagInHash(uint64_t FuncHash)
uint64_t ComputeHash(StringRef K)
static void write(bool isBE, void *P, T V)
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
raw_ostream & write(unsigned char C)
void sort(IteratorTy Start, IteratorTy End)
void addOneUnique(const CountSumOrPercent &UniqueFunc)
static ErrorSuccess success()
Create a success value.
offset_type Emit(raw_ostream &Out)
Emit the table to Out, which must not be at offset 0.
std::unique_ptr< ProfileSummary > getSummary()
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
support::endianness ValueProfDataEndianness
support::endian::Writer LE
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static std::unique_ptr< MemoryBuffer > getMemBufferCopy(StringRef InputData, const Twine &BufferName="")
Open the specified memory range as a MemoryBuffer, copying the contents and taking ownership of it...
CountSumOrPercent Overlap
Generates an on disk hash table.
std::vector< uint64_t > Counts
static void writeRecordInText(StringRef Name, uint64_t Hash, const InstrProfRecord &Counters, InstrProfSymtab &Symtab, raw_fd_ostream &OS)
Write Record in text format to OS.
Adapter to write values to a stream in a particular byte order.
A raw_ostream that writes to a file descriptor.
uint32_t getNumFunctions()
Profiling information for a single function.
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
Error addFuncName(StringRef FuncName)
Update the symtab by adding FuncName to the table.
void patch(PatchItem *P, int NItems)
void overlapRecord(NamedInstrProfRecord &&Other, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap, const OverlapFuncFilters &FuncFilter)
InstrProfSummaryBuilder * SummaryBuilder
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
A raw_ostream that writes to an std::string.
void write(raw_fd_ostream &OS)
Write the profile to OS.
LLVM Value Representation.
Error writeText(raw_fd_ostream &OS)
Write the profile in text format to OS.
Lightweight error class with error context and mandatory checking.
This class implements an extremely fast bulk output stream that can only output to a stream...
ProfOStream(raw_fd_ostream &FD)
StringRef - Represent a constant reference to a string, i.e.
std::unique_ptr< InstrProfValueData[]> getValueForSite(uint32_t ValueKind, uint32_t Site, uint64_t *TotalC=nullptr) const
Return the array of profiled values at Site.
StringRef getFuncNameOrExternalSymbol(uint64_t FuncMD5Hash)
Just like getFuncName, except that it will return a non-empty StringRef if the function is external t...
void set(SummaryFieldKind K, uint64_t V)
std::unique_ptr< MemoryBuffer > writeBuffer()
Write the profile, returning the raw data. For testing.