LLVM: lib/DebugInfo/GSYM/CallSiteInfo.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
19#include
20#include
21
22using namespace llvm;
23using namespace gsym;
24
30 O.writeU32(Entry);
32}
33
37
38
41 "0x%8.8" PRIx64 ": missing ReturnOffset", Offset);
43
44
47 "0x%8.8" PRIx64 ": missing Flags", Offset);
49
50
53 "0x%8.8" PRIx64 ": missing MatchRegex count",
56
58 for (uint32_t i = 0; i < NumEntries; ++i) {
61 "0x%8.8" PRIx64 ": missing MatchRegex entry",
65 }
66
67 return CSI;
68}
69
73 if (Error Err = CSI.encode(O))
74 return Err;
75
77}
78
83
84
87 "0x%8.8" PRIx64 ": missing CallSiteInfo count",
90
91 CSC.CallSites.reserve(NumCallSites);
92 for (uint32_t i = 0; i < NumCallSites; ++i) {
94 if (!ECSI)
96 CSC.CallSites.emplace_back(*ECSI);
97 }
98
99 return CSC;
100}
101
102
103namespace llvm {
104namespace yaml {
105
107
108
111 std::vectorstd::string flags;
112};
113
118
122
130
137
143
144}
145}
146
149
151
153 if (!BufferOrError)
155
156 std::unique_ptr Buffer = std::move(*BufferOrError);
157
158
160 yaml::Input Yin(Buffer->getMemBufferRef());
161 Yin >> FuncsYAML;
164 Buffer->getBufferIdentifier().str().c_str());
165
166
167 auto FuncMap = buildFunctionMap();
168
169
170 return processYAMLFunctions(FuncsYAML, FuncMap);
171}
172
174
175
176
177
178
180 for (auto &Func : Funcs) {
181 FuncMap.try_emplace(GCreator.getString(Func.Name), &Func);
182 if (auto &MFuncs = Func.MergedFunctions)
183 for (auto &MFunc : MFuncs->MergedFunctions)
184 FuncMap.try_emplace(GCreator.getString(MFunc.Name), &MFunc);
185 }
186 return FuncMap;
187}
188
189Error CallSiteInfoLoader::processYAMLFunctions(
191
192 for (const auto &FuncYAML : FuncYAMLs.functions) {
193 auto It = FuncMap.find(FuncYAML.name);
194 if (It == FuncMap.end())
196 std::errc::invalid_argument,
197 "Can't find function '%s' specified in callsite YAML\n",
198 FuncYAML.name.c_str());
199
201
204 for (const auto &CallSiteYAML : FuncYAML.callsites) {
206
207
208 CSI.ReturnOffset = CallSiteYAML.return_offset;
209 for (const auto &Regex : CallSiteYAML.match_regex) {
210 uint32_t StrOffset = GCreator.insertString(Regex);
212 }
213
214
215 for (const auto &FlagStr : CallSiteYAML.flags) {
216 if (FlagStr == "InternalCall") {
217 CSI.Flags |= static_cast<uint8_t>(CallSiteInfo::InternalCall);
218 } else if (FlagStr == "ExternalCall") {
219 CSI.Flags |= static_cast<uint8_t>(CallSiteInfo::ExternalCall);
220 } else {
222 "Unknown flag in callsite YAML: %s\n",
223 FlagStr.c_str());
224 }
225 }
226 FuncInfo->CallSites->CallSites.push_back(CSI);
227 }
228 }
230}
231
234 OS << " Flags=" << HEX8(CSI.Flags);
236 return OS;
237}
238
241 for (const auto &CS : CSIC.CallSites) {
242 OS << CS;
243 OS << "\n";
244 }
245 return OS;
246}
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
Error takeError()
Take ownership of the stored error.
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
iterator find(StringRef Key)
std::pair< iterator, bool > try_emplace(StringRef Key, ArgsTy &&...Args)
Emplace a new element for the specified key into the map if the key isn't already in the map.
StringRef - Represent a constant reference to a string, i.e.
LLVM_ABI llvm::Error loadYAML(StringRef YAMLFile)
This method reads the specified YAML file, parses its content, and updates the Funcs vector with call...
Definition CallSiteInfo.cpp:150
CallSiteInfoLoader(GsymCreator &GCreator, std::vector< FunctionInfo > &Funcs)
Constructor that initializes the CallSiteInfoLoader with necessary data structures.
A simplified binary data writer class that doesn't require targets, target definitions,...
This class implements an extremely fast bulk output stream that can only output to a stream.
void mapOptional(StringRef Key, T &Val)
void mapRequired(StringRef Key, T &Val)
The Input class is used to parse a yaml document into in-memory structs and vectors.
std::error_code error() override
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const CallSiteInfo &CSI)
Definition CallSiteInfo.cpp:232
This is an optimization pass for GlobalISel generic memory operations.
InterleavedRange< Range > interleaved(const Range &R, StringRef Separator=", ", StringRef Prefix="", StringRef Suffix="")
Output range R as a sequence of interleaved elements.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
FunctionAddr VTableAddr uintptr_t uintptr_t Data
LLVM_ABI Error errorCodeToError(std::error_code EC)
Helper for converting an std::error_code to a Error.
LLVM_ABI llvm::Error encode(FileWriter &O) const
Encode this CallSiteInfoCollection object into a FileWriter stream.
Definition CallSiteInfo.cpp:70
std::vector< CallSiteInfo > CallSites
static LLVM_ABI llvm::Expected< CallSiteInfoCollection > decode(DataExtractor &Data)
Decode a CallSiteInfoCollection object from a binary data stream.
Definition CallSiteInfo.cpp:80
LLVM_ABI llvm::Error encode(FileWriter &O) const
Encode this CallSiteInfo object into a FileWriter stream.
Definition CallSiteInfo.cpp:25
std::vector< uint32_t > MatchRegex
Offsets into the string table for function names regex patterns.
uint64_t ReturnOffset
The return offset of the call site - relative to the function start.
static LLVM_ABI llvm::Expected< CallSiteInfo > decode(DataExtractor &Data, uint64_t &Offset)
Decode a CallSiteInfo object from a binary data stream.
Definition CallSiteInfo.cpp:34
Function information in GSYM files encodes information for one contiguous address range.
std::optional< CallSiteInfoCollection > CallSites
Definition CallSiteInfo.cpp:106
std::vector< std::string > flags
Definition CallSiteInfo.cpp:111
std::vector< std::string > match_regex
Definition CallSiteInfo.cpp:110
Hex64 return_offset
Definition CallSiteInfo.cpp:109
Definition CallSiteInfo.cpp:114
std::string name
Definition CallSiteInfo.cpp:115
std::vector< CallSiteYAML > callsites
Definition CallSiteInfo.cpp:116
Definition CallSiteInfo.cpp:119
std::vector< FunctionYAML > functions
Definition CallSiteInfo.cpp:120
static void mapping(IO &io, CallSiteYAML &callsite)
Definition CallSiteInfo.cpp:124
static void mapping(IO &io, FunctionYAML &func)
Definition CallSiteInfo.cpp:132
static void mapping(IO &io, FunctionsYAML &FuncYAMLs)
Definition CallSiteInfo.cpp:139
This class should be specialized by any type that needs to be converted to/from a YAML mapping.