|
17 | 17 |
|
18 | 18 | #include "llvm/ADT/ArrayRef.h" |
19 | 19 | #include "llvm/ADT/BitVector.h" |
20 | | -#include "llvm/ADT/DepthFirstIterator.h" |
21 | 20 | #include "llvm/ADT/STLExtras.h" |
22 | 21 | #include "llvm/ADT/SetVector.h" |
23 | 22 | #include "llvm/ADT/SmallPtrSet.h" |
@@ -381,13 +380,18 @@ void PEI::calculateCallFrameInfo(MachineFunction &MF) { |
381 | 380 | MFI.setAdjustsStack(AdjustsStack); |
382 | 381 | MFI.setMaxCallFrameSize(MaxCallFrameSize); |
383 | 382 |
|
384 | | - for (MachineBasicBlock::iterator I : FrameSDOps) { |
| 383 | + if (TFI->canSimplifyCallFramePseudos(MF)) { |
385 | 384 | // If call frames are not being included as part of the stack frame, and |
386 | 385 | // the target doesn't indicate otherwise, remove the call frame pseudos |
387 | 386 | // here. The sub/add sp instruction pairs are still inserted, but we don't |
388 | 387 | // need to track the SP adjustment for frame index elimination. |
389 | | - if (TFI->canSimplifyCallFramePseudos(MF)) |
| 388 | + for (MachineBasicBlock::iterator I : FrameSDOps) |
390 | 389 | TFI->eliminateCallFramePseudoInstr(MF, *I->getParent(), I); |
| 390 | + |
| 391 | + // We can't track the call frame size after call frame pseudos have been |
| 392 | + // eliminated. Set it to zero everywhere to keep MachineVerifier happy. |
| 393 | + for (MachineBasicBlock &MBB : MF) |
| 394 | + MBB.setCallFrameSize(0); |
391 | 395 | } |
392 | 396 | } |
393 | 397 |
|
@@ -1341,34 +1345,16 @@ void PEI::replaceFrameIndices(MachineFunction &MF) { |
1341 | 1345 | FrameIndexEliminationScavenging = (RS && !FrameIndexVirtualScavenging) || |
1342 | 1346 | TRI->requiresFrameIndexReplacementScavenging(MF); |
1343 | 1347 |
|
1344 | | - // Store SPAdj at exit of a basic block. |
1345 | | - SmallVector<int, 8> SPState; |
1346 | | - SPState.resize(MF.getNumBlockIDs()); |
1347 | | - df_iterator_default_set<MachineBasicBlock*> Reachable; |
1348 | | - |
1349 | | - // Iterate over the reachable blocks in DFS order. |
1350 | | - for (auto DFI = df_ext_begin(&MF, Reachable), DFE = df_ext_end(&MF, Reachable); |
1351 | | - DFI != DFE; ++DFI) { |
1352 | | - int SPAdj = 0; |
1353 | | - // Check the exit state of the DFS stack predecessor. |
1354 | | - if (DFI.getPathLength() >= 2) { |
1355 | | - MachineBasicBlock *StackPred = DFI.getPath(DFI.getPathLength() - 2); |
1356 | | - assert(Reachable.count(StackPred) && |
1357 | | - "DFS stack predecessor is already visited.\n"); |
1358 | | - SPAdj = SPState[StackPred->getNumber()]; |
1359 | | - } |
1360 | | - MachineBasicBlock *BB = *DFI; |
1361 | | - replaceFrameIndices(BB, MF, SPAdj); |
1362 | | - SPState[BB->getNumber()] = SPAdj; |
1363 | | - } |
| 1348 | + for (auto &MBB : MF) { |
| 1349 | + int SPAdj = TFI.alignSPAdjust(MBB.getCallFrameSize()); |
| 1350 | + if (TFI.getStackGrowthDirection() == TargetFrameLowering::StackGrowsUp) |
| 1351 | + SPAdj = -SPAdj; |
1364 | 1352 |
|
1365 | | - // Handle the unreachable blocks. |
1366 | | - for (auto &BB : MF) { |
1367 | | - if (Reachable.count(&BB)) |
1368 | | - // Already handled in DFS traversal. |
1369 | | - continue; |
1370 | | - int SPAdj = 0; |
1371 | | - replaceFrameIndices(&BB, MF, SPAdj); |
| 1353 | + replaceFrameIndices(&MBB, MF, SPAdj); |
| 1354 | + |
| 1355 | + // We can't track the call frame size after call frame pseudos have been |
| 1356 | + // eliminated. Set it to zero everywhere to keep MachineVerifier happy. |
| 1357 | + MBB.setCallFrameSize(0); |
1372 | 1358 | } |
1373 | 1359 | } |
1374 | 1360 |
|
|
0 commit comments