Skip to content

Commit af28e7d

Browse files
committed
Apply clang-tidy's modernize-loop-convert to most of lib/IR.
Only minor manual fixes. No functionality change intended. llvm-svn: 273813
1 parent 57819aa commit af28e7d

10 files changed

+61
-70
lines changed

llvm/lib/IR/AsmWriter.cpp

+7-8
Original file line numberDiff line numberDiff line change
@@ -2709,8 +2709,8 @@ void AssemblyWriter::printFunction(const Function *F) {
27092709

27102710
Out << " {";
27112711
// Output all of the function's basic blocks.
2712-
for (Function::const_iterator I = F->begin(), E = F->end(); I != E; ++I)
2713-
printBasicBlock(&*I);
2712+
for (const BasicBlock &BB : *F)
2713+
printBasicBlock(&BB);
27142714

27152715
// Output the function's use-lists.
27162716
printUseLists(F);
@@ -2782,8 +2782,8 @@ void AssemblyWriter::printBasicBlock(const BasicBlock *BB) {
27822782
if (AnnotationWriter) AnnotationWriter->emitBasicBlockStartAnnot(BB, Out);
27832783

27842784
// Output all of the instructions in the basic block...
2785-
for (BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) {
2786-
printInstructionLine(*I);
2785+
for (const Instruction &I : *BB) {
2786+
printInstructionLine(I);
27872787
}
27882788

27892789
if (AnnotationWriter) AnnotationWriter->emitBasicBlockEndAnnot(BB, Out);
@@ -3243,10 +3243,9 @@ void AssemblyWriter::writeAllAttributeGroups() {
32433243
I != E; ++I)
32443244
asVec[I->second] = *I;
32453245

3246-
for (std::vector<std::pair<AttributeSet, unsigned> >::iterator
3247-
I = asVec.begin(), E = asVec.end(); I != E; ++I)
3248-
Out << "attributes #" << I->second << " = { "
3249-
<< I->first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
3246+
for (const auto &I : asVec)
3247+
Out << "attributes #" << I.second << " = { "
3248+
<< I.first.getAsString(AttributeSet::FunctionIndex, true) << " }\n";
32503249
}
32513250

32523251
void AssemblyWriter::printUseListOrder(const UseListOrder &Order) {

llvm/lib/IR/AttributeImpl.h

+6-7
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@ class AttributeSetNode final
162162
// There's memory after the node where we can store the entries in.
163163
std::copy(Attrs.begin(), Attrs.end(), getTrailingObjects<Attribute>());
164164

165-
for (iterator I = begin(), E = end(); I != E; ++I) {
166-
if (!I->isStringAttribute()) {
167-
AvailableAttrs |= ((uint64_t)1) << I->getKindAsEnum();
165+
for (Attribute I : *this) {
166+
if (!I.isStringAttribute()) {
167+
AvailableAttrs |= ((uint64_t)1) << I.getKindAsEnum();
168168
}
169169
}
170170
}
@@ -265,10 +265,9 @@ class AttributeSetImpl final
265265
const std::pair<unsigned, AttributeSetNode *> &Last = Slots.back();
266266
if (Last.first == AttributeSet::FunctionIndex) {
267267
const AttributeSetNode *Node = Last.second;
268-
for (AttributeSetNode::iterator I = Node->begin(), E = Node->end();
269-
I != E; ++I) {
270-
if (!I->isStringAttribute())
271-
AvailableFunctionAttrs |= ((uint64_t)1) << I->getKindAsEnum();
268+
for (Attribute I : *Node) {
269+
if (!I.isStringAttribute())
270+
AvailableFunctionAttrs |= ((uint64_t)1) << I.getKindAsEnum();
272271
}
273272
}
274273
}

llvm/lib/IR/Attributes.cpp

+23-23
Original file line numberDiff line numberDiff line change
@@ -570,61 +570,61 @@ AttributeSetNode *AttributeSetNode::get(LLVMContext &C,
570570
}
571571

572572
bool AttributeSetNode::hasAttribute(StringRef Kind) const {
573-
for (iterator I = begin(), E = end(); I != E; ++I)
574-
if (I->hasAttribute(Kind))
573+
for (Attribute I : *this)
574+
if (I.hasAttribute(Kind))
575575
return true;
576576
return false;
577577
}
578578

579579
Attribute AttributeSetNode::getAttribute(Attribute::AttrKind Kind) const {
580580
if (hasAttribute(Kind)) {
581-
for (iterator I = begin(), E = end(); I != E; ++I)
582-
if (I->hasAttribute(Kind))
583-
return *I;
581+
for (Attribute I : *this)
582+
if (I.hasAttribute(Kind))
583+
return I;
584584
}
585585
return Attribute();
586586
}
587587

588588
Attribute AttributeSetNode::getAttribute(StringRef Kind) const {
589-
for (iterator I = begin(), E = end(); I != E; ++I)
590-
if (I->hasAttribute(Kind))
591-
return *I;
589+
for (Attribute I : *this)
590+
if (I.hasAttribute(Kind))
591+
return I;
592592
return Attribute();
593593
}
594594

595595
unsigned AttributeSetNode::getAlignment() const {
596-
for (iterator I = begin(), E = end(); I != E; ++I)
597-
if (I->hasAttribute(Attribute::Alignment))
598-
return I->getAlignment();
596+
for (Attribute I : *this)
597+
if (I.hasAttribute(Attribute::Alignment))
598+
return I.getAlignment();
599599
return 0;
600600
}
601601

602602
unsigned AttributeSetNode::getStackAlignment() const {
603-
for (iterator I = begin(), E = end(); I != E; ++I)
604-
if (I->hasAttribute(Attribute::StackAlignment))
605-
return I->getStackAlignment();
603+
for (Attribute I : *this)
604+
if (I.hasAttribute(Attribute::StackAlignment))
605+
return I.getStackAlignment();
606606
return 0;
607607
}
608608

609609
uint64_t AttributeSetNode::getDereferenceableBytes() const {
610-
for (iterator I = begin(), E = end(); I != E; ++I)
611-
if (I->hasAttribute(Attribute::Dereferenceable))
612-
return I->getDereferenceableBytes();
610+
for (Attribute I : *this)
611+
if (I.hasAttribute(Attribute::Dereferenceable))
612+
return I.getDereferenceableBytes();
613613
return 0;
614614
}
615615

616616
uint64_t AttributeSetNode::getDereferenceableOrNullBytes() const {
617-
for (iterator I = begin(), E = end(); I != E; ++I)
618-
if (I->hasAttribute(Attribute::DereferenceableOrNull))
619-
return I->getDereferenceableOrNullBytes();
617+
for (Attribute I : *this)
618+
if (I.hasAttribute(Attribute::DereferenceableOrNull))
619+
return I.getDereferenceableOrNullBytes();
620620
return 0;
621621
}
622622

623623
std::pair<unsigned, Optional<unsigned>>
624624
AttributeSetNode::getAllocSizeArgs() const {
625-
for (iterator I = begin(), E = end(); I != E; ++I)
626-
if (I->hasAttribute(Attribute::AllocSize))
627-
return I->getAllocSizeArgs();
625+
for (Attribute I : *this)
626+
if (I.hasAttribute(Attribute::AllocSize))
627+
return I.getAllocSizeArgs();
628628
return std::make_pair(0, 0);
629629
}
630630

llvm/lib/IR/BasicBlock.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,8 @@ BasicBlock::iterator BasicBlock::getFirstInsertionPt() {
217217
}
218218

219219
void BasicBlock::dropAllReferences() {
220-
for(iterator I = begin(), E = end(); I != E; ++I)
221-
I->dropAllReferences();
220+
for (Instruction &I : *this)
221+
I.dropAllReferences();
222222
}
223223

224224
/// If this basic block has a single predecessor block,

llvm/lib/IR/Constants.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2331,8 +2331,8 @@ const char *ConstantDataSequential::getElementPointer(unsigned Elt) const {
23312331

23322332
/// Return true if the array is empty or all zeros.
23332333
static bool isAllZeros(StringRef Arr) {
2334-
for (StringRef::iterator I = Arr.begin(), E = Arr.end(); I != E; ++I)
2335-
if (*I != 0)
2334+
for (char I : Arr)
2335+
if (I != 0)
23362336
return false;
23372337
return true;
23382338
}

llvm/lib/IR/Core.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -2011,8 +2011,8 @@ unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
20112011

20122012
void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
20132013
Function *Fn = unwrap<Function>(FnRef);
2014-
for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
2015-
*BasicBlocksRefs++ = wrap(&*I);
2014+
for (BasicBlock &BB : *Fn)
2015+
*BasicBlocksRefs++ = wrap(&BB);
20162016
}
20172017

20182018
LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {

llvm/lib/IR/Function.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ void Function::setParent(Module *parent) {
347347
void Function::dropAllReferences() {
348348
setIsMaterializable(false);
349349

350-
for (iterator I = begin(), E = end(); I != E; ++I)
351-
I->dropAllReferences();
350+
for (BasicBlock &BB : *this)
351+
BB.dropAllReferences();
352352

353353
// Delete all basic blocks. They are now unused, except possibly by
354354
// blockaddresses, but BasicBlock's destructor takes care of those.
@@ -531,11 +531,9 @@ static std::string getMangledTypeStr(Type* Ty) {
531531

532532
std::string Intrinsic::getName(ID id, ArrayRef<Type*> Tys) {
533533
assert(id < num_intrinsics && "Invalid intrinsic ID!");
534-
if (Tys.empty())
535-
return IntrinsicNameTable[id];
536534
std::string Result(IntrinsicNameTable[id]);
537-
for (unsigned i = 0; i < Tys.size(); ++i) {
538-
Result += "." + getMangledTypeStr(Tys[i]);
535+
for (Type *Ty : Tys) {
536+
Result += "." + getMangledTypeStr(Ty);
539537
}
540538
return Result;
541539
}

llvm/lib/IR/LLVMContextImpl.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,9 @@ LLVMContextImpl::~LLVMContextImpl() {
9999
InlineAsms.freeConstants();
100100
DeleteContainerSeconds(IntConstants);
101101
DeleteContainerSeconds(FPConstants);
102-
103-
for (StringMap<ConstantDataSequential*>::iterator I = CDSConstants.begin(),
104-
E = CDSConstants.end(); I != E; ++I)
105-
delete I->second;
102+
103+
for (auto &CDSConstant : CDSConstants)
104+
delete CDSConstant.second;
106105
CDSConstants.clear();
107106

108107
// Destroy attributes.

llvm/lib/IR/TypeFinder.cpp

+7-11
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,19 @@ void TypeFinder::run(const Module &M, bool onlyNamed) {
4141

4242
// Get types from functions.
4343
SmallVector<std::pair<unsigned, MDNode *>, 4> MDForInst;
44-
for (Module::const_iterator FI = M.begin(), E = M.end(); FI != E; ++FI) {
45-
incorporateType(FI->getType());
44+
for (const Function &FI : M) {
45+
incorporateType(FI.getType());
4646

47-
for (const Use &U : FI->operands())
47+
for (const Use &U : FI.operands())
4848
incorporateValue(U.get());
4949

5050
// First incorporate the arguments.
51-
for (Function::const_arg_iterator AI = FI->arg_begin(),
52-
AE = FI->arg_end(); AI != AE; ++AI)
51+
for (Function::const_arg_iterator AI = FI.arg_begin(), AE = FI.arg_end();
52+
AI != AE; ++AI)
5353
incorporateValue(&*AI);
5454

55-
for (Function::const_iterator BB = FI->begin(), E = FI->end();
56-
BB != E;++BB)
57-
for (BasicBlock::const_iterator II = BB->begin(),
58-
E = BB->end(); II != E; ++II) {
59-
const Instruction &I = *II;
60-
55+
for (const BasicBlock &BB : FI)
56+
for (const Instruction &I : BB) {
6157
// Incorporate the type of the instruction.
6258
incorporateType(I.getType());
6359

llvm/lib/IR/ValueSymbolTable.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ using namespace llvm;
2424
// Class destructor
2525
ValueSymbolTable::~ValueSymbolTable() {
2626
#ifndef NDEBUG // Only do this in -g mode...
27-
for (iterator VI = vmap.begin(), VE = vmap.end(); VI != VE; ++VI)
27+
for (const auto &VI : vmap)
2828
dbgs() << "Value still in symbol table! Type = '"
29-
<< *VI->getValue()->getType() << "' Name = '"
30-
<< VI->getKeyData() << "'\n";
29+
<< *VI.getValue()->getType() << "' Name = '" << VI.getKeyData()
30+
<< "'\n";
3131
assert(vmap.empty() && "Values remain in symbol table!");
3232
#endif
3333
}
@@ -99,9 +99,9 @@ ValueName *ValueSymbolTable::createValueName(StringRef Name, Value *V) {
9999
//
100100
LLVM_DUMP_METHOD void ValueSymbolTable::dump() const {
101101
//DEBUG(dbgs() << "ValueSymbolTable:\n");
102-
for (const_iterator I = begin(), E = end(); I != E; ++I) {
102+
for (const auto &I : *this) {
103103
//DEBUG(dbgs() << " '" << I->getKeyData() << "' = ");
104-
I->getValue()->dump();
104+
I.getValue()->dump();
105105
//DEBUG(dbgs() << "\n");
106106
}
107107
}

0 commit comments

Comments
 (0)