LLVM  5.0.0
ModuleSummaryIndexYAML.h
Go to the documentation of this file.
1 //===-- llvm/ModuleSummaryIndexYAML.h - YAML I/O for summary ----*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_IR_MODULESUMMARYINDEXYAML_H
11 #define LLVM_IR_MODULESUMMARYINDEXYAML_H
12 
15 
16 namespace llvm {
17 namespace yaml {
18 
20  static void enumeration(IO &io, TypeTestResolution::Kind &value) {
21  io.enumCase(value, "Unsat", TypeTestResolution::Unsat);
22  io.enumCase(value, "ByteArray", TypeTestResolution::ByteArray);
23  io.enumCase(value, "Inline", TypeTestResolution::Inline);
24  io.enumCase(value, "Single", TypeTestResolution::Single);
25  io.enumCase(value, "AllOnes", TypeTestResolution::AllOnes);
26  }
27 };
28 
29 template <> struct MappingTraits<TypeTestResolution> {
30  static void mapping(IO &io, TypeTestResolution &res) {
31  io.mapOptional("Kind", res.TheKind);
32  io.mapOptional("SizeM1BitWidth", res.SizeM1BitWidth);
33  }
34 };
35 
36 template <>
38  static void enumeration(IO &io,
41  io.enumCase(value, "UniformRetVal",
43  io.enumCase(value, "UniqueRetVal",
45  io.enumCase(value, "VirtualConstProp",
47  }
48 };
49 
50 template <> struct MappingTraits<WholeProgramDevirtResolution::ByArg> {
52  io.mapOptional("Kind", res.TheKind);
53  io.mapOptional("Info", res.Info);
54  }
55 };
56 
57 template <>
59  std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>> {
60  static void inputOne(
61  IO &io, StringRef Key,
62  std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg> &V) {
63  std::vector<uint64_t> Args;
64  std::pair<StringRef, StringRef> P = {"", Key};
65  while (!P.second.empty()) {
66  P = P.second.split(',');
67  uint64_t Arg;
68  if (P.first.getAsInteger(0, Arg)) {
69  io.setError("key not an integer");
70  return;
71  }
72  Args.push_back(Arg);
73  }
74  io.mapRequired(Key.str().c_str(), V[Args]);
75  }
76  static void output(
77  IO &io,
78  std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg> &V) {
79  for (auto &P : V) {
80  std::string Key;
81  for (uint64_t Arg : P.first) {
82  if (!Key.empty())
83  Key += ',';
84  Key += llvm::utostr(Arg);
85  }
86  io.mapRequired(Key.c_str(), P.second);
87  }
88  }
89 };
90 
94  io.enumCase(value, "SingleImpl", WholeProgramDevirtResolution::SingleImpl);
95  }
96 };
97 
99  static void mapping(IO &io, WholeProgramDevirtResolution &res) {
100  io.mapOptional("Kind", res.TheKind);
101  io.mapOptional("SingleImplName", res.SingleImplName);
102  io.mapOptional("ResByArg", res.ResByArg);
103  }
104 };
105 
106 template <>
107 struct CustomMappingTraits<std::map<uint64_t, WholeProgramDevirtResolution>> {
108  static void inputOne(IO &io, StringRef Key,
109  std::map<uint64_t, WholeProgramDevirtResolution> &V) {
110  uint64_t KeyInt;
111  if (Key.getAsInteger(0, KeyInt)) {
112  io.setError("key not an integer");
113  return;
114  }
115  io.mapRequired(Key.str().c_str(), V[KeyInt]);
116  }
117  static void output(IO &io, std::map<uint64_t, WholeProgramDevirtResolution> &V) {
118  for (auto &P : V)
119  io.mapRequired(llvm::utostr(P.first).c_str(), P.second);
120  }
121 };
122 
123 template <> struct MappingTraits<TypeIdSummary> {
124  static void mapping(IO &io, TypeIdSummary& summary) {
125  io.mapOptional("TTRes", summary.TTRes);
126  io.mapOptional("WPDRes", summary.WPDRes);
127  }
128 };
129 
131  unsigned Linkage;
133  std::vector<uint64_t> TypeTests;
134  std::vector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
136  std::vector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
138 };
139 
140 } // End yaml namespace
141 } // End llvm namespace
142 
143 namespace llvm {
144 namespace yaml {
145 
146 template <> struct MappingTraits<FunctionSummary::VFuncId> {
147  static void mapping(IO &io, FunctionSummary::VFuncId& id) {
148  io.mapOptional("GUID", id.GUID);
149  io.mapOptional("Offset", id.Offset);
150  }
151 };
152 
153 template <> struct MappingTraits<FunctionSummary::ConstVCall> {
154  static void mapping(IO &io, FunctionSummary::ConstVCall& id) {
155  io.mapOptional("VFunc", id.VFunc);
156  io.mapOptional("Args", id.Args);
157  }
158 };
159 
160 } // End yaml namespace
161 } // End llvm namespace
162 
163 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummary::VFuncId)
164 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummary::ConstVCall)
165 
166 namespace llvm {
167 namespace yaml {
168 
169 template <> struct MappingTraits<FunctionSummaryYaml> {
170  static void mapping(IO &io, FunctionSummaryYaml& summary) {
171  io.mapOptional("Linkage", summary.Linkage);
172  io.mapOptional("NotEligibleToImport", summary.NotEligibleToImport);
173  io.mapOptional("Live", summary.Live);
174  io.mapOptional("TypeTests", summary.TypeTests);
175  io.mapOptional("TypeTestAssumeVCalls", summary.TypeTestAssumeVCalls);
176  io.mapOptional("TypeCheckedLoadVCalls", summary.TypeCheckedLoadVCalls);
177  io.mapOptional("TypeTestAssumeConstVCalls",
178  summary.TypeTestAssumeConstVCalls);
179  io.mapOptional("TypeCheckedLoadConstVCalls",
181  }
182 };
183 
184 } // End yaml namespace
185 } // End llvm namespace
186 
187 LLVM_YAML_IS_STRING_MAP(TypeIdSummary)
188 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummaryYaml)
189 
190 namespace llvm {
191 namespace yaml {
192 
193 // FIXME: Add YAML mappings for the rest of the module summary.
195  static void inputOne(IO &io, StringRef Key, GlobalValueSummaryMapTy &V) {
196  std::vector<FunctionSummaryYaml> FSums;
197  io.mapRequired(Key.str().c_str(), FSums);
198  uint64_t KeyInt;
199  if (Key.getAsInteger(0, KeyInt)) {
200  io.setError("key not an integer");
201  return;
202  }
203  auto &Elem = V[KeyInt];
204  for (auto &FSum : FSums) {
205  Elem.SummaryList.push_back(llvm::make_unique<FunctionSummary>(
207  static_cast<GlobalValue::LinkageTypes>(FSum.Linkage),
208  FSum.NotEligibleToImport, FSum.Live),
210  std::move(FSum.TypeTests), std::move(FSum.TypeTestAssumeVCalls),
211  std::move(FSum.TypeCheckedLoadVCalls),
212  std::move(FSum.TypeTestAssumeConstVCalls),
213  std::move(FSum.TypeCheckedLoadConstVCalls)));
214  }
215  }
216  static void output(IO &io, GlobalValueSummaryMapTy &V) {
217  for (auto &P : V) {
218  std::vector<FunctionSummaryYaml> FSums;
219  for (auto &Sum : P.second.SummaryList) {
220  if (auto *FSum = dyn_cast<FunctionSummary>(Sum.get()))
221  FSums.push_back(FunctionSummaryYaml{
222  FSum->flags().Linkage,
223  static_cast<bool>(FSum->flags().NotEligibleToImport),
224  static_cast<bool>(FSum->flags().Live), FSum->type_tests(),
225  FSum->type_test_assume_vcalls(), FSum->type_checked_load_vcalls(),
226  FSum->type_test_assume_const_vcalls(),
227  FSum->type_checked_load_const_vcalls()});
228  }
229  if (!FSums.empty())
230  io.mapRequired(llvm::utostr(P.first).c_str(), FSums);
231  }
232  }
233 };
234 
235 template <> struct MappingTraits<ModuleSummaryIndex> {
236  static void mapping(IO &io, ModuleSummaryIndex& index) {
237  io.mapOptional("GlobalValueMap", index.GlobalValueMap);
238  io.mapOptional("TypeIdMap", index.TypeIdMap);
239  io.mapOptional("WithGlobalValueDeadStripping",
240  index.WithGlobalValueDeadStripping);
241 
242  if (io.outputting()) {
243  std::vector<std::string> CfiFunctionDefs(index.CfiFunctionDefs.begin(),
244  index.CfiFunctionDefs.end());
245  io.mapOptional("CfiFunctionDefs", CfiFunctionDefs);
246  std::vector<std::string> CfiFunctionDecls(index.CfiFunctionDecls.begin(),
247  index.CfiFunctionDecls.end());
248  io.mapOptional("CfiFunctionDecls", CfiFunctionDecls);
249  } else {
250  std::vector<std::string> CfiFunctionDefs;
251  io.mapOptional("CfiFunctionDefs", CfiFunctionDefs);
252  index.CfiFunctionDefs = {CfiFunctionDefs.begin(), CfiFunctionDefs.end()};
253  std::vector<std::string> CfiFunctionDecls;
254  io.mapOptional("CfiFunctionDecls", CfiFunctionDecls);
255  index.CfiFunctionDecls = {CfiFunctionDecls.begin(),
256  CfiFunctionDecls.end()};
257  }
258  }
259 };
260 
261 } // End yaml namespace
262 } // End llvm namespace
263 
264 #endif
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:497
std::vector< FunctionSummary::ConstVCall > TypeCheckedLoadConstVCalls
void mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:656
Unsatisfiable type (i.e. no global has this type metadata)
uint64_t Info
Additional information for the resolution:
static void enumeration(IO &io, WholeProgramDevirtResolution::ByArg::Kind &value)
static void enumeration(IO &io, WholeProgramDevirtResolution::Kind &value)
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence...
Definition: YAMLTraits.h:1643
Kind
Specifies which kind of type check we should emit for this byte array.
std::map< uint64_t, WholeProgramDevirtResolution > WPDRes
Mapping from byte offset to whole-program devirt resolution for that (typeid, byte offset) pair...
virtual void setError(const Twine &)=0
TypeTestResolution TTRes
static void inputOne(IO &io, StringRef Key, GlobalValueSummaryMapTy &V)
static void mapping(IO &io, WholeProgramDevirtResolution::ByArg &res)
#define LLVM_YAML_IS_STRING_MAP(_type)
Utility for declaring that std::map<std::string, _type> should be considered a YAML map...
Definition: YAMLTraits.h:1705
Just do a regular virtual call.
std::map< GlobalValue::GUID, GlobalValueSummaryInfo > GlobalValueSummaryMapTy
Map from global value GUID to corresponding summary structures.
enum llvm::WholeProgramDevirtResolution::Kind TheKind
std::vector< FunctionSummary::VFuncId > TypeCheckedLoadVCalls
static void output(IO &io, GlobalValueSummaryMapTy &V)
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
static std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:160
static void output(IO &io, std::map< uint64_t, WholeProgramDevirtResolution > &V)
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static void output(IO &io, std::map< std::vector< uint64_t >, WholeProgramDevirtResolution::ByArg > &V)
static void mapping(IO &io, FunctionSummary::VFuncId &id)
static void inputOne(IO &io, StringRef Key, std::map< uint64_t, WholeProgramDevirtResolution > &V)
static void mapping(IO &io, ModuleSummaryIndex &index)
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:590
#define P(N)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static void inputOne(IO &io, StringRef Key, std::map< std::vector< uint64_t >, WholeProgramDevirtResolution::ByArg > &V)
This class should be specialized by any type that needs to be converted to/from a YAML mapping in the...
Definition: YAMLTraits.h:225
Single element (last example in "Short Inline Bit Vectors")
enum llvm::WholeProgramDevirtResolution::ByArg::Kind TheKind
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:228
An "identifier" for a virtual function.
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:98
Single implementation devirtualization.
std::vector< FunctionSummary::VFuncId > TypeTestAssumeVCalls
static void mapping(IO &io, TypeTestResolution &res)
std::vector< FunctionSummary::ConstVCall > TypeTestAssumeConstVCalls
enum llvm::TypeTestResolution::Kind TheKind
A specification for a virtual function call with all constant integer arguments.
LLVM_NODISCARD std::pair< StringRef, StringRef > split(char Separator) const
Split into two substrings around the first occurrence of a separator character.
Definition: StringRef.h:727
Test a byte array (first example)
std::map< std::vector< uint64_t >, ByArg > ResByArg
Resolutions for calls with all constant integer arguments (excluding the first argument, "this"), where the key is the argument vector.
All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors") ...
Inlined bit vector ("Short Inline Bit Vectors")
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
Function summary information to aid decisions and implementation of importing.
static void mapping(IO &io, TypeIdSummary &summary)
static void mapping(IO &io, FunctionSummaryYaml &summary)
virtual bool outputting()=0
const unsigned Kind
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
static void enumeration(IO &io, TypeTestResolution::Kind &value)
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
void mapRequired(const char *Key, T &Val)
Definition: YAMLTraits.h:646
static void mapping(IO &io, FunctionSummary::ConstVCall &id)
static void mapping(IO &io, WholeProgramDevirtResolution &res)