15 #ifndef LLVM_IR_MODULE_H
16 #define LLVM_IR_MODULE_H
48 class RandomNumberGenerator;
49 template <
class PtrType>
class SmallPtrSetImpl;
174 std::string GlobalScopeAsm;
177 std::unique_ptr<MemoryBuffer>
180 std::unique_ptr<GVMaterializer>
182 std::string ModuleID;
183 std::string SourceFileName;
185 std::string TargetTriple;
252 std::unique_ptr<RandomNumberGenerator>
createRNG(
const Pass*
P)
const;
274 GlobalScopeAsm =
Asm;
275 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
276 GlobalScopeAsm +=
'\n';
282 GlobalScopeAsm +=
Asm;
283 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
284 GlobalScopeAsm +=
'\n';
339 template<
typename... ArgsTy>
351 template<
typename... ArgsTy>
375 bool AllowInternal =
false) {
503 return &Module::GlobalList;
511 return &Module::FunctionList;
520 return &Module::AliasList;
529 return &Module::IFuncList;
538 return &Module::NamedMDList;
580 size_t size()
const {
return FunctionList.size(); }
581 bool empty()
const {
return FunctionList.empty(); }
686 return NamedMDList.begin();
691 return NamedMDList.end();
706 :
public std::iterator<std::input_iterator_tag, DICompileUnit *> {
710 void SkipNoDebugCUs();
714 : CUs(CUs), Idx(Idx) {
780 bool ShouldPreserveUseListOrder =
false,
781 bool IsForDebug =
false)
const;
848 SmallPtrSetImpl<GlobalValue *> &Set,
864 return reinterpret_cast<Module*
>(MP);
869 #endif // LLVM_IR_MODULE_H
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
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type. ...
llvm::Error materializeAll()
Make sure all GlobalValues in this Module are fully read and clear the Materializer.
base_list_type::const_iterator const_iterator
ValueSymbolTable & getValueSymbolTable()
Get the Module's symbol table of global variable and function identifiers.
const_alias_iterator alias_begin() const
DICompileUnit * operator*() const
Takes the max of the two values, which are required to be integers.
base_list_type::const_reverse_iterator const_reverse_iterator
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallPtrSetImpl< GlobalValue * > &Set, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
A Module instance is used to store all the information related to an LLVM module. ...
void setModuleIdentifier(StringRef ID)
Set the module identifier.
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
Constant * getOrInsertFunction(StringRef Name, AttributeList AttributeList, Type *RetTy, ArgsTy...Args)
Look up the specified function in the module symbol table.
This provides a very simple, boring adaptor for a begin and end iterator into a range type...
MachineInstrBuilder MachineInstrBuilder &DefMI const MCInstrDesc & Desc
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
debug_compile_units_iterator operator++(int)
named_metadata_iterator named_metadata_end()
ilist< NamedMDNode > NamedMDListType
The type for the list of named metadata.
FunctionListType::iterator iterator
The Function iterators.
Constant * getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy...Args)
Same as above, but without the attributes.
ifunc_iterator ifunc_end()
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
void setDataLayout(StringRef Desc)
Set the data layout.
global_object_iterator global_object_begin()
debug_compile_units_iterator & operator++()
concat_iterator< GlobalValue, iterator, global_iterator, alias_iterator, ifunc_iterator > global_value_iterator
bool operator!=(const debug_compile_units_iterator &I) const
std::vector< StructType * > getIdentifiedStructTypes() const
AliasListType::iterator alias_iterator
The Global Alias iterators.
std::unique_ptr< RandomNumberGenerator > createRNG(const Pass *P) const
Get a RandomNumberGenerator salted for use with this module.
debug_compile_units_iterator debug_compile_units_end() const
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.
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
StructType * getTypeByName(StringRef Name) const
Return the type with the specified name, or null if there is none by that name.
const IFuncListType & getIFuncList() const
Get the Module's list of ifuncs (constant).
Adds a requirement that another module flag be present and have a specified value after linking is pe...
iterator_range< global_object_iterator > global_objects()
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...
iterator_range< const_iterator > functions() const
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
global_value_iterator global_value_end()
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
StringRef getName() const
Get a short "name" for the module.
Attribute unwrap(LLVMAttributeRef Attr)
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Class to represent struct types.
iterator_range< const_global_object_iterator > global_objects() const
GVMaterializer * getMaterializer() const
Retrieves the GVMaterializer, if any, for this Module.
const NamedMDListType & getNamedMDList() const
Get the Module's list of named metadata (constant).
This file contains the simple types necessary to represent the attributes associated with functions a...
void setModuleInlineAsm(StringRef Asm)
Set the module-scope inline assembly blocks.
const_alias_iterator alias_end() const
Metadata * getProfileSummary()
Returns profile summary metadata.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
iterator_range< debug_compile_units_iterator > debug_compile_units() const
Return an iterator for all DICompileUnits listed in this Module's llvm.dbg.cu named metadata node and...
global_iterator global_begin()
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
DICompileUnit * operator->() const
Class to represent function types.
NamedMDListType & getNamedMDList()
Get the Module's list of named metadata.
size_t ifunc_size() const
SymbolTableList< GlobalVariable > GlobalListType
The type for the list of global variables.
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
bool named_metadata_empty() const
global_object_iterator global_object_end()
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...
bool operator==(const debug_compile_units_iterator &I) const
IFuncListType & getIFuncList()
Get the Module's list of ifuncs.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
bool global_empty() const
unsigned getNumberRegisterParameters() const
Returns the Number of Register ParametersDwarf Version by checking module flags.
static AliasListType Module::* getSublistAccess(GlobalAlias *)
const_reverse_iterator rbegin() const
const_global_iterator global_end() const
static IFuncListType Module::* getSublistAccess(GlobalIFunc *)
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
const_named_metadata_iterator named_metadata_begin() const
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
iterator_range< iterator > functions()
const_global_object_iterator global_object_end() const
alias_iterator alias_end()
void dump() const
Dump the module to stderr (for debugging).
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.
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
Constant * getOrInsertGlobal(StringRef Name, Type *Ty)
Look up the specified global in the module symbol table.
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
This is an important base class in LLVM.
ifunc_iterator ifunc_begin()
static GlobalListType Module::* getSublistAccess(GlobalVariable *)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
const_global_value_iterator global_value_end() const
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.
const_iterator end() const
SymbolTableList< GlobalAlias > AliasListType
The type for the list of aliases.
AliasListType::const_iterator const_alias_iterator
The Global Alias constant iterator.
An iterator for DICompileUnits that skips those marked NoDebug.
iterator_range< const_ifunc_iterator > ifuncs() const
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Interface used to provide a module to JIT or interpreter.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
An intrusive list with ownership and callbacks specified/controlled by ilist_traits, only with API safe for polymorphic types.
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
reverse_iterator rbegin()
const_ifunc_iterator ifunc_end() const
global_iterator global_end()
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
concat_iterator< GlobalObject, iterator, global_iterator > global_object_iterator
Iterator for intrusive lists based on ilist_node.
base_list_type::iterator iterator
iterator_range< const_global_value_iterator > global_values() const
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.
bool isMaterialized() const
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
SymbolTableList< Function > FunctionListType
The type for the list of functions.
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)
size_t named_metadata_size() const
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
alias_iterator alias_begin()
const_global_value_iterator global_value_begin() const
static NamedMDListType Module::* getSublistAccess(NamedMDNode *)
Uses the specified value, regardless of the behavior or value of the other module.
A range adaptor for a pair of iterators.
const_ifunc_iterator ifunc_begin() const
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.
void print(raw_ostream &OS, AssemblyAnnotationWriter *AAW, bool ShouldPreserveUseListOrder=false, bool IsForDebug=false) const
Print the module to an output stream with an optional AssemblyAnnotationWriter.
static std::vector< std::string > Flags
void setProfileSummary(Metadata *M)
Attach profile summary metadata to this module.
const_global_object_iterator global_object_begin() const
debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
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.
Appends the two values, which are required to be metadata nodes.
iterator_range< const_global_iterator > globals() const
GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal=false)
void setSourceFileName(StringRef Name)
Set the module's original source file name.
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
global_value_iterator global_value_begin()
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
size_t alias_size() const
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
void setTargetTriple(StringRef T)
Set the target triple.
StringMap< Comdat > ComdatSymTabType
The type of the comdat "symbol" table.
~Module()
The module destructor. This will dropAllReferences.
void setPIELevel(PIELevel::Level PL)
Set the PIE level (small or large model)
iterator_range< ifunc_iterator > ifuncs()
const std::string & getSourceFileName() const
Get the module's original source file name.
void setOwnedMemoryBuffer(std::unique_ptr< MemoryBuffer > MB)
Take ownership of the given memory buffer.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
FunctionListType::const_iterator const_iterator
The Function constant iterator.
iterator_range< const_alias_iterator > aliases() const
Lightweight error class with error context and mandatory checking.
const_named_metadata_iterator named_metadata_end() const
GlobalListType::const_iterator const_global_iterator
The Global Variable constant 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...
SymbolTableList< GlobalIFunc > IFuncListType
The type for the list of ifuncs.
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.
Iterator wrapper that concatenates sequences together.
iterator_range< global_value_iterator > global_values()
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
debug_compile_units_iterator debug_compile_units_begin() const
GlobalListType::iterator global_iterator
The Global Variable iterator.
llvm::Error materializeMetadata()
base_list_type::reverse_iterator reverse_iterator
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()