Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit dee03ee

Browse files
committed
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
1 parent b53f724 commit dee03ee

File tree

6 files changed

+101
-7
lines changed

6 files changed

+101
-7
lines changed

include/llvm/CodeGen/MIRYamlMapping.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,8 @@ template <> struct MappingTraits<MachineBasicBlock> {
129129
///
130130
/// TODO: Determine isPreallocated flag by mapping between objects and local
131131
/// objects (Serialize local objects).
132-
/// TODO: Serialize variable sized objects.
133132
struct MachineStackObject {
134-
enum ObjectType { DefaultType, SpillSlot };
133+
enum ObjectType { DefaultType, SpillSlot, VariableSized };
135134
// TODO: Serialize LLVM alloca reference.
136135
unsigned ID;
137136
ObjectType Type = DefaultType;
@@ -144,6 +143,7 @@ template <> struct ScalarEnumerationTraits<MachineStackObject::ObjectType> {
144143
static void enumeration(yaml::IO &IO, MachineStackObject::ObjectType &Type) {
145144
IO.enumCase(Type, "default", MachineStackObject::DefaultType);
146145
IO.enumCase(Type, "spill-slot", MachineStackObject::SpillSlot);
146+
IO.enumCase(Type, "variable-sized", MachineStackObject::VariableSized);
147147
}
148148
};
149149

@@ -154,7 +154,8 @@ template <> struct MappingTraits<MachineStackObject> {
154154
"type", Object.Type,
155155
MachineStackObject::DefaultType); // Don't print the default type.
156156
YamlIO.mapOptional("offset", Object.Offset);
157-
YamlIO.mapRequired("size", Object.Size);
157+
if (Object.Type != MachineStackObject::VariableSized)
158+
YamlIO.mapRequired("size", Object.Size);
158159
YamlIO.mapOptional("alignment", Object.Alignment);
159160
}
160161

include/llvm/CodeGen/MachineFrameInfo.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,14 @@ class MachineFrameInfo {
541541
return Objects[ObjectIdx+NumFixedObjects].Size == ~0ULL;
542542
}
543543

544+
/// Returns true if the specified index corresponds to a variable sized
545+
/// object.
546+
bool isVariableSizedObjectIndex(int ObjectIdx) const {
547+
assert(unsigned(ObjectIdx + NumFixedObjects) < Objects.size() &&
548+
"Invalid Object Idx!");
549+
return Objects[ObjectIdx + NumFixedObjects].Size == 0;
550+
}
551+
544552
/// Create a new statically sized stack object, returning
545553
/// a nonnegative identifier to represent it.
546554
int CreateStackObject(uint64_t Size, unsigned Alignment, bool isSS,

lib/CodeGen/MIRParser/MIRParser.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,14 @@ bool MIRParserImpl::initializeFrameInfo(MachineFrameInfo &MFI,
391391

392392
// Initialize the ordinary frame objects.
393393
for (const auto &Object : YamlMF.StackObjects) {
394-
int ObjectIdx = MFI.CreateStackObject(
395-
Object.Size, Object.Alignment,
396-
Object.Type == yaml::MachineStackObject::SpillSlot);
394+
int ObjectIdx;
395+
if (Object.Type == yaml::MachineStackObject::VariableSized)
396+
ObjectIdx =
397+
MFI.CreateVariableSizedObject(Object.Alignment, /*Alloca=*/nullptr);
398+
else
399+
ObjectIdx = MFI.CreateStackObject(
400+
Object.Size, Object.Alignment,
401+
Object.Type == yaml::MachineStackObject::SpillSlot);
397402
MFI.setObjectOffset(ObjectIdx, Object.Offset);
398403
// TODO: Store the mapping between object IDs and object indices to parse
399404
// stack object references correctly.

lib/CodeGen/MIRPrinter.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ void MIRPrinter::convertStackObjects(yaml::MachineFunction &MF,
188188
YamlObject.ID = ID++;
189189
YamlObject.Type = MFI.isSpillSlotObjectIndex(I)
190190
? yaml::MachineStackObject::SpillSlot
191-
: yaml::MachineStackObject::DefaultType;
191+
: MFI.isVariableSizedObjectIndex(I)
192+
? yaml::MachineStackObject::VariableSized
193+
: yaml::MachineStackObject::DefaultType;
192194
YamlObject.Offset = MFI.getObjectOffset(I);
193195
YamlObject.Size = MFI.getObjectSize(I);
194196
YamlObject.Alignment = MFI.getObjectAlignment(I);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# RUN: not llc -march=x86-64 -start-after branch-folder -stop-after branch-folder -o /dev/null %s 2>&1 | FileCheck %s
2+
--- |
3+
4+
define i32 @test(i32 %a) {
5+
entry:
6+
%b = alloca i32
7+
%x = alloca i64
8+
%y = alloca i32, i32 %a
9+
store i32 %a, i32* %b
10+
store i64 2, i64* %x
11+
%c = load i32, i32* %b
12+
ret i32 %c
13+
}
14+
15+
...
16+
---
17+
name: test
18+
frameInfo:
19+
stackSize: 24
20+
offsetAdjustment: -16
21+
maxAlignment: 8
22+
adjustsStack: true
23+
stack:
24+
- { id: 0, offset: -20, size: 4, alignment: 4 }
25+
- { id: 1, offset: -32, size: 8, alignment: 8 }
26+
# CHECK: [[@LINE+1]]:55: unknown key 'size'
27+
- { id: 2, type: variable-sized, offset: -32, size: 42, alignment: 1 }
28+
body:
29+
- id: 0
30+
name: entry
31+
instructions:
32+
- 'MOV32mr %rsp, 1, _, -4, _, %edi'
33+
- 'MOV64mi32 %rsp, 1, _, -16, _, 2'
34+
- '%eax = MOV32rm %rsp, 1, _, -4, _'
35+
- 'RETQ %eax'
36+
...
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# RUN: llc -march=x86-64 -start-after branch-folder -stop-after branch-folder -o /dev/null %s | FileCheck %s
2+
# This test ensures that the MIR parser parses variable sized stack objects
3+
# correctly.
4+
5+
--- |
6+
7+
define i32 @test(i32 %a) {
8+
entry:
9+
%b = alloca i32
10+
%x = alloca i64
11+
%y = alloca i32, i32 %a
12+
store i32 %a, i32* %b
13+
store i64 2, i64* %x
14+
%c = load i32, i32* %b
15+
ret i32 %c
16+
}
17+
18+
...
19+
---
20+
name: test
21+
frameInfo:
22+
stackSize: 24
23+
offsetAdjustment: -16
24+
maxAlignment: 8
25+
adjustsStack: true
26+
# CHECK: stack:
27+
# CHECK-NEXT: - { id: 0, offset: -20, size: 4, alignment: 4 }
28+
# CHECK-NEXT: - { id: 1, offset: -32, size: 8, alignment: 8 }
29+
# CHECK-NEXT: - { id: 2, type: variable-sized, offset: -32, alignment: 1 }
30+
stack:
31+
- { id: 0, offset: -20, size: 4, alignment: 4 }
32+
- { id: 1, offset: -32, size: 8, alignment: 8 }
33+
- { id: 2, type: variable-sized, offset: -32, alignment: 1 }
34+
body:
35+
- id: 0
36+
name: entry
37+
instructions:
38+
- 'MOV32mr %rsp, 1, _, -4, _, %edi'
39+
- 'MOV64mi32 %rsp, 1, _, -16, _, 2'
40+
- '%eax = MOV32rm %rsp, 1, _, -4, _'
41+
- 'RETQ %eax'
42+
...

0 commit comments

Comments
 (0)