summaryrefslogtreecommitdiff
path: root/lib/Linker
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2011-01-08 08:15:20 +0000
committerChris Lattner <sabre@nondot.org>2011-01-08 08:15:20 +0000
commitb5fa5fcecc97168a72c9533c84cf297c018b957c (patch)
tree97da777385f85e2d44f4a227621348056e460aa7 /lib/Linker
parent6ccb3652933bcdede2b2a53cf76ddd56ce9592a2 (diff)
downloadllvm-b5fa5fcecc97168a72c9533c84cf297c018b957c.tar.gz
llvm-b5fa5fcecc97168a72c9533c84cf297c018b957c.tar.bz2
llvm-b5fa5fcecc97168a72c9533c84cf297c018b957c.tar.xz
Revamp the ValueMapper interfaces in a couple ways:
1. Take a flags argument instead of a bool. This makes it more clear to the reader what it is used for. 2. Add a flag that says that "remapping a value not in the map is ok". 3. Reimplement MapValue to share a bunch of code and be a lot more efficient. For lookup failures, don't drop null values into the map. 4. Using the new flag a bunch of code can vaporize in LinkModules and LoopUnswitch, kill it. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123058 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker')
-rw-r--r--lib/Linker/LinkModules.cpp35
1 files changed, 6 insertions, 29 deletions
diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp
index d99e0a06b6..3b3d3a46bc 100644
--- a/lib/Linker/LinkModules.cpp
+++ b/lib/Linker/LinkModules.cpp
@@ -451,8 +451,7 @@ 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,
- true)));
+ ValueMap)));
}
}
@@ -814,9 +813,9 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
const GlobalVariable *SGV = I;
if (SGV->hasInitializer()) { // Only process initialized GV's
- // Figure out what the initializer looks like in the dest module...
+ // Figure out what the initializer looks like in the dest module.
Constant *SInit =
- cast<Constant>(MapValue(SGV->getInitializer(), ValueMap, true));
+ cast<Constant>(MapValue(SGV->getInitializer(), ValueMap));
// Grab destination global variable or alias.
GlobalValue *DGV = cast<GlobalValue>(ValueMap[SGV]->stripPointerCasts());
@@ -996,32 +995,10 @@ static bool LinkFunctionBody(Function *Dest, Function *Src,
// At this point, all of the instructions and values of the function are now
// copied over. The only problem is that they are still referencing values in
// 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.
- //
+ // functions and patch them up to point to the local versions.
for (Function::iterator BB = Dest->begin(), BE = Dest->end(); BB != BE; ++BB)
- 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, 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));
- }
- }
- }
+ for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
+ RemapInstruction(I, ValueMap, RF_IgnoreMissingEntries);
// There is no need to map the arguments anymore.
for (Function::arg_iterator I = Src->arg_begin(), E = Src->arg_end();