1 //===- MIRYamlMapping.h - Describe mapping between MIR and YAML--*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the mapping between various MIR data structures and
10 // their corresponding YAML representation.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_MIRYAMLMAPPING_H
15 #define LLVM_CODEGEN_MIRYAMLMAPPING_H
17 #include "llvm/ADT/Optional.h"
18 #include "llvm/ADT/StringRef.h"
19 #include "llvm/CodeGen/MachineJumpTableInfo.h"
20 #include "llvm/CodeGen/TargetFrameLowering.h"
21 #include "llvm/Support/SMLoc.h"
22 #include "llvm/Support/YAMLTraits.h"
23 #include "llvm/Support/raw_ostream.h"
32 /// A wrapper around std::string which contains a source range that's being
33 /// set during parsing.
38 StringValue() = default;
39 StringValue(std::string Value
) : Value(std::move(Value
)) {}
40 StringValue(const char Val
[]) : Value(Val
) {}
42 bool operator==(const StringValue
&Other
) const {
43 return Value
== Other
.Value
;
47 template <> struct ScalarTraits
<StringValue
> {
48 static void output(const StringValue
&S
, void *, raw_ostream
&OS
) {
52 static StringRef
input(StringRef Scalar
, void *Ctx
, StringValue
&S
) {
53 S
.Value
= Scalar
.str();
54 if (const auto *Node
=
55 reinterpret_cast<yaml::Input
*>(Ctx
)->getCurrentNode())
56 S
.SourceRange
= Node
->getSourceRange();
60 static QuotingType
mustQuote(StringRef S
) { return needsQuotes(S
); }
63 struct FlowStringValue
: StringValue
{
64 FlowStringValue() = default;
65 FlowStringValue(std::string Value
) : StringValue(std::move(Value
)) {}
68 template <> struct ScalarTraits
<FlowStringValue
> {
69 static void output(const FlowStringValue
&S
, void *, raw_ostream
&OS
) {
70 return ScalarTraits
<StringValue
>::output(S
, nullptr, OS
);
73 static StringRef
input(StringRef Scalar
, void *Ctx
, FlowStringValue
&S
) {
74 return ScalarTraits
<StringValue
>::input(Scalar
, Ctx
, S
);
77 static QuotingType
mustQuote(StringRef S
) { return needsQuotes(S
); }
80 struct BlockStringValue
{
83 bool operator==(const BlockStringValue
&Other
) const {
84 return Value
== Other
.Value
;
88 template <> struct BlockScalarTraits
<BlockStringValue
> {
89 static void output(const BlockStringValue
&S
, void *Ctx
, raw_ostream
&OS
) {
90 return ScalarTraits
<StringValue
>::output(S
.Value
, Ctx
, OS
);
93 static StringRef
input(StringRef Scalar
, void *Ctx
, BlockStringValue
&S
) {
94 return ScalarTraits
<StringValue
>::input(Scalar
, Ctx
, S
.Value
);
98 /// A wrapper around unsigned which contains a source range that's being set
100 struct UnsignedValue
{
104 UnsignedValue() = default;
105 UnsignedValue(unsigned Value
) : Value(Value
) {}
107 bool operator==(const UnsignedValue
&Other
) const {
108 return Value
== Other
.Value
;
112 template <> struct ScalarTraits
<UnsignedValue
> {
113 static void output(const UnsignedValue
&Value
, void *Ctx
, raw_ostream
&OS
) {
114 return ScalarTraits
<unsigned>::output(Value
.Value
, Ctx
, OS
);
117 static StringRef
input(StringRef Scalar
, void *Ctx
, UnsignedValue
&Value
) {
118 if (const auto *Node
=
119 reinterpret_cast<yaml::Input
*>(Ctx
)->getCurrentNode())
120 Value
.SourceRange
= Node
->getSourceRange();
121 return ScalarTraits
<unsigned>::input(Scalar
, Ctx
, Value
.Value
);
124 static QuotingType
mustQuote(StringRef Scalar
) {
125 return ScalarTraits
<unsigned>::mustQuote(Scalar
);
129 template <> struct ScalarEnumerationTraits
<MachineJumpTableInfo::JTEntryKind
> {
130 static void enumeration(yaml::IO
&IO
,
131 MachineJumpTableInfo::JTEntryKind
&EntryKind
) {
132 IO
.enumCase(EntryKind
, "block-address",
133 MachineJumpTableInfo::EK_BlockAddress
);
134 IO
.enumCase(EntryKind
, "gp-rel64-block-address",
135 MachineJumpTableInfo::EK_GPRel64BlockAddress
);
136 IO
.enumCase(EntryKind
, "gp-rel32-block-address",
137 MachineJumpTableInfo::EK_GPRel32BlockAddress
);
138 IO
.enumCase(EntryKind
, "label-difference32",
139 MachineJumpTableInfo::EK_LabelDifference32
);
140 IO
.enumCase(EntryKind
, "inline", MachineJumpTableInfo::EK_Inline
);
141 IO
.enumCase(EntryKind
, "custom32", MachineJumpTableInfo::EK_Custom32
);
145 } // end namespace yaml
146 } // end namespace llvm
148 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::StringValue
)
149 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::FlowStringValue
)
150 LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::UnsignedValue
)
155 struct VirtualRegisterDefinition
{
158 StringValue PreferredRegister
;
160 // TODO: Serialize the target specific register hints.
162 bool operator==(const VirtualRegisterDefinition
&Other
) const {
163 return ID
== Other
.ID
&& Class
== Other
.Class
&&
164 PreferredRegister
== Other
.PreferredRegister
;
168 template <> struct MappingTraits
<VirtualRegisterDefinition
> {
169 static void mapping(IO
&YamlIO
, VirtualRegisterDefinition
&Reg
) {
170 YamlIO
.mapRequired("id", Reg
.ID
);
171 YamlIO
.mapRequired("class", Reg
.Class
);
172 YamlIO
.mapOptional("preferred-register", Reg
.PreferredRegister
,
173 StringValue()); // Don't print out when it's empty.
176 static const bool flow
= true;
179 struct MachineFunctionLiveIn
{
180 StringValue Register
;
181 StringValue VirtualRegister
;
183 bool operator==(const MachineFunctionLiveIn
&Other
) const {
184 return Register
== Other
.Register
&&
185 VirtualRegister
== Other
.VirtualRegister
;
189 template <> struct MappingTraits
<MachineFunctionLiveIn
> {
190 static void mapping(IO
&YamlIO
, MachineFunctionLiveIn
&LiveIn
) {
191 YamlIO
.mapRequired("reg", LiveIn
.Register
);
193 "virtual-reg", LiveIn
.VirtualRegister
,
194 StringValue()); // Don't print the virtual register when it's empty.
197 static const bool flow
= true;
200 /// Serializable representation of stack object from the MachineFrameInfo class.
202 /// The flags 'isImmutable' and 'isAliased' aren't serialized, as they are
203 /// determined by the object's type and frame information flags.
204 /// Dead stack objects aren't serialized.
206 /// The 'isPreallocated' flag is determined by the local offset.
207 struct MachineStackObject
{
208 enum ObjectType
{ DefaultType
, SpillSlot
, VariableSized
};
211 // TODO: Serialize unnamed LLVM alloca reference.
212 ObjectType Type
= DefaultType
;
215 unsigned Alignment
= 0;
216 TargetStackID::Value StackID
;
217 StringValue CalleeSavedRegister
;
218 bool CalleeSavedRestored
= true;
219 Optional
<int64_t> LocalOffset
;
220 StringValue DebugVar
;
221 StringValue DebugExpr
;
222 StringValue DebugLoc
;
224 bool operator==(const MachineStackObject
&Other
) const {
225 return ID
== Other
.ID
&& Name
== Other
.Name
&& Type
== Other
.Type
&&
226 Offset
== Other
.Offset
&& Size
== Other
.Size
&&
227 Alignment
== Other
.Alignment
&&
228 StackID
== Other
.StackID
&&
229 CalleeSavedRegister
== Other
.CalleeSavedRegister
&&
230 CalleeSavedRestored
== Other
.CalleeSavedRestored
&&
231 LocalOffset
== Other
.LocalOffset
&& DebugVar
== Other
.DebugVar
&&
232 DebugExpr
== Other
.DebugExpr
&& DebugLoc
== Other
.DebugLoc
;
236 template <> struct ScalarEnumerationTraits
<MachineStackObject::ObjectType
> {
237 static void enumeration(yaml::IO
&IO
, MachineStackObject::ObjectType
&Type
) {
238 IO
.enumCase(Type
, "default", MachineStackObject::DefaultType
);
239 IO
.enumCase(Type
, "spill-slot", MachineStackObject::SpillSlot
);
240 IO
.enumCase(Type
, "variable-sized", MachineStackObject::VariableSized
);
244 template <> struct MappingTraits
<MachineStackObject
> {
245 static void mapping(yaml::IO
&YamlIO
, MachineStackObject
&Object
) {
246 YamlIO
.mapRequired("id", Object
.ID
);
247 YamlIO
.mapOptional("name", Object
.Name
,
248 StringValue()); // Don't print out an empty name.
251 MachineStackObject::DefaultType
); // Don't print the default type.
252 YamlIO
.mapOptional("offset", Object
.Offset
, (int64_t)0);
253 if (Object
.Type
!= MachineStackObject::VariableSized
)
254 YamlIO
.mapRequired("size", Object
.Size
);
255 YamlIO
.mapOptional("alignment", Object
.Alignment
, (unsigned)0);
256 YamlIO
.mapOptional("stack-id", Object
.StackID
, TargetStackID::Default
);
257 YamlIO
.mapOptional("callee-saved-register", Object
.CalleeSavedRegister
,
258 StringValue()); // Don't print it out when it's empty.
259 YamlIO
.mapOptional("callee-saved-restored", Object
.CalleeSavedRestored
,
261 YamlIO
.mapOptional("local-offset", Object
.LocalOffset
, Optional
<int64_t>());
262 YamlIO
.mapOptional("debug-info-variable", Object
.DebugVar
,
263 StringValue()); // Don't print it out when it's empty.
264 YamlIO
.mapOptional("debug-info-expression", Object
.DebugExpr
,
265 StringValue()); // Don't print it out when it's empty.
266 YamlIO
.mapOptional("debug-info-location", Object
.DebugLoc
,
267 StringValue()); // Don't print it out when it's empty.
270 static const bool flow
= true;
273 /// Serializable representation of the fixed stack object from the
274 /// MachineFrameInfo class.
275 struct FixedMachineStackObject
{
276 enum ObjectType
{ DefaultType
, SpillSlot
};
278 ObjectType Type
= DefaultType
;
281 unsigned Alignment
= 0;
282 TargetStackID::Value StackID
;
283 bool IsImmutable
= false;
284 bool IsAliased
= false;
285 StringValue CalleeSavedRegister
;
286 bool CalleeSavedRestored
= true;
287 StringValue DebugVar
;
288 StringValue DebugExpr
;
289 StringValue DebugLoc
;
291 bool operator==(const FixedMachineStackObject
&Other
) const {
292 return ID
== Other
.ID
&& Type
== Other
.Type
&& Offset
== Other
.Offset
&&
293 Size
== Other
.Size
&& Alignment
== Other
.Alignment
&&
294 StackID
== Other
.StackID
&&
295 IsImmutable
== Other
.IsImmutable
&& IsAliased
== Other
.IsAliased
&&
296 CalleeSavedRegister
== Other
.CalleeSavedRegister
&&
297 CalleeSavedRestored
== Other
.CalleeSavedRestored
&&
298 DebugVar
== Other
.DebugVar
&& DebugExpr
== Other
.DebugExpr
299 && DebugLoc
== Other
.DebugLoc
;
304 struct ScalarEnumerationTraits
<FixedMachineStackObject::ObjectType
> {
305 static void enumeration(yaml::IO
&IO
,
306 FixedMachineStackObject::ObjectType
&Type
) {
307 IO
.enumCase(Type
, "default", FixedMachineStackObject::DefaultType
);
308 IO
.enumCase(Type
, "spill-slot", FixedMachineStackObject::SpillSlot
);
313 struct ScalarEnumerationTraits
<TargetStackID::Value
> {
314 static void enumeration(yaml::IO
&IO
, TargetStackID::Value
&ID
) {
315 IO
.enumCase(ID
, "default", TargetStackID::Default
);
316 IO
.enumCase(ID
, "sgpr-spill", TargetStackID::SGPRSpill
);
317 IO
.enumCase(ID
, "noalloc", TargetStackID::NoAlloc
);
321 template <> struct MappingTraits
<FixedMachineStackObject
> {
322 static void mapping(yaml::IO
&YamlIO
, FixedMachineStackObject
&Object
) {
323 YamlIO
.mapRequired("id", Object
.ID
);
326 FixedMachineStackObject::DefaultType
); // Don't print the default type.
327 YamlIO
.mapOptional("offset", Object
.Offset
, (int64_t)0);
328 YamlIO
.mapOptional("size", Object
.Size
, (uint64_t)0);
329 YamlIO
.mapOptional("alignment", Object
.Alignment
, (unsigned)0);
330 YamlIO
.mapOptional("stack-id", Object
.StackID
, TargetStackID::Default
);
331 if (Object
.Type
!= FixedMachineStackObject::SpillSlot
) {
332 YamlIO
.mapOptional("isImmutable", Object
.IsImmutable
, false);
333 YamlIO
.mapOptional("isAliased", Object
.IsAliased
, false);
335 YamlIO
.mapOptional("callee-saved-register", Object
.CalleeSavedRegister
,
336 StringValue()); // Don't print it out when it's empty.
337 YamlIO
.mapOptional("callee-saved-restored", Object
.CalleeSavedRestored
,
339 YamlIO
.mapOptional("debug-info-variable", Object
.DebugVar
,
340 StringValue()); // Don't print it out when it's empty.
341 YamlIO
.mapOptional("debug-info-expression", Object
.DebugExpr
,
342 StringValue()); // Don't print it out when it's empty.
343 YamlIO
.mapOptional("debug-info-location", Object
.DebugLoc
,
344 StringValue()); // Don't print it out when it's empty.
347 static const bool flow
= true;
351 /// Serializable representation of CallSiteInfo.
352 struct CallSiteInfo
{
353 // Representation of call argument and register which is used to
359 bool operator==(const ArgRegPair
&Other
) const {
360 return Reg
== Other
.Reg
&& ArgNo
== Other
.ArgNo
;
364 /// Identifies call instruction location in machine function.
365 struct MachineInstrLoc
{
369 bool operator==(const MachineInstrLoc
&Other
) const {
370 return BlockNum
== Other
.BlockNum
&& Offset
== Other
.Offset
;
374 MachineInstrLoc CallLocation
;
375 std::vector
<ArgRegPair
> ArgForwardingRegs
;
377 bool operator==(const CallSiteInfo
&Other
) const {
378 return CallLocation
.BlockNum
== Other
.CallLocation
.BlockNum
&&
379 CallLocation
.Offset
== Other
.CallLocation
.Offset
;
383 template <> struct MappingTraits
<CallSiteInfo::ArgRegPair
> {
384 static void mapping(IO
&YamlIO
, CallSiteInfo::ArgRegPair
&ArgReg
) {
385 YamlIO
.mapRequired("arg", ArgReg
.ArgNo
);
386 YamlIO
.mapRequired("reg", ArgReg
.Reg
);
389 static const bool flow
= true;
394 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::CallSiteInfo::ArgRegPair
)
399 template <> struct MappingTraits
<CallSiteInfo
> {
400 static void mapping(IO
&YamlIO
, CallSiteInfo
&CSInfo
) {
401 YamlIO
.mapRequired("bb", CSInfo
.CallLocation
.BlockNum
);
402 YamlIO
.mapRequired("offset", CSInfo
.CallLocation
.Offset
);
403 YamlIO
.mapOptional("fwdArgRegs", CSInfo
.ArgForwardingRegs
,
404 std::vector
<CallSiteInfo::ArgRegPair
>());
407 static const bool flow
= true;
410 struct MachineConstantPoolValue
{
413 unsigned Alignment
= 0;
414 bool IsTargetSpecific
= false;
416 bool operator==(const MachineConstantPoolValue
&Other
) const {
417 return ID
== Other
.ID
&& Value
== Other
.Value
&&
418 Alignment
== Other
.Alignment
&&
419 IsTargetSpecific
== Other
.IsTargetSpecific
;
423 template <> struct MappingTraits
<MachineConstantPoolValue
> {
424 static void mapping(IO
&YamlIO
, MachineConstantPoolValue
&Constant
) {
425 YamlIO
.mapRequired("id", Constant
.ID
);
426 YamlIO
.mapOptional("value", Constant
.Value
, StringValue());
427 YamlIO
.mapOptional("alignment", Constant
.Alignment
, (unsigned)0);
428 YamlIO
.mapOptional("isTargetSpecific", Constant
.IsTargetSpecific
, false);
432 struct MachineJumpTable
{
435 std::vector
<FlowStringValue
> Blocks
;
437 bool operator==(const Entry
&Other
) const {
438 return ID
== Other
.ID
&& Blocks
== Other
.Blocks
;
442 MachineJumpTableInfo::JTEntryKind Kind
= MachineJumpTableInfo::EK_Custom32
;
443 std::vector
<Entry
> Entries
;
445 bool operator==(const MachineJumpTable
&Other
) const {
446 return Kind
== Other
.Kind
&& Entries
== Other
.Entries
;
450 template <> struct MappingTraits
<MachineJumpTable::Entry
> {
451 static void mapping(IO
&YamlIO
, MachineJumpTable::Entry
&Entry
) {
452 YamlIO
.mapRequired("id", Entry
.ID
);
453 YamlIO
.mapOptional("blocks", Entry
.Blocks
, std::vector
<FlowStringValue
>());
457 } // end namespace yaml
458 } // end namespace llvm
460 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineFunctionLiveIn
)
461 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::VirtualRegisterDefinition
)
462 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineStackObject
)
463 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::FixedMachineStackObject
)
464 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::CallSiteInfo
)
465 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineConstantPoolValue
)
466 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineJumpTable::Entry
)
471 template <> struct MappingTraits
<MachineJumpTable
> {
472 static void mapping(IO
&YamlIO
, MachineJumpTable
&JT
) {
473 YamlIO
.mapRequired("kind", JT
.Kind
);
474 YamlIO
.mapOptional("entries", JT
.Entries
,
475 std::vector
<MachineJumpTable::Entry
>());
479 /// Serializable representation of MachineFrameInfo.
481 /// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
482 /// 'RealignOption' as they are determined by the target and LLVM function
484 /// It also doesn't serialize attributes like 'NumFixedObject' and
485 /// 'HasVarSizedObjects' as they are determined by the frame objects themselves.
486 struct MachineFrameInfo
{
487 bool IsFrameAddressTaken
= false;
488 bool IsReturnAddressTaken
= false;
489 bool HasStackMap
= false;
490 bool HasPatchPoint
= false;
491 uint64_t StackSize
= 0;
492 int OffsetAdjustment
= 0;
493 unsigned MaxAlignment
= 0;
494 bool AdjustsStack
= false;
495 bool HasCalls
= false;
496 StringValue StackProtector
;
497 // TODO: Serialize FunctionContextIdx
498 unsigned MaxCallFrameSize
= ~0u; ///< ~0u means: not computed yet.
499 unsigned CVBytesOfCalleeSavedRegisters
= 0;
500 bool HasOpaqueSPAdjustment
= false;
501 bool HasVAStart
= false;
502 bool HasMustTailInVarArgFunc
= false;
503 unsigned LocalFrameSize
= 0;
504 StringValue SavePoint
;
505 StringValue RestorePoint
;
507 bool operator==(const MachineFrameInfo
&Other
) const {
508 return IsFrameAddressTaken
== Other
.IsFrameAddressTaken
&&
509 IsReturnAddressTaken
== Other
.IsReturnAddressTaken
&&
510 HasStackMap
== Other
.HasStackMap
&&
511 HasPatchPoint
== Other
.HasPatchPoint
&&
512 StackSize
== Other
.StackSize
&&
513 OffsetAdjustment
== Other
.OffsetAdjustment
&&
514 MaxAlignment
== Other
.MaxAlignment
&&
515 AdjustsStack
== Other
.AdjustsStack
&& HasCalls
== Other
.HasCalls
&&
516 StackProtector
== Other
.StackProtector
&&
517 MaxCallFrameSize
== Other
.MaxCallFrameSize
&&
518 CVBytesOfCalleeSavedRegisters
==
519 Other
.CVBytesOfCalleeSavedRegisters
&&
520 HasOpaqueSPAdjustment
== Other
.HasOpaqueSPAdjustment
&&
521 HasVAStart
== Other
.HasVAStart
&&
522 HasMustTailInVarArgFunc
== Other
.HasMustTailInVarArgFunc
&&
523 LocalFrameSize
== Other
.LocalFrameSize
&&
524 SavePoint
== Other
.SavePoint
&& RestorePoint
== Other
.RestorePoint
;
528 template <> struct MappingTraits
<MachineFrameInfo
> {
529 static void mapping(IO
&YamlIO
, MachineFrameInfo
&MFI
) {
530 YamlIO
.mapOptional("isFrameAddressTaken", MFI
.IsFrameAddressTaken
, false);
531 YamlIO
.mapOptional("isReturnAddressTaken", MFI
.IsReturnAddressTaken
, false);
532 YamlIO
.mapOptional("hasStackMap", MFI
.HasStackMap
, false);
533 YamlIO
.mapOptional("hasPatchPoint", MFI
.HasPatchPoint
, false);
534 YamlIO
.mapOptional("stackSize", MFI
.StackSize
, (uint64_t)0);
535 YamlIO
.mapOptional("offsetAdjustment", MFI
.OffsetAdjustment
, (int)0);
536 YamlIO
.mapOptional("maxAlignment", MFI
.MaxAlignment
, (unsigned)0);
537 YamlIO
.mapOptional("adjustsStack", MFI
.AdjustsStack
, false);
538 YamlIO
.mapOptional("hasCalls", MFI
.HasCalls
, false);
539 YamlIO
.mapOptional("stackProtector", MFI
.StackProtector
,
540 StringValue()); // Don't print it out when it's empty.
541 YamlIO
.mapOptional("maxCallFrameSize", MFI
.MaxCallFrameSize
, (unsigned)~0);
542 YamlIO
.mapOptional("cvBytesOfCalleeSavedRegisters",
543 MFI
.CVBytesOfCalleeSavedRegisters
, 0U);
544 YamlIO
.mapOptional("hasOpaqueSPAdjustment", MFI
.HasOpaqueSPAdjustment
,
546 YamlIO
.mapOptional("hasVAStart", MFI
.HasVAStart
, false);
547 YamlIO
.mapOptional("hasMustTailInVarArgFunc", MFI
.HasMustTailInVarArgFunc
,
549 YamlIO
.mapOptional("localFrameSize", MFI
.LocalFrameSize
, (unsigned)0);
550 YamlIO
.mapOptional("savePoint", MFI
.SavePoint
,
551 StringValue()); // Don't print it out when it's empty.
552 YamlIO
.mapOptional("restorePoint", MFI
.RestorePoint
,
553 StringValue()); // Don't print it out when it's empty.
557 /// Targets should override this in a way that mirrors the implementation of
558 /// llvm::MachineFunctionInfo.
559 struct MachineFunctionInfo
{
560 virtual ~MachineFunctionInfo() {}
561 virtual void mappingImpl(IO
&YamlIO
) {}
564 template <> struct MappingTraits
<std::unique_ptr
<MachineFunctionInfo
>> {
565 static void mapping(IO
&YamlIO
, std::unique_ptr
<MachineFunctionInfo
> &MFI
) {
567 MFI
->mappingImpl(YamlIO
);
571 struct MachineFunction
{
573 unsigned Alignment
= 0;
574 bool ExposesReturnsTwice
= false;
575 // GISel MachineFunctionProperties.
576 bool Legalized
= false;
577 bool RegBankSelected
= false;
578 bool Selected
= false;
579 bool FailedISel
= false;
580 // Register information
581 bool TracksRegLiveness
= false;
582 bool HasWinCFI
= false;
583 std::vector
<VirtualRegisterDefinition
> VirtualRegisters
;
584 std::vector
<MachineFunctionLiveIn
> LiveIns
;
585 Optional
<std::vector
<FlowStringValue
>> CalleeSavedRegisters
;
586 // TODO: Serialize the various register masks.
588 MachineFrameInfo FrameInfo
;
589 std::vector
<FixedMachineStackObject
> FixedStackObjects
;
590 std::vector
<MachineStackObject
> StackObjects
;
591 std::vector
<MachineConstantPoolValue
> Constants
; /// Constant pool.
592 std::unique_ptr
<MachineFunctionInfo
> MachineFuncInfo
;
593 std::vector
<CallSiteInfo
> CallSitesInfo
;
594 MachineJumpTable JumpTableInfo
;
595 BlockStringValue Body
;
598 template <> struct MappingTraits
<MachineFunction
> {
599 static void mapping(IO
&YamlIO
, MachineFunction
&MF
) {
600 YamlIO
.mapRequired("name", MF
.Name
);
601 YamlIO
.mapOptional("alignment", MF
.Alignment
, (unsigned)0);
602 YamlIO
.mapOptional("exposesReturnsTwice", MF
.ExposesReturnsTwice
, false);
603 YamlIO
.mapOptional("legalized", MF
.Legalized
, false);
604 YamlIO
.mapOptional("regBankSelected", MF
.RegBankSelected
, false);
605 YamlIO
.mapOptional("selected", MF
.Selected
, false);
606 YamlIO
.mapOptional("failedISel", MF
.FailedISel
, false);
607 YamlIO
.mapOptional("tracksRegLiveness", MF
.TracksRegLiveness
, false);
608 YamlIO
.mapOptional("hasWinCFI", MF
.HasWinCFI
, false);
609 YamlIO
.mapOptional("registers", MF
.VirtualRegisters
,
610 std::vector
<VirtualRegisterDefinition
>());
611 YamlIO
.mapOptional("liveins", MF
.LiveIns
,
612 std::vector
<MachineFunctionLiveIn
>());
613 YamlIO
.mapOptional("calleeSavedRegisters", MF
.CalleeSavedRegisters
,
614 Optional
<std::vector
<FlowStringValue
>>());
615 YamlIO
.mapOptional("frameInfo", MF
.FrameInfo
, MachineFrameInfo());
616 YamlIO
.mapOptional("fixedStack", MF
.FixedStackObjects
,
617 std::vector
<FixedMachineStackObject
>());
618 YamlIO
.mapOptional("stack", MF
.StackObjects
,
619 std::vector
<MachineStackObject
>());
620 YamlIO
.mapOptional("callSites", MF
.CallSitesInfo
,
621 std::vector
<CallSiteInfo
>());
622 YamlIO
.mapOptional("constants", MF
.Constants
,
623 std::vector
<MachineConstantPoolValue
>());
624 YamlIO
.mapOptional("machineFunctionInfo", MF
.MachineFuncInfo
);
625 if (!YamlIO
.outputting() || !MF
.JumpTableInfo
.Entries
.empty())
626 YamlIO
.mapOptional("jumpTable", MF
.JumpTableInfo
, MachineJumpTable());
627 YamlIO
.mapOptional("body", MF
.Body
, BlockStringValue());
631 } // end namespace yaml
632 } // end namespace llvm
634 #endif // LLVM_CODEGEN_MIRYAMLMAPPING_H