forked from OSchip/llvm-project
[llvm] Use range-based for loops (NFC)
This commit is contained in:
parent
18f9351223
commit
d1abf481da
|
@ -58,17 +58,13 @@ std::unique_ptr<Module> llvm::CloneModule(
|
|||
// new module. Here we add them to the VMap and to the new Module. We
|
||||
// don't worry about attributes or initializers, they will come later.
|
||||
//
|
||||
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
|
||||
I != E; ++I) {
|
||||
GlobalVariable *GV = new GlobalVariable(*New,
|
||||
I->getValueType(),
|
||||
I->isConstant(), I->getLinkage(),
|
||||
(Constant*) nullptr, I->getName(),
|
||||
(GlobalVariable*) nullptr,
|
||||
I->getThreadLocalMode(),
|
||||
I->getType()->getAddressSpace());
|
||||
GV->copyAttributesFrom(&*I);
|
||||
VMap[&*I] = GV;
|
||||
for (const GlobalVariable &I : M.globals()) {
|
||||
GlobalVariable *NewGV = new GlobalVariable(
|
||||
*New, I.getValueType(), I.isConstant(), I.getLinkage(),
|
||||
(Constant *)nullptr, I.getName(), (GlobalVariable *)nullptr,
|
||||
I.getThreadLocalMode(), I.getType()->getAddressSpace());
|
||||
NewGV->copyAttributesFrom(&I);
|
||||
VMap[&I] = NewGV;
|
||||
}
|
||||
|
||||
// Loop over the functions in the module, making external functions as before
|
||||
|
@ -81,34 +77,33 @@ std::unique_ptr<Module> llvm::CloneModule(
|
|||
}
|
||||
|
||||
// Loop over the aliases in the module
|
||||
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
|
||||
I != E; ++I) {
|
||||
if (!ShouldCloneDefinition(&*I)) {
|
||||
for (const GlobalAlias &I : M.aliases()) {
|
||||
if (!ShouldCloneDefinition(&I)) {
|
||||
// An alias cannot act as an external reference, so we need to create
|
||||
// either a function or a global variable depending on the value type.
|
||||
// FIXME: Once pointee types are gone we can probably pick one or the
|
||||
// other.
|
||||
GlobalValue *GV;
|
||||
if (I->getValueType()->isFunctionTy())
|
||||
GV = Function::Create(cast<FunctionType>(I->getValueType()),
|
||||
GlobalValue::ExternalLinkage,
|
||||
I->getAddressSpace(), I->getName(), New.get());
|
||||
if (I.getValueType()->isFunctionTy())
|
||||
GV = Function::Create(cast<FunctionType>(I.getValueType()),
|
||||
GlobalValue::ExternalLinkage, I.getAddressSpace(),
|
||||
I.getName(), New.get());
|
||||
else
|
||||
GV = new GlobalVariable(
|
||||
*New, I->getValueType(), false, GlobalValue::ExternalLinkage,
|
||||
nullptr, I->getName(), nullptr,
|
||||
I->getThreadLocalMode(), I->getType()->getAddressSpace());
|
||||
VMap[&*I] = GV;
|
||||
GV = new GlobalVariable(*New, I.getValueType(), false,
|
||||
GlobalValue::ExternalLinkage, nullptr,
|
||||
I.getName(), nullptr, I.getThreadLocalMode(),
|
||||
I.getType()->getAddressSpace());
|
||||
VMap[&I] = GV;
|
||||
// We do not copy attributes (mainly because copying between different
|
||||
// kinds of globals is forbidden), but this is generally not required for
|
||||
// correctness.
|
||||
continue;
|
||||
}
|
||||
auto *GA = GlobalAlias::create(I->getValueType(),
|
||||
I->getType()->getPointerAddressSpace(),
|
||||
I->getLinkage(), I->getName(), New.get());
|
||||
GA->copyAttributesFrom(&*I);
|
||||
VMap[&*I] = GA;
|
||||
auto *GA = GlobalAlias::create(I.getValueType(),
|
||||
I.getType()->getPointerAddressSpace(),
|
||||
I.getLinkage(), I.getName(), New.get());
|
||||
GA->copyAttributesFrom(&I);
|
||||
VMap[&I] = GA;
|
||||
}
|
||||
|
||||
// Now that all of the things that global variable initializer can refer to
|
||||
|
@ -153,10 +148,9 @@ std::unique_ptr<Module> llvm::CloneModule(
|
|||
}
|
||||
|
||||
Function::arg_iterator DestI = F->arg_begin();
|
||||
for (Function::const_arg_iterator J = I.arg_begin(); J != I.arg_end();
|
||||
++J) {
|
||||
DestI->setName(J->getName());
|
||||
VMap[&*J] = &*DestI++;
|
||||
for (const Argument &J : I.args()) {
|
||||
DestI->setName(J.getName());
|
||||
VMap[&J] = &*DestI++;
|
||||
}
|
||||
|
||||
SmallVector<ReturnInst *, 8> Returns; // Ignore returns cloned.
|
||||
|
@ -170,21 +164,17 @@ std::unique_ptr<Module> llvm::CloneModule(
|
|||
}
|
||||
|
||||
// And aliases
|
||||
for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
|
||||
I != E; ++I) {
|
||||
for (const GlobalAlias &I : M.aliases()) {
|
||||
// We already dealt with undefined aliases above.
|
||||
if (!ShouldCloneDefinition(&*I))
|
||||
if (!ShouldCloneDefinition(&I))
|
||||
continue;
|
||||
GlobalAlias *GA = cast<GlobalAlias>(VMap[&*I]);
|
||||
if (const Constant *C = I->getAliasee())
|
||||
GlobalAlias *GA = cast<GlobalAlias>(VMap[&I]);
|
||||
if (const Constant *C = I.getAliasee())
|
||||
GA->setAliasee(MapValue(C, VMap));
|
||||
}
|
||||
|
||||
// And named metadata....
|
||||
for (Module::const_named_metadata_iterator I = M.named_metadata_begin(),
|
||||
E = M.named_metadata_end();
|
||||
I != E; ++I) {
|
||||
const NamedMDNode &NMD = *I;
|
||||
for (const NamedMDNode &NMD : M.named_metadata()) {
|
||||
NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName());
|
||||
for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
|
||||
NewNMD->addOperand(MapMetadata(NMD.getOperand(i), VMap));
|
||||
|
|
|
@ -285,9 +285,8 @@ bool Evaluator::getFormalParams(CallBase &CB, Function *F,
|
|||
}
|
||||
|
||||
auto ArgI = CB.arg_begin();
|
||||
for (auto ParI = FTy->param_begin(), ParE = FTy->param_end(); ParI != ParE;
|
||||
++ParI) {
|
||||
auto *ArgC = ConstantFoldLoadThroughBitcast(getVal(*ArgI), *ParI, DL);
|
||||
for (Type *PTy : FTy->params()) {
|
||||
auto *ArgC = ConstantFoldLoadThroughBitcast(getVal(*ArgI), PTy, DL);
|
||||
if (!ArgC) {
|
||||
LLVM_DEBUG(dbgs() << "Can not convert function argument.\n");
|
||||
return false;
|
||||
|
|
|
@ -293,9 +293,8 @@ static Loop *separateNestedLoop(Loop *L, BasicBlock *Preheader,
|
|||
// L is now a subloop of our outer loop.
|
||||
NewOuter->addChildLoop(L);
|
||||
|
||||
for (Loop::block_iterator I = L->block_begin(), E = L->block_end();
|
||||
I != E; ++I)
|
||||
NewOuter->addBlockEntry(*I);
|
||||
for (BasicBlock *BB : L->blocks())
|
||||
NewOuter->addBlockEntry(BB);
|
||||
|
||||
// Now reset the header in L, which had been moved by
|
||||
// SplitBlockPredecessors for the outer loop.
|
||||
|
@ -496,12 +495,12 @@ ReprocessLoop:
|
|||
// predecessors that are not in the loop. This is not valid for natural
|
||||
// loops, but can occur if the blocks are unreachable. Since they are
|
||||
// unreachable we can just shamelessly delete those CFG edges!
|
||||
for (Loop::block_iterator BB = L->block_begin(), E = L->block_end();
|
||||
BB != E; ++BB) {
|
||||
if (*BB == L->getHeader()) continue;
|
||||
for (BasicBlock *BB : L->blocks()) {
|
||||
if (BB == L->getHeader())
|
||||
continue;
|
||||
|
||||
SmallPtrSet<BasicBlock*, 4> BadPreds;
|
||||
for (BasicBlock *P : predecessors(*BB))
|
||||
for (BasicBlock *P : predecessors(BB))
|
||||
if (!L->contains(P))
|
||||
BadPreds.insert(P);
|
||||
|
||||
|
|
|
@ -663,9 +663,8 @@ void llvm::deleteDeadLoop(Loop *L, DominatorTree *DT, ScalarEvolution *SE,
|
|||
// about ordering because we already dropped the references.
|
||||
// NOTE: This iteration is safe because erasing the block does not remove
|
||||
// its entry from the loop's block list. We do that in the next section.
|
||||
for (Loop::block_iterator LpI = L->block_begin(), LpE = L->block_end();
|
||||
LpI != LpE; ++LpI)
|
||||
(*LpI)->eraseFromParent();
|
||||
for (BasicBlock *BB : L->blocks())
|
||||
BB->eraseFromParent();
|
||||
|
||||
// Finally, the blocks from loopinfo. This has to happen late because
|
||||
// otherwise our loop iterators won't work.
|
||||
|
@ -1501,10 +1500,9 @@ Loop *llvm::cloneLoop(Loop *L, Loop *PL, ValueToValueMapTy &VM,
|
|||
LPM->addLoop(New);
|
||||
|
||||
// Add all of the blocks in L to the new loop.
|
||||
for (Loop::block_iterator I = L->block_begin(), E = L->block_end();
|
||||
I != E; ++I)
|
||||
if (LI->getLoopFor(*I) == L)
|
||||
New.addBasicBlockToLoop(cast<BasicBlock>(VM[*I]), *LI);
|
||||
for (BasicBlock *BB : L->blocks())
|
||||
if (LI->getLoopFor(BB) == L)
|
||||
New.addBasicBlockToLoop(cast<BasicBlock>(VM[BB]), *LI);
|
||||
|
||||
// Add all of the subloops to the new loop.
|
||||
for (Loop *I : *L)
|
||||
|
|
|
@ -92,12 +92,12 @@ void MetaRename(Module &M,
|
|||
Renamer renamer(randSeed);
|
||||
|
||||
// Rename all aliases
|
||||
for (auto AI = M.alias_begin(), AE = M.alias_end(); AI != AE; ++AI) {
|
||||
StringRef Name = AI->getName();
|
||||
for (GlobalAlias &GA : M.aliases()) {
|
||||
StringRef Name = GA.getName();
|
||||
if (Name.startswith("llvm.") || (!Name.empty() && Name[0] == 1))
|
||||
continue;
|
||||
|
||||
AI->setName("alias");
|
||||
GA.setName("alias");
|
||||
}
|
||||
|
||||
// Rename all global variables
|
||||
|
|
Loading…
Reference in New Issue