]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/IR/ModuleSummaryIndexYAML.h
Merge llvm, clang, lld and lldb release_40 branch r292009. Also update
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / IR / ModuleSummaryIndexYAML.h
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   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 <> struct MappingTraits<TypeIdSummary> {
37   static void mapping(IO &io, TypeIdSummary& summary) {
38     io.mapOptional("TTRes", summary.TTRes);
39   }
40 };
41
42 struct FunctionSummaryYaml {
43   std::vector<uint64_t> TypeTests;
44 };
45
46 } // End yaml namespace
47 } // End llvm namespace
48
49 LLVM_YAML_IS_SEQUENCE_VECTOR(uint64_t)
50
51 namespace llvm {
52 namespace yaml {
53
54 template <> struct MappingTraits<FunctionSummaryYaml> {
55   static void mapping(IO &io, FunctionSummaryYaml& summary) {
56     io.mapOptional("TypeTests", summary.TypeTests);
57   }
58 };
59
60 } // End yaml namespace
61 } // End llvm namespace
62
63 LLVM_YAML_IS_STRING_MAP(TypeIdSummary)
64 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummaryYaml)
65
66 namespace llvm {
67 namespace yaml {
68
69 // FIXME: Add YAML mappings for the rest of the module summary.
70 template <> struct CustomMappingTraits<GlobalValueSummaryMapTy> {
71   static void inputOne(IO &io, StringRef Key, GlobalValueSummaryMapTy &V) {
72     std::vector<FunctionSummaryYaml> FSums;
73     io.mapRequired(Key.str().c_str(), FSums);
74     uint64_t KeyInt;
75     if (Key.getAsInteger(0, KeyInt)) {
76       io.setError("key not an integer");
77       return;
78     }
79     auto &Elem = V[KeyInt];
80     for (auto &FSum : FSums) {
81       GlobalValueSummary::GVFlags GVFlags(GlobalValue::ExternalLinkage, false,
82                                           false);
83       Elem.push_back(llvm::make_unique<FunctionSummary>(
84           GVFlags, 0, ArrayRef<ValueInfo>{},
85           ArrayRef<FunctionSummary::EdgeTy>{}, std::move(FSum.TypeTests)));
86     }
87   }
88   static void output(IO &io, GlobalValueSummaryMapTy &V) {
89     for (auto &P : V) {
90       std::vector<FunctionSummaryYaml> FSums;
91       for (auto &Sum : P.second) {
92         if (auto *FSum = dyn_cast<FunctionSummary>(Sum.get()))
93           FSums.push_back(FunctionSummaryYaml{FSum->type_tests()});
94       }
95       if (!FSums.empty())
96         io.mapRequired(llvm::utostr(P.first).c_str(), FSums);
97     }
98   }
99 };
100
101 template <> struct MappingTraits<ModuleSummaryIndex> {
102   static void mapping(IO &io, ModuleSummaryIndex& index) {
103     io.mapOptional("GlobalValueMap", index.GlobalValueMap);
104     io.mapOptional("TypeIdMap", index.TypeIdMap);
105   }
106 };
107
108 } // End yaml namespace
109 } // End llvm namespace
110
111 #endif