LLVM 22.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"
21#include "llvm/Support/Debug.h"
23#include "llvm/Support/LEB128.h"
25#include <string>
26#include <system_error>
27
28using namespace llvm;
29using namespace sampleprof;
30
32 "profile-symbol-list-cutoff", cl::Hidden, cl::init(-1),
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",
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
42namespace llvm {
43namespace sampleprof {
47bool FunctionSamples::UseMD5 = false;
50} // namespace sampleprof
51} // namespace llvm
52
53namespace {
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.
58class 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) {
64 case sampleprof_error::success:
65 return "Success";
66 case sampleprof_error::bad_magic:
67 return "Invalid sample profile data (bad magic)";
68 case sampleprof_error::unsupported_version:
69 return "Unsupported sample profile format version";
70 case sampleprof_error::too_large:
71 return "Too much profile data";
72 case sampleprof_error::truncated:
73 return "Truncated profile data";
74 case sampleprof_error::malformed:
75 return "Malformed sample profile data";
76 case sampleprof_error::unrecognized_format:
77 return "Unrecognized sample profile encoding format";
78 case sampleprof_error::unsupported_writing_format:
79 return "Profile encoding format unsupported for writing operations";
80 case sampleprof_error::truncated_name_table:
81 return "Truncated function name table";
82 case sampleprof_error::not_implemented:
83 return "Unimplemented feature";
84 case sampleprof_error::counter_overflow:
85 return "Counter overflow";
86 case sampleprof_error::ostream_seek_unsupported:
87 return "Ostream does not support seek";
88 case sampleprof_error::uncompress_failed:
89 return "Uncompress failure";
90 case sampleprof_error::zlib_unavailable:
91 return "Zlib is unavailable";
92 case sampleprof_error::hash_mismatch:
93 return "Function hash mismatch";
94 case sampleprof_error::illegal_line_offset:
95 return "Illegal line offset in sample profile data";
96 }
97 llvm_unreachable("A value of sampleprof_error has no message.");
98 }
99};
100
101} // end anonymous namespace
102
103const std::error_category &llvm::sampleprof_category() {
104 static SampleProfErrorCategoryType ErrorCategory;
105 return ErrorCategory;
106}
107
109 OS << LineOffset;
110 if (Discriminator > 0)
111 OS << "." << Discriminator;
112}
113
115 const LineLocation &Loc) {
116 Loc.print(OS);
117 return OS;
118}
119
120/// Merge the samples in \p Other into this record.
121/// Optionally scale sample counts by \p Weight.
123 uint64_t Weight) {
124 sampleprof_error Result;
125 Result = addSamples(Other.getSamples(), Weight);
126 for (const auto &I : Other.getCallTargets()) {
127 mergeSampleProfErrors(Result, addCalledTarget(I.first, I.second, Weight));
128 }
129 return Result;
130}
131
133 raw_ostream &OS, const MapVector<FunctionId, uint32_t> &NameTable) const {
136 for (const auto &J : getSortedCallTargets()) {
137 FunctionId Callee = J.first;
138 uint64_t CalleeSamples = J.second;
139 if (auto NameIndexIter = NameTable.find(Callee);
140 NameIndexIter != NameTable.end()) {
141 encodeULEB128(NameIndexIter->second, OS);
142 } else {
143 // If the callee is not in the name table, we cannot serialize it.
145 }
146 encodeULEB128(CalleeSamples, OS);
147 }
149}
150
151#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
153#endif
154
158}
159
160/// Print the sample record to the stream \p OS indented by \p Indent.
161void SampleRecord::print(raw_ostream &OS, unsigned Indent) const {
162 OS << NumSamples;
163 if (hasCalls()) {
164 OS << ", calls:";
165 for (const auto &I : getSortedCallTargets())
166 OS << " " << I.first << ":" << I.second;
167 }
168 OS << "\n";
169}
170
171#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
173#endif
174
176 const SampleRecord &Sample) {
177 Sample.print(OS, 0);
178 return OS;
179}
180
181/// Print the samples collected for a function on stream \p OS.
182void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
183 if (getFunctionHash())
184 OS << "CFG checksum " << getFunctionHash() << "\n";
185
186 OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size()
187 << " sampled lines\n";
188
189 OS.indent(Indent);
190 if (!BodySamples.empty()) {
191 OS << "Samples collected in the function's body {\n";
192 SampleSorter<LineLocation, SampleRecord> SortedBodySamples(BodySamples);
193 for (const auto &SI : SortedBodySamples.get()) {
194 OS.indent(Indent + 2);
195 OS << SI->first << ": " << SI->second;
196 }
197 OS.indent(Indent);
198 OS << "}\n";
199 } else {
200 OS << "No samples collected in the function's body\n";
201 }
202
203 OS.indent(Indent);
204 if (!CallsiteSamples.empty()) {
205 OS << "Samples collected in inlined callsites {\n";
207 CallsiteSamples);
208 for (const auto *Element : SortedCallsiteSamples.get()) {
209 // Element is a pointer to a pair of LineLocation and FunctionSamplesMap.
210 const auto &[Loc, FunctionSampleMap] = *Element;
211 for (const FunctionSamples &FuncSample :
212 llvm::make_second_range(FunctionSampleMap)) {
213 OS.indent(Indent + 2);
214 OS << Loc << ": inlined callee: " << FuncSample.getFunction() << ": ";
215 FuncSample.print(OS, Indent + 4);
216 }
217 }
218 OS.indent(Indent);
219 OS << "}\n";
220 } else {
221 OS << "No inlined callsites in this function\n";
222 }
223}
224
226 const FunctionSamples &FS) {
227 FS.print(OS);
228 return OS;
229}
230
232 const SampleProfileMap &ProfileMap,
233 std::vector<NameFunctionSamples> &SortedProfiles) {
234 for (const auto &I : ProfileMap) {
235 SortedProfiles.push_back(std::make_pair(I.first, &I.second));
236 }
237 llvm::stable_sort(SortedProfiles, [](const NameFunctionSamples &A,
238 const NameFunctionSamples &B) {
239 if (A.second->getTotalSamples() == B.second->getTotalSamples())
240 return A.second->getContext() < B.second->getContext();
241 return A.second->getTotalSamples() > B.second->getTotalSamples();
242 });
243}
244
246 return (DIL->getLine() - DIL->getScope()->getSubprogram()->getLine()) &
247 0xffff;
248}
249
251 bool ProfileIsFS) {
253 // In a pseudo-probe based profile, a callsite is simply represented by the
254 // ID of the probe associated with the call instruction. The probe ID is
255 // encoded in the Discriminator field of the call instruction's debug
256 // metadata.
258 DIL->getDiscriminator()),
259 0);
260 } else {
261 unsigned Discriminator =
262 ProfileIsFS ? DIL->getDiscriminator() : DIL->getBaseDiscriminator();
263 return LineLocation(FunctionSamples::getOffset(DIL), Discriminator);
264 }
265}
266
270 *FuncNameToProfNameMap) const {
271 assert(DIL);
273
274 const DILocation *PrevDIL = DIL;
275 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
276 // Use C++ linkage name if possible.
277 StringRef Name = PrevDIL->getScope()->getSubprogram()->getLinkageName();
278 if (Name.empty())
279 Name = PrevDIL->getScope()->getSubprogram()->getName();
282 Name);
283 PrevDIL = DIL;
284 }
285
286 if (S.size() == 0)
287 return this;
288 const FunctionSamples *FS = this;
289 for (int i = S.size() - 1; i >= 0 && FS != nullptr; i--) {
290 FS = FS->findFunctionSamplesAt(S[i].first, S[i].second, Remapper,
291 FuncNameToProfNameMap);
292 }
293 return FS;
294}
295
297 NameSet.insert(getFunction());
298 for (const auto &BS : BodySamples)
299 NameSet.insert_range(llvm::make_first_range(BS.second.getCallTargets()));
300
301 for (const auto &CS : CallsiteSamples) {
302 for (const auto &NameFS : CS.second) {
303 NameSet.insert(NameFS.first);
304 NameFS.second.findAllNames(NameSet);
305 }
306 }
307}
308
310 const LineLocation &Loc, StringRef CalleeName,
313 *FuncNameToProfNameMap) const {
314 CalleeName = getCanonicalFnName(CalleeName);
315
316 auto I = CallsiteSamples.find(mapIRLocToProfileLoc(Loc));
317 if (I == CallsiteSamples.end())
318 return nullptr;
319 auto FS = I->second.find(getRepInFormat(CalleeName));
320 if (FS != I->second.end())
321 return &FS->second;
322
323 if (FuncNameToProfNameMap && !FuncNameToProfNameMap->empty()) {
324 auto R = FuncNameToProfNameMap->find(FunctionId(CalleeName));
325 if (R != FuncNameToProfNameMap->end()) {
326 CalleeName = R->second.stringRef();
327 auto FS = I->second.find(getRepInFormat(CalleeName));
328 if (FS != I->second.end())
329 return &FS->second;
330 }
331 }
332
333 if (Remapper) {
334 if (auto NameInProfile = Remapper->lookUpNameInProfile(CalleeName)) {
335 auto FS = I->second.find(getRepInFormat(*NameInProfile));
336 if (FS != I->second.end())
337 return &FS->second;
338 }
339 }
340 // If we cannot find exact match of the callee name, return the FS with
341 // the max total count. Only do this when CalleeName is not provided,
342 // i.e., only for indirect calls.
343 if (!CalleeName.empty())
344 return nullptr;
345 uint64_t MaxTotalSamples = 0;
346 const FunctionSamples *R = nullptr;
347 for (const auto &NameFS : I->second)
348 if (NameFS.second.getTotalSamples() >= MaxTotalSamples) {
349 MaxTotalSamples = NameFS.second.getTotalSamples();
350 R = &NameFS.second;
351 }
352 return R;
353}
354
355#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
357#endif
358
359std::error_code ProfileSymbolList::read(const uint8_t *Data,
360 uint64_t ListSize) {
361 const char *ListStart = reinterpret_cast<const char *>(Data);
362 uint64_t Size = 0;
363 uint64_t StrNum = 0;
364 while (Size < ListSize && StrNum < ProfileSymbolListCutOff) {
365 StringRef Str(ListStart + Size);
366 add(Str);
367 Size += Str.size() + 1;
368 StrNum++;
369 }
370 if (Size != ListSize && StrNum != ProfileSymbolListCutOff)
373}
374
376 uint64_t ColdCountThreshold, bool TrimColdContext, bool MergeColdContext,
377 uint32_t ColdContextFrameLength, bool TrimBaseProfileOnly) {
378 if (!TrimColdContext && !MergeColdContext)
379 return;
380
381 // Nothing to merge if sample threshold is zero
382 if (ColdCountThreshold == 0)
383 return;
384
385 // Trimming base profiles only is mainly to honor the preinliner decsion. When
386 // MergeColdContext is true preinliner decsion is not honored anyway so turn
387 // off TrimBaseProfileOnly.
388 if (MergeColdContext)
389 TrimBaseProfileOnly = false;
390
391 // Filter the cold profiles from ProfileMap and move them into a tmp
392 // container
393 std::vector<std::pair<hash_code, const FunctionSamples *>> ColdProfiles;
394 for (const auto &I : ProfileMap) {
395 const SampleContext &Context = I.second.getContext();
396 const FunctionSamples &FunctionProfile = I.second;
397 if (FunctionProfile.getTotalSamples() < ColdCountThreshold &&
398 (!TrimBaseProfileOnly || Context.isBaseContext()))
399 ColdProfiles.emplace_back(I.first, &I.second);
400 }
401
402 // Remove the cold profile from ProfileMap and merge them into
403 // MergedProfileMap by the last K frames of context
404 SampleProfileMap MergedProfileMap;
405 for (const auto &I : ColdProfiles) {
406 if (MergeColdContext) {
407 auto MergedContext = I.second->getContext().getContextFrames();
408 if (ColdContextFrameLength < MergedContext.size())
409 MergedContext = MergedContext.take_back(ColdContextFrameLength);
410 // Need to set MergedProfile's context here otherwise it will be lost.
411 FunctionSamples &MergedProfile = MergedProfileMap.create(MergedContext);
412 MergedProfile.merge(*I.second);
413 }
414 ProfileMap.erase(I.first);
415 }
416
417 // Move the merged profiles into ProfileMap;
418 for (const auto &I : MergedProfileMap) {
419 // Filter the cold merged profile
420 if (TrimColdContext && I.second.getTotalSamples() < ColdCountThreshold &&
421 ProfileMap.find(I.second.getContext()) == ProfileMap.end())
422 continue;
423 // Merge the profile if the original profile exists, otherwise just insert
424 // as a new profile. If inserted as a new profile from MergedProfileMap, it
425 // already has the right context.
426 auto Ret = ProfileMap.emplace(I.second.getContext(), FunctionSamples());
427 FunctionSamples &OrigProfile = Ret.first->second;
428 OrigProfile.merge(I.second);
429 }
430}
431
433 // Sort the symbols before output. If doing compression.
434 // It will make the compression much more effective.
435 std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
436 llvm::sort(SortedList);
437
438 std::string OutputString;
439 for (auto &Sym : SortedList) {
440 OutputString.append(Sym.str());
441 OutputString.append(1, '\0');
442 }
443
444 OS << OutputString;
446}
447
449 OS << "======== Dump profile symbol list ========\n";
450 std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
451 llvm::sort(SortedList);
452
453 for (auto &Sym : SortedList)
454 OS << Sym << "\n";
455}
456
459 FunctionId CalleeName) {
460 uint64_t Hash = FunctionSamples::getCallSiteHash(CalleeName, CallSite);
461 auto It = AllChildFrames.find(Hash);
462 if (It != AllChildFrames.end()) {
463 assert(It->second.FuncName == CalleeName &&
464 "Hash collision for child context node");
465 return &It->second;
466 }
467
468 AllChildFrames[Hash] = FrameNode(CalleeName, nullptr, CallSite);
469 return &AllChildFrames[Hash];
470}
471
473 : ProfileMap(Profiles) {
474 for (auto &FuncSample : Profiles) {
475 FunctionSamples *FSamples = &FuncSample.second;
476 auto *NewNode = getOrCreateContextPath(FSamples->getContext());
477 assert(!NewNode->FuncSamples && "New node cannot have sample profile");
478 NewNode->FuncSamples = FSamples;
479 }
480}
481
483ProfileConverter::getOrCreateContextPath(const SampleContext &Context) {
484 auto Node = &RootFrame;
485 LineLocation CallSiteLoc(0, 0);
486 for (auto &Callsite : Context.getContextFrames()) {
487 Node = Node->getOrCreateChildFrame(CallSiteLoc, Callsite.Func);
488 CallSiteLoc = Callsite.Location;
489 }
490 return Node;
491}
492
494 // Process each child profile. Add each child profile to callsite profile map
495 // of the current node `Node` if `Node` comes with a profile. Otherwise
496 // promote the child profile to a standalone profile.
497 auto *NodeProfile = Node.FuncSamples;
498 for (auto &It : Node.AllChildFrames) {
499 auto &ChildNode = It.second;
500 convertCSProfiles(ChildNode);
501 auto *ChildProfile = ChildNode.FuncSamples;
502 if (!ChildProfile)
503 continue;
504 SampleContext OrigChildContext = ChildProfile->getContext();
505 uint64_t OrigChildContextHash = OrigChildContext.getHashCode();
506 // Reset the child context to be contextless.
507 ChildProfile->getContext().setFunction(OrigChildContext.getFunction());
508 if (NodeProfile) {
509 // Add child profile to the callsite profile map.
510 auto &SamplesMap = NodeProfile->functionSamplesAt(ChildNode.CallSiteLoc);
511 SamplesMap.emplace(OrigChildContext.getFunction(), *ChildProfile);
512 NodeProfile->addTotalSamples(ChildProfile->getTotalSamples());
513 // Remove the corresponding body sample for the callsite and update the
514 // total weight.
515 auto Count = NodeProfile->removeCalledTargetAndBodySample(
516 ChildNode.CallSiteLoc.LineOffset, ChildNode.CallSiteLoc.Discriminator,
517 OrigChildContext.getFunction());
518 NodeProfile->removeTotalSamples(Count);
519 }
520
521 uint64_t NewChildProfileHash = 0;
522 // Separate child profile to be a standalone profile, if the current parent
523 // profile doesn't exist. This is a duplicating operation when the child
524 // profile is already incorporated into the parent which is still useful and
525 // thus done optionally. It is seen that duplicating context profiles into
526 // base profiles improves the code quality for thinlto build by allowing a
527 // profile in the prelink phase for to-be-fully-inlined functions.
528 if (!NodeProfile) {
529 ProfileMap[ChildProfile->getContext()].merge(*ChildProfile);
530 NewChildProfileHash = ChildProfile->getContext().getHashCode();
531 } else if (GenerateMergedBaseProfiles) {
532 ProfileMap[ChildProfile->getContext()].merge(*ChildProfile);
533 NewChildProfileHash = ChildProfile->getContext().getHashCode();
534 auto &SamplesMap = NodeProfile->functionSamplesAt(ChildNode.CallSiteLoc);
535 SamplesMap[ChildProfile->getFunction()].getContext().setAttribute(
537 }
538
539 // Remove the original child profile. Check if MD5 of new child profile
540 // collides with old profile, in this case the [] operator already
541 // overwritten it without the need of erase.
542 if (NewChildProfileHash != OrigChildContextHash)
543 ProfileMap.erase(OrigChildContextHash);
544 }
545}
546
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:638
std::string Name
uint64_t Size
Symbol * Sym
Definition: ELF_riscv.cpp:479
#define I(x, y, z)
Definition: MD5.cpp:58
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)
static const char * name
Definition: SMEABIPass.cpp:52
raw_pwrite_stream & OS
static cl::opt< bool > GenerateMergedBaseProfiles("generate-merged-base-profiles", cl::desc("When generating nested context-sensitive profiles, always " "generate extra base profile for function with all its context " "profiles merged into it."))
static cl::opt< uint64_t > ProfileSymbolListCutOff("profile-symbol-list-cutoff", cl::Hidden, cl::init(-1), cl::desc("Cutoff value about how many symbols in profile symbol list " "will be used. This is very useful for performance debugging"))
Debug location.
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:263
This class implements a map that also provides access to all stored values in a deterministic order.
Definition: MapVector.h:36
iterator end()
Definition: MapVector.h:67
iterator find(const KeyT &Key)
Definition: MapVector.h:141
size_t size() const
Definition: SmallVector.h:79
reference emplace_back(ArgTypes &&... Args)
Definition: SmallVector.h:938
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
constexpr bool empty() const
empty - Check if the string is empty.
Definition: StringRef.h:151
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:194
void insert_range(Range &&R)
Definition: DenseSet.h:222
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
This class represents a function that is read from a sample profile.
Definition: FunctionId.h:36
Representation of the samples collected for a function.
Definition: SampleProf.h:757
static LLVM_ABI bool ProfileIsPreInlined
Definition: SampleProf.h:1202
LLVM_ABI const FunctionSamples * findFunctionSamplesAt(const LineLocation &Loc, StringRef CalleeName, SampleProfileReaderItaniumRemapper *Remapper, const HashKeyMap< std::unordered_map, FunctionId, FunctionId > *FuncNameToProfNameMap=nullptr) const
Returns a pointer to FunctionSamples at the given callsite location Loc with callee CalleeName.
Definition: SampleProf.cpp:309
static uint64_t getCallSiteHash(FunctionId Callee, const LineLocation &Callsite)
Returns a unique hash code for a combination of a callsite location and the callee function name.
Definition: SampleProf.h:1175
static LLVM_ABI bool ProfileIsCS
Definition: SampleProf.h:1200
const LineLocation & mapIRLocToProfileLoc(const LineLocation &IRLoc) const
Definition: SampleProf.h:872
FunctionId getFunction() const
Return the function name.
Definition: SampleProf.h:1086
LLVM_ABI const FunctionSamples * findFunctionSamples(const DILocation *DIL, SampleProfileReaderItaniumRemapper *Remapper=nullptr, const HashKeyMap< std::unordered_map, FunctionId, FunctionId > *FuncNameToProfNameMap=nullptr) const
Get the FunctionSamples of the inline instance where DIL originates from.
Definition: SampleProf.cpp:267
static LLVM_ABI bool ProfileIsProbeBased
Definition: SampleProf.h:1198
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
Definition: SampleProf.h:1102
LLVM_ABI void findAllNames(DenseSet< FunctionId > &NameSet) const
Definition: SampleProf.cpp:296
static LLVM_ABI unsigned getOffset(const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
Definition: SampleProf.cpp:245
static LLVM_ABI bool ProfileIsFS
If this profile uses flow sensitive discriminators.
Definition: SampleProf.h:1215
SampleContext & getContext() const
Definition: SampleProf.h:1204
static LLVM_ABI bool HasUniqSuffix
Whether the profile contains any ".__uniq." suffix in a name.
Definition: SampleProf.h:1212
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Definition: SampleProf.h:946
LLVM_ABI void print(raw_ostream &OS=dbgs(), unsigned Indent=0) const
Print the samples collected for a function on stream OS.
Definition: SampleProf.cpp:182
sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight=1)
Merge the samples in Other into this one.
Definition: SampleProf.h:1010
LLVM_ABI void dump() const
Definition: SampleProf.cpp:356
static LLVM_ABI 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:250
static LLVM_ABI bool UseMD5
Whether the profile uses MD5 to represent string.
Definition: SampleProf.h:1209
This class is a wrapper to associative container MapT<KeyT, ValueT> using the hash value of the origi...
Definition: HashKeyMap.h:53
iterator find(const original_key_type &Key)
Definition: HashKeyMap.h:86
LLVM_ABI ProfileConverter(SampleProfileMap &Profiles)
Definition: SampleProf.cpp:472
void add(StringRef Name, bool Copy=false)
copy indicates whether we need to copy the underlying memory for the input Name.
Definition: SampleProf.h:1530
LLVM_ABI std::error_code write(raw_ostream &OS)
Definition: SampleProf.cpp:432
LLVM_ABI void dump(raw_ostream &OS=dbgs()) const
Definition: SampleProf.cpp:448
LLVM_ABI std::error_code read(const uint8_t *Data, uint64_t ListSize)
Definition: SampleProf.cpp:359
LLVM_ABI void trimAndMergeColdContextProfiles(uint64_t ColdCountThreshold, bool TrimColdContext, bool MergeColdContext, uint32_t ColdContextFrameLength, bool TrimBaseProfileOnly)
Definition: SampleProf.cpp:375
uint64_t getHashCode() const
Definition: SampleProf.h:651
FunctionId getFunction() const
Definition: SampleProf.h:629
This class provides operator overloads to the map container using MD5 as the key type,...
Definition: SampleProf.h:1325
mapped_type & create(const SampleContext &Ctx)
Definition: SampleProf.h:1329
size_t erase(const SampleContext &Ctx)
Definition: SampleProf.h:1346
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...
LLVM_ABI std::optional< StringRef > lookUpNameInProfile(StringRef FunctionName)
Return the equivalent name in the profile for FunctionName if it exists.
Representation of a single sample record.
Definition: SampleProf.h:331
LLVM_ABI std::error_code serialize(raw_ostream &OS, const MapVector< FunctionId, uint32_t > &NameTable) const
Serialize the sample record to the output stream using ULEB128 encoding.
Definition: SampleProf.cpp:132
LLVM_ABI void dump() const
Definition: SampleProf.cpp:172
bool hasCalls() const
Return true if this sample record contains function calls.
Definition: SampleProf.h:396
LLVM_ABI sampleprof_error merge(const SampleRecord &Other, uint64_t Weight=1)
Merge the samples in Other into this record.
Definition: SampleProf.cpp:122
const CallTargetMap & getCallTargets() const
Definition: SampleProf.h:399
uint64_t getSamples() const
Definition: SampleProf.h:398
sampleprof_error addSamples(uint64_t S, uint64_t Weight=1)
Increment the number of samples for this record by S.
Definition: SampleProf.h:352
const SortedCallTargetSet getSortedCallTargets() const
Definition: SampleProf.h:400
LLVM_ABI void print(raw_ostream &OS, unsigned Indent) const
Print the sample record to the stream OS indented by Indent.
Definition: SampleProf.cpp:161
sampleprof_error addCalledTarget(FunctionId F, uint64_t S, uint64_t Weight=1)
Add called function F with samples S.
Definition: SampleProf.h:373
Sort a LocationT->SampleT map by LocationT.
Definition: SampleProf.h:1366
const SamplesWithLocList & get() const
Definition: SampleProf.h:1379
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
Definition: CommandLine.h:444
static FunctionId getRepInFormat(StringRef Name)
Get the proper representation of a string according to whether the current Format uses MD5 to represe...
Definition: SampleProf.h:1311
LLVM_ABI void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
Definition: SampleProf.cpp:231
std::pair< hash_code, const FunctionSamples * > NameFunctionSamples
Definition: SampleProf.h:1356
raw_ostream & operator<<(raw_ostream &OS, const FunctionId &Obj)
Definition: FunctionId.h:159
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void stable_sort(R &&Range)
Definition: STLExtras.h:2077
auto size(R &&Range, std::enable_if_t< std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< decltype(Range.begin())>::iterator_category >::value, void > *=nullptr)
Get the size of a range.
Definition: STLExtras.h:1702
sampleprof_error mergeSampleProfErrors(sampleprof_error &Accumulator, sampleprof_error Result)
Definition: SampleProf.h:72
sampleprof_error
Definition: SampleProf.h:49
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1669
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:207
auto make_first_range(ContainerTy &&c)
Given a container of pairs, return a range over the first elements.
Definition: STLExtras.h:1444
@ Other
Any other memory.
LLVM_ABI const std::error_category & sampleprof_category()
Definition: SampleProf.cpp:103
auto make_second_range(ContainerTy &&c)
Given a container of pairs, return a range over the second elements.
Definition: STLExtras.h:1454
unsigned encodeULEB128(uint64_t Value, raw_ostream &OS, unsigned PadTo=0)
Utility function to encode a ULEB128 value to an output stream.
Definition: LEB128.h:81
static uint32_t extractProbeIndex(uint32_t Value)
Definition: PseudoProbe.h:75
Represents the relative location of an instruction.
Definition: SampleProf.h:283
LLVM_ABI void serialize(raw_ostream &OS) const
Definition: SampleProf.cpp:155
LLVM_ABI void print(raw_ostream &OS) const
Definition: SampleProf.cpp:108
LLVM_ABI void dump() const
Definition: SampleProf.cpp:152
LLVM_ABI FrameNode * getOrCreateChildFrame(const LineLocation &CallSite, FunctionId CalleeName)
Definition: SampleProf.cpp:458
std::map< uint64_t, FrameNode > AllChildFrames
Definition: SampleProf.h:1425