15 #ifndef LLVM_IR_MODULE_H 16 #define LLVM_IR_MODULE_H 49 class RandomNumberGenerator;
50 template <
class PtrType>
class SmallPtrSetImpl;
162 : Behavior(B), Key(K), Val(V) {}
176 std::string GlobalScopeAsm;
179 std::unique_ptr<MemoryBuffer>
182 std::unique_ptr<GVMaterializer>
184 std::string ModuleID;
185 std::string SourceFileName;
187 std::string TargetTriple;
259 std::unique_ptr<RandomNumberGenerator>
createRNG(
const Pass*
P)
const;
288 GlobalScopeAsm =
Asm;
289 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
290 GlobalScopeAsm +=
'\n';
296 GlobalScopeAsm +=
Asm;
297 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
298 GlobalScopeAsm +=
'\n';
353 template<
typename... ArgsTy>
355 AttributeList AttributeList,
365 template<
typename... ArgsTy>
371 template <
typename... ArgsTy>
394 bool AllowInternal =
false) {
526 return &Module::GlobalList;
534 return &Module::FunctionList;
543 return &Module::AliasList;
552 return &Module::IFuncList;
561 return &Module::NamedMDList;
603 size_t size()
const {
return FunctionList.size(); }
604 bool empty()
const {
return FunctionList.empty(); }
709 return NamedMDList.begin();
714 return NamedMDList.end();
729 :
public std::iterator<std::input_iterator_tag, DICompileUnit *> {
733 void SkipNoDebugCUs();
737 : CUs(CUs), Idx(Idx) {
803 bool ShouldPreserveUseListOrder =
false,
804 bool IsForDebug =
false)
const;
916 return reinterpret_cast<Module*
>(MP);
921 #endif // LLVM_IR_MODULE_H Pass interface - Implemented by all 'passes'.
debug_compile_units_iterator debug_compile_units_end() const
const_alias_iterator alias_end() const
A parsed version of the target data layout string in and methods for querying it. ...
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
This class provides a symbol table of name/value pairs.
const_named_metadata_iterator named_metadata_begin() const
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_reverse_iterator rend() const
Takes the max of the two values, which are required to be integers.
base_list_type::const_reverse_iterator const_reverse_iterator
This class represents lattice values for constants.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Constant * getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
A Module instance is used to store all the information related to an LLVM module. ...
void setModuleIdentifier(StringRef ID)
Set the module identifier.
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
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.
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
size_t named_metadata_size() const
debug_compile_units_iterator operator++(int)
named_metadata_iterator named_metadata_end()
FunctionListType::iterator iterator
The Function iterators.
An efficient, type-erasing, non-owning reference to a callable.
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
ifunc_iterator ifunc_end()
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
iterator_range< const_iterator > functions() const
bool global_empty() const
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
const_iterator begin() const
void setDataLayout(StringRef Desc)
Set the data layout.
global_object_iterator global_object_begin()
debug_compile_units_iterator & operator++()
const_reverse_iterator rbegin() const
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
Optional< CodeModel::Model > getCodeModel() const
Returns the code model (tiny, small, kernel, medium or large model)
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
const_global_iterator global_end() const
StringRef getName() const
Get a short "name" for the module.
AliasListType::iterator alias_iterator
The Global Alias iterators.
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
iterator_range< const_ifunc_iterator > ifuncs() const
const_ifunc_iterator ifunc_begin() const
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Adds a requirement that another module flag be present and have a specified value after linking is pe...
const AliasListType & getAliasList() const
Get the Module's list of aliases (constant).
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.
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type. ...
iterator_range< const_global_iterator > globals() const
amdgpu Simplify well known AMD library false Value Value const Twine & Name
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
global_value_iterator global_value_end()
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Attribute unwrap(LLVMAttributeRef Attr)
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
Class to represent struct types.
LLVMContext & getContext() const
Get the global data context.
unsigned getInstructionCount()
Returns the number of non-debug IR instructions in the module.
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.
Metadata * getProfileSummary()
Returns profile summary metadata.
APInt operator*(APInt a, uint64_t RHS)
global_iterator global_begin()
Class to represent function types.
void setRtLibUseGOT()
Set that PLT should be avoid for RTLib calls.
NamedMDListType & getNamedMDList()
Get the Module's list of named metadata.
const_iterator end() const
bool operator==(const debug_compile_units_iterator &I) const
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
debug_compile_units_iterator debug_compile_units_begin() const
global_object_iterator global_object_end()
iterator_range< const_alias_iterator > aliases() const
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining...
const_alias_iterator alias_begin() const
IFuncListType & getIFuncList()
Get the Module's list of ifuncs.
const std::string & getSourceFileName() const
Get the module's original source file name.
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
static AliasListType Module::* getSublistAccess(GlobalAlias *)
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
static IFuncListType Module::* getSublistAccess(GlobalIFunc *)
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
Emits an error if two values disagree, otherwise the resulting value is that of the operands...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
iterator_range< iterator > functions()
alias_iterator alias_end()
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
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.
iterator_range< const_global_object_iterator > global_objects() const
This is an important class for using LLVM in a threaded context.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
bool shouldEmitInstrCountChangedRemark()
Return true if size-info optimization remark is enabled, false otherwise.
This is an important base class in LLVM.
ifunc_iterator ifunc_begin()
iterator_range< const_global_value_iterator > global_values() const
void dump() const
Dump the module to stderr (for debugging).
static GlobalListType Module::* getSublistAccess(GlobalVariable *)
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
size_t alias_size() const
iterator_range< named_metadata_iterator > named_metadata()
static FunctionListType Module::* getSublistAccess(Function *)
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
void setCodeModel(CodeModel::Model CL)
Set the code model (tiny, small, kernel, medium or large)
AliasListType::const_iterator const_alias_iterator
The Global Alias constant iterator.
static FunctionType * get(Type *Result, ArrayRef< Type *> Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
const_global_value_iterator global_value_end() const
An iterator for DICompileUnits that skips those marked NoDebug.
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.
const NamedMDListType & getNamedMDList() const
Get the Module's list of named metadata (constant).
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
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_global_value_iterator global_value_begin() const
const IFuncListType & getIFuncList() const
Get the Module's list of ifuncs (constant).
std::vector< StructType * > getIdentifiedStructTypes() const
reverse_iterator rbegin()
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.
global_iterator global_end()
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
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 ...
Iterator for intrusive lists based on ilist_node.
base_list_type::iterator iterator
ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)
GlobalListType & getGlobalList()
Get the Module's list of global variables.
void dropTriviallyDeadConstantArrays()
Destroy ConstantArrays in LLVMContext if they are not used.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
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)
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
alias_iterator alias_begin()
const_ifunc_iterator ifunc_end() const
Constant * getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args)
Same as above, but without the attributes.
size_t ifunc_size() const
static NamedMDListType Module::* getSublistAccess(NamedMDNode *)
Uses the specified value, regardless of the behavior or value of the other module.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
A range adaptor for a pair of iterators.
Constant * getOrInsertFunction(StringRef Name, AttributeList AttributeList, Type *RetTy, ArgsTy... Args)
Look up the specified function in the module symbol table.
Emits a warning if two values disagree.
FunctionListType & getFunctionList()
Get the Module's list of functions.
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
const_global_object_iterator global_object_begin() const
const_named_metadata_iterator named_metadata_end() const
bool isMaterialized() const
void setProfileSummary(Metadata *M)
Attach profile summary metadata to this module.
debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
Represents a version number in the form major[.minor[.subminor[.build]]].
Constant * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
virtual bool isAnalysisRemarkEnabled(StringRef PassName) const
Return true if analysis remarks are enabled, override to provide different implementation.
Appends the two values, which are required to be metadata nodes.
GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal=false)
void setSourceFileName(StringRef Name)
Set the module's original source file name.
void setSDKVersion(const VersionTuple &V)
Attach a build SDK version metadata to this module.
global_value_iterator global_value_begin()
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...
std::unique_ptr< RandomNumberGenerator > createRNG(const Pass *P) const
Get a RandomNumberGenerator salted for use with this module.
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
void setTargetTriple(StringRef T)
Set the target triple.
StructType * getTypeByName(StringRef Name) const
Return the type with the specified name, or null if there is none by that name.
~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()
void setOwnedMemoryBuffer(std::unique_ptr< MemoryBuffer > MB)
Take ownership of the given memory buffer.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
const DiagnosticHandler * getDiagHandlerPtr() const
getDiagHandlerPtr - Returns const raw pointer of DiagnosticHandler set by setDiagnosticHandler.
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
unsigned getNumberRegisterParameters() const
Returns the Number of Register ParametersDwarf Version by checking module flags.
FunctionListType::const_iterator const_iterator
The Function constant iterator.
Lightweight error class with error context and mandatory checking.
bool named_metadata_empty() const
GlobalListType::const_iterator const_global_iterator
The Global Variable constant iterator.
const_global_iterator global_begin() 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...
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
iterator_range< global_iterator > globals()
StringRef - Represent a constant reference to a string, i.e.
Iterator wrapper that concatenates sequences together.
VersionTuple getSDKVersion() const
Get the build SDK version metadata.
iterator_range< global_value_iterator > global_values()
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type. ...
GlobalListType::iterator global_iterator
The Global Variable iterator.
llvm::Error materializeMetadata()
base_list_type::reverse_iterator reverse_iterator
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool operator!=(const debug_compile_units_iterator &I) const
named_metadata_iterator named_metadata_begin()
const_global_object_iterator global_object_end() const
GVMaterializer * getMaterializer() const
Retrieves the GVMaterializer, if any, for this Module.
iterator_range< const_named_metadata_iterator > named_metadata() const
iterator_range< alias_iterator > aliases()