LLVM 20.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"
15#include "llvm/Support/Error.h"
16#include <vector>
17
18namespace llvm {
19class DataExtractor;
20class raw_ostream;
21
22namespace yaml {
23struct FunctionsYAML;
24} // namespace yaml
25
26namespace gsym {
27class FileWriter;
28class GsymCreator;
29struct FunctionInfo;
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
41 };
42
43 /// The return offset of the call site - relative to the function start.
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
51
52 /// Equality comparison operator for CallSiteInfo.
53 bool operator==(const CallSiteInfo &RHS) const {
54 return ReturnOffset == RHS.ReturnOffset && MatchRegex == RHS.MatchRegex &&
55 Flags == RHS.Flags;
56 }
57
58 /// Inequality comparison operator for CallSiteInfo.
59 bool operator!=(const CallSiteInfo &RHS) const { return !(*this == RHS); }
60
61 /// Decode a CallSiteInfo object from a binary data stream.
62 ///
63 /// \param Data The binary stream to read the data from.
64 /// \param Offset The current offset within the data stream.
65 /// \returns A CallSiteInfo or an error describing the issue.
68
69 /// Encode this CallSiteInfo object into a FileWriter stream.
70 ///
71 /// \param O The binary stream to write the data to.
72 /// \returns An error object that indicates success or failure.
74};
75
77 std::vector<CallSiteInfo> CallSites;
78
79 /// Decode a CallSiteInfoCollection object from a binary data stream.
80 ///
81 /// \param Data The binary stream to read the data from.
82 /// \returns A CallSiteInfoCollection or an error describing the issue.
84
85 /// Encode this CallSiteInfoCollection object into a FileWriter stream.
86 ///
87 /// \param O The binary stream to write the data to.
88 /// \returns An error object that indicates success or failure.
90};
91
93public:
94 /// Constructor that initializes the CallSiteInfoLoader with necessary data
95 /// structures.
96 ///
97 /// \param GCreator A reference to the GsymCreator.
98 CallSiteInfoLoader(GsymCreator &GCreator, std::vector<FunctionInfo> &Funcs)
99 : GCreator(GCreator), Funcs(Funcs) {}
100
101 /// This method reads the specified YAML file, parses its content, and updates
102 /// the `Funcs` vector with call site information based on the YAML data.
103 ///
104 /// \param Funcs A reference to a vector of FunctionInfo objects to be
105 /// populated.
106 /// \param YAMLFile A StringRef representing the path to the YAML
107 /// file to be loaded.
108 /// \returns An `llvm::Error` indicating success or describing any issues
109 /// encountered during the loading process.
111
112private:
113 /// Builds a map from function names to FunctionInfo pointers based on the
114 /// provided `Funcs` vector.
115 ///
116 /// \param Funcs A reference to a vector of FunctionInfo objects.
117 /// \returns A StringMap mapping function names (StringRef) to their
118 /// corresponding FunctionInfo pointers.
119 StringMap<FunctionInfo *> buildFunctionMap();
120
121 /// Processes the parsed YAML functions and updates the `FuncMap` accordingly.
122 ///
123 /// \param FuncYAMLs A constant reference to an llvm::yaml::FunctionsYAML
124 /// object containing parsed YAML data.
125 /// \param FuncMap A reference to a StringMap mapping function names to
126 /// FunctionInfo pointers.
127 /// \returns An `llvm::Error` indicating success or describing any issues
128 /// encountered during processing.
129 llvm::Error processYAMLFunctions(const llvm::yaml::FunctionsYAML &FuncYAMLs,
131
132 /// Reference to the parent Gsym Creator object.
133 GsymCreator &GCreator;
134
135 /// Reference to the vector of FunctionInfo objects to be populated.
136 std::vector<FunctionInfo> &Funcs;
137};
138
139raw_ostream &operator<<(raw_ostream &OS, const CallSiteInfo &CSI);
140raw_ostream &operator<<(raw_ostream &OS, const CallSiteInfoCollection &CSIC);
141
142} // namespace gsym
143} // namespace llvm
144
145#endif // LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H
raw_pwrite_stream & OS
StringSet - A set-like wrapper for the StringMap.
Value * RHS
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Tagged union holding either a T or a Error.
Definition: Error.h:481
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition: StringMap.h:128
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
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.
Definition: CallSiteInfo.h:98
A simplified binary data writer class that doesn't require targets, target definitions,...
Definition: FileWriter.h:29
GsymCreator is used to emit GSYM data to a stand alone file or section within a file.
Definition: GsymCreator.h:134
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
raw_ostream & operator<<(raw_ostream &OS, const CallSiteInfo &CSI)
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:480
llvm::Error encode(FileWriter &O) const
Encode this CallSiteInfoCollection object into a FileWriter stream.
std::vector< CallSiteInfo > CallSites
Definition: CallSiteInfo.h:77
static llvm::Expected< CallSiteInfoCollection > decode(DataExtractor &Data)
Decode a CallSiteInfoCollection object from a binary data stream.
llvm::Error encode(FileWriter &O) const
Encode this CallSiteInfo object into a FileWriter stream.
std::vector< uint32_t > MatchRegex
Offsets into the string table for function names regex patterns.
Definition: CallSiteInfo.h:47
uint64_t ReturnOffset
The return offset of the call site - relative to the function start.
Definition: CallSiteInfo.h:44
bool operator!=(const CallSiteInfo &RHS) const
Inequality comparison operator for CallSiteInfo.
Definition: CallSiteInfo.h:59
static llvm::Expected< CallSiteInfo > decode(DataExtractor &Data, uint64_t &Offset)
Decode a CallSiteInfo object from a binary data stream.
bool operator==(const CallSiteInfo &RHS) const
Equality comparison operator for CallSiteInfo.
Definition: CallSiteInfo.h:53
Function information in GSYM files encodes information for one contiguous address range.
Definition: FunctionInfo.h:92