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));
552 insertGlobalVariable(GlobalList.end(), GV);
557 GlobalList.insert(Where, GV);
568 const GlobalListType &getGlobalList()
const {
return GlobalList; }
570 GlobalListType &getGlobalList() {
return GlobalList; }
573 return &Module::GlobalList;
583 return &Module::FunctionList;
610 NamedMDList.push_back(
MDNode);
617 const AliasListType &getAliasList()
const {
return AliasList; }
619 AliasListType &getAliasList() {
return AliasList; }
622 return &Module::AliasList;
627 const IFuncListType &getIFuncList()
const {
return IFuncList; }
629 IFuncListType &getIFuncList() {
return IFuncList; }
632 return &Module::IFuncList;
637 const NamedMDListType &getNamedMDList()
const {
return NamedMDList; }
639 NamedMDListType &getNamedMDList() {
return NamedMDList; }
641 static NamedMDListType
Module::*getSublistAccess(NamedMDNode*) {
642 return &Module::NamedMDList;
668 return make_range(global_begin(), global_end());
671 return make_range(global_begin(), global_end());
686 size_t size()
const {
return FunctionList.size(); }
687 bool empty()
const {
return FunctionList.empty(); }
708 return make_range(alias_begin(), alias_end());
711 return make_range(alias_begin(), alias_end());
726 return make_range(ifunc_begin(), ifunc_end());
729 return make_range(ifunc_begin(), ifunc_end());
761 return NamedMDList.begin();
766 return NamedMDList.end();
773 return make_range(named_metadata_begin(), named_metadata_end());
776 return make_range(named_metadata_begin(), named_metadata_end());
784 void SkipNoDebugCUs();
823 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
828 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
836 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
850 void dropTriviallyDeadConstantArrays();
860 bool ShouldPreserveUseListOrder =
false,
861 bool IsForDebug =
false)
const;
872 void dropAllReferences();
880 unsigned getNumberRegisterParameters()
const;
883 unsigned getDwarfVersion()
const;
886 bool isDwarf64()
const;
890 unsigned getCodeViewFlag()
const;
919 std::optional<CodeModel::Model> getCodeModel()
const;
933 Metadata *getProfileSummary(
bool IsCS)
const;
937 bool getSemanticInterposition()
const;
940 void setSemanticInterposition(
bool);
943 bool getRtLibUseGOT()
const;
946 void setRtLibUseGOT();
950 bool getDirectAccessExternalData()
const;
951 void setDirectAccessExternalData(
bool Value);
963 StringRef getStackProtectorGuard()
const;
964 void setStackProtectorGuard(
StringRef Kind);
969 StringRef getStackProtectorGuardReg()
const;
973 StringRef getStackProtectorGuardSymbol()
const;
974 void setStackProtectorGuardSymbol(
StringRef Symbol);
977 int getStackProtectorGuardOffset()
const;
978 void setStackProtectorGuardOffset(
int Offset);
981 unsigned getOverrideStackAlignment()
const;
982 void setOverrideStackAlignment(
unsigned Align);
984 unsigned getMaxTLSAlignment()
const;
999 void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB);
1009 StringRef getDarwinTargetVariantTriple()
const;
1013 void setDarwinTargetVariantTriple(
StringRef T);
1021 void setDarwinTargetVariantSDKVersion(
VersionTuple Version);
1028 SmallVectorImpl<GlobalValue *> &Vec,
1033 M.print(O,
nullptr);
1044 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()
void removeIFunc(GlobalIFunc *IFunc)
Detach IFunc from the list but don't delete it.
const_global_iterator global_begin() const
const_iterator begin() const
ifunc_iterator ifunc_begin()
void eraseNamedMDNode(NamedMDNode *MDNode)
Remove MDNode from the list and delete it.
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.
void insertIFunc(GlobalIFunc *IFunc)
Insert IFunc at the end of the alias list and take ownership.
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
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()
bool named_metadata_empty() const
ValueSymbolTable & getValueSymbolTable()
Get the Module's symbol table of global variable and function identifiers.
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_alias_iterator alias_end() const
void removeAlias(GlobalAlias *Alias)
Detach Alias from the list but don't delete it.
iterator_range< named_metadata_iterator > named_metadata()
named_metadata_iterator named_metadata_begin()
ifunc_iterator ifunc_end()
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.
void insertGlobalVariable(GlobalListType::iterator Where, GlobalVariable *GV)
Insert global variable GV into the global variable list before Where and take ownership.
alias_iterator alias_end()
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)
void eraseIFunc(GlobalIFunc *IFunc)
Remove IFunc from the list and delete it.
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
iterator_range< global_iterator > globals()
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.
void eraseAlias(GlobalAlias *Alias)
Remove Alias from the list and delete it.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
void eraseGlobalVariable(GlobalVariable *GV)
Remove global variable GV from the list and delete it.
reverse_iterator rbegin()
FunctionCallee getOrInsertFunction(StringRef Name, Type *RetTy, ArgsTy... Args)
Same as above, but without the attributes.
void insertNamedMDNode(NamedMDNode *MDNode)
Insert MDNode at the end of the alias list and take ownership.
const_named_metadata_iterator named_metadata_end() const
void removeNamedMDNode(NamedMDNode *MDNode)
Detach MDNode from the list but don't delete it.
AliasListType::iterator alias_iterator
The Global Alias iterators.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
void insertGlobalVariable(GlobalVariable *GV)
Insert global variable GV at the end of the global variable list and take ownership.
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.
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
const_iterator end() const
void setSourceFileName(StringRef Name)
Set the module's original source file name.
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.
void insertAlias(GlobalAlias *Alias)
Insert Alias at the end of the alias list and take ownership.
debug_compile_units_iterator debug_compile_units_begin() const
void setTargetTriple(StringRef T)
Set the target triple.
void removeGlobalVariable(GlobalVariable *GV)
Detach global variable GV from the list but don't delete it.
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.
LLVM Value Representation.
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)