LLVM 24.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 // VirtRegMap state.
207 // SplitFrom: id-form virtual register only (e.g. '%0'); physregs and named
208 // vregs are rejected by the parser.
209 // AssignedPhys: physical register only (e.g. '$r5'); virtregs are rejected.
212
213 // TODO: Serialize the target specific register hints.
214
216 return ID == Other.ID && Class == Other.Class &&
217 PreferredRegister == Other.PreferredRegister &&
218 SplitFrom == Other.SplitFrom && AssignedPhys == Other.AssignedPhys;
219 }
220};
221
223 static void mapping(IO &YamlIO, VirtualRegisterDefinition &Reg) {
224 YamlIO.mapRequired("id", Reg.ID);
225 YamlIO.mapRequired("class", Reg.Class);
226 YamlIO.mapOptional("preferred-register", Reg.PreferredRegister,
227 StringValue()); // Don't print out when it's empty.
228 YamlIO.mapOptional("flags", Reg.RegisterFlags,
229 std::vector<FlowStringValue>());
230 // MIRPrinter sets WriteDefaultValues=true unless -simplify-mir is passed,
231 // so a plain mapOptional with an empty default would still emit the keys
232 // and change every existing test's output.
233 // Skip the call on output when empty to keep them off entirely.
234 if (!YamlIO.outputting() || !Reg.SplitFrom.Value.empty())
235 YamlIO.mapOptional("split-from", Reg.SplitFrom, StringValue());
236 if (!YamlIO.outputting() || !Reg.AssignedPhys.Value.empty())
237 YamlIO.mapOptional("assigned-phys", Reg.AssignedPhys, StringValue());
238 }
239
240 static const bool flow = true;
241};
242
246
248 return Register == Other.Register &&
249 VirtualRegister == Other.VirtualRegister;
250 }
251};
252
254 static void mapping(IO &YamlIO, MachineFunctionLiveIn &LiveIn) {
255 YamlIO.mapRequired("reg", LiveIn.Register);
256 YamlIO.mapOptional(
257 "virtual-reg", LiveIn.VirtualRegister,
258 StringValue()); // Don't print the virtual register when it's empty.
259 }
260
261 static const bool flow = true;
262};
263
264/// Serializable representation of stack object from the MachineFrameInfo class.
265///
266/// The flags 'isImmutable' and 'isAliased' aren't serialized, as they are
267/// determined by the object's type and frame information flags.
268/// Dead stack objects aren't serialized.
269///
270/// The 'isPreallocated' flag is determined by the local offset.
275 // TODO: Serialize unnamed LLVM alloca reference.
277 int64_t Offset = 0;
279 MaybeAlign Alignment = std::nullopt;
283 std::optional<int64_t> LocalOffset;
287
289 return ID == Other.ID && Name == Other.Name && Type == Other.Type &&
290 Offset == Other.Offset && Size == Other.Size &&
291 Alignment == Other.Alignment &&
292 StackID == Other.StackID &&
293 CalleeSavedRegister == Other.CalleeSavedRegister &&
294 CalleeSavedRestored == Other.CalleeSavedRestored &&
295 LocalOffset == Other.LocalOffset && DebugVar == Other.DebugVar &&
296 DebugExpr == Other.DebugExpr && DebugLoc == Other.DebugLoc;
297 }
298};
299
307
309 static void mapping(yaml::IO &YamlIO, MachineStackObject &Object) {
310 YamlIO.mapRequired("id", Object.ID);
311 YamlIO.mapOptional("name", Object.Name,
312 StringValue()); // Don't print out an empty name.
313 YamlIO.mapOptional(
314 "type", Object.Type,
315 MachineStackObject::DefaultType); // Don't print the default type.
316 YamlIO.mapOptional("offset", Object.Offset, (int64_t)0);
317 if (Object.Type != MachineStackObject::VariableSized)
318 YamlIO.mapRequired("size", Object.Size);
319 YamlIO.mapOptional("alignment", Object.Alignment, std::nullopt);
320 YamlIO.mapOptional("stack-id", Object.StackID, TargetStackID::Default);
321 YamlIO.mapOptional("callee-saved-register", Object.CalleeSavedRegister,
322 StringValue()); // Don't print it out when it's empty.
323 YamlIO.mapOptional("callee-saved-restored", Object.CalleeSavedRestored,
324 true);
325 YamlIO.mapOptional("local-offset", Object.LocalOffset,
326 std::optional<int64_t>());
327 YamlIO.mapOptional("debug-info-variable", Object.DebugVar,
328 StringValue()); // Don't print it out when it's empty.
329 YamlIO.mapOptional("debug-info-expression", Object.DebugExpr,
330 StringValue()); // Don't print it out when it's empty.
331 YamlIO.mapOptional("debug-info-location", Object.DebugLoc,
332 StringValue()); // Don't print it out when it's empty.
333 }
334
335 static const bool flow = true;
336};
337
338/// Serializable representation of the MCRegister variant of
339/// MachineFunction::VariableDbgInfo.
345 bool operator==(const EntryValueObject &Other) const {
346 return EntryValueRegister == Other.EntryValueRegister &&
347 DebugVar == Other.DebugVar && DebugExpr == Other.DebugExpr &&
348 DebugLoc == Other.DebugLoc;
349 }
350};
351
352template <> struct MappingTraits<EntryValueObject> {
353 static void mapping(yaml::IO &YamlIO, EntryValueObject &Object) {
354 YamlIO.mapRequired("entry-value-register", Object.EntryValueRegister);
355 YamlIO.mapRequired("debug-info-variable", Object.DebugVar);
356 YamlIO.mapRequired("debug-info-expression", Object.DebugExpr);
357 YamlIO.mapRequired("debug-info-location", Object.DebugLoc);
358 }
359 static const bool flow = true;
360};
361
362/// Serializable representation of the fixed stack object from the
363/// MachineFrameInfo class.
368 int64_t Offset = 0;
370 MaybeAlign Alignment = std::nullopt;
372 bool IsImmutable = false;
373 bool IsAliased = false;
379
381 return ID == Other.ID && Type == Other.Type && Offset == Other.Offset &&
382 Size == Other.Size && Alignment == Other.Alignment &&
383 StackID == Other.StackID &&
384 IsImmutable == Other.IsImmutable && IsAliased == Other.IsAliased &&
385 CalleeSavedRegister == Other.CalleeSavedRegister &&
386 CalleeSavedRestored == Other.CalleeSavedRestored &&
387 DebugVar == Other.DebugVar && DebugExpr == Other.DebugExpr
388 && DebugLoc == Other.DebugLoc;
389 }
390};
391
392template <>
400
401template <>
404 IO.enumCase(ID, "default", TargetStackID::Default);
405 IO.enumCase(ID, "sgpr-spill", TargetStackID::SGPRSpill);
406 IO.enumCase(ID, "scalable-vector", TargetStackID::ScalableVector);
407 IO.enumCase(ID, "scalable-predicate-vector",
409 IO.enumCase(ID, "wasm-local", TargetStackID::WasmLocal);
410 IO.enumCase(ID, "avr-align", TargetStackID::AvrAlign);
411 IO.enumCase(ID, "noalloc", TargetStackID::NoAlloc);
412 }
413};
414
416 static void mapping(yaml::IO &YamlIO, FixedMachineStackObject &Object) {
417 YamlIO.mapRequired("id", Object.ID);
418 YamlIO.mapOptional(
419 "type", Object.Type,
420 FixedMachineStackObject::DefaultType); // Don't print the default type.
421 YamlIO.mapOptional("offset", Object.Offset, (int64_t)0);
422 YamlIO.mapOptional("size", Object.Size, (uint64_t)0);
423 YamlIO.mapOptional("alignment", Object.Alignment, std::nullopt);
424 YamlIO.mapOptional("stack-id", Object.StackID, TargetStackID::Default);
425 if (Object.Type != FixedMachineStackObject::SpillSlot) {
426 YamlIO.mapOptional("isImmutable", Object.IsImmutable, false);
427 YamlIO.mapOptional("isAliased", Object.IsAliased, false);
428 }
429 YamlIO.mapOptional("callee-saved-register", Object.CalleeSavedRegister,
430 StringValue()); // Don't print it out when it's empty.
431 YamlIO.mapOptional("callee-saved-restored", Object.CalleeSavedRestored,
432 true);
433 YamlIO.mapOptional("debug-info-variable", Object.DebugVar,
434 StringValue()); // Don't print it out when it's empty.
435 YamlIO.mapOptional("debug-info-expression", Object.DebugExpr,
436 StringValue()); // Don't print it out when it's empty.
437 YamlIO.mapOptional("debug-info-location", Object.DebugLoc,
438 StringValue()); // Don't print it out when it's empty.
439 }
440
441 static const bool flow = true;
442};
443
444/// A serializaable representation of a reference to a stack object or fixed
445/// stack object.
447 // The frame index as printed. This is always a positive number, even for
448 // fixed objects. To obtain the real index,
449 // MachineFrameInfo::getObjectIndexBegin has to be added.
450 int FI;
453
454 FrameIndex() = default;
456
458};
459
460template <> struct ScalarTraits<FrameIndex> {
461 static void output(const FrameIndex &FI, void *, raw_ostream &OS) {
463 }
464
465 static StringRef input(StringRef Scalar, void *Ctx, FrameIndex &FI) {
466 FI.IsFixed = false;
467 StringRef Num;
468 if (Scalar.starts_with("%stack.")) {
469 Num = Scalar.substr(7);
470 } else if (Scalar.starts_with("%fixed-stack.")) {
471 Num = Scalar.substr(13);
472 FI.IsFixed = true;
473 } else {
474 return "Invalid frame index, needs to start with %stack. or "
475 "%fixed-stack.";
476 }
477 if (Num.consumeInteger(10, FI.FI))
478 return "Invalid frame index, not a valid number";
479
480 if (const auto *Node =
481 reinterpret_cast<yaml::Input *>(Ctx)->getCurrentNode())
483 return StringRef();
484 }
485
487};
488
489/// Identifies call instruction location in machine function.
491 unsigned BlockNum;
492 unsigned Offset;
493
494 bool operator==(const MachineInstrLoc &Other) const {
495 return BlockNum == Other.BlockNum && Offset == Other.Offset;
496 }
497};
498
499/// Serializable representation of CallSiteInfo.
501 // Representation of call argument and register which is used to
502 // transfer it.
503 struct ArgRegPair {
506
507 bool operator==(const ArgRegPair &Other) const {
508 return Reg == Other.Reg && ArgNo == Other.ArgNo;
509 }
510 };
511
513 std::vector<ArgRegPair> ArgForwardingRegs;
514 /// Numeric callee type identifiers for the callgraph section.
515 std::vector<uint64_t> CalleeTypeIds;
516
517 bool operator==(const CallSiteInfo &Other) const {
518 return CallLocation.BlockNum == Other.CallLocation.BlockNum &&
519 CallLocation.Offset == Other.CallLocation.Offset;
520 }
521};
522
523template <> struct MappingTraits<CallSiteInfo::ArgRegPair> {
524 static void mapping(IO &YamlIO, CallSiteInfo::ArgRegPair &ArgReg) {
525 YamlIO.mapRequired("arg", ArgReg.ArgNo);
526 YamlIO.mapRequired("reg", ArgReg.Reg);
527 }
528
529 static const bool flow = true;
530};
531}
532}
533
535
536namespace llvm {
537namespace yaml {
538
539template <> struct MappingTraits<CallSiteInfo> {
540 static void mapping(IO &YamlIO, CallSiteInfo &CSInfo) {
541 YamlIO.mapRequired("bb", CSInfo.CallLocation.BlockNum);
542 YamlIO.mapRequired("offset", CSInfo.CallLocation.Offset);
543 YamlIO.mapOptional("fwdArgRegs", CSInfo.ArgForwardingRegs,
544 std::vector<CallSiteInfo::ArgRegPair>());
545 YamlIO.mapOptional("calleeTypeIds", CSInfo.CalleeTypeIds);
546 }
547
548 static const bool flow = true;
549};
550
551/// Serializable representation of debug value substitutions.
553 unsigned SrcInst;
554 unsigned SrcOp;
555 unsigned DstInst;
556 unsigned DstOp;
557 unsigned Subreg;
558
560 return std::tie(SrcInst, SrcOp, DstInst, DstOp) ==
561 std::tie(Other.SrcInst, Other.SrcOp, Other.DstInst, Other.DstOp);
562 }
563};
564
566 static void mapping(IO &YamlIO, DebugValueSubstitution &Sub) {
567 YamlIO.mapRequired("srcinst", Sub.SrcInst);
568 YamlIO.mapRequired("srcop", Sub.SrcOp);
569 YamlIO.mapRequired("dstinst", Sub.DstInst);
570 YamlIO.mapRequired("dstop", Sub.DstOp);
571 YamlIO.mapRequired("subreg", Sub.Subreg);
572 }
573
574 static const bool flow = true;
575};
576} // namespace yaml
577} // namespace llvm
578
580
581namespace llvm {
582namespace yaml {
586 MaybeAlign Alignment = std::nullopt;
587 bool IsTargetSpecific = false;
588
590 return ID == Other.ID && Value == Other.Value &&
591 Alignment == Other.Alignment &&
592 IsTargetSpecific == Other.IsTargetSpecific;
593 }
594};
595
598 YamlIO.mapRequired("id", Constant.ID);
599 YamlIO.mapOptional("value", Constant.Value, StringValue());
600 YamlIO.mapOptional("alignment", Constant.Alignment, std::nullopt);
601 YamlIO.mapOptional("isTargetSpecific", Constant.IsTargetSpecific, false);
602 }
603};
604
606 struct Entry {
608 std::vector<FlowStringValue> Blocks;
609
610 bool operator==(const Entry &Other) const {
611 return ID == Other.ID && Blocks == Other.Blocks;
612 }
613 };
614
616 std::vector<Entry> Entries;
617
618 bool operator==(const MachineJumpTable &Other) const {
619 return Kind == Other.Kind && Entries == Other.Entries;
620 }
621};
622
623template <> struct MappingTraits<MachineJumpTable::Entry> {
624 static void mapping(IO &YamlIO, MachineJumpTable::Entry &Entry) {
625 YamlIO.mapRequired("id", Entry.ID);
626 YamlIO.mapOptional("blocks", Entry.Blocks, std::vector<FlowStringValue>());
627 }
628};
629
633 unsigned Flags;
634
635 bool operator==(const CalledGlobal &Other) const {
636 return CallSite == Other.CallSite && Callee == Other.Callee &&
637 Flags == Other.Flags;
638 }
639};
640
641template <> struct MappingTraits<CalledGlobal> {
642 static void mapping(IO &YamlIO, CalledGlobal &CG) {
643 YamlIO.mapRequired("bb", CG.CallSite.BlockNum);
644 YamlIO.mapRequired("offset", CG.CallSite.Offset);
645 YamlIO.mapRequired("callee", CG.Callee);
646 YamlIO.mapRequired("flags", CG.Flags);
647 }
648};
649
650} // end namespace yaml
651} // end namespace llvm
652
662
663namespace llvm {
664namespace yaml {
665
666// Struct representing one save/restore point in the 'savePoint' /
667// 'restorePoint' list. One point consists of machine basic block name and list
668// of registers saved/restored in this basic block. In MIR it looks like:
669// savePoint:
670// - point: '%bb.1'
671// registers:
672// - '$rbx'
673// - '$r12'
674// ...
675// restorePoint:
676// - point: '%bb.1'
677// registers:
678// - '$rbx'
679// - '$r12'
680// If no register is saved/restored in the selected BB,
681// field 'registers' is not specified.
684 std::vector<StringValue> Registers;
685
687 return Point == Other.Point && Registers == Other.Registers;
688 }
689};
690
692 static void mapping(IO &YamlIO, SaveRestorePointEntry &Entry) {
693 YamlIO.mapRequired("point", Entry.Point);
694 YamlIO.mapOptional("registers", Entry.Registers,
695 std::vector<StringValue>());
696 }
697};
698
699template <> struct MappingTraits<MachineJumpTable> {
700 static void mapping(IO &YamlIO, MachineJumpTable &JT) {
701 YamlIO.mapRequired("kind", JT.Kind);
702 YamlIO.mapOptional("entries", JT.Entries,
703 std::vector<MachineJumpTable::Entry>());
704 }
705};
706
707} // namespace yaml
708} // namespace llvm
709
711
712namespace llvm {
713namespace yaml {
714
715/// Serializable representation of MachineFrameInfo.
716///
717/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
718/// 'RealignOption' as they are determined by the target and LLVM function
719/// attributes.
720/// It also doesn't serialize attributes like 'NumFixedObject' and
721/// 'HasVarSizedObjects' as they are determined by the frame objects themselves.
725 bool HasStackMap = false;
726 bool HasPatchPoint = false;
729 unsigned MaxAlignment = 0;
730 bool AdjustsStack = false;
731 bool HasCalls = false;
735 unsigned MaxCallFrameSize = ~0u; ///< ~0u means: not computed yet.
738 bool HasVAStart = false;
740 bool HasTailCall = false;
742 unsigned LocalFrameSize = 0;
743 std::vector<SaveRestorePointEntry> SavePoints;
744 std::vector<SaveRestorePointEntry> RestorePoints;
745
746 bool operator==(const MachineFrameInfo &Other) const {
747 return IsFrameAddressTaken == Other.IsFrameAddressTaken &&
748 IsReturnAddressTaken == Other.IsReturnAddressTaken &&
749 HasStackMap == Other.HasStackMap &&
750 HasPatchPoint == Other.HasPatchPoint &&
751 StackSize == Other.StackSize &&
752 OffsetAdjustment == Other.OffsetAdjustment &&
753 MaxAlignment == Other.MaxAlignment &&
754 AdjustsStack == Other.AdjustsStack && HasCalls == Other.HasCalls &&
755 FramePointerPolicy == Other.FramePointerPolicy &&
756 StackProtector == Other.StackProtector &&
757 FunctionContext == Other.FunctionContext &&
758 MaxCallFrameSize == Other.MaxCallFrameSize &&
760 Other.CVBytesOfCalleeSavedRegisters &&
761 HasOpaqueSPAdjustment == Other.HasOpaqueSPAdjustment &&
762 HasVAStart == Other.HasVAStart &&
763 HasMustTailInVarArgFunc == Other.HasMustTailInVarArgFunc &&
764 HasTailCall == Other.HasTailCall &&
765 LocalFrameSize == Other.LocalFrameSize &&
766 SavePoints == Other.SavePoints &&
767 RestorePoints == Other.RestorePoints &&
768 IsCalleeSavedInfoValid == Other.IsCalleeSavedInfoValid;
769 }
770};
771
772template <> struct MappingTraits<MachineFrameInfo> {
773 static void mapping(IO &YamlIO, MachineFrameInfo &MFI) {
774 YamlIO.mapOptional("isFrameAddressTaken", MFI.IsFrameAddressTaken, false);
775 YamlIO.mapOptional("isReturnAddressTaken", MFI.IsReturnAddressTaken, false);
776 YamlIO.mapOptional("hasStackMap", MFI.HasStackMap, false);
777 YamlIO.mapOptional("hasPatchPoint", MFI.HasPatchPoint, false);
778 YamlIO.mapOptional("stackSize", MFI.StackSize, (uint64_t)0);
779 YamlIO.mapOptional("offsetAdjustment", MFI.OffsetAdjustment, (int)0);
780 YamlIO.mapOptional("maxAlignment", MFI.MaxAlignment, (unsigned)0);
781 YamlIO.mapOptional("adjustsStack", MFI.AdjustsStack, false);
782 YamlIO.mapOptional("hasCalls", MFI.HasCalls, false);
783 YamlIO.mapOptional("framePointerPolicy", MFI.FramePointerPolicy);
784 YamlIO.mapOptional("stackProtector", MFI.StackProtector,
785 StringValue()); // Don't print it out when it's empty.
786 YamlIO.mapOptional("functionContext", MFI.FunctionContext,
787 StringValue()); // Don't print it out when it's empty.
788 YamlIO.mapOptional("maxCallFrameSize", MFI.MaxCallFrameSize, (unsigned)~0);
789 YamlIO.mapOptional("cvBytesOfCalleeSavedRegisters",
791 YamlIO.mapOptional("hasOpaqueSPAdjustment", MFI.HasOpaqueSPAdjustment,
792 false);
793 YamlIO.mapOptional("hasVAStart", MFI.HasVAStart, false);
794 YamlIO.mapOptional("hasMustTailInVarArgFunc", MFI.HasMustTailInVarArgFunc,
795 false);
796 YamlIO.mapOptional("hasTailCall", MFI.HasTailCall, false);
797 YamlIO.mapOptional("isCalleeSavedInfoValid", MFI.IsCalleeSavedInfoValid,
798 false);
799 YamlIO.mapOptional("localFrameSize", MFI.LocalFrameSize, (unsigned)0);
800 YamlIO.mapOptional("savePoint", MFI.SavePoints);
801 YamlIO.mapOptional("restorePoint", MFI.RestorePoints);
802 }
803};
804
805/// Targets should override this in a way that mirrors the implementation of
806/// llvm::MachineFunctionInfo.
808 virtual ~MachineFunctionInfo() = default;
809 virtual void mappingImpl(IO &YamlIO) {}
810};
811
812template <> struct MappingTraits<std::unique_ptr<MachineFunctionInfo>> {
813 static void mapping(IO &YamlIO, std::unique_ptr<MachineFunctionInfo> &MFI) {
814 if (MFI)
815 MFI->mappingImpl(YamlIO);
816 }
817};
818
821 MaybeAlign Alignment = std::nullopt;
823 // GISel MachineFunctionProperties.
824 bool Legalized = false;
825 bool RegBankSelected = false;
826 bool Selected = false;
827 bool FailedISel = false;
828 // Register information
829 bool TracksRegLiveness = false;
830 bool HasWinCFI = false;
831
832 // Computed properties that should be overridable
833 std::optional<bool> NoPHIs;
834 std::optional<bool> IsSSA;
835 std::optional<bool> NoVRegs;
836 std::optional<bool> HasFakeUses;
837
838 bool CallsEHReturn = false;
839 bool CallsUnwindInit = false;
840 bool HasEHContTarget = false;
841 bool HasEHScopes = false;
842 bool HasEHFunclets = false;
843 bool IsOutlined = false;
844
845 bool FailsVerification = false;
847 bool UseDebugInstrRef = false;
848 std::vector<VirtualRegisterDefinition> VirtualRegisters;
849 std::vector<MachineFunctionLiveIn> LiveIns;
850 std::optional<std::vector<FlowStringValue>> CalleeSavedRegisters;
851 // TODO: Serialize the various register masks.
852 // Frame information
854 std::vector<FixedMachineStackObject> FixedStackObjects;
855 std::vector<EntryValueObject> EntryValueObjects;
856 std::vector<MachineStackObject> StackObjects;
857 std::vector<MachineConstantPoolValue> Constants; /// Constant pool.
858 std::unique_ptr<MachineFunctionInfo> MachineFuncInfo;
859 std::vector<CallSiteInfo> CallSitesInfo;
860 std::vector<DebugValueSubstitution> DebugValueSubstitutions;
862 std::vector<StringValue> MachineMetadataNodes;
863 std::vector<CalledGlobal> CalledGlobals;
864 std::vector<FlowStringValue> PrefetchTargets;
866};
867
868template <> struct MappingTraits<MachineFunction> {
869 static void mapping(IO &YamlIO, MachineFunction &MF) {
870 YamlIO.mapRequired("name", MF.Name);
871 YamlIO.mapOptional("alignment", MF.Alignment, std::nullopt);
872 YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice, false);
873 YamlIO.mapOptional("legalized", MF.Legalized, false);
874 YamlIO.mapOptional("regBankSelected", MF.RegBankSelected, false);
875 YamlIO.mapOptional("selected", MF.Selected, false);
876 YamlIO.mapOptional("failedISel", MF.FailedISel, false);
877 YamlIO.mapOptional("tracksRegLiveness", MF.TracksRegLiveness, false);
878 YamlIO.mapOptional("hasWinCFI", MF.HasWinCFI, false);
879
880 // PHIs must be not be capitalized, since it will clash with the MIR opcode
881 // leading to false-positive FileCheck hits with CHECK-NOT
882 YamlIO.mapOptional("noPhis", MF.NoPHIs, std::optional<bool>());
883 YamlIO.mapOptional("isSSA", MF.IsSSA, std::optional<bool>());
884 YamlIO.mapOptional("noVRegs", MF.NoVRegs, std::optional<bool>());
885 YamlIO.mapOptional("hasFakeUses", MF.HasFakeUses, std::optional<bool>());
886
887 YamlIO.mapOptional("callsEHReturn", MF.CallsEHReturn, false);
888 YamlIO.mapOptional("callsUnwindInit", MF.CallsUnwindInit, false);
889 YamlIO.mapOptional("hasEHContTarget", MF.HasEHContTarget, false);
890 YamlIO.mapOptional("hasEHScopes", MF.HasEHScopes, false);
891 YamlIO.mapOptional("hasEHFunclets", MF.HasEHFunclets, false);
892 YamlIO.mapOptional("isOutlined", MF.IsOutlined, false);
893 YamlIO.mapOptional("debugInstrRef", MF.UseDebugInstrRef, false);
894
895 YamlIO.mapOptional("failsVerification", MF.FailsVerification, false);
896 YamlIO.mapOptional("tracksDebugUserValues", MF.TracksDebugUserValues,
897 false);
898 YamlIO.mapOptional("registers", MF.VirtualRegisters,
899 std::vector<VirtualRegisterDefinition>());
900 YamlIO.mapOptional("liveins", MF.LiveIns,
901 std::vector<MachineFunctionLiveIn>());
902 YamlIO.mapOptional("calleeSavedRegisters", MF.CalleeSavedRegisters,
903 std::optional<std::vector<FlowStringValue>>());
904 YamlIO.mapOptional("frameInfo", MF.FrameInfo, MachineFrameInfo());
905 YamlIO.mapOptional("fixedStack", MF.FixedStackObjects,
906 std::vector<FixedMachineStackObject>());
907 YamlIO.mapOptional("stack", MF.StackObjects,
908 std::vector<MachineStackObject>());
909 YamlIO.mapOptional("entry_values", MF.EntryValueObjects,
910 std::vector<EntryValueObject>());
911 YamlIO.mapOptional("callSites", MF.CallSitesInfo,
912 std::vector<CallSiteInfo>());
913 YamlIO.mapOptional("debugValueSubstitutions", MF.DebugValueSubstitutions,
914 std::vector<DebugValueSubstitution>());
915 YamlIO.mapOptional("constants", MF.Constants,
916 std::vector<MachineConstantPoolValue>());
917 YamlIO.mapOptional("machineFunctionInfo", MF.MachineFuncInfo);
918 if (!YamlIO.outputting() || !MF.JumpTableInfo.Entries.empty())
919 YamlIO.mapOptional("jumpTable", MF.JumpTableInfo, MachineJumpTable());
920 if (!YamlIO.outputting() || !MF.MachineMetadataNodes.empty())
921 YamlIO.mapOptional("machineMetadataNodes", MF.MachineMetadataNodes,
922 std::vector<StringValue>());
923 if (!YamlIO.outputting() || !MF.CalledGlobals.empty())
924 YamlIO.mapOptional("calledGlobals", MF.CalledGlobals,
925 std::vector<CalledGlobal>());
926 if (!YamlIO.outputting() || !MF.PrefetchTargets.empty())
927 YamlIO.mapOptional("prefetch-targets", MF.PrefetchTargets,
928 std::vector<FlowStringValue>());
929
930 YamlIO.mapOptional("body", MF.Body, BlockStringValue());
931 }
932};
933
934} // end namespace yaml
935} // end namespace llvm
936
937#endif // LLVM_CODEGEN_MIRYAMLMAPPING_H
unsigned uint64_t
#define LLVM_ABI
Definition Compiler.h:215
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
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
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:54
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:735
void mapOptional(StringRef Key, T &Val)
Definition YAMLTraits.h:800
void mapRequired(StringRef Key, T &Val)
Definition YAMLTraits.h:790
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
QuotingType
Describe which type of quotes should be used when quoting is necessary.
Definition YAMLTraits.h:132
QuotingType needsQuotes(StringRef S, bool ForcePreserveAsString=true)
Definition YAMLTraits.h:590
This is an optimization pass for GlobalISel generic memory operations.
FramePointerKind
Definition CodeGen.h:185
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition MathExtras.h:285
@ 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:878
#define N
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
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:180
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.
LLVM_ABI 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:63
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:108
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:150
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