LLVM 23.0.0git
CallSiteInfo.h
Go to the documentation of this file.
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
13#include "llvm/ADT/StringRef.h"
14#include "llvm/ADT/StringSet.h"
17#include "llvm/Support/Error.h"
18#include <vector>
19
20namespace llvm {
21class raw_ostream;
22
23namespace yaml {
24struct FunctionsYAML;
25} // namespace yaml
26
27namespace gsym {
28class FileWriter;
29class GsymCreator;
31struct FunctionInfo;
33 enum Flags : uint8_t {
34 None = 0,
35 // This flag specifies that the call site can only call a function within
36 // the same link unit as the call site.
37 InternalCall = 1 << 0,
38 // This flag specifies that the call site can only call a function outside
39 // the link unit that the call site is in.
40 ExternalCall = 1 << 1,
41
43 };
44
45 /// The return offset of the call site - relative to the function start.
47
48 /// Offsets into the string table for function names regex patterns.
49 std::vector<gsym_strp_t> MatchRegex;
50
51 /// Bitwise OR of CallSiteInfo::Flags values
53
54 /// Equality comparison operator for CallSiteInfo.
55 bool operator==(const CallSiteInfo &RHS) const {
56 return ReturnOffset == RHS.ReturnOffset && MatchRegex == RHS.MatchRegex &&
57 Flags == RHS.Flags;
58 }
59
60 /// Inequality comparison operator for CallSiteInfo.
61 bool operator!=(const CallSiteInfo &RHS) const { return !(*this == RHS); }
62
63 /// Decode a CallSiteInfo object from a binary data stream.
64 ///
65 /// \param Data The binary stream to read the data from.
66 /// \param Offset The current offset within the data stream.
67 /// \returns A CallSiteInfo or an error describing the issue.
70
71 /// Encode this CallSiteInfo object into a FileWriter stream.
72 ///
73 /// \param O The binary stream to write the data to.
74 /// \returns An error object that indicates success or failure.
76};
77
79 std::vector<CallSiteInfo> CallSites;
80
81 /// Decode a CallSiteInfoCollection object from a binary data stream.
82 ///
83 /// \param Data The binary stream to read the data from.
84 /// \returns A CallSiteInfoCollection or an error describing the issue.
87
88 /// Encode this CallSiteInfoCollection object into a FileWriter stream.
89 ///
90 /// \param O The binary stream to write the data to.
91 /// \returns An error object that indicates success or failure.
93};
94
96public:
97 /// Constructor that initializes the CallSiteInfoLoader with necessary data
98 /// structures.
99 ///
100 /// \param GCreator A reference to the GsymCreator.
101 CallSiteInfoLoader(GsymCreator &GCreator, std::vector<FunctionInfo> &Funcs)
102 : GCreator(GCreator), Funcs(Funcs) {}
103
104 /// This method reads the specified YAML file, parses its content, and updates
105 /// the `Funcs` vector with call site information based on the YAML data.
106 ///
107 /// \param Funcs A reference to a vector of FunctionInfo objects to be
108 /// populated.
109 /// \param YAMLFile A StringRef representing the path to the YAML
110 /// file to be loaded.
111 /// \returns An `llvm::Error` indicating success or describing any issues
112 /// encountered during the loading process.
114
115private:
116 /// Builds a map from function names to FunctionInfo pointers based on the
117 /// provided `Funcs` vector.
118 ///
119 /// \param Funcs A reference to a vector of FunctionInfo objects.
120 /// \returns A StringMap mapping function names (StringRef) to their
121 /// corresponding FunctionInfo pointers.
122 StringMap<FunctionInfo *> buildFunctionMap();
123
124 /// Processes the parsed YAML functions and updates the `FuncMap` accordingly.
125 ///
126 /// \param FuncYAMLs A constant reference to an llvm::yaml::FunctionsYAML
127 /// object containing parsed YAML data.
128 /// \param FuncMap A reference to a StringMap mapping function names to
129 /// FunctionInfo pointers.
130 /// \returns An `llvm::Error` indicating success or describing any issues
131 /// encountered during processing.
132 llvm::Error processYAMLFunctions(const llvm::yaml::FunctionsYAML &FuncYAMLs,
134
135 /// Reference to the parent Gsym Creator object.
136 GsymCreator &GCreator;
137
138 /// Reference to the vector of FunctionInfo objects to be populated.
139 std::vector<FunctionInfo> &Funcs;
140};
141
142LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const CallSiteInfo &CSI);
144 const CallSiteInfoCollection &CSIC);
145
146} // namespace gsym
147} // namespace llvm
148
149#endif // LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H
#define LLVM_ABI
Definition Compiler.h:213
StringSet - A set-like wrapper for the StringMap.
Value * RHS
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
LLVM_ABI llvm::Error loadYAML(StringRef YAMLFile)
This method reads the specified YAML file, parses its content, and updates the Funcs vector with call...
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,...
Definition FileWriter.h:30
GsymCreator is used to emit GSYM data to a stand alone file or section within a file.
A DataExtractor subclass that adds GSYM-specific string offset support.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
LLVM_ABI raw_ostream & operator<<(raw_ostream &OS, const CallSiteInfo &CSI)
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:532
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
LLVM_ABI llvm::Error encode(FileWriter &O) const
Encode this CallSiteInfoCollection object into a FileWriter stream.
std::vector< CallSiteInfo > CallSites
static LLVM_ABI llvm::Expected< CallSiteInfoCollection > decode(GsymDataExtractor &Data)
Decode a CallSiteInfoCollection object from a binary data stream.
LLVM_ABI llvm::Error encode(FileWriter &O) const
Encode this CallSiteInfo object into a FileWriter stream.
uint64_t ReturnOffset
The return offset of the call site - relative to the function start.
bool operator!=(const CallSiteInfo &RHS) const
Inequality comparison operator for CallSiteInfo.
std::vector< gsym_strp_t > MatchRegex
Offsets into the string table for function names regex patterns.
bool operator==(const CallSiteInfo &RHS) const
Equality comparison operator for CallSiteInfo.
static LLVM_ABI llvm::Expected< CallSiteInfo > decode(GsymDataExtractor &Data, uint64_t &Offset)
Decode a CallSiteInfo object from a binary data stream.
Function information in GSYM files encodes information for one contiguous address range.