mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-09 11:25:55 +00:00
Refactor some checks into shouldTailDuplicate. Update comments.
No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132798 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -91,6 +91,8 @@ namespace {
|
|||||||
SmallVector<MachineBasicBlock*, 8> &TDBBs,
|
SmallVector<MachineBasicBlock*, 8> &TDBBs,
|
||||||
SmallSetVector<MachineBasicBlock*, 8> &Succs);
|
SmallSetVector<MachineBasicBlock*, 8> &Succs);
|
||||||
bool TailDuplicateBlocks(MachineFunction &MF);
|
bool TailDuplicateBlocks(MachineFunction &MF);
|
||||||
|
bool shouldTailDuplicate(const MachineFunction &MF,
|
||||||
|
MachineBasicBlock &TailBB);
|
||||||
bool TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
|
bool TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
|
||||||
SmallVector<MachineBasicBlock*, 8> &TDBBs,
|
SmallVector<MachineBasicBlock*, 8> &TDBBs,
|
||||||
SmallVector<MachineInstr*, 16> &Copies);
|
SmallVector<MachineInstr*, 16> &Copies);
|
||||||
@@ -184,10 +186,6 @@ bool TailDuplicatePass::TailDuplicateBlocks(MachineFunction &MF) {
|
|||||||
if (NumTails == TailDupLimit)
|
if (NumTails == TailDupLimit)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
// Only duplicate blocks that end with unconditional branches.
|
|
||||||
if (MBB->canFallThrough())
|
|
||||||
continue;
|
|
||||||
|
|
||||||
// Save the successors list.
|
// Save the successors list.
|
||||||
SmallSetVector<MachineBasicBlock*, 8> Succs(MBB->succ_begin(),
|
SmallSetVector<MachineBasicBlock*, 8> Succs(MBB->succ_begin(),
|
||||||
MBB->succ_end());
|
MBB->succ_end());
|
||||||
@@ -450,14 +448,15 @@ TailDuplicatePass::UpdateSuccessorsPHIs(MachineBasicBlock *FromBB, bool isDead,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TailDuplicate - If it is profitable, duplicate TailBB's contents in each
|
/// shouldTailDuplicate - Determine if it is profitable to duplicate this block.
|
||||||
/// of its predecessors.
|
|
||||||
bool
|
bool
|
||||||
TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
|
TailDuplicatePass::shouldTailDuplicate(const MachineFunction &MF,
|
||||||
SmallVector<MachineBasicBlock*, 8> &TDBBs,
|
MachineBasicBlock &TailBB) {
|
||||||
SmallVector<MachineInstr*, 16> &Copies) {
|
// Only duplicate blocks that end with unconditional branches.
|
||||||
// Set the limit on the number of instructions to duplicate, with a default
|
if (TailBB.canFallThrough())
|
||||||
// of one less than the tail-merge threshold. When optimizing for size,
|
return false;
|
||||||
|
|
||||||
|
// Set the limit on the cost to duplicate. When optimizing for size,
|
||||||
// duplicate only one, because one branch instruction can be eliminated to
|
// duplicate only one, because one branch instruction can be eliminated to
|
||||||
// compensate for the duplication.
|
// compensate for the duplication.
|
||||||
unsigned MaxDuplicateCount;
|
unsigned MaxDuplicateCount;
|
||||||
@@ -468,12 +467,12 @@ TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
|
|||||||
MaxDuplicateCount = TailDuplicateSize;
|
MaxDuplicateCount = TailDuplicateSize;
|
||||||
|
|
||||||
if (PreRegAlloc) {
|
if (PreRegAlloc) {
|
||||||
if (TailBB->empty())
|
if (TailBB.empty())
|
||||||
return false;
|
return false;
|
||||||
const TargetInstrDesc &TID = TailBB->back().getDesc();
|
const TargetInstrDesc &TID = TailBB.back().getDesc();
|
||||||
// Pre-regalloc tail duplication hurts compile time and doesn't help
|
// Pre-regalloc tail duplication hurts compile time and doesn't help
|
||||||
// much except for indirect branches and returns.
|
// much except for indirect branches.
|
||||||
if (!TID.isIndirectBranch() && !TID.isReturn())
|
if (!TID.isIndirectBranch())
|
||||||
return false;
|
return false;
|
||||||
// If the target has hardware branch prediction that can handle indirect
|
// If the target has hardware branch prediction that can handle indirect
|
||||||
// branches, duplicating them can often make them predictable when there
|
// branches, duplicating them can often make them predictable when there
|
||||||
@@ -484,15 +483,15 @@ TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Don't try to tail-duplicate single-block loops.
|
// Don't try to tail-duplicate single-block loops.
|
||||||
if (TailBB->isSuccessor(TailBB))
|
if (TailBB.isSuccessor(&TailBB))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Check the instructions in the block to determine whether tail-duplication
|
// Check the instructions in the block to determine whether tail-duplication
|
||||||
// is invalid or unlikely to be profitable.
|
// is invalid or unlikely to be profitable.
|
||||||
unsigned InstrCount = 0;
|
unsigned InstrCount = 0;
|
||||||
bool HasCall = false;
|
bool HasCall = false;
|
||||||
for (MachineBasicBlock::iterator I = TailBB->begin();
|
for (MachineBasicBlock::const_iterator I = TailBB.begin(); I != TailBB.end();
|
||||||
I != TailBB->end(); ++I) {
|
++I) {
|
||||||
// Non-duplicable things shouldn't be tail-duplicated.
|
// Non-duplicable things shouldn't be tail-duplicated.
|
||||||
if (I->getDesc().isNotDuplicable()) return false;
|
if (I->getDesc().isNotDuplicable()) return false;
|
||||||
// Do not duplicate 'return' instructions if this is a pre-regalloc run.
|
// Do not duplicate 'return' instructions if this is a pre-regalloc run.
|
||||||
@@ -512,6 +511,18 @@ TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
|
|||||||
if (InstrCount > 1 && (PreRegAlloc && HasCall))
|
if (InstrCount > 1 && (PreRegAlloc && HasCall))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// TailDuplicate - If it is profitable, duplicate TailBB's contents in each
|
||||||
|
/// of its predecessors.
|
||||||
|
bool
|
||||||
|
TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
|
||||||
|
SmallVector<MachineBasicBlock*, 8> &TDBBs,
|
||||||
|
SmallVector<MachineInstr*, 16> &Copies) {
|
||||||
|
if (!shouldTailDuplicate(MF, *TailBB))
|
||||||
|
return false;
|
||||||
|
|
||||||
DEBUG(dbgs() << "\n*** Tail-duplicating BB#" << TailBB->getNumber() << '\n');
|
DEBUG(dbgs() << "\n*** Tail-duplicating BB#" << TailBB->getNumber() << '\n');
|
||||||
|
|
||||||
// Iterate through all the unique predecessors and tail-duplicate this
|
// Iterate through all the unique predecessors and tail-duplicate this
|
||||||
|
Reference in New Issue
Block a user