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
@@ -628,7 +653,7 @@ static void insertCSRRestores(MachineBasicBlock &RestoreBlock,
628
653
}
629
654
}
630
655
631
- void PEI ::spillCalleeSavedRegs (MachineFunction &MF) {
656
+ void PEIImpl ::spillCalleeSavedRegs (MachineFunction &MF) {
632
657
// We can't list this requirement in getRequiredProperties because some
633
658
// targets (WebAssembly) use virtual registers past this point, and the pass
634
659
// pipeline is set up without giving the passes a chance to look at the
@@ -820,7 +845,7 @@ static void AssignProtectedObjSet(const StackObjSet &UnassignedObjs,
820
845
821
846
// / calculateFrameObjectOffsets - Calculate actual frame offsets for all of the
822
847
// / abstract stack objects.
823
- void PEI ::calculateFrameObjectOffsets (MachineFunction &MF) {
848
+ void PEIImpl ::calculateFrameObjectOffsets (MachineFunction &MF) {
824
849
const TargetFrameLowering &TFI = *MF.getSubtarget ().getFrameLowering ();
825
850
826
851
bool StackGrowsDown =
@@ -1135,7 +1160,7 @@ void PEI::calculateFrameObjectOffsets(MachineFunction &MF) {
1135
1160
// / insertPrologEpilogCode - Scan the function for modified callee saved
1136
1161
// / registers, insert spill code for these callee saved registers, then add
1137
1162
// / prolog and epilog code to the function.
1138
- void PEI ::insertPrologEpilogCode (MachineFunction &MF) {
1163
+ void PEIImpl ::insertPrologEpilogCode (MachineFunction &MF) {
1139
1164
const TargetFrameLowering &TFI = *MF.getSubtarget ().getFrameLowering ();
1140
1165
1141
1166
// Add prologue to the function...
@@ -1172,7 +1197,7 @@ void PEI::insertPrologEpilogCode(MachineFunction &MF) {
1172
1197
}
1173
1198
1174
1199
// / insertZeroCallUsedRegs - Zero out call used registers.
1175
- void PEI ::insertZeroCallUsedRegs (MachineFunction &MF) {
1200
+ void PEIImpl ::insertZeroCallUsedRegs (MachineFunction &MF) {
1176
1201
const Function &F = MF.getFunction ();
1177
1202
1178
1203
if (!F.hasFnAttribute (" zero-call-used-regs" ))
@@ -1315,7 +1340,7 @@ void PEI::insertZeroCallUsedRegs(MachineFunction &MF) {
1315
1340
1316
1341
// / Replace all FrameIndex operands with physical register references and actual
1317
1342
// / offsets.
1318
- void PEI ::replaceFrameIndicesBackward (MachineFunction &MF) {
1343
+ void PEIImpl ::replaceFrameIndicesBackward (MachineFunction &MF) {
1319
1344
const TargetFrameLowering &TFI = *MF.getSubtarget ().getFrameLowering ();
1320
1345
1321
1346
for (auto &MBB : MF) {
@@ -1343,7 +1368,7 @@ void PEI::replaceFrameIndicesBackward(MachineFunction &MF) {
1343
1368
1344
1369
// / replaceFrameIndices - Replace all MO_FrameIndex operands with physical
1345
1370
// / register references and actual offsets.
1346
- void PEI ::replaceFrameIndices (MachineFunction &MF) {
1371
+ void PEIImpl ::replaceFrameIndices (MachineFunction &MF) {
1347
1372
const TargetFrameLowering &TFI = *MF.getSubtarget ().getFrameLowering ();
1348
1373
1349
1374
for (auto &MBB : MF) {
@@ -1359,8 +1384,8 @@ void PEI::replaceFrameIndices(MachineFunction &MF) {
1359
1384
}
1360
1385
}
1361
1386
1362
- bool PEI ::replaceFrameIndexDebugInstr (MachineFunction &MF, MachineInstr &MI,
1363
- unsigned OpIdx, int SPAdj) {
1387
+ bool PEIImpl ::replaceFrameIndexDebugInstr (MachineFunction &MF, MachineInstr &MI,
1388
+ unsigned OpIdx, int SPAdj) {
1364
1389
const TargetFrameLowering *TFI = MF.getSubtarget ().getFrameLowering ();
1365
1390
const TargetRegisterInfo &TRI = *MF.getSubtarget ().getRegisterInfo ();
1366
1391
if (MI.isDebugValue ()) {
@@ -1441,8 +1466,8 @@ bool PEI::replaceFrameIndexDebugInstr(MachineFunction &MF, MachineInstr &MI,
1441
1466
return false ;
1442
1467
}
1443
1468
1444
- void PEI ::replaceFrameIndicesBackward (MachineBasicBlock *BB,
1445
- MachineFunction &MF, int &SPAdj) {
1469
+ void PEIImpl ::replaceFrameIndicesBackward (MachineBasicBlock *BB,
1470
+ MachineFunction &MF, int &SPAdj) {
1446
1471
assert (MF.getSubtarget ().getRegisterInfo () &&
1447
1472
" getRegisterInfo() must be implemented!" );
1448
1473
@@ -1486,8 +1511,8 @@ void PEI::replaceFrameIndicesBackward(MachineBasicBlock *BB,
1486
1511
}
1487
1512
}
1488
1513
1489
- void PEI ::replaceFrameIndices (MachineBasicBlock *BB, MachineFunction &MF,
1490
- int &SPAdj) {
1514
+ void PEIImpl ::replaceFrameIndices (MachineBasicBlock *BB, MachineFunction &MF,
1515
+ int &SPAdj) {
1491
1516
assert (MF.getSubtarget ().getRegisterInfo () &&
1492
1517
" getRegisterInfo() must be implemented!" );
1493
1518
const TargetInstrInfo &TII = *MF.getSubtarget ().getInstrInfo ();
0 commit comments