summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Linker
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-08-25 21:36:50 +0000
committerDan Gohman <gohman@apple.com>2010-08-25 21:36:50 +0000
commitfd824487a37a62515d895de59880e05f5bbdba17 (patch)
tree2c427a4c6f3bb48671d8949eee1b24374213e213 /llvm/lib/Linker
parentd4085f6e9104aa9b85b6bd8cc7616090e1085c25 (diff)
downloadbcm5719-llvm-fd824487a37a62515d895de59880e05f5bbdba17.tar.gz
bcm5719-llvm-fd824487a37a62515d895de59880e05f5bbdba17.zip
Remap metadata attached to instructions when remapping individual
instructions, not when remapping modules. llvm-svn: 112091
Diffstat (limited to 'llvm/lib/Linker')
-rw-r--r--llvm/lib/Linker/LinkModules.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index 89f4cdc2296..07089f7feec 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -1005,13 +1005,31 @@ 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);
+ // 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);
+ 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();
I != E; ++I)
OpenPOWER on IntegriCloud