Movatterモバイル変換


[0]ホーム

URL:


LLVM 20.0.0git
SampleProf.h
Go to the documentation of this file.
1//===- SampleProf.h - Sampling profiling format support ---------*- C++ -*-===//
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#ifndef LLVM_PROFILEDATA_SAMPLEPROF_H
15#define LLVM_PROFILEDATA_SAMPLEPROF_H
16
17#include "llvm/ADT/DenseSet.h"
18#include "llvm/ADT/SmallVector.h"
19#include "llvm/ADT/StringExtras.h"
20#include "llvm/ADT/StringRef.h"
21#include "llvm/IR/Function.h"
22#include "llvm/IR/GlobalValue.h"
23#include "llvm/ProfileData/FunctionId.h"
24#include "llvm/Support/Allocator.h"
25#include "llvm/Support/Debug.h"
26#include "llvm/Support/ErrorOr.h"
27#include "llvm/Support/MathExtras.h"
28#include "llvm/ProfileData/HashKeyMap.h"
29#include <algorithm>
30#include <cstdint>
31#include <list>
32#include <map>
33#include <set>
34#include <sstream>
35#include <string>
36#include <system_error>
37#include <unordered_map>
38#include <utility>
39
40namespacellvm {
41
42classDILocation;
43classraw_ostream;
44
45const std::error_category &sampleprof_category();
46
47enum classsampleprof_error {
48success = 0,
49bad_magic,
50unsupported_version,
51too_large,
52truncated,
53malformed,
54unrecognized_format,
55unsupported_writing_format,
56truncated_name_table,
57not_implemented,
58counter_overflow,
59ostream_seek_unsupported,
60uncompress_failed,
61zlib_unavailable,
62hash_mismatch
63};
64
65inline std::error_codemake_error_code(sampleprof_errorE) {
66return std::error_code(static_cast<int>(E),sampleprof_category());
67}
68
69inlinesampleprof_errormergeSampleProfErrors(sampleprof_error &Accumulator,
70sampleprof_error Result) {
71// Prefer first error encountered as later errors may be secondary effects of
72// the initial problem.
73if (Accumulator ==sampleprof_error::success &&
74 Result !=sampleprof_error::success)
75Accumulator = Result;
76returnAccumulator;
77}
78
79}// end namespace llvm
80
81namespacestd {
82
83template <>
84structis_error_code_enum<llvm::sampleprof_error> : std::true_type {};
85
86}// end namespace std
87
88namespacellvm {
89namespacesampleprof {
90
91enumSampleProfileFormat {
92SPF_None = 0,
93SPF_Text = 0x1,
94SPF_Compact_Binary = 0x2,// Deprecated
95SPF_GCC = 0x3,
96SPF_Ext_Binary = 0x4,
97SPF_Binary = 0xff
98};
99
100enumSampleProfileLayout {
101SPL_None = 0,
102SPL_Nest = 0x1,
103SPL_Flat = 0x2,
104};
105
106staticinlineuint64_tSPMagic(SampleProfileFormatFormat =SPF_Binary) {
107returnuint64_t('S') << (64 - 8) |uint64_t('P') << (64 - 16) |
108uint64_t('R') << (64 - 24) |uint64_t('O') << (64 - 32) |
109uint64_t('F') << (64 - 40) |uint64_t('4') << (64 - 48) |
110uint64_t('2') << (64 - 56) |uint64_t(Format);
111}
112
113staticinlineuint64_tSPVersion() {return 103; }
114
115// Section Type used by SampleProfileExtBinaryBaseReader and
116// SampleProfileExtBinaryBaseWriter. Never change the existing
117// value of enum. Only append new ones.
118enumSecType {
119SecInValid = 0,
120SecProfSummary = 1,
121SecNameTable = 2,
122SecProfileSymbolList = 3,
123SecFuncOffsetTable = 4,
124SecFuncMetadata = 5,
125SecCSNameTable = 6,
126// marker for the first type of profile.
127SecFuncProfileFirst = 32,
128SecLBRProfile =SecFuncProfileFirst
129};
130
131staticinline std::stringgetSecName(SecTypeType) {
132switch (static_cast<int>(Type)) {// Avoid -Wcovered-switch-default
133caseSecInValid:
134return"InvalidSection";
135caseSecProfSummary:
136return"ProfileSummarySection";
137caseSecNameTable:
138return"NameTableSection";
139caseSecProfileSymbolList:
140return"ProfileSymbolListSection";
141caseSecFuncOffsetTable:
142return"FuncOffsetTableSection";
143caseSecFuncMetadata:
144return"FunctionMetadata";
145caseSecCSNameTable:
146return"CSNameTableSection";
147caseSecLBRProfile:
148return"LBRProfileSection";
149default:
150return"UnknownSection";
151 }
152}
153
154// Entry type of section header table used by SampleProfileExtBinaryBaseReader
155// and SampleProfileExtBinaryBaseWriter.
156structSecHdrTableEntry {
157SecTypeType;
158uint64_tFlags;
159uint64_tOffset;
160uint64_tSize;
161// The index indicating the location of the current entry in
162// SectionHdrLayout table.
163uint64_tLayoutIndex;
164};
165
166// Flags common for all sections are defined here. In SecHdrTableEntry::Flags,
167// common flags will be saved in the lower 32bits and section specific flags
168// will be saved in the higher 32 bits.
169enum classSecCommonFlags :uint32_t {
170SecFlagInValid = 0,
171SecFlagCompress = (1 << 0),
172// Indicate the section contains only profile without context.
173SecFlagFlat = (1 << 1)
174};
175
176// Section specific flags are defined here.
177// !!!Note: Everytime a new enum class is created here, please add
178// a new check in verifySecFlag.
179enum classSecNameTableFlags :uint32_t {
180SecFlagInValid = 0,
181SecFlagMD5Name = (1 << 0),
182// Store MD5 in fixed length instead of ULEB128 so NameTable can be
183// accessed like an array.
184SecFlagFixedLengthMD5 = (1 << 1),
185// Profile contains ".__uniq." suffix name. Compiler shouldn't strip
186// the suffix when doing profile matching when seeing the flag.
187SecFlagUniqSuffix = (1 << 2)
188};
189enum classSecProfSummaryFlags :uint32_t {
190SecFlagInValid = 0,
191 /// SecFlagPartial means the profile is for common/shared code.
192 /// The common profile is usually merged from profiles collected
193 /// from running other targets.
194SecFlagPartial = (1 << 0),
195 /// SecFlagContext means this is context-sensitive flat profile for
196 /// CSSPGO
197SecFlagFullContext = (1 << 1),
198 /// SecFlagFSDiscriminator means this profile uses flow-sensitive
199 /// discriminators.
200SecFlagFSDiscriminator = (1 << 2),
201 /// SecFlagIsPreInlined means this profile contains ShouldBeInlined
202 /// contexts thus this is CS preinliner computed.
203SecFlagIsPreInlined = (1 << 4),
204};
205
206enum classSecFuncMetadataFlags :uint32_t {
207SecFlagInvalid = 0,
208SecFlagIsProbeBased = (1 << 0),
209SecFlagHasAttribute = (1 << 1),
210};
211
212enum classSecFuncOffsetFlags :uint32_t {
213SecFlagInvalid = 0,
214// Store function offsets in an order of contexts. The order ensures that
215// callee contexts of a given context laid out next to it.
216SecFlagOrdered = (1 << 0),
217};
218
219// Verify section specific flag is used for the correct section.
220template <class SecFlagType>
221staticinlinevoidverifySecFlag(SecTypeType, SecFlagType Flag) {
222// No verification is needed for common flags.
223if (std::is_same<SecCommonFlags, SecFlagType>())
224return;
225
226// Verification starts here for section specific flag.
227bool IsFlagLegal =false;
228switch (Type) {
229caseSecNameTable:
230 IsFlagLegal = std::is_same<SecNameTableFlags, SecFlagType>();
231break;
232caseSecProfSummary:
233 IsFlagLegal = std::is_same<SecProfSummaryFlags, SecFlagType>();
234break;
235caseSecFuncMetadata:
236 IsFlagLegal = std::is_same<SecFuncMetadataFlags, SecFlagType>();
237break;
238default:
239caseSecFuncOffsetTable:
240 IsFlagLegal = std::is_same<SecFuncOffsetFlags, SecFlagType>();
241break;
242 }
243if (!IsFlagLegal)
244llvm_unreachable("Misuse of a flag in an incompatible section");
245}
246
247template <class SecFlagType>
248staticinlinevoidaddSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag) {
249verifySecFlag(Entry.Type, Flag);
250auto FVal =static_cast<uint64_t>(Flag);
251bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
252 Entry.Flags |= IsCommon ? FVal : (FVal << 32);
253}
254
255template <class SecFlagType>
256staticinlinevoidremoveSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag) {
257verifySecFlag(Entry.Type, Flag);
258auto FVal =static_cast<uint64_t>(Flag);
259bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
260 Entry.Flags &= ~(IsCommon ? FVal : (FVal << 32));
261}
262
263template <class SecFlagType>
264staticinlineboolhasSecFlag(constSecHdrTableEntry &Entry, SecFlagType Flag) {
265verifySecFlag(Entry.Type, Flag);
266auto FVal =static_cast<uint64_t>(Flag);
267bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
268return Entry.Flags & (IsCommon ? FVal : (FVal << 32));
269}
270
271/// Represents the relative location of an instruction.
272///
273/// Instruction locations are specified by the line offset from the
274/// beginning of the function (marked by the line where the function
275/// header is) and the discriminator value within that line.
276///
277/// The discriminator value is useful to distinguish instructions
278/// that are on the same line but belong to different basic blocks
279/// (e.g., the two post-increment instructions in "if (p) x++; else y++;").
280structLineLocation {
281LineLocation(uint32_t L,uint32_tD) :LineOffset(L),Discriminator(D) {}
282
283voidprint(raw_ostream &OS)const;
284voiddump()const;
285
286booloperator<(constLineLocation &O) const{
287returnLineOffset < O.LineOffset ||
288 (LineOffset == O.LineOffset &&Discriminator < O.Discriminator);
289 }
290
291booloperator==(constLineLocation &O) const{
292returnLineOffset == O.LineOffset &&Discriminator == O.Discriminator;
293 }
294
295booloperator!=(constLineLocation &O) const{
296returnLineOffset != O.LineOffset ||Discriminator != O.Discriminator;
297 }
298
299uint64_tgetHashCode() const{
300return ((uint64_t)Discriminator << 32) |LineOffset;
301 }
302
303uint32_tLineOffset;
304uint32_tDiscriminator;
305};
306
307structLineLocationHash {
308uint64_toperator()(constLineLocation &Loc) const{
309return Loc.getHashCode();
310 }
311};
312
313raw_ostream &operator<<(raw_ostream &OS,constLineLocation &Loc);
314
315/// Representation of a single sample record.
316///
317/// A sample record is represented by a positive integer value, which
318/// indicates how frequently was the associated line location executed.
319///
320/// Additionally, if the associated location contains a function call,
321/// the record will hold a list of all the possible called targets. For
322/// direct calls, this will be the exact function being invoked. For
323/// indirect calls (function pointers, virtual table dispatch), this
324/// will be a list of one or more functions.
325classSampleRecord {
326public:
327usingCallTarget = std::pair<FunctionId, uint64_t>;
328structCallTargetComparator {
329booloperator()(constCallTarget &LHS,constCallTarget &RHS) const{
330if (LHS.second !=RHS.second)
331returnLHS.second >RHS.second;
332
333returnLHS.first <RHS.first;
334 }
335 };
336
337usingSortedCallTargetSet = std::set<CallTarget, CallTargetComparator>;
338usingCallTargetMap = std::unordered_map<FunctionId, uint64_t>;
339SampleRecord() =default;
340
341 /// Increment the number of samples for this record by \p S.
342 /// Optionally scale sample count \p S by \p Weight.
343 ///
344 /// Sample counts accumulate using saturating arithmetic, to avoid wrapping
345 /// around unsigned integers.
346sampleprof_erroraddSamples(uint64_t S,uint64_t Weight = 1) {
347bool Overflowed;
348 NumSamples =SaturatingMultiplyAdd(S, Weight, NumSamples, &Overflowed);
349return Overflowed ?sampleprof_error::counter_overflow
350 :sampleprof_error::success;
351 }
352
353 /// Decrease the number of samples for this record by \p S. Return the amout
354 /// of samples actually decreased.
355uint64_tremoveSamples(uint64_t S) {
356if (S > NumSamples)
357 S = NumSamples;
358 NumSamples -= S;
359return S;
360 }
361
362 /// Add called function \p F with samples \p S.
363 /// Optionally scale sample count \p S by \p Weight.
364 ///
365 /// Sample counts accumulate using saturating arithmetic, to avoid wrapping
366 /// around unsigned integers.
367sampleprof_erroraddCalledTarget(FunctionIdF,uint64_t S,
368uint64_t Weight = 1) {
369uint64_t &TargetSamples = CallTargets[F];
370bool Overflowed;
371 TargetSamples =
372SaturatingMultiplyAdd(S, Weight, TargetSamples, &Overflowed);
373return Overflowed ?sampleprof_error::counter_overflow
374 :sampleprof_error::success;
375 }
376
377 /// Remove called function from the call target map. Return the target sample
378 /// count of the called function.
379uint64_tremoveCalledTarget(FunctionIdF) {
380uint64_t Count = 0;
381autoI = CallTargets.find(F);
382if (I != CallTargets.end()) {
383 Count =I->second;
384 CallTargets.erase(I);
385 }
386return Count;
387 }
388
389 /// Return true if this sample record contains function calls.
390boolhasCalls() const{return !CallTargets.empty(); }
391
392uint64_tgetSamples() const{return NumSamples; }
393constCallTargetMap &getCallTargets() const{return CallTargets; }
394constSortedCallTargetSetgetSortedCallTargets() const{
395returnsortCallTargets(CallTargets);
396 }
397
398uint64_tgetCallTargetSum() const{
399uint64_t Sum = 0;
400for (constauto &I : CallTargets)
401 Sum +=I.second;
402return Sum;
403 }
404
405 /// Sort call targets in descending order of call frequency.
406staticconstSortedCallTargetSet
407sortCallTargets(constCallTargetMap &Targets) {
408SortedCallTargetSet SortedTargets;
409for (constauto &[Target, Frequency] : Targets) {
410 SortedTargets.emplace(Target, Frequency);
411 }
412return SortedTargets;
413 }
414
415 /// Prorate call targets by a distribution factor.
416staticconstCallTargetMapadjustCallTargets(constCallTargetMap &Targets,
417float DistributionFactor) {
418CallTargetMap AdjustedTargets;
419for (constauto &[Target, Frequency] : Targets) {
420 AdjustedTargets[Target] = Frequency * DistributionFactor;
421 }
422return AdjustedTargets;
423 }
424
425 /// Merge the samples in \p Other into this record.
426 /// Optionally scale sample counts by \p Weight.
427sampleprof_errormerge(constSampleRecord &Other,uint64_t Weight = 1);
428voidprint(raw_ostream &OS,unsigned Indent)const;
429voiddump()const;
430
431booloperator==(constSampleRecord &Other) const{
432return NumSamples ==Other.NumSamples && CallTargets ==Other.CallTargets;
433 }
434
435booloperator!=(constSampleRecord &Other) const{
436return !(*this ==Other);
437 }
438
439private:
440uint64_t NumSamples = 0;
441CallTargetMap CallTargets;
442};
443
444raw_ostream &operator<<(raw_ostream &OS,constSampleRecord &Sample);
445
446// State of context associated with FunctionSamples
447enumContextStateMask {
448UnknownContext = 0x0,// Profile without context
449RawContext = 0x1,// Full context profile from input profile
450SyntheticContext = 0x2,// Synthetic context created for context promotion
451InlinedContext = 0x4,// Profile for context that is inlined into caller
452MergedContext = 0x8// Profile for context merged into base profile
453};
454
455// Attribute of context associated with FunctionSamples
456enumContextAttributeMask {
457ContextNone = 0x0,
458ContextWasInlined = 0x1,// Leaf of context was inlined in previous build
459ContextShouldBeInlined = 0x2,// Leaf of context should be inlined
460ContextDuplicatedIntoBase =
461 0x4,// Leaf of context is duplicated into the base profile
462};
463
464// Represents a context frame with profile function and line location
465structSampleContextFrame {
466FunctionIdFunc;
467LineLocationLocation;
468
469SampleContextFrame() :Location(0, 0) {}
470
471SampleContextFrame(FunctionIdFunc,LineLocationLocation)
472 :Func(Func),Location(Location) {}
473
474booloperator==(constSampleContextFrame &That) const{
475returnLocation == That.Location &&Func == That.Func;
476 }
477
478booloperator!=(constSampleContextFrame &That) const{
479return !(*this == That);
480 }
481
482 std::stringtoString(bool OutputLineLocation) const{
483 std::ostringstream OContextStr;
484 OContextStr <<Func.str();
485if (OutputLineLocation) {
486 OContextStr <<":" <<Location.LineOffset;
487if (Location.Discriminator)
488 OContextStr <<"." <<Location.Discriminator;
489 }
490return OContextStr.str();
491 }
492
493uint64_tgetHashCode() const{
494uint64_t NameHash =Func.getHashCode();
495uint64_t LocId =Location.getHashCode();
496return NameHash + (LocId << 5) + LocId;
497 }
498};
499
500staticinlinehash_codehash_value(constSampleContextFrame &arg) {
501return arg.getHashCode();
502}
503
504usingSampleContextFrameVector =SmallVector<SampleContextFrame, 1>;
505usingSampleContextFrames =ArrayRef<SampleContextFrame>;
506
507structSampleContextFrameHash {
508uint64_toperator()(constSampleContextFrameVector &S) const{
509returnhash_combine_range(S.begin(), S.end());
510 }
511};
512
513// Sample context for FunctionSamples. It consists of the calling context,
514// the function name and context state. Internally sample context is represented
515// using ArrayRef, which is also the input for constructing a `SampleContext`.
516// It can accept and represent both full context string as well as context-less
517// function name.
518// For a CS profile, a full context vector can look like:
519// `main:3 _Z5funcAi:1 _Z8funcLeafi`
520// For a base CS profile without calling context, the context vector should only
521// contain the leaf frame name.
522// For a non-CS profile, the context vector should be empty.
523classSampleContext {
524public:
525SampleContext() : State(UnknownContext), Attributes(ContextNone) {}
526
527SampleContext(StringRefName)
528 : Func(Name), State(UnknownContext), Attributes(ContextNone) {
529assert(!Name.empty() &&"Name is empty");
530 }
531
532SampleContext(FunctionId Func)
533 : Func(Func), State(UnknownContext), Attributes(ContextNone) {}
534
535SampleContext(SampleContextFrames Context,
536ContextStateMask CState =RawContext)
537 : Attributes(ContextNone) {
538assert(!Context.empty() &&"Context is empty");
539setContext(Context, CState);
540 }
541
542// Give a context string, decode and populate internal states like
543// Function name, Calling context and context state. Example of input
544// `ContextStr`: `[main:3 @ _Z5funcAi:1 @ _Z8funcLeafi]`
545SampleContext(StringRef ContextStr,
546 std::list<SampleContextFrameVector> &CSNameTable,
547ContextStateMask CState =RawContext)
548 : Attributes(ContextNone) {
549assert(!ContextStr.empty());
550// Note that `[]` wrapped input indicates a full context string, otherwise
551// it's treated as context-less function name only.
552bool HasContext = ContextStr.starts_with("[");
553if (!HasContext) {
554 State =UnknownContext;
555 Func =FunctionId(ContextStr);
556 }else {
557 CSNameTable.emplace_back();
558SampleContextFrameVector &Context = CSNameTable.back();
559createCtxVectorFromStr(ContextStr, Context);
560setContext(Context, CState);
561 }
562 }
563
564 /// Create a context vector from a given context string and save it in
565 /// `Context`.
566staticvoidcreateCtxVectorFromStr(StringRef ContextStr,
567SampleContextFrameVector &Context) {
568// Remove encapsulating '[' and ']' if any
569 ContextStr = ContextStr.substr(1, ContextStr.size() - 2);
570StringRef ContextRemain = ContextStr;
571StringRef ChildContext;
572FunctionId Callee;
573while (!ContextRemain.empty()) {
574auto ContextSplit = ContextRemain.split(" @ ");
575 ChildContext = ContextSplit.first;
576 ContextRemain = ContextSplit.second;
577LineLocation CallSiteLoc(0, 0);
578decodeContextString(ChildContext, Callee, CallSiteLoc);
579 Context.emplace_back(Callee, CallSiteLoc);
580 }
581 }
582
583// Decode context string for a frame to get function name and location.
584// `ContextStr` is in the form of `FuncName:StartLine.Discriminator`.
585staticvoiddecodeContextString(StringRef ContextStr,
586FunctionId &Func,
587LineLocation &LineLoc) {
588// Get function name
589auto EntrySplit = ContextStr.split(':');
590 Func =FunctionId(EntrySplit.first);
591
592 LineLoc = {0, 0};
593if (!EntrySplit.second.empty()) {
594// Get line offset, use signed int for getAsInteger so string will
595// be parsed as signed.
596int LineOffset = 0;
597auto LocSplit = EntrySplit.second.split('.');
598 LocSplit.first.getAsInteger(10, LineOffset);
599 LineLoc.LineOffset = LineOffset;
600
601// Get discriminator
602if (!LocSplit.second.empty())
603 LocSplit.second.getAsInteger(10, LineLoc.Discriminator);
604 }
605 }
606
607operatorSampleContextFrames() const{return FullContext; }
608boolhasAttribute(ContextAttributeMaskA) {return Attributes & (uint32_t)A; }
609voidsetAttribute(ContextAttributeMaskA) { Attributes |= (uint32_t)A; }
610uint32_tgetAllAttributes() {return Attributes; }
611voidsetAllAttributes(uint32_tA) { Attributes =A; }
612boolhasState(ContextStateMask S) {return State & (uint32_t)S; }
613voidsetState(ContextStateMask S) { State |= (uint32_t)S; }
614voidclearState(ContextStateMask S) { State &= (uint32_t)~S; }
615boolhasContext() const{return State !=UnknownContext; }
616boolisBaseContext() const{return FullContext.size() == 1; }
617FunctionIdgetFunction() const{return Func; }
618SampleContextFramesgetContextFrames() const{return FullContext; }
619
620static std::stringgetContextString(SampleContextFrames Context,
621bool IncludeLeafLineLocation =false) {
622 std::ostringstream OContextStr;
623for (uint32_tI = 0;I < Context.size();I++) {
624if (OContextStr.str().size()) {
625 OContextStr <<" @ ";
626 }
627 OContextStr << Context[I].toString(I != Context.size() - 1 ||
628 IncludeLeafLineLocation);
629 }
630return OContextStr.str();
631 }
632
633 std::stringtoString() const{
634if (!hasContext())
635return Func.str();
636returngetContextString(FullContext,false);
637 }
638
639uint64_tgetHashCode() const{
640if (hasContext())
641returnhash_value(getContextFrames());
642returngetFunction().getHashCode();
643 }
644
645 /// Set the name of the function and clear the current context.
646voidsetFunction(FunctionId NewFunctionID) {
647 Func = NewFunctionID;
648 FullContext =SampleContextFrames();
649 State =UnknownContext;
650 }
651
652voidsetContext(SampleContextFrames Context,
653ContextStateMask CState =RawContext) {
654assert(CState !=UnknownContext);
655 FullContext = Context;
656 Func = Context.back().Func;
657 State = CState;
658 }
659
660booloperator==(constSampleContext &That) const{
661return State == That.State && Func == That.Func &&
662 FullContext == That.FullContext;
663 }
664
665booloperator!=(constSampleContext &That) const{return !(*this == That); }
666
667booloperator<(constSampleContext &That) const{
668if (State != That.State)
669return State < That.State;
670
671if (!hasContext()) {
672return Func < That.Func;
673 }
674
675uint64_tI = 0;
676while (I < std::min(FullContext.size(), That.FullContext.size())) {
677auto &Context1 = FullContext[I];
678auto &Context2 = That.FullContext[I];
679auto V = Context1.Func.compare(Context2.Func);
680if (V)
681return V < 0;
682if (Context1.Location != Context2.Location)
683return Context1.Location < Context2.Location;
684I++;
685 }
686
687return FullContext.size() < That.FullContext.size();
688 }
689
690structHash {
691uint64_toperator()(constSampleContext &Context) const{
692return Context.getHashCode();
693 }
694 };
695
696boolisPrefixOf(constSampleContext &That) const{
697auto ThisContext = FullContext;
698auto ThatContext = That.FullContext;
699if (ThatContext.size() < ThisContext.size())
700returnfalse;
701 ThatContext = ThatContext.take_front(ThisContext.size());
702// Compare Leaf frame first
703if (ThisContext.back().Func != ThatContext.back().Func)
704returnfalse;
705// Compare leading context
706return ThisContext.drop_back() == ThatContext.drop_back();
707 }
708
709private:
710// The function associated with this context. If CS profile, this is the leaf
711// function.
712FunctionId Func;
713// Full context including calling context and leaf function name
714SampleContextFrames FullContext;
715// State of the associated sample profile
716uint32_t State;
717// Attribute of the associated sample profile
718uint32_t Attributes;
719};
720
721staticinlinehash_codehash_value(constSampleContext &Context) {
722return Context.getHashCode();
723}
724
725inlineraw_ostream &operator<<(raw_ostream &OS,constSampleContext &Context) {
726returnOS << Context.toString();
727}
728
729classFunctionSamples;
730classSampleProfileReaderItaniumRemapper;
731
732usingBodySampleMap = std::map<LineLocation, SampleRecord>;
733// NOTE: Using a StringMap here makes parsed profiles consume around 17% more
734// memory, which is *very* significant for large profiles.
735usingFunctionSamplesMap = std::map<FunctionId, FunctionSamples>;
736usingCallsiteSampleMap = std::map<LineLocation, FunctionSamplesMap>;
737usingLocToLocMap =
738 std::unordered_map<LineLocation, LineLocation, LineLocationHash>;
739
740/// Representation of the samples collected for a function.
741///
742/// This data structure contains all the collected samples for the body
743/// of a function. Each sample corresponds to a LineLocation instance
744/// within the body of the function.
745classFunctionSamples {
746public:
747FunctionSamples() =default;
748
749voidprint(raw_ostream &OS =dbgs(),unsigned Indent = 0)const;
750voiddump()const;
751
752sampleprof_erroraddTotalSamples(uint64_t Num,uint64_t Weight = 1) {
753bool Overflowed;
754 TotalSamples =
755SaturatingMultiplyAdd(Num, Weight, TotalSamples, &Overflowed);
756return Overflowed ?sampleprof_error::counter_overflow
757 :sampleprof_error::success;
758 }
759
760voidremoveTotalSamples(uint64_t Num) {
761if (TotalSamples < Num)
762 TotalSamples = 0;
763else
764 TotalSamples -= Num;
765 }
766
767voidsetTotalSamples(uint64_t Num) { TotalSamples = Num; }
768
769voidsetHeadSamples(uint64_t Num) { TotalHeadSamples = Num; }
770
771sampleprof_erroraddHeadSamples(uint64_t Num,uint64_t Weight = 1) {
772bool Overflowed;
773 TotalHeadSamples =
774SaturatingMultiplyAdd(Num, Weight, TotalHeadSamples, &Overflowed);
775return Overflowed ?sampleprof_error::counter_overflow
776 :sampleprof_error::success;
777 }
778
779sampleprof_erroraddBodySamples(uint32_t LineOffset,uint32_t Discriminator,
780uint64_t Num,uint64_t Weight = 1) {
781return BodySamples[LineLocation(LineOffset, Discriminator)].addSamples(
782 Num, Weight);
783 }
784
785sampleprof_erroraddCalledTargetSamples(uint32_t LineOffset,
786uint32_t Discriminator,
787FunctionId Func,
788uint64_t Num,
789uint64_t Weight = 1) {
790return BodySamples[LineLocation(LineOffset, Discriminator)].addCalledTarget(
791 Func, Num, Weight);
792 }
793
794sampleprof_erroraddSampleRecord(LineLocation Location,
795constSampleRecord &SampleRecord,
796uint64_t Weight = 1) {
797return BodySamples[Location].merge(SampleRecord, Weight);
798 }
799
800// Remove a call target and decrease the body sample correspondingly. Return
801// the number of body samples actually decreased.
802uint64_tremoveCalledTargetAndBodySample(uint32_t LineOffset,
803uint32_t Discriminator,
804FunctionId Func) {
805uint64_t Count = 0;
806autoI = BodySamples.find(LineLocation(LineOffset, Discriminator));
807if (I != BodySamples.end()) {
808 Count =I->second.removeCalledTarget(Func);
809 Count =I->second.removeSamples(Count);
810if (!I->second.getSamples())
811 BodySamples.erase(I);
812 }
813return Count;
814 }
815
816// Remove all call site samples for inlinees. This is needed when flattening
817// a nested profile.
818voidremoveAllCallsiteSamples() {
819 CallsiteSamples.clear();
820 }
821
822// Accumulate all call target samples to update the body samples.
823voidupdateCallsiteSamples() {
824for (auto &I : BodySamples) {
825uint64_t TargetSamples =I.second.getCallTargetSum();
826// It's possible that the body sample count can be greater than the call
827// target sum. E.g, if some call targets are external targets, they won't
828// be considered valid call targets, but the body sample count which is
829// from lbr ranges can actually include them.
830if (TargetSamples >I.second.getSamples())
831I.second.addSamples(TargetSamples -I.second.getSamples());
832 }
833 }
834
835// Accumulate all body samples to set total samples.
836voidupdateTotalSamples() {
837setTotalSamples(0);
838for (constauto &I : BodySamples)
839addTotalSamples(I.second.getSamples());
840
841for (auto &I : CallsiteSamples) {
842for (auto &CS :I.second) {
843 CS.second.updateTotalSamples();
844addTotalSamples(CS.second.getTotalSamples());
845 }
846 }
847 }
848
849// Set current context and all callee contexts to be synthetic.
850voidsetContextSynthetic() {
851 Context.setState(SyntheticContext);
852for (auto &I : CallsiteSamples) {
853for (auto &CS :I.second) {
854 CS.second.setContextSynthetic();
855 }
856 }
857 }
858
859// Query the stale profile matching results and remap the location.
860constLineLocation &mapIRLocToProfileLoc(constLineLocation &IRLoc) const{
861// There is no remapping if the profile is not stale or the matching gives
862// the same location.
863if (!IRToProfileLocationMap)
864return IRLoc;
865constauto &ProfileLoc = IRToProfileLocationMap->find(IRLoc);
866if (ProfileLoc != IRToProfileLocationMap->end())
867return ProfileLoc->second;
868return IRLoc;
869 }
870
871 /// Return the number of samples collected at the given location.
872 /// Each location is specified by \p LineOffset and \p Discriminator.
873 /// If the location is not found in profile, return error.
874ErrorOr<uint64_t>findSamplesAt(uint32_t LineOffset,
875uint32_t Discriminator) const{
876constauto &Ret = BodySamples.find(
877mapIRLocToProfileLoc(LineLocation(LineOffset, Discriminator)));
878if (Ret == BodySamples.end())
879return std::error_code();
880return Ret->second.getSamples();
881 }
882
883 /// Returns the call target map collected at a given location.
884 /// Each location is specified by \p LineOffset and \p Discriminator.
885 /// If the location is not found in profile, return error.
886ErrorOr<const SampleRecord::CallTargetMap &>
887findCallTargetMapAt(uint32_t LineOffset,uint32_t Discriminator) const{
888constauto &Ret = BodySamples.find(
889mapIRLocToProfileLoc(LineLocation(LineOffset, Discriminator)));
890if (Ret == BodySamples.end())
891return std::error_code();
892return Ret->second.getCallTargets();
893 }
894
895 /// Returns the call target map collected at a given location specified by \p
896 /// CallSite. If the location is not found in profile, return error.
897ErrorOr<const SampleRecord::CallTargetMap &>
898findCallTargetMapAt(constLineLocation &CallSite) const{
899constauto &Ret = BodySamples.find(mapIRLocToProfileLoc(CallSite));
900if (Ret == BodySamples.end())
901return std::error_code();
902return Ret->second.getCallTargets();
903 }
904
905 /// Return the function samples at the given callsite location.
906FunctionSamplesMap &functionSamplesAt(constLineLocation &Loc) {
907return CallsiteSamples[mapIRLocToProfileLoc(Loc)];
908 }
909
910 /// Returns the FunctionSamplesMap at the given \p Loc.
911constFunctionSamplesMap *
912findFunctionSamplesMapAt(constLineLocation &Loc) const{
913auto Iter = CallsiteSamples.find(mapIRLocToProfileLoc(Loc));
914if (Iter == CallsiteSamples.end())
915returnnullptr;
916return &Iter->second;
917 }
918
919 /// Returns a pointer to FunctionSamples at the given callsite location
920 /// \p Loc with callee \p CalleeName. If no callsite can be found, relax
921 /// the restriction to return the FunctionSamples at callsite location
922 /// \p Loc with the maximum total sample count. If \p Remapper or \p
923 /// FuncNameToProfNameMap is not nullptr, use them to find FunctionSamples
924 /// with equivalent name as \p CalleeName.
925constFunctionSamples *findFunctionSamplesAt(
926constLineLocation &Loc,StringRef CalleeName,
927SampleProfileReaderItaniumRemapper *Remapper,
928constHashKeyMap<std::unordered_map, FunctionId, FunctionId>
929 *FuncNameToProfNameMap =nullptr)const;
930
931boolempty() const{return TotalSamples == 0; }
932
933 /// Return the total number of samples collected inside the function.
934uint64_tgetTotalSamples() const{return TotalSamples; }
935
936 /// For top-level functions, return the total number of branch samples that
937 /// have the function as the branch target (or 0 otherwise). This is the raw
938 /// data fetched from the profile. This should be equivalent to the sample of
939 /// the first instruction of the symbol. But as we directly get this info for
940 /// raw profile without referring to potentially inaccurate debug info, this
941 /// gives more accurate profile data and is preferred for standalone symbols.
942uint64_tgetHeadSamples() const{return TotalHeadSamples; }
943
944 /// Return an estimate of the sample count of the function entry basic block.
945 /// The function can be either a standalone symbol or an inlined function.
946 /// For Context-Sensitive profiles, this will prefer returning the head
947 /// samples (i.e. getHeadSamples()), if non-zero. Otherwise it estimates from
948 /// the function body's samples or callsite samples.
949uint64_tgetHeadSamplesEstimate() const{
950if (FunctionSamples::ProfileIsCS &&getHeadSamples()) {
951// For CS profile, if we already have more accurate head samples
952// counted by branch sample from caller, use them as entry samples.
953returngetHeadSamples();
954 }
955uint64_t Count = 0;
956// Use either BodySamples or CallsiteSamples which ever has the smaller
957// lineno.
958if (!BodySamples.empty() &&
959 (CallsiteSamples.empty() ||
960 BodySamples.begin()->first < CallsiteSamples.begin()->first))
961 Count = BodySamples.begin()->second.getSamples();
962elseif (!CallsiteSamples.empty()) {
963// An indirect callsite may be promoted to several inlined direct calls.
964// We need to get the sum of them.
965for (constauto &FuncSamples : CallsiteSamples.begin()->second)
966 Count += FuncSamples.second.getHeadSamplesEstimate();
967 }
968// Return at least 1 if total sample is not 0.
969return Count ? Count : TotalSamples > 0;
970 }
971
972 /// Return all the samples collected in the body of the function.
973constBodySampleMap &getBodySamples() const{return BodySamples; }
974
975 /// Return all the callsite samples collected in the body of the function.
976constCallsiteSampleMap &getCallsiteSamples() const{
977return CallsiteSamples;
978 }
979
980 /// Return the maximum of sample counts in a function body. When SkipCallSite
981 /// is false, which is the default, the return count includes samples in the
982 /// inlined functions. When SkipCallSite is true, the return count only
983 /// considers the body samples.
984uint64_tgetMaxCountInside(bool SkipCallSite =false) const{
985uint64_t MaxCount = 0;
986for (constauto &L :getBodySamples())
987 MaxCount = std::max(MaxCount, L.second.getSamples());
988if (SkipCallSite)
989return MaxCount;
990for (constauto &C :getCallsiteSamples())
991for (const FunctionSamplesMap::value_type &F :C.second)
992 MaxCount = std::max(MaxCount,F.second.getMaxCountInside());
993return MaxCount;
994 }
995
996 /// Merge the samples in \p Other into this one.
997 /// Optionally scale samples by \p Weight.
998sampleprof_errormerge(constFunctionSamples &Other,uint64_t Weight = 1) {
999sampleprof_error Result =sampleprof_error::success;
1000if (!GUIDToFuncNameMap)
1001GUIDToFuncNameMap =Other.GUIDToFuncNameMap;
1002if (Context.getFunction().empty())
1003 Context =Other.getContext();
1004if (FunctionHash == 0) {
1005// Set the function hash code for the target profile.
1006 FunctionHash =Other.getFunctionHash();
1007 }elseif (FunctionHash !=Other.getFunctionHash()) {
1008// The two profiles coming with different valid hash codes indicates
1009// either:
1010// 1. They are same-named static functions from different compilation
1011// units (without using -unique-internal-linkage-names), or
1012// 2. They are really the same function but from different compilations.
1013// Let's bail out in either case for now, which means one profile is
1014// dropped.
1015returnsampleprof_error::hash_mismatch;
1016 }
1017
1018mergeSampleProfErrors(Result,
1019addTotalSamples(Other.getTotalSamples(), Weight));
1020mergeSampleProfErrors(Result,
1021addHeadSamples(Other.getHeadSamples(), Weight));
1022for (constauto &I :Other.getBodySamples()) {
1023constLineLocation &Loc =I.first;
1024constSampleRecord &Rec =I.second;
1025mergeSampleProfErrors(Result, BodySamples[Loc].merge(Rec, Weight));
1026 }
1027for (constauto &I :Other.getCallsiteSamples()) {
1028constLineLocation &Loc =I.first;
1029FunctionSamplesMap &FSMap =functionSamplesAt(Loc);
1030for (constauto &Rec :I.second)
1031mergeSampleProfErrors(Result,
1032 FSMap[Rec.first].merge(Rec.second, Weight));
1033 }
1034return Result;
1035 }
1036
1037 /// Recursively traverses all children, if the total sample count of the
1038 /// corresponding function is no less than \p Threshold, add its corresponding
1039 /// GUID to \p S. Also traverse the BodySamples to add hot CallTarget's GUID
1040 /// to \p S.
1041voidfindInlinedFunctions(DenseSet<GlobalValue::GUID> &S,
1042constHashKeyMap<std::unordered_map,FunctionId,
1043Function *> &SymbolMap,
1044uint64_t Threshold) const{
1045if (TotalSamples <= Threshold)
1046return;
1047auto IsDeclaration = [](constFunction *F) {
1048return !F ||F->isDeclaration();
1049 };
1050if (IsDeclaration(SymbolMap.lookup(getFunction()))) {
1051// Add to the import list only when it's defined out of module.
1052 S.insert(getGUID());
1053 }
1054// Import hot CallTargets, which may not be available in IR because full
1055// profile annotation cannot be done until backend compilation in ThinLTO.
1056for (constauto &BS : BodySamples)
1057for (constauto &TS : BS.second.getCallTargets())
1058if (TS.second > Threshold) {
1059constFunction *Callee = SymbolMap.lookup(TS.first);
1060if (IsDeclaration(Callee))
1061 S.insert(TS.first.getHashCode());
1062 }
1063for (constauto &CS : CallsiteSamples)
1064for (constauto &NameFS : CS.second)
1065 NameFS.second.findInlinedFunctions(S, SymbolMap, Threshold);
1066 }
1067
1068 /// Set the name of the function.
1069voidsetFunction(FunctionId NewFunctionID) {
1070 Context.setFunction(NewFunctionID);
1071 }
1072
1073 /// Return the function name.
1074FunctionIdgetFunction() const{return Context.getFunction(); }
1075
1076 /// Return the original function name.
1077StringRefgetFuncName() const{returngetFuncName(getFunction()); }
1078
1079voidsetFunctionHash(uint64_t Hash) { FunctionHash = Hash; }
1080
1081uint64_tgetFunctionHash() const{return FunctionHash; }
1082
1083voidsetIRToProfileLocationMap(constLocToLocMap *LTLM) {
1084assert(IRToProfileLocationMap ==nullptr &&"this should be set only once");
1085 IRToProfileLocationMap = LTLM;
1086 }
1087
1088 /// Return the canonical name for a function, taking into account
1089 /// suffix elision policy attributes.
1090staticStringRefgetCanonicalFnName(constFunction &F) {
1091constchar *AttrName ="sample-profile-suffix-elision-policy";
1092auto Attr =F.getFnAttribute(AttrName).getValueAsString();
1093returngetCanonicalFnName(F.getName(), Attr);
1094 }
1095
1096 /// Name suffixes which canonicalization should handle to avoid
1097 /// profile mismatch.
1098staticconstexprconstchar *LLVMSuffix =".llvm.";
1099staticconstexprconstchar *PartSuffix =".part.";
1100staticconstexprconstchar *UniqSuffix =".__uniq.";
1101
1102staticStringRefgetCanonicalFnName(StringRef FnName,
1103StringRef Attr ="selected") {
1104// Note the sequence of the suffixes in the knownSuffixes array matters.
1105// If suffix "A" is appended after the suffix "B", "A" should be in front
1106// of "B" in knownSuffixes.
1107constchar *KnownSuffixes[] = {LLVMSuffix,PartSuffix,UniqSuffix};
1108if (Attr =="" || Attr =="all")
1109return FnName.split('.').first;
1110if (Attr =="selected") {
1111StringRef Cand(FnName);
1112for (constauto &Suf : KnownSuffixes) {
1113StringRef Suffix(Suf);
1114// If the profile contains ".__uniq." suffix, don't strip the
1115// suffix for names in the IR.
1116if (Suffix ==UniqSuffix &&FunctionSamples::HasUniqSuffix)
1117continue;
1118auto It = Cand.rfind(Suffix);
1119if (It ==StringRef::npos)
1120continue;
1121auto Dit = Cand.rfind('.');
1122if (Dit == It + Suffix.size() - 1)
1123 Cand = Cand.substr(0, It);
1124 }
1125return Cand;
1126 }
1127if (Attr =="none")
1128return FnName;
1129assert(false &&"internal error: unknown suffix elision policy");
1130return FnName;
1131 }
1132
1133 /// Translate \p Func into its original name.
1134 /// When profile doesn't use MD5, \p Func needs no translation.
1135 /// When profile uses MD5, \p Func in current FunctionSamples
1136 /// is actually GUID of the original function name. getFuncName will
1137 /// translate \p Func in current FunctionSamples into its original name
1138 /// by looking up in the function map GUIDToFuncNameMap.
1139 /// If the original name doesn't exist in the map, return empty StringRef.
1140StringRefgetFuncName(FunctionId Func) const{
1141if (!UseMD5)
1142return Func.stringRef();
1143
1144assert(GUIDToFuncNameMap &&"GUIDToFuncNameMap needs to be populated first");
1145returnGUIDToFuncNameMap->lookup(Func.getHashCode());
1146 }
1147
1148 /// Returns the line offset to the start line of the subprogram.
1149 /// We assume that a single function will not exceed 65535 LOC.
1150staticunsignedgetOffset(constDILocation *DIL);
1151
1152 /// Returns a unique call site identifier for a given debug location of a call
1153 /// instruction. This is wrapper of two scenarios, the probe-based profile and
1154 /// regular profile, to hide implementation details from the sample loader and
1155 /// the context tracker.
1156staticLineLocationgetCallSiteIdentifier(constDILocation *DIL,
1157boolProfileIsFS =false);
1158
1159 /// Returns a unique hash code for a combination of a callsite location and
1160 /// the callee function name.
1161 /// Guarantee MD5 and non-MD5 representation of the same function results in
1162 /// the same hash.
1163staticuint64_tgetCallSiteHash(FunctionId Callee,
1164constLineLocation &Callsite) {
1165returnSampleContextFrame(Callee, Callsite).getHashCode();
1166 }
1167
1168 /// Get the FunctionSamples of the inline instance where DIL originates
1169 /// from.
1170 ///
1171 /// The FunctionSamples of the instruction (Machine or IR) associated to
1172 /// \p DIL is the inlined instance in which that instruction is coming from.
1173 /// We traverse the inline stack of that instruction, and match it with the
1174 /// tree nodes in the profile.
1175 ///
1176 /// \returns the FunctionSamples pointer to the inlined instance.
1177 /// If \p Remapper or \p FuncNameToProfNameMap is not nullptr, it will be used
1178 /// to find matching FunctionSamples with not exactly the same but equivalent
1179 /// name.
1180constFunctionSamples *findFunctionSamples(
1181constDILocation *DIL,
1182SampleProfileReaderItaniumRemapper *Remapper =nullptr,
1183constHashKeyMap<std::unordered_map, FunctionId, FunctionId>
1184 *FuncNameToProfNameMap =nullptr)const;
1185
1186staticboolProfileIsProbeBased;
1187
1188staticboolProfileIsCS;
1189
1190staticboolProfileIsPreInlined;
1191
1192SampleContext &getContext() const{return Context; }
1193
1194voidsetContext(constSampleContext &FContext) { Context = FContext; }
1195
1196 /// Whether the profile uses MD5 to represent string.
1197staticboolUseMD5;
1198
1199 /// Whether the profile contains any ".__uniq." suffix in a name.
1200staticboolHasUniqSuffix;
1201
1202 /// If this profile uses flow sensitive discriminators.
1203staticboolProfileIsFS;
1204
1205 /// GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for
1206 /// all the function symbols defined or declared in current module.
1207DenseMap<uint64_t, StringRef> *GUIDToFuncNameMap =nullptr;
1208
1209 /// Return the GUID of the context's name. If the context is already using
1210 /// MD5, don't hash it again.
1211uint64_tgetGUID() const{
1212returngetFunction().getHashCode();
1213 }
1214
1215// Find all the names in the current FunctionSamples including names in
1216// all the inline instances and names of call targets.
1217voidfindAllNames(DenseSet<FunctionId> &NameSet)const;
1218
1219booloperator==(constFunctionSamples &Other) const{
1220return (GUIDToFuncNameMap ==Other.GUIDToFuncNameMap ||
1221 (GUIDToFuncNameMap &&Other.GUIDToFuncNameMap &&
1222 *GUIDToFuncNameMap == *Other.GUIDToFuncNameMap)) &&
1223 FunctionHash ==Other.FunctionHash && Context ==Other.Context &&
1224 TotalSamples ==Other.TotalSamples &&
1225 TotalHeadSamples ==Other.TotalHeadSamples &&
1226 BodySamples ==Other.BodySamples &&
1227 CallsiteSamples ==Other.CallsiteSamples;
1228 }
1229
1230booloperator!=(constFunctionSamples &Other) const{
1231return !(*this ==Other);
1232 }
1233
1234private:
1235 /// CFG hash value for the function.
1236uint64_t FunctionHash = 0;
1237
1238 /// Calling context for function profile
1239mutableSampleContext Context;
1240
1241 /// Total number of samples collected inside this function.
1242 ///
1243 /// Samples are cumulative, they include all the samples collected
1244 /// inside this function and all its inlined callees.
1245uint64_t TotalSamples = 0;
1246
1247 /// Total number of samples collected at the head of the function.
1248 /// This is an approximation of the number of calls made to this function
1249 /// at runtime.
1250uint64_t TotalHeadSamples = 0;
1251
1252 /// Map instruction locations to collected samples.
1253 ///
1254 /// Each entry in this map contains the number of samples
1255 /// collected at the corresponding line offset. All line locations
1256 /// are an offset from the start of the function.
1257BodySampleMap BodySamples;
1258
1259 /// Map call sites to collected samples for the called function.
1260 ///
1261 /// Each entry in this map corresponds to all the samples
1262 /// collected for the inlined function call at the given
1263 /// location. For example, given:
1264 ///
1265 /// void foo() {
1266 /// 1 bar();
1267 /// ...
1268 /// 8 baz();
1269 /// }
1270 ///
1271 /// If the bar() and baz() calls were inlined inside foo(), this
1272 /// map will contain two entries. One for all the samples collected
1273 /// in the call to bar() at line offset 1, the other for all the samples
1274 /// collected in the call to baz() at line offset 8.
1275CallsiteSampleMap CallsiteSamples;
1276
1277 /// IR to profile location map generated by stale profile matching.
1278 ///
1279 /// Each entry is a mapping from the location on current build to the matched
1280 /// location in the "stale" profile. For example:
1281 /// Profiled source code:
1282 /// void foo() {
1283 /// 1 bar();
1284 /// }
1285 ///
1286 /// Current source code:
1287 /// void foo() {
1288 /// 1 // Code change
1289 /// 2 bar();
1290 /// }
1291 /// Supposing the stale profile matching algorithm generated the mapping [2 ->
1292 /// 1], the profile query using the location of bar on the IR which is 2 will
1293 /// be remapped to 1 and find the location of bar in the profile.
1294constLocToLocMap *IRToProfileLocationMap =nullptr;
1295};
1296
1297/// Get the proper representation of a string according to whether the
1298/// current Format uses MD5 to represent the string.
1299staticinlineFunctionIdgetRepInFormat(StringRefName) {
1300if (Name.empty() || !FunctionSamples::UseMD5)
1301returnFunctionId(Name);
1302returnFunctionId(Function::getGUID(Name));
1303}
1304
1305raw_ostream &operator<<(raw_ostream &OS,constFunctionSamples &FS);
1306
1307/// This class provides operator overloads to the map container using MD5 as the
1308/// key type, so that existing code can still work in most cases using
1309/// SampleContext as key.
1310/// Note: when populating container, make sure to assign the SampleContext to
1311/// the mapped value immediately because the key no longer holds it.
1312classSampleProfileMap
1313 :publicHashKeyMap<std::unordered_map, SampleContext, FunctionSamples> {
1314public:
1315// Convenience method because this is being used in many places. Set the
1316// FunctionSamples' context if its newly inserted.
1317mapped_type &create(constSampleContext &Ctx) {
1318auto Ret =try_emplace(Ctx,FunctionSamples());
1319if (Ret.second)
1320 Ret.first->second.setContext(Ctx);
1321return Ret.first->second;
1322 }
1323
1324iteratorfind(constSampleContext &Ctx) {
1325returnHashKeyMap<std::unordered_map, SampleContext, FunctionSamples>::find(
1326 Ctx);
1327 }
1328
1329const_iteratorfind(constSampleContext &Ctx) const{
1330returnHashKeyMap<std::unordered_map, SampleContext, FunctionSamples>::find(
1331 Ctx);
1332 }
1333
1334size_terase(constSampleContext &Ctx) {
1335returnHashKeyMap<std::unordered_map, SampleContext, FunctionSamples>::
1336 erase(Ctx);
1337 }
1338
1339size_terase(constkey_type &Key) {return base_type::erase(Key); }
1340
1341iteratorerase(iterator It) {return base_type::erase(It); }
1342};
1343
1344usingNameFunctionSamples = std::pair<hash_code, const FunctionSamples *>;
1345
1346voidsortFuncProfiles(constSampleProfileMap &ProfileMap,
1347 std::vector<NameFunctionSamples> &SortedProfiles);
1348
1349/// Sort a LocationT->SampleT map by LocationT.
1350///
1351/// It produces a sorted list of <LocationT, SampleT> records by ascending
1352/// order of LocationT.
1353template <class LocationT,class SampleT>classSampleSorter {
1354public:
1355usingSamplesWithLoc = std::pair<const LocationT, SampleT>;
1356usingSamplesWithLocList =SmallVector<const SamplesWithLoc *, 20>;
1357
1358SampleSorter(const std::map<LocationT, SampleT> &Samples) {
1359for (constauto &I : Samples)
1360 V.push_back(&I);
1361llvm::stable_sort(V, [](constSamplesWithLoc *A,constSamplesWithLoc *B) {
1362returnA->first <B->first;
1363 });
1364 }
1365
1366constSamplesWithLocList &get() const{return V; }
1367
1368private:
1369SamplesWithLocList V;
1370};
1371
1372/// SampleContextTrimmer impelements helper functions to trim, merge cold
1373/// context profiles. It also supports context profile canonicalization to make
1374/// sure ProfileMap's key is consistent with FunctionSample's name/context.
1375classSampleContextTrimmer {
1376public:
1377SampleContextTrimmer(SampleProfileMap &Profiles) : ProfileMap(Profiles){};
1378// Trim and merge cold context profile when requested. TrimBaseProfileOnly
1379// should only be effective when TrimColdContext is true. On top of
1380// TrimColdContext, TrimBaseProfileOnly can be used to specify to trim all
1381// cold profiles or only cold base profiles. Trimming base profiles only is
1382// mainly to honor the preinliner decsion. Note that when MergeColdContext is
1383// true, preinliner decsion is not honored anyway so TrimBaseProfileOnly will
1384// be ignored.
1385voidtrimAndMergeColdContextProfiles(uint64_tColdCountThreshold,
1386bool TrimColdContext,
1387bool MergeColdContext,
1388uint32_t ColdContextFrameLength,
1389bool TrimBaseProfileOnly);
1390
1391private:
1392SampleProfileMap &ProfileMap;
1393};
1394
1395/// Helper class for profile conversion.
1396///
1397/// It supports full context-sensitive profile to nested profile conversion,
1398/// nested profile to flatten profile conversion, etc.
1399classProfileConverter {
1400public:
1401ProfileConverter(SampleProfileMap &Profiles);
1402// Convert a full context-sensitive flat sample profile into a nested sample
1403// profile.
1404voidconvertCSProfiles();
1405structFrameNode {
1406FrameNode(FunctionId FName =FunctionId(),
1407FunctionSamples *FSamples =nullptr,
1408LineLocation CallLoc = {0, 0})
1409 :FuncName(FName),FuncSamples(FSamples),CallSiteLoc(CallLoc){};
1410
1411// Map line+discriminator location to child frame
1412 std::map<uint64_t, FrameNode>AllChildFrames;
1413// Function name for current frame
1414FunctionIdFuncName;
1415// Function Samples for current frame
1416FunctionSamples *FuncSamples;
1417// Callsite location in parent context
1418LineLocationCallSiteLoc;
1419
1420FrameNode *getOrCreateChildFrame(constLineLocation &CallSite,
1421FunctionId CalleeName);
1422 };
1423
1424staticvoidflattenProfile(SampleProfileMap &ProfileMap,
1425bool ProfileIsCS =false) {
1426SampleProfileMap TmpProfiles;
1427flattenProfile(ProfileMap, TmpProfiles, ProfileIsCS);
1428 ProfileMap = std::move(TmpProfiles);
1429 }
1430
1431staticvoidflattenProfile(constSampleProfileMap &InputProfiles,
1432SampleProfileMap &OutputProfiles,
1433bool ProfileIsCS =false) {
1434if (ProfileIsCS) {
1435for (constauto &I : InputProfiles) {
1436// Retain the profile name and clear the full context for each function
1437// profile.
1438FunctionSamples &FS = OutputProfiles.create(I.second.getFunction());
1439 FS.merge(I.second);
1440 }
1441 }else {
1442for (constauto &I : InputProfiles)
1443 flattenNestedProfile(OutputProfiles,I.second);
1444 }
1445 }
1446
1447private:
1448staticvoid flattenNestedProfile(SampleProfileMap &OutputProfiles,
1449constFunctionSamples &FS) {
1450// To retain the context, checksum, attributes of the original profile, make
1451// a copy of it if no profile is found.
1452SampleContext &Context = FS.getContext();
1453auto Ret = OutputProfiles.try_emplace(Context, FS);
1454FunctionSamples &Profile = Ret.first->second;
1455if (Ret.second) {
1456// Clear nested inlinees' samples for the flattened copy. These inlinees
1457// will have their own top-level entries after flattening.
1458Profile.removeAllCallsiteSamples();
1459// We recompute TotalSamples later, so here set to zero.
1460Profile.setTotalSamples(0);
1461 }else {
1462for (constauto &[LineLocation,SampleRecord] : FS.getBodySamples()) {
1463Profile.addSampleRecord(LineLocation,SampleRecord);
1464 }
1465 }
1466
1467assert(Profile.getCallsiteSamples().empty() &&
1468"There should be no inlinees' profiles after flattening.");
1469
1470// TotalSamples might not be equal to the sum of all samples from
1471// BodySamples and CallsiteSamples. So here we use "TotalSamples =
1472// Original_TotalSamples - All_of_Callsite_TotalSamples +
1473// All_of_Callsite_HeadSamples" to compute the new TotalSamples.
1474uint64_t TotalSamples =FS.getTotalSamples();
1475
1476for (constauto &I :FS.getCallsiteSamples()) {
1477for (constauto &Callee :I.second) {
1478constauto &CalleeProfile =Callee.second;
1479// Add body sample.
1480Profile.addBodySamples(I.first.LineOffset,I.first.Discriminator,
1481 CalleeProfile.getHeadSamplesEstimate());
1482// Add callsite sample.
1483Profile.addCalledTargetSamples(
1484I.first.LineOffset,I.first.Discriminator,
1485 CalleeProfile.getFunction(),
1486 CalleeProfile.getHeadSamplesEstimate());
1487// Update total samples.
1488 TotalSamples = TotalSamples >= CalleeProfile.getTotalSamples()
1489 ? TotalSamples - CalleeProfile.getTotalSamples()
1490 : 0;
1491 TotalSamples += CalleeProfile.getHeadSamplesEstimate();
1492// Recursively convert callee profile.
1493 flattenNestedProfile(OutputProfiles, CalleeProfile);
1494 }
1495 }
1496Profile.addTotalSamples(TotalSamples);
1497
1498Profile.setHeadSamples(Profile.getHeadSamplesEstimate());
1499 }
1500
1501// Nest all children profiles into the profile of Node.
1502voidconvertCSProfiles(FrameNode &Node);
1503 FrameNode *getOrCreateContextPath(const SampleContext &Context);
1504
1505 SampleProfileMap &ProfileMap;
1506 FrameNode RootFrame;
1507};
1508
1509/// ProfileSymbolList records the list of function symbols shown up
1510/// in the binary used to generate the profile. It is useful to
1511/// to discriminate a function being so cold as not to shown up
1512/// in the profile and a function newly added.
1513classProfileSymbolList {
1514public:
1515 /// copy indicates whether we need to copy the underlying memory
1516 /// for the input Name.
1517voidadd(StringRefName,bool Copy =false) {
1518if (!Copy) {
1519 Syms.insert(Name);
1520return;
1521 }
1522 Syms.insert(Name.copy(Allocator));
1523 }
1524
1525boolcontains(StringRefName) {return Syms.count(Name); }
1526
1527voidmerge(constProfileSymbolList &List) {
1528for (autoSym :List.Syms)
1529add(Sym,true);
1530 }
1531
1532unsignedsize() {return Syms.size(); }
1533
1534voidsetToCompress(bool TC) { ToCompress = TC; }
1535booltoCompress() {return ToCompress; }
1536
1537 std::error_coderead(constuint8_t *Data,uint64_t ListSize);
1538 std::error_codewrite(raw_ostream &OS);
1539voiddump(raw_ostream &OS =dbgs())const;
1540
1541private:
1542// Determine whether or not to compress the symbol list when
1543// writing it into profile. The variable is unused when the symbol
1544// list is read from an existing profile.
1545bool ToCompress =false;
1546DenseSet<StringRef> Syms;
1547BumpPtrAllocator Allocator;
1548};
1549
1550}// end namespace sampleprof
1551
1552using namespacesampleprof;
1553// Provide DenseMapInfo for SampleContext.
1554template <>structDenseMapInfo<SampleContext> {
1555staticinlineSampleContextgetEmptyKey() {returnSampleContext(); }
1556
1557staticinlineSampleContextgetTombstoneKey() {
1558returnSampleContext(FunctionId(~1ULL));
1559 }
1560
1561staticunsignedgetHashValue(constSampleContext &Val) {
1562return Val.getHashCode();
1563 }
1564
1565staticboolisEqual(constSampleContext &LHS,constSampleContext &RHS) {
1566returnLHS ==RHS;
1567 }
1568};
1569
1570// Prepend "__uniq" before the hash for tools like profilers to understand
1571// that this symbol is of internal linkage type. The "__uniq" is the
1572// pre-determined prefix that is used to tell tools that this symbol was
1573// created with -funique-internal-linkage-symbols and the tools can strip or
1574// keep the prefix as needed.
1575inline std::stringgetUniqueInternalLinkagePostfix(constStringRef &FName) {
1576llvm::MD5 Md5;
1577 Md5.update(FName);
1578llvm::MD5::MD5Result R;
1579 Md5.final(R);
1580SmallString<32> Str;
1581llvm::MD5::stringifyResult(R, Str);
1582// Convert MD5hash to Decimal. Demangler suffixes can either contain
1583// numbers or characters but not both.
1584llvm::APInt IntHash(128, Str.str(), 16);
1585returntoString(IntHash,/* Radix = */ 10,/* Signed = */false)
1586 .insert(0,FunctionSamples::UniqSuffix);
1587}
1588
1589}// end namespace llvm
1590
1591#endif// LLVM_PROFILEDATA_SAMPLEPROF_H
FMAInstKind::Accumulator
@ Accumulator
Allocator.h
This file defines the BumpPtrAllocator interface.
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
D
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Debug.h
DenseSet.h
This file defines the DenseSet and SmallDenseSet classes.
Name
std::string Name
Definition:ELFObjHandler.cpp:77
Sym
Symbol * Sym
Definition:ELF_riscv.cpp:479
ErrorOr.h
Provides ErrorOr<T> smart pointer.
GlobalValue.h
HashKeyMap.h
Defines HashKeyMap template.
Function.h
F
#define F(x, y, z)
Definition:MD5.cpp:55
I
#define I(x, y, z)
Definition:MD5.cpp:58
Profile
Load MIR Sample Profile
Definition:MIRSampleProfile.cpp:78
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)
MathExtras.h
FunctionId.h
Defines FunctionId class.
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
OS
raw_pwrite_stream & OS
Definition:SampleProfWriter.cpp:51
SmallVector.h
This file defines the SmallVector class.
StringExtras.h
This file contains some functions that are useful when dealing with strings.
StringRef.h
RHS
Value * RHS
Definition:X86PartialReduction.cpp:74
LHS
Value * LHS
Definition:X86PartialReduction.cpp:73
Node
Definition:ItaniumDemangle.h:163
llvm::APInt
Class for arbitrary precision integers.
Definition:APInt.h:78
llvm::ArrayRef< SampleContextFrame >
llvm::ArrayRef::back
const T & back() const
back - Get the last element.
Definition:ArrayRef.h:177
llvm::ArrayRef::take_front
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
Definition:ArrayRef.h:231
llvm::ArrayRef::size
size_t size() const
size - Get the array size.
Definition:ArrayRef.h:168
llvm::ArrayRef::drop_back
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
Definition:ArrayRef.h:213
llvm::ArrayRef::empty
bool empty() const
empty - Check if the array is empty.
Definition:ArrayRef.h:163
llvm::BumpPtrAllocatorImpl
Allocate memory in an ever growing pool, as if by bump-pointer.
Definition:Allocator.h:66
llvm::DILocation
Debug location.
Definition:DebugInfoMetadata.h:1988
llvm::DenseMapBase::lookup
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
Definition:DenseMap.h:194
llvm::DenseMap
Definition:DenseMap.h:727
llvm::DenseSet
Implements a dense probed hash-table based set.
Definition:DenseSet.h:278
llvm::ErrorOr
Represents either an error or a value T.
Definition:ErrorOr.h:56
llvm::Function
Definition:Function.h:63
llvm::GlobalValue::getGUID
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
Definition:GlobalValue.h:596
llvm::MD5
Definition:MD5.h:41
llvm::MD5::update
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
Definition:MD5.cpp:189
llvm::MD5::stringifyResult
static void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
Definition:MD5.cpp:287
llvm::MD5::final
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
Definition:MD5.cpp:234
llvm::SmallString
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition:SmallString.h:26
llvm::SmallVectorImpl::emplace_back
reference emplace_back(ArgTypes &&... Args)
Definition:SmallVector.h:937
llvm::SmallVectorTemplateBase::push_back
void push_back(const T &Elt)
Definition:SmallVector.h:413
llvm::SmallVectorTemplateCommon::end
iterator end()
Definition:SmallVector.h:269
llvm::SmallVectorTemplateCommon::begin
iterator begin()
Definition:SmallVector.h:267
llvm::SmallVectorTemplateCommon::back
reference back()
Definition:SmallVector.h:308
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::split
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition:StringRef.h:700
llvm::StringRef::substr
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
Definition:StringRef.h:571
llvm::StringRef::starts_with
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
Definition:StringRef.h:265
llvm::StringRef::empty
constexpr bool empty() const
empty - Check if the string is empty.
Definition:StringRef.h:147
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition:StringRef.h:150
llvm::StringRef::rfind
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
Definition:StringRef.h:347
llvm::StringRef::npos
static constexpr size_t npos
Definition:StringRef.h:53
llvm::Target
Target - Wrapper for Target specific information.
Definition:TargetRegistry.h:144
llvm::Type
The instances of the Type class are immutable: once they are created, they are never changed.
Definition:Type.h:45
llvm::detail::DenseSetImpl::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition:DenseSet.h:213
llvm::hash_code
An opaque object representing a hash code.
Definition:Hashing.h:75
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::sampleprof::FunctionId
This class represents a function that is read from a sample profile.
Definition:FunctionId.h:36
llvm::sampleprof::FunctionId::getHashCode
uint64_t getHashCode() const
Get hash code of this object.
Definition:FunctionId.h:123
llvm::sampleprof::FunctionId::empty
bool empty() const
Definition:FunctionId.h:129
llvm::sampleprof::FunctionId::str
std::string str() const
Convert to a string, usually for output purpose.
Definition:FunctionId.h:97
llvm::sampleprof::FunctionSamples
Representation of the samples collected for a function.
Definition:SampleProf.h:745
llvm::sampleprof::FunctionSamples::setTotalSamples
void setTotalSamples(uint64_t Num)
Definition:SampleProf.h:767
llvm::sampleprof::FunctionSamples::ProfileIsPreInlined
static bool ProfileIsPreInlined
Definition:SampleProf.h:1190
llvm::sampleprof::FunctionSamples::findInlinedFunctions
void findInlinedFunctions(DenseSet< GlobalValue::GUID > &S, const HashKeyMap< std::unordered_map, FunctionId, Function * > &SymbolMap, uint64_t Threshold) const
Recursively traverses all children, if the total sample count of the corresponding function is no les...
Definition:SampleProf.h:1041
llvm::sampleprof::FunctionSamples::operator!=
bool operator!=(const FunctionSamples &Other) const
Definition:SampleProf.h:1230
llvm::sampleprof::FunctionSamples::updateTotalSamples
void updateTotalSamples()
Definition:SampleProf.h:836
llvm::sampleprof::FunctionSamples::setHeadSamples
void setHeadSamples(uint64_t Num)
Definition:SampleProf.h:769
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::addTotalSamples
sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight=1)
Definition:SampleProf.h:752
llvm::sampleprof::FunctionSamples::UniqSuffix
static constexpr const char * UniqSuffix
Definition:SampleProf.h:1100
llvm::sampleprof::FunctionSamples::updateCallsiteSamples
void updateCallsiteSamples()
Definition:SampleProf.h:823
llvm::sampleprof::FunctionSamples::getCanonicalFnName
static StringRef getCanonicalFnName(StringRef FnName, StringRef Attr="selected")
Definition:SampleProf.h:1102
llvm::sampleprof::FunctionSamples::operator==
bool operator==(const FunctionSamples &Other) const
Definition:SampleProf.h:1219
llvm::sampleprof::FunctionSamples::PartSuffix
static constexpr const char * PartSuffix
Definition:SampleProf.h:1099
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::findFunctionSamplesMapAt
const FunctionSamplesMap * findFunctionSamplesMapAt(const LineLocation &Loc) const
Returns the FunctionSamplesMap at the given Loc.
Definition:SampleProf.h:912
llvm::sampleprof::FunctionSamples::removeAllCallsiteSamples
void removeAllCallsiteSamples()
Definition:SampleProf.h:818
llvm::sampleprof::FunctionSamples::getMaxCountInside
uint64_t getMaxCountInside(bool SkipCallSite=false) const
Return the maximum of sample counts in a function body.
Definition:SampleProf.h:984
llvm::sampleprof::FunctionSamples::removeTotalSamples
void removeTotalSamples(uint64_t Num)
Definition:SampleProf.h:760
llvm::sampleprof::FunctionSamples::getHeadSamples
uint64_t getHeadSamples() const
For top-level functions, return the total number of branch samples that have the function as the bran...
Definition:SampleProf.h:942
llvm::sampleprof::FunctionSamples::setFunction
void setFunction(FunctionId NewFunctionID)
Set the name of the function.
Definition:SampleProf.h:1069
llvm::sampleprof::FunctionSamples::findSamplesAt
ErrorOr< uint64_t > findSamplesAt(uint32_t LineOffset, uint32_t Discriminator) const
Return the number of samples collected at the given location.
Definition:SampleProf.h:874
llvm::sampleprof::FunctionSamples::ProfileIsCS
static bool ProfileIsCS
Definition:SampleProf.h:1188
llvm::sampleprof::FunctionSamples::findCallTargetMapAt
ErrorOr< const SampleRecord::CallTargetMap & > findCallTargetMapAt(const LineLocation &CallSite) const
Returns the call target map collected at a given location specified by CallSite.
Definition:SampleProf.h:898
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::LLVMSuffix
static constexpr const char * LLVMSuffix
Name suffixes which canonicalization should handle to avoid profile mismatch.
Definition:SampleProf.h:1098
llvm::sampleprof::FunctionSamples::getFuncName
StringRef getFuncName(FunctionId Func) const
Translate Func into its original name.
Definition:SampleProf.h:1140
llvm::sampleprof::FunctionSamples::addHeadSamples
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight=1)
Definition:SampleProf.h:771
llvm::sampleprof::FunctionSamples::addSampleRecord
sampleprof_error addSampleRecord(LineLocation Location, const SampleRecord &SampleRecord, uint64_t Weight=1)
Definition:SampleProf.h:794
llvm::sampleprof::FunctionSamples::removeCalledTargetAndBodySample
uint64_t removeCalledTargetAndBodySample(uint32_t LineOffset, uint32_t Discriminator, FunctionId Func)
Definition:SampleProf.h:802
llvm::sampleprof::FunctionSamples::GUIDToFuncNameMap
DenseMap< uint64_t, StringRef > * GUIDToFuncNameMap
GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for all the function symbols define...
Definition:SampleProf.h:1207
llvm::sampleprof::FunctionSamples::addCalledTargetSamples
sampleprof_error addCalledTargetSamples(uint32_t LineOffset, uint32_t Discriminator, FunctionId Func, uint64_t Num, uint64_t Weight=1)
Definition:SampleProf.h:785
llvm::sampleprof::FunctionSamples::functionSamplesAt
FunctionSamplesMap & functionSamplesAt(const LineLocation &Loc)
Return the function samples at the given callsite location.
Definition:SampleProf.h:906
llvm::sampleprof::FunctionSamples::empty
bool empty() const
Definition:SampleProf.h:931
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::setIRToProfileLocationMap
void setIRToProfileLocationMap(const LocToLocMap *LTLM)
Definition:SampleProf.h:1083
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::getFuncName
StringRef getFuncName() const
Return the original function name.
Definition:SampleProf.h:1077
llvm::sampleprof::FunctionSamples::findAllNames
void findAllNames(DenseSet< FunctionId > &NameSet) const
Definition:SampleProf.cpp:267
llvm::sampleprof::FunctionSamples::addBodySamples
sampleprof_error addBodySamples(uint32_t LineOffset, uint32_t Discriminator, uint64_t Num, uint64_t Weight=1)
Definition:SampleProf.h:779
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::setContextSynthetic
void setContextSynthetic()
Definition:SampleProf.h:850
llvm::sampleprof::FunctionSamples::setFunctionHash
void setFunctionHash(uint64_t Hash)
Definition:SampleProf.h:1079
llvm::sampleprof::FunctionSamples::ProfileIsFS
static bool ProfileIsFS
If this profile uses flow sensitive discriminators.
Definition:SampleProf.h:1203
llvm::sampleprof::FunctionSamples::findCallTargetMapAt
ErrorOr< const SampleRecord::CallTargetMap & > findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const
Returns the call target map collected at a given location.
Definition:SampleProf.h:887
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::FunctionSamples
FunctionSamples()=default
llvm::sampleprof::FunctionSamples::getCallsiteSamples
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
Definition:SampleProf.h:976
llvm::sampleprof::FunctionSamples::dump
void dump() const
Definition:SampleProf.cpp:328
llvm::sampleprof::FunctionSamples::setContext
void setContext(const SampleContext &FContext)
Definition:SampleProf.h:1194
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::getHeadSamplesEstimate
uint64_t getHeadSamplesEstimate() const
Return an estimate of the sample count of the function entry basic block.
Definition:SampleProf.h:949
llvm::sampleprof::FunctionSamples::getGUID
uint64_t getGUID() const
Return the GUID of the context's name.
Definition:SampleProf.h:1211
llvm::sampleprof::FunctionSamples::getBodySamples
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
Definition:SampleProf.h:973
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< std::unordered_map, SampleContext, FunctionSamples >::try_emplace
std::pair< iterator, bool > try_emplace(const key_type &Hash, const original_key_type &Key, Ts &&...Args)
Definition:HashKeyMap.h:65
llvm::sampleprof::HashKeyMap< std::unordered_map, SampleContext, FunctionSamples >::iterator
typename base_type::iterator iterator
Definition:HashKeyMap.h:61
llvm::sampleprof::HashKeyMap< std::unordered_map, SampleContext, FunctionSamples >::key_type
decltype(hash_value(SampleContext())) key_type
Definition:HashKeyMap.h:56
llvm::sampleprof::HashKeyMap::erase
size_t erase(const original_key_type &Ctx)
Definition:HashKeyMap.h:111
llvm::sampleprof::HashKeyMap::find
iterator find(const original_key_type &Key)
Definition:HashKeyMap.h:86
llvm::sampleprof::HashKeyMap< std::unordered_map, SampleContext, FunctionSamples >::const_iterator
typename base_type::const_iterator const_iterator
Definition:HashKeyMap.h:62
llvm::sampleprof::ProfileConverter
Helper class for profile conversion.
Definition:SampleProf.h:1399
llvm::sampleprof::ProfileConverter::convertCSProfiles
void convertCSProfiles()
Definition:SampleProf.cpp:519
llvm::sampleprof::ProfileConverter::flattenProfile
static void flattenProfile(SampleProfileMap &ProfileMap, bool ProfileIsCS=false)
Definition:SampleProf.h:1424
llvm::sampleprof::ProfileConverter::flattenProfile
static void flattenProfile(const SampleProfileMap &InputProfiles, SampleProfileMap &OutputProfiles, bool ProfileIsCS=false)
Definition:SampleProf.h:1431
llvm::sampleprof::ProfileSymbolList
ProfileSymbolList records the list of function symbols shown up in the binary used to generate the pr...
Definition:SampleProf.h:1513
llvm::sampleprof::ProfileSymbolList::setToCompress
void setToCompress(bool TC)
Definition:SampleProf.h:1534
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::toCompress
bool toCompress()
Definition:SampleProf.h:1535
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::merge
void merge(const ProfileSymbolList &List)
Definition:SampleProf.h:1527
llvm::sampleprof::ProfileSymbolList::contains
bool contains(StringRef Name)
Definition:SampleProf.h:1525
llvm::sampleprof::ProfileSymbolList::size
unsigned size()
Definition:SampleProf.h:1532
llvm::sampleprof::ProfileSymbolList::read
std::error_code read(const uint8_t *Data, uint64_t ListSize)
Definition:SampleProf.cpp:331
llvm::sampleprof::SampleContextTrimmer
SampleContextTrimmer impelements helper functions to trim, merge cold context profiles.
Definition:SampleProf.h:1375
llvm::sampleprof::SampleContextTrimmer::SampleContextTrimmer
SampleContextTrimmer(SampleProfileMap &Profiles)
Definition:SampleProf.h:1377
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::createCtxVectorFromStr
static void createCtxVectorFromStr(StringRef ContextStr, SampleContextFrameVector &Context)
Create a context vector from a given context string and save it in Context.
Definition:SampleProf.h:566
llvm::sampleprof::SampleContext::operator==
bool operator==(const SampleContext &That) const
Definition:SampleProf.h:660
llvm::sampleprof::SampleContext::setFunction
void setFunction(FunctionId NewFunctionID)
Set the name of the function and clear the current context.
Definition:SampleProf.h:646
llvm::sampleprof::SampleContext::SampleContext
SampleContext(SampleContextFrames Context, ContextStateMask CState=RawContext)
Definition:SampleProf.h:535
llvm::sampleprof::SampleContext::operator<
bool operator<(const SampleContext &That) const
Definition:SampleProf.h:667
llvm::sampleprof::SampleContext::SampleContext
SampleContext(StringRef ContextStr, std::list< SampleContextFrameVector > &CSNameTable, ContextStateMask CState=RawContext)
Definition:SampleProf.h:545
llvm::sampleprof::SampleContext::hasState
bool hasState(ContextStateMask S)
Definition:SampleProf.h:612
llvm::sampleprof::SampleContext::hasContext
bool hasContext() const
Definition:SampleProf.h:615
llvm::sampleprof::SampleContext::clearState
void clearState(ContextStateMask S)
Definition:SampleProf.h:614
llvm::sampleprof::SampleContext::getContextFrames
SampleContextFrames getContextFrames() const
Definition:SampleProf.h:618
llvm::sampleprof::SampleContext::SampleContext
SampleContext(FunctionId Func)
Definition:SampleProf.h:532
llvm::sampleprof::SampleContext::isBaseContext
bool isBaseContext() const
Definition:SampleProf.h:616
llvm::sampleprof::SampleContext::decodeContextString
static void decodeContextString(StringRef ContextStr, FunctionId &Func, LineLocation &LineLoc)
Definition:SampleProf.h:585
llvm::sampleprof::SampleContext::getContextString
static std::string getContextString(SampleContextFrames Context, bool IncludeLeafLineLocation=false)
Definition:SampleProf.h:620
llvm::sampleprof::SampleContext::operator!=
bool operator!=(const SampleContext &That) const
Definition:SampleProf.h:665
llvm::sampleprof::SampleContext::setState
void setState(ContextStateMask S)
Definition:SampleProf.h:613
llvm::sampleprof::SampleContext::setAllAttributes
void setAllAttributes(uint32_t A)
Definition:SampleProf.h:611
llvm::sampleprof::SampleContext::getHashCode
uint64_t getHashCode() const
Definition:SampleProf.h:639
llvm::sampleprof::SampleContext::setContext
void setContext(SampleContextFrames Context, ContextStateMask CState=RawContext)
Definition:SampleProf.h:652
llvm::sampleprof::SampleContext::getFunction
FunctionId getFunction() const
Definition:SampleProf.h:617
llvm::sampleprof::SampleContext::SampleContext
SampleContext()
Definition:SampleProf.h:525
llvm::sampleprof::SampleContext::getAllAttributes
uint32_t getAllAttributes()
Definition:SampleProf.h:610
llvm::sampleprof::SampleContext::setAttribute
void setAttribute(ContextAttributeMask A)
Definition:SampleProf.h:609
llvm::sampleprof::SampleContext::hasAttribute
bool hasAttribute(ContextAttributeMask A)
Definition:SampleProf.h:608
llvm::sampleprof::SampleContext::toString
std::string toString() const
Definition:SampleProf.h:633
llvm::sampleprof::SampleContext::SampleContext
SampleContext(StringRef Name)
Definition:SampleProf.h:527
llvm::sampleprof::SampleContext::isPrefixOf
bool isPrefixOf(const SampleContext &That) const
Definition:SampleProf.h:696
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::find
iterator find(const SampleContext &Ctx)
Definition:SampleProf.h:1324
llvm::sampleprof::SampleProfileMap::create
mapped_type & create(const SampleContext &Ctx)
Definition:SampleProf.h:1317
llvm::sampleprof::SampleProfileMap::erase
iterator erase(iterator It)
Definition:SampleProf.h:1341
llvm::sampleprof::SampleProfileMap::erase
size_t erase(const key_type &Key)
Definition:SampleProf.h:1339
llvm::sampleprof::SampleProfileMap::find
const_iterator find(const SampleContext &Ctx) const
Definition:SampleProf.h:1329
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::SampleRecord
Representation of a single sample record.
Definition:SampleProf.h:325
llvm::sampleprof::SampleRecord::CallTargetMap
std::unordered_map< FunctionId, uint64_t > CallTargetMap
Definition:SampleProf.h:338
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::sortCallTargets
static const SortedCallTargetSet sortCallTargets(const CallTargetMap &Targets)
Sort call targets in descending order of call frequency.
Definition:SampleProf.h:407
llvm::sampleprof::SampleRecord::getCallTargets
const CallTargetMap & getCallTargets() const
Definition:SampleProf.h:393
llvm::sampleprof::SampleRecord::SortedCallTargetSet
std::set< CallTarget, CallTargetComparator > SortedCallTargetSet
Definition:SampleProf.h:337
llvm::sampleprof::SampleRecord::getSamples
uint64_t getSamples() const
Definition:SampleProf.h:392
llvm::sampleprof::SampleRecord::getCallTargetSum
uint64_t getCallTargetSum() const
Definition:SampleProf.h:398
llvm::sampleprof::SampleRecord::removeSamples
uint64_t removeSamples(uint64_t S)
Decrease the number of samples for this record by S.
Definition:SampleProf.h:355
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::removeCalledTarget
uint64_t removeCalledTarget(FunctionId F)
Remove called function from the call target map.
Definition:SampleProf.h:379
llvm::sampleprof::SampleRecord::SampleRecord
SampleRecord()=default
llvm::sampleprof::SampleRecord::getSortedCallTargets
const SortedCallTargetSet getSortedCallTargets() const
Definition:SampleProf.h:394
llvm::sampleprof::SampleRecord::adjustCallTargets
static const CallTargetMap adjustCallTargets(const CallTargetMap &Targets, float DistributionFactor)
Prorate call targets by a distribution factor.
Definition:SampleProf.h:416
llvm::sampleprof::SampleRecord::CallTarget
std::pair< FunctionId, uint64_t > CallTarget
Definition:SampleProf.h:327
llvm::sampleprof::SampleRecord::operator!=
bool operator!=(const SampleRecord &Other) const
Definition:SampleProf.h:435
llvm::sampleprof::SampleRecord::operator==
bool operator==(const SampleRecord &Other) const
Definition:SampleProf.h:431
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::SamplesWithLoc
std::pair< const LocationT, SampleT > SamplesWithLoc
Definition:SampleProf.h:1355
llvm::sampleprof::SampleSorter::SampleSorter
SampleSorter(const std::map< LocationT, SampleT > &Samples)
Definition:SampleProf.h:1358
llvm::sampleprof::SampleSorter::get
const SamplesWithLocList & get() const
Definition:SampleProf.h:1366
llvm::sampleprof::SampleSorter::SamplesWithLocList
SmallVector< const SamplesWithLoc *, 20 > SamplesWithLocList
Definition:SampleProf.h:1356
uint32_t
uint64_t
uint8_t
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition:ErrorHandling.h:143
llvm::CallingConv::C
@ C
The default llvm calling convention, compatible with C.
Definition:CallingConv.h:34
llvm::X86AS::FS
@ FS
Definition:X86.h:211
llvm::pdb::PDB_SymType::Callee
@ Callee
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::verifySecFlag
static void verifySecFlag(SecType Type, SecFlagType Flag)
Definition:SampleProf.h:221
llvm::sampleprof::SampleContextFrames
ArrayRef< SampleContextFrame > SampleContextFrames
Definition:SampleProf.h:505
llvm::sampleprof::sortFuncProfiles
void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
Definition:SampleProf.cpp:202
llvm::sampleprof::SPMagic
static uint64_t SPMagic(SampleProfileFormat Format=SPF_Binary)
Definition:SampleProf.h:106
llvm::sampleprof::SecCommonFlags
SecCommonFlags
Definition:SampleProf.h:169
llvm::sampleprof::SecCommonFlags::SecFlagCompress
@ SecFlagCompress
llvm::sampleprof::SecCommonFlags::SecFlagFlat
@ SecFlagFlat
llvm::sampleprof::SecCommonFlags::SecFlagInValid
@ SecFlagInValid
llvm::sampleprof::LocToLocMap
std::unordered_map< LineLocation, LineLocation, LineLocationHash > LocToLocMap
Definition:SampleProf.h:738
llvm::sampleprof::NameFunctionSamples
std::pair< hash_code, const FunctionSamples * > NameFunctionSamples
Definition:SampleProf.h:1344
llvm::sampleprof::SampleProfileFormat
SampleProfileFormat
Definition:SampleProf.h:91
llvm::sampleprof::SPF_Binary
@ SPF_Binary
Definition:SampleProf.h:97
llvm::sampleprof::SPF_Ext_Binary
@ SPF_Ext_Binary
Definition:SampleProf.h:96
llvm::sampleprof::SPF_GCC
@ SPF_GCC
Definition:SampleProf.h:95
llvm::sampleprof::SPF_None
@ SPF_None
Definition:SampleProf.h:92
llvm::sampleprof::SPF_Compact_Binary
@ SPF_Compact_Binary
Definition:SampleProf.h:94
llvm::sampleprof::SPF_Text
@ SPF_Text
Definition:SampleProf.h:93
llvm::sampleprof::addSecFlag
static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
Definition:SampleProf.h:248
llvm::sampleprof::hasSecFlag
static bool hasSecFlag(const SecHdrTableEntry &Entry, SecFlagType Flag)
Definition:SampleProf.h:264
llvm::sampleprof::CallsiteSampleMap
std::map< LineLocation, FunctionSamplesMap > CallsiteSampleMap
Definition:SampleProf.h:736
llvm::sampleprof::ContextStateMask
ContextStateMask
Definition:SampleProf.h:447
llvm::sampleprof::InlinedContext
@ InlinedContext
Definition:SampleProf.h:451
llvm::sampleprof::RawContext
@ RawContext
Definition:SampleProf.h:449
llvm::sampleprof::MergedContext
@ MergedContext
Definition:SampleProf.h:452
llvm::sampleprof::UnknownContext
@ UnknownContext
Definition:SampleProf.h:448
llvm::sampleprof::SyntheticContext
@ SyntheticContext
Definition:SampleProf.h:450
llvm::sampleprof::SecNameTableFlags
SecNameTableFlags
Definition:SampleProf.h:179
llvm::sampleprof::SecNameTableFlags::SecFlagMD5Name
@ SecFlagMD5Name
llvm::sampleprof::SecNameTableFlags::SecFlagUniqSuffix
@ SecFlagUniqSuffix
llvm::sampleprof::SecNameTableFlags::SecFlagFixedLengthMD5
@ SecFlagFixedLengthMD5
llvm::sampleprof::ContextAttributeMask
ContextAttributeMask
Definition:SampleProf.h:456
llvm::sampleprof::ContextNone
@ ContextNone
Definition:SampleProf.h:457
llvm::sampleprof::ContextDuplicatedIntoBase
@ ContextDuplicatedIntoBase
Definition:SampleProf.h:460
llvm::sampleprof::ContextWasInlined
@ ContextWasInlined
Definition:SampleProf.h:458
llvm::sampleprof::ContextShouldBeInlined
@ ContextShouldBeInlined
Definition:SampleProf.h:459
llvm::sampleprof::BodySampleMap
std::map< LineLocation, SampleRecord > BodySampleMap
Definition:SampleProf.h:732
llvm::sampleprof::SecProfSummaryFlags
SecProfSummaryFlags
Definition:SampleProf.h:189
llvm::sampleprof::SecProfSummaryFlags::SecFlagIsPreInlined
@ SecFlagIsPreInlined
SecFlagIsPreInlined means this profile contains ShouldBeInlined contexts thus this is CS preinliner c...
llvm::sampleprof::SecProfSummaryFlags::SecFlagPartial
@ SecFlagPartial
SecFlagPartial means the profile is for common/shared code.
llvm::sampleprof::SecProfSummaryFlags::SecFlagFSDiscriminator
@ SecFlagFSDiscriminator
SecFlagFSDiscriminator means this profile uses flow-sensitive discriminators.
llvm::sampleprof::SecProfSummaryFlags::SecFlagFullContext
@ SecFlagFullContext
SecFlagContext means this is context-sensitive flat profile for CSSPGO.
llvm::sampleprof::removeSecFlag
static void removeSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
Definition:SampleProf.h:256
llvm::sampleprof::SecFuncOffsetFlags
SecFuncOffsetFlags
Definition:SampleProf.h:212
llvm::sampleprof::SecFuncOffsetFlags::SecFlagOrdered
@ SecFlagOrdered
llvm::sampleprof::FunctionSamplesMap
std::map< FunctionId, FunctionSamples > FunctionSamplesMap
Definition:SampleProf.h:735
llvm::sampleprof::operator<<
raw_ostream & operator<<(raw_ostream &OS, const FunctionId &Obj)
Definition:FunctionId.h:159
llvm::sampleprof::SecFuncMetadataFlags
SecFuncMetadataFlags
Definition:SampleProf.h:206
llvm::sampleprof::SecFuncMetadataFlags::SecFlagHasAttribute
@ SecFlagHasAttribute
llvm::sampleprof::SecFuncMetadataFlags::SecFlagIsProbeBased
@ SecFlagIsProbeBased
llvm::sampleprof::SecFuncMetadataFlags::SecFlagInvalid
@ SecFlagInvalid
llvm::sampleprof::getSecName
static std::string getSecName(SecType Type)
Definition:SampleProf.h:131
llvm::sampleprof::hash_value
uint64_t hash_value(const FunctionId &Obj)
Definition:FunctionId.h:171
llvm::sampleprof::SPVersion
static uint64_t SPVersion()
Definition:SampleProf.h:113
llvm::sampleprof::SampleProfileLayout
SampleProfileLayout
Definition:SampleProf.h:100
llvm::sampleprof::SPL_Flat
@ SPL_Flat
Definition:SampleProf.h:103
llvm::sampleprof::SPL_None
@ SPL_None
Definition:SampleProf.h:101
llvm::sampleprof::SPL_Nest
@ SPL_Nest
Definition:SampleProf.h:102
llvm::sampleprof::SecType
SecType
Definition:SampleProf.h:118
llvm::sampleprof::SecNameTable
@ SecNameTable
Definition:SampleProf.h:121
llvm::sampleprof::SecLBRProfile
@ SecLBRProfile
Definition:SampleProf.h:128
llvm::sampleprof::SecFuncProfileFirst
@ SecFuncProfileFirst
Definition:SampleProf.h:127
llvm::sampleprof::SecProfSummary
@ SecProfSummary
Definition:SampleProf.h:120
llvm::sampleprof::SecCSNameTable
@ SecCSNameTable
Definition:SampleProf.h:125
llvm::sampleprof::SecFuncMetadata
@ SecFuncMetadata
Definition:SampleProf.h:124
llvm::sampleprof::SecProfileSymbolList
@ SecProfileSymbolList
Definition:SampleProf.h:122
llvm::sampleprof::SecFuncOffsetTable
@ SecFuncOffsetTable
Definition:SampleProf.h:123
llvm::sampleprof::SecInValid
@ SecInValid
Definition:SampleProf.h:119
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::make_error_code
std::error_code make_error_code(BitcodeError E)
Definition:BitcodeReader.h:310
llvm::mergeSampleProfErrors
sampleprof_error mergeSampleProfErrors(sampleprof_error &Accumulator, sampleprof_error Result)
Definition:SampleProf.h:69
llvm::cgdata_error::success
@ success
llvm::cgdata_error::unsupported_version
@ unsupported_version
llvm::cgdata_error::bad_magic
@ bad_magic
llvm::cgdata_error::malformed
@ malformed
llvm::sampleprof_error
sampleprof_error
Definition:SampleProf.h:47
llvm::sampleprof_error::success
@ success
llvm::sampleprof_error::counter_overflow
@ counter_overflow
llvm::sampleprof_error::not_implemented
@ not_implemented
llvm::sampleprof_error::unsupported_writing_format
@ unsupported_writing_format
llvm::sampleprof_error::truncated_name_table
@ truncated_name_table
llvm::sampleprof_error::hash_mismatch
@ hash_mismatch
llvm::sampleprof_error::ostream_seek_unsupported
@ ostream_seek_unsupported
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition:Debug.cpp:163
llvm::SaturatingMultiplyAdd
std::enable_if_t< std::is_unsigned_v< T >, T > SaturatingMultiplyAdd(T X, T Y, T A, bool *ResultOverflowed=nullptr)
Multiply two unsigned integers, X and Y, and add the unsigned integer, A to the product.
Definition:MathExtras.h:685
llvm::IRMemLocation::Other
@ Other
Any other memory.
llvm::sampleprof_category
const std::error_category & sampleprof_category()
Definition:SampleProf.cpp:100
llvm::instrprof_error::zlib_unavailable
@ zlib_unavailable
llvm::instrprof_error::uncompress_failed
@ uncompress_failed
llvm::instrprof_error::counter_overflow
@ counter_overflow
llvm::instrprof_error::too_large
@ too_large
llvm::instrprof_error::truncated
@ truncated
llvm::instrprof_error::hash_mismatch
@ hash_mismatch
llvm::instrprof_error::unrecognized_format
@ unrecognized_format
llvm::getUniqueInternalLinkagePostfix
std::string getUniqueInternalLinkagePostfix(const StringRef &FName)
Definition:SampleProf.h:1575
llvm::ReplacementType::Format
@ Format
llvm::BasicBlockSection::List
@ List
llvm::toString
const char * toString(DWARFSectionKind Kind)
Definition:DWARFUnitIndex.h:67
llvm::Data
@ Data
Definition:SIMachineScheduler.h:55
llvm::hash_combine_range
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Definition:Hashing.h:468
std
Implement std::hash so that hash_code can be used in STL containers.
Definition:BitVector.h:858
llvm::DenseMapInfo< SampleContext >::getHashValue
static unsigned getHashValue(const SampleContext &Val)
Definition:SampleProf.h:1561
llvm::DenseMapInfo< SampleContext >::getTombstoneKey
static SampleContext getTombstoneKey()
Definition:SampleProf.h:1557
llvm::DenseMapInfo< SampleContext >::getEmptyKey
static SampleContext getEmptyKey()
Definition:SampleProf.h:1555
llvm::DenseMapInfo< SampleContext >::isEqual
static bool isEqual(const SampleContext &LHS, const SampleContext &RHS)
Definition:SampleProf.h:1565
llvm::DenseMapInfo
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition:DenseMapInfo.h:52
llvm::MD5::MD5Result
Definition:MD5.h:43
llvm::sampleprof::LineLocationHash
Definition:SampleProf.h:307
llvm::sampleprof::LineLocationHash::operator()
uint64_t operator()(const LineLocation &Loc) const
Definition:SampleProf.h:308
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::LineLocation
LineLocation(uint32_t L, uint32_t D)
Definition:SampleProf.h:281
llvm::sampleprof::LineLocation::operator!=
bool operator!=(const LineLocation &O) const
Definition:SampleProf.h:295
llvm::sampleprof::LineLocation::operator<
bool operator<(const LineLocation &O) const
Definition:SampleProf.h:286
llvm::sampleprof::LineLocation::getHashCode
uint64_t getHashCode() const
Definition:SampleProf.h:299
llvm::sampleprof::LineLocation::operator==
bool operator==(const LineLocation &O) const
Definition:SampleProf.h:291
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::CallSiteLoc
LineLocation CallSiteLoc
Definition:SampleProf.h:1418
llvm::sampleprof::ProfileConverter::FrameNode::FuncSamples
FunctionSamples * FuncSamples
Definition:SampleProf.h:1416
llvm::sampleprof::ProfileConverter::FrameNode::FuncName
FunctionId FuncName
Definition:SampleProf.h:1414
llvm::sampleprof::ProfileConverter::FrameNode::FrameNode
FrameNode(FunctionId FName=FunctionId(), FunctionSamples *FSamples=nullptr, LineLocation CallLoc={0, 0})
Definition:SampleProf.h:1406
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
llvm::sampleprof::SampleContextFrameHash
Definition:SampleProf.h:507
llvm::sampleprof::SampleContextFrameHash::operator()
uint64_t operator()(const SampleContextFrameVector &S) const
Definition:SampleProf.h:508
llvm::sampleprof::SampleContextFrame
Definition:SampleProf.h:465
llvm::sampleprof::SampleContextFrame::operator==
bool operator==(const SampleContextFrame &That) const
Definition:SampleProf.h:474
llvm::sampleprof::SampleContextFrame::SampleContextFrame
SampleContextFrame(FunctionId Func, LineLocation Location)
Definition:SampleProf.h:471
llvm::sampleprof::SampleContextFrame::SampleContextFrame
SampleContextFrame()
Definition:SampleProf.h:469
llvm::sampleprof::SampleContextFrame::operator!=
bool operator!=(const SampleContextFrame &That) const
Definition:SampleProf.h:478
llvm::sampleprof::SampleContextFrame::toString
std::string toString(bool OutputLineLocation) const
Definition:SampleProf.h:482
llvm::sampleprof::SampleContextFrame::getHashCode
uint64_t getHashCode() const
Definition:SampleProf.h:493
llvm::sampleprof::SampleContextFrame::Location
LineLocation Location
Definition:SampleProf.h:467
llvm::sampleprof::SampleContextFrame::Func
FunctionId Func
Definition:SampleProf.h:466
llvm::sampleprof::SampleContext::Hash
Definition:SampleProf.h:690
llvm::sampleprof::SampleContext::Hash::operator()
uint64_t operator()(const SampleContext &Context) const
Definition:SampleProf.h:691
llvm::sampleprof::SampleRecord::CallTargetComparator
Definition:SampleProf.h:328
llvm::sampleprof::SampleRecord::CallTargetComparator::operator()
bool operator()(const CallTarget &LHS, const CallTarget &RHS) const
Definition:SampleProf.h:329
llvm::sampleprof::SecHdrTableEntry
Definition:SampleProf.h:156
llvm::sampleprof::SecHdrTableEntry::Offset
uint64_t Offset
Definition:SampleProf.h:159
llvm::sampleprof::SecHdrTableEntry::Flags
uint64_t Flags
Definition:SampleProf.h:158
llvm::sampleprof::SecHdrTableEntry::Type
SecType Type
Definition:SampleProf.h:157
llvm::sampleprof::SecHdrTableEntry::LayoutIndex
uint64_t LayoutIndex
Definition:SampleProf.h:163
llvm::sampleprof::SecHdrTableEntry::Size
uint64_t Size
Definition:SampleProf.h:160

Generated on Thu Jul 17 2025 10:13:09 for LLVM by doxygen 1.9.6
[8]ページ先頭

©2009-2025 Movatter.jp