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,23 @@ 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
+ }
123
+
106
124
char LocalStackSlotPass::ID = 0 ;
107
125
108
126
char &llvm::LocalStackSlotAllocationID = LocalStackSlotPass::ID;
109
127
INITIALIZE_PASS (LocalStackSlotPass, DEBUG_TYPE,
110
128
" Local Stack Slot Allocation" , false , false )
111
129
112
- bool LocalStackSlotPass ::runOnMachineFunction(MachineFunction &MF) {
130
+ bool LocalStackSlotImpl ::runOnMachineFunction(MachineFunction &MF) {
113
131
MachineFrameInfo &MFI = MF.getFrameInfo ();
114
132
const TargetRegisterInfo *TRI = MF.getSubtarget ().getRegisterInfo ();
115
133
unsigned LocalObjectCount = MFI.getObjectIndexEnd ();
@@ -139,7 +157,7 @@ bool LocalStackSlotPass::runOnMachineFunction(MachineFunction &MF) {
139
157
}
140
158
141
159
// / AdjustStackOffset - Helper function used to adjust the stack frame offset.
142
- void LocalStackSlotPass ::AdjustStackOffset (MachineFrameInfo &MFI, int FrameIdx,
160
+ void LocalStackSlotImpl ::AdjustStackOffset (MachineFrameInfo &MFI, int FrameIdx,
143
161
int64_t &Offset, bool StackGrowsDown,
144
162
Align &MaxAlign) {
145
163
// If the stack grows down, add the object size to find the lowest address.
@@ -171,7 +189,7 @@ void LocalStackSlotPass::AdjustStackOffset(MachineFrameInfo &MFI, int FrameIdx,
171
189
172
190
// / AssignProtectedObjSet - Helper function to assign large stack objects (i.e.,
173
191
// / those required to be close to the Stack Protector) to stack offsets.
174
- void LocalStackSlotPass ::AssignProtectedObjSet (
192
+ void LocalStackSlotImpl ::AssignProtectedObjSet (
175
193
const StackObjSet &UnassignedObjs, SmallSet<int , 16 > &ProtectedObjs,
176
194
MachineFrameInfo &MFI, bool StackGrowsDown, int64_t &Offset,
177
195
Align &MaxAlign) {
@@ -183,7 +201,7 @@ void LocalStackSlotPass::AssignProtectedObjSet(
183
201
184
202
// / calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
185
203
// / abstract stack objects.
186
- void LocalStackSlotPass ::calculateFrameObjectOffsets (MachineFunction &Fn) {
204
+ void LocalStackSlotImpl ::calculateFrameObjectOffsets (MachineFunction &Fn) {
187
205
// Loop over all of the stack objects, assigning sequential addresses...
188
206
MachineFrameInfo &MFI = Fn.getFrameInfo ();
189
207
const TargetFrameLowering &TFI = *Fn.getSubtarget ().getFrameLowering ();
@@ -281,7 +299,7 @@ lookupCandidateBaseReg(unsigned BaseReg,
281
299
return TRI->isFrameOffsetLegal (&MI, BaseReg, Offset);
282
300
}
283
301
284
- bool LocalStackSlotPass ::insertFrameReferenceRegisters (MachineFunction &Fn) {
302
+ bool LocalStackSlotImpl ::insertFrameReferenceRegisters (MachineFunction &Fn) {
285
303
// Scan the function's instructions looking for frame index references.
286
304
// For each, ask the target if it wants a virtual base register for it
287
305
// based on what we can tell it about where the local will end up in the
0 commit comments