LLVM API Documentation

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 FunctionTypegetFT (const PATypeHolder &TH)
static const StructTypegetST (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 ValueRemapOperand (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)


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(), llvm::PluginLoader::operator=(), and llvm::AsmPrinter::printInlineAsm().

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 327 of file LinkModules.cpp.

References llvm::Value::getName(), llvm::GlobalValue::getParent(), llvm::Module::getSymbolTable(), llvm::GlobalValue::getType(), GV, llvm::GlobalValue::hasInternalLinkage(), llvm::SymbolTable::lookup(), and llvm::Value::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 350 of file LinkModules.cpp.

References Dest, Error(), and Src.

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 710 of file LinkModules.cpp.

References Error(), llvm::SequentialType::getElementType(), llvm::Module::getGlobalList(), llvm::GlobalVariable::getInitializer(), llvm::GlobalValue::getLinkage(), llvm::ArrayType::getNumElements(), llvm::GlobalValue::getType(), llvm::GlobalVariable::isConstant(), M, llvm::Value::replaceAllUsesWith(), llvm::GlobalVariable::setInitializer(), and llvm::Value::setName().

Referenced by llvm::Linker::LinkModules().

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

Definition at line 687 of file LinkModules.cpp.

References DF, E, LinkFunctionBody(), and Src.

Referenced by llvm::Linker::LinkModules().

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

Definition at line 645 of file LinkModules.cpp.

References BB, llvm::BasicBlock::begin(), Dest, E, llvm::BasicBlock::end(), OE, OI, RemapOperand(), and Src.

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 566 of file LinkModules.cpp.

References Dest, DF, E, EF, Error(), ForceRenaming(), RecursiveResolveTypes(), Src, and ToStr().

Referenced by llvm::Linker::LinkModules().

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

Definition at line 521 of file LinkModules.cpp.

References E, Error(), llvm::GlobalVariable::getInitializer(), llvm::GlobalValue::hasAppendingLinkage(), llvm::GlobalVariable::hasInitializer(), llvm::GlobalValue::hasLinkOnceLinkage(), llvm::GlobalValue::hasWeakLinkage(), RemapOperand(), llvm::GlobalVariable::setInitializer(), Src, and ToStr().

Referenced by llvm::Linker::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 398 of file LinkModules.cpp.

References Dest, E, llvm::GlobalVariable::eraseFromParent(), ForceRenaming(), llvm::GlobalValue::getAlignment(), llvm::GlobalValue::getLinkage(), GetLinkageResult(), llvm::Value::getName(), llvm::GlobalValue::getType(), llvm::GlobalValue::hasAppendingLinkage(), llvm::GlobalValue::hasInternalLinkage(), llvm::GlobalVariable::isConstant(), llvm::GlobalVariable::isExternal(), RecursiveResolveTypes(), llvm::Value::replaceAllUsesWith(), llvm::GlobalValue::setAlignment(), llvm::GlobalVariable::setConstant(), llvm::GlobalVariable::setInitializer(), llvm::GlobalValue::setLinkage(), and Src.

Referenced by llvm::Linker::LinkModules().

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

Definition at line 176 of file LinkModules.cpp.

References Dest, llvm::SymbolTable::lookupType(), Name, RecursiveResolveTypes(), ResolveTypes(), Src, llvm::SymbolTable::type_begin(), and llvm::SymbolTable::type_end().

Referenced by llvm::Linker::LinkModules().

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

Definition at line 251 of file LinkModules.cpp.

References E.

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 first, llvm::PATypeHolder::get(), llvm::SequentialType::getElementType(), getFT(), llvm::ArrayType::getNumElements(), getST(), and ResolveTypes().

Referenced by RecursiveResolveTypes().

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

Definition at line 266 of file LinkModules.cpp.

References CP, llvm::User::getNumOperands(), llvm::Constant::getOperand(), Ops, and PrintMap().

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().

Referenced by LinkTypes(), and RecursiveResolveTypesI().

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

Definition at line 39 of file LinkModules.cpp.

References M, OS, Ty, and llvm::WriteTypeSymbolic().

Referenced by LinkFunctionProtos(), and LinkGlobalInits().