LLVM API Documentation

Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

LinkModules.cpp File Reference

#include "llvm/Linker.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Module.h"
#include "llvm/SymbolTable.h"
#include "llvm/Instructions.h"
#include "llvm/Assembly/Writer.h"
#include "llvm/System/Path.h"
#include <iostream>
#include <sstream>

Include dependency graph for LinkModules.cpp:

Go to the source code of this file.

Functions

static bool Error (std::string *E, const std::string &Message)
static std::string ToStr (const Type *Ty, const Module *M)
static bool ResolveTypes (const Type *DestTy, const Type *SrcTy, SymbolTable *DestST, const std::string &Name)
static const FunctionType * getFT (const PATypeHolder &TH)
static const StructType * getST (const PATypeHolder &TH)
static bool RecursiveResolveTypesI (const PATypeHolder &DestTy, const PATypeHolder &SrcTy, SymbolTable *DestST, const std::string &Name, std::vector< std::pair< PATypeHolder, PATypeHolder > > &Pointers)
static bool RecursiveResolveTypes (const PATypeHolder &DestTy, const PATypeHolder &SrcTy, SymbolTable *DestST, const std::string &Name)
static bool LinkTypes (Module *Dest, const Module *Src, std::string *Err)
static void PrintMap (const std::map< const Value *, Value * > &M)
static Value * RemapOperand (const Value *In, std::map< const Value *, Value * > &ValueMap)
static void ForceRenaming (GlobalValue *GV, const std::string &Name)
static bool GetLinkageResult (GlobalValue *Dest, GlobalValue *Src, GlobalValue::LinkageTypes &LT, bool &LinkFromSrc, std::string *Err)
static bool LinkGlobals (Module *Dest, Module *Src, std::map< const Value *, Value * > &ValueMap, std::multimap< std::string, GlobalVariable * > &AppendingVars, std::map< std::string, GlobalValue * > &GlobalsByName, std::string *Err)
static bool LinkGlobalInits (Module *Dest, const Module *Src, std::map< const Value *, Value * > &ValueMap, std::string *Err)
static bool LinkFunctionProtos (Module *Dest, const Module *Src, std::map< const Value *, Value * > &ValueMap, std::map< std::string, GlobalValue * > &GlobalsByName, std::string *Err)
static bool LinkFunctionBody (Function *Dest, Function *Src, std::map< const Value *, Value * > &GlobalMap, std::string *Err)
static bool LinkFunctionBodies (Module *Dest, Module *Src, std::map< const Value *, Value * > &ValueMap, std::string *Err)
static bool LinkAppendingVars (Module *M, std::multimap< std::string, GlobalVariable * > &AppendingVars, std::string *ErrorMsg)
bool llvm::LinkModules (Module *Dest, Module *Src, std::string *ErrorMsg)
 Link two modules together.


Function Documentation

static bool Error (  std::string *  E,
const std::string &  Message
)  [inline, static]
 

Definition at line 33 of file LinkModules.cpp.

Referenced by llvm::JIT::create(), GetLinkageResult(), LinkAppendingVars(), LinkFunctionProtos(), LinkGlobalInits(), and LinkGlobals().

static void ForceRenaming (  GlobalValue *  GV,
const std::string &  Name
)  [static]
 

ForceRenaming - The LLVM SymbolTable class autorenames globals that conflict in the symbol table. This is good for all clients except for us. Go through the trouble to force this back.

Definition at line 359 of file LinkModules.cpp.

References llvm::Value::getName(), llvm::GlobalValue::getParent(), llvm::Module::getSymbolTable(), llvm::GlobalValue::getType(), llvm::GlobalValue::hasInternalLinkage(), llvm::SymbolTable::lookup(), and llvm::Constant::setName().

Referenced by LinkFunctionProtos(), and LinkGlobals().

static const FunctionType* getFT (  const PATypeHolder &  TH  )  [static]
 

Definition at line 84 of file LinkModules.cpp.

References llvm::PATypeHolder::get().

Referenced by RecursiveResolveTypesI().

static bool GetLinkageResult (  GlobalValue *  Dest,
GlobalValue *  Src,
GlobalValue::LinkageTypes &  LT,
bool &  LinkFromSrc,
std::string *  Err
)  [static]
 

GetLinkageResult - This analyzes the two global values and determines what the result will look like in the destination module. In particular, it computes the resultant linkage type, computes whether the global in the source should be copied over to the destination (replacing the existing one), and computes whether this linkage is an error or not.

Definition at line 382 of file LinkModules.cpp.

References Error(), llvm::GlobalValue::ExternalLinkage, llvm::GlobalValue::getLinkage(), llvm::Value::getName(), llvm::GlobalValue::hasAppendingLinkage(), llvm::GlobalValue::hasExternalLinkage(), llvm::GlobalValue::hasInternalLinkage(), llvm::GlobalValue::hasLinkOnceLinkage(), llvm::GlobalValue::hasWeakLinkage(), and llvm::GlobalValue::isExternal().

Referenced by LinkGlobals().

static const StructType* getST (  const PATypeHolder &  TH  )  [static]
 

Definition at line 87 of file LinkModules.cpp.

References llvm::PATypeHolder::get().

Referenced by RecursiveResolveTypesI().

static bool LinkAppendingVars (  Module *  M,
std::multimap< std::string, GlobalVariable * > &  AppendingVars,
std::string *  ErrorMsg
)  [static]
 

Definition at line 735 of file LinkModules.cpp.

References Error(), llvm::ConstantArray::get(), llvm::ArrayType::get(), llvm::ConstantExpr::getCast(), llvm::SequentialType::getElementType(), llvm::Module::getGlobalList(), llvm::GlobalVariable::getInitializer(), llvm::GlobalValue::getLinkage(), llvm::Constant::getNullValue(), llvm::ArrayType::getNumElements(), llvm::GlobalValue::getType(), I, llvm::GlobalVariable::isConstant(), llvm::Value::replaceAllUsesWith(), and llvm::GlobalVariable::setInitializer().

Referenced by llvm::LinkModules().

static bool LinkFunctionBodies (  Module *  Dest,
Module *  Src,
std::map< const Value *, Value * > &  ValueMap,
std::string *  Err
)  [static]
 

Definition at line 712 of file LinkModules.cpp.

References llvm::Module::begin(), llvm::X86II::DF, E, llvm::Module::end(), llvm::Function::isExternal(), and LinkFunctionBody().

Referenced by llvm::LinkModules().

static bool LinkFunctionBody (  Function *  Dest,
Function *  Src,
std::map< const Value *, Value * > &  GlobalMap,
std::string *  Err
)  [static]
 

Definition at line 671 of file LinkModules.cpp.

References llvm::Function::abegin(), llvm::Function::aend(), llvm::Function::begin(), E, llvm::Function::end(), llvm::Function::getBasicBlockList(), I, llvm::Function::isExternal(), and RemapOperand().

Referenced by LinkFunctionBodies().

static bool LinkFunctionProtos (  Module *  Dest,
const Module *  Src,
std::map< const Value *, Value * > &  ValueMap,
std::map< std::string, GlobalValue * > &  GlobalsByName,
std::string *  Err
)  [static]
 

Definition at line 593 of file LinkModules.cpp.

References llvm::Module::begin(), llvm::X86II::DF, E, llvm::Module::end(), Error(), ForceRenaming(), llvm::Module::getFunction(), llvm::Function::getFunctionType(), llvm::GlobalValue::getLinkage(), llvm::Value::getName(), llvm::Module::getSymbolTable(), llvm::GlobalValue::getType(), llvm::GlobalValue::hasExternalLinkage(), llvm::GlobalValue::hasInternalLinkage(), llvm::GlobalValue::hasLinkOnceLinkage(), llvm::Value::hasName(), llvm::GlobalValue::hasWeakLinkage(), I, llvm::Function::isExternal(), RecursiveResolveTypes(), llvm::GlobalValue::setLinkage(), and ToStr().

Referenced by llvm::LinkModules().

static bool LinkGlobalInits (  Module *  Dest,
const Module *  Src,
std::map< const Value *, Value * > &  ValueMap,
std::string *  Err
)  [static]
 

Definition at line 549 of file LinkModules.cpp.

References E, Error(), llvm::Module::gbegin(), llvm::Module::gend(), llvm::GlobalVariable::getInitializer(), llvm::Value::getName(), llvm::GlobalValue::getType(), llvm::GlobalValue::hasAppendingLinkage(), llvm::GlobalValue::hasExternalLinkage(), llvm::GlobalVariable::hasInitializer(), llvm::GlobalValue::hasLinkOnceLinkage(), llvm::GlobalValue::hasWeakLinkage(), I, RemapOperand(), llvm::GlobalVariable::setInitializer(), and ToStr().

Referenced by llvm::LinkModules().

static bool LinkGlobals (  Module *  Dest,
Module *  Src,
std::map< const Value *, Value * > &  ValueMap,
std::multimap< std::string, GlobalVariable * > &  AppendingVars,
std::map< std::string, GlobalValue * > &  GlobalsByName,
std::string *  Err
)  [static]
 

Definition at line 430 of file LinkModules.cpp.

References E, llvm::GlobalVariable::eraseFromParent(), Error(), llvm::GlobalValue::ExternalLinkage, ForceRenaming(), llvm::Module::gbegin(), llvm::Module::gend(), llvm::ConstantExpr::getCast(), llvm::SequentialType::getElementType(), llvm::Module::getGlobalList(), llvm::Module::getGlobalVariable(), llvm::GlobalValue::getLinkage(), GetLinkageResult(), llvm::Value::getName(), llvm::Module::getSymbolTable(), llvm::GlobalValue::getType(), llvm::GlobalValue::hasAppendingLinkage(), llvm::GlobalValue::hasExternalLinkage(), llvm::GlobalVariable::hasInitializer(), llvm::GlobalValue::hasInternalLinkage(), llvm::Value::hasName(), I, llvm::GlobalVariable::isConstant(), llvm::GlobalVariable::isExternal(), RecursiveResolveTypes(), llvm::Value::replaceAllUsesWith(), llvm::GlobalVariable::setConstant(), llvm::GlobalVariable::setInitializer(), and llvm::GlobalValue::setLinkage().

Referenced by llvm::LinkModules().

static bool LinkTypes (  Module *  Dest,
const Module *  Src,
std::string *  Err
)  [static]
 

Definition at line 176 of file LinkModules.cpp.

References llvm::Module::getSymbolTable(), llvm::SymbolTable::lookupType(), RecursiveResolveTypes(), ResolveTypes(), llvm::SymbolTable::type_begin(), llvm::SymbolTable::type_end(), and llvm::WriteTypeSymbolic().

Referenced by llvm::LinkModules().

static void PrintMap (  const std::map< const Value *, Value * > &  M  )  [static]
 

Definition at line 263 of file LinkModules.cpp.

References E, and I.

Referenced by RemapOperand().

static bool RecursiveResolveTypes (  const PATypeHolder &  DestTy,
const PATypeHolder &  SrcTy,
SymbolTable *  DestST,
const std::string &  Name
)  [static]
 

Definition at line 165 of file LinkModules.cpp.

References PointerTypes, and RecursiveResolveTypesI().

Referenced by LinkFunctionProtos(), LinkGlobals(), and LinkTypes().

static bool RecursiveResolveTypesI (  const PATypeHolder &  DestTy,
const PATypeHolder &  SrcTy,
SymbolTable *  DestST,
const std::string &  Name,
std::vector< std::pair< PATypeHolder, PATypeHolder > > &  Pointers
)  [static]
 

Definition at line 94 of file LinkModules.cpp.

References llvm::Type::ArrayTyID, first, llvm::Type::FunctionTyID, llvm::PATypeHolder::get(), llvm::SequentialType::getElementType(), getFT(), llvm::ArrayType::getNumElements(), getST(), llvm::Type::PointerTyID, ResolveTypes(), and llvm::Type::StructTyID.

Referenced by RecursiveResolveTypes().

static Value* RemapOperand (  const Value *  In,
std::map< const Value *, Value * > &  ValueMap
)  [static]
 

Definition at line 278 of file LinkModules.cpp.

References llvm::Instruction::Cast, llvm::ConstantExpr::get(), llvm::ConstantStruct::get(), llvm::ConstantArray::get(), llvm::ConstantExpr::getCast(), llvm::ConstantExpr::getGetElementPtr(), llvm::ConstantExpr::getSelect(), I, PrintMap(), llvm::Select, and V.

Referenced by LinkFunctionBody(), and LinkGlobalInits().

static bool ResolveTypes (  const Type *  DestTy,
const Type *  SrcTy,
SymbolTable *  DestST,
const std::string &  Name
)  [static]
 

Definition at line 63 of file LinkModules.cpp.

References llvm::SymbolTable::insert().

static std::string ToStr (  const Type *  Ty,
const Module *  M
)  [static]
 

Definition at line 39 of file LinkModules.cpp.

References llvm::WriteTypeSymbolic().

Referenced by LinkFunctionProtos(), and LinkGlobalInits().