1 //===- MIRYAMLMapping.h - Describes the mapping between MIR and YAML ------===//
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 // The MIR serialization library is currently a work in progress. It can't
11 // serialize machine functions at this time.
13 // This file implements the mapping between various MIR data structures and
14 // their corresponding YAML representation.
16 //===----------------------------------------------------------------------===//
18 #ifndef LLVM_LIB_CODEGEN_MIRYAMLMAPPING_H
19 #define LLVM_LIB_CODEGEN_MIRYAMLMAPPING_H
21 #include "llvm/ADT/StringRef.h"
22 #include "llvm/Support/YAMLTraits.h"
28 /// A wrapper around std::string which contains a source range that's being
29 /// set during parsing.
35 StringValue(std::string Value) : Value(std::move(Value)) {}
37 bool operator==(const StringValue &Other) const {
38 return Value == Other.Value;
42 template <> struct ScalarTraits<StringValue> {
43 static void output(const StringValue &S, void *, llvm::raw_ostream &OS) {
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();
55 static bool mustQuote(StringRef Scalar) { return needsQuotes(Scalar); }
58 } // end namespace yaml
59 } // end namespace llvm
61 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::StringValue)
66 struct MachineBasicBlock {
68 unsigned Alignment = 0;
69 bool IsLandingPad = false;
70 bool AddressTaken = false;
71 // TODO: Serialize the successors and liveins.
73 std::vector<StringValue> Instructions;
76 template <> struct MappingTraits<MachineBasicBlock> {
77 static void mapping(IO &YamlIO, MachineBasicBlock &MBB) {
78 YamlIO.mapOptional("name", MBB.Name,
79 std::string()); // Don't print out an empty name.
80 YamlIO.mapOptional("alignment", MBB.Alignment);
81 YamlIO.mapOptional("isLandingPad", MBB.IsLandingPad);
82 YamlIO.mapOptional("addressTaken", MBB.AddressTaken);
83 YamlIO.mapOptional("instructions", MBB.Instructions);
87 } // end namespace yaml
88 } // end namespace llvm
90 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineBasicBlock)
95 struct MachineFunction {
97 unsigned Alignment = 0;
98 bool ExposesReturnsTwice = false;
99 bool HasInlineAsm = false;
100 // Register information
102 bool TracksRegLiveness = false;
103 bool TracksSubRegLiveness = false;
104 // TODO: Serialize virtual register definitions.
105 // TODO: Serialize the various register masks.
106 // TODO: Serialize live in registers.
108 std::vector<MachineBasicBlock> BasicBlocks;
111 template <> struct MappingTraits<MachineFunction> {
112 static void mapping(IO &YamlIO, MachineFunction &MF) {
113 YamlIO.mapRequired("name", MF.Name);
114 YamlIO.mapOptional("alignment", MF.Alignment);
115 YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice);
116 YamlIO.mapOptional("hasInlineAsm", MF.HasInlineAsm);
117 YamlIO.mapOptional("isSSA", MF.IsSSA);
118 YamlIO.mapOptional("tracksRegLiveness", MF.TracksRegLiveness);
119 YamlIO.mapOptional("tracksSubRegLiveness", MF.TracksSubRegLiveness);
120 YamlIO.mapOptional("body", MF.BasicBlocks);
124 } // end namespace yaml
125 } // end namespace llvm