aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/CloneModule.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneModule.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/CloneModule.cpp72
1 files changed, 31 insertions, 41 deletions
diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp
index eb226b9b246d..200deca4b317 100644
--- a/llvm/lib/Transforms/Utils/CloneModule.cpp
+++ b/llvm/lib/Transforms/Utils/CloneModule.cpp
@@ -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));