Go to the documentation of this file.
29 #define DEBUG_TYPE "mcpseudoprobe"
52 assert((LastProbe || IsSentinel) &&
53 "Last probe should not be null for non-sentinel probes");
61 assert(
Type <= 0xF &&
"Probe type too big to encode, exceeding 15");
63 "Probe attributes too big to encode, exceeding 7");
93 assert(isRoot() &&
"Should only be called on root");
108 if (InlineStack.empty()) {
111 Top =
InlineSite(std::get<0>(InlineStack.front()), 0);
114 auto *Cur = getOrAddNode(Top);
118 if (!InlineStack.empty()) {
119 auto Iter = InlineStack.begin();
120 auto Index = std::get<1>(*Iter);
122 for (; Iter != InlineStack.end(); Iter++) {
125 Index = std::get<1>(*Iter);
130 Cur->Probes.push_back(Probe);
137 dbgs() <<
"Group [\n";
140 assert(!isRoot() &&
"Root should be handled seperately");
145 dbgs() <<
"GUID: " << Guid <<
"\n";
151 bool NeedSentinel =
false;
152 if (Parent->isRoot()) {
154 "Starting probe of a top-level function should be a sentinel probe");
156 if (LastProbe->
getGuid() != Guid)
165 LastProbe->
emit(MCOS,
nullptr);
168 for (
const auto &Probe : Probes) {
169 Probe.emit(MCOS, LastProbe);
175 using InlineeType = std::pair<InlineSite, MCPseudoProbeInlineTree *>;
176 auto Comparer = [](
const InlineeType &A,
const InlineeType &
B) {
177 return A.first <
B.first;
179 std::vector<InlineeType> Inlinees;
180 for (
const auto &Child : Children)
181 Inlinees.emplace_back(Child.first, Child.second.get());
182 std::sort(Inlinees.begin(), Inlinees.end(), Comparer);
184 for (
const auto &Inlinee : Inlinees) {
189 dbgs() <<
"InlineSite: " << std::get<1>(Inlinee.first) <<
"\n";
192 Inlinee.second->emit(MCOS, LastProbe);
204 for (
auto &ProbeSec : MCProbeDivisions) {
205 const auto *FuncSym = ProbeSec.first;
206 const auto &Root = ProbeSec.second;
208 FuncSym->getSection())) {
214 using InlineeType = std::pair<InlineSite, MCPseudoProbeInlineTree *>;
215 auto Comparer = [](
const InlineeType &A,
const InlineeType &
B) {
216 return A.first <
B.first;
218 std::vector<InlineeType> Inlinees;
219 for (
const auto &Child : Root.getChildren())
220 Inlinees.emplace_back(Child.first, Child.second.get());
221 std::sort(Inlinees.begin(), Inlinees.end(), Comparer);
223 for (
const auto &Inlinee : Inlinees) {
231 Inlinee.second->emit(MCOS, Probe);
247 if (ProbeSections.empty())
253 ProbeSections.emit(MCOS);
258 auto It = GUID2FuncMAP.
find(GUID);
259 assert(It != GUID2FuncMAP.end() &&
260 "Probe function must exist for a valid GUID");
261 return It->second.FuncName;
265 OS <<
"GUID: " << FuncGUID <<
" Name: " << FuncName <<
"\n";
266 OS <<
"Hash: " << FuncHash <<
"\n";
272 uint32_t Begin = ContextStack.size();
283 std::reverse(ContextStack.begin() + Begin, ContextStack.end());
288 std::ostringstream OContextStr;
290 getInlineContext(ContextStack, GUID2FuncMAP);
291 for (
auto &Cxt : ContextStack) {
292 if (OContextStr.str().size())
293 OContextStr <<
" @ ";
294 OContextStr << Cxt.first.str() <<
":" << Cxt.second;
296 return OContextStr.str();
304 bool ShowName)
const {
308 OS << FuncName.
str() <<
" ";
312 OS <<
"Index: " <<
Index <<
" ";
314 std::string InlineContextStr = getInlineContextStr(GUID2FuncMAP);
315 if (InlineContextStr.size()) {
317 OS << InlineContextStr;
322 template <
typename T>
ErrorOr<T> MCPseudoProbeDecoder::readUnencodedNumber() {
323 if (Data +
sizeof(
T) > End) {
324 return std::error_code();
326 T Val = endian::readNext<T, little, unaligned>(Data);
330 template <
typename T>
ErrorOr<T> MCPseudoProbeDecoder::readUnsignedNumber() {
331 unsigned NumBytesRead = 0;
334 return std::error_code();
336 Data += NumBytesRead;
340 template <
typename T>
ErrorOr<T> MCPseudoProbeDecoder::readSignedNumber() {
341 unsigned NumBytesRead = 0;
344 return std::error_code();
346 Data += NumBytesRead;
351 StringRef Str(
reinterpret_cast<const char *
>(Data), Size);
352 if (Data + Size > End) {
353 return std::error_code();
376 auto ErrorOrGUID = readUnencodedNumber<uint64_t>();
380 auto ErrorOrHash = readUnencodedNumber<uint64_t>();
384 auto ErrorOrNameSize = readUnsignedNumber<uint32_t>();
385 if (!ErrorOrNameSize)
400 assert(
Data == End &&
"Have unprocessed data in pseudo_probe_desc section");
411 bool IsTopLevelFunc = Cur == &DummyInlineRoot;
412 if (IsTopLevelFunc) {
417 auto ErrorOrIndex = readUnsignedNumber<uint32_t>();
424 auto ErrorOrCurGuid = readUnencodedNumber<uint64_t>();
430 if (IsTopLevelFunc && !GuidFilter.
empty() && !GuidFilter.
count(Guid))
438 if (IsTopLevelFunc && !EncodingIsAddrBased) {
439 if (
auto V = FuncStartAddrs.
lookup(Guid))
445 auto ErrorOrNodeCount = readUnsignedNumber<uint32_t>();
446 if (!ErrorOrNodeCount)
450 auto ErrorOrCurChildrenToProcess = readUnsignedNumber<uint32_t>();
451 if (!ErrorOrCurChildrenToProcess)
454 for (std::size_t
I = 0;
I < NodeCount;
I++) {
456 auto ErrorOrIndex = readUnsignedNumber<uint32_t>();
461 auto ErrorOrValue = readUnencodedNumber<uint8_t>();
465 uint8_t Kind =
Value & 0xf;
466 uint8_t Attr = (
Value & 0x70) >> 4;
470 auto ErrorOrOffset = readSignedNumber<int64_t>();
473 int64_t Offset =
std::move(*ErrorOrOffset);
474 Addr = LastAddr + Offset;
476 auto ErrorOrAddr = readUnencodedNumber<int64_t>();
490 EncodingIsAddrBased =
true;
496 auto &Probes = Address2ProbesMap[
Addr];
506 buildAddress2ProbeMap(Cur, LastAddr, GuidFilter, FuncStartAddrs);
513 const uint8_t *Start, std::size_t Size,
const Uint64Set &GuidFilter,
519 buildAddress2ProbeMap(&DummyInlineRoot, LastAddr, GuidFilter,
521 assert(
Data == End &&
"Have unprocessed data in pseudo_probe section");
526 OS <<
"Pseudo Probe Desc:\n";
528 std::map<uint64_t, MCPseudoProbeFuncDesc> OrderedMap(GUID2FuncDescMap.begin(),
529 GUID2FuncDescMap.end());
530 for (
auto &
I : OrderedMap) {
537 auto It = Address2ProbesMap.find(Address);
538 if (It != Address2ProbesMap.end()) {
539 for (
auto &Probe : It->second) {
541 Probe.print(OS, GUID2FuncDescMap,
true);
547 std::vector<uint64_t> Addresses;
548 for (
auto Entry : Address2ProbesMap)
549 Addresses.push_back(Entry.first);
551 for (
auto K : Addresses) {
555 printProbeForAddress(OS, K);
561 auto It = Address2ProbesMap.find(Address);
562 if (It == Address2ProbesMap.end())
564 const auto &Probes = It->second;
567 for (
const auto &Probe : Probes) {
568 if (Probe.isCall()) {
570 "There should be only one call probe corresponding to address "
571 "which is a callsite.");
580 auto It = GUID2FuncDescMap.find(GUID);
581 assert(It != GUID2FuncDescMap.end() &&
"Function descriptor doesn't exist");
588 bool IncludeLeaf)
const {
594 const auto *FuncDesc = getFuncDescForGUID(Probe->
getGuid());
604 return getFuncDescForGUID(InlinerNode->
Parent->
Guid);
void emit(MCObjectStreamer *MCOS)
std::unordered_map< uint64_t, MCPseudoProbeFuncDesc > GUIDProbeFunctionMap
const MCObjectFileInfo * getObjectFileInfo() const
void printProbeForAddress(raw_ostream &OS, uint64_t Address)
This is an optimization pass for GlobalISel generic memory operations.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
std::tuple< uint64_t, uint32_t > InlineSite
void print(raw_ostream &OS, const GUIDProbeFunctionMap &GUID2FuncMAP, bool ShowName) const
Context object for machine code objects.
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...
void emitInt64(uint64_t Value)
void emitInt8(uint64_t Value)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Instances of this class represent a pseudo probe instance for a pseudo probe table entry,...
MCSection * getPseudoProbeSection(const MCSection &TextSec) const
void addPseudoProbe(const MCPseudoProbe &Probe, const MCPseudoProbeInlineStack &InlineStack)
The instances of the Type class are immutable: once they are created, they are never changed.
AttributeList getAttributes(LLVMContext &C, ID id)
Return the attributes for an intrinsic.
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
uint8_t getAttributes() const
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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.
void print(raw_ostream &OS)
MCDecodedPseudoProbeInlineTree * getInlineTreeNode() const
MCPseudoProbeTable & getMCPseudoProbeTable()
virtual void switchSection(MCSection *Section, const MCExpr *Subsection=nullptr)
Set the current section where code is being emitted to Section.
Streaming object file generation interface.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Flag
These should be considered private to the implementation of the MCInstrDesc class.
void emit(MCObjectStreamer *MCOS, const MCPseudoProbe *&LastProbe)
void getInlineContextForProbe(const MCDecodedPseudoProbe *Probe, SmallVectorImpl< MCPseduoProbeFrameLocation > &InlineContextStack, bool IncludeLeaf) const
This class implements an extremely fast bulk output stream that can only output to a stream.
bool buildGUID2FuncDescMap(const uint8_t *Start, std::size_t Size)
DerivedProbeInlineTreeType * getOrAddNode(const InlineSite &Site)
static StringRef getProbeFNameForGUID(const GUIDProbeFunctionMap &GUID2FuncMAP, uint64_t GUID)
void sort(IteratorTy Start, IteratorTy End)
static const MCExpr * buildSymbolDiff(MCObjectStreamer *MCOS, const MCSymbol *A, const MCSymbol *B)
InlinedProbeTreeMap & getChildren()
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 emit(MCObjectStreamer *MCOS, const MCPseudoProbe *LastProbe) const
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
unsigned emitSLEB128IntValue(int64_t Value)
Special case of EmitSLEB128Value that avoids the client having to pass in a MCExpr for constant integ...
static const MCBinaryExpr * create(Opcode Op, const MCExpr *LHS, const MCExpr *RHS, MCContext &Ctx, SMLoc Loc=SMLoc())
static bool isSentinelProbe(uint32_t Flags)
void insert(MCFragment *F)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
MCSymbol * getLabel() const
MCPseudoProbeInlineTreeBase< ProbeType, DerivedProbeInlineTreeType > * Parent
std::string getInlineContextStr(const GUIDProbeFunctionMap &GUID2FuncMAP) const
StringRef - Represent a constant reference to a string, i.e.
void printGUID2FuncDescMap(raw_ostream &OS)
static const char * PseudoProbeTypeStr[3]
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
bool buildAddress2ProbeMap(const uint8_t *Start, std::size_t Size, const Uint64Set &GuildFilter, const Uint64Map &FuncStartAddrs)
void addProbes(ProbeType Probe)
static int DdgPrintIndent
uint64_t getIndex() const
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
bool hasInlineSite() const
const MCDecodedPseudoProbe * getCallProbeForAddr(uint64_t Address) const
void printProbesForAllAddresses(raw_ostream &OS)
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.
const MCPseudoProbeFuncDesc * getFuncDescForGUID(uint64_t GUID) const
MCContext & getContext() const
raw_ostream & indent(unsigned NumSpaces)
indent - Insert 'NumSpaces' spaces.
Represents either an error or a value T.
Reimplement select in terms of SEL *We would really like to support but we need to prove that the add doesn t need to overflow between the two bit chunks *Implement pre post increment support(e.g. PR935) *Implement smarter const ant generation for binops with large immediates. A few ARMv6T2 ops should be pattern matched
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
auto reverse(ContainerTy &&C)
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.
void getInlineContext(SmallVectorImpl< MCPseduoProbeFrameLocation > &ContextStack, const GUIDProbeFunctionMap &GUID2FuncMAP) const
std::pair< StringRef, uint32_t > MCPseduoProbeFrameLocation
const MCPseudoProbeFuncDesc * getInlinerDescForProbe(const MCDecodedPseudoProbe *Probe) const
static StringRef readString(WasmObjectFile::ReadContext &Ctx)
MCPseudoProbeSections & getProbeSections()
LLVM Value Representation.
Base class for the full range of assembler expressions which are needed for parsing.
reference emplace_back(ArgTypes &&... Args)
MCAssembler * getAssemblerPtr() override
uint64_t MD5Hash(StringRef Str)
Helper to compute and return lower 64 bits of the given string's MD5 hash.
static void emit(MCObjectStreamer *MCOS)