57 using namespace support;
60 for (
int K = 0; K < NItems; K++) {
61 FDOStream.
seek(P[K].Pos);
62 for (
int I = 0;
I < P[K].
N;
I++)
68 std::string &Data = SOStream.
str();
69 for (
int K = 0; K < NItems; K++) {
70 for (
int I = 0;
I < P[K].
N;
I++) {
71 uint64_t Bytes = endian::byte_swap<uint64_t, little>(P[K].
D[
I]);
72 Data.replace(P[K].Pos +
I *
sizeof(uint64_t),
sizeof(uint64_t),
73 (
const char *)&Bytes,
sizeof(uint64_t));
105 static std::pair<offset_type, offset_type>
107 using namespace llvm::support;
114 for (
const auto &ProfileData : *V) {
116 M +=
sizeof(uint64_t);
117 M +=
sizeof(uint64_t);
118 M += ProfRecord.
Counts.size() *
sizeof(uint64_t);
121 M += ValueProfData::getSize(ProfileData.second);
125 return std::make_pair(
N, M);
133 using namespace llvm::support;
135 for (
const auto &ProfileData : *V) {
137 SummaryBuilder->addRecord(ProfRecord);
139 LE.
write<uint64_t>(ProfileData.first);
141 for (uint64_t
I : ProfRecord.
Counts)
145 std::unique_ptr<ValueProfData> VDataPtr =
146 ValueProfData::serializeFrom(ProfileData.second);
148 VDataPtr->swapBytesFromHost(ValueProfDataEndianness);
149 Out.
write((
const char *)VDataPtr.get(), S);
157 : Sparse(Sparse), FunctionData(),
ProfileKind(PF_Unknown),
169 this->Sparse = Sparse;
173 auto &ProfileDataMap = FunctionData[
I.Name];
177 std::tie(Where, NewFunc) =
185 Dest.
Name = FunctionData.find(Dest.
Name)->getKey();
199 for (
auto &
I : IPW.FunctionData)
200 for (
auto &
Func :
I.getValue())
206 bool InstrProfWriter::shouldEncodeData(
const ProfilingData &
PD) {
209 for (
const auto &
Func : PD) {
211 if (
any_of(IPR.
Counts, [](uint64_t Count) {
return Count > 0; }))
219 using namespace IndexedInstrProf;
229 for (
unsigned I = 0;
I < Res.size();
I++)
236 using namespace IndexedInstrProf;
238 InfoObj->SummaryBuilder = &ISB;
241 for (
const auto &
I : FunctionData)
242 if (shouldEncodeData(
I.getValue()))
243 Generator.insert(
I.getKey(), &
I.getValue());
249 Header.Version |= VARIANT_MASK_IR_PROF;
252 Header.HashOffset = 0;
258 for (
int I = 0;
I <
N - 1;
I++)
259 OS.
write(reinterpret_cast<uint64_t *>(&Header)[
I]);
262 uint64_t HashTableStartFieldOffset = OS.
tell();
268 uint32_t SummarySize = Summary::getSize(Summary::NumKinds, NumEntries);
270 uint64_t SummaryOffset = OS.
tell();
271 for (
unsigned I = 0; I < SummarySize /
sizeof(uint64_t); I++)
275 uint64_t HashTableStart = Generator.
Emit(OS.
OS, *InfoObj);
278 std::unique_ptr<IndexedInstrProf::Summary> TheSummary =
282 std::unique_ptr<ProfileSummary>
PS = ISB.getSummary();
284 InfoObj->SummaryBuilder =
nullptr;
289 {HashTableStartFieldOffset, &HashTableStart, 1},
291 {SummaryOffset,
reinterpret_cast<uint64_t *
>(TheSummary.get()),
292 (
int)(SummarySize /
sizeof(uint64_t))}};
293 OS.
patch(PatchItems,
sizeof(PatchItems) /
sizeof(*PatchItems));
313 #define VALUE_PROF_KIND(Enumerator, Value) #Enumerator,
320 OS << Func.
Name <<
"\n";
321 OS <<
"# Func Hash:\n" << Func.
Hash <<
"\n";
322 OS <<
"# Num Counters:\n" << Func.
Counts.size() <<
"\n";
323 OS <<
"# Counter Values:\n";
324 for (uint64_t Count : Func.
Counts)
328 if (!NumValueKinds) {
334 for (
uint32_t VK = 0; VK < IPVK_Last + 1; VK++) {
338 OS <<
"# ValueKind = " << ValueProfKindStr[VK] <<
":\n" << VK <<
"\n";
339 OS <<
"# NumValueSites:\n" << NS <<
"\n";
343 std::unique_ptr<InstrProfValueData[]> VD = Func.
getValueForSite(VK, S);
345 if (VK == IPVK_IndirectCallTarget)
348 OS << VD[
I].Value <<
":" << VD[
I].Count <<
"\n";
358 OS <<
"# IR level Instrumentation Flag\n:ir\n";
360 for (
const auto &I : FunctionData)
361 if (shouldEncodeData(I.getValue()))
365 for (
const auto &I : FunctionData)
366 if (shouldEncodeData(I.getValue()))
367 for (
const auto &
Func : I.getValue())
void scale(uint64_t Weight)
Scale up profile counts (including value profile data) by Weight.
void setValueProfDataEndianness(support::endianness Endianness)
static const char * ValueProfKindStr[]
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
uint64_t NumCutoffEntries
void sortValueData()
Sort value profile data (per site) by count.
Error addRecord(InstrProfRecord &&I, uint64_t Weight=1)
Add function counts for the given function.
Defines facilities for reading and writing on-disk hash tables.
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)
void writeText(raw_fd_ostream &OS)
Write the profile in text format to OS.
std::unique_ptr< Summary > allocSummary(uint32_t TotalSize)
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
uint64_t getMaxInternalCount()
static void setSummary(IndexedInstrProf::Summary *TheSummary, ProfileSummary &PS)
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type N)
Error takeError()
Get the error contained within the record's soft error counter.
ProfOStream(llvm::raw_fd_ostream &FD)
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
void merge(InstrProfRecord &Other, uint64_t Weight=1)
Merge the counts in Other into this one.
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
uint64_t NumSummaryFields
uint64_t tell() const
tell - Return the current offset with the file.
StringRef getFuncName(uint64_t FuncNameAddress, size_t NameSize)
Return function's PGO name from the function name's symbol address in the object file.
uint64_t getMaxFunctionCount()
void addFuncName(StringRef FuncName)
Update the symtab by adding FuncName to the table.
Function Alias Analysis false
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
size_t size() const
size - Get the array size.
SummaryEntryVector & getDetailedSummary()
const InstrProfWriter::ProfilingData *const data_type
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
void write(ArrayRef< value_type > Vals)
void setOutputSparse(bool Sparse)
static hash_value_type ComputeHash(key_type_ref K)
InstrProfRecordWriterTrait()
bool any_of(R &&Range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly...
Error mergeRecordsFromWriter(InstrProfWriter &&IPW)
Merge existing function counts from the given writer.
uint64_t ComputeHash(StringRef K)
uint32_t getNumValueDataForSite(uint32_t ValueKind, uint32_t Site) const
Return the number of value data collected for ValueKind at profiling site: Site.
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.
ProfOStream(llvm::raw_string_ostream &STR)
support::endianness ValueProfDataEndianness
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
A raw_ostream that writes to a file descriptor.
uint32_t getNumFunctions()
Profiling information for a single function.
uint32_t getNumValueKinds() const
Return the number of value profile kinds with non-zero number of profile sites.
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
void patch(PatchItem *P, int NItems)
InstrProfSummaryBuilder * SummaryBuilder
uint32_t getNumValueSites(uint32_t ValueKind) const
Return the number of instrumented sites for ValueKind.
A raw_ostream that writes to an std::string.
void write(raw_fd_ostream &OS)
Write the profile to OS.
std::unique_ptr< InstrProfValueData[]> getValueForSite(uint32_t ValueKind, uint32_t Site, uint64_t *TotalC=0) const
Return the array of profiled values at Site.
LLVM Value Representation.
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...
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).
support::endian::Writer< support::little > LE
StringRef - Represent a constant reference to a string, i.e.
void set(SummaryFieldKind K, uint64_t V)
const InstrProfWriter::ProfilingData *const data_type_ref
std::unique_ptr< MemoryBuffer > writeBuffer()
Write the profile, returning the raw data. For testing.
static void writeRecordInText(const InstrProfRecord &Record, InstrProfSymtab &Symtab, raw_fd_ostream &OS)
Write Record in text format to OS.