blob: f7fa16df11003ddc6407504429664afb1d41044c [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===-- llvm/ModuleSummaryIndexYAML.h - YAML I/O for summary ----*- C++ -*-===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_IR_MODULESUMMARYINDEXYAML_H
10#define LLVM_IR_MODULESUMMARYINDEXYAML_H
11
12#include "llvm/IR/ModuleSummaryIndex.h"
13#include "llvm/Support/YAMLTraits.h"
14
15namespace llvm {
16namespace yaml {
17
18template <> struct ScalarEnumerationTraits<TypeTestResolution::Kind> {
19 static void enumeration(IO &io, TypeTestResolution::Kind &value) {
Olivier Deprezf4ef2d02021-04-20 13:36:24 +020020 io.enumCase(value, "Unknown", TypeTestResolution::Unknown);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +010021 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
29template <> struct MappingTraits<TypeTestResolution> {
30 static void mapping(IO &io, TypeTestResolution &res) {
31 io.mapOptional("Kind", res.TheKind);
32 io.mapOptional("SizeM1BitWidth", res.SizeM1BitWidth);
33 io.mapOptional("AlignLog2", res.AlignLog2);
34 io.mapOptional("SizeM1", res.SizeM1);
35 io.mapOptional("BitMask", res.BitMask);
36 io.mapOptional("InlineBits", res.InlineBits);
37 }
38};
39
40template <>
41struct ScalarEnumerationTraits<WholeProgramDevirtResolution::ByArg::Kind> {
42 static void enumeration(IO &io,
43 WholeProgramDevirtResolution::ByArg::Kind &value) {
44 io.enumCase(value, "Indir", WholeProgramDevirtResolution::ByArg::Indir);
45 io.enumCase(value, "UniformRetVal",
46 WholeProgramDevirtResolution::ByArg::UniformRetVal);
47 io.enumCase(value, "UniqueRetVal",
48 WholeProgramDevirtResolution::ByArg::UniqueRetVal);
49 io.enumCase(value, "VirtualConstProp",
50 WholeProgramDevirtResolution::ByArg::VirtualConstProp);
51 }
52};
53
54template <> struct MappingTraits<WholeProgramDevirtResolution::ByArg> {
55 static void mapping(IO &io, WholeProgramDevirtResolution::ByArg &res) {
56 io.mapOptional("Kind", res.TheKind);
57 io.mapOptional("Info", res.Info);
58 io.mapOptional("Byte", res.Byte);
59 io.mapOptional("Bit", res.Bit);
60 }
61};
62
63template <>
64struct CustomMappingTraits<
65 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>> {
66 static void inputOne(
67 IO &io, StringRef Key,
68 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg> &V) {
69 std::vector<uint64_t> Args;
70 std::pair<StringRef, StringRef> P = {"", Key};
71 while (!P.second.empty()) {
72 P = P.second.split(',');
73 uint64_t Arg;
74 if (P.first.getAsInteger(0, Arg)) {
75 io.setError("key not an integer");
76 return;
77 }
78 Args.push_back(Arg);
79 }
80 io.mapRequired(Key.str().c_str(), V[Args]);
81 }
82 static void output(
83 IO &io,
84 std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg> &V) {
85 for (auto &P : V) {
86 std::string Key;
87 for (uint64_t Arg : P.first) {
88 if (!Key.empty())
89 Key += ',';
90 Key += llvm::utostr(Arg);
91 }
92 io.mapRequired(Key.c_str(), P.second);
93 }
94 }
95};
96
97template <> struct ScalarEnumerationTraits<WholeProgramDevirtResolution::Kind> {
98 static void enumeration(IO &io, WholeProgramDevirtResolution::Kind &value) {
99 io.enumCase(value, "Indir", WholeProgramDevirtResolution::Indir);
100 io.enumCase(value, "SingleImpl", WholeProgramDevirtResolution::SingleImpl);
101 io.enumCase(value, "BranchFunnel",
102 WholeProgramDevirtResolution::BranchFunnel);
103 }
104};
105
106template <> struct MappingTraits<WholeProgramDevirtResolution> {
107 static void mapping(IO &io, WholeProgramDevirtResolution &res) {
108 io.mapOptional("Kind", res.TheKind);
109 io.mapOptional("SingleImplName", res.SingleImplName);
110 io.mapOptional("ResByArg", res.ResByArg);
111 }
112};
113
114template <>
115struct CustomMappingTraits<std::map<uint64_t, WholeProgramDevirtResolution>> {
116 static void inputOne(IO &io, StringRef Key,
117 std::map<uint64_t, WholeProgramDevirtResolution> &V) {
118 uint64_t KeyInt;
119 if (Key.getAsInteger(0, KeyInt)) {
120 io.setError("key not an integer");
121 return;
122 }
123 io.mapRequired(Key.str().c_str(), V[KeyInt]);
124 }
125 static void output(IO &io, std::map<uint64_t, WholeProgramDevirtResolution> &V) {
126 for (auto &P : V)
127 io.mapRequired(llvm::utostr(P.first).c_str(), P.second);
128 }
129};
130
131template <> struct MappingTraits<TypeIdSummary> {
132 static void mapping(IO &io, TypeIdSummary& summary) {
133 io.mapOptional("TTRes", summary.TTRes);
134 io.mapOptional("WPDRes", summary.WPDRes);
135 }
136};
137
138struct FunctionSummaryYaml {
139 unsigned Linkage;
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100140 bool NotEligibleToImport, Live, IsLocal, CanAutoHide;
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100141 std::vector<uint64_t> Refs;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100142 std::vector<uint64_t> TypeTests;
143 std::vector<FunctionSummary::VFuncId> TypeTestAssumeVCalls,
144 TypeCheckedLoadVCalls;
145 std::vector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls,
146 TypeCheckedLoadConstVCalls;
147};
148
149} // End yaml namespace
150} // End llvm namespace
151
152namespace llvm {
153namespace yaml {
154
155template <> struct MappingTraits<FunctionSummary::VFuncId> {
156 static void mapping(IO &io, FunctionSummary::VFuncId& id) {
157 io.mapOptional("GUID", id.GUID);
158 io.mapOptional("Offset", id.Offset);
159 }
160};
161
162template <> struct MappingTraits<FunctionSummary::ConstVCall> {
163 static void mapping(IO &io, FunctionSummary::ConstVCall& id) {
164 io.mapOptional("VFunc", id.VFunc);
165 io.mapOptional("Args", id.Args);
166 }
167};
168
169} // End yaml namespace
170} // End llvm namespace
171
172LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummary::VFuncId)
173LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummary::ConstVCall)
174
175namespace llvm {
176namespace yaml {
177
178template <> struct MappingTraits<FunctionSummaryYaml> {
179 static void mapping(IO &io, FunctionSummaryYaml& summary) {
180 io.mapOptional("Linkage", summary.Linkage);
181 io.mapOptional("NotEligibleToImport", summary.NotEligibleToImport);
182 io.mapOptional("Live", summary.Live);
183 io.mapOptional("Local", summary.IsLocal);
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100184 io.mapOptional("CanAutoHide", summary.CanAutoHide);
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100185 io.mapOptional("Refs", summary.Refs);
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100186 io.mapOptional("TypeTests", summary.TypeTests);
187 io.mapOptional("TypeTestAssumeVCalls", summary.TypeTestAssumeVCalls);
188 io.mapOptional("TypeCheckedLoadVCalls", summary.TypeCheckedLoadVCalls);
189 io.mapOptional("TypeTestAssumeConstVCalls",
190 summary.TypeTestAssumeConstVCalls);
191 io.mapOptional("TypeCheckedLoadConstVCalls",
192 summary.TypeCheckedLoadConstVCalls);
193 }
194};
195
196} // End yaml namespace
197} // End llvm namespace
198
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100199LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummaryYaml)
200
201namespace llvm {
202namespace yaml {
203
204// FIXME: Add YAML mappings for the rest of the module summary.
205template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
206 static void inputOne(IO &io, StringRef Key, GlobalValueSummaryMapTy &V) {
207 std::vector<FunctionSummaryYaml> FSums;
208 io.mapRequired(Key.str().c_str(), FSums);
209 uint64_t KeyInt;
210 if (Key.getAsInteger(0, KeyInt)) {
211 io.setError("key not an integer");
212 return;
213 }
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100214 if (!V.count(KeyInt))
215 V.emplace(KeyInt, /*IsAnalysis=*/false);
216 auto &Elem = V.find(KeyInt)->second;
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100217 for (auto &FSum : FSums) {
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100218 std::vector<ValueInfo> Refs;
219 for (auto &RefGUID : FSum.Refs) {
220 if (!V.count(RefGUID))
221 V.emplace(RefGUID, /*IsAnalysis=*/false);
222 Refs.push_back(ValueInfo(/*IsAnalysis=*/false, &*V.find(RefGUID)));
223 }
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200224 Elem.SummaryList.push_back(std::make_unique<FunctionSummary>(
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100225 GlobalValueSummary::GVFlags(
226 static_cast<GlobalValue::LinkageTypes>(FSum.Linkage),
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200227 FSum.NotEligibleToImport, FSum.Live, FSum.IsLocal,
228 FSum.CanAutoHide),
Andrew Walbran16937d02019-10-22 13:54:20 +0100229 /*NumInsts=*/0, FunctionSummary::FFlags{}, /*EntryCount=*/0, Refs,
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100230 ArrayRef<FunctionSummary::EdgeTy>{}, std::move(FSum.TypeTests),
231 std::move(FSum.TypeTestAssumeVCalls),
232 std::move(FSum.TypeCheckedLoadVCalls),
233 std::move(FSum.TypeTestAssumeConstVCalls),
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200234 std::move(FSum.TypeCheckedLoadConstVCalls),
235 ArrayRef<FunctionSummary::ParamAccess>{}));
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100236 }
237 }
238 static void output(IO &io, GlobalValueSummaryMapTy &V) {
239 for (auto &P : V) {
240 std::vector<FunctionSummaryYaml> FSums;
241 for (auto &Sum : P.second.SummaryList) {
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100242 if (auto *FSum = dyn_cast<FunctionSummary>(Sum.get())) {
243 std::vector<uint64_t> Refs;
244 for (auto &VI : FSum->refs())
245 Refs.push_back(VI.getGUID());
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100246 FSums.push_back(FunctionSummaryYaml{
247 FSum->flags().Linkage,
248 static_cast<bool>(FSum->flags().NotEligibleToImport),
249 static_cast<bool>(FSum->flags().Live),
Andrew Walbran3d2c1972020-04-07 12:24:26 +0100250 static_cast<bool>(FSum->flags().DSOLocal),
251 static_cast<bool>(FSum->flags().CanAutoHide), Refs,
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100252 FSum->type_tests(), FSum->type_test_assume_vcalls(),
253 FSum->type_checked_load_vcalls(),
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100254 FSum->type_test_assume_const_vcalls(),
255 FSum->type_checked_load_const_vcalls()});
Andrew Scullcdfcccc2018-10-05 20:58:37 +0100256 }
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100257 }
258 if (!FSums.empty())
259 io.mapRequired(llvm::utostr(P.first).c_str(), FSums);
260 }
261 }
262};
263
Andrew Scull0372a572018-11-16 15:47:06 +0000264template <> struct CustomMappingTraits<TypeIdSummaryMapTy> {
265 static void inputOne(IO &io, StringRef Key, TypeIdSummaryMapTy &V) {
266 TypeIdSummary TId;
267 io.mapRequired(Key.str().c_str(), TId);
Olivier Deprezf4ef2d02021-04-20 13:36:24 +0200268 V.insert({GlobalValue::getGUID(Key), {std::string(Key), TId}});
Andrew Scull0372a572018-11-16 15:47:06 +0000269 }
270 static void output(IO &io, TypeIdSummaryMapTy &V) {
271 for (auto TidIter = V.begin(); TidIter != V.end(); TidIter++)
272 io.mapRequired(TidIter->second.first.c_str(), TidIter->second.second);
273 }
274};
275
Andrew Scull5e1ddfa2018-08-14 10:06:54 +0100276template <> struct MappingTraits<ModuleSummaryIndex> {
277 static void mapping(IO &io, ModuleSummaryIndex& index) {
278 io.mapOptional("GlobalValueMap", index.GlobalValueMap);
279 io.mapOptional("TypeIdMap", index.TypeIdMap);
280 io.mapOptional("WithGlobalValueDeadStripping",
281 index.WithGlobalValueDeadStripping);
282
283 if (io.outputting()) {
284 std::vector<std::string> CfiFunctionDefs(index.CfiFunctionDefs.begin(),
285 index.CfiFunctionDefs.end());
286 io.mapOptional("CfiFunctionDefs", CfiFunctionDefs);
287 std::vector<std::string> CfiFunctionDecls(index.CfiFunctionDecls.begin(),
288 index.CfiFunctionDecls.end());
289 io.mapOptional("CfiFunctionDecls", CfiFunctionDecls);
290 } else {
291 std::vector<std::string> CfiFunctionDefs;
292 io.mapOptional("CfiFunctionDefs", CfiFunctionDefs);
293 index.CfiFunctionDefs = {CfiFunctionDefs.begin(), CfiFunctionDefs.end()};
294 std::vector<std::string> CfiFunctionDecls;
295 io.mapOptional("CfiFunctionDecls", CfiFunctionDecls);
296 index.CfiFunctionDecls = {CfiFunctionDecls.begin(),
297 CfiFunctionDecls.end()};
298 }
299 }
300};
301
302} // End yaml namespace
303} // End llvm namespace
304
305#endif