r344730 - [TI removal] Test predicate rather than casting to detect a terminator

Chandler Carruth via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 18 01:16:21 PDT 2018


Author: chandlerc
Date: Thu Oct 18 01:16:20 2018
New Revision: 344730

URL: http://llvm.org/viewvc/llvm-project?rev=344730&view=rev
Log:
[TI removal] Test predicate rather than casting to detect a terminator
and use the range based successor API.

Modified:
    cfe/trunk/lib/CodeGen/CGLoopInfo.cpp

Modified: cfe/trunk/lib/CodeGen/CGLoopInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGLoopInfo.cpp?rev=344730&r1=344729&r2=344730&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGLoopInfo.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGLoopInfo.cpp Thu Oct 18 01:16:20 2018
@@ -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(Instruc
   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;




More information about the cfe-commits mailing list