Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.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
14#include "llvm/ProfileData/SampleProf.h"
15#include "llvm/Config/llvm-config.h"
16#include "llvm/IR/DebugInfoMetadata.h"
17#include "llvm/IR/PseudoProbe.h"
18#include "llvm/ProfileData/SampleProfReader.h"
19#include "llvm/Support/CommandLine.h"
20#include "llvm/Support/Compiler.h"
21#include "llvm/Support/Debug.h"
22#include "llvm/Support/ErrorHandling.h"
23#include "llvm/Support/raw_ostream.h"
24#include <string>
25#include <system_error>
26
27using namespacellvm;
28using namespacesampleprof;
29
30staticcl::opt<uint64_t>ProfileSymbolListCutOff(
31"profile-symbol-list-cutoff",cl::Hidden,cl::init(-1),
32cl::desc("Cutoff value about how many symbols in profile symbol list "
33"will be used. This is very useful for performance debugging"));
34
35staticcl::opt<bool>GenerateMergedBaseProfiles(
36"generate-merged-base-profiles",
37cl::desc("When generating nested context-sensitive profiles, always "
38"generate extra base profile for function with all its context "
39"profiles merged into it."));
40
41namespacellvm {
42namespacesampleprof {
43boolFunctionSamples::ProfileIsProbeBased =false;
44boolFunctionSamples::ProfileIsCS =false;
45boolFunctionSamples::ProfileIsPreInlined =false;
46boolFunctionSamples::UseMD5 =false;
47boolFunctionSamples::HasUniqSuffix =true;
48boolFunctionSamples::ProfileIsFS =false;
49}// namespace sampleprof
50}// namespace llvm
51
52namespace{
53
54// FIXME: This class is only here to support the transition to llvm::Error. It
55// will be removed once this transition is complete. Clients should prefer to
56// deal with the Error value directly, rather than converting to error_code.
57classSampleProfErrorCategoryType :public std::error_category {
58constchar *name()const noexcept override{return"llvm.sampleprof"; }
59
60 std::string message(int IE) const override{
61sampleprof_error E =static_cast<sampleprof_error>(IE);
62switch (E) {
63case sampleprof_error::success:
64return"Success";
65case sampleprof_error::bad_magic:
66return"Invalid sample profile data (bad magic)";
67case sampleprof_error::unsupported_version:
68return"Unsupported sample profile format version";
69case sampleprof_error::too_large:
70return"Too much profile data";
71case sampleprof_error::truncated:
72return"Truncated profile data";
73case sampleprof_error::malformed:
74return"Malformed sample profile data";
75case sampleprof_error::unrecognized_format:
76return"Unrecognized sample profile encoding format";
77case sampleprof_error::unsupported_writing_format:
78return"Profile encoding format unsupported for writing operations";
79case sampleprof_error::truncated_name_table:
80return"Truncated function name table";
81case sampleprof_error::not_implemented:
82return"Unimplemented feature";
83case sampleprof_error::counter_overflow:
84return"Counter overflow";
85case sampleprof_error::ostream_seek_unsupported:
86return"Ostream does not support seek";
87case sampleprof_error::uncompress_failed:
88return"Uncompress failure";
89case sampleprof_error::zlib_unavailable:
90return"Zlib is unavailable";
91case sampleprof_error::hash_mismatch:
92return"Function hash mismatch";
93 }
94llvm_unreachable("A value of sampleprof_error has no message.");
95 }
96};
97
98}// end anonymous namespace
99
100const std::error_category &llvm::sampleprof_category() {
101static SampleProfErrorCategoryType ErrorCategory;
102return ErrorCategory;
103}
104
105voidLineLocation::print(raw_ostream &OS) const{
106OS <<LineOffset;
107if (Discriminator > 0)
108OS <<"." <<Discriminator;
109}
110
111raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,
112constLineLocation &Loc) {
113 Loc.print(OS);
114returnOS;
115}
116
117/// Merge the samples in \p Other into this record.
118/// Optionally scale sample counts by \p Weight.
119sampleprof_errorSampleRecord::merge(constSampleRecord &Other,
120uint64_t Weight) {
121sampleprof_error Result;
122 Result =addSamples(Other.getSamples(), Weight);
123for (constauto &I :Other.getCallTargets()) {
124mergeSampleProfErrors(Result,addCalledTarget(I.first,I.second, Weight));
125 }
126return Result;
127}
128
129#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
130LLVM_DUMP_METHODvoidLineLocation::dump() const{print(dbgs()); }
131#endif
132
133/// Print the sample record to the stream \p OS indented by \p Indent.
134voidSampleRecord::print(raw_ostream &OS,unsigned Indent) const{
135OS << NumSamples;
136if (hasCalls()) {
137OS <<", calls:";
138for (constauto &I :getSortedCallTargets())
139OS <<" " <<I.first <<":" <<I.second;
140 }
141OS <<"\n";
142}
143
144#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
145LLVM_DUMP_METHODvoidSampleRecord::dump() const{print(dbgs(), 0); }
146#endif
147
148raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,
149constSampleRecord &Sample) {
150 Sample.print(OS, 0);
151returnOS;
152}
153
154/// Print the samples collected for a function on stream \p OS.
155voidFunctionSamples::print(raw_ostream &OS,unsigned Indent) const{
156if (getFunctionHash())
157OS <<"CFG checksum " <<getFunctionHash() <<"\n";
158
159OS << TotalSamples <<", " << TotalHeadSamples <<", " << BodySamples.size()
160 <<" sampled lines\n";
161
162OS.indent(Indent);
163if (!BodySamples.empty()) {
164OS <<"Samples collected in the function's body {\n";
165SampleSorter<LineLocation, SampleRecord> SortedBodySamples(BodySamples);
166for (constauto &SI : SortedBodySamples.get()) {
167OS.indent(Indent + 2);
168OS << SI->first <<": " << SI->second;
169 }
170OS.indent(Indent);
171OS <<"}\n";
172 }else {
173OS <<"No samples collected in the function's body\n";
174 }
175
176OS.indent(Indent);
177if (!CallsiteSamples.empty()) {
178OS <<"Samples collected in inlined callsites {\n";
179SampleSorter<LineLocation, FunctionSamplesMap> SortedCallsiteSamples(
180 CallsiteSamples);
181for (constauto &CS : SortedCallsiteSamples.get()) {
182for (constauto &FS : CS->second) {
183OS.indent(Indent + 2);
184OS << CS->first <<": inlined callee: " << FS.second.getFunction()
185 <<": ";
186 FS.second.print(OS, Indent + 4);
187 }
188 }
189OS.indent(Indent);
190OS <<"}\n";
191 }else {
192OS <<"No inlined callsites in this function\n";
193 }
194}
195
196raw_ostream &llvm::sampleprof::operator<<(raw_ostream &OS,
197constFunctionSamples &FS) {
198 FS.print(OS);
199returnOS;
200}
201
202voidsampleprof::sortFuncProfiles(
203constSampleProfileMap &ProfileMap,
204 std::vector<NameFunctionSamples> &SortedProfiles) {
205for (constauto &I : ProfileMap) {
206 SortedProfiles.push_back(std::make_pair(I.first, &I.second));
207 }
208llvm::stable_sort(SortedProfiles, [](constNameFunctionSamples &A,
209constNameFunctionSamples &B) {
210if (A.second->getTotalSamples() ==B.second->getTotalSamples())
211returnA.second->getContext() <B.second->getContext();
212returnA.second->getTotalSamples() >B.second->getTotalSamples();
213 });
214}
215
216unsignedFunctionSamples::getOffset(constDILocation *DIL) {
217return (DIL->getLine() - DIL->getScope()->getSubprogram()->getLine()) &
218 0xffff;
219}
220
221LineLocationFunctionSamples::getCallSiteIdentifier(constDILocation *DIL,
222bool ProfileIsFS) {
223if (FunctionSamples::ProfileIsProbeBased) {
224// In a pseudo-probe based profile, a callsite is simply represented by the
225// ID of the probe associated with the call instruction. The probe ID is
226// encoded in the Discriminator field of the call instruction's debug
227// metadata.
228returnLineLocation(PseudoProbeDwarfDiscriminator::extractProbeIndex(
229 DIL->getDiscriminator()),
230 0);
231 }else {
232unsigned Discriminator =
233ProfileIsFS ? DIL->getDiscriminator() : DIL->getBaseDiscriminator();
234returnLineLocation(FunctionSamples::getOffset(DIL), Discriminator);
235 }
236}
237
238constFunctionSamples *FunctionSamples::findFunctionSamples(
239constDILocation *DIL,SampleProfileReaderItaniumRemapper *Remapper,
240constHashKeyMap<std::unordered_map, FunctionId, FunctionId>
241 *FuncNameToProfNameMap) const{
242assert(DIL);
243SmallVector<std::pair<LineLocation, StringRef>, 10> S;
244
245constDILocation *PrevDIL = DIL;
246for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
247// Use C++ linkage name if possible.
248StringRefName = PrevDIL->getScope()->getSubprogram()->getLinkageName();
249if (Name.empty())
250Name = PrevDIL->getScope()->getSubprogram()->getName();
251 S.emplace_back(FunctionSamples::getCallSiteIdentifier(
252 DIL,FunctionSamples::ProfileIsFS),
253Name);
254 PrevDIL = DIL;
255 }
256
257if (S.size() == 0)
258returnthis;
259constFunctionSamples *FS =this;
260for (int i = S.size() - 1; i >= 0 && FS !=nullptr; i--) {
261 FS = FS->findFunctionSamplesAt(S[i].first, S[i].second, Remapper,
262 FuncNameToProfNameMap);
263 }
264return FS;
265}
266
267voidFunctionSamples::findAllNames(DenseSet<FunctionId> &NameSet) const{
268 NameSet.insert(getFunction());
269for (constauto &BS : BodySamples)
270for (constauto &TS : BS.second.getCallTargets())
271 NameSet.insert(TS.first);
272
273for (constauto &CS : CallsiteSamples) {
274for (constauto &NameFS : CS.second) {
275 NameSet.insert(NameFS.first);
276 NameFS.second.findAllNames(NameSet);
277 }
278 }
279}
280
281constFunctionSamples *FunctionSamples::findFunctionSamplesAt(
282constLineLocation &Loc,StringRef CalleeName,
283SampleProfileReaderItaniumRemapper *Remapper,
284constHashKeyMap<std::unordered_map, FunctionId, FunctionId>
285 *FuncNameToProfNameMap) const{
286 CalleeName =getCanonicalFnName(CalleeName);
287
288autoI = CallsiteSamples.find(mapIRLocToProfileLoc(Loc));
289if (I == CallsiteSamples.end())
290returnnullptr;
291auto FS =I->second.find(getRepInFormat(CalleeName));
292if (FS !=I->second.end())
293return &FS->second;
294
295if (FuncNameToProfNameMap && !FuncNameToProfNameMap->empty()) {
296auto R = FuncNameToProfNameMap->find(FunctionId(CalleeName));
297if (R != FuncNameToProfNameMap->end()) {
298 CalleeName = R->second.stringRef();
299auto FS =I->second.find(getRepInFormat(CalleeName));
300if (FS !=I->second.end())
301return &FS->second;
302 }
303 }
304
305if (Remapper) {
306if (auto NameInProfile = Remapper->lookUpNameInProfile(CalleeName)) {
307auto FS =I->second.find(getRepInFormat(*NameInProfile));
308if (FS !=I->second.end())
309return &FS->second;
310 }
311 }
312// If we cannot find exact match of the callee name, return the FS with
313// the max total count. Only do this when CalleeName is not provided,
314// i.e., only for indirect calls.
315if (!CalleeName.empty())
316returnnullptr;
317uint64_t MaxTotalSamples = 0;
318constFunctionSamples *R =nullptr;
319for (constauto &NameFS :I->second)
320if (NameFS.second.getTotalSamples() >= MaxTotalSamples) {
321 MaxTotalSamples = NameFS.second.getTotalSamples();
322 R = &NameFS.second;
323 }
324return R;
325}
326
327#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
328LLVM_DUMP_METHODvoidFunctionSamples::dump() const{print(dbgs(), 0); }
329#endif
330
331std::error_codeProfileSymbolList::read(constuint8_t *Data,
332uint64_t ListSize) {
333constchar *ListStart =reinterpret_cast<constchar *>(Data);
334uint64_tSize = 0;
335uint64_t StrNum = 0;
336while (Size < ListSize && StrNum <ProfileSymbolListCutOff) {
337StringRef Str(ListStart +Size);
338add(Str);
339Size += Str.size() + 1;
340 StrNum++;
341 }
342if (Size != ListSize && StrNum !=ProfileSymbolListCutOff)
343returnsampleprof_error::malformed;
344returnsampleprof_error::success;
345}
346
347voidSampleContextTrimmer::trimAndMergeColdContextProfiles(
348uint64_tColdCountThreshold,bool TrimColdContext,bool MergeColdContext,
349uint32_t ColdContextFrameLength,bool TrimBaseProfileOnly) {
350if (!TrimColdContext && !MergeColdContext)
351return;
352
353// Nothing to merge if sample threshold is zero
354if (ColdCountThreshold == 0)
355return;
356
357// Trimming base profiles only is mainly to honor the preinliner decsion. When
358// MergeColdContext is true preinliner decsion is not honored anyway so turn
359// off TrimBaseProfileOnly.
360if (MergeColdContext)
361 TrimBaseProfileOnly =false;
362
363// Filter the cold profiles from ProfileMap and move them into a tmp
364// container
365 std::vector<std::pair<hash_code, const FunctionSamples *>> ColdProfiles;
366for (constauto &I : ProfileMap) {
367constSampleContext &Context =I.second.getContext();
368constFunctionSamples &FunctionProfile =I.second;
369if (FunctionProfile.getTotalSamples() <ColdCountThreshold &&
370 (!TrimBaseProfileOnly || Context.isBaseContext()))
371 ColdProfiles.emplace_back(I.first, &I.second);
372 }
373
374// Remove the cold profile from ProfileMap and merge them into
375// MergedProfileMap by the last K frames of context
376SampleProfileMap MergedProfileMap;
377for (constauto &I : ColdProfiles) {
378if (MergeColdContext) {
379autoMergedContext =I.second->getContext().getContextFrames();
380if (ColdContextFrameLength <MergedContext.size())
381MergedContext =MergedContext.take_back(ColdContextFrameLength);
382// Need to set MergedProfile's context here otherwise it will be lost.
383FunctionSamples &MergedProfile = MergedProfileMap.create(MergedContext);
384 MergedProfile.merge(*I.second);
385 }
386 ProfileMap.erase(I.first);
387 }
388
389// Move the merged profiles into ProfileMap;
390for (constauto &I : MergedProfileMap) {
391// Filter the cold merged profile
392if (TrimColdContext &&I.second.getTotalSamples() <ColdCountThreshold &&
393 ProfileMap.find(I.second.getContext()) == ProfileMap.end())
394continue;
395// Merge the profile if the original profile exists, otherwise just insert
396// as a new profile. If inserted as a new profile from MergedProfileMap, it
397// already has the right context.
398auto Ret = ProfileMap.emplace(I.second.getContext(),FunctionSamples());
399FunctionSamples &OrigProfile = Ret.first->second;
400 OrigProfile.merge(I.second);
401 }
402}
403
404std::error_codeProfileSymbolList::write(raw_ostream &OS) {
405// Sort the symbols before output. If doing compression.
406// It will make the compression much more effective.
407 std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
408llvm::sort(SortedList);
409
410 std::string OutputString;
411for (auto &Sym : SortedList) {
412 OutputString.append(Sym.str());
413 OutputString.append(1,'\0');
414 }
415
416OS << OutputString;
417returnsampleprof_error::success;
418}
419
420voidProfileSymbolList::dump(raw_ostream &OS) const{
421OS <<"======== Dump profile symbol list ========\n";
422 std::vector<StringRef> SortedList(Syms.begin(), Syms.end());
423llvm::sort(SortedList);
424
425for (auto &Sym : SortedList)
426OS <<Sym <<"\n";
427}
428
429ProfileConverter::FrameNode *
430ProfileConverter::FrameNode::getOrCreateChildFrame(constLineLocation &CallSite,
431FunctionId CalleeName) {
432uint64_t Hash =FunctionSamples::getCallSiteHash(CalleeName, CallSite);
433auto It =AllChildFrames.find(Hash);
434if (It !=AllChildFrames.end()) {
435assert(It->second.FuncName == CalleeName &&
436"Hash collision for child context node");
437return &It->second;
438 }
439
440AllChildFrames[Hash] =FrameNode(CalleeName,nullptr, CallSite);
441return &AllChildFrames[Hash];
442}
443
444ProfileConverter::ProfileConverter(SampleProfileMap &Profiles)
445 : ProfileMap(Profiles) {
446for (auto &FuncSample : Profiles) {
447FunctionSamples *FSamples = &FuncSample.second;
448auto *NewNode = getOrCreateContextPath(FSamples->getContext());
449assert(!NewNode->FuncSamples &&"New node cannot have sample profile");
450 NewNode->FuncSamples = FSamples;
451 }
452}
453
454ProfileConverter::FrameNode *
455ProfileConverter::getOrCreateContextPath(constSampleContext &Context) {
456auto Node = &RootFrame;
457LineLocation CallSiteLoc(0, 0);
458for (auto &Callsite : Context.getContextFrames()) {
459 Node = Node->getOrCreateChildFrame(CallSiteLoc, Callsite.Func);
460 CallSiteLoc = Callsite.Location;
461 }
462return Node;
463}
464
465voidProfileConverter::convertCSProfiles(ProfileConverter::FrameNode &Node) {
466// Process each child profile. Add each child profile to callsite profile map
467// of the current node `Node` if `Node` comes with a profile. Otherwise
468// promote the child profile to a standalone profile.
469auto *NodeProfile =Node.FuncSamples;
470for (auto &It :Node.AllChildFrames) {
471auto &ChildNode = It.second;
472convertCSProfiles(ChildNode);
473auto *ChildProfile = ChildNode.FuncSamples;
474if (!ChildProfile)
475continue;
476SampleContext OrigChildContext = ChildProfile->getContext();
477uint64_t OrigChildContextHash = OrigChildContext.getHashCode();
478// Reset the child context to be contextless.
479 ChildProfile->getContext().setFunction(OrigChildContext.getFunction());
480if (NodeProfile) {
481// Add child profile to the callsite profile map.
482auto &SamplesMap = NodeProfile->functionSamplesAt(ChildNode.CallSiteLoc);
483 SamplesMap.emplace(OrigChildContext.getFunction(), *ChildProfile);
484 NodeProfile->addTotalSamples(ChildProfile->getTotalSamples());
485// Remove the corresponding body sample for the callsite and update the
486// total weight.
487auto Count = NodeProfile->removeCalledTargetAndBodySample(
488 ChildNode.CallSiteLoc.LineOffset, ChildNode.CallSiteLoc.Discriminator,
489 OrigChildContext.getFunction());
490 NodeProfile->removeTotalSamples(Count);
491 }
492
493uint64_t NewChildProfileHash = 0;
494// Separate child profile to be a standalone profile, if the current parent
495// profile doesn't exist. This is a duplicating operation when the child
496// profile is already incorporated into the parent which is still useful and
497// thus done optionally. It is seen that duplicating context profiles into
498// base profiles improves the code quality for thinlto build by allowing a
499// profile in the prelink phase for to-be-fully-inlined functions.
500if (!NodeProfile) {
501 ProfileMap[ChildProfile->getContext()].merge(*ChildProfile);
502 NewChildProfileHash = ChildProfile->getContext().getHashCode();
503 }elseif (GenerateMergedBaseProfiles) {
504 ProfileMap[ChildProfile->getContext()].merge(*ChildProfile);
505 NewChildProfileHash = ChildProfile->getContext().getHashCode();
506auto &SamplesMap = NodeProfile->functionSamplesAt(ChildNode.CallSiteLoc);
507 SamplesMap[ChildProfile->getFunction()].getContext().setAttribute(
508ContextDuplicatedIntoBase);
509 }
510
511// Remove the original child profile. Check if MD5 of new child profile
512// collides with old profile, in this case the [] operator already
513// overwritten it without the need of erase.
514if (NewChildProfileHash != OrigChildContextHash)
515 ProfileMap.erase(OrigChildContextHash);
516 }
517}
518
519voidProfileConverter::convertCSProfiles() {convertCSProfiles(RootFrame); }
const
aarch64 promote const
Definition:AArch64PromoteConstant.cpp:230
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
CommandLine.h
Compiler.h
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:622
DebugInfoMetadata.h
Debug.h
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Size
uint64_t Size
Definition:ELFObjHandler.cpp:81
Sym
Symbol * Sym
Definition:ELF_riscv.cpp:479
I
#define I(x, y, z)
Definition:MD5.cpp:58
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)
PseudoProbe.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
name
static const char * name
Definition:SMEABIPass.cpp:46
SampleProfReader.h
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
GenerateMergedBaseProfiles
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."))
ProfileSymbolListCutOff
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"))
SampleProf.h
Node
Definition:ItaniumDemangle.h:163
llvm::DILocation
Debug location.
Definition:DebugInfoMetadata.h:1988
llvm::DILocation::getBaseDiscriminator
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
Definition:DebugInfoMetadata.h:2406
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition:DenseSet.h:278
llvm::SmallVectorBase::size
size_t size() const
Definition:SmallVector.h:78
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition:SmallVector.h:937
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition:SmallVector.h:1196
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition:StringRef.h:51
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::cl::opt
Definition:CommandLine.h:1423
llvm::detail::DenseSetImpl::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition:DenseSet.h:213
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition:raw_ostream.h:52
llvm::raw_ostream::indent
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
Definition:raw_ostream.cpp:495
llvm::sampleprof::FunctionId
This class represents a function that is read from a sample profile.
Definition:FunctionId.h:36
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition:SampleProf.h:745
llvm::sampleprof::FunctionSamples::ProfileIsPreInlined
static bool ProfileIsPreInlined
Definition:SampleProf.h:1190
llvm::sampleprof::FunctionSamples::findFunctionSamplesAt
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:281
llvm::sampleprof::FunctionSamples::getCallSiteHash
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:1163
llvm::sampleprof::FunctionSamples::ProfileIsCS
static bool ProfileIsCS
Definition:SampleProf.h:1188
llvm::sampleprof::FunctionSamples::mapIRLocToProfileLoc
const LineLocation & mapIRLocToProfileLoc(const LineLocation &IRLoc) const
Definition:SampleProf.h:860
llvm::sampleprof::FunctionSamples::getFunction
FunctionId getFunction() const
Return the function name.
Definition:SampleProf.h:1074
llvm::sampleprof::FunctionSamples::getFunctionHash
uint64_t getFunctionHash() const
Definition:SampleProf.h:1081
llvm::sampleprof::FunctionSamples::findFunctionSamples
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:238
llvm::sampleprof::FunctionSamples::ProfileIsProbeBased
static bool ProfileIsProbeBased
Definition:SampleProf.h:1186
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:1090
llvm::sampleprof::FunctionSamples::findAllNames
void findAllNames(DenseSet< FunctionId > &NameSet) const
Definition:SampleProf.cpp:267
llvm::sampleprof::FunctionSamples::getOffset
static unsigned getOffset(const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
Definition:SampleProf.cpp:216
llvm::sampleprof::FunctionSamples::ProfileIsFS
static bool ProfileIsFS
If this profile uses flow sensitive discriminators.
Definition:SampleProf.h:1203
llvm::sampleprof::FunctionSamples::getContext
SampleContext & getContext() const
Definition:SampleProf.h:1192
llvm::sampleprof::FunctionSamples::HasUniqSuffix
static bool HasUniqSuffix
Whether the profile contains any ".__uniq." suffix in a name.
Definition:SampleProf.h:1200
llvm::sampleprof::FunctionSamples::getTotalSamples
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
Definition:SampleProf.h:934
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:155
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:998
llvm::sampleprof::FunctionSamples::dump
void dump() const
Definition:SampleProf.cpp:328
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:221
llvm::sampleprof::FunctionSamples::UseMD5
static bool UseMD5
Whether the profile uses MD5 to represent string.
Definition:SampleProf.h:1197
llvm::sampleprof::HashKeyMap
This class is a wrapper to associative container MapT<KeyT, ValueT> using the hash value of the origi...
Definition:HashKeyMap.h:53
llvm::sampleprof::HashKeyMap::find
iterator find(const original_key_type &Key)
Definition:HashKeyMap.h:86
llvm::sampleprof::ProfileConverter::ProfileConverter
ProfileConverter(SampleProfileMap &Profiles)
Definition:SampleProf.cpp:444
llvm::sampleprof::ProfileConverter::convertCSProfiles
void convertCSProfiles()
Definition:SampleProf.cpp:519
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:1517
llvm::sampleprof::ProfileSymbolList::write
std::error_code write(raw_ostream &OS)
Definition:SampleProf.cpp:404
llvm::sampleprof::ProfileSymbolList::dump
void dump(raw_ostream &OS=dbgs()) const
Definition:SampleProf.cpp:420
llvm::sampleprof::ProfileSymbolList::read
std::error_code read(const uint8_t *Data, uint64_t ListSize)
Definition:SampleProf.cpp:331
llvm::sampleprof::SampleContextTrimmer::trimAndMergeColdContextProfiles
void trimAndMergeColdContextProfiles(uint64_t ColdCountThreshold, bool TrimColdContext, bool MergeColdContext, uint32_t ColdContextFrameLength, bool TrimBaseProfileOnly)
Definition:SampleProf.cpp:347
llvm::sampleprof::SampleContext
Definition:SampleProf.h:523
llvm::sampleprof::SampleContext::getContextFrames
SampleContextFrames getContextFrames() const
Definition:SampleProf.h:618
llvm::sampleprof::SampleContext::isBaseContext
bool isBaseContext() const
Definition:SampleProf.h:616
llvm::sampleprof::SampleContext::getHashCode
uint64_t getHashCode() const
Definition:SampleProf.h:639
llvm::sampleprof::SampleContext::getFunction
FunctionId getFunction() const
Definition:SampleProf.h:617
llvm::sampleprof::SampleProfileMap
This class provides operator overloads to the map container using MD5 as the key type,...
Definition:SampleProf.h:1313
llvm::sampleprof::SampleProfileMap::create
mapped_type & create(const SampleContext &Ctx)
Definition:SampleProf.h:1317
llvm::sampleprof::SampleProfileMap::erase
size_t erase(const SampleContext &Ctx)
Definition:SampleProf.h:1334
llvm::sampleprof::SampleProfileReaderItaniumRemapper
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...
Definition:SampleProfReader.h:265
llvm::sampleprof::SampleProfileReaderItaniumRemapper::lookUpNameInProfile
std::optional< StringRef > lookUpNameInProfile(StringRef FunctionName)
Return the equivalent name in the profile for FunctionName if it exists.
Definition:SampleProfReader.cpp:1870
llvm::sampleprof::SampleRecord
Representation of a single sample record.
Definition:SampleProf.h:325
llvm::sampleprof::SampleRecord::dump
void dump() const
Definition:SampleProf.cpp:145
llvm::sampleprof::SampleRecord::hasCalls
bool hasCalls() const
Return true if this sample record contains function calls.
Definition:SampleProf.h:390
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:119
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:346
llvm::sampleprof::SampleRecord::getSortedCallTargets
const SortedCallTargetSet getSortedCallTargets() const
Definition:SampleProf.h:394
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:134
llvm::sampleprof::SampleRecord::addCalledTarget
sampleprof_error addCalledTarget(FunctionId F, uint64_t S, uint64_t Weight=1)
Add called function F with samples S.
Definition:SampleProf.h:367
llvm::sampleprof::SampleSorter
Sort a LocationT->SampleT map by LocationT.
Definition:SampleProf.h:1353
llvm::sampleprof::SampleSorter::get
const SamplesWithLocList & get() const
Definition:SampleProf.h:1366
uint32_t
uint64_t
uint8_t
ErrorHandling.h
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
llvm::ARM_PROC::IE
@ IE
Definition:ARMBaseInfo.h:27
llvm::cl::Hidden
@ Hidden
Definition:CommandLine.h:137
llvm::cl::init
initializer< Ty > init(const Ty &Val)
Definition:CommandLine.h:443
llvm::sampleprof::getRepInFormat
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:1299
llvm::sampleprof::sortFuncProfiles
void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
Definition:SampleProf.cpp:202
llvm::sampleprof::NameFunctionSamples
std::pair< hash_code, const FunctionSamples * > NameFunctionSamples
Definition:SampleProf.h:1344
llvm::sampleprof::MergedContext
@ MergedContext
Definition:SampleProf.h:452
llvm::sampleprof::ContextDuplicatedIntoBase
@ ContextDuplicatedIntoBase
Definition:SampleProf.h:460
llvm::sampleprof::operator<<
raw_ostream & operator<<(raw_ostream &OS, const FunctionId &Obj)
Definition:FunctionId.h:159
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition:AddressRanges.h:18
llvm::stable_sort
void stable_sort(R &&Range)
Definition:STLExtras.h:2037
llvm::mergeSampleProfErrors
sampleprof_error mergeSampleProfErrors(sampleprof_error &Accumulator, sampleprof_error Result)
Definition:SampleProf.h:69
llvm::sampleprof_error
sampleprof_error
Definition:SampleProf.h:47
llvm::sampleprof_error::success
@ success
llvm::sampleprof_error::malformed
@ malformed
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition:STLExtras.h:1664
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::IRMemLocation::Other
@ Other
Any other memory.
llvm::sampleprof_category
const std::error_category & sampleprof_category()
Definition:SampleProf.cpp:100
llvm::Data
@ Data
Definition:SIMachineScheduler.h:55
raw_ostream.h
llvm::PseudoProbeDwarfDiscriminator::extractProbeIndex
static uint32_t extractProbeIndex(uint32_t Value)
Definition:PseudoProbe.h:74
llvm::cl::desc
Definition:CommandLine.h:409
llvm::sampleprof::LineLocation
Represents the relative location of an instruction.
Definition:SampleProf.h:280
llvm::sampleprof::LineLocation::print
void print(raw_ostream &OS) const
Definition:SampleProf.cpp:105
llvm::sampleprof::LineLocation::LineOffset
uint32_t LineOffset
Definition:SampleProf.h:303
llvm::sampleprof::LineLocation::dump
void dump() const
Definition:SampleProf.cpp:130
llvm::sampleprof::LineLocation::Discriminator
uint32_t Discriminator
Definition:SampleProf.h:304
llvm::sampleprof::ProfileConverter::FrameNode
Definition:SampleProf.h:1405
llvm::sampleprof::ProfileConverter::FrameNode::getOrCreateChildFrame
FrameNode * getOrCreateChildFrame(const LineLocation &CallSite, FunctionId CalleeName)
Definition:SampleProf.cpp:430
llvm::sampleprof::ProfileConverter::FrameNode::AllChildFrames
std::map< uint64_t, FrameNode > AllChildFrames
Definition:SampleProf.h:1412

Generated on Thu Jul 17 2025 12:36:41 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp