Redirect DataLayout from TargetMachine to Module in ComputeValueVTs()
[oota-llvm.git] / include / llvm / CodeGen / MIRYamlMapping.h
1 //===- MIRYAMLMapping.h - Describes the mapping between MIR and YAML ------===//
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 // The MIR serialization library is currently a work in progress. It can't
11 // serialize machine functions at this time.
12 //
13 // This file implements the mapping between various MIR data structures and
14 // their corresponding YAML representation.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #ifndef LLVM_LIB_CODEGEN_MIRYAMLMAPPING_H
19 #define LLVM_LIB_CODEGEN_MIRYAMLMAPPING_H
20
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/YAMLTraits.h"
23 #include <vector>
24
25 namespace llvm {
26 namespace yaml {
27
28 /// A wrapper around std::string which contains a source range that's being
29 /// set during parsing.
30 struct StringValue {
31   std::string Value;
32   SMRange SourceRange;
33
34   StringValue() {}
35   StringValue(std::string Value) : Value(std::move(Value)) {}
36
37   bool operator==(const StringValue &Other) const {
38     return Value == Other.Value;
39   }
40 };
41
42 template <> struct ScalarTraits<StringValue> {
43   static void output(const StringValue &S, void *, llvm::raw_ostream &OS) {
44     OS << S.Value;
45   }
46
47   static StringRef input(StringRef Scalar, void *Ctx, StringValue &S) {
48     S.Value = Scalar.str();
49     if (const auto *Node =
50             reinterpret_cast<yaml::Input *>(Ctx)->getCurrentNode())
51       S.SourceRange = Node->getSourceRange();
52     return "";
53   }
54
55   static bool mustQuote(StringRef Scalar) { return needsQuotes(Scalar); }
56 };
57
58 struct FlowStringValue : StringValue {
59   FlowStringValue() {}
60   FlowStringValue(std::string Value) : StringValue(Value) {}
61 };
62
63 template <> struct ScalarTraits<FlowStringValue> {
64   static void output(const FlowStringValue &S, void *, llvm::raw_ostream &OS) {
65     return ScalarTraits<StringValue>::output(S, nullptr, OS);
66   }
67
68   static StringRef input(StringRef Scalar, void *Ctx, FlowStringValue &S) {
69     return ScalarTraits<StringValue>::input(Scalar, Ctx, S);
70   }
71
72   static bool mustQuote(StringRef Scalar) { return needsQuotes(Scalar); }
73 };
74
75 } // end namespace yaml
76 } // end namespace llvm
77
78 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::StringValue)
79 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::FlowStringValue)
80
81 namespace llvm {
82 namespace yaml {
83
84 struct MachineBasicBlock {
85   unsigned ID;
86   StringValue Name;
87   unsigned Alignment = 0;
88   bool IsLandingPad = false;
89   bool AddressTaken = false;
90   // TODO: Serialize the successor weights and liveins.
91   std::vector<FlowStringValue> Successors;
92
93   std::vector<StringValue> Instructions;
94 };
95
96 template <> struct MappingTraits<MachineBasicBlock> {
97   static void mapping(IO &YamlIO, MachineBasicBlock &MBB) {
98     YamlIO.mapRequired("id", MBB.ID);
99     YamlIO.mapOptional("name", MBB.Name,
100                        StringValue()); // Don't print out an empty name.
101     YamlIO.mapOptional("alignment", MBB.Alignment);
102     YamlIO.mapOptional("isLandingPad", MBB.IsLandingPad);
103     YamlIO.mapOptional("addressTaken", MBB.AddressTaken);
104     YamlIO.mapOptional("successors", MBB.Successors);
105     YamlIO.mapOptional("instructions", MBB.Instructions);
106   }
107 };
108
109 } // end namespace yaml
110 } // end namespace llvm
111
112 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineBasicBlock)
113
114 namespace llvm {
115 namespace yaml {
116
117 struct MachineFunction {
118   StringRef Name;
119   unsigned Alignment = 0;
120   bool ExposesReturnsTwice = false;
121   bool HasInlineAsm = false;
122   // Register information
123   bool IsSSA = false;
124   bool TracksRegLiveness = false;
125   bool TracksSubRegLiveness = false;
126   // TODO: Serialize virtual register definitions.
127   // TODO: Serialize the various register masks.
128   // TODO: Serialize live in registers.
129
130   std::vector<MachineBasicBlock> BasicBlocks;
131 };
132
133 template <> struct MappingTraits<MachineFunction> {
134   static void mapping(IO &YamlIO, MachineFunction &MF) {
135     YamlIO.mapRequired("name", MF.Name);
136     YamlIO.mapOptional("alignment", MF.Alignment);
137     YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice);
138     YamlIO.mapOptional("hasInlineAsm", MF.HasInlineAsm);
139     YamlIO.mapOptional("isSSA", MF.IsSSA);
140     YamlIO.mapOptional("tracksRegLiveness", MF.TracksRegLiveness);
141     YamlIO.mapOptional("tracksSubRegLiveness", MF.TracksSubRegLiveness);
142     YamlIO.mapOptional("body", MF.BasicBlocks);
143   }
144 };
145
146 } // end namespace yaml
147 } // end namespace llvm
148
149 #endif