llvm.org GIT mirror llvm / 7c6ad33
MIR Serialization: Serialize the simple MachineFrameInfo attributes. This commit serializes the 13 scalar boolean and integer attributes from the MachineFrameInfo class: IsFrameAddressTaken, IsReturnAddressTaken, HasStackMap, HasPatchPoint, StackSize, OffsetAdjustment, MaxAlignment, AdjustsStack, HasCalls, MaxCallFrameSize, HasOpaqueSPAdjustment, HasVAStart, and HasMustTailInVarArgFunc. These attributes are serialized as part of the frameInfo YAML mapping, which itself is a part of the machine function's YAML mapping. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241844 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Lorenz 5 years ago
4 changed file(s) with 185 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
113113 namespace llvm {
114114 namespace yaml {
115115
116 /// Serializable representation of MachineFrameInfo.
117 ///
118 /// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
119 /// 'RealignOption' as they are determined by the target and LLVM function
120 /// attributes.
121 /// It also doesn't serialize attributes like 'NumFixedObject' and
122 /// 'HasVarSizedObjects' as they are determined by the frame objects themselves.
123 struct MachineFrameInfo {
124 // TODO: Serialize stack objects.
125 bool IsFrameAddressTaken = false;
126 bool IsReturnAddressTaken = false;
127 bool HasStackMap = false;
128 bool HasPatchPoint = false;
129 uint64_t StackSize = 0;
130 int OffsetAdjustment = 0;
131 unsigned MaxAlignment = 0;
132 bool AdjustsStack = false;
133 bool HasCalls = false;
134 // TODO: Serialize StackProtectorIdx and FunctionContextIdx
135 unsigned MaxCallFrameSize = 0;
136 // TODO: Serialize callee saved info.
137 // TODO: Serialize local frame objects.
138 bool HasOpaqueSPAdjustment = false;
139 bool HasVAStart = false;
140 bool HasMustTailInVarArgFunc = false;
141 // TODO: Serialize save and restore MBB references.
142 };
143
144 template <> struct MappingTraits {
145 static void mapping(IO &YamlIO, MachineFrameInfo &MFI) {
146 YamlIO.mapOptional("isFrameAddressTaken", MFI.IsFrameAddressTaken);
147 YamlIO.mapOptional("isReturnAddressTaken", MFI.IsReturnAddressTaken);
148 YamlIO.mapOptional("hasStackMap", MFI.HasStackMap);
149 YamlIO.mapOptional("hasPatchPoint", MFI.HasPatchPoint);
150 YamlIO.mapOptional("stackSize", MFI.StackSize);
151 YamlIO.mapOptional("offsetAdjustment", MFI.OffsetAdjustment);
152 YamlIO.mapOptional("maxAlignment", MFI.MaxAlignment);
153 YamlIO.mapOptional("adjustsStack", MFI.AdjustsStack);
154 YamlIO.mapOptional("hasCalls", MFI.HasCalls);
155 YamlIO.mapOptional("maxCallFrameSize", MFI.MaxCallFrameSize);
156 YamlIO.mapOptional("hasOpaqueSPAdjustment", MFI.HasOpaqueSPAdjustment);
157 YamlIO.mapOptional("hasVAStart", MFI.HasVAStart);
158 YamlIO.mapOptional("hasMustTailInVarArgFunc", MFI.HasMustTailInVarArgFunc);
159 }
160 };
161
116162 struct MachineFunction {
117163 StringRef Name;
118164 unsigned Alignment = 0;
125171 // TODO: Serialize virtual register definitions.
126172 // TODO: Serialize the various register masks.
127173 // TODO: Serialize live in registers.
174 // Frame information
175 MachineFrameInfo FrameInfo;
128176
129177 std::vector BasicBlocks;
130178 };
138186 YamlIO.mapOptional("isSSA", MF.IsSSA);
139187 YamlIO.mapOptional("tracksRegLiveness", MF.TracksRegLiveness);
140188 YamlIO.mapOptional("tracksSubRegLiveness", MF.TracksSubRegLiveness);
189 YamlIO.mapOptional("frameInfo", MF.FrameInfo);
141190 YamlIO.mapOptional("body", MF.BasicBlocks);
142191 }
143192 };
2020 #include "llvm/AsmParser/Parser.h"
2121 #include "llvm/AsmParser/SlotMapping.h"
2222 #include "llvm/CodeGen/MachineFunction.h"
23 #include "llvm/CodeGen/MachineFrameInfo.h"
2324 #include "llvm/CodeGen/MachineRegisterInfo.h"
2425 #include "llvm/CodeGen/MIRYamlMapping.h"
2526 #include "llvm/IR/BasicBlock.h"
100101
101102 bool initializeRegisterInfo(MachineRegisterInfo &RegInfo,
102103 const yaml::MachineFunction &YamlMF);
104
105 bool initializeFrameInfo(MachineFrameInfo &MFI,
106 const yaml::MachineFrameInfo &YamlMFI);
103107
104108 private:
105109 /// Return a MIR diagnostic converted from an MI string diagnostic.
243247 MF.setExposesReturnsTwice(YamlMF.ExposesReturnsTwice);
244248 MF.setHasInlineAsm(YamlMF.HasInlineAsm);
245249 if (initializeRegisterInfo(MF.getRegInfo(), YamlMF))
250 return true;
251 if (initializeFrameInfo(*MF.getFrameInfo(), YamlMF.FrameInfo))
246252 return true;
247253
248254 PerFunctionMIParsingState PFS;
319325 return false;
320326 }
321327
328 bool MIRParserImpl::initializeFrameInfo(MachineFrameInfo &MFI,
329 const yaml::MachineFrameInfo &YamlMFI) {
330 MFI.setFrameAddressIsTaken(YamlMFI.IsFrameAddressTaken);
331 MFI.setReturnAddressIsTaken(YamlMFI.IsReturnAddressTaken);
332 MFI.setHasStackMap(YamlMFI.HasStackMap);
333 MFI.setHasPatchPoint(YamlMFI.HasPatchPoint);
334 MFI.setStackSize(YamlMFI.StackSize);
335 MFI.setOffsetAdjustment(YamlMFI.OffsetAdjustment);
336 if (YamlMFI.MaxAlignment)
337 MFI.ensureMaxAlignment(YamlMFI.MaxAlignment);
338 MFI.setAdjustsStack(YamlMFI.AdjustsStack);
339 MFI.setHasCalls(YamlMFI.HasCalls);
340 MFI.setMaxCallFrameSize(YamlMFI.MaxCallFrameSize);
341 MFI.setHasOpaqueSPAdjustment(YamlMFI.HasOpaqueSPAdjustment);
342 MFI.setHasVAStart(YamlMFI.HasVAStart);
343 MFI.setHasMustTailInVarArgFunc(YamlMFI.HasMustTailInVarArgFunc);
344 return false;
345 }
346
322347 SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
323348 SMRange SourceRange) {
324349 assert(SourceRange.isValid() && "Invalid source range");
1414 #include "MIRPrinter.h"
1515 #include "llvm/ADT/STLExtras.h"
1616 #include "llvm/CodeGen/MachineFunction.h"
17 #include "llvm/CodeGen/MachineFrameInfo.h"
1718 #include "llvm/CodeGen/MachineRegisterInfo.h"
1819 #include "llvm/CodeGen/MIRYamlMapping.h"
1920 #include "llvm/IR/BasicBlock.h"
4142 void print(const MachineFunction &MF);
4243
4344 void convert(yaml::MachineFunction &MF, const MachineRegisterInfo &RegInfo);
45 void convert(yaml::MachineFrameInfo &YamlMFI, const MachineFrameInfo &MFI);
4446 void convert(ModuleSlotTracker &MST, yaml::MachineBasicBlock &YamlMBB,
4547 const MachineBasicBlock &MBB);
4648
9395 YamlMF.ExposesReturnsTwice = MF.exposesReturnsTwice();
9496 YamlMF.HasInlineAsm = MF.hasInlineAsm();
9597 convert(YamlMF, MF.getRegInfo());
98 convert(YamlMF.FrameInfo, *MF.getFrameInfo());
9699
97100 int I = 0;
98101 ModuleSlotTracker MST(MF.getFunction()->getParent());
117120 MF.IsSSA = RegInfo.isSSA();
118121 MF.TracksRegLiveness = RegInfo.tracksLiveness();
119122 MF.TracksSubRegLiveness = RegInfo.subRegLivenessEnabled();
123 }
124
125 void MIRPrinter::convert(yaml::MachineFrameInfo &YamlMFI,
126 const MachineFrameInfo &MFI) {
127 YamlMFI.IsFrameAddressTaken = MFI.isFrameAddressTaken();
128 YamlMFI.IsReturnAddressTaken = MFI.isReturnAddressTaken();
129 YamlMFI.HasStackMap = MFI.hasStackMap();
130 YamlMFI.HasPatchPoint = MFI.hasPatchPoint();
131 YamlMFI.StackSize = MFI.getStackSize();
132 YamlMFI.OffsetAdjustment = MFI.getOffsetAdjustment();
133 YamlMFI.MaxAlignment = MFI.getMaxAlignment();
134 YamlMFI.AdjustsStack = MFI.adjustsStack();
135 YamlMFI.HasCalls = MFI.hasCalls();
136 YamlMFI.MaxCallFrameSize = MFI.getMaxCallFrameSize();
137 YamlMFI.HasOpaqueSPAdjustment = MFI.hasOpaqueSPAdjustment();
138 YamlMFI.HasVAStart = MFI.hasVAStart();
139 YamlMFI.HasMustTailInVarArgFunc = MFI.hasMustTailInVarArgFunc();
120140 }
121141
122142 void MIRPrinter::convert(ModuleSlotTracker &MST,
0 # RUN: llc -start-after machine-sink -stop-after machine-sink -o /dev/null %s | FileCheck %s
1 # This test ensures that the MIR parser parses machine frame info properties
2 # correctly.
3
4 --- |
5
6 define i32 @test(i32 %a) {
7 entry:
8 %b = alloca i32
9 store i32 %a, i32* %b
10 %c = load i32, i32* %b
11 ret i32 %c
12 }
13
14 define i32 @test2(i32 %a) {
15 entry:
16 %b = alloca i32
17 store i32 %a, i32* %b
18 %c = load i32, i32* %b
19 ret i32 %c
20 }
21
22 ...
23 ---
24 name: test
25 isSSA: true
26 tracksRegLiveness: true
27
28 # CHECK: frameInfo:
29 # CHECK-NEXT: isFrameAddressTaken: false
30 # CHECK-NEXT: isReturnAddressTaken: false
31 # CHECK-NEXT: hasStackMap: false
32 # CHECK-NEXT: hasPatchPoint: false
33 # CHECK-NEXT: stackSize: 0
34 # CHECK-NEXT: offsetAdjustment: 0
35 # Note: max alignment can be target specific when printed.
36 # CHECK-NEXT: maxAlignment:
37 # CHECK-NEXT: adjustsStack: false
38 # CHECK-NEXT: hasCalls: false
39 # CHECK-NEXT: maxCallFrameSize: 0
40 # CHECK-NEXT: hasOpaqueSPAdjustment: false
41 # CHECK-NEXT: hasVAStart: false
42 # CHECK-NEXT: hasMustTailInVarArgFunc: false
43 # CHECK: body
44 frameInfo:
45 maxAlignment: 4
46 body:
47 - id: 0
48 name: entry
49 ...
50 ---
51 name: test2
52 isSSA: true
53 tracksRegLiveness: true
54
55 # CHECK: test2
56 # CHECK: frameInfo:
57 # CHECK-NEXT: isFrameAddressTaken: true
58 # CHECK-NEXT: isReturnAddressTaken: true
59 # CHECK-NEXT: hasStackMap: true
60 # CHECK-NEXT: hasPatchPoint: true
61 # CHECK-NEXT: stackSize: 4
62 # CHECK-NEXT: offsetAdjustment: 4
63 # Note: max alignment can be target specific when printed.
64 # CHECK-NEXT: maxAlignment:
65 # CHECK-NEXT: adjustsStack: true
66 # CHECK-NEXT: hasCalls: true
67 # CHECK-NEXT: maxCallFrameSize: 4
68 # CHECK-NEXT: hasOpaqueSPAdjustment: true
69 # CHECK-NEXT: hasVAStart: true
70 # CHECK-NEXT: hasMustTailInVarArgFunc: true
71 # CHECK: body
72 frameInfo:
73 isFrameAddressTaken: true
74 isReturnAddressTaken: true
75 hasStackMap: true
76 hasPatchPoint: true
77 stackSize: 4
78 offsetAdjustment: 4
79 maxAlignment: 4
80 adjustsStack: true
81 hasCalls: true
82 maxCallFrameSize: 4
83 hasOpaqueSPAdjustment: true
84 hasVAStart: true
85 hasMustTailInVarArgFunc: true
86 body:
87 - id: 0
88 name: entry
89 ...
90