Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:42

0001 //===- CallSiteInfo.h -------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H
0010 #define LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H
0011 
0012 #include "llvm/ADT/BitmaskEnum.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/ADT/StringSet.h"
0015 #include "llvm/Support/Error.h"
0016 #include <vector>
0017 
0018 namespace llvm {
0019 class DataExtractor;
0020 class raw_ostream;
0021 
0022 namespace yaml {
0023 struct FunctionsYAML;
0024 } // namespace yaml
0025 
0026 namespace gsym {
0027 class FileWriter;
0028 class GsymCreator;
0029 struct FunctionInfo;
0030 struct CallSiteInfo {
0031   enum Flags : uint8_t {
0032     None = 0,
0033     // This flag specifies that the call site can only call a function within
0034     // the same link unit as the call site.
0035     InternalCall = 1 << 0,
0036     // This flag specifies that the call site can only call a function outside
0037     // the link unit that the call site is in.
0038     ExternalCall = 1 << 1,
0039 
0040     LLVM_MARK_AS_BITMASK_ENUM(/*LargestValue*/ ExternalCall),
0041   };
0042 
0043   /// The return offset of the call site - relative to the function start.
0044   uint64_t ReturnOffset = 0;
0045 
0046   /// Offsets into the string table for function names regex patterns.
0047   std::vector<uint32_t> MatchRegex;
0048 
0049   /// Bitwise OR of CallSiteInfo::Flags values
0050   uint8_t Flags = CallSiteInfo::Flags::None;
0051 
0052   /// Equality comparison operator for CallSiteInfo.
0053   bool operator==(const CallSiteInfo &RHS) const {
0054     return ReturnOffset == RHS.ReturnOffset && MatchRegex == RHS.MatchRegex &&
0055            Flags == RHS.Flags;
0056   }
0057 
0058   /// Inequality comparison operator for CallSiteInfo.
0059   bool operator!=(const CallSiteInfo &RHS) const { return !(*this == RHS); }
0060 
0061   /// Decode a CallSiteInfo object from a binary data stream.
0062   ///
0063   /// \param Data The binary stream to read the data from.
0064   /// \param Offset The current offset within the data stream.
0065   /// \returns A CallSiteInfo or an error describing the issue.
0066   static llvm::Expected<CallSiteInfo> decode(DataExtractor &Data,
0067                                              uint64_t &Offset);
0068 
0069   /// Encode this CallSiteInfo object into a FileWriter stream.
0070   ///
0071   /// \param O The binary stream to write the data to.
0072   /// \returns An error object that indicates success or failure.
0073   llvm::Error encode(FileWriter &O) const;
0074 };
0075 
0076 struct CallSiteInfoCollection {
0077   std::vector<CallSiteInfo> CallSites;
0078 
0079   /// Decode a CallSiteInfoCollection object from a binary data stream.
0080   ///
0081   /// \param Data The binary stream to read the data from.
0082   /// \returns A CallSiteInfoCollection or an error describing the issue.
0083   static llvm::Expected<CallSiteInfoCollection> decode(DataExtractor &Data);
0084 
0085   /// Encode this CallSiteInfoCollection object into a FileWriter stream.
0086   ///
0087   /// \param O The binary stream to write the data to.
0088   /// \returns An error object that indicates success or failure.
0089   llvm::Error encode(FileWriter &O) const;
0090 };
0091 
0092 class CallSiteInfoLoader {
0093 public:
0094   /// Constructor that initializes the CallSiteInfoLoader with necessary data
0095   /// structures.
0096   ///
0097   /// \param GCreator A reference to the GsymCreator.
0098   CallSiteInfoLoader(GsymCreator &GCreator, std::vector<FunctionInfo> &Funcs)
0099       : GCreator(GCreator), Funcs(Funcs) {}
0100 
0101   /// This method reads the specified YAML file, parses its content, and updates
0102   /// the `Funcs` vector with call site information based on the YAML data.
0103   ///
0104   /// \param Funcs A reference to a vector of FunctionInfo objects to be
0105   /// populated.
0106   /// \param YAMLFile A StringRef representing the path to the YAML
0107   /// file to be loaded.
0108   /// \returns An `llvm::Error` indicating success or describing any issues
0109   /// encountered during the loading process.
0110   llvm::Error loadYAML(StringRef YAMLFile);
0111 
0112 private:
0113   /// Builds a map from function names to FunctionInfo pointers based on the
0114   /// provided `Funcs` vector.
0115   ///
0116   /// \param Funcs A reference to a vector of FunctionInfo objects.
0117   /// \returns A StringMap mapping function names (StringRef) to their
0118   /// corresponding FunctionInfo pointers.
0119   StringMap<FunctionInfo *> buildFunctionMap();
0120 
0121   /// Processes the parsed YAML functions and updates the `FuncMap` accordingly.
0122   ///
0123   /// \param FuncYAMLs A constant reference to an llvm::yaml::FunctionsYAML
0124   /// object containing parsed YAML data.
0125   /// \param FuncMap A reference to a StringMap mapping function names to
0126   /// FunctionInfo pointers.
0127   /// \returns An `llvm::Error` indicating success or describing any issues
0128   /// encountered during processing.
0129   llvm::Error processYAMLFunctions(const llvm::yaml::FunctionsYAML &FuncYAMLs,
0130                                    StringMap<FunctionInfo *> &FuncMap);
0131 
0132   /// Reference to the parent Gsym Creator object.
0133   GsymCreator &GCreator;
0134 
0135   /// Reference to the vector of FunctionInfo objects to be populated.
0136   std::vector<FunctionInfo> &Funcs;
0137 };
0138 
0139 raw_ostream &operator<<(raw_ostream &OS, const CallSiteInfo &CSI);
0140 raw_ostream &operator<<(raw_ostream &OS, const CallSiteInfoCollection &CSIC);
0141 
0142 } // namespace gsym
0143 } // namespace llvm
0144 
0145 #endif // LLVM_DEBUGINFO_GSYM_CALLSITEINFO_H