14#ifndef LLVM_PROFILEDATA_SAMPLEPROF_H
15#define LLVM_PROFILEDATA_SAMPLEPROF_H
36#include <system_error>
37#include <unordered_map>
84struct is_error_code_enum<
llvm::sampleprof_error> : std::true_type {};
132 switch (
static_cast<int>(
Type)) {
134 return "InvalidSection";
136 return "ProfileSummarySection";
138 return "NameTableSection";
140 return "ProfileSymbolListSection";
142 return "FuncOffsetTableSection";
144 return "FunctionMetadata";
146 return "CSNameTableSection";
148 return "LBRProfileSection";
150 return "UnknownSection";
220template <
class SecFlagType>
223 if (std::is_same<SecCommonFlags, SecFlagType>())
227 bool IsFlagLegal =
false;
230 IsFlagLegal = std::is_same<SecNameTableFlags, SecFlagType>();
233 IsFlagLegal = std::is_same<SecProfSummaryFlags, SecFlagType>();
236 IsFlagLegal = std::is_same<SecFuncMetadataFlags, SecFlagType>();
240 IsFlagLegal = std::is_same<SecFuncOffsetFlags, SecFlagType>();
247template <
class SecFlagType>
250 auto FVal =
static_cast<uint64_t>(Flag);
251 bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
252 Entry.Flags |= IsCommon ? FVal : (FVal << 32);
255template <
class SecFlagType>
258 auto FVal =
static_cast<uint64_t>(Flag);
259 bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
260 Entry.Flags &= ~(IsCommon ? FVal : (FVal << 32));
263template <
class SecFlagType>
266 auto FVal =
static_cast<uint64_t>(Flag);
267 bool IsCommon = std::is_same<SecCommonFlags, SecFlagType>();
268 return Entry.Flags & (IsCommon ? FVal : (FVal << 32));
330 if (
LHS.second !=
RHS.second)
331 return LHS.second >
RHS.second;
333 return LHS.first <
RHS.first;
369 uint64_t &TargetSamples = CallTargets[
F];
381 auto I = CallTargets.find(
F);
382 if (
I != CallTargets.end()) {
384 CallTargets.erase(
I);
390 bool hasCalls()
const {
return !CallTargets.empty(); }
400 for (
const auto &
I : CallTargets)
409 for (
const auto &[
Target, Frequency] : Targets) {
410 SortedTargets.emplace(
Target, Frequency);
412 return SortedTargets;
417 float DistributionFactor) {
419 for (
const auto &[
Target, Frequency] : Targets) {
420 AdjustedTargets[
Target] = Frequency * DistributionFactor;
422 return AdjustedTargets;
432 return NumSamples ==
Other.NumSamples && CallTargets ==
Other.CallTargets;
436 return !(*
this ==
Other);
479 return !(*
this == That);
482 std::string
toString(
bool OutputLineLocation)
const {
483 std::ostringstream OContextStr;
485 if (OutputLineLocation) {
490 return OContextStr.str();
496 return NameHash + (LocId << 5) + LocId;
546 std::list<SampleContextFrameVector> &CSNameTable,
557 CSNameTable.emplace_back();
569 ContextStr = ContextStr.
substr(1, ContextStr.
size() - 2);
573 while (!ContextRemain.
empty()) {
574 auto ContextSplit = ContextRemain.
split(
" @ ");
575 ChildContext = ContextSplit.first;
576 ContextRemain = ContextSplit.second;
589 auto EntrySplit = ContextStr.
split(
':');
593 if (!EntrySplit.second.empty()) {
597 auto LocSplit = EntrySplit.second.split(
'.');
598 LocSplit.first.getAsInteger(10, LineOffset);
602 if (!LocSplit.second.empty())
621 bool IncludeLeafLineLocation =
false) {
622 std::ostringstream OContextStr;
624 if (OContextStr.str().size()) {
625 OContextStr <<
" @ ";
627 OContextStr << Context[
I].toString(
I != Context.
size() - 1 ||
628 IncludeLeafLineLocation);
630 return OContextStr.str();
647 Func = NewFunctionID;
655 FullContext = Context;
661 return State == That.State && Func == That.Func &&
662 FullContext == That.FullContext;
668 if (State != That.State)
669 return State < That.State;
672 return Func < That.Func;
676 while (
I < std::min(FullContext.
size(), That.FullContext.
size())) {
677 auto &Context1 = FullContext[
I];
678 auto &Context2 = That.FullContext[
I];
679 auto V = Context1.Func.compare(Context2.Func);
682 if (Context1.Location != Context2.Location)
683 return Context1.Location < Context2.Location;
687 return FullContext.
size() < That.FullContext.
size();
697 auto ThisContext = FullContext;
698 auto ThatContext = That.FullContext;
699 if (ThatContext.size() < ThisContext.size())
701 ThatContext = ThatContext.
take_front(ThisContext.size());
703 if (ThisContext.back().Func != ThatContext.back().Func)
738 std::unordered_map<LineLocation, LineLocation, LineLocationHash>;
761 if (TotalSamples < Num)
781 return BodySamples[
LineLocation(LineOffset, Discriminator)].addSamples(
790 return BodySamples[
LineLocation(LineOffset, Discriminator)].addCalledTarget(
797 return BodySamples[Location].merge(
SampleRecord, Weight);
806 auto I = BodySamples.find(
LineLocation(LineOffset, Discriminator));
807 if (
I != BodySamples.end()) {
808 Count =
I->second.removeCalledTarget(Func);
809 Count =
I->second.removeSamples(Count);
810 if (!
I->second.getSamples())
811 BodySamples.erase(
I);
819 CallsiteSamples.clear();
824 for (
auto &
I : BodySamples) {
825 uint64_t TargetSamples =
I.second.getCallTargetSum();
830 if (TargetSamples >
I.second.getSamples())
831 I.second.addSamples(TargetSamples -
I.second.getSamples());
838 for (
const auto &
I : BodySamples)
841 for (
auto &
I : CallsiteSamples) {
842 for (
auto &CS :
I.second) {
843 CS.second.updateTotalSamples();
852 for (
auto &
I : CallsiteSamples) {
853 for (
auto &CS :
I.second) {
854 CS.second.setContextSynthetic();
863 if (!IRToProfileLocationMap)
865 const auto &ProfileLoc = IRToProfileLocationMap->find(IRLoc);
866 if (ProfileLoc != IRToProfileLocationMap->end())
867 return ProfileLoc->second;
876 const auto &Ret = BodySamples.find(
878 if (Ret == BodySamples.end())
879 return std::error_code();
880 return Ret->second.getSamples();
888 const auto &Ret = BodySamples.find(
890 if (Ret == BodySamples.end())
891 return std::error_code();
892 return Ret->second.getCallTargets();
900 if (Ret == BodySamples.end())
901 return std::error_code();
902 return Ret->second.getCallTargets();
914 if (Iter == CallsiteSamples.end())
916 return &Iter->second;
929 *FuncNameToProfNameMap =
nullptr)
const;
931 bool empty()
const {
return TotalSamples == 0; }
958 if (!BodySamples.empty() &&
959 (CallsiteSamples.empty() ||
960 BodySamples.begin()->first < CallsiteSamples.begin()->first))
961 Count = BodySamples.begin()->second.getSamples();
962 else if (!CallsiteSamples.empty()) {
965 for (
const auto &FuncSamples : CallsiteSamples.begin()->second)
966 Count += FuncSamples.second.getHeadSamplesEstimate();
969 return Count ? Count : TotalSamples > 0;
977 return CallsiteSamples;
987 MaxCount = std::max(MaxCount, L.second.getSamples());
991 for (
const FunctionSamplesMap::value_type &
F :
C.second)
992 MaxCount = std::max(MaxCount,
F.second.getMaxCountInside());
1003 Context =
Other.getContext();
1004 if (FunctionHash == 0) {
1006 FunctionHash =
Other.getFunctionHash();
1007 }
else if (FunctionHash !=
Other.getFunctionHash()) {
1022 for (
const auto &
I :
Other.getBodySamples()) {
1027 for (
const auto &
I :
Other.getCallsiteSamples()) {
1030 for (
const auto &Rec :
I.second)
1032 FSMap[Rec.first].merge(Rec.second, Weight));
1045 if (TotalSamples <= Threshold)
1047 auto IsDeclaration = [](
const Function *
F) {
1048 return !
F ||
F->isDeclaration();
1056 for (
const auto &BS : BodySamples)
1057 for (
const auto &TS : BS.second.getCallTargets())
1058 if (TS.second > Threshold) {
1060 if (IsDeclaration(Callee))
1061 S.
insert(TS.first.getHashCode());
1063 for (
const auto &CS : CallsiteSamples)
1064 for (
const auto &NameFS : CS.second)
1065 NameFS.second.findInlinedFunctions(S, SymbolMap, Threshold);
1084 assert(IRToProfileLocationMap ==
nullptr &&
"this should be set only once");
1085 IRToProfileLocationMap = LTLM;
1091 const char *AttrName =
"sample-profile-suffix-elision-policy";
1092 auto Attr =
F.getFnAttribute(AttrName).getValueAsString();
1108 if (Attr ==
"" || Attr ==
"all")
1109 return FnName.
split(
'.').first;
1110 if (Attr ==
"selected") {
1112 for (
const auto &Suf : KnownSuffixes) {
1118 auto It = Cand.
rfind(Suffix);
1121 auto Dit = Cand.
rfind(
'.');
1122 if (Dit == It + Suffix.
size() - 1)
1123 Cand = Cand.
substr(0, It);
1129 assert(
false &&
"internal error: unknown suffix elision policy");
1142 return Func.stringRef();
1184 *FuncNameToProfNameMap =
nullptr)
const;
1223 FunctionHash ==
Other.FunctionHash && Context ==
Other.Context &&
1224 TotalSamples ==
Other.TotalSamples &&
1225 TotalHeadSamples ==
Other.TotalHeadSamples &&
1226 BodySamples ==
Other.BodySamples &&
1227 CallsiteSamples ==
Other.CallsiteSamples;
1231 return !(*
this ==
Other);
1294 const LocToLocMap *IRToProfileLocationMap =
nullptr;
1313 :
public HashKeyMap<std::unordered_map, SampleContext, FunctionSamples> {
1320 Ret.first->second.setContext(Ctx);
1321 return Ret.first->second;
1347 std::vector<NameFunctionSamples> &SortedProfiles);
1359 for (
const auto &
I : Samples)
1362 return A->first <
B->first;
1386 bool TrimColdContext,
1387 bool MergeColdContext,
1389 bool TrimBaseProfileOnly);
1425 bool ProfileIsCS =
false) {
1428 ProfileMap = std::move(TmpProfiles);
1433 bool ProfileIsCS =
false) {
1435 for (
const auto &
I : InputProfiles) {
1442 for (
const auto &
I : InputProfiles)
1443 flattenNestedProfile(OutputProfiles,
I.second);
1453 auto Ret = OutputProfiles.
try_emplace(Context, FS);
1458 Profile.removeAllCallsiteSamples();
1468 "There should be no inlinees' profiles after flattening.");
1474 uint64_t TotalSamples =
FS.getTotalSamples();
1476 for (
const auto &
I :
FS.getCallsiteSamples()) {
1477 for (
const auto &Callee :
I.second) {
1478 const auto &CalleeProfile =
Callee.second;
1480 Profile.addBodySamples(
I.first.LineOffset,
I.first.Discriminator,
1481 CalleeProfile.getHeadSamplesEstimate());
1483 Profile.addCalledTargetSamples(
1484 I.first.LineOffset,
I.first.Discriminator,
1485 CalleeProfile.getFunction(),
1486 CalleeProfile.getHeadSamplesEstimate());
1488 TotalSamples = TotalSamples >= CalleeProfile.getTotalSamples()
1489 ? TotalSamples - CalleeProfile.getTotalSamples()
1491 TotalSamples += CalleeProfile.getHeadSamplesEstimate();
1493 flattenNestedProfile(OutputProfiles, CalleeProfile);
1496 Profile.addTotalSamples(TotalSamples);
1503 FrameNode *getOrCreateContextPath(
const SampleContext &Context);
1505 SampleProfileMap &ProfileMap;
1506 FrameNode RootFrame;
1522 Syms.insert(
Name.copy(Allocator));
1532 unsigned size() {
return Syms.size(); }
1545 bool ToCompress =
false;
1552using namespace sampleprof;
1585 return toString(IntHash, 10,
false)
This file defines the BumpPtrAllocator interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseSet and SmallDenseSet classes.
Provides ErrorOr<T> smart pointer.
Defines HashKeyMap template.
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)
Defines FunctionId class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
Class for arbitrary precision integers.
const T & back() const
back - Get the last element.
ArrayRef< T > take_front(size_t N=1) const
Return a copy of *this with only the first N elements.
size_t size() const
size - Get the array size.
ArrayRef< T > drop_back(size_t N=1) const
Drop the last N elements of the array.
bool empty() const
empty - Check if the array is empty.
Allocate memory in an ever growing pool, as if by bump-pointer.
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...
Implements a dense probed hash-table based set.
Represents either an error or a value T.
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
void update(ArrayRef< uint8_t > Data)
Updates the hash for the byte stream provided.
static void stringifyResult(MD5Result &Result, SmallVectorImpl< char > &Str)
Translates the bytes in Res to a hex string that is deposited into Str.
void final(MD5Result &Result)
Finishes off the hash and puts the result in result.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
reference emplace_back(ArgTypes &&... Args)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
constexpr StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
constexpr bool empty() const
empty - Check if the string is empty.
constexpr size_t size() const
size - Get the string size.
size_t rfind(char C, size_t From=npos) const
Search for the last character C in the string.
static constexpr size_t npos
Target - Wrapper for Target specific information.
The instances of the Type class are immutable: once they are created, they are never changed.
std::pair< iterator, bool > insert(const ValueT &V)
An opaque object representing a hash code.
This class implements an extremely fast bulk output stream that can only output to a stream.
This class represents a function that is read from a sample profile.
uint64_t getHashCode() const
Get hash code of this object.
std::string str() const
Convert to a string, usually for output purpose.
Representation of the samples collected for a function.
void setTotalSamples(uint64_t Num)
static bool ProfileIsPreInlined
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...
bool operator!=(const FunctionSamples &Other) const
void updateTotalSamples()
void setHeadSamples(uint64_t Num)
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.
sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight=1)
static constexpr const char * UniqSuffix
void updateCallsiteSamples()
static StringRef getCanonicalFnName(StringRef FnName, StringRef Attr="selected")
bool operator==(const FunctionSamples &Other) const
static constexpr const char * PartSuffix
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.
const FunctionSamplesMap * findFunctionSamplesMapAt(const LineLocation &Loc) const
Returns the FunctionSamplesMap at the given Loc.
void removeAllCallsiteSamples()
uint64_t getMaxCountInside(bool SkipCallSite=false) const
Return the maximum of sample counts in a function body.
void removeTotalSamples(uint64_t Num)
uint64_t getHeadSamples() const
For top-level functions, return the total number of branch samples that have the function as the bran...
void setFunction(FunctionId NewFunctionID)
Set the name of the function.
ErrorOr< uint64_t > findSamplesAt(uint32_t LineOffset, uint32_t Discriminator) const
Return the number of samples collected at the given location.
ErrorOr< const SampleRecord::CallTargetMap & > findCallTargetMapAt(const LineLocation &CallSite) const
Returns the call target map collected at a given location specified by CallSite.
const LineLocation & mapIRLocToProfileLoc(const LineLocation &IRLoc) const
FunctionId getFunction() const
Return the function name.
uint64_t getFunctionHash() const
static constexpr const char * LLVMSuffix
Name suffixes which canonicalization should handle to avoid profile mismatch.
StringRef getFuncName(FunctionId Func) const
Translate Func into its original name.
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight=1)
sampleprof_error addSampleRecord(LineLocation Location, const SampleRecord &SampleRecord, uint64_t Weight=1)
uint64_t removeCalledTargetAndBodySample(uint32_t LineOffset, uint32_t Discriminator, FunctionId Func)
DenseMap< uint64_t, StringRef > * GUIDToFuncNameMap
GUIDToFuncNameMap saves the mapping from GUID to the symbol name, for all the function symbols define...
sampleprof_error addCalledTargetSamples(uint32_t LineOffset, uint32_t Discriminator, FunctionId Func, uint64_t Num, uint64_t Weight=1)
FunctionSamplesMap & functionSamplesAt(const LineLocation &Loc)
Return the function samples at the given callsite location.
const FunctionSamples * findFunctionSamples(const DILocation *DIL, SampleProfileReaderItaniumRemapper *Remapper=nullptr, const HashKeyMap< std::unordered_map, FunctionId, FunctionId > *FuncNameToProfNameMap=nullptr) const
Get the FunctionSamples of the inline instance where DIL originates from.
static bool ProfileIsProbeBased
void setIRToProfileLocationMap(const LocToLocMap *LTLM)
static StringRef getCanonicalFnName(const Function &F)
Return the canonical name for a function, taking into account suffix elision policy attributes.
StringRef getFuncName() const
Return the original function name.
void findAllNames(DenseSet< FunctionId > &NameSet) const
sampleprof_error addBodySamples(uint32_t LineOffset, uint32_t Discriminator, uint64_t Num, uint64_t Weight=1)
static unsigned getOffset(const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
void setContextSynthetic()
void setFunctionHash(uint64_t Hash)
static bool ProfileIsFS
If this profile uses flow sensitive discriminators.
ErrorOr< const SampleRecord::CallTargetMap & > findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const
Returns the call target map collected at a given location.
SampleContext & getContext() const
static bool HasUniqSuffix
Whether the profile contains any ".__uniq." suffix in a name.
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
void print(raw_ostream &OS=dbgs(), unsigned Indent=0) const
Print the samples collected for a function on stream OS.
sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight=1)
Merge the samples in Other into this one.
FunctionSamples()=default
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
void setContext(const SampleContext &FContext)
static LineLocation getCallSiteIdentifier(const DILocation *DIL, bool ProfileIsFS=false)
Returns a unique call site identifier for a given debug location of a call instruction.
uint64_t getHeadSamplesEstimate() const
Return an estimate of the sample count of the function entry basic block.
uint64_t getGUID() const
Return the GUID of the context's name.
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
static bool UseMD5
Whether the profile uses MD5 to represent string.
This class is a wrapper to associative container MapT<KeyT, ValueT> using the hash value of the origi...
std::pair< iterator, bool > try_emplace(const key_type &Hash, const original_key_type &Key, Ts &&...Args)
typename base_type::iterator iterator
decltype(hash_value(SampleContext())) key_type
size_t erase(const original_key_type &Ctx)
iterator find(const original_key_type &Key)
typename base_type::const_iterator const_iterator
Helper class for profile conversion.
static void flattenProfile(SampleProfileMap &ProfileMap, bool ProfileIsCS=false)
static void flattenProfile(const SampleProfileMap &InputProfiles, SampleProfileMap &OutputProfiles, bool ProfileIsCS=false)
ProfileSymbolList records the list of function symbols shown up in the binary used to generate the pr...
void setToCompress(bool TC)
void add(StringRef Name, bool Copy=false)
copy indicates whether we need to copy the underlying memory for the input Name.
std::error_code write(raw_ostream &OS)
void dump(raw_ostream &OS=dbgs()) const
void merge(const ProfileSymbolList &List)
bool contains(StringRef Name)
std::error_code read(const uint8_t *Data, uint64_t ListSize)
SampleContextTrimmer impelements helper functions to trim, merge cold context profiles.
SampleContextTrimmer(SampleProfileMap &Profiles)
void trimAndMergeColdContextProfiles(uint64_t ColdCountThreshold, bool TrimColdContext, bool MergeColdContext, uint32_t ColdContextFrameLength, bool TrimBaseProfileOnly)
static void createCtxVectorFromStr(StringRef ContextStr, SampleContextFrameVector &Context)
Create a context vector from a given context string and save it in Context.
bool operator==(const SampleContext &That) const
void setFunction(FunctionId NewFunctionID)
Set the name of the function and clear the current context.
SampleContext(SampleContextFrames Context, ContextStateMask CState=RawContext)
bool operator<(const SampleContext &That) const
SampleContext(StringRef ContextStr, std::list< SampleContextFrameVector > &CSNameTable, ContextStateMask CState=RawContext)
bool hasState(ContextStateMask S)
void clearState(ContextStateMask S)
SampleContextFrames getContextFrames() const
SampleContext(FunctionId Func)
bool isBaseContext() const
static void decodeContextString(StringRef ContextStr, FunctionId &Func, LineLocation &LineLoc)
static std::string getContextString(SampleContextFrames Context, bool IncludeLeafLineLocation=false)
bool operator!=(const SampleContext &That) const
void setState(ContextStateMask S)
void setAllAttributes(uint32_t A)
uint64_t getHashCode() const
void setContext(SampleContextFrames Context, ContextStateMask CState=RawContext)
FunctionId getFunction() const
uint32_t getAllAttributes()
void setAttribute(ContextAttributeMask A)
bool hasAttribute(ContextAttributeMask A)
std::string toString() const
SampleContext(StringRef Name)
bool isPrefixOf(const SampleContext &That) const
This class provides operator overloads to the map container using MD5 as the key type,...
iterator find(const SampleContext &Ctx)
mapped_type & create(const SampleContext &Ctx)
iterator erase(iterator It)
size_t erase(const key_type &Key)
const_iterator find(const SampleContext &Ctx) const
size_t erase(const SampleContext &Ctx)
SampleProfileReaderItaniumRemapper remaps the profile data from a sample profile data reader,...
Representation of a single sample record.
std::unordered_map< FunctionId, uint64_t > CallTargetMap
bool hasCalls() const
Return true if this sample record contains function calls.
sampleprof_error merge(const SampleRecord &Other, uint64_t Weight=1)
Merge the samples in Other into this record.
static const SortedCallTargetSet sortCallTargets(const CallTargetMap &Targets)
Sort call targets in descending order of call frequency.
const CallTargetMap & getCallTargets() const
std::set< CallTarget, CallTargetComparator > SortedCallTargetSet
uint64_t getSamples() const
uint64_t getCallTargetSum() const
uint64_t removeSamples(uint64_t S)
Decrease the number of samples for this record by S.
sampleprof_error addSamples(uint64_t S, uint64_t Weight=1)
Increment the number of samples for this record by S.
uint64_t removeCalledTarget(FunctionId F)
Remove called function from the call target map.
const SortedCallTargetSet getSortedCallTargets() const
static const CallTargetMap adjustCallTargets(const CallTargetMap &Targets, float DistributionFactor)
Prorate call targets by a distribution factor.
std::pair< FunctionId, uint64_t > CallTarget
bool operator!=(const SampleRecord &Other) const
bool operator==(const SampleRecord &Other) const
void print(raw_ostream &OS, unsigned Indent) const
Print the sample record to the stream OS indented by Indent.
sampleprof_error addCalledTarget(FunctionId F, uint64_t S, uint64_t Weight=1)
Add called function F with samples S.
Sort a LocationT->SampleT map by LocationT.
std::pair< const LocationT, SampleT > SamplesWithLoc
SampleSorter(const std::map< LocationT, SampleT > &Samples)
const SamplesWithLocList & get() const
SmallVector< const SamplesWithLoc *, 20 > SamplesWithLocList
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
static FunctionId getRepInFormat(StringRef Name)
Get the proper representation of a string according to whether the current Format uses MD5 to represe...
static void verifySecFlag(SecType Type, SecFlagType Flag)
ArrayRef< SampleContextFrame > SampleContextFrames
void sortFuncProfiles(const SampleProfileMap &ProfileMap, std::vector< NameFunctionSamples > &SortedProfiles)
static uint64_t SPMagic(SampleProfileFormat Format=SPF_Binary)
std::unordered_map< LineLocation, LineLocation, LineLocationHash > LocToLocMap
std::pair< hash_code, const FunctionSamples * > NameFunctionSamples
static void addSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
static bool hasSecFlag(const SecHdrTableEntry &Entry, SecFlagType Flag)
std::map< LineLocation, FunctionSamplesMap > CallsiteSampleMap
@ ContextDuplicatedIntoBase
std::map< LineLocation, SampleRecord > BodySampleMap
@ SecFlagIsPreInlined
SecFlagIsPreInlined means this profile contains ShouldBeInlined contexts thus this is CS preinliner c...
@ SecFlagPartial
SecFlagPartial means the profile is for common/shared code.
@ SecFlagFSDiscriminator
SecFlagFSDiscriminator means this profile uses flow-sensitive discriminators.
@ SecFlagFullContext
SecFlagContext means this is context-sensitive flat profile for CSSPGO.
static void removeSecFlag(SecHdrTableEntry &Entry, SecFlagType Flag)
std::map< FunctionId, FunctionSamples > FunctionSamplesMap
raw_ostream & operator<<(raw_ostream &OS, const FunctionId &Obj)
static std::string getSecName(SecType Type)
uint64_t hash_value(const FunctionId &Obj)
static uint64_t SPVersion()
This is an optimization pass for GlobalISel generic memory operations.
void stable_sort(R &&Range)
std::error_code make_error_code(BitcodeError E)
sampleprof_error mergeSampleProfErrors(sampleprof_error &Accumulator, sampleprof_error Result)
@ unsupported_writing_format
@ ostream_seek_unsupported
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
const std::error_category & sampleprof_category()
std::string getUniqueInternalLinkagePostfix(const StringRef &FName)
const char * toString(DWARFSectionKind Kind)
hash_code hash_combine_range(InputIteratorT first, InputIteratorT last)
Compute a hash_code for a sequence of values.
Implement std::hash so that hash_code can be used in STL containers.
static unsigned getHashValue(const SampleContext &Val)
static SampleContext getTombstoneKey()
static SampleContext getEmptyKey()
static bool isEqual(const SampleContext &LHS, const SampleContext &RHS)
An information struct used to provide DenseMap with the various necessary components for a given valu...
uint64_t operator()(const LineLocation &Loc) const
Represents the relative location of an instruction.
void print(raw_ostream &OS) const
LineLocation(uint32_t L, uint32_t D)
bool operator!=(const LineLocation &O) const
bool operator<(const LineLocation &O) const
uint64_t getHashCode() const
bool operator==(const LineLocation &O) const
FunctionSamples * FuncSamples
FrameNode(FunctionId FName=FunctionId(), FunctionSamples *FSamples=nullptr, LineLocation CallLoc={0, 0})
FrameNode * getOrCreateChildFrame(const LineLocation &CallSite, FunctionId CalleeName)
std::map< uint64_t, FrameNode > AllChildFrames
uint64_t operator()(const SampleContextFrameVector &S) const
bool operator==(const SampleContextFrame &That) const
SampleContextFrame(FunctionId Func, LineLocation Location)
bool operator!=(const SampleContextFrame &That) const
std::string toString(bool OutputLineLocation) const
uint64_t getHashCode() const
uint64_t operator()(const SampleContext &Context) const
bool operator()(const CallTarget &LHS, const CallTarget &RHS) const