LLVM  4.0.0
ModuleSummaryIndexYAML.h
Go to the documentation of this file.
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 
15 
16 namespace llvm {
17 namespace yaml {
18 
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 
43  std::vector<uint64_t> TypeTests;
44 };
45 
46 } // End yaml namespace
47 } // End llvm namespace
48 
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.
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
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:494
void mapOptional(const char *Key, T &Val)
Definition: YAMLTraits.h:646
Unsatisfiable type (i.e. no global has this type metadata)
std::map< GlobalValue::GUID, GlobalValueSummaryList > GlobalValueSummaryMapTy
Map from global value GUID to corresponding summary structures.
#define LLVM_YAML_IS_SEQUENCE_VECTOR(_type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence...
Definition: YAMLTraits.h:1565
Kind
Specifies which kind of type check we should emit for this byte array.
virtual void setError(const Twine &)=0
TypeTestResolution TTRes
static void inputOne(IO &io, StringRef Key, GlobalValueSummaryMapTy &V)
#define LLVM_YAML_IS_STRING_MAP(_type)
Utility for declaring that std::map<std::string, _type> should be considered a YAML map...
Definition: YAMLTraits.h:1616
static void output(IO &io, GlobalValueSummaryMapTy &V)
This class should be specialized by any type that needs to be converted to/from a YAML mapping...
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory)...
Definition: APInt.h:33
static std::string utostr(uint64_t X, bool isNeg=false)
Definition: StringExtras.h:79
Class to hold module path string table and global value map, and encapsulate methods for operating on...
static void mapping(IO &io, ModuleSummaryIndex &index)
void enumCase(T &Val, const char *Str, const T ConstVal)
Definition: YAMLTraits.h:581
#define P(N)
This class should be specialized by any type that needs to be converted to/from a YAML mapping in the...
Definition: YAMLTraits.h:216
Single element (last example in "Short Inline Bit Vectors")
LLVM_NODISCARD std::string str() const
str - Get the contents as an std::string.
Definition: StringRef.h:225
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition: YAMLTraits.h:97
static void mapping(IO &io, TypeTestResolution &res)
enum llvm::TypeTestResolution::Kind TheKind
Test a byte array (first example)
All-ones bit vector ("Eliminating Bit Vector Checks for All-Ones Bit Vectors") ...
Inlined bit vector ("Short Inline Bit Vectors")
unsigned SizeM1BitWidth
Range of size-1 expressed as a bit width.
static void mapping(IO &io, TypeIdSummary &summary)
static void mapping(IO &io, FunctionSummaryYaml &summary)
const unsigned Kind
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
static void enumeration(IO &io, TypeTestResolution::Kind &value)
Group flags (Linkage, NotEligibleToImport, etc.) as a bitfield.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47
void mapRequired(const char *Key, T &Val)
Definition: YAMLTraits.h:637