2014-10-30 19:00:06 +01:00
|
|
|
//=-- SampleProf.h - Sampling profiling format support --------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file contains common definitions used in the reading and writing of
|
|
|
|
// sample profile data.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2015-11-04 23:32:32 +01:00
|
|
|
|
2014-10-30 19:00:06 +01:00
|
|
|
#ifndef LLVM_PROFILEDATA_SAMPLEPROF_H_
|
|
|
|
#define LLVM_PROFILEDATA_SAMPLEPROF_H_
|
|
|
|
|
|
|
|
#include "llvm/ADT/SmallVector.h"
|
2014-11-01 01:56:55 +01:00
|
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm/Support/Debug.h"
|
2015-09-29 20:28:15 +02:00
|
|
|
#include "llvm/Support/ErrorOr.h"
|
2014-10-30 19:00:06 +01:00
|
|
|
#include "llvm/Support/raw_ostream.h"
|
2015-12-12 00:21:38 +01:00
|
|
|
|
|
|
|
#include <map>
|
2014-10-30 19:00:06 +01:00
|
|
|
#include <system_error>
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
const std::error_category &sampleprof_category();
|
|
|
|
|
|
|
|
enum class sampleprof_error {
|
|
|
|
success = 0,
|
|
|
|
bad_magic,
|
|
|
|
unsupported_version,
|
|
|
|
too_large,
|
|
|
|
truncated,
|
2014-11-01 01:56:55 +01:00
|
|
|
malformed,
|
2015-09-17 02:17:24 +02:00
|
|
|
unrecognized_format,
|
2015-10-14 00:48:46 +02:00
|
|
|
unsupported_writing_format,
|
|
|
|
truncated_name_table,
|
2015-12-16 22:45:43 +01:00
|
|
|
not_implemented,
|
|
|
|
counter_overflow
|
2014-10-30 19:00:06 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
inline std::error_code make_error_code(sampleprof_error E) {
|
|
|
|
return std::error_code(static_cast<int>(E), sampleprof_category());
|
|
|
|
}
|
|
|
|
|
2015-12-16 22:45:43 +01:00
|
|
|
inline sampleprof_error MergeResult(sampleprof_error &Accumulator,
|
|
|
|
sampleprof_error Result) {
|
|
|
|
// Prefer first error encountered as later errors may be secondary effects of
|
|
|
|
// the initial problem.
|
|
|
|
if (Accumulator == sampleprof_error::success &&
|
|
|
|
Result != sampleprof_error::success)
|
|
|
|
Accumulator = Result;
|
|
|
|
return Accumulator;
|
|
|
|
}
|
|
|
|
|
2014-10-30 19:00:06 +01:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
namespace std {
|
|
|
|
template <>
|
|
|
|
struct is_error_code_enum<llvm::sampleprof_error> : std::true_type {};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
|
|
|
namespace sampleprof {
|
|
|
|
|
|
|
|
static inline uint64_t SPMagic() {
|
|
|
|
return uint64_t('S') << (64 - 8) | uint64_t('P') << (64 - 16) |
|
|
|
|
uint64_t('R') << (64 - 24) | uint64_t('O') << (64 - 32) |
|
|
|
|
uint64_t('F') << (64 - 40) | uint64_t('4') << (64 - 48) |
|
|
|
|
uint64_t('2') << (64 - 56) | uint64_t(0xff);
|
|
|
|
}
|
|
|
|
|
2016-02-19 04:15:33 +01:00
|
|
|
static inline uint64_t SPVersion() { return 103; }
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Represents the relative location of an instruction.
|
2014-10-30 19:00:06 +01:00
|
|
|
///
|
|
|
|
/// Instruction locations are specified by the line offset from the
|
|
|
|
/// beginning of the function (marked by the line where the function
|
|
|
|
/// header is) and the discriminator value within that line.
|
|
|
|
///
|
|
|
|
/// The discriminator value is useful to distinguish instructions
|
|
|
|
/// that are on the same line but belong to different basic blocks
|
|
|
|
/// (e.g., the two post-increment instructions in "if (p) x++; else y++;").
|
|
|
|
struct LineLocation {
|
2015-10-15 18:36:21 +02:00
|
|
|
LineLocation(uint32_t L, uint32_t D) : LineOffset(L), Discriminator(D) {}
|
2015-11-17 20:04:46 +01:00
|
|
|
void print(raw_ostream &OS) const;
|
|
|
|
void dump() const;
|
2015-11-19 16:33:08 +01:00
|
|
|
bool operator<(const LineLocation &O) const {
|
|
|
|
return LineOffset < O.LineOffset ||
|
|
|
|
(LineOffset == O.LineOffset && Discriminator < O.Discriminator);
|
|
|
|
}
|
2015-11-13 21:24:28 +01:00
|
|
|
|
2015-10-15 18:36:21 +02:00
|
|
|
uint32_t LineOffset;
|
|
|
|
uint32_t Discriminator;
|
2014-10-30 19:00:06 +01:00
|
|
|
};
|
|
|
|
|
2015-11-17 20:04:46 +01:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const LineLocation &Loc);
|
2015-11-13 21:24:28 +01:00
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Representation of a single sample record.
|
2014-10-30 19:00:06 +01:00
|
|
|
///
|
|
|
|
/// A sample record is represented by a positive integer value, which
|
|
|
|
/// indicates how frequently was the associated line location executed.
|
|
|
|
///
|
|
|
|
/// Additionally, if the associated location contains a function call,
|
|
|
|
/// the record will hold a list of all the possible called targets. For
|
|
|
|
/// direct calls, this will be the exact function being invoked. For
|
|
|
|
/// indirect calls (function pointers, virtual table dispatch), this
|
|
|
|
/// will be a list of one or more functions.
|
|
|
|
class SampleRecord {
|
|
|
|
public:
|
2015-10-15 18:36:21 +02:00
|
|
|
typedef StringMap<uint64_t> CallTargetMap;
|
2014-10-30 19:00:06 +01:00
|
|
|
|
|
|
|
SampleRecord() : NumSamples(0), CallTargets() {}
|
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Increment the number of samples for this record by \p S.
|
2015-12-15 18:37:09 +01:00
|
|
|
/// Optionally scale sample count \p S by \p Weight.
|
2014-11-01 01:56:55 +01:00
|
|
|
///
|
|
|
|
/// Sample counts accumulate using saturating arithmetic, to avoid wrapping
|
|
|
|
/// around unsigned integers.
|
2015-12-16 22:45:43 +01:00
|
|
|
sampleprof_error addSamples(uint64_t S, uint64_t Weight = 1) {
|
2015-12-15 18:37:09 +01:00
|
|
|
bool Overflowed;
|
2016-01-12 23:34:00 +01:00
|
|
|
NumSamples = SaturatingMultiplyAdd(S, Weight, NumSamples, &Overflowed);
|
|
|
|
return Overflowed ? sampleprof_error::counter_overflow
|
|
|
|
: sampleprof_error::success;
|
2015-12-15 18:37:09 +01:00
|
|
|
}
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Add called function \p F with samples \p S.
|
2015-12-15 18:37:09 +01:00
|
|
|
/// Optionally scale sample count \p S by \p Weight.
|
2014-11-01 01:56:55 +01:00
|
|
|
///
|
|
|
|
/// Sample counts accumulate using saturating arithmetic, to avoid wrapping
|
|
|
|
/// around unsigned integers.
|
2015-12-16 22:45:43 +01:00
|
|
|
sampleprof_error addCalledTarget(StringRef F, uint64_t S,
|
|
|
|
uint64_t Weight = 1) {
|
2015-10-15 18:36:21 +02:00
|
|
|
uint64_t &TargetSamples = CallTargets[F];
|
2015-12-15 18:37:09 +01:00
|
|
|
bool Overflowed;
|
2016-01-12 23:34:00 +01:00
|
|
|
TargetSamples =
|
|
|
|
SaturatingMultiplyAdd(S, Weight, TargetSamples, &Overflowed);
|
|
|
|
return Overflowed ? sampleprof_error::counter_overflow
|
|
|
|
: sampleprof_error::success;
|
2014-10-30 19:00:06 +01:00
|
|
|
}
|
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Return true if this sample record contains function calls.
|
2014-10-30 19:00:06 +01:00
|
|
|
bool hasCalls() const { return CallTargets.size() > 0; }
|
|
|
|
|
2015-10-15 18:36:21 +02:00
|
|
|
uint64_t getSamples() const { return NumSamples; }
|
2014-11-01 01:56:55 +01:00
|
|
|
const CallTargetMap &getCallTargets() const { return CallTargets; }
|
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Merge the samples in \p Other into this record.
|
2015-12-15 18:37:09 +01:00
|
|
|
/// Optionally scale sample counts by \p Weight.
|
2015-12-16 22:45:43 +01:00
|
|
|
sampleprof_error merge(const SampleRecord &Other, uint64_t Weight = 1) {
|
|
|
|
sampleprof_error Result = addSamples(Other.getSamples(), Weight);
|
|
|
|
for (const auto &I : Other.getCallTargets()) {
|
|
|
|
MergeResult(Result, addCalledTarget(I.first(), I.second, Weight));
|
|
|
|
}
|
|
|
|
return Result;
|
2014-11-01 01:56:55 +01:00
|
|
|
}
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-11-13 21:24:28 +01:00
|
|
|
void print(raw_ostream &OS, unsigned Indent) const;
|
2015-11-17 20:04:46 +01:00
|
|
|
void dump() const;
|
2015-11-13 21:24:28 +01:00
|
|
|
|
2014-10-30 19:00:06 +01:00
|
|
|
private:
|
2015-10-15 18:36:21 +02:00
|
|
|
uint64_t NumSamples;
|
2014-11-01 01:56:55 +01:00
|
|
|
CallTargetMap CallTargets;
|
2014-10-30 19:00:06 +01:00
|
|
|
};
|
|
|
|
|
2015-11-17 20:04:46 +01:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const SampleRecord &Sample);
|
2015-11-13 21:24:28 +01:00
|
|
|
|
2015-12-12 00:21:38 +01:00
|
|
|
typedef std::map<LineLocation, SampleRecord> BodySampleMap;
|
2015-09-30 02:42:46 +02:00
|
|
|
class FunctionSamples;
|
2016-03-03 19:09:32 +01:00
|
|
|
typedef std::map<LineLocation, FunctionSamples> CallsiteSampleMap;
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Representation of the samples collected for a function.
|
2014-10-30 19:00:06 +01:00
|
|
|
///
|
|
|
|
/// This data structure contains all the collected samples for the body
|
|
|
|
/// of a function. Each sample corresponds to a LineLocation instance
|
|
|
|
/// within the body of the function.
|
|
|
|
class FunctionSamples {
|
|
|
|
public:
|
2016-03-03 19:09:32 +01:00
|
|
|
FunctionSamples() : Name(), TotalSamples(0), TotalHeadSamples(0) {}
|
2015-10-08 21:40:37 +02:00
|
|
|
void print(raw_ostream &OS = dbgs(), unsigned Indent = 0) const;
|
2015-11-17 20:04:46 +01:00
|
|
|
void dump() const;
|
2015-12-16 22:45:43 +01:00
|
|
|
sampleprof_error addTotalSamples(uint64_t Num, uint64_t Weight = 1) {
|
2015-12-15 18:37:09 +01:00
|
|
|
bool Overflowed;
|
2016-01-12 23:34:00 +01:00
|
|
|
TotalSamples =
|
|
|
|
SaturatingMultiplyAdd(Num, Weight, TotalSamples, &Overflowed);
|
|
|
|
return Overflowed ? sampleprof_error::counter_overflow
|
|
|
|
: sampleprof_error::success;
|
2015-12-15 18:37:09 +01:00
|
|
|
}
|
2015-12-16 22:45:43 +01:00
|
|
|
sampleprof_error addHeadSamples(uint64_t Num, uint64_t Weight = 1) {
|
2015-12-15 18:37:09 +01:00
|
|
|
bool Overflowed;
|
2016-01-12 23:34:00 +01:00
|
|
|
TotalHeadSamples =
|
|
|
|
SaturatingMultiplyAdd(Num, Weight, TotalHeadSamples, &Overflowed);
|
|
|
|
return Overflowed ? sampleprof_error::counter_overflow
|
|
|
|
: sampleprof_error::success;
|
2015-12-15 18:37:09 +01:00
|
|
|
}
|
2015-12-16 22:45:43 +01:00
|
|
|
sampleprof_error addBodySamples(uint32_t LineOffset, uint32_t Discriminator,
|
|
|
|
uint64_t Num, uint64_t Weight = 1) {
|
|
|
|
return BodySamples[LineLocation(LineOffset, Discriminator)].addSamples(
|
|
|
|
Num, Weight);
|
2014-10-30 19:00:06 +01:00
|
|
|
}
|
2015-12-16 22:45:43 +01:00
|
|
|
sampleprof_error addCalledTargetSamples(uint32_t LineOffset,
|
|
|
|
uint32_t Discriminator,
|
2016-06-08 21:09:22 +02:00
|
|
|
const std::string &FName,
|
|
|
|
uint64_t Num, uint64_t Weight = 1) {
|
2015-12-16 22:45:43 +01:00
|
|
|
return BodySamples[LineLocation(LineOffset, Discriminator)].addCalledTarget(
|
2015-12-15 18:37:09 +01:00
|
|
|
FName, Num, Weight);
|
2014-10-30 19:00:06 +01:00
|
|
|
}
|
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Return the number of samples collected at the given location.
|
2014-10-30 19:00:06 +01:00
|
|
|
/// Each location is specified by \p LineOffset and \p Discriminator.
|
2015-09-29 20:28:15 +02:00
|
|
|
/// If the location is not found in profile, return error.
|
2015-10-15 18:36:21 +02:00
|
|
|
ErrorOr<uint64_t> findSamplesAt(uint32_t LineOffset,
|
|
|
|
uint32_t Discriminator) const {
|
2015-09-29 20:28:15 +02:00
|
|
|
const auto &ret = BodySamples.find(LineLocation(LineOffset, Discriminator));
|
|
|
|
if (ret == BodySamples.end())
|
|
|
|
return std::error_code();
|
|
|
|
else
|
|
|
|
return ret->second.getSamples();
|
2014-10-30 19:00:06 +01:00
|
|
|
}
|
|
|
|
|
2016-09-19 18:06:37 +02:00
|
|
|
/// Return the total number of call target samples collected at a given
|
|
|
|
/// location. Each location is specified by \p LineOffset and
|
|
|
|
/// \p Discriminator. If the location is not found in profile, return error.
|
|
|
|
ErrorOr<uint64_t> findCallSamplesAt(uint32_t LineOffset,
|
|
|
|
uint32_t Discriminator) const {
|
|
|
|
const auto &ret = BodySamples.find(LineLocation(LineOffset, Discriminator));
|
|
|
|
if (ret == BodySamples.end())
|
|
|
|
return std::error_code();
|
|
|
|
uint64_t T = 0;
|
|
|
|
for (const auto &t_c : ret->second.getCallTargets()) {
|
|
|
|
T += t_c.second;
|
|
|
|
}
|
|
|
|
return T;
|
|
|
|
}
|
|
|
|
|
2015-09-30 02:42:46 +02:00
|
|
|
/// Return the function samples at the given callsite location.
|
2016-03-03 19:09:32 +01:00
|
|
|
FunctionSamples &functionSamplesAt(const LineLocation &Loc) {
|
2015-09-30 02:42:46 +02:00
|
|
|
return CallsiteSamples[Loc];
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Return a pointer to function samples at the given callsite location.
|
2016-03-03 19:09:32 +01:00
|
|
|
const FunctionSamples *findFunctionSamplesAt(const LineLocation &Loc) const {
|
2015-09-30 02:42:46 +02:00
|
|
|
auto iter = CallsiteSamples.find(Loc);
|
|
|
|
if (iter == CallsiteSamples.end()) {
|
2015-11-04 23:32:32 +01:00
|
|
|
return nullptr;
|
2015-09-30 02:42:46 +02:00
|
|
|
} else {
|
|
|
|
return &iter->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool empty() const { return TotalSamples == 0; }
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Return the total number of samples collected inside the function.
|
2015-10-15 18:36:21 +02:00
|
|
|
uint64_t getTotalSamples() const { return TotalSamples; }
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Return the total number of samples collected at the head of the
|
2014-10-30 19:00:06 +01:00
|
|
|
/// function.
|
2015-10-15 18:36:21 +02:00
|
|
|
uint64_t getHeadSamples() const { return TotalHeadSamples; }
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Return all the samples collected in the body of the function.
|
2014-10-30 19:00:06 +01:00
|
|
|
const BodySampleMap &getBodySamples() const { return BodySamples; }
|
|
|
|
|
2015-09-30 02:42:46 +02:00
|
|
|
/// Return all the callsite samples collected in the body of the function.
|
|
|
|
const CallsiteSampleMap &getCallsiteSamples() const {
|
|
|
|
return CallsiteSamples;
|
|
|
|
}
|
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Merge the samples in \p Other into this one.
|
2015-12-15 18:37:09 +01:00
|
|
|
/// Optionally scale samples by \p Weight.
|
2015-12-16 22:45:43 +01:00
|
|
|
sampleprof_error merge(const FunctionSamples &Other, uint64_t Weight = 1) {
|
|
|
|
sampleprof_error Result = sampleprof_error::success;
|
2016-03-03 19:09:32 +01:00
|
|
|
Name = Other.getName();
|
2015-12-16 22:45:43 +01:00
|
|
|
MergeResult(Result, addTotalSamples(Other.getTotalSamples(), Weight));
|
|
|
|
MergeResult(Result, addHeadSamples(Other.getHeadSamples(), Weight));
|
2014-11-01 01:56:55 +01:00
|
|
|
for (const auto &I : Other.getBodySamples()) {
|
|
|
|
const LineLocation &Loc = I.first;
|
|
|
|
const SampleRecord &Rec = I.second;
|
2015-12-16 22:45:43 +01:00
|
|
|
MergeResult(Result, BodySamples[Loc].merge(Rec, Weight));
|
2014-11-01 01:56:55 +01:00
|
|
|
}
|
2015-09-30 02:42:46 +02:00
|
|
|
for (const auto &I : Other.getCallsiteSamples()) {
|
2016-03-03 19:09:32 +01:00
|
|
|
const LineLocation &Loc = I.first;
|
2015-09-30 02:42:46 +02:00
|
|
|
const FunctionSamples &Rec = I.second;
|
2015-12-16 22:45:43 +01:00
|
|
|
MergeResult(Result, functionSamplesAt(Loc).merge(Rec, Weight));
|
2015-09-30 02:42:46 +02:00
|
|
|
}
|
2015-12-16 22:45:43 +01:00
|
|
|
return Result;
|
2014-11-01 01:56:55 +01:00
|
|
|
}
|
|
|
|
|
2016-03-03 19:09:32 +01:00
|
|
|
/// Set the name of the function.
|
|
|
|
void setName(StringRef FunctionName) { Name = FunctionName; }
|
|
|
|
|
|
|
|
/// Return the function name.
|
|
|
|
const StringRef &getName() const { return Name; }
|
|
|
|
|
2014-10-30 19:00:06 +01:00
|
|
|
private:
|
2016-03-03 19:09:32 +01:00
|
|
|
/// Mangled name of the function.
|
|
|
|
StringRef Name;
|
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Total number of samples collected inside this function.
|
2014-10-30 19:00:06 +01:00
|
|
|
///
|
|
|
|
/// Samples are cumulative, they include all the samples collected
|
|
|
|
/// inside this function and all its inlined callees.
|
2015-10-15 18:36:21 +02:00
|
|
|
uint64_t TotalSamples;
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Total number of samples collected at the head of the function.
|
|
|
|
/// This is an approximation of the number of calls made to this function
|
|
|
|
/// at runtime.
|
2015-10-15 18:36:21 +02:00
|
|
|
uint64_t TotalHeadSamples;
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-05-13 00:03:00 +02:00
|
|
|
/// Map instruction locations to collected samples.
|
2014-10-30 19:00:06 +01:00
|
|
|
///
|
|
|
|
/// Each entry in this map contains the number of samples
|
|
|
|
/// collected at the corresponding line offset. All line locations
|
|
|
|
/// are an offset from the start of the function.
|
|
|
|
BodySampleMap BodySamples;
|
2015-09-30 02:42:46 +02:00
|
|
|
|
2015-10-08 21:40:37 +02:00
|
|
|
/// Map call sites to collected samples for the called function.
|
|
|
|
///
|
|
|
|
/// Each entry in this map corresponds to all the samples
|
|
|
|
/// collected for the inlined function call at the given
|
|
|
|
/// location. For example, given:
|
|
|
|
///
|
|
|
|
/// void foo() {
|
|
|
|
/// 1 bar();
|
|
|
|
/// ...
|
|
|
|
/// 8 baz();
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// If the bar() and baz() calls were inlined inside foo(), this
|
|
|
|
/// map will contain two entries. One for all the samples collected
|
|
|
|
/// in the call to bar() at line offset 1, the other for all the samples
|
|
|
|
/// collected in the call to baz() at line offset 8.
|
2015-09-30 02:42:46 +02:00
|
|
|
CallsiteSampleMap CallsiteSamples;
|
2014-10-30 19:00:06 +01:00
|
|
|
};
|
|
|
|
|
2015-11-17 20:04:46 +01:00
|
|
|
raw_ostream &operator<<(raw_ostream &OS, const FunctionSamples &FS);
|
2015-11-13 21:24:28 +01:00
|
|
|
|
2015-11-19 16:33:08 +01:00
|
|
|
/// Sort a LocationT->SampleT map by LocationT.
|
|
|
|
///
|
|
|
|
/// It produces a sorted list of <LocationT, SampleT> records by ascending
|
|
|
|
/// order of LocationT.
|
|
|
|
template <class LocationT, class SampleT> class SampleSorter {
|
|
|
|
public:
|
2015-12-12 00:21:38 +01:00
|
|
|
typedef std::pair<const LocationT, SampleT> SamplesWithLoc;
|
2015-11-19 16:33:08 +01:00
|
|
|
typedef SmallVector<const SamplesWithLoc *, 20> SamplesWithLocList;
|
|
|
|
|
2015-12-12 00:21:38 +01:00
|
|
|
SampleSorter(const std::map<LocationT, SampleT> &Samples) {
|
2015-11-19 16:33:08 +01:00
|
|
|
for (const auto &I : Samples)
|
|
|
|
V.push_back(&I);
|
|
|
|
std::stable_sort(V.begin(), V.end(),
|
|
|
|
[](const SamplesWithLoc *A, const SamplesWithLoc *B) {
|
|
|
|
return A->first < B->first;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const SamplesWithLocList &get() const { return V; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
SamplesWithLocList V;
|
|
|
|
};
|
|
|
|
|
2015-11-04 23:32:32 +01:00
|
|
|
} // end namespace sampleprof
|
2014-10-30 19:00:06 +01:00
|
|
|
|
2015-11-04 23:32:32 +01:00
|
|
|
} // end namespace llvm
|
2014-10-30 19:00:06 +01:00
|
|
|
|
|
|
|
#endif // LLVM_PROFILEDATA_SAMPLEPROF_H_
|