@@ -27,6 +27,21 @@ class MachineBasicBlock;
27
27
class BitVector ;
28
28
class AllocaInst ;
29
29
30
+ using SaveRestorePoints = DenseMap<MachineBasicBlock *, std::vector<Register>>;
31
+
32
+ class CalleeSavedInfoPerBB {
33
+ DenseMap<MachineBasicBlock *, std::vector<CalleeSavedInfo>> Map;
34
+
35
+ public:
36
+ std::vector<CalleeSavedInfo> get (MachineBasicBlock *MBB) const {
37
+ return Map.lookup (MBB);
38
+ }
39
+
40
+ void set (DenseMap<MachineBasicBlock *, std::vector<CalleeSavedInfo>> CSI) {
41
+ Map = std::move (CSI);
42
+ }
43
+ };
44
+
30
45
// / The CalleeSavedInfo class tracks the information need to locate where a
31
46
// / callee saved register is in the current frame.
32
47
// / Callee saved reg can also be saved to a different register rather than
@@ -37,6 +52,8 @@ class CalleeSavedInfo {
37
52
int FrameIdx;
38
53
unsigned DstReg;
39
54
};
55
+ std::vector<MachineBasicBlock *> SpilledIn;
56
+ std::vector<MachineBasicBlock *> RestoredIn;
40
57
// / Flag indicating whether the register is actually restored in the epilog.
41
58
// / In most cases, if a register is saved, it is also restored. There are
42
59
// / some situations, though, when this is not the case. For example, the
@@ -58,9 +75,9 @@ class CalleeSavedInfo {
58
75
explicit CalleeSavedInfo (unsigned R, int FI = 0 ) : Reg(R), FrameIdx(FI) {}
59
76
60
77
// Accessors.
61
- Register getReg () const { return Reg; }
62
- int getFrameIdx () const { return FrameIdx; }
63
- unsigned getDstReg () const { return DstReg; }
78
+ Register getReg () const { return Reg; }
79
+ int getFrameIdx () const { return FrameIdx; }
80
+ unsigned getDstReg () const { return DstReg; }
64
81
void setFrameIdx (int FI) {
65
82
FrameIdx = FI;
66
83
SpilledToReg = false ;
@@ -72,6 +89,16 @@ class CalleeSavedInfo {
72
89
bool isRestored () const { return Restored; }
73
90
void setRestored (bool R) { Restored = R; }
74
91
bool isSpilledToReg () const { return SpilledToReg; }
92
+ ArrayRef<MachineBasicBlock *> spilledIn () const { return SpilledIn; }
93
+ ArrayRef<MachineBasicBlock *> restoredIn () const { return RestoredIn; }
94
+ void addSpilledIn (MachineBasicBlock *MBB) { SpilledIn.push_back (MBB); }
95
+ void addRestoredIn (MachineBasicBlock *MBB) { RestoredIn.push_back (MBB); }
96
+ void setSpilledIn (std::vector<MachineBasicBlock *> BBV) {
97
+ SpilledIn = std::move (BBV);
98
+ }
99
+ void setRestoredIn (std::vector<MachineBasicBlock *> BBV) {
100
+ RestoredIn = std::move (BBV);
101
+ }
75
102
};
76
103
77
104
// / The MachineFrameInfo class represents an abstract stack frame until
@@ -295,6 +322,10 @@ class MachineFrameInfo {
295
322
// / Has CSInfo been set yet?
296
323
bool CSIValid = false ;
297
324
325
+ CalleeSavedInfoPerBB CSInfoPerSave;
326
+
327
+ CalleeSavedInfoPerBB CSInfoPerRestore;
328
+
298
329
// / References to frame indices which are mapped
299
330
// / into the local frame allocation block. <FrameIdx, LocalOffset>
300
331
SmallVector<std::pair<int , int64_t >, 32 > LocalFrameObjects;
@@ -331,9 +362,16 @@ class MachineFrameInfo {
331
362
bool HasTailCall = false ;
332
363
333
364
// / Not null, if shrink-wrapping found a better place for the prologue.
334
- MachineBasicBlock *Save = nullptr ;
365
+ MachineBasicBlock *Prolog = nullptr ;
335
366
// / Not null, if shrink-wrapping found a better place for the epilogue.
336
- MachineBasicBlock *Restore = nullptr ;
367
+ MachineBasicBlock *Epilog = nullptr ;
368
+
369
+ // / Not empty, if shrink-wrapping found a better place for saving callee
370
+ // / saves.
371
+ SaveRestorePoints SavePoints;
372
+ // / Not empty, if shrink-wrapping found a better place for restoring callee
373
+ // / saves.
374
+ SaveRestorePoints RestorePoints;
337
375
338
376
// / Size of the UnsafeStack Frame
339
377
uint64_t UnsafeStackSize = 0 ;
@@ -809,21 +847,105 @@ class MachineFrameInfo {
809
847
// / \copydoc getCalleeSavedInfo()
810
848
std::vector<CalleeSavedInfo> &getCalleeSavedInfo () { return CSInfo; }
811
849
850
+ // / Returns callee saved info vector for provided save point in
851
+ // / the current function.
852
+ std::vector<CalleeSavedInfo> getCSInfoPerSave (MachineBasicBlock *MBB) const {
853
+ return CSInfoPerSave.get (MBB);
854
+ }
855
+
856
+ // / Returns callee saved info vector for provided restore point
857
+ // / in the current function.
858
+ std::vector<CalleeSavedInfo>
859
+ getCSInfoPerRestore (MachineBasicBlock *MBB) const {
860
+ return CSInfoPerRestore.get (MBB);
861
+ }
862
+
812
863
// / Used by prolog/epilog inserter to set the function's callee saved
813
864
// / information.
814
865
void setCalleeSavedInfo (std::vector<CalleeSavedInfo> CSI) {
815
866
CSInfo = std::move (CSI);
816
867
}
817
868
869
+ // / Used by prolog/epilog inserter to set the function's callee saved
870
+ // / information for particular save point.
871
+ void setCSInfoPerSave (
872
+ DenseMap<MachineBasicBlock *, std::vector<CalleeSavedInfo>> CSI) {
873
+ CSInfoPerSave.set (CSI);
874
+ }
875
+
876
+ // / Used by prolog/epilog inserter to set the function's callee saved
877
+ // / information for particular restore point.
878
+ void setCSInfoPerRestore (
879
+ DenseMap<MachineBasicBlock *, std::vector<CalleeSavedInfo>> CSI) {
880
+ CSInfoPerRestore.set (CSI);
881
+ }
882
+
818
883
// / Has the callee saved info been calculated yet?
819
884
bool isCalleeSavedInfoValid () const { return CSIValid; }
820
885
821
886
void setCalleeSavedInfoValid (bool v) { CSIValid = v; }
822
887
823
- MachineBasicBlock *getSavePoint () const { return Save; }
824
- void setSavePoint (MachineBasicBlock *NewSave) { Save = NewSave; }
825
- MachineBasicBlock *getRestorePoint () const { return Restore; }
826
- void setRestorePoint (MachineBasicBlock *NewRestore) { Restore = NewRestore; }
888
+ const SaveRestorePoints &getRestorePoints () const { return RestorePoints; }
889
+
890
+ const SaveRestorePoints &getSavePoints () const { return SavePoints; }
891
+
892
+ std::pair<MachineBasicBlock *, std::vector<Register>>
893
+ getRestorePoint (MachineBasicBlock *MBB) const {
894
+ if (auto It = RestorePoints.find (MBB); It != RestorePoints.end ())
895
+ return *It;
896
+
897
+ std::vector<Register> Regs = {};
898
+ return std::make_pair (nullptr , Regs);
899
+ }
900
+
901
+ std::pair<MachineBasicBlock *, std::vector<Register>>
902
+ getSavePoint (MachineBasicBlock *MBB) const {
903
+ if (auto It = SavePoints.find (MBB); It != SavePoints.end ())
904
+ return *It;
905
+
906
+ std::vector<Register> Regs = {};
907
+ return std::make_pair (nullptr , Regs);
908
+ }
909
+
910
+ void setSavePoints (SaveRestorePoints NewSavePoints) {
911
+ SavePoints = std::move (NewSavePoints);
912
+ }
913
+
914
+ void setRestorePoints (SaveRestorePoints NewRestorePoints) {
915
+ RestorePoints = std::move (NewRestorePoints);
916
+ }
917
+
918
+ void setSavePoint (MachineBasicBlock *MBB, std::vector<Register> &Regs) {
919
+ if (SavePoints.contains (MBB))
920
+ SavePoints[MBB] = Regs;
921
+ else
922
+ SavePoints.insert (std::make_pair (MBB, Regs));
923
+ }
924
+
925
+ static const SaveRestorePoints constructSaveRestorePoints (
926
+ const SaveRestorePoints &SRP,
927
+ const DenseMap<MachineBasicBlock *, MachineBasicBlock *> &BBMap) {
928
+ SaveRestorePoints Pts{};
929
+ for (auto &Src : SRP) {
930
+ Pts.insert (std::make_pair (BBMap.find (Src.first )->second , Src.second ));
931
+ }
932
+ return Pts;
933
+ }
934
+
935
+ void setRestorePoint (MachineBasicBlock *MBB, std::vector<Register> &Regs) {
936
+ if (RestorePoints.contains (MBB))
937
+ RestorePoints[MBB] = Regs;
938
+ else
939
+ RestorePoints.insert (std::make_pair (MBB, Regs));
940
+ }
941
+
942
+ MachineBasicBlock *getProlog () const { return Prolog; }
943
+ void setProlog (MachineBasicBlock *BB) { Prolog = BB; }
944
+ MachineBasicBlock *getEpilog () const { return Epilog; }
945
+ void setEpilog (MachineBasicBlock *BB) { Epilog = BB; }
946
+
947
+ void clearSavePoints () { SavePoints.clear (); }
948
+ void clearRestorePoints () { RestorePoints.clear (); }
827
949
828
950
uint64_t getUnsafeStackSize () const { return UnsafeStackSize; }
829
951
void setUnsafeStackSize (uint64_t Size) { UnsafeStackSize = Size; }
0 commit comments