LLVM  16.0.0git
SampleProf.h
Go to the documentation of this file.
1 //===- SampleProf.h - Sampling profiling format support ---------*- C++ -*-===//
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 common definitions used in the reading and writing of
10 // sample profile data.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_PROFILEDATA_SAMPLEPROF_H
15 #define LLVM_PROFILEDATA_SAMPLEPROF_H
16 
17 #include "llvm/ADT/DenseSet.h"
18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringExtras.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/IR/GlobalValue.h"
24 #include "llvm/Support/Allocator.h"
25 #include "llvm/Support/Debug.h"
26 #include "llvm/Support/ErrorOr.h"
28 #include <algorithm>
29 #include <cstdint>
30 #include <list>
31 #include <map>
32 #include <set>
33 #include <sstream>
34 #include <string>
35 #include <system_error>
36 #include <unordered_map>
37 #include <utility>
38 
39 namespace llvm {
40 
41 class DILocation;
42 class raw_ostream;
43 
44 const std::error_category &sampleprof_category();
45 
46 enum class sampleprof_error {
47  success = 0,
48  bad_magic,
50  too_large,
51  truncated,
52  malformed,
62 };
63 
64 inline std::error_code make_error_code(sampleprof_error E) {
65  return std::error_code(static_cast<int>(E), sampleprof_category());
66 }
67 
69  sampleprof_error Result) {
70  // Prefer first error encountered as later errors may be secondary effects of
71  // the initial problem.
73  Result != sampleprof_error::success)
74  Accumulator = Result;
75  return Accumulator;
76 }
77 
78 } // end namespace llvm
79 
80 namespace std {
81 
82 template <>
83 struct is_error_code_enum<llvm::sampleprof_error> : std::true_type {};
84 
85 } // end namespace std
86 
87 namespace llvm {
88 namespace sampleprof {
89 
91  SPF_None = 0,
92  SPF_Text = 0x1,
94  SPF_GCC = 0x3,
96  SPF_Binary = 0xff
97 };
98 
100  return uint64_t('S') << (64 - 8) | uint64_t('P') << (64 - 16) |
101  uint64_t('R') << (64 - 24) | uint64_t('O') << (64 - 32) |
102  uint64_t('F') << (64 - 40) | uint64_t('4') << (64 - 48) |
103  uint64_t('2') << (64 - 56) | uint64_t(Format);
104 }
105 
106 /// Get the proper representation of a string according to whether the
107 /// current Format uses MD5 to represent the string.
108 static inline StringRef getRepInFormat(StringRef Name, bool UseMD5,
109  std::string &GUIDBuf) {
110  if (Name.empty() || !UseMD5)
111  return Name;
113  return GUIDBuf;
114 }
115 
116 static inline uint64_t SPVersion() { return 103; }
117 
118 // Section Type used by SampleProfileExtBinaryBaseReader and
119 // SampleProfileExtBinaryBaseWriter. Never change the existing
120 // value of enum. Only append new ones.
121 enum SecType {
129  // marker for the first type of profile.
132 };
133 
134 static inline std::string getSecName(SecType Type) {
135  switch ((int)Type) { // Avoid -Wcovered-switch-default
136  case SecInValid:
137  return "InvalidSection";
138  case SecProfSummary:
139  return "ProfileSummarySection";
140  case SecNameTable:
141  return "NameTableSection";
143  return "ProfileSymbolListSection";
144  case SecFuncOffsetTable:
145  return "FuncOffsetTableSection";
146  case SecFuncMetadata:
147  return "FunctionMetadata";
148  case SecCSNameTable:
149  return "CSNameTableSection";
150  case SecLBRProfile:
151  return "LBRProfileSection";
152  default:
153  return "UnknownSection";
154  }
155 }
156 
157 // Entry type of section header table used by SampleProfileExtBinaryBaseReader
158 // and SampleProfileExtBinaryBaseWriter.
164  // The index indicating the location of the current entry in
165  // SectionHdrLayout table.
167 };
168 
169 // Flags common for all sections are defined here. In SecHdrTableEntry::Flags,
170 // common flags will be saved in the lower 32bits and section specific flags
171 // will be saved in the higher 32 bits.
172 enum class SecCommonFlags : uint32_t {
173  SecFlagInValid = 0,
174  SecFlagCompress = (1 << 0),
175  // Indicate the section contains only profile without context.
176  SecFlagFlat = (1 << 1)
177 };
178 
179 // Section specific flags are defined here.
180 // !!!Note: Everytime a new enum class is created here, please add
181 // a new check in verifySecFlag.
183  SecFlagInValid = 0,
184  SecFlagMD5Name = (1 << 0),
185  // Store MD5 in fixed length instead of ULEB128 so NameTable can be
186  // accessed like an array.
187  SecFlagFixedLengthMD5 = (1 << 1),
188  // Profile contains ".__uniq." suffix name. Compiler shouldn't strip
189  // the suffix when doing profile matching when seeing the flag.
190  SecFlagUniqSuffix = (1 << 2)
191 };
193  SecFlagInValid = 0,
194  /// SecFlagPartial means the profile is for common/shared code.
195  /// The common profile is usually merged from profiles collected
196  /// from running other targets.
197  SecFlagPartial = (1 << 0),
198  /// SecFlagContext means this is context-sensitive flat profile for
199  /// CSSPGO
200  SecFlagFullContext = (1 << 1),
201  /// SecFlagFSDiscriminator means this profile uses flow-sensitive
202  /// discriminators.
203  SecFlagFSDiscriminator = (1 << 2),
204  /// SecFlagIsPreInlined means this profile contains ShouldBeInlined
205  /// contexts thus this is CS preinliner computed.
206  SecFlagIsPreInlined = (1 << 4),
207 };
208 
210  SecFlagInvalid = 0,
211  SecFlagIsProbeBased = (1 << 0),
212  SecFlagHasAttribute = (1 << 1),
213 };
214 
216  SecFlagInvalid = 0,
217  // Store function offsets in an order of contexts. The order ensures that
218  // callee contexts of a given context laid out next to it.
219  SecFlagOrdered = (1 << 0),
220 };
221 
222 // Verify section specific flag is used for the correct section.
223 template <class SecFlagType>
224 static inline void verifySecFlag(SecType Type, SecFlagType Flag) {
225  // No verification is needed for common flags.
226  if (std::is_same<SecCommonFlags, SecFlagType>())
227  return;
228 
229  // Verification starts here for section specific flag.
230  bool IsFlagLegal = false;
231  switch (Type) {
232  case SecNameTable:
233  IsFlagLegal = std::is_same<SecNameTableFlags, SecFlagType>();
234  break;
235  case SecProfSummary:
236  IsFlagLegal = std::is_same<SecProfSummaryFlags, SecFlagType>();
237  break;
238  case SecFuncMetadata:
239  IsFlagLegal = std::is_same<SecFuncMetadataFlags, SecFlagType>();
240  break;
241  default:
242  case SecFuncOffsetTable:
243  IsFlagLegal = std::is_same<SecFuncOffsetFlags, SecFlagType>();
244  break;
245  }
246  if (!IsFlagLegal)
247  llvm_unreachable("Misuse of a flag in an incompatible section");
248 }
249 
250 template <class SecFlagType>
251 static inline void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag) {
252  verifySecFlag(Entry.Type, Flag);
253  auto FVal = static_cast<uint64_t>(Flag);
254  bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
255  Entry.Flags |= IsCommon ? FVal : (FVal << 32);
256 }
257 
258 template <class SecFlagType>
259 static inline void removeSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag) {
260  verifySecFlag(Entry.Type, Flag);
261  auto FVal = static_cast<uint64_t>(Flag);
262  bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
263  Entry.Flags &= ~(IsCommon ? FVal : (FVal << 32));
264 }
265 
266 template <class SecFlagType>
267 static inline bool hasSecFlag(const SecHdrTableEntry &Entry, SecFlagType Flag) {
268  verifySecFlag(Entry.Type, Flag);
269  auto FVal = static_cast<uint64_t>(Flag);
270  bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
271  return Entry.Flags & (IsCommon ? FVal : (FVal << 32));
272 }
273 
274 /// Represents the relative location of an instruction.
275 ///
276 /// Instruction locations are specified by the line offset from the
277 /// beginning of the function (marked by the line where the function
278 /// header is) and the discriminator value within that line.
279 ///
280 /// The discriminator value is useful to distinguish instructions
281 /// that are on the same line but belong to different basic blocks
282 /// (e.g., the two post-increment instructions in "if (p) x++; else y++;").
283 struct LineLocation {
285 
286  void print(raw_ostream &OS) const;
287  void dump() const;
288 
289  bool operator<(const LineLocation &O) const {
290  return LineOffset < O.LineOffset ||
291  (LineOffset == O.LineOffset && Discriminator < O.Discriminator);
292  }
293 
294  bool operator==(const LineLocation &O) const {
295  return LineOffset == O.LineOffset && Discriminator == O.Discriminator;
296  }
297 
298  bool operator!=(const LineLocation &O) const {
299  return LineOffset != O.LineOffset || Discriminator != O.Discriminator;
300  }
301 
304 };
305 
307 
308 /// Representation of a single sample record.
309 ///
310 /// A sample record is represented by a positive integer value, which
311 /// indicates how frequently was the associated line location executed.
312 ///
313 /// Additionally, if the associated location contains a function call,
314 /// the record will hold a list of all the possible called targets. For
315 /// direct calls, this will be the exact function being invoked. For
316 /// indirect calls (function pointers, virtual table dispatch), this
317 /// will be a list of one or more functions.
319 public:
320  using CallTarget = std::pair<StringRef, uint64_t>;
322  bool operator()(const CallTarget &LHS, const CallTarget &RHS) const {
323  if (LHS.second != RHS.second)
324  return LHS.second > RHS.second;
325 
326  return LHS.first < RHS.first;
327  }
328  };
329 
330  using SortedCallTargetSet = std::set<CallTarget, CallTargetComparator>;
332  SampleRecord() = default;
333 
334  /// Increment the number of samples for this record by \p S.
335  /// Optionally scale sample count \p S by \p Weight.
336  ///
337  /// Sample counts accumulate using saturating arithmetic, to avoid wrapping
338  /// around unsigned integers.
340  bool Overflowed;
341  NumSamples = SaturatingMultiplyAdd(S, Weight, NumSamples, &Overflowed);
342  return Overflowed ? sampleprof_error::counter_overflow
344  }
345 
346  /// Decrease the number of samples for this record by \p S. Return the amout
347  /// of samples actually decreased.
349  if (S > NumSamples)
350  S = NumSamples;
351  NumSamples -= S;
352  return S;
353  }
354 
355  /// Add called function \p F with samples \p S.
356  /// Optionally scale sample count \p S by \p Weight.
357  ///
358  /// Sample counts accumulate using saturating arithmetic, to avoid wrapping
359  /// around unsigned integers.
361  uint64_t Weight = 1) {
362  uint64_t &TargetSamples = CallTargets[F];
363  bool Overflowed;
364  TargetSamples =
365  SaturatingMultiplyAdd(S, Weight, TargetSamples, &Overflowed);
366  return Overflowed ? sampleprof_error::counter_overflow
368  }
369 
370  /// Remove called function from the call target map. Return the target sample
371  /// count of the called function.
373  uint64_t Count = 0;
374  auto I = CallTargets.find(F);
375  if (I != CallTargets.end()) {
376  Count = I->second;
377  CallTargets.erase(I);
378  }
379  return Count;
380  }
381 
382  /// Return true if this sample record contains function calls.
383  bool hasCalls() const { return !CallTargets.empty(); }
384 
385  uint64_t getSamples() const { return NumSamples; }
386  const CallTargetMap &getCallTargets() const { return CallTargets; }
388  return SortCallTargets(CallTargets);
389  }
390 
392  uint64_t Sum = 0;
393  for (const auto &I : CallTargets)
394  Sum += I.second;
395  return Sum;
396  }
397 
398  /// Sort call targets in descending order of call frequency.
399  static const SortedCallTargetSet SortCallTargets(const CallTargetMap &Targets) {
400  SortedCallTargetSet SortedTargets;
401  for (const auto &I : Targets) {
402  SortedTargets.emplace(I.first(), I.second);
403  }
404  return SortedTargets;
405  }
406 
407  /// Prorate call targets by a distribution factor.
408  static const CallTargetMap adjustCallTargets(const CallTargetMap &Targets,
409  float DistributionFactor) {
410  CallTargetMap AdjustedTargets;
411  for (const auto &I : Targets) {
412  AdjustedTargets[I.first()] = I.second * DistributionFactor;
413  }
414  return AdjustedTargets;
415  }
416 
417  /// Merge the samples in \p Other into this record.
418  /// Optionally scale sample counts by \p Weight.
419  sampleprof_error merge(const SampleRecord &Other, uint64_t Weight = 1);
420  void print(raw_ostream &OS, unsigned Indent) const;
421  void dump() const;
422 
423 private:
424  uint64_t NumSamples = 0;
425  CallTargetMap CallTargets;
426 };
427 
428 raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample);
429 
430 // State of context associated with FunctionSamples
432  UnknownContext = 0x0, // Profile without context
433  RawContext = 0x1, // Full context profile from input profile
434  SyntheticContext = 0x2, // Synthetic context created for context promotion
435  InlinedContext = 0x4, // Profile for context that is inlined into caller
436  MergedContext = 0x8 // Profile for context merged into base profile
437 };
438 
439 // Attribute of context associated with FunctionSamples
441  ContextNone = 0x0,
442  ContextWasInlined = 0x1, // Leaf of context was inlined in previous build
443  ContextShouldBeInlined = 0x2, // Leaf of context should be inlined
445  0x4, // Leaf of context is duplicated into the base profile
446 };
447 
448 // Represents a context frame with function name and line location
452 
454 
457 
458  bool operator==(const SampleContextFrame &That) const {
459  return Location == That.Location && FuncName == That.FuncName;
460  }
461 
462  bool operator!=(const SampleContextFrame &That) const {
463  return !(*this == That);
464  }
465 
466  std::string toString(bool OutputLineLocation) const {
467  std::ostringstream OContextStr;
468  OContextStr << FuncName.str();
469  if (OutputLineLocation) {
470  OContextStr << ":" << Location.LineOffset;
472  OContextStr << "." << Location.Discriminator;
473  }
474  return OContextStr.str();
475  }
476 };
477 
478 static inline hash_code hash_value(const SampleContextFrame &arg) {
479  return hash_combine(arg.FuncName, arg.Location.LineOffset,
480  arg.Location.Discriminator);
481 }
482 
485 
488  return hash_combine_range(S.begin(), S.end());
489  }
490 };
491 
492 // Sample context for FunctionSamples. It consists of the calling context,
493 // the function name and context state. Internally sample context is represented
494 // using ArrayRef, which is also the input for constructing a `SampleContext`.
495 // It can accept and represent both full context string as well as context-less
496 // function name.
497 // For a CS profile, a full context vector can look like:
498 // `main:3 _Z5funcAi:1 _Z8funcLeafi`
499 // For a base CS profile without calling context, the context vector should only
500 // contain the leaf frame name.
501 // For a non-CS profile, the context vector should be empty.
503 public:
504  SampleContext() : State(UnknownContext), Attributes(ContextNone) {}
505 
507  : Name(Name), State(UnknownContext), Attributes(ContextNone) {}
508 
510  ContextStateMask CState = RawContext)
511  : Attributes(ContextNone) {
512  assert(!Context.empty() && "Context is empty");
513  setContext(Context, CState);
514  }
515 
516  // Give a context string, decode and populate internal states like
517  // Function name, Calling context and context state. Example of input
518  // `ContextStr`: `[main:3 @ _Z5funcAi:1 @ _Z8funcLeafi]`
520  std::list<SampleContextFrameVector> &CSNameTable,
521  ContextStateMask CState = RawContext)
522  : Attributes(ContextNone) {
523  assert(!ContextStr.empty());
524  // Note that `[]` wrapped input indicates a full context string, otherwise
525  // it's treated as context-less function name only.
526  bool HasContext = ContextStr.startswith("[");
527  if (!HasContext) {
528  State = UnknownContext;
529  Name = ContextStr;
530  } else {
531  CSNameTable.emplace_back();
532  SampleContextFrameVector &Context = CSNameTable.back();
533  createCtxVectorFromStr(ContextStr, Context);
534  setContext(Context, CState);
535  }
536  }
537 
538  /// Create a context vector from a given context string and save it in
539  /// `Context`.
540  static void createCtxVectorFromStr(StringRef ContextStr,
542  // Remove encapsulating '[' and ']' if any
543  ContextStr = ContextStr.substr(1, ContextStr.size() - 2);
544  StringRef ContextRemain = ContextStr;
545  StringRef ChildContext;
546  StringRef CalleeName;
547  while (!ContextRemain.empty()) {
548  auto ContextSplit = ContextRemain.split(" @ ");
549  ChildContext = ContextSplit.first;
550  ContextRemain = ContextSplit.second;
551  LineLocation CallSiteLoc(0, 0);
552  decodeContextString(ChildContext, CalleeName, CallSiteLoc);
553  Context.emplace_back(CalleeName, CallSiteLoc);
554  }
555  }
556 
557  // Decode context string for a frame to get function name and location.
558  // `ContextStr` is in the form of `FuncName:StartLine.Discriminator`.
559  static void decodeContextString(StringRef ContextStr, StringRef &FName,
560  LineLocation &LineLoc) {
561  // Get function name
562  auto EntrySplit = ContextStr.split(':');
563  FName = EntrySplit.first;
564 
565  LineLoc = {0, 0};
566  if (!EntrySplit.second.empty()) {
567  // Get line offset, use signed int for getAsInteger so string will
568  // be parsed as signed.
569  int LineOffset = 0;
570  auto LocSplit = EntrySplit.second.split('.');
571  LocSplit.first.getAsInteger(10, LineOffset);
572  LineLoc.LineOffset = LineOffset;
573 
574  // Get discriminator
575  if (!LocSplit.second.empty())
576  LocSplit.second.getAsInteger(10, LineLoc.Discriminator);
577  }
578  }
579 
580  operator SampleContextFrames() const { return FullContext; }
581  bool hasAttribute(ContextAttributeMask A) { return Attributes & (uint32_t)A; }
582  void setAttribute(ContextAttributeMask A) { Attributes |= (uint32_t)A; }
583  uint32_t getAllAttributes() { return Attributes; }
584  void setAllAttributes(uint32_t A) { Attributes = A; }
585  bool hasState(ContextStateMask S) { return State & (uint32_t)S; }
586  void setState(ContextStateMask S) { State |= (uint32_t)S; }
587  void clearState(ContextStateMask S) { State &= (uint32_t)~S; }
588  bool hasContext() const { return State != UnknownContext; }
589  bool isBaseContext() const { return FullContext.size() == 1; }
590  StringRef getName() const { return Name; }
591  SampleContextFrames getContextFrames() const { return FullContext; }
592 
594  bool IncludeLeafLineLocation = false) {
595  std::ostringstream OContextStr;
596  for (uint32_t I = 0; I < Context.size(); I++) {
597  if (OContextStr.str().size()) {
598  OContextStr << " @ ";
599  }
600  OContextStr << Context[I].toString(I != Context.size() - 1 ||
601  IncludeLeafLineLocation);
602  }
603  return OContextStr.str();
604  }
605 
606  std::string toString() const {
607  if (!hasContext())
608  return Name.str();
609  return getContextString(FullContext, false);
610  }
611 
614  : hash_value(getName());
615  }
616 
617  /// Set the name of the function and clear the current context.
618  void setName(StringRef FunctionName) {
619  Name = FunctionName;
620  FullContext = SampleContextFrames();
621  State = UnknownContext;
622  }
623 
625  ContextStateMask CState = RawContext) {
626  assert(CState != UnknownContext);
627  FullContext = Context;
628  Name = Context.back().FuncName;
629  State = CState;
630  }
631 
632  bool operator==(const SampleContext &That) const {
633  return State == That.State && Name == That.Name &&
634  FullContext == That.FullContext;
635  }
636 
637  bool operator!=(const SampleContext &That) const { return !(*this == That); }
638 
639  bool operator<(const SampleContext &That) const {
640  if (State != That.State)
641  return State < That.State;
642 
643  if (!hasContext()) {
644  return (Name.compare(That.Name)) == -1;
645  }
646 
647  uint64_t I = 0;
648  while (I < std::min(FullContext.size(), That.FullContext.size())) {
649  auto &Context1 = FullContext[I];
650  auto &Context2 = That.FullContext[I];
651  auto V = Context1.FuncName.compare(Context2.FuncName);
652  if (V)
653  return V == -1;
654  if (Context1.Location != Context2.Location)
655  return Context1.Location < Context2.Location;
656  I++;
657  }
658 
659  return FullContext.size() < That.FullContext.size();
660  }
661 
662  struct Hash {
664  return Context.getHashCode();
665  }
666  };
667 
668  bool IsPrefixOf(const SampleContext &That) const {
669  auto ThisContext = FullContext;
670  auto ThatContext = That.FullContext;
671  if (ThatContext.size() < ThisContext.size())
672  return false;
673  ThatContext = ThatContext.take_front(ThisContext.size());
674  // Compare Leaf frame first
675  if (ThisContext.back().FuncName != ThatContext.back().FuncName)
676  return false;
677  // Compare leading context
678  return ThisContext.drop_back() == ThatContext.drop_back();
679  }
680 
681 private:
682  /// Mangled name of the function.
683  StringRef Name;
684  // Full context including calling context and leaf function name
685  SampleContextFrames FullContext;
686  // State of the associated sample profile
687  uint32_t State;
688  // Attribute of the associated sample profile
689  uint32_t Attributes;
690 };
691 
692 static inline hash_code hash_value(const SampleContext &arg) {
693  return arg.hasContext() ? hash_value(arg.getContextFrames())
694  : hash_value(arg.getName());
695 }
696 
697 class FunctionSamples;
699 
700 using BodySampleMap = std::map<LineLocation, SampleRecord>;
701 // NOTE: Using a StringMap here makes parsed profiles consume around 17% more
702 // memory, which is *very* significant for large profiles.
703 using FunctionSamplesMap = std::map<std::string, FunctionSamples, std::less<>>;
704 using CallsiteSampleMap = std::map<LineLocation, FunctionSamplesMap>;
705 
706 /// Representation of the samples collected for a function.
707 ///
708 /// This data structure contains all the collected samples for the body
709 /// of a function. Each sample corresponds to a LineLocation instance
710 /// within the body of the function.
712 public:
713  FunctionSamples() = default;
714 
715  void print(raw_ostream &OS = dbgs(), unsigned Indent = 0) const;
716  void dump() const;
717 
719  bool Overflowed;
720  TotalSamples =
721  SaturatingMultiplyAdd(Num, Weight, TotalSamples, &Overflowed);
722  return Overflowed ? sampleprof_error::counter_overflow
724  }
725 
727  if (TotalSamples < Num)
728  TotalSamples = 0;
729  else
730  TotalSamples -= Num;
731  }
732 
733  void setTotalSamples(uint64_t Num) { TotalSamples = Num; }
734 
736  bool Overflowed;
737  TotalHeadSamples =
738  SaturatingMultiplyAdd(Num, Weight, TotalHeadSamples, &Overflowed);
739  return Overflowed ? sampleprof_error::counter_overflow
741  }
742 
744  uint64_t Num, uint64_t Weight = 1) {
745  return BodySamples[LineLocation(LineOffset, Discriminator)].addSamples(
746  Num, Weight);
747  }
748 
750  uint32_t Discriminator,
751  StringRef FName, uint64_t Num,
752  uint64_t Weight = 1) {
753  return BodySamples[LineLocation(LineOffset, Discriminator)].addCalledTarget(
754  FName, Num, Weight);
755  }
756 
757  // Remove a call target and decrease the body sample correspondingly. Return
758  // the number of body samples actually decreased.
760  uint32_t Discriminator,
761  StringRef FName) {
762  uint64_t Count = 0;
763  auto I = BodySamples.find(LineLocation(LineOffset, Discriminator));
764  if (I != BodySamples.end()) {
765  Count = I->second.removeCalledTarget(FName);
766  Count = I->second.removeSamples(Count);
767  if (!I->second.getSamples())
768  BodySamples.erase(I);
769  }
770  return Count;
771  }
772 
774  uint64_t Weight = 1) {
775  SampleRecord S;
776  S.addSamples(Num, Weight);
777  return BodySamples[LineLocation(Index, 0)].merge(S, Weight);
778  }
779 
780  // Accumulate all call target samples to update the body samples.
782  for (auto &I : BodySamples) {
783  uint64_t TargetSamples = I.second.getCallTargetSum();
784  // It's possible that the body sample count can be greater than the call
785  // target sum. E.g, if some call targets are external targets, they won't
786  // be considered valid call targets, but the body sample count which is
787  // from lbr ranges can actually include them.
788  if (TargetSamples > I.second.getSamples())
789  I.second.addSamples(TargetSamples - I.second.getSamples());
790  }
791  }
792 
793  // Accumulate all body samples to set total samples.
795  setTotalSamples(0);
796  for (const auto &I : BodySamples)
797  addTotalSamples(I.second.getSamples());
798 
799  for (auto &I : CallsiteSamples) {
800  for (auto &CS : I.second) {
801  CS.second.updateTotalSamples();
802  addTotalSamples(CS.second.getTotalSamples());
803  }
804  }
805  }
806 
807  // Set current context and all callee contexts to be synthetic.
809  Context.setState(SyntheticContext);
810  for (auto &I : CallsiteSamples) {
811  for (auto &CS : I.second) {
812  CS.second.SetContextSynthetic();
813  }
814  }
815  }
816 
817  /// Return the number of samples collected at the given location.
818  /// Each location is specified by \p LineOffset and \p Discriminator.
819  /// If the location is not found in profile, return error.
821  uint32_t Discriminator) const {
822  const auto &ret = BodySamples.find(LineLocation(LineOffset, Discriminator));
823  if (ret == BodySamples.end())
824  return std::error_code();
825  return ret->second.getSamples();
826  }
827 
828  /// Returns the call target map collected at a given location.
829  /// Each location is specified by \p LineOffset and \p Discriminator.
830  /// If the location is not found in profile, return error.
832  findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const {
833  const auto &ret = BodySamples.find(LineLocation(LineOffset, Discriminator));
834  if (ret == BodySamples.end())
835  return std::error_code();
836  return ret->second.getCallTargets();
837  }
838 
839  /// Returns the call target map collected at a given location specified by \p
840  /// CallSite. If the location is not found in profile, return error.
842  findCallTargetMapAt(const LineLocation &CallSite) const {
843  const auto &Ret = BodySamples.find(CallSite);
844  if (Ret == BodySamples.end())
845  return std::error_code();
846  return Ret->second.getCallTargets();
847  }
848 
849  /// Return the function samples at the given callsite location.
851  return CallsiteSamples[Loc];
852  }
853 
854  /// Returns the FunctionSamplesMap at the given \p Loc.
855  const FunctionSamplesMap *
857  auto iter = CallsiteSamples.find(Loc);
858  if (iter == CallsiteSamples.end())
859  return nullptr;
860  return &iter->second;
861  }
862 
863  /// Returns a pointer to FunctionSamples at the given callsite location
864  /// \p Loc with callee \p CalleeName. If no callsite can be found, relax
865  /// the restriction to return the FunctionSamples at callsite location
866  /// \p Loc with the maximum total sample count. If \p Remapper is not
867  /// nullptr, use \p Remapper to find FunctionSamples with equivalent name
868  /// as \p CalleeName.
869  const FunctionSamples *
870  findFunctionSamplesAt(const LineLocation &Loc, StringRef CalleeName,
871  SampleProfileReaderItaniumRemapper *Remapper) const;
872 
873  bool empty() const { return TotalSamples == 0; }
874 
875  /// Return the total number of samples collected inside the function.
876  uint64_t getTotalSamples() const { return TotalSamples; }
877 
878  /// For top-level functions, return the total number of branch samples that
879  /// have the function as the branch target (or 0 otherwise). This is the raw
880  /// data fetched from the profile. This should be equivalent to the sample of
881  /// the first instruction of the symbol. But as we directly get this info for
882  /// raw profile without referring to potentially inaccurate debug info, this
883  /// gives more accurate profile data and is preferred for standalone symbols.
884  uint64_t getHeadSamples() const { return TotalHeadSamples; }
885 
886  /// Return an estimate of the sample count of the function entry basic block.
887  /// The function can be either a standalone symbol or an inlined function.
888  /// For Context-Sensitive profiles, this will prefer returning the head
889  /// samples (i.e. getHeadSamples()), if non-zero. Otherwise it estimates from
890  /// the function body's samples or callsite samples.
893  // For CS profile, if we already have more accurate head samples
894  // counted by branch sample from caller, use them as entry samples.
895  return getHeadSamples();
896  }
897  uint64_t Count = 0;
898  // Use either BodySamples or CallsiteSamples which ever has the smaller
899  // lineno.
900  if (!BodySamples.empty() &&
901  (CallsiteSamples.empty() ||
902  BodySamples.begin()->first < CallsiteSamples.begin()->first))
903  Count = BodySamples.begin()->second.getSamples();
904  else if (!CallsiteSamples.empty()) {
905  // An indirect callsite may be promoted to several inlined direct calls.
906  // We need to get the sum of them.
907  for (const auto &N_FS : CallsiteSamples.begin()->second)
908  Count += N_FS.second.getHeadSamplesEstimate();
909  }
910  // Return at least 1 if total sample is not 0.
911  return Count ? Count : TotalSamples > 0;
912  }
913 
914  /// Return all the samples collected in the body of the function.
915  const BodySampleMap &getBodySamples() const { return BodySamples; }
916 
917  /// Return all the callsite samples collected in the body of the function.
919  return CallsiteSamples;
920  }
921 
922  /// Return the maximum of sample counts in a function body including functions
923  /// inlined in it.
925  uint64_t MaxCount = 0;
926  for (const auto &L : getBodySamples())
927  MaxCount = std::max(MaxCount, L.second.getSamples());
928  for (const auto &C : getCallsiteSamples())
929  for (const FunctionSamplesMap::value_type &F : C.second)
930  MaxCount = std::max(MaxCount, F.second.getMaxCountInside());
931  return MaxCount;
932  }
933 
934  /// Merge the samples in \p Other into this one.
935  /// Optionally scale samples by \p Weight.
936  sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight = 1) {
938  if (!GUIDToFuncNameMap)
939  GUIDToFuncNameMap = Other.GUIDToFuncNameMap;
940  if (Context.getName().empty())
941  Context = Other.getContext();
942  if (FunctionHash == 0) {
943  // Set the function hash code for the target profile.
944  FunctionHash = Other.getFunctionHash();
945  } else if (FunctionHash != Other.getFunctionHash()) {
946  // The two profiles coming with different valid hash codes indicates
947  // either:
948  // 1. They are same-named static functions from different compilation
949  // units (without using -unique-internal-linkage-names), or
950  // 2. They are really the same function but from different compilations.
951  // Let's bail out in either case for now, which means one profile is
952  // dropped.
954  }
955 
956  MergeResult(Result, addTotalSamples(Other.getTotalSamples(), Weight));
957  MergeResult(Result, addHeadSamples(Other.getHeadSamples(), Weight));
958  for (const auto &I : Other.getBodySamples()) {
959  const LineLocation &Loc = I.first;
960  const SampleRecord &Rec = I.second;
961  MergeResult(Result, BodySamples[Loc].merge(Rec, Weight));
962  }
963  for (const auto &I : Other.getCallsiteSamples()) {
964  const LineLocation &Loc = I.first;
966  for (const auto &Rec : I.second)
967  MergeResult(Result, FSMap[Rec.first].merge(Rec.second, Weight));
968  }
969  return Result;
970  }
971 
972  /// Recursively traverses all children, if the total sample count of the
973  /// corresponding function is no less than \p Threshold, add its corresponding
974  /// GUID to \p S. Also traverse the BodySamples to add hot CallTarget's GUID
975  /// to \p S.
978  uint64_t Threshold) const {
979  if (TotalSamples <= Threshold)
980  return;
981  auto isDeclaration = [](const Function *F) {
982  return !F || F->isDeclaration();
983  };
984  if (isDeclaration(SymbolMap.lookup(getFuncName()))) {
985  // Add to the import list only when it's defined out of module.
986  S.insert(getGUID(getName()));
987  }
988  // Import hot CallTargets, which may not be available in IR because full
989  // profile annotation cannot be done until backend compilation in ThinLTO.
990  for (const auto &BS : BodySamples)
991  for (const auto &TS : BS.second.getCallTargets())
992  if (TS.getValue() > Threshold) {
993  const Function *Callee = SymbolMap.lookup(getFuncName(TS.getKey()));
994  if (isDeclaration(Callee))
995  S.insert(getGUID(TS.getKey()));
996  }
997  for (const auto &CS : CallsiteSamples)
998  for (const auto &NameFS : CS.second)
999  NameFS.second.findInlinedFunctions(S, SymbolMap, Threshold);
1000  }
1001 
1002  /// Set the name of the function.
1003  void setName(StringRef FunctionName) { Context.setName(FunctionName); }
1004 
1005  /// Return the function name.
1006  StringRef getName() const { return Context.getName(); }
1007 
1008  /// Return the original function name.
1009  StringRef getFuncName() const { return getFuncName(getName()); }
1010 
1011  void setFunctionHash(uint64_t Hash) { FunctionHash = Hash; }
1012 
1013  uint64_t getFunctionHash() const { return FunctionHash; }
1014 
1015  /// Return the canonical name for a function, taking into account
1016  /// suffix elision policy attributes.
1018  auto AttrName = "sample-profile-suffix-elision-policy";
1019  auto Attr = F.getFnAttribute(AttrName).getValueAsString();
1020  return getCanonicalFnName(F.getName(), Attr);
1021  }
1022 
1023  /// Name suffixes which canonicalization should handle to avoid
1024  /// profile mismatch.
1025  static constexpr const char *LLVMSuffix = ".llvm.";
1026  static constexpr const char *PartSuffix = ".part.";
1027  static constexpr const char *UniqSuffix = ".__uniq.";
1028 
1030  StringRef Attr = "selected") {
1031  // Note the sequence of the suffixes in the knownSuffixes array matters.
1032  // If suffix "A" is appended after the suffix "B", "A" should be in front
1033  // of "B" in knownSuffixes.
1034  const char *knownSuffixes[] = {LLVMSuffix, PartSuffix, UniqSuffix};
1035  if (Attr == "" || Attr == "all") {
1036  return FnName.split('.').first;
1037  } else if (Attr == "selected") {
1038  StringRef Cand(FnName);
1039  for (const auto &Suf : knownSuffixes) {
1040  StringRef Suffix(Suf);
1041  // If the profile contains ".__uniq." suffix, don't strip the
1042  // suffix for names in the IR.
1043  if (Suffix == UniqSuffix && FunctionSamples::HasUniqSuffix)
1044  continue;
1045  auto It = Cand.rfind(Suffix);
1046  if (It == StringRef::npos)
1047  continue;
1048  auto Dit = Cand.rfind('.');
1049  if (Dit == It + Suffix.size() - 1)
1050  Cand = Cand.substr(0, It);
1051  }
1052  return Cand;
1053  } else if (Attr == "none") {
1054  return FnName;
1055  } else {
1056  assert(false && "internal error: unknown suffix elision policy");
1057  }
1058  return FnName;
1059  }
1060 
1061  /// Translate \p Name into its original name.
1062  /// When profile doesn't use MD5, \p Name needs no translation.
1063  /// When profile uses MD5, \p Name in current FunctionSamples
1064  /// is actually GUID of the original function name. getFuncName will
1065  /// translate \p Name in current FunctionSamples into its original name
1066  /// by looking up in the function map GUIDToFuncNameMap.
1067  /// If the original name doesn't exist in the map, return empty StringRef.
1069  if (!UseMD5)
1070  return Name;
1071 
1072  assert(GUIDToFuncNameMap && "GUIDToFuncNameMap needs to be populated first");
1073  return GUIDToFuncNameMap->lookup(std::stoull(Name.data()));
1074  }
1075 
1076  /// Returns the line offset to the start line of the subprogram.
1077  /// We assume that a single function will not exceed 65535 LOC.
1078  static unsigned getOffset(const DILocation *DIL);
1079 
1080  /// Returns a unique call site identifier for a given debug location of a call
1081  /// instruction. This is wrapper of two scenarios, the probe-based profile and
1082  /// regular profile, to hide implementation details from the sample loader and
1083  /// the context tracker.
1084  static LineLocation getCallSiteIdentifier(const DILocation *DIL,
1085  bool ProfileIsFS = false);
1086 
1087  /// Returns a unique hash code for a combination of a callsite location and
1088  /// the callee function name.
1089  static uint64_t getCallSiteHash(StringRef CalleeName,
1090  const LineLocation &Callsite);
1091 
1092  /// Get the FunctionSamples of the inline instance where DIL originates
1093  /// from.
1094  ///
1095  /// The FunctionSamples of the instruction (Machine or IR) associated to
1096  /// \p DIL is the inlined instance in which that instruction is coming from.
1097  /// We traverse the inline stack of that instruction, and match it with the
1098  /// tree nodes in the profile.
1099  ///
1100  /// \returns the FunctionSamples pointer to the inlined instance.
1101  /// If \p Remapper is not nullptr, it will be used to find matching
1102  /// FunctionSamples with not exactly the same but equivalent name.
1104  const DILocation *DIL,
1105  SampleProfileReaderItaniumRemapper *Remapper = nullptr) const;
1106 
1107  static bool ProfileIsProbeBased;
1108 
1109  static bool ProfileIsCS;
1110 
1111  static bool ProfileIsPreInlined;
1112 
1113  SampleContext &getContext() const { return Context; }
1114 
1115  void setContext(const SampleContext &FContext) { Context = FContext; }
1116 
1117  /// Whether the profile uses MD5 to represent string.
1118  static bool UseMD5;
1119 
1120  /// Whether the profile contains any ".__uniq." suffix in a name.
1121  static bool HasUniqSuffix;
1122 
1123  /// If this profile uses flow sensitive discriminators.
1124  static bool ProfileIsFS;
1125 
1126  /// GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for
1127  /// all the function symbols defined or declared in current module.
1129 
1130  // Assume the input \p Name is a name coming from FunctionSamples itself.
1131  // If UseMD5 is true, the name is already a GUID and we
1132  // don't want to return the GUID of GUID.
1134  return UseMD5 ? std::stoull(Name.data()) : Function::getGUID(Name);
1135  }
1136 
1137  // Find all the names in the current FunctionSamples including names in
1138  // all the inline instances and names of call targets.
1139  void findAllNames(DenseSet<StringRef> &NameSet) const;
1140 
1141 private:
1142  /// CFG hash value for the function.
1143  uint64_t FunctionHash = 0;
1144 
1145  /// Calling context for function profile
1146  mutable SampleContext Context;
1147 
1148  /// Total number of samples collected inside this function.
1149  ///
1150  /// Samples are cumulative, they include all the samples collected
1151  /// inside this function and all its inlined callees.
1152  uint64_t TotalSamples = 0;
1153 
1154  /// Total number of samples collected at the head of the function.
1155  /// This is an approximation of the number of calls made to this function
1156  /// at runtime.
1157  uint64_t TotalHeadSamples = 0;
1158 
1159  /// Map instruction locations to collected samples.
1160  ///
1161  /// Each entry in this map contains the number of samples
1162  /// collected at the corresponding line offset. All line locations
1163  /// are an offset from the start of the function.
1164  BodySampleMap BodySamples;
1165 
1166  /// Map call sites to collected samples for the called function.
1167  ///
1168  /// Each entry in this map corresponds to all the samples
1169  /// collected for the inlined function call at the given
1170  /// location. For example, given:
1171  ///
1172  /// void foo() {
1173  /// 1 bar();
1174  /// ...
1175  /// 8 baz();
1176  /// }
1177  ///
1178  /// If the bar() and baz() calls were inlined inside foo(), this
1179  /// map will contain two entries. One for all the samples collected
1180  /// in the call to bar() at line offset 1, the other for all the samples
1181  /// collected in the call to baz() at line offset 8.
1182  CallsiteSampleMap CallsiteSamples;
1183 };
1184 
1186 
1187 using SampleProfileMap =
1188  std::unordered_map<SampleContext, FunctionSamples, SampleContext::Hash>;
1189 
1190 using NameFunctionSamples = std::pair<SampleContext, const FunctionSamples *>;
1191 
1192 void sortFuncProfiles(const SampleProfileMap &ProfileMap,
1193  std::vector<NameFunctionSamples> &SortedProfiles);
1194 
1195 /// Sort a LocationT->SampleT map by LocationT.
1196 ///
1197 /// It produces a sorted list of <LocationT, SampleT> records by ascending
1198 /// order of LocationT.
1199 template <class LocationT, class SampleT> class SampleSorter {
1200 public:
1201  using SamplesWithLoc = std::pair<const LocationT, SampleT>;
1203 
1204  SampleSorter(const std::map<LocationT, SampleT> &Samples) {
1205  for (const auto &I : Samples)
1206  V.push_back(&I);
1207  llvm::stable_sort(V, [](const SamplesWithLoc *A, const SamplesWithLoc *B) {
1208  return A->first < B->first;
1209  });
1210  }
1211 
1212  const SamplesWithLocList &get() const { return V; }
1213 
1214 private:
1216 };
1217 
1218 /// SampleContextTrimmer impelements helper functions to trim, merge cold
1219 /// context profiles. It also supports context profile canonicalization to make
1220 /// sure ProfileMap's key is consistent with FunctionSample's name/context.
1222 public:
1223  SampleContextTrimmer(SampleProfileMap &Profiles) : ProfileMap(Profiles){};
1224  // Trim and merge cold context profile when requested. TrimBaseProfileOnly
1225  // should only be effective when TrimColdContext is true. On top of
1226  // TrimColdContext, TrimBaseProfileOnly can be used to specify to trim all
1227  // cold profiles or only cold base profiles. Trimming base profiles only is
1228  // mainly to honor the preinliner decsion. Note that when MergeColdContext is
1229  // true, preinliner decsion is not honored anyway so TrimBaseProfileOnly will
1230  // be ignored.
1232  bool TrimColdContext,
1233  bool MergeColdContext,
1234  uint32_t ColdContextFrameLength,
1235  bool TrimBaseProfileOnly);
1236  // Canonicalize context profile name and attributes.
1238 
1239 private:
1240  SampleProfileMap &ProfileMap;
1241 };
1242 
1243 // CSProfileConverter converts a full context-sensitive flat sample profile into
1244 // a nested context-sensitive sample profile.
1246 public:
1248  void convertProfiles();
1249  struct FrameNode {
1251  FunctionSamples *FSamples = nullptr,
1252  LineLocation CallLoc = {0, 0})
1253  : FuncName(FName), FuncSamples(FSamples), CallSiteLoc(CallLoc){};
1254 
1255  // Map line+discriminator location to child frame
1256  std::map<uint64_t, FrameNode> AllChildFrames;
1257  // Function name for current frame
1259  // Function Samples for current frame
1261  // Callsite location in parent context
1263 
1264  FrameNode *getOrCreateChildFrame(const LineLocation &CallSite,
1265  StringRef CalleeName);
1266  };
1267 
1268 private:
1269  // Nest all children profiles into the profile of Node.
1271  FrameNode *getOrCreateContextPath(const SampleContext &Context);
1272 
1273  SampleProfileMap &ProfileMap;
1274  FrameNode RootFrame;
1275 };
1276 
1277 /// ProfileSymbolList records the list of function symbols shown up
1278 /// in the binary used to generate the profile. It is useful to
1279 /// to discriminate a function being so cold as not to shown up
1280 /// in the profile and a function newly added.
1282 public:
1283  /// copy indicates whether we need to copy the underlying memory
1284  /// for the input Name.
1285  void add(StringRef Name, bool copy = false) {
1286  if (!copy) {
1287  Syms.insert(Name);
1288  return;
1289  }
1290  Syms.insert(Name.copy(Allocator));
1291  }
1292 
1293  bool contains(StringRef Name) { return Syms.count(Name); }
1294 
1295  void merge(const ProfileSymbolList &List) {
1296  for (auto Sym : List.Syms)
1297  add(Sym, true);
1298  }
1299 
1300  unsigned size() { return Syms.size(); }
1301 
1302  void setToCompress(bool TC) { ToCompress = TC; }
1303  bool toCompress() { return ToCompress; }
1304 
1305  std::error_code read(const uint8_t *Data, uint64_t ListSize);
1306  std::error_code write(raw_ostream &OS);
1307  void dump(raw_ostream &OS = dbgs()) const;
1308 
1309 private:
1310  // Determine whether or not to compress the symbol list when
1311  // writing it into profile. The variable is unused when the symbol
1312  // list is read from an existing profile.
1313  bool ToCompress = false;
1314  DenseSet<StringRef> Syms;
1315  BumpPtrAllocator Allocator;
1316 };
1317 
1318 } // end namespace sampleprof
1319 
1320 using namespace sampleprof;
1321 // Provide DenseMapInfo for SampleContext.
1322 template <> struct DenseMapInfo<SampleContext> {
1323  static inline SampleContext getEmptyKey() { return SampleContext(); }
1324 
1325  static inline SampleContext getTombstoneKey() { return SampleContext("@"); }
1326 
1327  static unsigned getHashValue(const SampleContext &Val) {
1328  return Val.getHashCode();
1329  }
1330 
1331  static bool isEqual(const SampleContext &LHS, const SampleContext &RHS) {
1332  return LHS == RHS;
1333  }
1334 };
1335 
1336 // Prepend "__uniq" before the hash for tools like profilers to understand
1337 // that this symbol is of internal linkage type. The "__uniq" is the
1338 // pre-determined prefix that is used to tell tools that this symbol was
1339 // created with -funique-internal-linakge-symbols and the tools can strip or
1340 // keep the prefix as needed.
1341 inline std::string getUniqueInternalLinkagePostfix(const StringRef &FName) {
1342  llvm::MD5 Md5;
1343  Md5.update(FName);
1345  Md5.final(R);
1346  SmallString<32> Str;
1348  // Convert MD5hash to Decimal. Demangler suffixes can either contain
1349  // numbers or characters but not both.
1350  llvm::APInt IntHash(128, Str.str(), 16);
1351  return toString(IntHash, /* Radix = */ 10, /* Signed = */ false)
1352  .insert(0, FunctionSamples::UniqSuffix);
1353 }
1354 
1355 } // end namespace llvm
1356 
1357 #endif // LLVM_PROFILEDATA_SAMPLEPROF_H
llvm::sampleprof::CSProfileConverter
Definition: SampleProf.h:1245
llvm::sampleprof::SampleRecord::getSamples
uint64_t getSamples() const
Definition: SampleProf.h:385
llvm::sampleprof_error::uncompress_failed
@ uncompress_failed
llvm::sampleprof::FunctionSamples::getBodySamples
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
Definition: SampleProf.h:915
llvm::ArrayRef::drop_back
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition: ArrayRef.h:209
llvm::sampleprof::SecHdrTableEntry::Offset
uint64_t Offset
Definition: SampleProf.h:162
MathExtras.h
llvm::sampleprof::CSProfileConverter::FrameNode::FuncSamples
FunctionSamples * FuncSamples
Definition: SampleProf.h:1260
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::sampleprof::SecFuncMetadataFlags::SecFlagHasAttribute
@ SecFlagHasAttribute
llvm::sampleprof::BodySampleMap
std::map< LineLocation, SampleRecord > BodySampleMap
Definition: SampleProf.h:700
llvm::sampleprof::SecProfSummaryFlags::SecFlagFSDiscriminator
@ SecFlagFSDiscriminator
SecFlagFSDiscriminator means this profile uses flow-sensitive discriminators.
llvm::sampleprof::SampleSorter::get
const SamplesWithLocList & get() const
Definition: SampleProf.h:1212
llvm::sampleprof::SampleContext::decodeContextString
static void decodeContextString(StringRef ContextStr, StringRef &FName, LineLocation &LineLoc)
Definition: SampleProf.h:559
llvm::sampleprof::ContextDuplicatedIntoBase
@ ContextDuplicatedIntoBase
Definition: SampleProf.h:444
llvm::MD5::update
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition: MD5.cpp:189
llvm::sampleprof::SampleContext::operator!=
bool operator!=(const SampleContext &That) const
Definition: SampleProf.h:637
llvm::sampleprof::FunctionSamples::ProfileIsProbeBased
static bool ProfileIsProbeBased
Definition: SampleProf.h:1107
llvm::sampleprof::hash_value
static hash_code hash_value(const SampleContextFrame &arg)
Definition: SampleProf.h:478
llvm::getUniqueInternalLinkagePostfix
std::string getUniqueInternalLinkagePostfix(const StringRef &FName)
Definition: SampleProf.h:1341
llvm::StringRef::rfind
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
Definition: StringRef.h:337
llvm::sampleprof::FunctionSamples::dump
void dump() const
Definition: SampleProf.cpp:323
llvm::sampleprof::FunctionSamples::ProfileIsCS
static bool ProfileIsCS
Definition: SampleProf.h:1109
llvm::sampleprof::RawContext
@ RawContext
Definition: SampleProf.h:433
llvm::MD5::stringifyResult
static void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
Definition: MD5.cpp:287
llvm::sampleprof::LineLocation::dump
void dump() const
Definition: SampleProf.cpp:130
llvm::StringRef::compare
int compare(StringRef RHS) const
compare - Compare two strings; the result is -1, 0, or 1 if this string is lexicographically less tha...
Definition: StringRef.h:176
llvm::sampleprof::SampleRecord::CallTargetComparator::operator()
bool operator()(const CallTarget &LHS, const CallTarget &RHS) const
Definition: SampleProf.h:322
llvm::sampleprof::SampleContext::hasAttribute
bool hasAttribute(ContextAttributeMask A)
Definition: SampleProf.h:581
llvm::Function
Definition: Function.h:60
llvm::DenseMapBase::lookup
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition: DenseMap.h:197
StringRef.h
llvm::sampleprof::SecHdrTableEntry
Definition: SampleProf.h:159
llvm::sampleprof::FunctionSamples::removeTotalSamples
void removeTotalSamples(uint64_t Num)
Definition: SampleProf.h:726
llvm::sampleprof::CallsiteSampleMap
std::map< LineLocation, FunctionSamplesMap > CallsiteSampleMap
Definition: SampleProf.h:704
llvm::sampleprof::LineLocation::LineLocation
LineLocation(uint32_t L, uint32_t D)
Definition: SampleProf.h:284
llvm::sampleprof::SampleSorter::SamplesWithLocList
SmallVector< const SamplesWithLoc *, 20 > SamplesWithLocList
Definition: SampleProf.h:1202
llvm::sampleprof::SampleRecord::hasCalls
bool hasCalls() const
Return true if this sample record contains function calls.
Definition: SampleProf.h:383
llvm::sampleprof_error::hash_mismatch
@ hash_mismatch
llvm::sampleprof::SecNameTableFlags::SecFlagFixedLengthMD5
@ SecFlagFixedLengthMD5
llvm::StringRef::npos
static constexpr size_t npos
Definition: StringRef.h:52
llvm::sampleprof::FunctionSamples::getFuncName
StringRef getFuncName(StringRef Name) const
Translate Name into its original name.
Definition: SampleProf.h:1068
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1181
llvm::sampleprof::NameFunctionSamples
std::pair< SampleContext, const FunctionSamples * > NameFunctionSamples
Definition: SampleProf.h:1190
llvm::sampleprof::ProfileSymbolList::size
unsigned size()
Definition: SampleProf.h:1300
llvm::sampleprof::SampleContext::setContext
void setContext(SampleContextFrames Context, ContextStateMask CState=RawContext)
Definition: SampleProf.h:624
llvm::sampleprof::SampleContext::SampleContext
SampleContext(SampleContextFrames Context, ContextStateMask CState=RawContext)
Definition: SampleProf.h:509
llvm::sampleprof::SampleContextFrame::toString
std::string toString(bool OutputLineLocation) const
Definition: SampleProf.h:466
llvm::sampleprof::SecProfSummaryFlags::SecFlagFullContext
@ SecFlagFullContext
SecFlagContext means this is context-sensitive flat profile for CSSPGO.
Allocator.h
llvm::sampleprof::SampleContext::toString
std::string toString() const
Definition: SampleProf.h:606
llvm::sampleprof_error::unsupported_version
@ unsupported_version
llvm::sampleprof::SampleProfileMap
std::unordered_map< SampleContext, FunctionSamples, SampleContext::Hash > SampleProfileMap
Definition: SampleProf.h:1188
llvm::sampleprof::SampleContext::operator==
bool operator==(const SampleContext &That) const
Definition: SampleProf.h:632
llvm::sampleprof::hasSecFlag
static bool hasSecFlag(const SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:267
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1557
llvm::sampleprof::LineLocation::operator<
bool operator<(const LineLocation &O) const
Definition: SampleProf.h:289
llvm::sampleprof::SPF_GCC
@ SPF_GCC
Definition: SampleProf.h:94
llvm::StringMap::end
iterator end()
Definition: StringMap.h:204
llvm::X86AS::FS
@ FS
Definition: X86.h:200
llvm::sampleprof::ContextShouldBeInlined
@ ContextShouldBeInlined
Definition: SampleProf.h:443
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
llvm::sampleprof::SecFuncOffsetTable
@ SecFuncOffsetTable
Definition: SampleProf.h:126
llvm::sampleprof::addSecFlag
static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:251
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1641
llvm::sampleprof_error::not_implemented
@ not_implemented
FMAInstKind::Accumulator
@ Accumulator
llvm::StringRef::substr
StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition: StringRef.h:561
llvm::sampleprof::SecCommonFlags::SecFlagCompress
@ SecFlagCompress
ret
to esp esp setne al movzbw ax esp setg cl movzbw cx cmove cx cl jne LBB1_2 esp ret(also really horrible code on ppc). This is due to the expand code for 64-bit compares. GCC produces multiple branches
llvm::sampleprof::SampleContext::getAllAttributes
uint32_t getAllAttributes()
Definition: SampleProf.h:583
llvm::sampleprof::SecNameTableFlags::SecFlagMD5Name
@ SecFlagMD5Name
llvm::max
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:337
llvm::sampleprof::FunctionSamples::findInlinedFunctions
void findInlinedFunctions(DenseSet< GlobalValue::GUID > &S, const StringMap< Function * > &SymbolMap, uint64_t Threshold) const
Recursively traverses all children, if the total sample count of the corresponding function is no les...
Definition: SampleProf.h:976
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:119
llvm::sampleprof::SampleRecord::SampleRecord
SampleRecord()=default
llvm::sampleprof::FunctionSamples::findAllNames
void findAllNames(DenseSet< StringRef > &NameSet) const
Definition: SampleProf.cpp:272
llvm::sampleprof::FunctionSamples::getName
StringRef getName() const
Return the function name.
Definition: SampleProf.h:1006
llvm::sampleprof::FunctionSamplesMap
std::map< std::string, FunctionSamples, std::less<> > FunctionSamplesMap
Definition: SampleProf.h:703
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
llvm::sampleprof::MergedContext
@ MergedContext
Definition: SampleProf.h:436
llvm::StringMap::find
iterator find(StringRef Key)
Definition: StringMap.h:217
llvm::sampleprof::SPF_None
@ SPF_None
Definition: SampleProf.h:91
llvm::sampleprof::CSProfileConverter::FrameNode::getOrCreateChildFrame
FrameNode * getOrCreateChildFrame(const LineLocation &CallSite, StringRef CalleeName)
Definition: SampleProf.cpp:465
llvm::sampleprof::FunctionSamples::getCanonicalFnName
static StringRef getCanonicalFnName(StringRef FnName, StringRef Attr="selected")
Definition: SampleProf.h:1029
llvm::sampleprof::SecHdrTableEntry::Size
uint64_t Size
Definition: SampleProf.h:163
llvm::sampleprof::SPF_Binary
@ SPF_Binary
Definition: SampleProf.h:96
llvm::sampleprof::LineLocation::Discriminator
uint32_t Discriminator
Definition: SampleProf.h:303
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::sampleprof_error::counter_overflow
@ counter_overflow
llvm::sampleprof::LineLocation::LineOffset
uint32_t LineOffset
Definition: SampleProf.h:302
llvm::sampleprof::FunctionSamples::SetContextSynthetic
void SetContextSynthetic()
Definition: SampleProf.h:808
Context
LLVMContext & Context
Definition: NVVMIntrRange.cpp:66
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::DenseMapInfo< SampleContext >::isEqual
static bool isEqual(const SampleContext &LHS, const SampleContext &RHS)
Definition: SampleProf.h:1331
llvm::sampleprof::FunctionSamples::HasUniqSuffix
static bool HasUniqSuffix
Whether the profile contains any ".__uniq." suffix in a name.
Definition: SampleProf.h:1121
llvm::sampleprof::removeSecFlag
static void removeSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:259
llvm::sampleprof::ProfileSymbolList::setToCompress
void setToCompress(bool TC)
Definition: SampleProf.h:1302
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
llvm::sampleprof::SecFuncMetadataFlags::SecFlagIsProbeBased
@ SecFlagIsProbeBased
llvm::DenseMapInfo
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: APInt.h:34
llvm::sampleprof::FunctionSamples::getFuncName
StringRef getFuncName() const
Return the original function name.
Definition: SampleProf.h:1009
GlobalValue.h
llvm::MD5::final
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition: MD5.cpp:234
llvm::sampleprof_error::unsupported_writing_format
@ unsupported_writing_format
llvm::StringRef::startswith
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:256
llvm::sampleprof::SampleProfileFormat
SampleProfileFormat
Definition: SampleProf.h:90
llvm::sampleprof::getRepInFormat
static StringRef getRepInFormat(StringRef Name, bool UseMD5, std::string &GUIDBuf)
Get the proper representation of a string according to whether the current Format uses MD5 to represe...
Definition: SampleProf.h:108
llvm::sampleprof::FunctionSamples::PartSuffix
static constexpr const char * PartSuffix
Definition: SampleProf.h:1026
llvm::sampleprof::FunctionSamples::removeCalledTargetAndBodySample
uint64_t removeCalledTargetAndBodySample(uint32_t LineOffset, uint32_t Discriminator, StringRef FName)
Definition: SampleProf.h:759
llvm::sampleprof::FunctionSamples::setTotalSamples
void setTotalSamples(uint64_t Num)
Definition: SampleProf.h:733
llvm::sampleprof::FunctionSamples::getTotalSamples
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Definition: SampleProf.h:876
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::sampleprof::SampleContextFrameHash
Definition: SampleProf.h:486
llvm::sampleprof::FunctionSamples::updateTotalSamples
void updateTotalSamples()
Definition: SampleProf.h:794
llvm::sampleprof::SampleContext::hasState
bool hasState(ContextStateMask S)
Definition: SampleProf.h:585
llvm::sampleprof::SampleRecord::CallTarget
std::pair< StringRef, uint64_t > CallTarget
Definition: SampleProf.h:320
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::sampleprof::SampleContext::Hash
Definition: SampleProf.h:662
llvm::sampleprof::CSProfileConverter::FrameNode
Definition: SampleProf.h:1249
llvm::sampleprof::SampleContext::getHashCode
uint64_t getHashCode() const
Definition: SampleProf.h:612
llvm::sampleprof::FunctionSamples::FunctionSamples
FunctionSamples()=default
llvm::sampleprof::SampleRecord::removeSamples
uint64_t removeSamples(uint64_t S)
Decrease the number of samples for this record by S.
Definition: SampleProf.h:348
llvm::sampleprof::SyntheticContext
@ SyntheticContext
Definition: SampleProf.h:434
llvm::sampleprof::SampleContextFrame::SampleContextFrame
SampleContextFrame()
Definition: SampleProf.h:453
llvm::sampleprof::SecProfSummaryFlags::SecFlagPartial
@ SecFlagPartial
SecFlagPartial means the profile is for common/shared code.
llvm::sampleprof::FunctionSamples::findCallTargetMapAt
ErrorOr< SampleRecord::CallTargetMap > findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const
Returns the call target map collected at a given location.
Definition: SampleProf.h:832
llvm::sampleprof::FunctionSamples::getHeadSamplesEstimate
uint64_t getHeadSamplesEstimate() const
Return an estimate of the sample count of the function entry basic block.
Definition: SampleProf.h:891
llvm::sampleprof::SampleContext::createCtxVectorFromStr
static void createCtxVectorFromStr(StringRef ContextStr, SampleContextFrameVector &Context)
Create a context vector from a given context string and save it in Context.
Definition: SampleProf.h:540
DenseSet.h
llvm::orc::SymbolMap
DenseMap< SymbolStringPtr, JITEvaluatedSymbol > SymbolMap
A map from symbol names (as SymbolStringPtrs) to JITSymbols (address/flags pairs).
Definition: Core.h:113
llvm::sampleprof::FunctionSamples::getGUID
static uint64_t getGUID(StringRef Name)
Definition: SampleProf.h:1133
llvm::sampleprof::SampleContext::operator<
bool operator<(const SampleContext &That) const
Definition: SampleProf.h:639
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::sampleprof_category
const std::error_category & sampleprof_category()
Definition: SampleProf.cpp:100
llvm::DenseMapInfo< SampleContext >::getHashValue
static unsigned getHashValue(const SampleContext &Val)
Definition: SampleProf.h:1327
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:147
ColdCountThreshold
static cl::opt< unsigned > ColdCountThreshold("mfs-count-threshold", cl::desc("Minimum number of times a block must be executed to be retained."), cl::init(1), cl::Hidden)
llvm::sampleprof::SampleSorter::SampleSorter
SampleSorter(const std::map< LocationT, SampleT > &Samples)
Definition: SampleProf.h:1204
llvm::sampleprof::SPMagic
static uint64_t SPMagic(SampleProfileFormat Format=SPF_Binary)
Definition: SampleProf.h:99
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
llvm::sampleprof::SecNameTableFlags::SecFlagInValid
@ SecFlagInValid
llvm::sampleprof::ContextStateMask
ContextStateMask
Definition: SampleProf.h:431
llvm::sampleprof::ProfileSymbolList::read
std::error_code read(const uint8_t *Data, uint64_t ListSize)
Definition: SampleProf.cpp:326
llvm::sampleprof::SampleContextFrames
ArrayRef< SampleContextFrame > SampleContextFrames
Definition: SampleProf.h:484
llvm::sampleprof::CSProfileConverter::FrameNode::AllChildFrames
std::map< uint64_t, FrameNode > AllChildFrames
Definition: SampleProf.h:1253
llvm::sampleprof::SampleContext
Definition: SampleProf.h:502
llvm::sampleprof::SecProfSummaryFlags::SecFlagInValid
@ SecFlagInValid
llvm::sampleprof::FunctionSamples::getHeadSamples
uint64_t getHeadSamples() const
For top-level functions, return the total number of branch samples that have the function as the bran...
Definition: SampleProf.h:884
llvm::sampleprof::SampleContext::isBaseContext
bool isBaseContext() const
Definition: SampleProf.h:589
llvm::sampleprof::sortFuncProfiles
void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
Definition: SampleProf.cpp:201
llvm::StringMap< uint64_t >
llvm::SmallString< 32 >
llvm::sampleprof::FunctionSamples::ProfileIsFS
static bool ProfileIsFS
If this profile uses flow sensitive discriminators.
Definition: SampleProf.h:1124
llvm::sampleprof::FunctionSamples::empty
bool empty() const
Definition: SampleProf.h:873
llvm::sampleprof::SecHdrTableEntry::Type
SecType Type
Definition: SampleProf.h:160
llvm::sampleprof::LineLocation::operator!=
bool operator!=(const LineLocation &O) const
Definition: SampleProf.h:298
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:134
llvm::sampleprof::SampleRecord::getCallTargets
const CallTargetMap & getCallTargets() const
Definition: SampleProf.h:386
llvm::sampleprof::SampleRecord::SortedCallTargetSet
std::set< CallTarget, CallTargetComparator > SortedCallTargetSet
Definition: SampleProf.h:330
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:268
llvm::sampleprof::SampleContext::SampleContext
SampleContext(StringRef ContextStr, std::list< SampleContextFrameVector > &CSNameTable, ContextStateMask CState=RawContext)
Definition: SampleProf.h:519
llvm::sampleprof::ProfileSymbolList::contains
bool contains(StringRef Name)
Definition: SampleProf.h:1293
llvm::sampleprof::SampleContext::getContextFrames
SampleContextFrames getContextFrames() const
Definition: SampleProf.h:591
llvm::sampleprof::FunctionSamples::getCallsiteSamples
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
Definition: SampleProf.h:918
llvm::sampleprof::SampleContext::setName
void setName(StringRef FunctionName)
Set the name of the function and clear the current context.
Definition: SampleProf.h:618
llvm::sampleprof::SecHdrTableEntry::Flags
uint64_t Flags
Definition: SampleProf.h:161
llvm::sampleprof::SampleRecord::CallTargetComparator
Definition: SampleProf.h:321
llvm::sampleprof::UnknownContext
@ UnknownContext
Definition: SampleProf.h:432
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:264
llvm::sampleprof::SecProfSummary
@ SecProfSummary
Definition: SampleProf.h:123
llvm::sampleprof::SPF_Compact_Binary
@ SPF_Compact_Binary
Definition: SampleProf.h:93
llvm::sampleprof::ProfileSymbolList
ProfileSymbolList records the list of function symbols shown up in the binary used to generate the pr...
Definition: SampleProf.h:1281
llvm::sampleprof::SampleContext::setAttribute
void setAttribute(ContextAttributeMask A)
Definition: SampleProf.h:582
llvm::StringMap::erase
void erase(iterator I)
Definition: StringMap.h:370
llvm::sampleprof::FunctionSamples::addHeadSamples
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:735
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::sampleprof::SampleContext::SampleContext
SampleContext()
Definition: SampleProf.h:504
llvm::sampleprof::FunctionSamples::GUIDToFuncNameMap
DenseMap< uint64_t, StringRef > * GUIDToFuncNameMap
GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for all the function symbols define...
Definition: SampleProf.h:1128
llvm::sampleprof::LineLocation::operator==
bool operator==(const LineLocation &O) const
Definition: SampleProf.h:294
llvm::sampleprof::SecFuncOffsetFlags
SecFuncOffsetFlags
Definition: SampleProf.h:215
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition: SampleProf.h:711
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:63
llvm::sampleprof::SampleContextFrame::Location
LineLocation Location
Definition: SampleProf.h:451
llvm::MD5
Definition: MD5.h:41
llvm::sampleprof::SecFuncMetadataFlags::SecFlagInvalid
@ SecFlagInvalid
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:850
ErrorOr.h
llvm::DenseMapInfo< SampleContext >::getTombstoneKey
static SampleContext getTombstoneKey()
Definition: SampleProf.h:1325
llvm::sampleprof::SampleContext::clearState
void clearState(ContextStateMask S)
Definition: SampleProf.h:587
llvm::sampleprof::SecLBRProfile
@ SecLBRProfile
Definition: SampleProf.h:131
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::sampleprof::FunctionSamples::getCallSiteHash
static uint64_t getCallSiteHash(StringRef CalleeName, const LineLocation &Callsite)
Returns a unique hash code for a combination of a callsite location and the callee function name.
Definition: SampleProf.cpp:238
StringExtras.h
llvm::SaturatingMultiplyAdd
std::enable_if_t< std::is_unsigned< T >::value, T > SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, and add the unsigned integer, A to the product.
Definition: MathExtras.h:807
llvm::sampleprof::FunctionSamples::setContext
void setContext(const SampleContext &FContext)
Definition: SampleProf.h:1115
llvm::sampleprof::SampleRecord::getCallTargetSum
uint64_t getCallTargetSum() const
Definition: SampleProf.h:391
llvm::sampleprof::FunctionSamples::getFunctionHash
uint64_t getFunctionHash() const
Definition: SampleProf.h:1013
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:749
llvm::sampleprof::SampleContextFrame::FuncName
StringRef FuncName
Definition: SampleProf.h:450
llvm::sampleprof::SampleRecord::adjustCallTargets
static const CallTargetMap adjustCallTargets(const CallTargetMap &Targets, float DistributionFactor)
Prorate call targets by a distribution factor.
Definition: SampleProf.h:408
llvm::sampleprof::SampleRecord::getSortedCallTargets
const SortedCallTargetSet getSortedCallTargets() const
Definition: SampleProf.h:387
llvm::sampleprof::SampleContext::setAllAttributes
void setAllAttributes(uint32_t A)
Definition: SampleProf.h:584
llvm::sampleprof_error::malformed
@ malformed
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::sampleprof::SecCommonFlags::SecFlagInValid
@ SecFlagInValid
llvm::sampleprof::SampleContext::getName
StringRef getName() const
Definition: SampleProf.h:590
llvm::sampleprof::SampleContext::setState
void setState(ContextStateMask S)
Definition: SampleProf.h:586
llvm::sampleprof::operator<<
raw_ostream & operator<<(raw_ostream &OS, const LineLocation &Loc)
Definition: SampleProf.cpp:111
llvm::sampleprof::FunctionSamples::UseMD5
static bool UseMD5
Whether the profile uses MD5 to represent string.
Definition: SampleProf.h:1118
llvm::sampleprof::CSProfileConverter::FrameNode::FuncName
StringRef FuncName
Definition: SampleProf.h:1258
llvm::sampleprof::SecHdrTableEntry::LayoutIndex
uint32_t LayoutIndex
Definition: SampleProf.h:166
llvm::sampleprof::ProfileSymbolList::merge
void merge(const ProfileSymbolList &List)
Definition: SampleProf.h:1295
llvm::sampleprof::CSProfileConverter::FrameNode::CallSiteLoc
LineLocation CallSiteLoc
Definition: SampleProf.h:1262
llvm::sampleprof::FunctionSamples::getOffset
static unsigned getOffset(const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
Definition: SampleProf.cpp:216
llvm::sampleprof::LineLocation
Represents the relative location of an instruction.
Definition: SampleProf.h:283
llvm::APInt
Class for arbitrary precision integers.
Definition: APInt.h:75
llvm::MergeResult
sampleprof_error MergeResult(sampleprof_error &Accumulator, sampleprof_error Result)
Definition: SampleProf.h:68
llvm::ArrayRef< SampleContextFrame >
llvm::sampleprof::SampleContext::IsPrefixOf
bool IsPrefixOf(const SampleContext &That) const
Definition: SampleProf.h:668
llvm::sampleprof::SampleContext::SampleContext
SampleContext(StringRef Name)
Definition: SampleProf.h:506
llvm::min
Expected< ExpressionValue > min(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:357
llvm::sampleprof::SecProfSummaryFlags
SecProfSummaryFlags
Definition: SampleProf.h:192
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::sampleprof::SampleSorter
Sort a LocationT->SampleT map by LocationT.
Definition: SampleProf.h:1199
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
llvm::sampleprof_error::unrecognized_format
@ unrecognized_format
llvm::sampleprof::SecInValid
@ SecInValid
Definition: SampleProf.h:122
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:743
llvm::sampleprof::SampleContextFrame::operator==
bool operator==(const SampleContextFrame &That) const
Definition: SampleProf.h:458
llvm::sampleprof::ProfileSymbolList::add
void add(StringRef Name, bool copy=false)
copy indicates whether we need to copy the underlying memory for the input Name.
Definition: SampleProf.h:1285
llvm::sampleprof::FunctionSamples::print
void print(raw_ostream &OS=dbgs(), unsigned Indent=0) const
Print the samples collected for a function on stream OS.
Definition: SampleProf.cpp:155
llvm::sampleprof::FunctionSamples::findFunctionSamplesMapAt
const FunctionSamplesMap * findFunctionSamplesMapAt(const LineLocation &Loc) const
Returns the FunctionSamplesMap at the given Loc.
Definition: SampleProf.h:856
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::sampleprof::FunctionSamples::findSamplesAt
ErrorOr< uint64_t > findSamplesAt(uint32_t LineOffset, uint32_t Discriminator) const
Return the number of samples collected at the given location.
Definition: SampleProf.h:820
llvm::sampleprof::SampleRecord::CallTargetMap
StringMap< uint64_t > CallTargetMap
Definition: SampleProf.h:331
Node
Definition: ItaniumDemangle.h:155
llvm::sampleprof::SPF_Text
@ SPF_Text
Definition: SampleProf.h:92
llvm::sampleprof::SecFuncOffsetFlags::SecFlagOrdered
@ SecFlagOrdered
llvm::sampleprof::getSecName
static std::string getSecName(SecType Type)
Definition: SampleProf.h:134
llvm::sampleprof::FunctionSamples::findFunctionSamplesAt
const FunctionSamples * findFunctionSamplesAt(const LineLocation &Loc, StringRef CalleeName, SampleProfileReaderItaniumRemapper *Remapper) const
Returns a pointer to FunctionSamples at the given callsite location Loc with callee CalleeName.
Definition: SampleProf.cpp:286
llvm::sampleprof::ProfileSymbolList::toCompress
bool toCompress()
Definition: SampleProf.h:1303
llvm::make_error_code
std::error_code make_error_code(BitcodeError E)
Definition: BitcodeReader.h:271
llvm::sampleprof::InlinedContext
@ InlinedContext
Definition: SampleProf.h:435
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:187
llvm::sampleprof_error::ostream_seek_unsupported
@ ostream_seek_unsupported
llvm::sampleprof::CSProfileConverter::convertProfiles
void convertProfiles()
Definition: SampleProf.cpp:547
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition: StringRef.h:137
llvm::MD5::MD5Result
Definition: MD5.h:43
llvm::stable_sort
void stable_sort(R &&Range)
Definition: STLExtras.h:1752
llvm::sampleprof::ProfileSymbolList::write
std::error_code write(raw_ostream &OS)
Definition: SampleProf.cpp:439
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
std
Definition: BitVector.h:851
llvm::sampleprof::LineLocation::print
void print(raw_ostream &OS) const
Definition: SampleProf.cpp:105
llvm::sampleprof::SampleRecord::print
void print(raw_ostream &OS, unsigned Indent) const
Print the sample record to the stream OS indented by Indent.
Definition: SampleProf.cpp:134
llvm::toString
const char * toString(DWARFSectionKind Kind)
Definition: DWARFUnitIndex.h:67
llvm::sampleprof::SPVersion
static uint64_t SPVersion()
Definition: SampleProf.h:116
llvm::ArrayRef::take_front
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition: ArrayRef.h:227
llvm::sampleprof::verifySecFlag
static void verifySecFlag(SecType Type, SecFlagType Flag)
Definition: SampleProf.h:224
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:589
llvm::sampleprof::SecProfileSymbolList
@ SecProfileSymbolList
Definition: SampleProf.h:125
Function.h
llvm::sampleprof::FunctionSamples::findCallTargetMapAt
ErrorOr< SampleRecord::CallTargetMap > findCallTargetMapAt(const LineLocation &CallSite) const
Returns the call target map collected at a given location specified by CallSite.
Definition: SampleProf.h:842
llvm::sampleprof::FunctionSamples::addTotalSamples
sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:718
llvm::sampleprof::SecType
SecType
Definition: SampleProf.h:121
llvm::sampleprof::SampleRecord
Representation of a single sample record.
Definition: SampleProf.h:318
llvm::sampleprof::CSProfileConverter::FrameNode::FrameNode
FrameNode(StringRef FName=StringRef(), FunctionSamples *FSamples=nullptr, LineLocation CallLoc={0, 0})
Definition: SampleProf.h:1250
llvm::sampleprof_error
sampleprof_error
Definition: SampleProf.h:46
llvm::sampleprof::FunctionSamples::merge
sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight=1)
Merge the samples in Other into this one.
Definition: SampleProf.h:936
llvm::sampleprof::FunctionSamples::LLVMSuffix
static constexpr const char * LLVMSuffix
Name suffixes which canonicalization should handle to avoid profile mismatch.
Definition: SampleProf.h:1025
llvm::sampleprof::ContextNone
@ ContextNone
Definition: SampleProf.h:441
llvm::sampleprof_error::zlib_unavailable
@ zlib_unavailable
llvm::sampleprof::SampleContext::hasContext
bool hasContext() const
Definition: SampleProf.h:588
llvm::sampleprof::SecFuncProfileFirst
@ SecFuncProfileFirst
Definition: SampleProf.h:130
llvm::sampleprof_error::too_large
@ too_large
llvm::sampleprof::SampleContextTrimmer::trimAndMergeColdContextProfiles
void trimAndMergeColdContextProfiles(uint64_t ColdCountThreshold, bool TrimColdContext, bool MergeColdContext, uint32_t ColdContextFrameLength, bool TrimBaseProfileOnly)
Definition: SampleProf.cpp:342
llvm::sampleprof::SampleRecord::addCalledTarget
sampleprof_error addCalledTarget(StringRef F, uint64_t S, uint64_t Weight=1)
Add called function F with samples S.
Definition: SampleProf.h:360
llvm::sampleprof::FunctionSamples::getContext
SampleContext & getContext() const
Definition: SampleProf.h:1113
llvm::sampleprof_error::success
@ success
llvm::sampleprof::SecNameTableFlags::SecFlagUniqSuffix
@ SecFlagUniqSuffix
llvm::sampleprof::FunctionSamples::getMaxCountInside
uint64_t getMaxCountInside() const
Return the maximum of sample counts in a function body including functions inlined in it.
Definition: SampleProf.h:924
llvm::sampleprof::ContextAttributeMask
ContextAttributeMask
Definition: SampleProf.h:440
llvm::sampleprof::SampleContextFrame::SampleContextFrame
SampleContextFrame(StringRef FuncName, LineLocation Location)
Definition: SampleProf.h:455
llvm::sampleprof::SampleContextTrimmer::SampleContextTrimmer
SampleContextTrimmer(SampleProfileMap &Profiles)
Definition: SampleProf.h:1223
llvm::sampleprof::SampleRecord::removeCalledTarget
uint64_t removeCalledTarget(StringRef F)
Remove called function from the call target map.
Definition: SampleProf.h:372
llvm::sampleprof::SecNameTableFlags
SecNameTableFlags
Definition: SampleProf.h:182
llvm::sampleprof::ContextWasInlined
@ ContextWasInlined
Definition: SampleProf.h:442
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:1017
llvm::sampleprof::SampleContextTrimmer::canonicalizeContextProfiles
void canonicalizeContextProfiles()
Definition: SampleProf.cpp:403
llvm::StringMapImpl::empty
bool empty() const
Definition: StringMap.h:94
SmallVector.h
llvm::sampleprof::SampleRecord::dump
void dump() const
Definition: SampleProf.cpp:145
llvm::DenseMapInfo< SampleContext >::getEmptyKey
static SampleContext getEmptyKey()
Definition: SampleProf.h:1323
llvm::sampleprof::SampleRecord::SortCallTargets
static const SortedCallTargetSet SortCallTargets(const CallTargetMap &Targets)
Sort call targets in descending order of call frequency.
Definition: SampleProf.h:399
llvm::hash_combine
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition: Hashing.h:605
llvm::sampleprof::SampleContextFrame::operator!=
bool operator!=(const SampleContextFrame &That) const
Definition: SampleProf.h:462
llvm::sampleprof::SecCommonFlags::SecFlagFlat
@ SecFlagFlat
llvm::sampleprof::SecCommonFlags
SecCommonFlags
Definition: SampleProf.h:172
List
const NodeList & List
Definition: RDFGraph.cpp:199
llvm::sampleprof::FunctionSamples::UniqSuffix
static constexpr const char * UniqSuffix
Definition: SampleProf.h:1027
llvm::sampleprof::SampleRecord::merge
sampleprof_error merge(const SampleRecord &Other, uint64_t Weight=1)
Merge the samples in Other into this record.
Definition: SampleProf.cpp:119
llvm::sampleprof::SecCSNameTable
@ SecCSNameTable
Definition: SampleProf.h:128
llvm::hash_combine_range
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition: Hashing.h:483
llvm::ErrorOr
Represents either an error or a value T.
Definition: ErrorOr.h:56
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:85
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:164
llvm::sampleprof::SecProfSummaryFlags::SecFlagIsPreInlined
@ SecFlagIsPreInlined
SecFlagIsPreInlined means this profile contains ShouldBeInlined contexts thus this is CS preinliner c...
llvm::sampleprof::SampleContext::getContextString
static std::string getContextString(SampleContextFrames Context, bool IncludeLeafLineLocation=false)
Definition: SampleProf.h:593
llvm::sampleprof::SecNameTable
@ SecNameTable
Definition: SampleProf.h:124
llvm::sampleprof::FunctionSamples::addBodySamplesForProbe
sampleprof_error addBodySamplesForProbe(uint32_t Index, uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:773
llvm::StringRef::str
std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:221
llvm::sampleprof::SampleProfileReaderItaniumRemapper
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...
Definition: SampleProfReader.h:261
llvm::sampleprof::SecFuncMetadata
@ SecFuncMetadata
Definition: SampleProf.h:127
llvm::sampleprof::SampleContextFrame
Definition: SampleProf.h:449
llvm::sampleprof_error::truncated_name_table
@ truncated_name_table
llvm::sampleprof::SampleSorter::SamplesWithLoc
std::pair< const LocationT, SampleT > SamplesWithLoc
Definition: SampleProf.h:1201
llvm::sampleprof::SampleContextTrimmer
SampleContextTrimmer impelements helper functions to trim, merge cold context profiles.
Definition: SampleProf.h:1221
llvm::sampleprof::ProfileSymbolList::dump
void dump(raw_ostream &OS=dbgs()) const
Definition: SampleProf.cpp:455
StringMap.h
llvm::sampleprof::FunctionSamples::updateCallsiteSamples
void updateCallsiteSamples()
Definition: SampleProf.h:781
llvm::sampleprof::SecFuncOffsetFlags::SecFlagInvalid
@ SecFlagInvalid
llvm::sampleprof_error::truncated
@ truncated
llvm::StringRef::split
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:689
Debug.h
llvm::sampleprof::SampleRecord::addSamples
sampleprof_error addSamples(uint64_t S, uint64_t Weight=1)
Increment the number of samples for this record by S.
Definition: SampleProf.h:339
llvm::sampleprof::SampleContextFrameHash::operator()
uint64_t operator()(const SampleContextFrameVector &S) const
Definition: SampleProf.h:487
llvm::sampleprof::SecFuncMetadataFlags
SecFuncMetadataFlags
Definition: SampleProf.h:209
llvm::sampleprof_error::bad_magic
@ bad_magic
llvm::sampleprof::CSProfileConverter::CSProfileConverter
CSProfileConverter(SampleProfileMap &Profiles)
Definition: SampleProf.cpp:479
llvm::sampleprof::FunctionSamples::setFunctionHash
void setFunctionHash(uint64_t Hash)
Definition: SampleProf.h:1011
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1247
llvm::sampleprof::FunctionSamples::getCallSiteIdentifier
static LineLocation getCallSiteIdentifier(const DILocation *DIL, bool ProfileIsFS=false)
Returns a unique call site identifier for a given debug location of a call instruction.
Definition: SampleProf.cpp:221
llvm::sampleprof::FunctionSamples::findFunctionSamples
const FunctionSamples * findFunctionSamples(const DILocation *DIL, SampleProfileReaderItaniumRemapper *Remapper=nullptr) const
Get the FunctionSamples of the inline instance where DIL originates from.
Definition: SampleProf.cpp:246
llvm::hash_code
An opaque object representing a hash code.
Definition: Hashing.h:73
llvm::sampleprof::FunctionSamples::ProfileIsPreInlined
static bool ProfileIsPreInlined
Definition: SampleProf.h:1111
llvm::sampleprof::SampleContext::Hash::operator()
uint64_t operator()(const SampleContext &Context) const
Definition: SampleProf.h:663
llvm::sampleprof::FunctionSamples::setName
void setName(StringRef FunctionName)
Set the name of the function.
Definition: SampleProf.h:1003