[PM] Switch tihs code to use a range based for loop over the function.
authorChandler Carruth <chandlerc@gmail.com>
Sat, 24 Jan 2015 10:57:19 +0000 (10:57 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Sat, 24 Jan 2015 10:57:19 +0000 (10:57 +0000)
We can't switch the loop over the instructions because it needs to
early-increment the iterator.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226996 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LowerExpectIntrinsic.cpp

index aa991faafea48c141b0109b6c27fb4dc7937d911..fa82d62b32f4c9304582cde865986bb5751e8aea 100644 (file)
@@ -143,20 +143,18 @@ static bool handleBranchExpect(BranchInst &BI) {
 }
 
 bool LowerExpectIntrinsic::runOnFunction(Function &F) {
-  for (Function::iterator I = F.begin(), E = F.end(); I != E;) {
-    BasicBlock *BB = I++;
-
+  for (BasicBlock &BB : F) {
     // Create "block_weights" metadata.
-    if (BranchInst *BI = dyn_cast<BranchInst>(BB->getTerminator())) {
+    if (BranchInst *BI = dyn_cast<BranchInst>(BB.getTerminator())) {
       if (handleBranchExpect(*BI))
         IfHandled++;
-    } else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB->getTerminator())) {
+    } else if (SwitchInst *SI = dyn_cast<SwitchInst>(BB.getTerminator())) {
       if (handleSwitchExpect(*SI))
         IfHandled++;
     }
 
     // remove llvm.expect intrinsics.
-    for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE;) {
+    for (BasicBlock::iterator BI = BB.begin(), BE = BB.end(); BI != BE;) {
       CallInst *CI = dyn_cast<CallInst>(BI++);
       if (!CI)
         continue;