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);
167 : Behavior(
B), Key(K), Val(V) {}
176 GlobalListType GlobalList;
177 FunctionListType FunctionList;
178 AliasListType AliasList;
179 IFuncListType IFuncList;
180 NamedMDListType NamedMDList;
181 std::string GlobalScopeAsm;
182 std::unique_ptr<ValueSymbolTable> ValSymTab;
183 ComdatSymTabType ComdatSymTab;
184 std::unique_ptr<MemoryBuffer>
187 std::unique_ptr<GVMaterializer>
189 std::string ModuleID;
190 std::string SourceFileName;
192 std::string TargetTriple;
194 NamedMDSymTabType NamedMDSymTab;
200 UniquedIntrinsicNames;
222 void removeDebugIntrinsicDeclarations();
226 for (
auto &
F : *
this) {
227 F.convertToNewDbgValues();
229 IsNewDbgInfoFormat =
true;
234 for (
auto &
F : *
this) {
235 F.convertFromNewDbgValues();
237 IsNewDbgInfoFormat =
false;
241 if (UseNewFormat && !IsNewDbgInfoFormat)
242 convertToNewDbgValues();
243 else if (!UseNewFormat && IsNewDbgInfoFormat)
244 convertFromNewDbgValues();
247 for (
auto &
F : *
this) {
248 F.setNewDbgInfoFormatFlag(NewFlag);
250 IsNewDbgInfoFormat = NewFlag;
270 unsigned getInstructionCount()
const;
287 return DL.getStringRepresentation();
314 std::unique_ptr<RandomNumberGenerator> createRNG(
const StringRef Name)
const;
319 return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
343 GlobalScopeAsm = std::string(Asm);
344 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
345 GlobalScopeAsm +=
'\n';
351 GlobalScopeAsm += Asm;
352 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
353 GlobalScopeAsm +=
'\n';
366 unsigned getNumNamedValues()
const;
381 std::vector<StructType *> getIdentifiedStructTypes()
const;
409 template <
typename... ArgsTy>
414 return getOrInsertFunction(
Name,
415 FunctionType::get(
RetTy, ArgTys,
false),
420 template <
typename... ArgsTy>
427 template <
typename... ArgsTy>
451 bool AllowInternal =
false) {
464 static_cast<const Module *
>(
this)->getNamedGlobal(
Name));
584 insertGlobalVariable(GlobalList.end(), GV);
589 GlobalList.insert(Where, GV);
600 const GlobalListType &getGlobalList()
const {
return GlobalList; }
602 GlobalListType &getGlobalList() {
return GlobalList; }
605 return &Module::GlobalList;
615 return &Module::FunctionList;
642 NamedMDList.push_back(
MDNode);
649 const AliasListType &getAliasList()
const {
return AliasList; }
651 AliasListType &getAliasList() {
return AliasList; }
654 return &Module::AliasList;
659 const IFuncListType &getIFuncList()
const {
return IFuncList; }
661 IFuncListType &getIFuncList() {
return IFuncList; }
664 return &Module::IFuncList;
669 const NamedMDListType &getNamedMDList()
const {
return NamedMDList; }
671 NamedMDListType &getNamedMDList() {
return NamedMDList; }
673 static NamedMDListType
Module::*getSublistAccess(NamedMDNode*) {
674 return &Module::NamedMDList;
700 return make_range(global_begin(), global_end());
703 return make_range(global_begin(), global_end());
718 size_t size()
const {
return FunctionList.size(); }
719 bool empty()
const {
return FunctionList.empty(); }
740 return make_range(alias_begin(), alias_end());
743 return make_range(alias_begin(), alias_end());
758 return make_range(ifunc_begin(), ifunc_end());
761 return make_range(ifunc_begin(), ifunc_end());
793 return NamedMDList.begin();
798 return NamedMDList.end();
805 return make_range(named_metadata_begin(), named_metadata_end());
808 return make_range(named_metadata_begin(), named_metadata_end());
816 void SkipNoDebugCUs();
855 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
860 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
868 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
882 void dropTriviallyDeadConstantArrays();
892 bool ShouldPreserveUseListOrder =
false,
893 bool IsForDebug =
false)
const;
904 void dropAllReferences();
912 unsigned getNumberRegisterParameters()
const;
915 unsigned getDwarfVersion()
const;
918 bool isDwarf64()
const;
922 unsigned getCodeViewFlag()
const;
962 std::optional<uint64_t> getLargeDataThreshold()
const;
965 void setLargeDataThreshold(
uint64_t Threshold);
976 Metadata *getProfileSummary(
bool IsCS)
const;
980 bool getSemanticInterposition()
const;
983 void setSemanticInterposition(
bool);
986 bool getRtLibUseGOT()
const;
989 void setRtLibUseGOT();
993 bool getDirectAccessExternalData()
const;
994 void setDirectAccessExternalData(
bool Value);
1006 StringRef getStackProtectorGuard()
const;
1007 void setStackProtectorGuard(
StringRef Kind);
1012 StringRef getStackProtectorGuardReg()
const;
1016 StringRef getStackProtectorGuardSymbol()
const;
1017 void setStackProtectorGuardSymbol(
StringRef Symbol);
1020 int getStackProtectorGuardOffset()
const;
1021 void setStackProtectorGuardOffset(
int Offset);
1024 unsigned getOverrideStackAlignment()
const;
1025 void setOverrideStackAlignment(
unsigned Align);
1027 unsigned getMaxTLSAlignment()
const;
1042 void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB);
1052 StringRef getDarwinTargetVariantTriple()
const;
1056 void setDarwinTargetVariantTriple(
StringRef T);
1064 void setDarwinTargetVariantSDKVersion(
VersionTuple Version);
1071 SmallVectorImpl<GlobalValue *> &Vec,
1076 M.print(O,
nullptr);
1087 return reinterpret_cast<Module*
>(MP);
This file defines the StringMap class.
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")
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 CodeModel::Model getCodeModel(const PPCSubtarget &S, const TargetMachine &TM, const MachineOperand &MO)
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).
bool IsNewDbgInfoFormat
Is this Module using intrinsics to record the position of debugging information, or non-intrinsic rec...
global_iterator global_end()
GlobalVariable * getNamedGlobal(StringRef Name)
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
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.
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.
void setNewDbgInfoFormatFlag(bool NewFlag)
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.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
iterator_range< const_iterator > functions() const
void setIsNewDbgInfoFormat(bool UseNewFormat)
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
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.
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.
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.
Description of the encoding of one expression Op.
ModuleFlagEntry(ModFlagBehavior B, MDString *K, Metadata *V)