|
| 1 | +//===- CallSiteInfo.h -------------------------------------------*- C++ -*-===// |
| 2 | +// |
| 3 | +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | +// See https://llvm.org/LICENSE.txt for license information. |
| 5 | +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | +// |
| 7 | +//===----------------------------------------------------------------------===// |
| 8 | + |
| 9 | +#ifndef LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H |
| 10 | +#define LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H |
| 11 | + |
| 12 | +#include "llvm/ADT/BitmaskEnum.h" |
| 13 | +#include "llvm/ADT/StringRef.h" |
| 14 | +#include "llvm/ADT/StringSet.h" |
| 15 | +#include "llvm/Support/Error.h" |
| 16 | +#include <vector> |
| 17 | + |
| 18 | +namespace llvm { |
| 19 | +class DataExtractor; |
| 20 | +class raw_ostream; |
| 21 | + |
| 22 | +namespace yaml { |
| 23 | +struct FunctionsYAML; |
| 24 | +} // namespace yaml |
| 25 | + |
| 26 | +namespace gsym { |
| 27 | +class FileWriter; |
| 28 | +class GsymCreator; |
| 29 | +struct FunctionInfo; |
| 30 | +struct CallSiteInfo { |
| 31 | + enum Flags : uint8_t { |
| 32 | + None = 0, |
| 33 | + // This flag specifies that the call site can only call a function within |
| 34 | + // the same link unit as the call site. |
| 35 | + InternalCall = 1 << 0, |
| 36 | + // This flag specifies that the call site can only call a function outside |
| 37 | + // the link unit that the call site is in. |
| 38 | + ExternalCall = 1 << 1, |
| 39 | + |
| 40 | + LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue*/ ExternalCall), |
| 41 | + }; |
| 42 | + |
| 43 | + /// The return offset of the call site - relative to the function start. |
| 44 | + uint64_t ReturnOffset = 0; |
| 45 | + |
| 46 | + /// Offsets into the string table for function names regex patterns. |
| 47 | + std::vector<uint32_t> MatchRegex; |
| 48 | + |
| 49 | + /// Bitwise OR of CallSiteInfo::Flags values |
| 50 | + uint8_t Flags = CallSiteInfo::Flags::None; |
| 51 | + |
| 52 | + /// Decode a CallSiteInfo object from a binary data stream. |
| 53 | + /// |
| 54 | + /// \param Data The binary stream to read the data from. |
| 55 | + /// \param Offset The current offset within the data stream. |
| 56 | + /// \returns A CallSiteInfo or an error describing the issue. |
| 57 | + static llvm::Expected<CallSiteInfo> decode(DataExtractor &Data, |
| 58 | + uint64_t &Offset); |
| 59 | + |
| 60 | + /// Encode this CallSiteInfo object into a FileWriter stream. |
| 61 | + /// |
| 62 | + /// \param O The binary stream to write the data to. |
| 63 | + /// \returns An error object that indicates success or failure. |
| 64 | + llvm::Error encode(FileWriter &O) const; |
| 65 | +}; |
| 66 | + |
| 67 | +struct CallSiteInfoCollection { |
| 68 | + std::vector<CallSiteInfo> CallSites; |
| 69 | + |
| 70 | + /// Decode a CallSiteInfoCollection object from a binary data stream. |
| 71 | + /// |
| 72 | + /// \param Data The binary stream to read the data from. |
| 73 | + /// \returns A CallSiteInfoCollection or an error describing the issue. |
| 74 | + static llvm::Expected<CallSiteInfoCollection> decode(DataExtractor &Data); |
| 75 | + |
| 76 | + /// Encode this CallSiteInfoCollection object into a FileWriter stream. |
| 77 | + /// |
| 78 | + /// \param O The binary stream to write the data to. |
| 79 | + /// \returns An error object that indicates success or failure. |
| 80 | + llvm::Error encode(FileWriter &O) const; |
| 81 | +}; |
| 82 | + |
| 83 | +class CallSiteInfoLoader { |
| 84 | +public: |
| 85 | + /// Constructor that initializes the CallSiteInfoLoader with necessary data |
| 86 | + /// structures. |
| 87 | + /// |
| 88 | + /// \param GCreator A reference to the GsymCreator. |
| 89 | + CallSiteInfoLoader(GsymCreator &GCreator, std::vector<FunctionInfo> &Funcs) |
| 90 | + : GCreator(GCreator), Funcs(Funcs) {} |
| 91 | + |
| 92 | + /// This method reads the specified YAML file, parses its content, and updates |
| 93 | + /// the `Funcs` vector with call site information based on the YAML data. |
| 94 | + /// |
| 95 | + /// \param Funcs A reference to a vector of FunctionInfo objects to be |
| 96 | + /// populated. |
| 97 | + /// \param YAMLFile A StringRef representing the path to the YAML |
| 98 | + /// file to be loaded. |
| 99 | + /// \returns An `llvm::Error` indicating success or describing any issues |
| 100 | + /// encountered during the loading process. |
| 101 | + llvm::Error loadYAML(StringRef YAMLFile); |
| 102 | + |
| 103 | +private: |
| 104 | + /// Builds a map from function names to FunctionInfo pointers based on the |
| 105 | + /// provided `Funcs` vector. |
| 106 | + /// |
| 107 | + /// \param Funcs A reference to a vector of FunctionInfo objects. |
| 108 | + /// \returns A StringMap mapping function names (StringRef) to their |
| 109 | + /// corresponding FunctionInfo pointers. |
| 110 | + StringMap<FunctionInfo *> buildFunctionMap(); |
| 111 | + |
| 112 | + /// Processes the parsed YAML functions and updates the `FuncMap` accordingly. |
| 113 | + /// |
| 114 | + /// \param FuncYAMLs A constant reference to an llvm::yaml::FunctionsYAML |
| 115 | + /// object containing parsed YAML data. |
| 116 | + /// \param FuncMap A reference to a StringMap mapping function names to |
| 117 | + /// FunctionInfo pointers. |
| 118 | + /// \returns An `llvm::Error` indicating success or describing any issues |
| 119 | + /// encountered during processing. |
| 120 | + llvm::Error processYAMLFunctions(const llvm::yaml::FunctionsYAML &FuncYAMLs, |
| 121 | + StringMap<FunctionInfo *> &FuncMap); |
| 122 | + |
| 123 | + /// Reference to the parent Gsym Creator object. |
| 124 | + GsymCreator &GCreator; |
| 125 | + |
| 126 | + /// Reference to the vector of FunctionInfo objects to be populated. |
| 127 | + std::vector<FunctionInfo> &Funcs; |
| 128 | +}; |
| 129 | + |
| 130 | +raw_ostream &operator<<(raw_ostream &OS, const CallSiteInfo &CSI); |
| 131 | +raw_ostream &operator<<(raw_ostream &OS, const CallSiteInfoCollection &CSIC); |
| 132 | + |
| 133 | +} // namespace gsym |
| 134 | +} // namespace llvm |
| 135 | + |
| 136 | +#endif // LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H |
0 commit comments