[llvm] r280626 - [PowerPC] During branch relaxation, recompute padding offsets before each iteration
Hal Finkel via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 4 07:18:29 PDT 2016
Author: hfinkel
Date: Sun Sep 4 09:18:29 2016
New Revision: 280626
URL: http://llvm.org/viewvc/llvm-project?rev=280626&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/Target/PowerPC/PPCBranchSelector.cpp
Modified: llvm/trunk/lib/Target/PowerPC/PPCBranchSelector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCBranchSelector.cpp?rev=280626&r1=280625&r2=280626&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCBranchSelector.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCBranchSelector.cpp Sun Sep 4 09:18:29 2016
@@ -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(Machi
// 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(Machi
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(Machi
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(Machi
// 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;
}
More information about the llvm-commits
mailing list