diff options
author | Hal Finkel <hfinkel@anl.gov> | 2016-09-04 14:18:29 +0000 |
---|---|---|
committer | Hal Finkel <hfinkel@anl.gov> | 2016-09-04 14:18:29 +0000 |
commit | f0bc9db96e563e00883bb8ebcf902031e1ad6639 (patch) | |
tree | 9477da73a161587df6d47e39dcafdea6d9a61af1 | |
parent | 7e2a0dfa0cf37f54a2092c78e3f2e4143b61b3b2 (diff) | |
download | bcm5719-llvm-f0bc9db96e563e00883bb8ebcf902031e1ad6639.tar.gz bcm5719-llvm-f0bc9db96e563e00883bb8ebcf902031e1ad6639.zip |
[PowerPC] During branch relaxation, recompute padding offsets before each iteration
We used to compute the padding contributions to the block sizes during branch
relaxation only at the start of the transformation. As we perform branch
relaxation, we change the sizes of the blocks, and so the amount of inter-block
padding might change. Accordingly, we need to recompute the (alignment-based)
padding in between every iteration on our way toward the fixed point.
Unfortunately, I don't have a test case (and none was provided in the bug
report), and while this obviously seems needed, algorithmically, I don't have
any way of generating a small and/or non-fragile regression test.
llvm-svn: 280626
-rw-r--r-- | llvm/lib/Target/PowerPC/PPCBranchSelector.cpp | 46 |
1 files changed, 39 insertions, 7 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCBranchSelector.cpp b/llvm/lib/Target/PowerPC/PPCBranchSelector.cpp index fec0917b05b..962a7b8672e 100644 --- a/llvm/lib/Target/PowerPC/PPCBranchSelector.cpp +++ b/llvm/lib/Target/PowerPC/PPCBranchSelector.cpp @@ -41,8 +41,10 @@ namespace { initializePPCBSelPass(*PassRegistry::getPassRegistry()); } - /// BlockSizes - The sizes of the basic blocks in the function. - std::vector<unsigned> BlockSizes; + // The sizes of the basic blocks in the function (the first + // element of the pair); the second element of the pair is the amount of the + // size that is due to potential padding. + std::vector<std::pair<unsigned, unsigned>> BlockSizes; bool runOnMachineFunction(MachineFunction &Fn) override; @@ -102,7 +104,11 @@ bool PPCBSel::runOnMachineFunction(MachineFunction &Fn) { // alignment requirement. if (MBB->getNumber() > 0) { unsigned AlignExtra = GetAlignmentAdjustment(*MBB, FuncSize); - BlockSizes[MBB->getNumber()-1] += AlignExtra; + + auto &BS = BlockSizes[MBB->getNumber()-1]; + BS.first += AlignExtra; + BS.second = AlignExtra; + FuncSize += AlignExtra; } @@ -110,7 +116,7 @@ bool PPCBSel::runOnMachineFunction(MachineFunction &Fn) { for (MachineInstr &MI : *MBB) BlockSize += TII->getInstSizeInBytes(MI); - BlockSizes[MBB->getNumber()] = BlockSize; + BlockSizes[MBB->getNumber()].first = BlockSize; FuncSize += BlockSize; } @@ -169,14 +175,14 @@ bool PPCBSel::runOnMachineFunction(MachineFunction &Fn) { BranchSize = MBBStartOffset; for (unsigned i = Dest->getNumber(), e = MBB.getNumber(); i != e; ++i) - BranchSize += BlockSizes[i]; + BranchSize += BlockSizes[i].first; } else { // Otherwise, add the size of the blocks between this block and the // dest to the number of bytes left in this block. BranchSize = -MBBStartOffset; for (unsigned i = MBB.getNumber(), e = Dest->getNumber(); i != e; ++i) - BranchSize += BlockSizes[i]; + BranchSize += BlockSizes[i].first; } // If this branch is in range, ignore it. @@ -226,12 +232,38 @@ bool PPCBSel::runOnMachineFunction(MachineFunction &Fn) { // Remember that this instruction is 8-bytes, increase the size of the // block by 4, remember to iterate. - BlockSizes[MBB.getNumber()] += 4; + BlockSizes[MBB.getNumber()].first += 4; MBBStartOffset += 8; ++NumExpanded; MadeChange = true; } } + + if (MadeChange) { + // If we're going to iterate again, make sure we've updated our + // padding-based contributions to the block sizes. + unsigned Offset = 0; + for (MachineFunction::iterator MFI = Fn.begin(), E = Fn.end(); MFI != E; + ++MFI) { + MachineBasicBlock *MBB = &*MFI; + + if (MBB->getNumber() > 0) { + auto &BS = BlockSizes[MBB->getNumber()-1]; + BS.first -= BS.second; + Offset -= BS.second; + + unsigned AlignExtra = GetAlignmentAdjustment(*MBB, Offset); + + BS.first += AlignExtra; + BS.second = AlignExtra; + + Offset += AlignExtra; + } + + Offset += BlockSizes[MBB->getNumber()].first; + } + } + EverMadeChange |= MadeChange; } |