56 uint64_t
tell() {
return OS.tell(); }
57 void write(uint64_t V) {
LE.write<uint64_t>(V); }
63 using namespace support;
67 for (
int K = 0; K < NItems; K++) {
68 FDOStream.
seek(P[K].Pos);
69 for (
int I = 0;
I < P[K].
N;
I++)
74 std::string &
Data = SOStream.
str();
75 for (
int K = 0; K < NItems; K++) {
76 for (
int I = 0;
I < P[K].
N;
I++) {
77 uint64_t Bytes = endian::byte_swap<uint64_t, little>(P[K].
D[
I]);
78 Data.replace(P[K].Pos +
I *
sizeof(uint64_t),
sizeof(uint64_t),
79 (
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) {
148 LE.write<uint64_t>(ProfileData.first);
149 LE.write<uint64_t>(ProfRecord.
Counts.size());
150 for (uint64_t
I : ProfRecord.
Counts)
151 LE.write<uint64_t>(
I);
154 std::unique_ptr<ValueProfData> VDataPtr =
155 ValueProfData::serializeFrom(ProfileData.second);
157 VDataPtr->swapBytesFromHost(ValueProfDataEndianness);
158 Out.
write((
const char *)VDataPtr.get(), S);
177 this->Sparse = Sparse;
190 auto &ProfileDataMap = FunctionData[
Name];
194 std::tie(Where, NewFunc) =
199 Warn(make_error<InstrProfError>(
E));
206 Dest.
scale(Weight, MapWarn);
209 Dest.
merge(
I, Weight, MapWarn);
217 for (
auto &
I : IPW.FunctionData)
218 for (
auto &Func :
I.getValue())
219 addRecord(
I.getKey(), Func.first, std::move(Func.second), 1, Warn);
225 for (
const auto &Func : PD) {
235 using namespace IndexedInstrProf;
246 for (
unsigned I = 0;
I < Res.size();
I++)
251 using namespace IndexedInstrProf;
256 InfoObj->SummaryBuilder = &ISB;
259 for (
const auto &
I : FunctionData)
260 if (shouldEncodeData(
I.getValue()))
261 Generator.insert(
I.getKey(), &
I.getValue());
267 Header.
Version |= VARIANT_MASK_IR_PROF;
276 for (
int I = 0;
I < N - 1;
I++)
277 OS.
write(reinterpret_cast<uint64_t *>(&Header)[
I]);
280 uint64_t HashTableStartFieldOffset = OS.
tell();
286 uint32_t SummarySize = Summary::getSize(Summary::NumKinds, NumEntries);
288 uint64_t SummaryOffset = OS.
tell();
289 for (
unsigned I = 0; I < SummarySize /
sizeof(uint64_t); I++)
293 uint64_t HashTableStart = Generator.
Emit(OS.
OS, *InfoObj);
296 std::unique_ptr<IndexedInstrProf::Summary> TheSummary =
300 std::unique_ptr<ProfileSummary> PS = ISB.
getSummary();
302 InfoObj->SummaryBuilder =
nullptr;
307 {HashTableStartFieldOffset, &HashTableStart, 1},
309 {SummaryOffset,
reinterpret_cast<uint64_t *
>(TheSummary.get()),
310 (
int)(SummarySize /
sizeof(uint64_t))}};
311 OS.
patch(PatchItems,
sizeof(PatchItems) /
sizeof(*PatchItems));
331 #define VALUE_PROF_KIND(Enumerator, Value) #Enumerator, 340 OS <<
"# Func Hash:\n" << Hash <<
"\n";
341 OS <<
"# Num Counters:\n" << Func.
Counts.size() <<
"\n";
342 OS <<
"# Counter Values:\n";
343 for (uint64_t Count : Func.
Counts)
347 if (!NumValueKinds) {
353 for (
uint32_t VK = 0; VK < IPVK_Last + 1; VK++) {
357 OS <<
"# ValueKind = " << ValueProfKindStr[VK] <<
":\n" << VK <<
"\n";
358 OS <<
"# NumValueSites:\n" << NS <<
"\n";
362 std::unique_ptr<InstrProfValueData[]> VD = Func.
getValueForSite(VK, S);
364 if (VK == IPVK_IndirectCallTarget)
366 << VD[
I].Count <<
"\n";
368 OS << VD[
I].Value <<
":" << VD[
I].Count <<
"\n";
378 OS <<
"# IR level Instrumentation Flag\n:ir\n";
380 for (
const auto &
I : FunctionData)
381 if (shouldEncodeData(
I.getValue()))
385 for (
const auto &
I : FunctionData)
386 if (shouldEncodeData(
I.getValue()))
387 for (
const auto &Func :
I.getValue())
void setValueProfDataEndianness(support::endianness Endianness)
const InstrProfWriter::ProfilingData *const data_type
static const char * ValueProfKindStr[]
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.
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...
InstrProfWriter(bool Sparse=false)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
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.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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()
SummaryEntryVector & getDetailedSummary()
void mergeRecordsFromWriter(InstrProfWriter &&IPW, function_ref< void(Error)> Warn)
Merge existing function counts from the given writer.
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")
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...
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)
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()
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...
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)
InstrProfSummaryBuilder * SummaryBuilder
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.