LLVM  14.0.0git
SampleProfReader.cpp
Go to the documentation of this file.
1 //===- SampleProfReader.cpp - Read LLVM sample profile data ---------------===//
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 implements the class that reads LLVM sample profiles. It
10 // supports three file formats: text, binary and gcov.
11 //
12 // The textual representation is useful for debugging and testing purposes. The
13 // binary representation is more compact, resulting in smaller file sizes.
14 //
15 // The gcov encoding is the one generated by GCC's AutoFDO profile creation
16 // tool (https://github.com/google/autofdo)
17 //
18 // All three encodings can be used interchangeably as an input sample profile.
19 //
20 //===----------------------------------------------------------------------===//
21 
23 #include "llvm/ADT/DenseMap.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/ADT/StringRef.h"
26 #include "llvm/IR/ProfileSummary.h"
31 #include "llvm/Support/ErrorOr.h"
32 #include "llvm/Support/LEB128.h"
34 #include "llvm/Support/MD5.h"
37 #include <algorithm>
38 #include <cstddef>
39 #include <cstdint>
40 #include <limits>
41 #include <memory>
42 #include <set>
43 #include <system_error>
44 #include <vector>
45 
46 using namespace llvm;
47 using namespace sampleprof;
48 
49 #define DEBUG_TYPE "samplepgo-reader"
50 
51 // This internal option specifies if the profile uses FS discriminators.
52 // It only applies to text, binary and compact binary format profiles.
53 // For ext-binary format profiles, the flag is set in the summary.
55  "profile-isfs", cl::Hidden, cl::init(false),
56  cl::desc("Profile uses flow sensitive discriminators"));
57 
58 /// Dump the function profile for \p FName.
59 ///
60 /// \param FContext Name + context of the function to print.
61 /// \param OS Stream to emit the output to.
63  raw_ostream &OS) {
64  OS << "Function: " << FContext.toString() << ": " << Profiles[FContext];
65 }
66 
67 /// Dump all the function profiles found on stream \p OS.
69  std::vector<NameFunctionSamples> V;
71  for (const auto &I : V)
72  dumpFunctionProfile(I.first, OS);
73 }
74 
75 /// Parse \p Input as function head.
76 ///
77 /// Parse one line of \p Input, and update function name in \p FName,
78 /// function's total sample count in \p NumSamples, function's entry
79 /// count in \p NumHeadSamples.
80 ///
81 /// \returns true if parsing is successful.
82 static bool ParseHead(const StringRef &Input, StringRef &FName,
83  uint64_t &NumSamples, uint64_t &NumHeadSamples) {
84  if (Input[0] == ' ')
85  return false;
86  size_t n2 = Input.rfind(':');
87  size_t n1 = Input.rfind(':', n2 - 1);
88  FName = Input.substr(0, n1);
89  if (Input.substr(n1 + 1, n2 - n1 - 1).getAsInteger(10, NumSamples))
90  return false;
91  if (Input.substr(n2 + 1).getAsInteger(10, NumHeadSamples))
92  return false;
93  return true;
94 }
95 
96 /// Returns true if line offset \p L is legal (only has 16 bits).
97 static bool isOffsetLegal(unsigned L) { return (L & 0xffff) == L; }
98 
99 /// Parse \p Input that contains metadata.
100 /// Possible metadata:
101 /// - CFG Checksum information:
102 /// !CFGChecksum: 12345
103 /// - CFG Checksum information:
104 /// !Attributes: 1
105 /// Stores the FunctionHash (a.k.a. CFG Checksum) into \p FunctionHash.
106 static bool parseMetadata(const StringRef &Input, uint64_t &FunctionHash,
107  uint32_t &Attributes) {
108  if (Input.startswith("!CFGChecksum:")) {
109  StringRef CFGInfo = Input.substr(strlen("!CFGChecksum:")).trim();
110  return !CFGInfo.getAsInteger(10, FunctionHash);
111  }
112 
113  if (Input.startswith("!Attributes:")) {
114  StringRef Attrib = Input.substr(strlen("!Attributes:")).trim();
115  return !Attrib.getAsInteger(10, Attributes);
116  }
117 
118  return false;
119 }
120 
121 enum class LineType {
123  BodyProfile,
124  Metadata,
125 };
126 
127 /// Parse \p Input as line sample.
128 ///
129 /// \param Input input line.
130 /// \param LineTy Type of this line.
131 /// \param Depth the depth of the inline stack.
132 /// \param NumSamples total samples of the line/inlined callsite.
133 /// \param LineOffset line offset to the start of the function.
134 /// \param Discriminator discriminator of the line.
135 /// \param TargetCountMap map from indirect call target to count.
136 /// \param FunctionHash the function's CFG hash, used by pseudo probe.
137 ///
138 /// returns true if parsing is successful.
139 static bool ParseLine(const StringRef &Input, LineType &LineTy, uint32_t &Depth,
140  uint64_t &NumSamples, uint32_t &LineOffset,
141  uint32_t &Discriminator, StringRef &CalleeName,
142  DenseMap<StringRef, uint64_t> &TargetCountMap,
143  uint64_t &FunctionHash, uint32_t &Attributes) {
144  for (Depth = 0; Input[Depth] == ' '; Depth++)
145  ;
146  if (Depth == 0)
147  return false;
148 
149  if (Input[Depth] == '!') {
150  LineTy = LineType::Metadata;
151  return parseMetadata(Input.substr(Depth), FunctionHash, Attributes);
152  }
153 
154  size_t n1 = Input.find(':');
155  StringRef Loc = Input.substr(Depth, n1 - Depth);
156  size_t n2 = Loc.find('.');
157  if (n2 == StringRef::npos) {
158  if (Loc.getAsInteger(10, LineOffset) || !isOffsetLegal(LineOffset))
159  return false;
160  Discriminator = 0;
161  } else {
162  if (Loc.substr(0, n2).getAsInteger(10, LineOffset))
163  return false;
164  if (Loc.substr(n2 + 1).getAsInteger(10, Discriminator))
165  return false;
166  }
167 
168  StringRef Rest = Input.substr(n1 + 2);
169  if (isDigit(Rest[0])) {
170  LineTy = LineType::BodyProfile;
171  size_t n3 = Rest.find(' ');
172  if (n3 == StringRef::npos) {
173  if (Rest.getAsInteger(10, NumSamples))
174  return false;
175  } else {
176  if (Rest.substr(0, n3).getAsInteger(10, NumSamples))
177  return false;
178  }
179  // Find call targets and their sample counts.
180  // Note: In some cases, there are symbols in the profile which are not
181  // mangled. To accommodate such cases, use colon + integer pairs as the
182  // anchor points.
183  // An example:
184  // _M_construct<char *>:1000 string_view<std::allocator<char> >:437
185  // ":1000" and ":437" are used as anchor points so the string above will
186  // be interpreted as
187  // target: _M_construct<char *>
188  // count: 1000
189  // target: string_view<std::allocator<char> >
190  // count: 437
191  while (n3 != StringRef::npos) {
192  n3 += Rest.substr(n3).find_first_not_of(' ');
193  Rest = Rest.substr(n3);
194  n3 = Rest.find_first_of(':');
195  if (n3 == StringRef::npos || n3 == 0)
196  return false;
197 
199  uint64_t count, n4;
200  while (true) {
201  // Get the segment after the current colon.
202  StringRef AfterColon = Rest.substr(n3 + 1);
203  // Get the target symbol before the current colon.
204  Target = Rest.substr(0, n3);
205  // Check if the word after the current colon is an integer.
206  n4 = AfterColon.find_first_of(' ');
207  n4 = (n4 != StringRef::npos) ? n3 + n4 + 1 : Rest.size();
208  StringRef WordAfterColon = Rest.substr(n3 + 1, n4 - n3 - 1);
209  if (!WordAfterColon.getAsInteger(10, count))
210  break;
211 
212  // Try to find the next colon.
213  uint64_t n5 = AfterColon.find_first_of(':');
214  if (n5 == StringRef::npos)
215  return false;
216  n3 += n5 + 1;
217  }
218 
219  // An anchor point is found. Save the {target, count} pair
220  TargetCountMap[Target] = count;
221  if (n4 == Rest.size())
222  break;
223  // Change n3 to the next blank space after colon + integer pair.
224  n3 = n4;
225  }
226  } else {
227  LineTy = LineType::CallSiteProfile;
228  size_t n3 = Rest.find_last_of(':');
229  CalleeName = Rest.substr(0, n3);
230  if (Rest.substr(n3 + 1).getAsInteger(10, NumSamples))
231  return false;
232  }
233  return true;
234 }
235 
236 /// Load samples from a text file.
237 ///
238 /// See the documentation at the top of the file for an explanation of
239 /// the expected format.
240 ///
241 /// \returns true if the file was loaded successfully, false otherwise.
243  line_iterator LineIt(*Buffer, /*SkipBlanks=*/true, '#');
245 
246  InlineCallStack InlineStack;
247  uint32_t TopLevelProbeProfileCount = 0;
248 
249  // DepthMetadata tracks whether we have processed metadata for the current
250  // top-level or nested function profile.
251  uint32_t DepthMetadata = 0;
252 
255  for (; !LineIt.is_at_eof(); ++LineIt) {
256  if ((*LineIt)[(*LineIt).find_first_not_of(' ')] == '#')
257  continue;
258  // Read the header of each function.
259  //
260  // Note that for function identifiers we are actually expecting
261  // mangled names, but we may not always get them. This happens when
262  // the compiler decides not to emit the function (e.g., it was inlined
263  // and removed). In this case, the binary will not have the linkage
264  // name for the function, so the profiler will emit the function's
265  // unmangled name, which may contain characters like ':' and '>' in its
266  // name (member functions, templates, etc).
267  //
268  // The only requirement we place on the identifier, then, is that it
269  // should not begin with a number.
270  if ((*LineIt)[0] != ' ') {
271  uint64_t NumSamples, NumHeadSamples;
272  StringRef FName;
273  if (!ParseHead(*LineIt, FName, NumSamples, NumHeadSamples)) {
274  reportError(LineIt.line_number(),
275  "Expected 'mangled_name:NUM:NUM', found " + *LineIt);
277  }
278  DepthMetadata = 0;
279  SampleContext FContext(FName, CSNameTable);
280  if (FContext.hasContext())
281  ++CSProfileCount;
282  Profiles[FContext] = FunctionSamples();
283  FunctionSamples &FProfile = Profiles[FContext];
284  FProfile.setContext(FContext);
285  MergeResult(Result, FProfile.addTotalSamples(NumSamples));
286  MergeResult(Result, FProfile.addHeadSamples(NumHeadSamples));
287  InlineStack.clear();
288  InlineStack.push_back(&FProfile);
289  } else {
290  uint64_t NumSamples;
291  StringRef FName;
292  DenseMap<StringRef, uint64_t> TargetCountMap;
293  uint32_t Depth, LineOffset, Discriminator;
294  LineType LineTy;
295  uint64_t FunctionHash = 0;
296  uint32_t Attributes = 0;
297  if (!ParseLine(*LineIt, LineTy, Depth, NumSamples, LineOffset,
298  Discriminator, FName, TargetCountMap, FunctionHash,
299  Attributes)) {
300  reportError(LineIt.line_number(),
301  "Expected 'NUM[.NUM]: NUM[ mangled_name:NUM]*', found " +
302  *LineIt);
304  }
305  if (LineTy != LineType::Metadata && Depth == DepthMetadata) {
306  // Metadata must be put at the end of a function profile.
307  reportError(LineIt.line_number(),
308  "Found non-metadata after metadata: " + *LineIt);
310  }
311 
312  // Here we handle FS discriminators.
313  Discriminator &= getDiscriminatorMask();
314 
315  while (InlineStack.size() > Depth) {
316  InlineStack.pop_back();
317  }
318  switch (LineTy) {
320  FunctionSamples &FSamples = InlineStack.back()->functionSamplesAt(
321  LineLocation(LineOffset, Discriminator))[std::string(FName)];
322  FSamples.setName(FName);
323  MergeResult(Result, FSamples.addTotalSamples(NumSamples));
324  InlineStack.push_back(&FSamples);
325  DepthMetadata = 0;
326  break;
327  }
328  case LineType::BodyProfile: {
329  while (InlineStack.size() > Depth) {
330  InlineStack.pop_back();
331  }
332  FunctionSamples &FProfile = *InlineStack.back();
333  for (const auto &name_count : TargetCountMap) {
334  MergeResult(Result, FProfile.addCalledTargetSamples(
335  LineOffset, Discriminator, name_count.first,
336  name_count.second));
337  }
338  MergeResult(Result, FProfile.addBodySamples(LineOffset, Discriminator,
339  NumSamples));
340  break;
341  }
342  case LineType::Metadata: {
343  FunctionSamples &FProfile = *InlineStack.back();
344  if (FunctionHash) {
345  FProfile.setFunctionHash(FunctionHash);
346  if (Depth == 1)
347  ++TopLevelProbeProfileCount;
348  }
351  ProfileIsCSNested = true;
352  DepthMetadata = Depth;
353  break;
354  }
355  }
356  }
357  }
358 
359  assert((CSProfileCount == 0 || CSProfileCount == Profiles.size()) &&
360  "Cannot have both context-sensitive and regular profile");
362  assert((TopLevelProbeProfileCount == 0 ||
363  TopLevelProbeProfileCount == Profiles.size()) &&
364  "Cannot have both probe-based profiles and regular profiles");
365  ProfileIsProbeBased = (TopLevelProbeProfileCount > 0);
369 
370  if (Result == sampleprof_error::success)
371  computeSummary();
372 
373  return Result;
374 }
375 
377  bool result = false;
378 
379  // Check that the first non-comment line is a valid function header.
380  line_iterator LineIt(Buffer, /*SkipBlanks=*/true, '#');
381  if (!LineIt.is_at_eof()) {
382  if ((*LineIt)[0] != ' ') {
383  uint64_t NumSamples, NumHeadSamples;
384  StringRef FName;
385  result = ParseHead(*LineIt, FName, NumSamples, NumHeadSamples);
386  }
387  }
388 
389  return result;
390 }
391 
393  unsigned NumBytesRead = 0;
394  std::error_code EC;
395  uint64_t Val = decodeULEB128(Data, &NumBytesRead);
396 
397  if (Val > std::numeric_limits<T>::max())
399  else if (Data + NumBytesRead > End)
401  else
403 
404  if (EC) {
405  reportError(0, EC.message());
406  return EC;
407  }
408 
409  Data += NumBytesRead;
410  return static_cast<T>(Val);
411 }
412 
414  std::error_code EC;
415  StringRef Str(reinterpret_cast<const char *>(Data));
416  if (Data + Str.size() + 1 > End) {
418  reportError(0, EC.message());
419  return EC;
420  }
421 
422  Data += Str.size() + 1;
423  return Str;
424 }
425 
426 template <typename T>
428  std::error_code EC;
429 
430  if (Data + sizeof(T) > End) {
432  reportError(0, EC.message());
433  return EC;
434  }
435 
436  using namespace support;
437  T Val = endian::readNext<T, little, unaligned>(Data);
438  return Val;
439 }
440 
441 template <typename T>
443  std::error_code EC;
444  auto Idx = readNumber<uint32_t>();
445  if (std::error_code EC = Idx.getError())
446  return EC;
447  if (*Idx >= Table.size())
449  return *Idx;
450 }
451 
453  auto Idx = readStringIndex(NameTable);
454  if (std::error_code EC = Idx.getError())
455  return EC;
456 
457  return NameTable[*Idx];
458 }
459 
461  auto FName(readStringFromTable());
462  if (std::error_code EC = FName.getError())
463  return EC;
464  return SampleContext(*FName);
465 }
466 
468  if (!FixedLengthMD5)
470 
471  // read NameTable index.
472  auto Idx = readStringIndex(NameTable);
473  if (std::error_code EC = Idx.getError())
474  return EC;
475 
476  // Check whether the name to be accessed has been accessed before,
477  // if not, read it from memory directly.
478  StringRef &SR = NameTable[*Idx];
479  if (SR.empty()) {
480  const uint8_t *SavedData = Data;
481  Data = MD5NameMemStart + ((*Idx) * sizeof(uint64_t));
482  auto FID = readUnencodedNumber<uint64_t>();
483  if (std::error_code EC = FID.getError())
484  return EC;
485  // Save the string converted from uint64_t in MD5StringBuf. All the
486  // references to the name are all StringRefs refering to the string
487  // in MD5StringBuf.
488  MD5StringBuf->push_back(std::to_string(*FID));
489  SR = MD5StringBuf->back();
490  Data = SavedData;
491  }
492  return SR;
493 }
494 
495 ErrorOr<StringRef> SampleProfileReaderCompactBinary::readStringFromTable() {
496  auto Idx = readStringIndex(NameTable);
497  if (std::error_code EC = Idx.getError())
498  return EC;
499 
500  return StringRef(NameTable[*Idx]);
501 }
502 
503 std::error_code
505  auto NumSamples = readNumber<uint64_t>();
506  if (std::error_code EC = NumSamples.getError())
507  return EC;
508  FProfile.addTotalSamples(*NumSamples);
509 
510  // Read the samples in the body.
511  auto NumRecords = readNumber<uint32_t>();
512  if (std::error_code EC = NumRecords.getError())
513  return EC;
514 
515  for (uint32_t I = 0; I < *NumRecords; ++I) {
516  auto LineOffset = readNumber<uint64_t>();
517  if (std::error_code EC = LineOffset.getError())
518  return EC;
519 
520  if (!isOffsetLegal(*LineOffset)) {
521  return std::error_code();
522  }
523 
524  auto Discriminator = readNumber<uint64_t>();
525  if (std::error_code EC = Discriminator.getError())
526  return EC;
527 
528  auto NumSamples = readNumber<uint64_t>();
529  if (std::error_code EC = NumSamples.getError())
530  return EC;
531 
532  auto NumCalls = readNumber<uint32_t>();
533  if (std::error_code EC = NumCalls.getError())
534  return EC;
535 
536  // Here we handle FS discriminators:
537  uint32_t DiscriminatorVal = (*Discriminator) & getDiscriminatorMask();
538 
539  for (uint32_t J = 0; J < *NumCalls; ++J) {
540  auto CalledFunction(readStringFromTable());
541  if (std::error_code EC = CalledFunction.getError())
542  return EC;
543 
544  auto CalledFunctionSamples = readNumber<uint64_t>();
545  if (std::error_code EC = CalledFunctionSamples.getError())
546  return EC;
547 
548  FProfile.addCalledTargetSamples(*LineOffset, DiscriminatorVal,
549  *CalledFunction, *CalledFunctionSamples);
550  }
551 
552  FProfile.addBodySamples(*LineOffset, DiscriminatorVal, *NumSamples);
553  }
554 
555  // Read all the samples for inlined function calls.
556  auto NumCallsites = readNumber<uint32_t>();
557  if (std::error_code EC = NumCallsites.getError())
558  return EC;
559 
560  for (uint32_t J = 0; J < *NumCallsites; ++J) {
561  auto LineOffset = readNumber<uint64_t>();
562  if (std::error_code EC = LineOffset.getError())
563  return EC;
564 
565  auto Discriminator = readNumber<uint64_t>();
566  if (std::error_code EC = Discriminator.getError())
567  return EC;
568 
569  auto FName(readStringFromTable());
570  if (std::error_code EC = FName.getError())
571  return EC;
572 
573  // Here we handle FS discriminators:
574  uint32_t DiscriminatorVal = (*Discriminator) & getDiscriminatorMask();
575 
576  FunctionSamples &CalleeProfile = FProfile.functionSamplesAt(
577  LineLocation(*LineOffset, DiscriminatorVal))[std::string(*FName)];
578  CalleeProfile.setName(*FName);
579  if (std::error_code EC = readProfile(CalleeProfile))
580  return EC;
581  }
582 
584 }
585 
586 std::error_code
588  Data = Start;
589  auto NumHeadSamples = readNumber<uint64_t>();
590  if (std::error_code EC = NumHeadSamples.getError())
591  return EC;
592 
594  if (std::error_code EC = FContext.getError())
595  return EC;
596 
597  Profiles[*FContext] = FunctionSamples();
598  FunctionSamples &FProfile = Profiles[*FContext];
599  FProfile.setContext(*FContext);
600  FProfile.addHeadSamples(*NumHeadSamples);
601 
602  if (FContext->hasContext())
603  CSProfileCount++;
604 
605  if (std::error_code EC = readProfile(FProfile))
606  return EC;
608 }
609 
613  while (!at_eof()) {
614  if (std::error_code EC = readFuncProfile(Data))
615  return EC;
616  }
617 
619 }
620 
623  auto ContextIdx = readNumber<uint32_t>();
624  if (std::error_code EC = ContextIdx.getError())
625  return EC;
626  if (*ContextIdx >= CSNameTable->size())
628  return (*CSNameTable)[*ContextIdx];
629 }
630 
633  if (ProfileIsCSFlat) {
634  auto FContext(readContextFromTable());
635  if (std::error_code EC = FContext.getError())
636  return EC;
637  return SampleContext(*FContext);
638  } else {
639  auto FName(readStringFromTable());
640  if (std::error_code EC = FName.getError())
641  return EC;
642  return SampleContext(*FName);
643  }
644 }
645 
647  const uint8_t *Start, uint64_t Size, const SecHdrTableEntry &Entry) {
648  Data = Start;
649  End = Start + Size;
650  switch (Entry.Type) {
651  case SecProfSummary:
652  if (std::error_code EC = readSummary())
653  return EC;
655  Summary->setPartialProfile(true);
660  break;
661  case SecNameTable: {
662  FixedLengthMD5 =
664  bool UseMD5 = hasSecFlag(Entry, SecNameTableFlags::SecFlagMD5Name);
665  assert((!FixedLengthMD5 || UseMD5) &&
666  "If FixedLengthMD5 is true, UseMD5 has to be true");
669  if (std::error_code EC = readNameTableSec(UseMD5))
670  return EC;
671  break;
672  }
673  case SecCSNameTable: {
674  if (std::error_code EC = readCSNameTableSec())
675  return EC;
676  break;
677  }
678  case SecLBRProfile:
679  if (std::error_code EC = readFuncProfiles())
680  return EC;
681  break;
682  case SecFuncOffsetTable:
683  FuncOffsetsOrdered = hasSecFlag(Entry, SecFuncOffsetFlags::SecFlagOrdered);
684  if (std::error_code EC = readFuncOffsetTable())
685  return EC;
686  break;
687  case SecFuncMetadata: {
694  bool HasAttribute =
696  if (std::error_code EC = readFuncMetadata(HasAttribute))
697  return EC;
698  break;
699  }
701  if (std::error_code EC = readProfileSymbolList())
702  return EC;
703  break;
704  default:
705  if (std::error_code EC = readCustomSection(Entry))
706  return EC;
707  break;
708  }
710 }
711 
713  if (!M)
714  return false;
715  FuncsToUse.clear();
716  for (auto &F : *M)
717  FuncsToUse.insert(FunctionSamples::getCanonicalFnName(F));
718  return true;
719 }
720 
722  // If there are more than one FuncOffsetTable, the profile read associated
723  // with previous FuncOffsetTable has to be done before next FuncOffsetTable
724  // is read.
725  FuncOffsetTable.clear();
726 
727  auto Size = readNumber<uint64_t>();
728  if (std::error_code EC = Size.getError())
729  return EC;
730 
731  FuncOffsetTable.reserve(*Size);
732 
733  if (FuncOffsetsOrdered) {
734  OrderedFuncOffsets =
735  std::make_unique<std::vector<std::pair<SampleContext, uint64_t>>>();
736  OrderedFuncOffsets->reserve(*Size);
737  }
738 
739  for (uint32_t I = 0; I < *Size; ++I) {
740  auto FContext(readSampleContextFromTable());
741  if (std::error_code EC = FContext.getError())
742  return EC;
743 
744  auto Offset = readNumber<uint64_t>();
745  if (std::error_code EC = Offset.getError())
746  return EC;
747 
748  FuncOffsetTable[*FContext] = *Offset;
749  if (FuncOffsetsOrdered)
750  OrderedFuncOffsets->emplace_back(*FContext, *Offset);
751  }
752 
754 }
755 
757  // Collect functions used by current module if the Reader has been
758  // given a module.
759  // collectFuncsFromModule uses FunctionSamples::getCanonicalFnName
760  // which will query FunctionSamples::HasUniqSuffix, so it has to be
761  // called after FunctionSamples::HasUniqSuffix is set, i.e. after
762  // NameTable section is read.
763  bool LoadFuncsToBeUsed = collectFuncsFromModule();
764 
765  // When LoadFuncsToBeUsed is false, load all the function profiles.
766  const uint8_t *Start = Data;
767  if (!LoadFuncsToBeUsed) {
768  while (Data < End) {
769  if (std::error_code EC = readFuncProfile(Data))
770  return EC;
771  }
772  assert(Data == End && "More data is read than expected");
773  } else {
774  // Load function profiles on demand.
775  if (Remapper) {
776  for (auto Name : FuncsToUse) {
777  Remapper->insert(Name);
778  }
779  }
780 
781  if (ProfileIsCSFlat) {
782  DenseSet<uint64_t> FuncGuidsToUse;
783  if (useMD5()) {
784  for (auto Name : FuncsToUse)
785  FuncGuidsToUse.insert(Function::getGUID(Name));
786  }
787 
788  // For each function in current module, load all context profiles for
789  // the function as well as their callee contexts which can help profile
790  // guided importing for ThinLTO. This can be achieved by walking
791  // through an ordered context container, where contexts are laid out
792  // as if they were walked in preorder of a context trie. While
793  // traversing the trie, a link to the highest common ancestor node is
794  // kept so that all of its decendants will be loaded.
795  assert(OrderedFuncOffsets.get() &&
796  "func offset table should always be sorted in CS profile");
797  const SampleContext *CommonContext = nullptr;
798  for (const auto &NameOffset : *OrderedFuncOffsets) {
799  const auto &FContext = NameOffset.first;
800  auto FName = FContext.getName();
801  // For function in the current module, keep its farthest ancestor
802  // context. This can be used to load itself and its child and
803  // sibling contexts.
804  if ((useMD5() && FuncGuidsToUse.count(std::stoull(FName.data()))) ||
805  (!useMD5() && (FuncsToUse.count(FName) ||
806  (Remapper && Remapper->exist(FName))))) {
807  if (!CommonContext || !CommonContext->IsPrefixOf(FContext))
808  CommonContext = &FContext;
809  }
810 
811  if (CommonContext == &FContext ||
812  (CommonContext && CommonContext->IsPrefixOf(FContext))) {
813  // Load profile for the current context which originated from
814  // the common ancestor.
815  const uint8_t *FuncProfileAddr = Start + NameOffset.second;
816  assert(FuncProfileAddr < End && "out of LBRProfile section");
817  if (std::error_code EC = readFuncProfile(FuncProfileAddr))
818  return EC;
819  }
820  }
821  } else {
822  if (useMD5()) {
823  for (auto Name : FuncsToUse) {
824  auto GUID = std::to_string(MD5Hash(Name));
825  auto iter = FuncOffsetTable.find(StringRef(GUID));
826  if (iter == FuncOffsetTable.end())
827  continue;
828  const uint8_t *FuncProfileAddr = Start + iter->second;
829  assert(FuncProfileAddr < End && "out of LBRProfile section");
830  if (std::error_code EC = readFuncProfile(FuncProfileAddr))
831  return EC;
832  }
833  } else {
834  for (auto NameOffset : FuncOffsetTable) {
835  SampleContext FContext(NameOffset.first);
836  auto FuncName = FContext.getName();
837  if (!FuncsToUse.count(FuncName) &&
838  (!Remapper || !Remapper->exist(FuncName)))
839  continue;
840  const uint8_t *FuncProfileAddr = Start + NameOffset.second;
841  assert(FuncProfileAddr < End && "out of LBRProfile section");
842  if (std::error_code EC = readFuncProfile(FuncProfileAddr))
843  return EC;
844  }
845  }
846  }
847  Data = End;
848  }
849  assert((CSProfileCount == 0 || CSProfileCount == Profiles.size()) &&
850  "Cannot have both context-sensitive and regular profile");
852  "Section flag should be consistent with actual profile");
854 }
855 
857  if (!ProfSymList)
858  ProfSymList = std::make_unique<ProfileSymbolList>();
859 
860  if (std::error_code EC = ProfSymList->read(Data, End - Data))
861  return EC;
862 
863  Data = End;
865 }
866 
867 std::error_code SampleProfileReaderExtBinaryBase::decompressSection(
868  const uint8_t *SecStart, const uint64_t SecSize,
869  const uint8_t *&DecompressBuf, uint64_t &DecompressBufSize) {
870  Data = SecStart;
871  End = SecStart + SecSize;
872  auto DecompressSize = readNumber<uint64_t>();
873  if (std::error_code EC = DecompressSize.getError())
874  return EC;
875  DecompressBufSize = *DecompressSize;
876 
877  auto CompressSize = readNumber<uint64_t>();
878  if (std::error_code EC = CompressSize.getError())
879  return EC;
880 
883 
884  StringRef CompressedStrings(reinterpret_cast<const char *>(Data),
885  *CompressSize);
886  char *Buffer = Allocator.Allocate<char>(DecompressBufSize);
887  size_t UCSize = DecompressBufSize;
888  llvm::Error E =
889  zlib::uncompress(CompressedStrings, Buffer, UCSize);
890  if (E)
892  DecompressBuf = reinterpret_cast<const uint8_t *>(Buffer);
894 }
895 
897  const uint8_t *BufStart =
898  reinterpret_cast<const uint8_t *>(Buffer->getBufferStart());
899 
900  for (auto &Entry : SecHdrTable) {
901  // Skip empty section.
902  if (!Entry.Size)
903  continue;
904 
905  // Skip sections without context when SkipFlatProf is true.
906  if (SkipFlatProf && hasSecFlag(Entry, SecCommonFlags::SecFlagFlat))
907  continue;
908 
909  const uint8_t *SecStart = BufStart + Entry.Offset;
910  uint64_t SecSize = Entry.Size;
911 
912  // If the section is compressed, decompress it into a buffer
913  // DecompressBuf before reading the actual data. The pointee of
914  // 'Data' will be changed to buffer hold by DecompressBuf
915  // temporarily when reading the actual data.
916  bool isCompressed = hasSecFlag(Entry, SecCommonFlags::SecFlagCompress);
917  if (isCompressed) {
918  const uint8_t *DecompressBuf;
919  uint64_t DecompressBufSize;
920  if (std::error_code EC = decompressSection(
921  SecStart, SecSize, DecompressBuf, DecompressBufSize))
922  return EC;
923  SecStart = DecompressBuf;
924  SecSize = DecompressBufSize;
925  }
926 
927  if (std::error_code EC = readOneSection(SecStart, SecSize, Entry))
928  return EC;
929  if (Data != SecStart + SecSize)
931 
932  // Change the pointee of 'Data' from DecompressBuf to original Buffer.
933  if (isCompressed) {
934  Data = BufStart + Entry.Offset;
935  End = BufStart + Buffer->getBufferSize();
936  }
937  }
938 
940 }
941 
943  // Collect functions used by current module if the Reader has been
944  // given a module.
945  bool LoadFuncsToBeUsed = collectFuncsFromModule();
948  std::vector<uint64_t> OffsetsToUse;
949  if (!LoadFuncsToBeUsed) {
950  // load all the function profiles.
951  for (auto FuncEntry : FuncOffsetTable) {
952  OffsetsToUse.push_back(FuncEntry.second);
953  }
954  } else {
955  // load function profiles on demand.
956  for (auto Name : FuncsToUse) {
957  auto GUID = std::to_string(MD5Hash(Name));
958  auto iter = FuncOffsetTable.find(StringRef(GUID));
959  if (iter == FuncOffsetTable.end())
960  continue;
961  OffsetsToUse.push_back(iter->second);
962  }
963  }
964 
965  for (auto Offset : OffsetsToUse) {
966  const uint8_t *SavedData = Data;
967  if (std::error_code EC = readFuncProfile(
968  reinterpret_cast<const uint8_t *>(Buffer->getBufferStart()) +
969  Offset))
970  return EC;
971  Data = SavedData;
972  }
974 }
975 
976 std::error_code SampleProfileReaderRawBinary::verifySPMagic(uint64_t Magic) {
977  if (Magic == SPMagic())
980 }
981 
982 std::error_code SampleProfileReaderExtBinary::verifySPMagic(uint64_t Magic) {
983  if (Magic == SPMagic(SPF_Ext_Binary))
986 }
987 
988 std::error_code
989 SampleProfileReaderCompactBinary::verifySPMagic(uint64_t Magic) {
993 }
994 
996  auto Size = readNumber<uint32_t>();
997  if (std::error_code EC = Size.getError())
998  return EC;
999  NameTable.reserve(*Size + NameTable.size());
1000  for (uint32_t I = 0; I < *Size; ++I) {
1001  auto Name(readString());
1002  if (std::error_code EC = Name.getError())
1003  return EC;
1004  NameTable.push_back(*Name);
1005  }
1006 
1008 }
1009 
1011  auto Size = readNumber<uint64_t>();
1012  if (std::error_code EC = Size.getError())
1013  return EC;
1014  MD5StringBuf = std::make_unique<std::vector<std::string>>();
1015  MD5StringBuf->reserve(*Size);
1016  if (FixedLengthMD5) {
1017  // Preallocate and initialize NameTable so we can check whether a name
1018  // index has been read before by checking whether the element in the
1019  // NameTable is empty, meanwhile readStringIndex can do the boundary
1020  // check using the size of NameTable.
1021  NameTable.resize(*Size + NameTable.size());
1022 
1023  MD5NameMemStart = Data;
1024  Data = Data + (*Size) * sizeof(uint64_t);
1026  }
1027  NameTable.reserve(*Size);
1028  for (uint32_t I = 0; I < *Size; ++I) {
1029  auto FID = readNumber<uint64_t>();
1030  if (std::error_code EC = FID.getError())
1031  return EC;
1032  MD5StringBuf->push_back(std::to_string(*FID));
1033  // NameTable is a vector of StringRef. Here it is pushing back a
1034  // StringRef initialized with the last string in MD5stringBuf.
1035  NameTable.push_back(MD5StringBuf->back());
1036  }
1038 }
1039 
1041  if (IsMD5)
1042  return readMD5NameTable();
1044 }
1045 
1046 // Read in the CS name table section, which basically contains a list of context
1047 // vectors. Each element of a context vector, aka a frame, refers to the
1048 // underlying raw function names that are stored in the name table, as well as
1049 // a callsite identifier that only makes sense for non-leaf frames.
1051  auto Size = readNumber<uint32_t>();
1052  if (std::error_code EC = Size.getError())
1053  return EC;
1054 
1055  std::vector<SampleContextFrameVector> *PNameVec =
1056  new std::vector<SampleContextFrameVector>();
1057  PNameVec->reserve(*Size);
1058  for (uint32_t I = 0; I < *Size; ++I) {
1059  PNameVec->emplace_back(SampleContextFrameVector());
1060  auto ContextSize = readNumber<uint32_t>();
1061  if (std::error_code EC = ContextSize.getError())
1062  return EC;
1063  for (uint32_t J = 0; J < *ContextSize; ++J) {
1064  auto FName(readStringFromTable());
1065  if (std::error_code EC = FName.getError())
1066  return EC;
1067  auto LineOffset = readNumber<uint64_t>();
1068  if (std::error_code EC = LineOffset.getError())
1069  return EC;
1070 
1071  if (!isOffsetLegal(*LineOffset))
1072  return std::error_code();
1073 
1074  auto Discriminator = readNumber<uint64_t>();
1075  if (std::error_code EC = Discriminator.getError())
1076  return EC;
1077 
1078  PNameVec->back().emplace_back(
1079  FName.get(), LineLocation(LineOffset.get(), Discriminator.get()));
1080  }
1081  }
1082 
1083  // From this point the underlying object of CSNameTable should be immutable.
1084  CSNameTable.reset(PNameVec);
1086 }
1087 
1088 std::error_code
1089 
1091  FunctionSamples *FProfile) {
1092  if (Data < End) {
1093  if (ProfileIsProbeBased) {
1094  auto Checksum = readNumber<uint64_t>();
1095  if (std::error_code EC = Checksum.getError())
1096  return EC;
1097  if (FProfile)
1098  FProfile->setFunctionHash(*Checksum);
1099  }
1100 
1101  if (ProfileHasAttribute) {
1102  auto Attributes = readNumber<uint32_t>();
1103  if (std::error_code EC = Attributes.getError())
1104  return EC;
1105  if (FProfile)
1106  FProfile->getContext().setAllAttributes(*Attributes);
1107  }
1108 
1109  if (!ProfileIsCSFlat) {
1110  // Read all the attributes for inlined function calls.
1111  auto NumCallsites = readNumber<uint32_t>();
1112  if (std::error_code EC = NumCallsites.getError())
1113  return EC;
1114 
1115  for (uint32_t J = 0; J < *NumCallsites; ++J) {
1116  auto LineOffset = readNumber<uint64_t>();
1117  if (std::error_code EC = LineOffset.getError())
1118  return EC;
1119 
1120  auto Discriminator = readNumber<uint64_t>();
1121  if (std::error_code EC = Discriminator.getError())
1122  return EC;
1123 
1124  auto FContext(readSampleContextFromTable());
1125  if (std::error_code EC = FContext.getError())
1126  return EC;
1127 
1128  FunctionSamples *CalleeProfile = nullptr;
1129  if (FProfile) {
1130  CalleeProfile = const_cast<FunctionSamples *>(
1131  &FProfile->functionSamplesAt(LineLocation(
1132  *LineOffset,
1133  *Discriminator))[std::string(FContext.get().getName())]);
1134  }
1135  if (std::error_code EC =
1136  readFuncMetadata(ProfileHasAttribute, CalleeProfile))
1137  return EC;
1138  }
1139  }
1140  }
1141 
1143 }
1144 
1145 std::error_code
1147  while (Data < End) {
1148  auto FContext(readSampleContextFromTable());
1149  if (std::error_code EC = FContext.getError())
1150  return EC;
1151  FunctionSamples *FProfile = nullptr;
1152  auto It = Profiles.find(*FContext);
1153  if (It != Profiles.end())
1154  FProfile = &It->second;
1155 
1156  if (std::error_code EC = readFuncMetadata(ProfileHasAttribute, FProfile))
1157  return EC;
1158  }
1159 
1160  assert(Data == End && "More data is read than expected");
1162 }
1163 
1164 std::error_code SampleProfileReaderCompactBinary::readNameTable() {
1165  auto Size = readNumber<uint64_t>();
1166  if (std::error_code EC = Size.getError())
1167  return EC;
1168  NameTable.reserve(*Size);
1169  for (uint32_t I = 0; I < *Size; ++I) {
1170  auto FID = readNumber<uint64_t>();
1171  if (std::error_code EC = FID.getError())
1172  return EC;
1173  NameTable.push_back(std::to_string(*FID));
1174  }
1176 }
1177 
1178 std::error_code
1180  SecHdrTableEntry Entry;
1181  auto Type = readUnencodedNumber<uint64_t>();
1182  if (std::error_code EC = Type.getError())
1183  return EC;
1184  Entry.Type = static_cast<SecType>(*Type);
1185 
1186  auto Flags = readUnencodedNumber<uint64_t>();
1187  if (std::error_code EC = Flags.getError())
1188  return EC;
1189  Entry.Flags = *Flags;
1190 
1191  auto Offset = readUnencodedNumber<uint64_t>();
1192  if (std::error_code EC = Offset.getError())
1193  return EC;
1194  Entry.Offset = *Offset;
1195 
1196  auto Size = readUnencodedNumber<uint64_t>();
1197  if (std::error_code EC = Size.getError())
1198  return EC;
1199  Entry.Size = *Size;
1200 
1201  Entry.LayoutIndex = Idx;
1202  SecHdrTable.push_back(std::move(Entry));
1204 }
1205 
1207  auto EntryNum = readUnencodedNumber<uint64_t>();
1208  if (std::error_code EC = EntryNum.getError())
1209  return EC;
1210 
1211  for (uint32_t i = 0; i < (*EntryNum); i++)
1212  if (std::error_code EC = readSecHdrTableEntry(i))
1213  return EC;
1214 
1216 }
1217 
1219  const uint8_t *BufStart =
1220  reinterpret_cast<const uint8_t *>(Buffer->getBufferStart());
1221  Data = BufStart;
1222  End = BufStart + Buffer->getBufferSize();
1223 
1224  if (std::error_code EC = readMagicIdent())
1225  return EC;
1226 
1227  if (std::error_code EC = readSecHdrTable())
1228  return EC;
1229 
1231 }
1232 
1234  uint64_t Size = 0;
1235  for (auto &Entry : SecHdrTable) {
1236  if (Entry.Type == Type)
1237  Size += Entry.Size;
1238  }
1239  return Size;
1240 }
1241 
1243  // Sections in SecHdrTable is not necessarily in the same order as
1244  // sections in the profile because section like FuncOffsetTable needs
1245  // to be written after section LBRProfile but needs to be read before
1246  // section LBRProfile, so we cannot simply use the last entry in
1247  // SecHdrTable to calculate the file size.
1248  uint64_t FileSize = 0;
1249  for (auto &Entry : SecHdrTable) {
1250  FileSize = std::max(Entry.Offset + Entry.Size, FileSize);
1251  }
1252  return FileSize;
1253 }
1254 
1255 static std::string getSecFlagsStr(const SecHdrTableEntry &Entry) {
1256  std::string Flags;
1258  Flags.append("{compressed,");
1259  else
1260  Flags.append("{");
1261 
1263  Flags.append("flat,");
1264 
1265  switch (Entry.Type) {
1266  case SecNameTable:
1268  Flags.append("fixlenmd5,");
1270  Flags.append("md5,");
1272  Flags.append("uniq,");
1273  break;
1274  case SecProfSummary:
1276  Flags.append("partial,");
1278  Flags.append("context,");
1280  Flags.append("fs-discriminator,");
1281  break;
1282  case SecFuncOffsetTable:
1284  Flags.append("ordered,");
1285  break;
1286  case SecFuncMetadata:
1288  Flags.append("probe,");
1290  Flags.append("attr,");
1292  Flags.append("preinlined,");
1293  break;
1294  default:
1295  break;
1296  }
1297  char &last = Flags.back();
1298  if (last == ',')
1299  last = '}';
1300  else
1301  Flags.append("}");
1302  return Flags;
1303 }
1304 
1306  uint64_t TotalSecsSize = 0;
1307  for (auto &Entry : SecHdrTable) {
1308  OS << getSecName(Entry.Type) << " - Offset: " << Entry.Offset
1309  << ", Size: " << Entry.Size << ", Flags: " << getSecFlagsStr(Entry)
1310  << "\n";
1311  ;
1312  TotalSecsSize += Entry.Size;
1313  }
1314  uint64_t HeaderSize = SecHdrTable.front().Offset;
1315  assert(HeaderSize + TotalSecsSize == getFileSize() &&
1316  "Size of 'header + sections' doesn't match the total size of profile");
1317 
1318  OS << "Header Size: " << HeaderSize << "\n";
1319  OS << "Total Sections Size: " << TotalSecsSize << "\n";
1320  OS << "File Size: " << getFileSize() << "\n";
1321  return true;
1322 }
1323 
1325  // Read and check the magic identifier.
1326  auto Magic = readNumber<uint64_t>();
1327  if (std::error_code EC = Magic.getError())
1328  return EC;
1329  else if (std::error_code EC = verifySPMagic(*Magic))
1330  return EC;
1331 
1332  // Read the version number.
1333  auto Version = readNumber<uint64_t>();
1334  if (std::error_code EC = Version.getError())
1335  return EC;
1336  else if (*Version != SPVersion())
1338 
1340 }
1341 
1343  Data = reinterpret_cast<const uint8_t *>(Buffer->getBufferStart());
1344  End = Data + Buffer->getBufferSize();
1345 
1346  if (std::error_code EC = readMagicIdent())
1347  return EC;
1348 
1349  if (std::error_code EC = readSummary())
1350  return EC;
1351 
1352  if (std::error_code EC = readNameTable())
1353  return EC;
1355 }
1356 
1357 std::error_code SampleProfileReaderCompactBinary::readHeader() {
1359  if (std::error_code EC = readFuncOffsetTable())
1360  return EC;
1362 }
1363 
1364 std::error_code SampleProfileReaderCompactBinary::readFuncOffsetTable() {
1365  auto TableOffset = readUnencodedNumber<uint64_t>();
1366  if (std::error_code EC = TableOffset.getError())
1367  return EC;
1368 
1369  const uint8_t *SavedData = Data;
1370  const uint8_t *TableStart =
1371  reinterpret_cast<const uint8_t *>(Buffer->getBufferStart()) +
1372  *TableOffset;
1373  Data = TableStart;
1374 
1375  auto Size = readNumber<uint64_t>();
1376  if (std::error_code EC = Size.getError())
1377  return EC;
1378 
1379  FuncOffsetTable.reserve(*Size);
1380  for (uint32_t I = 0; I < *Size; ++I) {
1381  auto FName(readStringFromTable());
1382  if (std::error_code EC = FName.getError())
1383  return EC;
1384 
1385  auto Offset = readNumber<uint64_t>();
1386  if (std::error_code EC = Offset.getError())
1387  return EC;
1388 
1389  FuncOffsetTable[*FName] = *Offset;
1390  }
1391  End = TableStart;
1392  Data = SavedData;
1394 }
1395 
1397  if (!M)
1398  return false;
1399  FuncsToUse.clear();
1400  for (auto &F : *M)
1401  FuncsToUse.insert(FunctionSamples::getCanonicalFnName(F));
1402  return true;
1403 }
1404 
1405 std::error_code SampleProfileReaderBinary::readSummaryEntry(
1406  std::vector<ProfileSummaryEntry> &Entries) {
1407  auto Cutoff = readNumber<uint64_t>();
1408  if (std::error_code EC = Cutoff.getError())
1409  return EC;
1410 
1411  auto MinBlockCount = readNumber<uint64_t>();
1412  if (std::error_code EC = MinBlockCount.getError())
1413  return EC;
1414 
1415  auto NumBlocks = readNumber<uint64_t>();
1416  if (std::error_code EC = NumBlocks.getError())
1417  return EC;
1418 
1419  Entries.emplace_back(*Cutoff, *MinBlockCount, *NumBlocks);
1421 }
1422 
1424  auto TotalCount = readNumber<uint64_t>();
1425  if (std::error_code EC = TotalCount.getError())
1426  return EC;
1427 
1428  auto MaxBlockCount = readNumber<uint64_t>();
1429  if (std::error_code EC = MaxBlockCount.getError())
1430  return EC;
1431 
1432  auto MaxFunctionCount = readNumber<uint64_t>();
1433  if (std::error_code EC = MaxFunctionCount.getError())
1434  return EC;
1435 
1436  auto NumBlocks = readNumber<uint64_t>();
1437  if (std::error_code EC = NumBlocks.getError())
1438  return EC;
1439 
1440  auto NumFunctions = readNumber<uint64_t>();
1441  if (std::error_code EC = NumFunctions.getError())
1442  return EC;
1443 
1444  auto NumSummaryEntries = readNumber<uint64_t>();
1445  if (std::error_code EC = NumSummaryEntries.getError())
1446  return EC;
1447 
1448  std::vector<ProfileSummaryEntry> Entries;
1449  for (unsigned i = 0; i < *NumSummaryEntries; i++) {
1450  std::error_code EC = readSummaryEntry(Entries);
1451  if (EC != sampleprof_error::success)
1452  return EC;
1453  }
1454  Summary = std::make_unique<ProfileSummary>(
1455  ProfileSummary::PSK_Sample, Entries, *TotalCount, *MaxBlockCount, 0,
1456  *MaxFunctionCount, *NumBlocks, *NumFunctions);
1457 
1459 }
1460 
1462  const uint8_t *Data =
1463  reinterpret_cast<const uint8_t *>(Buffer.getBufferStart());
1465  return Magic == SPMagic();
1466 }
1467 
1469  const uint8_t *Data =
1470  reinterpret_cast<const uint8_t *>(Buffer.getBufferStart());
1472  return Magic == SPMagic(SPF_Ext_Binary);
1473 }
1474 
1476  const uint8_t *Data =
1477  reinterpret_cast<const uint8_t *>(Buffer.getBufferStart());
1479  return Magic == SPMagic(SPF_Compact_Binary);
1480 }
1481 
1483  uint32_t dummy;
1484  if (!GcovBuffer.readInt(dummy))
1487 }
1488 
1490  if (sizeof(T) <= sizeof(uint32_t)) {
1491  uint32_t Val;
1492  if (GcovBuffer.readInt(Val) && Val <= std::numeric_limits<T>::max())
1493  return static_cast<T>(Val);
1494  } else if (sizeof(T) <= sizeof(uint64_t)) {
1495  uint64_t Val;
1496  if (GcovBuffer.readInt64(Val) && Val <= std::numeric_limits<T>::max())
1497  return static_cast<T>(Val);
1498  }
1499 
1500  std::error_code EC = sampleprof_error::malformed;
1501  reportError(0, EC.message());
1502  return EC;
1503 }
1504 
1506  StringRef Str;
1507  if (!GcovBuffer.readString(Str))
1509  return Str;
1510 }
1511 
1513  // Read the magic identifier.
1514  if (!GcovBuffer.readGCDAFormat())
1516 
1517  // Read the version number. Note - the GCC reader does not validate this
1518  // version, but the profile creator generates v704.
1519  GCOV::GCOVVersion version;
1520  if (!GcovBuffer.readGCOVVersion(version))
1522 
1523  if (version != GCOV::V407)
1525 
1526  // Skip the empty integer.
1527  if (std::error_code EC = skipNextWord())
1528  return EC;
1529 
1531 }
1532 
1534  uint32_t Tag;
1535  if (!GcovBuffer.readInt(Tag))
1537 
1538  if (Tag != Expected)
1540 
1541  if (std::error_code EC = skipNextWord())
1542  return EC;
1543 
1545 }
1546 
1548  if (std::error_code EC = readSectionTag(GCOVTagAFDOFileNames))
1549  return EC;
1550 
1551  uint32_t Size;
1552  if (!GcovBuffer.readInt(Size))
1554 
1555  for (uint32_t I = 0; I < Size; ++I) {
1556  StringRef Str;
1557  if (!GcovBuffer.readString(Str))
1559  Names.push_back(std::string(Str));
1560  }
1561 
1563 }
1564 
1566  if (std::error_code EC = readSectionTag(GCOVTagAFDOFunction))
1567  return EC;
1568 
1569  uint32_t NumFunctions;
1570  if (!GcovBuffer.readInt(NumFunctions))
1572 
1573  InlineCallStack Stack;
1574  for (uint32_t I = 0; I < NumFunctions; ++I)
1575  if (std::error_code EC = readOneFunctionProfile(Stack, true, 0))
1576  return EC;
1577 
1578  computeSummary();
1580 }
1581 
1583  const InlineCallStack &InlineStack, bool Update, uint32_t Offset) {
1584  uint64_t HeadCount = 0;
1585  if (InlineStack.size() == 0)
1586  if (!GcovBuffer.readInt64(HeadCount))
1588 
1589  uint32_t NameIdx;
1590  if (!GcovBuffer.readInt(NameIdx))
1592 
1593  StringRef Name(Names[NameIdx]);
1594 
1595  uint32_t NumPosCounts;
1596  if (!GcovBuffer.readInt(NumPosCounts))
1598 
1599  uint32_t NumCallsites;
1600  if (!GcovBuffer.readInt(NumCallsites))
1602 
1603  FunctionSamples *FProfile = nullptr;
1604  if (InlineStack.size() == 0) {
1605  // If this is a top function that we have already processed, do not
1606  // update its profile again. This happens in the presence of
1607  // function aliases. Since these aliases share the same function
1608  // body, there will be identical replicated profiles for the
1609  // original function. In this case, we simply not bother updating
1610  // the profile of the original function.
1611  FProfile = &Profiles[Name];
1612  FProfile->addHeadSamples(HeadCount);
1613  if (FProfile->getTotalSamples() > 0)
1614  Update = false;
1615  } else {
1616  // Otherwise, we are reading an inlined instance. The top of the
1617  // inline stack contains the profile of the caller. Insert this
1618  // callee in the caller's CallsiteMap.
1619  FunctionSamples *CallerProfile = InlineStack.front();
1620  uint32_t LineOffset = Offset >> 16;
1621  uint32_t Discriminator = Offset & 0xffff;
1622  FProfile = &CallerProfile->functionSamplesAt(
1623  LineLocation(LineOffset, Discriminator))[std::string(Name)];
1624  }
1625  FProfile->setName(Name);
1626 
1627  for (uint32_t I = 0; I < NumPosCounts; ++I) {
1628  uint32_t Offset;
1629  if (!GcovBuffer.readInt(Offset))
1631 
1632  uint32_t NumTargets;
1633  if (!GcovBuffer.readInt(NumTargets))
1635 
1636  uint64_t Count;
1637  if (!GcovBuffer.readInt64(Count))
1639 
1640  // The line location is encoded in the offset as:
1641  // high 16 bits: line offset to the start of the function.
1642  // low 16 bits: discriminator.
1643  uint32_t LineOffset = Offset >> 16;
1644  uint32_t Discriminator = Offset & 0xffff;
1645 
1646  InlineCallStack NewStack;
1647  NewStack.push_back(FProfile);
1648  llvm::append_range(NewStack, InlineStack);
1649  if (Update) {
1650  // Walk up the inline stack, adding the samples on this line to
1651  // the total sample count of the callers in the chain.
1652  for (auto CallerProfile : NewStack)
1653  CallerProfile->addTotalSamples(Count);
1654 
1655  // Update the body samples for the current profile.
1656  FProfile->addBodySamples(LineOffset, Discriminator, Count);
1657  }
1658 
1659  // Process the list of functions called at an indirect call site.
1660  // These are all the targets that a function pointer (or virtual
1661  // function) resolved at runtime.
1662  for (uint32_t J = 0; J < NumTargets; J++) {
1663  uint32_t HistVal;
1664  if (!GcovBuffer.readInt(HistVal))
1666 
1667  if (HistVal != HIST_TYPE_INDIR_CALL_TOPN)
1669 
1670  uint64_t TargetIdx;
1671  if (!GcovBuffer.readInt64(TargetIdx))
1673  StringRef TargetName(Names[TargetIdx]);
1674 
1675  uint64_t TargetCount;
1676  if (!GcovBuffer.readInt64(TargetCount))
1678 
1679  if (Update)
1680  FProfile->addCalledTargetSamples(LineOffset, Discriminator,
1681  TargetName, TargetCount);
1682  }
1683  }
1684 
1685  // Process all the inlined callers into the current function. These
1686  // are all the callsites that were inlined into this function.
1687  for (uint32_t I = 0; I < NumCallsites; I++) {
1688  // The offset is encoded as:
1689  // high 16 bits: line offset to the start of the function.
1690  // low 16 bits: discriminator.
1691  uint32_t Offset;
1692  if (!GcovBuffer.readInt(Offset))
1694  InlineCallStack NewStack;
1695  NewStack.push_back(FProfile);
1696  llvm::append_range(NewStack, InlineStack);
1697  if (std::error_code EC = readOneFunctionProfile(NewStack, Update, Offset))
1698  return EC;
1699  }
1700 
1702 }
1703 
1704 /// Read a GCC AutoFDO profile.
1705 ///
1706 /// This format is generated by the Linux Perf conversion tool at
1707 /// https://github.com/google/autofdo.
1709  assert(!ProfileIsFSDisciminator && "Gcc profiles not support FSDisciminator");
1710  // Read the string table.
1711  if (std::error_code EC = readNameTable())
1712  return EC;
1713 
1714  // Read the source profile.
1715  if (std::error_code EC = readFunctionProfiles())
1716  return EC;
1717 
1719 }
1720 
1722  StringRef Magic(reinterpret_cast<const char *>(Buffer.getBufferStart()));
1723  return Magic == "adcg*704";
1724 }
1725 
1727  // If the reader uses MD5 to represent string, we can't remap it because
1728  // we don't know what the original function names were.
1729  if (Reader.useMD5()) {
1731  Reader.getBuffer()->getBufferIdentifier(),
1732  "Profile data remapping cannot be applied to profile data "
1733  "in compact format (original mangled names are not available).",
1734  DS_Warning));
1735  return;
1736  }
1737 
1738  // CSSPGO-TODO: Remapper is not yet supported.
1739  // We will need to remap the entire context string.
1740  assert(Remappings && "should be initialized while creating remapper");
1741  for (auto &Sample : Reader.getProfiles()) {
1742  DenseSet<StringRef> NamesInSample;
1743  Sample.second.findAllNames(NamesInSample);
1744  for (auto &Name : NamesInSample)
1745  if (auto Key = Remappings->insert(Name))
1746  NameMap.insert({Key, Name});
1747  }
1748 
1749  RemappingApplied = true;
1750 }
1751 
1754  if (auto Key = Remappings->lookup(Fname))
1755  return NameMap.lookup(Key);
1756  return None;
1757 }
1758 
1759 /// Prepare a memory buffer for the contents of \p Filename.
1760 ///
1761 /// \returns an error code indicating the status of the buffer.
1763 setupMemoryBuffer(const Twine &Filename) {
1764  auto BufferOrErr = MemoryBuffer::getFileOrSTDIN(Filename, /*IsText=*/true);
1765  if (std::error_code EC = BufferOrErr.getError())
1766  return EC;
1767  auto Buffer = std::move(BufferOrErr.get());
1768 
1769  // Check the file.
1770  if (uint64_t(Buffer->getBufferSize()) > std::numeric_limits<uint32_t>::max())
1772 
1773  return std::move(Buffer);
1774 }
1775 
1776 /// Create a sample profile reader based on the format of the input file.
1777 ///
1778 /// \param Filename The file to open.
1779 ///
1780 /// \param C The LLVM context to use to emit diagnostics.
1781 ///
1782 /// \param P The FSDiscriminatorPass.
1783 ///
1784 /// \param RemapFilename The file used for profile remapping.
1785 ///
1786 /// \returns an error code indicating the status of the created reader.
1788 SampleProfileReader::create(const std::string Filename, LLVMContext &C,
1790  const std::string RemapFilename) {
1791  auto BufferOrError = setupMemoryBuffer(Filename);
1792  if (std::error_code EC = BufferOrError.getError())
1793  return EC;
1794  return create(BufferOrError.get(), C, P, RemapFilename);
1795 }
1796 
1797 /// Create a sample profile remapper from the given input, to remap the
1798 /// function names in the given profile data.
1799 ///
1800 /// \param Filename The file to open.
1801 ///
1802 /// \param Reader The profile reader the remapper is going to be applied to.
1803 ///
1804 /// \param C The LLVM context to use to emit diagnostics.
1805 ///
1806 /// \returns an error code indicating the status of the created reader.
1809  SampleProfileReader &Reader,
1810  LLVMContext &C) {
1811  auto BufferOrError = setupMemoryBuffer(Filename);
1812  if (std::error_code EC = BufferOrError.getError())
1813  return EC;
1814  return create(BufferOrError.get(), Reader, C);
1815 }
1816 
1817 /// Create a sample profile remapper from the given input, to remap the
1818 /// function names in the given profile data.
1819 ///
1820 /// \param B The memory buffer to create the reader from (assumes ownership).
1821 ///
1822 /// \param C The LLVM context to use to emit diagnostics.
1823 ///
1824 /// \param Reader The profile reader the remapper is going to be applied to.
1825 ///
1826 /// \returns an error code indicating the status of the created reader.
1828 SampleProfileReaderItaniumRemapper::create(std::unique_ptr<MemoryBuffer> &B,
1829  SampleProfileReader &Reader,
1830  LLVMContext &C) {
1831  auto Remappings = std::make_unique<SymbolRemappingReader>();
1832  if (Error E = Remappings->read(*B.get())) {
1834  std::move(E), [&](const SymbolRemappingParseError &ParseError) {
1835  C.diagnose(DiagnosticInfoSampleProfile(B->getBufferIdentifier(),
1836  ParseError.getLineNum(),
1837  ParseError.getMessage()));
1838  });
1840  }
1841 
1842  return std::make_unique<SampleProfileReaderItaniumRemapper>(
1843  std::move(B), std::move(Remappings), Reader);
1844 }
1845 
1846 /// Create a sample profile reader based on the format of the input data.
1847 ///
1848 /// \param B The memory buffer to create the reader from (assumes ownership).
1849 ///
1850 /// \param C The LLVM context to use to emit diagnostics.
1851 ///
1852 /// \param P The FSDiscriminatorPass.
1853 ///
1854 /// \param RemapFilename The file used for profile remapping.
1855 ///
1856 /// \returns an error code indicating the status of the created reader.
1858 SampleProfileReader::create(std::unique_ptr<MemoryBuffer> &B, LLVMContext &C,
1860  const std::string RemapFilename) {
1861  std::unique_ptr<SampleProfileReader> Reader;
1863  Reader.reset(new SampleProfileReaderRawBinary(std::move(B), C));
1865  Reader.reset(new SampleProfileReaderExtBinary(std::move(B), C));
1867  Reader.reset(new SampleProfileReaderCompactBinary(std::move(B), C));
1869  Reader.reset(new SampleProfileReaderGCC(std::move(B), C));
1871  Reader.reset(new SampleProfileReaderText(std::move(B), C));
1872  else
1874 
1875  if (!RemapFilename.empty()) {
1876  auto ReaderOrErr =
1877  SampleProfileReaderItaniumRemapper::create(RemapFilename, *Reader, C);
1878  if (std::error_code EC = ReaderOrErr.getError()) {
1879  std::string Msg = "Could not create remapper: " + EC.message();
1880  C.diagnose(DiagnosticInfoSampleProfile(RemapFilename, Msg));
1881  return EC;
1882  }
1883  Reader->Remapper = std::move(ReaderOrErr.get());
1884  }
1885 
1886  FunctionSamples::Format = Reader->getFormat();
1887  if (std::error_code EC = Reader->readHeader()) {
1888  return EC;
1889  }
1890 
1891  Reader->setDiscriminatorMaskedBitFrom(P);
1892 
1893  return std::move(Reader);
1894 }
1895 
1896 // For text and GCC file formats, we compute the summary after reading the
1897 // profile. Binary format has the profile summary in its header.
1900  Summary = Builder.computeSummaryForProfiles(Profiles);
1901 }
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
llvm::sampleprof::SampleProfileReader::ProfileIsFS
bool ProfileIsFS
Whether the function profiles use FS discriminators.
Definition: SampleProfReader.h:549
i
i
Definition: README.txt:29
MemoryBuffer.h
llvm::sampleprof::SampleProfileReader::dump
void dump(raw_ostream &OS=dbgs())
Print all the profiles on stream OS.
Definition: SampleProfReader.cpp:68
llvm::sampleprof_error::uncompress_failed
@ uncompress_failed
llvm::sampleprof::SampleProfileReaderText
Definition: SampleProfReader.h:564
llvm::StringRef::back
LLVM_NODISCARD char back() const
back - Get the last character in the string.
Definition: StringRef.h:167
llvm::sampleprof::SampleProfileReaderBinary::readNameTable
virtual std::error_code readNameTable()
Read the whole name table.
Definition: SampleProfReader.cpp:995
Compression.h
llvm::sampleprof::SampleProfileReader::CSProfileCount
uint32_t CSProfileCount
Number of context-sensitive profiles.
Definition: SampleProfReader.h:546
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:285
llvm::sampleprof::SampleProfileReaderText::readImpl
std::error_code readImpl() override
Read sample profiles from the associated file.
Definition: SampleProfReader.cpp:242
llvm::sampleprof::SampleProfileReaderItaniumRemapper::create
static ErrorOr< std::unique_ptr< SampleProfileReaderItaniumRemapper > > create(const std::string Filename, SampleProfileReader &Reader, LLVMContext &C)
Create a remapper from the given remapping file.
Definition: SampleProfReader.cpp:1808
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::sampleprof::SecFuncMetadataFlags::SecFlagHasAttribute
@ SecFlagHasAttribute
llvm::sampleprof::SampleProfileReader::M
const Module * M
The current module being compiled if SampleProfileReader is used by compiler.
Definition: SampleProfReader.h:557
llvm::sampleprof::SecProfSummaryFlags::SecFlagFSDiscriminator
@ SecFlagFSDiscriminator
SecFlagFSDiscriminator means this profile uses flow-sensitive discriminators.
llvm::sampleprof::SampleProfileReader::Remapper
std::unique_ptr< SampleProfileReaderItaniumRemapper > Remapper
Definition: SampleProfReader.h:534
llvm::sampleprof::FunctionSamples::ProfileIsProbeBased
static bool ProfileIsProbeBased
Definition: SampleProf.h:1045
llvm::line_iterator
A forward iterator which reads text lines from a buffer.
Definition: LineIterator.h:33
llvm::sampleprof::SampleProfileReaderGCC::readFunctionProfiles
std::error_code readFunctionProfiles()
Definition: SampleProfReader.cpp:1565
T
llvm::StringRef::rfind
LLVM_NODISCARD size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
Definition: StringRef.h:374
llvm::sampleprof::SampleProfileReaderGCC::readSectionTag
std::error_code readSectionTag(uint32_t Expected)
Read the section tag and check that it's the same as Expected.
Definition: SampleProfReader.cpp:1533
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::sampleprof::SecHdrTableEntry
Definition: SampleProf.h:159
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readCSNameTableSec
std::error_code readCSNameTableSec()
Definition: SampleProfReader.cpp:1050
llvm::sampleprof::SecNameTableFlags::SecFlagFixedLengthMD5
@ SecFlagFixedLengthMD5
llvm::StringRef::npos
static constexpr size_t npos
Definition: StringRef.h:59
llvm::sampleprof::SampleProfileReaderBinary::readProfile
std::error_code readProfile(FunctionSamples &FProfile)
Read the contents of the given profile instance.
Definition: SampleProfReader.cpp:504
llvm::StringRef::find
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
Definition: StringRef.h:314
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1177
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readContextFromTable
ErrorOr< SampleContextFrames > readContextFromTable()
Definition: SampleProfReader.cpp:622
llvm::zlib::uncompress
Error uncompress(StringRef InputBuffer, char *UncompressedBuffer, size_t &UncompressedSize)
Definition: Compression.cpp:63
llvm::sampleprof::SecProfSummaryFlags::SecFlagFullContext
@ SecFlagFullContext
SecFlagContext means this is context-sensitive profile for CSSPGO.
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readStringFromTable
virtual ErrorOr< StringRef > readStringFromTable() override
Read a string indirectly via the name table.
Definition: SampleProfReader.cpp:467
llvm::GCOV::GCOVVersion
GCOVVersion
Definition: GCOV.h:45
llvm::sampleprof::SampleProfileReaderGCC::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:1721
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readNameTableSec
std::error_code readNameTableSec(bool IsMD5)
Definition: SampleProfReader.cpp:1040
llvm::SymbolRemappingParseError::getMessage
StringRef getMessage() const
Definition: SymbolRemappingReader.h:83
llvm::sampleprof::SampleContext::toString
std::string toString() const
Definition: SampleProf.h:584
llvm::sampleprof_error::unsupported_version
@ unsupported_version
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::sampleprof::hasSecFlag
static bool hasSecFlag(const SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:265
llvm::sampleprof::SampleProfileReaderItaniumRemapper::applyRemapping
void applyRemapping(LLVMContext &Ctx)
Apply remappings to the profile read by Reader.
Definition: SampleProfReader.cpp:1726
llvm::Depth
@ Depth
Definition: SIMachineScheduler.h:36
llvm::sampleprof::ContextShouldBeInlined
@ ContextShouldBeInlined
Definition: SampleProf.h:413
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
DenseMap.h
llvm::sampleprof::SampleProfileReaderGCC::readNameTable
std::error_code readNameTable()
Definition: SampleProfReader.cpp:1547
llvm::sampleprof::SecFuncOffsetTable
@ SecFuncOffsetTable
Definition: SampleProf.h:126
llvm::AMDGPU::Exp::Target
Target
Definition: SIDefines.h:743
llvm::Optional
Definition: APInt.h:33
llvm::sampleprof::SecCommonFlags::SecFlagCompress
@ SecFlagCompress
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readMD5NameTable
std::error_code readMD5NameTable()
Definition: SampleProfReader.cpp:1010
Offset
uint64_t Offset
Definition: ELFObjHandler.cpp:80
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readSecHdrTableEntry
std::error_code readSecHdrTableEntry(uint32_t Idx)
Definition: SampleProfReader.cpp:1179
llvm::sampleprof::SecNameTableFlags::SecFlagMD5Name
@ SecFlagMD5Name
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readSampleContextFromTable
virtual ErrorOr< SampleContext > readSampleContextFromTable() override
Definition: SampleProfReader.cpp:632
llvm::sampleprof::SampleProfileReader::collectFuncsFromModule
virtual bool collectFuncsFromModule()
Collect functions with definitions in Module M.
Definition: SampleProfReader.h:392
llvm::sampleprof::SampleProfileReader::ProfileIsCSNested
bool ProfileIsCSNested
Whether function profiles are context-sensitive nested profiles.
Definition: SampleProfReader.h:543
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
STLExtras.h
llvm::detail::DenseSetImpl::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::detail::DenseSetImpl::count
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:97
ProfileCommon.h
isOffsetLegal
static bool isOffsetLegal(unsigned L)
Returns true if line offset L is legal (only has 16 bits).
Definition: SampleProfReader.cpp:97
llvm::sampleprof::SampleProfileReader::Summary
std::unique_ptr< ProfileSummary > Summary
Profile summary information.
Definition: SampleProfReader.h:523
llvm::sampleprof::SampleProfileReaderGCC::readOneFunctionProfile
std::error_code readOneFunctionProfile(const InlineCallStack &InlineStack, bool Update, uint32_t Offset)
Definition: SampleProfReader.cpp:1582
llvm::SampleProfileSummaryBuilder
Definition: ProfileCommon.h:88
llvm::MemoryBuffer
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:50
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::sampleprof::SampleProfileReaderGCC::readNumber
ErrorOr< T > readNumber()
Definition: SampleProfReader.cpp:1489
llvm::sampleprof::SampleProfileReaderBinary::readStringFromTable
virtual ErrorOr< StringRef > readStringFromTable()
Read a string indirectly via the name table.
Definition: SampleProfReader.cpp:452
result
It looks like we only need to define PPCfmarto for these because according to these instructions perform RTO on fma s result
Definition: README_P9.txt:256
llvm::sampleprof::FSDiscriminatorPass
FSDiscriminatorPass
Definition: Discriminator.h:57
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::sampleprof::FunctionSamples::HasUniqSuffix
static bool HasUniqSuffix
Whether the profile contains any ".__uniq." suffix in a name.
Definition: SampleProf.h:1061
CommandLine.h
llvm::decodeULEB128
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
Definition: LEB128.h:128
llvm::sampleprof::SampleProfileReader::getDiscriminatorMask
uint32_t getDiscriminatorMask() const
Get the bitmask the discriminators: For FS profiles, return the bit mask for this pass.
Definition: SampleProfReader.h:365
llvm::sampleprof::SecFuncMetadataFlags::SecFlagIsProbeBased
@ SecFlagIsProbeBased
llvm::StringRef::find_last_of
LLVM_NODISCARD size_t find_last_of(char C, size_t From=npos) const
Find the last character in the string that is C, or npos if not found.
Definition: StringRef.h:435
llvm::sampleprof::SampleProfileReaderBinary::NameTable
std::vector< StringRef > NameTable
Function name table.
Definition: SampleProfReader.h:649
llvm::SymbolRemappingParseError::getLineNum
int64_t getLineNum() const
Definition: SymbolRemappingReader.h:82
MD5.h
llvm::sampleprof::SampleProfileReaderCompactBinary::readImpl
std::error_code readImpl() override
Read samples only for functions to use.
Definition: SampleProfReader.cpp:942
llvm::sampleprof::FunctionSamples::getTotalSamples
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Definition: SampleProf.h:818
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::DS_Warning
@ DS_Warning
Definition: DiagnosticInfo.h:47
llvm::sampleprof::FunctionSamples::ProfileIsCSFlat
static bool ProfileIsCSFlat
Definition: SampleProf.h:1047
llvm::sampleprof::SampleProfileReaderRawBinary::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:1461
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::sampleprof::SampleProfileReaderBinary::readFuncProfile
std::error_code readFuncProfile(const uint8_t *Start)
Read the next function profile instance.
Definition: SampleProfReader.cpp:587
llvm::GCOV::V407
@ V407
Definition: GCOV.h:45
llvm::sampleprof::SecProfSummaryFlags::SecFlagPartial
@ SecFlagPartial
SecFlagPartial means the profile is for common/shared code.
llvm::AMDGPU::PALMD::Key
Key
PAL metadata keys.
Definition: AMDGPUMetadata.h:481
llvm::ErrorOr::getError
std::error_code getError() const
Definition: ErrorOr.h:153
SampleProf.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::sampleprof::SampleProfileReaderItaniumRemapper::lookUpNameInProfile
Optional< StringRef > lookUpNameInProfile(StringRef FunctionName)
Return the equivalent name in the profile for FunctionName if it exists.
Definition: SampleProfReader.cpp:1753
llvm::sampleprof::FunctionSamples::Format
static SampleProfileFormat Format
Definition: SampleProf.h:1055
llvm::sampleprof::SampleProfileReaderBinary::readString
ErrorOr< StringRef > readString()
Read a string from the profile.
Definition: SampleProfReader.cpp:413
llvm::sampleprof::SecFuncMetadataFlags::SecFlagIsCSNested
@ SecFlagIsCSNested
llvm::sampleprof::SPMagic
static uint64_t SPMagic(SampleProfileFormat Format=SPF_Binary)
Definition: SampleProf.h:99
LineIterator.h
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
getSecFlagsStr
static std::string getSecFlagsStr(const SecHdrTableEntry &Entry)
Definition: SampleProfReader.cpp:1255
llvm::sampleprof::SampleProfileReaderText::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:376
llvm::ProfileSummary::PSK_Sample
@ PSK_Sample
Definition: ProfileSummary.h:47
llvm::Metadata
Root of the metadata hierarchy.
Definition: Metadata.h:62
llvm::sampleprof::SampleContext
Definition: SampleProf.h:470
llvm::None
const NoneType None
Definition: None.h:23
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
parseMetadata
static bool parseMetadata(const StringRef &Input, uint64_t &FunctionHash, uint32_t &Attributes)
Parse Input that contains metadata.
Definition: SampleProfReader.cpp:106
llvm::sampleprof::sortFuncProfiles
void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
Definition: SampleProf.cpp:208
llvm::sampleprof::FunctionSamples::ProfileIsFS
static bool ProfileIsFS
If this profile uses flow sensitive discriminators.
Definition: SampleProf.h:1064
llvm::StringRef::trim
LLVM_NODISCARD StringRef trim(char Char) const
Return string with consecutive Char characters starting from the left and right removed.
Definition: StringRef.h:869
llvm::DenseSet< uint64_t >
llvm::cl::opt< bool >
llvm::sampleprof::SPF_Compact_Binary
@ SPF_Compact_Binary
Definition: SampleProf.h:93
llvm::sampleprof::SecProfSummary
@ SecProfSummary
Definition: SampleProf.h:123
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
llvm::sampleprof::FunctionSamples::addHeadSamples
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:706
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readSecHdrTable
std::error_code readSecHdrTable()
Definition: SampleProfReader.cpp:1206
uint64_t
setupMemoryBuffer
static ErrorOr< std::unique_ptr< MemoryBuffer > > setupMemoryBuffer(const Twine &Filename)
Prepare a memory buffer for the contents of Filename.
Definition: SampleProfReader.cpp:1763
llvm::sampleprof::SampleProfileReaderExtBinaryBase::getSectionSize
uint64_t getSectionSize(SecType Type)
Get the total size of all Type sections.
Definition: SampleProfReader.cpp:1233
llvm::sampleprof::SampleProfileReaderGCC
Definition: SampleProfReader.h:861
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition: SampleProf.h:689
LEB128.h
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::LLVMContext
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
llvm::sampleprof::SPF_Ext_Binary
@ SPF_Ext_Binary
Definition: SampleProf.h:95
llvm::DenseMap
Definition: DenseMap.h:714
llvm::sampleprof::FunctionSamples::functionSamplesAt
FunctionSamplesMap & functionSamplesAt(const LineLocation &Loc)
Return the function samples at the given callsite location.
Definition: SampleProf.h:792
ErrorOr.h
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::sampleprof::SecLBRProfile
@ SecLBRProfile
Definition: SampleProf.h:131
llvm::sampleprof::FunctionSamples::ProfileIsCSNested
static bool ProfileIsCSNested
Definition: SampleProf.h:1049
I
#define I(x, y, z)
Definition: MD5.cpp:58
SampleProfReader.h
Attributes
AMDGPU Kernel Attributes
Definition: AMDGPULowerKernelAttributes.cpp:254
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:441
llvm::sampleprof::FunctionSamples::setContext
void setContext(const SampleContext &FContext)
Definition: SampleProf.h:1053
Magic
const char Magic[]
Definition: Archive.cpp:41
llvm::sampleprof::FunctionSamples::addCalledTargetSamples
sampleprof_error addCalledTargetSamples(uint32_t LineOffset, uint32_t Discriminator, StringRef FName, uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:720
llvm::sampleprof::SampleProfileReaderBinary::readSampleContextFromTable
virtual ErrorOr< SampleContext > readSampleContextFromTable()
Definition: SampleProfReader.cpp:460
llvm::sampleprof::SampleContext::setAllAttributes
void setAllAttributes(uint32_t A)
Definition: SampleProf.h:562
llvm::sampleprof_error::malformed
@ malformed
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::sampleprof::SampleContext::getName
StringRef getName() const
Definition: SampleProf.h:568
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncMetadata
std::error_code readFuncMetadata(bool ProfileHasAttribute)
Definition: SampleProfReader.cpp:1146
llvm::sampleprof::SampleProfileReaderGCC::readString
ErrorOr< StringRef > readString()
Definition: SampleProfReader.cpp:1505
llvm::StringRef::find_first_not_of
LLVM_NODISCARD size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
Definition: StringRef.cpp:241
llvm::sampleprof::SampleProfileReader::create
static ErrorOr< std::unique_ptr< SampleProfileReader > > create(const std::string Filename, LLVMContext &C, FSDiscriminatorPass P=FSDiscriminatorPass::Base, const std::string RemapFilename="")
Create a sample profile reader appropriate to the file format.
Definition: SampleProfReader.cpp:1788
llvm::zlib::isAvailable
bool isAvailable()
Definition: Compression.cpp:47
llvm::sampleprof::LineLocation
Represents the relative location of an instruction.
Definition: SampleProf.h:281
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:650
llvm::DiagnosticInfoSampleProfile
Diagnostic information for the sample profiler.
Definition: DiagnosticInfo.h:286
llvm::sampleprof::SampleProfileReaderExtBinary
Definition: SampleProfReader.h:792
llvm::sampleprof::SampleProfileReaderBinary::readMagicIdent
std::error_code readMagicIdent()
Read the contents of Magic number and Version number.
Definition: SampleProfReader.cpp:1324
llvm::sampleprof::SampleProfileReaderBinary::End
const uint8_t * End
Points to the end of the buffer.
Definition: SampleProfReader.h:646
llvm::sampleprof::SampleProfileReaderCompactBinary
Definition: SampleProfReader.h:811
llvm::MergeResult
sampleprof_error MergeResult(sampleprof_error &Accumulator, sampleprof_error Result)
Definition: SampleProf.h:68
isDigit
static bool isDigit(const char C)
Definition: RustDemangle.cpp:206
LineType::CallSiteProfile
@ CallSiteProfile
llvm::sampleprof::SampleContext::IsPrefixOf
bool IsPrefixOf(const SampleContext &That) const
Definition: SampleProf.h:646
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readImpl
std::error_code readImpl() override
Read sample profiles in extensible format from the associated file.
Definition: SampleProfReader.cpp:896
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm::sampleprof_error::unrecognized_format
@ unrecognized_format
uint32_t
llvm::sampleprof::FunctionSamples::addBodySamples
sampleprof_error addBodySamples(uint32_t LineOffset, uint32_t Discriminator, uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:714
llvm::append_range
void append_range(Container &C, Range &&R)
Wrapper function to append a range to a container.
Definition: STLExtras.h:1846
llvm::sampleprof::SampleProfileReader::reportError
void reportError(int64_t LineNumber, const Twine &Msg) const
Report a parse error message.
Definition: SampleProfReader.h:444
llvm::sampleprof::SampleProfileReader::computeSummary
void computeSummary()
Compute summary for this profile.
Definition: SampleProfReader.cpp:1898
llvm::sampleprof::SecFuncOffsetFlags::SecFlagOrdered
@ SecFlagOrdered
llvm::sampleprof::SampleContextFrameVector
SmallVector< SampleContextFrame, 10 > SampleContextFrameVector
Definition: SampleProf.h:451
llvm::sampleprof::getSecName
static std::string getSecName(SecType Type)
Definition: SampleProf.h:134
llvm::sampleprof::SampleProfileReaderRawBinary
Definition: SampleProfReader.h:660
ParseHead
static bool ParseHead(const StringRef &Input, StringRef &FName, uint64_t &NumSamples, uint64_t &NumHeadSamples)
Parse Input as function head.
Definition: SampleProfReader.cpp:82
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:156
llvm::LLVMContext::diagnose
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
Definition: LLVMContext.cpp:228
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
llvm::sampleprof::SampleProfileReader::Profiles
SampleProfileMap Profiles
Map every function to its associated profile.
Definition: SampleProfReader.h:510
llvm::sampleprof::SampleProfileReaderGCC::skipNextWord
std::error_code skipNextWord()
Definition: SampleProfReader.cpp:1482
llvm::sampleprof::SPVersion
static uint64_t SPVersion()
Definition: SampleProf.h:116
llvm::sampleprof::SampleProfileReaderBinary::readSummary
std::error_code readSummary()
Read profile summary.
Definition: SampleProfReader.cpp:1423
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:157
llvm::sampleprof::SampleProfileReaderGCC::readHeader
std::error_code readHeader() override
Read and validate the file header.
Definition: SampleProfReader.cpp:1512
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:517
llvm::sampleprof::SecProfileSymbolList
@ SecProfileSymbolList
Definition: SampleProf.h:125
llvm::sampleprof::FunctionSamples::addTotalSamples
sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:696
llvm::sampleprof::SecType
SecType
Definition: SampleProf.h:121
LineType
LineType
Definition: SampleProfReader.cpp:121
llvm::sampleprof::SampleProfileReader
Sample-based profile reader.
Definition: SampleProfReader.h:345
llvm::sampleprof::SampleProfileReaderExtBinaryBase::getFileSize
uint64_t getFileSize()
Get the total size of header and all sections.
Definition: SampleProfReader.cpp:1242
llvm::sampleprof_error
sampleprof_error
Definition: SampleProf.h:45
llvm::SmallVectorImpl::clear
void clear()
Definition: SmallVector.h:581
llvm::sampleprof_error::zlib_unavailable
@ zlib_unavailable
llvm::sampleprof::SampleContext::hasContext
bool hasContext() const
Definition: SampleProf.h:566
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readHeader
virtual std::error_code readHeader() override
Read and validate the file header.
Definition: SampleProfReader.cpp:1218
llvm::sampleprof_error::too_large
@ too_large
llvm::line_iterator::is_at_eof
bool is_at_eof() const
Return true if we've reached EOF or are an "end" iterator.
Definition: LineIterator.h:60
llvm::sampleprof::HIST_TYPE_INDIR_CALL_TOPN
@ HIST_TYPE_INDIR_CALL_TOPN
Definition: SampleProfReader.h:858
llvm::sampleprof::FunctionSamples::getContext
SampleContext & getContext() const
Definition: SampleProf.h:1051
llvm::sampleprof_error::success
@ success
llvm::sampleprof::SecNameTableFlags::SecFlagUniqSuffix
@ SecFlagUniqSuffix
llvm::sampleprof::SampleProfileReaderBinary::readUnencodedNumber
ErrorOr< T > readUnencodedNumber()
Read a numeric value of type T from the profile.
Definition: SampleProfReader.cpp:427
llvm::line_iterator::line_number
int64_t line_number() const
Return the current line number. May return any number at EOF.
Definition: LineIterator.h:66
llvm::sampleprof::FunctionSamples::getCanonicalFnName
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
Definition: SampleProf.h:955
llvm::sampleprof::SampleProfileReaderBinary::readNumber
ErrorOr< T > readNumber()
Read a numeric value of type T from the profile.
Definition: SampleProfReader.cpp:392
llvm::sampleprof::SampleProfileReaderBinary::readImpl
std::error_code readImpl() override
Read sample profiles from the associated file.
Definition: SampleProfReader.cpp:610
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncProfiles
std::error_code readFuncProfiles()
Definition: SampleProfReader.cpp:756
llvm::sampleprof::SampleProfileReader::Ctx
LLVMContext & Ctx
LLVM context used to emit diagnostics.
Definition: SampleProfReader.h:513
Version
uint64_t Version
Definition: RawMemProfReader.cpp:25
Allocator
Basic Register Allocator
Definition: RegAllocBasic.cpp:146
llvm::sampleprof::SecCommonFlags::SecFlagFlat
@ SecFlagFlat
llvm::sampleprof::SampleProfileReaderCompactBinary::collectFuncsFromModule
bool collectFuncsFromModule() override
Collect functions with definitions in Module M.
Definition: SampleProfReader.cpp:1396
llvm::sampleprof::SecCSNameTable
@ SecCSNameTable
Definition: SampleProf.h:128
LineType::Metadata
@ Metadata
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::sampleprof::SampleProfileReader::useMD5
virtual bool useMD5()
Return whether names in the profile are all MD5 numbers.
Definition: SampleProfReader.h:492
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:87
llvm::sampleprof::SampleProfileReader::ProfileIsCSFlat
bool ProfileIsCSFlat
Whether function profiles are context-sensitive flat profiles.
Definition: SampleProfReader.h:540
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::sampleprof::SampleProfileReaderExtBinaryBase::readOneSection
virtual std::error_code readOneSection(const uint8_t *Start, uint64_t Size, const SecHdrTableEntry &Entry)
Definition: SampleProfReader.cpp:646
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readFuncOffsetTable
std::error_code readFuncOffsetTable()
Definition: SampleProfReader.cpp:721
llvm::SymbolRemappingParseError
Definition: SymbolRemappingReader.h:69
llvm::sampleprof::SampleProfileReader::dumpFunctionProfile
void dumpFunctionProfile(SampleContext FContext, raw_ostream &OS=dbgs())
Print the profile for FContext on stream OS.
Definition: SampleProfReader.cpp:62
llvm::sampleprof::SecNameTable
@ SecNameTable
Definition: SampleProf.h:124
llvm::BTF::HeaderSize
@ HeaderSize
Definition: BTF.h:58
ParseLine
static bool ParseLine(const StringRef &Input, LineType &LineTy, uint32_t &Depth, uint64_t &NumSamples, uint32_t &LineOffset, uint32_t &Discriminator, StringRef &CalleeName, DenseMap< StringRef, uint64_t > &TargetCountMap, uint64_t &FunctionHash, uint32_t &Attributes)
Parse Input as line sample.
Definition: SampleProfReader.cpp:139
llvm::sampleprof::SampleProfileReaderExtBinaryBase::readProfileSymbolList
std::error_code readProfileSymbolList()
Definition: SampleProfReader.cpp:856
llvm::sampleprof::SampleProfileReaderCompactBinary::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:1475
llvm::sampleprof::SecFuncMetadata
@ SecFuncMetadata
Definition: SampleProf.h:127
llvm::StringRef::find_first_of
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
Definition: StringRef.h:409
llvm::sampleprof_error::truncated_name_table
@ truncated_name_table
LineType::BodyProfile
@ BodyProfile
llvm::sampleprof::SampleProfileReaderExtBinaryBase::dumpSectionInfo
virtual bool dumpSectionInfo(raw_ostream &OS=dbgs()) override
Definition: SampleProfReader.cpp:1305
llvm::cl::desc
Definition: CommandLine.h:412
raw_ostream.h
ProfileIsFSDisciminator
static cl::opt< bool > ProfileIsFSDisciminator("profile-isfs", cl::Hidden, cl::init(false), cl::desc("Profile uses flow sensitive discriminators"))
llvm::sampleprof::SampleProfileReaderExtBinary::hasFormat
static bool hasFormat(const MemoryBuffer &Buffer)
Return true if Buffer is in the format supported by this class.
Definition: SampleProfReader.cpp:1468
llvm::sampleprof::SampleProfileReaderGCC::readImpl
std::error_code readImpl() override
Read sample profiles from the associated file.
Definition: SampleProfReader.cpp:1708
llvm::sampleprof::SampleProfileReaderBinary::readStringIndex
ErrorOr< uint32_t > readStringIndex(T &Table)
Read the string index and check whether it overflows the table.
Definition: SampleProfReader.cpp:442
llvm::ProfileSummaryBuilder::DefaultCutoffs
static const ArrayRef< uint32_t > DefaultCutoffs
A vector of useful cutoff values for detailed summary.
Definition: ProfileCommon.h:65
llvm::handleAllErrors
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition: Error.h:968
llvm::sampleprof_error::truncated
@ truncated
llvm::sampleprof::SampleProfileReaderBinary::Data
const uint8_t * Data
Points to the current location in the buffer.
Definition: SampleProfReader.h:643
llvm::sampleprof::SampleProfileReaderBinary::readHeader
virtual std::error_code readHeader() override
Read and validate the file header.
Definition: SampleProfReader.cpp:1342
llvm::sampleprof::SampleProfileReader::Buffer
std::unique_ptr< MemoryBuffer > Buffer
Memory buffer holding the profile file.
Definition: SampleProfReader.h:516
llvm::sampleprof_error::bad_magic
@ bad_magic
llvm::sampleprof::FunctionSamples::setFunctionHash
void setFunctionHash(uint64_t Hash)
Definition: SampleProf.h:949
llvm::MD5Hash
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.
Definition: MD5.h:122
llvm::sampleprof::SampleProfileReaderExtBinaryBase::collectFuncsFromModule
bool collectFuncsFromModule() override
Collect functions with definitions in Module M.
Definition: SampleProfReader.cpp:712
llvm::sampleprof::SampleProfileReader::ProfileIsProbeBased
bool ProfileIsProbeBased
Whether samples are collected based on pseudo probes.
Definition: SampleProfReader.h:537
llvm::sampleprof::SampleProfileReaderBinary::at_eof
bool at_eof() const
Return true if we've reached the end of file.
Definition: SampleProfReader.h:625
llvm::sampleprof::FunctionSamples::setName
void setName(StringRef FunctionName)
Set the name of the function.
Definition: SampleProf.h:941