summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2016-06-26 14:10:56 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2016-06-26 14:10:56 +0000
commite96e21f0036e2d3980ef31513925b8cd0afa846c (patch)
tree36b245ded2a6f99bcc92f1b5df94c28d55e90cac
parent36a5f73f454bdb0c092745fe9c8b092b6c3ca7ac (diff)
Apply clang-tidy's modernize-loop-convert to most of lib/IR.
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
-rw-r--r--lib/IR/AsmWriter.cpp15
-rw-r--r--lib/IR/AttributeImpl.h13
-rw-r--r--lib/IR/Attributes.cpp46
-rw-r--r--lib/IR/BasicBlock.cpp4
-rw-r--r--lib/IR/Constants.cpp4
-rw-r--r--lib/IR/Core.cpp4
-rw-r--r--lib/IR/Function.cpp10
-rw-r--r--lib/IR/LLVMContextImpl.cpp7
-rw-r--r--lib/IR/TypeFinder.cpp18
-rw-r--r--lib/IR/ValueSymbolTable.cpp10
10 files changed, 61 insertions, 70 deletions
diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp
index 0aa0b8014f0..b0c6984943e 100644
--- a/lib/IR/AsmWriter.cpp
+++ b/lib/IR/AsmWriter.cpp
@@ -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) {
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h
index 500e7a35985..267a0dab2f2 100644
--- a/lib/IR/AttributeImpl.h
+++ b/lib/IR/AttributeImpl.h
@@ -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();
}
}
}
diff --git a/lib/IR/Attributes.cpp b/lib/IR/Attributes.cpp
index b470fac5782..bc49b930070 100644
--- a/lib/IR/Attributes.cpp
+++ b/lib/IR/Attributes.cpp
@@ -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);
}
diff --git a/lib/IR/BasicBlock.cpp b/lib/IR/BasicBlock.cpp
index 9f806fad680..4640b4f9d41 100644
--- a/lib/IR/BasicBlock.cpp
+++ b/lib/IR/BasicBlock.cpp
@@ -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,
diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp
index 35233ae522a..d8d55b472f3 100644
--- a/lib/IR/Constants.cpp
+++ b/lib/IR/Constants.cpp
@@ -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;
}
diff --git a/lib/IR/Core.cpp b/lib/IR/Core.cpp
index a1c094a758c..a55361489ad 100644
--- a/lib/IR/Core.cpp
+++ b/lib/IR/Core.cpp
@@ -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) {
diff --git a/lib/IR/Function.cpp b/lib/IR/Function.cpp
index 0da9b98258c..42fb7649aa6 100644
--- a/lib/IR/Function.cpp
+++ b/lib/IR/Function.cpp
@@ -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;
}
diff --git a/lib/IR/LLVMContextImpl.cpp b/lib/IR/LLVMContextImpl.cpp
index d27fcb1f2e7..3e354b5e0cf 100644
--- a/lib/IR/LLVMContextImpl.cpp
+++ b/lib/IR/LLVMContextImpl.cpp
@@ -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.
diff --git a/lib/IR/TypeFinder.cpp b/lib/IR/TypeFinder.cpp
index b5bdab0865b..dc4c1cffb20 100644
--- a/lib/IR/TypeFinder.cpp
+++ b/lib/IR/TypeFinder.cpp
@@ -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());
diff --git a/lib/IR/ValueSymbolTable.cpp b/lib/IR/ValueSymbolTable.cpp
index 8305a2b3ae7..f6f1dd984e9 100644
--- a/lib/IR/ValueSymbolTable.cpp
+++ b/lib/IR/ValueSymbolTable.cpp
@@ -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");
}
}