summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Linker/LinkModules.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2004-11-16 07:31:51 +0000
committerChris Lattner <sabre@nondot.org>2004-11-16 07:31:51 +0000
commit2f0557d0e4077d943c61cd364ad87e8736440e54 (patch)
tree639d3b0c90e864a7760bc343313831beb8338460 /llvm/lib/Linker/LinkModules.cpp
parent4c66d89b336e79eccd4d543cf3728b88434bd09a (diff)
downloadbcm5719-llvm-2f0557d0e4077d943c61cd364ad87e8736440e54.tar.gz
bcm5719-llvm-2f0557d0e4077d943c61cd364ad87e8736440e54.zip
Take advantage of the fact that we are allowed to clobber the input module
by splicing function bodies from the src module to the destination module. This speeds up linking quite a bit, e.g. gccld time on 176.gcc from 26s -> 20s when forming the .rbc file, with a profile build. One of the really strange but cool effects of this patch is that it speeds up the optimizers as well, from 12s -> 10.7s, presumably because of better locality??? In any case, this is just a first step. We can trivially get rid of the LocalMap now and do other simplifications. llvm-svn: 17893
Diffstat (limited to 'llvm/lib/Linker/LinkModules.cpp')
-rw-r--r--llvm/lib/Linker/LinkModules.cpp34
1 files changed, 8 insertions, 26 deletions
diff --git a/llvm/lib/Linker/LinkModules.cpp b/llvm/lib/Linker/LinkModules.cpp
index dcdcabb1dfa..a95a1c1814a 100644
--- a/llvm/lib/Linker/LinkModules.cpp
+++ b/llvm/lib/Linker/LinkModules.cpp
@@ -676,7 +676,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// fix up references to values. At this point we know that Dest is an external
// function, and that Src is not.
//
-static bool LinkFunctionBody(Function *Dest, const Function *Src,
+static bool LinkFunctionBody(Function *Dest, Function *Src,
std::map<const Value*, Value*> &GlobalMap,
std::string *Err) {
assert(Src && Dest && Dest->isExternal() && !Src->isExternal());
@@ -684,7 +684,7 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
// Go through and convert function arguments over...
Function::aiterator DI = Dest->abegin();
- for (Function::const_aiterator I = Src->abegin(), E = Src->aend();
+ for (Function::aiterator I = Src->abegin(), E = Src->aend();
I != E; ++I, ++DI) {
DI->setName(I->getName()); // Copy the name information over...
@@ -692,27 +692,8 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
LocalMap.insert(std::make_pair(I, DI));
}
- // Loop over all of the basic blocks, copying the instructions over...
- //
- for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
- // Create new basic block and add to mapping and the Dest function...
- BasicBlock *DBB = new BasicBlock(I->getName(), Dest);
- LocalMap.insert(std::make_pair(I, DBB));
-
- // Loop over all of the instructions in the src basic block, copying them
- // over. Note that this is broken in a strict sense because the cloned
- // instructions will still be referencing values in the Src module, not
- // the remapped values. In our case, however, we will not get caught and
- // so we can delay patching the values up until later...
- //
- for (BasicBlock::const_iterator II = I->begin(), IE = I->end();
- II != IE; ++II) {
- Instruction *DI = II->clone();
- DI->setName(II->getName());
- DBB->getInstList().push_back(DI);
- LocalMap.insert(std::make_pair(II, DI));
- }
- }
+ // Splice the body of the source function into the dest function.
+ Dest->getBasicBlockList().splice(Dest->end(), Src->getBasicBlockList());
// 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
@@ -723,7 +704,8 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
for (Instruction::op_iterator OI = I->op_begin(), OE = I->op_end();
OI != OE; ++OI)
- *OI = RemapOperand(*OI, LocalMap, &GlobalMap);
+ if (!isa<Instruction>(*OI) && !isa<BasicBlock>(*OI))
+ *OI = RemapOperand(*OI, LocalMap, &GlobalMap);
return false;
}
@@ -733,14 +715,14 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
// source module into the DestModule. This consists basically of copying the
// function over and fixing up references to values.
//
-static bool LinkFunctionBodies(Module *Dest, const Module *Src,
+static bool LinkFunctionBodies(Module *Dest, Module *Src,
std::map<const Value*, Value*> &ValueMap,
std::string *Err) {
// Loop over all of the functions in the src module, mapping them over as we
// go
//
- for (Module::const_iterator SF = Src->begin(), E = Src->end(); SF != E; ++SF){
+ for (Module::iterator SF = Src->begin(), E = Src->end(); SF != E; ++SF) {
if (!SF->isExternal()) { // No body if function is external
Function *DF = cast<Function>(ValueMap[SF]); // Destination function
OpenPOWER on IntegriCloud