13
13
//
14
14
// ===----------------------------------------------------------------------===//
15
15
16
+ #include " llvm/CodeGen/LocalStackSlotAllocation.h"
16
17
#include " llvm/ADT/SetVector.h"
17
18
#include " llvm/ADT/SmallSet.h"
18
19
#include " llvm/ADT/SmallVector.h"
@@ -71,7 +72,7 @@ namespace {
71
72
int getFrameIndex () const { return FrameIdx; }
72
73
};
73
74
74
- class LocalStackSlotPass : public MachineFunctionPass {
75
+ class LocalStackSlotImpl {
75
76
SmallVector<int64_t , 16 > LocalOffsets;
76
77
77
78
// / StackObjSet - A set of stack object indexes
@@ -86,14 +87,21 @@ namespace {
86
87
void calculateFrameObjectOffsets (MachineFunction &Fn);
87
88
bool insertFrameReferenceRegisters (MachineFunction &Fn);
88
89
90
+ public:
91
+ bool runOnMachineFunction (MachineFunction &MF);
92
+ };
93
+
94
+ class LocalStackSlotPass : public MachineFunctionPass {
89
95
public:
90
96
static char ID; // Pass identification, replacement for typeid
91
97
92
98
explicit LocalStackSlotPass () : MachineFunctionPass(ID) {
93
99
initializeLocalStackSlotPassPass (*PassRegistry::getPassRegistry ());
94
100
}
95
101
96
- bool runOnMachineFunction (MachineFunction &MF) override ;
102
+ bool runOnMachineFunction (MachineFunction &MF) override {
103
+ return LocalStackSlotImpl ().runOnMachineFunction (MF);
104
+ }
97
105
98
106
void getAnalysisUsage (AnalysisUsage &AU) const override {
99
107
AU.setPreservesCFG ();
@@ -103,13 +111,24 @@ namespace {
103
111
104
112
} // end anonymous namespace
105
113
114
+ PreservedAnalyses
115
+ LocalStackSlotAllocationPass::run (MachineFunction &MF,
116
+ MachineFunctionAnalysisManager &) {
117
+ bool Changed = LocalStackSlotImpl ().runOnMachineFunction (MF);
118
+ if (!Changed)
119
+ return PreservedAnalyses::all ();
120
+ auto PA = getMachineFunctionPassPreservedAnalyses ();
121
+ PA.preserveSet <CFGAnalyses>();
122
+ return PA;
123
+ }
124
+
106
125
char LocalStackSlotPass::ID = 0 ;
107
126
108
127
char &llvm::LocalStackSlotAllocationID = LocalStackSlotPass::ID;
109
128
INITIALIZE_PASS (LocalStackSlotPass, DEBUG_TYPE,
110
129
" Local Stack Slot Allocation" , false , false )
111
130
112
- bool LocalStackSlotPass ::runOnMachineFunction(MachineFunction &MF) {
131
+ bool LocalStackSlotImpl ::runOnMachineFunction(MachineFunction &MF) {
113
132
MachineFrameInfo &MFI = MF.getFrameInfo ();
114
133
const TargetRegisterInfo *TRI = MF.getSubtarget ().getRegisterInfo ();
115
134
unsigned LocalObjectCount = MFI.getObjectIndexEnd ();
@@ -139,7 +158,7 @@ bool LocalStackSlotPass::runOnMachineFunction(MachineFunction &MF) {
139
158
}
140
159
141
160
// / AdjustStackOffset - Helper function used to adjust the stack frame offset.
142
- void LocalStackSlotPass ::AdjustStackOffset (MachineFrameInfo &MFI, int FrameIdx,
161
+ void LocalStackSlotImpl ::AdjustStackOffset (MachineFrameInfo &MFI, int FrameIdx,
143
162
int64_t &Offset, bool StackGrowsDown,
144
163
Align &MaxAlign) {
145
164
// If the stack grows down, add the object size to find the lowest address.
@@ -171,7 +190,7 @@ void LocalStackSlotPass::AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx,
171
190
172
191
// / AssignProtectedObjSet - Helper function to assign large stack objects (i.e.,
173
192
// / those required to be close to the Stack Protector) to stack offsets.
174
- void LocalStackSlotPass ::AssignProtectedObjSet (
193
+ void LocalStackSlotImpl ::AssignProtectedObjSet (
175
194
const StackObjSet &UnassignedObjs, SmallSet<int , 16 > &ProtectedObjs,
176
195
MachineFrameInfo &MFI, bool StackGrowsDown, int64_t &Offset,
177
196
Align &MaxAlign) {
@@ -183,7 +202,7 @@ void LocalStackSlotPass::AssignProtectedObjSet(
183
202
184
203
// / calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
185
204
// / abstract stack objects.
186
- void LocalStackSlotPass ::calculateFrameObjectOffsets (MachineFunction &Fn) {
205
+ void LocalStackSlotImpl ::calculateFrameObjectOffsets (MachineFunction &Fn) {
187
206
// Loop over all of the stack objects, assigning sequential addresses...
188
207
MachineFrameInfo &MFI = Fn.getFrameInfo ();
189
208
const TargetFrameLowering &TFI = *Fn.getSubtarget ().getFrameLowering ();
@@ -281,7 +300,7 @@ lookupCandidateBaseReg(unsigned BaseReg,
281
300
return TRI->isFrameOffsetLegal (&MI, BaseReg, Offset);
282
301
}
283
302
284
- bool LocalStackSlotPass ::insertFrameReferenceRegisters (MachineFunction &Fn) {
303
+ bool LocalStackSlotImpl ::insertFrameReferenceRegisters (MachineFunction &Fn) {
285
304
// Scan the function's instructions looking for frame index references.
286
305
// For each, ask the target if it wants a virtual base register for it
287
306
// based on what we can tell it about where the local will end up in the
0 commit comments