15 #ifndef LLVM_IR_MODULE_H
16 #define LLVM_IR_MODULE_H
27 #include "llvm/Support/DataTypes.h"
28 #include <system_error>
34 class RandomNumberGenerator;
43 return static_cast<Function*
>(&Sentinel);
213 std::string GlobalScopeAsm;
216 std::unique_ptr<GVMaterializer>
218 std::string ModuleID;
219 std::string TargetTriple;
299 GlobalScopeAsm =
Asm;
300 if (!GlobalScopeAsm.empty() &&
301 GlobalScopeAsm[GlobalScopeAsm.size()-1] !=
'\n')
302 GlobalScopeAsm +=
'\n';
308 GlobalScopeAsm +=
Asm;
309 if (!GlobalScopeAsm.empty() &&
310 GlobalScopeAsm[GlobalScopeAsm.size()-1] !=
'\n')
311 GlobalScopeAsm +=
'\n';
516 return &Module::GlobalList;
523 return &Module::FunctionList;
530 return &Module::AliasList;
537 return &Module::NamedMDList;
577 size_t size()
const {
return FunctionList.
size(); }
611 return NamedMDList.
begin();
616 return NamedMDList.
end();
649 bool ShouldPreserveUseListOrder =
false)
const;
694 return reinterpret_cast<Module*
>(MP);
Pass interface - Implemented by all 'passes'.
A parsed version of the target data layout string in and methods for querying it. ...
This class provides a symbol table of name/value pairs.
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
iterator_range< const_named_metadata_iterator > named_metadata() const
NamedMDNode * createSentinel() const
ValueSymbolTable & getValueSymbolTable()
Get the Module's symbol table of global variable and function identifiers.
const_alias_iterator alias_begin() const
Function * provideInitialHead() const
std::error_code materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
iplist< NamedMDNode >::iterator iterator
RandomNumberGenerator * createRNG(const Pass *P) const
Get a RandomNumberGenerator salted for use with this module.
A Module instance is used to store all the information related to an LLVM module. ...
void dematerialize(GlobalValue *GV)
If the GlobalValue is read in, and if the GVMaterializer supports it, release the memory for the func...
void setModuleIdentifier(StringRef ID)
Set the module identifier.
FunctionListType::const_reverse_iterator const_reverse_iterator
The Function constant reverse iterator.
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
static void noteHead(Function *, Function *)
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
named_metadata_iterator named_metadata_end()
static void destroySentinel(NamedMDNode *)
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
void setDataLayout(StringRef Desc)
Set the data layout.
FunctionListType::const_iterator const_iterator
The Function constant iterator.
std::vector< StructType * > getIdentifiedStructTypes() const
void addNodeToList(NamedMDNode *)
const_reverse_iterator rend() const
const AliasListType & getAliasList() const
Get the Module's list of aliases (constant).
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
StructType * getTypeByName(StringRef Name) const
Return the type with the specified name, or null if there is none by that name.
static void destroySentinel(Function *)
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
reverse_iterator rbegin()
Adds a requirement that another module flag be present and have a specified value after linking is pe...
ComdatSymTabType & getComdatSymbolTable()
Get the Module's symbol table for COMDATs.
Appends the two values, which are required to be metadata nodes.
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
GlobalVariable * createSentinel() const
iterator_range< const_iterator > functions() const
AliasListType::const_iterator const_alias_iterator
The Global Alias constant iterator.
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef getName() const
Get a short "name" for the module.
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
const GlobalVariable * getNamedGlobal(StringRef Name) const
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
StructType - Class to represent struct types.
iplist< GlobalAlias > AliasListType
The type for the list of aliases.
GVMaterializer * getMaterializer() const
Retrieves the GVMaterializer, if any, for this Module.
ilist< NamedMDNode > NamedMDListType
The type for the list of named metadata.
const NamedMDListType & getNamedMDList() const
Get the Module's list of named metadata (constant).
ilist_default_traits - Default template traits for intrusive list.
void setModuleInlineAsm(StringRef Asm)
Set the module-scope inline assembly blocks.
const_alias_iterator alias_end() const
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
void removeNodeFromList(NamedMDNode *)
global_iterator global_begin()
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Interface used to provide a module to JIT or interpreter.
std::error_code materializeAllPermanently()
Make sure all GlobalValues in this Module are fully read and clear the Materializer.
std::error_code materializeAll()
Make sure all GlobalValues in this Module are fully read.
FunctionType - Class to represent function types.
NamedMDListType & getNamedMDList()
Get the Module's list of named metadata.
iplist< Function > FunctionListType
The type for the list of functions.
bool named_metadata_empty() const
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining...
GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal) const
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
bool global_empty() const
static AliasListType Module::* getSublistAccess(GlobalAlias *)
const_reverse_iterator rbegin() const
const_global_iterator global_end() const
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
const_named_metadata_iterator named_metadata_begin() const
DataLayout * unwrap(LLVMTargetDataRef P)
FunctionListType::reverse_iterator reverse_iterator
The Function reverse iterator.
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
iterator_range< iterator > functions()
GlobalVariable * ensureHead(GlobalVariable *) const
alias_iterator alias_end()
Function * createSentinel() const
bool isDematerializable(const GlobalValue *GV) const
Returns true if this GV was loaded from this Module's GVMaterializer and the GVMaterializer knows how...
void dump() const
Dump the module to stderr (for debugging).
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeSet AttributeList)
Look up the specified function in the module symbol table.
The instances of the Type class are immutable: once they are created, they are never changed...
AliasListType & getAliasList()
Get the Module's list of aliases.
This is an important class for using LLVM in a threaded context.
Constant * getOrInsertGlobal(StringRef Name, Type *Ty)
Look up the specified global in the module symbol table.
GlobalAlias * ensureHead(GlobalAlias *) const
size_type LLVM_ATTRIBUTE_UNUSED_RESULT size() const
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
This is an important base class in LLVM.
std::error_code materializeMetadata()
GlobalListType::const_iterator const_global_iterator
The Global Variable constant iterator.
static GlobalListType Module::* getSublistAccess(GlobalVariable *)
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
iterator_range< named_metadata_iterator > named_metadata()
const_iterator begin() const
static FunctionListType Module::* getSublistAccess(Function *)
const_global_iterator global_begin() const
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
NamedMDNode * ensureHead(NamedMDNode *) const
const_iterator end() const
GlobalAlias * createSentinel() const
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
static void noteHead(GlobalVariable *, GlobalVariable *)
static void destroySentinel(GlobalVariable *)
#define LLVM_END_WITH_NULL
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
AliasListType::iterator alias_iterator
The Global Alias iterators.
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
reverse_iterator rbegin()
global_iterator global_end()
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
GlobalListType::iterator global_iterator
The Global Variable iterator.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
GlobalListType & getGlobalList()
Get the Module's list of global variables.
void dropTriviallyDeadConstantArrays()
Destroy ConstantArrays in LLVMContext if they are not used.
Function * ensureHead(Function *) const
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB...
GlobalVariable * getNamedGlobal(StringRef Name)
Return the global variable in the module with the specified name, of arbitrary type.
size_t named_metadata_size() const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
NamedMDNode * provideInitialHead() const
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
alias_iterator alias_begin()
std::reverse_iterator< iterator > reverse_iterator
static void destroySentinel(GlobalAlias *)
static NamedMDListType Module::* getSublistAccess(NamedMDNode *)
Uses the specified value, regardless of the behavior or value of the other module.
NamedMDListType::const_iterator const_named_metadata_iterator
The named metadata constant iterators.
A range adaptor for a pair of iterators.
iplist< GlobalVariable > GlobalListType
The type for the list of global variables.
Emits a warning if two values disagree.
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type. ...
FunctionListType & getFunctionList()
Get the Module's list of functions.
A random number generator.
static void noteHead(GlobalAlias *, GlobalAlias *)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
static void noteHead(NamedMDNode *, NamedMDNode *)
Appends the two values, which are required to be metadata nodes.
iterator_range< const_global_iterator > globals() const
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
size_t alias_size() const
FunctionListType::iterator iterator
The Function iterators.
void setTargetTriple(StringRef T)
Set the target triple.
~Module()
The module destructor. This will dropAllReferences.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
static NodeTy * createSentinel()
createSentinel - create the dynamic sentinel
GlobalVariable * provideInitialHead() const
StringMap< Comdat > ComdatSymTabType
The type of the comdat "symbol" table.
NamedMDListType::iterator named_metadata_iterator
The named metadata iterators.
GlobalAlias * provideInitialHead() const
iterator_range< const_alias_iterator > aliases() const
const_named_metadata_iterator named_metadata_end() const
std::reverse_iterator< const_iterator > const_reverse_iterator
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
This class implements an extremely fast bulk output stream that can only output to a stream...
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
named_metadata_iterator named_metadata_begin()
LLVMContext & getContext() const
Get the global data context.
iterator_range< alias_iterator > aliases()