LLVM  10.0.0svn
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/IR/Function.h"
22 #include "llvm/IR/GlobalValue.h"
23 #include "llvm/IR/Module.h"
24 #include "llvm/Support/Debug.h"
25 #include "llvm/Support/ErrorOr.h"
27 #include <algorithm>
28 #include <cstdint>
29 #include <map>
30 #include <set>
31 #include <string>
32 #include <system_error>
33 #include <utility>
34 
35 namespace llvm {
36 
37 class raw_ostream;
38 
40 
41 enum class sampleprof_error {
42  success = 0,
43  bad_magic,
45  too_large,
46  truncated,
47  malformed,
54 };
55 
56 inline std::error_code make_error_code(sampleprof_error E) {
57  return std::error_code(static_cast<int>(E), sampleprof_category());
58 }
59 
61  sampleprof_error Result) {
62  // Prefer first error encountered as later errors may be secondary effects of
63  // the initial problem.
64  if (Accumulator == sampleprof_error::success &&
65  Result != sampleprof_error::success)
66  Accumulator = Result;
67  return Accumulator;
68 }
69 
70 } // end namespace llvm
71 
72 namespace std {
73 
74 template <>
75 struct is_error_code_enum<llvm::sampleprof_error> : std::true_type {};
76 
77 } // end namespace std
78 
79 namespace llvm {
80 namespace sampleprof {
81 
83  SPF_None = 0,
84  SPF_Text = 0x1,
86  SPF_GCC = 0x3,
87  SPF_Binary = 0xff
88 };
89 
90 static inline uint64_t SPMagic(SampleProfileFormat Format = SPF_Binary) {
91  return uint64_t('S') << (64 - 8) | uint64_t('P') << (64 - 16) |
92  uint64_t('R') << (64 - 24) | uint64_t('O') << (64 - 32) |
93  uint64_t('F') << (64 - 40) | uint64_t('4') << (64 - 48) |
94  uint64_t('2') << (64 - 56) | uint64_t(Format);
95 }
96 
97 // Get the proper representation of a string in the input Format.
100  std::string &GUIDBuf) {
101  if (Name.empty())
102  return Name;
103  GUIDBuf = std::to_string(Function::getGUID(Name));
104  return (Format == SPF_Compact_Binary) ? StringRef(GUIDBuf) : Name;
105 }
106 
107 static inline uint64_t SPVersion() { return 103; }
108 
109 /// Represents the relative location of an instruction.
110 ///
111 /// Instruction locations are specified by the line offset from the
112 /// beginning of the function (marked by the line where the function
113 /// header is) and the discriminator value within that line.
114 ///
115 /// The discriminator value is useful to distinguish instructions
116 /// that are on the same line but belong to different basic blocks
117 /// (e.g., the two post-increment instructions in "if (p) x++; else y++;").
118 struct LineLocation {
119  LineLocation(uint32_t L, uint32_t D) : LineOffset(L), Discriminator(D) {}
120 
121  void print(raw_ostream &OS) const;
122  void dump() const;
123 
124  bool operator<(const LineLocation &O) const {
125  return LineOffset < O.LineOffset ||
126  (LineOffset == O.LineOffset && Discriminator < O.Discriminator);
127  }
128 
131 };
132 
134 
135 /// Representation of a single sample record.
136 ///
137 /// A sample record is represented by a positive integer value, which
138 /// indicates how frequently was the associated line location executed.
139 ///
140 /// Additionally, if the associated location contains a function call,
141 /// the record will hold a list of all the possible called targets. For
142 /// direct calls, this will be the exact function being invoked. For
143 /// indirect calls (function pointers, virtual table dispatch), this
144 /// will be a list of one or more functions.
146 public:
147  using CallTarget = std::pair<StringRef, uint64_t>;
149  bool operator()(const CallTarget &LHS, const CallTarget &RHS) const {
150  if (LHS.second != RHS.second)
151  return LHS.second > RHS.second;
152 
153  return LHS.first < RHS.first;
154  }
155  };
156 
157  using SortedCallTargetSet = std::set<CallTarget, CallTargetComparator>;
159  SampleRecord() = default;
160 
161  /// Increment the number of samples for this record by \p S.
162  /// Optionally scale sample count \p S by \p Weight.
163  ///
164  /// Sample counts accumulate using saturating arithmetic, to avoid wrapping
165  /// around unsigned integers.
166  sampleprof_error addSamples(uint64_t S, uint64_t Weight = 1) {
167  bool Overflowed;
168  NumSamples = SaturatingMultiplyAdd(S, Weight, NumSamples, &Overflowed);
169  return Overflowed ? sampleprof_error::counter_overflow
171  }
172 
173  /// Add called function \p F with samples \p S.
174  /// Optionally scale sample count \p S by \p Weight.
175  ///
176  /// Sample counts accumulate using saturating arithmetic, to avoid wrapping
177  /// around unsigned integers.
179  uint64_t Weight = 1) {
180  uint64_t &TargetSamples = CallTargets[F];
181  bool Overflowed;
182  TargetSamples =
183  SaturatingMultiplyAdd(S, Weight, TargetSamples, &Overflowed);
184  return Overflowed ? sampleprof_error::counter_overflow
186  }
187 
188  /// Return true if this sample record contains function calls.
189  bool hasCalls() const { return !CallTargets.empty(); }
190 
191  uint64_t getSamples() const { return NumSamples; }
192  const CallTargetMap &getCallTargets() const { return CallTargets; }
194  return SortCallTargets(CallTargets);
195  }
196 
197  /// Sort call targets in descending order of call frequency.
198  static const SortedCallTargetSet SortCallTargets(const CallTargetMap &Targets) {
199  SortedCallTargetSet SortedTargets;
200  for (const auto &I : Targets) {
201  SortedTargets.emplace(I.first(), I.second);
202  }
203  return SortedTargets;
204  }
205 
206  /// Merge the samples in \p Other into this record.
207  /// Optionally scale sample counts by \p Weight.
208  sampleprof_error merge(const SampleRecord &Other, uint64_t Weight = 1) {
209  sampleprof_error Result = addSamples(Other.getSamples(), Weight);
210  for (const auto &I : Other.getCallTargets()) {
211  MergeResult(Result, addCalledTarget(I.first(), I.second, Weight));
212  }
213  return Result;
214  }
215 
216  void print(raw_ostream &OS, unsigned Indent) const;
217  void dump() const;
218 
219 private:
220  uint64_t NumSamples = 0;
221  CallTargetMap CallTargets;
222 };
223 
224 raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample);
225 
226 class FunctionSamples;
227 
228 using BodySampleMap = std::map<LineLocation, SampleRecord>;
229 // NOTE: Using a StringMap here makes parsed profiles consume around 17% more
230 // memory, which is *very* significant for large profiles.
231 using FunctionSamplesMap = std::map<std::string, FunctionSamples, std::less<>>;
232 using CallsiteSampleMap = std::map<LineLocation, FunctionSamplesMap>;
233 
234 /// Representation of the samples collected for a function.
235 ///
236 /// This data structure contains all the collected samples for the body
237 /// of a function. Each sample corresponds to a LineLocation instance
238 /// within the body of the function.
240 public:
241  FunctionSamples() = default;
242 
243  void print(raw_ostream &OS = dbgs(), unsigned Indent = 0) const;
244  void dump() const;
245 
246  sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight = 1) {
247  bool Overflowed;
248  TotalSamples =
249  SaturatingMultiplyAdd(Num, Weight, TotalSamples, &Overflowed);
250  return Overflowed ? sampleprof_error::counter_overflow
252  }
253 
254  sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight = 1) {
255  bool Overflowed;
256  TotalHeadSamples =
257  SaturatingMultiplyAdd(Num, Weight, TotalHeadSamples, &Overflowed);
258  return Overflowed ? sampleprof_error::counter_overflow
260  }
261 
263  uint64_t Num, uint64_t Weight = 1) {
264  return BodySamples[LineLocation(LineOffset, Discriminator)].addSamples(
265  Num, Weight);
266  }
267 
269  uint32_t Discriminator,
270  StringRef FName, uint64_t Num,
271  uint64_t Weight = 1) {
272  return BodySamples[LineLocation(LineOffset, Discriminator)].addCalledTarget(
273  FName, Num, Weight);
274  }
275 
276  /// Return the number of samples collected at the given location.
277  /// Each location is specified by \p LineOffset and \p Discriminator.
278  /// If the location is not found in profile, return error.
280  uint32_t Discriminator) const {
281  const auto &ret = BodySamples.find(LineLocation(LineOffset, Discriminator));
282  if (ret == BodySamples.end())
283  return std::error_code();
284  else
285  return ret->second.getSamples();
286  }
287 
288  /// Returns the call target map collected at a given location.
289  /// Each location is specified by \p LineOffset and \p Discriminator.
290  /// If the location is not found in profile, return error.
292  findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const {
293  const auto &ret = BodySamples.find(LineLocation(LineOffset, Discriminator));
294  if (ret == BodySamples.end())
295  return std::error_code();
296  return ret->second.getCallTargets();
297  }
298 
299  /// Return the function samples at the given callsite location.
301  return CallsiteSamples[Loc];
302  }
303 
304  /// Returns the FunctionSamplesMap at the given \p Loc.
305  const FunctionSamplesMap *
307  auto iter = CallsiteSamples.find(Loc);
308  if (iter == CallsiteSamples.end())
309  return nullptr;
310  return &iter->second;
311  }
312 
313  /// Returns a pointer to FunctionSamples at the given callsite location \p Loc
314  /// with callee \p CalleeName. If no callsite can be found, relax the
315  /// restriction to return the FunctionSamples at callsite location \p Loc
316  /// with the maximum total sample count.
318  StringRef CalleeName) const {
319  std::string CalleeGUID;
320  CalleeName = getRepInFormat(CalleeName, Format, CalleeGUID);
321 
322  auto iter = CallsiteSamples.find(Loc);
323  if (iter == CallsiteSamples.end())
324  return nullptr;
325  auto FS = iter->second.find(CalleeName);
326  if (FS != iter->second.end())
327  return &FS->second;
328  // If we cannot find exact match of the callee name, return the FS with
329  // the max total count.
330  uint64_t MaxTotalSamples = 0;
331  const FunctionSamples *R = nullptr;
332  for (const auto &NameFS : iter->second)
333  if (NameFS.second.getTotalSamples() >= MaxTotalSamples) {
334  MaxTotalSamples = NameFS.second.getTotalSamples();
335  R = &NameFS.second;
336  }
337  return R;
338  }
339 
340  bool empty() const { return TotalSamples == 0; }
341 
342  /// Return the total number of samples collected inside the function.
343  uint64_t getTotalSamples() const { return TotalSamples; }
344 
345  /// Return the total number of branch samples that have the function as the
346  /// branch target. This should be equivalent to the sample of the first
347  /// instruction of the symbol. But as we directly get this info for raw
348  /// profile without referring to potentially inaccurate debug info, this
349  /// gives more accurate profile data and is preferred for standalone symbols.
350  uint64_t getHeadSamples() const { return TotalHeadSamples; }
351 
352  /// Return the sample count of the first instruction of the function.
353  /// The function can be either a standalone symbol or an inlined function.
354  uint64_t getEntrySamples() const {
355  // Use either BodySamples or CallsiteSamples which ever has the smaller
356  // lineno.
357  if (!BodySamples.empty() &&
358  (CallsiteSamples.empty() ||
359  BodySamples.begin()->first < CallsiteSamples.begin()->first))
360  return BodySamples.begin()->second.getSamples();
361  if (!CallsiteSamples.empty()) {
362  uint64_t T = 0;
363  // An indirect callsite may be promoted to several inlined direct calls.
364  // We need to get the sum of them.
365  for (const auto &N_FS : CallsiteSamples.begin()->second)
366  T += N_FS.second.getEntrySamples();
367  return T;
368  }
369  return 0;
370  }
371 
372  /// Return all the samples collected in the body of the function.
373  const BodySampleMap &getBodySamples() const { return BodySamples; }
374 
375  /// Return all the callsite samples collected in the body of the function.
377  return CallsiteSamples;
378  }
379 
380  /// Merge the samples in \p Other into this one.
381  /// Optionally scale samples by \p Weight.
382  sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight = 1) {
384  Name = Other.getName();
385  MergeResult(Result, addTotalSamples(Other.getTotalSamples(), Weight));
386  MergeResult(Result, addHeadSamples(Other.getHeadSamples(), Weight));
387  for (const auto &I : Other.getBodySamples()) {
388  const LineLocation &Loc = I.first;
389  const SampleRecord &Rec = I.second;
390  MergeResult(Result, BodySamples[Loc].merge(Rec, Weight));
391  }
392  for (const auto &I : Other.getCallsiteSamples()) {
393  const LineLocation &Loc = I.first;
394  FunctionSamplesMap &FSMap = functionSamplesAt(Loc);
395  for (const auto &Rec : I.second)
396  MergeResult(Result, FSMap[Rec.first].merge(Rec.second, Weight));
397  }
398  return Result;
399  }
400 
401  /// Recursively traverses all children, if the total sample count of the
402  /// corresponding function is no less than \p Threshold, add its corresponding
403  /// GUID to \p S. Also traverse the BodySamples to add hot CallTarget's GUID
404  /// to \p S.
406  uint64_t Threshold) const {
407  if (TotalSamples <= Threshold)
408  return;
409  S.insert(getGUID(Name));
410  // Import hot CallTargets, which may not be available in IR because full
411  // profile annotation cannot be done until backend compilation in ThinLTO.
412  for (const auto &BS : BodySamples)
413  for (const auto &TS : BS.second.getCallTargets())
414  if (TS.getValue() > Threshold) {
415  const Function *Callee =
416  M->getFunction(getNameInModule(TS.getKey(), M));
417  if (!Callee || !Callee->getSubprogram())
418  S.insert(getGUID(TS.getKey()));
419  }
420  for (const auto &CS : CallsiteSamples)
421  for (const auto &NameFS : CS.second)
422  NameFS.second.findInlinedFunctions(S, M, Threshold);
423  }
424 
425  /// Set the name of the function.
426  void setName(StringRef FunctionName) { Name = FunctionName; }
427 
428  /// Return the function name.
429  StringRef getName() const { return Name; }
430 
431  /// Return the original function name if it exists in Module \p M.
433  return getNameInModule(Name, M);
434  }
435 
436  /// Return the canonical name for a function, taking into account
437  /// suffix elision policy attributes.
439  static const char *knownSuffixes[] = { ".llvm.", ".part." };
440  auto AttrName = "sample-profile-suffix-elision-policy";
441  auto Attr = F.getFnAttribute(AttrName).getValueAsString();
442  if (Attr == "" || Attr == "all") {
443  return F.getName().split('.').first;
444  } else if (Attr == "selected") {
445  StringRef Cand(F.getName());
446  for (const auto &Suf : knownSuffixes) {
447  StringRef Suffix(Suf);
448  auto It = Cand.rfind(Suffix);
449  if (It == StringRef::npos)
450  return Cand;
451  auto Dit = Cand.rfind('.');
452  if (Dit == It + Suffix.size() - 1)
453  Cand = Cand.substr(0, It);
454  }
455  return Cand;
456  } else if (Attr == "none") {
457  return F.getName();
458  } else {
459  assert(false && "internal error: unknown suffix elision policy");
460  }
461  return F.getName();
462  }
463 
464  /// Translate \p Name into its original name in Module.
465  /// When the Format is not SPF_Compact_Binary, \p Name needs no translation.
466  /// When the Format is SPF_Compact_Binary, \p Name in current FunctionSamples
467  /// is actually GUID of the original function name. getNameInModule will
468  /// translate \p Name in current FunctionSamples into its original name.
469  /// If the original name doesn't exist in \p M, return empty StringRef.
471  if (Format != SPF_Compact_Binary)
472  return Name;
473 
474  assert(GUIDToFuncNameMap && "GUIDToFuncNameMap needs to be popluated first");
475  auto iter = GUIDToFuncNameMap->find(std::stoull(Name.data()));
476  if (iter == GUIDToFuncNameMap->end())
477  return StringRef();
478  return iter->second;
479  }
480 
481  /// Returns the line offset to the start line of the subprogram.
482  /// We assume that a single function will not exceed 65535 LOC.
483  static unsigned getOffset(const DILocation *DIL);
484 
485  /// Get the FunctionSamples of the inline instance where DIL originates
486  /// from.
487  ///
488  /// The FunctionSamples of the instruction (Machine or IR) associated to
489  /// \p DIL is the inlined instance in which that instruction is coming from.
490  /// We traverse the inline stack of that instruction, and match it with the
491  /// tree nodes in the profile.
492  ///
493  /// \returns the FunctionSamples pointer to the inlined instance.
494  const FunctionSamples *findFunctionSamples(const DILocation *DIL) const;
495 
497 
498  /// GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for
499  /// all the function symbols defined or declared in current module.
500  DenseMap<uint64_t, StringRef> *GUIDToFuncNameMap = nullptr;
501 
502  // Assume the input \p Name is a name coming from FunctionSamples itself.
503  // If the format is SPF_Compact_Binary, the name is already a GUID and we
504  // don't want to return the GUID of GUID.
505  static uint64_t getGUID(StringRef Name) {
506  return (Format == SPF_Compact_Binary) ? std::stoull(Name.data())
507  : Function::getGUID(Name);
508  }
509 
510 private:
511  /// Mangled name of the function.
512  StringRef Name;
513 
514  /// Total number of samples collected inside this function.
515  ///
516  /// Samples are cumulative, they include all the samples collected
517  /// inside this function and all its inlined callees.
518  uint64_t TotalSamples = 0;
519 
520  /// Total number of samples collected at the head of the function.
521  /// This is an approximation of the number of calls made to this function
522  /// at runtime.
523  uint64_t TotalHeadSamples = 0;
524 
525  /// Map instruction locations to collected samples.
526  ///
527  /// Each entry in this map contains the number of samples
528  /// collected at the corresponding line offset. All line locations
529  /// are an offset from the start of the function.
530  BodySampleMap BodySamples;
531 
532  /// Map call sites to collected samples for the called function.
533  ///
534  /// Each entry in this map corresponds to all the samples
535  /// collected for the inlined function call at the given
536  /// location. For example, given:
537  ///
538  /// void foo() {
539  /// 1 bar();
540  /// ...
541  /// 8 baz();
542  /// }
543  ///
544  /// If the bar() and baz() calls were inlined inside foo(), this
545  /// map will contain two entries. One for all the samples collected
546  /// in the call to bar() at line offset 1, the other for all the samples
547  /// collected in the call to baz() at line offset 8.
548  CallsiteSampleMap CallsiteSamples;
549 };
550 
552 
553 /// Sort a LocationT->SampleT map by LocationT.
554 ///
555 /// It produces a sorted list of <LocationT, SampleT> records by ascending
556 /// order of LocationT.
557 template <class LocationT, class SampleT> class SampleSorter {
558 public:
559  using SamplesWithLoc = std::pair<const LocationT, SampleT>;
561 
562  SampleSorter(const std::map<LocationT, SampleT> &Samples) {
563  for (const auto &I : Samples)
564  V.push_back(&I);
565  llvm::stable_sort(V, [](const SamplesWithLoc *A, const SamplesWithLoc *B) {
566  return A->first < B->first;
567  });
568  }
569 
570  const SamplesWithLocList &get() const { return V; }
571 
572 private:
574 };
575 
576 } // end namespace sampleprof
577 } // end namespace llvm
578 
579 #endif // LLVM_PROFILEDATA_SAMPLEPROF_H
const FunctionSamplesMap * findFunctionSamplesMapAt(const LineLocation &Loc) const
Returns the FunctionSamplesMap at the given Loc.
Definition: SampleProf.h:306
static uint64_t getGUID(StringRef Name)
Definition: SampleProf.h:505
Represents either an error or a value T.
Definition: ErrorOr.h:56
This class represents lattice values for constants.
Definition: AllocatorList.h:23
static StringRef getRepInFormat(StringRef Name, SampleProfileFormat Format, std::string &GUIDBuf)
Definition: SampleProf.h:98
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
Implements a dense probed hash-table based set.
Definition: DenseSet.h:249
sampleprof_error merge(const SampleRecord &Other, uint64_t Weight=1)
Merge the samples in Other into this record.
Definition: SampleProf.h:208
LineLocation(uint32_t L, uint32_t D)
Definition: SampleProf.h:119
SampleSorter(const std::map< LocationT, SampleT > &Samples)
Definition: SampleProf.h:562
ErrorOr< uint64_t > findSamplesAt(uint32_t LineOffset, uint32_t Discriminator) const
Return the number of samples collected at the given location.
Definition: SampleProf.h:279
F(f)
std::pair< const LocationT, SampleT > SamplesWithLoc
Definition: SampleProf.h:559
void findInlinedFunctions(DenseSet< GlobalValue::GUID > &S, const Module *M, uint64_t Threshold) const
Recursively traverses all children, if the total sample count of the corresponding function is no les...
Definition: SampleProf.h:405
bool operator<(const LineLocation &O) const
Definition: SampleProf.h:124
static SampleProfileFormat Format
Definition: SampleProf.h:496
Representation of the samples collected for a function.
Definition: SampleProf.h:239
static const SortedCallTargetSet SortCallTargets(const CallTargetMap &Targets)
Sort call targets in descending order of call frequency.
Definition: SampleProf.h:198
Definition: BitVector.h:937
std::error_code make_error_code(BitcodeError E)
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:126
sampleprof_error addCalledTarget(StringRef F, uint64_t S, uint64_t Weight=1)
Add called function F with samples S.
Definition: SampleProf.h:178
Representation of a single sample record.
Definition: SampleProf.h:145
LLVM_NODISCARD size_t size() const
size - Get the string size.
Definition: StringRef.h:130
void setName(StringRef FunctionName)
Set the name of the function.
Definition: SampleProf.h:426
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
std::map< LineLocation, SampleRecord > BodySampleMap
Definition: SampleProf.h:228
Debug location.
static uint64_t SPVersion()
Definition: SampleProf.h:107
Sort a LocationT->SampleT map by LocationT.
Definition: SampleProf.h:557
uint64_t getHeadSamples() const
Return the total number of branch samples that have the function as the branch target.
Definition: SampleProf.h:350
uint64_t getSamples() const
Definition: SampleProf.h:191
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
sampleprof_error
Definition: SampleProf.h:41
DISubprogram * getSubprogram() const
Get the attached subprogram.
Definition: Metadata.cpp:1504
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
Definition: SampleProf.h:373
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
sampleprof_error addBodySamples(uint32_t LineOffset, uint32_t Discriminator, uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:262
sampleprof_error addSamples(uint64_t S, uint64_t Weight=1)
Increment the number of samples for this record by S.
Definition: SampleProf.h:166
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes...
Definition: SampleProf.h:438
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:74
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
std::map< std::string, FunctionSamples, std::less<> > FunctionSamplesMap
Definition: SampleProf.h:231
StringRef getFuncNameInModule(const Module *M) const
Return the original function name if it exists in Module M.
Definition: SampleProf.h:432
std::enable_if< std::is_unsigned< T >::value, T >::type 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:843
const FunctionSamples * findFunctionSamplesAt(const LineLocation &Loc, StringRef CalleeName) const
Returns a pointer to FunctionSamples at the given callsite location Loc with callee CalleeName...
Definition: SampleProf.h:317
sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:246
Module.h This file contains the declarations for the Module class.
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:696
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
FunctionSamplesMap & functionSamplesAt(const LineLocation &Loc)
Return the function samples at the given callsite location.
Definition: SampleProf.h:300
ErrorOr< SampleRecord::CallTargetMap > findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const
Returns the call target map collected at a given location.
Definition: SampleProf.h:292
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:132
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
Definition: Module.cpp:174
const std::error_category & sampleprof_category()
Definition: SampleProf.cpp:78
amdgpu Simplify well known AMD library false FunctionCallee Callee
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition: GlobalValue.h:510
bool hasCalls() const
Return true if this sample record contains function calls.
Definition: SampleProf.h:189
std::map< LineLocation, FunctionSamplesMap > CallsiteSampleMap
Definition: SampleProf.h:232
static const size_t npos
Definition: StringRef.h:50
Represents the relative location of an instruction.
Definition: SampleProf.h:118
StringRef getNameInModule(StringRef Name, const Module *M) const
Translate Name into its original name in Module.
Definition: SampleProf.h:470
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:223
StringRef getName() const
Return a constant reference to the value&#39;s name.
Definition: Value.cpp:214
#define I(x, y, z)
Definition: MD5.cpp:58
StringRef getName() const
Return the function name.
Definition: SampleProf.h:429
const CallTargetMap & getCallTargets() const
Definition: SampleProf.h:192
std::set< CallTarget, CallTargetComparator > SortedCallTargetSet
Definition: SampleProf.h:157
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
Definition: APInt.h:2045
static GlobalValue::GUID getGUID(GlobalValue::GUID G)
static uint64_t SPMagic(SampleProfileFormat Format=SPF_Binary)
Definition: SampleProf.h:90
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:254
const std::string to_string(const T &Value)
Definition: ScopedPrinter.h:61
Provides ErrorOr<T> smart pointer.
LLVM_NODISCARD const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
Definition: StringRef.h:122
std::pair< StringRef, uint64_t > CallTarget
Definition: SampleProf.h:147
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
void stable_sort(R &&Range)
Definition: STLExtras.h:1301
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Definition: SampleProf.h:343
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
Definition: SampleProf.h:376
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
Definition: Function.h:333
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
uint64_t getEntrySamples() const
Return the sample count of the first instruction of the function.
Definition: SampleProf.h:354
const SortedCallTargetSet getSortedCallTargets() const
Definition: SampleProf.h:193
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
bool operator()(const CallTarget &LHS, const CallTarget &RHS) const
Definition: SampleProf.h:149
sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight=1)
Merge the samples in Other into this one.
Definition: SampleProf.h:382
sampleprof_error addCalledTargetSamples(uint32_t LineOffset, uint32_t Discriminator, StringRef FName, uint64_t Num, uint64_t Weight=1)
Definition: SampleProf.h:268
sampleprof_error MergeResult(sampleprof_error &Accumulator, sampleprof_error Result)
Definition: SampleProf.h:60