SplitBlockPredecessors uses ArrayRef instead of Data and Size.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@146277 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Jakub Staszak 2011-12-09 21:19:53 +00:00
parent cd462d055f
commit 2fac1d5d61
7 changed files with 18 additions and 32 deletions

View File

@ -173,9 +173,8 @@ BasicBlock *SplitBlock(BasicBlock *Old, Instruction *SplitPt, Pass *P);
/// complicated to handle the case where one of the edges being split /// complicated to handle the case where one of the edges being split
/// is an exit of a loop with other exits). /// is an exit of a loop with other exits).
/// ///
BasicBlock *SplitBlockPredecessors(BasicBlock *BB, BasicBlock *const *Preds, BasicBlock *SplitBlockPredecessors(BasicBlock *BB, ArrayRef<BasicBlock*> Preds,
unsigned NumPreds, const char *Suffix, const char *Suffix, Pass *P = 0);
Pass *P = 0);
/// SplitLandingPadPredecessors - This method transforms the landing pad, /// SplitLandingPadPredecessors - This method transforms the landing pad,
/// OrigBB, by introducing two new basic blocks into the function. One of those /// OrigBB, by introducing two new basic blocks into the function. One of those

View File

@ -926,8 +926,7 @@ bool JumpThreading::SimplifyPartiallyRedundantLoad(LoadInst *LI) {
// Split them out to their own block. // Split them out to their own block.
UnavailablePred = UnavailablePred =
SplitBlockPredecessors(LoadBB, &PredsToSplit[0], PredsToSplit.size(), SplitBlockPredecessors(LoadBB, PredsToSplit, "thread-pre-split", this);
"thread-pre-split", this);
} }
// If the value isn't available in all predecessors, then there will be // If the value isn't available in all predecessors, then there will be
@ -1339,8 +1338,7 @@ bool JumpThreading::ThreadEdge(BasicBlock *BB,
else { else {
DEBUG(dbgs() << " Factoring out " << PredBBs.size() DEBUG(dbgs() << " Factoring out " << PredBBs.size()
<< " common predecessors.\n"); << " common predecessors.\n");
PredBB = SplitBlockPredecessors(BB, &PredBBs[0], PredBBs.size(), PredBB = SplitBlockPredecessors(BB, PredBBs, ".thr_comm", this);
".thr_comm", this);
} }
// And finally, do it! // And finally, do it!
@ -1484,8 +1482,7 @@ bool JumpThreading::DuplicateCondBranchOnPHIIntoPred(BasicBlock *BB,
else { else {
DEBUG(dbgs() << " Factoring out " << PredBBs.size() DEBUG(dbgs() << " Factoring out " << PredBBs.size()
<< " common predecessors.\n"); << " common predecessors.\n");
PredBB = SplitBlockPredecessors(BB, &PredBBs[0], PredBBs.size(), PredBB = SplitBlockPredecessors(BB, PredBBs, ".thr_comm", this);
".thr_comm", this);
} }
// Okay, we decided to do this! Clone all the instructions in BB onto the end // Okay, we decided to do this! Clone all the instructions in BB onto the end

View File

@ -565,8 +565,7 @@ void LoopUnswitch::SplitExitEdges(Loop *L,
// Although SplitBlockPredecessors doesn't preserve loop-simplify in // Although SplitBlockPredecessors doesn't preserve loop-simplify in
// general, if we call it on all predecessors of all exits then it does. // general, if we call it on all predecessors of all exits then it does.
if (!ExitBlock->isLandingPad()) { if (!ExitBlock->isLandingPad()) {
SplitBlockPredecessors(ExitBlock, Preds.data(), Preds.size(), SplitBlockPredecessors(ExitBlock, Preds, ".us-lcssa", this);
".us-lcssa", this);
} else { } else {
SmallVector<BasicBlock*, 2> NewBBs; SmallVector<BasicBlock*, 2> NewBBs;
SplitLandingPadPredecessors(ExitBlock, Preds, ".us-lcssa", ".us-lcssa", SplitLandingPadPredecessors(ExitBlock, Preds, ".us-lcssa", ".us-lcssa",

View File

@ -453,9 +453,8 @@ static void UpdatePHINodes(BasicBlock *OrigBB, BasicBlock *NewBB,
/// of the edges being split is an exit of a loop with other exits). /// of the edges being split is an exit of a loop with other exits).
/// ///
BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB, BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
BasicBlock *const *Preds, ArrayRef<BasicBlock*> Preds,
unsigned NumPreds, const char *Suffix, const char *Suffix, Pass *P) {
Pass *P) {
// Create new basic block, insert right before the original block. // Create new basic block, insert right before the original block.
BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), BB->getName()+Suffix, BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), BB->getName()+Suffix,
BB->getParent(), BB); BB->getParent(), BB);
@ -464,7 +463,7 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
BranchInst *BI = BranchInst::Create(BB, NewBB); BranchInst *BI = BranchInst::Create(BB, NewBB);
// Move the edges from Preds to point to NewBB instead of BB. // Move the edges from Preds to point to NewBB instead of BB.
for (unsigned i = 0; i != NumPreds; ++i) { for (unsigned i = 0, e = Preds.size(); i != e; ++i) {
// This is slightly more strict than necessary; the minimum requirement // This is slightly more strict than necessary; the minimum requirement
// is that there be no more than one indirectbr branching to BB. And // is that there be no more than one indirectbr branching to BB. And
// all BlockAddress uses would need to be updated. // all BlockAddress uses would need to be updated.
@ -477,7 +476,7 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
// node becomes an incoming value for BB's phi node. However, if the Preds // node becomes an incoming value for BB's phi node. However, if the Preds
// list is empty, we need to insert dummy entries into the PHI nodes in BB to // list is empty, we need to insert dummy entries into the PHI nodes in BB to
// account for the newly created predecessor. // account for the newly created predecessor.
if (NumPreds == 0) { if (Preds.size() == 0) {
// Insert dummy values as the incoming value. // Insert dummy values as the incoming value.
for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I) for (BasicBlock::iterator I = BB->begin(); isa<PHINode>(I); ++I)
cast<PHINode>(I)->addIncoming(UndefValue::get(I->getType()), NewBB); cast<PHINode>(I)->addIncoming(UndefValue::get(I->getType()), NewBB);
@ -486,12 +485,10 @@ BasicBlock *llvm::SplitBlockPredecessors(BasicBlock *BB,
// Update DominatorTree, LoopInfo, and LCCSA analysis information. // Update DominatorTree, LoopInfo, and LCCSA analysis information.
bool HasLoopExit = false; bool HasLoopExit = false;
UpdateAnalysisInformation(BB, NewBB, ArrayRef<BasicBlock*>(Preds, NumPreds), UpdateAnalysisInformation(BB, NewBB, Preds, P, HasLoopExit);
P, HasLoopExit);
// Update the PHI nodes in BB with the values coming from NewBB. // Update the PHI nodes in BB with the values coming from NewBB.
UpdatePHINodes(BB, NewBB, ArrayRef<BasicBlock*>(Preds, NumPreds), BI, UpdatePHINodes(BB, NewBB, Preds, BI, P, HasLoopExit);
P, HasLoopExit);
return NewBB; return NewBB;
} }

View File

@ -372,8 +372,7 @@ BasicBlock *llvm::SplitCriticalEdge(TerminatorInst *TI, unsigned SuccNum,
// form, which we're in the process of restoring! // form, which we're in the process of restoring!
if (!Preds.empty() && HasPredOutsideOfLoop) { if (!Preds.empty() && HasPredOutsideOfLoop) {
BasicBlock *NewExitBB = BasicBlock *NewExitBB =
SplitBlockPredecessors(Exit, Preds.data(), Preds.size(), SplitBlockPredecessors(Exit, Preds, "split", P);
"split", P);
if (P->mustPreserveAnalysisID(LCSSAID)) if (P->mustPreserveAnalysisID(LCSSAID))
CreatePHIsForSplitLoopExit(Preds, NewExitBB, Exit); CreatePHIsForSplitLoopExit(Preds, NewExitBB, Exit);
} }

View File

@ -380,8 +380,7 @@ BasicBlock *LoopSimplify::InsertPreheaderForLoop(Loop *L) {
// Split out the loop pre-header. // Split out the loop pre-header.
BasicBlock *NewBB = BasicBlock *NewBB =
SplitBlockPredecessors(Header, &OutsideBlocks[0], OutsideBlocks.size(), SplitBlockPredecessors(Header, OutsideBlocks, ".preheader", this);
".preheader", this);
NewBB->getTerminator()->setDebugLoc(Header->getFirstNonPHI()->getDebugLoc()); NewBB->getTerminator()->setDebugLoc(Header->getFirstNonPHI()->getDebugLoc());
DEBUG(dbgs() << "LoopSimplify: Creating pre-header " << NewBB->getName() DEBUG(dbgs() << "LoopSimplify: Creating pre-header " << NewBB->getName()
@ -420,9 +419,7 @@ BasicBlock *LoopSimplify::RewriteLoopExitBlock(Loop *L, BasicBlock *Exit) {
this, NewBBs); this, NewBBs);
NewExitBB = NewBBs[0]; NewExitBB = NewBBs[0];
} else { } else {
NewExitBB = SplitBlockPredecessors(Exit, &LoopBlocks[0], NewExitBB = SplitBlockPredecessors(Exit, LoopBlocks, ".loopexit", this);
LoopBlocks.size(), ".loopexit",
this);
} }
DEBUG(dbgs() << "LoopSimplify: Creating dedicated exit block " DEBUG(dbgs() << "LoopSimplify: Creating dedicated exit block "
@ -556,9 +553,8 @@ Loop *LoopSimplify::SeparateNestedLoop(Loop *L, LPPassManager &LPM) {
SE->forgetLoop(L); SE->forgetLoop(L);
BasicBlock *Header = L->getHeader(); BasicBlock *Header = L->getHeader();
BasicBlock *NewBB = SplitBlockPredecessors(Header, &OuterLoopPreds[0], BasicBlock *NewBB =
OuterLoopPreds.size(), SplitBlockPredecessors(Header, OuterLoopPreds, ".outer", this);
".outer", this);
// Make sure that NewBB is put someplace intelligent, which doesn't mess up // Make sure that NewBB is put someplace intelligent, which doesn't mess up
// code layout too horribly. // code layout too horribly.

View File

@ -114,8 +114,7 @@ static void ConnectProlog(Loop *L, Value *TripCount, unsigned Count,
// Split the exit to maintain loop canonicalization guarantees // Split the exit to maintain loop canonicalization guarantees
SmallVector<BasicBlock*, 4> Preds(pred_begin(Exit), pred_end(Exit)); SmallVector<BasicBlock*, 4> Preds(pred_begin(Exit), pred_end(Exit));
if (!Exit->isLandingPad()) { if (!Exit->isLandingPad()) {
SplitBlockPredecessors(Exit, Preds.data(), Preds.size(), SplitBlockPredecessors(Exit, Preds, ".unr-lcssa", P);
".unr-lcssa", P);
} else { } else {
SmallVector<BasicBlock*, 2> NewBBs; SmallVector<BasicBlock*, 2> NewBBs;
SplitLandingPadPredecessors(Exit, Preds, ".unr1-lcssa", ".unr2-lcssa", SplitLandingPadPredecessors(Exit, Preds, ".unr1-lcssa", ".unr2-lcssa",