LLVM API Documentation
#include <Module.h>
Collaboration diagram for llvm::Module:
Member Variables | |
class | Constant |
Public Types | |
Types And Enumerations | |
enum | Endianness { AnyEndianness, LittleEndian, BigEndian } |
An enumeration for describing the endianess of the target machine. More... | |
enum | PointerSize { AnyPointerSize, Pointer32, Pointer64 } |
An enumeration for describing the size of a pointer on the target machine. More... | |
typedef iplist< GlobalVariable > | GlobalListType |
The type for the list of global variables. | |
typedef iplist< Function > | FunctionListType |
The type for the list of functions. | |
typedef SetVector< std::string > | LibraryListType |
The type for the list of dependent libraries. | |
typedef GlobalListType::iterator | global_iterator |
The Global Variable iterator. | |
typedef GlobalListType::const_iterator | const_global_iterator |
The Global Variable constant iterator. | |
typedef FunctionListType::iterator | iterator |
The Function iterators. | |
typedef FunctionListType::const_iterator | const_iterator |
The Function constant iterator. | |
typedef LibraryListType::const_iterator | lib_iterator |
The Library list iterator. | |
Public Member Functions | |
Module Level Accessors | |
const std::string & | getModuleIdentifier () const |
const std::string & | getTargetTriple () const |
Endianness | getEndianness () const |
Target endian information... | |
PointerSize | getPointerSize () const |
Target Pointer Size information... | |
const std::string & | getModuleInlineAsm () const |
Module Level Mutators | |
void | setModuleIdentifier (const std::string &ID) |
Set the module identifier. | |
void | setTargetTriple (const std::string &T) |
Set the target triple. | |
void | setEndianness (Endianness E) |
Set the target endian information. | |
void | setPointerSize (PointerSize PS) |
Set the target pointer size. | |
void | setModuleInlineAsm (const std::string &Asm) |
Set the module-scope inline assembly blocks. | |
Function Accessors | |
Function * | getOrInsertFunction (const std::string &Name, const FunctionType *T) |
Function * | getOrInsertFunction (const std::string &Name, const Type *RetTy,...) END_WITH_NULL |
Function * | getFunction (const std::string &Name, const FunctionType *Ty) |
Function * | getMainFunction () |
Function * | getNamedFunction (const std::string &Name) const |
Global Variable Accessors | |
GlobalVariable * | getGlobalVariable (const std::string &Name, const Type *Ty, bool AllowInternal=false) |
GlobalVariable * | getNamedGlobal (const std::string &Name) const |
Type Accessors | |
bool | addTypeName (const std::string &Name, const Type *Ty) |
std::string | getTypeName (const Type *Ty) const |
const Type * | getTypeByName (const std::string &Name) const |
Direct access to the globals list, functions list, and symbol table | |
const GlobalListType & | getGlobalList () const |
Get the Module's list of global variables (constant). | |
GlobalListType & | getGlobalList () |
Get the Module's list of global variables. | |
const FunctionListType & | getFunctionList () const |
Get the Module's list of functions (constant). | |
FunctionListType & | getFunctionList () |
Get the Module's list of functions. | |
const SymbolTable & | getSymbolTable () const |
Get the symbol table of global variable and function identifiers. | |
SymbolTable & | getSymbolTable () |
Get the Module's symbol table of global variable and function identifiers. | |
Global Variable Iteration | |
global_iterator | global_begin () |
Get an iterator to the first global variable. | |
const_global_iterator | global_begin () const |
Get a constant iterator to the first global variable. | |
global_iterator | global_end () |
Get an iterator to the last global variable. | |
const_global_iterator | global_end () const |
Get a constant iterator to the last global variable. | |
bool | global_empty () const |
Determine if the list of globals is empty. | |
Function Iteration | |
iterator | begin () |
Get an iterator to the first function. | |
const_iterator | begin () const |
Get a constant iterator to the first function. | |
iterator | end () |
Get an iterator to the last function. | |
const_iterator | end () const |
Get a constant iterator to the last function. | |
size_t | size () const |
Determine how many functions are in the Module's list of functions. | |
bool | empty () const |
Determine if the list of functions is empty. | |
Dependent Library Iteration | |
lib_iterator | lib_begin () const |
Get a constant iterator to beginning of dependent library list. | |
lib_iterator | lib_end () const |
Get a constant iterator to end of dependent library list. | |
size_t | lib_size () const |
Returns the number of items in the list of libraries. | |
void | addLibrary (const std::string &Lib) |
Add a library to the list of dependent libraries. | |
void | removeLibrary (const std::string &Lib) |
Remove a library from the list of dependent libraries. | |
const LibraryListType & | getLibraries () const |
Get all the libraries. | |
Utility functions for printing and dumping Module objects | |
void | print (std::ostream &OS) const |
Print the module to an output stream. | |
void | print (std::ostream &OS, AssemblyAnnotationWriter *AAW) const |
Print the module to an output stream with AssemblyAnnotationWriter. | |
void | dump () const |
Dump the module to std::cerr (for debugging). | |
void | dropAllReferences () |
A Module instance is used to store all the information related to an LLVM module. Modules are the top level container of all other LLVM Intermediate Representation (IR) objects. Each module directly contains a list of globals variables, a list of functions, a list of libraries (or other modules) this module depends on, a symbol table, and various data about the target's characteristics.
A module maintains a GlobalValRefMap object that is used to hold all constant references to global variables in the module. When a global variable is destroyed, it should have no entries in the GlobalValueRefMap.
Definition at line 55 of file Module.h.
typedef iplist<GlobalVariable> llvm::Module::GlobalListType |
typedef iplist<Function> llvm::Module::FunctionListType |
typedef SetVector<std::string> llvm::Module::LibraryListType |
typedef GlobalListType::iterator llvm::Module::global_iterator |
typedef GlobalListType::const_iterator llvm::Module::const_global_iterator |
typedef FunctionListType::iterator llvm::Module::iterator |
typedef FunctionListType::const_iterator llvm::Module::const_iterator |
Module::Module | ( | const std::string & | ModuleID | ) |
The Module constructor. Note that there is no default constructor. You must provide a name for the module upon construction.
Definition at line 65 of file Module.cpp.
Module::~Module | ( | ) |
The module destructor. This will dropAllReferences.
Definition at line 74 of file Module.cpp.
References llvm::SetVector< T >::clear(), and dropAllReferences().
Module::Module | ( | const std::string & | ModuleID | ) |
The Module constructor. Note that there is no default constructor. You must provide a name for the module upon construction.
Definition at line 65 of file Module.cpp.
Module::~Module | ( | ) |
The module destructor. This will dropAllReferences.
Definition at line 74 of file Module.cpp.
References llvm::SetVector< T >::clear(), and dropAllReferences().
const std::string& llvm::Module::getModuleIdentifier | ( | ) | const [inline] |
Get the module identifier which is, essentially, the name of the module.
Definition at line 117 of file Module.h.
Referenced by llvm::CloneModule(), llvm::Linker::LinkInArchive(), llvm::PMDebug::PrintPassInformation(), llvm::ProgramInfo::ProgramInfo(), and ResolveFunctions().
const std::string& llvm::Module::getTargetTriple | ( | ) | const [inline] |
Get the target triple which is a string describing the target host.
Definition at line 121 of file Module.h.
Referenced by llvm::CloneModule(), llvm::X86TargetMachine::getModuleMatchQuality(), llvm::SparcTargetMachine::getModuleMatchQuality(), llvm::PPC64TargetMachine::getModuleMatchQuality(), llvm::PPC32TargetMachine::getModuleMatchQuality(), llvm::IA64TargetMachine::getModuleMatchQuality(), llvm::ARMTargetMachine::getModuleMatchQuality(), llvm::AlphaTargetMachine::getModuleMatchQuality(), llvm::PPCSubtarget::PPCSubtarget(), and llvm::X86Subtarget::X86Subtarget().
Module::Endianness Module::getEndianness | ( | ) | const |
Target endian information...
Get the target endian information.
Definition at line 90 of file Module.cpp.
References AnyEndianness, BigEndian, llvm::getToken(), and LittleEndian.
Referenced by llvm::BytecodeWriter::BytecodeWriter(), llvm::CloneModule(), llvm::Interpreter::create(), llvm::X86TargetMachine::getModuleMatchQuality(), llvm::SparcTargetMachine::getModuleMatchQuality(), llvm::PPC64TargetMachine::getModuleMatchQuality(), llvm::PPC32TargetMachine::getModuleMatchQuality(), llvm::AlphaTargetMachine::getModuleMatchQuality(), and llvm::TargetData::TargetData().
Module::PointerSize Module::getPointerSize | ( | ) | const |
Target Pointer Size information...
Get the target pointer size.
Definition at line 118 of file Module.cpp.
References AnyPointerSize, llvm::getToken(), Pointer32, Pointer64, and size().
Referenced by llvm::BytecodeWriter::BytecodeWriter(), llvm::CloneModule(), llvm::Interpreter::create(), llvm::X86TargetMachine::getModuleMatchQuality(), llvm::SparcTargetMachine::getModuleMatchQuality(), llvm::PPC64TargetMachine::getModuleMatchQuality(), llvm::PPC32TargetMachine::getModuleMatchQuality(), llvm::ARMTargetMachine::getModuleMatchQuality(), llvm::AlphaTargetMachine::getModuleMatchQuality(), lle_X_sprintf(), and llvm::TargetData::TargetData().
const std::string& llvm::Module::getModuleInlineAsm | ( | ) | const [inline] |
Get any module-scope inline assembly blocks.
Definition at line 133 of file Module.h.
Referenced by llvm::CloneModule(), and llvm::AsmPrinter::doInitialization().
void llvm::Module::setModuleIdentifier | ( | const std::string & | ID | ) | [inline] |
void llvm::Module::setTargetTriple | ( | const std::string & | T | ) | [inline] |
Set the target triple.
Definition at line 143 of file Module.h.
Referenced by llvm::CloneModule(), and llvm::BytecodeReader::ParseModuleGlobalInfo().
void Module::setEndianness | ( | Endianness | E | ) |
Set the target endian information.
Definition at line 107 of file Module.cpp.
References AnyEndianness, BigEndian, and LittleEndian.
Referenced by llvm::CloneModule(), llvm::Interpreter::create(), and llvm::BytecodeReader::ParseVersionInfo().
void Module::setPointerSize | ( | PointerSize | PS | ) |
Set the target pointer size.
Definition at line 138 of file Module.cpp.
References AnyPointerSize, Pointer32, and Pointer64.
Referenced by llvm::CloneModule(), llvm::Interpreter::create(), and llvm::BytecodeReader::ParseVersionInfo().
void llvm::Module::setModuleInlineAsm | ( | const std::string & | Asm | ) | [inline] |
Set the module-scope inline assembly blocks.
Definition at line 152 of file Module.h.
Referenced by llvm::CloneModule(), and llvm::BytecodeReader::ParseModuleGlobalInfo().
Function * Module::getOrInsertFunction | ( | const std::string & | Name, | |
const FunctionType * | T | |||
) |
getOrInsertFunction - Look up the specified function in the module symbol table. If it does not exist, add a prototype for the function and return it.
Definition at line 157 of file Module.cpp.
References llvm::GlobalValue::ExternalLinkage, llvm::PointerType::get(), getSymbolTable(), llvm::SymbolTable::lookup(), Ty, and V.
Referenced by CheckVarargs(), EnsureFunctionExists(), getOrInsertFunction(), getUpgradedIntrinsic(), getUpgradedUnaryFn(), llvm::InlineFunction(), InsertInstrumentationCall(), llvm::InsertProfilingInitCall(), llvm::BytecodeReader::ParseInstruction(), ReplaceCallWith(), and RunParser().
getOrInsertFunction - Look up the specified function in the module symbol table. If it does not exist, add a prototype for the function and return it. This version of the method takes a null terminated list of function arguments, which makes it easier for clients to use.
Definition at line 176 of file Module.cpp.
References llvm::FunctionType::get(), getOrInsertFunction(), and RetTy.
Function * Module::getFunction | ( | const std::string & | Name, | |
const FunctionType * | Ty | |||
) |
getFunction - Look up the specified function in the module symbol table. If it does not exist, return null.
Definition at line 196 of file Module.cpp.
References llvm::PointerType::get(), getSymbolTable(), llvm::SymbolTable::lookup(), and Ty.
Referenced by getMainFunction().
Function * Module::getMainFunction | ( | ) |
getMainFunction - This function looks up main efficiently. This is such a common case, that it is a method in Module. If main cannot be found, a null pointer is returned.
Definition at line 206 of file Module.cpp.
References F, llvm::PointerType::get(), llvm::FunctionType::get(), getFunction(), getNamedFunction(), llvm::Type::IntTy, llvm::Type::SByteTy, and llvm::Type::VoidTy.
Referenced by GetAllUndefinedSymbols(), llvm::TDDataStructures::runOnModule(), llvm::EquivClassGraphs::runOnModule(), llvm::CompleteBUDataStructures::runOnModule(), and llvm::BUDataStructures::runOnModule().
Function * Module::getNamedFunction | ( | const std::string & | Name | ) | const |
getNamedFunction - Return the first function in the module with the specified name, of arbitrary type. This method returns null if a function with the specified name is not found.
Definition at line 253 of file Module.cpp.
References begin(), E, and end().
Referenced by CheckVarargs(), EnsureFunctionExists(), getMainFunction(), getPointerToNamedFunction(), ReplaceCallWith(), and RunParser().
GlobalVariable * Module::getGlobalVariable | ( | const std::string & | Name, | |
const Type * | Ty, | |||
bool | AllowInternal = false | |||
) |
getGlobalVariable - Look up the specified global variable in the module symbol table. If it does not exist, return null. The type argument should be the underlying type of the global, i.e., it should not have the top-level PointerType, which represents the address of the global. If AllowInternal is set to true, this function will return types that have InternalLinkage. By default, these types are not returned.
Definition at line 276 of file Module.cpp.
References llvm::PointerType::get(), getSymbolTable(), llvm::GlobalValue::hasInternalLinkage(), Ty, and V.
Referenced by getGlobalVariablesUsing(), llvm::ProgramInfo::getSourceFiles(), llvm::ProgramInfo::getSourceFunctions(), and ParseGlobalVariable().
GlobalVariable * Module::getNamedGlobal | ( | const std::string & | Name | ) | const |
getNamedGlobal - Return the first global variable in the module with the specified name, of arbitrary type. This method returns null if a global with the specified name is not found.
Definition at line 290 of file Module.cpp.
References E, global_begin(), and global_end().
Referenced by llvm::ExecutionEngine::runStaticConstructorsDestructors().
bool Module::addTypeName | ( | const std::string & | Name, | |
const Type * | Ty | |||
) |
addTypeName - Insert an entry in the symbol table mapping Str to Type. If there is already an entry for this name, true is returned and the symbol table is not modified.
Definition at line 311 of file Module.cpp.
References getSymbolTable(), llvm::SymbolTable::insert(), llvm::SymbolTable::lookupType(), and Ty.
Referenced by llvm::CloneModule(), llvm::DISerializer::getTagType(), and setTypeName().
std::string Module::getTypeName | ( | const Type * | Ty | ) | const |
getTypeName - If there is at least one entry in the symbol table for the specified type, return it.
Definition at line 333 of file Module.cpp.
References getSymbolTable(), Ty, llvm::SymbolTable::type_begin(), and llvm::SymbolTable::type_end().
const Type * Module::getTypeByName | ( | const std::string & | Name | ) | const |
getTypeByName - Return the type with the specified name in this module, or null if there is none by that name.
Definition at line 325 of file Module.cpp.
References getSymbolTable(), and llvm::SymbolTable::lookupType().
Referenced by getTypeVal(), and setTypeName().
const GlobalListType& llvm::Module::getGlobalList | ( | ) | const [inline] |
Get the Module's list of global variables (constant).
Definition at line 224 of file Module.h.
Referenced by llvm::GlobalVariable::eraseFromParent(), getStringRef(), llvm::GlobalVariable::GlobalVariable(), InstallGlobalCtors(), LinkAppendingVars(), OptimizeGlobalAddressOfMalloc(), ParseGlobalVariable(), llvm::GlobalVariable::removeFromParent(), ResolveGlobalVariables(), ShrinkGlobalToBoolean(), and SRAGlobal().
GlobalListType& llvm::Module::getGlobalList | ( | ) | [inline] |
const FunctionListType& llvm::Module::getFunctionList | ( | ) | const [inline] |
Get the Module's list of functions (constant).
Definition at line 228 of file Module.h.
Referenced by llvm::Function::eraseFromParent(), llvm::Function::Function(), llvm::Function::removeFromParent(), llvm::CallGraph::removeFunctionFromModule(), ResolveFunctions(), and RunParser().
FunctionListType& llvm::Module::getFunctionList | ( | ) | [inline] |
const SymbolTable& llvm::Module::getSymbolTable | ( | ) | const [inline] |
Get the symbol table of global variable and function identifiers.
Definition at line 232 of file Module.h.
Referenced by addTypeName(), llvm::BytecodeWriter::BytecodeWriter(), llvm::CloneModule(), fillTypeNameTable(), ForceRenaming(), getFunction(), getGlobalVariable(), getOrInsertFunction(), llvm::SlotCalculator::getPlane(), getTypeByName(), getTypeName(), lookupInSymbolTable(), llvm::BytecodeReader::ParseModule(), and llvm::Function::renameLocalSymbols().
SymbolTable& llvm::Module::getSymbolTable | ( | ) | [inline] |
global_iterator llvm::Module::global_begin | ( | ) | [inline] |
Get an iterator to the first global variable.
Definition at line 241 of file Module.h.
Referenced by llvm::CloneModule(), llvm::X86IntelAsmPrinter::doFinalization(), llvm::X86SharedAsmPrinter::doFinalization(), llvm::ELFWriter::doFinalization(), llvm::X86IntelAsmPrinter::doInitialization(), dropAllReferences(), llvm::ExecutionEngine::emitGlobals(), GetAllDefinedSymbols(), GetAllUndefinedSymbols(), getNamedGlobal(), llvm::SlotCalculator::getPlane(), getSymbols(), llvm::Mangler::Mangler(), llvm::LocalDataStructures::runOnModule(), llvm::FindUsedTypes::runOnModule(), and llvm::EquivClassGraphs::runOnModule().
const_global_iterator llvm::Module::global_begin | ( | ) | const [inline] |
global_iterator llvm::Module::global_end | ( | ) | [inline] |
Get an iterator to the last global variable.
Definition at line 245 of file Module.h.
Referenced by llvm::CloneModule(), llvm::X86IntelAsmPrinter::doFinalization(), llvm::X86SharedAsmPrinter::doFinalization(), llvm::ELFWriter::doFinalization(), llvm::X86IntelAsmPrinter::doInitialization(), dropAllReferences(), llvm::ExecutionEngine::emitGlobals(), GetAllDefinedSymbols(), GetAllUndefinedSymbols(), getNamedGlobal(), llvm::SlotCalculator::getPlane(), getSymbols(), llvm::Mangler::Mangler(), llvm::LocalDataStructures::runOnModule(), llvm::FindUsedTypes::runOnModule(), and llvm::EquivClassGraphs::runOnModule().
const_global_iterator llvm::Module::global_end | ( | ) | const [inline] |
bool llvm::Module::global_empty | ( | ) | const [inline] |
iterator llvm::Module::begin | ( | ) | [inline] |
Get an iterator to the first function.
Definition at line 256 of file Module.h.
Referenced by llvm::DefaultIntrinsicLowering::AddPrototypes(), llvm::BytecodeWriter::BytecodeWriter(), CheckAllGraphs(), llvm::CloneModule(), llvm::X86IntelAsmPrinter::doInitialization(), dropAllReferences(), GetAllDefinedSymbols(), GetAllUndefinedSymbols(), llvm::ProfileInfoLoader::getBlockCounts(), llvm::ProfileInfoLoader::getEdgeCounts(), llvm::ProfileInfoLoader::getFunctionCounts(), getNamedFunction(), llvm::SlotCalculator::getPlane(), getSymbols(), llvm::Mangler::Mangler(), PerModuleInfo::ModuleDone(), printCollection(), llvm::TDDataStructures::runOnModule(), llvm::FunctionPass::runOnModule(), llvm::LocalDataStructures::runOnModule(), llvm::FindUsedTypes::runOnModule(), llvm::EquivClassGraphs::runOnModule(), llvm::CompleteBUDataStructures::runOnModule(), and llvm::BUDataStructures::runOnModule().
const_iterator llvm::Module::begin | ( | ) | const [inline] |
iterator llvm::Module::end | ( | ) | [inline] |
Get an iterator to the last function.
Definition at line 260 of file Module.h.
Referenced by llvm::DefaultIntrinsicLowering::AddPrototypes(), llvm::BytecodeWriter::BytecodeWriter(), CheckAllGraphs(), llvm::CloneModule(), llvm::X86IntelAsmPrinter::doInitialization(), dropAllReferences(), GetAllDefinedSymbols(), GetAllUndefinedSymbols(), llvm::ProfileInfoLoader::getBlockCounts(), llvm::ProfileInfoLoader::getEdgeCounts(), llvm::ProfileInfoLoader::getFunctionCounts(), getNamedFunction(), llvm::SlotCalculator::getPlane(), getSymbols(), llvm::Mangler::Mangler(), PerModuleInfo::ModuleDone(), printCollection(), llvm::TDDataStructures::runOnModule(), llvm::FunctionPass::runOnModule(), llvm::LocalDataStructures::runOnModule(), llvm::FindUsedTypes::runOnModule(), llvm::EquivClassGraphs::runOnModule(), llvm::CompleteBUDataStructures::runOnModule(), and llvm::BUDataStructures::runOnModule().
const_iterator llvm::Module::end | ( | ) | const [inline] |
size_t llvm::Module::size | ( | ) | const [inline] |
Determine how many functions are in the Module's list of functions.
Definition at line 264 of file Module.h.
Referenced by getPointerSize().
bool llvm::Module::empty | ( | ) | const [inline] |
lib_iterator llvm::Module::lib_begin | ( | ) | const [inline] |
Get a constant iterator to beginning of dependent library list.
Definition at line 273 of file Module.h.
References llvm::SetVector< T >::begin().
Referenced by llvm::CloneModule(), and llvm::Linker::LinkInItems().
lib_iterator llvm::Module::lib_end | ( | ) | const [inline] |
Get a constant iterator to end of dependent library list.
Definition at line 275 of file Module.h.
References llvm::SetVector< T >::end().
Referenced by llvm::CloneModule(), and llvm::Linker::LinkInItems().
size_t llvm::Module::lib_size | ( | ) | const [inline] |
Returns the number of items in the list of libraries.
Definition at line 277 of file Module.h.
References llvm::SetVector< T >::size().
void llvm::Module::addLibrary | ( | const std::string & | Lib | ) | [inline] |
Add a library to the list of dependent libraries.
Definition at line 279 of file Module.h.
References llvm::SetVector< T >::insert().
Referenced by llvm::CloneModule(), and llvm::BytecodeReader::ParseModuleGlobalInfo().
void llvm::Module::removeLibrary | ( | const std::string & | Lib | ) | [inline] |
Remove a library from the list of dependent libraries.
Definition at line 281 of file Module.h.
References llvm::SetVector< T >::remove().
const LibraryListType& llvm::Module::getLibraries | ( | ) | const [inline] |
Get all the libraries.
Definition at line 283 of file Module.h.
Referenced by llvm::GetBytecodeDependentLibraries(), and llvm::Linker::LinkInLibraries().
void llvm::Module::print | ( | std::ostream & | OS | ) | const [inline] |
Print the module to an output stream.
Definition at line 290 of file Module.h.
Referenced by dump(), and llvm::operator<<().
void Module::print | ( | std::ostream & | OS, | |
AssemblyAnnotationWriter * | AAW | |||
) | const |
Print the module to an output stream with AssemblyAnnotationWriter.
Definition at line 1276 of file AsmWriter.cpp.
References llvm::AssemblyWriter::write().
void Module::dump | ( | ) | const |
Dump the module to std::cerr (for debugging).
Definition at line 85 of file Module.cpp.
References print().
void Module::dropAllReferences | ( | ) |
This function causes all the subinstructions to "let go" of all references that they are maintaining. This allows one to 'delete' a whole class at a time, even though there may be circular references... first all references are dropped, and all use counts go to zero. Then everything is delete'd for real. Note that no operations are valid on an object that has "dropped all references", except operator delete.
Definition at line 360 of file Module.cpp.
References begin(), E, end(), global_begin(), and global_end().
Referenced by ~Module().