LLVM  14.0.0git
InstrProfWriter.cpp
Go to the documentation of this file.
1 //===- InstrProfWriter.cpp - Instrumented profiling writer ----------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains support for writing profiling data for clang's
10 // instrumentation based PGO and coverage.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/STLExtras.h"
16 #include "llvm/ADT/StringRef.h"
17 #include "llvm/IR/ProfileSummary.h"
20 #include "llvm/Support/Endian.h"
22 #include "llvm/Support/Error.h"
26 #include <algorithm>
27 #include <cstdint>
28 #include <memory>
29 #include <string>
30 #include <tuple>
31 #include <utility>
32 #include <vector>
33 
34 using namespace llvm;
35 
36 // A struct to define how the data stream should be patched. For Indexed
37 // profiling, only uint64_t data type is needed.
38 struct PatchItem {
39  uint64_t Pos; // Where to patch.
40  uint64_t *D; // Pointer to an array of source data.
41  int N; // Number of elements in \c D array.
42 };
43 
44 namespace llvm {
45 
46 // A wrapper class to abstract writer stream with support of bytes
47 // back patching.
48 class ProfOStream {
49 public:
51  : IsFDOStream(true), OS(FD), LE(FD, support::little) {}
53  : IsFDOStream(false), OS(STR), LE(STR, support::little) {}
54 
55  uint64_t tell() { return OS.tell(); }
56  void write(uint64_t V) { LE.write<uint64_t>(V); }
57 
58  // \c patch can only be called when all data is written and flushed.
59  // For raw_string_ostream, the patch is done on the target string
60  // directly and it won't be reflected in the stream's internal buffer.
61  void patch(PatchItem *P, int NItems) {
62  using namespace support;
63 
64  if (IsFDOStream) {
65  raw_fd_ostream &FDOStream = static_cast<raw_fd_ostream &>(OS);
66  for (int K = 0; K < NItems; K++) {
67  FDOStream.seek(P[K].Pos);
68  for (int I = 0; I < P[K].N; I++)
69  write(P[K].D[I]);
70  }
71  } else {
72  raw_string_ostream &SOStream = static_cast<raw_string_ostream &>(OS);
73  std::string &Data = SOStream.str(); // with flush
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));
79  }
80  }
81  }
82  }
83 
84  // If \c OS is an instance of \c raw_fd_ostream, this field will be
85  // true. Otherwise, \c OS will be an raw_string_ostream.
89 };
90 
92 public:
95 
98 
101 
102  support::endianness ValueProfDataEndianness = support::little;
105 
106  InstrProfRecordWriterTrait() = default;
107 
110  }
111 
112  static std::pair<offset_type, offset_type>
114  using namespace support;
115 
116  endian::Writer LE(Out, little);
117 
118  offset_type N = K.size();
119  LE.write<offset_type>(N);
120 
121  offset_type M = 0;
122  for (const auto &ProfileData : *V) {
123  const InstrProfRecord &ProfRecord = ProfileData.second;
124  M += sizeof(uint64_t); // The function hash
125  M += sizeof(uint64_t); // The size of the Counts vector
126  M += ProfRecord.Counts.size() * sizeof(uint64_t);
127 
128  // Value data
129  M += ValueProfData::getSize(ProfileData.second);
130  }
131  LE.write<offset_type>(M);
132 
133  return std::make_pair(N, M);
134  }
135 
137  Out.write(K.data(), N);
138  }
139 
141  using namespace support;
142 
143  endian::Writer LE(Out, little);
144  for (const auto &ProfileData : *V) {
145  const InstrProfRecord &ProfRecord = ProfileData.second;
146  if (NamedInstrProfRecord::hasCSFlagInHash(ProfileData.first))
147  CSSummaryBuilder->addRecord(ProfRecord);
148  else
149  SummaryBuilder->addRecord(ProfRecord);
150 
151  LE.write<uint64_t>(ProfileData.first); // Function hash
152  LE.write<uint64_t>(ProfRecord.Counts.size());
153  for (uint64_t I : ProfRecord.Counts)
154  LE.write<uint64_t>(I);
155 
156  // Write value data
157  std::unique_ptr<ValueProfData> VDataPtr =
158  ValueProfData::serializeFrom(ProfileData.second);
159  uint32_t S = VDataPtr->getSize();
160  VDataPtr->swapBytesFromHost(ValueProfDataEndianness);
161  Out.write((const char *)VDataPtr.get(), S);
162  }
163  }
164 };
165 
166 } // end namespace llvm
167 
168 InstrProfWriter::InstrProfWriter(bool Sparse, bool InstrEntryBBEnabled)
169  : Sparse(Sparse), InstrEntryBBEnabled(InstrEntryBBEnabled),
170  InfoObj(new InstrProfRecordWriterTrait()) {}
171 
173 
174 // Internal interface for testing purpose only.
178 }
179 
181  this->Sparse = Sparse;
182 }
183 
185  function_ref<void(Error)> Warn) {
186  auto Name = I.Name;
187  auto Hash = I.Hash;
188  addRecord(Name, Hash, std::move(I), Weight, Warn);
189 }
190 
192  OverlapStats &Overlap,
193  OverlapStats &FuncLevelOverlap,
194  const OverlapFuncFilters &FuncFilter) {
195  auto Name = Other.Name;
196  auto Hash = Other.Hash;
197  Other.accumulateCounts(FuncLevelOverlap.Test);
198  if (FunctionData.find(Name) == FunctionData.end()) {
199  Overlap.addOneUnique(FuncLevelOverlap.Test);
200  return;
201  }
202  if (FuncLevelOverlap.Test.CountSum < 1.0f) {
203  Overlap.Overlap.NumEntries += 1;
204  return;
205  }
206  auto &ProfileDataMap = FunctionData[Name];
207  bool NewFunc;
209  std::tie(Where, NewFunc) =
210  ProfileDataMap.insert(std::make_pair(Hash, InstrProfRecord()));
211  if (NewFunc) {
212  Overlap.addOneMismatch(FuncLevelOverlap.Test);
213  return;
214  }
215  InstrProfRecord &Dest = Where->second;
216 
217  uint64_t ValueCutoff = FuncFilter.ValueCutoff;
218  if (!FuncFilter.NameFilter.empty() &&
219  Name.find(FuncFilter.NameFilter) != Name.npos)
220  ValueCutoff = 0;
221 
222  Dest.overlap(Other, Overlap, FuncLevelOverlap, ValueCutoff);
223 }
224 
226  InstrProfRecord &&I, uint64_t Weight,
227  function_ref<void(Error)> Warn) {
228  auto &ProfileDataMap = FunctionData[Name];
229 
230  bool NewFunc;
232  std::tie(Where, NewFunc) =
233  ProfileDataMap.insert(std::make_pair(Hash, InstrProfRecord()));
234  InstrProfRecord &Dest = Where->second;
235 
236  auto MapWarn = [&](instrprof_error E) {
237  Warn(make_error<InstrProfError>(E));
238  };
239 
240  if (NewFunc) {
241  // We've never seen a function with this name and hash, add it.
242  Dest = std::move(I);
243  if (Weight > 1)
244  Dest.scale(Weight, 1, MapWarn);
245  } else {
246  // We're updating a function we've seen before.
247  Dest.merge(I, Weight, MapWarn);
248  }
249 
250  Dest.sortValueData();
251 }
252 
254  function_ref<void(Error)> Warn) {
255  for (auto &I : IPW.FunctionData)
256  for (auto &Func : I.getValue())
257  addRecord(I.getKey(), Func.first, std::move(Func.second), 1, Warn);
258 }
259 
260 bool InstrProfWriter::shouldEncodeData(const ProfilingData &PD) {
261  if (!Sparse)
262  return true;
263  for (const auto &Func : PD) {
264  const InstrProfRecord &IPR = Func.second;
265  if (llvm::any_of(IPR.Counts, [](uint64_t Count) { return Count > 0; }))
266  return true;
267  }
268  return false;
269 }
270 
271 static void setSummary(IndexedInstrProf::Summary *TheSummary,
272  ProfileSummary &PS) {
273  using namespace IndexedInstrProf;
274 
275  std::vector<ProfileSummaryEntry> &Res = PS.getDetailedSummary();
276  TheSummary->NumSummaryFields = Summary::NumKinds;
277  TheSummary->NumCutoffEntries = Res.size();
279  TheSummary->set(Summary::MaxBlockCount, PS.getMaxCount());
281  TheSummary->set(Summary::TotalBlockCount, PS.getTotalCount());
282  TheSummary->set(Summary::TotalNumBlocks, PS.getNumCounts());
284  for (unsigned I = 0; I < Res.size(); I++)
285  TheSummary->setEntry(I, Res[I]);
286 }
287 
288 Error InstrProfWriter::writeImpl(ProfOStream &OS) {
289  using namespace IndexedInstrProf;
290 
292 
294  InfoObj->SummaryBuilder = &ISB;
296  InfoObj->CSSummaryBuilder = &CSISB;
297 
298  // Populate the hash table generator.
299  for (const auto &I : FunctionData)
300  if (shouldEncodeData(I.getValue()))
301  Generator.insert(I.getKey(), &I.getValue());
302  // Write the header.
306  if (ProfileKind == PF_IRLevel)
307  Header.Version |= VARIANT_MASK_IR_PROF;
308  if (ProfileKind == PF_IRLevelWithCS) {
309  Header.Version |= VARIANT_MASK_IR_PROF;
310  Header.Version |= VARIANT_MASK_CSIR_PROF;
311  }
312  if (InstrEntryBBEnabled)
313  Header.Version |= VARIANT_MASK_INSTR_ENTRY;
314 
315  Header.Unused = 0;
316  Header.HashType = static_cast<uint64_t>(IndexedInstrProf::HashType);
317  Header.HashOffset = 0;
318  int N = sizeof(IndexedInstrProf::Header) / sizeof(uint64_t);
319 
320  // Only write out all the fields except 'HashOffset'. We need
321  // to remember the offset of that field to allow back patching
322  // later.
323  for (int I = 0; I < N - 1; I++)
324  OS.write(reinterpret_cast<uint64_t *>(&Header)[I]);
325 
326  // Save the location of Header.HashOffset field in \c OS.
327  uint64_t HashTableStartFieldOffset = OS.tell();
328  // Reserve the space for HashOffset field.
329  OS.write(0);
330 
331  // Reserve space to write profile summary data.
333  uint32_t SummarySize = Summary::getSize(Summary::NumKinds, NumEntries);
334  // Remember the summary offset.
335  uint64_t SummaryOffset = OS.tell();
336  for (unsigned I = 0; I < SummarySize / sizeof(uint64_t); I++)
337  OS.write(0);
338  uint64_t CSSummaryOffset = 0;
339  uint64_t CSSummarySize = 0;
340  if (ProfileKind == PF_IRLevelWithCS) {
341  CSSummaryOffset = OS.tell();
342  CSSummarySize = SummarySize / sizeof(uint64_t);
343  for (unsigned I = 0; I < CSSummarySize; I++)
344  OS.write(0);
345  }
346 
347  // Write the hash table.
348  uint64_t HashTableStart = Generator.Emit(OS.OS, *InfoObj);
349 
350  // Allocate space for data to be serialized out.
351  std::unique_ptr<IndexedInstrProf::Summary> TheSummary =
352  IndexedInstrProf::allocSummary(SummarySize);
353  // Compute the Summary and copy the data to the data
354  // structure to be serialized out (to disk or buffer).
355  std::unique_ptr<ProfileSummary> PS = ISB.getSummary();
356  setSummary(TheSummary.get(), *PS);
357  InfoObj->SummaryBuilder = nullptr;
358 
359  // For Context Sensitive summary.
360  std::unique_ptr<IndexedInstrProf::Summary> TheCSSummary = nullptr;
361  if (ProfileKind == PF_IRLevelWithCS) {
362  TheCSSummary = IndexedInstrProf::allocSummary(SummarySize);
363  std::unique_ptr<ProfileSummary> CSPS = CSISB.getSummary();
364  setSummary(TheCSSummary.get(), *CSPS);
365  }
366  InfoObj->CSSummaryBuilder = nullptr;
367 
368  // Now do the final patch:
369  PatchItem PatchItems[] = {
370  // Patch the Header.HashOffset field.
371  {HashTableStartFieldOffset, &HashTableStart, 1},
372  // Patch the summary data.
373  {SummaryOffset, reinterpret_cast<uint64_t *>(TheSummary.get()),
374  (int)(SummarySize / sizeof(uint64_t))},
375  {CSSummaryOffset, reinterpret_cast<uint64_t *>(TheCSSummary.get()),
376  (int)CSSummarySize}};
377 
378  OS.patch(PatchItems, sizeof(PatchItems) / sizeof(*PatchItems));
379 
380  for (const auto &I : FunctionData)
381  for (const auto &F : I.getValue())
382  if (Error E = validateRecord(F.second))
383  return E;
384 
385  return Error::success();
386 }
387 
389  // Write the hash table.
390  ProfOStream POS(OS);
391  return writeImpl(POS);
392 }
393 
394 std::unique_ptr<MemoryBuffer> InstrProfWriter::writeBuffer() {
395  std::string Data;
397  ProfOStream POS(OS);
398  // Write the hash table.
399  if (Error E = writeImpl(POS))
400  return nullptr;
401  // Return this in an aligned memory buffer.
403 }
404 
405 static const char *ValueProfKindStr[] = {
406 #define VALUE_PROF_KIND(Enumerator, Value, Descr) #Enumerator,
408 };
409 
411  for (uint32_t VK = 0; VK <= IPVK_Last; VK++) {
412  uint32_t NS = Func.getNumValueSites(VK);
413  if (!NS)
414  continue;
415  for (uint32_t S = 0; S < NS; S++) {
416  uint32_t ND = Func.getNumValueDataForSite(VK, S);
417  std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S);
418  bool WasZero = false;
419  for (uint32_t I = 0; I < ND; I++)
420  if ((VK != IPVK_IndirectCallTarget) && (VD[I].Value == 0)) {
421  if (WasZero)
422  return make_error<InstrProfError>(instrprof_error::invalid_prof);
423  WasZero = true;
424  }
425  }
426  }
427 
428  return Error::success();
429 }
430 
432  const InstrProfRecord &Func,
433  InstrProfSymtab &Symtab,
434  raw_fd_ostream &OS) {
435  OS << Name << "\n";
436  OS << "# Func Hash:\n" << Hash << "\n";
437  OS << "# Num Counters:\n" << Func.Counts.size() << "\n";
438  OS << "# Counter Values:\n";
439  for (uint64_t Count : Func.Counts)
440  OS << Count << "\n";
441 
442  uint32_t NumValueKinds = Func.getNumValueKinds();
443  if (!NumValueKinds) {
444  OS << "\n";
445  return;
446  }
447 
448  OS << "# Num Value Kinds:\n" << Func.getNumValueKinds() << "\n";
449  for (uint32_t VK = 0; VK < IPVK_Last + 1; VK++) {
450  uint32_t NS = Func.getNumValueSites(VK);
451  if (!NS)
452  continue;
453  OS << "# ValueKind = " << ValueProfKindStr[VK] << ":\n" << VK << "\n";
454  OS << "# NumValueSites:\n" << NS << "\n";
455  for (uint32_t S = 0; S < NS; S++) {
456  uint32_t ND = Func.getNumValueDataForSite(VK, S);
457  OS << ND << "\n";
458  std::unique_ptr<InstrProfValueData[]> VD = Func.getValueForSite(VK, S);
459  for (uint32_t I = 0; I < ND; I++) {
460  if (VK == IPVK_IndirectCallTarget)
461  OS << Symtab.getFuncNameOrExternalSymbol(VD[I].Value) << ":"
462  << VD[I].Count << "\n";
463  else
464  OS << VD[I].Value << ":" << VD[I].Count << "\n";
465  }
466  }
467  }
468 
469  OS << "\n";
470 }
471 
473  if (ProfileKind == PF_IRLevel)
474  OS << "# IR level Instrumentation Flag\n:ir\n";
475  else if (ProfileKind == PF_IRLevelWithCS)
476  OS << "# CSIR level Instrumentation Flag\n:csir\n";
477  if (InstrEntryBBEnabled)
478  OS << "# Always instrument the function entry block\n:entry_first\n";
479  InstrProfSymtab Symtab;
480 
482  using RecordType = std::pair<StringRef, FuncPair>;
483  SmallVector<RecordType, 4> OrderedFuncData;
484 
485  for (const auto &I : FunctionData) {
486  if (shouldEncodeData(I.getValue())) {
487  if (Error E = Symtab.addFuncName(I.getKey()))
488  return E;
489  for (const auto &Func : I.getValue())
490  OrderedFuncData.push_back(std::make_pair(I.getKey(), Func));
491  }
492  }
493 
494  llvm::sort(OrderedFuncData, [](const RecordType &A, const RecordType &B) {
495  return std::tie(A.first, A.second.first) <
496  std::tie(B.first, B.second.first);
497  });
498 
499  for (const auto &record : OrderedFuncData) {
500  const StringRef &Name = record.first;
501  const FuncPair &Func = record.second;
502  writeRecordInText(Name, Func.first, Func.second, Symtab, OS);
503  }
504 
505  for (const auto &record : OrderedFuncData) {
506  const FuncPair &Func = record.second;
507  if (Error E = validateRecord(Func.second))
508  return E;
509  }
510 
511  return Error::success();
512 }
MemoryBuffer.h
llvm::raw_ostream::tell
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:135
llvm::InstrProfWriter::writeText
Error writeText(raw_fd_ostream &OS)
Write the profile in text format to OS.
Definition: InstrProfWriter.cpp:472
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::msgpack::Endianness
constexpr support::endianness Endianness
The endianness of all multi-byte encoded values in MessagePack.
Definition: MsgPack.h:24
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::IndexedInstrProf::Header::Version
uint64_t Version
Definition: InstrProf.h:1001
llvm::InstrProfWriter::write
Error write(raw_fd_ostream &OS)
Write the profile to OS.
Definition: InstrProfWriter.cpp:388
llvm::OnDiskChainedHashTableGenerator
Generates an on disk hash table.
Definition: OnDiskHashTable.h:59
ProfileSummary.h
StringRef.h
P
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Definition: README-SSE.txt:411
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:625
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1168
llvm::IndexedInstrProf::ComputeHash
uint64_t ComputeHash(StringRef K)
Definition: InstrProf.h:995
llvm::FunctionLoweringInfo::StatepointRelocationRecord
Helper object to track which of three possible relocation mechanisms are used for a particular value ...
Definition: FunctionLoweringInfo.h:96
llvm::ProfOStream::write
void write(uint64_t V)
Definition: InstrProfWriter.cpp:56
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
llvm::SmallDenseMap
Definition: DenseMap.h:880
Error.h
llvm::DenseMapIterator
Definition: DenseMap.h:56
llvm::IndexedInstrProf::Summary::NumKinds
@ NumKinds
Definition: InstrProf.h:1035
llvm::OverlapStats
Definition: InstrProf.h:611
llvm::InstrProfRecord::overlap
void overlap(InstrProfRecord &Other, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap, uint64_t ValueCutoff)
Compute the overlap b/w this IntrprofRecord and Other.
Definition: InstrProf.cpp:573
llvm::ProfileSummary::getTotalCount
uint64_t getTotalCount()
Definition: ProfileSummary.h:92
llvm::InstrProfRecordWriterTrait::CSSummaryBuilder
InstrProfSummaryBuilder * CSSummaryBuilder
Definition: InstrProfWriter.cpp:104
llvm::InstrProfRecordWriterTrait::ValueProfDataEndianness
support::endianness ValueProfDataEndianness
Definition: InstrProfWriter.cpp:102
llvm::ProfOStream::tell
uint64_t tell()
Definition: InstrProfWriter.cpp:55
STLExtras.h
llvm::instrprof_error::invalid_prof
@ invalid_prof
llvm::support::endian::Writer
Adapter to write values to a stream in a particular byte order.
Definition: EndianStream.h:52
ProfileCommon.h
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::detail::DenseMapPair
Definition: DenseMap.h:41
llvm::InstrProfRecord
Profiling information for a single function.
Definition: InstrProf.h:691
new
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM ID Predecessors according to mbb< bb27, 0x8b0a7c0 > Note ADDri is not a two address instruction its result reg1037 is an operand of the PHI node in bb76 and its operand reg1039 is the result of the PHI node We should treat it as a two address code and make sure the ADDri is scheduled after any node that reads reg1039 Use info(i.e. register scavenger) to assign it a free register to allow reuse the collector could move the objects and invalidate the derived pointer This is bad enough in the first but safe points can crop up unpredictably **array_addr i32 n y store obj * new
Definition: README.txt:125
F
#define F(x, y, z)
Definition: MD5.cpp:56
InstrProfData.inc
llvm::InstrProfRecordWriterTrait
Definition: InstrProfWriter.cpp:91
InstrProfWriter.h
llvm::OverlapFuncFilters
Definition: InstrProf.h:654
llvm::coverage::CurrentVersion
@ CurrentVersion
Definition: CoverageMapping.h:1010
PatchItem::Pos
uint64_t Pos
Definition: InstrProfWriter.cpp:39
llvm::ProfileSummary::getMaxFunctionCount
uint64_t getMaxFunctionCount()
Definition: ProfileSummary.h:90
llvm::CountSumOrPercent::CountSum
double CountSum
Definition: InstrProf.h:599
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::ProfileSummary::getNumFunctions
uint32_t getNumFunctions()
Definition: ProfileSummary.h:89
llvm::support::little
@ little
Definition: Endian.h:27
llvm::InstrProfWriter::InstrProfWriter
InstrProfWriter(bool Sparse=false, bool InstrEntryBBEnabled=false)
Definition: InstrProfWriter.cpp:168
llvm::OnDiskChainedHashTableGenerator::Emit
offset_type Emit(raw_ostream &Out)
Emit the table to Out, which must not be at offset 0.
Definition: OnDiskHashTable.h:143
OnDiskHashTable.h
llvm::InstrProfWriter::writeRecordInText
static void writeRecordInText(StringRef Name, uint64_t Hash, const InstrProfRecord &Counters, InstrProfSymtab &Symtab, raw_fd_ostream &OS)
Write Record in text format to OS.
Definition: InstrProfWriter.cpp:431
llvm::InstrProfRecordWriterTrait::EmitData
void EmitData(raw_ostream &Out, key_type_ref, data_type_ref V, offset_type)
Definition: InstrProfWriter.cpp:140
PatchItem::N
int N
Definition: InstrProfWriter.cpp:41
llvm::InstrProfWriter::PF_IRLevelWithCS
@ PF_IRLevelWithCS
Definition: InstrProfWriter.h:37
false
Definition: StackSlotColoring.cpp:142
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::ProfOStream::OS
raw_ostream & OS
Definition: InstrProfWriter.cpp:87
PatchItem
Definition: InstrProfWriter.cpp:38
llvm::raw_ostream::write
raw_ostream & write(unsigned char C)
Definition: raw_ostream.cpp:220
InstrProf.h
llvm::IndexedInstrProf::Header::Magic
uint64_t Magic
Definition: InstrProf.h:1000
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::IndexedInstrProf::Header
Definition: InstrProf.h:999
llvm::raw_fd_ostream::seek
uint64_t seek(uint64_t off)
Flushes the stream and repositions the underlying file descriptor position to the offset specified fr...
Definition: raw_ostream.cpp:801
llvm::IndexedInstrProf::Summary::TotalBlockCount
@ TotalBlockCount
The sum of all instrumented block counts.
Definition: InstrProf.h:1034
ValueProfKindStr
static const char * ValueProfKindStr[]
Definition: InstrProfWriter.cpp:405
llvm::InstrProfWriter::PF_IRLevel
@ PF_IRLevel
Definition: InstrProfWriter.h:37
llvm::function_ref
An efficient, type-erasing, non-owning reference to a callable.
Definition: STLExtras.h:168
llvm::IndexedInstrProf::Summary::MaxFunctionCount
@ MaxFunctionCount
The maximal execution count among all functions.
Definition: InstrProf.h:1028
llvm::ProfileSummary::getDetailedSummary
SummaryEntryVector & getDetailedSummary()
Definition: ProfileSummary.h:88
llvm::CountSumOrPercent::NumEntries
uint64_t NumEntries
Definition: InstrProf.h:598
llvm::IndexedInstrProf::Summary::set
void set(SummaryFieldKind K, uint64_t V)
Definition: InstrProf.h:1074
llvm::InstrProfRecordWriterTrait::data_type
const InstrProfWriter::ProfilingData *const data_type
Definition: InstrProfWriter.cpp:96
llvm::ProfOStream::patch
void patch(PatchItem *P, int NItems)
Definition: InstrProfWriter.cpp:61
llvm::InstrProfWriter
Definition: InstrProfWriter.h:33
uint64_t
llvm::InstrProfWriter::setValueProfDataEndianness
void setValueProfDataEndianness(support::endianness Endianness)
Definition: InstrProfWriter.cpp:175
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::InstrProfRecordWriterTrait::SummaryBuilder
InstrProfSummaryBuilder * SummaryBuilder
Definition: InstrProfWriter.cpp:103
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::InstrProfSummaryBuilder
Definition: ProfileCommon.h:74
llvm::ProfileSummary::getMaxCount
uint64_t getMaxCount()
Definition: ProfileSummary.h:93
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::instrprof_error
instrprof_error
Definition: InstrProf.h:282
llvm::ProfileSummary
Definition: ProfileSummary.h:45
setSummary
static void setSummary(IndexedInstrProf::Summary *TheSummary, ProfileSummary &PS)
Definition: InstrProfWriter.cpp:271
llvm::X86II::PD
@ PD
Definition: X86BaseInfo.h:782
llvm::IndexedInstrProf::Header::HashType
uint64_t HashType
Definition: InstrProf.h:1003
llvm::IndexedInstrProf::allocSummary
std::unique_ptr< Summary > allocSummary(uint32_t TotalSize)
Definition: InstrProf.h:1088
llvm::IndexedInstrProf::Summary::TotalNumFunctions
@ TotalNumFunctions
The total number of functions instrumented.
Definition: InstrProf.h:1022
llvm::InstrProfWriter::addRecord
void addRecord(NamedInstrProfRecord &&I, uint64_t Weight, function_ref< void(Error)> Warn)
Add function counts for the given function.
Definition: InstrProfWriter.cpp:184
llvm::ProfOStream::ProfOStream
ProfOStream(raw_fd_ostream &FD)
Definition: InstrProfWriter.cpp:50
llvm::IndexedInstrProf::Summary::setEntry
void setEntry(uint32_t I, const ProfileSummaryEntry &E)
Definition: InstrProf.h:1080
llvm::OverlapStats::addOneUnique
void addOneUnique(const CountSumOrPercent &UniqueFunc)
Definition: InstrProf.cpp:1217
llvm::any_of
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1554
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::IndexedInstrProf::Magic
const uint64_t Magic
Definition: InstrProf.h:962
llvm::support::endian::Writer::write
void write(ArrayRef< value_type > Val)
Definition: EndianStream.h:56
llvm::NamedInstrProfRecord::hasCSFlagInHash
static bool hasCSFlagInHash(uint64_t FuncHash)
Definition: InstrProf.h:860
uint32_t
llvm::IndexedInstrProf::Summary::NumCutoffEntries
uint64_t NumCutoffEntries
Definition: InstrProf.h:1041
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::raw_fd_ostream
A raw_ostream that writes to a file descriptor.
Definition: raw_ostream.h:443
llvm::InstrProfRecord::merge
void merge(InstrProfRecord &Other, uint64_t Weight, function_ref< void(instrprof_error)> Warn)
Merge the counts in Other into this one.
Definition: InstrProf.cpp:678
llvm::InstrProfWriter::writeBuffer
std::unique_ptr< MemoryBuffer > writeBuffer()
Write the profile, returning the raw data. For testing.
Definition: InstrProfWriter.cpp:394
llvm::IndexedInstrProf::Summary::MaxInternalBlockCount
@ MaxInternalBlockCount
Max internal block count of the program (excluding entry blocks).
Definition: InstrProf.h:1032
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::InstrProfSymtab
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:414
EndianStream.h
llvm::InstrProfWriter::~InstrProfWriter
~InstrProfWriter()
Definition: InstrProfWriter.cpp:172
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::InstrProfRecordWriterTrait::data_type_ref
const InstrProfWriter::ProfilingData *const data_type_ref
Definition: InstrProfWriter.cpp:97
llvm::IndexedInstrProf::Summary
Definition: InstrProf.h:1010
llvm::InstrProfWriter::validateRecord
Error validateRecord(const InstrProfRecord &Func)
Definition: InstrProfWriter.cpp:410
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1488
llvm::IndexedInstrProf::Summary::MaxBlockCount
@ MaxBlockCount
Max block count of the program.
Definition: InstrProf.h:1030
llvm::ProfOStream::LE
support::endian::Writer LE
Definition: InstrProfWriter.cpp:88
llvm::OverlapStats::Overlap
CountSumOrPercent Overlap
Definition: InstrProf.h:618
llvm::IndexedInstrProf::HashType
const HashT HashType
Definition: InstrProf.h:993
llvm::InstrProfRecordWriterTrait::EmitKey
void EmitKey(raw_ostream &Out, key_type_ref K, offset_type N)
Definition: InstrProfWriter.cpp:136
llvm::ProfileSummary::getMaxInternalCount
uint64_t getMaxInternalCount()
Definition: ProfileSummary.h:94
llvm::IndexedInstrProf::Header::HashOffset
uint64_t HashOffset
Definition: InstrProf.h:1004
llvm::ProfileSummary::getNumCounts
uint32_t getNumCounts()
Definition: ProfileSummary.h:91
llvm::InstrProfSymtab::addFuncName
Error addFuncName(StringRef FuncName)
Update the symtab by adding FuncName to the table.
Definition: InstrProf.h:475
llvm::DenseMapBase< SmallDenseMap< KeyT, ValueT, 4, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >, KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > >::iterator
DenseMapIterator< KeyT, ValueT, DenseMapInfo< KeyT >, llvm::detail::DenseMapPair< KeyT, ValueT > > iterator
Definition: DenseMap.h:70
llvm::InstrProfRecord::sortValueData
void sortValueData()
Sort value profile data (per site) by count.
Definition: InstrProf.h:761
llvm::OverlapFuncFilters::ValueCutoff
uint64_t ValueCutoff
Definition: InstrProf.h:655
llvm::InstrProfSymtab::getFuncNameOrExternalSymbol
StringRef getFuncNameOrExternalSymbol(uint64_t FuncMD5Hash)
Just like getFuncName, except that it will return a non-empty StringRef if the function is external t...
Definition: InstrProf.h:558
N
#define N
llvm::OverlapFuncFilters::NameFilter
const std::string NameFilter
Definition: InstrProf.h:656
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:165
support
Reimplement select in terms of SEL *We would really like to support but we need to prove that the add doesn t need to overflow between the two bit chunks *Implement pre post increment support(e.g. PR935) *Implement smarter const ant generation for binops with large immediates. A few ARMv6T2 ops should be pattern matched
Definition: README.txt:10
llvm::IndexedInstrProf::Header::Unused
uint64_t Unused
Definition: InstrProf.h:1002
llvm::support::endianness
endianness
Definition: Endian.h:27
llvm::StringRef::data
const LLVM_NODISCARD char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:149
llvm::NamedInstrProfRecord
Definition: InstrProf.h:848
llvm::InstrProfSummaryBuilder::addRecord
void addRecord(const InstrProfRecord &)
Definition: ProfileSummaryBuilder.cpp:95
llvm::InstrProfRecordWriterTrait::EmitKeyDataLength
static std::pair< offset_type, offset_type > EmitKeyDataLength(raw_ostream &Out, key_type_ref K, data_type_ref V)
Definition: InstrProfWriter.cpp:113
PatchItem::D
uint64_t * D
Definition: InstrProfWriter.cpp:40
llvm::IndexedInstrProf::Summary::TotalNumBlocks
@ TotalNumBlocks
Total number of instrumented blocks/edges.
Definition: InstrProf.h:1024
llvm::InstrProfRecordWriterTrait::ComputeHash
static hash_value_type ComputeHash(key_type_ref K)
Definition: InstrProfWriter.cpp:108
llvm::ProfOStream
Definition: InstrProfWriter.cpp:48
llvm::InstrProfWriter::setOutputSparse
void setOutputSparse(bool Sparse)
Definition: InstrProfWriter.cpp:180
raw_ostream.h
llvm::StringRef::size
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:157
llvm::MemoryBuffer::getMemBufferCopy
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.
Definition: MemoryBuffer.cpp:136
Endian.h
llvm::InstrProfWriter::mergeRecordsFromWriter
void mergeRecordsFromWriter(InstrProfWriter &&IPW, function_ref< void(Error)> Warn)
Merge existing function counts from the given writer.
Definition: InstrProfWriter.cpp:253
true
basic Basic Alias true
Definition: BasicAliasAnalysis.cpp:1815
llvm::raw_string_ostream::str
std::string & str()
Flushes the stream contents to the target string and returns the string's reference.
Definition: raw_ostream.h:643
llvm::IndexedInstrProf::Summary::NumSummaryFields
uint64_t NumSummaryFields
Definition: InstrProf.h:1039
llvm::ProfileSummaryBuilder::DefaultCutoffs
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
Definition: ProfileCommon.h:65
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::OverlapStats::addOneMismatch
void addOneMismatch(const CountSumOrPercent &MismatchFunc)
Definition: InstrProf.cpp:1207
llvm::InstrProfRecord::Counts
std::vector< uint64_t > Counts
Definition: InstrProf.h:692
llvm::ProfOStream::IsFDOStream
bool IsFDOStream
Definition: InstrProfWriter.cpp:86
llvm::OverlapStats::Test
CountSumOrPercent Test
Definition: InstrProf.h:616
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1172
llvm::ProfOStream::ProfOStream
ProfOStream(raw_string_ostream &STR)
Definition: InstrProfWriter.cpp:52
llvm::InstrProfWriter::overlapRecord
void overlapRecord(NamedInstrProfRecord &&Other, OverlapStats &Overlap, OverlapStats &FuncLevelOverlap, const OverlapFuncFilters &FuncFilter)
Definition: InstrProfWriter.cpp:191
llvm::InstrProfRecord::scale
void scale(uint64_t N, uint64_t D, function_ref< void(instrprof_error)> Warn)
Scale up profile counts (including value profile data) by a factor of (N / D).
Definition: InstrProf.cpp:706