//===- MCPseudoProbe.h - Pseudo probe encoding support ---------*- C++ -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception // //===----------------------------------------------------------------------===// // // This file contains the declaration of the MCPseudoProbe to support the pseudo // probe encoding for AutoFDO. Pseudo probes together with their inline context // are encoded in a DFS recursive way in the .pseudoprobe sections. For each // .pseudoprobe section, the encoded binary data consist of a single or mutiple // function records each for one outlined function. A function record has the // following format : // // FUNCTION BODY (one for each outlined function present in the text section) // GUID (uint64) // GUID of the function's source name which may be different from the // actual binary linkage name. This GUID will be used to decode and // generate a profile against the source function name. // NPROBES (ULEB128) // Number of probes originating from this function. // NUM_INLINED_FUNCTIONS (ULEB128) // Number of callees inlined into this function, aka number of // first-level inlinees // PROBE RECORDS // A list of NPROBES entries. Each entry contains: // INDEX (ULEB128) // TYPE (uint4) // 0 - block probe, 1 - indirect call, 2 - direct call // ATTRIBUTE (uint3) // 1 - reserved // 2 - Sentinel // 4 - HasDiscriminator // ADDRESS_TYPE (uint1) // 0 - code address for regular probes (for downwards compatibility) // - GUID of linkage name for sentinel probes // 1 - address delta // CODE_ADDRESS (uint64 or ULEB128) // code address or address delta, depending on ADDRESS_TYPE // DISCRIMINATOR (ULEB128) if HasDiscriminator // INLINED FUNCTION RECORDS // A list of NUM_INLINED_FUNCTIONS entries describing each of the inlined // callees. Each record contains: // INLINE SITE // ID of the callsite probe (ULEB128) // FUNCTION BODY // A FUNCTION BODY entry describing the inlined function. // // TODO: retire the ADDRESS_TYPE encoding for code addresses once compatibility // is no longer an issue. //===----------------------------------------------------------------------===// #ifndef LLVM_MC_MCPSEUDOPROBE_H #define LLVM_MC_MCPSEUDOPROBE_H #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMap.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" #include "llvm/ADT/iterator.h" #include "llvm/IR/PseudoProbe.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/ErrorOr.h" #include <functional> #include <memory> #include <string> #include <tuple> #include <type_traits> #include <unordered_map> #include <vector> namespace llvm { class MCSymbol; class MCObjectStreamer; class raw_ostream; enum class MCPseudoProbeFlag { … }; // Function descriptor decoded from .pseudo_probe_desc section struct MCPseudoProbeFuncDesc { … }; class MCDecodedPseudoProbe; // An inline frame has the form <CalleeGuid, ProbeID> InlineSite; MCPseudoProbeInlineStack; // GUID to PseudoProbeFuncDesc map class GUIDProbeFunctionMap : public std::vector<MCPseudoProbeFuncDesc> { … }; class MCDecodedPseudoProbeInlineTree; class MCPseudoProbeBase { … }; /// Instances of this class represent a pseudo probe instance for a pseudo probe /// table entry, which is created during a machine instruction is assembled and /// uses an address from a temporary label created at the current address in the /// current section. class MCPseudoProbe : public MCPseudoProbeBase { … }; // Represents a callsite with caller function name and probe id MCPseudoProbeFrameLocation; class MCDecodedPseudoProbe : public MCPseudoProbeBase { … }; // Address to pseudo probes map. class AddressProbesMap : public std::vector<std::reference_wrapper<MCDecodedPseudoProbe>> { … }; template <typename ProbesType, typename DerivedProbeInlineTreeType, typename InlinedProbeTreeMap> class MCPseudoProbeInlineTreeBase { … }; // A Tri-tree based data structure to group probes by inline stack. // A tree is allocated for a standalone .text section. A fake // instance is created as the root of a tree. // A real instance of this class is created for each function, either a // not inlined function that has code in .text section or an inlined function. struct InlineSiteHash { … }; class MCPseudoProbeInlineTree : public MCPseudoProbeInlineTreeBase< std::vector<MCPseudoProbe>, MCPseudoProbeInlineTree, std::unordered_map<InlineSite, std::unique_ptr<MCPseudoProbeInlineTree>, InlineSiteHash>> { … }; // inline tree node for the decoded pseudo probe class MCDecodedPseudoProbeInlineTree : public MCPseudoProbeInlineTreeBase< MCDecodedPseudoProbe *, MCDecodedPseudoProbeInlineTree, MutableArrayRef<MCDecodedPseudoProbeInlineTree>> { … }; /// Instances of this class represent the pseudo probes inserted into a compile /// unit. class MCPseudoProbeSections { … }; class MCPseudoProbeTable { … }; class MCPseudoProbeDecoder { … }; } // end namespace llvm #endif // LLVM_MC_MCPSEUDOPROBE_H