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