mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-16 12:24:03 +00:00
Reapply r112091 and r111922, support for metadata linking, with a
fix: add a flag to MapValue and friends which indicates whether any module-level mappings are being made. In the common case of inlining, no module-level mappings are needed, so MapValue doesn't need to examine non-function-local metadata, which can be very expensive in the case of a large module with really deep metadata (e.g. a large C++ program compiled with -g). This flag is a little awkward; perhaps eventually it can be moved into the ClonedCodeInfo class. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@112190 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -89,7 +89,8 @@ Module *llvm::CloneModule(const Module *M,
|
||||
GlobalVariable *GV = cast<GlobalVariable>(VMap[I]);
|
||||
if (I->hasInitializer())
|
||||
GV->setInitializer(cast<Constant>(MapValue(I->getInitializer(),
|
||||
VMap)));
|
||||
VMap,
|
||||
true)));
|
||||
GV->setLinkage(I->getLinkage());
|
||||
GV->setThreadLocal(I->isThreadLocal());
|
||||
GV->setConstant(I->isConstant());
|
||||
@ -108,7 +109,7 @@ Module *llvm::CloneModule(const Module *M,
|
||||
}
|
||||
|
||||
SmallVector<ReturnInst*, 8> Returns; // Ignore returns cloned.
|
||||
CloneFunctionInto(F, I, VMap, Returns);
|
||||
CloneFunctionInto(F, I, VMap, /*ModuleLevelChanges=*/true, Returns);
|
||||
}
|
||||
|
||||
F->setLinkage(I->getLinkage());
|
||||
@ -120,7 +121,7 @@ Module *llvm::CloneModule(const Module *M,
|
||||
GlobalAlias *GA = cast<GlobalAlias>(VMap[I]);
|
||||
GA->setLinkage(I->getLinkage());
|
||||
if (const Constant* C = I->getAliasee())
|
||||
GA->setAliasee(cast<Constant>(MapValue(C, VMap)));
|
||||
GA->setAliasee(cast<Constant>(MapValue(C, VMap, true)));
|
||||
}
|
||||
|
||||
// And named metadata....
|
||||
@ -129,23 +130,8 @@ Module *llvm::CloneModule(const Module *M,
|
||||
const NamedMDNode &NMD = *I;
|
||||
NamedMDNode *NewNMD = New->getOrInsertNamedMetadata(NMD.getName());
|
||||
for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
|
||||
NewNMD->addOperand(cast<MDNode>(MapValue(NMD.getOperand(i), VMap)));
|
||||
NewNMD->addOperand(cast<MDNode>(MapValue(NMD.getOperand(i), VMap, true)));
|
||||
}
|
||||
|
||||
// Update metadata attach with instructions.
|
||||
for (Module::iterator MI = New->begin(), ME = New->end(); MI != ME; ++MI)
|
||||
for (Function::iterator FI = MI->begin(), FE = MI->end();
|
||||
FI != FE; ++FI)
|
||||
for (BasicBlock::iterator BI = FI->begin(), BE = FI->end();
|
||||
BI != BE; ++BI) {
|
||||
SmallVector<std::pair<unsigned, MDNode *>, 4 > MDs;
|
||||
BI->getAllMetadata(MDs);
|
||||
for (SmallVector<std::pair<unsigned, MDNode *>, 4>::iterator
|
||||
MDI = MDs.begin(), MDE = MDs.end(); MDI != MDE; ++MDI) {
|
||||
Value *MappedValue = MapValue(MDI->second, VMap);
|
||||
if (MDI->second != MappedValue && MappedValue)
|
||||
BI->setMetadata(MDI->first, cast<MDNode>(MappedValue));
|
||||
}
|
||||
}
|
||||
return New;
|
||||
}
|
||||
|
Reference in New Issue
Block a user