LLVM 23.0.0git
MIRYamlMapping.h
Go to the documentation of this file.
1//===- MIRYamlMapping.h - Describe mapping between MIR and YAML--*- C++ -*-===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file implements the mapping between various MIR data structures and
10// their corresponding YAML representation.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_MIRYAMLMAPPING_H
15#define LLVM_CODEGEN_MIRYAMLMAPPING_H
16
17#include "llvm/ADT/StringRef.h"
21#include "llvm/Support/SMLoc.h"
24#include <algorithm>
25#include <cstdint>
26#include <optional>
27#include <string>
28#include <vector>
29
30namespace llvm {
31namespace yaml {
32
33/// A wrapper around std::string which contains a source range that's being
34/// set during parsing.
36 std::string Value;
38
39 StringValue() = default;
40 StringValue(std::string Value) : Value(std::move(Value)) {}
41 StringValue(const char Val[]) : Value(Val) {}
42
43 bool operator==(const StringValue &Other) const {
44 return Value == Other.Value;
45 }
46};
47
48template <> struct ScalarTraits<StringValue> {
49 static void output(const StringValue &S, void *, raw_ostream &OS) {
50 OS << S.Value;
51 }
52
53 static StringRef input(StringRef Scalar, void *Ctx, StringValue &S) {
54 S.Value = Scalar.str();
55 if (const auto *Node =
56 reinterpret_cast<yaml::Input *>(Ctx)->getCurrentNode())
58 return "";
59 }
60
61 static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
62};
63
68
69template <> struct ScalarTraits<FlowStringValue> {
70 static void output(const FlowStringValue &S, void *, raw_ostream &OS) {
71 return ScalarTraits<StringValue>::output(S, nullptr, OS);
72 }
73
76 }
77
78 static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
79};
80
83
84 bool operator==(const BlockStringValue &Other) const {
85 return Value == Other.Value;
86 }
87};
88
90 static void output(const BlockStringValue &S, void *Ctx, raw_ostream &OS) {
92 }
93
97};
98
99/// A wrapper around unsigned which contains a source range that's being set
100/// during parsing.
102 unsigned Value = 0;
104
105 UnsignedValue() = default;
107
108 bool operator==(const UnsignedValue &Other) const {
109 return Value == Other.Value;
110 }
111};
112
113template <> struct ScalarTraits<UnsignedValue> {
114 static void output(const UnsignedValue &Value, void *Ctx, raw_ostream &OS) {
116 }
117
119 if (const auto *Node =
120 reinterpret_cast<yaml::Input *>(Ctx)->getCurrentNode())
121 Value.SourceRange = Node->getSourceRange();
123 }
124
128};
129
130template <> struct ScalarEnumerationTraits<MachineJumpTableInfo::JTEntryKind> {
131 static void enumeration(yaml::IO &IO,
133 IO.enumCase(EntryKind, "block-address",
135 IO.enumCase(EntryKind, "gp-rel64-block-address",
137 IO.enumCase(EntryKind, "gp-rel32-block-address",
139 IO.enumCase(EntryKind, "label-difference32",
141 IO.enumCase(EntryKind, "label-difference64",
143 IO.enumCase(EntryKind, "inline", MachineJumpTableInfo::EK_Inline);
144 IO.enumCase(EntryKind, "custom32", MachineJumpTableInfo::EK_Custom32);
145 }
146};
147
157
158template <> struct ScalarTraits<MaybeAlign> {
159 static void output(const MaybeAlign &Alignment, void *,
160 llvm::raw_ostream &out) {
161 out << uint64_t(Alignment ? Alignment->value() : 0U);
162 }
163 static StringRef input(StringRef Scalar, void *, MaybeAlign &Alignment) {
164 unsigned long long n;
165 if (getAsUnsignedInteger(Scalar, 10, n))
166 return "invalid number";
167 if (n > 0 && !isPowerOf2_64(n))
168 return "must be 0 or a power of two";
169 Alignment = MaybeAlign(n);
170 return StringRef();
171 }
173};
174
175template <> struct ScalarTraits<Align> {
176 static void output(const Align &Alignment, void *, llvm::raw_ostream &OS) {
177 OS << Alignment.value();
178 }
179 static StringRef input(StringRef Scalar, void *, Align &Alignment) {
180 unsigned long long N;
181 if (getAsUnsignedInteger(Scalar, 10, N))
182 return "invalid number";
183 if (!isPowerOf2_64(N))
184 return "must be a power of two";
185 Alignment = Align(N);
186 return StringRef();
187 }
189};
190
191} // end namespace yaml
192} // end namespace llvm
193
197
198namespace llvm {
199namespace yaml {
200
205 std::vector<FlowStringValue> RegisterFlags;
206
207 // TODO: Serialize the target specific register hints.
208
210 return ID == Other.ID && Class == Other.Class &&
211 PreferredRegister == Other.PreferredRegister;
212 }
213};
214
216 static void mapping(IO &YamlIO, VirtualRegisterDefinition &Reg) {
217 YamlIO.mapRequired("id", Reg.ID);
218 YamlIO.mapRequired("class", Reg.Class);
219 YamlIO.mapOptional("preferred-register", Reg.PreferredRegister,
220 StringValue()); // Don't print out when it's empty.
221 YamlIO.mapOptional("flags", Reg.RegisterFlags,
222 std::vector<FlowStringValue>());
223 }
224
225 static const bool flow = true;
226};
227
231
233 return Register == Other.Register &&
234 VirtualRegister == Other.VirtualRegister;
235 }
236};
237
239 static void mapping(IO &YamlIO, MachineFunctionLiveIn &LiveIn) {
240 YamlIO.mapRequired("reg", LiveIn.Register);
241 YamlIO.mapOptional(
242 "virtual-reg", LiveIn.VirtualRegister,
243 StringValue()); // Don't print the virtual register when it's empty.
244 }
245
246 static const bool flow = true;
247};
248
249/// Serializable representation of stack object from the MachineFrameInfo class.
250///
251/// The flags 'isImmutable' and 'isAliased' aren't serialized, as they are
252/// determined by the object's type and frame information flags.
253/// Dead stack objects aren't serialized.
254///
255/// The 'isPreallocated' flag is determined by the local offset.
260 // TODO: Serialize unnamed LLVM alloca reference.
262 int64_t Offset = 0;
264 MaybeAlign Alignment = std::nullopt;
268 std::optional<int64_t> LocalOffset;
272
274 return ID == Other.ID && Name == Other.Name && Type == Other.Type &&
275 Offset == Other.Offset && Size == Other.Size &&
276 Alignment == Other.Alignment &&
277 StackID == Other.StackID &&
278 CalleeSavedRegister == Other.CalleeSavedRegister &&
279 CalleeSavedRestored == Other.CalleeSavedRestored &&
280 LocalOffset == Other.LocalOffset && DebugVar == Other.DebugVar &&
281 DebugExpr == Other.DebugExpr && DebugLoc == Other.DebugLoc;
282 }
283};
284
292
294 static void mapping(yaml::IO &YamlIO, MachineStackObject &Object) {
295 YamlIO.mapRequired("id", Object.ID);
296 YamlIO.mapOptional("name", Object.Name,
297 StringValue()); // Don't print out an empty name.
298 YamlIO.mapOptional(
299 "type", Object.Type,
300 MachineStackObject::DefaultType); // Don't print the default type.
301 YamlIO.mapOptional("offset", Object.Offset, (int64_t)0);
302 if (Object.Type != MachineStackObject::VariableSized)
303 YamlIO.mapRequired("size", Object.Size);
304 YamlIO.mapOptional("alignment", Object.Alignment, std::nullopt);
305 YamlIO.mapOptional("stack-id", Object.StackID, TargetStackID::Default);
306 YamlIO.mapOptional("callee-saved-register", Object.CalleeSavedRegister,
307 StringValue()); // Don't print it out when it's empty.
308 YamlIO.mapOptional("callee-saved-restored", Object.CalleeSavedRestored,
309 true);
310 YamlIO.mapOptional("local-offset", Object.LocalOffset,
311 std::optional<int64_t>());
312 YamlIO.mapOptional("debug-info-variable", Object.DebugVar,
313 StringValue()); // Don't print it out when it's empty.
314 YamlIO.mapOptional("debug-info-expression", Object.DebugExpr,
315 StringValue()); // Don't print it out when it's empty.
316 YamlIO.mapOptional("debug-info-location", Object.DebugLoc,
317 StringValue()); // Don't print it out when it's empty.
318 }
319
320 static const bool flow = true;
321};
322
323/// Serializable representation of the MCRegister variant of
324/// MachineFunction::VariableDbgInfo.
330 bool operator==(const EntryValueObject &Other) const {
331 return EntryValueRegister == Other.EntryValueRegister &&
332 DebugVar == Other.DebugVar && DebugExpr == Other.DebugExpr &&
333 DebugLoc == Other.DebugLoc;
334 }
335};
336
337template <> struct MappingTraits<EntryValueObject> {
338 static void mapping(yaml::IO &YamlIO, EntryValueObject &Object) {
339 YamlIO.mapRequired("entry-value-register", Object.EntryValueRegister);
340 YamlIO.mapRequired("debug-info-variable", Object.DebugVar);
341 YamlIO.mapRequired("debug-info-expression", Object.DebugExpr);
342 YamlIO.mapRequired("debug-info-location", Object.DebugLoc);
343 }
344 static const bool flow = true;
345};
346
347/// Serializable representation of the fixed stack object from the
348/// MachineFrameInfo class.
353 int64_t Offset = 0;
355 MaybeAlign Alignment = std::nullopt;
357 bool IsImmutable = false;
358 bool IsAliased = false;
364
366 return ID == Other.ID && Type == Other.Type && Offset == Other.Offset &&
367 Size == Other.Size && Alignment == Other.Alignment &&
368 StackID == Other.StackID &&
369 IsImmutable == Other.IsImmutable && IsAliased == Other.IsAliased &&
370 CalleeSavedRegister == Other.CalleeSavedRegister &&
371 CalleeSavedRestored == Other.CalleeSavedRestored &&
372 DebugVar == Other.DebugVar && DebugExpr == Other.DebugExpr
373 && DebugLoc == Other.DebugLoc;
374 }
375};
376
377template <>
385
386template <>
390 IO.enumCase(ID, "sgpr-spill", TargetStackID::SGPRSpill);
391 IO.enumCase(ID, "scalable-vector", TargetStackID::ScalableVector);
392 IO.enumCase(ID, "scalable-predicate-vector",
394 IO.enumCase(ID, "wasm-local", TargetStackID::WasmLocal);
396 }
397};
398
400 static void mapping(yaml::IO &YamlIO, FixedMachineStackObject &Object) {
401 YamlIO.mapRequired("id", Object.ID);
402 YamlIO.mapOptional(
403 "type", Object.Type,
404 FixedMachineStackObject::DefaultType); // Don't print the default type.
405 YamlIO.mapOptional("offset", Object.Offset, (int64_t)0);
406 YamlIO.mapOptional("size", Object.Size, (uint64_t)0);
407 YamlIO.mapOptional("alignment", Object.Alignment, std::nullopt);
408 YamlIO.mapOptional("stack-id", Object.StackID, TargetStackID::Default);
409 if (Object.Type != FixedMachineStackObject::SpillSlot) {
410 YamlIO.mapOptional("isImmutable", Object.IsImmutable, false);
411 YamlIO.mapOptional("isAliased", Object.IsAliased, false);
412 }
413 YamlIO.mapOptional("callee-saved-register", Object.CalleeSavedRegister,
414 StringValue()); // Don't print it out when it's empty.
415 YamlIO.mapOptional("callee-saved-restored", Object.CalleeSavedRestored,
416 true);
417 YamlIO.mapOptional("debug-info-variable", Object.DebugVar,
418 StringValue()); // Don't print it out when it's empty.
419 YamlIO.mapOptional("debug-info-expression", Object.DebugExpr,
420 StringValue()); // Don't print it out when it's empty.
421 YamlIO.mapOptional("debug-info-location", Object.DebugLoc,
422 StringValue()); // Don't print it out when it's empty.
423 }
424
425 static const bool flow = true;
426};
427
428/// A serializaable representation of a reference to a stack object or fixed
429/// stack object.
431 // The frame index as printed. This is always a positive number, even for
432 // fixed objects. To obtain the real index,
433 // MachineFrameInfo::getObjectIndexBegin has to be added.
434 int FI;
437
438 FrameIndex() = default;
439 FrameIndex(int FI, const llvm::MachineFrameInfo &MFI);
440
442};
443
444template <> struct ScalarTraits<FrameIndex> {
445 static void output(const FrameIndex &FI, void *, raw_ostream &OS) {
447 }
448
449 static StringRef input(StringRef Scalar, void *Ctx, FrameIndex &FI) {
450 FI.IsFixed = false;
451 StringRef Num;
452 if (Scalar.starts_with("%stack.")) {
453 Num = Scalar.substr(7);
454 } else if (Scalar.starts_with("%fixed-stack.")) {
455 Num = Scalar.substr(13);
456 FI.IsFixed = true;
457 } else {
458 return "Invalid frame index, needs to start with %stack. or "
459 "%fixed-stack.";
460 }
461 if (Num.consumeInteger(10, FI.FI))
462 return "Invalid frame index, not a valid number";
463
464 if (const auto *Node =
465 reinterpret_cast<yaml::Input *>(Ctx)->getCurrentNode())
467 return StringRef();
468 }
469
471};
472
473/// Identifies call instruction location in machine function.
475 unsigned BlockNum;
476 unsigned Offset;
477
478 bool operator==(const MachineInstrLoc &Other) const {
479 return BlockNum == Other.BlockNum && Offset == Other.Offset;
480 }
481};
482
483/// Serializable representation of CallSiteInfo.
485 // Representation of call argument and register which is used to
486 // transfer it.
487 struct ArgRegPair {
490
491 bool operator==(const ArgRegPair &Other) const {
492 return Reg == Other.Reg && ArgNo == Other.ArgNo;
493 }
494 };
495
497 std::vector<ArgRegPair> ArgForwardingRegs;
498 /// Numeric callee type identifiers for the callgraph section.
499 std::vector<uint64_t> CalleeTypeIds;
500
501 bool operator==(const CallSiteInfo &Other) const {
502 return CallLocation.BlockNum == Other.CallLocation.BlockNum &&
503 CallLocation.Offset == Other.CallLocation.Offset;
504 }
505};
506
507template <> struct MappingTraits<CallSiteInfo::ArgRegPair> {
508 static void mapping(IO &YamlIO, CallSiteInfo::ArgRegPair &ArgReg) {
509 YamlIO.mapRequired("arg", ArgReg.ArgNo);
510 YamlIO.mapRequired("reg", ArgReg.Reg);
511 }
512
513 static const bool flow = true;
514};
515}
516}
517
519
520namespace llvm {
521namespace yaml {
522
523template <> struct MappingTraits<CallSiteInfo> {
524 static void mapping(IO &YamlIO, CallSiteInfo &CSInfo) {
525 YamlIO.mapRequired("bb", CSInfo.CallLocation.BlockNum);
526 YamlIO.mapRequired("offset", CSInfo.CallLocation.Offset);
527 YamlIO.mapOptional("fwdArgRegs", CSInfo.ArgForwardingRegs,
528 std::vector<CallSiteInfo::ArgRegPair>());
529 YamlIO.mapOptional("calleeTypeIds", CSInfo.CalleeTypeIds);
530 }
531
532 static const bool flow = true;
533};
534
535/// Serializable representation of debug value substitutions.
537 unsigned SrcInst;
538 unsigned SrcOp;
539 unsigned DstInst;
540 unsigned DstOp;
541 unsigned Subreg;
542
544 return std::tie(SrcInst, SrcOp, DstInst, DstOp) ==
545 std::tie(Other.SrcInst, Other.SrcOp, Other.DstInst, Other.DstOp);
546 }
547};
548
550 static void mapping(IO &YamlIO, DebugValueSubstitution &Sub) {
551 YamlIO.mapRequired("srcinst", Sub.SrcInst);
552 YamlIO.mapRequired("srcop", Sub.SrcOp);
553 YamlIO.mapRequired("dstinst", Sub.DstInst);
554 YamlIO.mapRequired("dstop", Sub.DstOp);
555 YamlIO.mapRequired("subreg", Sub.Subreg);
556 }
557
558 static const bool flow = true;
559};
560} // namespace yaml
561} // namespace llvm
562
564
565namespace llvm {
566namespace yaml {
570 MaybeAlign Alignment = std::nullopt;
571 bool IsTargetSpecific = false;
572
574 return ID == Other.ID && Value == Other.Value &&
575 Alignment == Other.Alignment &&
576 IsTargetSpecific == Other.IsTargetSpecific;
577 }
578};
579
582 YamlIO.mapRequired("id", Constant.ID);
583 YamlIO.mapOptional("value", Constant.Value, StringValue());
584 YamlIO.mapOptional("alignment", Constant.Alignment, std::nullopt);
585 YamlIO.mapOptional("isTargetSpecific", Constant.IsTargetSpecific, false);
586 }
587};
588
590 struct Entry {
592 std::vector<FlowStringValue> Blocks;
593
594 bool operator==(const Entry &Other) const {
595 return ID == Other.ID && Blocks == Other.Blocks;
596 }
597 };
598
600 std::vector<Entry> Entries;
601
602 bool operator==(const MachineJumpTable &Other) const {
603 return Kind == Other.Kind && Entries == Other.Entries;
604 }
605};
606
607template <> struct MappingTraits<MachineJumpTable::Entry> {
608 static void mapping(IO &YamlIO, MachineJumpTable::Entry &Entry) {
609 YamlIO.mapRequired("id", Entry.ID);
610 YamlIO.mapOptional("blocks", Entry.Blocks, std::vector<FlowStringValue>());
611 }
612};
613
617 unsigned Flags;
618
619 bool operator==(const CalledGlobal &Other) const {
620 return CallSite == Other.CallSite && Callee == Other.Callee &&
621 Flags == Other.Flags;
622 }
623};
624
625template <> struct MappingTraits<CalledGlobal> {
626 static void mapping(IO &YamlIO, CalledGlobal &CG) {
627 YamlIO.mapRequired("bb", CG.CallSite.BlockNum);
628 YamlIO.mapRequired("offset", CG.CallSite.Offset);
629 YamlIO.mapRequired("callee", CG.Callee);
630 YamlIO.mapRequired("flags", CG.Flags);
631 }
632};
633
634} // end namespace yaml
635} // end namespace llvm
636
646
647namespace llvm {
648namespace yaml {
649
650// Struct representing one save/restore point in the 'savePoint' /
651// 'restorePoint' list. One point consists of machine basic block name and list
652// of registers saved/restored in this basic block. In MIR it looks like:
653// savePoint:
654// - point: '%bb.1'
655// registers:
656// - '$rbx'
657// - '$r12'
658// ...
659// restorePoint:
660// - point: '%bb.1'
661// registers:
662// - '$rbx'
663// - '$r12'
664// If no register is saved/restored in the selected BB,
665// field 'registers' is not specified.
668 std::vector<StringValue> Registers;
669
671 return Point == Other.Point && Registers == Other.Registers;
672 }
673};
674
676 static void mapping(IO &YamlIO, SaveRestorePointEntry &Entry) {
677 YamlIO.mapRequired("point", Entry.Point);
678 YamlIO.mapOptional("registers", Entry.Registers,
679 std::vector<StringValue>());
680 }
681};
682
683template <> struct MappingTraits<MachineJumpTable> {
684 static void mapping(IO &YamlIO, MachineJumpTable &JT) {
685 YamlIO.mapRequired("kind", JT.Kind);
686 YamlIO.mapOptional("entries", JT.Entries,
687 std::vector<MachineJumpTable::Entry>());
688 }
689};
690
691} // namespace yaml
692} // namespace llvm
693
695
696namespace llvm {
697namespace yaml {
698
699/// Serializable representation of MachineFrameInfo.
700///
701/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
702/// 'RealignOption' as they are determined by the target and LLVM function
703/// attributes.
704/// It also doesn't serialize attributes like 'NumFixedObject' and
705/// 'HasVarSizedObjects' as they are determined by the frame objects themselves.
709 bool HasStackMap = false;
710 bool HasPatchPoint = false;
713 unsigned MaxAlignment = 0;
714 bool AdjustsStack = false;
715 bool HasCalls = false;
719 unsigned MaxCallFrameSize = ~0u; ///< ~0u means: not computed yet.
722 bool HasVAStart = false;
724 bool HasTailCall = false;
726 unsigned LocalFrameSize = 0;
727 std::vector<SaveRestorePointEntry> SavePoints;
728 std::vector<SaveRestorePointEntry> RestorePoints;
729
730 bool operator==(const MachineFrameInfo &Other) const {
731 return IsFrameAddressTaken == Other.IsFrameAddressTaken &&
732 IsReturnAddressTaken == Other.IsReturnAddressTaken &&
733 HasStackMap == Other.HasStackMap &&
734 HasPatchPoint == Other.HasPatchPoint &&
735 StackSize == Other.StackSize &&
736 OffsetAdjustment == Other.OffsetAdjustment &&
737 MaxAlignment == Other.MaxAlignment &&
738 AdjustsStack == Other.AdjustsStack && HasCalls == Other.HasCalls &&
739 FramePointerPolicy == Other.FramePointerPolicy &&
740 StackProtector == Other.StackProtector &&
741 FunctionContext == Other.FunctionContext &&
742 MaxCallFrameSize == Other.MaxCallFrameSize &&
744 Other.CVBytesOfCalleeSavedRegisters &&
745 HasOpaqueSPAdjustment == Other.HasOpaqueSPAdjustment &&
746 HasVAStart == Other.HasVAStart &&
747 HasMustTailInVarArgFunc == Other.HasMustTailInVarArgFunc &&
748 HasTailCall == Other.HasTailCall &&
749 LocalFrameSize == Other.LocalFrameSize &&
750 SavePoints == Other.SavePoints &&
751 RestorePoints == Other.RestorePoints &&
752 IsCalleeSavedInfoValid == Other.IsCalleeSavedInfoValid;
753 }
754};
755
756template <> struct MappingTraits<MachineFrameInfo> {
757 static void mapping(IO &YamlIO, MachineFrameInfo &MFI) {
758 YamlIO.mapOptional("isFrameAddressTaken", MFI.IsFrameAddressTaken, false);
759 YamlIO.mapOptional("isReturnAddressTaken", MFI.IsReturnAddressTaken, false);
760 YamlIO.mapOptional("hasStackMap", MFI.HasStackMap, false);
761 YamlIO.mapOptional("hasPatchPoint", MFI.HasPatchPoint, false);
762 YamlIO.mapOptional("stackSize", MFI.StackSize, (uint64_t)0);
763 YamlIO.mapOptional("offsetAdjustment", MFI.OffsetAdjustment, (int)0);
764 YamlIO.mapOptional("maxAlignment", MFI.MaxAlignment, (unsigned)0);
765 YamlIO.mapOptional("adjustsStack", MFI.AdjustsStack, false);
766 YamlIO.mapOptional("hasCalls", MFI.HasCalls, false);
767 YamlIO.mapOptional("framePointerPolicy", MFI.FramePointerPolicy);
768 YamlIO.mapOptional("stackProtector", MFI.StackProtector,
769 StringValue()); // Don't print it out when it's empty.
770 YamlIO.mapOptional("functionContext", MFI.FunctionContext,
771 StringValue()); // Don't print it out when it's empty.
772 YamlIO.mapOptional("maxCallFrameSize", MFI.MaxCallFrameSize, (unsigned)~0);
773 YamlIO.mapOptional("cvBytesOfCalleeSavedRegisters",
775 YamlIO.mapOptional("hasOpaqueSPAdjustment", MFI.HasOpaqueSPAdjustment,
776 false);
777 YamlIO.mapOptional("hasVAStart", MFI.HasVAStart, false);
778 YamlIO.mapOptional("hasMustTailInVarArgFunc", MFI.HasMustTailInVarArgFunc,
779 false);
780 YamlIO.mapOptional("hasTailCall", MFI.HasTailCall, false);
781 YamlIO.mapOptional("isCalleeSavedInfoValid", MFI.IsCalleeSavedInfoValid,
782 false);
783 YamlIO.mapOptional("localFrameSize", MFI.LocalFrameSize, (unsigned)0);
784 YamlIO.mapOptional("savePoint", MFI.SavePoints);
785 YamlIO.mapOptional("restorePoint", MFI.RestorePoints);
786 }
787};
788
789/// Targets should override this in a way that mirrors the implementation of
790/// llvm::MachineFunctionInfo.
792 virtual ~MachineFunctionInfo() = default;
793 virtual void mappingImpl(IO &YamlIO) {}
794};
795
796template <> struct MappingTraits<std::unique_ptr<MachineFunctionInfo>> {
797 static void mapping(IO &YamlIO, std::unique_ptr<MachineFunctionInfo> &MFI) {
798 if (MFI)
799 MFI->mappingImpl(YamlIO);
800 }
801};
802
805 MaybeAlign Alignment = std::nullopt;
807 // GISel MachineFunctionProperties.
808 bool Legalized = false;
809 bool RegBankSelected = false;
810 bool Selected = false;
811 bool FailedISel = false;
812 // Register information
813 bool TracksRegLiveness = false;
814 bool HasWinCFI = false;
815
816 // Computed properties that should be overridable
817 std::optional<bool> NoPHIs;
818 std::optional<bool> IsSSA;
819 std::optional<bool> NoVRegs;
820 std::optional<bool> HasFakeUses;
821
822 bool CallsEHReturn = false;
823 bool CallsUnwindInit = false;
824 bool HasEHContTarget = false;
825 bool HasEHScopes = false;
826 bool HasEHFunclets = false;
827 bool IsOutlined = false;
828
829 bool FailsVerification = false;
831 bool UseDebugInstrRef = false;
832 std::vector<VirtualRegisterDefinition> VirtualRegisters;
833 std::vector<MachineFunctionLiveIn> LiveIns;
834 std::optional<std::vector<FlowStringValue>> CalleeSavedRegisters;
835 // TODO: Serialize the various register masks.
836 // Frame information
838 std::vector<FixedMachineStackObject> FixedStackObjects;
839 std::vector<EntryValueObject> EntryValueObjects;
840 std::vector<MachineStackObject> StackObjects;
841 std::vector<MachineConstantPoolValue> Constants; /// Constant pool.
842 std::unique_ptr<MachineFunctionInfo> MachineFuncInfo;
843 std::vector<CallSiteInfo> CallSitesInfo;
844 std::vector<DebugValueSubstitution> DebugValueSubstitutions;
846 std::vector<StringValue> MachineMetadataNodes;
847 std::vector<CalledGlobal> CalledGlobals;
848 std::vector<FlowStringValue> PrefetchTargets;
850};
851
852template <> struct MappingTraits<MachineFunction> {
853 static void mapping(IO &YamlIO, MachineFunction &MF) {
854 YamlIO.mapRequired("name", MF.Name);
855 YamlIO.mapOptional("alignment", MF.Alignment, std::nullopt);
856 YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice, false);
857 YamlIO.mapOptional("legalized", MF.Legalized, false);
858 YamlIO.mapOptional("regBankSelected", MF.RegBankSelected, false);
859 YamlIO.mapOptional("selected", MF.Selected, false);
860 YamlIO.mapOptional("failedISel", MF.FailedISel, false);
861 YamlIO.mapOptional("tracksRegLiveness", MF.TracksRegLiveness, false);
862 YamlIO.mapOptional("hasWinCFI", MF.HasWinCFI, false);
863
864 // PHIs must be not be capitalized, since it will clash with the MIR opcode
865 // leading to false-positive FileCheck hits with CHECK-NOT
866 YamlIO.mapOptional("noPhis", MF.NoPHIs, std::optional<bool>());
867 YamlIO.mapOptional("isSSA", MF.IsSSA, std::optional<bool>());
868 YamlIO.mapOptional("noVRegs", MF.NoVRegs, std::optional<bool>());
869 YamlIO.mapOptional("hasFakeUses", MF.HasFakeUses, std::optional<bool>());
870
871 YamlIO.mapOptional("callsEHReturn", MF.CallsEHReturn, false);
872 YamlIO.mapOptional("callsUnwindInit", MF.CallsUnwindInit, false);
873 YamlIO.mapOptional("hasEHContTarget", MF.HasEHContTarget, false);
874 YamlIO.mapOptional("hasEHScopes", MF.HasEHScopes, false);
875 YamlIO.mapOptional("hasEHFunclets", MF.HasEHFunclets, false);
876 YamlIO.mapOptional("isOutlined", MF.IsOutlined, false);
877 YamlIO.mapOptional("debugInstrRef", MF.UseDebugInstrRef, false);
878
879 YamlIO.mapOptional("failsVerification", MF.FailsVerification, false);
880 YamlIO.mapOptional("tracksDebugUserValues", MF.TracksDebugUserValues,
881 false);
882 YamlIO.mapOptional("registers", MF.VirtualRegisters,
883 std::vector<VirtualRegisterDefinition>());
884 YamlIO.mapOptional("liveins", MF.LiveIns,
885 std::vector<MachineFunctionLiveIn>());
886 YamlIO.mapOptional("calleeSavedRegisters", MF.CalleeSavedRegisters,
887 std::optional<std::vector<FlowStringValue>>());
888 YamlIO.mapOptional("frameInfo", MF.FrameInfo, MachineFrameInfo());
889 YamlIO.mapOptional("fixedStack", MF.FixedStackObjects,
890 std::vector<FixedMachineStackObject>());
891 YamlIO.mapOptional("stack", MF.StackObjects,
892 std::vector<MachineStackObject>());
893 YamlIO.mapOptional("entry_values", MF.EntryValueObjects,
894 std::vector<EntryValueObject>());
895 YamlIO.mapOptional("callSites", MF.CallSitesInfo,
896 std::vector<CallSiteInfo>());
897 YamlIO.mapOptional("debugValueSubstitutions", MF.DebugValueSubstitutions,
898 std::vector<DebugValueSubstitution>());
899 YamlIO.mapOptional("constants", MF.Constants,
900 std::vector<MachineConstantPoolValue>());
901 YamlIO.mapOptional("machineFunctionInfo", MF.MachineFuncInfo);
902 if (!YamlIO.outputting() || !MF.JumpTableInfo.Entries.empty())
903 YamlIO.mapOptional("jumpTable", MF.JumpTableInfo, MachineJumpTable());
904 if (!YamlIO.outputting() || !MF.MachineMetadataNodes.empty())
905 YamlIO.mapOptional("machineMetadataNodes", MF.MachineMetadataNodes,
906 std::vector<StringValue>());
907 if (!YamlIO.outputting() || !MF.CalledGlobals.empty())
908 YamlIO.mapOptional("calledGlobals", MF.CalledGlobals,
909 std::vector<CalledGlobal>());
910 if (!YamlIO.outputting() || !MF.PrefetchTargets.empty())
911 YamlIO.mapOptional("prefetch-targets", MF.PrefetchTargets,
912 std::vector<FlowStringValue>());
913
914 YamlIO.mapOptional("body", MF.Body, BlockStringValue());
915 }
916};
917
918} // end namespace yaml
919} // end namespace llvm
920
921#endif // LLVM_CODEGEN_MIRYAMLMAPPING_H
Register Reg
#define LLVM_YAML_IS_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML sequence.
#define LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(type)
Utility for declaring that a std::vector of a particular type should be considered a YAML flow sequen...
This is an important base class in LLVM.
Definition Constant.h:43
Tagged union holding either a T or a Error.
Definition Error.h:485
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
JTEntryKind
JTEntryKind - This enum indicates how each entry of the jump table is represented and emitted.
@ EK_GPRel32BlockAddress
EK_GPRel32BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
@ EK_Inline
EK_Inline - Jump table entries are emitted inline at their point of use.
@ EK_LabelDifference32
EK_LabelDifference32 - Each entry is the address of the block minus the address of the jump table.
@ EK_Custom32
EK_Custom32 - Each entry is a 32-bit value that is custom lowered by the TargetLowering::LowerCustomJ...
@ EK_LabelDifference64
EK_LabelDifference64 - Each entry is the address of the block minus the address of the jump table.
@ EK_BlockAddress
EK_BlockAddress - Each entry is a plain address of block, e.g.: .word LBB123.
@ EK_GPRel64BlockAddress
EK_GPRel64BlockAddress - Each entry is an address of block, encoded with a relocation as gp-relative,...
static LLVM_ABI void printStackObjectReference(raw_ostream &OS, unsigned FrameIndex, bool IsFixed, StringRef Name)
Print a stack object reference.
Represents a range in source code.
Definition SMLoc.h:47
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
bool consumeInteger(unsigned Radix, T &Result)
Parse the current string as an integer of the specified radix.
Definition StringRef.h:519
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
LLVM Value Representation.
Definition Value.h:75
LLVM_ABI Value(Type *Ty, unsigned scid)
Definition Value.cpp:53
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
virtual bool outputting() const =0
void enumCase(T &Val, StringRef Str, const T ConstVal)
Definition YAMLTraits.h:734
void mapOptional(StringRef Key, T &Val)
Definition YAMLTraits.h:799
void mapRequired(StringRef Key, T &Val)
Definition YAMLTraits.h:789
The Input class is used to parse a yaml document into in-memory structs and vectors.
Abstract base class for all Nodes.
Definition YAMLParser.h:121
SMRange getSourceRange() const
Definition YAMLParser.h:167
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
QuotingType
Describe which type of quotes should be used when quoting is necessary.
Definition YAMLTraits.h:131
QuotingType needsQuotes(StringRef S, bool ForcePreserveAsString=true)
Definition YAMLTraits.h:589
This is an optimization pass for GlobalISel generic memory operations.
FramePointerKind
Definition CodeGen.h:118
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition MathExtras.h:284
@ Other
Any other memory.
Definition ModRef.h:68
@ Sub
Subtraction of integers.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1917
LLVM_ABI bool getAsUnsignedInteger(StringRef Str, unsigned Radix, unsigned long long &Result)
Helper functions for StringRef::getAsInteger.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
Definition Alignment.h:77
This struct is a compact representation of a valid (power of two) or undefined (0) alignment.
Definition Alignment.h:106
static void output(const BlockStringValue &S, void *Ctx, raw_ostream &OS)
static StringRef input(StringRef Scalar, void *Ctx, BlockStringValue &S)
This class should be specialized by type that requires custom conversion to/from a YAML literal block...
Definition YAMLTraits.h:179
bool operator==(const BlockStringValue &Other) const
bool operator==(const ArgRegPair &Other) const
Serializable representation of CallSiteInfo.
std::vector< uint64_t > CalleeTypeIds
Numeric callee type identifiers for the callgraph section.
std::vector< ArgRegPair > ArgForwardingRegs
MachineInstrLoc CallLocation
bool operator==(const CallSiteInfo &Other) const
bool operator==(const CalledGlobal &Other) const
Serializable representation of debug value substitutions.
bool operator==(const DebugValueSubstitution &Other) const
Serializable representation of the MCRegister variant of MachineFunction::VariableDbgInfo.
bool operator==(const EntryValueObject &Other) const
Serializable representation of the fixed stack object from the MachineFrameInfo class.
bool operator==(const FixedMachineStackObject &Other) const
FlowStringValue(std::string Value)
A serializaable representation of a reference to a stack object or fixed stack object.
Expected< int > getFI(const llvm::MachineFrameInfo &MFI) const
bool operator==(const MachineConstantPoolValue &Other) const
Serializable representation of MachineFrameInfo.
bool operator==(const MachineFrameInfo &Other) const
std::vector< SaveRestorePointEntry > RestorePoints
unsigned MaxCallFrameSize
~0u means: not computed yet.
FramePointerKind FramePointerPolicy
std::vector< SaveRestorePointEntry > SavePoints
Targets should override this in a way that mirrors the implementation of llvm::MachineFunctionInfo.
virtual void mappingImpl(IO &YamlIO)
virtual ~MachineFunctionInfo()=default
bool operator==(const MachineFunctionLiveIn &Other) const
std::vector< MachineStackObject > StackObjects
std::vector< StringValue > MachineMetadataNodes
std::optional< std::vector< FlowStringValue > > CalleeSavedRegisters
std::vector< CalledGlobal > CalledGlobals
std::optional< bool > HasFakeUses
std::vector< EntryValueObject > EntryValueObjects
std::optional< bool > NoPHIs
std::vector< FlowStringValue > PrefetchTargets
std::vector< MachineConstantPoolValue > Constants
std::optional< bool > NoVRegs
std::vector< CallSiteInfo > CallSitesInfo
std::vector< MachineFunctionLiveIn > LiveIns
std::vector< VirtualRegisterDefinition > VirtualRegisters
std::vector< FixedMachineStackObject > FixedStackObjects
std::optional< bool > IsSSA
std::vector< DebugValueSubstitution > DebugValueSubstitutions
std::unique_ptr< MachineFunctionInfo > MachineFuncInfo
Constant pool.
Identifies call instruction location in machine function.
bool operator==(const MachineInstrLoc &Other) const
bool operator==(const Entry &Other) const
std::vector< FlowStringValue > Blocks
bool operator==(const MachineJumpTable &Other) const
std::vector< Entry > Entries
MachineJumpTableInfo::JTEntryKind Kind
Serializable representation of stack object from the MachineFrameInfo class.
bool operator==(const MachineStackObject &Other) const
std::optional< int64_t > LocalOffset
static void mapping(IO &YamlIO, CallSiteInfo &CSInfo)
static void mapping(IO &YamlIO, CallSiteInfo::ArgRegPair &ArgReg)
static void mapping(IO &YamlIO, CalledGlobal &CG)
static void mapping(IO &YamlIO, DebugValueSubstitution &Sub)
static void mapping(yaml::IO &YamlIO, EntryValueObject &Object)
static void mapping(yaml::IO &YamlIO, FixedMachineStackObject &Object)
static void mapping(IO &YamlIO, MachineConstantPoolValue &Constant)
static void mapping(IO &YamlIO, MachineFrameInfo &MFI)
static void mapping(IO &YamlIO, MachineFunctionLiveIn &LiveIn)
static void mapping(IO &YamlIO, MachineFunction &MF)
static void mapping(IO &YamlIO, MachineJumpTable &JT)
static void mapping(IO &YamlIO, MachineJumpTable::Entry &Entry)
static void mapping(yaml::IO &YamlIO, MachineStackObject &Object)
static void mapping(IO &YamlIO, SaveRestorePointEntry &Entry)
static void mapping(IO &YamlIO, VirtualRegisterDefinition &Reg)
static void mapping(IO &YamlIO, std::unique_ptr< MachineFunctionInfo > &MFI)
This class should be specialized by any type that needs to be converted to/from a YAML mapping.
Definition YAMLTraits.h:62
std::vector< StringValue > Registers
bool operator==(const SaveRestorePointEntry &Other) const
static void enumeration(yaml::IO &IO, FixedMachineStackObject::ObjectType &Type)
static void enumeration(IO &IO, FramePointerKind &FP)
static void enumeration(yaml::IO &IO, MachineJumpTableInfo::JTEntryKind &EntryKind)
static void enumeration(yaml::IO &IO, MachineStackObject::ObjectType &Type)
static void enumeration(yaml::IO &IO, TargetStackID::Value &ID)
This class should be specialized by any integral type that converts to/from a YAML scalar where there...
Definition YAMLTraits.h:107
static StringRef input(StringRef Scalar, void *, Align &Alignment)
static QuotingType mustQuote(StringRef)
static void output(const Align &Alignment, void *, llvm::raw_ostream &OS)
static QuotingType mustQuote(StringRef S)
static void output(const FlowStringValue &S, void *, raw_ostream &OS)
static StringRef input(StringRef Scalar, void *Ctx, FlowStringValue &S)
static void output(const FrameIndex &FI, void *, raw_ostream &OS)
static StringRef input(StringRef Scalar, void *Ctx, FrameIndex &FI)
static QuotingType mustQuote(StringRef S)
static StringRef input(StringRef Scalar, void *, MaybeAlign &Alignment)
static void output(const MaybeAlign &Alignment, void *, llvm::raw_ostream &out)
static QuotingType mustQuote(StringRef)
static StringRef input(StringRef Scalar, void *Ctx, StringValue &S)
static QuotingType mustQuote(StringRef S)
static void output(const StringValue &S, void *, raw_ostream &OS)
static StringRef input(StringRef Scalar, void *Ctx, UnsignedValue &Value)
static QuotingType mustQuote(StringRef Scalar)
static void output(const UnsignedValue &Value, void *Ctx, raw_ostream &OS)
This class should be specialized by type that requires custom conversion to/from a yaml scalar.
Definition YAMLTraits.h:149
A wrapper around std::string which contains a source range that's being set during parsing.
StringValue(const char Val[])
StringValue(std::string Value)
bool operator==(const StringValue &Other) const
A wrapper around unsigned which contains a source range that's being set during parsing.
bool operator==(const UnsignedValue &Other) const
UnsignedValue(unsigned Value)
bool operator==(const VirtualRegisterDefinition &Other) const
std::vector< FlowStringValue > RegisterFlags