Skip to content

Commit 5bc9d8b

Browse files
committed
[llvm] support multiple save/restore points in mir
Currently mir supports only one save and one restore point specification: ``` savePoint: '%bb.1' restorePoint: '%bb.2' ``` This patch provide possibility to have multiple save and multiple restore points in mir: ``` savePoints: - point: '%bb.1' restorePoints: - point: '%bb.2' ```
1 parent 2230ab1 commit 5bc9d8b

File tree

337 files changed

+1341
-1265
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

337 files changed

+1341
-1265
lines changed

llvm/include/llvm/CodeGen/MIRYamlMapping.h

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,20 @@ LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::MachineJumpTable::Entry)
610610
namespace llvm {
611611
namespace yaml {
612612

613+
struct SRPEntry {
614+
StringValue Point;
615+
616+
bool operator==(const SRPEntry &Other) const { return Point == Other.Point; }
617+
};
618+
619+
using SaveRestorePoints = std::vector<SRPEntry>;
620+
621+
template <> struct MappingTraits<SRPEntry> {
622+
static void mapping(IO &YamlIO, SRPEntry &Entry) {
623+
YamlIO.mapRequired("point", Entry.Point);
624+
}
625+
};
626+
613627
template <> struct MappingTraits<MachineJumpTable> {
614628
static void mapping(IO &YamlIO, MachineJumpTable &JT) {
615629
YamlIO.mapRequired("kind", JT.Kind);
@@ -618,6 +632,14 @@ template <> struct MappingTraits<MachineJumpTable> {
618632
}
619633
};
620634

635+
} // namespace yaml
636+
} // namespace llvm
637+
638+
LLVM_YAML_IS_SEQUENCE_VECTOR(llvm::yaml::SRPEntry)
639+
640+
namespace llvm {
641+
namespace yaml {
642+
621643
/// Serializable representation of MachineFrameInfo.
622644
///
623645
/// Doesn't serialize attributes like 'StackAlignment', 'IsStackRealignable' and
@@ -645,8 +667,8 @@ struct MachineFrameInfo {
645667
bool HasTailCall = false;
646668
bool IsCalleeSavedInfoValid = false;
647669
unsigned LocalFrameSize = 0;
648-
StringValue SavePoint;
649-
StringValue RestorePoint;
670+
SaveRestorePoints SavePoints;
671+
SaveRestorePoints RestorePoints;
650672

651673
bool operator==(const MachineFrameInfo &Other) const {
652674
return IsFrameAddressTaken == Other.IsFrameAddressTaken &&
@@ -667,7 +689,8 @@ struct MachineFrameInfo {
667689
HasMustTailInVarArgFunc == Other.HasMustTailInVarArgFunc &&
668690
HasTailCall == Other.HasTailCall &&
669691
LocalFrameSize == Other.LocalFrameSize &&
670-
SavePoint == Other.SavePoint && RestorePoint == Other.RestorePoint &&
692+
SavePoints == Other.SavePoints &&
693+
RestorePoints == Other.RestorePoints &&
671694
IsCalleeSavedInfoValid == Other.IsCalleeSavedInfoValid;
672695
}
673696
};
@@ -699,10 +722,12 @@ template <> struct MappingTraits<MachineFrameInfo> {
699722
YamlIO.mapOptional("isCalleeSavedInfoValid", MFI.IsCalleeSavedInfoValid,
700723
false);
701724
YamlIO.mapOptional("localFrameSize", MFI.LocalFrameSize, (unsigned)0);
702-
YamlIO.mapOptional("savePoint", MFI.SavePoint,
703-
StringValue()); // Don't print it out when it's empty.
704-
YamlIO.mapOptional("restorePoint", MFI.RestorePoint,
705-
StringValue()); // Don't print it out when it's empty.
725+
YamlIO.mapOptional(
726+
"savePoints", MFI.SavePoints,
727+
SaveRestorePoints()); // Don't print it out when it's empty.
728+
YamlIO.mapOptional(
729+
"restorePoints", MFI.RestorePoints,
730+
SaveRestorePoints()); // Don't print it out when it's empty.
706731
}
707732
};
708733

llvm/lib/CodeGen/MIRParser/MIRParser.cpp

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ class MIRParserImpl {
124124
bool initializeFrameInfo(PerFunctionMIParsingState &PFS,
125125
const yaml::MachineFunction &YamlMF);
126126

127+
bool initializeSaveRestorePoints(PerFunctionMIParsingState &PFS,
128+
const yaml::SaveRestorePoints &YamlSRP,
129+
bool IsSavePoints);
130+
127131
bool initializeCallSiteInfo(PerFunctionMIParsingState &PFS,
128132
const yaml::MachineFunction &YamlMF);
129133

@@ -832,18 +836,9 @@ bool MIRParserImpl::initializeFrameInfo(PerFunctionMIParsingState &PFS,
832836
MFI.setHasTailCall(YamlMFI.HasTailCall);
833837
MFI.setCalleeSavedInfoValid(YamlMFI.IsCalleeSavedInfoValid);
834838
MFI.setLocalFrameSize(YamlMFI.LocalFrameSize);
835-
if (!YamlMFI.SavePoint.Value.empty()) {
836-
MachineBasicBlock *MBB = nullptr;
837-
if (parseMBBReference(PFS, MBB, YamlMFI.SavePoint))
838-
return true;
839-
MFI.setSavePoint(MBB);
840-
}
841-
if (!YamlMFI.RestorePoint.Value.empty()) {
842-
MachineBasicBlock *MBB = nullptr;
843-
if (parseMBBReference(PFS, MBB, YamlMFI.RestorePoint))
844-
return true;
845-
MFI.setRestorePoint(MBB);
846-
}
839+
initializeSaveRestorePoints(PFS, YamlMFI.SavePoints, true /*IsSavePoints*/);
840+
initializeSaveRestorePoints(PFS, YamlMFI.RestorePoints,
841+
false /*IsSavePoints*/);
847842

848843
std::vector<CalleeSavedInfo> CSIInfo;
849844
// Initialize the fixed frame objects.
@@ -1058,8 +1053,28 @@ bool MIRParserImpl::initializeConstantPool(PerFunctionMIParsingState &PFS,
10581053
return false;
10591054
}
10601055

1061-
bool MIRParserImpl::initializeJumpTableInfo(PerFunctionMIParsingState &PFS,
1062-
const yaml::MachineJumpTable &YamlJTI) {
1056+
bool MIRParserImpl::initializeSaveRestorePoints(
1057+
PerFunctionMIParsingState &PFS, const yaml::SaveRestorePoints &YamlSRP,
1058+
bool IsSavePoints) {
1059+
MachineFunction &MF = PFS.MF;
1060+
MachineFrameInfo &MFI = MF.getFrameInfo();
1061+
1062+
if (!YamlSRP.empty()) {
1063+
const auto &Entry = YamlSRP.front();
1064+
const auto &MBBSource = Entry.Point;
1065+
MachineBasicBlock *MBB = nullptr;
1066+
if (parseMBBReference(PFS, MBB, MBBSource.Value))
1067+
return true;
1068+
if (IsSavePoints)
1069+
MFI.setSavePoint(MBB);
1070+
else
1071+
MFI.setRestorePoint(MBB);
1072+
}
1073+
return false;
1074+
}
1075+
1076+
bool MIRParserImpl::initializeJumpTableInfo(
1077+
PerFunctionMIParsingState &PFS, const yaml::MachineJumpTable &YamlJTI) {
10631078
MachineJumpTableInfo *JTI = PFS.MF.getOrCreateJumpTableInfo(YamlJTI.Kind);
10641079
for (const auto &Entry : YamlJTI.Entries) {
10651080
std::vector<MachineBasicBlock *> Blocks;

llvm/lib/CodeGen/MIRPrinter.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class MIRPrinter {
118118
const TargetRegisterInfo *TRI);
119119
void convert(ModuleSlotTracker &MST, yaml::MachineFrameInfo &YamlMFI,
120120
const MachineFrameInfo &MFI);
121+
void convert(ModuleSlotTracker &MST, yaml::SaveRestorePoints &YamlSRP,
122+
MachineBasicBlock *SaveRestorePoint);
121123
void convert(yaml::MachineFunction &MF,
122124
const MachineConstantPool &ConstantPool);
123125
void convert(ModuleSlotTracker &MST, yaml::MachineJumpTable &YamlJTI,
@@ -392,14 +394,10 @@ void MIRPrinter::convert(ModuleSlotTracker &MST,
392394
YamlMFI.HasTailCall = MFI.hasTailCall();
393395
YamlMFI.IsCalleeSavedInfoValid = MFI.isCalleeSavedInfoValid();
394396
YamlMFI.LocalFrameSize = MFI.getLocalFrameSize();
395-
if (MFI.getSavePoint()) {
396-
raw_string_ostream StrOS(YamlMFI.SavePoint.Value);
397-
StrOS << printMBBReference(*MFI.getSavePoint());
398-
}
399-
if (MFI.getRestorePoint()) {
400-
raw_string_ostream StrOS(YamlMFI.RestorePoint.Value);
401-
StrOS << printMBBReference(*MFI.getRestorePoint());
402-
}
397+
if (MFI.getSavePoint())
398+
convert(MST, YamlMFI.SavePoints, MFI.getSavePoint());
399+
if (MFI.getRestorePoint())
400+
convert(MST, YamlMFI.RestorePoints, MFI.getRestorePoint());
403401
}
404402

405403
void MIRPrinter::convertEntryValueObjects(yaml::MachineFunction &YMF,
@@ -618,6 +616,18 @@ void MIRPrinter::convert(yaml::MachineFunction &MF,
618616
}
619617
}
620618

619+
void MIRPrinter::convert(ModuleSlotTracker &MST,
620+
yaml::SaveRestorePoints &YamlSRP,
621+
MachineBasicBlock *SRP) {
622+
std::string Str;
623+
yaml::SRPEntry Entry;
624+
raw_string_ostream StrOS(Str);
625+
StrOS << printMBBReference(*SRP);
626+
Entry.Point = StrOS.str();
627+
Str.clear();
628+
YamlSRP.push_back(Entry);
629+
}
630+
621631
void MIRPrinter::convert(ModuleSlotTracker &MST,
622632
yaml::MachineJumpTable &YamlJTI,
623633
const MachineJumpTableInfo &JTI) {

llvm/test/CodeGen/AArch64/GlobalISel/store-merging-debug.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ frameInfo:
8686
hasMustTailInVarArgFunc: false
8787
hasTailCall: false
8888
localFrameSize: 0
89-
savePoint: ''
90-
restorePoint: ''
89+
savePoints: []
90+
restorePoints: []
9191
fixedStack: []
9292
stack: []
9393
callSites: []

llvm/test/CodeGen/AArch64/aarch64-ldst-no-premature-sp-pop.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ frameInfo:
5959
hasVAStart: false
6060
hasMustTailInVarArgFunc: false
6161
localFrameSize: 16
62-
savePoint: ''
63-
restorePoint: ''
62+
savePoints: []
63+
restorePoints: []
6464
fixedStack: []
6565
stack:
6666
- { id: 0, type: default, offset: -16, size: 16,

llvm/test/CodeGen/AArch64/aarch64-mov-debug-locs.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ frameInfo:
157157
hasVAStart: false
158158
hasMustTailInVarArgFunc: false
159159
localFrameSize: 0
160-
savePoint: ''
161-
restorePoint: ''
160+
savePoints: []
161+
restorePoints: []
162162
fixedStack: []
163163
stack:
164164
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,

llvm/test/CodeGen/AArch64/aarch64st1.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ frameInfo:
5858
hasMustTailInVarArgFunc: false
5959
hasTailCall: false
6060
localFrameSize: 0
61-
savePoint: ''
62-
restorePoint: ''
61+
savePoints: []
62+
restorePoints: []
6363
fixedStack: []
6464
stack:
6565
- { id: 0, name: '', type: default, offset: 0, size: 4, alignment: 4,

llvm/test/CodeGen/AArch64/cfi-fixup-multi-block-prologue.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ frameInfo:
8080
hasMustTailInVarArgFunc: false
8181
hasTailCall: false
8282
localFrameSize: 30000
83-
savePoint: ''
84-
restorePoint: ''
83+
savePoints: []
84+
restorePoints: []
8585
fixedStack: []
8686
stack:
8787
- { id: 0, name: p, type: default, offset: -30016, size: 30000, alignment: 1,

llvm/test/CodeGen/AArch64/cfi-fixup-multi-section.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ frameInfo:
4747
hasMustTailInVarArgFunc: false
4848
hasTailCall: false
4949
localFrameSize: 0
50-
savePoint: ''
51-
restorePoint: ''
50+
savePoints: []
51+
restorePoints: []
5252
fixedStack: []
5353
stack:
5454
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,

llvm/test/CodeGen/AArch64/cfi-fixup.mir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ frameInfo:
6565
hasMustTailInVarArgFunc: false
6666
hasTailCall: false
6767
localFrameSize: 0
68-
savePoint: ''
69-
restorePoint: ''
68+
savePoints: []
69+
restorePoints: []
7070
fixedStack: []
7171
stack:
7272
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -248,8 +248,8 @@ frameInfo:
248248
hasMustTailInVarArgFunc: false
249249
hasTailCall: false
250250
localFrameSize: 0
251-
savePoint: ''
252-
restorePoint: ''
251+
savePoints: []
252+
restorePoints: []
253253
fixedStack: []
254254
stack:
255255
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,
@@ -403,8 +403,8 @@ frameInfo:
403403
hasMustTailInVarArgFunc: false
404404
hasTailCall: false
405405
localFrameSize: 0
406-
savePoint: ''
407-
restorePoint: ''
406+
savePoints: []
407+
restorePoints: []
408408
fixedStack: []
409409
stack:
410410
- { id: 0, name: '', type: spill-slot, offset: -16, size: 8, alignment: 16,

llvm/test/CodeGen/AArch64/dont-shrink-wrap-stack-mayloadorstore.mir

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,23 @@
66
; RUN: llc -x=mir -simplify-mir -run-pass=shrink-wrap -o - %s | FileCheck %s
77
; CHECK: name: compiler_pop_stack
88
; CHECK: frameInfo:
9-
; CHECK: savePoint: '%bb.1'
10-
; CHECK: restorePoint: '%bb.7'
9+
; CHECK: savePoints:
10+
; CHECK-NEXT: - point: '%bb.1'
11+
; CHECK: restorePoints:
12+
; CHECK-NEXT: - point: '%bb.7'
1113
; CHECK: name: compiler_pop_stack_no_memoperands
1214
; CHECK: frameInfo:
13-
; CHECK: savePoint: '%bb.1'
14-
; CHECK: restorePoint: '%bb.7'
15+
; CHECK: savePoints:
16+
; CHECK-NEXT: - point: '%bb.1'
17+
; CHECK: restorePoints:
18+
; CHECK-NEXT: - point: '%bb.7'
1519
; CHECK: name: f
1620
; CHECK: frameInfo:
17-
; CHECK: savePoint: '%bb.2'
18-
; CHECK-NEXT: restorePoint: '%bb.4'
19-
; CHECK-NEXT: stack:
21+
; CHECK: savePoints:
22+
; CHECK-NEXT: - point: '%bb.2'
23+
; CHECK: restorePoints:
24+
; CHECK-NEXT: - point: '%bb.4'
25+
; CHECK: stack:
2026

2127
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
2228
target triple = "aarch64"

llvm/test/CodeGen/AArch64/early-ifcvt-regclass-mismatch.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ frameInfo:
105105
hasVAStart: false
106106
hasMustTailInVarArgFunc: false
107107
localFrameSize: 0
108-
savePoint: ''
109-
restorePoint: ''
108+
savePoints: []
109+
restorePoints: []
110110
fixedStack: []
111111
stack: []
112112
callSites: []

llvm/test/CodeGen/AArch64/emit_fneg_with_non_register_operand.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ frameInfo:
7575
hasMustTailInVarArgFunc: false
7676
hasTailCall: true
7777
localFrameSize: 0
78-
savePoint: ''
79-
restorePoint: ''
78+
savePoints: []
79+
restorePoints: []
8080
fixedStack: []
8181
stack: []
8282
entry_values: []

llvm/test/CodeGen/AArch64/irg-nomem.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ frameInfo:
4747
hasVAStart: false
4848
hasMustTailInVarArgFunc: false
4949
localFrameSize: 0
50-
savePoint: ''
51-
restorePoint: ''
50+
savePoints: []
51+
restorePoints: []
5252
fixedStack: []
5353
stack: []
5454
callSites: []

llvm/test/CodeGen/AArch64/jump-table-duplicate.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ frameInfo:
9292
hasVAStart: false
9393
hasMustTailInVarArgFunc: false
9494
localFrameSize: 0
95-
savePoint: ''
96-
restorePoint: ''
95+
savePoints: []
96+
restorePoints: []
9797
fixedStack: []
9898
stack:
9999
- { id: 0, name: '', type: spill-slot, offset: -8, size: 8, alignment: 8,

llvm/test/CodeGen/AArch64/ldst-nopreidx-sp-redzone.mir

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ frameInfo:
103103
hasVAStart: false
104104
hasMustTailInVarArgFunc: false
105105
localFrameSize: 480
106-
savePoint: ''
107-
restorePoint: ''
106+
savePoints: []
107+
restorePoints: []
108108
fixedStack: []
109109
stack:
110110
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -216,8 +216,8 @@ frameInfo:
216216
hasVAStart: false
217217
hasMustTailInVarArgFunc: false
218218
localFrameSize: 480
219-
savePoint: ''
220-
restorePoint: ''
219+
savePoints: []
220+
restorePoints: []
221221
fixedStack: []
222222
stack:
223223
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,
@@ -327,8 +327,8 @@ frameInfo:
327327
hasVAStart: false
328328
hasMustTailInVarArgFunc: false
329329
localFrameSize: 480
330-
savePoint: ''
331-
restorePoint: ''
330+
savePoints: []
331+
restorePoints: []
332332
fixedStack: []
333333
stack:
334334
- { id: 0, name: StackGuardSlot, type: default, offset: -40, size: 8,

0 commit comments

Comments
 (0)