]> granicus.if.org Git - llvm/commitdiff
Apply clang-tidy's modernize-loop-convert to most of lib/IR.
authorBenjamin Kramer <benny.kra@googlemail.com>
Sun, 26 Jun 2016 14:10:56 +0000 (14:10 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Sun, 26 Jun 2016 14:10:56 +0000 (14:10 +0000)
Only minor manual fixes. No functionality change intended.

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

lib/IR/AsmWriter.cpp
lib/IR/AttributeImpl.h
lib/IR/Attributes.cpp
lib/IR/BasicBlock.cpp
lib/IR/Constants.cpp
lib/IR/Core.cpp
lib/IR/Function.cpp
lib/IR/LLVMContextImpl.cpp
lib/IR/TypeFinder.cpp
lib/IR/ValueSymbolTable.cpp

index 0aa0b8014f037f17f6c413c244341e3fc7ef882f..b0c6984943ea7f81e932ca467d6a2490859313e5 100644 (file)
@@ -2709,8 +2709,8 @@ void AssemblyWriter::printFunction(const Function *F) {
 
     Out << " {";
     // Output all of the function's basic blocks.
-    for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
-      printBasicBlock(&*I);
+    for (const BasicBlock &BB : *F)
+      printBasicBlock(&BB);
 
     // Output the function's use-lists.
     printUseLists(F);
@@ -2782,8 +2782,8 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
   if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
 
   // Output all of the instructions in the basic block...
-  for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
-    printInstructionLine(*I);
+  for (const Instruction &I : *BB) {
+    printInstructionLine(I);
   }
 
   if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
@@ -3243,10 +3243,9 @@ void AssemblyWriter::writeAllAttributeGroups() {
        I != E; ++I)
     asVec[I->second] = *I;
 
-  for (std::vector<std::pair<AttributeSet, unsigned> >::iterator
-         I = asVec.begin(), E = asVec.end(); I != E; ++I)
-    Out << "attributes #" << I->second << " = { "
-        << I->first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
+  for (const auto &I : asVec)
+    Out << "attributes #" << I.second << " = { "
+        << I.first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
 }
 
 void AssemblyWriter::printUseListOrder(const UseListOrder &Order) {
index 500e7a3598591c8f909e721751efa044a1d471b1..267a0dab2f25b13185fe462e3fa950f2301e930c 100644 (file)
@@ -162,9 +162,9 @@ class AttributeSetNode final
     // There's memory after the node where we can store the entries in.
     std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
 
-    for (iterator I = begin(), E = end(); I != E; ++I) {
-      if (!I->isStringAttribute()) {
-        AvailableAttrs |= ((uint64_t)1) << I->getKindAsEnum();
+    for (Attribute I : *this) {
+      if (!I.isStringAttribute()) {
+        AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
       }
     }
   }
@@ -265,10 +265,9 @@ public:
       const std::pair<unsigned, AttributeSetNode *> &Last = Slots.back();
       if (Last.first == AttributeSet::FunctionIndex) {
         const AttributeSetNode *Node = Last.second;
-        for (AttributeSetNode::iterator I = Node->begin(), E = Node->end();
-             I != E; ++I) {
-          if (!I->isStringAttribute())
-            AvailableFunctionAttrs |= ((uint64_t)1) << I->getKindAsEnum();
+        for (Attribute I : *Node) {
+          if (!I.isStringAttribute())
+            AvailableFunctionAttrs |= ((uint64_t)1) << I.getKindAsEnum();
         }
       }
     }
index b470fac5782b98cd2eb186b366357bb072e1e9bf..bc49b9300706b3cbdbe838480a68d0ee9fcab99d 100644 (file)
@@ -570,61 +570,61 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
 }
 
 bool AttributeSetNode::hasAttribute(StringRef Kind) const {
-  for (iterator I = begin(), E = end(); I != E; ++I)
-    if (I->hasAttribute(Kind))
+  for (Attribute I : *this)
+    if (I.hasAttribute(Kind))
       return true;
   return false;
 }
 
 Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
   if (hasAttribute(Kind)) {
-    for (iterator I = begin(), E = end(); I != E; ++I)
-      if (I->hasAttribute(Kind))
-        return *I;
+    for (Attribute I : *this)
+      if (I.hasAttribute(Kind))
+        return I;
   }
   return Attribute();
 }
 
 Attribute AttributeSetNode::getAttribute(StringRef Kind) const {
-  for (iterator I = begin(), E = end(); I != E; ++I)
-    if (I->hasAttribute(Kind))
-      return *I;
+  for (Attribute I : *this)
+    if (I.hasAttribute(Kind))
+      return I;
   return Attribute();
 }
 
 unsigned AttributeSetNode::getAlignment() const {
-  for (iterator I = begin(), E = end(); I != E; ++I)
-    if (I->hasAttribute(Attribute::Alignment))
-      return I->getAlignment();
+  for (Attribute I : *this)
+    if (I.hasAttribute(Attribute::Alignment))
+      return I.getAlignment();
   return 0;
 }
 
 unsigned AttributeSetNode::getStackAlignment() const {
-  for (iterator I = begin(), E = end(); I != E; ++I)
-    if (I->hasAttribute(Attribute::StackAlignment))
-      return I->getStackAlignment();
+  for (Attribute I : *this)
+    if (I.hasAttribute(Attribute::StackAlignment))
+      return I.getStackAlignment();
   return 0;
 }
 
 uint64_t AttributeSetNode::getDereferenceableBytes() const {
-  for (iterator I = begin(), E = end(); I != E; ++I)
-    if (I->hasAttribute(Attribute::Dereferenceable))
-      return I->getDereferenceableBytes();
+  for (Attribute I : *this)
+    if (I.hasAttribute(Attribute::Dereferenceable))
+      return I.getDereferenceableBytes();
   return 0;
 }
 
 uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const {
-  for (iterator I = begin(), E = end(); I != E; ++I)
-    if (I->hasAttribute(Attribute::DereferenceableOrNull))
-      return I->getDereferenceableOrNullBytes();
+  for (Attribute I : *this)
+    if (I.hasAttribute(Attribute::DereferenceableOrNull))
+      return I.getDereferenceableOrNullBytes();
   return 0;
 }
 
 std::pair<unsigned, Optional<unsigned>>
 AttributeSetNode::getAllocSizeArgs() const {
-  for (iterator I = begin(), E = end(); I != E; ++I)
-    if (I->hasAttribute(Attribute::AllocSize))
-      return I->getAllocSizeArgs();
+  for (Attribute I : *this)
+    if (I.hasAttribute(Attribute::AllocSize))
+      return I.getAllocSizeArgs();
   return std::make_pair(0, 0);
 }
 
index 9f806fad6801d2feee7858ac50513d41dc9563c1..4640b4f9d413cc4fd238ba88cafd0daf114ca14a 100644 (file)
@@ -217,8 +217,8 @@ BasicBlock::iterator BasicBlock::getFirstInsertionPt() {
 }
 
 void BasicBlock::dropAllReferences() {
-  for(iterator I = begin(), E = end(); I != E; ++I)
-    I->dropAllReferences();
+  for (Instruction &I : *this)
+    I.dropAllReferences();
 }
 
 /// If this basic block has a single predecessor block,
index 35233ae522a2a4dc47a4ead7984e2d4243f71de2..d8d55b472f32c4ec89d061bc50a9e0d89bdf4430 100644 (file)
@@ -2331,8 +2331,8 @@ const char *ConstantDataSequential::getElementPointer(unsigned Elt) const {
 
 /// Return true if the array is empty or all zeros.
 static bool isAllZeros(StringRef Arr) {
-  for (StringRef::iterator I = Arr.begin(), E = Arr.end(); I != E; ++I)
-    if (*I != 0)
+  for (char I : Arr)
+    if (I != 0)
       return false;
   return true;
 }
index a1c094a758c79ed69f77c1045b2516a52030cbd5..a55361489adacbc233923e59b629646b9b47cd77 100644 (file)
@@ -2011,8 +2011,8 @@ unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
 
 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
   Function *Fn = unwrap<Function>(FnRef);
-  for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
-    *BasicBlocksRefs++ = wrap(&*I);
+  for (BasicBlock &BB : *Fn)
+    *BasicBlocksRefs++ = wrap(&BB);
 }
 
 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
index 0da9b98258c3c75005b1eb41948d35f739cbae33..42fb7649aa6bca9b2a88d6e704ba72c4f8653edc 100644 (file)
@@ -347,8 +347,8 @@ void Function::setParent(Module *parent) {
 void Function::dropAllReferences() {
   setIsMaterializable(false);
 
-  for (iterator I = begin(), E = end(); I != E; ++I)
-    I->dropAllReferences();
+  for (BasicBlock &BB : *this)
+    BB.dropAllReferences();
 
   // Delete all basic blocks. They are now unused, except possibly by
   // blockaddresses, but BasicBlock's destructor takes care of those.
@@ -531,11 +531,9 @@ static std::string getMangledTypeStr(Type* Ty) {
 
 std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
   assert(id < num_intrinsics && "Invalid intrinsic ID!");
-  if (Tys.empty())
-    return IntrinsicNameTable[id];
   std::string Result(IntrinsicNameTable[id]);
-  for (unsigned i = 0; i < Tys.size(); ++i) {
-    Result += "." + getMangledTypeStr(Tys[i]);
+  for (Type *Ty : Tys) {
+    Result += "." + getMangledTypeStr(Ty);
   }
   return Result;
 }
index d27fcb1f2e78441c19038f2bc8bac6296f056510..3e354b5e0cfef97e71ae095c9d7884acb11d6e82 100644 (file)
@@ -99,10 +99,9 @@ LLVMContextImpl::~LLVMContextImpl() {
   InlineAsms.freeConstants();
   DeleteContainerSeconds(IntConstants);
   DeleteContainerSeconds(FPConstants);
-  
-  for (StringMap<ConstantDataSequential*>::iterator I = CDSConstants.begin(),
-       E = CDSConstants.end(); I != E; ++I)
-    delete I->second;
+
+  for (auto &CDSConstant : CDSConstants)
+    delete CDSConstant.second;
   CDSConstants.clear();
 
   // Destroy attributes.
index b5bdab0865b6122418d3a8ac570985d1cd50ff7e..dc4c1cffb20c5973fb3b01052c74c60914ab3f38 100644 (file)
@@ -41,23 +41,19 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
 
   // Get types from functions.
   SmallVector<std::pair<unsigned, MDNode *>, 4> MDForInst;
-  for (Module::const_iterator FI = M.begin(), E = M.end(); FI != E; ++FI) {
-    incorporateType(FI->getType());
+  for (const Function &FI : M) {
+    incorporateType(FI.getType());
 
-    for (const Use &U : FI->operands())
+    for (const Use &U : FI.operands())
       incorporateValue(U.get());
 
     // First incorporate the arguments.
-    for (Function::const_arg_iterator AI = FI->arg_begin(),
-           AE = FI->arg_end(); AI != AE; ++AI)
+    for (Function::const_arg_iterator AI = FI.arg_begin(), AE = FI.arg_end();
+         AI != AE; ++AI)
       incorporateValue(&*AI);
 
-    for (Function::const_iterator BB = FI->begin(), E = FI->end();
-         BB != E;++BB)
-      for (BasicBlock::const_iterator II = BB->begin(),
-             E = BB->end(); II != E; ++II) {
-        const Instruction &I = *II;
-
+    for (const BasicBlock &BB : FI)
+      for (const Instruction &I : BB) {
         // Incorporate the type of the instruction.
         incorporateType(I.getType());
 
index 8305a2b3ae74265329b5d782db08c17c3b77aa17..f6f1dd984e9f91034ab8ec11aba56b6d2717a2a9 100644 (file)
@@ -24,10 +24,10 @@ using namespace llvm;
 // Class destructor
 ValueSymbolTable::~ValueSymbolTable() {
 #ifndef NDEBUG   // Only do this in -g mode...
-  for (iterator VI = vmap.begin(), VE = vmap.end(); VI != VE; ++VI)
+  for (const auto &VI : vmap)
     dbgs() << "Value still in symbol table! Type = '"
-           << *VI->getValue()->getType() << "' Name = '"
-           << VI->getKeyData() << "'\n";
+           << *VI.getValue()->getType() << "' Name = '" << VI.getKeyData()
+           << "'\n";
   assert(vmap.empty() && "Values remain in symbol table!");
 #endif
 }
@@ -99,9 +99,9 @@ ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
 //
 LLVM_DUMP_METHOD void ValueSymbolTable::dump() const {
   //DEBUG(dbgs() << "ValueSymbolTable:\n");
-  for (const_iterator I = begin(), E = end(); I != E; ++I) {
+  for (const auto &I : *this) {
     //DEBUG(dbgs() << "  '" << I->getKeyData() << "' = ");
-    I->getValue()->dump();
+    I.getValue()->dump();
     //DEBUG(dbgs() << "\n");
   }
 }