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();
274 for (
auto &
F : *
this) {
275 F.convertFromNewDbgValues();
299 unsigned getInstructionCount()
const;
316 return DL.getStringRepresentation();
331 return GlobalScopeAsm;
336 return GlobalScopeAsm;
351 std::unique_ptr<RandomNumberGenerator> createRNG(
const StringRef Name)
const;
356 return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
382 GlobalScopeAsm.clear();
387 GlobalScopeAsm.clear();
394 if (Fragment.empty())
397 if (!GlobalScopeAsm.empty() &&
398 GlobalScopeAsm.back().hasSameProperties(Fragment)) {
399 GlobalScopeAsm.back().Asm += Fragment.Asm;
401 GlobalScopeAsm.emplace_back(std::move(Fragment));
407 if (Fragment.empty())
410 if (!GlobalScopeAsm.empty() &&
411 GlobalScopeAsm.front().hasSameProperties(Fragment)) {
412 GlobalScopeAsm.front().Asm.insert(0, Fragment.Asm);
414 GlobalScopeAsm.insert(GlobalScopeAsm.begin(), std::move(Fragment));
428 unsigned getNumNamedValues()
const;
432 unsigned getMDKindID(
StringRef Name)
const;
443 std::vector<StructType *> getIdentifiedStructTypes()
const;
465 AttributeList AttributeList);
471 template <
typename... ArgsTy>
473 AttributeList AttributeList,
Type *RetTy,
482 template <
typename... ArgsTy>
489 template <
typename... ArgsTy>
513 bool AllowInternal =
false) {
526 static_cast<const Module *
>(
this)->getNamedGlobal(Name));
650 GlobalList.insert(Where, GV);
656 const auto It = ValueToGUIDMap.find(V);
657 if (It == ValueToGUIDMap.end())
660 return It->getSecond();
664 const auto [It, WasInserted] = ValueToGUIDMap.insert({V, GUID});
666 (void)It, (
void)WasInserted;
669 assert((It->second == GUID) &&
"insertGUID called with different value");
685 const GlobalListType &getGlobalList()
const {
return GlobalList; }
687 GlobalListType &getGlobalList() {
return GlobalList; }
690 return &Module::GlobalList;
700 return &Module::FunctionList;
727 NamedMDList.push_back(
MDNode);
734 const AliasListType &getAliasList()
const {
return AliasList; }
736 AliasListType &getAliasList() {
return AliasList; }
739 return &Module::AliasList;
744 const IFuncListType &getIFuncList()
const {
return IFuncList; }
746 IFuncListType &getIFuncList() {
return IFuncList; }
749 return &Module::IFuncList;
754 const NamedMDListType &getNamedMDList()
const {
return NamedMDList; }
756 NamedMDListType &getNamedMDList() {
return NamedMDList; }
758 static NamedMDListType
Module::*getSublistAccess(NamedMDNode*) {
759 return &Module::NamedMDList;
803 size_t size()
const {
return FunctionList.size(); }
804 bool empty()
const {
return FunctionList.empty(); }
817 [](
Function &
F) {
return !
F.isDeclaration(); });
889 return NamedMDList.begin();
894 return NamedMDList.end();
922 : CUs(CUs), Idx(Idx) {
979 bool ShouldPreserveUseListOrder =
false,
980 bool IsForDebug =
false)
const;
991 void dropAllReferences();
999 unsigned getNumberRegisterParameters()
const;
1002 unsigned getDwarfVersion()
const;
1005 bool isDwarf64()
const;
1009 unsigned getCodeViewFlag()
const;
1049 std::optional<uint64_t> getLargeDataThreshold()
const;
1052 void setLargeDataThreshold(
uint64_t Threshold);
1063 Metadata *getProfileSummary(
bool IsCS)
const;
1067 bool getSemanticInterposition()
const;
1070 void setSemanticInterposition(
bool);
1073 bool getRtLibUseGOT()
const;
1076 void setRtLibUseGOT();
1080 bool getDirectAccessExternalData()
const;
1081 void setDirectAccessExternalData(
bool Value);
1093 StringRef getStackProtectorGuard()
const;
1094 void setStackProtectorGuard(
StringRef Kind);
1099 StringRef getStackProtectorGuardReg()
const;
1103 StringRef getStackProtectorGuardSymbol()
const;
1104 void setStackProtectorGuardSymbol(
StringRef Symbol);
1107 int getStackProtectorGuardOffset()
const;
1108 void setStackProtectorGuardOffset(
int Offset);
1111 std::optional<unsigned> getStackProtectorGuardValueWidth()
const;
1112 void setStackProtectorGuardValueWidth(
unsigned Width);
1115 bool hasStackProtectorGuardRecord()
const;
1116 void setStackProtectorGuardRecord(
bool Flag);
1119 unsigned getOverrideStackAlignment()
const;
1120 void setOverrideStackAlignment(
unsigned Align);
1122 unsigned getMaxTLSAlignment()
const;
1137 void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB);
1147 StringRef getDarwinTargetVariantTriple()
const;
1151 void setDarwinTargetVariantTriple(
StringRef T);
1180 M.print(O,
nullptr);
1191 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< 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, WebAssemblyTargetMachine &TM, 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 convertFromNewDbgValues()
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()
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()
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.
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.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
@ C
The default llvm calling convention, compatible with C.
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.
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)