[llvm-branch-commits] [llvm-branch] r88936 - /llvm/branches/Apple/Leela/lib/Target/ARM/ARMConstantIslandPass.cpp
Jim Grosbach
grosbach at apple.com
Mon Nov 16 11:04:50 PST 2009
Author: grosbach
Date: Mon Nov 16 13:04:50 2009
New Revision: 88936
URL: http://llvm.org/viewvc/llvm-project?rev=88936&view=rev
Log:
merge 88933 88935
Modified:
llvm/branches/Apple/Leela/lib/Target/ARM/ARMConstantIslandPass.cpp
Modified: llvm/branches/Apple/Leela/lib/Target/ARM/ARMConstantIslandPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Leela/lib/Target/ARM/ARMConstantIslandPass.cpp?rev=88936&r1=88935&r2=88936&view=diff
==============================================================================
--- llvm/branches/Apple/Leela/lib/Target/ARM/ARMConstantIslandPass.cpp (original)
+++ llvm/branches/Apple/Leela/lib/Target/ARM/ARMConstantIslandPass.cpp Mon Nov 16 13:04:50 2009
@@ -281,8 +281,6 @@
JumpTableFunctionScan(MF);
MadeChange |= ReorderThumb2JumpTables(MF);
// Data is out of date, so clear it. It'll be re-computed later.
- BBSizes.clear();
- BBOffsets.clear();
T2JumpTables.clear();
// Blocks may have shifted around. Keep the numbering up to date.
MF.RenumberBlocks();
@@ -438,32 +436,14 @@
/// information about the sizes of each block and the locations of all
/// the jump tables.
void ARMConstantIslands::JumpTableFunctionScan(MachineFunction &MF) {
- unsigned Offset = 0;
for (MachineFunction::iterator MBBI = MF.begin(), E = MF.end();
MBBI != E; ++MBBI) {
MachineBasicBlock &MBB = *MBBI;
- unsigned MBBSize = 0;
for (MachineBasicBlock::iterator I = MBB.begin(), E = MBB.end();
- I != E; ++I) {
- // Add instruction size to MBBSize.
- MBBSize += TII->GetInstSizeInBytes(I);
-
- int Opc = I->getOpcode();
- if (I->getDesc().isBranch()) {
- switch (Opc) {
- default:
- continue; // Ignore other JT branches
- case ARM::t2BR_JT:
- T2JumpTables.push_back(I);
- continue; // Does not get an entry in ImmBranches
- }
- }
- }
-
- BBSizes.push_back(MBBSize);
- BBOffsets.push_back(Offset);
- Offset += MBBSize;
+ I != E; ++I)
+ if (I->getDesc().isBranch() && I->getOpcode() == ARM::t2BR_JT)
+ T2JumpTables.push_back(I);
}
}
@@ -1718,8 +1698,8 @@
return MadeChange;
}
-/// ReorderThumb2JumpTables - Use tbb / tbh instructions to generate smaller
-/// jumptables when it's possible.
+/// ReorderThumb2JumpTables - Adjust the function's block layout to ensure that
+/// jump tables always branch forwards, since that's what tbb and tbh need.
bool ARMConstantIslands::ReorderThumb2JumpTables(MachineFunction &MF) {
bool MadeChange = false;
@@ -1737,13 +1717,13 @@
// We prefer if target blocks for the jump table come after the jump
// instruction so we can use TB[BH]. Loop through the target blocks
// and try to adjust them such that that's true.
- unsigned JTOffset = GetOffsetOf(MI) + 4;
+ int JTNumber = MI->getParent()->getNumber();
const std::vector<MachineBasicBlock*> &JTBBs = JT[JTI].MBBs;
for (unsigned j = 0, ee = JTBBs.size(); j != ee; ++j) {
MachineBasicBlock *MBB = JTBBs[j];
- unsigned DstOffset = BBOffsets[MBB->getNumber()];
+ int DTNumber = MBB->getNumber();
- if (DstOffset < JTOffset) {
+ if (DTNumber < JTNumber) {
// The destination precedes the switch. Try to move the block forward
// so we have a positive offset.
MachineBasicBlock *NewBB =
@@ -1763,13 +1743,10 @@
{
MachineFunction &MF = *BB->getParent();
- // FIXME: If it's a small block terminated by an unconditional branch,
+ // If it's the destination block is terminated by an unconditional branch,
// try to move it; otherwise, create a new block following the jump
- // table that branches back to the actual target. This is an overly
- // simplistic heuristic here for proof-of-concept.
-
- int BBI = BB->getNumber();
- int Size = BBSizes[BBI];
+ // table that branches back to the actual target. This is a very simple
+ // heuristic. FIXME: We can definitely improve it.
MachineBasicBlock *TBB = 0, *FBB = 0;
SmallVector<MachineOperand, 4> Cond;
@@ -1777,13 +1754,16 @@
if (TII->AnalyzeBranch(*BB, TBB, FBB, Cond))
return NULL;
- // If the block is small and ends in an unconditional branch, move it.
- if (Size < 50 && Cond.empty() && BB != MF.begin()) {
+ // If the block ends in an unconditional branch, move it. Be paranoid
+ // and make sure we're not trying to move the entry block of the function.
+ if (Cond.empty() && BB != MF.begin()) {
MachineFunction::iterator BBi = BB;
MachineFunction::iterator OldPrior = prior(BBi);
BB->moveAfter(JTBB);
OldPrior->updateTerminator();
BB->updateTerminator();
+ // Update numbering to account for the block being moved.
+ MF.RenumberBlocks(OldPrior);
++NumJTMoved;
return NULL;
}
@@ -1808,30 +1788,6 @@
JTBB->removeSuccessor(BB);
JTBB->addSuccessor(NewBB);
- // Insert a size into BBSizes to align it properly with the (newly
- // renumbered) block numbers.
- BBSizes.insert(BBSizes.begin()+NewBB->getNumber(), 0);
-
- // Likewise for BBOffsets.
- BBOffsets.insert(BBOffsets.begin()+NewBB->getNumber(), 0);
-
- // Figure out how large the first NewMBB is.
- unsigned NewBBSize = 0;
- for (MachineBasicBlock::iterator I = NewBB->begin(), E = NewBB->end();
- I != E; ++I)
- NewBBSize += TII->GetInstSizeInBytes(I);
-
- unsigned NewBBI = NewBB->getNumber();
- unsigned JTBBI = JTBB->getNumber();
- // Set the size of NewBB in BBSizes.
- BBSizes[NewBBI] = NewBBSize;
-
- // ...and adjust BBOffsets for NewBB accordingly.
- BBOffsets[NewBBI] = BBOffsets[JTBBI] + BBSizes[JTBBI];
-
- // All BBOffsets following these blocks must be modified.
- AdjustBBOffsetsAfter(NewBB, 4);
-
++NumJTInserted;
return NewBB;
}
More information about the llvm-branch-commits
mailing list