LLVM API Documentation

llvm::Module Class Reference

The main container class for the LLVM Intermediate Representation. More...

#include <Module.h>

Collaboration diagram for llvm::Module:

Collaboration graph
[legend]

List of all members.

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< GlobalVariableGlobalListType
 The type for the list of global variables.
typedef iplist< FunctionFunctionListType
 The type for the list of functions.
typedef iplist< GlobalAliasAliasListType
 The type for the list of aliases.
typedef std::vector< 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 AliasListType::iterator alias_iterator
 The Global Alias iterators.
typedef
AliasListType::const_iterator 
const_alias_iterator
 The Global Alias constant iterator.
typedef
LibraryListType::const_iterator 
lib_iterator
 The Library list iterator.

Public Member Functions

Constructors
 Module (const std::string &ModuleID)
 ~Module ()
 The module destructor. This will dropAllReferences.
Module Level Accessors
const std::string & getModuleIdentifier () const
const std::string & getDataLayout () 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 setDataLayout (const std::string &DL)
 Set the data layout.
void setTargetTriple (const std::string &T)
 Set the target triple.
void setModuleInlineAsm (const std::string &Asm)
 Set the module-scope inline assembly blocks.
void appendModuleInlineAsm (const std::string &Asm)
Function Accessors
ConstantgetOrInsertFunction (const std::string &Name, const FunctionType *T, AttrListPtr AttributeList)
ConstantgetOrInsertFunction (const std::string &Name, const FunctionType *T)
ConstantgetOrInsertFunction (const std::string &Name, AttrListPtr AttributeList, const Type *RetTy,...) END_WITH_NULL
ConstantgetOrInsertFunction (const std::string &Name, const Type *RetTy,...) END_WITH_NULL
FunctiongetFunction (const std::string &Name) const
FunctiongetFunction (const char *Name) const
Global Variable Accessors
GlobalVariablegetGlobalVariable (const std::string &Name, bool AllowInternal=false) const
GlobalVariablegetNamedGlobal (const std::string &Name) const
ConstantgetOrInsertGlobal (const std::string &Name, const Type *Ty)
Global Alias Accessors
GlobalAliasgetNamedAlias (const std::string &Name) const
Type Accessors
bool addTypeName (const std::string &Name, const Type *Ty)
std::string getTypeName (const Type *Ty) const
const TypegetTypeByName (const std::string &Name) const
Direct access to the globals list, functions list, and symbol table
const GlobalListTypegetGlobalList () const
 Get the Module's list of global variables (constant).
GlobalListTypegetGlobalList ()
 Get the Module's list of global variables.
const FunctionListTypegetFunctionList () const
 Get the Module's list of functions (constant).
FunctionListTypegetFunctionList ()
 Get the Module's list of functions.
const AliasListTypegetAliasList () const
 Get the Module's list of aliases (constant).
AliasListTypegetAliasList ()
 Get the Module's list of aliases.
const ValueSymbolTablegetValueSymbolTable () const
 Get the symbol table of global variable and function identifiers.
ValueSymbolTablegetValueSymbolTable ()
 Get the Module's symbol table of global variable and function identifiers.
const TypeSymbolTablegetTypeSymbolTable () const
 Get the symbol table of types.
TypeSymbolTablegetTypeSymbolTable ()
 Get the Module's symbol table of types.
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 LibraryListTypegetLibraries () const
 Get all the libraries.
Alias Iteration
alias_iterator alias_begin ()
 Get an iterator to the first alias.
const_alias_iterator alias_begin () const
 Get a constant iterator to the first alias.
alias_iterator alias_end ()
 Get an iterator to the last alias.
const_alias_iterator alias_end () const
 Get a constant iterator to the last alias.
size_t alias_size () const
 Determine how many functions are in the Module's list of aliases.
bool alias_empty () const
 Determine if the list of aliases is empty.
Utility functions for printing and dumping Module objects
void print (raw_ostream &OS, AssemblyAnnotationWriter *AAW) const
 Print the module to an output stream with AssemblyAnnotationWriter.
void print (std::ostream &OS, AssemblyAnnotationWriter *AAW) const
void dump () const
 Dump the module to stderr (for debugging).
void dropAllReferences ()

Static Public Member Functions

static unsigned getFunctionListOffset ()
static unsigned getGlobalVariableListOffset ()
static unsigned getAliasListOffset ()


Detailed Description

The main container class for the LLVM Intermediate Representation.

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 67 of file Module.h.


Member Typedef Documentation

The type for the list of global variables.

Definition at line 72 of file Module.h.

The type for the list of functions.

Definition at line 74 of file Module.h.

The type for the list of aliases.

Definition at line 76 of file Module.h.

typedef std::vector<std::string> llvm::Module::LibraryListType

The type for the list of dependent libraries.

Definition at line 79 of file Module.h.

typedef GlobalListType::iterator llvm::Module::global_iterator

The Global Variable iterator.

Definition at line 82 of file Module.h.

typedef GlobalListType::const_iterator llvm::Module::const_global_iterator

The Global Variable constant iterator.

Definition at line 84 of file Module.h.

typedef FunctionListType::iterator llvm::Module::iterator

The Function iterators.

Definition at line 87 of file Module.h.

typedef FunctionListType::const_iterator llvm::Module::const_iterator

The Function constant iterator.

Definition at line 89 of file Module.h.

typedef AliasListType::iterator llvm::Module::alias_iterator

The Global Alias iterators.

Definition at line 92 of file Module.h.

typedef AliasListType::const_iterator llvm::Module::const_alias_iterator

The Global Alias constant iterator.

Definition at line 94 of file Module.h.

typedef LibraryListType::const_iterator llvm::Module::lib_iterator

The Library list iterator.

Definition at line 97 of file Module.h.


Member Enumeration Documentation

An enumeration for describing the endianess of the target machine.

Enumerator:
AnyEndianness 
LittleEndian 
BigEndian 

Definition at line 100 of file Module.h.

An enumeration for describing the size of a pointer on the target machine.

Enumerator:
AnyPointerSize 
Pointer32 
Pointer64 

Definition at line 103 of file Module.h.


Constructor & Destructor Documentation

Module::Module ( const std::string &  ModuleID  )  [explicit]

The Module constructor. Note that there is no default constructor. You must provide a name for the module upon construction.

Definition at line 75 of file Module.cpp.

References DataLayout.

Module::~Module (  ) 

The module destructor. This will dropAllReferences.

Definition at line 81 of file Module.cpp.

References dropAllReferences().


Member Function Documentation

const std::string& llvm::Module::getModuleIdentifier (  )  const [inline]

Get the module identifier which is, essentially, the name of the module.

Returns:
the module identifier as a string

Definition at line 138 of file Module.h.

Referenced by llvm::CloneModule(), llvm::AsmPrinter::doInitialization(), EmitCamlGlobal(), llvm::Linker::LinkInArchive(), llvm::Linker::LinkModules(), llvm::ProgramInfo::ProgramInfo(), and llvm::MPPassManager::runOnModule().

const std::string& llvm::Module::getDataLayout (  )  const [inline]

Get the data layout string for the module's target platform. This encodes the type sizes and alignments expected by this module.

Returns:
the data layout as a string

Definition at line 143 of file Module.h.

References DataLayout.

Referenced by llvm::CloneModule(), llvm::Linker::LinkModules(), llvm::TargetData::TargetData(), and WriteModuleInfo().

const std::string& llvm::Module::getTargetTriple (  )  const [inline]

Module::Endianness Module::getEndianness (  )  const

Module::PointerSize Module::getPointerSize (  )  const

const std::string& llvm::Module::getModuleInlineAsm (  )  const [inline]

Get any module-scope inline assembly blocks.

Returns:
a string containing the module-scope inline assembly blocks.

Definition at line 159 of file Module.h.

Referenced by llvm::CloneModule(), llvm::AsmPrinter::doInitialization(), llvm::Linker::LinkModules(), and WriteModuleInfo().

void llvm::Module::setModuleIdentifier ( const std::string &  ID  )  [inline]

Set the module identifier.

Definition at line 166 of file Module.h.

void llvm::Module::setDataLayout ( const std::string &  DL  )  [inline]

Set the data layout.

Definition at line 169 of file Module.h.

References DataLayout.

Referenced by llvm::CloneModule(), and llvm::Linker::LinkModules().

void llvm::Module::setTargetTriple ( const std::string &  T  )  [inline]

Set the target triple.

Definition at line 172 of file Module.h.

Referenced by llvm::CloneModule(), and llvm::Linker::LinkModules().

void llvm::Module::setModuleInlineAsm ( const std::string &  Asm  )  [inline]

Set the module-scope inline assembly blocks.

Definition at line 175 of file Module.h.

Referenced by llvm::CloneModule(), and llvm::Linker::LinkModules().

void llvm::Module::appendModuleInlineAsm ( const std::string &  Asm  )  [inline]

Append to the module-scope inline assembly blocks, automatically appending a newline to the end.

Definition at line 179 of file Module.h.

Constant * Module::getOrInsertFunction ( const std::string &  Name,
const FunctionType T,
AttrListPtr  AttributeList 
)

getOrInsertFunction - Look up the specified function in the module symbol table. Four possibilities: 1. If it does not exist, add a prototype for the function and return it. 2. If it exists, and has internal linkage, the existing function is renamed and a new one is inserted. 3. Otherwise, if the existing function has the correct prototype, return the existing function. 4. Finally, the function exists but has the wrong prototype: return the function with a constantexpr cast to the right prototype.

Definition at line 139 of file Module.cpp.

References llvm::Function::Create(), llvm::GlobalValue::ExternalLinkage, F, llvm::ConstantExpr::getBitCast(), llvm::GlobalValue::getType(), llvm::PointerType::getUnqual(), getValueSymbolTable(), llvm::GlobalValue::hasInternalLinkage(), llvm::Function::isIntrinsic(), llvm::ValueSymbolTable::lookup(), llvm::Function::setAttributes(), and llvm::Value::setName().

Referenced by llvm::IntrinsicLowering::AddPrototypes(), EnsureFunctionExists(), llvm::Intrinsic::getDeclaration(), getOrInsertFunction(), llvm::InsertProfilingInitCall(), LowerPartSelect(), LowerPartSet(), ReplaceCallWith(), and UpgradeIntrinsicFunction1().

Constant * Module::getOrInsertFunction ( const std::string &  Name,
const FunctionType T 
)

Definition at line 174 of file Module.cpp.

References llvm::AttrListPtr::get(), and getOrInsertFunction().

Constant * Module::getOrInsertFunction ( const std::string &  Name,
AttrListPtr  AttributeList,
const Type RetTy,
  ... 
)

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 function guarantees to return a constant of pointer to the specified function type or a ConstantExpr BitCast of that type if the named function has a different type. This version of the method takes a null terminated list of function arguments, which makes it easier for clients to use.

Definition at line 185 of file Module.cpp.

References llvm::FunctionType::get(), and getOrInsertFunction().

Constant * Module::getOrInsertFunction ( const std::string &  Name,
const Type RetTy,
  ... 
)

Function * Module::getFunction ( const std::string &  Name  )  const

getFunction - Look up the specified function in the module symbol table. If it does not exist, return null.

Definition at line 223 of file Module.cpp.

References getValueSymbolTable(), and llvm::ValueSymbolTable::lookup().

Referenced by llvm::AsmPrinter::doFinalization(), GetAllUndefinedSymbols(), LinkAlias(), and StripDebugInfo().

Function * Module::getFunction ( const char *  Name  )  const

Definition at line 228 of file Module.cpp.

References getValueSymbolTable(), and llvm::ValueSymbolTable::lookup().

GlobalVariable * Module::getGlobalVariable ( const std::string &  Name,
bool  AllowInternal = false 
) const

getGlobalVariable - Look up the specified global variable in the module symbol table. If it does not exist, return null. If AllowInternal is set to true, this function will return types that have InternalLinkage. By default, these types are not returned.

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 244 of file Module.cpp.

References llvm::dyn_cast(), llvm::GlobalValue::hasInternalLinkage(), llvm::ValueSymbolTable::lookup(), and V.

Referenced by llvm::MachineModuleInfo::AnalyzeModule(), findUsedValues(), getGlobalVariablesUsing(), getNamedGlobal(), llvm::ProgramInfo::getSourceFiles(), llvm::ProgramInfo::getSourceFunctions(), LinkAlias(), and llvm::DebugInfoBuilder::setModule().

GlobalVariable* llvm::Module::getNamedGlobal ( const std::string &  Name  )  const [inline]

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 235 of file Module.h.

References getGlobalVariable().

Referenced by llvm::ExecutionEngine::runStaticConstructorsDestructors(), and StripDebugInfo().

Constant * Module::getOrInsertGlobal ( const std::string &  Name,
const Type Ty 
)

getOrInsertGlobal - Look up the specified global in the module symbol table. 1. If it does not exist, add a declaration of the global and return it. 2. Else, the global exists but has the wrong type: return the function with a constantexpr cast to the right type. 3. Finally, if the existing global is the correct delclaration, return the existing global.

getOrInsertGlobal - Look up the specified global in the module symbol table. 1. If it does not exist, add a declaration of the global and return it. 2. Else, the global exists but has the wrong type: return the function with a constantexpr cast to the right type. 3. Finally, if the existing global is the correct delclaration, return the existing global.

Definition at line 260 of file Module.cpp.

References llvm::GlobalValue::ExternalLinkage, llvm::ConstantExpr::getBitCast(), llvm::GlobalValue::getType(), llvm::PointerType::getUnqual(), getValueSymbolTable(), GV, and llvm::ValueSymbolTable::lookup().

GlobalAlias * Module::getNamedAlias ( const std::string &  Name  )  const

getNamedAlias - Return the first global alias 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 289 of file Module.cpp.

References getValueSymbolTable(), and llvm::ValueSymbolTable::lookup().

Referenced by LinkAlias().

bool Module::addTypeName ( const std::string &  Name,
const Type Ty 
)

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 325 of file Module.cpp.

References llvm::TypeSymbolTable::begin(), llvm::TypeSymbolTable::end(), and getTypeSymbolTable().

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.

getTypeByName - Return the type with the specified name in this module, or null if there is none by that name.

Definition at line 317 of file Module.cpp.

References getTypeSymbolTable(), and llvm::TypeSymbolTable::lookup().

const GlobalListType& llvm::Module::getGlobalList (  )  const [inline]

GlobalListType& llvm::Module::getGlobalList (  )  [inline]

Get the Module's list of global variables.

Definition at line 281 of file Module.h.

const FunctionListType& llvm::Module::getFunctionList (  )  const [inline]

FunctionListType& llvm::Module::getFunctionList (  )  [inline]

Get the Module's list of functions.

Definition at line 285 of file Module.h.

const AliasListType& llvm::Module::getAliasList (  )  const [inline]

Get the Module's list of aliases (constant).

Definition at line 287 of file Module.h.

Referenced by llvm::GlobalAlias::eraseFromParent(), llvm::GlobalAlias::GlobalAlias(), and llvm::GlobalAlias::removeFromParent().

AliasListType& llvm::Module::getAliasList (  )  [inline]

Get the Module's list of aliases.

Definition at line 289 of file Module.h.

const ValueSymbolTable& llvm::Module::getValueSymbolTable (  )  const [inline]

ValueSymbolTable& llvm::Module::getValueSymbolTable (  )  [inline]

Get the Module's symbol table of global variable and function identifiers.

Definition at line 293 of file Module.h.

const TypeSymbolTable& llvm::Module::getTypeSymbolTable (  )  const [inline]

TypeSymbolTable& llvm::Module::getTypeSymbolTable (  )  [inline]

Get the Module's symbol table of types.

Definition at line 297 of file Module.h.

global_iterator llvm::Module::global_begin (  )  [inline]

const_global_iterator llvm::Module::global_begin (  )  const [inline]

Get a constant iterator to the first global variable.

Definition at line 306 of file Module.h.

global_iterator llvm::Module::global_end (  )  [inline]

const_global_iterator llvm::Module::global_end (  )  const [inline]

Get a constant iterator to the last global variable.

Definition at line 310 of file Module.h.

bool llvm::Module::global_empty (  )  const [inline]

Determine if the list of globals is empty.

Definition at line 312 of file Module.h.

Referenced by WriteModuleInfo().

iterator llvm::Module::begin (  )  [inline]

const_iterator llvm::Module::begin (  )  const [inline]

Get a constant iterator to the first function.

Definition at line 321 of file Module.h.

iterator llvm::Module::end (  )  [inline]

const_iterator llvm::Module::end (  )  const [inline]

Get a constant iterator to the last function.

Definition at line 325 of file Module.h.

size_t llvm::Module::size (  )  const [inline]

Determine how many functions are in the Module's list of functions.

Definition at line 327 of file Module.h.

Referenced by getPointerSize().

bool llvm::Module::empty (  )  const [inline]

Determine if the list of functions is empty.

Definition at line 329 of file Module.h.

lib_iterator llvm::Module::lib_begin (  )  const [inline]

Get a constant iterator to beginning of dependent library list.

Definition at line 336 of file Module.h.

Referenced by addLibrary(), llvm::CloneModule(), llvm::Linker::LinkInItems(), llvm::Linker::LinkModules(), and WriteModuleInfo().

lib_iterator llvm::Module::lib_end (  )  const [inline]

Get a constant iterator to end of dependent library list.

Definition at line 338 of file Module.h.

Referenced by addLibrary(), llvm::CloneModule(), llvm::Linker::LinkInItems(), llvm::Linker::LinkModules(), and WriteModuleInfo().