15 #ifndef LLVM_PROFILEDATA_SAMPLEPROF_H_
16 #define LLVM_PROFILEDATA_SAMPLEPROF_H_
25 #include <system_error>
68 namespace sampleprof {
71 return uint64_t(
'S') << (64 - 8) | uint64_t(
'P') << (64 - 16) |
72 uint64_t(
'R') << (64 - 24) | uint64_t(
'O') << (64 - 32) |
73 uint64_t(
'F') << (64 - 40) | uint64_t(
'4') << (64 - 48) |
74 uint64_t(
'2') << (64 - 56) | uint64_t(0xff);
137 uint64_t Weight = 1) {
138 uint64_t &TargetSamples = CallTargets[
F];
201 uint64_t Num, uint64_t Weight = 1) {
202 return BodySamples[
LineLocation(LineOffset, Discriminator)].addSamples(
207 const std::string &FName,
208 uint64_t Num, uint64_t Weight = 1) {
209 return BodySamples[
LineLocation(LineOffset, Discriminator)].addCalledTarget(
218 const auto &ret = BodySamples.find(
LineLocation(LineOffset, Discriminator));
219 if (ret == BodySamples.end())
220 return std::error_code();
222 return ret->second.getSamples();
230 const auto &ret = BodySamples.find(
LineLocation(LineOffset, Discriminator));
231 if (ret == BodySamples.end())
232 return std::error_code();
234 for (
const auto &t_c : ret->second.getCallTargets()) {
242 return CallsiteSamples[Loc];
247 auto iter = CallsiteSamples.find(Loc);
248 if (iter == CallsiteSamples.end()) {
251 return &iter->second;
255 bool empty()
const {
return TotalSamples == 0; }
269 return CallsiteSamples;
306 uint64_t TotalSamples;
311 uint64_t TotalHeadSamples;
351 for (
const auto &
I : Samples)
353 std::stable_sort(V.
begin(), V.
end(),
355 return A->first <
B->first;
368 #endif // LLVM_PROFILEDATA_SAMPLEPROF_H_
void push_back(const T &Elt)
Represents either an error or a value T.
raw_ostream & operator<<(raw_ostream &OS, const LineLocation &Loc)
const BodySampleMap & getBodySamples() const
Return all the samples collected in the body of the function.
SmallVector< const SamplesWithLoc *, 20 > SamplesWithLocList
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)
const FunctionSamples * findFunctionSamplesAt(const LineLocation &Loc) const
Return a pointer to function samples at the given callsite location.
const StringRef & getName() const
Return the function name.
const CallTargetMap & getCallTargets() const
Representation of the samples collected for a function.
static GCRegistry::Add< StatepointGC > D("statepoint-example","an example strategy for statepoint")
std::error_code make_error_code(BitcodeError E)
uint64_t getHeadSamples() const
Return the total number of samples collected at the head of the function.
ErrorOr< uint64_t > findCallSamplesAt(uint32_t LineOffset, uint32_t Discriminator) const
Return the total number of call target samples collected at a given location.
std::map< LineLocation, SampleRecord > BodySampleMap
std::map< LineLocation, FunctionSamples > CallsiteSampleMap
sampleprof_error addCalledTarget(StringRef F, uint64_t S, uint64_t Weight=1)
Add called function F with samples S.
Representation of a single sample record.
void setName(StringRef FunctionName)
Set the name of the function.
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
bool operator<(const LineLocation &O) const
static uint64_t SPVersion()
Sort a LocationT->SampleT map by LocationT.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
void print(raw_ostream &OS=dbgs(), unsigned Indent=0) const
Print the samples collected for a function on stream OS.
sampleprof_error addBodySamples(uint32_t LineOffset, uint32_t Discriminator, uint64_t Num, uint64_t Weight=1)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
sampleprof_error addSamples(uint64_t S, uint64_t Weight=1)
Increment the number of samples for this record by S.
static ManagedStatic< _object_error_category > error_category
uint64_t getTotalSamples() const
Return the total number of samples collected inside the function.
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 CallsiteSampleMap & getCallsiteSamples() const
Return all the callsite samples collected in the body of the function.
sampleprof_error addCalledTargetSamples(uint32_t LineOffset, uint32_t Discriminator, const std::string &FName, uint64_t Num, uint64_t Weight=1)
sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight=1)
std::pair< const LocationT, SampleT > SamplesWithLoc
uint64_t getSamples() const
StringMap< uint64_t > CallTargetMap
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
const std::error_category & sampleprof_category()
void print(raw_ostream &OS) const
bool hasCalls() const
Return true if this sample record contains function calls.
static uint64_t SPMagic()
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
Represents the relative location of an instruction.
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight=1)
Provides ErrorOr<T> smart pointer.
This class implements an extremely fast bulk output stream that can only output to a stream...
ErrorOr< uint64_t > findSamplesAt(uint32_t LineOffset, uint32_t Discriminator) const
Return the number of samples collected at the given location.
StringRef - Represent a constant reference to a string, i.e.
void print(raw_ostream &OS, unsigned Indent) const
Print the sample record to the stream OS indented by Indent.
static GCRegistry::Add< ErlangGC > A("erlang","erlang-compatible garbage collector")
sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight=1)
Merge the samples in Other into this one.
sampleprof_error MergeResult(sampleprof_error &Accumulator, sampleprof_error Result)
FunctionSamples & functionSamplesAt(const LineLocation &Loc)
Return the function samples at the given callsite location.