Coverage Report

Created: 2019-07-24 05:18

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