diff options
author | Dan Gohman <gohman@apple.com> | 2010-08-26 15:41:53 +0000 |
---|---|---|
committer | Dan Gohman <gohman@apple.com> | 2010-08-26 15:41:53 +0000 |
commit | 6cb8c23db1c3becdce6dfbf1b7f1677faca4251e (patch) | |
tree | 87960d3ef2ad54c7932c0a72352fb9c01672aaf3 /lib/Linker/LinkModules.cpp | |
parent | 837bccd052ea930915173fc83e733c7d8187002d (diff) |
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
Diffstat (limited to 'lib/Linker/LinkModules.cpp')
-rw-r--r-- | lib/Linker/LinkModules.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 89f4cdc229..19d22475f6 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -460,7 +460,8 @@ static void LinkNamedMDNodes(Module *Dest, Module *Src, // Add Src elements into Dest node. for (unsigned i = 0, e = SrcNMD->getNumOperands(); i != e; ++i) DestNMD->addOperand(cast<MDNode>(MapValue(SrcNMD->getOperand(i), - ValueMap))); + ValueMap, + true))); } } @@ -823,7 +824,7 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src, if (SGV->hasInitializer()) { // Only process initialized GV's // Figure out what the initializer looks like in the dest module... Constant *SInit = - cast<Constant>(MapValue(SGV->getInitializer(), ValueMap)); + cast<Constant>(MapValue(SGV->getInitializer(), ValueMap, true)); // Grab destination global variable or alias. GlobalValue *DGV = cast<GlobalValue>(ValueMap[SGV]->stripPointerCasts()); @@ -1005,12 +1006,30 @@ static bool LinkFunctionBody(Function *Dest, Function *Src, // the Source function as operands. Loop through all of the operands of the // functions and patch them up to point to the local versions... // + // This is the same as RemapInstruction, except that it avoids remapping + // instruction and basic block operands. + // for (Function::iterator BB = Dest->begin(), BE = Dest->end(); BB != BE; ++BB) - for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) + for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) { + // Remap operands. for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end(); OI != OE; ++OI) if (!isa<Instruction>(*OI) && !isa<BasicBlock>(*OI)) - *OI = MapValue(*OI, ValueMap); + *OI = MapValue(*OI, ValueMap, true); + + // Remap attached metadata. + SmallVector<std::pair<unsigned, MDNode *>, 4> MDs; + I->getAllMetadata(MDs); + for (SmallVectorImpl<std::pair<unsigned, MDNode *> >::iterator + MI = MDs.begin(), ME = MDs.end(); MI != ME; ++MI) { + Value *Old = MI->second; + if (!isa<Instruction>(Old) && !isa<BasicBlock>(Old)) { + Value *New = MapValue(Old, ValueMap, true); + if (New != Old) + I->setMetadata(MI->first, cast<MDNode>(New)); + } + } + } // There is no need to map the arguments anymore. for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end(); |