LLVM  14.0.0git
SampleProf.cpp
Go to the documentation of this file.
1 //=-- SampleProf.cpp - Sample profiling format support --------------------===//
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 
15 #include "llvm/Config/llvm-config.h"
17 #include "llvm/IR/PseudoProbe.h"
20 #include "llvm/Support/Compiler.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/Support/Error.h"
24 #include "llvm/Support/LEB128.h"
27 #include <string>
28 #include <system_error>
29 
30 using namespace llvm;
31 using namespace sampleprof;
32 
34  "profile-symbol-list-cutoff", cl::Hidden, cl::init(-1), cl::ZeroOrMore,
35  cl::desc("Cutoff value about how many symbols in profile symbol list "
36  "will be used. This is very useful for performance debugging"));
37 
39  "generate-merged-base-profiles", cl::init(true), cl::ZeroOrMore,
40  cl::desc("When generating nested context-sensitive profiles, always "
41  "generate extra base profile for function with all its context "
42  "profiles merged into it."));
43 
44 namespace llvm {
45 namespace sampleprof {
50 bool FunctionSamples::UseMD5 = false;
52 bool FunctionSamples::ProfileIsFS = false;
53 } // namespace sampleprof
54 } // namespace llvm
55 
56 namespace {
57 
58 // FIXME: This class is only here to support the transition to llvm::Error. It
59 // will be removed once this transition is complete. Clients should prefer to
60 // deal with the Error value directly, rather than converting to error_code.
61 class SampleProfErrorCategoryType : public std::error_category {
62  const char *name() const noexcept override { return "llvm.sampleprof"; }
63 
64  std::string message(int IE) const override {
65  sampleprof_error E = static_cast<sampleprof_error>(IE);
66  switch (E) {
68  return "Success";
70  return "Invalid sample profile data (bad magic)";
72  return "Unsupported sample profile format version";
74  return "Too much profile data";
76  return "Truncated profile data";
78  return "Malformed sample profile data";
80  return "Unrecognized sample profile encoding format";
82  return "Profile encoding format unsupported for writing operations";
84  return "Truncated function name table";
86  return "Unimplemented feature";
88  return "Counter overflow";
90  return "Ostream does not support seek";
92  return "Compress failure";
94  return "Uncompress failure";
96  return "Zlib is unavailable";
98  return "Function hash mismatch";
99  }
100  llvm_unreachable("A value of sampleprof_error has no message.");
101  }
102 };
103 
104 } // end anonymous namespace
105 
107 
109  return *ErrorCategory;
110 }
111 
113  OS << LineOffset;
114  if (Discriminator > 0)
115  OS << "." << Discriminator;
116 }
117 
119  const LineLocation &Loc) {
120  Loc.print(OS);
121  return OS;
122 }
123 
124 /// Merge the samples in \p Other into this record.
125 /// Optionally scale sample counts by \p Weight.
127  uint64_t Weight) {
128  sampleprof_error Result;
129  Result = addSamples(Other.getSamples(), Weight);
130  for (const auto &I : Other.getCallTargets()) {
131  MergeResult(Result, addCalledTarget(I.first(), I.second, Weight));
132  }
133  return Result;
134 }
135 
136 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
138 #endif
139 
140 /// Print the sample record to the stream \p OS indented by \p Indent.
141 void SampleRecord::print(raw_ostream &OS, unsigned Indent) const {
142  OS << NumSamples;
143  if (hasCalls()) {
144  OS << ", calls:";
145  for (const auto &I : getSortedCallTargets())
146  OS << " " << I.first << ":" << I.second;
147  }
148  OS << "\n";
149 }
150 
151 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
153 #endif
154 
156  const SampleRecord &Sample) {
157  Sample.print(OS, 0);
158  return OS;
159 }
160 
161 /// Print the samples collected for a function on stream \p OS.
162 void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
163  if (getFunctionHash())
164  OS << "CFG checksum " << getFunctionHash() << "\n";
165 
166  OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size()
167  << " sampled lines\n";
168 
169  OS.indent(Indent);
170  if (!BodySamples.empty()) {
171  OS << "Samples collected in the function's body {\n";
172  SampleSorter<LineLocation, SampleRecord> SortedBodySamples(BodySamples);
173  for (const auto &SI : SortedBodySamples.get()) {
174  OS.indent(Indent + 2);
175  OS << SI->first << ": " << SI->second;
176  }
177  OS.indent(Indent);
178  OS << "}\n";
179  } else {
180  OS << "No samples collected in the function's body\n";
181  }
182 
183  OS.indent(Indent);
184  if (!CallsiteSamples.empty()) {
185  OS << "Samples collected in inlined callsites {\n";
187  CallsiteSamples);
188  for (const auto &CS : SortedCallsiteSamples.get()) {
189  for (const auto &FS : CS->second) {
190  OS.indent(Indent + 2);
191  OS << CS->first << ": inlined callee: " << FS.second.getName() << ": ";
192  FS.second.print(OS, Indent + 4);
193  }
194  }
195  OS.indent(Indent);
196  OS << "}\n";
197  } else {
198  OS << "No inlined callsites in this function\n";
199  }
200 }
201 
203  const FunctionSamples &FS) {
204  FS.print(OS);
205  return OS;
206 }
207 
209  const SampleProfileMap &ProfileMap,
210  std::vector<NameFunctionSamples> &SortedProfiles) {
211  for (const auto &I : ProfileMap) {
212  assert(I.first == I.second.getContext() && "Inconsistent profile map");
213  SortedProfiles.push_back(std::make_pair(I.second.getContext(), &I.second));
214  }
215  llvm::stable_sort(SortedProfiles, [](const NameFunctionSamples &A,
216  const NameFunctionSamples &B) {
217  if (A.second->getTotalSamples() == B.second->getTotalSamples())
218  return A.first < B.first;
219  return A.second->getTotalSamples() > B.second->getTotalSamples();
220  });
221 }
222 
224  return (DIL->getLine() - DIL->getScope()->getSubprogram()->getLine()) &
225  0xffff;
226 }
227 
229  bool ProfileIsFS) {
231  // In a pseudo-probe based profile, a callsite is simply represented by the
232  // ID of the probe associated with the call instruction. The probe ID is
233  // encoded in the Discriminator field of the call instruction's debug
234  // metadata.
236  DIL->getDiscriminator()),
237  0);
238  } else {
239  unsigned Discriminator =
240  ProfileIsFS ? DIL->getDiscriminator() : DIL->getBaseDiscriminator();
241  return LineLocation(FunctionSamples::getOffset(DIL), Discriminator);
242  }
243 }
244 
246  const LineLocation &Callsite) {
247  uint64_t NameHash = std::hash<std::string>{}(CalleeName.str());
248  uint64_t LocId =
249  (((uint64_t)Callsite.LineOffset) << 32) | Callsite.Discriminator;
250  return NameHash + (LocId << 5) + LocId;
251 }
252 
254  const DILocation *DIL, SampleProfileReaderItaniumRemapper *Remapper) const {
255  assert(DIL);
257 
258  const DILocation *PrevDIL = DIL;
259  for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
260  // Use C++ linkage name if possible.
261  StringRef Name = PrevDIL->getScope()->getSubprogram()->getLinkageName();
262  if (Name.empty())
263  Name = PrevDIL->getScope()->getSubprogram()->getName();
266  Name);
267  PrevDIL = DIL;
268  }
269 
270  if (S.size() == 0)
271  return this;
272  const FunctionSamples *FS = this;
273  for (int i = S.size() - 1; i >= 0 && FS != nullptr; i--) {
274  FS = FS->findFunctionSamplesAt(S[i].first, S[i].second, Remapper);
275  }
276  return FS;
277 }
278 
280  NameSet.insert(getName());
281  for (const auto &BS : BodySamples)
282  for (const auto &TS : BS.second.getCallTargets())
283  NameSet.insert(TS.getKey());
284 
285  for (const auto &CS : CallsiteSamples) {
286  for (const auto &NameFS : CS.second) {
287  NameSet.insert(NameFS.first);
288  NameFS.second.findAllNames(NameSet);
289  }
290  }
291 }
292 
294  const LineLocation &Loc, StringRef CalleeName,
295  SampleProfileReaderItaniumRemapper *Remapper) const {
296  CalleeName = getCanonicalFnName(CalleeName);
297 
298  std::string CalleeGUID;
299  CalleeName = getRepInFormat(CalleeName, UseMD5, CalleeGUID);
300 
301  auto iter = CallsiteSamples.find(Loc);
302  if (iter == CallsiteSamples.end())
303  return nullptr;
304  auto FS = iter->second.find(CalleeName);
305  if (FS != iter->second.end())
306  return &FS->second;
307  if (Remapper) {
308  if (auto NameInProfile = Remapper->lookUpNameInProfile(CalleeName)) {
309  auto FS = iter->second.find(*NameInProfile);
310  if (FS != iter->second.end())
311  return &FS->second;
312  }
313  }
314  // If we cannot find exact match of the callee name, return the FS with
315  // the max total count. Only do this when CalleeName is not provided,
316  // i.e., only for indirect calls.
317  if (!CalleeName.empty())
318  return nullptr;
319  uint64_t MaxTotalSamples = 0;
320  const FunctionSamples *R = nullptr;
321  for (const auto &NameFS : iter->second)
322  if (NameFS.second.getTotalSamples() >= MaxTotalSamples) {
323  MaxTotalSamples = NameFS.second.getTotalSamples();
324  R = &NameFS.second;
325  }
326  return R;
327 }
328 
329 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
331 #endif
332 
333 std::error_code ProfileSymbolList::read(const uint8_t *Data,
334  uint64_t ListSize) {
335  const char *ListStart = reinterpret_cast<const char *>(Data);
336  uint64_t Size = 0;
337  uint64_t StrNum = 0;
338  while (Size < ListSize && StrNum < ProfileSymbolListCutOff) {
339  StringRef Str(ListStart + Size);
340  add(Str);
341  Size += Str.size() + 1;
342  StrNum++;
343  }
344  if (Size != ListSize && StrNum != ProfileSymbolListCutOff)
347 }
348 
350  uint64_t ColdCountThreshold, bool TrimColdContext, bool MergeColdContext,
351  uint32_t ColdContextFrameLength, bool TrimBaseProfileOnly) {
352  if (!TrimColdContext && !MergeColdContext)
353  return;
354 
355  // Nothing to merge if sample threshold is zero
356  if (ColdCountThreshold == 0)
357  return;
358 
359  // Trimming base profiles only is mainly to honor the preinliner decsion. When
360  // MergeColdContext is true preinliner decsion is not honored anyway so turn
361  // off TrimBaseProfileOnly.
362  if (MergeColdContext)
363  TrimBaseProfileOnly = false;
364 
365  // Filter the cold profiles from ProfileMap and move them into a tmp
366  // container
367  std::vector<std::pair<SampleContext, const FunctionSamples *>> ColdProfiles;
368  for (const auto &I : ProfileMap) {
369  const SampleContext &Context = I.first;
370  const FunctionSamples &FunctionProfile = I.second;
371  if (FunctionProfile.getTotalSamples() < ColdCountThreshold &&
372  (!TrimBaseProfileOnly || Context.isBaseContext()))
373  ColdProfiles.emplace_back(Context, &I.second);
374  }
375 
376  // Remove the cold profile from ProfileMap and merge them into
377  // MergedProfileMap by the last K frames of context
378  SampleProfileMap MergedProfileMap;
379  for (const auto &I : ColdProfiles) {
380  if (MergeColdContext) {
381  auto MergedContext = I.second->getContext().getContextFrames();
382  if (ColdContextFrameLength < MergedContext.size())
383  MergedContext = MergedContext.take_back(ColdContextFrameLength);
384  auto Ret = MergedProfileMap.emplace(MergedContext, FunctionSamples());
385  FunctionSamples &MergedProfile = Ret.first->second;
386  MergedProfile.merge(*I.second);
387  }
388  ProfileMap.erase(I.first);
389  }
390 
391  // Move the merged profiles into ProfileMap;
392  for (const auto &I : MergedProfileMap) {
393  // Filter the cold merged profile
394  if (TrimColdContext && I.second.getTotalSamples() < ColdCountThreshold &&
395  ProfileMap.find(I.first) == ProfileMap.end())
396  continue;
397  // Merge the profile if the original profile exists, otherwise just insert
398  // as a new profile
399  auto Ret = ProfileMap.emplace(I.first, FunctionSamples());
400  if (Ret.second) {
401  SampleContext FContext(Ret.first->first, RawContext);
402  FunctionSamples &FProfile = Ret.first->second;
403  FProfile.setContext(FContext);
404  }
405  FunctionSamples &OrigProfile = Ret.first->second;
406  OrigProfile.merge(I.second);
407  }
408 }
409 
411  std::vector<SampleContext> ProfilesToBeRemoved;
412  SampleProfileMap ProfilesToBeAdded;
413  for (auto &I : ProfileMap) {
414  FunctionSamples &FProfile = I.second;
415  SampleContext &Context = FProfile.getContext();
416  if (I.first == Context)
417  continue;
418 
419  // Use the context string from FunctionSamples to update the keys of
420  // ProfileMap. They can get out of sync after context profile promotion
421  // through pre-inliner.
422  // Duplicate the function profile for later insertion to avoid a conflict
423  // caused by a context both to be add and to be removed. This could happen
424  // when a context is promoted to another context which is also promoted to
425  // the third context. For example, given an original context A @ B @ C that
426  // is promoted to B @ C and the original context B @ C which is promoted to
427  // just C, adding B @ C to the profile map while removing same context (but
428  // with different profiles) from the map can cause a conflict if they are
429  // not handled in a right order. This can be solved by just caching the
430  // profiles to be added.
431  auto Ret = ProfilesToBeAdded.emplace(Context, FProfile);
432  (void)Ret;
433  assert(Ret.second && "Context conflict during canonicalization");
434  ProfilesToBeRemoved.push_back(I.first);
435  }
436 
437  for (auto &I : ProfilesToBeRemoved) {
438  ProfileMap.erase(I);
439  }
440 
441  for (auto &I : ProfilesToBeAdded) {
442  ProfileMap.emplace(I.first, I.second);
443  }
444 }
445 
446 std::error_code ProfileSymbolList::write(raw_ostream &OS) {
447  // Sort the symbols before output. If doing compression.
448  // It will make the compression much more effective.
449  std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
450  llvm::sort(SortedList);
451 
452  std::string OutputString;
453  for (auto &Sym : SortedList) {
454  OutputString.append(Sym.str());
455  OutputString.append(1, '\0');
456  }
457 
458  OS << OutputString;
460 }
461 
463  OS << "======== Dump profile symbol list ========\n";
464  std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
465  llvm::sort(SortedList);
466 
467  for (auto &Sym : SortedList)
468  OS << Sym << "\n";
469 }
470 
473  const LineLocation &CallSite, StringRef CalleeName) {
474  uint64_t Hash = FunctionSamples::getCallSiteHash(CalleeName, CallSite);
475  auto It = AllChildFrames.find(Hash);
476  if (It != AllChildFrames.end()) {
477  assert(It->second.FuncName == CalleeName &&
478  "Hash collision for child context node");
479  return &It->second;
480  }
481 
482  AllChildFrames[Hash] = FrameNode(CalleeName, nullptr, CallSite);
483  return &AllChildFrames[Hash];
484 }
485 
487  : ProfileMap(Profiles) {
488  for (auto &FuncSample : Profiles) {
489  FunctionSamples *FSamples = &FuncSample.second;
490  auto *NewNode = getOrCreateContextPath(FSamples->getContext());
491  assert(!NewNode->FuncSamples && "New node cannot have sample profile");
492  NewNode->FuncSamples = FSamples;
493  }
494 }
495 
497 CSProfileConverter::getOrCreateContextPath(const SampleContext &Context) {
498  auto Node = &RootFrame;
499  LineLocation CallSiteLoc(0, 0);
500  for (auto &Callsite : Context.getContextFrames()) {
501  Node = Node->getOrCreateChildFrame(CallSiteLoc, Callsite.FuncName);
502  CallSiteLoc = Callsite.Location;
503  }
504  return Node;
505 }
506 
508  // Process each child profile. Add each child profile to callsite profile map
509  // of the current node `Node` if `Node` comes with a profile. Otherwise
510  // promote the child profile to a standalone profile.
511  auto *NodeProfile = Node.FuncSamples;
512  for (auto &It : Node.AllChildFrames) {
513  auto &ChildNode = It.second;
514  convertProfiles(ChildNode);
515  auto *ChildProfile = ChildNode.FuncSamples;
516  if (!ChildProfile)
517  continue;
518  SampleContext OrigChildContext = ChildProfile->getContext();
519  // Reset the child context to be contextless.
520  ChildProfile->getContext().setName(OrigChildContext.getName());
521  if (NodeProfile) {
522  // Add child profile to the callsite profile map.
523  auto &SamplesMap = NodeProfile->functionSamplesAt(ChildNode.CallSiteLoc);
524  SamplesMap.emplace(OrigChildContext.getName().str(), *ChildProfile);
525  NodeProfile->addTotalSamples(ChildProfile->getTotalSamples());
526  }
527 
528  // Separate child profile to be a standalone profile, if the current parent
529  // profile doesn't exist. This is a duplicating operation when the child
530  // profile is already incorporated into the parent which is still useful and
531  // thus done optionally. It is seen that duplicating context profiles into
532  // base profiles improves the code quality for thinlto build by allowing a
533  // profile in the prelink phase for to-be-fully-inlined functions.
534  if (!NodeProfile || GenerateMergedBaseProfiles)
535  ProfileMap[ChildProfile->getContext()].merge(*ChildProfile);
536 
537  // Contexts coming with a `ContextShouldBeInlined` attribute indicate this
538  // is a preinliner-computed profile.
539  if (OrigChildContext.hasAttribute(ContextShouldBeInlined))
541 
542  // Remove the original child profile.
543  ProfileMap.erase(OrigChildContext);
544  }
545 }
546 
llvm::Check::Size
@ Size
Definition: FileCheck.h:73
i
i
Definition: README.txt:29
llvm::sampleprof_error::uncompress_failed
@ uncompress_failed
llvm::InstrProfKind::CS
@ CS
LLVM_DUMP_METHOD
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:507
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:22
llvm::sampleprof::SampleSorter::get
const SamplesWithLocList & get() const
Definition: SampleProf.h:1154
llvm::sampleprof::FunctionSamples::ProfileIsProbeBased
static bool ProfileIsProbeBased
Definition: SampleProf.h:1047
llvm::X86AS::FS
@ FS
Definition: X86.h:188
llvm::sampleprof::FunctionSamples::dump
void dump() const
Definition: SampleProf.cpp:330
llvm::sampleprof::RawContext
@ RawContext
Definition: SampleProf.h:405
DebugInfoMetadata.h
llvm::sampleprof::LineLocation::dump
void dump() const
Definition: SampleProf.cpp:137
llvm::sampleprof::SampleContext::hasAttribute
bool hasAttribute(ContextAttributeMask A)
Definition: SampleProf.h:561
ErrorCategory
static ManagedStatic< SampleProfErrorCategoryType > ErrorCategory
Definition: SampleProf.cpp:106
llvm::sampleprof::SampleRecord::hasCalls
bool hasCalls() const
Return true if this sample record contains function calls.
Definition: SampleProf.h:362
llvm::sampleprof_error::hash_mismatch
@ hash_mismatch
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1176
llvm::sampleprof::NameFunctionSamples
std::pair< SampleContext, const FunctionSamples * > NameFunctionSamples
Definition: SampleProf.h:1132
ErrorHandling.h
ManagedStatic.h
Error.h
llvm::sampleprof_error::unsupported_version
@ unsupported_version
llvm::sampleprof::SampleProfileMap
std::unordered_map< SampleContext, FunctionSamples, SampleContext::Hash > SampleProfileMap
Definition: SampleProf.h:1130
llvm::cl::Hidden
@ Hidden
Definition: CommandLine.h:143
llvm::DILocation
Debug location.
Definition: DebugInfoMetadata.h:1592
llvm::sampleprof::ContextShouldBeInlined
@ ContextShouldBeInlined
Definition: SampleProf.h:415
llvm::sampleprof_error::not_implemented
@ not_implemented
llvm::MipsISD::Ret
@ Ret
Definition: MipsISelLowering.h:116
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:946
llvm::sampleprof::MergedContext
@ MergedContext
Definition: SampleProf.h:408
llvm::detail::DenseSetImpl< ValueT, DenseMap< ValueT, detail::DenseSetEmpty, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:205
llvm::sampleprof::CSProfileConverter::FrameNode::getOrCreateChildFrame
FrameNode * getOrCreateChildFrame(const LineLocation &CallSite, StringRef CalleeName)
Definition: SampleProf.cpp:472
llvm::Data
@ Data
Definition: SIMachineScheduler.h:55
llvm::sampleprof::LineLocation::Discriminator
uint32_t Discriminator
Definition: SampleProf.h:303
llvm::sampleprof_error::counter_overflow
@ counter_overflow
llvm::sampleprof::LineLocation::LineOffset
uint32_t LineOffset
Definition: SampleProf.h:302
Context
ManagedStatic< detail::RecordContext > Context
Definition: Record.cpp:96
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::sampleprof::FunctionSamples::HasUniqSuffix
static bool HasUniqSuffix
Whether the profile contains any ".__uniq." suffix in a name.
Definition: SampleProf.h:1063
CommandLine.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::getTotalSamples
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Definition: SampleProf.h:820
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::sampleprof::FunctionSamples::ProfileIsCSFlat
static bool ProfileIsCSFlat
Definition: SampleProf.h:1049
llvm::sampleprof::CSProfileConverter::FrameNode
Definition: SampleProf.h:1191
llvm::ManagedStatic
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
Definition: ManagedStatic.h:83
SampleProf.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::sampleprof::SampleProfileReaderItaniumRemapper::lookUpNameInProfile
Optional< StringRef > lookUpNameInProfile(StringRef FunctionName)
Return the equivalent name in the profile for FunctionName if it exists.
Definition: SampleProfReader.cpp:1752
llvm::sampleprof_category
const std::error_category & sampleprof_category()
Definition: SampleProf.cpp:108
llvm::sampleprof::FunctionSamples::Format
static SampleProfileFormat Format
Definition: SampleProf.h:1057
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::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:54
llvm::sampleprof::ProfileSymbolList::read
std::error_code read(const uint8_t *Data, uint64_t ListSize)
Definition: SampleProf.cpp:333
llvm::StringRef::str
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:245
llvm::sampleprof::CSProfileConverter::FrameNode::AllChildFrames
std::map< uint64_t, FrameNode > AllChildFrames
Definition: SampleProf.h:1195
llvm::sampleprof::SampleContext
Definition: SampleProf.h:472
GenerateMergedBaseProfiles
cl::opt< bool > GenerateMergedBaseProfiles("generate-merged-base-profiles", cl::init(true), cl::ZeroOrMore, cl::desc("When generating nested context-sensitive profiles, always " "generate extra base profile for function with all its context " "profiles merged into it."))
llvm::sampleprof::sortFuncProfiles
void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
Definition: SampleProf.cpp:208
llvm::sampleprof::FunctionSamples::ProfileIsFS
static bool ProfileIsFS
If this profile uses flow sensitive discriminators.
Definition: SampleProf.h:1066
llvm::ARM_PROC::IE
@ IE
Definition: ARMBaseInfo.h:27
llvm::cl::ZeroOrMore
@ ZeroOrMore
Definition: CommandLine.h:120
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition: DenseSet.h:267
llvm::cl::opt
Definition: CommandLine.h:1432
llvm::sampleprof::SampleContext::setName
void setName(StringRef FunctionName)
Set the name of the function and clear the current context.
Definition: SampleProf.h:598
llvm::StringRef::empty
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:153
uint64_t
const
aarch64 promote const
Definition: AArch64PromoteConstant.cpp:232
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition: SampleProf.h:691
LEB128.h
llvm::sampleprof::FunctionSamples::ProfileIsCSNested
static bool ProfileIsCSNested
Definition: SampleProf.h:1051
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
SampleProfReader.h
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:441
llvm::sampleprof::FunctionSamples::setContext
void setContext(const SampleContext &FContext)
Definition: SampleProf.h:1055
llvm::sampleprof::FunctionSamples::getFunctionHash
uint64_t getFunctionHash() const
Definition: SampleProf.h:953
llvm::sampleprof::SampleRecord::getSortedCallTargets
const SortedCallTargetSet getSortedCallTargets() const
Definition: SampleProf.h:366
llvm::sampleprof_error::malformed
@ malformed
message
message(STATUS "Targeting ${t}") add_subdirectory($
Definition: CMakeLists.txt:33
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::sampleprof::SampleContext::getName
StringRef getName() const
Definition: SampleProf.h:570
SI
StandardInstrumentations SI(Debug, VerifyEach)
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:1060
llvm::PseudoProbeDwarfDiscriminator::extractProbeIndex
static uint32_t extractProbeIndex(uint32_t Value)
Definition: PseudoProbe.h:53
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:283
llvm::MergeResult
sampleprof_error MergeResult(sampleprof_error &Accumulator, sampleprof_error Result)
Definition: SampleProf.h:68
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::sampleprof::SampleSorter
Sort a LocationT->SampleT map by LocationT.
Definition: SampleProf.h:1141
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
uint32_t
Compiler.h
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:1227
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
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::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_error::ostream_seek_unsupported
@ ostream_seek_unsupported
llvm::sampleprof::CSProfileConverter::convertProfiles
void convertProfiles()
Definition: SampleProf.cpp:547
name
static const char * name
Definition: SVEIntrinsicOpts.cpp:74
llvm::stable_sort
void stable_sort(R &&Range)
Definition: STLExtras.h:1727
llvm::sampleprof::ProfileSymbolList::write
std::error_code write(raw_ostream &OS)
Definition: SampleProf.cpp:446
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
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::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1533
llvm::sampleprof::SampleRecord
Representation of a single sample record.
Definition: SampleProf.h:318
llvm::sampleprof::CSProfileConverter::FrameNode::FrameNode
FrameNode(StringRef FName=StringRef(), FunctionSamples *FSamples=nullptr, LineLocation CallLoc={0, 0})
Definition: SampleProf.h:1192
llvm::sampleprof_error::compress_failed
@ compress_failed
PseudoProbe.h
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:876
llvm::sampleprof_error::zlib_unavailable
@ zlib_unavailable
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:351
llvm::sampleprof::FunctionSamples::getContext
SampleContext & getContext() const
Definition: SampleProf.h:1053
llvm::sampleprof_error::success
@ success
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:957
llvm::DILocation::getBaseDiscriminator
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
Definition: DebugInfoMetadata.h:2251
llvm::sampleprof::SampleContextTrimmer::canonicalizeContextProfiles
void canonicalizeContextProfiles()
Definition: SampleProf.cpp:410
llvm::sampleprof::SampleRecord::dump
void dump() const
Definition: SampleProf.cpp:152
llvm::raw_ostream::indent
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
Definition: raw_ostream.cpp:496
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::SampleProfileReaderItaniumRemapper
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...
Definition: SampleProfReader.h:264
llvm::sampleprof_error::truncated_name_table
@ truncated_name_table
llvm::sampleprof::ProfileSymbolList::dump
void dump(raw_ostream &OS=dbgs()) const
Definition: SampleProf.cpp:462
ProfileSymbolListCutOff
static cl::opt< uint64_t > ProfileSymbolListCutOff("profile-symbol-list-cutoff", cl::Hidden, cl::init(-1), cl::ZeroOrMore, cl::desc("Cutoff value about how many symbols in profile symbol list " "will be used. This is very useful for performance debugging"))
llvm::cl::desc
Definition: CommandLine.h:412
raw_ostream.h
error_category
static ManagedStatic< _object_error_category > error_category
Definition: Error.cpp:76
llvm::sampleprof_error::truncated
@ truncated
Debug.h
llvm::sampleprof::SampleRecord::addSamples
sampleprof_error addSamples(uint64_t S, uint64_t Weight=1)
Increment the number of samples for this record by S.
Definition: SampleProf.h:339
llvm::sampleprof_error::bad_magic
@ bad_magic
llvm::sampleprof::CSProfileConverter::CSProfileConverter
CSProfileConverter(SampleProfileMap &Profiles)
Definition: SampleProf.cpp:486
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