llvm.org GIT mirror llvm / ad7556d
MIR Serialization: Serialize the fixed stack objects. This commit serializes the fixed stack objects, including fixed spill slots. The fixed stack objects are serialized using a YAML sequence of YAML inline mappings. Each mapping has the object's ID, type, size, offset, and alignment. The objects that aren't spill slots also serialize the isImmutable and isAliased flags. The fixed stack objects are a part of the machine function's YAML mapping. Reviewers: Duncan P. N. Exon Smith git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242045 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Lorenz 5 years ago
7 changed file(s) with 213 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
128128 ///
129129 /// TODO: Determine isPreallocated flag by mapping between objects and local
130130 /// objects (Serialize local objects).
131 /// TODO: Serialize variable sized and fixed stack objects.
131 /// TODO: Serialize variable sized objects.
132132 struct MachineStackObject {
133133 enum ObjectType { DefaultType, SpillSlot };
134134 // TODO: Serialize LLVM alloca reference.
160160 static const bool flow = true;
161161 };
162162
163 /// Serializable representation of the fixed stack object from the
164 /// MachineFrameInfo class.
165 struct FixedMachineStackObject {
166 enum ObjectType { DefaultType, SpillSlot };
167 unsigned ID;
168 ObjectType Type = DefaultType;
169 int64_t Offset = 0;
170 uint64_t Size = 0;
171 unsigned Alignment = 0;
172 bool IsImmutable = false;
173 bool IsAliased = false;
174 };
175
176 template <>
177 struct ScalarEnumerationTraits {
178 static void enumeration(yaml::IO &IO,
179 FixedMachineStackObject::ObjectType &Type) {
180 IO.enumCase(Type, "default", FixedMachineStackObject::DefaultType);
181 IO.enumCase(Type, "spill-slot", FixedMachineStackObject::SpillSlot);
182 }
183 };
184
185 template <> struct MappingTraits {
186 static void mapping(yaml::IO &YamlIO, FixedMachineStackObject &Object) {
187 YamlIO.mapRequired("id", Object.ID);
188 YamlIO.mapOptional(
189 "type", Object.Type,
190 FixedMachineStackObject::DefaultType); // Don't print the default type.
191 YamlIO.mapOptional("offset", Object.Offset);
192 YamlIO.mapOptional("size", Object.Size);
193 YamlIO.mapOptional("alignment", Object.Alignment);
194 if (Object.Type != FixedMachineStackObject::SpillSlot) {
195 YamlIO.mapOptional("isImmutable", Object.IsImmutable);
196 YamlIO.mapOptional("isAliased", Object.IsAliased);
197 }
198 }
199
200 static const bool flow = true;
201 };
202
163203 } // end namespace yaml
164204 } // end namespace llvm
165205
166206 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::VirtualRegisterDefinition)
167207 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineBasicBlock)
168208 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineStackObject)
209 LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::FixedMachineStackObject)
169210
170211 namespace llvm {
171212 namespace yaml {
229270 // TODO: Serialize live in registers.
230271 // Frame information
231272 MachineFrameInfo FrameInfo;
273 std::vector FixedStackObjects;
232274 std::vector StackObjects;
233275
234276 std::vector BasicBlocks;
245287 YamlIO.mapOptional("tracksSubRegLiveness", MF.TracksSubRegLiveness);
246288 YamlIO.mapOptional("registers", MF.VirtualRegisters);
247289 YamlIO.mapOptional("frameInfo", MF.FrameInfo);
290 YamlIO.mapOptional("fixedStack", MF.FixedStackObjects);
248291 YamlIO.mapOptional("stack", MF.StackObjects);
249292 YamlIO.mapOptional("body", MF.BasicBlocks);
250293 }
375375 MFI.setHasVAStart(YamlMFI.HasVAStart);
376376 MFI.setHasMustTailInVarArgFunc(YamlMFI.HasMustTailInVarArgFunc);
377377
378 // Initialize the frame objects.
378 // Initialize the fixed frame objects.
379 for (const auto &Object : YamlMF.FixedStackObjects) {
380 int ObjectIdx;
381 if (Object.Type != yaml::FixedMachineStackObject::SpillSlot)
382 ObjectIdx = MFI.CreateFixedObject(Object.Size, Object.Offset,
383 Object.IsImmutable, Object.IsAliased);
384 else
385 ObjectIdx = MFI.CreateFixedSpillStackObject(Object.Size, Object.Offset);
386 MFI.setObjectAlignment(ObjectIdx, Object.Alignment);
387 // TODO: Store the mapping between fixed object IDs and object indices to
388 // parse fixed stack object references correctly.
389 }
390
391 // Initialize the ordinary frame objects.
379392 for (const auto &Object : YamlMF.StackObjects) {
380393 int ObjectIdx = MFI.CreateStackObject(
381394 Object.Size, Object.Alignment,
156156
157157 void MIRPrinter::convertStackObjects(yaml::MachineFunction &MF,
158158 const MachineFrameInfo &MFI) {
159 // Process fixed stack objects.
159160 unsigned ID = 0;
161 for (int I = MFI.getObjectIndexBegin(); I < 0; ++I) {
162 if (MFI.isDeadObjectIndex(I))
163 continue;
164
165 yaml::FixedMachineStackObject YamlObject;
166 YamlObject.ID = ID++;
167 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
168 ? yaml::FixedMachineStackObject::SpillSlot
169 : yaml::FixedMachineStackObject::DefaultType;
170 YamlObject.Offset = MFI.getObjectOffset(I);
171 YamlObject.Size = MFI.getObjectSize(I);
172 YamlObject.Alignment = MFI.getObjectAlignment(I);
173 YamlObject.IsImmutable = MFI.isImmutableObjectIndex(I);
174 YamlObject.IsAliased = MFI.isAliasedObjectIndex(I);
175 MF.FixedStackObjects.push_back(YamlObject);
176 // TODO: Store the mapping between fixed object IDs and object indices to
177 // print the fixed stack object references correctly.
178 }
179
180 // Process ordinary stack objects.
181 ID = 0;
160182 for (int I = 0, E = MFI.getObjectIndexEnd(); I < E; ++I) {
161183 if (MFI.isDeadObjectIndex(I))
162184 continue;
0 # RUN: llc -march=x86 -start-after branch-folder -stop-after branch-folder -o /dev/null %s | FileCheck %s
1 # This test ensures that the MIR parser parses fixed stack objects correctly.
2
3 --- |
4
5 define i32 @test(i32 %a) #0 {
6 entry:
7 %b = alloca i32
8 store i32 %a, i32* %b
9 %c = load i32, i32* %b
10 ret i32 %c
11 }
12
13 attributes #0 = { "no-frame-pointer-elim"="false" }
14
15 ...
16 ---
17 name: test
18 frameInfo:
19 stackSize: 4
20 maxAlignment: 4
21 # CHECK: fixedStack:
22 # CHECK-NEXT: - { id: 0, offset: 0, size: 4, alignment: 4, isImmutable: true, isAliased: false }
23 fixedStack:
24 - { id: 0, offset: 0, size: 4, alignment: 4, isImmutable: true, isAliased: false }
25 stack:
26 - { id: 0, offset: -8, size: 4, alignment: 4 }
27 body:
28 - id: 0
29 name: entry
30 instructions:
31 - '%eax = MOV32rm %esp, 1, _, 8, _'
32 - 'MOV32mr %esp, 1, _, 0, _, %eax'
33 - 'RETL %eax'
34 ...
0 # RUN: not llc -march=x86-64 -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s
1
2 --- |
3
4 define i32 @test(i32 %a) #0 {
5 entry:
6 %b = alloca i32
7 store i32 %a, i32* %b
8 %c = load i32, i32* %b
9 ret i32 %c
10 }
11
12 attributes #0 = { "no-frame-pointer-elim"="false" }
13
14 ...
15 ---
16 name: test
17 frameInfo:
18 maxAlignment: 4
19 fixedStack:
20 # CHECK: [[@LINE+1]]:63: unknown key 'isAliased'
21 - { id: 0, type: spill-slot, offset: 0, size: 4, isAliased: true }
22 stack:
23 - { id: 0, offset: -12, size: 4, alignment: 4 }
24 body:
25 - id: 0
26 name: entry
27 instructions:
28 - 'MOV32mr %rsp, 1, _, -4, _, %edi'
29 - '%eax = COPY %edi'
30 - 'RETQ %eax'
31 ...
0 # RUN: not llc -march=x86-64 -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s
1
2 --- |
3
4 define i32 @test(i32 %a) #0 {
5 entry:
6 %b = alloca i32
7 store i32 %a, i32* %b
8 %c = load i32, i32* %b
9 ret i32 %c
10 }
11
12 attributes #0 = { "no-frame-pointer-elim"="false" }
13
14 ...
15 ---
16 name: test
17 frameInfo:
18 maxAlignment: 4
19 fixedStack:
20 # CHECK: [[@LINE+1]]:65: unknown key 'isImmutable'
21 - { id: 0, type: spill-slot, offset: 0, size: 4, isImmutable: true }
22 stack:
23 - { id: 0, offset: -12, size: 4, alignment: 4 }
24 body:
25 - id: 0
26 name: entry
27 instructions:
28 - 'MOV32mr %rsp, 1, _, -4, _, %edi'
29 - '%eax = COPY %edi'
30 - 'RETQ %eax'
31 ...
0 # RUN: llc -march=x86-64 -start-after branch-folder -stop-after branch-folder -o /dev/null %s | FileCheck %s
1 # This test ensures that the MIR parser parses fixed stack objects correctly.
2
3 --- |
4
5 define i32 @test(i32 %a) #0 {
6 entry:
7 %b = alloca i32
8 store i32 %a, i32* %b
9 %c = load i32, i32* %b
10 ret i32 %c
11 }
12
13 attributes #0 = { "no-frame-pointer-elim"="false" }
14
15 ...
16 ---
17 name: test
18 frameInfo:
19 maxAlignment: 4
20 # CHECK: fixedStack:
21 # CHECK-NEXT: - { id: 0, type: spill-slot, offset: 0, size: 4, alignment: 4 }
22 fixedStack:
23 - { id: 0, type: spill-slot, offset: 0, size: 4, alignment: 4 }
24 stack:
25 - { id: 0, offset: -12, size: 4, alignment: 4 }
26 body:
27 - id: 0
28 name: entry
29 instructions:
30 - 'MOV32mr %rsp, 1, _, -4, _, %edi'
31 - '%eax = COPY %edi'
32 - 'RETQ %eax'
33 ...