mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-15 04:30:12 +00:00
Simplify thumb2 jump table adjustments. Remove unnecessary calculation and
usage of block sizes and offsets. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@88935 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
9249efe4c7
commit
08cbda56b6
@ -281,8 +281,6 @@ bool ARMConstantIslands::runOnMachineFunction(MachineFunction &MF) {
|
||||
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 @@ ARMConstantIslands::CPEntry
|
||||
/// 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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1737,13 +1717,13 @@ bool ARMConstantIslands::ReorderThumb2JumpTables(MachineFunction &MF) {
|
||||
// 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 @@ AdjustJTTargetBlockForward(MachineBasicBlock *BB, MachineBasicBlock *JTBB)
|
||||
{
|
||||
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 @@ AdjustJTTargetBlockForward(MachineBasicBlock *BB, MachineBasicBlock *JTBB)
|
||||
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 @@ AdjustJTTargetBlockForward(MachineBasicBlock *BB, MachineBasicBlock *JTBB)
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user