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;
273 unsigned getInstructionCount()
const;
290 return DL.getStringRepresentation();
317 std::unique_ptr<RandomNumberGenerator> createRNG(
const StringRef Name)
const;
322 return getContext().getDiagHandlerPtr()->isAnalysisRemarkEnabled(
346 GlobalScopeAsm = std::string(Asm);
347 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
348 GlobalScopeAsm +=
'\n';
354 GlobalScopeAsm += Asm;
355 if (!GlobalScopeAsm.empty() && GlobalScopeAsm.back() !=
'\n')
356 GlobalScopeAsm +=
'\n';
369 unsigned getNumNamedValues()
const;
384 std::vector<StructType *> getIdentifiedStructTypes()
const;
412 template <
typename... ArgsTy>
417 return getOrInsertFunction(
Name,
418 FunctionType::get(
RetTy, ArgTys,
false),
423 template <
typename... ArgsTy>
430 template <
typename... ArgsTy>
454 bool AllowInternal =
false) {
467 static_cast<const Module *
>(
this)->getNamedGlobal(
Name));
587 insertGlobalVariable(GlobalList.end(), GV);
592 GlobalList.insert(Where, GV);
603 const GlobalListType &getGlobalList()
const {
return GlobalList; }
605 GlobalListType &getGlobalList() {
return GlobalList; }
608 return &Module::GlobalList;
618 return &Module::FunctionList;
645 NamedMDList.push_back(
MDNode);
652 const AliasListType &getAliasList()
const {
return AliasList; }
654 AliasListType &getAliasList() {
return AliasList; }
657 return &Module::AliasList;
662 const IFuncListType &getIFuncList()
const {
return IFuncList; }
664 IFuncListType &getIFuncList() {
return IFuncList; }
667 return &Module::IFuncList;
672 const NamedMDListType &getNamedMDList()
const {
return NamedMDList; }
674 NamedMDListType &getNamedMDList() {
return NamedMDList; }
676 static NamedMDListType
Module::*getSublistAccess(NamedMDNode*) {
677 return &Module::NamedMDList;
703 return make_range(global_begin(), global_end());
706 return make_range(global_begin(), global_end());
721 size_t size()
const {
return FunctionList.size(); }
722 bool empty()
const {
return FunctionList.empty(); }
743 return make_range(alias_begin(), alias_end());
746 return make_range(alias_begin(), alias_end());
761 return make_range(ifunc_begin(), ifunc_end());
764 return make_range(ifunc_begin(), ifunc_end());
796 return NamedMDList.begin();
801 return NamedMDList.end();
808 return make_range(named_metadata_begin(), named_metadata_end());
811 return make_range(named_metadata_begin(), named_metadata_end());
819 void SkipNoDebugCUs();
858 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
863 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
871 auto *CUs = getNamedMetadata(
"llvm.dbg.cu");
885 void dropTriviallyDeadConstantArrays();
895 bool ShouldPreserveUseListOrder =
false,
896 bool IsForDebug =
false)
const;
907 void dropAllReferences();
915 unsigned getNumberRegisterParameters()
const;
918 unsigned getDwarfVersion()
const;
921 bool isDwarf64()
const;
925 unsigned getCodeViewFlag()
const;
965 std::optional<uint64_t> getLargeDataThreshold()
const;
968 void setLargeDataThreshold(
uint64_t Threshold);
979 Metadata *getProfileSummary(
bool IsCS)
const;
983 bool getSemanticInterposition()
const;
986 void setSemanticInterposition(
bool);
989 bool getRtLibUseGOT()
const;
992 void setRtLibUseGOT();
996 bool getDirectAccessExternalData()
const;
997 void setDirectAccessExternalData(
bool Value);
1009 StringRef getStackProtectorGuard()
const;
1010 void setStackProtectorGuard(
StringRef Kind);
1015 StringRef getStackProtectorGuardReg()
const;
1019 StringRef getStackProtectorGuardSymbol()
const;
1020 void setStackProtectorGuardSymbol(
StringRef Symbol);
1023 int getStackProtectorGuardOffset()
const;
1024 void setStackProtectorGuardOffset(
int Offset);
1027 unsigned getOverrideStackAlignment()
const;
1028 void setOverrideStackAlignment(
unsigned Align);
1030 unsigned getMaxTLSAlignment()
const;
1045 void setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB);
1055 StringRef getDarwinTargetVariantTriple()
const;
1059 void setDarwinTargetVariantTriple(
StringRef T);
1067 void setDarwinTargetVariantSDKVersion(
VersionTuple Version);
1074 SmallVectorImpl<GlobalValue *> &Vec,
1079 M.print(O,
nullptr);
1090 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)
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)