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
51std::error_code
53 const MapVector<FunctionId, uint32_t> &NameTable,
54 raw_ostream &OS) {
55 encodeULEB128(Map.size(), OS);
56 for (const auto &[TypeName, SampleCount] : Map) {
57 if (auto NameIndexIter = NameTable.find(TypeName);
58 NameIndexIter != NameTable.end()) {
59 encodeULEB128(NameIndexIter->second, OS);
60 } else {
61 // If the type is not in the name table, we cannot serialize it.
63 }
64 encodeULEB128(SampleCount, OS);
65 }
67}
68} // namespace sampleprof
69} // namespace llvm
70
71namespace {
72
73// FIXME: This class is only here to support the transition to llvm::Error. It
74// will be removed once this transition is complete. Clients should prefer to
75// deal with the Error value directly, rather than converting to error_code.
76class SampleProfErrorCategoryType : public std::error_category {
77 const char *name() const noexcept override { return "llvm.sampleprof"; }
78
79 std::string message(int IE) const override {
80 sampleprof_error E = static_cast<sampleprof_error>(IE);
81 switch (E) {
82 case sampleprof_error::success:
83 return "Success";
84 case sampleprof_error::bad_magic:
85 return "Invalid sample profile data (bad magic)";
86 case sampleprof_error::unsupported_version:
87 return "Unsupported sample profile format version";
88 case sampleprof_error::too_large:
89 return "Too much profile data";
90 case sampleprof_error::truncated:
91 return "Truncated profile data";
92 case sampleprof_error::malformed:
93 return "Malformed sample profile data";
94 case sampleprof_error::unrecognized_format:
95 return "Unrecognized sample profile encoding format";
96 case sampleprof_error::unsupported_writing_format:
97 return "Profile encoding format unsupported for writing operations";
98 case sampleprof_error::truncated_name_table:
99 return "Truncated function name table";
100 case sampleprof_error::not_implemented:
101 return "Unimplemented feature";
102 case sampleprof_error::counter_overflow:
103 return "Counter overflow";
104 case sampleprof_error::ostream_seek_unsupported:
105 return "Ostream does not support seek";
106 case sampleprof_error::uncompress_failed:
107 return "Uncompress failure";
108 case sampleprof_error::zlib_unavailable:
109 return "Zlib is unavailable";
110 case sampleprof_error::hash_mismatch:
111 return "Function hash mismatch";
112 case sampleprof_error::illegal_line_offset:
113 return "Illegal line offset in sample profile data";
114 }
115 llvm_unreachable("A value of sampleprof_error has no message.");
116 }
117};
118
119} // end anonymous namespace
120
121const std::error_category &llvm::sampleprof_category() {
122 static SampleProfErrorCategoryType ErrorCategory;
123 return ErrorCategory;
124}
125
127 OS << LineOffset;
128 if (Discriminator > 0)
129 OS << "." << Discriminator;
130}
131
133 const LineLocation &Loc) {
134 Loc.print(OS);
135 return OS;
136}
137
138/// Merge the samples in \p Other into this record.
139/// Optionally scale sample counts by \p Weight.
141 uint64_t Weight) {
142 sampleprof_error Result;
143 Result = addSamples(Other.getSamples(), Weight);
144 for (const auto &I : Other.getCallTargets()) {
145 mergeSampleProfErrors(Result, addCalledTarget(I.first, I.second, Weight));
146 }
147 return Result;
148}
149
151 raw_ostream &OS, const MapVector<FunctionId, uint32_t> &NameTable) const {
154 for (const auto &J : getSortedCallTargets()) {
155 FunctionId Callee = J.first;
156 uint64_t CalleeSamples = J.second;
157 if (auto NameIndexIter = NameTable.find(Callee);
158 NameIndexIter != NameTable.end()) {
159 encodeULEB128(NameIndexIter->second, OS);
160 } else {
161 // If the callee is not in the name table, we cannot serialize it.
163 }
164 encodeULEB128(CalleeSamples, OS);
165 }
167}
168
169#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
171#endif
172
177
178/// Print the sample record to the stream \p OS indented by \p Indent.
179void SampleRecord::print(raw_ostream &OS, unsigned Indent) const {
180 OS << NumSamples;
181 if (hasCalls()) {
182 OS << ", calls:";
183 for (const auto &I : getSortedCallTargets())
184 OS << " " << I.first << ":" << I.second;
185 }
186 OS << "\n";
187}
188
189#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
191#endif
192
194 const SampleRecord &Sample) {
195 Sample.print(OS, 0);
196 return OS;
197}
198
200 const TypeCountMap &TypeCountMap) {
201 if (TypeCountMap.empty()) {
202 return;
203 }
204 OS << Loc << ": vtables: ";
205 for (const auto &[Type, Count] : TypeCountMap)
206 OS << Type << ":" << Count << " ";
207 OS << "\n";
208}
209
210/// Print the samples collected for a function on stream \p OS.
211void FunctionSamples::print(raw_ostream &OS, unsigned Indent) const {
212 if (getFunctionHash())
213 OS << "CFG checksum " << getFunctionHash() << "\n";
214
215 OS << TotalSamples << ", " << TotalHeadSamples << ", " << BodySamples.size()
216 << " sampled lines\n";
217
218 OS.indent(Indent);
219 if (!BodySamples.empty()) {
220 OS << "Samples collected in the function's body {\n";
221 SampleSorter<LineLocation, SampleRecord> SortedBodySamples(BodySamples);
222 for (const auto &SI : SortedBodySamples.get()) {
223 OS.indent(Indent + 2);
224 const auto &Loc = SI->first;
225 OS << SI->first << ": " << SI->second;
226 if (const TypeCountMap *TypeCountMap =
228 OS.indent(Indent + 2);
230 }
231 }
232 OS.indent(Indent);
233 OS << "}\n";
234 } else {
235 OS << "No samples collected in the function's body\n";
236 }
237
238 OS.indent(Indent);
239 if (!CallsiteSamples.empty()) {
240 OS << "Samples collected in inlined callsites {\n";
242 CallsiteSamples);
243 for (const auto *Element : SortedCallsiteSamples.get()) {
244 // Element is a pointer to a pair of LineLocation and FunctionSamplesMap.
245 const auto &[Loc, FunctionSampleMap] = *Element;
246 for (const FunctionSamples &FuncSample :
247 llvm::make_second_range(FunctionSampleMap)) {
248 OS.indent(Indent + 2);
249 OS << Loc << ": inlined callee: " << FuncSample.getFunction() << ": ";
250 FuncSample.print(OS, Indent + 4);
251 }
252 auto TypeSamplesIter = VirtualCallsiteTypeCounts.find(Loc);
253 if (TypeSamplesIter != VirtualCallsiteTypeCounts.end()) {
254 OS.indent(Indent + 2);
255 printTypeCountMap(OS, Loc, TypeSamplesIter->second);
256 }
257 }
258 OS.indent(Indent);
259 OS << "}\n";
260 } else {
261 OS << "No inlined callsites in this function\n";
262 }
263}
264
266 const FunctionSamples &FS) {
267 FS.print(OS);
268 return OS;
269}
270
272 const SampleProfileMap &ProfileMap,
273 std::vector<NameFunctionSamples> &SortedProfiles) {
274 for (const auto &I : ProfileMap) {
275 SortedProfiles.push_back(std::make_pair(I.first, &I.second));
276 }
277 llvm::stable_sort(SortedProfiles, [](const NameFunctionSamples &A,
278 const NameFunctionSamples &B) {
279 if (A.second->getTotalSamples() == B.second->getTotalSamples())
280 return A.second->getContext() < B.second->getContext();
281 return A.second->getTotalSamples() > B.second->getTotalSamples();
282 });
283}
284
286 return (DIL->getLine() - DIL->getScope()->getSubprogram()->getLine()) &
287 0xffff;
288}
289
291 bool ProfileIsFS) {
293 // In a pseudo-probe based profile, a callsite is simply represented by the
294 // ID of the probe associated with the call instruction. The probe ID is
295 // encoded in the Discriminator field of the call instruction's debug
296 // metadata.
298 DIL->getDiscriminator()),
299 0);
300 } else {
301 unsigned Discriminator =
302 ProfileIsFS ? DIL->getDiscriminator() : DIL->getBaseDiscriminator();
303 return LineLocation(FunctionSamples::getOffset(DIL), Discriminator);
304 }
305}
306
310 *FuncNameToProfNameMap) const {
311 assert(DIL);
313
314 const DILocation *PrevDIL = DIL;
315 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
316 // Use C++ linkage name if possible.
317 StringRef Name = PrevDIL->getScope()->getSubprogram()->getLinkageName();
318 if (Name.empty())
319 Name = PrevDIL->getScope()->getSubprogram()->getName();
322 Name);
323 PrevDIL = DIL;
324 }
325
326 if (S.size() == 0)
327 return this;
328 const FunctionSamples *FS = this;
329 for (int i = S.size() - 1; i >= 0 && FS != nullptr; i--) {
330 FS = FS->findFunctionSamplesAt(S[i].first, S[i].second, Remapper,
331 FuncNameToProfNameMap);
332 }
333 return FS;
334}
335
337 NameSet.insert(getFunction());
338 for (const auto &BS : BodySamples)
339 NameSet.insert_range(llvm::make_first_range(BS.second.getCallTargets()));
340
341 for (const auto &CS : CallsiteSamples) {
342 for (const auto &NameFS : CS.second) {
343 NameSet.insert(NameFS.first);
344 NameFS.second.findAllNames(NameSet);
345 }
346 }
347}
348
350 const LineLocation &Loc, StringRef CalleeName,
353 *FuncNameToProfNameMap) const {
354 CalleeName = getCanonicalFnName(CalleeName);
355
356 auto I = CallsiteSamples.find(mapIRLocToProfileLoc(Loc));
357 if (I == CallsiteSamples.end())
358 return nullptr;
359 auto FS = I->second.find(getRepInFormat(CalleeName));
360 if (FS != I->second.end())
361 return &FS->second;
362
363 if (FuncNameToProfNameMap && !FuncNameToProfNameMap->empty()) {
364 auto R = FuncNameToProfNameMap->find(FunctionId(CalleeName));
365 if (R != FuncNameToProfNameMap->end()) {
366 CalleeName = R->second.stringRef();
367 auto FS = I->second.find(getRepInFormat(CalleeName));
368 if (FS != I->second.end())
369 return &FS->second;
370 }
371 }
372
373 if (Remapper) {
374 if (auto NameInProfile = Remapper->lookUpNameInProfile(CalleeName)) {
375 auto FS = I->second.find(getRepInFormat(*NameInProfile));
376 if (FS != I->second.end())
377 return &FS->second;
378 }
379 }
380 // If we cannot find exact match of the callee name, return the FS with
381 // the max total count. Only do this when CalleeName is not provided,
382 // i.e., only for indirect calls.
383 if (!CalleeName.empty())
384 return nullptr;
385 uint64_t MaxTotalSamples = 0;
386 const FunctionSamples *R = nullptr;
387 for (const auto &NameFS : I->second)
388 if (NameFS.second.getTotalSamples() >= MaxTotalSamples) {
389 MaxTotalSamples = NameFS.second.getTotalSamples();
390 R = &NameFS.second;
391 }
392 return R;
393}
394
395#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
397#endif
398
399std::error_code ProfileSymbolList::read(const uint8_t *Data,
400 uint64_t ListSize) {
401 const char *ListStart = reinterpret_cast<const char *>(Data);
402 uint64_t Size = 0;
403 uint64_t StrNum = 0;
404 while (Size < ListSize && StrNum < ProfileSymbolListCutOff) {
405 StringRef Str(ListStart + Size);
406 add(Str);
407 Size += Str.size() + 1;
408 StrNum++;
409 }
410 if (Size != ListSize && StrNum != ProfileSymbolListCutOff)
413}
414
416 uint64_t ColdCountThreshold, bool TrimColdContext, bool MergeColdContext,
417 uint32_t ColdContextFrameLength, bool TrimBaseProfileOnly) {
418 if (!TrimColdContext && !MergeColdContext)
419 return;
420
421 // Nothing to merge if sample threshold is zero
422 if (ColdCountThreshold == 0)
423 return;
424
425 // Trimming base profiles only is mainly to honor the preinliner decsion. When
426 // MergeColdContext is true preinliner decsion is not honored anyway so turn
427 // off TrimBaseProfileOnly.
428 if (MergeColdContext)
429 TrimBaseProfileOnly = false;
430
431 // Filter the cold profiles from ProfileMap and move them into a tmp
432 // container
433 std::vector<std::pair<hash_code, const FunctionSamples *>> ColdProfiles;
434 for (const auto &I : ProfileMap) {
435 const SampleContext &Context = I.second.getContext();
436 const FunctionSamples &FunctionProfile = I.second;
437 if (FunctionProfile.getTotalSamples() < ColdCountThreshold &&
438 (!TrimBaseProfileOnly || Context.isBaseContext()))
439 ColdProfiles.emplace_back(I.first, &I.second);
440 }
441
442 // Remove the cold profile from ProfileMap and merge them into
443 // MergedProfileMap by the last K frames of context
444 SampleProfileMap MergedProfileMap;
445 for (const auto &I : ColdProfiles) {
446 if (MergeColdContext) {
447 auto MergedContext = I.second->getContext().getContextFrames();
448 if (ColdContextFrameLength < MergedContext.size())
449 MergedContext = MergedContext.take_back(ColdContextFrameLength);
450 // Need to set MergedProfile's context here otherwise it will be lost.
451 FunctionSamples &MergedProfile = MergedProfileMap.create(MergedContext);
452 MergedProfile.merge(*I.second);
453 }
454 ProfileMap.erase(I.first);
455 }
456
457 // Move the merged profiles into ProfileMap;
458 for (const auto &I : MergedProfileMap) {
459 // Filter the cold merged profile
460 if (TrimColdContext && I.second.getTotalSamples() < ColdCountThreshold &&
461 ProfileMap.find(I.second.getContext()) == ProfileMap.end())
462 continue;
463 // Merge the profile if the original profile exists, otherwise just insert
464 // as a new profile. If inserted as a new profile from MergedProfileMap, it
465 // already has the right context.
466 auto Ret = ProfileMap.emplace(I.second.getContext(), FunctionSamples());
467 FunctionSamples &OrigProfile = Ret.first->second;
468 OrigProfile.merge(I.second);
469 }
470}
471
473 // Sort the symbols before output. If doing compression.
474 // It will make the compression much more effective.
475 std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
476 llvm::sort(SortedList);
477
478 std::string OutputString;
479 for (auto &Sym : SortedList) {
480 OutputString.append(Sym.str());
481 OutputString.append(1, '\0');
482 }
483
484 OS << OutputString;
486}
487
489 OS << "======== Dump profile symbol list ========\n";
490 std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
491 llvm::sort(SortedList);
492
493 for (auto &Sym : SortedList)
494 OS << Sym << "\n";
495}
496
499 FunctionId CalleeName) {
500 uint64_t Hash = FunctionSamples::getCallSiteHash(CalleeName, CallSite);
501 auto It = AllChildFrames.find(Hash);
502 if (It != AllChildFrames.end()) {
503 assert(It->second.FuncName == CalleeName &&
504 "Hash collision for child context node");
505 return &It->second;
506 }
507
508 AllChildFrames[Hash] = FrameNode(CalleeName, nullptr, CallSite);
509 return &AllChildFrames[Hash];
510}
511
513 : ProfileMap(Profiles) {
514 for (auto &FuncSample : Profiles) {
515 FunctionSamples *FSamples = &FuncSample.second;
516 auto *NewNode = getOrCreateContextPath(FSamples->getContext());
517 assert(!NewNode->FuncSamples && "New node cannot have sample profile");
518 NewNode->FuncSamples = FSamples;
519 }
520}
521
523ProfileConverter::getOrCreateContextPath(const SampleContext &Context) {
524 auto Node = &RootFrame;
525 LineLocation CallSiteLoc(0, 0);
526 for (auto &Callsite : Context.getContextFrames()) {
527 Node = Node->getOrCreateChildFrame(CallSiteLoc, Callsite.Func);
528 CallSiteLoc = Callsite.Location;
529 }
530 return Node;
531}
532
534 // Process each child profile. Add each child profile to callsite profile map
535 // of the current node `Node` if `Node` comes with a profile. Otherwise
536 // promote the child profile to a standalone profile.
537 auto *NodeProfile = Node.FuncSamples;
538 for (auto &It : Node.AllChildFrames) {
539 auto &ChildNode = It.second;
540 convertCSProfiles(ChildNode);
541 auto *ChildProfile = ChildNode.FuncSamples;
542 if (!ChildProfile)
543 continue;
544 SampleContext OrigChildContext = ChildProfile->getContext();
545 uint64_t OrigChildContextHash = OrigChildContext.getHashCode();
546 // Reset the child context to be contextless.
547 ChildProfile->getContext().setFunction(OrigChildContext.getFunction());
548 if (NodeProfile) {
549 // Add child profile to the callsite profile map.
550 auto &SamplesMap = NodeProfile->functionSamplesAt(ChildNode.CallSiteLoc);
551 SamplesMap.emplace(OrigChildContext.getFunction(), *ChildProfile);
552 NodeProfile->addTotalSamples(ChildProfile->getTotalSamples());
553 // Remove the corresponding body sample for the callsite and update the
554 // total weight.
555 auto Count = NodeProfile->removeCalledTargetAndBodySample(
556 ChildNode.CallSiteLoc.LineOffset, ChildNode.CallSiteLoc.Discriminator,
557 OrigChildContext.getFunction());
558 NodeProfile->removeTotalSamples(Count);
559 }
560
561 uint64_t NewChildProfileHash = 0;
562 // Separate child profile to be a standalone profile, if the current parent
563 // profile doesn't exist. This is a duplicating operation when the child
564 // profile is already incorporated into the parent which is still useful and
565 // thus done optionally. It is seen that duplicating context profiles into
566 // base profiles improves the code quality for thinlto build by allowing a
567 // profile in the prelink phase for to-be-fully-inlined functions.
568 if (!NodeProfile) {
569 ProfileMap[ChildProfile->getContext()].merge(*ChildProfile);
570 NewChildProfileHash = ChildProfile->getContext().getHashCode();
571 } else if (GenerateMergedBaseProfiles) {
572 ProfileMap[ChildProfile->getContext()].merge(*ChildProfile);
573 NewChildProfileHash = ChildProfile->getContext().getHashCode();
574 auto &SamplesMap = NodeProfile->functionSamplesAt(ChildNode.CallSiteLoc);
575 SamplesMap[ChildProfile->getFunction()].getContext().setAttribute(
577 }
578
579 // Remove the original child profile. Check if MD5 of new child profile
580 // collides with old profile, in this case the [] operator already
581 // overwritten it without the need of erase.
582 if (NewChildProfileHash != OrigChildContextHash)
583 ProfileMap.erase(OrigChildContextHash);
584 }
585}
586
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
aarch64 promote const
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
#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
static void printTypeCountMap(raw_ostream &OS, LineLocation Loc, const TypeCountMap &TypeCountMap)
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"))
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
Implements a dense probed hash-table based set.
Definition DenseSet.h:269
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
reference emplace_back(ArgTypes &&... Args)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:45
std::pair< iterator, bool > insert(const ValueT &V)
Definition DenseSet.h:194
void insert_range(Range &&R)
Definition DenseSet.h:220
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:777
static LLVM_ABI bool ProfileIsPreInlined
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.
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.
static LLVM_ABI bool ProfileIsCS
const LineLocation & mapIRLocToProfileLoc(const LineLocation &IRLoc) const
Definition SampleProf.h:903
FunctionId getFunction() const
Return the function name.
const TypeCountMap * findCallsiteTypeSamplesAt(const LineLocation &Loc) const
Returns the TypeCountMap for inlined callsites at the given Loc.
Definition SampleProf.h:963
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.
static LLVM_ABI bool ProfileIsProbeBased
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
LLVM_ABI void findAllNames(DenseSet< FunctionId > &NameSet) const
static LLVM_ABI unsigned getOffset(const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
static LLVM_ABI bool ProfileIsFS
If this profile uses flow sensitive discriminators.
SampleContext & getContext() const
static LLVM_ABI bool HasUniqSuffix
Whether the profile contains any ".__uniq." suffix in a name.
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Definition SampleProf.h:985
LLVM_ABI void print(raw_ostream &OS=dbgs(), unsigned Indent=0) const
Print the samples collected for a function on stream OS.
sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight=1)
Merge the samples in Other into this one.
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.
static LLVM_ABI bool UseMD5
Whether the profile uses MD5 to represent string.
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)
void add(StringRef Name, bool Copy=false)
copy indicates whether we need to copy the underlying memory for the input Name.
LLVM_ABI std::error_code write(raw_ostream &OS)
LLVM_ABI void dump(raw_ostream &OS=dbgs()) const
LLVM_ABI std::error_code read(const uint8_t *Data, uint64_t ListSize)
LLVM_ABI void trimAndMergeColdContextProfiles(uint64_t ColdCountThreshold, bool TrimColdContext, bool MergeColdContext, uint32_t ColdContextFrameLength, bool TrimBaseProfileOnly)
FunctionId getFunction() const
Definition SampleProf.h:648
This class provides operator overloads to the map container using MD5 as the key type,...
mapped_type & create(const SampleContext &Ctx)
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:350
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.
LLVM_ABI void dump() const
bool hasCalls() const
Return true if this sample record contains function calls.
Definition SampleProf.h:415
LLVM_ABI sampleprof_error merge(const SampleRecord &Other, uint64_t Weight=1)
Merge the samples in Other into this record.
const CallTargetMap & getCallTargets() const
Definition SampleProf.h:418
sampleprof_error addSamples(uint64_t S, uint64_t Weight=1)
Increment the number of samples for this record by S.
Definition SampleProf.h:371
const SortedCallTargetSet getSortedCallTargets() const
Definition SampleProf.h:419
LLVM_ABI void print(raw_ostream &OS, unsigned Indent) const
Print the sample record to the stream OS indented by Indent.
sampleprof_error addCalledTarget(FunctionId F, uint64_t S, uint64_t Weight=1)
Add called function F with samples S.
Definition SampleProf.h:392
Sort a LocationT->SampleT map by LocationT.
const SamplesWithLocList & get() const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
initializer< Ty > init(const Ty &Val)
static FunctionId getRepInFormat(StringRef Name)
Get the proper representation of a string according to whether the current Format uses MD5 to represe...
LLVM_ABI void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
std::pair< hash_code, const FunctionSamples * > NameFunctionSamples
raw_ostream & operator<<(raw_ostream &OS, const FunctionId &Obj)
Definition FunctionId.h:159
std::map< FunctionId, uint64_t > TypeCountMap
Key represents type of a C++ polymorphic class type by its vtable and value represents its counter.
Definition SampleProf.h:330
std::error_code serializeTypeMap(const TypeCountMap &Map, const MapVector< FunctionId, uint32_t > &NameTable, raw_ostream &OS)
Write Map to the output stream.
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
Definition STLExtras.h:2038
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:1657
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:1624
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:1399
FunctionAddr VTableAddr Count
Definition InstrProf.h:139
@ Other
Any other memory.
Definition ModRef.h:68
LLVM_ABI const std::error_category & sampleprof_category()
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:189
auto make_second_range(ContainerTy &&c)
Given a container of pairs, return a range over the second elements.
Definition STLExtras.h:1409
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:288
LLVM_ABI void serialize(raw_ostream &OS) const
LLVM_ABI void print(raw_ostream &OS) const
LLVM_ABI void dump() const
FrameNode(FunctionId FName=FunctionId(), FunctionSamples *FSamples=nullptr, LineLocation CallLoc={0, 0})
LLVM_ABI FrameNode * getOrCreateChildFrame(const LineLocation &CallSite, FunctionId CalleeName)
std::map< uint64_t, FrameNode > AllChildFrames