14#ifndef LLVM_IR_MODULE_H
15#define LLVM_IR_MODULE_H
161 static bool isValidModFlagBehavior(
Metadata *MD, ModFlagBehavior &MFB);
189 return !(*
this ==
Other);
200 if (!Asm.empty() && Asm.back() !=
'\n')
217 GlobalListType GlobalList;
218 FunctionListType FunctionList;
219 AliasListType AliasList;
220 IFuncListType IFuncList;
221 NamedMDListType NamedMDList;
224 std::unique_ptr<ValueSymbolTable> ValSymTab;
225 ComdatSymTabType ComdatSymTab;
226 std::unique_ptr<MemoryBuffer>
229 std::unique_ptr<GVMaterializer>
231 std::string ModuleID;
232 std::string SourceFileName;
238 NamedMDSymTabType NamedMDSymTab;
244 UniquedIntrinsicNames;
265 for (
auto &
F : *
this) {
266 F.convertToNewDbgValues();
276 for (
auto &
F : *
this) {
277 if (
F.convertFromNewDbgValues())
303 unsigned getInstructionCount()
const;
320 return DL.getStringRepresentation();
335 return GlobalScopeAsm;
340 return GlobalScopeAsm;
355 std::unique_ptr<RandomNumberGenerator> createRNG(
const StringRef Name)
const;
360 return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
386 GlobalScopeAsm.clear();
391 GlobalScopeAsm.clear();
398 if (Fragment.empty())
401 if (!GlobalScopeAsm.empty() &&
402 GlobalScopeAsm.back().hasSameProperties(Fragment)) {
403 GlobalScopeAsm.back().Asm += Fragment.Asm;
405 GlobalScopeAsm.emplace_back(std::move(Fragment));
411 if (Fragment.empty())
414 if (!GlobalScopeAsm.empty() &&
415 GlobalScopeAsm.front().hasSameProperties(Fragment)) {
416 GlobalScopeAsm.front().Asm.insert(0, Fragment.Asm);
418 GlobalScopeAsm.insert(GlobalScopeAsm.begin(), std::move(Fragment));
432 unsigned getNumNamedValues()
const;
436 unsigned getMDKindID(
StringRef Name)
const;
447 std::vector<StructType *> getIdentifiedStructTypes()
const;
469 AttributeList AttributeList);
475 template <
typename... ArgsTy>
477 AttributeList AttributeList,
Type *RetTy,
486 template <
typename... ArgsTy>
493 template <
typename... ArgsTy>
517 bool AllowInternal =
false) {
530 static_cast<const Module *
>(
this)->getNamedGlobal(Name));
662 GlobalList.insert(Where, GV);
668 const auto It = ValueToGUIDMap.find(V);
669 if (It == ValueToGUIDMap.end())
672 return It->getSecond();
676 const auto [It, WasInserted] = ValueToGUIDMap.insert({V, GUID});
678 (void)It, (
void)WasInserted;
681 assert((It->second == GUID) &&
"insertGUID called with different value");
697 const GlobalListType &getGlobalList()
const {
return GlobalList; }
699 GlobalListType &getGlobalList() {
return GlobalList; }
702 return &Module::GlobalList;
712 return &Module::FunctionList;
739 NamedMDList.push_back(
MDNode);
746 const AliasListType &getAliasList()
const {
return AliasList; }
748 AliasListType &getAliasList() {
return AliasList; }
751 return &Module::AliasList;
756 const IFuncListType &getIFuncList()
const {
return IFuncList; }
758 IFuncListType &getIFuncList() {
return IFuncList; }
761 return &Module::IFuncList;
766 const NamedMDListType &getNamedMDList()
const {
return NamedMDList; }
768 NamedMDListType &getNamedMDList() {
return NamedMDList; }
770 static NamedMDListType
Module::*getSublistAccess(NamedMDNode*) {
771 return &Module::NamedMDList;
815 size_t size()
const {
return FunctionList.size(); }
816 bool empty()
const {
return FunctionList.empty(); }
829 [](
Function &
F) {
return !
F.isDeclaration(); });
901 return NamedMDList.begin();
906 return NamedMDList.end();
934 : CUs(CUs), Idx(Idx) {
991 bool ShouldPreserveUseListOrder =
false,
992 bool IsForDebug =
false)
const;
1003 void dropAllReferences();
1011 unsigned getNumberRegisterParameters()
const;
1014 unsigned getDwarfVersion()
const;
1017 bool isDwarf64()
const;
1021 unsigned getCodeViewFlag()
const;
1082 std::optional<uint64_t> getLargeDataThreshold()
const;
1085 void setLargeDataThreshold(
uint64_t Threshold);
1096 Metadata *getProfileSummary(
bool IsCS)
const;
1100 bool getSemanticInterposition()
const;
1103 void setSemanticInterposition(
bool);
1106 bool getRtLibUseGOT()
const;
1109 void setRtLibUseGOT();
1113 bool getDirectAccessExternalData()
const;
1114 void setDirectAccessExternalData(
bool Value);
1126 StringRef getStackProtectorGuard()
const;
1127 void setStackProtectorGuard(
StringRef Kind);
1132 StringRef getStackProtectorGuardReg()
const;
1136 StringRef getStackProtectorGuardSymbol()
const;
1137 void setStackProtectorGuardSymbol(
StringRef Symbol);
1140 int getStackProtectorGuardOffset()
const;
1141 void setStackProtectorGuardOffset(
int Offset);
1144 std::optional<unsigned> getStackProtectorGuardValueWidth()
const;
1145 void setStackProtectorGuardValueWidth(
unsigned Width);
1148 bool hasStackProtectorGuardRecord()
const;
1149 void setStackProtectorGuardRecord(
bool Flag);
1152 unsigned getOverrideStackAlignment()
const;
1153 void setOverrideStackAlignment(
unsigned Align);
1155 unsigned getMaxTLSAlignment()
const;
1170 void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB);
1180 StringRef getDarwinTargetVariantTriple()
const;
1184 void setDarwinTargetVariantTriple(
StringRef T);
1213 M.print(O,
nullptr);
1224 return reinterpret_cast<Module*
>(MP);
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the StringMap class.
Lower uses of LDS variables from non kernel functions
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
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< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define DEFINE_SIMPLE_CONVERSION_FUNCTIONS(ty, ref)
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 CodeModel::Model getCodeModel(const PPCSubtarget &S, const TargetMachine &TM, const MachineOperand &MO)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
static Function * getFunction(FunctionType *Ty, const Twine &Name, Module *M)
static GlobalVariable * getGlobalVariable(Module &M, Type *Ty, const char *Name)
Represent a constant reference to an array (0 or more elements consecutively in memory),...
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.
static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
uint64_t GUID
Declare a type to represent a global unique identifier for a global value.
This is an important class for using LLVM in a threaded context.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
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
DICompileUnit * value_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.
const Triple & getTargetTriple() const
Get the target triple which is a string describing the target host.
StringMap< Comdat > ComdatSymTabType
The type of the comdat "symbol" table.
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
NamedMDNode * getNamedMetadata(StringRef Name) const
Return the first NamedMDNode in the module with the specified name.
ifunc_iterator ifunc_begin()
void eraseNamedMDNode(NamedMDNode *MDNode)
Remove MDNode from the list and delete it.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
@ AppendUnique
Appends the two values, which are required to be metadata nodes.
@ Override
Uses the specified value, regardless of the behavior or value of the other module.
@ Warning
Emits a warning if two values disagree.
@ Error
Emits an error if two values disagree, otherwise the resulting value is that of the operands.
@ ModFlagBehaviorFirstVal
@ Min
Takes the min of the two values, which are required to be integers.
@ Append
Appends the two values, which are required to be metadata nodes.
@ Max
Takes the max of the two values, which are required to be integers.
@ Require
Adds a requirement that another module flag be present and have a specified value after linking is pe...
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
const ComdatSymTabType & getComdatSymbolTable() const
Get the Module's symbol table for COMDATs (constant).
global_iterator global_end()
GlobalVariable * getNamedGlobal(StringRef Name)
void setTargetTriple(Triple T)
Set the target triple.
NamedMDListType::iterator named_metadata_iterator
The named metadata iterators.
size_t alias_size() const
const_global_iterator global_end() const
bool global_empty() const
void convertToNewDbgValues()
FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, Type *RetTy, ArgsTy... Args)
Same as above, but takes a list of function arguments, which makes it easier for clients to use.
const_ifunc_iterator ifunc_end() const
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val)
iterator_range< ifunc_iterator > ifuncs()
bool named_metadata_empty() const
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
ilist< NamedMDNode > NamedMDListType
The type for the list of named metadata.
SymbolTableList< Function > FunctionListType
The type for the list of functions.
void removeDebugIntrinsicDeclarations()
Used when printing this module in the new debug info format; removes all declarations of debug intrin...
ValueSymbolTable & getValueSymbolTable()
Get the Module's symbol table of global variable and function identifiers.
NamedMDListType::const_iterator const_named_metadata_iterator
The named metadata constant iterators.
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.
void prependModuleInlineAsm(GlobalAsmFragment Fragment)
Prepend to the module-scope inline assembly blocks.
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()
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Like addModuleFlag but replaces the old module flag if it already exists.
ifunc_iterator ifunc_end()
GlobalListType::const_iterator const_global_iterator
The Global Variable constant iterator.
void appendModuleInlineAsm(GlobalAsmFragment Fragment)
Append to the module-scope inline assembly blocks.
iterator_range< alias_iterator > aliases()
void removeModuleInlineAsm()
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()
bool convertFromNewDbgValues()
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.
StringMap< NamedMDNode * > NamedMDSymTabType
The type for mapping names to named metadata.
auto getFunctionDefs()
Get an iterator range over all function definitions (excluding declarations).
GlobalListType::iterator global_iterator
The Global Variable iterator.
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, int Val)
FunctionListType::const_reverse_iterator const_reverse_iterator
The Function constant reverse iterator.
FunctionCallee getOrInsertFunction(StringRef Name, AttributeList AttributeList, FunctionType *Invalid, ArgsTy... Args)=delete
void insertGUID(const Value *V, GlobalValue::GUID GUID)
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
concat_iterator< GlobalObject, iterator, global_iterator > global_object_iterator
IFuncListType::const_iterator const_ifunc_iterator
The Global IFunc constant iterator.
size_t ifunc_size() const
SymbolTableList< GlobalVariable > GlobalListType
The type for the list of global variables.
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.
std::optional< GlobalValue::GUID > getGUID(const Value *V) const
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.
bool hasModuleInlineAsm() const
Return whether there is any module-scope inline assembly.
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
iterator_range< global_object_iterator > global_objects()
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.
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
ComdatSymTabType & getComdatSymbolTable()
Get the Module's symbol table for COMDATs.
FunctionListType::reverse_iterator reverse_iterator
The Function reverse iterator.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
iterator_range< const_iterator > functions() const
concat_iterator< GlobalValue, iterator, global_iterator, alias_iterator, ifunc_iterator > global_value_iterator
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
iterator_range< const_global_iterator > globals() const
void setModuleIdentifier(StringRef ID)
Set the module identifier.
iterator_range< const_ifunc_iterator > ifuncs() const
SymbolTableList< GlobalAlias > AliasListType
The type for the list of aliases.
const_iterator end() const
void setSourceFileName(StringRef Name)
Set the module's original source file name.
void setModuleInlineAsm(GlobalAsmFragment Fragment)
Set the module-scope inline assembly blocks.
void setModuleInlineAsm(ArrayRef< GlobalAsmFragment > Fragments)
SymbolTableList< GlobalIFunc > IFuncListType
The type for the list of ifuncs.
auto getFunctionDefs() const
ArrayRef< GlobalAsmFragment > getModuleInlineAsm() const
Get any module-scope inline assembly blocks.
MutableArrayRef< GlobalAsmFragment > getModuleInlineAsm()
Get any module-scope inline assembly blocks.
const_ifunc_iterator ifunc_begin() const
concat_iterator< const GlobalObject, const_iterator, const_global_iterator > const_global_object_iterator
const std::string & getDataLayoutStr() const
Get the data layout string for the module's target platform.
static FunctionListType Module::* getSublistAccess(Function *)
FunctionListType::const_iterator const_iterator
The Function constant iterator.
concat_iterator< const GlobalValue, const_iterator, const_global_iterator, const_alias_iterator, const_ifunc_iterator > const_global_value_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
iterator_range< global_value_iterator > global_values()
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
Represent a mutable reference to an array (0 or more elements consecutively in memory),...
A random number generator.
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.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Represent a constant reference to a string, i.e.
Class to represent struct types.
List that automatically updates parent links and symbol tables.
Triple - Helper class for working with autoconf configuration names.
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.
typename base_list_type::const_reverse_iterator const_reverse_iterator
typename base_list_type::reverse_iterator reverse_iterator
typename base_list_type::iterator iterator
typename base_list_type::const_iterator const_iterator
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)
LongDoubleFormat
The floating-point format used for the target's "long double" type.
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
iplist< T, Options... > ilist
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
Attribute unwrap(LLVMAttributeRef Attr)
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
LLVM_ABI 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 ...
Implement std::hash so that hash_code can be used in STL containers.
This struct is a compact representation of a valid (non-zero power of two) alignment.
GlobalAsmFragment(StringRef Asm)
GlobalAsmProperties Props
GlobalAsmFragment(std::string AsmArg, GlobalAsmProperties Props={})
bool hasSameProperties(const GlobalAsmFragment &Other) const
LLVM_ABI bool set(StringRef Name, std::string Value)
Set a property using a string name.
bool operator==(const GlobalAsmProperties &Other) const
LLVM_ABI SmallVector< std::pair< StringRef, StringRef > > getAsStrings() const
Get a list of set properties as pairs of key and value.
std::string TargetFeatures
bool operator!=(const GlobalAsmProperties &Other) const
ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)