LLVM  14.0.0git
InstrProfReader.cpp
Go to the documentation of this file.
1 //===- InstrProfReader.cpp - Instrumented profiling reader ----------------===//
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 reading profiling data for clang's
10 // instrumentation based PGO and coverage.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "llvm/ADT/ArrayRef.h"
16 #include "llvm/ADT/DenseMap.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/StringExtras.h"
19 #include "llvm/ADT/StringRef.h"
20 #include "llvm/IR/ProfileSummary.h"
23 #include "llvm/Support/Endian.h"
24 #include "llvm/Support/Error.h"
25 #include "llvm/Support/ErrorOr.h"
29 #include <algorithm>
30 #include <cctype>
31 #include <cstddef>
32 #include <cstdint>
33 #include <limits>
34 #include <memory>
35 #include <system_error>
36 #include <utility>
37 #include <vector>
38 
39 using namespace llvm;
40 
42 setupMemoryBuffer(const Twine &Path) {
44  MemoryBuffer::getFileOrSTDIN(Path, /*IsText=*/true);
45  if (std::error_code EC = BufferOrErr.getError())
46  return errorCodeToError(EC);
47  return std::move(BufferOrErr.get());
48 }
49 
51  return Reader.readHeader();
52 }
53 
56  const InstrProfCorrelator *Correlator) {
57  // Set up the buffer to read.
58  auto BufferOrError = setupMemoryBuffer(Path);
59  if (Error E = BufferOrError.takeError())
60  return std::move(E);
61  return InstrProfReader::create(std::move(BufferOrError.get()), Correlator);
62 }
63 
65 InstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer,
66  const InstrProfCorrelator *Correlator) {
67  // Sanity check the buffer.
68  if (uint64_t(Buffer->getBufferSize()) > std::numeric_limits<uint64_t>::max())
69  return make_error<InstrProfError>(instrprof_error::too_large);
70 
71  if (Buffer->getBufferSize() == 0)
72  return make_error<InstrProfError>(instrprof_error::empty_raw_profile);
73 
74  std::unique_ptr<InstrProfReader> Result;
75  // Create the reader.
77  Result.reset(new IndexedInstrProfReader(std::move(Buffer)));
78  else if (RawInstrProfReader64::hasFormat(*Buffer))
79  Result.reset(new RawInstrProfReader64(std::move(Buffer), Correlator));
80  else if (RawInstrProfReader32::hasFormat(*Buffer))
81  Result.reset(new RawInstrProfReader32(std::move(Buffer), Correlator));
82  else if (TextInstrProfReader::hasFormat(*Buffer))
83  Result.reset(new TextInstrProfReader(std::move(Buffer)));
84  else
85  return make_error<InstrProfError>(instrprof_error::unrecognized_format);
86 
87  // Initialize the reader and return the result.
88  if (Error E = initializeReader(*Result))
89  return std::move(E);
90 
91  return std::move(Result);
92 }
93 
95 IndexedInstrProfReader::create(const Twine &Path, const Twine &RemappingPath) {
96  // Set up the buffer to read.
97  auto BufferOrError = setupMemoryBuffer(Path);
98  if (Error E = BufferOrError.takeError())
99  return std::move(E);
100 
101  // Set up the remapping buffer if requested.
102  std::unique_ptr<MemoryBuffer> RemappingBuffer;
103  std::string RemappingPathStr = RemappingPath.str();
104  if (!RemappingPathStr.empty()) {
105  auto RemappingBufferOrError = setupMemoryBuffer(RemappingPathStr);
106  if (Error E = RemappingBufferOrError.takeError())
107  return std::move(E);
108  RemappingBuffer = std::move(RemappingBufferOrError.get());
109  }
110 
111  return IndexedInstrProfReader::create(std::move(BufferOrError.get()),
112  std::move(RemappingBuffer));
113 }
114 
116 IndexedInstrProfReader::create(std::unique_ptr<MemoryBuffer> Buffer,
117  std::unique_ptr<MemoryBuffer> RemappingBuffer) {
118  if (uint64_t(Buffer->getBufferSize()) > std::numeric_limits<uint64_t>::max())
119  return make_error<InstrProfError>(instrprof_error::too_large);
120 
121  // Create the reader.
122  if (!IndexedInstrProfReader::hasFormat(*Buffer))
123  return make_error<InstrProfError>(instrprof_error::bad_magic);
124  auto Result = std::make_unique<IndexedInstrProfReader>(
125  std::move(Buffer), std::move(RemappingBuffer));
126 
127  // Initialize the reader and return the result.
128  if (Error E = initializeReader(*Result))
129  return std::move(E);
130 
131  return std::move(Result);
132 }
133 
134 void InstrProfIterator::Increment() {
135  if (auto E = Reader->readNextRecord(Record)) {
136  // Handle errors in the reader.
138  *this = InstrProfIterator();
139  }
140 }
141 
143  // Verify that this really looks like plain ASCII text by checking a
144  // 'reasonable' number of characters (up to profile magic size).
145  size_t count = std::min(Buffer.getBufferSize(), sizeof(uint64_t));
146  StringRef buffer = Buffer.getBufferStart();
147  return count == 0 ||
148  std::all_of(buffer.begin(), buffer.begin() + count,
149  [](char c) { return isPrint(c) || isSpace(c); });
150 }
151 
152 // Read the profile variant flag from the header: ":FE" means this is a FE
153 // generated profile. ":IR" means this is an IR level profile. Other strings
154 // with a leading ':' will be reported an error format.
156  Symtab.reset(new InstrProfSymtab());
157  bool IsIRInstr = false;
158  bool IsEntryFirst = false;
159  bool IsCS = false;
160 
161  while (Line->startswith(":")) {
162  StringRef Str = Line->substr(1);
163  if (Str.equals_insensitive("ir"))
164  IsIRInstr = true;
165  else if (Str.equals_insensitive("fe"))
166  IsIRInstr = false;
167  else if (Str.equals_insensitive("csir")) {
168  IsIRInstr = true;
169  IsCS = true;
170  } else if (Str.equals_insensitive("entry_first"))
171  IsEntryFirst = true;
172  else if (Str.equals_insensitive("not_entry_first"))
173  IsEntryFirst = false;
174  else
176  ++Line;
177  }
178  IsIRLevelProfile = IsIRInstr;
179  InstrEntryBBEnabled = IsEntryFirst;
180  HasCSIRLevelProfile = IsCS;
181  return success();
182 }
183 
184 Error
185 TextInstrProfReader::readValueProfileData(InstrProfRecord &Record) {
186 
187 #define CHECK_LINE_END(Line) \
188  if (Line.is_at_end()) \
189  return error(instrprof_error::truncated);
190 #define READ_NUM(Str, Dst) \
191  if ((Str).getAsInteger(10, (Dst))) \
192  return error(instrprof_error::malformed);
193 #define VP_READ_ADVANCE(Val) \
194  CHECK_LINE_END(Line); \
195  uint32_t Val; \
196  READ_NUM((*Line), (Val)); \
197  Line++;
198 
199  if (Line.is_at_end())
200  return success();
201 
202  uint32_t NumValueKinds;
203  if (Line->getAsInteger(10, NumValueKinds)) {
204  // No value profile data
205  return success();
206  }
207  if (NumValueKinds == 0 || NumValueKinds > IPVK_Last + 1)
209  "number of value kinds is invalid");
210  Line++;
211 
212  for (uint32_t VK = 0; VK < NumValueKinds; VK++) {
214  if (ValueKind > IPVK_Last)
215  return error(instrprof_error::malformed, "value kind is invalid");
216  ;
217  VP_READ_ADVANCE(NumValueSites);
218  if (!NumValueSites)
219  continue;
220 
221  Record.reserveSites(VK, NumValueSites);
222  for (uint32_t S = 0; S < NumValueSites; S++) {
223  VP_READ_ADVANCE(NumValueData);
224 
225  std::vector<InstrProfValueData> CurrentValues;
226  for (uint32_t V = 0; V < NumValueData; V++) {
227  CHECK_LINE_END(Line);
228  std::pair<StringRef, StringRef> VD = Line->rsplit(':');
229  uint64_t TakenCount, Value;
230  if (ValueKind == IPVK_IndirectCallTarget) {
231  if (InstrProfSymtab::isExternalSymbol(VD.first)) {
232  Value = 0;
233  } else {
234  if (Error E = Symtab->addFuncName(VD.first))
235  return E;
237  }
238  } else {
239  READ_NUM(VD.first, Value);
240  }
241  READ_NUM(VD.second, TakenCount);
242  CurrentValues.push_back({Value, TakenCount});
243  Line++;
244  }
245  Record.addValueData(ValueKind, S, CurrentValues.data(), NumValueData,
246  nullptr);
247  }
248  }
249  return success();
250 
251 #undef CHECK_LINE_END
252 #undef READ_NUM
253 #undef VP_READ_ADVANCE
254 }
255 
257  // Skip empty lines and comments.
258  while (!Line.is_at_end() && (Line->empty() || Line->startswith("#")))
259  ++Line;
260  // If we hit EOF while looking for a name, we're done.
261  if (Line.is_at_end()) {
262  return error(instrprof_error::eof);
263  }
264 
265  // Read the function name.
266  Record.Name = *Line++;
267  if (Error E = Symtab->addFuncName(Record.Name))
268  return error(std::move(E));
269 
270  // Read the function hash.
271  if (Line.is_at_end())
273  if ((Line++)->getAsInteger(0, Record.Hash))
275  "function hash is not a valid integer");
276 
277  // Read the number of counters.
278  uint64_t NumCounters;
279  if (Line.is_at_end())
281  if ((Line++)->getAsInteger(10, NumCounters))
283  "number of counters is not a valid integer");
284  if (NumCounters == 0)
285  return error(instrprof_error::malformed, "number of counters is zero");
286 
287  // Read each counter and fill our internal storage with the values.
288  Record.Clear();
289  Record.Counts.reserve(NumCounters);
290  for (uint64_t I = 0; I < NumCounters; ++I) {
291  if (Line.is_at_end())
293  uint64_t Count;
294  if ((Line++)->getAsInteger(10, Count))
295  return error(instrprof_error::malformed, "count is invalid");
296  Record.Counts.push_back(Count);
297  }
298 
299  // Check if value profile data exists and read it if so.
300  if (Error E = readValueProfileData(Record))
301  return error(std::move(E));
302 
303  return success();
304 }
305 
306 template <class IntPtrT>
308  if (DataBuffer.getBufferSize() < sizeof(uint64_t))
309  return false;
310  uint64_t Magic =
311  *reinterpret_cast<const uint64_t *>(DataBuffer.getBufferStart());
312  return RawInstrProf::getMagic<IntPtrT>() == Magic ||
313  sys::getSwappedBytes(RawInstrProf::getMagic<IntPtrT>()) == Magic;
314 }
315 
316 template <class IntPtrT>
318  if (!hasFormat(*DataBuffer))
320  if (DataBuffer->getBufferSize() < sizeof(RawInstrProf::Header))
322  auto *Header = reinterpret_cast<const RawInstrProf::Header *>(
323  DataBuffer->getBufferStart());
324  ShouldSwapBytes = Header->Magic != RawInstrProf::getMagic<IntPtrT>();
325  return readHeader(*Header);
326 }
327 
328 template <class IntPtrT>
329 Error RawInstrProfReader<IntPtrT>::readNextHeader(const char *CurrentPos) {
330  const char *End = DataBuffer->getBufferEnd();
331  // Skip zero padding between profiles.
332  while (CurrentPos != End && *CurrentPos == 0)
333  ++CurrentPos;
334  // If there's nothing left, we're done.
335  if (CurrentPos == End)
336  return make_error<InstrProfError>(instrprof_error::eof);
337  // If there isn't enough space for another header, this is probably just
338  // garbage at the end of the file.
339  if (CurrentPos + sizeof(RawInstrProf::Header) > End)
340  return make_error<InstrProfError>(instrprof_error::malformed,
341  "not enough space for another header");
342  // The writer ensures each profile is padded to start at an aligned address.
343  if (reinterpret_cast<size_t>(CurrentPos) % alignof(uint64_t))
344  return make_error<InstrProfError>(instrprof_error::malformed,
345  "insufficient padding");
346  // The magic should have the same byte order as in the previous header.
347  uint64_t Magic = *reinterpret_cast<const uint64_t *>(CurrentPos);
348  if (Magic != swap(RawInstrProf::getMagic<IntPtrT>()))
349  return make_error<InstrProfError>(instrprof_error::bad_magic);
350 
351  // There's another profile to read, so we need to process the header.
352  auto *Header = reinterpret_cast<const RawInstrProf::Header *>(CurrentPos);
353  return readHeader(*Header);
354 }
355 
356 template <class IntPtrT>
358  if (Error E = Symtab.create(StringRef(NamesStart, NamesEnd - NamesStart)))
359  return error(std::move(E));
360  for (const RawInstrProf::ProfileData<IntPtrT> *I = Data; I != DataEnd; ++I) {
361  const IntPtrT FPtr = swap(I->FunctionPointer);
362  if (!FPtr)
363  continue;
364  Symtab.mapAddress(FPtr, I->NameRef);
365  }
366  return success();
367 }
368 
369 template <class IntPtrT>
371  const RawInstrProf::Header &Header) {
372  Version = swap(Header.Version);
373  if (GET_VERSION(Version) != RawInstrProf::Version)
375  if (useDebugInfoCorrelate() && !Correlator)
377  if (!useDebugInfoCorrelate() && Correlator)
379 
380  BinaryIdsSize = swap(Header.BinaryIdsSize);
381  if (BinaryIdsSize % sizeof(uint64_t))
383 
384  CountersDelta = swap(Header.CountersDelta);
385  NamesDelta = swap(Header.NamesDelta);
386  auto NumData = swap(Header.NumData);
387  auto PaddingBytesBeforeCounters = swap(Header.PaddingBytesBeforeCounters);
388  auto CountersSize = swap(Header.NumCounters) * getCounterTypeSize();
389  auto PaddingBytesAfterCounters = swap(Header.PaddingBytesAfterCounters);
390  auto NamesSize = swap(Header.NamesSize);
391  ValueKindLast = swap(Header.ValueKindLast);
392 
393  auto DataSize = NumData * sizeof(RawInstrProf::ProfileData<IntPtrT>);
394  auto PaddingSize = getNumPaddingBytes(NamesSize);
395 
396  // Profile data starts after profile header and binary ids if exist.
397  ptrdiff_t DataOffset = sizeof(RawInstrProf::Header) + BinaryIdsSize;
398  ptrdiff_t CountersOffset = DataOffset + DataSize + PaddingBytesBeforeCounters;
399  ptrdiff_t NamesOffset =
400  CountersOffset + CountersSize + PaddingBytesAfterCounters;
401  ptrdiff_t ValueDataOffset = NamesOffset + NamesSize + PaddingSize;
402 
403  auto *Start = reinterpret_cast<const char *>(&Header);
404  if (Start + ValueDataOffset > DataBuffer->getBufferEnd())
406 
407  if (Correlator) {
408  // These sizes in the raw file are zero because we constructed them in the
409  // Correlator.
410  assert(DataSize == 0 && NamesSize == 0);
411  assert(CountersDelta == 0 && NamesDelta == 0);
412  Data = Correlator->getDataPointer();
413  DataEnd = Data + Correlator->getDataSize();
414  NamesStart = Correlator->getCompressedNamesPointer();
415  NamesEnd = NamesStart + Correlator->getCompressedNamesSize();
416  } else {
417  Data = reinterpret_cast<const RawInstrProf::ProfileData<IntPtrT> *>(
418  Start + DataOffset);
419  DataEnd = Data + NumData;
420  NamesStart = Start + NamesOffset;
421  NamesEnd = NamesStart + NamesSize;
422  }
423 
424  // Binary ids start just after the header.
425  BinaryIdsStart =
426  reinterpret_cast<const uint8_t *>(&Header) + sizeof(RawInstrProf::Header);
427  CountersStart = Start + CountersOffset;
428  CountersEnd = CountersStart + CountersSize;
429  ValueDataStart = reinterpret_cast<const uint8_t *>(Start + ValueDataOffset);
430 
431  const uint8_t *BufferEnd = (const uint8_t *)DataBuffer->getBufferEnd();
432  if (BinaryIdsStart + BinaryIdsSize > BufferEnd)
434 
435  std::unique_ptr<InstrProfSymtab> NewSymtab = std::make_unique<InstrProfSymtab>();
436  if (Error E = createSymtab(*NewSymtab.get()))
437  return E;
438 
439  Symtab = std::move(NewSymtab);
440  return success();
441 }
442 
443 template <class IntPtrT>
445  Record.Name = getName(Data->NameRef);
446  return success();
447 }
448 
449 template <class IntPtrT>
451  Record.Hash = swap(Data->FuncHash);
452  return success();
453 }
454 
455 template <class IntPtrT>
458  uint32_t NumCounters = swap(Data->NumCounters);
459  if (NumCounters == 0)
460  return error(instrprof_error::malformed, "number of counters is zero");
461 
462  ptrdiff_t CounterBaseOffset = swap(Data->CounterPtr) - CountersDelta;
463  if (CounterBaseOffset < 0)
464  return error(
466  ("counter offset " + Twine(CounterBaseOffset) + " is negative").str());
467 
468  if (CounterBaseOffset >= CountersEnd - CountersStart)
470  ("counter offset " + Twine(CounterBaseOffset) +
471  " is greater than the maximum counter offset " +
472  Twine(CountersEnd - CountersStart - 1))
473  .str());
474 
475  uint64_t MaxNumCounters =
476  (CountersEnd - (CountersStart + CounterBaseOffset)) /
477  getCounterTypeSize();
478  if (NumCounters > MaxNumCounters)
480  ("number of counters " + Twine(NumCounters) +
481  " is greater than the maximum number of counters " +
482  Twine(MaxNumCounters))
483  .str());
484 
485  Record.Counts.clear();
486  Record.Counts.reserve(NumCounters);
487  for (uint32_t I = 0; I < NumCounters; I++) {
488  const auto *CounterValue = reinterpret_cast<const uint64_t *>(
489  CountersStart + CounterBaseOffset + I * getCounterTypeSize());
490  Record.Counts.push_back(swap(*CounterValue));
491  }
492 
493  return success();
494 }
495 
496 template <class IntPtrT>
499  Record.clearValueData();
500  CurValueDataSize = 0;
501  // Need to match the logic in value profile dumper code in compiler-rt:
502  uint32_t NumValueKinds = 0;
503  for (uint32_t I = 0; I < IPVK_Last + 1; I++)
504  NumValueKinds += (Data->NumValueSites[I] != 0);
505 
506  if (!NumValueKinds)
507  return success();
508 
510  ValueProfData::getValueProfData(
511  ValueDataStart, (const unsigned char *)DataBuffer->getBufferEnd(),
512  getDataEndianness());
513 
514  if (Error E = VDataPtrOrErr.takeError())
515  return E;
516 
517  // Note that besides deserialization, this also performs the conversion for
518  // indirect call targets. The function pointers from the raw profile are
519  // remapped into function name hashes.
520  VDataPtrOrErr.get()->deserializeTo(Record, Symtab.get());
521  CurValueDataSize = VDataPtrOrErr.get()->getSize();
522  return success();
523 }
524 
525 template <class IntPtrT>
527  if (atEnd())
528  // At this point, ValueDataStart field points to the next header.
529  if (Error E = readNextHeader(getNextHeaderPos()))
530  return error(std::move(E));
531 
532  // Read name ad set it in Record.
533  if (Error E = readName(Record))
534  return error(std::move(E));
535 
536  // Read FuncHash and set it in Record.
537  if (Error E = readFuncHash(Record))
538  return error(std::move(E));
539 
540  // Read raw counts and set Record.
541  if (Error E = readRawCounts(Record))
542  return error(std::move(E));
543 
544  // Read value data and set Record.
545  if (Error E = readValueProfilingData(Record))
546  return error(std::move(E));
547 
548  // Iterate.
549  advanceData();
550  return success();
551 }
552 
553 static size_t RoundUp(size_t size, size_t align) {
554  return (size + align - 1) & ~(align - 1);
555 }
556 
557 template <class IntPtrT>
559  if (BinaryIdsSize == 0)
560  return success();
561 
562  OS << "Binary IDs: \n";
563  const uint8_t *BI = BinaryIdsStart;
564  const uint8_t *BIEnd = BinaryIdsStart + BinaryIdsSize;
565  while (BI < BIEnd) {
566  size_t Remaining = BIEnd - BI;
567 
568  // There should be enough left to read the binary ID size field.
569  if (Remaining < sizeof(uint64_t))
570  return make_error<InstrProfError>(
572  "not enough data to read binary id length");
573 
574  uint64_t BinaryIdLen = swap(*reinterpret_cast<const uint64_t *>(BI));
575 
576  // There should be enough left to read the binary ID size field, and the
577  // binary ID.
578  if (Remaining < sizeof(BinaryIdLen) + BinaryIdLen)
579  return make_error<InstrProfError>(
580  instrprof_error::malformed, "not enough data to read binary id data");
581 
582  // Increment by binary id length data type size.
583  BI += sizeof(BinaryIdLen);
584  if (BI > (const uint8_t *)DataBuffer->getBufferEnd())
585  return make_error<InstrProfError>(
587  "binary id that is read is bigger than buffer size");
588 
589  for (uint64_t I = 0; I < BinaryIdLen; I++)
590  OS << format("%02x", BI[I]);
591  OS << "\n";
592 
593  // Increment by binary id data length, rounded to the next 8 bytes. This
594  // accounts for the zero-padding after each build ID.
595  BI += RoundUp(BinaryIdLen, sizeof(uint64_t));
596  if (BI > (const uint8_t *)DataBuffer->getBufferEnd())
597  return make_error<InstrProfError>(instrprof_error::malformed);
598  }
599 
600  return success();
601 }
602 
603 namespace llvm {
604 
605 template class RawInstrProfReader<uint32_t>;
606 template class RawInstrProfReader<uint64_t>;
607 
608 } // end namespace llvm
609 
612  return IndexedInstrProf::ComputeHash(HashType, K);
613 }
614 
617 
619  const unsigned char *&D, const unsigned char *const End) {
621  ValueProfData::getValueProfData(D, End, ValueProfDataEndianness);
622 
623  if (VDataPtrOrErr.takeError())
624  return false;
625 
626  VDataPtrOrErr.get()->deserializeTo(DataBuffer.back(), nullptr);
627  D += VDataPtrOrErr.get()->TotalSize;
628 
629  return true;
630 }
631 
633  offset_type N) {
634  using namespace support;
635 
636  // Check if the data is corrupt. If so, don't try to read it.
637  if (N % sizeof(uint64_t))
638  return data_type();
639 
640  DataBuffer.clear();
641  std::vector<uint64_t> CounterBuffer;
642 
643  const unsigned char *End = D + N;
644  while (D < End) {
645  // Read hash.
646  if (D + sizeof(uint64_t) >= End)
647  return data_type();
648  uint64_t Hash = endian::readNext<uint64_t, little, unaligned>(D);
649 
650  // Initialize number of counters for GET_VERSION(FormatVersion) == 1.
651  uint64_t CountsSize = N / sizeof(uint64_t) - 1;
652  // If format version is different then read the number of counters.
653  if (GET_VERSION(FormatVersion) != IndexedInstrProf::ProfVersion::Version1) {
654  if (D + sizeof(uint64_t) > End)
655  return data_type();
656  CountsSize = endian::readNext<uint64_t, little, unaligned>(D);
657  }
658  // Read counter values.
659  if (D + CountsSize * sizeof(uint64_t) > End)
660  return data_type();
661 
662  CounterBuffer.clear();
663  CounterBuffer.reserve(CountsSize);
664  for (uint64_t J = 0; J < CountsSize; ++J)
665  CounterBuffer.push_back(endian::readNext<uint64_t, little, unaligned>(D));
666 
667  DataBuffer.emplace_back(K, Hash, std::move(CounterBuffer));
668 
669  // Read value profiling data.
670  if (GET_VERSION(FormatVersion) > IndexedInstrProf::ProfVersion::Version2 &&
671  !readValueProfilingData(D, End)) {
672  DataBuffer.clear();
673  return data_type();
674  }
675  }
676  return DataBuffer;
677 }
678 
679 template <typename HashTableImpl>
682  auto Iter = HashTable->find(FuncName);
683  if (Iter == HashTable->end())
684  return make_error<InstrProfError>(instrprof_error::unknown_function);
685 
686  Data = (*Iter);
687  if (Data.empty())
688  return make_error<InstrProfError>(instrprof_error::malformed,
689  "profile data is empty");
690 
691  return Error::success();
692 }
693 
694 template <typename HashTableImpl>
697  if (atEnd())
698  return make_error<InstrProfError>(instrprof_error::eof);
699 
700  Data = *RecordIterator;
701 
702  if (Data.empty())
703  return make_error<InstrProfError>(instrprof_error::malformed,
704  "profile data is empty");
705 
706  return Error::success();
707 }
708 
709 template <typename HashTableImpl>
711  const unsigned char *Buckets, const unsigned char *const Payload,
712  const unsigned char *const Base, IndexedInstrProf::HashT HashType,
713  uint64_t Version) {
714  FormatVersion = Version;
715  HashTable.reset(HashTableImpl::Create(
716  Buckets, Payload, Base,
717  typename HashTableImpl::InfoType(HashType, Version)));
718  RecordIterator = HashTable->data_begin();
719 }
720 
721 namespace {
722 /// A remapper that does not apply any remappings.
723 class InstrProfReaderNullRemapper : public InstrProfReaderRemapper {
725 
726 public:
727  InstrProfReaderNullRemapper(InstrProfReaderIndexBase &Underlying)
728  : Underlying(Underlying) {}
729 
730  Error getRecords(StringRef FuncName,
732  return Underlying.getRecords(FuncName, Data);
733  }
734 };
735 } // namespace
736 
737 /// A remapper that applies remappings based on a symbol remapping file.
738 template <typename HashTableImpl>
740  : public InstrProfReaderRemapper {
741 public:
743  std::unique_ptr<MemoryBuffer> RemapBuffer,
745  : RemapBuffer(std::move(RemapBuffer)), Underlying(Underlying) {
746  }
747 
748  /// Extract the original function name from a PGO function name.
750  // We can have multiple :-separated pieces; there can be pieces both
751  // before and after the mangled name. Find the first part that starts
752  // with '_Z'; we'll assume that's the mangled name we want.
753  std::pair<StringRef, StringRef> Parts = {StringRef(), Name};
754  while (true) {
755  Parts = Parts.second.split(':');
756  if (Parts.first.startswith("_Z"))
757  return Parts.first;
758  if (Parts.second.empty())
759  return Name;
760  }
761  }
762 
763  /// Given a mangled name extracted from a PGO function name, and a new
764  /// form for that mangled name, reconstitute the name.
765  static void reconstituteName(StringRef OrigName, StringRef ExtractedName,
766  StringRef Replacement,
767  SmallVectorImpl<char> &Out) {
768  Out.reserve(OrigName.size() + Replacement.size() - ExtractedName.size());
769  Out.insert(Out.end(), OrigName.begin(), ExtractedName.begin());
770  Out.insert(Out.end(), Replacement.begin(), Replacement.end());
771  Out.insert(Out.end(), ExtractedName.end(), OrigName.end());
772  }
773 
775  if (Error E = Remappings.read(*RemapBuffer))
776  return E;
777  for (StringRef Name : Underlying.HashTable->keys()) {
778  StringRef RealName = extractName(Name);
779  if (auto Key = Remappings.insert(RealName)) {
780  // FIXME: We could theoretically map the same equivalence class to
781  // multiple names in the profile data. If that happens, we should
782  // return NamedInstrProfRecords from all of them.
783  MappedNames.insert({Key, RealName});
784  }
785  }
786  return Error::success();
787  }
788 
791  StringRef RealName = extractName(FuncName);
792  if (auto Key = Remappings.lookup(RealName)) {
793  StringRef Remapped = MappedNames.lookup(Key);
794  if (!Remapped.empty()) {
795  if (RealName.begin() == FuncName.begin() &&
796  RealName.end() == FuncName.end())
797  FuncName = Remapped;
798  else {
799  // Try rebuilding the name from the given remapping.
800  SmallString<256> Reconstituted;
801  reconstituteName(FuncName, RealName, Remapped, Reconstituted);
802  Error E = Underlying.getRecords(Reconstituted, Data);
803  if (!E)
804  return E;
805 
806  // If we failed because the name doesn't exist, fall back to asking
807  // about the original name.
808  if (Error Unhandled = handleErrors(
809  std::move(E), [](std::unique_ptr<InstrProfError> Err) {
810  return Err->get() == instrprof_error::unknown_function
811  ? Error::success()
812  : Error(std::move(Err));
813  }))
814  return Unhandled;
815  }
816  }
817  }
818  return Underlying.getRecords(FuncName, Data);
819  }
820 
821 private:
822  /// The memory buffer containing the remapping configuration. Remappings
823  /// holds pointers into this buffer.
824  std::unique_ptr<MemoryBuffer> RemapBuffer;
825 
826  /// The mangling remapper.
827  SymbolRemappingReader Remappings;
828 
829  /// Mapping from mangled name keys to the name used for the key in the
830  /// profile data.
831  /// FIXME: Can we store a location within the on-disk hash table instead of
832  /// redoing lookup?
834 
835  /// The real profile data reader.
837 };
838 
840  using namespace support;
841 
842  if (DataBuffer.getBufferSize() < 8)
843  return false;
844  uint64_t Magic =
845  endian::read<uint64_t, little, aligned>(DataBuffer.getBufferStart());
846  // Verify that it's magical.
847  return Magic == IndexedInstrProf::Magic;
848 }
849 
850 const unsigned char *
851 IndexedInstrProfReader::readSummary(IndexedInstrProf::ProfVersion Version,
852  const unsigned char *Cur, bool UseCS) {
853  using namespace IndexedInstrProf;
854  using namespace support;
855 
857  const IndexedInstrProf::Summary *SummaryInLE =
858  reinterpret_cast<const IndexedInstrProf::Summary *>(Cur);
859  uint64_t NFields =
860  endian::byte_swap<uint64_t, little>(SummaryInLE->NumSummaryFields);
861  uint64_t NEntries =
862  endian::byte_swap<uint64_t, little>(SummaryInLE->NumCutoffEntries);
863  uint32_t SummarySize =
864  IndexedInstrProf::Summary::getSize(NFields, NEntries);
865  std::unique_ptr<IndexedInstrProf::Summary> SummaryData =
866  IndexedInstrProf::allocSummary(SummarySize);
867 
868  const uint64_t *Src = reinterpret_cast<const uint64_t *>(SummaryInLE);
869  uint64_t *Dst = reinterpret_cast<uint64_t *>(SummaryData.get());
870  for (unsigned I = 0; I < SummarySize / sizeof(uint64_t); I++)
871  Dst[I] = endian::byte_swap<uint64_t, little>(Src[I]);
872 
873  SummaryEntryVector DetailedSummary;
874  for (unsigned I = 0; I < SummaryData->NumCutoffEntries; I++) {
875  const IndexedInstrProf::Summary::Entry &Ent = SummaryData->getEntry(I);
876  DetailedSummary.emplace_back((uint32_t)Ent.Cutoff, Ent.MinBlockCount,
877  Ent.NumBlocks);
878  }
879  std::unique_ptr<llvm::ProfileSummary> &Summary =
880  UseCS ? this->CS_Summary : this->Summary;
881 
882  // initialize InstrProfSummary using the SummaryData from disk.
883  Summary = std::make_unique<ProfileSummary>(
885  DetailedSummary, SummaryData->get(Summary::TotalBlockCount),
886  SummaryData->get(Summary::MaxBlockCount),
887  SummaryData->get(Summary::MaxInternalBlockCount),
888  SummaryData->get(Summary::MaxFunctionCount),
889  SummaryData->get(Summary::TotalNumBlocks),
890  SummaryData->get(Summary::TotalNumFunctions));
891  return Cur + SummarySize;
892  } else {
893  // The older versions do not support a profile summary. This just computes
894  // an empty summary, which will not result in accurate hot/cold detection.
895  // We would need to call addRecord for all NamedInstrProfRecords to get the
896  // correct summary. However, this version is old (prior to early 2016) and
897  // has not been supporting an accurate summary for several years.
899  Summary = Builder.getSummary();
900  return Cur;
901  }
902 }
903 
905  using namespace support;
906 
907  const unsigned char *Start =
908  (const unsigned char *)DataBuffer->getBufferStart();
909  const unsigned char *Cur = Start;
910  if ((const unsigned char *)DataBuffer->getBufferEnd() - Cur < 24)
912 
913  auto *Header = reinterpret_cast<const IndexedInstrProf::Header *>(Cur);
914  Cur += sizeof(IndexedInstrProf::Header);
915 
916  // Check the magic number.
917  uint64_t Magic = endian::byte_swap<uint64_t, little>(Header->Magic);
920 
921  // Read the version.
922  uint64_t FormatVersion = endian::byte_swap<uint64_t, little>(Header->Version);
923  if (GET_VERSION(FormatVersion) >
926 
927  Cur = readSummary((IndexedInstrProf::ProfVersion)FormatVersion, Cur,
928  /* UseCS */ false);
929  if (FormatVersion & VARIANT_MASK_CSIR_PROF)
930  Cur = readSummary((IndexedInstrProf::ProfVersion)FormatVersion, Cur,
931  /* UseCS */ true);
932 
933  // Read the hash type and start offset.
934  IndexedInstrProf::HashT HashType = static_cast<IndexedInstrProf::HashT>(
935  endian::byte_swap<uint64_t, little>(Header->HashType));
936  if (HashType > IndexedInstrProf::HashT::Last)
938 
939  uint64_t HashOffset = endian::byte_swap<uint64_t, little>(Header->HashOffset);
940 
941  // The rest of the file is an on disk hash table.
942  auto IndexPtr =
943  std::make_unique<InstrProfReaderIndex<OnDiskHashTableImplV3>>(
944  Start + HashOffset, Cur, Start, HashType, FormatVersion);
945 
946  // Load the remapping table now if requested.
947  if (RemappingBuffer) {
948  Remapper = std::make_unique<
950  std::move(RemappingBuffer), *IndexPtr);
951  if (Error E = Remapper->populateRemappings())
952  return E;
953  } else {
954  Remapper = std::make_unique<InstrProfReaderNullRemapper>(*IndexPtr);
955  }
956  Index = std::move(IndexPtr);
957 
958  return success();
959 }
960 
962  if (Symtab.get())
963  return *Symtab.get();
964 
965  std::unique_ptr<InstrProfSymtab> NewSymtab = std::make_unique<InstrProfSymtab>();
966  if (Error E = Index->populateSymtab(*NewSymtab.get())) {
968  }
969 
970  Symtab = std::move(NewSymtab);
971  return *Symtab.get();
972 }
973 
976  uint64_t FuncHash) {
978  Error Err = Remapper->getRecords(FuncName, Data);
979  if (Err)
980  return std::move(Err);
981  // Found it. Look for counters with the right hash.
982  for (const NamedInstrProfRecord &I : Data) {
983  // Check for a match and fill the vector if there is one.
984  if (I.Hash == FuncHash)
985  return std::move(I);
986  }
988 }
989 
991  uint64_t FuncHash,
992  std::vector<uint64_t> &Counts) {
993  Expected<InstrProfRecord> Record = getInstrProfRecord(FuncName, FuncHash);
994  if (Error E = Record.takeError())
995  return error(std::move(E));
996 
997  Counts = Record.get().Counts;
998  return success();
999 }
1000 
1003 
1004  Error E = Index->getRecords(Data);
1005  if (E)
1006  return error(std::move(E));
1007 
1008  Record = Data[RecordIndex++];
1009  if (RecordIndex >= Data.size()) {
1010  Index->advanceToNextKey();
1011  RecordIndex = 0;
1012  }
1013  return success();
1014 }
1015 
1017  uint64_t NumFuncs = 0;
1018  for (const auto &Func : *this) {
1019  if (isIRLevelProfile()) {
1020  bool FuncIsCS = NamedInstrProfRecord::hasCSFlagInHash(Func.Hash);
1021  if (FuncIsCS != IsCS)
1022  continue;
1023  }
1024  Func.accumulateCounts(Sum);
1025  ++NumFuncs;
1026  }
1027  Sum.NumEntries = NumFuncs;
1028 }
llvm::coverage::coveragemap_error::success
@ success
MemoryBuffer.h
llvm::IndexedInstrProfReader::getSymtab
InstrProfSymtab & getSymtab() override
Return the PGO symtab.
Definition: InstrProfReader.cpp:961
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:285
llvm::instrprof_error::bad_header
@ bad_header
llvm::RawInstrProfReader
Reader for the raw instrprof binary format from runtime.
Definition: InstrProfReader.h:220
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:42
llvm::InstrProfReader::success
Error success()
Clear the current error and return a successful one.
Definition: InstrProfReader.h:139
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::IndexedInstrProf::ProfVersion
ProfVersion
Definition: InstrProf.h:972
llvm::handleErrors
Error handleErrors(Error E, HandlerTs &&... Hs)
Pass the ErrorInfo(s) contained in E to their respective handlers.
Definition: Error.h:945
offset_type
InstrProfLookupTrait::offset_type offset_type
Definition: InstrProfReader.cpp:616
llvm::IndexedInstrProfReader::hasFormat
static bool hasFormat(const MemoryBuffer &DataBuffer)
Return true if the given buffer is in an indexed instrprof format.
Definition: InstrProfReader.cpp:839
llvm::InstrProfLookupTrait::hash_value_type
uint64_t hash_value_type
Definition: InstrProfReader.h:367
ProfileSummary.h
StringRef.h
llvm::IndexedInstrProf::Summary::Entry::NumBlocks
uint64_t NumBlocks
Number of blocks >= the minumum execution count.
Definition: InstrProf.h:1023
llvm::InstrProfReader::readNextRecord
virtual Error readNextRecord(NamedInstrProfRecord &Record)=0
Read a single record.
llvm::IndexedInstrProf::ComputeHash
uint64_t ComputeHash(StringRef K)
Definition: InstrProf.h:1003
llvm::InstrProfReaderIndex::InstrProfReaderIndex
InstrProfReaderIndex(const unsigned char *Buckets, const unsigned char *const Payload, const unsigned char *const Base, IndexedInstrProf::HashT HashType, uint64_t Version)
Definition: InstrProfReader.cpp:710
llvm::RawInstrProfReader64
RawInstrProfReader< uint64_t > RawInstrProfReader64
Definition: InstrProfReader.h:340
llvm::InstrProfSymtab::create
Error create(object::SectionRef &Section)
Create InstrProfSymtab from an object file section which contains function PGO names.
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:331
Error.h
SwapByteOrder.h
llvm::IndexedInstrProf::Summary::Entry
Definition: InstrProf.h:1019
llvm::InstrProfLookupTrait::data_type
ArrayRef< NamedInstrProfRecord > data_type
Definition: InstrProfReader.h:363
llvm::BitmaskEnumDetail::Underlying
std::underlying_type_t< E > Underlying(E Val)
Check that Val is in range for E, and return Val cast to E's underlying type.
Definition: BitmaskEnum.h:90
DenseMap.h
llvm::StringRef::rsplit
LLVM_NODISCARD std::pair< StringRef, StringRef > rsplit(StringRef Separator) const
Split into two substrings around the last occurrence of a separator string.
Definition: StringRef.h:781
llvm::InstrProfLookupTrait::ComputeHash
hash_value_type ComputeHash(StringRef K)
Definition: InstrProfReader.cpp:611
error
#define error(X)
Definition: SymbolRecordMapping.cpp:14
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
STLExtras.h
ProfileCommon.h
llvm::consumeError
void consumeError(Error Err)
Consume a Error without doing anything.
Definition: Error.h:1045
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::MemoryBuffer
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
llvm::InstrProfRecord
Profiling information for a single function.
Definition: InstrProf.h:699
llvm::instrprof_error::unexpected_debug_info_for_correlation
@ unexpected_debug_info_for_correlation
llvm::StringRef::substr
LLVM_NODISCARD StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:610
llvm::TextInstrProfReader::readHeader
Error readHeader() override
Read the header.
Definition: InstrProfReader.cpp:155
llvm::IndexedInstrProf::Version4
@ Version4
Definition: InstrProf.h:988
llvm::AMDGPU::HSAMD::ValueKind
ValueKind
Value kinds.
Definition: AMDGPUMetadata.h:73
llvm::coverage::Version1
@ Version1
Definition: CoverageMapping.h:993
llvm::all_of
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1649
llvm::coverage::CurrentVersion
@ CurrentVersion
Definition: CoverageMapping.h:1009
llvm::SymbolRemappingReader
Reader for symbol remapping files.
Definition: SymbolRemappingReader.h:97
ptrdiff_t
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::MemoryBuffer::getBufferSize
size_t getBufferSize() const
Definition: MemoryBuffer.h:67
llvm::errorCodeToError
Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
Definition: Error.cpp:90
InfoType
InfoType
FunctionInfo information type that is used to encode the optional data that is associated with a Func...
Definition: FunctionInfo.cpp:21
setupMemoryBuffer
static Expected< std::unique_ptr< MemoryBuffer > > setupMemoryBuffer(const Twine &Path)
Definition: InstrProfReader.cpp:42
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::ErrorOr::getError
std::error_code getError() const
Definition: ErrorOr.h:153
llvm::InstrProfReaderItaniumRemapper::InstrProfReaderItaniumRemapper
InstrProfReaderItaniumRemapper(std::unique_ptr< MemoryBuffer > RemapBuffer, InstrProfReaderIndex< HashTableImpl > &Underlying)
Definition: InstrProfReader.cpp:742
CHECK_LINE_END
#define CHECK_LINE_END(Line)
InstrProf.h
llvm::instrprof_error::truncated
@ truncated
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::IndexedInstrProfReader::getFunctionCounts
Error getFunctionCounts(StringRef FuncName, uint64_t FuncHash, std::vector< uint64_t > &Counts)
Fill Counts with the profile data for the given function name.
Definition: InstrProfReader.cpp:990
llvm::TextInstrProfReader::readNextRecord
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
Definition: InstrProfReader.cpp:256
c
the resulting code requires compare and branches when and if the revised code is with conditional branches instead of More there is a byte word extend before each where there should be only and the condition codes are not remembered when the same two values are compared twice More LSR enhancements i8 and i32 load store addressing modes are identical int int c
Definition: README.txt:418
llvm::IndexedInstrProf::Header
Definition: InstrProf.h:1007
llvm::instrprof_error::bad_magic
@ bad_magic
llvm::instrprof_error::unsupported_version
@ unsupported_version
llvm::StringRef::getAsInteger
std::enable_if_t< std::numeric_limits< T >::is_signed, bool > getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:509
llvm::InstrProfReader::Symtab
std::unique_ptr< InstrProfSymtab > Symtab
Definition: InstrProfReader.h:119
RoundUp
static size_t RoundUp(size_t size, size_t align)
Definition: InstrProfReader.cpp:553
llvm::IndexedInstrProfReader::readHeader
Error readHeader() override
Read the file header.
Definition: InstrProfReader.cpp:904
llvm::instrprof_error::too_large
@ too_large
llvm::InstrProfError::take
static instrprof_error take(Error E)
Consume an Error and return the raw enum value contained within it.
Definition: InstrProf.h:333
llvm::SmallString< 256 >
llvm::Twine::str
std::string str() const
Return the twine contents as a std::string.
Definition: Twine.cpp:17
llvm::sys::getSwappedBytes
unsigned char getSwappedBytes(unsigned char C)
Definition: SwapByteOrder.h:103
llvm::instrprof_error::unsupported_hash_type
@ unsupported_hash_type
llvm::IndexedInstrProfReader::getInstrProfRecord
Expected< InstrProfRecord > getInstrProfRecord(StringRef FuncName, uint64_t FuncHash)
Return the NamedInstrProfRecord associated with FuncName and FuncHash.
Definition: InstrProfReader.cpp:975
llvm::InstrProfReaderItaniumRemapper::extractName
static StringRef extractName(StringRef Name)
Extract the original function name from a PGO function name.
Definition: InstrProfReader.cpp:749
InstrProfReader.h
llvm::CountSumOrPercent::NumEntries
uint64_t NumEntries
Definition: InstrProf.h:606
llvm::InstrProfReaderItaniumRemapper::getRecords
Error getRecords(StringRef FuncName, ArrayRef< NamedInstrProfRecord > &Data) override
Definition: InstrProfReader.cpp:789
SymbolRemappingReader.h
initializeReader
static Error initializeReader(InstrProfReader &Reader)
Definition: InstrProfReader.cpp:50
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:152
llvm::count
auto count(R &&Range, const E &Element)
Wrapper function around std::count to count the number of times an element Element occurs in the give...
Definition: STLExtras.h:1732
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::StringRef::end
iterator end() const
Definition: StringRef.h:129
llvm::IndexedInstrProfReader
Reader for the indexed binary instrprof format.
Definition: InstrProfReader.h:483
llvm::IndexedInstrProf::Summary::getSize
static uint32_t getSize(uint32_t NumSumFields, uint32_t NumCutoffEntries)
Definition: InstrProf.h:1056
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::DenseMap
Definition: DenseMap.h:714
ErrorOr.h
llvm::InstrProfSummaryBuilder
Definition: ProfileCommon.h:74
llvm::MemoryBuffer::getFileOrSTDIN
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFileOrSTDIN(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true)
Open the specified file as a MemoryBuffer, or open stdin if the Filename is "-".
Definition: MemoryBuffer.cpp:144
llvm::CountSumOrPercent
Definition: InstrProf.h:605
llvm::TextInstrProfReader
Reader for the simple text based instrprof format.
Definition: InstrProfReader.h:173
llvm::instrprof_error::empty_raw_profile
@ empty_raw_profile
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::line_iterator::is_at_end
bool is_at_end() const
Return true if we're an "end" iterator or have reached EOF.
Definition: LineIterator.h:63
StringExtras.h
ArrayRef.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::move
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1707
std::swap
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:840
llvm::instrprof_error::unknown_function
@ unknown_function
llvm::IndexedInstrProf::HashT::Last
@ Last
llvm::instrprof_error::unrecognized_format
@ unrecognized_format
llvm::IndexedInstrProf::allocSummary
std::unique_ptr< Summary > allocSummary(uint32_t TotalSize)
Definition: InstrProf.h:1096
llvm::Record
Definition: Record.h:1485
llvm::IndexedInstrProfReader::create
static Expected< std::unique_ptr< IndexedInstrProfReader > > create(const Twine &Path, const Twine &RemappingPath="")
Factory method to create an indexed reader.
Definition: InstrProfReader.cpp:95
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:650
llvm::size
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1630
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::InstrProfSymtab::isExternalSymbol
static bool isExternalSymbol(const StringRef &Symbol)
True if Symbol is the value used to represent external symbols.
Definition: InstrProf.h:519
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::InstrProfReaderIndex
Definition: InstrProfReader.h:426
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::IndexedInstrProf::Summary::Entry::Cutoff
uint64_t Cutoff
The required percentile of total execution count.
Definition: InstrProf.h:1020
llvm::msf::Magic
static const char Magic[]
Definition: MSFCommon.h:23
llvm::IndexedInstrProf::Magic
const uint64_t Magic
Definition: InstrProf.h:970
llvm::IndexedInstrProf::HashT
HashT
Definition: InstrProf.h:957
llvm::NamedInstrProfRecord::hasCSFlagInHash
static bool hasCSFlagInHash(uint64_t FuncHash)
Definition: InstrProf.h:868
llvm::Expected::get
reference get()
Returns a reference to the stored T value.
Definition: Error.h:569
uint32_t
llvm::instrprof_error::eof
@ eof
llvm::IndexedInstrProf::Summary::NumCutoffEntries
uint64_t NumCutoffEntries
Definition: InstrProf.h:1049
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::RawInstrProfReader::readHeader
Error readHeader() override
Read the header. Required before reading first record.
Definition: InstrProfReader.cpp:317
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::ProfileSummary::PSK_CSInstr
@ PSK_CSInstr
Definition: ProfileSummary.h:47
llvm::RawInstrProfReader::hasFormat
static bool hasFormat(const MemoryBuffer &DataBuffer)
Definition: InstrProfReader.cpp:307
llvm::instrprof_error::hash_mismatch
@ hash_mismatch
llvm::SummaryEntryVector
std::vector< ProfileSummaryEntry > SummaryEntryVector
Definition: ProfileSummary.h:43
llvm::InstrProfReaderItaniumRemapper
A remapper that applies remappings based on a symbol remapping file.
Definition: InstrProfReader.h:423
VP_READ_ADVANCE
#define VP_READ_ADVANCE(Val)
llvm::InstrProfLookupTrait::ReadData
data_type ReadData(StringRef K, const unsigned char *D, offset_type N)
Definition: InstrProfReader.cpp:632
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:156
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::MemoryBuffer::getBufferStart
const char * getBufferStart() const
Definition: MemoryBuffer.h:65
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::InstrProfSymtab
A symbol table used for function PGO name look-up with keys (such as pointers, md5hash values) to the...
Definition: InstrProf.h:421
llvm::InstrProfReader::accumulateCounts
void accumulateCounts(CountSumOrPercent &Sum, bool IsCS)
Compute the sum of counts and return in Sum.
Definition: InstrProfReader.cpp:1016
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::InstrProfReaderItaniumRemapper::reconstituteName
static void reconstituteName(StringRef OrigName, StringRef ExtractedName, StringRef Replacement, SmallVectorImpl< char > &Out)
Given a mangled name extracted from a PGO function name, and a new form for that mangled name,...
Definition: InstrProfReader.cpp:765
llvm::IndexedInstrProf::Summary
Definition: InstrProf.h:1018
READ_NUM
#define READ_NUM(Str, Dst)
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::InstrProfReaderRemapper
Name matcher supporting fuzzy matching of symbol names to names in profiles.
Definition: InstrProfReader.h:474
llvm::InstrProfReader::create
static Expected< std::unique_ptr< InstrProfReader > > create(const Twine &Path, const InstrProfCorrelator *Correlator=nullptr)
Factory method to create an appropriately typed reader for the given instrprof file.
Definition: InstrProfReader.cpp:55
llvm::InstrProfReader::readHeader
virtual Error readHeader()=0
Read the header. Required before reading first record.
llvm::RawInstrProfReader::readNextRecord
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
Definition: InstrProfReader.cpp:526
llvm::InstrProfReaderIndexBase
Definition: InstrProfReader.h:399
llvm::RawInstrProf::ProfileData
Definition: InstrProf.h:1133
llvm::IndexedInstrProfReader::readNextRecord
Error readNextRecord(NamedInstrProfRecord &Record) override
Read a single record.
Definition: InstrProfReader.cpp:1001
llvm::Expected::takeError
Error takeError()
Take ownership of the stored error.
Definition: Error.h:599
llvm::RawInstrProfReader::printBinaryIds
Error printBinaryIds(raw_ostream &OS) override
Print binary ids on stream OS.
Definition: InstrProfReader.cpp:558
align
mov r0 ldr L5 sub r0 lr needed for prologue ldmia ip add bx lr r2 The last stmia stores r2 into the address passed in there is one additional stmia that stores and r2 to some stack location The store is dead The llvm gcc generated code looks like align
Definition: README.txt:236
Version
uint64_t Version
Definition: RawMemProfReader.cpp:25
llvm::InstrProfSymtab::mapAddress
void mapAddress(uint64_t Addr, uint64_t MD5Val)
Map a function address to its name's MD5 hash.
Definition: InstrProf.h:497
llvm::ErrorOr::get
reference get()
Definition: ErrorOr.h:150
llvm::TextInstrProfReader::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if the given buffer is in text instrprof format.
Definition: InstrProfReader.cpp:142
llvm::ProfileSummary::PSK_Instr
@ PSK_Instr
Definition: ProfileSummary.h:47
N
#define N
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::coverage::Version2
@ Version2
Definition: CoverageMapping.h:997
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
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::InstrProfCorrelator
InstrProfCorrelator - A base class used to create raw instrumentation data to their functions.
Definition: InstrProfCorrelator.h:29
llvm::NamedInstrProfRecord
Definition: InstrProf.h:856
llvm::SmallVectorImpl< char >
llvm::instrprof_error::malformed
@ malformed
llvm::RawInstrProf::Version
const uint64_t Version
Definition: InstrProf.h:1117
llvm::RawInstrProf::Header
Definition: InstrProf.h:1142
llvm::InstrProfLookupTrait::offset_type
uint64_t offset_type
Definition: InstrProfReader.h:368
llvm::InstrProfReaderItaniumRemapper::populateRemappings
Error populateRemappings() override
Definition: InstrProfReader.cpp:774
llvm::SmallVectorImpl::reserve
void reserve(size_type N)
Definition: SmallVector.h:634
Endian.h
llvm::StringRef::begin
iterator begin() const
Definition: StringRef.h:127
llvm::IndexedInstrProf::Summary::NumSummaryFields
uint64_t NumSummaryFields
Definition: InstrProf.h:1047
llvm::IndexedInstrProf::Summary::Entry::MinBlockCount
uint64_t MinBlockCount
The minimum execution count for this percentile.
Definition: InstrProf.h:1022
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:74
llvm::InstrProfReader
Base class and interface for reading profiling data of any known instrprof format.
Definition: InstrProfReader.h:73
llvm::RawInstrProfReader32
RawInstrProfReader< uint32_t > RawInstrProfReader32
Definition: InstrProfReader.h:339
llvm::sampleprof::Base
@ Base
Definition: Discriminator.h:58
llvm::InstrProfIterator::InstrProfIterator
InstrProfIterator()=default
llvm::instrprof_error::missing_debug_info_for_correlation
@ missing_debug_info_for_correlation
llvm::InstrProfLookupTrait::readValueProfilingData
bool readValueProfilingData(const unsigned char *&D, const unsigned char *const End)
Definition: InstrProfReader.cpp:618
llvm::InstrProfReader::error
Error error(instrprof_error Err, const std::string &ErrMsg="")
Set the current error and return same.
Definition: InstrProfReader.h:122
llvm::InstrProfReaderIndex::getRecords
Error getRecords(ArrayRef< NamedInstrProfRecord > &Data) override
Definition: InstrProfReader.cpp:695
llvm::SmallVectorImpl::insert
iterator insert(iterator I, T &&Elt)
Definition: SmallVector.h:782