Updates to move some header files out of include/llvm/Transforms into

the Scalar and Utils subdirectories


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2523 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2002-05-07 18:36:35 +00:00
parent efbe5d682b
commit c8cc4cb03b
15 changed files with 130 additions and 121 deletions

View File

@ -6,7 +6,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/Dominators.h"
#include "llvm/Transforms/UnifyFunctionExitNodes.h" #include "llvm/Transforms/Scalar/UnifyFunctionExitNodes.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "Support/DepthFirstIterator.h" #include "Support/DepthFirstIterator.h"
#include "Support/STLExtras.h" #include "Support/STLExtras.h"

View File

@ -7,7 +7,7 @@
#include "Interpreter.h" #include "Interpreter.h"
#include "llvm/Bytecode/Reader.h" #include "llvm/Bytecode/Reader.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include "llvm/Transforms/Linker.h" #include "llvm/Transforms/Utils/Linker.h"
#include <algorithm> #include <algorithm>
using std::string; using std::string;
using std::cout; using std::cout;

View File

@ -5,11 +5,11 @@
// Specifically, this: // Specifically, this:
// * Merges global variables between the two modules // * Merges global variables between the two modules
// * Uninit + Uninit = Init, Init + Uninit = Init, Init + Init = Error if != // * Uninit + Uninit = Init, Init + Uninit = Init, Init + Init = Error if !=
// * Merges methods between two modules // * Merges functions between two modules
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/Linker.h" #include "llvm/Transforms/Utils/Linker.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
@ -235,8 +235,8 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
} }
// LinkFunctionProtos - Link the functions together between the two modules, // LinkFunctionProtos - Link the functions together between the two modules,
// without doing method bodies... this just adds external method prototypes to // without doing function bodies... this just adds external function prototypes
// the Dest function... // to the Dest function...
// //
static bool LinkFunctionProtos(Module *Dest, const Module *Src, static bool LinkFunctionProtos(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap, map<const Value*, Value*> &ValueMap,
@ -245,14 +245,15 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// level symbol table... // level symbol table...
SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0; SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0;
// Loop over all of the methods in the src module, mapping them over as we go // Loop over all of the functions in the src module, mapping them over as we
// go
// //
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Function *SM = *I; // SrcFunction const Function *SM = *I; // SrcFunction
Value *V; Value *V;
// If the method has a name, and that name is already in use in the // If the function has a name, and that name is already in use in the Dest
// Dest module, make sure that the name is a compatible method... // module, make sure that the name is a compatible function...
// //
if (SM->hasExternalLinkage() && SM->hasName() && if (SM->hasExternalLinkage() && SM->hasName() &&
(V = ST->lookup(SM->getType(), SM->getName())) && (V = ST->lookup(SM->getType(), SM->getName())) &&
@ -263,7 +264,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// //
Function *DM = cast<Function>(V); // DestFunction Function *DM = cast<Function>(V); // DestFunction
// Check to make sure the method is not defined in both modules... // Check to make sure the function is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal()) if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Function '" + return Error(Err, "Function '" +
SM->getFunctionType()->getDescription() + "':\"" + SM->getFunctionType()->getDescription() + "':\"" +
@ -272,13 +273,13 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Otherwise, just remember this mapping... // Otherwise, just remember this mapping...
ValueMap.insert(std::make_pair(SM, DM)); ValueMap.insert(std::make_pair(SM, DM));
} else { } else {
// Function does not already exist, simply insert an external method // Function does not already exist, simply insert an external function
// signature identical to SM into the dest module... // signature identical to SM into the dest module...
Function *DM = new Function(SM->getFunctionType(), Function *DM = new Function(SM->getFunctionType(),
SM->hasInternalLinkage(), SM->hasInternalLinkage(),
SM->getName()); SM->getName());
// Add the method signature to the dest module... // Add the function signature to the dest module...
Dest->getFunctionList().push_back(DM); Dest->getFunctionList().push_back(DM);
// ... and remember this mapping... // ... and remember this mapping...
@ -288,23 +289,23 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
return false; return false;
} }
// LinkFunctionBody - Copy the source method over into the dest method // LinkFunctionBody - Copy the source function over into the dest function and
// and fix up references to values. At this point we know that Dest // fix up references to values. At this point we know that Dest is an external
// is an external method, and that Src is not. // function, and that Src is not.
// //
static bool LinkFunctionBody(Function *Dest, const Function *Src, static bool LinkFunctionBody(Function *Dest, const Function *Src,
const map<const Value*, Value*> &GlobalMap, const map<const Value*, Value*> &GlobalMap,
string *Err = 0) { string *Err = 0) {
assert(Src && Dest && Dest->isExternal() && !Src->isExternal()); assert(Src && Dest && Dest->isExternal() && !Src->isExternal());
map<const Value*, Value*> LocalMap; // Map for method local values map<const Value*, Value*> LocalMap; // Map for function local values
// Go through and convert method arguments over... // Go through and convert function arguments over...
for (Function::ArgumentListType::const_iterator for (Function::ArgumentListType::const_iterator
I = Src->getArgumentList().begin(), I = Src->getArgumentList().begin(),
E = Src->getArgumentList().end(); I != E; ++I) { E = Src->getArgumentList().end(); I != E; ++I) {
const Argument *SMA = *I; const Argument *SMA = *I;
// Create the new method argument and add to the dest method... // Create the new function argument and add to the dest function...
Argument *DMA = new Argument(SMA->getType(), SMA->getName()); Argument *DMA = new Argument(SMA->getType(), SMA->getName());
Dest->getArgumentList().push_back(DMA); Dest->getArgumentList().push_back(DMA);
@ -317,7 +318,7 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const BasicBlock *SBB = *I; const BasicBlock *SBB = *I;
// Create new basic block and add to mapping and the Dest method... // Create new basic block and add to mapping and the Dest function...
BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest); BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest);
LocalMap.insert(std::make_pair(SBB, DBB)); LocalMap.insert(std::make_pair(SBB, DBB));
@ -337,10 +338,10 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
} }
} }
// At this point, all of the instructions and values of the method are now // 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 // copied over. The only problem is that they are still referencing values in
// in the Source method as operands. Loop through all of the operands of the // the Source function as operands. Loop through all of the operands of the
// methods and patch them up to point to the local versions... // functions and patch them up to point to the local versions...
// //
for (Function::iterator BI = Dest->begin(), BE = Dest->end(); for (Function::iterator BI = Dest->begin(), BE = Dest->end();
BI != BE; ++BI) { BI != BE; ++BI) {
@ -358,20 +359,21 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
} }
// LinkFunctionBodies - Link in the method bodies that are defined in the source // LinkFunctionBodies - Link in the function bodies that are defined in the
// module into the DestModule. This consists basically of copying the method // source module into the DestModule. This consists basically of copying the
// over and fixing up references to values. // function over and fixing up references to values.
// //
static bool LinkFunctionBodies(Module *Dest, const Module *Src, static bool LinkFunctionBodies(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap, map<const Value*, Value*> &ValueMap,
string *Err = 0) { string *Err = 0) {
// Loop over all of the methods in the src module, mapping them over as we go // Loop over all of the functions in the src module, mapping them over as we
// go
// //
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Function *SM = *I; // Source Function const Function *SM = *I; // Source Function
if (!SM->isExternal()) { // No body if method is external if (!SM->isExternal()) { // No body if function is external
Function *DM = cast<Function>(ValueMap[SM]); // Destination method Function *DM = cast<Function>(ValueMap[SM]); // Destination function
// DM not external SM external? // DM not external SM external?
if (!DM->isExternal()) { if (!DM->isExternal()) {
@ -417,16 +419,17 @@ bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0) {
// //
if (LinkGlobalInits(Dest, Src, ValueMap, ErrorMsg)) return true; if (LinkGlobalInits(Dest, Src, ValueMap, ErrorMsg)) return true;
// Link the methods together between the two modules, without doing method // Link the functions together between the two modules, without doing function
// bodies... this just adds external method prototypes to the Dest method... // bodies... this just adds external function prototypes to the Dest
// We do this so that when we begin processing method bodies, all of the // function... We do this so that when we begin processing function bodies,
// global values that may be referenced are available in our ValueMap. // all of the global values that may be referenced are available in our
// ValueMap.
// //
if (LinkFunctionProtos(Dest, Src, ValueMap, ErrorMsg)) return true; if (LinkFunctionProtos(Dest, Src, ValueMap, ErrorMsg)) return true;
// Link in the method bodies that are defined in the source module into the // Link in the function bodies that are defined in the source module into the
// DestModule. This consists basically of copying the method over and fixing // DestModule. This consists basically of copying the function over and
// up references to values. // fixing up references to values.
// //
if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true; if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true;

View File

@ -10,7 +10,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/IPO/PoolAllocate.h" #include "llvm/Transforms/IPO/PoolAllocate.h"
#include "llvm/Transforms/CloneFunction.h" #include "llvm/Transforms/Utils/CloneFunction.h"
#include "llvm/Analysis/DataStructureGraph.h" #include "llvm/Analysis/DataStructureGraph.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Function.h" #include "llvm/Function.h"

View File

@ -25,7 +25,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/Instrumentation/ProfilePaths.h" #include "llvm/Transforms/Instrumentation/ProfilePaths.h"
#include "llvm/Transforms/UnifyFunctionExitNodes.h" #include "llvm/Transforms/Scalar/UnifyFunctionExitNodes.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"

View File

@ -14,7 +14,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/SymbolStripping.h" #include "llvm/Transforms/Scalar/SymbolStripping.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/SymbolTable.h" #include "llvm/SymbolTable.h"

View File

@ -1,7 +1,7 @@
// FIXME: document // FIXME: document
#include "llvm/Transforms/CloneFunction.h" #include "llvm/Transforms/Utils/CloneFunction.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
#include "llvm/Instruction.h" #include "llvm/Instruction.h"

View File

@ -5,11 +5,11 @@
// Specifically, this: // Specifically, this:
// * Merges global variables between the two modules // * Merges global variables between the two modules
// * Uninit + Uninit = Init, Init + Uninit = Init, Init + Init = Error if != // * Uninit + Uninit = Init, Init + Uninit = Init, Init + Init = Error if !=
// * Merges methods between two modules // * Merges functions between two modules
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/Linker.h" #include "llvm/Transforms/Utils/Linker.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
@ -235,8 +235,8 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
} }
// LinkFunctionProtos - Link the functions together between the two modules, // LinkFunctionProtos - Link the functions together between the two modules,
// without doing method bodies... this just adds external method prototypes to // without doing function bodies... this just adds external function prototypes
// the Dest function... // to the Dest function...
// //
static bool LinkFunctionProtos(Module *Dest, const Module *Src, static bool LinkFunctionProtos(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap, map<const Value*, Value*> &ValueMap,
@ -245,14 +245,15 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// level symbol table... // level symbol table...
SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0; SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0;
// Loop over all of the methods in the src module, mapping them over as we go // Loop over all of the functions in the src module, mapping them over as we
// go
// //
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Function *SM = *I; // SrcFunction const Function *SM = *I; // SrcFunction
Value *V; Value *V;
// If the method has a name, and that name is already in use in the // If the function has a name, and that name is already in use in the Dest
// Dest module, make sure that the name is a compatible method... // module, make sure that the name is a compatible function...
// //
if (SM->hasExternalLinkage() && SM->hasName() && if (SM->hasExternalLinkage() && SM->hasName() &&
(V = ST->lookup(SM->getType(), SM->getName())) && (V = ST->lookup(SM->getType(), SM->getName())) &&
@ -263,7 +264,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// //
Function *DM = cast<Function>(V); // DestFunction Function *DM = cast<Function>(V); // DestFunction
// Check to make sure the method is not defined in both modules... // Check to make sure the function is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal()) if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Function '" + return Error(Err, "Function '" +
SM->getFunctionType()->getDescription() + "':\"" + SM->getFunctionType()->getDescription() + "':\"" +
@ -272,13 +273,13 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Otherwise, just remember this mapping... // Otherwise, just remember this mapping...
ValueMap.insert(std::make_pair(SM, DM)); ValueMap.insert(std::make_pair(SM, DM));
} else { } else {
// Function does not already exist, simply insert an external method // Function does not already exist, simply insert an external function
// signature identical to SM into the dest module... // signature identical to SM into the dest module...
Function *DM = new Function(SM->getFunctionType(), Function *DM = new Function(SM->getFunctionType(),
SM->hasInternalLinkage(), SM->hasInternalLinkage(),
SM->getName()); SM->getName());
// Add the method signature to the dest module... // Add the function signature to the dest module...
Dest->getFunctionList().push_back(DM); Dest->getFunctionList().push_back(DM);
// ... and remember this mapping... // ... and remember this mapping...
@ -288,23 +289,23 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
return false; return false;
} }
// LinkFunctionBody - Copy the source method over into the dest method // LinkFunctionBody - Copy the source function over into the dest function and
// and fix up references to values. At this point we know that Dest // fix up references to values. At this point we know that Dest is an external
// is an external method, and that Src is not. // function, and that Src is not.
// //
static bool LinkFunctionBody(Function *Dest, const Function *Src, static bool LinkFunctionBody(Function *Dest, const Function *Src,
const map<const Value*, Value*> &GlobalMap, const map<const Value*, Value*> &GlobalMap,
string *Err = 0) { string *Err = 0) {
assert(Src && Dest && Dest->isExternal() && !Src->isExternal()); assert(Src && Dest && Dest->isExternal() && !Src->isExternal());
map<const Value*, Value*> LocalMap; // Map for method local values map<const Value*, Value*> LocalMap; // Map for function local values
// Go through and convert method arguments over... // Go through and convert function arguments over...
for (Function::ArgumentListType::const_iterator for (Function::ArgumentListType::const_iterator
I = Src->getArgumentList().begin(), I = Src->getArgumentList().begin(),
E = Src->getArgumentList().end(); I != E; ++I) { E = Src->getArgumentList().end(); I != E; ++I) {
const Argument *SMA = *I; const Argument *SMA = *I;
// Create the new method argument and add to the dest method... // Create the new function argument and add to the dest function...
Argument *DMA = new Argument(SMA->getType(), SMA->getName()); Argument *DMA = new Argument(SMA->getType(), SMA->getName());
Dest->getArgumentList().push_back(DMA); Dest->getArgumentList().push_back(DMA);
@ -317,7 +318,7 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const BasicBlock *SBB = *I; const BasicBlock *SBB = *I;
// Create new basic block and add to mapping and the Dest method... // Create new basic block and add to mapping and the Dest function...
BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest); BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest);
LocalMap.insert(std::make_pair(SBB, DBB)); LocalMap.insert(std::make_pair(SBB, DBB));
@ -337,10 +338,10 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
} }
} }
// At this point, all of the instructions and values of the method are now // 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 // copied over. The only problem is that they are still referencing values in
// in the Source method as operands. Loop through all of the operands of the // the Source function as operands. Loop through all of the operands of the
// methods and patch them up to point to the local versions... // functions and patch them up to point to the local versions...
// //
for (Function::iterator BI = Dest->begin(), BE = Dest->end(); for (Function::iterator BI = Dest->begin(), BE = Dest->end();
BI != BE; ++BI) { BI != BE; ++BI) {
@ -358,20 +359,21 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
} }
// LinkFunctionBodies - Link in the method bodies that are defined in the source // LinkFunctionBodies - Link in the function bodies that are defined in the
// module into the DestModule. This consists basically of copying the method // source module into the DestModule. This consists basically of copying the
// over and fixing up references to values. // function over and fixing up references to values.
// //
static bool LinkFunctionBodies(Module *Dest, const Module *Src, static bool LinkFunctionBodies(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap, map<const Value*, Value*> &ValueMap,
string *Err = 0) { string *Err = 0) {
// Loop over all of the methods in the src module, mapping them over as we go // Loop over all of the functions in the src module, mapping them over as we
// go
// //
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Function *SM = *I; // Source Function const Function *SM = *I; // Source Function
if (!SM->isExternal()) { // No body if method is external if (!SM->isExternal()) { // No body if function is external
Function *DM = cast<Function>(ValueMap[SM]); // Destination method Function *DM = cast<Function>(ValueMap[SM]); // Destination function
// DM not external SM external? // DM not external SM external?
if (!DM->isExternal()) { if (!DM->isExternal()) {
@ -417,16 +419,17 @@ bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0) {
// //
if (LinkGlobalInits(Dest, Src, ValueMap, ErrorMsg)) return true; if (LinkGlobalInits(Dest, Src, ValueMap, ErrorMsg)) return true;
// Link the methods together between the two modules, without doing method // Link the functions together between the two modules, without doing function
// bodies... this just adds external method prototypes to the Dest method... // bodies... this just adds external function prototypes to the Dest
// We do this so that when we begin processing method bodies, all of the // function... We do this so that when we begin processing function bodies,
// global values that may be referenced are available in our ValueMap. // all of the global values that may be referenced are available in our
// ValueMap.
// //
if (LinkFunctionProtos(Dest, Src, ValueMap, ErrorMsg)) return true; if (LinkFunctionProtos(Dest, Src, ValueMap, ErrorMsg)) return true;
// Link in the method bodies that are defined in the source module into the // Link in the function bodies that are defined in the source module into the
// DestModule. This consists basically of copying the method over and fixing // DestModule. This consists basically of copying the function over and
// up references to values. // fixing up references to values.
// //
if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true; if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true;

View File

@ -5,7 +5,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/UnifyFunctionExitNodes.h" #include "llvm/Transforms/Scalar/UnifyFunctionExitNodes.h"
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/iTerminators.h" #include "llvm/iTerminators.h"

View File

@ -6,7 +6,7 @@
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Analysis/Dominators.h" #include "llvm/Analysis/Dominators.h"
#include "llvm/Transforms/UnifyFunctionExitNodes.h" #include "llvm/Transforms/Scalar/UnifyFunctionExitNodes.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
#include "Support/DepthFirstIterator.h" #include "Support/DepthFirstIterator.h"
#include "Support/STLExtras.h" #include "Support/STLExtras.h"

View File

@ -5,11 +5,11 @@
// Specifically, this: // Specifically, this:
// * Merges global variables between the two modules // * Merges global variables between the two modules
// * Uninit + Uninit = Init, Init + Uninit = Init, Init + Init = Error if != // * Uninit + Uninit = Init, Init + Uninit = Init, Init + Init = Error if !=
// * Merges methods between two modules // * Merges functions between two modules
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/Linker.h" #include "llvm/Transforms/Utils/Linker.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/Function.h" #include "llvm/Function.h"
#include "llvm/BasicBlock.h" #include "llvm/BasicBlock.h"
@ -235,8 +235,8 @@ static bool LinkGlobalInits(Module *Dest, const Module *Src,
} }
// LinkFunctionProtos - Link the functions together between the two modules, // LinkFunctionProtos - Link the functions together between the two modules,
// without doing method bodies... this just adds external method prototypes to // without doing function bodies... this just adds external function prototypes
// the Dest function... // to the Dest function...
// //
static bool LinkFunctionProtos(Module *Dest, const Module *Src, static bool LinkFunctionProtos(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap, map<const Value*, Value*> &ValueMap,
@ -245,14 +245,15 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// level symbol table... // level symbol table...
SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0; SymbolTable *ST = Src->getSymbolTable() ? Dest->getSymbolTableSure() : 0;
// Loop over all of the methods in the src module, mapping them over as we go // Loop over all of the functions in the src module, mapping them over as we
// go
// //
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Function *SM = *I; // SrcFunction const Function *SM = *I; // SrcFunction
Value *V; Value *V;
// If the method has a name, and that name is already in use in the // If the function has a name, and that name is already in use in the Dest
// Dest module, make sure that the name is a compatible method... // module, make sure that the name is a compatible function...
// //
if (SM->hasExternalLinkage() && SM->hasName() && if (SM->hasExternalLinkage() && SM->hasName() &&
(V = ST->lookup(SM->getType(), SM->getName())) && (V = ST->lookup(SM->getType(), SM->getName())) &&
@ -263,7 +264,7 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// //
Function *DM = cast<Function>(V); // DestFunction Function *DM = cast<Function>(V); // DestFunction
// Check to make sure the method is not defined in both modules... // Check to make sure the function is not defined in both modules...
if (!SM->isExternal() && !DM->isExternal()) if (!SM->isExternal() && !DM->isExternal())
return Error(Err, "Function '" + return Error(Err, "Function '" +
SM->getFunctionType()->getDescription() + "':\"" + SM->getFunctionType()->getDescription() + "':\"" +
@ -272,13 +273,13 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
// Otherwise, just remember this mapping... // Otherwise, just remember this mapping...
ValueMap.insert(std::make_pair(SM, DM)); ValueMap.insert(std::make_pair(SM, DM));
} else { } else {
// Function does not already exist, simply insert an external method // Function does not already exist, simply insert an external function
// signature identical to SM into the dest module... // signature identical to SM into the dest module...
Function *DM = new Function(SM->getFunctionType(), Function *DM = new Function(SM->getFunctionType(),
SM->hasInternalLinkage(), SM->hasInternalLinkage(),
SM->getName()); SM->getName());
// Add the method signature to the dest module... // Add the function signature to the dest module...
Dest->getFunctionList().push_back(DM); Dest->getFunctionList().push_back(DM);
// ... and remember this mapping... // ... and remember this mapping...
@ -288,23 +289,23 @@ static bool LinkFunctionProtos(Module *Dest, const Module *Src,
return false; return false;
} }
// LinkFunctionBody - Copy the source method over into the dest method // LinkFunctionBody - Copy the source function over into the dest function and
// and fix up references to values. At this point we know that Dest // fix up references to values. At this point we know that Dest is an external
// is an external method, and that Src is not. // function, and that Src is not.
// //
static bool LinkFunctionBody(Function *Dest, const Function *Src, static bool LinkFunctionBody(Function *Dest, const Function *Src,
const map<const Value*, Value*> &GlobalMap, const map<const Value*, Value*> &GlobalMap,
string *Err = 0) { string *Err = 0) {
assert(Src && Dest && Dest->isExternal() && !Src->isExternal()); assert(Src && Dest && Dest->isExternal() && !Src->isExternal());
map<const Value*, Value*> LocalMap; // Map for method local values map<const Value*, Value*> LocalMap; // Map for function local values
// Go through and convert method arguments over... // Go through and convert function arguments over...
for (Function::ArgumentListType::const_iterator for (Function::ArgumentListType::const_iterator
I = Src->getArgumentList().begin(), I = Src->getArgumentList().begin(),
E = Src->getArgumentList().end(); I != E; ++I) { E = Src->getArgumentList().end(); I != E; ++I) {
const Argument *SMA = *I; const Argument *SMA = *I;
// Create the new method argument and add to the dest method... // Create the new function argument and add to the dest function...
Argument *DMA = new Argument(SMA->getType(), SMA->getName()); Argument *DMA = new Argument(SMA->getType(), SMA->getName());
Dest->getArgumentList().push_back(DMA); Dest->getArgumentList().push_back(DMA);
@ -317,7 +318,7 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { for (Function::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const BasicBlock *SBB = *I; const BasicBlock *SBB = *I;
// Create new basic block and add to mapping and the Dest method... // Create new basic block and add to mapping and the Dest function...
BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest); BasicBlock *DBB = new BasicBlock(SBB->getName(), Dest);
LocalMap.insert(std::make_pair(SBB, DBB)); LocalMap.insert(std::make_pair(SBB, DBB));
@ -337,10 +338,10 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
} }
} }
// At this point, all of the instructions and values of the method are now // 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 // copied over. The only problem is that they are still referencing values in
// in the Source method as operands. Loop through all of the operands of the // the Source function as operands. Loop through all of the operands of the
// methods and patch them up to point to the local versions... // functions and patch them up to point to the local versions...
// //
for (Function::iterator BI = Dest->begin(), BE = Dest->end(); for (Function::iterator BI = Dest->begin(), BE = Dest->end();
BI != BE; ++BI) { BI != BE; ++BI) {
@ -358,20 +359,21 @@ static bool LinkFunctionBody(Function *Dest, const Function *Src,
} }
// LinkFunctionBodies - Link in the method bodies that are defined in the source // LinkFunctionBodies - Link in the function bodies that are defined in the
// module into the DestModule. This consists basically of copying the method // source module into the DestModule. This consists basically of copying the
// over and fixing up references to values. // function over and fixing up references to values.
// //
static bool LinkFunctionBodies(Module *Dest, const Module *Src, static bool LinkFunctionBodies(Module *Dest, const Module *Src,
map<const Value*, Value*> &ValueMap, map<const Value*, Value*> &ValueMap,
string *Err = 0) { string *Err = 0) {
// Loop over all of the methods in the src module, mapping them over as we go // Loop over all of the functions in the src module, mapping them over as we
// go
// //
for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) { for (Module::const_iterator I = Src->begin(), E = Src->end(); I != E; ++I) {
const Function *SM = *I; // Source Function const Function *SM = *I; // Source Function
if (!SM->isExternal()) { // No body if method is external if (!SM->isExternal()) { // No body if function is external
Function *DM = cast<Function>(ValueMap[SM]); // Destination method Function *DM = cast<Function>(ValueMap[SM]); // Destination function
// DM not external SM external? // DM not external SM external?
if (!DM->isExternal()) { if (!DM->isExternal()) {
@ -417,16 +419,17 @@ bool LinkModules(Module *Dest, const Module *Src, string *ErrorMsg = 0) {
// //
if (LinkGlobalInits(Dest, Src, ValueMap, ErrorMsg)) return true; if (LinkGlobalInits(Dest, Src, ValueMap, ErrorMsg)) return true;
// Link the methods together between the two modules, without doing method // Link the functions together between the two modules, without doing function
// bodies... this just adds external method prototypes to the Dest method... // bodies... this just adds external function prototypes to the Dest
// We do this so that when we begin processing method bodies, all of the // function... We do this so that when we begin processing function bodies,
// global values that may be referenced are available in our ValueMap. // all of the global values that may be referenced are available in our
// ValueMap.
// //
if (LinkFunctionProtos(Dest, Src, ValueMap, ErrorMsg)) return true; if (LinkFunctionProtos(Dest, Src, ValueMap, ErrorMsg)) return true;
// Link in the method bodies that are defined in the source module into the // Link in the function bodies that are defined in the source module into the
// DestModule. This consists basically of copying the method over and fixing // DestModule. This consists basically of copying the function over and
// up references to values. // fixing up references to values.
// //
if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true; if (LinkFunctionBodies(Dest, Src, ValueMap, ErrorMsg)) return true;

View File

@ -14,14 +14,14 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/Linker.h" #include "llvm/Transforms/Utils/Linker.h"
#include "llvm/Module.h" #include "llvm/Module.h"
#include "llvm/PassManager.h" #include "llvm/PassManager.h"
#include "llvm/Bytecode/Reader.h" #include "llvm/Bytecode/Reader.h"
#include "llvm/Bytecode/WriteBytecodePass.h" #include "llvm/Bytecode/WriteBytecodePass.h"
#include "llvm/Transforms/SymbolStripping.h"
#include "llvm/Transforms/CleanupGCCOutput.h" #include "llvm/Transforms/CleanupGCCOutput.h"
#include "llvm/Transforms/ConstantMerge.h" #include "llvm/Transforms/ConstantMerge.h"
#include "llvm/Transforms/ScalarSymbolStripping.h"
#include "llvm/Transforms/IPO/GlobalDCE.h" #include "llvm/Transforms/IPO/GlobalDCE.h"
#include "llvm/Transforms/IPO/Internalize.h" #include "llvm/Transforms/IPO/Internalize.h"
#include "Support/CommandLine.h" #include "Support/CommandLine.h"

View File

@ -9,7 +9,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/Linker.h" #include "llvm/Transforms/Utils/Linker.h"
#include "llvm/Bytecode/Reader.h" #include "llvm/Bytecode/Reader.h"
#include "llvm/Bytecode/Writer.h" #include "llvm/Bytecode/Writer.h"
#include "llvm/Module.h" #include "llvm/Module.h"

View File

@ -9,7 +9,7 @@
// //
//===----------------------------------------------------------------------===// //===----------------------------------------------------------------------===//
#include "llvm/Transforms/Linker.h" #include "llvm/Transforms/Utils/Linker.h"
#include "llvm/Bytecode/Reader.h" #include "llvm/Bytecode/Reader.h"
#include "llvm/Bytecode/Writer.h" #include "llvm/Bytecode/Writer.h"
#include "llvm/Module.h" #include "llvm/Module.h"

View File

@ -12,24 +12,24 @@
#include "llvm/Bytecode/WriteBytecodePass.h" #include "llvm/Bytecode/WriteBytecodePass.h"
#include "llvm/Assembly/PrintModulePass.h" #include "llvm/Assembly/PrintModulePass.h"
#include "llvm/Analysis/Verifier.h" #include "llvm/Analysis/Verifier.h"
#include "llvm/Transforms/UnifyFunctionExitNodes.h"
#include "llvm/Transforms/ConstantMerge.h" #include "llvm/Transforms/ConstantMerge.h"
#include "llvm/Transforms/CleanupGCCOutput.h" #include "llvm/Transforms/CleanupGCCOutput.h"
#include "llvm/Transforms/LevelChange.h" #include "llvm/Transforms/LevelChange.h"
#include "llvm/Transforms/FunctionInlining.h" #include "llvm/Transforms/FunctionInlining.h"
#include "llvm/Transforms/SymbolStripping.h"
#include "llvm/Transforms/ChangeAllocations.h" #include "llvm/Transforms/ChangeAllocations.h"
#include "llvm/Transforms/IPO/SimpleStructMutation.h" #include "llvm/Transforms/IPO/SimpleStructMutation.h"
#include "llvm/Transforms/IPO/Internalize.h" #include "llvm/Transforms/IPO/Internalize.h"
#include "llvm/Transforms/IPO/GlobalDCE.h" #include "llvm/Transforms/IPO/GlobalDCE.h"
#include "llvm/Transforms/IPO/PoolAllocate.h" #include "llvm/Transforms/IPO/PoolAllocate.h"
#include "llvm/Transforms/Scalar/DCE.h"
#include "llvm/Transforms/Scalar/ConstantProp.h" #include "llvm/Transforms/Scalar/ConstantProp.h"
#include "llvm/Transforms/Scalar/DCE.h"
#include "llvm/Transforms/Scalar/DecomposeMultiDimRefs.h"
#include "llvm/Transforms/Scalar/GCSE.h" #include "llvm/Transforms/Scalar/GCSE.h"
#include "llvm/Transforms/Scalar/IndVarSimplify.h" #include "llvm/Transforms/Scalar/IndVarSimplify.h"
#include "llvm/Transforms/Scalar/InstructionCombining.h" #include "llvm/Transforms/Scalar/InstructionCombining.h"
#include "llvm/Transforms/Scalar/PromoteMemoryToRegister.h" #include "llvm/Transforms/Scalar/PromoteMemoryToRegister.h"
#include "llvm/Transforms/Scalar/DecomposeMultiDimRefs.h" #include "llvm/Transforms/Scalar/SymbolStripping.h"
#include "llvm/Transforms/Scalar/UnifyFunctionExitNodes.h"
#include "llvm/Transforms/Instrumentation/TraceValues.h" #include "llvm/Transforms/Instrumentation/TraceValues.h"
#include "llvm/Transforms/Instrumentation/ProfilePaths.h" #include "llvm/Transforms/Instrumentation/ProfilePaths.h"
#include "Support/CommandLine.h" #include "Support/CommandLine.h"