Go to the documentation of this file.
14 #ifndef LLVM_IR_MODULE_H
15 #define LLVM_IR_MODULE_H
49 class ModuleSummaryIndex;
51 class RandomNumberGenerator;
52 template <
class PtrType>
class SmallPtrSetImpl;
185 std::string GlobalScopeAsm;
186 std::unique_ptr<ValueSymbolTable> ValSymTab;
188 std::unique_ptr<MemoryBuffer>
191 std::unique_ptr<GVMaterializer>
193 std::string ModuleID;
194 std::string SourceFileName;
196 std::string TargetTriple;
241 return DL.getStringRepresentation();
297 GlobalScopeAsm = std::string(
Asm);
298 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
299 GlobalScopeAsm +=
'\n';
305 GlobalScopeAsm +=
Asm;
306 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
307 GlobalScopeAsm +=
'\n';
360 template <
typename... ArgsTy>
371 template <
typename... ArgsTy>
378 template <
typename... ArgsTy>
402 bool AllowInternal =
false) {
536 return &Module::GlobalList;
544 return &Module::FunctionList;
553 return &Module::AliasList;
562 return &Module::IFuncList;
571 return &Module::NamedMDList;
614 size_t size()
const {
return FunctionList.size(); }
615 bool empty()
const {
return FunctionList.empty(); }
689 return NamedMDList.begin();
694 return NamedMDList.end();
709 :
public std::iterator<std::input_iterator_tag, DICompileUnit *> {
713 void SkipNoDebugCUs();
717 : CUs(CUs), Idx(Idx) {
783 bool ShouldPreserveUseListOrder =
false,
784 bool IsForDebug =
false)
const;
895 SmallVectorImpl<GlobalValue *> &Vec,
911 return reinterpret_cast<Module*
>(MP);
916 #endif // LLVM_IR_MODULE_H
iterator_range< global_value_iterator > global_values()
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
size_t ifunc_size() const
This class represents lattice values for constants.
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
print lazy value Lazy Value Info Printer Pass
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
A parsed version of the target data layout string in and methods for querying it.
bool named_metadata_empty() const
bool isDwarf64() const
Returns the DWARF format by checking module flags.
const_ifunc_iterator ifunc_end() const
FunctionListType::iterator iterator
The Function iterators.
bool shouldEmitInstrCountChangedRemark()
Return true if size-info optimization remark is enabled, false otherwise.
void dump() const
Dump the module to stderr (for debugging).
iterator_range< ifunc_iterator > ifuncs()
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
@ ModFlagBehaviorFirstVal
debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
StringMap< NamedMDNode * > NamedMDSymTabType
The type for mapping names to named metadata.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
~Module()
The module destructor. This will dropAllReferences.
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
AliasListType & getAliasList()
Get the Module's list of aliases.
ifunc_iterator ifunc_end()
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
const_iterator begin() const
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
size_t named_metadata_size() const
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...
The instances of the Type class are immutable: once they are created, they are never changed.
Optional< CodeModel::Model > getCodeModel() const
Returns the code model (tiny, small, kernel, medium or large model)
StringMap< Comdat > ComdatSymTabType
The type of the comdat "symbol" table.
AliasListType::const_iterator const_alias_iterator
The Global Alias constant iterator.
void setSDKVersion(const VersionTuple &V)
Attach a build SDK version metadata to this module.
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
ilist< NamedMDNode > NamedMDListType
The type for the list of named metadata.
iterator_range< global_object_iterator > global_objects()
Metadata * getProfileSummary(bool IsCS) const
Returns profile summary metadata.
const NamedMDListType & getNamedMDList() const
Get the Module's list of named metadata (constant).
const_reverse_iterator rbegin() const
iterator_range< const_alias_iterator > aliases() const
Iterator wrapper that concatenates sequences together.
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
@ Override
Uses the specified value, regardless of the behavior or value of the other module.
size_t alias_size() const
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
An intrusive list with ownership and callbacks specified/controlled by ilist_traits,...
const_iterator end() const
void setPIELevel(PIELevel::Level PL)
Set the PIE level (small or large model)
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallVectorImpl< GlobalValue * > &Vec, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
VersionTuple getSDKVersion() const
Get the build SDK version metadata.
debug_compile_units_iterator operator++(int)
FunctionListType::const_reverse_iterator const_reverse_iterator
The Function constant reverse iterator.
static AliasListType Module::* getSublistAccess(GlobalAlias *)
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
SymbolTableList< GlobalIFunc > IFuncListType
The type for the list of ifuncs.
void setRtLibUseGOT()
Set that PLT should be avoid for RTLib calls.
void setModuleIdentifier(StringRef ID)
Set the module identifier.
NamedMDListType & getNamedMDList()
Get the Module's list of named metadata.
const_named_metadata_iterator named_metadata_begin() const
void setSemanticInterposition(bool)
Set whether semantic interposition is to be respected.
alias_iterator alias_begin()
iterator_range< global_iterator > globals()
@ Append
Appends the two values, which are required to be metadata nodes.
named_metadata_iterator named_metadata_end()
void setCodeModel(CodeModel::Model CL)
Set the code model (tiny, small, kernel, medium or large)
(vector float) vec_cmpeq(*A, *B) C
SymbolTableList< GlobalVariable > GlobalListType
The type for the list of global variables.
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
iterator_range< named_metadata_iterator > named_metadata()
const_global_iterator global_end() const
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type.
concat_iterator< GlobalObject, iterator, global_iterator > global_object_iterator
IFuncListType::const_iterator const_ifunc_iterator
The Global IFunc constant iterator.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
iterator_range< const_iterator > functions() const
const AliasListType & getAliasList() const
Get the Module's list of aliases (constant).
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Interface used to provide a module to JIT or interpreter.
const_alias_iterator alias_end() const
Attribute unwrap(LLVMAttributeRef Attr)
GlobalListType::iterator global_iterator
The Global Variable iterator.
This class implements an extremely fast bulk output stream that can only output to a stream.
debug_compile_units_iterator & operator++()
Constant * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
DICompileUnit * operator*() const
Represents a version number in the form major[.minor[.subminor[.build]]].
void setModuleInlineAsm(StringRef Asm)
Set the module-scope inline assembly blocks.
void setTargetTriple(StringRef T)
Set the target triple.
const_reverse_iterator rend() const
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type.
global_iterator global_begin()
reverse_iterator rbegin()
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
const_ifunc_iterator ifunc_begin() const
An efficient, type-erasing, non-owning reference to a callable.
const DiagnosticHandler * getDiagHandlerPtr() const
getDiagHandlerPtr - Returns const raw pointer of DiagnosticHandler set by setDiagnosticHandler.
ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)
iterator_range< alias_iterator > aliases()
FunctionCallee getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args)
Same as above, but without the attributes.
StringRef getName() const
Get a short "name" for the module.
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
This is an important base class in LLVM.
unsigned getNumberRegisterParameters() const
Returns the Number of Register ParametersDwarf Version by checking module flags.
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining.
debug_compile_units_iterator debug_compile_units_end() const
base_list_type::iterator iterator
bool global_empty() const
static IFuncListType Module::* getSublistAccess(GlobalIFunc *)
GlobalListType & getGlobalList()
Get the Module's list of global variables.
This is an important class for using LLVM in a threaded context.
global_iterator global_end()
const_alias_iterator alias_begin() const
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.
static GlobalListType Module::* getSublistAccess(GlobalVariable *)
iterator_range< const_ifunc_iterator > ifuncs() const
iterator_range< iterator > functions()
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions inline
void setDataLayout(StringRef Desc)
Set the data layout.
void setSourceFileName(StringRef Name)
Set the module's original source file name.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
bool operator!=(const debug_compile_units_iterator &I) const
llvm::Error materializeMetadata()
debug_compile_units_iterator debug_compile_units_begin() const
A Module instance is used to store all the information related to an LLVM module.
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Like addModuleFlag but replaces the old module flag if it already exists.
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.
void setOwnedMemoryBuffer(std::unique_ptr< MemoryBuffer > MB)
Take ownership of the given memory buffer.
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
IFuncListType::iterator ifunc_iterator
The Global IFunc iterators.
@ Warning
Emits a warning if two values disagree.
StringRef - Represent a constant reference to a string, i.e.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
virtual bool isAnalysisRemarkEnabled(StringRef PassName) const
Return true if analysis remarks are enabled, override to provide different implementation.
unsigned getInstructionCount()
Returns the number of non-debug IR instructions in the module.
Machine Check Debug Module
SymbolTableList< GlobalAlias > AliasListType
The type for the list of aliases.
const_global_iterator global_begin() const
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
AliasListType::iterator alias_iterator
The Global Alias iterators.
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
const std::string & getSourceFileName() const
Get the module's original source file name.
static FunctionListType Module::* getSublistAccess(Function *)
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
alias_iterator alias_end()
GlobalVariable * getNamedGlobal(StringRef Name)
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
bool getSemanticInterposition() const
Returns whether semantic interposition is to be respected.
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
const IFuncListType & getIFuncList() const
Get the Module's list of ifuncs (constant).
DICompileUnit * operator->() const
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
bool isMaterialized() const
Iterator for intrusive lists based on ilist_node.
named_metadata_iterator named_metadata_begin()
Lightweight error class with error context and mandatory checking.
ifunc_iterator ifunc_begin()
LLVMContext & getContext() const
Get the global data context.
size_t global_size() const
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
GVMaterializer * getMaterializer() const
Retrieves the GVMaterializer, if any, for this Module.
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal=false)
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
std::vector< StructType * > getIdentifiedStructTypes() const
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
std::unique_ptr< RandomNumberGenerator > createRNG(const StringRef Name) const
Get a RandomNumberGenerator salted for use with this module.
SymbolTableList< Function > FunctionListType
The type for the list of functions.
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
void setPartialSampleProfileRatio(const ModuleSummaryIndex &Index)
Set the partial sample profile ratio in the profile summary module flag, if applicable.
FunctionListType::reverse_iterator reverse_iterator
The Function reverse iterator.
GlobalListType::const_iterator const_global_iterator
The Global Variable constant iterator.
iterator_range< const_global_iterator > globals() const
FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, Type *RetTy, ArgsTy... Args)
Look up the specified function in the module symbol table.
This class provides a symbol table of name/value pairs.
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
iterator_range< const_named_metadata_iterator > named_metadata() const
Class to hold module path string table and global value map, and encapsulate methods for operating on...
void dropTriviallyDeadConstantArrays()
Destroy ConstantArrays in LLVMContext if they are not used.
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
base_list_type::const_iterator const_iterator
FunctionListType::const_iterator const_iterator
The Function constant iterator.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
static bool isValidModuleFlag(const MDNode &ModFlag, ModFlagBehavior &MFB, MDString *&Key, Metadata *&Val)
Check if the given module flag metadata represents a valid module flag, and store the flag behavior,...
A range adaptor for a pair of iterators.
@ Max
Takes the max of the two values, which are required to be integers.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
const_named_metadata_iterator named_metadata_end() const
ComdatSymTabType & getComdatSymbolTable()
Get the Module's symbol table for COMDATs.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
static NamedMDListType Module::* getSublistAccess(NamedMDNode *)
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind)
Attach profile summary metadata to this module.
IFuncListType & getIFuncList()
Get the Module's list of ifuncs.
An iterator for DICompileUnits that skips those marked NoDebug.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
bool operator==(const debug_compile_units_iterator &I) const
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
Optional< std::vector< StOtherPiece > > Other
Class to represent function types.