llvm.org GIT mirror llvm / dee03ee
MIR Serialization: Serialize the variable sized stack objects. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@242095 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Lorenz 5 years ago
6 changed file(s) with 101 addition(s) and 7 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 objects.
132131 struct MachineStackObject {
133 enum ObjectType { DefaultType, SpillSlot };
132 enum ObjectType { DefaultType, SpillSlot, VariableSized };
134133 // TODO: Serialize LLVM alloca reference.
135134 unsigned ID;
136135 ObjectType Type = DefaultType;
143142 static void enumeration(yaml::IO &IO, MachineStackObject::ObjectType &Type) {
144143 IO.enumCase(Type, "default", MachineStackObject::DefaultType);
145144 IO.enumCase(Type, "spill-slot", MachineStackObject::SpillSlot);
145 IO.enumCase(Type, "variable-sized", MachineStackObject::VariableSized);
146146 }
147147 };
148148
153153 "type", Object.Type,
154154 MachineStackObject::DefaultType); // Don't print the default type.
155155 YamlIO.mapOptional("offset", Object.Offset);
156 YamlIO.mapRequired("size", Object.Size);
156 if (Object.Type != MachineStackObject::VariableSized)
157 YamlIO.mapRequired("size", Object.Size);
157158 YamlIO.mapOptional("alignment", Object.Alignment);
158159 }
159160
540540 return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
541541 }
542542
543 /// Returns true if the specified index corresponds to a variable sized
544 /// object.
545 bool isVariableSizedObjectIndex(int ObjectIdx) const {
546 assert(unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
547 "Invalid Object Idx!");
548 return Objects[ObjectIdx + NumFixedObjects].Size == 0;
549 }
550
543551 /// Create a new statically sized stack object, returning
544552 /// a nonnegative identifier to represent it.
545553 int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS,
390390
391391 // Initialize the ordinary frame objects.
392392 for (const auto &Object : YamlMF.StackObjects) {
393 int ObjectIdx = MFI.CreateStackObject(
394 Object.Size, Object.Alignment,
395 Object.Type == yaml::MachineStackObject::SpillSlot);
393 int ObjectIdx;
394 if (Object.Type == yaml::MachineStackObject::VariableSized)
395 ObjectIdx =
396 MFI.CreateVariableSizedObject(Object.Alignment, /*Alloca=*/nullptr);
397 else
398 ObjectIdx = MFI.CreateStackObject(
399 Object.Size, Object.Alignment,
400 Object.Type == yaml::MachineStackObject::SpillSlot);
396401 MFI.setObjectOffset(ObjectIdx, Object.Offset);
397402 // TODO: Store the mapping between object IDs and object indices to parse
398403 // stack object references correctly.
187187 YamlObject.ID = ID++;
188188 YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
189189 ? yaml::MachineStackObject::SpillSlot
190 : yaml::MachineStackObject::DefaultType;
190 : MFI.isVariableSizedObjectIndex(I)
191 ? yaml::MachineStackObject::VariableSized
192 : yaml::MachineStackObject::DefaultType;
191193 YamlObject.Offset = MFI.getObjectOffset(I);
192194 YamlObject.Size = MFI.getObjectSize(I);
193195 YamlObject.Alignment = MFI.getObjectAlignment(I);
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 define i32 @test(i32 %a) {
4 entry:
5 %b = alloca i32
6 %x = alloca i64
7 %y = alloca i32, i32 %a
8 store i32 %a, i32* %b
9 store i64 2, i64* %x
10 %c = load i32, i32* %b
11 ret i32 %c
12 }
13
14 ...
15 ---
16 name: test
17 frameInfo:
18 stackSize: 24
19 offsetAdjustment: -16
20 maxAlignment: 8
21 adjustsStack: true
22 stack:
23 - { id: 0, offset: -20, size: 4, alignment: 4 }
24 - { id: 1, offset: -32, size: 8, alignment: 8 }
25 # CHECK: [[@LINE+1]]:55: unknown key 'size'
26 - { id: 2, type: variable-sized, offset: -32, size: 42, alignment: 1 }
27 body:
28 - id: 0
29 name: entry
30 instructions:
31 - 'MOV32mr %rsp, 1, _, -4, _, %edi'
32 - 'MOV64mi32 %rsp, 1, _, -16, _, 2'
33 - '%eax = MOV32rm %rsp, 1, _, -4, _'
34 - 'RETQ %eax'
35 ...
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 variable sized stack objects
2 # correctly.
3
4 --- |
5
6 define i32 @test(i32 %a) {
7 entry:
8 %b = alloca i32
9 %x = alloca i64
10 %y = alloca i32, i32 %a
11 store i32 %a, i32* %b
12 store i64 2, i64* %x
13 %c = load i32, i32* %b
14 ret i32 %c
15 }
16
17 ...
18 ---
19 name: test
20 frameInfo:
21 stackSize: 24
22 offsetAdjustment: -16
23 maxAlignment: 8
24 adjustsStack: true
25 # CHECK: stack:
26 # CHECK-NEXT: - { id: 0, offset: -20, size: 4, alignment: 4 }
27 # CHECK-NEXT: - { id: 1, offset: -32, size: 8, alignment: 8 }
28 # CHECK-NEXT: - { id: 2, type: variable-sized, offset: -32, alignment: 1 }
29 stack:
30 - { id: 0, offset: -20, size: 4, alignment: 4 }
31 - { id: 1, offset: -32, size: 8, alignment: 8 }
32 - { id: 2, type: variable-sized, offset: -32, alignment: 1 }
33 body:
34 - id: 0
35 name: entry
36 instructions:
37 - 'MOV32mr %rsp, 1, _, -4, _, %edi'
38 - 'MOV64mi32 %rsp, 1, _, -16, _, 2'
39 - '%eax = MOV32rm %rsp, 1, _, -4, _'
40 - 'RETQ %eax'
41 ...