@@ -228,9 +228,8 @@ bool PEI::runOnMachineFunction(MachineFunction &MF) {
228
228
FrameIndexVirtualScavenging = TRI->requiresFrameIndexScavenging (MF);
229
229
ORE = &getAnalysis<MachineOptimizationRemarkEmitterPass>().getORE ();
230
230
231
- // Calculate the MaxCallFrameSize and AdjustsStack variables for the
232
- // function's frame information. Also eliminates call frame pseudo
233
- // instructions.
231
+ // Calculate the MaxCallFrameSize value for the function's frame
232
+ // information. Also eliminates call frame pseudo instructions.
234
233
calculateCallFrameInfo (MF);
235
234
236
235
// Determine placement of CSR spill/restore code and prolog/epilog code:
@@ -350,17 +349,13 @@ bool PEI::runOnMachineFunction(MachineFunction &MF) {
350
349
return true ;
351
350
}
352
351
353
- // / Calculate the MaxCallFrameSize and AdjustsStack
354
- // / variables for the function's frame information and eliminate call frame
355
- // / pseudo instructions.
352
+ // / Calculate the MaxCallFrameSize variables for the function's frame
353
+ // / information and eliminate call frame pseudo instructions.
356
354
void PEI::calculateCallFrameInfo (MachineFunction &MF) {
357
355
const TargetInstrInfo &TII = *MF.getSubtarget ().getInstrInfo ();
358
356
const TargetFrameLowering *TFI = MF.getSubtarget ().getFrameLowering ();
359
357
MachineFrameInfo &MFI = MF.getFrameInfo ();
360
358
361
- unsigned MaxCallFrameSize = 0 ;
362
- bool AdjustsStack = MFI.adjustsStack ();
363
-
364
359
// Get the function call frame set-up and tear-down instruction opcode
365
360
unsigned FrameSetupOpcode = TII.getCallFrameSetupOpcode ();
366
361
unsigned FrameDestroyOpcode = TII.getCallFrameDestroyOpcode ();
@@ -370,26 +365,14 @@ void PEI::calculateCallFrameInfo(MachineFunction &MF) {
370
365
if (FrameSetupOpcode == ~0u && FrameDestroyOpcode == ~0u )
371
366
return ;
372
367
368
+ // (Re-)Compute the MaxCallFrameSize with some sanity checks.
369
+ bool WasComputed = MFI.isMaxCallFrameSizeComputed ();
370
+ unsigned MaxCFSIn = MFI.getMaxCallFrameSize ();
371
+ bool AdjStackIn = MFI.adjustsStack ();
373
372
std::vector<MachineBasicBlock::iterator> FrameSDOps;
374
- for (MachineBasicBlock &BB : MF)
375
- for (MachineBasicBlock::iterator I = BB.begin (); I != BB.end (); ++I)
376
- if (TII.isFrameInstr (*I)) {
377
- unsigned Size = TII.getFrameSize (*I);
378
- if (Size > MaxCallFrameSize) MaxCallFrameSize = Size ;
379
- AdjustsStack = true ;
380
- FrameSDOps.push_back (I);
381
- } else if (I->isInlineAsm ()) {
382
- // Some inline asm's need a stack frame, as indicated by operand 1.
383
- unsigned ExtraInfo = I->getOperand (InlineAsm::MIOp_ExtraInfo).getImm ();
384
- if (ExtraInfo & InlineAsm::Extra_IsAlignStack)
385
- AdjustsStack = true ;
386
- }
387
-
388
- assert (!MFI.isMaxCallFrameSizeComputed () ||
389
- (MFI.getMaxCallFrameSize () >= MaxCallFrameSize &&
390
- !(AdjustsStack && !MFI.adjustsStack ())));
391
- MFI.setAdjustsStack (AdjustsStack);
392
- MFI.setMaxCallFrameSize (MaxCallFrameSize);
373
+ MFI.computeMaxCallFrameSize (MF, &FrameSDOps);
374
+ assert (!WasComputed || (MaxCFSIn >= MFI.getMaxCallFrameSize () &&
375
+ !(!AdjStackIn && MFI.adjustsStack ())));
393
376
394
377
if (TFI->canSimplifyCallFramePseudos (MF)) {
395
378
// If call frames are not being included as part of the stack frame, and
0 commit comments