1 //===-- llvm/ModuleSummaryIndexYAML.h - YAML I/O for summary ----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_IR_MODULESUMMARYINDEXYAML_H
11 #define LLVM_IR_MODULESUMMARYINDEXYAML_H
13 #include "llvm/IR/ModuleSummaryIndex.h"
14 #include "llvm/Support/YAMLTraits.h"
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);
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);
36 template <> struct MappingTraits<TypeIdSummary> {
37 static void mapping(IO &io, TypeIdSummary& summary) {
38 io.mapOptional("TTRes", summary.TTRes);
42 struct FunctionSummaryYaml {
43 std::vector<uint64_t> TypeTests;
46 } // End yaml namespace
47 } // End llvm namespace
49 LLVM_YAML_IS_SEQUENCE_VECTOR(uint64_t)
54 template <> struct MappingTraits<FunctionSummaryYaml> {
55 static void mapping(IO &io, FunctionSummaryYaml& summary) {
56 io.mapOptional("TypeTests", summary.TypeTests);
60 } // End yaml namespace
61 } // End llvm namespace
63 LLVM_YAML_IS_STRING_MAP(TypeIdSummary)
64 LLVM_YAML_IS_SEQUENCE_VECTOR(FunctionSummaryYaml)
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);
75 if (Key.getAsInteger(0, KeyInt)) {
76 io.setError("key not an integer");
79 auto &Elem = V[KeyInt];
80 for (auto &FSum : FSums) {
81 GlobalValueSummary::GVFlags GVFlags(GlobalValue::ExternalLinkage, false,
83 Elem.push_back(llvm::make_unique<FunctionSummary>(
84 GVFlags, 0, ArrayRef<ValueInfo>{},
85 ArrayRef<FunctionSummary::EdgeTy>{}, std::move(FSum.TypeTests)));
88 static void output(IO &io, GlobalValueSummaryMapTy &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()});
96 io.mapRequired(llvm::utostr(P.first).c_str(), FSums);
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);
108 } // End yaml namespace
109 } // End llvm namespace