llvm.org GIT mirror llvm / 2bcc808
Standardize {pred,succ,use,user}_empty() The functions {pred,succ,use,user}_{begin,end} exist, but many users have to check *_begin() with *_end() by hand to determine if the BasicBlock or User is empty. Fix this with a standard *_empty(), demonstrating a few usecases. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225760 91177308-0d34-0410-b5e6-96231b3b80d8 Ramkumar Ramachandra 5 years ago
8 changed file(s) with 18 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
9191 inline pred_iterator pred_end(BasicBlock *BB) { return pred_iterator(BB, true);}
9292 inline const_pred_iterator pred_end(const BasicBlock *BB) {
9393 return const_pred_iterator(BB, true);
94 }
95 inline bool pred_empty(const BasicBlock *BB) {
96 return pred_begin(BB) == pred_end(BB);
9497 }
9598
9699
256259 inline succ_const_iterator succ_end(const BasicBlock *BB) {
257260 return succ_const_iterator(BB->getTerminator(), true);
258261 }
262 inline bool succ_empty(const BasicBlock *BB) {
263 return succ_begin(BB) == succ_end(BB);
264 }
259265
260266 template struct isPodLike > {
261267 static const bool value = isPodLike::value;
284284 iterator_range uses() const {
285285 return iterator_range(use_begin(), use_end());
286286 }
287
288 bool user_empty() const { return UseList == nullptr; }
287289
288290 typedef user_iterator_impl user_iterator;
289291 typedef user_iterator_impl const_user_iterator;
2626 void llvm::FindFunctionBackedges(const Function &F,
2727 SmallVectorImpl > &Result) {
2828 const BasicBlock *BB = &F.getEntryBlock();
29 if (succ_begin(BB) == succ_end(BB))
29 if (succ_empty(BB))
3030 return;
3131
3232 SmallPtrSet Visited;
11271127
11281128 // Check the entry node
11291129 const BasicBlock *Entry = &F.getEntryBlock();
1130 Assert1(pred_begin(Entry) == pred_end(Entry),
1130 Assert1(pred_empty(Entry),
11311131 "Entry block to function must not have predecessors!", Entry);
11321132
11331133 // The address of the entry block cannot be taken, unless it is dead.
199199 BB->getInstList().pop_back();
200200
201201 // If the unwind block is now dead, nuke it.
202 if (pred_begin(UnwindBlock) == pred_end(UnwindBlock))
202 if (pred_empty(UnwindBlock))
203203 DeleteBasicBlock(UnwindBlock); // Delete the new BB.
204204
205205 ++NumRemoved;
233233 /// updating the callgraph to reflect any now-obsolete edges due to calls that
234234 /// exist in the BB.
235235 void PruneEH::DeleteBasicBlock(BasicBlock *BB) {
236 assert(pred_begin(BB) == pred_end(BB) && "BB is not dead!");
236 assert(pred_empty(BB) && "BB is not dead!");
237237 CallGraph &CG = getAnalysis().getCallGraph();
238238
239239 CallGraphNode *CGN = CG[BB->getParent()];
187187
188188 // If the block is trivially dead, zap it. This eliminates the successor
189189 // edges which simplifies the CFG.
190 if (pred_begin(BB) == pred_end(BB) &&
190 if (pred_empty(BB) &&
191191 BB != &BB->getParent()->getEntryBlock()) {
192192 DEBUG(dbgs() << " JT: Deleting dead block '" << BB->getName()
193193 << "' with terminator: " << *BB->getTerminator() << '\n');
661661 bool JumpThreading::ProcessBlock(BasicBlock *BB) {
662662 // If the block is trivially dead, just return and let the caller nuke it.
663663 // This simplifies other transformations.
664 if (pred_begin(BB) == pred_end(BB) &&
664 if (pred_empty(BB) &&
665665 BB != &BB->getParent()->getEntryBlock())
666666 return false;
667667
7272
7373 // Insert all new allocas into entry block.
7474 BasicBlock *BBEntry = &F.getEntryBlock();
75 assert(pred_begin(BBEntry) == pred_end(BBEntry) &&
75 assert(pred_empty(BBEntry) &&
7676 "Entry block to function must not have predecessors!");
7777
7878 // Find first non-alloca instruction and create insertion point. This is
30193019 }
30203020
30213021 // If we eliminated all predecessors of the block, delete the block now.
3022 if (pred_begin(BB) == pred_end(BB))
3022 if (pred_empty(BB))
30233023 // We know there are no successors, so just nuke the block.
30243024 BB->eraseFromParent();
30253025
31923192 }
31933193
31943194 // If this block is now dead, remove it.
3195 if (pred_begin(BB) == pred_end(BB) &&
3195 if (pred_empty(BB) &&
31963196 BB != &BB->getParent()->getEntryBlock()) {
31973197 // We know there are no successors, so just nuke the block.
31983198 BB->eraseFromParent();
45864586
45874587 // Remove basic blocks that have no predecessors (except the entry block)...
45884588 // or that just have themself as a predecessor. These are unreachable.
4589 if ((pred_begin(BB) == pred_end(BB) &&
4589 if ((pred_emtpy(BB) &&
45904590 BB != &BB->getParent()->getEntryBlock()) ||
45914591 BB->getSinglePredecessor() == BB) {
45924592 DEBUG(dbgs() << "Removing BB: \n" << *BB);