Lines Matching refs:BB
116 bool ProcessBlock(BasicBlock *BB);
117 bool ThreadEdge(BasicBlock *BB, const SmallVectorImpl<BasicBlock*> &PredBBs,
119 bool DuplicateCondBranchOnPHIIntoPred(BasicBlock *BB,
122 bool ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB,
125 bool ProcessThreadableEdges(Value *Cond, BasicBlock *BB,
160 BasicBlock *BB = I; in runOnFunction() local
162 while (ProcessBlock(BB)) in runOnFunction()
169 if (pred_begin(BB) == pred_end(BB) && in runOnFunction()
170 BB != &BB->getParent()->getEntryBlock()) { in runOnFunction()
171 DEBUG(dbgs() << " JT: Deleting dead block '" << BB->getName() in runOnFunction()
172 << "' with terminator: " << *BB->getTerminator() << '\n'); in runOnFunction()
173 LoopHeaders.erase(BB); in runOnFunction()
174 LVI->eraseBlock(BB); in runOnFunction()
175 DeleteDeadBlock(BB); in runOnFunction()
180 BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator()); in runOnFunction()
186 BB != &BB->getParent()->getEntryBlock() && in runOnFunction()
188 BB->getFirstNonPHIOrDbg()->isTerminator()) { in runOnFunction()
192 bool ErasedFromLoopHeaders = LoopHeaders.erase(BB); in runOnFunction()
199 LVI->eraseBlock(BB); in runOnFunction()
200 if (TryToSimplifyUncondBranchFromEmptyBlock(BB)) { in runOnFunction()
204 BB = Succ; in runOnFunction()
208 LoopHeaders.insert(BB); in runOnFunction()
220 static unsigned getJumpThreadDuplicationCost(const BasicBlock *BB) { in getJumpThreadDuplicationCost() argument
222 BasicBlock::const_iterator I = BB->getFirstNonPHI(); in getJumpThreadDuplicationCost()
316 ComputeValueKnownInPredecessors(Value *V, BasicBlock *BB, PredValueInfo &Result, in ComputeValueKnownInPredecessors() argument
322 if (!RecursionSet.insert(std::make_pair(V, BB)).second) in ComputeValueKnownInPredecessors()
327 RecursionSetRemover remover(RecursionSet, std::make_pair(V, BB)); in ComputeValueKnownInPredecessors()
331 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) in ComputeValueKnownInPredecessors()
340 if (I == 0 || I->getParent() != BB) { in ComputeValueKnownInPredecessors()
355 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) { in ComputeValueKnownInPredecessors()
359 Constant *PredCst = LVI->getConstantOnEdge(V, P, BB); in ComputeValueKnownInPredecessors()
375 PN->getIncomingBlock(i), BB); in ComputeValueKnownInPredecessors()
393 ComputeValueKnownInPredecessors(I->getOperand(0), BB, LHSVals, in ComputeValueKnownInPredecessors()
395 ComputeValueKnownInPredecessors(I->getOperand(1), BB, RHSVals, in ComputeValueKnownInPredecessors()
436 ComputeValueKnownInPredecessors(I->getOperand(0), BB, Result, in ComputeValueKnownInPredecessors()
454 ComputeValueKnownInPredecessors(BO->getOperand(0), BB, LHSVals, in ComputeValueKnownInPredecessors()
474 if (PN && PN->getParent() == BB) { in ComputeValueKnownInPredecessors()
480 Value *RHS = Cmp->getOperand(1)->DoPHITranslation(BB, PredBB); in ComputeValueKnownInPredecessors()
489 cast<Constant>(RHS), PredBB, BB); in ComputeValueKnownInPredecessors()
507 cast<Instruction>(Cmp->getOperand(0))->getParent() != BB) { in ComputeValueKnownInPredecessors()
510 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB);PI != E; ++PI){ in ComputeValueKnownInPredecessors()
516 RHSCst, P, BB); in ComputeValueKnownInPredecessors()
531 ComputeValueKnownInPredecessors(I->getOperand(0), BB, LHSVals, in ComputeValueKnownInPredecessors()
554 ComputeValueKnownInPredecessors(SI->getCondition(), BB, Conds, in ComputeValueKnownInPredecessors()
582 Constant *CI = LVI->getConstant(V, BB); in ComputeValueKnownInPredecessors()
584 for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI) in ComputeValueKnownInPredecessors()
599 static unsigned GetBestDestForJumpOnUndef(BasicBlock *BB) { in GetBestDestForJumpOnUndef() argument
600 TerminatorInst *BBTerm = BB->getTerminator(); in GetBestDestForJumpOnUndef()
617 static bool hasAddressTakenAndUsed(BasicBlock *BB) { in hasAddressTakenAndUsed() argument
618 if (!BB->hasAddressTaken()) return false; in hasAddressTakenAndUsed()
622 BlockAddress *BA = BlockAddress::get(BB); in hasAddressTakenAndUsed()
629 bool JumpThreading::ProcessBlock(BasicBlock *BB) { in ProcessBlock() argument
632 if (pred_begin(BB) == pred_end(BB) && in ProcessBlock()
633 BB != &BB->getParent()->getEntryBlock()) in ProcessBlock()
640 if (BasicBlock *SinglePred = BB->getSinglePredecessor()) { in ProcessBlock()
642 SinglePred != BB && !hasAddressTakenAndUsed(BB)) { in ProcessBlock()
645 LoopHeaders.insert(BB); in ProcessBlock()
651 MergeBasicBlockIntoOnlyPred(BB); in ProcessBlock()
653 if (isEntry && BB != &BB->getParent()->getEntryBlock()) in ProcessBlock()
654 BB->moveBefore(&BB->getParent()->getEntryBlock()); in ProcessBlock()
665 Instruction *Terminator = BB->getTerminator(); in ProcessBlock()
693 unsigned BestSucc = GetBestDestForJumpOnUndef(BB); in ProcessBlock()
696 TerminatorInst *BBTerm = BB->getTerminator(); in ProcessBlock()
699 BBTerm->getSuccessor(i)->removePredecessor(BB, true); in ProcessBlock()
702 DEBUG(dbgs() << " In block '" << BB->getName() in ProcessBlock()
713 DEBUG(dbgs() << " In block '" << BB->getName() in ProcessBlock()
714 << "' folding terminator: " << *BB->getTerminator() << '\n'); in ProcessBlock()
716 ConstantFoldTerminator(BB, true); in ProcessBlock()
725 if (ProcessThreadableEdges(Condition, BB, Preference)) in ProcessBlock()
735 BranchInst *CondBr = dyn_cast<BranchInst>(BB->getTerminator()); in ProcessBlock()
737 pred_iterator PI = pred_begin(BB), PE = pred_end(BB); in ProcessBlock()
740 cast<Instruction>(CondCmp->getOperand(0))->getParent() != BB)) { in ProcessBlock()
747 CondConst, *PI, BB); in ProcessBlock()
753 CondCmp->getOperand(0), CondConst, *PI, BB); in ProcessBlock()
761 CondBr->getSuccessor(ToRemove)->removePredecessor(BB, true); in ProcessBlock()
791 if (ProcessThreadableEdges(CondInst, BB, Preference)) in ProcessBlock()
797 if (PN->getParent() == BB && isa<BranchInst>(BB->getTerminator())) in ProcessBlock()
803 CondInst->getParent() == BB && isa<BranchInst>(BB->getTerminator())) in ProcessBlock()
993 FindMostPopularDest(BasicBlock *BB, in FindMostPopularDest() argument
1035 TerminatorInst *TI = BB->getTerminator(); in FindMostPopularDest()
1052 bool JumpThreading::ProcessThreadableEdges(Value *Cond, BasicBlock *BB, in ProcessThreadableEdges() argument
1056 if (LoopHeaders.count(BB)) in ProcessThreadableEdges()
1060 if (!ComputeValueKnownInPredecessors(Cond, BB, PredValues, Preference)) in ProcessThreadableEdges()
1066 DEBUG(dbgs() << "IN BB: " << *BB; in ProcessThreadableEdges()
1068 dbgs() << " BB '" << BB->getName() << "': FOUND condition = " in ProcessThreadableEdges()
1098 else if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) in ProcessThreadableEdges()
1100 else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB->getTerminator())) { in ProcessThreadableEdges()
1103 assert(isa<IndirectBrInst>(BB->getTerminator()) in ProcessThreadableEdges()
1128 MostPopularDest = FindMostPopularDest(BB, PredToDestList); in ProcessThreadableEdges()
1142 if (PredTI->getSuccessor(i) == BB) in ProcessThreadableEdges()
1149 MostPopularDest = BB->getTerminator()-> in ProcessThreadableEdges()
1150 getSuccessor(GetBestDestForJumpOnUndef(BB)); in ProcessThreadableEdges()
1153 return ThreadEdge(BB, PredsToFactor, MostPopularDest); in ProcessThreadableEdges()
1161 BasicBlock *BB = PN->getParent(); in ProcessBranchOnPHI() local
1178 if (DuplicateCondBranchOnPHIIntoPred(BB, PredBBs)) in ProcessBranchOnPHI()
1191 BasicBlock *BB = BO->getParent(); in ProcessBranchOnXOR() local
1201 if (!isa<PHINode>(BB->front())) in ProcessBranchOnXOR()
1224 if (!ComputeValueKnownInPredecessors(BO->getOperand(0), BB, XorOpValues, in ProcessBranchOnXOR()
1227 if (!ComputeValueKnownInPredecessors(BO->getOperand(1), BB, XorOpValues, in ProcessBranchOnXOR()
1252 SplitVal = ConstantInt::getTrue(BB->getContext()); in ProcessBranchOnXOR()
1254 SplitVal = ConstantInt::getFalse(BB->getContext()); in ProcessBranchOnXOR()
1270 cast<PHINode>(BB->front()).getNumIncomingValues()) { in ProcessBranchOnXOR()
1288 return DuplicateCondBranchOnPHIIntoPred(BB, BlocksToFoldInto); in ProcessBranchOnXOR()
1319 bool JumpThreading::ThreadEdge(BasicBlock *BB, in ThreadEdge() argument
1323 if (SuccBB == BB) { in ThreadEdge()
1324 DEBUG(dbgs() << " Not threading across BB '" << BB->getName() in ThreadEdge()
1331 if (LoopHeaders.count(BB)) { in ThreadEdge()
1332 DEBUG(dbgs() << " Not threading across loop header BB '" << BB->getName() in ThreadEdge()
1338 unsigned JumpThreadCost = getJumpThreadDuplicationCost(BB); in ThreadEdge()
1340 DEBUG(dbgs() << " Not threading BB '" << BB->getName() in ThreadEdge()
1352 PredBB = SplitBlockPredecessors(BB, PredBBs, ".thr_comm", this); in ThreadEdge()
1359 << *BB << "\n"); in ThreadEdge()
1361 LVI->threadEdge(PredBB, BB, SuccBB); in ThreadEdge()
1368 BasicBlock *NewBB = BasicBlock::Create(BB->getContext(), in ThreadEdge()
1369 BB->getName()+".thread", in ThreadEdge()
1370 BB->getParent(), BB); in ThreadEdge()
1373 BasicBlock::iterator BI = BB->begin(); in ThreadEdge()
1397 NewBI->setDebugLoc(BB->getTerminator()->getDebugLoc()); in ThreadEdge()
1401 AddPHINodeEntriesForMappedBlock(SuccBB, BB, NewBB, ValueMapping); in ThreadEdge()
1409 for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) { in ThreadEdge()
1416 if (UserPN->getIncomingBlock(UI) == BB) in ThreadEdge()
1418 } else if (User->getParent() == BB) in ThreadEdge()
1434 SSAUpdate.AddAvailableValue(BB, I); in ThreadEdge()
1448 if (PredTerm->getSuccessor(i) == BB) { in ThreadEdge()
1449 BB->removePredecessor(PredBB, true); in ThreadEdge()
1468 bool JumpThreading::DuplicateCondBranchOnPHIIntoPred(BasicBlock *BB, in DuplicateCondBranchOnPHIIntoPred() argument
1475 if (LoopHeaders.count(BB)) { in DuplicateCondBranchOnPHIIntoPred()
1476 DEBUG(dbgs() << " Not duplicating loop header '" << BB->getName() in DuplicateCondBranchOnPHIIntoPred()
1482 unsigned DuplicationCost = getJumpThreadDuplicationCost(BB); in DuplicateCondBranchOnPHIIntoPred()
1484 DEBUG(dbgs() << " Not duplicating BB '" << BB->getName() in DuplicateCondBranchOnPHIIntoPred()
1496 PredBB = SplitBlockPredecessors(BB, PredBBs, ".thr_comm", this); in DuplicateCondBranchOnPHIIntoPred()
1501 DEBUG(dbgs() << " Duplicating block '" << BB->getName() << "' into end of '" in DuplicateCondBranchOnPHIIntoPred()
1503 << DuplicationCost << " block is:" << *BB << "\n"); in DuplicateCondBranchOnPHIIntoPred()
1510 PredBB = SplitEdge(PredBB, BB, this); in DuplicateCondBranchOnPHIIntoPred()
1518 BasicBlock::iterator BI = BB->begin(); in DuplicateCondBranchOnPHIIntoPred()
1524 for (; BI != BB->end(); ++BI) { in DuplicateCondBranchOnPHIIntoPred()
1551 BranchInst *BBBranch = cast<BranchInst>(BB->getTerminator()); in DuplicateCondBranchOnPHIIntoPred()
1552 AddPHINodeEntriesForMappedBlock(BBBranch->getSuccessor(0), BB, PredBB, in DuplicateCondBranchOnPHIIntoPred()
1554 AddPHINodeEntriesForMappedBlock(BBBranch->getSuccessor(1), BB, PredBB, in DuplicateCondBranchOnPHIIntoPred()
1563 for (BasicBlock::iterator I = BB->begin(); I != BB->end(); ++I) { in DuplicateCondBranchOnPHIIntoPred()
1570 if (UserPN->getIncomingBlock(UI) == BB) in DuplicateCondBranchOnPHIIntoPred()
1572 } else if (User->getParent() == BB) in DuplicateCondBranchOnPHIIntoPred()
1588 SSAUpdate.AddAvailableValue(BB, I); in DuplicateCondBranchOnPHIIntoPred()
1598 BB->removePredecessor(PredBB, true); in DuplicateCondBranchOnPHIIntoPred()