OSDN Git Service

Use ranged for loops in TypeFinder.cpp, NFC
authorVedant Kumar <vsk@apple.com>
Thu, 8 Feb 2018 18:02:27 +0000 (18:02 +0000)
committerVedant Kumar <vsk@apple.com>
Thu, 8 Feb 2018 18:02:27 +0000 (18:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@324628 91177308-0d34-0410-b5e6-96231b3b80d8

lib/IR/TypeFinder.cpp

index b39678a..e9af78c 100644 (file)
@@ -33,18 +33,16 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
   OnlyNamed = onlyNamed;
 
   // Get types from global variables.
-  for (Module::const_global_iterator I = M.global_begin(),
-         E = M.global_end(); I != E; ++I) {
-    incorporateType(I->getType());
-    if (I->hasInitializer())
-      incorporateValue(I->getInitializer());
+  for (const auto &G : M.globals()) {
+    incorporateType(G.getType());
+    if (G.hasInitializer())
+      incorporateValue(G.getInitializer());
   }
 
   // Get types from aliases.
-  for (Module::const_alias_iterator I = M.alias_begin(),
-         E = M.alias_end(); I != E; ++I) {
-    incorporateType(I->getType());
-    if (const Value *Aliasee = I->getAliasee())
+  for (const auto &A : M.aliases()) {
+    incorporateType(A.getType());
+    if (const Value *Aliasee = A.getAliasee())
       incorporateValue(Aliasee);
   }
 
@@ -57,9 +55,8 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
       incorporateValue(U.get());
 
     // First incorporate the arguments.
-    for (Function::const_arg_iterator AI = FI.arg_begin(), AE = FI.arg_end();
-         AI != AE; ++AI)
-      incorporateValue(&*AI);
+    for (const auto &A : FI.args())
+      incorporateValue(&A);
 
     for (const BasicBlock &BB : FI)
       for (const Instruction &I : BB) {
@@ -68,26 +65,21 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
 
         // Incorporate non-instruction operand types. (We are incorporating all
         // instructions with this loop.)
-        for (User::const_op_iterator OI = I.op_begin(), OE = I.op_end();
-             OI != OE; ++OI)
-          if (*OI && !isa<Instruction>(OI))
-            incorporateValue(*OI);
+        for (const auto &O : I.operands())
+          if (&*O && !isa<Instruction>(&*O))
+            incorporateValue(&*O);
 
         // Incorporate types hiding in metadata.
         I.getAllMetadataOtherThanDebugLoc(MDForInst);
-        for (unsigned i = 0, e = MDForInst.size(); i != e; ++i)
-          incorporateMDNode(MDForInst[i].second);
-
+        for (const auto &MD : MDForInst)
+          incorporateMDNode(MD.second);
         MDForInst.clear();
       }
   }
 
-  for (Module::const_named_metadata_iterator I = M.named_metadata_begin(),
-         E = M.named_metadata_end(); I != E; ++I) {
-    const NamedMDNode *NMD = &*I;
-    for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
-      incorporateMDNode(NMD->getOperand(i));
-  }
+  for (const auto &NMD : M.named_metadata())
+    for (const auto &MDOp : NMD.operands())
+      incorporateMDNode(MDOp);
 }
 
 void TypeFinder::clear() {
@@ -150,9 +142,8 @@ void TypeFinder::incorporateValue(const Value *V) {
 
   // Look in operands for types.
   const User *U = cast<User>(V);
-  for (Constant::const_op_iterator I = U->op_begin(),
-         E = U->op_end(); I != E;++I)
-    incorporateValue(*I);
+  for (const auto &I : U->operands())
+    incorporateValue(&*I);
 }
 
 /// incorporateMDNode - This method is used to walk the operands of an MDNode to
@@ -163,8 +154,7 @@ void TypeFinder::incorporateMDNode(const MDNode *V) {
     return;
 
   // Look in operands for types.
-  for (unsigned i = 0, e = V->getNumOperands(); i != e; ++i) {
-    Metadata *Op = V->getOperand(i);
+  for (Metadata *Op : V->operands()) {
     if (!Op)
       continue;
     if (auto *N = dyn_cast<MDNode>(Op)) {