[llvm] r273813 - Apply clang-tidy's modernize-loop-convert to most of lib/IR.
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 26 07:10:56 PDT 2016
Author: d0k
Date: Sun Jun 26 09:10:56 2016
New Revision: 273813
URL: http://llvm.org/viewvc/llvm-project?rev=273813&view=rev
Log:
Apply clang-tidy's modernize-loop-convert to most of lib/IR.
Only minor manual fixes. No functionality change intended.
Modified:
llvm/trunk/lib/IR/AsmWriter.cpp
llvm/trunk/lib/IR/AttributeImpl.h
llvm/trunk/lib/IR/Attributes.cpp
llvm/trunk/lib/IR/BasicBlock.cpp
llvm/trunk/lib/IR/Constants.cpp
llvm/trunk/lib/IR/Core.cpp
llvm/trunk/lib/IR/Function.cpp
llvm/trunk/lib/IR/LLVMContextImpl.cpp
llvm/trunk/lib/IR/TypeFinder.cpp
llvm/trunk/lib/IR/ValueSymbolTable.cpp
Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Sun Jun 26 09:10:56 2016
@@ -2709,8 +2709,8 @@ void AssemblyWriter::printFunction(const
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(con
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::writeAllAttributeGr
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) {
Modified: llvm/trunk/lib/IR/AttributeImpl.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AttributeImpl.h?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AttributeImpl.h (original)
+++ llvm/trunk/lib/IR/AttributeImpl.h Sun Jun 26 09:10:56 2016
@@ -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();
}
}
}
Modified: llvm/trunk/lib/IR/Attributes.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Attributes.cpp?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Attributes.cpp (original)
+++ llvm/trunk/lib/IR/Attributes.cpp Sun Jun 26 09:10:56 2016
@@ -570,61 +570,61 @@ AttributeSetNode *AttributeSetNode::get(
}
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);
}
Modified: llvm/trunk/lib/IR/BasicBlock.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/BasicBlock.cpp?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/BasicBlock.cpp (original)
+++ llvm/trunk/lib/IR/BasicBlock.cpp Sun Jun 26 09:10:56 2016
@@ -217,8 +217,8 @@ BasicBlock::iterator BasicBlock::getFirs
}
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,
Modified: llvm/trunk/lib/IR/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Constants.cpp?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Constants.cpp (original)
+++ llvm/trunk/lib/IR/Constants.cpp Sun Jun 26 09:10:56 2016
@@ -2331,8 +2331,8 @@ const char *ConstantDataSequential::getE
/// 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;
}
Modified: llvm/trunk/lib/IR/Core.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Core.cpp?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Core.cpp (original)
+++ llvm/trunk/lib/IR/Core.cpp Sun Jun 26 09:10:56 2016
@@ -2011,8 +2011,8 @@ unsigned LLVMCountBasicBlocks(LLVMValueR
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) {
Modified: llvm/trunk/lib/IR/Function.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Function.cpp?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Function.cpp (original)
+++ llvm/trunk/lib/IR/Function.cpp Sun Jun 26 09:10:56 2016
@@ -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(Typ
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;
}
Modified: llvm/trunk/lib/IR/LLVMContextImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/LLVMContextImpl.cpp?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/LLVMContextImpl.cpp (original)
+++ llvm/trunk/lib/IR/LLVMContextImpl.cpp Sun Jun 26 09:10:56 2016
@@ -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.
Modified: llvm/trunk/lib/IR/TypeFinder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/TypeFinder.cpp?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/TypeFinder.cpp (original)
+++ llvm/trunk/lib/IR/TypeFinder.cpp Sun Jun 26 09:10:56 2016
@@ -41,23 +41,19 @@ void TypeFinder::run(const Module &M, bo
// 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());
Modified: llvm/trunk/lib/IR/ValueSymbolTable.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/ValueSymbolTable.cpp?rev=273813&r1=273812&r2=273813&view=diff
==============================================================================
--- llvm/trunk/lib/IR/ValueSymbolTable.cpp (original)
+++ llvm/trunk/lib/IR/ValueSymbolTable.cpp Sun Jun 26 09:10:56 2016
@@ -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::createValue
//
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");
}
}
More information about the llvm-commits
mailing list