LLVM  14.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/StringMap.h"
20 #include "llvm/ADT/StringRef.h"
21 #include "llvm/ADT/StringSet.h"
22 #include "llvm/IR/Function.h"
23 #include "llvm/IR/GlobalValue.h"
24 #include "llvm/IR/Module.h"
25 #include "llvm/Support/Allocator.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/ErrorOr.h"
30 #include <algorithm>
31 #include <cstdint>
32 #include <list>
33 #include <map>
34 #include <set>
35 #include <sstream>
36 #include <string>
37 #include <system_error>
38 #include <unordered_map>
39 #include <utility>
40 
41 namespace llvm {
42 
44 
45 enum class sampleprof_error {
46  success = 0,
47  bad_magic,
49  too_large,
50  truncated,
51  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 profile for
199  /// CSSPGO
200  SecFlagFullContext = (1 << 1),
201  /// SecFlagFSDiscriminator means this profile uses flow-sensitive
202  /// discriminators.
203  SecFlagFSDiscriminator = (1 << 2)
204 };
205 
207  SecFlagInvalid = 0,
208  SecFlagIsProbeBased = (1 << 0),
209  SecFlagHasAttribute = (1 << 1),
210  SecFlagIsCSNested = (1 << 2),
211 };
212 
214  SecFlagInvalid = 0,
215  // Store function offsets in an order of contexts. The order ensures that
216  // callee contexts of a given context laid out next to it.
217  SecFlagOrdered = (1 << 0),
218 };
219 
220 // Verify section specific flag is used for the correct section.
221 template <class SecFlagType>
222 static inline void verifySecFlag(SecType Type, SecFlagType Flag) {
223  // No verification is needed for common flags.
224  if (std::is_same<SecCommonFlags, SecFlagType>())
225  return;
226 
227  // Verification starts here for section specific flag.
228  bool IsFlagLegal = false;
229  switch (Type) {
230  case SecNameTable:
231  IsFlagLegal = std::is_same<SecNameTableFlags, SecFlagType>();
232  break;
233  case SecProfSummary:
234  IsFlagLegal = std::is_same<SecProfSummaryFlags, SecFlagType>();
235  break;
236  case SecFuncMetadata:
237  IsFlagLegal = std::is_same<SecFuncMetadataFlags, SecFlagType>();
238  break;
239  default:
240  case SecFuncOffsetTable:
241  IsFlagLegal = std::is_same<SecFuncOffsetFlags, SecFlagType>();
242  break;
243  }
244  if (!IsFlagLegal)
245  llvm_unreachable("Misuse of a flag in an incompatible section");
246 }
247 
248 template <class SecFlagType>
249 static inline void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag) {
250  verifySecFlag(Entry.Type, Flag);
251  auto FVal = static_cast<uint64_t>(Flag);
252  bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
253  Entry.Flags |= IsCommon ? FVal : (FVal << 32);
254 }
255 
256 template <class SecFlagType>
257 static inline void removeSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag) {
258  verifySecFlag(Entry.Type, Flag);
259  auto FVal = static_cast<uint64_t>(Flag);
260  bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
261  Entry.Flags &= ~(IsCommon ? FVal : (FVal << 32));
262 }
263 
264 template <class SecFlagType>
265 static inline bool hasSecFlag(const SecHdrTableEntry &Entry, SecFlagType Flag) {
266  verifySecFlag(Entry.Type, Flag);
267  auto FVal = static_cast<uint64_t>(Flag);
268  bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
269  return Entry.Flags & (IsCommon ? FVal : (FVal << 32));
270 }
271 
272 /// Represents the relative location of an instruction.
273 ///
274 /// Instruction locations are specified by the line offset from the
275 /// beginning of the function (marked by the line where the function
276 /// header is) and the discriminator value within that line.
277 ///
278 /// The discriminator value is useful to distinguish instructions
279 /// that are on the same line but belong to different basic blocks
280 /// (e.g., the two post-increment instructions in "if (p) x++; else y++;").
281 struct LineLocation {
283 
284  void print(raw_ostream &OS) const;
285  void dump() const;
286 
287  bool operator<(const LineLocation &O) const {
288  return LineOffset < O.LineOffset ||
289  (LineOffset == O.LineOffset && Discriminator < O.Discriminator);
290  }
291 
292  bool operator==(const LineLocation &O) const {
293  return LineOffset == O.LineOffset && Discriminator == O.Discriminator;
294  }
295 
296  bool operator!=(const LineLocation &O) const {
297  return LineOffset != O.LineOffset || Discriminator != O.Discriminator;
298  }
299 
302 };
303 
305 
306 /// Representation of a single sample record.
307 ///
308 /// A sample record is represented by a positive integer value, which
309 /// indicates how frequently was the associated line location executed.
310 ///
311 /// Additionally, if the associated location contains a function call,
312 /// the record will hold a list of all the possible called targets. For
313 /// direct calls, this will be the exact function being invoked. For
314 /// indirect calls (function pointers, virtual table dispatch), this
315 /// will be a list of one or more functions.
317 public:
318  using CallTarget = std::pair<StringRef, uint64_t>;
320  bool operator()(const CallTarget &LHS, const CallTarget &RHS) const {
321  if (LHS.second != RHS.second)
322  return LHS.second > RHS.second;
323 
324  return LHS.first < RHS.first;
325  }
326  };
327 
328  using SortedCallTargetSet = std::set<CallTarget, CallTargetComparator>;
330  SampleRecord() = default;
331 
332  /// Increment the number of samples for this record by \p S.
333  /// Optionally scale sample count \p S by \p Weight.
334  ///
335  /// Sample counts accumulate using saturating arithmetic, to avoid wrapping
336  /// around unsigned integers.
338  bool Overflowed;
339  NumSamples = SaturatingMultiplyAdd(S, Weight, NumSamples, &Overflowed);
340  return Overflowed ? sampleprof_error::counter_overflow
342  }
343 
344  /// Add called function \p F with samples \p S.
345  /// Optionally scale sample count \p S by \p Weight.
346  ///
347  /// Sample counts accumulate using saturating arithmetic, to avoid wrapping
348  /// around unsigned integers.
350  uint64_t Weight = 1) {
351  uint64_t &TargetSamples = CallTargets[F];
352  bool Overflowed;
353  TargetSamples =
354  SaturatingMultiplyAdd(S, Weight, TargetSamples, &Overflowed);
355  return Overflowed ? sampleprof_error::counter_overflow
357  }
358 
359  /// Return true if this sample record contains function calls.
360  bool hasCalls() const { return !CallTargets.empty(); }
361 
362  uint64_t getSamples() const { return NumSamples; }
363  const CallTargetMap &getCallTargets() const { return CallTargets; }
365  return SortCallTargets(CallTargets);
366  }
367 
368  /// Sort call targets in descending order of call frequency.
369  static const SortedCallTargetSet SortCallTargets(const CallTargetMap &Targets) {
370  SortedCallTargetSet SortedTargets;
371  for (const auto &I : Targets) {
372  SortedTargets.emplace(I.first(), I.second);
373  }
374  return SortedTargets;
375  }
376 
377  /// Prorate call targets by a distribution factor.
378  static const CallTargetMap adjustCallTargets(const CallTargetMap &Targets,
379  float DistributionFactor) {
380  CallTargetMap AdjustedTargets;
381  for (const auto &I : Targets) {
382  AdjustedTargets[I.first()] = I.second * DistributionFactor;
383  }
384  return AdjustedTargets;
385  }
386 
387  /// Merge the samples in \p Other into this record.
388  /// Optionally scale sample counts by \p Weight.
389  sampleprof_error merge(const SampleRecord &Other, uint64_t Weight = 1);
390  void print(raw_ostream &OS, unsigned Indent) const;
391  void dump() const;
392 
393 private:
394  uint64_t NumSamples = 0;
395  CallTargetMap CallTargets;
396 };
397 
398 raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample);
399 
400 // State of context associated with FunctionSamples
402  UnknownContext = 0x0, // Profile without context
403  RawContext = 0x1, // Full context profile from input profile
404  SyntheticContext = 0x2, // Synthetic context created for context promotion
405  InlinedContext = 0x4, // Profile for context that is inlined into caller
406  MergedContext = 0x8 // Profile for context merged into base profile
407 };
408 
409 // Attribute of context associated with FunctionSamples
411  ContextNone = 0x0,
412  ContextWasInlined = 0x1, // Leaf of context was inlined in previous build
413  ContextShouldBeInlined = 0x2, // Leaf of context should be inlined
414 };
415 
416 // Represents a context frame with function name and line location
420 
422 
425 
426  bool operator==(const SampleContextFrame &That) const {
427  return Location == That.Location && FuncName == That.FuncName;
428  }
429 
430  bool operator!=(const SampleContextFrame &That) const {
431  return !(*this == That);
432  }
433 
434  std::string toString(bool OutputLineLocation) const {
435  std::ostringstream OContextStr;
436  OContextStr << FuncName.str();
437  if (OutputLineLocation) {
438  OContextStr << ":" << Location.LineOffset;
440  OContextStr << "." << Location.Discriminator;
441  }
442  return OContextStr.str();
443  }
444 };
445 
446 static inline hash_code hash_value(const SampleContextFrame &arg) {
447  return hash_combine(arg.FuncName, arg.Location.LineOffset,
448  arg.Location.Discriminator);
449 }
450 
453 
456  return hash_combine_range(S.begin(), S.end());
457  }
458 };
459 
460 // Sample context for FunctionSamples. It consists of the calling context,
461 // the function name and context state. Internally sample context is represented
462 // using ArrayRef, which is also the input for constructing a `SampleContext`.
463 // It can accept and represent both full context string as well as context-less
464 // function name.
465 // For a CS profile, a full context vector can look like:
466 // `main:3 _Z5funcAi:1 _Z8funcLeafi`
467 // For a base CS profile without calling context, the context vector should only
468 // contain the leaf frame name.
469 // For a non-CS profile, the context vector should be empty.
471 public:
472  SampleContext() : State(UnknownContext), Attributes(ContextNone) {}
473 
475  : Name(Name), State(UnknownContext), Attributes(ContextNone) {}
476 
478  ContextStateMask CState = RawContext)
479  : Attributes(ContextNone) {
480  assert(!Context.empty() && "Context is empty");
481  setContext(Context, CState);
482  }
483 
484  // Give a context string, decode and populate internal states like
485  // Function name, Calling context and context state. Example of input
486  // `ContextStr`: `[main:3 @ _Z5funcAi:1 @ _Z8funcLeafi]`
488  std::list<SampleContextFrameVector> &CSNameTable,
489  ContextStateMask CState = RawContext)
490  : Attributes(ContextNone) {
491  assert(!ContextStr.empty());
492  // Note that `[]` wrapped input indicates a full context string, otherwise
493  // it's treated as context-less function name only.
494  bool HasContext = ContextStr.startswith("[");
495  if (!HasContext) {
496  State = UnknownContext;
497  Name = ContextStr;
498  } else {
499  CSNameTable.emplace_back();
500  SampleContextFrameVector &Context = CSNameTable.back();
501  createCtxVectorFromStr(ContextStr, Context);
502  setContext(Context, CState);
503  }
504  }
505 
506  /// Create a context vector from a given context string and save it in
507  /// `Context`.
508  static void createCtxVectorFromStr(StringRef ContextStr,
510  // Remove encapsulating '[' and ']' if any
511  ContextStr = ContextStr.substr(1, ContextStr.size() - 2);
512  StringRef ContextRemain = ContextStr;
513  StringRef ChildContext;
514  StringRef CalleeName;
515  while (!ContextRemain.empty()) {
516  auto ContextSplit = ContextRemain.split(" @ ");
517  ChildContext = ContextSplit.first;
518  ContextRemain = ContextSplit.second;
519  LineLocation CallSiteLoc(0, 0);
520  decodeContextString(ChildContext, CalleeName, CallSiteLoc);
521  Context.emplace_back(CalleeName, CallSiteLoc);
522  }
523  }
524 
525  // Promote context by removing top frames with the length of
526  // `ContextFramesToRemove`. Note that with array representation of context,
527  // the promotion is effectively a slice operation with first
528  // `ContextFramesToRemove` elements removed from left.
529  void promoteOnPath(uint32_t ContextFramesToRemove) {
530  assert(ContextFramesToRemove <= FullContext.size() &&
531  "Cannot remove more than the whole context");
532  FullContext = FullContext.drop_front(ContextFramesToRemove);
533  }
534 
535  // Decode context string for a frame to get function name and location.
536  // `ContextStr` is in the form of `FuncName:StartLine.Discriminator`.
537  static void decodeContextString(StringRef ContextStr, StringRef &FName,
538  LineLocation &LineLoc) {
539  // Get function name
540  auto EntrySplit = ContextStr.split(':');
541  FName = EntrySplit.first;
542 
543  LineLoc = {0, 0};
544  if (!EntrySplit.second.empty()) {
545  // Get line offset, use signed int for getAsInteger so string will
546  // be parsed as signed.
547  int LineOffset = 0;
548  auto LocSplit = EntrySplit.second.split('.');
549  LocSplit.first.getAsInteger(10, LineOffset);
550  LineLoc.LineOffset = LineOffset;
551 
552  // Get discriminator
553  if (!LocSplit.second.empty())
554  LocSplit.second.getAsInteger(10, LineLoc.Discriminator);
555  }
556  }
557 
558  operator SampleContextFrames() const { return FullContext; }
559  bool hasAttribute(ContextAttributeMask A) { return Attributes & (uint32_t)A; }
560  void setAttribute(ContextAttributeMask A) { Attributes |= (uint32_t)A; }
561  uint32_t getAllAttributes() { return Attributes; }
562  void setAllAttributes(uint32_t A) { Attributes = A; }
563  bool hasState(ContextStateMask S) { return State & (uint32_t)S; }
564  void setState(ContextStateMask S) { State |= (uint32_t)S; }
565  void clearState(ContextStateMask S) { State &= (uint32_t)~S; }
566  bool hasContext() const { return State != UnknownContext; }
567  bool isBaseContext() const { return FullContext.size() == 1; }
568  StringRef getName() const { return Name; }
569  SampleContextFrames getContextFrames() const { return FullContext; }
570 
572  bool IncludeLeafLineLocation = false) {
573  std::ostringstream OContextStr;
574  for (uint32_t I = 0; I < Context.size(); I++) {
575  if (OContextStr.str().size()) {
576  OContextStr << " @ ";
577  }
578  OContextStr << Context[I].toString(I != Context.size() - 1 ||
579  IncludeLeafLineLocation);
580  }
581  return OContextStr.str();
582  }
583 
584  std::string toString() const {
585  if (!hasContext())
586  return Name.str();
587  return getContextString(FullContext, false);
588  }
589 
592  : hash_value(getName());
593  }
594 
595  /// Set the name of the function and clear the current context.
596  void setName(StringRef FunctionName) {
597  Name = FunctionName;
598  FullContext = SampleContextFrames();
599  State = UnknownContext;
600  }
601 
603  ContextStateMask CState = RawContext) {
604  assert(CState != UnknownContext);
605  FullContext = Context;
606  Name = Context.back().FuncName;
607  State = CState;
608  }
609 
610  bool operator==(const SampleContext &That) const {
611  return State == That.State && Name == That.Name &&
612  FullContext == That.FullContext;
613  }
614 
615  bool operator!=(const SampleContext &That) const { return !(*this == That); }
616 
617  bool operator<(const SampleContext &That) const {
618  if (State != That.State)
619  return State < That.State;
620 
621  if (!hasContext()) {
622  return (Name.compare(That.Name)) == -1;
623  }
624 
625  uint64_t I = 0;
626  while (I < std::min(FullContext.size(), That.FullContext.size())) {
627  auto &Context1 = FullContext[I];
628  auto &Context2 = That.FullContext[I];
629  auto V = Context1.FuncName.compare(Context2.FuncName);
630  if (V)
631  return V == -1;
632  if (Context1.Location != Context2.Location)
633  return Context1.Location < Context2.Location;
634  I++;
635  }
636 
637  return FullContext.size() < That.FullContext.size();
638  }
639 
640  struct Hash {
642  return Context.getHashCode();
643  }
644  };
645 
646  bool IsPrefixOf(const SampleContext &That) const {
647  auto ThisContext = FullContext;
648  auto ThatContext = That.FullContext;
649  if (ThatContext.size() < ThisContext.size())
650  return false;
651  ThatContext = ThatContext.take_front(ThisContext.size());
652  // Compare Leaf frame first
653  if (ThisContext.back().FuncName != ThatContext.back().FuncName)
654  return false;
655  // Compare leading context
656  return ThisContext.drop_back() == ThatContext.drop_back();
657  }
658 
659 private:
660  /// Mangled name of the function.
661  StringRef Name;
662  // Full context including calling context and leaf function name
663  SampleContextFrames FullContext;
664  // State of the associated sample profile
665  uint32_t State;
666  // Attribute of the associated sample profile
667  uint32_t Attributes;
668 };
669 
670 static inline hash_code hash_value(const SampleContext &arg) {
671  return arg.hasContext() ? hash_value(arg.getContextFrames())
672  : hash_value(arg.getName());
673 }
674 
675 class FunctionSamples;
677 
678 using BodySampleMap = std::map<LineLocation, SampleRecord>;
679 // NOTE: Using a StringMap here makes parsed profiles consume around 17% more
680 // memory, which is *very* significant for large profiles.
681 using FunctionSamplesMap = std::map<std::string, FunctionSamples, std::less<>>;
682 using CallsiteSampleMap = std::map<LineLocation, FunctionSamplesMap>;
683 
684 /// Representation of the samples collected for a function.
685 ///
686 /// This data structure contains all the collected samples for the body
687 /// of a function. Each sample corresponds to a LineLocation instance
688 /// within the body of the function.
690 public:
691  FunctionSamples() = default;
692 
693  void print(raw_ostream &OS = dbgs(), unsigned Indent = 0) const;
694  void dump() const;
695 
697  bool Overflowed;
698  TotalSamples =
699  SaturatingMultiplyAdd(Num, Weight, TotalSamples, &Overflowed);
700  return Overflowed ? sampleprof_error::counter_overflow
702  }
703 
704  void setTotalSamples(uint64_t Num) { TotalSamples = Num; }
705 
707  bool Overflowed;
708  TotalHeadSamples =
709  SaturatingMultiplyAdd(Num, Weight, TotalHeadSamples, &Overflowed);
710  return Overflowed ? sampleprof_error::counter_overflow
712  }
713 
715  uint64_t Num, uint64_t Weight = 1) {
716  return BodySamples[LineLocation(LineOffset, Discriminator)].addSamples(
717  Num, Weight);
718  }
719 
721  uint32_t Discriminator,
722  StringRef FName, uint64_t Num,
723  uint64_t Weight = 1) {
724  return BodySamples[LineLocation(LineOffset, Discriminator)].addCalledTarget(
725  FName, Num, Weight);
726  }
727 
729  uint64_t Weight = 1) {
730  SampleRecord S;
731  S.addSamples(Num, Weight);
732  return BodySamples[LineLocation(Index, 0)].merge(S, Weight);
733  }
734 
735  // Accumulate all body samples to set total samples.
737  setTotalSamples(0);
738  for (const auto &I : BodySamples)
739  addTotalSamples(I.second.getSamples());
740 
741  for (auto &I : CallsiteSamples) {
742  for (auto &CS : I.second) {
743  CS.second.updateTotalSamples();
744  addTotalSamples(CS.second.getTotalSamples());
745  }
746  }
747  }
748 
749  // Set current context and all callee contexts to be synthetic.
751  Context.setState(SyntheticContext);
752  for (auto &I : CallsiteSamples) {
753  for (auto &CS : I.second) {
754  CS.second.SetContextSynthetic();
755  }
756  }
757  }
758 
759  /// Return the number of samples collected at the given location.
760  /// Each location is specified by \p LineOffset and \p Discriminator.
761  /// If the location is not found in profile, return error.
763  uint32_t Discriminator) const {
764  const auto &ret = BodySamples.find(LineLocation(LineOffset, Discriminator));
765  if (ret == BodySamples.end())
766  return std::error_code();
767  return ret->second.getSamples();
768  }
769 
770  /// Returns the call target map collected at a given location.
771  /// Each location is specified by \p LineOffset and \p Discriminator.
772  /// If the location is not found in profile, return error.
774  findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const {
775  const auto &ret = BodySamples.find(LineLocation(LineOffset, Discriminator));
776  if (ret == BodySamples.end())
777  return std::error_code();
778  return ret->second.getCallTargets();
779  }
780 
781  /// Returns the call target map collected at a given location specified by \p
782  /// CallSite. If the location is not found in profile, return error.
784  findCallTargetMapAt(const LineLocation &CallSite) const {
785  const auto &Ret = BodySamples.find(CallSite);
786  if (Ret == BodySamples.end())
787  return std::error_code();
788  return Ret->second.getCallTargets();
789  }
790 
791  /// Return the function samples at the given callsite location.
793  return CallsiteSamples[Loc];
794  }
795 
796  /// Returns the FunctionSamplesMap at the given \p Loc.
797  const FunctionSamplesMap *
799  auto iter = CallsiteSamples.find(Loc);
800  if (iter == CallsiteSamples.end())
801  return nullptr;
802  return &iter->second;
803  }
804 
805  /// Returns a pointer to FunctionSamples at the given callsite location
806  /// \p Loc with callee \p CalleeName. If no callsite can be found, relax
807  /// the restriction to return the FunctionSamples at callsite location
808  /// \p Loc with the maximum total sample count. If \p Remapper is not
809  /// nullptr, use \p Remapper to find FunctionSamples with equivalent name
810  /// as \p CalleeName.
811  const FunctionSamples *
812  findFunctionSamplesAt(const LineLocation &Loc, StringRef CalleeName,
813  SampleProfileReaderItaniumRemapper *Remapper) const;
814 
815  bool empty() const { return TotalSamples == 0; }
816 
817  /// Return the total number of samples collected inside the function.
818  uint64_t getTotalSamples() const { return TotalSamples; }
819 
820  /// Return the total number of branch samples that have the function as the
821  /// branch target. This should be equivalent to the sample of the first
822  /// instruction of the symbol. But as we directly get this info for raw
823  /// profile without referring to potentially inaccurate debug info, this
824  /// gives more accurate profile data and is preferred for standalone symbols.
825  uint64_t getHeadSamples() const { return TotalHeadSamples; }
826 
827  /// Return the sample count of the first instruction of the function.
828  /// The function can be either a standalone symbol or an inlined function.
831  // For CS profile, if we already have more accurate head samples
832  // counted by branch sample from caller, use them as entry samples.
833  return getHeadSamples();
834  }
835  uint64_t Count = 0;
836  // Use either BodySamples or CallsiteSamples which ever has the smaller
837  // lineno.
838  if (!BodySamples.empty() &&
839  (CallsiteSamples.empty() ||
840  BodySamples.begin()->first < CallsiteSamples.begin()->first))
841  Count = BodySamples.begin()->second.getSamples();
842  else if (!CallsiteSamples.empty()) {
843  // An indirect callsite may be promoted to several inlined direct calls.
844  // We need to get the sum of them.
845  for (const auto &N_FS : CallsiteSamples.begin()->second)
846  Count += N_FS.second.getEntrySamples();
847  }
848  // Return at least 1 if total sample is not 0.
849  return Count ? Count : TotalSamples > 0;
850  }
851 
852  /// Return all the samples collected in the body of the function.
853  const BodySampleMap &getBodySamples() const { return BodySamples; }
854 
855  /// Return all the callsite samples collected in the body of the function.
857  return CallsiteSamples;
858  }
859 
860  /// Return the maximum of sample counts in a function body including functions
861  /// inlined in it.
863  uint64_t MaxCount = 0;
864  for (const auto &L : getBodySamples())
865  MaxCount = std::max(MaxCount, L.second.getSamples());
866  for (const auto &C : getCallsiteSamples())
867  for (const FunctionSamplesMap::value_type &F : C.second)
868  MaxCount = std::max(MaxCount, F.second.getMaxCountInside());
869  return MaxCount;
870  }
871 
872  /// Merge the samples in \p Other into this one.
873  /// Optionally scale samples by \p Weight.
874  sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight = 1) {
876  if (!GUIDToFuncNameMap)
877  GUIDToFuncNameMap = Other.GUIDToFuncNameMap;
878  if (Context.getName().empty())
879  Context = Other.getContext();
880  if (FunctionHash == 0) {
881  // Set the function hash code for the target profile.
882  FunctionHash = Other.getFunctionHash();
883  } else if (FunctionHash != Other.getFunctionHash()) {
884  // The two profiles coming with different valid hash codes indicates
885  // either:
886  // 1. They are same-named static functions from different compilation
887  // units (without using -unique-internal-linkage-names), or
888  // 2. They are really the same function but from different compilations.
889  // Let's bail out in either case for now, which means one profile is
890  // dropped.
892  }
893 
894  MergeResult(Result, addTotalSamples(Other.getTotalSamples(), Weight));
895  MergeResult(Result, addHeadSamples(Other.getHeadSamples(), Weight));
896  for (const auto &I : Other.getBodySamples()) {
897  const LineLocation &Loc = I.first;
898  const SampleRecord &Rec = I.second;
899  MergeResult(Result, BodySamples[Loc].merge(Rec, Weight));
900  }
901  for (const auto &I : Other.getCallsiteSamples()) {
902  const LineLocation &Loc = I.first;
904  for (const auto &Rec : I.second)
905  MergeResult(Result, FSMap[Rec.first].merge(Rec.second, Weight));
906  }
907  return Result;
908  }
909 
910  /// Recursively traverses all children, if the total sample count of the
911  /// corresponding function is no less than \p Threshold, add its corresponding
912  /// GUID to \p S. Also traverse the BodySamples to add hot CallTarget's GUID
913  /// to \p S.
916  uint64_t Threshold) const {
917  if (TotalSamples <= Threshold)
918  return;
919  auto isDeclaration = [](const Function *F) {
920  return !F || F->isDeclaration();
921  };
922  if (isDeclaration(SymbolMap.lookup(getFuncName()))) {
923  // Add to the import list only when it's defined out of module.
924  S.insert(getGUID(getName()));
925  }
926  // Import hot CallTargets, which may not be available in IR because full
927  // profile annotation cannot be done until backend compilation in ThinLTO.
928  for (const auto &BS : BodySamples)
929  for (const auto &TS : BS.second.getCallTargets())
930  if (TS.getValue() > Threshold) {
931  const Function *Callee = SymbolMap.lookup(getFuncName(TS.getKey()));
932  if (isDeclaration(Callee))
933  S.insert(getGUID(TS.getKey()));
934  }
935  for (const auto &CS : CallsiteSamples)
936  for (const auto &NameFS : CS.second)
937  NameFS.second.findInlinedFunctions(S, SymbolMap, Threshold);
938  }
939 
940  /// Set the name of the function.
941  void setName(StringRef FunctionName) { Context.setName(FunctionName); }
942 
943  /// Return the function name.
944  StringRef getName() const { return Context.getName(); }
945 
946  /// Return the original function name.
947  StringRef getFuncName() const { return getFuncName(getName()); }
948 
949  void setFunctionHash(uint64_t Hash) { FunctionHash = Hash; }
950 
951  uint64_t getFunctionHash() const { return FunctionHash; }
952 
953  /// Return the canonical name for a function, taking into account
954  /// suffix elision policy attributes.
956  auto AttrName = "sample-profile-suffix-elision-policy";
957  auto Attr = F.getFnAttribute(AttrName).getValueAsString();
958  return getCanonicalFnName(F.getName(), Attr);
959  }
960 
961  /// Name suffixes which canonicalization should handle to avoid
962  /// profile mismatch.
963  static constexpr const char *LLVMSuffix = ".llvm.";
964  static constexpr const char *PartSuffix = ".part.";
965  static constexpr const char *UniqSuffix = ".__uniq.";
966 
968  StringRef Attr = "selected") {
969  // Note the sequence of the suffixes in the knownSuffixes array matters.
970  // If suffix "A" is appended after the suffix "B", "A" should be in front
971  // of "B" in knownSuffixes.
972  const char *knownSuffixes[] = {LLVMSuffix, PartSuffix, UniqSuffix};
973  if (Attr == "" || Attr == "all") {
974  return FnName.split('.').first;
975  } else if (Attr == "selected") {
976  StringRef Cand(FnName);
977  for (const auto &Suf : knownSuffixes) {
978  StringRef Suffix(Suf);
979  // If the profile contains ".__uniq." suffix, don't strip the
980  // suffix for names in the IR.
982  continue;
983  auto It = Cand.rfind(Suffix);
984  if (It == StringRef::npos)
985  continue;
986  auto Dit = Cand.rfind('.');
987  if (Dit == It + Suffix.size() - 1)
988  Cand = Cand.substr(0, It);
989  }
990  return Cand;
991  } else if (Attr == "none") {
992  return FnName;
993  } else {
994  assert(false && "internal error: unknown suffix elision policy");
995  }
996  return FnName;
997  }
998 
999  /// Translate \p Name into its original name.
1000  /// When profile doesn't use MD5, \p Name needs no translation.
1001  /// When profile uses MD5, \p Name in current FunctionSamples
1002  /// is actually GUID of the original function name. getFuncName will
1003  /// translate \p Name in current FunctionSamples into its original name
1004  /// by looking up in the function map GUIDToFuncNameMap.
1005  /// If the original name doesn't exist in the map, return empty StringRef.
1007  if (!UseMD5)
1008  return Name;
1009 
1010  assert(GUIDToFuncNameMap && "GUIDToFuncNameMap needs to be populated first");
1011  return GUIDToFuncNameMap->lookup(std::stoull(Name.data()));
1012  }
1013 
1014  /// Returns the line offset to the start line of the subprogram.
1015  /// We assume that a single function will not exceed 65535 LOC.
1016  static unsigned getOffset(const DILocation *DIL);
1017 
1018  /// Returns a unique call site identifier for a given debug location of a call
1019  /// instruction. This is wrapper of two scenarios, the probe-based profile and
1020  /// regular profile, to hide implementation details from the sample loader and
1021  /// the context tracker.
1022  static LineLocation getCallSiteIdentifier(const DILocation *DIL,
1023  bool ProfileIsFS = false);
1024 
1025  /// Returns a unique hash code for a combination of a callsite location and
1026  /// the callee function name.
1027  static uint64_t getCallSiteHash(StringRef CalleeName,
1028  const LineLocation &Callsite);
1029 
1030  /// Get the FunctionSamples of the inline instance where DIL originates
1031  /// from.
1032  ///
1033  /// The FunctionSamples of the instruction (Machine or IR) associated to
1034  /// \p DIL is the inlined instance in which that instruction is coming from.
1035  /// We traverse the inline stack of that instruction, and match it with the
1036  /// tree nodes in the profile.
1037  ///
1038  /// \returns the FunctionSamples pointer to the inlined instance.
1039  /// If \p Remapper is not nullptr, it will be used to find matching
1040  /// FunctionSamples with not exactly the same but equivalent name.
1042  const DILocation *DIL,
1043  SampleProfileReaderItaniumRemapper *Remapper = nullptr) const;
1044 
1045  static bool ProfileIsProbeBased;
1046 
1047  static bool ProfileIsCSFlat;
1048 
1049  static bool ProfileIsCSNested;
1050 
1051  SampleContext &getContext() const { return Context; }
1052 
1053  void setContext(const SampleContext &FContext) { Context = FContext; }
1054 
1056 
1057  /// Whether the profile uses MD5 to represent string.
1058  static bool UseMD5;
1059 
1060  /// Whether the profile contains any ".__uniq." suffix in a name.
1061  static bool HasUniqSuffix;
1062 
1063  /// If this profile uses flow sensitive discriminators.
1064  static bool ProfileIsFS;
1065 
1066  /// GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for
1067  /// all the function symbols defined or declared in current module.
1069 
1070  // Assume the input \p Name is a name coming from FunctionSamples itself.
1071  // If UseMD5 is true, the name is already a GUID and we
1072  // don't want to return the GUID of GUID.
1074  return UseMD5 ? std::stoull(Name.data()) : Function::getGUID(Name);
1075  }
1076 
1077  // Find all the names in the current FunctionSamples including names in
1078  // all the inline instances and names of call targets.
1079  void findAllNames(DenseSet<StringRef> &NameSet) const;
1080 
1081 private:
1082  /// CFG hash value for the function.
1083  uint64_t FunctionHash = 0;
1084 
1085  /// Calling context for function profile
1086  mutable SampleContext Context;
1087 
1088  /// Total number of samples collected inside this function.
1089  ///
1090  /// Samples are cumulative, they include all the samples collected
1091  /// inside this function and all its inlined callees.
1092  uint64_t TotalSamples = 0;
1093 
1094  /// Total number of samples collected at the head of the function.
1095  /// This is an approximation of the number of calls made to this function
1096  /// at runtime.
1097  uint64_t TotalHeadSamples = 0;
1098 
1099  /// Map instruction locations to collected samples.
1100  ///
1101  /// Each entry in this map contains the number of samples
1102  /// collected at the corresponding line offset. All line locations
1103  /// are an offset from the start of the function.
1104  BodySampleMap BodySamples;
1105 
1106  /// Map call sites to collected samples for the called function.
1107  ///
1108  /// Each entry in this map corresponds to all the samples
1109  /// collected for the inlined function call at the given
1110  /// location. For example, given:
1111  ///
1112  /// void foo() {
1113  /// 1 bar();
1114  /// ...
1115  /// 8 baz();
1116  /// }
1117  ///
1118  /// If the bar() and baz() calls were inlined inside foo(), this
1119  /// map will contain two entries. One for all the samples collected
1120  /// in the call to bar() at line offset 1, the other for all the samples
1121  /// collected in the call to baz() at line offset 8.
1122  CallsiteSampleMap CallsiteSamples;
1123 };
1124 
1126 
1127 using SampleProfileMap =
1128  std::unordered_map<SampleContext, FunctionSamples, SampleContext::Hash>;
1129 
1130 using NameFunctionSamples = std::pair<SampleContext, const FunctionSamples *>;
1131 
1132 void sortFuncProfiles(const SampleProfileMap &ProfileMap,
1133  std::vector<NameFunctionSamples> &SortedProfiles);
1134 
1135 /// Sort a LocationT->SampleT map by LocationT.
1136 ///
1137 /// It produces a sorted list of <LocationT, SampleT> records by ascending
1138 /// order of LocationT.
1139 template <class LocationT, class SampleT> class SampleSorter {
1140 public:
1141  using SamplesWithLoc = std::pair<const LocationT, SampleT>;
1143 
1144  SampleSorter(const std::map<LocationT, SampleT> &Samples) {
1145  for (const auto &I : Samples)
1146  V.push_back(&I);
1147  llvm::stable_sort(V, [](const SamplesWithLoc *A, const SamplesWithLoc *B) {
1148  return A->first < B->first;
1149  });
1150  }
1151 
1152  const SamplesWithLocList &get() const { return V; }
1153 
1154 private:
1156 };
1157 
1158 /// SampleContextTrimmer impelements helper functions to trim, merge cold
1159 /// context profiles. It also supports context profile canonicalization to make
1160 /// sure ProfileMap's key is consistent with FunctionSample's name/context.
1162 public:
1163  SampleContextTrimmer(SampleProfileMap &Profiles) : ProfileMap(Profiles){};
1164  // Trim and merge cold context profile when requested. TrimBaseProfileOnly
1165  // should only be effective when TrimColdContext is true. On top of
1166  // TrimColdContext, TrimBaseProfileOnly can be used to specify to trim all
1167  // cold profiles or only cold base profiles. Trimming base profiles only is
1168  // mainly to honor the preinliner decsion. Note that when MergeColdContext is
1169  // true, preinliner decsion is not honored anyway so TrimBaseProfileOnly will
1170  // be ignored.
1172  bool TrimColdContext,
1173  bool MergeColdContext,
1174  uint32_t ColdContextFrameLength,
1175  bool TrimBaseProfileOnly);
1176  // Canonicalize context profile name and attributes.
1178 
1179 private:
1180  SampleProfileMap &ProfileMap;
1181 };
1182 
1183 // CSProfileConverter converts a full context-sensitive flat sample profile into
1184 // a nested context-sensitive sample profile.
1186 public:
1188  void convertProfiles();
1189  struct FrameNode {
1191  FunctionSamples *FSamples = nullptr,
1192  LineLocation CallLoc = {0, 0})
1193  : FuncName(FName), FuncSamples(FSamples), CallSiteLoc(CallLoc){};
1194 
1195  // Map line+discriminator location to child frame
1196  std::map<uint64_t, FrameNode> AllChildFrames;
1197  // Function name for current frame
1199  // Function Samples for current frame
1201  // Callsite location in parent context
1203 
1204  FrameNode *getOrCreateChildFrame(const LineLocation &CallSite,
1205  StringRef CalleeName);
1206  };
1207 
1208 private:
1209  // Nest all children profiles into the profile of Node.
1211  FrameNode *getOrCreateContextPath(const SampleContext &Context);
1212 
1213  SampleProfileMap &ProfileMap;
1214  FrameNode RootFrame;
1215 };
1216 
1217 /// ProfileSymbolList records the list of function symbols shown up
1218 /// in the binary used to generate the profile. It is useful to
1219 /// to discriminate a function being so cold as not to shown up
1220 /// in the profile and a function newly added.
1222 public:
1223  /// copy indicates whether we need to copy the underlying memory
1224  /// for the input Name.
1225  void add(StringRef Name, bool copy = false) {
1226  if (!copy) {
1227  Syms.insert(Name);
1228  return;
1229  }
1230  Syms.insert(Name.copy(Allocator));
1231  }
1232 
1233  bool contains(StringRef Name) { return Syms.count(Name); }
1234 
1235  void merge(const ProfileSymbolList &List) {
1236  for (auto Sym : List.Syms)
1237  add(Sym, true);
1238  }
1239 
1240  unsigned size() { return Syms.size(); }
1241 
1242  void setToCompress(bool TC) { ToCompress = TC; }
1243  bool toCompress() { return ToCompress; }
1244 
1245  std::error_code read(const uint8_t *Data, uint64_t ListSize);
1246  std::error_code write(raw_ostream &OS);
1247  void dump(raw_ostream &OS = dbgs()) const;
1248 
1249 private:
1250  // Determine whether or not to compress the symbol list when
1251  // writing it into profile. The variable is unused when the symbol
1252  // list is read from an existing profile.
1253  bool ToCompress = false;
1254  DenseSet<StringRef> Syms;
1255  BumpPtrAllocator Allocator;
1256 };
1257 
1258 } // end namespace sampleprof
1259 
1260 using namespace sampleprof;
1261 // Provide DenseMapInfo for SampleContext.
1262 template <> struct DenseMapInfo<SampleContext> {
1263  static inline SampleContext getEmptyKey() { return SampleContext(); }
1264 
1265  static inline SampleContext getTombstoneKey() { return SampleContext("@"); }
1266 
1267  static unsigned getHashValue(const SampleContext &Val) {
1268  return Val.getHashCode();
1269  }
1270 
1271  static bool isEqual(const SampleContext &LHS, const SampleContext &RHS) {
1272  return LHS == RHS;
1273  }
1274 };
1275 } // end namespace llvm
1276 
1277 #endif // LLVM_PROFILEDATA_SAMPLEPROF_H
llvm::sampleprof::CSProfileConverter
Definition: SampleProf.h:1185
llvm::sampleprof::SampleRecord::getSamples
uint64_t getSamples() const
Definition: SampleProf.h:362
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:853
llvm::StringRef::startswith
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition: StringRef.h:285
llvm::ArrayRef::drop_back
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition: ArrayRef.h:208
llvm::sampleprof::SecHdrTableEntry::Offset
uint64_t Offset
Definition: SampleProf.h:162
MathExtras.h
llvm::sampleprof::CSProfileConverter::FrameNode::FuncSamples
FunctionSamples * FuncSamples
Definition: SampleProf.h:1200
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::sampleprof::SecFuncMetadataFlags::SecFlagHasAttribute
@ SecFlagHasAttribute
llvm::sampleprof::BodySampleMap
std::map< LineLocation, SampleRecord > BodySampleMap
Definition: SampleProf.h:678
llvm::sampleprof::SecProfSummaryFlags::SecFlagFSDiscriminator
@ SecFlagFSDiscriminator
SecFlagFSDiscriminator means this profile uses flow-sensitive discriminators.
llvm::sampleprof::SampleSorter::get
const SamplesWithLocList & get() const
Definition: SampleProf.h:1152
llvm::sampleprof::SampleContext::decodeContextString
static void decodeContextString(StringRef ContextStr, StringRef &FName, LineLocation &LineLoc)
Definition: SampleProf.h:537
llvm::sampleprof::SampleContext::operator!=
bool operator!=(const SampleContext &That) const
Definition: SampleProf.h:615
llvm::sampleprof::FunctionSamples::ProfileIsProbeBased
static bool ProfileIsProbeBased
Definition: SampleProf.h:1045
llvm::X86AS::FS
@ FS
Definition: X86.h:188
llvm::sampleprof::hash_value
static hash_code hash_value(const SampleContextFrame &arg)
Definition: SampleProf.h:446
llvm::sampleprof::FunctionSamples::dump
void dump() const
Definition: SampleProf.cpp:330
llvm::sampleprof::RawContext
@ RawContext
Definition: SampleProf.h:403
llvm::sampleprof::LineLocation::dump
void dump() const
Definition: SampleProf.cpp:137
llvm::sampleprof::SampleRecord::CallTargetComparator::operator()
bool operator()(const CallTarget &LHS, const CallTarget &RHS) const
Definition: SampleProf.h:320
llvm::sampleprof::SampleContext::hasAttribute
bool hasAttribute(ContextAttributeMask A)
Definition: SampleProf.h:559
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::Function
Definition: Function.h:62
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::CallsiteSampleMap
std::map< LineLocation, FunctionSamplesMap > CallsiteSampleMap
Definition: SampleProf.h:682
llvm::sampleprof::LineLocation::LineLocation
LineLocation(uint32_t L, uint32_t D)
Definition: SampleProf.h:282
llvm::sampleprof::SampleSorter::SamplesWithLocList
SmallVector< const SamplesWithLoc *, 20 > SamplesWithLocList
Definition: SampleProf.h:1142
llvm::sampleprof::SampleRecord::hasCalls
bool hasCalls() const
Return true if this sample record contains function calls.
Definition: SampleProf.h:360
llvm::sampleprof_error::hash_mismatch
@ hash_mismatch
llvm::sampleprof::SecNameTableFlags::SecFlagFixedLengthMD5
@ SecFlagFixedLengthMD5
llvm::StringRef::npos
static constexpr size_t npos
Definition: StringRef.h:59
llvm::sampleprof::FunctionSamples::getFuncName
StringRef getFuncName(StringRef Name) const
Translate Name into its original name.
Definition: SampleProf.h:1006
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::NameFunctionSamples
std::pair< SampleContext, const FunctionSamples * > NameFunctionSamples
Definition: SampleProf.h:1130
llvm::sampleprof::ProfileSymbolList::size
unsigned size()
Definition: SampleProf.h:1240
llvm::sampleprof::SampleContext::setContext
void setContext(SampleContextFrames Context, ContextStateMask CState=RawContext)
Definition: SampleProf.h:602
llvm::sampleprof::SampleContext::SampleContext
SampleContext(SampleContextFrames Context, ContextStateMask CState=RawContext)
Definition: SampleProf.h:477
llvm::sampleprof::SampleContextFrame::toString
std::string toString(bool OutputLineLocation) const
Definition: SampleProf.h:434
llvm::sampleprof::SecProfSummaryFlags::SecFlagFullContext
@ SecFlagFullContext
SecFlagContext means this is context-sensitive profile for CSSPGO.
Allocator.h
llvm::sampleprof::SampleContext::toString
std::string toString() const
Definition: SampleProf.h:584
llvm::sampleprof_error::unsupported_version
@ unsupported_version
llvm::sampleprof::SampleProfileMap
std::unordered_map< SampleContext, FunctionSamples, SampleContext::Hash > SampleProfileMap
Definition: SampleProf.h:1128
llvm::sampleprof::SampleContext::operator==
bool operator==(const SampleContext &That) const
Definition: SampleProf.h:610
llvm::sampleprof::hasSecFlag
static bool hasSecFlag(const SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:265
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1580
llvm::sampleprof::LineLocation::operator<
bool operator<(const LineLocation &O) const
Definition: SampleProf.h:287
llvm::sampleprof::SPF_GCC
@ SPF_GCC
Definition: SampleProf.h:94
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
Module.h
llvm::sampleprof::SecFuncOffsetTable
@ SecFuncOffsetTable
Definition: SampleProf.h:126
llvm::sampleprof::addSecFlag
static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:249
llvm::copy
OutputIt copy(R &&Range, OutputIt Out)
Definition: STLExtras.h:1700
llvm::sampleprof_error::not_implemented
@ not_implemented
FMAInstKind::Accumulator
@ Accumulator
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:561
llvm::sampleprof::SecNameTableFlags::SecFlagMD5Name
@ SecFlagMD5Name
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:914
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
llvm::sampleprof::SampleRecord::SampleRecord
SampleRecord()=default
llvm::sampleprof::FunctionSamples::findAllNames
void findAllNames(DenseSet< StringRef > &NameSet) const
Definition: SampleProf.cpp:279
llvm::sampleprof::FunctionSamples::getName
StringRef getName() const
Return the function name.
Definition: SampleProf.h:944
llvm::sampleprof::FunctionSamplesMap
std::map< std::string, FunctionSamples, std::less<> > FunctionSamplesMap
Definition: SampleProf.h:681
RHS
Value * RHS
Definition: X86PartialReduction.cpp:74
llvm::sampleprof::MergedContext
@ MergedContext
Definition: SampleProf.h:406
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:472
llvm::sampleprof::FunctionSamples::getCanonicalFnName
static StringRef getCanonicalFnName(StringRef FnName, StringRef Attr="selected")
Definition: SampleProf.h:967
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:301
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:300
Context
ManagedStatic< detail::RecordContext > Context
Definition: Record.cpp:96
llvm::sampleprof::FunctionSamples::SetContextSynthetic
void SetContextSynthetic()
Definition: SampleProf.h:750
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:1271
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
llvm::sampleprof::removeSecFlag
static void removeSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
Definition: SampleProf.h:257
llvm::sampleprof::ProfileSymbolList::setToCompress
void setToCompress(bool TC)
Definition: SampleProf.h:1242
LHS
Value * LHS
Definition: X86PartialReduction.cpp:73
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:947
GlobalValue.h
llvm::sampleprof_error::unsupported_writing_format
@ unsupported_writing_format
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:964
llvm::sampleprof::FunctionSamples::setTotalSamples
void setTotalSamples(uint64_t Num)
Definition: SampleProf.h:704
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::sampleprof::SampleContextFrameHash
Definition: SampleProf.h:454
llvm::sampleprof::FunctionSamples::updateTotalSamples
void updateTotalSamples()
Definition: SampleProf.h:736
llvm::sampleprof::SampleContext::hasState
bool hasState(ContextStateMask S)
Definition: SampleProf.h:563
llvm::sampleprof::FunctionSamples::ProfileIsCSFlat
static bool ProfileIsCSFlat
Definition: SampleProf.h:1047
llvm::StringRef::split
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:748
llvm::sampleprof::SampleRecord::CallTarget
std::pair< StringRef, uint64_t > CallTarget
Definition: SampleProf.h:318
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::sampleprof::SampleContext::Hash
Definition: SampleProf.h:640
llvm::sampleprof::CSProfileConverter::FrameNode
Definition: SampleProf.h:1189
llvm::sampleprof::SampleContext::getHashCode
uint64_t getHashCode() const
Definition: SampleProf.h:590
llvm::sampleprof::FunctionSamples::FunctionSamples
FunctionSamples()=default
llvm::sampleprof::SyntheticContext
@ SyntheticContext
Definition: SampleProf.h:404
llvm::sampleprof::SampleContextFrame::SampleContextFrame
SampleContextFrame()
Definition: SampleProf.h:421
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:774
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:508
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:1073
llvm::sampleprof::SampleContext::operator<
bool operator<(const SampleContext &That) const
Definition: SampleProf.h:617
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::sampleprof_category
const std::error_category & sampleprof_category()
Definition: SampleProf.cpp:108
llvm::DenseMapInfo< SampleContext >::getHashValue
static unsigned getHashValue(const SampleContext &Val)
Definition: SampleProf.h:1267
llvm::sampleprof::FunctionSamples::Format
static SampleProfileFormat Format
Definition: SampleProf.h:1055
llvm::MCID::Flag
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Definition: MCInstrDesc.h:146
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:1144
llvm::sampleprof::SecFuncMetadataFlags::SecFlagIsCSNested
@ SecFlagIsCSNested
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:53
llvm::sampleprof::SecNameTableFlags::SecFlagInValid
@ SecFlagInValid
llvm::sampleprof::ContextStateMask
ContextStateMask
Definition: SampleProf.h:401
StringMap.h
llvm::sampleprof::ProfileSymbolList::read
std::error_code read(const uint8_t *Data, uint64_t ListSize)
Definition: SampleProf.cpp:333
llvm::sampleprof::SampleContextFrames
ArrayRef< SampleContextFrame > SampleContextFrames
Definition: SampleProf.h:452
llvm::StringRef::str
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:244
llvm::sampleprof::CSProfileConverter::FrameNode::AllChildFrames
std::map< uint64_t, FrameNode > AllChildFrames
Definition: SampleProf.h:1193
llvm::sampleprof::SampleContext
Definition: SampleProf.h:470
llvm::sampleprof::SecProfSummaryFlags::SecFlagInValid
@ SecFlagInValid
llvm::sampleprof::FunctionSamples::getHeadSamples
uint64_t getHeadSamples() const
Return the total number of branch samples that have the function as the branch target.
Definition: SampleProf.h:825
llvm::sampleprof::SampleContext::isBaseContext
bool isBaseContext() const
Definition: SampleProf.h:567
llvm::sampleprof::sortFuncProfiles
void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
Definition: SampleProf.cpp:208
llvm::StringMap< uint64_t >
llvm::sampleprof::FunctionSamples::ProfileIsFS
static bool ProfileIsFS
If this profile uses flow sensitive discriminators.
Definition: SampleProf.h:1064
llvm::sampleprof::FunctionSamples::empty
bool empty() const
Definition: SampleProf.h:815
llvm::sampleprof::SecHdrTableEntry::Type
SecType Type
Definition: SampleProf.h:160
llvm::sampleprof::LineLocation::operator!=
bool operator!=(const LineLocation &O) const
Definition: SampleProf.h:296
llvm::sampleprof::SampleRecord::getCallTargets
const CallTargetMap & getCallTargets() const
Definition: SampleProf.h:363
llvm::sampleprof::SampleRecord::SortedCallTargetSet
std::set< CallTarget, CallTargetComparator > SortedCallTargetSet
Definition: SampleProf.h:328
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:487
llvm::sampleprof::ProfileSymbolList::contains
bool contains(StringRef Name)
Definition: SampleProf.h:1233
llvm::sampleprof::SampleContext::getContextFrames
SampleContextFrames getContextFrames() const
Definition: SampleProf.h:569
llvm::sampleprof::FunctionSamples::getCallsiteSamples
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
Definition: SampleProf.h:856
llvm::sampleprof::SampleContext::setName
void setName(StringRef FunctionName)
Set the name of the function and clear the current context.
Definition: SampleProf.h:596
llvm::sampleprof::SecHdrTableEntry::Flags
uint64_t Flags
Definition: SampleProf.h:161
llvm::sampleprof::SampleRecord::CallTargetComparator
Definition: SampleProf.h:319
llvm::sampleprof::UnknownContext
@ UnknownContext
Definition: SampleProf.h:402
llvm::RISCVFenceField::O
@ O
Definition: RISCVBaseInfo.h:206
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:1221
llvm::ArrayRef::drop_front
ArrayRef< T > drop_front(size_t N=1) const
Drop the first N elements of the array.
Definition: ArrayRef.h:202
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:152
Index
uint32_t Index
Definition: ELFObjHandler.cpp:83
llvm::sampleprof::SampleContext::setAttribute
void setAttribute(ContextAttributeMask A)
Definition: SampleProf.h:560
llvm::sampleprof::FunctionSamples::addHeadSamples
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:706
uint64_t
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
llvm::sampleprof::SampleContext::SampleContext
SampleContext()
Definition: SampleProf.h:472
llvm::sampleprof::FunctionSamples::getEntrySamples
uint64_t getEntrySamples() const
Return the sample count of the first instruction of the function.
Definition: SampleProf.h:829
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:1068
llvm::sampleprof::LineLocation::operator==
bool operator==(const LineLocation &O) const
Definition: SampleProf.h:292
llvm::sampleprof::SecFuncOffsetFlags
SecFuncOffsetFlags
Definition: SampleProf.h:213
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition: SampleProf.h:689
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition: Allocator.h:67
llvm::sampleprof::SampleContextFrame::Location
LineLocation Location
Definition: SampleProf.h:419
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:792
ErrorOr.h
llvm::DenseMapInfo< SampleContext >::getTombstoneKey
static SampleContext getTombstoneKey()
Definition: SampleProf.h:1265
llvm::sampleprof::SampleContext::clearState
void clearState(ContextStateMask S)
Definition: SampleProf.h:565
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
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:245
llvm::sampleprof::SampleContext::promoteOnPath
void promoteOnPath(uint32_t ContextFramesToRemove)
Definition: SampleProf.h:529
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:866
llvm::sampleprof::FunctionSamples::setContext
void setContext(const SampleContext &FContext)
Definition: SampleProf.h:1053
llvm::sampleprof::FunctionSamples::getFunctionHash
uint64_t getFunctionHash() const
Definition: SampleProf.h:951
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::SampleContextFrame::FuncName
StringRef FuncName
Definition: SampleProf.h:418
llvm::sampleprof::SampleRecord::adjustCallTargets
static const CallTargetMap adjustCallTargets(const CallTargetMap &Targets, float DistributionFactor)
Prorate call targets by a distribution factor.
Definition: SampleProf.h:378
llvm::sampleprof::SampleRecord::getSortedCallTargets
const SortedCallTargetSet getSortedCallTargets() const
Definition: SampleProf.h:364
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::SecCommonFlags::SecFlagInValid
@ SecFlagInValid
llvm::sampleprof::SampleContext::getName
StringRef getName() const
Definition: SampleProf.h:568
llvm::sampleprof::SampleContext::setState
void setState(ContextStateMask S)
Definition: SampleProf.h:564
llvm::sampleprof::operator<<
raw_ostream & operator<<(raw_ostream &OS, const LineLocation &Loc)
Definition: SampleProf.cpp:118
llvm::sampleprof::FunctionSamples::UseMD5
static bool UseMD5
Whether the profile uses MD5 to represent string.
Definition: SampleProf.h:1058
llvm::sampleprof::CSProfileConverter::FrameNode::FuncName
StringRef FuncName
Definition: SampleProf.h:1198
llvm::sampleprof::SecHdrTableEntry::LayoutIndex
uint32_t LayoutIndex
Definition: SampleProf.h:166
llvm::sampleprof::ProfileSymbolList::merge
void merge(const ProfileSymbolList &List)
Definition: SampleProf.h:1235
llvm::sampleprof::CSProfileConverter::FrameNode::CallSiteLoc
LineLocation CallSiteLoc
Definition: SampleProf.h:1202
llvm::sampleprof::FunctionSamples::getOffset
static unsigned getOffset(const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
Definition: SampleProf.cpp:223
llvm::sampleprof::LineLocation
Represents the relative location of an instruction.
Definition: SampleProf.h:281
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:646
llvm::sampleprof::SampleContext::SampleContext
SampleContext(StringRef Name)
Definition: SampleProf.h:474
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:57
llvm::sampleprof::SampleSorter
Sort a LocationT->SampleT map by LocationT.
Definition: SampleProf.h:1139
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
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:714
llvm::sampleprof::SampleContextFrame::operator==
bool operator==(const SampleContextFrame &That) const
Definition: SampleProf.h:426
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:1225
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:162
llvm::sampleprof::FunctionSamples::findFunctionSamplesMapAt
const FunctionSamplesMap * findFunctionSamplesMapAt(const LineLocation &Loc) const
Returns the FunctionSamplesMap at the given Loc.
Definition: SampleProf.h:798
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:762
llvm::sampleprof::SampleRecord::CallTargetMap
StringMap< uint64_t > CallTargetMap
Definition: SampleProf.h:329
Node
Definition: ItaniumDemangle.h:235
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:293
llvm::sampleprof::ProfileSymbolList::toCompress
bool toCompress()
Definition: SampleProf.h:1243
llvm::make_error_code
std::error_code make_error_code(BitcodeError E)
Definition: BitcodeReader.h:270
llvm::sampleprof::InlinedContext
@ InlinedContext
Definition: SampleProf.h:405
Callee
amdgpu Simplify well known AMD library false FunctionCallee Callee
Definition: AMDGPULibCalls.cpp:185
llvm::sampleprof_error::ostream_seek_unsupported
@ ostream_seek_unsupported
llvm::sampleprof::CSProfileConverter::convertProfiles
void convertProfiles()
Definition: SampleProf.cpp:547
StringSet.h
llvm::StringRef::size
constexpr LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:156
llvm::stable_sort
void stable_sort(R &&Range)
Definition: STLExtras.h:1784
llvm::sampleprof::ProfileSymbolList::write
std::error_code write(raw_ostream &OS)
Definition: SampleProf.cpp:446
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:52
std
Definition: BitVector.h:838
llvm::sampleprof::LineLocation::print
void print(raw_ostream &OS) const
Definition: SampleProf.cpp:112
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:141
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:226
llvm::sampleprof::verifySecFlag
static void verifySecFlag(SecType Type, SecFlagType Flag)
Definition: SampleProf.h:222
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
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:784
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
llvm::sampleprof::SampleRecord
Representation of a single sample record.
Definition: SampleProf.h:316
llvm::sampleprof::CSProfileConverter::FrameNode::FrameNode
FrameNode(StringRef FName=StringRef(), FunctionSamples *FSamples=nullptr, LineLocation CallLoc={0, 0})
Definition: SampleProf.h:1190
llvm::sampleprof_error::compress_failed
@ compress_failed
llvm::sampleprof_error
sampleprof_error
Definition: SampleProf.h:45
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:874
llvm::sampleprof::FunctionSamples::LLVMSuffix
static constexpr const char * LLVMSuffix
Name suffixes which canonicalization should handle to avoid profile mismatch.
Definition: SampleProf.h:963
llvm::sampleprof::ContextNone
@ ContextNone
Definition: SampleProf.h:411
llvm::sampleprof_error::zlib_unavailable
@ zlib_unavailable
llvm::sampleprof::SampleContext::hasContext
bool hasContext() const
Definition: SampleProf.h:566
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:349
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:349
llvm::sampleprof::FunctionSamples::getContext
SampleContext & getContext() const
Definition: SampleProf.h:1051
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:862
llvm::sampleprof::ContextAttributeMask
ContextAttributeMask
Definition: SampleProf.h:410
llvm::sampleprof::SampleContextFrame::SampleContextFrame
SampleContextFrame(StringRef FuncName, LineLocation Location)
Definition: SampleProf.h:423
llvm::sampleprof::SampleContextTrimmer::SampleContextTrimmer
SampleContextTrimmer(SampleProfileMap &Profiles)
Definition: SampleProf.h:1163
llvm::sampleprof::SecNameTableFlags
SecNameTableFlags
Definition: SampleProf.h:182
llvm::sampleprof::ContextWasInlined
@ ContextWasInlined
Definition: SampleProf.h:412
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::SampleContextTrimmer::canonicalizeContextProfiles
void canonicalizeContextProfiles()
Definition: SampleProf.cpp:410
llvm::StringMapImpl::empty
bool empty() const
Definition: StringMap.h:92
SmallVector.h
llvm::sampleprof::SampleRecord::dump
void dump() const
Definition: SampleProf.cpp:152
llvm::DenseMapInfo< SampleContext >::getEmptyKey
static SampleContext getEmptyKey()
Definition: SampleProf.h:1263
llvm::sampleprof::SampleRecord::SortCallTargets
static const SortedCallTargetSet SortCallTargets(const CallTargetMap &Targets)
Sort call targets in descending order of call frequency.
Definition: SampleProf.h:369
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:430
llvm::sampleprof::SecCommonFlags::SecFlagFlat
@ SecFlagFlat
llvm::sampleprof::SecCommonFlags
SecCommonFlags
Definition: SampleProf.h:172
List
const NodeList & List
Definition: RDFGraph.cpp:201
llvm::sampleprof::FunctionSamples::UniqSuffix
static constexpr const char * UniqSuffix
Definition: SampleProf.h:965
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:126
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:87
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition: ArrayRef.h:163
llvm::max
Align max(MaybeAlign Lhs, Align Rhs)
Definition: Alignment.h:340
Threshold
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
llvm::sampleprof::SampleContext::getContextString
static std::string getContextString(SampleContextFrames Context, bool IncludeLeafLineLocation=false)
Definition: SampleProf.h:571
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:728
llvm::sampleprof::SampleProfileReaderItaniumRemapper
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...
Definition: SampleProfReader.h:264
llvm::sampleprof::SecFuncMetadata
@ SecFuncMetadata
Definition: SampleProf.h:127
llvm::sampleprof::SampleContextFrame
Definition: SampleProf.h:417
llvm::sampleprof_error::truncated_name_table
@ truncated_name_table
llvm::sampleprof::SampleSorter::SamplesWithLoc
std::pair< const LocationT, SampleT > SamplesWithLoc
Definition: SampleProf.h:1141
llvm::sampleprof::SampleContextTrimmer
SampleContextTrimmer impelements helper functions to trim, merge cold context profiles.
Definition: SampleProf.h:1161
llvm::sampleprof::ProfileSymbolList::dump
void dump(raw_ostream &OS=dbgs()) const
Definition: SampleProf.cpp:462
raw_ostream.h
error_category
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:76
llvm::sampleprof::SecFuncOffsetFlags::SecFlagInvalid
@ SecFlagInvalid
llvm::sampleprof_error::truncated
@ truncated
llvm::StringRef::compare
LLVM_NODISCARD 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:200
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:337
llvm::sampleprof::SampleContextFrameHash::operator()
uint64_t operator()(const SampleContextFrameVector &S) const
Definition: SampleProf.h:455
llvm::sampleprof::SecFuncMetadataFlags
SecFuncMetadataFlags
Definition: SampleProf.h:206
llvm::sampleprof_error::bad_magic
@ bad_magic
llvm::sampleprof::CSProfileConverter::CSProfileConverter
CSProfileConverter(SampleProfileMap &Profiles)
Definition: SampleProf.cpp:486
llvm::sampleprof::FunctionSamples::setFunctionHash
void setFunctionHash(uint64_t Hash)
Definition: SampleProf.h:949
Other
Optional< std::vector< StOtherPiece > > Other
Definition: ELFYAML.cpp:1198
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:228
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:253
llvm::hash_code
An opaque object representing a hash code.
Definition: Hashing.h:73
llvm::sampleprof::SampleContext::Hash::operator()
uint64_t operator()(const SampleContext &Context) const
Definition: SampleProf.h:641
llvm::sampleprof::FunctionSamples::setName
void setName(StringRef FunctionName)
Set the name of the function.
Definition: SampleProf.h:941