]> granicus.if.org Git - clang/commitdiff
[TI removal] Test predicate rather than casting to detect a terminator
authorChandler Carruth <chandlerc@gmail.com>
Thu, 18 Oct 2018 08:16:20 +0000 (08:16 +0000)
committerChandler Carruth <chandlerc@gmail.com>
Thu, 18 Oct 2018 08:16:20 +0000 (08:16 +0000)
and use the range based successor API.

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

lib/CodeGen/CGLoopInfo.cpp

index 8f9a9b96077625efa7d17e912424faa2e46cb9d3..be69e26d4418c61496acb0ff86d168024439f4d4 100644 (file)
@@ -12,6 +12,7 @@
 #include "clang/AST/Attr.h"
 #include "clang/Sema/LoopHint.h"
 #include "llvm/IR/BasicBlock.h"
+#include "llvm/IR/CFG.h"
 #include "llvm/IR/Constants.h"
 #include "llvm/IR/InstrTypes.h"
 #include "llvm/IR/Instructions.h"
@@ -335,10 +336,10 @@ void LoopInfoStack::InsertHelper(Instruction *I) const {
   if (!L.getLoopID())
     return;
 
-  if (TerminatorInst *TI = dyn_cast<TerminatorInst>(I)) {
-    for (unsigned i = 0, ie = TI->getNumSuccessors(); i < ie; ++i)
-      if (TI->getSuccessor(i) == L.getHeader()) {
-        TI->setMetadata(llvm::LLVMContext::MD_loop, L.getLoopID());
+  if (I->isTerminator()) {
+    for (BasicBlock *Succ : successors(I))
+      if (Succ == L.getHeader()) {
+        I->setMetadata(llvm::LLVMContext::MD_loop, L.getLoopID());
         break;
       }
     return;