llvm::Module

Top-level container for LLVM IR objects in a translation unit.

Synopsis

Declared in <llvm/IR/Module.h>

class Module;

Description

A Module instance is used to store all the information related to an LLVM module. Modules are the top level container of all other LLVM Intermediate Representation (IR) objects. Each module directly contains a list of globals variables, a list of functions, a list of libraries (or other modules) this module depends on, a symbol table, and various data about the target's characteristics.

A module maintains a GlobalList object that is used to hold all constant references to global variables in the module. When a global variable is destroyed, it should have no entries in the GlobalList. The main container class for the LLVM Intermediate Representation.

Types

NameDescription
GlobalAsmFragment A module-scope inline assembly blob with optional target properties.
GlobalAsmProperties Target CPU and feature strings attached to a global asm fragment.
ModuleFlagEntry A single module-flag entry: merge behavior, key, and value.
debug_compile_units_iterator An iterator for DICompileUnits that skips those marked NoDebug.

Type Aliases

NameDescription
AliasListType The type for the list of aliases.
ComdatSymTabType The type of the comdat "symbol" table.
FunctionListType The type for the list of functions.
GlobalListType The type for the list of global variables.
IFuncListType The type for the list of ifuncs.
NamedMDListType The type for the list of named metadata.
NamedMDSymTabType The type for mapping names to named metadata.
alias_iterator The Global Alias iterators.
const_alias_iterator The Global Alias constant iterator
const_global_iterator The Global Variable constant iterator.
const_global_object_iterator Const iterator over functions and global variables as GlobalObject.
const_global_value_iterator Const iterator over functions, globals, aliases, and ifuncs as GlobalValue.
const_ifunc_iterator The Global IFunc constant iterator
const_iterator The Function constant iterator
const_named_metadata_iterator The named metadata constant iterators.
const_reverse_iterator The Function constant reverse iterator.
global_iterator The Global Variable iterator.
global_object_iterator Iterator over functions and global variables as GlobalObject.
global_value_iterator Iterator over functions, globals, aliases, and ifuncs as GlobalValue.
ifunc_iterator The Global IFunc iterators.
iterator The Function iterators.
named_metadata_iterator The named metadata iterators.
reverse_iterator The Function reverse iterator.

Enums

NameDescription
ModFlagBehavior This enumeration defines the supported behaviors of module flags.

Member Functions

NameDescription
Module [constructor]The Module constructor. Note that there is no default constructor. You must provide a name for the module upon construction.
~Module [destructor]The module destructor. This will dropAllReferences.
operator= Move assignment.
addModuleFlag addModuleFlag overloads
alias_begin alias_begin overloads
alias_empty Return true if this module has no aliases.
alias_end alias_end overloads
alias_size Return the number of aliases.
aliases aliases overloads
appendModuleInlineAsm Append to the module-scope inline assembly blocks. A trailing newline is added if the input doesn't have one.
begin begin overloads
convertFromNewDbgValues Convert DbgRecords in every function back to debug value intrinsics.
convertToNewDbgValues Convert debug value intrinsics in every function to DbgRecords.
createRNG Get a RandomNumberGenerator salted for use with this module.
debug_compile_units Return an iterator for all DICompileUnits listed in this Module's llvm.dbg.cu named metadata node and aren't explicitly marked as NoDebug.
debug_compile_units_begin Return an iterator to the first non-NoDebug compile unit.
debug_compile_units_end Return an iterator past the last compile unit.
dropAllReferences Drop all references held by values in this module.
dump Dump the module to stderr (for debugging).
empty Return true if this module has no functions.
end end overloads
eraseAlias Remove Alias from the list and delete it.
eraseGlobalVariable Remove global variable GV from the list and delete it.
eraseIFunc Remove IFunc from the list and delete it.
eraseNamedMDNode Remove MDNode from the list and delete it.
eraseNamedMetadata Remove the given NamedMDNode from this module and delete it.
functions functions overloads
getCodeModel Returns the code model (tiny, small, kernel, medium or large model)
getCodeViewFlag Returns the CodeView Version by checking module flags. Returns zero if not present in module.
getComdatSymbolTable getComdatSymbolTable overloads
getContext Get the global data context.
getControlFlowGuardMode Gets the Control Flow Guard mode.
getDarwinTargetVariantSDKVersion Get the target variant version build SDK version metadata.
getDarwinTargetVariantTriple Get the Darwin target-variant triple for this module.
getDataLayout Get the data layout for the module's target platform.
getDataLayoutStr Get the data layout string for the module's target platform. This is equivalent to getDataLayout()->getStringRepresentation().
getDirectAccessExternalData Get/set whether referencing global variables can use direct access relocations on ELF targets.
getDwarfVersion Returns the Dwarf Version by checking module flags.
getFloatABI Returns the floating-point ABI recorded by the "float-abi" module flag, or the ABI implied by the target triple when the flag is absent.
getFramePointer Get/set whether synthesized functions should get the "frame-pointer" attribute.
getFunction Look up the specified function in the module symbol table. If it does not exist, return null.
getFunctionDefs getFunctionDefs overloads
getFunctionList getFunctionList overloads
getGUID Look up the GUID recorded for a Value, if any.
getGlobalVariable getGlobalVariable overloads
getIdentifiedStructTypes Return the identified (non-literal) struct types used in this module.
getInstructionCount Returns the number of non-debug IR instructions in this module.
getLargeDataThreshold Returns the large data threshold.
getLongDoubleFormat Returns the long double format from the "long-double-type" module flag, or the triple default when the flag is absent.
getMDKindID Return a unique non-zero ID for the specified metadata kind. This ID is uniqued across modules in the current LLVMContext.
getMDKindNames Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMContext.
getMaterializer Retrieves the GVMaterializer, if any, for this Module.
getMaxTLSAlignment Return the maximum TLS alignment in bits from module flags, or 0.
getModuleFlag Return the corresponding value if Key appears in module flags, otherwise return null.
getModuleFlagsMetadata getModuleFlagsMetadata overloads
getModuleIdentifier Get the module identifier which is, essentially, the name of the module.
getModuleInlineAsm Get any module-scope inline assembly blocks.
getName Get a short "name" for the module.
getNamedAlias Return the global alias in the module with the specified name, of arbitrary type. This method returns null if a global with the specified name is not found.
getNamedGlobal getNamedGlobal overloads
getNamedIFunc Return the global ifunc in the module with the specified name, of arbitrary type. This method returns null if a global with the specified name is not found.
getNamedMetadata Return the first NamedMDNode in the module with the specified name. This method returns null if a NamedMDNode with the specified name is not found.
getNamedValue Return the global value in the module with the specified name, of arbitrary type. This method returns null if a global with the specified name is not found.
getNumNamedValues Return the number of global values in the module.
getNumberRegisterParameters Returns the Number of Register ParametersDwarf Version by checking module flags.
getOperandBundleTags Populate client supplied SmallVector with the bundle tags registered in this LLVMContext. The bundle tags are ordered by increasing bundle IDs.
getOrInsertComdat Return the Comdat in the module with the specified name. It is created if it didn't already exist.
getOrInsertFunction getOrInsertFunction overloads
getOrInsertGlobal getOrInsertGlobal overloads
getOrInsertModuleFlagsMetadata Returns the NamedMDNode in the module that represents module-level flags. If module-level flags aren't found, it creates the named metadata that contains them.
getOrInsertNamedMetadata Return the named MDNode in the module with the specified name. This method returns a new NamedMDNode if a NamedMDNode with the specified name is not found.
getOverrideStackAlignment Get/set the stack alignment overridden from the default.
getPICLevel Returns the PIC level (small or large model)
getPIELevel Returns the PIE level (small or large model)
getProfileSummary Returns profile summary metadata. When IsCS is true, use the context sensitive profile summary.
getRtLibUseGOT Returns true if PLT should be avoided for RTLib calls.
getSDKVersion Get the build SDK version metadata.
getSemanticInterposition Returns whether semantic interposition is to be respected.
getSourceFileName Get the module's original source file name.
getStackProtectorGuard Get/set what kind of stack protector guard to use.
getStackProtectorGuardOffset Get/set what offset from the stack protector to use.
getStackProtectorGuardReg Get/set which register to use as the stack protector guard register. The empty string is equivalent to "global". Other values may be "tls" or "sysreg".
getStackProtectorGuardSymbol Get/set a symbol to use as the stack protector guard.
getStackProtectorGuardValueWidth Get/set the width in memory of the stack protector guard value.
getTargetABIFromMD Returns target-abi from MDString, null if target-abi is absent.
getTargetTriple Get the target triple which is a string describing the target host.
getUniqueIntrinsicName Return a unique name for an intrinsic whose mangling is based on an unnamed type. The Proto represents the function prototype.
getUwtable Get/set whether synthesized functions should get the uwtable attribute.
getValueSymbolTable getValueSymbolTable overloads
getWinX64EHUnwindMode Get how unwind information should be generated for x64 Windows.
global_begin global_begin overloads
global_empty Return true if this module has no global variables.
global_end global_end overloads
global_objects global_objects overloads
global_size Return the number of global variables.
global_values global_values overloads
globals globals overloads
hasModuleInlineAsm Return whether there is any module-scope inline assembly.
hasStackProtectorGuardRecord Return whether a __stack_protector_loc section should be emitted.
ifunc_begin ifunc_begin overloads
ifunc_empty Return true if this module has no ifuncs.
ifunc_end ifunc_end overloads
ifunc_size Return the number of ifuncs.
ifuncs ifuncs overloads
insertAlias Insert Alias at the end of the alias list and take ownership.
insertGUID Record a GUID for a Value, typically populated from bitcode.
insertGlobalVariable insertGlobalVariable overloads
insertIFunc Insert IFunc at the end of the alias list and take ownership.
insertNamedMDNode Insert MDNode at the end of the alias list and take ownership.
isDwarf64 Returns the DWARF format by checking module flags.
isMaterialized Return true if this module has no pending materializer.
materialize Make sure the GlobalValue is fully read.
materializeAll Make sure all GlobalValues in this Module are fully read and clear the Materializer.
materializeMetadata Materialize metadata for this module if a materializer is present.
named_metadata named_metadata overloads
named_metadata_begin named_metadata_begin overloads
named_metadata_empty Return true if this module has no named metadata nodes.
named_metadata_end named_metadata_end overloads
named_metadata_size Return the number of named metadata nodes.
prependModuleInlineAsm Prepend to the module-scope inline assembly blocks.
print Print the module to an output stream.
rbegin rbegin overloads
removeAlias Detach Alias from the list but don't delete it.
removeDebugIntrinsicDeclarations Remove debug intrinsic declarations used only by the old debug-info format.
removeGlobalVariable Detach global variable GV from the list but don't delete it.
removeIFunc Detach IFunc from the list but don't delete it.
removeModuleInlineAsm Remove all module-scope inline assembly.
removeNamedMDNode Detach MDNode from the list but don't delete it.
rend rend overloads
setCodeModel Set the code model (tiny, small, kernel, medium or large)
setDarwinTargetVariantSDKVersion Set the target variant version build SDK version metadata.
setDarwinTargetVariantTriple Set the target variant triple which is a string describing a variant of the target host platform.
setDataLayout setDataLayout overloads
setDirectAccessExternalData Set whether referencing global variables can use direct access relocations on ELF targets.
setFramePointer Set whether synthesized functions should get the "frame-pointer" attribute.
setLargeDataThreshold Set the large data threshold.
setLongDoubleFormat Set the long double format.
setMaterializer Set the GVMaterializer used to lazily load GlobalValues.
setModuleFlag setModuleFlag overloads
setModuleIdentifier Set the module identifier.
setModuleInlineAsm setModuleInlineAsm overloads
setOverrideStackAlignment Override the default stack alignment for this module.
setOwnedMemoryBuffer Take ownership of the given memory buffer.
setPICLevel Set the PIC level (small or large model)
setPIELevel Set the PIE level (small or large model)
setPartialSampleProfileRatio Set the partial sample profile ratio in the profile summary module flag, if applicable.
setProfileSummary Attach profile summary metadata to this module.
setRtLibUseGOT Set that PLT should be avoid for RTLib calls.
setSDKVersion Attach a build SDK version metadata to this module.
setSemanticInterposition Set whether semantic interposition is to be respected.
setSourceFileName Set the module's original source file name.
setStackProtectorGuard Set what kind of stack protector guard to use.
setStackProtectorGuardOffset Set the offset from the stack protector guard.
setStackProtectorGuardRecord Set whether to emit a __stack_protector_loc section.
setStackProtectorGuardReg Set which register to use as the stack protector guard register.
setStackProtectorGuardSymbol Set a symbol to use as the stack protector guard.
setStackProtectorGuardValueWidth Set the width in memory of the stack protector guard value.
setTargetTriple Set the target triple.
setUwtable Set whether synthesized functions should get the uwtable attribute.
shouldEmitInstrCountChangedRemark Return true if size-info optimization remark is enabled, false otherwise.
size Return the number of functions.

Static Member Functions

NameDescription
getSublistAccess Return a pointer-to-member for the function list used by list traits.
isValidModFlagBehavior Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB.

Friends

NameDescription
llvm::SymbolTableListTraitsTraits that keep parent links and symbol tables in sync with list changes.
llvm::ConstantLLVM Constant Representation

Non-Member Functions

NameDescription
CloneModuleReturn an exact copy of the specified module.
CloneModuleReturn a copy of the specified module, recording mappings in VMap.
CloneModuleReturn a copy of the specified module with selective definition cloning.
RemapDbgRecordRemap the Values used in the DbgRecord DR using the value map VM.
RemapDbgRecordRangeRemap the Values used in the DbgRecords Range using the value map VM.
SplitModuleSplits a module into multiple linkable partitions.
StripDebugInfoStrip debug info in the module if it exists.
StructuralHashReturns a hash of the module M by hashing all functions and global variables contained within.
UpgradeARCRuntimeConvert calls to ARC runtime functions to intrinsic calls and upgrade the old retain release marker to new module flag format.
UpgradeCFIFunctionsMetadataUpgrade the cfi.functions metadata node by calculating and inserting the GUID for each function entry if it's missing.
UpgradeDebugInfoCheck the debug info version number, if it is out-dated, drop the debug info. Return true if module is modified.
UpgradeModuleFlagsThis checks for module flags which should be upgraded. It returns true if module is modified.
UpgradeNVVMAnnotationsConvert legacy nvvm.annotations metadata to appropriate function attributes.
UpgradeSectionAttributesUpgrade outdated section attributes on globals in a module.
WriteBitcodeToFileWrite the specified module to the specified raw output stream.
annotateValueSiteAnnotate Inst with value-profile metadata from array VDs.
annotateValueSiteAnnotate Inst with value-profile metadata from record InstrProfR.
appendToCompilerUsedAdds global values to the llvm.compiler.used list.
appendToGlobalCtorsAppend F to the global constructors of module M.
appendToGlobalDtorsAppend F to the global destructors of module M.
appendToUsedAdds global values to the llvm.used list.
applyDebugifyMetadataAdd synthesized debug information to a module.
buildModuleSummaryIndexDirect function to compute a ModuleSummaryIndex from a given module.
checkDebugInfoMetadataCheck original debug information after a pass.
checkIfAlreadyInstrumentedCheck if module has flag attached, if not add the flag.
collectDebugInfoMetadataCollect original debug information before a pass.
collectUsedGlobalVariablesGiven "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that global in a SmallVector and return the global itself.
copyModuleAttrToFunctionsCopies module attributes to the functions in the module.
createPGOFuncNameVarCreate a PGO function-name global variable in module M.
createPrivateGlobalForStringCreate a private global holding the bytes of Str for runtime use.
createProfileFileNameVarCreate the module global that holds the default profile output path.
createProfileSamplingVarCreate the module global used for profile sampling.
createSanitizerCtorCreates sanitizer constructor function.
createSanitizerCtorAndInitFunctionsCreates sanitizer constructor function, and calls sanitizer's init function from it.
declareSanitizerInitFunctionDeclare a sanitizer initialization function in module M.
embedBitcodeInModuleEmbed bitcode and optional command-line data as sections in M.
embedBufferInModuleEmbed memory buffer Buf into module M as a global.
getDebugMetadataVersionFromModuleReturn Debug Info Metadata Version by checking module flags.
getDevelopmentModeAdvisorCreate a development-mode (dynamic model) InlineAdvisor for M.
getFloatFnGet the name of the overloaded floating point function corresponding to Ty.
getLazyIRFileModuleCreate a Module from a file, with lazy function-body loading for bitcode.
getLazyIRModuleCreate a Module from a MemoryBuffer, with lazy function-body loading for bitcode.
getOrCreateSanitizerCtorAndInitFunctionsCreates sanitizer constructor and init functions lazily.
getOrInsertLibFuncGet or insert a library function built from a return type and arg types.
getOrInsertLibFuncGet or insert a library function, applying mandatory argument attributes.
getOrInsertLibFuncGet or insert a library function without an explicit attribute list.
getOrInsertLibFuncGet or insert a library function with the given type and no extra attrs.
getOrInsertLibFuncDeleted overload that would otherwise allow an incorrect argument order.
getReleaseModeAdvisorCreate a release-mode (compiled-in model) InlineAdvisor for M.
getReplayInlineAdvisorCreate a replay inline advisor that consults prior inlining remarks.
getUniqueModuleIdProduce a unique identifier for this module by taking the MD5 sum of the names of the module's strong external symbols that are not comdat members.
hasFloatFnCheck whether the overloaded floating point function corresponding to Ty is available.
inferNonMandatoryLibFuncAttrsInfer and set non-mandatory attributes on a library function by name.
internalizeModuleHelper function to internalize functions and variables in a Module.
isAssignmentTrackingEnabledReturn true if assignment tracking is enabled for module M.
isGPUProfTargetReturn true if M targets a GPU eligible for PGO instrumentation.
isIRPGOFlagSetReturn true if INSTR_PROF_RAW_VERSION_VAR is defined in M.
isLibFuncEmittableReturn true if the library function is available and correctly typed.
isLibFuncEmittableReturn true if a named library function is available and correctly typed.
lintModuleLint a module.
lowerGlobalIFuncUsersAsGlobalCtorLower ifunc calls via a global table initialized by a constructor.
lowerUnaryVectorIntrinsicAsLoopLower CI as a loop. CI is a unary intrinsic with a vector argument and is deleted and replaced with a loop.
nameUnamedGlobalsRename all the anon globals in the module using a hash computed from the list of public globals in the module.
needsParamAccessSummaryReturn true if M needs a parameter access summary for stack safety.
optimizeGlobalCtorsListCall "ShouldRemove" for every entry in M's global_ctor list and remove the entries for which it returns true.
parseAndVerifyTry to parse module and verify it. May output verification errors to the errs().
parseAssemblyParse LLVM Assembly from a MemoryBuffer.
parseAssemblyFileParse LLVM Assembly from a file.
parseAssemblyStringParse LLVM Assembly from a string.
parseIRIf the given MemoryBuffer holds a bitcode image, return a Module for it. Otherwise, attempt to parse it as LLVM Assembly and return a Module for it.
parseIRFileIf the given file holds a bitcode image, return a Module for it. Otherwise, attempt to parse it as LLVM Assembly and return a Module for it.
parseModuleFuzzer friendly interface for the llvm bitcode parser.
prepareForDynamicDebuggingPrepare a module for dynamic debugging before running optimizations.
removeFromUsedListsRemoves selected entries from llvm.used and llvm.compiler.used.
renameModuleForThinLTOPerform in-place global value handling on the given Module for exported local functions renamed and promoted for ThinLTO.
setIrrLoopHeaderMetadataAttach irreducible-loop header weight metadata to an instruction.
setKCFITypeSets the KCFI type for the function.
setupModuleAsmPrinterConfigure AsmPrinter for module-level emission of M.
stripDebugifyMetadataStrip out all of the metadata and debug info inserted by debugify.
stripNonLineTableDebugInfoDowngrade the debug info in a module to contain only line table information.
thinLTOFinalizeInModuleApply ThinLTO summary linkage, visibility, and optional attribute updates.
thinLTOInternalizeModuleInternalize TheModule based on the information recorded in the summaries during global summary-based analysis.
transformGlobalCtorsApply Fn to the list of global constructors of module M.
transformGlobalDtorsApply Fn to the list of global destructors of module M.
unwrapUnwrap a historical LLVMModuleProviderRef as a Module pointer.
unwrapConvert an opaque LLVMModuleRef to a Module pointer.
updateCompilerUsedCreate or update the magic "llvm.compiler_used" global in a module.
updatePublicTypeTestCallsUpdate public type-test calls according to whole-program visibility.
updateVCallVisibilityInModuleUpdate virtual-call visibility metadata on vtables in M.
verifyModuleCheck a module for errors.
wrapConvert a Module pointer to an opaque LLVMModuleRef.
writeModuleFuzzer friendly interface for the llvm bitcode printer.
writeThinLinkBitcodeToFileWrite a minimized thin-link bitcode file to Out.
AA::isGPUReturn true iff M target a GPU (and we can use GPU AS reasoning).
AA::isGPUConstantAddressSpaceCheck if the given address space AS corresponds to a GPU constant address space for the target triple in module M.
AA::isGPUGenericAddressSpaceCheck if the given address space AS corresponds to a GPU generic address space for the target triple in module M.
AA::isGPUGlobalAddressSpaceCheck if the given address space AS corresponds to a GPU global address space for the target triple in module M.
AA::isGPULocalAddressSpaceCheck if the given address space AS corresponds to a GPU local/private address space for the target triple in module M.
AA::isGPUSharedAddressSpaceCheck if the given address space AS corresponds to a GPU shared address space for the target triple in module M.
Intrinsic::getDeclarationIfExistsThis version supports overloaded intrinsics.
Intrinsic::getDeclarationIfExistsLook up the Function declaration of intrinsic id if it exists.
Intrinsic::getOrInsertDeclarationLook up or insert the Function declaration for intrinsic id in M.
Intrinsic::getOrInsertDeclarationLook up or insert the Function declaration for intrinsic IID in M.
cgdata::loadModuleForTwoRoundsLoad the optimized bitcode module for the second codegen round.
cgdata::saveModuleForTwoRoundsSave the module before the first codegen round.
codegen::setFunctionAttributesSet function attributes of functions in Module M based on CPU, TuneCPU, Features, and command line flags.
lto::initImportListDistributed ThinLTO: collect the referenced modules based on module summary and initialize ImportList.
memprof::computeUndriftMapCompute an undrifting map from profile locations to IR locations.
memprof::extractCallsFromIRExtract all calls from the IR, keyed by caller GUID.
objcarc::ModuleHasARCTest if the given module looks interesting to run ARC optimization on.
offloading::emitOffloadingEntryCreate an offloading entry used to register this global at runtime.
offloading::getEntryTyReturns the type of the offloading entry we use to store kernels and globals that will be registered with the offloading runtime.
offloading::getOffloadEntryArrayCreates a pair of constants used to iterate the array of offloading entries by accessing the section variables provided by the linker.
offloading::getOffloadEntrySectionReturns the section name for offloading entries based on the target triple.
offloading::getOffloadingEntryInitializerCreate a constant struct initializer used to register this global at runtime.
offloading::wrapCudaBinaryWraps the input fatbinary image into the module M as global symbols and registers the images with the CUDA runtime.
offloading::wrapHIPBinaryWraps the input bundled image into the module M as global symbols and registers the images with the HIP runtime.
offloading::wrapOpenMPBinariesWraps the input device images into the module M as global symbols and registers the images with the OpenMP Offloading runtime libomptarget.
offloading::wrapSYCLBinariesWraps OffloadBinaries in the given Buffers into the module M as global symbols and registers the images with the SYCL Runtime.
omp::containsOpenMPHelper to determine if M contains OpenMP.
omp::getDeviceKernelsGet OpenMP device kernels in M.
omp::isOpenMPDeviceHelper to determine if M is a OpenMP target offloading device module.
orc::cloneExternalModuleToContextClone an unlocked Module onto the given ThreadSafeContext.
orc::cloneFunctionDeclClone a function declaration into a new module.
orc::cloneGlobalAliasDeclClone a global alias declaration into a new module.
orc::cloneGlobalVariableDeclClone a global variable declaration into a new module.
orc::getConstructorsCreate an iterator range over the entries of the llvm.global_ctors array.
orc::getDestructorsCreate an iterator range over the entries of the llvm.global_dtors array.
orc::getStaticInitGVsCreate an iterator range over the GlobalValues that contribute to static initialization.
sampleprofutil::createFSDiscriminatorVariableCreate a global variable to flag FSDiscriminators are used.