14#ifndef LLVM_IR_MODULE_H
15#define LLVM_IR_MODULE_H
49class ModuleSummaryIndex;
50class RandomNumberGenerator;
154 ModFlagBehaviorLastVal = Min
159 static bool isValidModFlagBehavior(
Metadata *MD, ModFlagBehavior &MFB);
163 static bool isValidModuleFlag(
const MDNode &ModFlag, ModFlagBehavior &MFB,
172 : Behavior(
B), Key(K), Val(V) {}
181 GlobalListType GlobalList;
182 FunctionListType FunctionList;
183 AliasListType AliasList;
184 IFuncListType IFuncList;
185 NamedMDListType NamedMDList;
186 std::string GlobalScopeAsm;
187 std::unique_ptr<ValueSymbolTable> ValSymTab;
188 ComdatSymTabType ComdatSymTab;
189 std::unique_ptr<MemoryBuffer>
192 std::unique_ptr<GVMaterializer>
194 std::string ModuleID;
195 std::string SourceFileName;
197 std::string TargetTriple;
199 NamedMDSymTabType NamedMDSymTab;
205 UniquedIntrinsicNames;
233 unsigned getInstructionCount()
const;
250 return DL.getStringRepresentation();
277 std::unique_ptr<RandomNumberGenerator> createRNG(
const StringRef Name)
const;
282 return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
306 GlobalScopeAsm = std::string(Asm);
307 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
308 GlobalScopeAsm +=
'\n';
314 GlobalScopeAsm += Asm;
315 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
316 GlobalScopeAsm +=
'\n';
329 unsigned getNumNamedValues()
const;
344 std::vector<StructType *> getIdentifiedStructTypes()
const;
379 template <
typename... ArgsTy>
384 return getOrInsertFunction(
Name,
385 FunctionType::get(
RetTy, ArgTys,
false),
390 template <
typename... ArgsTy>
397 template <
typename... ArgsTy>
421 bool AllowInternal =
false) {
434 static_cast<const Module *
>(
this)->getNamedGlobal(
Name));
555 return &Module::GlobalList;
563 return &Module::FunctionList;
572 return &Module::AliasList;
581 return &Module::IFuncList;
590 return &Module::NamedMDList;
615 return make_range(global_begin(), global_end());
618 return make_range(global_begin(), global_end());
633 size_t size()
const {
return FunctionList.size(); }
634 bool empty()
const {
return FunctionList.empty(); }
655 return make_range(alias_begin(), alias_end());
658 return make_range(alias_begin(), alias_end());
673 return make_range(ifunc_begin(), ifunc_end());
676 return make_range(ifunc_begin(), ifunc_end());
708 return NamedMDList.begin();
713 return NamedMDList.end();
720 return make_range(named_metadata_begin(), named_metadata_end());
723 return make_range(named_metadata_begin(), named_metadata_end());
731 void SkipNoDebugCUs();
770 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
775 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
783 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
797 void dropTriviallyDeadConstantArrays();
807 bool ShouldPreserveUseListOrder =
false,
808 bool IsForDebug =
false)
const;
819 void dropAllReferences();
827 unsigned getNumberRegisterParameters()
const;
830 unsigned getDwarfVersion()
const;
833 bool isDwarf64()
const;
837 unsigned getCodeViewFlag()
const;
866 std::optional<CodeModel::Model> getCodeModel()
const;
880 Metadata *getProfileSummary(
bool IsCS)
const;
884 bool getSemanticInterposition()
const;
887 void setSemanticInterposition(
bool);
890 bool getRtLibUseGOT()
const;
893 void setRtLibUseGOT();
905 StringRef getStackProtectorGuard()
const;
906 void setStackProtectorGuard(
StringRef Kind);
911 StringRef getStackProtectorGuardReg()
const;
915 StringRef getStackProtectorGuardSymbol()
const;
916 void setStackProtectorGuardSymbol(
StringRef Symbol);
919 int getStackProtectorGuardOffset()
const;
920 void setStackProtectorGuardOffset(
int Offset);
923 unsigned getOverrideStackAlignment()
const;
924 void setOverrideStackAlignment(
unsigned Align);
939 void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB);
949 StringRef getDarwinTargetVariantTriple()
const;
953 void setDarwinTargetVariantTriple(
StringRef T);
961 void setDarwinTargetVariantSDKVersion(
VersionTuple Version);
968 SmallVectorImpl<GlobalValue *> &Vec,
984 return reinterpret_cast<Module*
>(MP);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the StringMap class.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
#define LLVM_EXTERNAL_VISIBILITY
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
std::optional< std::vector< StOtherPiece > > Other
static Function * getFunction(Constant *C)
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
Machine Check Debug Module
static Constant * getOrInsertGlobal(Module &M, StringRef Name, Type *Ty)
static GlobalVariable * getGlobalVariable(Module &M, Type *Ty, WebAssemblyTargetMachine &TM, const char *Name)
This is an important base class in LLVM.
A parsed version of the target data layout string in and methods for querying it.
Lightweight error class with error context and mandatory checking.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
This is an important class for using LLVM in a threaded context.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
An iterator for DICompileUnits that skips those marked NoDebug.
debug_compile_units_iterator & operator++()
bool operator==(const debug_compile_units_iterator &I) const
debug_compile_units_iterator operator++(int)
std::input_iterator_tag iterator_category
std::ptrdiff_t difference_type
debug_compile_units_iterator(NamedMDNode *CUs, unsigned Idx)
bool operator!=(const debug_compile_units_iterator &I) const
A Module instance is used to store all the information related to an LLVM module.
global_iterator global_begin()
const_global_iterator global_begin() const
const_iterator begin() const
ifunc_iterator ifunc_begin()
const std::string & getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
LLVMContext & getContext() const
Get the global data context.
iterator_range< const_alias_iterator > aliases() const
void setModuleInlineAsm(StringRef Asm)
Set the module-scope inline assembly blocks.
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
global_iterator global_end()
GlobalVariable * getNamedGlobal(StringRef Name)
size_t alias_size() const
const_global_iterator global_end() const
bool global_empty() const
static NamedMDListType Module::* getSublistAccess(NamedMDNode *)
FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, Type *RetTy, ArgsTy... Args)
Look up the specified function in the module symbol table.
const_ifunc_iterator ifunc_end() const
iterator_range< ifunc_iterator > ifuncs()
IFuncListType & getIFuncList()
Get the Module's list of ifuncs.
bool named_metadata_empty() const
ValueSymbolTable & getValueSymbolTable()
Get the Module's symbol table of global variable and function identifiers.
static IFuncListType Module::* getSublistAccess(GlobalIFunc *)
const_named_metadata_iterator named_metadata_begin() const
size_t global_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...
iterator_range< iterator > functions()
StringRef getName() const
Get a short "name" for the module.
GVMaterializer * getMaterializer() const
Retrieves the GVMaterializer, if any, for this Module.
const std::string & getSourceFileName() const
Get the module's original source file name.
IFuncListType::iterator ifunc_iterator
The Global IFunc iterators.
const GlobalListType & getGlobalList() const
Get the Module's list of global variables (constant).
const_alias_iterator alias_end() const
iterator_range< named_metadata_iterator > named_metadata()
named_metadata_iterator named_metadata_begin()
ifunc_iterator ifunc_end()
const IFuncListType & getIFuncList() const
Get the Module's list of ifuncs (constant).
AliasListType & getAliasList()
Get the Module's list of aliases.
GlobalListType::const_iterator const_global_iterator
The Global Variable constant iterator.
iterator_range< alias_iterator > aliases()
const std::string & getTargetTriple() const
Get the target triple which is a string describing the target host.
alias_iterator alias_end()
GlobalListType & getGlobalList()
Get the Module's list of global variables.
const_alias_iterator alias_begin() const
const_reverse_iterator rbegin() const
alias_iterator alias_begin()
FunctionListType::iterator iterator
The Function iterators.
GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal=false)
bool shouldEmitInstrCountChangedRemark()
Return true if size-info optimization remark is enabled, false otherwise.
GlobalListType::iterator global_iterator
The Global Variable iterator.
FunctionListType::const_reverse_iterator const_reverse_iterator
The Function constant reverse iterator.
FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, FunctionType *Invalid, ArgsTy... Args)=delete
const AliasListType & getAliasList() const
Get the Module's list of aliases (constant).
iterator_range< global_iterator > globals()
const FunctionListType & getFunctionList() const
Get the Module's list of functions (constant).
const_reverse_iterator rend() const
iterator_range< const_named_metadata_iterator > named_metadata() const
IFuncListType::const_iterator const_ifunc_iterator
The Global IFunc constant iterator.
size_t ifunc_size() const
FunctionListType & getFunctionList()
Get the Module's list of functions.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
reverse_iterator rbegin()
FunctionCallee getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args)
Same as above, but without the attributes.
const_named_metadata_iterator named_metadata_end() const
AliasListType::iterator alias_iterator
The Global Alias iterators.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
const NamedMDListType & getNamedMDList() const
Get the Module's list of named metadata (constant).
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
size_t named_metadata_size() const
named_metadata_iterator named_metadata_end()
bool isMaterialized() const
const GlobalVariable * getNamedGlobal(StringRef Name) const
Return the global variable in the module with the specified name, of arbitrary type.
AliasListType::const_iterator const_alias_iterator
The Global Alias constant iterator.
NamedMDListType & getNamedMDList()
Get the Module's list of named metadata.
ComdatSymTabType & getComdatSymbolTable()
Get the Module's symbol table for COMDATs.
FunctionListType::reverse_iterator reverse_iterator
The Function reverse iterator.
iterator_range< const_iterator > functions() const
iterator_range< const_global_iterator > globals() const
void setModuleIdentifier(StringRef ID)
Set the module identifier.
iterator_range< const_ifunc_iterator > ifuncs() const
static AliasListType Module::* getSublistAccess(GlobalAlias *)
const_iterator end() const
void setSourceFileName(StringRef Name)
Set the module's original source file name.
static GlobalListType Module::* getSublistAccess(GlobalVariable *)
const_ifunc_iterator ifunc_begin() const
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
static FunctionListType Module::* getSublistAccess(Function *)
void appendModuleInlineAsm(StringRef Asm)
Append to the module-scope inline assembly blocks.
FunctionListType::const_iterator const_iterator
The Function constant iterator.
debug_compile_units_iterator debug_compile_units_begin() const
void setTargetTriple(StringRef T)
Set the target triple.
debug_compile_units_iterator debug_compile_units_end() const
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
The instances of the Type class are immutable: once they are created, they are never changed.
This class provides a symbol table of name/value pairs.
Represents a version number in the form major[.minor[.subminor[.build]]].
Iterator wrapper that concatenates sequences together.
An efficient, type-erasing, non-owning reference to a callable.
Iterator for intrusive lists based on ilist_node.
base_list_type::const_reverse_iterator const_reverse_iterator
base_list_type::reverse_iterator reverse_iterator
base_list_type::const_iterator const_iterator
base_list_type::iterator iterator
An intrusive list with ownership and callbacks specified/controlled by ilist_traits,...
A range adaptor for a pair of iterators.
This class implements an extremely fast bulk output stream that can only output to a stream.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
struct LLVMOpaqueModuleProvider * LLVMModuleProviderRef
Interface used to provide a module to JIT or interpreter.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
APInt operator*(APInt a, uint64_t RHS)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Attribute unwrap(LLVMAttributeRef Attr)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
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 ...
This struct is a compact representation of a valid (non-zero power of two) alignment.
ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)