15 #include "llvm/Config/llvm-config.h" 25 #include <system_error> 28 using namespace sampleprof;
31 namespace sampleprof {
42 const char *
name()
const noexcept
override {
return "llvm.sampleprof"; }
44 std::string message(
int IE)
const override {
50 return "Invalid sample profile data (bad magic)";
52 return "Unsupported sample profile format version";
54 return "Too much profile data";
56 return "Truncated profile data";
58 return "Malformed sample profile data";
60 return "Unrecognized sample profile encoding format";
62 return "Profile encoding format unsupported for writing operations";
64 return "Truncated function name table";
66 return "Unimplemented feature";
68 return "Counter overflow";
70 return "Ostream does not support seek";
72 return "Compress failure";
74 return "Uncompress failure";
76 return "Zlib is unavailable";
92 if (Discriminator > 0)
93 OS <<
"." << Discriminator;
102 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 111 for (
const auto &
I : getSortedCallTargets())
112 OS <<
" " <<
I.first <<
":" <<
I.second;
117 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 129 OS << TotalSamples <<
", " << TotalHeadSamples <<
", " << BodySamples.size()
130 <<
" sampled lines\n";
133 if (!BodySamples.empty()) {
134 OS <<
"Samples collected in the function's body {\n";
136 for (
const auto &
SI : SortedBodySamples.
get()) {
138 OS <<
SI->first <<
": " <<
SI->second;
143 OS <<
"No samples collected in the function's body\n";
147 if (!CallsiteSamples.empty()) {
148 OS <<
"Samples collected in inlined callsites {\n";
151 for (
const auto &CS : SortedCallsiteSamples.
get()) {
152 for (
const auto &
FS : CS->second) {
154 OS << CS->first <<
": inlined callee: " <<
FS.second.getName() <<
": ";
155 FS.second.print(OS, Indent + 4);
161 OS <<
"No inlined callsites in this function\n";
172 return (DIL->getLine() - DIL->getScope()->getSubprogram()->getLine()) &
182 for (DIL = DIL->getInlinedAt(); DIL; DIL = DIL->getInlinedAt()) {
185 PrevDIL->getScope()->getSubprogram()->getLinkageName()));
191 for (
int i = S.
size() - 1; i >= 0 && FS !=
nullptr; i--) {
197 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 203 const char *ListStart =
reinterpret_cast<const char *
>(Data);
205 while (Size < ListSize) {
208 Size += Str.
size() + 1;
210 if (Size != ListSize)
218 std::vector<StringRef> SortedList;
219 SortedList.insert(SortedList.begin(), Syms.begin(), Syms.end());
222 std::string OutputString;
223 for (
auto &Sym : SortedList) {
224 OutputString.append(Sym.str());
225 OutputString.append(1,
'\0');
233 OS <<
"======== Dump profile symbol list ========\n";
234 std::vector<StringRef> SortedList;
235 SortedList.insert(SortedList.begin(), Syms.begin(), Syms.end());
238 for (
auto &Sym : SortedList)
raw_ostream & operator<<(raw_ostream &OS, const LineLocation &Loc)
This class represents lattice values for constants.
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds...
void push_back(const T &Elt)
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
static SampleProfileFormat Format
Representation of the samples collected for a function.
void print(raw_ostream &OS=dbgs(), unsigned Indent=0) const
Print the samples collected for a function on stream OS.
void print(raw_ostream &OS, unsigned Indent) const
Print the sample record to the stream OS indented by Indent.
Representation of a single sample record.
LLVM_NODISCARD size_t size() const
size - Get the string size.
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
const SamplesWithLocList & get() const
Sort a LocationT->SampleT map by LocationT.
void dump(raw_ostream &OS=dbgs()) const
const FunctionSamples * findFunctionSamples(const DILocation *DIL) const
Get the FunctionSamples of the inline instance where DIL originates from.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static ManagedStatic< _object_error_category > error_category
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void sort(IteratorTy Start, IteratorTy End)
const FunctionSamples * findFunctionSamplesAt(const LineLocation &Loc, StringRef CalleeName) const
Returns a pointer to FunctionSamples at the given callsite location Loc with callee CalleeName...
static uint64_t add(uint64_t LeftOp, uint64_t RightOp)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
static unsigned getOffset(const DILocation *DIL)
Returns the line offset to the start line of the subprogram.
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
static ManagedStatic< SampleProfErrorCategoryType > ErrorCategory
unsigned getBaseDiscriminator() const
Returns the base discriminator stored in the discriminator.
Represents the relative location of an instruction.
std::error_code write(raw_ostream &OS)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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.
ManagedStatic - This transparently changes the behavior of global statics to be lazily constructed on...
std::error_code read(const uint8_t *Data, uint64_t ListSize)