31#define DEBUG_TYPE "mcpseudoprobe"
34using namespace support;
54 assert((LastProbe || IsSentinel) &&
55 "Last probe should not be null for non-sentinel probes");
64 assert(
Type <= 0xF &&
"Probe type too big to encode, exceeding 15");
68 assert(NewAttributes <= 0x7 &&
69 "Probe attributes too big to encode, exceeding 7");
70 uint8_t PackedType =
Type | (NewAttributes << 4);
118 if (InlineStack.
empty()) {
128 if (!InlineStack.
empty()) {
129 auto Iter = InlineStack.
begin();
130 auto Index = std::get<1>(*Iter);
132 for (; Iter != InlineStack.
end(); Iter++) {
135 Index = std::get<1>(*Iter);
140 Cur->Probes.push_back(Probe);
147 dbgs() <<
"Group [\n";
150 assert(!
isRoot() &&
"Root should be handled separately");
161 bool NeedSentinel =
false;
164 "Starting probe of a top-level function should be a sentinel probe");
175 LastProbe->
emit(MCOS,
nullptr);
178 for (
const auto &Probe :
Probes) {
179 Probe.emit(MCOS, LastProbe);
185 using InlineeType = std::pair<InlineSite, MCPseudoProbeInlineTree *>;
186 std::vector<InlineeType> Inlinees;
188 Inlinees.emplace_back(Child.first, Child.second.get());
191 for (
const auto &Inlinee : Inlinees) {
196 dbgs() <<
"InlineSite: " << std::get<1>(Inlinee.first) <<
"\n";
199 Inlinee.second->emit(MCOS, LastProbe);
212 Vec.
reserve(MCProbeDivisions.size());
213 for (
auto &ProbeSec : MCProbeDivisions)
216 I.value().setOrdinal(
I.index());
218 return A.first->getSection().getOrdinal() <
219 B.first->getSection().getOrdinal();
221 for (
auto [FuncSym, RootPtr] : Vec) {
222 const auto &Root = *RootPtr;
224 FuncSym->getSection())) {
230 using InlineeType = std::pair<InlineSite, MCPseudoProbeInlineTree *>;
231 std::vector<InlineeType> Inlinees;
232 for (
const auto &Child : Root.getChildren())
233 Inlinees.emplace_back(Child.first, Child.second.get());
236 for (
const auto &Inlinee : Inlinees) {
244 Inlinee.second->emit(MCOS, Probe);
260 if (ProbeSections.empty())
266 ProbeSections.emit(MCOS);
271 auto It = GUID2FuncMAP.
find(GUID);
272 assert(It != GUID2FuncMAP.end() &&
273 "Probe function must exist for a valid GUID");
274 return It->second.FuncName;
296 std::reverse(ContextStack.
begin() + Begin, ContextStack.
end());
301 std::ostringstream OContextStr;
304 for (
auto &Cxt : ContextStack) {
305 if (OContextStr.str().size())
306 OContextStr <<
" @ ";
307 OContextStr << Cxt.first.str() <<
":" << Cxt.second;
309 return OContextStr.str();
317 bool ShowName)
const {
321 OS << FuncName.
str() <<
" ";
325 OS <<
"Index: " <<
Index <<
" ";
330 if (InlineContextStr.size()) {
332 OS << InlineContextStr;
337template <
typename T>
ErrorOr<T> MCPseudoProbeDecoder::readUnencodedNumber() {
338 if (Data +
sizeof(
T) > End) {
339 return std::error_code();
341 T Val = endian::readNext<T, llvm::endianness::little>(Data);
345template <
typename T>
ErrorOr<T> MCPseudoProbeDecoder::readUnsignedNumber() {
346 unsigned NumBytesRead = 0;
348 if (Val > std::numeric_limits<T>::max() || (Data + NumBytesRead > End)) {
349 return std::error_code();
351 Data += NumBytesRead;
355template <
typename T>
ErrorOr<T> MCPseudoProbeDecoder::readSignedNumber() {
356 unsigned NumBytesRead = 0;
358 if (Val > std::numeric_limits<T>::max() || (Data + NumBytesRead > End)) {
359 return std::error_code();
361 Data += NumBytesRead;
367 if (Data +
Size > End) {
368 return std::error_code();
391 auto ErrorOrGUID = readUnencodedNumber<uint64_t>();
395 auto ErrorOrHash = readUnencodedNumber<uint64_t>();
399 auto ErrorOrNameSize = readUnsignedNumber<uint32_t>();
400 if (!ErrorOrNameSize)
404 auto ErrorOrName = readString(
NameSize);
408 uint64_t GUID = std::move(*ErrorOrGUID);
409 uint64_t Hash = std::move(*ErrorOrHash);
415 assert(Data == End &&
"Have unprocessed data in pseudo_probe_desc section");
426 bool IsTopLevelFunc = Cur == &DummyInlineRoot;
427 if (IsTopLevelFunc) {
432 auto ErrorOrIndex = readUnsignedNumber<uint32_t>();
435 Index = std::move(*ErrorOrIndex);
439 auto ErrorOrCurGuid = readUnencodedNumber<uint64_t>();
445 if (IsTopLevelFunc && !GuidFilter.
empty() && !GuidFilter.
count(
Guid))
453 if (IsTopLevelFunc && !EncodingIsAddrBased) {
460 auto ErrorOrNodeCount = readUnsignedNumber<uint32_t>();
461 if (!ErrorOrNodeCount)
463 uint32_t NodeCount = std::move(*ErrorOrNodeCount);
465 auto ErrorOrCurChildrenToProcess = readUnsignedNumber<uint32_t>();
466 if (!ErrorOrCurChildrenToProcess)
469 for (std::size_t
I = 0;
I < NodeCount;
I++) {
471 auto ErrorOrIndex = readUnsignedNumber<uint32_t>();
476 auto ErrorOrValue = readUnencodedNumber<uint8_t>();
479 uint8_t
Value = std::move(*ErrorOrValue);
480 uint8_t Kind =
Value & 0xf;
481 uint8_t Attr = (
Value & 0x70) >> 4;
485 auto ErrorOrOffset = readSignedNumber<int64_t>();
488 int64_t
Offset = std::move(*ErrorOrOffset);
491 auto ErrorOrAddr = readUnencodedNumber<int64_t>();
494 Addr = std::move(*ErrorOrAddr);
505 EncodingIsAddrBased =
true;
511 auto ErrorOrDiscriminator = readUnsignedNumber<uint32_t>();
512 if (!ErrorOrDiscriminator)
514 Discriminator = std::move(*ErrorOrDiscriminator);
519 auto &Probes = Address2ProbesMap[
Addr];
527 uint32_t ChildrenToProcess = std::move(*ErrorOrCurChildrenToProcess);
536 const uint8_t *Start, std::size_t
Size,
const Uint64Set &GuidFilter,
544 assert(Data == End &&
"Have unprocessed data in pseudo_probe section");
549 OS <<
"Pseudo Probe Desc:\n";
551 std::map<uint64_t, MCPseudoProbeFuncDesc> OrderedMap(GUID2FuncDescMap.begin(),
552 GUID2FuncDescMap.end());
553 for (
auto &
I : OrderedMap) {
560 auto It = Address2ProbesMap.find(
Address);
561 if (It != Address2ProbesMap.end()) {
564 Probe.
print(
OS, GUID2FuncDescMap,
true);
573 for (
auto K : Addresses) {
583 auto It = Address2ProbesMap.find(
Address);
584 if (It == Address2ProbesMap.end())
586 const auto &Probes = It->second;
590 if (Probe.isCall()) {
612 auto It = GUID2FuncDescMap.find(GUID);
613 assert(It != GUID2FuncDescMap.end() &&
"Function descriptor doesn't exist");
620 bool IncludeLeaf)
const {
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static const MCExpr * buildSymbolDiff(MCObjectStreamer &OS, const MCSymbol *A, const MCSymbol *B, SMLoc Loc)
static const char * PseudoProbeTypeStr[3]
static StringRef getProbeFNameForGUID(const GUIDProbeFunctionMap &GUID2FuncMAP, uint64_t GUID)
static const MCExpr * buildSymbolDiff(MCObjectStreamer *MCOS, const MCSymbol *A, const MCSymbol *B)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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...
Represents either an error or a value T.
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
Context object for machine code objects.
MCPseudoProbeTable & getMCPseudoProbeTable()
const MCObjectFileInfo * getObjectFileInfo() const
F * allocFragment(Args &&...args)
bool hasInlineSite() const
void print(raw_ostream &OS, const GUIDProbeFunctionMap &GUID2FuncMAP, bool ShowName) const
std::string getInlineContextStr(const GUIDProbeFunctionMap &GUID2FuncMAP) const
MCDecodedPseudoProbeInlineTree * getInlineTreeNode() const
void getInlineContext(SmallVectorImpl< MCPseudoProbeFrameLocation > &ContextStack, const GUIDProbeFunctionMap &GUID2FuncMAP) const
Base class for the full range of assembler expressions which are needed for parsing.
MCSection * getPseudoProbeSection(const MCSection &TextSec) const
Streaming object file generation interface.
MCAssembler & getAssembler()
MCAssembler * getAssemblerPtr() override
void insert(MCFragment *F)
uint8_t getAttributes() const
uint64_t getIndex() const
bool buildAddress2ProbeMap(const uint8_t *Start, std::size_t Size, const Uint64Set &GuildFilter, const Uint64Map &FuncStartAddrs)
void printProbesForAllAddresses(raw_ostream &OS)
bool buildGUID2FuncDescMap(const uint8_t *Start, std::size_t Size)
void printGUID2FuncDescMap(raw_ostream &OS)
void printProbeForAddress(raw_ostream &OS, uint64_t Address)
void getInlineContextForProbe(const MCDecodedPseudoProbe *Probe, SmallVectorImpl< MCPseudoProbeFrameLocation > &InlineContextStack, bool IncludeLeaf) const
const MCPseudoProbeFuncDesc * getInlinerDescForProbe(const MCDecodedPseudoProbe *Probe) const
const MCDecodedPseudoProbe * getCallProbeForAddr(uint64_t Address) const
const MCPseudoProbeFuncDesc * getFuncDescForGUID(uint64_t GUID) const
InlinedProbeTreeMap & getChildren()
MCPseudoProbeInlineTreeBase< MCPseudoProbe, MCPseudoProbeInlineTree > * Parent
void addProbes(ProbeType Probe)
MCPseudoProbeInlineTree * getOrAddNode(const InlineSite &Site)
std::vector< MCPseudoProbe > Probes
InlinedProbeTreeMap Children
void emit(MCObjectStreamer *MCOS, const MCPseudoProbe *&LastProbe)
void addPseudoProbe(const MCPseudoProbe &Probe, const MCPseudoProbeInlineStack &InlineStack)
void emit(MCObjectStreamer *MCOS)
MCPseudoProbeSections & getProbeSections()
static int DdgPrintIndent
static void emit(MCObjectStreamer *MCOS)
Instances of this class represent a pseudo probe instance for a pseudo probe table entry,...
MCSymbol * getLabel() const
void emit(MCObjectStreamer *MCOS, const MCPseudoProbe *LastProbe) const
MCContext & getContext() const
unsigned emitULEB128IntValue(uint64_t Value, unsigned PadTo=0)
Special case of EmitULEB128Value that avoids the client having to pass in a MCExpr for constant integ...
void emitInt64(uint64_t Value)
virtual void switchSection(MCSection *Section, uint32_t Subsec=0)
Set the current section where code is being emitted to Section.
unsigned emitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
void emitInt8(uint64_t Value)
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
reference emplace_back(ArgTypes &&... Args)
void reserve(size_type N)
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::string str() const
str - Get the contents as an std::string.
size_t find(char C, size_t From=0) const
Search for the first character C in the string.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM Value Representation.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
This class implements an extremely fast bulk output stream that can only output to a stream.
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
constexpr size_t NameSize
uint64_t MD5Hash(const FunctionId &Obj)
This is an optimization pass for GlobalISel generic memory operations.
static bool isSentinelProbe(uint32_t Flags)
auto enumerate(FirstRange &&First, RestRanges &&...Rest)
Given two or more input ranges, returns a new range whose values are tuples (A, B,...
std::tuple< uint64_t, uint32_t > InlineSite
uint64_t decodeULEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a ULEB128 value.
int64_t decodeSLEB128(const uint8_t *p, unsigned *n=nullptr, const uint8_t *end=nullptr, const char **error=nullptr)
Utility function to decode a SLEB128 value.
void sort(IteratorTy Start, IteratorTy End)
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
auto make_first_range(ContainerTy &&c)
Given a container of pairs, return a range over the first elements.
static bool hasDiscriminator(uint32_t Flags)
std::pair< StringRef, uint32_t > MCPseudoProbeFrameLocation
std::unordered_map< uint64_t, MCPseudoProbeFuncDesc > GUIDProbeFunctionMap
void print(raw_ostream &OS)
Function object to check whether the first component of a container supported by std::get (like std::...