36
36
#include " llvm/CodeGen/MachineOperand.h"
37
37
#include " llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
38
38
#include " llvm/CodeGen/MachineRegisterInfo.h"
39
+ #include " llvm/CodeGen/PEI.h"
39
40
#include " llvm/CodeGen/RegisterScavenging.h"
40
41
#include " llvm/CodeGen/TargetFrameLowering.h"
41
42
#include " llvm/CodeGen/TargetInstrInfo.h"
@@ -77,21 +78,7 @@ STATISTIC(NumFuncSeen, "Number of functions seen in PEI");
77
78
78
79
namespace {
79
80
80
- class PEI : public MachineFunctionPass {
81
- public:
82
- static char ID;
83
-
84
- PEI () : MachineFunctionPass(ID) {
85
- initializePEIPass (*PassRegistry::getPassRegistry ());
86
- }
87
-
88
- void getAnalysisUsage (AnalysisUsage &AU) const override ;
89
-
90
- // / runOnMachineFunction - Insert prolog/epilog code and replace abstract
91
- // / frame indexes with appropriate references.
92
- bool runOnMachineFunction (MachineFunction &MF) override ;
93
-
94
- private:
81
+ class PEIImpl {
95
82
RegScavenger *RS = nullptr ;
96
83
97
84
// MinCSFrameIndex, MaxCSFrameIndex - Keeps the range of callee saved
@@ -137,31 +124,50 @@ class PEI : public MachineFunctionPass {
137
124
138
125
void insertPrologEpilogCode (MachineFunction &MF);
139
126
void insertZeroCallUsedRegs (MachineFunction &MF);
127
+
128
+ public:
129
+ PEIImpl (MachineOptimizationRemarkEmitter *ORE) : ORE(ORE) {}
130
+ bool run (MachineFunction &MF);
131
+ };
132
+
133
+ class PEILegacy : public MachineFunctionPass {
134
+ public:
135
+ static char ID;
136
+
137
+ PEILegacy () : MachineFunctionPass(ID) {
138
+ initializePEILegacyPass (*PassRegistry::getPassRegistry ());
139
+ }
140
+
141
+ void getAnalysisUsage (AnalysisUsage &AU) const override ;
142
+
143
+ // / runOnMachineFunction - Insert prolog/epilog code and replace abstract
144
+ // / frame indexes with appropriate references.
145
+ bool runOnMachineFunction (MachineFunction &MF) override ;
140
146
};
141
147
142
148
} // end anonymous namespace
143
149
144
- char PEI ::ID = 0 ;
150
+ char PEILegacy ::ID = 0 ;
145
151
146
- char &llvm::PrologEpilogCodeInserterID = PEI ::ID;
152
+ char &llvm::PrologEpilogCodeInserterID = PEILegacy ::ID;
147
153
148
- INITIALIZE_PASS_BEGIN (PEI , DEBUG_TYPE, " Prologue/Epilogue Insertion" , false ,
149
- false )
154
+ INITIALIZE_PASS_BEGIN (PEILegacy , DEBUG_TYPE, " Prologue/Epilogue Insertion" ,
155
+ false , false )
150
156
INITIALIZE_PASS_DEPENDENCY(MachineLoopInfoWrapperPass)
151
157
INITIALIZE_PASS_DEPENDENCY(MachineDominatorTreeWrapperPass)
152
158
INITIALIZE_PASS_DEPENDENCY(MachineOptimizationRemarkEmitterPass)
153
- INITIALIZE_PASS_END(PEI , DEBUG_TYPE,
159
+ INITIALIZE_PASS_END(PEILegacy , DEBUG_TYPE,
154
160
" Prologue/Epilogue Insertion & Frame Finalization" , false ,
155
161
false )
156
162
157
163
MachineFunctionPass *llvm::createPrologEpilogInserterPass() {
158
- return new PEI ();
164
+ return new PEILegacy ();
159
165
}
160
166
161
167
STATISTIC (NumBytesStackSpace,
162
168
" Number of bytes used for stack in all functions" );
163
169
164
- void PEI ::getAnalysisUsage (AnalysisUsage &AU) const {
170
+ void PEILegacy ::getAnalysisUsage (AnalysisUsage &AU) const {
165
171
AU.setPreservesCFG ();
166
172
AU.addPreserved <MachineLoopInfoWrapperPass>();
167
173
AU.addPreserved <MachineDominatorTreeWrapperPass>();
@@ -213,17 +219,14 @@ static void stashEntryDbgValues(MachineBasicBlock &MBB,
213
219
MI->removeFromParent ();
214
220
}
215
221
216
- // / runOnMachineFunction - Insert prolog/epilog code and replace abstract
217
- // / frame indexes with appropriate references.
218
- bool PEI::runOnMachineFunction (MachineFunction &MF) {
222
+ bool PEIImpl::run (MachineFunction &MF) {
219
223
NumFuncSeen++;
220
224
const Function &F = MF.getFunction ();
221
225
const TargetRegisterInfo *TRI = MF.getSubtarget ().getRegisterInfo ();
222
226
const TargetFrameLowering *TFI = MF.getSubtarget ().getFrameLowering ();
223
227
224
228
RS = TRI->requiresRegisterScavenging (MF) ? new RegScavenger () : nullptr ;
225
229
FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging (MF);
226
- ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE ();
227
230
228
231
// Spill frame pointer and/or base pointer registers if they are clobbered.
229
232
// It is placed before call frame instruction elimination so it will not mess
@@ -354,9 +357,31 @@ bool PEI::runOnMachineFunction(MachineFunction &MF) {
354
357
return true ;
355
358
}
356
359
360
+ // / runOnMachineFunction - Insert prolog/epilog code and replace abstract
361
+ // / frame indexes with appropriate references.
362
+ bool PEILegacy::runOnMachineFunction (MachineFunction &MF) {
363
+ MachineOptimizationRemarkEmitter *ORE =
364
+ &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE ();
365
+ return PEIImpl (ORE).run (MF);
366
+ }
367
+
368
+ PreservedAnalyses
369
+ PrologEpilogInserterPass::run (MachineFunction &MF,
370
+ MachineFunctionAnalysisManager &MFAM) {
371
+ MachineOptimizationRemarkEmitter &ORE =
372
+ MFAM.getResult <MachineOptimizationRemarkEmitterAnalysis>(MF);
373
+ if (!PEIImpl (&ORE).run (MF))
374
+ return PreservedAnalyses::all ();
375
+
376
+ return getMachineFunctionPassPreservedAnalyses ()
377
+ .preserveSet <CFGAnalyses>()
378
+ .preserve <MachineDominatorTreeAnalysis>()
379
+ .preserve <MachineLoopAnalysis>();
380
+ }
381
+
357
382
// / Calculate the MaxCallFrameSize variable for the function's frame
358
383
// / information and eliminate call frame pseudo instructions.
359
- void PEI ::calculateCallFrameInfo (MachineFunction &MF) {
384
+ void PEIImpl ::calculateCallFrameInfo (MachineFunction &MF) {
360
385
const TargetInstrInfo &TII = *MF.getSubtarget ().getInstrInfo ();
361
386
const TargetFrameLowering *TFI = MF.getSubtarget ().getFrameLowering ();
362
387
MachineFrameInfo &MFI = MF.getFrameInfo ();
@@ -397,7 +422,7 @@ void PEI::calculateCallFrameInfo(MachineFunction &MF) {
397
422
398
423
// / Compute the sets of entry and return blocks for saving and restoring
399
424
// / callee-saved registers, and placing prolog and epilog code.
400
- void PEI ::calculateSaveRestoreBlocks (MachineFunction &MF) {
425
+ void PEIImpl ::calculateSaveRestoreBlocks (MachineFunction &MF) {
401
426
const MachineFrameInfo &MFI = MF.getFrameInfo ();
402
427
403
428
// Even when we do not change any CSR, we still want to insert the
@@ -651,7 +676,7 @@ static void insertCSRRestores(MachineBasicBlock &RestoreBlock,
651
676
}
652
677
}
653
678
654
- void PEI ::spillCalleeSavedRegs (MachineFunction &MF) {
679
+ void PEIImpl ::spillCalleeSavedRegs (MachineFunction &MF) {
655
680
// We can't list this requirement in getRequiredProperties because some
656
681
// targets (WebAssembly) use virtual registers past this point, and the pass
657
682
// pipeline is set up without giving the passes a chance to look at the
@@ -843,7 +868,7 @@ static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs,
843
868
844
869
// / calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
845
870
// / abstract stack objects.
846
- void PEI ::calculateFrameObjectOffsets (MachineFunction &MF) {
871
+ void PEIImpl ::calculateFrameObjectOffsets (MachineFunction &MF) {
847
872
const TargetFrameLowering &TFI = *MF.getSubtarget ().getFrameLowering ();
848
873
849
874
bool StackGrowsDown =
@@ -1158,7 +1183,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &MF) {
1158
1183
// / insertPrologEpilogCode - Scan the function for modified callee saved
1159
1184
// / registers, insert spill code for these callee saved registers, then add
1160
1185
// / prolog and epilog code to the function.
1161
- void PEI ::insertPrologEpilogCode (MachineFunction &MF) {
1186
+ void PEIImpl ::insertPrologEpilogCode (MachineFunction &MF) {
1162
1187
const TargetFrameLowering &TFI = *MF.getSubtarget ().getFrameLowering ();
1163
1188
1164
1189
// Add prologue to the function...
@@ -1195,7 +1220,7 @@ void PEI::insertPrologEpilogCode(MachineFunction &MF) {
1195
1220
}
1196
1221
1197
1222
// / insertZeroCallUsedRegs - Zero out call used registers.
1198
- void PEI ::insertZeroCallUsedRegs (MachineFunction &MF) {
1223
+ void PEIImpl ::insertZeroCallUsedRegs (MachineFunction &MF) {
1199
1224
const Function &F = MF.getFunction ();
1200
1225
1201
1226
if (!F.hasFnAttribute (" zero-call-used-regs" ))
@@ -1338,7 +1363,7 @@ void PEI::insertZeroCallUsedRegs(MachineFunction &MF) {
1338
1363
1339
1364
// / Replace all FrameIndex operands with physical register references and actual
1340
1365
// / offsets.
1341
- void PEI ::replaceFrameIndicesBackward (MachineFunction &MF) {
1366
+ void PEIImpl ::replaceFrameIndicesBackward (MachineFunction &MF) {
1342
1367
const TargetFrameLowering &TFI = *MF.getSubtarget ().getFrameLowering ();
1343
1368
1344
1369
for (auto &MBB : MF) {
@@ -1366,7 +1391,7 @@ void PEI::replaceFrameIndicesBackward(MachineFunction &MF) {
1366
1391
1367
1392
// / replaceFrameIndices - Replace all MO_FrameIndex operands with physical
1368
1393
// / register references and actual offsets.
1369
- void PEI ::replaceFrameIndices (MachineFunction &MF) {
1394
+ void PEIImpl ::replaceFrameIndices (MachineFunction &MF) {
1370
1395
const TargetFrameLowering &TFI = *MF.getSubtarget ().getFrameLowering ();
1371
1396
1372
1397
for (auto &MBB : MF) {
@@ -1382,8 +1407,8 @@ void PEI::replaceFrameIndices(MachineFunction &MF) {
1382
1407
}
1383
1408
}
1384
1409
1385
- bool PEI ::replaceFrameIndexDebugInstr (MachineFunction &MF, MachineInstr &MI,
1386
- unsigned OpIdx, int SPAdj) {
1410
+ bool PEIImpl ::replaceFrameIndexDebugInstr (MachineFunction &MF, MachineInstr &MI,
1411
+ unsigned OpIdx, int SPAdj) {
1387
1412
const TargetFrameLowering *TFI = MF.getSubtarget ().getFrameLowering ();
1388
1413
const TargetRegisterInfo &TRI = *MF.getSubtarget ().getRegisterInfo ();
1389
1414
if (MI.isDebugValue ()) {
@@ -1464,8 +1489,8 @@ bool PEI::replaceFrameIndexDebugInstr(MachineFunction &MF, MachineInstr &MI,
1464
1489
return false ;
1465
1490
}
1466
1491
1467
- void PEI ::replaceFrameIndicesBackward (MachineBasicBlock *BB,
1468
- MachineFunction &MF, int &SPAdj) {
1492
+ void PEIImpl ::replaceFrameIndicesBackward (MachineBasicBlock *BB,
1493
+ MachineFunction &MF, int &SPAdj) {
1469
1494
assert (MF.getSubtarget ().getRegisterInfo () &&
1470
1495
" getRegisterInfo() must be implemented!" );
1471
1496
@@ -1509,8 +1534,8 @@ void PEI::replaceFrameIndicesBackward(MachineBasicBlock *BB,
1509
1534
}
1510
1535
}
1511
1536
1512
- void PEI ::replaceFrameIndices (MachineBasicBlock *BB, MachineFunction &MF,
1513
- int &SPAdj) {
1537
+ void PEIImpl ::replaceFrameIndices (MachineBasicBlock *BB, MachineFunction &MF,
1538
+ int &SPAdj) {
1514
1539
assert (MF.getSubtarget ().getRegisterInfo () &&
1515
1540
" getRegisterInfo() must be implemented!" );
1516
1541
const TargetInstrInfo &TII = *MF.getSubtarget ().getInstrInfo ();
0 commit comments