/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
Line | Count | Source (jump to first uncovered line) |
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 | | |
13 | | #include "llvm/IR/ModuleSummaryIndex.h" |
14 | | #include "llvm/Support/YAMLTraits.h" |
15 | | |
16 | | namespace llvm { |
17 | | namespace yaml { |
18 | | |
19 | | template <> struct ScalarEnumerationTraits<TypeTestResolution::Kind> { |
20 | 65 | static void enumeration(IO &io, TypeTestResolution::Kind &value) { |
21 | 65 | io.enumCase(value, "Unsat", TypeTestResolution::Unsat); |
22 | 65 | io.enumCase(value, "ByteArray", TypeTestResolution::ByteArray); |
23 | 65 | io.enumCase(value, "Inline", TypeTestResolution::Inline); |
24 | 65 | io.enumCase(value, "Single", TypeTestResolution::Single); |
25 | 65 | io.enumCase(value, "AllOnes", TypeTestResolution::AllOnes); |
26 | 65 | } |
27 | | }; |
28 | | |
29 | | template <> struct MappingTraits<TypeTestResolution> { |
30 | 65 | static void mapping(IO &io, TypeTestResolution &res) { |
31 | 65 | io.mapOptional("Kind", res.TheKind); |
32 | 65 | io.mapOptional("SizeM1BitWidth", res.SizeM1BitWidth); |
33 | 65 | io.mapOptional("AlignLog2", res.AlignLog2); |
34 | 65 | io.mapOptional("SizeM1", res.SizeM1); |
35 | 65 | io.mapOptional("BitMask", res.BitMask); |
36 | 65 | io.mapOptional("InlineBits", res.InlineBits); |
37 | 65 | } |
38 | | }; |
39 | | |
40 | | template <> |
41 | | struct ScalarEnumerationTraits<WholeProgramDevirtResolution::ByArg::Kind> { |
42 | | static void enumeration(IO &io, |
43 | 25 | WholeProgramDevirtResolution::ByArg::Kind &value) { |
44 | 25 | io.enumCase(value, "Indir", WholeProgramDevirtResolution::ByArg::Indir); |
45 | 25 | io.enumCase(value, "UniformRetVal", |
46 | 25 | WholeProgramDevirtResolution::ByArg::UniformRetVal); |
47 | 25 | io.enumCase(value, "UniqueRetVal", |
48 | 25 | WholeProgramDevirtResolution::ByArg::UniqueRetVal); |
49 | 25 | io.enumCase(value, "VirtualConstProp", |
50 | 25 | WholeProgramDevirtResolution::ByArg::VirtualConstProp); |
51 | 25 | } |
52 | | }; |
53 | | |
54 | | template <> struct MappingTraits<WholeProgramDevirtResolution::ByArg> { |
55 | 25 | static void mapping(IO &io, WholeProgramDevirtResolution::ByArg &res) { |
56 | 25 | io.mapOptional("Kind", res.TheKind); |
57 | 25 | io.mapOptional("Info", res.Info); |
58 | 25 | io.mapOptional("Byte", res.Byte); |
59 | 25 | io.mapOptional("Bit", res.Bit); |
60 | 25 | } |
61 | | }; |
62 | | |
63 | | template <> |
64 | | struct CustomMappingTraits< |
65 | | std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg>> { |
66 | | static void inputOne( |
67 | | IO &io, StringRef Key, |
68 | 15 | std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg> &V) { |
69 | 15 | std::vector<uint64_t> Args; |
70 | 15 | std::pair<StringRef, StringRef> P = {"", Key}; |
71 | 30 | while (!P.second.empty()30 ) { |
72 | 15 | P = P.second.split(','); |
73 | 15 | uint64_t Arg; |
74 | 15 | if (P.first.getAsInteger(0, Arg)15 ) { |
75 | 0 | io.setError("key not an integer"); |
76 | 0 | return; |
77 | 0 | } |
78 | 15 | Args.push_back(Arg); |
79 | 15 | } |
80 | 15 | io.mapRequired(Key.str().c_str(), V[Args]); |
81 | 15 | } |
82 | | static void output( |
83 | | IO &io, |
84 | 17 | std::map<std::vector<uint64_t>, WholeProgramDevirtResolution::ByArg> &V) { |
85 | 10 | for (auto &P : V) { |
86 | 10 | std::string Key; |
87 | 17 | for (uint64_t Arg : P.first) { |
88 | 17 | if (!Key.empty()) |
89 | 8 | Key += ','; |
90 | 17 | Key += llvm::utostr(Arg); |
91 | 17 | } |
92 | 10 | io.mapRequired(Key.c_str(), P.second); |
93 | 10 | } |
94 | 17 | } |
95 | | }; |
96 | | |
97 | | template <> struct ScalarEnumerationTraits<WholeProgramDevirtResolution::Kind> { |
98 | 33 | static void enumeration(IO &io, WholeProgramDevirtResolution::Kind &value) { |
99 | 33 | io.enumCase(value, "Indir", WholeProgramDevirtResolution::Indir); |
100 | 33 | io.enumCase(value, "SingleImpl", WholeProgramDevirtResolution::SingleImpl); |
101 | 33 | } |
102 | | }; |
103 | | |
104 | | template <> struct MappingTraits<WholeProgramDevirtResolution> { |
105 | 33 | static void mapping(IO &io, WholeProgramDevirtResolution &res) { |
106 | 33 | io.mapOptional("Kind", res.TheKind); |
107 | 33 | io.mapOptional("SingleImplName", res.SingleImplName); |
108 | 33 | io.mapOptional("ResByArg", res.ResByArg); |
109 | 33 | } |
110 | | }; |
111 | | |
112 | | template <> |
113 | | struct CustomMappingTraits<std::map<uint64_t, WholeProgramDevirtResolution>> { |
114 | | static void inputOne(IO &io, StringRef Key, |
115 | 16 | std::map<uint64_t, WholeProgramDevirtResolution> &V) { |
116 | 16 | uint64_t KeyInt; |
117 | 16 | if (Key.getAsInteger(0, KeyInt)16 ) { |
118 | 0 | io.setError("key not an integer"); |
119 | 0 | return; |
120 | 0 | } |
121 | 16 | io.mapRequired(Key.str().c_str(), V[KeyInt]); |
122 | 16 | } |
123 | 34 | static void output(IO &io, std::map<uint64_t, WholeProgramDevirtResolution> &V) { |
124 | 34 | for (auto &P : V) |
125 | 17 | io.mapRequired(llvm::utostr(P.first).c_str(), P.second); |
126 | 34 | } |
127 | | }; |
128 | | |
129 | | template <> struct MappingTraits<TypeIdSummary> { |
130 | 80 | static void mapping(IO &io, TypeIdSummary& summary) { |
131 | 80 | io.mapOptional("TTRes", summary.TTRes); |
132 | 80 | io.mapOptional("WPDRes", summary.WPDRes); |
133 | 80 | } |
134 | | }; |
135 | | |
136 | | struct FunctionSummaryYaml { |
137 | | unsigned Linkage; |
138 | | bool NotEligibleToImport, Live; |
139 | | std::vector<uint64_t> TypeTests; |
140 | | std::vector<FunctionSummary::VFuncId> TypeTestAssumeVCalls, |
141 | | TypeCheckedLoadVCalls; |
142 | | std::vector<FunctionSummary::ConstVCall> TypeTestAssumeConstVCalls, |
143 | | TypeCheckedLoadConstVCalls; |
144 | | }; |
145 | | |
146 | | } // End yaml namespace |
147 | | } // End llvm namespace |
148 | | |
149 | | namespace llvm { |
150 | | namespace yaml { |
151 | | |
152 | | template <> struct MappingTraits<FunctionSummary::VFuncId> { |
153 | 60 | static void mapping(IO &io, FunctionSummary::VFuncId& id) { |
154 | 60 | io.mapOptional("GUID", id.GUID); |
155 | 60 | io.mapOptional("Offset", id.Offset); |
156 | 60 | } |
157 | | }; |
158 | | |
159 | | template <> struct MappingTraits<FunctionSummary::ConstVCall> { |
160 | 28 | static void mapping(IO &io, FunctionSummary::ConstVCall& id) { |
161 | 28 | io.mapOptional("VFunc", id.VFunc); |
162 | 28 | io.mapOptional("Args", id.Args); |
163 | 28 | } |
164 | | }; |
165 | | |
166 | | } // End yaml namespace |
167 | | } // End llvm namespace |
168 | | |
169 | | LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummary::VFuncId) |
170 | | LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummary::ConstVCall) |
171 | | |
172 | | namespace llvm { |
173 | | namespace yaml { |
174 | | |
175 | | template <> struct MappingTraits<FunctionSummaryYaml> { |
176 | 36 | static void mapping(IO &io, FunctionSummaryYaml& summary) { |
177 | 36 | io.mapOptional("Linkage", summary.Linkage); |
178 | 36 | io.mapOptional("NotEligibleToImport", summary.NotEligibleToImport); |
179 | 36 | io.mapOptional("Live", summary.Live); |
180 | 36 | io.mapOptional("TypeTests", summary.TypeTests); |
181 | 36 | io.mapOptional("TypeTestAssumeVCalls", summary.TypeTestAssumeVCalls); |
182 | 36 | io.mapOptional("TypeCheckedLoadVCalls", summary.TypeCheckedLoadVCalls); |
183 | 36 | io.mapOptional("TypeTestAssumeConstVCalls", |
184 | 36 | summary.TypeTestAssumeConstVCalls); |
185 | 36 | io.mapOptional("TypeCheckedLoadConstVCalls", |
186 | 36 | summary.TypeCheckedLoadConstVCalls); |
187 | 36 | } |
188 | | }; |
189 | | |
190 | | } // End yaml namespace |
191 | | } // End llvm namespace |
192 | | |
193 | | LLVM_YAML_IS_STRING_MAP(TypeIdSummary) |
194 | | LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummaryYaml) |
195 | | |
196 | | namespace llvm { |
197 | | namespace yaml { |
198 | | |
199 | | // FIXME: Add YAML mappings for the rest of the module summary. |
200 | | template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> { |
201 | 18 | static void inputOne(IO &io, StringRef Key, GlobalValueSummaryMapTy &V) { |
202 | 18 | std::vector<FunctionSummaryYaml> FSums; |
203 | 18 | io.mapRequired(Key.str().c_str(), FSums); |
204 | 18 | uint64_t KeyInt; |
205 | 18 | if (Key.getAsInteger(0, KeyInt)18 ) { |
206 | 0 | io.setError("key not an integer"); |
207 | 0 | return; |
208 | 0 | } |
209 | 18 | auto &Elem = V[KeyInt]; |
210 | 18 | for (auto &FSum : FSums) { |
211 | 18 | Elem.SummaryList.push_back(llvm::make_unique<FunctionSummary>( |
212 | 18 | GlobalValueSummary::GVFlags( |
213 | 18 | static_cast<GlobalValue::LinkageTypes>(FSum.Linkage), |
214 | 18 | FSum.NotEligibleToImport, FSum.Live), |
215 | 18 | 0, FunctionSummary::FFlags{}, ArrayRef<ValueInfo>{}, |
216 | 18 | ArrayRef<FunctionSummary::EdgeTy>{}, std::move(FSum.TypeTests), |
217 | 18 | std::move(FSum.TypeTestAssumeVCalls), |
218 | 18 | std::move(FSum.TypeCheckedLoadVCalls), |
219 | 18 | std::move(FSum.TypeTestAssumeConstVCalls), |
220 | 18 | std::move(FSum.TypeCheckedLoadConstVCalls))); |
221 | 18 | } |
222 | 18 | } |
223 | 20 | static void output(IO &io, GlobalValueSummaryMapTy &V) { |
224 | 18 | for (auto &P : V) { |
225 | 18 | std::vector<FunctionSummaryYaml> FSums; |
226 | 18 | for (auto &Sum : P.second.SummaryList) { |
227 | 18 | if (auto *FSum = dyn_cast<FunctionSummary>(Sum.get())) |
228 | 18 | FSums.push_back(FunctionSummaryYaml{ |
229 | 18 | FSum->flags().Linkage, |
230 | 18 | static_cast<bool>(FSum->flags().NotEligibleToImport), |
231 | 18 | static_cast<bool>(FSum->flags().Live), FSum->type_tests(), |
232 | 18 | FSum->type_test_assume_vcalls(), FSum->type_checked_load_vcalls(), |
233 | 18 | FSum->type_test_assume_const_vcalls(), |
234 | 18 | FSum->type_checked_load_const_vcalls()}); |
235 | 18 | } |
236 | 18 | if (!FSums.empty()) |
237 | 18 | io.mapRequired(llvm::utostr(P.first).c_str(), FSums); |
238 | 18 | } |
239 | 20 | } |
240 | | }; |
241 | | |
242 | | template <> struct MappingTraits<ModuleSummaryIndex> { |
243 | 51 | static void mapping(IO &io, ModuleSummaryIndex& index) { |
244 | 51 | io.mapOptional("GlobalValueMap", index.GlobalValueMap); |
245 | 51 | io.mapOptional("TypeIdMap", index.TypeIdMap); |
246 | 51 | io.mapOptional("WithGlobalValueDeadStripping", |
247 | 51 | index.WithGlobalValueDeadStripping); |
248 | 51 | |
249 | 51 | if (io.outputting()51 ) { |
250 | 20 | std::vector<std::string> CfiFunctionDefs(index.CfiFunctionDefs.begin(), |
251 | 20 | index.CfiFunctionDefs.end()); |
252 | 20 | io.mapOptional("CfiFunctionDefs", CfiFunctionDefs); |
253 | 20 | std::vector<std::string> CfiFunctionDecls(index.CfiFunctionDecls.begin(), |
254 | 20 | index.CfiFunctionDecls.end()); |
255 | 20 | io.mapOptional("CfiFunctionDecls", CfiFunctionDecls); |
256 | 51 | } else { |
257 | 31 | std::vector<std::string> CfiFunctionDefs; |
258 | 31 | io.mapOptional("CfiFunctionDefs", CfiFunctionDefs); |
259 | 31 | index.CfiFunctionDefs = {CfiFunctionDefs.begin(), CfiFunctionDefs.end()}; |
260 | 31 | std::vector<std::string> CfiFunctionDecls; |
261 | 31 | io.mapOptional("CfiFunctionDecls", CfiFunctionDecls); |
262 | 31 | index.CfiFunctionDecls = {CfiFunctionDecls.begin(), |
263 | 31 | CfiFunctionDecls.end()}; |
264 | 31 | } |
265 | 51 | } |
266 | | }; |
267 | | |
268 | | } // End yaml namespace |
269 | | } // End llvm namespace |
270 | | |
271 | | #endif |