15 #ifndef LLVM_IR_MODULE_H
16 #define LLVM_IR_MODULE_H
28 #include "llvm/Support/DataTypes.h"
31 template <
typename T>
class Optional;
37 class RandomNumberGenerator;
39 template <
class PtrType>
class SmallPtrSetImpl;
159 std::string GlobalScopeAsm;
162 std::unique_ptr<MemoryBuffer>
165 std::unique_ptr<GVMaterializer>
167 std::string ModuleID;
168 std::string SourceFileName;
170 std::string TargetTriple;
259 GlobalScopeAsm =
Asm;
260 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
261 GlobalScopeAsm +=
'\n';
267 GlobalScopeAsm +=
Asm;
268 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
269 GlobalScopeAsm +=
'\n';
475 return &Module::GlobalList;
482 return &Module::FunctionList;
489 return &Module::AliasList;
496 return &Module::IFuncList;
503 return &Module::NamedMDList;
543 size_t size()
const {
return FunctionList.size(); }
544 bool empty()
const {
return FunctionList.empty(); }
624 return NamedMDList.begin();
629 return NamedMDList.end();
644 :
public std::iterator<std::input_iterator_tag, DICompileUnit *> {
647 void SkipNoDebugCUs();
650 : CUs(CUs), Idx(Idx) {
711 bool ShouldPreserveUseListOrder =
false,
712 bool IsForDebug =
false)
const;
775 SmallPtrSetImpl<GlobalValue *> &Set,
791 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
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.
ValueSymbolTable & getValueSymbolTable()
Get the Module's symbol table of global variable and function identifiers.
const_alias_iterator alias_begin() const
DICompileUnit * operator*() const
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
SymbolTableList< GlobalVariable > GlobalListType
The type for the list of global variables.
RandomNumberGenerator * createRNG(const Pass *P) const
Get a RandomNumberGenerator salted for use with this module.
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 ...
A Module instance is used to store all the information related to an LLVM module. ...
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).
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()
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.
FunctionListType::const_iterator const_iterator
The Function constant iterator.
global_object_iterator global_object_begin()
debug_compile_units_iterator & operator++()
bool operator!=(const debug_compile_units_iterator &I) const
std::vector< StructType * > getIdentifiedStructTypes() const
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
AliasListType::const_iterator const_alias_iterator
The Global Alias constant iterator.
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
struct fuzzer::@269 Flags
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.
SymbolTableList< GlobalAlias > AliasListType
The type for the list of aliases.
const GlobalVariable * getNamedGlobal(StringRef Name) const
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.
ilist< NamedMDNode > NamedMDListType
The type for the list of named metadata.
const NamedMDListType & getNamedMDList() const
Get the Module's list of named metadata (constant).
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()
concat_iterator< const GlobalObject, const_iterator, const_global_iterator > const_global_object_iterator
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
bool named_metadata_empty() const
static GCRegistry::Add< OcamlGC > B("ocaml","ocaml 3.10-compatible GC")
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.
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
static IFuncListType Module::* getSublistAccess(GlobalIFunc *)
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
const_named_metadata_iterator named_metadata_begin() const
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()
const_global_object_iterator global_object_end() const
alias_iterator alias_end()
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.
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()
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.
SymbolTableList< Function > FunctionListType
The type for the list of functions.
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
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.
#define LLVM_END_WITH_NULL
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
AliasListType::iterator alias_iterator
The Global Alias iterators.
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).
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.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Iterator for intrusive lists based on ilist_node.
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
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
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
alias_iterator alias_begin()
static NamedMDListType Module::* getSublistAccess(NamedMDNode *)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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.
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.
A random number generator.
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.
concat_iterator< GlobalObject, iterator, global_iterator > global_object_iterator
iterator_range< const_global_iterator > globals() const
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).
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
size_t alias_size() const
FunctionListType::iterator iterator
The Function iterators.
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
void setTargetTriple(StringRef T)
Set the target triple.
~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)
StringMap< Comdat > ComdatSymTabType
The type of the comdat "symbol" table.
NamedMDListType::iterator named_metadata_iterator
The named metadata iterators.
IFuncListType::iterator ifunc_iterator
The Global IFunc iterators.
iterator_range< const_alias_iterator > aliases() const
Lightweight error class with error context and mandatory checking.
const_named_metadata_iterator named_metadata_end() const
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.
Iterator wrapper that concatenates sequences together.
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
SymbolTableList< GlobalIFunc > IFuncListType
The type for the list of ifuncs.
llvm::Error materializeMetadata()
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.
IFuncListType::const_iterator const_ifunc_iterator
The Global IFunc constant iterator.
iterator_range< alias_iterator > aliases()