Now that bb with phis are not considered simple, duplicate them even if

we cannot duplicate to every predecessor.

llvm-svn: 133797
This commit is contained in:
Rafael Espindola 2011-06-24 15:47:41 +00:00
parent 67677898d3
commit cb0213bda6
1 changed files with 18 additions and 12 deletions

View File

@ -98,7 +98,7 @@ namespace {
bool IsSimple, MachineBasicBlock &TailBB); bool IsSimple, MachineBasicBlock &TailBB);
bool isSimpleBB(MachineBasicBlock *TailBB); bool isSimpleBB(MachineBasicBlock *TailBB);
bool canCompletelyDuplicateBB(MachineBasicBlock &BB, bool IsSimple); bool canCompletelyDuplicateBB(MachineBasicBlock &BB, bool IsSimple);
void duplicateSimpleBB(MachineBasicBlock *TailBB, bool duplicateSimpleBB(MachineBasicBlock *TailBB,
SmallVector<MachineBasicBlock*, 8> &TDBBs, SmallVector<MachineBasicBlock*, 8> &TDBBs,
const DenseSet<unsigned> &RegsUsedByPhi, const DenseSet<unsigned> &RegsUsedByPhi,
SmallVector<MachineInstr*, 16> &Copies); SmallVector<MachineInstr*, 16> &Copies);
@ -568,7 +568,7 @@ TailDuplicatePass::shouldTailDuplicate(const MachineFunction &MF,
return true; return true;
if (IsSimple) if (IsSimple)
return canCompletelyDuplicateBB(TailBB, IsSimple); return true;
if (!PreRegAlloc) if (!PreRegAlloc)
return true; return true;
@ -635,24 +635,32 @@ TailDuplicatePass::canCompletelyDuplicateBB(MachineBasicBlock &BB,
return true; return true;
} }
void bool
TailDuplicatePass::duplicateSimpleBB(MachineBasicBlock *TailBB, TailDuplicatePass::duplicateSimpleBB(MachineBasicBlock *TailBB,
SmallVector<MachineBasicBlock*, 8> &TDBBs, SmallVector<MachineBasicBlock*, 8> &TDBBs,
const DenseSet<unsigned> &UsedByPhi, const DenseSet<unsigned> &UsedByPhi,
SmallVector<MachineInstr*, 16> &Copies) { SmallVector<MachineInstr*, 16> &Copies) {
SmallPtrSet<MachineBasicBlock*, 8> Succs(TailBB->succ_begin(),
TailBB->succ_end());
SmallVector<MachineBasicBlock*, 8> Preds(TailBB->pred_begin(), SmallVector<MachineBasicBlock*, 8> Preds(TailBB->pred_begin(),
TailBB->pred_end()); TailBB->pred_end());
bool Changed = false;
for (SmallSetVector<MachineBasicBlock *, 8>::iterator PI = Preds.begin(), for (SmallSetVector<MachineBasicBlock *, 8>::iterator PI = Preds.begin(),
PE = Preds.end(); PI != PE; ++PI) { PE = Preds.end(); PI != PE; ++PI) {
MachineBasicBlock *PredBB = *PI; MachineBasicBlock *PredBB = *PI;
if (PredBB->getLandingPadSuccessor())
continue;
if (bothUsedInPHI(*PredBB, Succs))
continue;
MachineBasicBlock *PredTBB = NULL, *PredFBB = NULL; MachineBasicBlock *PredTBB = NULL, *PredFBB = NULL;
SmallVector<MachineOperand, 4> PredCond; SmallVector<MachineOperand, 4> PredCond;
bool NotAnalyzable = if (TII->AnalyzeBranch(*PredBB, PredTBB, PredFBB, PredCond, true))
TII->AnalyzeBranch(*PredBB, PredTBB, PredFBB, PredCond, true); continue;
(void)NotAnalyzable;
assert(!NotAnalyzable && "Cannot duplicate this!");
Changed = true;
DEBUG(dbgs() << "\nTail-duplicating into PredBB: " << *PredBB DEBUG(dbgs() << "\nTail-duplicating into PredBB: " << *PredBB
<< "From simple Succ: " << *TailBB); << "From simple Succ: " << *TailBB);
@ -700,6 +708,7 @@ TailDuplicatePass::duplicateSimpleBB(MachineBasicBlock *TailBB,
TDBBs.push_back(PredBB); TDBBs.push_back(PredBB);
} }
return Changed;
} }
/// TailDuplicate - If it is profitable, duplicate TailBB's contents in each /// TailDuplicate - If it is profitable, duplicate TailBB's contents in each
@ -718,11 +727,8 @@ TailDuplicatePass::TailDuplicate(MachineBasicBlock *TailBB, MachineFunction &MF,
DenseSet<unsigned> UsedByPhi; DenseSet<unsigned> UsedByPhi;
getRegsUsedByPHIs(*TailBB, &UsedByPhi); getRegsUsedByPHIs(*TailBB, &UsedByPhi);
if (IsSimple) { if (IsSimple)
duplicateSimpleBB(TailBB, TDBBs, UsedByPhi, Copies); return duplicateSimpleBB(TailBB, TDBBs, UsedByPhi, Copies);
return true;
}
// Iterate through all the unique predecessors and tail-duplicate this // Iterate through all the unique predecessors and tail-duplicate this
// block into them, if possible. Copying the list ahead of time also // block into them, if possible. Copying the list ahead of time also