15 #ifndef LLVM_PROFILEDATA_SAMPLEPROF_H 16 #define LLVM_PROFILEDATA_SAMPLEPROF_H 32 #include <system_error> 79 namespace sampleprof {
90 return uint64_t(
'S') << (64 - 8) | uint64_t(
'P') << (64 - 16) |
91 uint64_t(
'R') << (64 - 24) | uint64_t(
'O') << (64 - 32) |
92 uint64_t(
'F') << (64 - 40) | uint64_t(
'4') << (64 - 48) |
93 uint64_t(
'2') << (64 - 56) | uint64_t(
Format);
99 std::string &GUIDBuf) {
168 uint64_t Weight = 1) {
169 uint64_t &TargetSamples = CallTargets[
F];
178 bool hasCalls()
const {
return !CallTargets.empty(); }
188 MergeResult(Result, addCalledTarget(
I.first(),
I.second, Weight));
197 uint64_t NumSamples = 0;
240 uint64_t Num, uint64_t Weight = 1) {
241 return BodySamples[
LineLocation(LineOffset, Discriminator)].addSamples(
248 uint64_t Weight = 1) {
249 return BodySamples[
LineLocation(LineOffset, Discriminator)].addCalledTarget(
258 const auto &ret = BodySamples.find(
LineLocation(LineOffset, Discriminator));
259 if (ret == BodySamples.end())
260 return std::error_code();
262 return ret->second.getSamples();
270 const auto &ret = BodySamples.find(
LineLocation(LineOffset, Discriminator));
271 if (ret == BodySamples.end())
272 return std::error_code();
273 return ret->second.getCallTargets();
278 return CallsiteSamples[Loc];
284 auto iter = CallsiteSamples.find(Loc);
285 if (iter == CallsiteSamples.end())
287 return &iter->second;
296 auto iter = CallsiteSamples.find(Loc);
297 if (iter == CallsiteSamples.end())
299 auto FS = iter->second.find(CalleeName);
300 if (FS != iter->second.end())
304 uint64_t MaxTotalSamples = 0;
306 for (
const auto &NameFS : iter->second)
307 if (NameFS.second.getTotalSamples() >= MaxTotalSamples) {
308 MaxTotalSamples = NameFS.second.getTotalSamples();
314 bool empty()
const {
return TotalSamples == 0; }
331 if (!BodySamples.empty() &&
332 (CallsiteSamples.empty() ||
333 BodySamples.begin()->first < CallsiteSamples.begin()->first))
334 return BodySamples.begin()->second.getSamples();
335 if (!CallsiteSamples.empty()) {
339 for (
const auto &N_FS : CallsiteSamples.begin()->second)
340 T += N_FS.second.getEntrySamples();
351 return CallsiteSamples;
364 MergeResult(Result, BodySamples[Loc].merge(Rec, Weight));
369 for (
const auto &Rec :
I.second)
370 MergeResult(Result, FSMap[Rec.first].merge(Rec.second, Weight));
380 uint64_t
Threshold,
bool isCompact)
const {
381 if (TotalSamples <= Threshold)
386 for (
const auto &BS : BodySamples)
387 for (
const auto &TS : BS.second.getCallTargets())
391 S.
insert(isCompact ? std::stol(TS.getKey().data())
394 for (
const auto &CS : CallsiteSamples)
395 for (
const auto &NameFS : CS.second)
396 NameFS.second.findInlinedFunctions(S, M, Threshold, isCompact);
428 uint64_t TotalSamples = 0;
433 uint64_t TotalHeadSamples = 0;
473 for (
const auto &
I : Samples)
475 std::stable_sort(V.begin(), V.end(),
477 return A->first <
B->first;
490 #endif // LLVM_PROFILEDATA_SAMPLEPROF_H const FunctionSamplesMap * findFunctionSamplesMapAt(const LineLocation &Loc) const
Returns the FunctionSamplesMap at the given Loc.
Represents either an error or a value T.
Compute iterated dominance frontiers using a linear time algorithm.
static StringRef getRepInFormat(StringRef Name, SampleProfileFormat Format, std::string &GUIDBuf)
A Module instance is used to store all the information related to an LLVM module. ...
Implements a dense probed hash-table based set.
sampleprof_error merge(const SampleRecord &Other, uint64_t Weight=1)
Merge the samples in Other into this record.
LineLocation(uint32_t L, uint32_t D)
SampleSorter(const std::map< LocationT, SampleT > &Samples)
ErrorOr< uint64_t > findSamplesAt(uint32_t LineOffset, uint32_t Discriminator) const
Return the number of samples collected at the given location.
std::pair< const LocationT, SampleT > SamplesWithLoc
const StringRef & getName() const
Return the function name.
bool operator<(const LineLocation &O) const
Representation of the samples collected for a function.
std::error_code make_error_code(BitcodeError E)
sampleprof_error addCalledTarget(StringRef F, uint64_t S, uint64_t Weight=1)
Add called function F with samples S.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
Representation of a single sample record.
void setName(StringRef FunctionName)
Set the name of the function.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
std::map< LineLocation, SampleRecord > BodySampleMap
static uint64_t SPVersion()
amdgpu Simplify well known AMD library false Value * Callee
Sort a LocationT->SampleT map by LocationT.
uint64_t getHeadSamples() const
Return the total number of branch samples that have the function as the branch target.
uint64_t getSamples() const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
void findInlinedFunctions(DenseSet< GlobalValue::GUID > &S, const Module *M, uint64_t Threshold, bool isCompact) const
Recursively traverses all children, if the total sample count of the corresponding function is no les...
DISubprogram * getSubprogram() const
Get the attached subprogram.
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
sampleprof_error addBodySamples(uint32_t LineOffset, uint32_t Discriminator, uint64_t Num, uint64_t Weight=1)
sampleprof_error addSamples(uint64_t S, uint64_t Weight=1)
Increment the number of samples for this record by S.
std::pair< iterator, bool > insert(const ValueT &V)
static ManagedStatic< _object_error_category > error_category
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
std::enable_if< std::is_unsigned< T >::value, T >::type 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 FunctionSamples * findFunctionSamplesAt(const LineLocation &Loc, StringRef CalleeName) 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)
Module.h This file contains the declarations for the Module class.
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
FunctionSamplesMap & functionSamplesAt(const LineLocation &Loc)
Return the function samples at the given callsite location.
ErrorOr< SampleRecord::CallTargetMap > findCallTargetMapAt(uint32_t LineOffset, uint32_t Discriminator) const
Returns the call target map collected at a given location.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
const std::error_category & sampleprof_category()
GUID getGUID() const
Return a 64-bit global unique ID constructed from global value name (i.e.
bool hasCalls() const
Return true if this sample record contains function calls.
std::map< LineLocation, FunctionSamplesMap > CallsiteSampleMap
Represents the relative location of an instruction.
std::map< std::string, FunctionSamples > FunctionSamplesMap
const CallTargetMap & getCallTargets() const
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
static uint64_t SPMagic(SampleProfileFormat Format=SPF_Binary)
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight=1)
const std::string to_string(const T &Value)
Provides ErrorOr<T> smart pointer.
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
const CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
This class implements an extremely fast bulk output stream that can only output to a stream...
StringRef - Represent a constant reference to a string, i.e.
uint64_t getEntrySamples() const
Return the sample count of the first instruction of the function.
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight=1)
Merge the samples in Other into this one.
sampleprof_error addCalledTargetSamples(uint32_t LineOffset, uint32_t Discriminator, StringRef FName, uint64_t Num, uint64_t Weight=1)
sampleprof_error MergeResult(sampleprof_error &Accumulator, sampleprof_error Result)