Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/MIRYamlMapping.h
Line
Count
Source (jump to first uncovered line)
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/Optional.h"
18
#include "llvm/ADT/StringRef.h"
19
#include "llvm/CodeGen/MachineJumpTableInfo.h"
20
#include "llvm/CodeGen/TargetFrameLowering.h"
21
#include "llvm/Support/SMLoc.h"
22
#include "llvm/Support/YAMLTraits.h"
23
#include "llvm/Support/raw_ostream.h"
24
#include <algorithm>
25
#include <cstdint>
26
#include <string>
27
#include <vector>
28
29
namespace llvm {
30
namespace yaml {
31
32
/// A wrapper around std::string which contains a source range that's being
33
/// set during parsing.
34
struct StringValue {
35
  std::string Value;
36
  SMRange SourceRange;
37
38
557k
  StringValue() = default;
39
504
  StringValue(std::string Value) : Value(std::move(Value)) {}
40
46.4k
  StringValue(const char Val[]) : Value(Val) {}
41
42
178k
  bool operator==(const StringValue &Other) const {
43
178k
    return Value == Other.Value;
44
178k
  }
45
};
46
47
template <> struct ScalarTraits<StringValue> {
48
232k
  static void output(const StringValue &S, void *, raw_ostream &OS) {
49
232k
    OS << S.Value;
50
232k
  }
51
52
42.0k
  static StringRef input(StringRef Scalar, void *Ctx, StringValue &S) {
53
42.0k
    S.Value = Scalar.str();
54
42.0k
    if (const auto *Node =
55
42.0k
            reinterpret_cast<yaml::Input *>(Ctx)->getCurrentNode())
56
42.0k
      S.SourceRange = Node->getSourceRange();
57
42.0k
    return "";
58
42.0k
  }
59
60
249k
  static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
61
};
62
63
struct FlowStringValue : StringValue {
64
1.32k
  FlowStringValue() = default;
65
238
  FlowStringValue(std::string Value) : StringValue(std::move(Value)) {}
66
};
67
68
template <> struct ScalarTraits<FlowStringValue> {
69
651
  static void output(const FlowStringValue &S, void *, raw_ostream &OS) {
70
651
    return ScalarTraits<StringValue>::output(S, nullptr, OS);
71
651
  }
72
73
913
  static StringRef input(StringRef Scalar, void *Ctx, FlowStringValue &S) {
74
913
    return ScalarTraits<StringValue>::input(Scalar, Ctx, S);
75
913
  }
76
77
1.56k
  static QuotingType mustQuote(StringRef S) { return needsQuotes(S); }
78
};
79
80
struct BlockStringValue {
81
  StringValue Value;
82
83
11.9k
  bool operator==(const BlockStringValue &Other) const {
84
11.9k
    return Value == Other.Value;
85
11.9k
  }
86
};
87
88
template <> struct BlockScalarTraits<BlockStringValue> {
89
11.9k
  static void output(const BlockStringValue &S, void *Ctx, raw_ostream &OS) {
90
11.9k
    return ScalarTraits<StringValue>::output(S.Value, Ctx, OS);
91
11.9k
  }
92
93
11.2k
  static StringRef input(StringRef Scalar, void *Ctx, BlockStringValue &S) {
94
11.2k
    return ScalarTraits<StringValue>::input(Scalar, Ctx, S.Value);
95
11.2k
  }
96
};
97
98
/// A wrapper around unsigned which contains a source range that's being set
99
/// during parsing.
100
struct UnsignedValue {
101
  unsigned Value = 0;
102
  SMRange SourceRange;
103
104
88.9k
  UnsignedValue() = default;
105
70.6k
  UnsignedValue(unsigned Value) : Value(Value) {}
106
107
0
  bool operator==(const UnsignedValue &Other) const {
108
0
    return Value == Other.Value;
109
0
  }
110
};
111
112
template <> struct ScalarTraits<UnsignedValue> {
113
70.5k
  static void output(const UnsignedValue &Value, void *Ctx, raw_ostream &OS) {
114
70.5k
    return ScalarTraits<unsigned>::output(Value.Value, Ctx, OS);
115
70.5k
  }
116
117
18.3k
  static StringRef input(StringRef Scalar, void *Ctx, UnsignedValue &Value) {
118
18.3k
    if (const auto *Node =
119
18.3k
            reinterpret_cast<yaml::Input *>(Ctx)->getCurrentNode())
120
18.3k
      Value.SourceRange = Node->getSourceRange();
121
18.3k
    return ScalarTraits<unsigned>::input(Scalar, Ctx, Value.Value);
122
18.3k
  }
123
124
88.8k
  static QuotingType mustQuote(StringRef Scalar) {
125
88.8k
    return ScalarTraits<unsigned>::mustQuote(Scalar);
126
88.8k
  }
127
};
128
129
template <> struct ScalarEnumerationTraits<MachineJumpTableInfo::JTEntryKind> {
130
  static void enumeration(yaml::IO &IO,
131
29
                          MachineJumpTableInfo::JTEntryKind &EntryKind) {
132
29
    IO.enumCase(EntryKind, "block-address",
133
29
                MachineJumpTableInfo::EK_BlockAddress);
134
29
    IO.enumCase(EntryKind, "gp-rel64-block-address",
135
29
                MachineJumpTableInfo::EK_GPRel64BlockAddress);
136
29
    IO.enumCase(EntryKind, "gp-rel32-block-address",
137
29
                MachineJumpTableInfo::EK_GPRel32BlockAddress);
138
29
    IO.enumCase(EntryKind, "label-difference32",
139
29
                MachineJumpTableInfo::EK_LabelDifference32);
140
29
    IO.enumCase(EntryKind, "inline", MachineJumpTableInfo::EK_Inline);
141
29
    IO.enumCase(EntryKind, "custom32", MachineJumpTableInfo::EK_Custom32);
142
29
  }
143
};
144
145
} // end namespace yaml
146
} // end namespace llvm
147
148
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::StringValue)
149
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::FlowStringValue)
150
LLVM_YAML_IS_FLOW_SEQUENCE_VECTOR(llvm::yaml::UnsignedValue)
151
152
namespace llvm {
153
namespace yaml {
154
155
struct VirtualRegisterDefinition {
156
  UnsignedValue ID;
157
  StringValue Class;
158
  StringValue PreferredRegister;
159
160
  // TODO: Serialize the target specific register hints.
161
162
0
  bool operator==(const VirtualRegisterDefinition &Other) const {
163
0
    return ID == Other.ID && Class == Other.Class &&
164
0
           PreferredRegister == Other.PreferredRegister;
165
0
  }
166
};
167
168
template <> struct MappingTraits<VirtualRegisterDefinition> {
169
86.2k
  static void mapping(IO &YamlIO, VirtualRegisterDefinition &Reg) {
170
86.2k
    YamlIO.mapRequired("id", Reg.ID);
171
86.2k
    YamlIO.mapRequired("class", Reg.Class);
172
86.2k
    YamlIO.mapOptional("preferred-register", Reg.PreferredRegister,
173
86.2k
                       StringValue()); // Don't print out when it's empty.
174
86.2k
  }
175
176
  static const bool flow = true;
177
};
178
179
struct MachineFunctionLiveIn {
180
  StringValue Register;
181
  StringValue VirtualRegister;
182
183
0
  bool operator==(const MachineFunctionLiveIn &Other) const {
184
0
    return Register == Other.Register &&
185
0
           VirtualRegister == Other.VirtualRegister;
186
0
  }
187
};
188
189
template <> struct MappingTraits<MachineFunctionLiveIn> {
190
4.83k
  static void mapping(IO &YamlIO, MachineFunctionLiveIn &LiveIn) {
191
4.83k
    YamlIO.mapRequired("reg", LiveIn.Register);
192
4.83k
    YamlIO.mapOptional(
193
4.83k
        "virtual-reg", LiveIn.VirtualRegister,
194
4.83k
        StringValue()); // Don't print the virtual register when it's empty.
195
4.83k
  }
196
197
  static const bool flow = true;
198
};
199
200
/// Serializable representation of stack object from the MachineFrameInfo class.
201
///
202
/// The flags 'isImmutable' and 'isAliased' aren't serialized, as they are
203
/// determined by the object's type and frame information flags.
204
/// Dead stack objects aren't serialized.
205
///
206
/// The 'isPreallocated' flag is determined by the local offset.
207
struct MachineStackObject {
208
  enum ObjectType { DefaultType, SpillSlot, VariableSized };
209
  UnsignedValue ID;
210
  StringValue Name;
211
  // TODO: Serialize unnamed LLVM alloca reference.
212
  ObjectType Type = DefaultType;
213
  int64_t Offset = 0;
214
  uint64_t Size = 0;
215
  unsigned Alignment = 0;
216
  TargetStackID::Value StackID;
217
  StringValue CalleeSavedRegister;
218
  bool CalleeSavedRestored = true;
219
  Optional<int64_t> LocalOffset;
220
  StringValue DebugVar;
221
  StringValue DebugExpr;
222
  StringValue DebugLoc;
223
224
0
  bool operator==(const MachineStackObject &Other) const {
225
0
    return ID == Other.ID && Name == Other.Name && Type == Other.Type &&
226
0
           Offset == Other.Offset && Size == Other.Size &&
227
0
           Alignment == Other.Alignment &&
228
0
           StackID == Other.StackID &&
229
0
           CalleeSavedRegister == Other.CalleeSavedRegister &&
230
0
           CalleeSavedRestored == Other.CalleeSavedRestored &&
231
0
           LocalOffset == Other.LocalOffset && DebugVar == Other.DebugVar &&
232
0
           DebugExpr == Other.DebugExpr && DebugLoc == Other.DebugLoc;
233
0
  }
234
};
235
236
template <> struct ScalarEnumerationTraits<MachineStackObject::ObjectType> {
237
1.50k
  static void enumeration(yaml::IO &IO, MachineStackObject::ObjectType &Type) {
238
1.50k
    IO.enumCase(Type, "default", MachineStackObject::DefaultType);
239
1.50k
    IO.enumCase(Type, "spill-slot", MachineStackObject::SpillSlot);
240
1.50k
    IO.enumCase(Type, "variable-sized", MachineStackObject::VariableSized);
241
1.50k
  }
242
};
243
244
template <> struct MappingTraits<MachineStackObject> {
245
1.64k
  static void mapping(yaml::IO &YamlIO, MachineStackObject &Object) {
246
1.64k
    YamlIO.mapRequired("id", Object.ID);
247
1.64k
    YamlIO.mapOptional("name", Object.Name,
248
1.64k
                       StringValue()); // Don't print out an empty name.
249
1.64k
    YamlIO.mapOptional(
250
1.64k
        "type", Object.Type,
251
1.64k
        MachineStackObject::DefaultType); // Don't print the default type.
252
1.64k
    YamlIO.mapOptional("offset", Object.Offset, (int64_t)0);
253
1.64k
    if (Object.Type != MachineStackObject::VariableSized)
254
1.62k
      YamlIO.mapRequired("size", Object.Size);
255
1.64k
    YamlIO.mapOptional("alignment", Object.Alignment, (unsigned)0);
256
1.64k
    YamlIO.mapOptional("stack-id", Object.StackID, TargetStackID::Default);
257
1.64k
    YamlIO.mapOptional("callee-saved-register", Object.CalleeSavedRegister,
258
1.64k
                       StringValue()); // Don't print it out when it's empty.
259
1.64k
    YamlIO.mapOptional("callee-saved-restored", Object.CalleeSavedRestored,
260
1.64k
                       true);
261
1.64k
    YamlIO.mapOptional("local-offset", Object.LocalOffset, Optional<int64_t>());
262
1.64k
    YamlIO.mapOptional("debug-info-variable", Object.DebugVar,
263
1.64k
                       StringValue()); // Don't print it out when it's empty.
264
1.64k
    YamlIO.mapOptional("debug-info-expression", Object.DebugExpr,
265
1.64k
                       StringValue()); // Don't print it out when it's empty.
266
1.64k
    YamlIO.mapOptional("debug-info-location", Object.DebugLoc,
267
1.64k
                       StringValue()); // Don't print it out when it's empty.
268
1.64k
  }
269
270
  static const bool flow = true;
271
};
272
273
/// Serializable representation of the fixed stack object from the
274
/// MachineFrameInfo class.
275
struct FixedMachineStackObject {
276
  enum ObjectType { DefaultType, SpillSlot };
277
  UnsignedValue ID;
278
  ObjectType Type = DefaultType;
279
  int64_t Offset = 0;
280
  uint64_t Size = 0;
281
  unsigned Alignment = 0;
282
  TargetStackID::Value StackID;
283
  bool IsImmutable = false;
284
  bool IsAliased = false;
285
  StringValue CalleeSavedRegister;
286
  bool CalleeSavedRestored = true;
287
  StringValue DebugVar;
288
  StringValue DebugExpr;
289
  StringValue DebugLoc;
290
291
0
  bool operator==(const FixedMachineStackObject &Other) const {
292
0
    return ID == Other.ID && Type == Other.Type && Offset == Other.Offset &&
293
0
           Size == Other.Size && Alignment == Other.Alignment &&
294
0
           StackID == Other.StackID &&
295
0
           IsImmutable == Other.IsImmutable && IsAliased == Other.IsAliased &&
296
0
           CalleeSavedRegister == Other.CalleeSavedRegister &&
297
0
           CalleeSavedRestored == Other.CalleeSavedRestored &&
298
0
           DebugVar == Other.DebugVar && DebugExpr == Other.DebugExpr
299
0
           && DebugLoc == Other.DebugLoc;
300
0
  }
301
};
302
303
template <>
304
struct ScalarEnumerationTraits<FixedMachineStackObject::ObjectType> {
305
  static void enumeration(yaml::IO &IO,
306
736
                          FixedMachineStackObject::ObjectType &Type) {
307
736
    IO.enumCase(Type, "default", FixedMachineStackObject::DefaultType);
308
736
    IO.enumCase(Type, "spill-slot", FixedMachineStackObject::SpillSlot);
309
736
  }
310
};
311
312
template <>
313
struct ScalarEnumerationTraits<TargetStackID::Value> {
314
2.15k
  static void enumeration(yaml::IO &IO, TargetStackID::Value &ID) {
315
2.15k
    IO.enumCase(ID, "default", TargetStackID::Default);
316
2.15k
    IO.enumCase(ID, "sgpr-spill", TargetStackID::SGPRSpill);
317
2.15k
    IO.enumCase(ID, "noalloc", TargetStackID::NoAlloc);
318
2.15k
  }
319
};
320
321
template <> struct MappingTraits<FixedMachineStackObject> {
322
859
  static void mapping(yaml::IO &YamlIO, FixedMachineStackObject &Object) {
323
859
    YamlIO.mapRequired("id", Object.ID);
324
859
    YamlIO.mapOptional(
325
859
        "type", Object.Type,
326
859
        FixedMachineStackObject::DefaultType); // Don't print the default type.
327
859
    YamlIO.mapOptional("offset", Object.Offset, (int64_t)0);
328
859
    YamlIO.mapOptional("size", Object.Size, (uint64_t)0);
329
859
    YamlIO.mapOptional("alignment", Object.Alignment, (unsigned)0);
330
859
    YamlIO.mapOptional("stack-id", Object.StackID, TargetStackID::Default);
331
859
    if (Object.Type != FixedMachineStackObject::SpillSlot) {
332
710
      YamlIO.mapOptional("isImmutable", Object.IsImmutable, false);
333
710
      YamlIO.mapOptional("isAliased", Object.IsAliased, false);
334
710
    }
335
859
    YamlIO.mapOptional("callee-saved-register", Object.CalleeSavedRegister,
336
859
                       StringValue()); // Don't print it out when it's empty.
337
859
    YamlIO.mapOptional("callee-saved-restored", Object.CalleeSavedRestored,
338
859
                     true);
339
859
    YamlIO.mapOptional("debug-info-variable", Object.DebugVar,
340
859
                       StringValue()); // Don't print it out when it's empty.
341
859
    YamlIO.mapOptional("debug-info-expression", Object.DebugExpr,
342
859
                       StringValue()); // Don't print it out when it's empty.
343
859
    YamlIO.mapOptional("debug-info-location", Object.DebugLoc,
344
859
                       StringValue()); // Don't print it out when it's empty.
345
859
  }
346
347
  static const bool flow = true;
348
};
349
350
351
/// Serializable representation of CallSiteInfo.
352
struct CallSiteInfo {
353
  // Representation of call argument and register which is used to
354
  // transfer it.
355
  struct ArgRegPair {
356
    StringValue Reg;
357
    uint16_t ArgNo;
358
359
0
    bool operator==(const ArgRegPair &Other) const {
360
0
      return Reg == Other.Reg && ArgNo == Other.ArgNo;
361
0
    }
362
  };
363
364
  /// Identifies call instruction location in machine function.
365
  struct MachineInstrLoc {
366
    unsigned BlockNum;
367
    unsigned Offset;
368
369
0
    bool operator==(const MachineInstrLoc &Other) const {
370
0
      return BlockNum == Other.BlockNum && Offset == Other.Offset;
371
0
    }
372
  };
373
374
  MachineInstrLoc CallLocation;
375
  std::vector<ArgRegPair> ArgForwardingRegs;
376
377
0
  bool operator==(const CallSiteInfo &Other) const {
378
0
    return CallLocation.BlockNum == Other.CallLocation.BlockNum &&
379
0
           CallLocation.Offset == Other.CallLocation.Offset;
380
0
  }
381
};
382
383
template <> struct MappingTraits<CallSiteInfo::ArgRegPair> {
384
13
  static void mapping(IO &YamlIO, CallSiteInfo::ArgRegPair &ArgReg) {
385
13
    YamlIO.mapRequired("arg", ArgReg.ArgNo);
386
13
    YamlIO.mapRequired("reg", ArgReg.Reg);
387
13
  }
388
389
  static const bool flow = true;
390
};
391
}
392
}
393
394
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::CallSiteInfo::ArgRegPair)
395
396
namespace llvm {
397
namespace yaml {
398
399
template <> struct MappingTraits<CallSiteInfo> {
400
7
  static void mapping(IO &YamlIO, CallSiteInfo &CSInfo) {
401
7
    YamlIO.mapRequired("bb", CSInfo.CallLocation.BlockNum);
402
7
    YamlIO.mapRequired("offset", CSInfo.CallLocation.Offset);
403
7
    YamlIO.mapOptional("fwdArgRegs", CSInfo.ArgForwardingRegs,
404
7
                       std::vector<CallSiteInfo::ArgRegPair>());
405
7
  }
406
407
  static const bool flow = true;
408
};
409
410
struct MachineConstantPoolValue {
411
  UnsignedValue ID;
412
  StringValue Value;
413
  unsigned Alignment = 0;
414
  bool IsTargetSpecific = false;
415
416
0
  bool operator==(const MachineConstantPoolValue &Other) const {
417
0
    return ID == Other.ID && Value == Other.Value &&
418
0
           Alignment == Other.Alignment &&
419
0
           IsTargetSpecific == Other.IsTargetSpecific;
420
0
  }
421
};
422
423
template <> struct MappingTraits<MachineConstantPoolValue> {
424
124
  static void mapping(IO &YamlIO, MachineConstantPoolValue &Constant) {
425
124
    YamlIO.mapRequired("id", Constant.ID);
426
124
    YamlIO.mapOptional("value", Constant.Value, StringValue());
427
124
    YamlIO.mapOptional("alignment", Constant.Alignment, (unsigned)0);
428
124
    YamlIO.mapOptional("isTargetSpecific", Constant.IsTargetSpecific, false);
429
124
  }
430
};
431
432
struct MachineJumpTable {
433
  struct Entry {
434
    UnsignedValue ID;
435
    std::vector<FlowStringValue> Blocks;
436
437
0
    bool operator==(const Entry &Other) const {
438
0
      return ID == Other.ID && Blocks == Other.Blocks;
439
0
    }
440
  };
441
442
  MachineJumpTableInfo::JTEntryKind Kind = MachineJumpTableInfo::EK_Custom32;
443
  std::vector<Entry> Entries;
444
445
13
  bool operator==(const MachineJumpTable &Other) const {
446
13
    return Kind == Other.Kind && 
Entries == Other.Entries0
;
447
13
  }
448
};
449
450
template <> struct MappingTraits<MachineJumpTable::Entry> {
451
39
  static void mapping(IO &YamlIO, MachineJumpTable::Entry &Entry) {
452
39
    YamlIO.mapRequired("id", Entry.ID);
453
39
    YamlIO.mapOptional("blocks", Entry.Blocks, std::vector<FlowStringValue>());
454
39
  }
455
};
456
457
} // end namespace yaml
458
} // end namespace llvm
459
460
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineFunctionLiveIn)
461
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::VirtualRegisterDefinition)
462
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineStackObject)
463
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::FixedMachineStackObject)
464
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::CallSiteInfo)
465
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineConstantPoolValue)
466
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineJumpTable::Entry)
467
468
namespace llvm {
469
namespace yaml {
470
471
template <> struct MappingTraits<MachineJumpTable> {
472
29
  static void mapping(IO &YamlIO, MachineJumpTable &JT) {
473
29
    YamlIO.mapRequired("kind", JT.Kind);
474
29
    YamlIO.mapOptional("entries", JT.Entries,
475
29
                       std::vector<MachineJumpTable::Entry>());
476
29
  }
477
};
478
479
/// Serializable representation of MachineFrameInfo.
480
///
481
/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
482
/// 'RealignOption' as they are determined by the target and LLVM function
483
/// attributes.
484
/// It also doesn't serialize attributes like 'NumFixedObject' and
485
/// 'HasVarSizedObjects' as they are determined by the frame objects themselves.
486
struct MachineFrameInfo {
487
  bool IsFrameAddressTaken = false;
488
  bool IsReturnAddressTaken = false;
489
  bool HasStackMap = false;
490
  bool HasPatchPoint = false;
491
  uint64_t StackSize = 0;
492
  int OffsetAdjustment = 0;
493
  unsigned MaxAlignment = 0;
494
  bool AdjustsStack = false;
495
  bool HasCalls = false;
496
  StringValue StackProtector;
497
  // TODO: Serialize FunctionContextIdx
498
  unsigned MaxCallFrameSize = ~0u; ///< ~0u means: not computed yet.
499
  unsigned CVBytesOfCalleeSavedRegisters = 0;
500
  bool HasOpaqueSPAdjustment = false;
501
  bool HasVAStart = false;
502
  bool HasMustTailInVarArgFunc = false;
503
  unsigned LocalFrameSize = 0;
504
  StringValue SavePoint;
505
  StringValue RestorePoint;
506
507
11.9k
  bool operator==(const MachineFrameInfo &Other) const {
508
11.9k
    return IsFrameAddressTaken == Other.IsFrameAddressTaken &&
509
11.9k
           
IsReturnAddressTaken == Other.IsReturnAddressTaken11.9k
&&
510
11.9k
           
HasStackMap == Other.HasStackMap11.9k
&&
511
11.9k
           
HasPatchPoint == Other.HasPatchPoint11.9k
&&
512
11.9k
           
StackSize == Other.StackSize11.9k
&&
513
11.9k
           
OffsetAdjustment == Other.OffsetAdjustment11.7k
&&
514
11.9k
           
MaxAlignment == Other.MaxAlignment11.7k
&&
515
11.9k
           
AdjustsStack == Other.AdjustsStack11.1k
&&
HasCalls == Other.HasCalls11.1k
&&
516
11.9k
           
StackProtector == Other.StackProtector10.6k
&&
517
11.9k
           
MaxCallFrameSize == Other.MaxCallFrameSize10.6k
&&
518
11.9k
           CVBytesOfCalleeSavedRegisters ==
519
8.74k
               Other.CVBytesOfCalleeSavedRegisters &&
520
11.9k
           
HasOpaqueSPAdjustment == Other.HasOpaqueSPAdjustment8.74k
&&
521
11.9k
           
HasVAStart == Other.HasVAStart8.74k
&&
522
11.9k
           
HasMustTailInVarArgFunc == Other.HasMustTailInVarArgFunc8.74k
&&
523
11.9k
           
LocalFrameSize == Other.LocalFrameSize8.74k
&&
524
11.9k
           
SavePoint == Other.SavePoint8.74k
&&
RestorePoint == Other.RestorePoint8.74k
;
525
11.9k
  }
526
};
527
528
template <> struct MappingTraits<MachineFrameInfo> {
529
12.7k
  static void mapping(IO &YamlIO, MachineFrameInfo &MFI) {
530
12.7k
    YamlIO.mapOptional("isFrameAddressTaken", MFI.IsFrameAddressTaken, false);
531
12.7k
    YamlIO.mapOptional("isReturnAddressTaken", MFI.IsReturnAddressTaken, false);
532
12.7k
    YamlIO.mapOptional("hasStackMap", MFI.HasStackMap, false);
533
12.7k
    YamlIO.mapOptional("hasPatchPoint", MFI.HasPatchPoint, false);
534
12.7k
    YamlIO.mapOptional("stackSize", MFI.StackSize, (uint64_t)0);
535
12.7k
    YamlIO.mapOptional("offsetAdjustment", MFI.OffsetAdjustment, (int)0);
536
12.7k
    YamlIO.mapOptional("maxAlignment", MFI.MaxAlignment, (unsigned)0);
537
12.7k
    YamlIO.mapOptional("adjustsStack", MFI.AdjustsStack, false);
538
12.7k
    YamlIO.mapOptional("hasCalls", MFI.HasCalls, false);
539
12.7k
    YamlIO.mapOptional("stackProtector", MFI.StackProtector,
540
12.7k
                       StringValue()); // Don't print it out when it's empty.
541
12.7k
    YamlIO.mapOptional("maxCallFrameSize", MFI.MaxCallFrameSize, (unsigned)~0);
542
12.7k
    YamlIO.mapOptional("cvBytesOfCalleeSavedRegisters",
543
12.7k
                       MFI.CVBytesOfCalleeSavedRegisters, 0U);
544
12.7k
    YamlIO.mapOptional("hasOpaqueSPAdjustment", MFI.HasOpaqueSPAdjustment,
545
12.7k
                       false);
546
12.7k
    YamlIO.mapOptional("hasVAStart", MFI.HasVAStart, false);
547
12.7k
    YamlIO.mapOptional("hasMustTailInVarArgFunc", MFI.HasMustTailInVarArgFunc,
548
12.7k
                       false);
549
12.7k
    YamlIO.mapOptional("localFrameSize", MFI.LocalFrameSize, (unsigned)0);
550
12.7k
    YamlIO.mapOptional("savePoint", MFI.SavePoint,
551
12.7k
                       StringValue()); // Don't print it out when it's empty.
552
12.7k
    YamlIO.mapOptional("restorePoint", MFI.RestorePoint,
553
12.7k
                       StringValue()); // Don't print it out when it's empty.
554
12.7k
  }
555
};
556
557
/// Targets should override this in a way that mirrors the implementation of
558
/// llvm::MachineFunctionInfo.
559
struct MachineFunctionInfo {
560
11.4k
  virtual ~MachineFunctionInfo() {}
561
0
  virtual void mappingImpl(IO &YamlIO) {}
562
};
563
564
template <> struct MappingTraits<std::unique_ptr<MachineFunctionInfo>> {
565
12.5k
  static void mapping(IO &YamlIO, std::unique_ptr<MachineFunctionInfo> &MFI) {
566
12.5k
    if (MFI)
567
6.02k
      MFI->mappingImpl(YamlIO);
568
12.5k
  }
569
};
570
571
struct MachineFunction {
572
  StringRef Name;
573
  unsigned Alignment = 0;
574
  bool ExposesReturnsTwice = false;
575
  // GISel MachineFunctionProperties.
576
  bool Legalized = false;
577
  bool RegBankSelected = false;
578
  bool Selected = false;
579
  bool FailedISel = false;
580
  // Register information
581
  bool TracksRegLiveness = false;
582
  bool HasWinCFI = false;
583
  std::vector<VirtualRegisterDefinition> VirtualRegisters;
584
  std::vector<MachineFunctionLiveIn> LiveIns;
585
  Optional<std::vector<FlowStringValue>> CalleeSavedRegisters;
586
  // TODO: Serialize the various register masks.
587
  // Frame information
588
  MachineFrameInfo FrameInfo;
589
  std::vector<FixedMachineStackObject> FixedStackObjects;
590
  std::vector<MachineStackObject> StackObjects;
591
  std::vector<MachineConstantPoolValue> Constants; /// Constant pool.
592
  std::unique_ptr<MachineFunctionInfo> MachineFuncInfo;
593
  std::vector<CallSiteInfo> CallSitesInfo;
594
  MachineJumpTable JumpTableInfo;
595
  BlockStringValue Body;
596
};
597
598
template <> struct MappingTraits<MachineFunction> {
599
23.2k
  static void mapping(IO &YamlIO, MachineFunction &MF) {
600
23.2k
    YamlIO.mapRequired("name", MF.Name);
601
23.2k
    YamlIO.mapOptional("alignment", MF.Alignment, (unsigned)0);
602
23.2k
    YamlIO.mapOptional("exposesReturnsTwice", MF.ExposesReturnsTwice, false);
603
23.2k
    YamlIO.mapOptional("legalized", MF.Legalized, false);
604
23.2k
    YamlIO.mapOptional("regBankSelected", MF.RegBankSelected, false);
605
23.2k
    YamlIO.mapOptional("selected", MF.Selected, false);
606
23.2k
    YamlIO.mapOptional("failedISel", MF.FailedISel, false);
607
23.2k
    YamlIO.mapOptional("tracksRegLiveness", MF.TracksRegLiveness, false);
608
23.2k
    YamlIO.mapOptional("hasWinCFI", MF.HasWinCFI, false);
609
23.2k
    YamlIO.mapOptional("registers", MF.VirtualRegisters,
610
23.2k
                       std::vector<VirtualRegisterDefinition>());
611
23.2k
    YamlIO.mapOptional("liveins", MF.LiveIns,
612
23.2k
                       std::vector<MachineFunctionLiveIn>());
613
23.2k
    YamlIO.mapOptional("calleeSavedRegisters", MF.CalleeSavedRegisters,
614
23.2k
                       Optional<std::vector<FlowStringValue>>());
615
23.2k
    YamlIO.mapOptional("frameInfo", MF.FrameInfo, MachineFrameInfo());
616
23.2k
    YamlIO.mapOptional("fixedStack", MF.FixedStackObjects,
617
23.2k
                       std::vector<FixedMachineStackObject>());
618
23.2k
    YamlIO.mapOptional("stack", MF.StackObjects,
619
23.2k
                       std::vector<MachineStackObject>());
620
23.2k
    YamlIO.mapOptional("callSites", MF.CallSitesInfo,
621
23.2k
                       std::vector<CallSiteInfo>());
622
23.2k
    YamlIO.mapOptional("constants", MF.Constants,
623
23.2k
                       std::vector<MachineConstantPoolValue>());
624
23.2k
    YamlIO.mapOptional("machineFunctionInfo", MF.MachineFuncInfo);
625
23.2k
    if (!YamlIO.outputting() || 
!MF.JumpTableInfo.Entries.empty()11.9k
)
626
11.3k
      YamlIO.mapOptional("jumpTable", MF.JumpTableInfo, MachineJumpTable());
627
23.2k
    YamlIO.mapOptional("body", MF.Body, BlockStringValue());
628
23.2k
  }
629
};
630
631
} // end namespace yaml
632
} // end namespace llvm
633
634
#endif // LLVM_CODEGEN_MIRYAMLMAPPING_H