Remove an evil vector bool. Cosmetic refactoring,

no functional change.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50921 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Dale Johannesen
2008-05-09 23:28:24 +00:00
parent d880b97257
commit 6b8583cbf1

View File

@ -71,10 +71,15 @@ namespace {
MachineBasicBlock *NewDest); MachineBasicBlock *NewDest);
MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB, MachineBasicBlock *SplitMBBAt(MachineBasicBlock &CurMBB,
MachineBasicBlock::iterator BBI1); MachineBasicBlock::iterator BBI1);
unsigned ComputeSameTails(unsigned CurHash, unsigned minCommonTailLength);
void RemoveBlocksWithHash(unsigned CurHash, MachineBasicBlock* SuccBB,
MachineBasicBlock* PredBB);
typedef std::pair<unsigned,MachineBasicBlock*> MergePotentialsElt; typedef std::pair<unsigned,MachineBasicBlock*> MergePotentialsElt;
std::vector<MergePotentialsElt> MergePotentials;
typedef std::vector<MergePotentialsElt>::iterator MPIterator; typedef std::vector<MergePotentialsElt>::iterator MPIterator;
std::vector<MergePotentialsElt> MergePotentials;
typedef std::pair<MPIterator, MachineBasicBlock::iterator> SameTailElt;
std::vector<SameTailElt> SameTails;
const TargetRegisterInfo *RegInfo; const TargetRegisterInfo *RegInfo;
RegScavenger *RS; RegScavenger *RS;
@ -221,8 +226,7 @@ bool BranchFolder::runOnMachineFunction(MachineFunction &MF) {
// If a jump table was merge with another one, walk the function rewriting // If a jump table was merge with another one, walk the function rewriting
// references to jump tables to reference the new JT ID's. Keep track of // references to jump tables to reference the new JT ID's. Keep track of
// whether we see a jump table idx, if not, we can delete the JT. // whether we see a jump table idx, if not, we can delete the JT.
std::vector<bool> JTIsLive; BitVector JTIsLive(JTs.size());
JTIsLive.resize(JTs.size());
for (MachineFunction::iterator BB = MF.begin(), E = MF.end(); for (MachineFunction::iterator BB = MF.begin(), E = MF.end();
BB != E; ++BB) { BB != E; ++BB) {
for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end(); for (MachineBasicBlock::iterator I = BB->begin(), E = BB->end();
@ -234,7 +238,7 @@ bool BranchFolder::runOnMachineFunction(MachineFunction &MF) {
Op.setIndex(NewIdx); Op.setIndex(NewIdx);
// Remember that this JT is live. // Remember that this JT is live.
JTIsLive[NewIdx] = true; JTIsLive.set(NewIdx);
} }
} }
@ -242,7 +246,7 @@ bool BranchFolder::runOnMachineFunction(MachineFunction &MF) {
// indirect jump was unreachable (and thus deleted) or because the jump // indirect jump was unreachable (and thus deleted) or because the jump
// table was merged with some other one. // table was merged with some other one.
for (unsigned i = 0, e = JTIsLive.size(); i != e; ++i) for (unsigned i = 0, e = JTIsLive.size(); i != e; ++i)
if (!JTIsLive[i]) { if (!JTIsLive.test(i)) {
JTI->RemoveJumpTable(i); JTI->RemoveJumpTable(i);
EverMadeChange = true; EverMadeChange = true;
} }
@ -468,7 +472,7 @@ static void FixTail(MachineBasicBlock* CurMBB, MachineBasicBlock *SuccBB,
if (I != MF->end() && if (I != MF->end() &&
!TII->AnalyzeBranch(*CurMBB, TBB, FBB, Cond)) { !TII->AnalyzeBranch(*CurMBB, TBB, FBB, Cond)) {
MachineBasicBlock *NextBB = I; MachineBasicBlock *NextBB = I;
if (TBB == NextBB && Cond.size() && !FBB) { if (TBB == NextBB && !Cond.empty() && !FBB) {
if (!TII->ReverseBranchCondition(Cond)) { if (!TII->ReverseBranchCondition(Cond)) {
TII->RemoveBranch(*CurMBB); TII->RemoveBranch(*CurMBB);
TII->InsertBranch(*CurMBB, SuccBB, NULL, Cond); TII->InsertBranch(*CurMBB, SuccBB, NULL, Cond);
@ -499,44 +503,18 @@ static bool MergeCompare(const std::pair<unsigned,MachineBasicBlock*> &p,
} }
} }
// See if any of the blocks in MergePotentials (which all have a common single /// ComputeSameTails - Look through all the blocks in MergePotentials that have
// successor, or all have no successor) can be tail-merged. If there is a /// hash CurHash (guaranteed to match the last element). Build the vector
// successor, any blocks in MergePotentials that are not tail-merged and /// SameTails of all those that have the (same) largest number of instructions
// are not immediately before Succ must have an unconditional branch to /// in common of any pair of these blocks. SameTails entries contain an
// Succ added (but the predecessor/successor lists need no adjustment). /// iterator into MergePotentials (from which the MachineBasicBlock can be
// The lone predecessor of Succ that falls through into Succ, /// found) and a MachineBasicBlock::iterator into that MBB indicating the
// if any, is given in PredBB. /// instruction where the matching code sequence begins.
/// Order of elements in SameTails is the reverse of the order in which
bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB, /// those blocks appear in MergePotentials (where they are not necessarily
MachineBasicBlock* PredBB) { /// consecutive).
// We cannot jump to the entry block, which affects various choices below. unsigned BranchFolder::ComputeSameTails(unsigned CurHash,
MachineBasicBlock *Entry = MergePotentials.begin()->second-> unsigned minCommonTailLength) {
getParent()->begin();
// It doesn't make sense to save a single instruction since tail merging
// will add a jump.
// FIXME: Ask the target to provide the threshold?
unsigned minCommonTailLength = (SuccBB ? 1 : 2) + 1;
MadeChange = false;
DOUT << "\nTryMergeBlocks " << MergePotentials.size();
// Sort by hash value so that blocks with identical end sequences sort
// together.
std::stable_sort(MergePotentials.begin(), MergePotentials.end(), MergeCompare);
// Walk through equivalence sets looking for actual exact matches.
while (MergePotentials.size() > 1) {
unsigned CurHash = prior(MergePotentials.end())->first;
// Look through all the other blocks that have the same hash as this
// one, and build a vector of all those that have the (same) largest number
// of instructions in common.
// Order of elements in SameTails is the reverse of the order in which
// those blocks appear in MergePotentials (where they are not necessarily
// consecutive).
typedef std::pair<MPIterator, MachineBasicBlock::iterator> SameTailElt;
std::vector<SameTailElt> SameTails;
unsigned maxCommonTailLength = 0U; unsigned maxCommonTailLength = 0U;
SameTails.clear(); SameTails.clear();
MachineBasicBlock::iterator TrialBBI1, TrialBBI2; MachineBasicBlock::iterator TrialBBI1, TrialBBI2;
@ -565,10 +543,14 @@ bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB,
break; break;
} }
} }
return maxCommonTailLength;
}
// If we didn't find any pair that has at least minCommonTailLength /// RemoveBlocksWithHash - Remove all blocks with hash CurHash from
// instructions in common, remove all blocks with this hash code and retry. /// MergePotentials, restoring branches at ends of blocks as appropriate.
if (SameTails.empty()) { void BranchFolder::RemoveBlocksWithHash(unsigned CurHash,
MachineBasicBlock* SuccBB,
MachineBasicBlock* PredBB) {
for (MPIterator CurMPIter = prior(MergePotentials.end()), for (MPIterator CurMPIter = prior(MergePotentials.end()),
B = MergePotentials.begin(); B = MergePotentials.begin();
CurMPIter->first==CurHash; CurMPIter->first==CurHash;
@ -581,6 +563,47 @@ bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB,
if (CurMPIter==B) if (CurMPIter==B)
break; break;
} }
}
// See if any of the blocks in MergePotentials (which all have a common single
// successor, or all have no successor) can be tail-merged. If there is a
// successor, any blocks in MergePotentials that are not tail-merged and
// are not immediately before Succ must have an unconditional branch to
// Succ added (but the predecessor/successor lists need no adjustment).
// The lone predecessor of Succ that falls through into Succ,
// if any, is given in PredBB.
bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB,
MachineBasicBlock* PredBB) {
// We cannot jump to the entry block, which affects various choices below.
MachineBasicBlock *Entry = MergePotentials.begin()->second->
getParent()->begin();
// It doesn't make sense to save a single instruction since tail merging
// will add a jump.
// FIXME: Ask the target to provide the threshold?
unsigned minCommonTailLength = (SuccBB ? 1 : 2) + 1;
MadeChange = false;
DOUT << "\nTryMergeBlocks " << MergePotentials.size();
// Sort by hash value so that blocks with identical end sequences sort
// together.
std::stable_sort(MergePotentials.begin(), MergePotentials.end(),MergeCompare);
// Walk through equivalence sets looking for actual exact matches.
while (MergePotentials.size() > 1) {
unsigned CurHash = prior(MergePotentials.end())->first;
// Build SameTails, identifying the set of blocks with this hash code
// and with the maximum number of instructions in common.
unsigned maxCommonTailLength = ComputeSameTails(CurHash,
minCommonTailLength);
// If we didn't find any pair that has at least minCommonTailLength
// instructions in common, remove all blocks with this hash code and retry.
if (SameTails.empty()) {
RemoveBlocksWithHash(CurHash, SuccBB, PredBB);
continue; continue;
} }
@ -629,9 +652,9 @@ bool BranchFolder::TryMergeBlocks(MachineBasicBlock *SuccBB,
// entry block, so if one block is the entry block, split the other one. // entry block, so if one block is the entry block, split the other one.
// The second half of the split block will remain in SameTails, and will // The second half of the split block will remain in SameTails, and will
// consist entirely of common code. Thus in the case where there are multiple // consist entirely of common code. Thus in the case where there are
// blocks that would all need to be split, the next iteration of the // multiple blocks that would all need to be split, the next iteration of
// outer loop will handle all the rest of them. // the outer loop will handle all the rest of them.
// Decide whether we want to split MBB1 or MBB2. // Decide whether we want to split MBB1 or MBB2.
if (ShouldSplitFirstBlock(MBB1, BBI1, MBB2, BBI2, PredBB)) { if (ShouldSplitFirstBlock(MBB1, BBI1, MBB2, BBI2, PredBB)) {
@ -717,7 +740,7 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
// Failing case: IBB is the target of a cbr, and // Failing case: IBB is the target of a cbr, and
// we cannot reverse the branch. // we cannot reverse the branch.
std::vector<MachineOperand> NewCond(Cond); std::vector<MachineOperand> NewCond(Cond);
if (Cond.size() && TBB==IBB) { if (!Cond.empty() && TBB==IBB) {
if (TII->ReverseBranchCondition(NewCond)) if (TII->ReverseBranchCondition(NewCond))
continue; continue;
// This is the QBB case described above // This is the QBB case described above
@ -747,9 +770,9 @@ bool BranchFolder::TailMergeBlocks(MachineFunction &MF) {
} }
} }
// Remove the unconditional branch at the end, if any. // Remove the unconditional branch at the end, if any.
if (TBB && (Cond.size()==0 || FBB)) { if (TBB && (Cond.empty() || FBB)) {
TII->RemoveBranch(*PBB); TII->RemoveBranch(*PBB);
if (Cond.size()) if (!Cond.empty())
// reinsert conditional branch only, for now // reinsert conditional branch only, for now
TII->InsertBranch(*PBB, (TBB==IBB) ? FBB : TBB, 0, NewCond); TII->InsertBranch(*PBB, (TBB==IBB) ? FBB : TBB, 0, NewCond);
} }