75 IsNewDbgInfoFormat(
false) {
76 Context.addModule(
this);
80 Context.removeModule(
this);
88std::unique_ptr<RandomNumberGenerator>
104 return std::unique_ptr<RandomNumberGenerator>(
153 if (!New->isIntrinsic())
186 bool AllowLocal)
const {
189 if (AllowLocal || !Result->hasLocalLinkage())
206 GV = CreateGlobalCallback();
207 assert(GV &&
"The CreateGlobalCallback is expected to create a global");
242 return NamedMDSymTab.
lookup(NameRef);
252 NMD->setParent(
this);
266 if (
ConstantInt *Behavior = mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
267 uint64_t Val = Behavior->getLimitedValue();
294 if (!ModFlags)
return;
314 if (Key == MFE.Key->getString())
355 assert(Node->getNumOperands() == 3 &&
356 "Invalid number of operands for module flag!");
357 assert(mdconst::hasa<ConstantInt>(Node->getOperand(0)) &&
358 isa<MDString>(Node->getOperand(1)) &&
359 "Invalid operand types for module flag!");
373 Flag->replaceOperandWith(2, Val);
387 return cast<DICompileUnit>(CUs->
getOperand(Idx));
390 return cast<DICompileUnit>(CUs->getOperand(
Idx));
393void Module::debug_compile_units_iterator::SkipNoDebugCUs() {
394 while (CUs && (Idx < CUs->getNumOperands()) &&
420 "Module already has a GVMaterializer. Call materializeAll"
421 " to clear it out before setting another one.");
422 Materializer.reset(GVM);
429 return Materializer->materialize(GV);
435 std::unique_ptr<GVMaterializer> M = std::move(Materializer);
436 return M->materializeModule();
442 return Materializer->materializeMetadata();
454 return Materializer->getIdentifiedStructTypes();
456 std::vector<StructType *> Ret;
458 SrcStructTypes.
run(*
this,
true);
459 Ret.assign(SrcStructTypes.
begin(), SrcStructTypes.
end());
465 auto Encode = [&BaseName](
unsigned Suffix) {
466 return (
Twine(BaseName) +
"." +
Twine(Suffix)).str();
471 auto UinItInserted = UniquedIntrinsicNames.insert({{Id, Proto}, 0});
472 if (!UinItInserted.second)
473 return Encode(UinItInserted.first->second);
480 auto NiidItInserted = CurrentIntrinsicIds.
insert({BaseName, 0});
481 unsigned Count = NiidItInserted.first->second;
487 NewName = Encode(Count);
491 UniquedIntrinsicNames[{Id, Proto}] = Count;
496 FunctionType *FT = dyn_cast<FunctionType>(
F->getValueType());
497 auto UinItInserted = UniquedIntrinsicNames.insert({{Id, FT}, Count});
501 UinItInserted.first->second = Count;
508 NiidItInserted.first->second = Count + 1;
522 F.dropAllReferences();
525 GV.dropAllReferences();
528 GA.dropAllReferences();
531 GIF.dropAllReferences();
536 cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"NumRegisterParameters"));
539 return cast<ConstantInt>(Val->getValue())->getZExtValue();
543 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"Dwarf Version"));
546 return cast<ConstantInt>(Val->getValue())->getZExtValue();
550 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"DWARF64"));
551 return Val && cast<ConstantInt>(Val->getValue())->isOne();
555 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"CodeView"));
558 return cast<ConstantInt>(Val->getValue())->getZExtValue();
562 unsigned NumInstrs = 0;
564 NumInstrs +=
F.getInstructionCount();
570 Entry.second.Name = &Entry;
571 return &Entry.second;
575 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"PIC Level"));
581 cast<ConstantInt>(Val->getValue())->getZExtValue());
591 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"PIE Level"));
597 cast<ConstantInt>(Val->getValue())->getZExtValue());
605 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"Code Model"));
611 cast<ConstantInt>(Val->getValue())->getZExtValue());
624 cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"Large Data Threshold"));
629 return cast<ConstantInt>(Val->getValue())->getZExtValue();
654 auto *Val = cast_or_null<ConstantAsMetadata>(MF);
658 return cast<ConstantInt>(Val->getValue())->getZExtValue();
666 OwnedMemoryBuffer = std::move(MB);
670 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"RtLibUseGOT"));
671 return Val && (cast<ConstantInt>(Val->getValue())->getZExtValue() > 0);
679 auto *Val = cast_or_null<ConstantAsMetadata>(
682 return cast<ConstantInt>(Val->getValue())->getZExtValue() > 0;
691 if (
auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"uwtable")))
692 return UWTableKind(cast<ConstantInt>(Val->getValue())->getZExtValue());
701 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"frame-pointer"));
703 Val ? cast<ConstantInt>(Val->getValue())->getZExtValue() : 0);
712 if (
auto *MDS = dyn_cast_or_null<MDString>(MD))
713 return MDS->getString();
724 if (
auto *MDS = dyn_cast_or_null<MDString>(MD))
725 return MDS->getString();
736 if (
auto *MDS = dyn_cast_or_null<MDString>(MD))
737 return MDS->getString();
748 if (
auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD))
749 return CI->getSExtValue();
759 if (
auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD))
760 return CI->getZExtValue();
766 if (
auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD))
767 return CI->getZExtValue();
777 Entries.push_back(V.getMajor());
778 if (
auto Minor = V.getMinor()) {
779 Entries.push_back(*Minor);
780 if (
auto Subminor = V.getSubminor())
781 Entries.push_back(*Subminor);
794 auto *CM = dyn_cast_or_null<ConstantAsMetadata>(MD);
797 auto *Arr = dyn_cast_or_null<ConstantDataArray>(CM->getValue());
800 auto getVersionComponent = [&](
unsigned Index) -> std::optional<unsigned> {
801 if (
Index >= Arr->getNumElements())
803 return (
unsigned)Arr->getElementAsInteger(
Index);
805 auto Major = getVersionComponent(0);
809 if (
auto Minor = getVersionComponent(1)) {
811 if (
auto Subminor = getVersionComponent(2)) {
824 const char *
Name = CompilerUsed ?
"llvm.compiler.used" :
"llvm.used";
849 double Ratio = (double)BlockCount / NumCounts;
858 if (
const auto *MD =
getModuleFlag(
"darwin.target_variant.triple"))
859 return cast<MDString>(MD)->getString();
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the StringMap class.
This file contains the simple types necessary to represent the attributes associated with functions a...
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
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
This file contains the declaration of the GlobalIFunc class, which represents a single indirect funct...
static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)
A Lookup helper functions.
ModuleSummaryIndex.h This file contains the declarations the classes that hold the module index and s...
static VersionTuple getSDKVersionMD(Metadata *MD)
static void addSDKVersionMD(const VersionTuple &V, Module &M, StringRef Name)
Module.h This file contains the declarations for the Module class.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallString class.
This file defines the SmallVector class.
Defines the llvm::VersionTuple class, which represents a version in the form major[....
ConstantArray - Constant Array Declarations.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
This is the shared class of boolean and integer constants.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
This is an important base class in LLVM.
This class represents an Operation in the Expression.
A parsed version of the target data layout string in and methods for querying it.
unsigned getProgramAddressSpace() const
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
Class to represent function types.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
@ ExternalLinkage
Externally visible function.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
bool hasInitializer() const
Definitions have initializers, declarations don't.
This is an important class for using LLVM in a threaded context.
unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
getOperandBundleTags - Populate client supplied SmallVector with the bundle tags registered in this L...
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
getMDKindNames - Populate client supplied SmallVector with the name for custom metadata IDs registere...
const MDOperand & getOperand(unsigned I) const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
static MDString * get(LLVMContext &Context, StringRef Str)
Class to hold module path string table and global value map, and encapsulate methods for operating on...
DICompileUnit * operator*() const
DICompileUnit * operator->() const
A Module instance is used to store all the information related to an LLVM module.
static bool isValidModuleFlag(const MDNode &ModFlag, ModFlagBehavior &MFB, MDString *&Key, Metadata *&Val)
Check if the given module flag metadata represents a valid module flag, and store the flag behavior,...
void setStackProtectorGuardSymbol(StringRef Symbol)
void setSemanticInterposition(bool)
Set whether semantic interposition is to be respected.
void eraseNamedMDNode(NamedMDNode *MDNode)
Remove MDNode from the list and delete it.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
@ 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.
@ Max
Takes the max of the two values, which are required to be integers.
llvm::Error materializeAll()
Make sure all GlobalValues in this Module are fully read and clear the Materializer.
LLVMContext & getContext() const
Get the global data context.
void setOverrideStackAlignment(unsigned Align)
void setDirectAccessExternalData(bool Value)
unsigned getMaxTLSAlignment() const
void setOwnedMemoryBuffer(std::unique_ptr< MemoryBuffer > MB)
Take ownership of the given memory buffer.
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
void setCodeModel(CodeModel::Model CL)
Set the code model (tiny, small, kernel, medium or large)
StringRef getStackProtectorGuardSymbol() const
Get/set a symbol to use as the stack protector guard.
iterator_range< ifunc_iterator > ifuncs()
bool getSemanticInterposition() const
Returns whether semantic interposition is to be respected.
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
void setRtLibUseGOT()
Set that PLT should be avoid for RTLib calls.
llvm::Error materializeMetadata()
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
iterator_range< iterator > functions()
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
unsigned getNumNamedValues() const
Return the number of global values in the module.
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
void setFramePointer(FramePointerKind Kind)
std::optional< uint64_t > getLargeDataThreshold() const
Returns the code model (tiny, small, kernel, medium or large model)
StringRef getStackProtectorGuard() const
Get/set what kind of stack protector guard to use.
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Like addModuleFlag but replaces the old module flag if it already exists.
UWTableKind getUwtable() const
Get/set whether synthesized functions should get the uwtable attribute.
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining.
void setStackProtectorGuard(StringRef Kind)
iterator_range< alias_iterator > aliases()
void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind)
Attach profile summary metadata to this module.
void setUwtable(UWTableKind Kind)
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
void setPartialSampleProfileRatio(const ModuleSummaryIndex &Index)
Set the partial sample profile ratio in the profile summary module flag, if applicable.
std::string getUniqueIntrinsicName(StringRef BaseName, Intrinsic::ID Id, const FunctionType *Proto)
Return a unique name for an intrinsic whose mangling is based on an unnamed type.
~Module()
The module destructor. This will dropAllReferences.
FramePointerKind getFramePointer() const
Get/set whether synthesized functions should get the "frame-pointer" attribute.
unsigned getOverrideStackAlignment() const
Get/set the stack alignment overridden from the default.
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
void setStackProtectorGuardReg(StringRef Reg)
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
std::unique_ptr< RandomNumberGenerator > createRNG(const StringRef Name) const
Get a RandomNumberGenerator salted for use with this module.
iterator_range< global_iterator > globals()
std::vector< StructType * > getIdentifiedStructTypes() const
void setDarwinTargetVariantTriple(StringRef T)
Set the target variant triple which is a string describing a variant of the target host platform.
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
unsigned getNumberRegisterParameters() const
Returns the Number of Register ParametersDwarf Version by checking module flags.
void insertNamedMDNode(NamedMDNode *MDNode)
Insert MDNode at the end of the alias list and take ownership.
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type.
StringRef getStackProtectorGuardReg() const
Get/set which register to use as the stack protector guard register.
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
void setDataLayout(StringRef Desc)
Set the data layout.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
void setLargeDataThreshold(uint64_t Threshold)
Set the code model (tiny, small, kernel, medium or large)
bool isDwarf64() const
Returns the DWARF format by checking module flags.
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB.
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
void setStackProtectorGuardOffset(int Offset)
iterator_range< global_object_iterator > global_objects()
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
unsigned getInstructionCount() const
Returns the number of non-debug IR instructions in the module.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
Constant * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
std::optional< CodeModel::Model > getCodeModel() const
Returns the code model (tiny, small, kernel, medium or large model)
VersionTuple getDarwinTargetVariantSDKVersion() const
Get the target variant version build SDK version metadata.
void setPIELevel(PIELevel::Level PL)
Set the PIE level (small or large model)
VersionTuple getSDKVersion() const
Get the build SDK version metadata.
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type.
void setDarwinTargetVariantSDKVersion(VersionTuple Version)
Set the target variant version build SDK version metadata.
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
StringRef getDarwinTargetVariantTriple() const
Get the target variant triple which is a string describing a variant of the target host platform.
void setSDKVersion(const VersionTuple &V)
Attach a build SDK version metadata to this module.
iterator_range< global_value_iterator > global_values()
int getStackProtectorGuardOffset() const
Get/set what offset from the stack protector to use.
bool getDirectAccessExternalData() const
Get/set whether referencing global variables can use direct access relocations on ELF targets.
Metadata * getProfileSummary(bool IsCS) const
Returns profile summary metadata.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
StringRef getName() const
MDNode * getOperand(unsigned i) const
unsigned getNumOperands() const
iterator_range< op_iterator > operands()
void addOperand(MDNode *M)
void setPartialProfileRatio(double R)
Metadata * getMD(LLVMContext &Context, bool AddPartialField=true, bool AddPartialProfileRatioField=true)
Return summary information as metadata.
uint32_t getNumCounts() const
bool isPartialProfile() const
static ProfileSummary * getFromMD(Metadata *MD)
Construct profile summary from metdata.
A random number generator.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
void run(const Module &M, bool onlyNamed)
The instances of the Type class are immutable: once they are created, they are never changed.
static IntegerType * getInt32Ty(LLVMContext &C)
static IntegerType * getInt64Ty(LLVMContext &C)
This class provides a symbol table of name/value pairs.
unsigned size() const
The number of name/type pairs is returned.
LLVM Value Representation.
Represents a version number in the form major[.minor[.subminor[.build]]].
An efficient, type-erasing, non-owning reference to a callable.
void push_back(pointer val)
A range adaptor for a pair of iterators.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM.
@ C
The default llvm calling convention, compatible with C.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
This is an optimization pass for GlobalISel generic memory operations.
@ None
No unwind table requested.
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.
Description of the encoding of one expression Op.