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 // 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 <>
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);
411 }
412};
413
415 static void mapping(yaml::IO &YamlIO, FixedMachineStackObject &Object) {
416 YamlIO.mapRequired("id", Object.ID);
417 YamlIO.mapOptional(
418 "type", Object.Type,
419 FixedMachineStackObject::DefaultType); // Don't print the default type.
420 YamlIO.mapOptional("offset", Object.Offset, (int64_t)0);
421 YamlIO.mapOptional("size", Object.Size, (uint64_t)0);
422 YamlIO.mapOptional("alignment", Object.Alignment, std::nullopt);
423 YamlIO.mapOptional("stack-id", Object.StackID, TargetStackID::Default);
424 if (Object.Type != FixedMachineStackObject::SpillSlot) {
425 YamlIO.mapOptional("isImmutable", Object.IsImmutable, false);
426 YamlIO.mapOptional("isAliased", Object.IsAliased, false);
427 }
428 YamlIO.mapOptional("callee-saved-register", Object.CalleeSavedRegister,
429 StringValue()); // Don't print it out when it's empty.
430 YamlIO.mapOptional("callee-saved-restored", Object.CalleeSavedRestored,
431 true);
432 YamlIO.mapOptional("debug-info-variable", Object.DebugVar,
433 StringValue()); // Don't print it out when it's empty.
434 YamlIO.mapOptional("debug-info-expression", Object.DebugExpr,
435 StringValue()); // Don't print it out when it's empty.
436 YamlIO.mapOptional("debug-info-location", Object.DebugLoc,
437 StringValue()); // Don't print it out when it's empty.
438 }
439
440 static const bool flow = true;
441};
442
443/// A serializaable representation of a reference to a stack object or fixed
444/// stack object.
446 // The frame index as printed. This is always a positive number, even for
447 // fixed objects. To obtain the real index,
448 // MachineFrameInfo::getObjectIndexBegin has to be added.
449 int FI;
452
453 FrameIndex() = default;
455
457};
458
459template <> struct ScalarTraits<FrameIndex> {
460 static void output(const FrameIndex &FI, void *, raw_ostream &OS) {
462 }
463
464 static StringRef input(StringRef Scalar, void *Ctx, FrameIndex &FI) {
465 FI.IsFixed = false;
466 StringRef Num;
467 if (Scalar.starts_with("%stack.")) {
468 Num = Scalar.substr(7);
469 } else if (Scalar.starts_with("%fixed-stack.")) {
470 Num = Scalar.substr(13);
471 FI.IsFixed = true;
472 } else {
473 return "Invalid frame index, needs to start with %stack. or "
474 "%fixed-stack.";
475 }
476 if (Num.consumeInteger(10, FI.FI))
477 return "Invalid frame index, not a valid number";
478
479 if (const auto *Node =
480 reinterpret_cast<yaml::Input *>(Ctx)->getCurrentNode())
482 return StringRef();
483 }
484
486};
487
488/// Identifies call instruction location in machine function.
490 unsigned BlockNum;
491 unsigned Offset;
492
493 bool operator==(const MachineInstrLoc &Other) const {
494 return BlockNum == Other.BlockNum && Offset == Other.Offset;
495 }
496};
497
498/// Serializable representation of CallSiteInfo.
500 // Representation of call argument and register which is used to
501 // transfer it.
502 struct ArgRegPair {
505
506 bool operator==(const ArgRegPair &Other) const {
507 return Reg == Other.Reg && ArgNo == Other.ArgNo;
508 }
509 };
510
512 std::vector<ArgRegPair> ArgForwardingRegs;
513 /// Numeric callee type identifiers for the callgraph section.
514 std::vector<uint64_t> CalleeTypeIds;
515
516 bool operator==(const CallSiteInfo &Other) const {
517 return CallLocation.BlockNum == Other.CallLocation.BlockNum &&
518 CallLocation.Offset == Other.CallLocation.Offset;
519 }
520};
521
522template <> struct MappingTraits<CallSiteInfo::ArgRegPair> {
523 static void mapping(IO &YamlIO, CallSiteInfo::ArgRegPair &ArgReg) {
524 YamlIO.mapRequired("arg", ArgReg.ArgNo);
525 YamlIO.mapRequired("reg", ArgReg.Reg);
526 }
527
528 static const bool flow = true;
529};
530}
531}
532
534
535namespace llvm {
536namespace yaml {
537
538template <> struct MappingTraits<CallSiteInfo> {
539 static void mapping(IO &YamlIO, CallSiteInfo &CSInfo) {
540 YamlIO.mapRequired("bb", CSInfo.CallLocation.BlockNum);
541 YamlIO.mapRequired("offset", CSInfo.CallLocation.Offset);
542 YamlIO.mapOptional("fwdArgRegs", CSInfo.ArgForwardingRegs,
543 std::vector<CallSiteInfo::ArgRegPair>());
544 YamlIO.mapOptional("calleeTypeIds", CSInfo.CalleeTypeIds);
545 }
546
547 static const bool flow = true;
548};
549
550/// Serializable representation of debug value substitutions.
552 unsigned SrcInst;
553 unsigned SrcOp;
554 unsigned DstInst;
555 unsigned DstOp;
556 unsigned Subreg;
557
559 return std::tie(SrcInst, SrcOp, DstInst, DstOp) ==
560 std::tie(Other.SrcInst, Other.SrcOp, Other.DstInst, Other.DstOp);
561 }
562};
563
565 static void mapping(IO &YamlIO, DebugValueSubstitution &Sub) {
566 YamlIO.mapRequired("srcinst", Sub.SrcInst);
567 YamlIO.mapRequired("srcop", Sub.SrcOp);
568 YamlIO.mapRequired("dstinst", Sub.DstInst);
569 YamlIO.mapRequired("dstop", Sub.DstOp);
570 YamlIO.mapRequired("subreg", Sub.Subreg);
571 }
572
573 static const bool flow = true;
574};
575} // namespace yaml
576} // namespace llvm
577
579
580namespace llvm {
581namespace yaml {
585 MaybeAlign Alignment = std::nullopt;
586 bool IsTargetSpecific = false;
587
589 return ID == Other.ID && Value == Other.Value &&
590 Alignment == Other.Alignment &&
591 IsTargetSpecific == Other.IsTargetSpecific;
592 }
593};
594
597 YamlIO.mapRequired("id", Constant.ID);
598 YamlIO.mapOptional("value", Constant.Value, StringValue());
599 YamlIO.mapOptional("alignment", Constant.Alignment, std::nullopt);
600 YamlIO.mapOptional("isTargetSpecific", Constant.IsTargetSpecific, false);
601 }
602};
603
605 struct Entry {
607 std::vector<FlowStringValue> Blocks;
608
609 bool operator==(const Entry &Other) const {
610 return ID == Other.ID && Blocks == Other.Blocks;
611 }
612 };
613
615 std::vector<Entry> Entries;
616
617 bool operator==(const MachineJumpTable &Other) const {
618 return Kind == Other.Kind && Entries == Other.Entries;
619 }
620};
621
622template <> struct MappingTraits<MachineJumpTable::Entry> {
623 static void mapping(IO &YamlIO, MachineJumpTable::Entry &Entry) {
624 YamlIO.mapRequired("id", Entry.ID);
625 YamlIO.mapOptional("blocks", Entry.Blocks, std::vector<FlowStringValue>());
626 }
627};
628
632 unsigned Flags;
633
634 bool operator==(const CalledGlobal &Other) const {
635 return CallSite == Other.CallSite && Callee == Other.Callee &&
636 Flags == Other.Flags;
637 }
638};
639
640template <> struct MappingTraits<CalledGlobal> {
641 static void mapping(IO &YamlIO, CalledGlobal &CG) {
642 YamlIO.mapRequired("bb", CG.CallSite.BlockNum);
643 YamlIO.mapRequired("offset", CG.CallSite.Offset);
644 YamlIO.mapRequired("callee", CG.Callee);
645 YamlIO.mapRequired("flags", CG.Flags);
646 }
647};
648
649} // end namespace yaml
650} // end namespace llvm
651
661
662namespace llvm {
663namespace yaml {
664
665// Struct representing one save/restore point in the 'savePoint' /
666// 'restorePoint' list. One point consists of machine basic block name and list
667// of registers saved/restored in this basic block. In MIR it looks like:
668// savePoint:
669// - point: '%bb.1'
670// registers:
671// - '$rbx'
672// - '$r12'
673// ...
674// restorePoint:
675// - point: '%bb.1'
676// registers:
677// - '$rbx'
678// - '$r12'
679// If no register is saved/restored in the selected BB,
680// field 'registers' is not specified.
683 std::vector<StringValue> Registers;
684
686 return Point == Other.Point && Registers == Other.Registers;
687 }
688};
689
691 static void mapping(IO &YamlIO, SaveRestorePointEntry &Entry) {
692 YamlIO.mapRequired("point", Entry.Point);
693 YamlIO.mapOptional("registers", Entry.Registers,
694 std::vector<StringValue>());
695 }
696};
697
698template <> struct MappingTraits<MachineJumpTable> {
699 static void mapping(IO &YamlIO, MachineJumpTable &JT) {
700 YamlIO.mapRequired("kind", JT.Kind);
701 YamlIO.mapOptional("entries", JT.Entries,
702 std::vector<MachineJumpTable::Entry>());
703 }
704};
705
706} // namespace yaml
707} // namespace llvm
708
710
711namespace llvm {
712namespace yaml {
713
714/// Serializable representation of MachineFrameInfo.
715///
716/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
717/// 'RealignOption' as they are determined by the target and LLVM function
718/// attributes.
719/// It also doesn't serialize attributes like 'NumFixedObject' and
720/// 'HasVarSizedObjects' as they are determined by the frame objects themselves.
724 bool HasStackMap = false;
725 bool HasPatchPoint = false;
728 unsigned MaxAlignment = 0;
729 bool AdjustsStack = false;
730 bool HasCalls = false;
734 unsigned MaxCallFrameSize = ~0u; ///< ~0u means: not computed yet.
737 bool HasVAStart = false;
739 bool HasTailCall = false;
741 unsigned LocalFrameSize = 0;
742 std::vector<SaveRestorePointEntry> SavePoints;
743 std::vector<SaveRestorePointEntry> RestorePoints;
744
745 bool operator==(const MachineFrameInfo &Other) const {
746 return IsFrameAddressTaken == Other.IsFrameAddressTaken &&
747 IsReturnAddressTaken == Other.IsReturnAddressTaken &&
748 HasStackMap == Other.HasStackMap &&
749 HasPatchPoint == Other.HasPatchPoint &&
750 StackSize == Other.StackSize &&
751 OffsetAdjustment == Other.OffsetAdjustment &&
752 MaxAlignment == Other.MaxAlignment &&
753 AdjustsStack == Other.AdjustsStack && HasCalls == Other.HasCalls &&
754 FramePointerPolicy == Other.FramePointerPolicy &&
755 StackProtector == Other.StackProtector &&
756 FunctionContext == Other.FunctionContext &&
757 MaxCallFrameSize == Other.MaxCallFrameSize &&
759 Other.CVBytesOfCalleeSavedRegisters &&
760 HasOpaqueSPAdjustment == Other.HasOpaqueSPAdjustment &&
761 HasVAStart == Other.HasVAStart &&
762 HasMustTailInVarArgFunc == Other.HasMustTailInVarArgFunc &&
763 HasTailCall == Other.HasTailCall &&
764 LocalFrameSize == Other.LocalFrameSize &&
765 SavePoints == Other.SavePoints &&
766 RestorePoints == Other.RestorePoints &&
767 IsCalleeSavedInfoValid == Other.IsCalleeSavedInfoValid;
768 }
769};
770
771template <> struct MappingTraits<MachineFrameInfo> {
772 static void mapping(IO &YamlIO, MachineFrameInfo &MFI) {
773 YamlIO.mapOptional("isFrameAddressTaken", MFI.IsFrameAddressTaken, false);
774 YamlIO.mapOptional("isReturnAddressTaken", MFI.IsReturnAddressTaken, false);
775 YamlIO.mapOptional("hasStackMap", MFI.HasStackMap, false);
776 YamlIO.mapOptional("hasPatchPoint", MFI.HasPatchPoint, false);
777 YamlIO.mapOptional("stackSize", MFI.StackSize, (uint64_t)0);
778 YamlIO.mapOptional("offsetAdjustment", MFI.OffsetAdjustment, (int)0);
779 YamlIO.mapOptional("maxAlignment", MFI.MaxAlignment, (unsigned)0);
780 YamlIO.mapOptional("adjustsStack", MFI.AdjustsStack, false);
781 YamlIO.mapOptional("hasCalls", MFI.HasCalls, false);
782 YamlIO.mapOptional("framePointerPolicy", MFI.FramePointerPolicy);
783 YamlIO.mapOptional("stackProtector", MFI.StackProtector,
784 StringValue()); // Don't print it out when it's empty.
785 YamlIO.mapOptional("functionContext", MFI.FunctionContext,
786 StringValue()); // Don't print it out when it's empty.
787 YamlIO.mapOptional("maxCallFrameSize", MFI.MaxCallFrameSize, (unsigned)~0);
788 YamlIO.mapOptional("cvBytesOfCalleeSavedRegisters",
790 YamlIO.mapOptional("hasOpaqueSPAdjustment", MFI.HasOpaqueSPAdjustment,
791 false);
792 YamlIO.mapOptional("hasVAStart", MFI.HasVAStart, false);
793 YamlIO.mapOptional("hasMustTailInVarArgFunc", MFI.HasMustTailInVarArgFunc,
794 false);
795 YamlIO.mapOptional("hasTailCall", MFI.HasTailCall, false);
796 YamlIO.mapOptional("isCalleeSavedInfoValid", MFI.IsCalleeSavedInfoValid,
797 false);
798 YamlIO.mapOptional("localFrameSize", MFI.LocalFrameSize, (unsigned)0);
799 YamlIO.mapOptional("savePoint", MFI.SavePoints);
800 YamlIO.mapOptional("restorePoint", MFI.RestorePoints);
801 }
802};
803
804/// Targets should override this in a way that mirrors the implementation of
805/// llvm::MachineFunctionInfo.
807 virtual ~MachineFunctionInfo() = default;
808 virtual void mappingImpl(IO &YamlIO) {}
809};
810
811template <> struct MappingTraits<std::unique_ptr<MachineFunctionInfo>> {
812 static void mapping(IO &YamlIO, std::unique_ptr<MachineFunctionInfo> &MFI) {
813 if (MFI)
814 MFI->mappingImpl(YamlIO);
815 }
816};
817
820 MaybeAlign Alignment = std::nullopt;
822 // GISel MachineFunctionProperties.
823 bool Legalized = false;
824 bool RegBankSelected = false;
825 bool Selected = false;
826 bool FailedISel = false;
827 // Register information
828 bool TracksRegLiveness = false;
829 bool HasWinCFI = false;
830
831 // Computed properties that should be overridable
832 std::optional<bool> NoPHIs;
833 std::optional<bool> IsSSA;
834 std::optional<bool> NoVRegs;
835 std::optional<bool> HasFakeUses;
836
837 bool CallsEHReturn = false;
838 bool CallsUnwindInit = false;
839 bool HasEHContTarget = false;
840 bool HasEHScopes = false;
841 bool HasEHFunclets = false;
842 bool IsOutlined = false;
843
844 bool FailsVerification = false;
846 bool UseDebugInstrRef = false;
847 std::vector<VirtualRegisterDefinition> VirtualRegisters;
848 std::vector<MachineFunctionLiveIn> LiveIns;
849 std::optional<std::vector<FlowStringValue>> CalleeSavedRegisters;
850 // TODO: Serialize the various register masks.
851 // Frame information
853 std::vector<FixedMachineStackObject> FixedStackObjects;
854 std::vector<EntryValueObject> EntryValueObjects;
855 std::vector<MachineStackObject> StackObjects;
856 std::vector<MachineConstantPoolValue> Constants; /// Constant pool.
857 std::unique_ptr<MachineFunctionInfo> MachineFuncInfo;
858 std::vector<CallSiteInfo> CallSitesInfo;
859 std::vector<DebugValueSubstitution> DebugValueSubstitutions;
861 std::vector<StringValue> MachineMetadataNodes;
862 std::vector<CalledGlobal> CalledGlobals;
863 std::vector<FlowStringValue> PrefetchTargets;
865};
866
867template <> struct MappingTraits<MachineFunction> {
868 static void mapping(IO &YamlIO, MachineFunction &MF) {
869 YamlIO.mapRequired("name", MF.Name);
870 YamlIO.mapOptional("alignment", MF.Alignment, std::nullopt);
871 YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice, false);
872 YamlIO.mapOptional("legalized", MF.Legalized, false);
873 YamlIO.mapOptional("regBankSelected", MF.RegBankSelected, false);
874 YamlIO.mapOptional("selected", MF.Selected, false);
875 YamlIO.mapOptional("failedISel", MF.FailedISel, false);
876 YamlIO.mapOptional("tracksRegLiveness", MF.TracksRegLiveness, false);
877 YamlIO.mapOptional("hasWinCFI", MF.HasWinCFI, false);
878
879 // PHIs must be not be capitalized, since it will clash with the MIR opcode
880 // leading to false-positive FileCheck hits with CHECK-NOT
881 YamlIO.mapOptional("noPhis", MF.NoPHIs, std::optional<bool>());
882 YamlIO.mapOptional("isSSA", MF.IsSSA, std::optional<bool>());
883 YamlIO.mapOptional("noVRegs", MF.NoVRegs, std::optional<bool>());
884 YamlIO.mapOptional("hasFakeUses", MF.HasFakeUses, std::optional<bool>());
885
886 YamlIO.mapOptional("callsEHReturn", MF.CallsEHReturn, false);
887 YamlIO.mapOptional("callsUnwindInit", MF.CallsUnwindInit, false);
888 YamlIO.mapOptional("hasEHContTarget", MF.HasEHContTarget, false);
889 YamlIO.mapOptional("hasEHScopes", MF.HasEHScopes, false);
890 YamlIO.mapOptional("hasEHFunclets", MF.HasEHFunclets, false);
891 YamlIO.mapOptional("isOutlined", MF.IsOutlined, false);
892 YamlIO.mapOptional("debugInstrRef", MF.UseDebugInstrRef, false);
893
894 YamlIO.mapOptional("failsVerification", MF.FailsVerification, false);
895 YamlIO.mapOptional("tracksDebugUserValues", MF.TracksDebugUserValues,
896 false);
897 YamlIO.mapOptional("registers", MF.VirtualRegisters,
898 std::vector<VirtualRegisterDefinition>());
899 YamlIO.mapOptional("liveins", MF.LiveIns,
900 std::vector<MachineFunctionLiveIn>());
901 YamlIO.mapOptional("calleeSavedRegisters", MF.CalleeSavedRegisters,
902 std::optional<std::vector<FlowStringValue>>());
903 YamlIO.mapOptional("frameInfo", MF.FrameInfo, MachineFrameInfo());
904 YamlIO.mapOptional("fixedStack", MF.FixedStackObjects,
905 std::vector<FixedMachineStackObject>());
906 YamlIO.mapOptional("stack", MF.StackObjects,
907 std::vector<MachineStackObject>());
908 YamlIO.mapOptional("entry_values", MF.EntryValueObjects,
909 std::vector<EntryValueObject>());
910 YamlIO.mapOptional("callSites", MF.CallSitesInfo,
911 std::vector<CallSiteInfo>());
912 YamlIO.mapOptional("debugValueSubstitutions", MF.DebugValueSubstitutions,
913 std::vector<DebugValueSubstitution>());
914 YamlIO.mapOptional("constants", MF.Constants,
915 std::vector<MachineConstantPoolValue>());
916 YamlIO.mapOptional("machineFunctionInfo", MF.MachineFuncInfo);
917 if (!YamlIO.outputting() || !MF.JumpTableInfo.Entries.empty())
918 YamlIO.mapOptional("jumpTable", MF.JumpTableInfo, MachineJumpTable());
919 if (!YamlIO.outputting() || !MF.MachineMetadataNodes.empty())
920 YamlIO.mapOptional("machineMetadataNodes", MF.MachineMetadataNodes,
921 std::vector<StringValue>());
922 if (!YamlIO.outputting() || !MF.CalledGlobals.empty())
923 YamlIO.mapOptional("calledGlobals", MF.CalledGlobals,
924 std::vector<CalledGlobal>());
925 if (!YamlIO.outputting() || !MF.PrefetchTargets.empty())
926 YamlIO.mapOptional("prefetch-targets", MF.PrefetchTargets,
927 std::vector<FlowStringValue>());
928
929 YamlIO.mapOptional("body", MF.Body, BlockStringValue());
930 }
931};
932
933} // end namespace yaml
934} // end namespace llvm
935
936#endif // LLVM_CODEGEN_MIRYAMLMAPPING_H
#define LLVM_ABI
Definition Compiler.h:213
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
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: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: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:1916
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:860
#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: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