75 Context.addModule(
this);
79 Context.removeModule(
this);
87std::unique_ptr<RandomNumberGenerator>
103 return std::unique_ptr<RandomNumberGenerator>(
152 if (!New->isIntrinsic())
161 if (
F->getType() != PTy)
191 bool AllowLocal)
const {
194 if (AllowLocal || !Result->hasLocalLinkage())
211 GV = CreateGlobalCallback();
212 assert(GV &&
"The CreateGlobalCallback is expected to create a global");
254 return NamedMDSymTab.
lookup(NameRef);
264 NMD->setParent(
this);
278 if (
ConstantInt *Behavior = mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
279 uint64_t Val = Behavior->getLimitedValue();
306 if (!ModFlags)
return;
326 if (Key == MFE.Key->getString())
367 assert(Node->getNumOperands() == 3 &&
368 "Invalid number of operands for module flag!");
369 assert(mdconst::hasa<ConstantInt>(Node->getOperand(0)) &&
370 isa<MDString>(Node->getOperand(1)) &&
371 "Invalid operand types for module flag!");
385 Flag->replaceOperandWith(2, Val);
401 return cast<DICompileUnit>(CUs->
getOperand(Idx));
404 return cast<DICompileUnit>(CUs->getOperand(
Idx));
407void Module::debug_compile_units_iterator::SkipNoDebugCUs() {
408 while (CUs && (Idx < CUs->getNumOperands()) &&
434 "Module already has a GVMaterializer. Call materializeAll"
435 " to clear it out before setting another one.");
436 Materializer.reset(GVM);
443 return Materializer->materialize(GV);
449 std::unique_ptr<GVMaterializer> M = std::move(Materializer);
450 return M->materializeModule();
456 return Materializer->materializeMetadata();
468 return Materializer->getIdentifiedStructTypes();
470 std::vector<StructType *> Ret;
472 SrcStructTypes.
run(*
this,
true);
473 Ret.assign(SrcStructTypes.
begin(), SrcStructTypes.
end());
479 auto Encode = [&BaseName](
unsigned Suffix) {
480 return (
Twine(BaseName) +
"." +
Twine(Suffix)).str();
485 auto UinItInserted = UniquedIntrinsicNames.insert({{Id, Proto}, 0});
486 if (!UinItInserted.second)
487 return Encode(UinItInserted.first->second);
494 auto NiidItInserted = CurrentIntrinsicIds.
insert({BaseName, 0});
495 unsigned Count = NiidItInserted.first->second;
501 NewName = Encode(Count);
505 UniquedIntrinsicNames[{Id, Proto}] = Count;
510 FunctionType *FT = dyn_cast<FunctionType>(
F->getValueType());
511 auto UinItInserted = UniquedIntrinsicNames.insert({{Id, FT}, Count});
515 UinItInserted.first->second = Count;
522 NiidItInserted.first->second = Count + 1;
536 F.dropAllReferences();
539 GV.dropAllReferences();
542 GA.dropAllReferences();
545 GIF.dropAllReferences();
550 cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"NumRegisterParameters"));
553 return cast<ConstantInt>(Val->getValue())->getZExtValue();
557 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"Dwarf Version"));
560 return cast<ConstantInt>(Val->getValue())->getZExtValue();
564 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"DWARF64"));
565 return Val && cast<ConstantInt>(Val->getValue())->isOne();
569 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"CodeView"));
572 return cast<ConstantInt>(Val->getValue())->getZExtValue();
576 unsigned NumInstrs = 0;
578 NumInstrs +=
F.getInstructionCount();
584 Entry.second.Name = &Entry;
585 return &Entry.second;
589 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"PIC Level"));
595 cast<ConstantInt>(Val->getValue())->getZExtValue());
605 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"PIE Level"));
611 cast<ConstantInt>(Val->getValue())->getZExtValue());
619 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"Code Model"));
625 cast<ConstantInt>(Val->getValue())->getZExtValue());
651 auto *Val = cast_or_null<ConstantAsMetadata>(MF);
655 return cast<ConstantInt>(Val->getValue())->getZExtValue();
663 OwnedMemoryBuffer = std::move(MB);
667 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"RtLibUseGOT"));
668 return Val && (cast<ConstantInt>(Val->getValue())->getZExtValue() > 0);
676 auto *Val = cast_or_null<ConstantAsMetadata>(
679 return cast<ConstantInt>(Val->getValue())->getZExtValue() > 0;
688 if (
auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"uwtable")))
689 return UWTableKind(cast<ConstantInt>(Val->getValue())->getZExtValue());
698 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"frame-pointer"));
700 Val ? cast<ConstantInt>(Val->getValue())->getZExtValue() : 0);
709 if (
auto *MDS = dyn_cast_or_null<MDString>(MD))
710 return MDS->getString();
721 if (
auto *MDS = dyn_cast_or_null<MDString>(MD))
722 return MDS->getString();
733 if (
auto *MDS = dyn_cast_or_null<MDString>(MD))
734 return MDS->getString();
745 if (
auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD))
746 return CI->getSExtValue();
756 if (
auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD))
757 return CI->getZExtValue();
763 if (
auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD))
764 return CI->getZExtValue();
774 Entries.push_back(V.getMajor());
775 if (
auto Minor = V.getMinor()) {
776 Entries.push_back(*Minor);
777 if (
auto Subminor = V.getSubminor())
778 Entries.push_back(*Subminor);
791 auto *CM = dyn_cast_or_null<ConstantAsMetadata>(MD);
794 auto *Arr = dyn_cast_or_null<ConstantDataArray>(CM->getValue());
797 auto getVersionComponent = [&](
unsigned Index) -> std::optional<unsigned> {
798 if (
Index >= Arr->getNumElements())
800 return (
unsigned)Arr->getElementAsInteger(
Index);
802 auto Major = getVersionComponent(0);
806 if (
auto Minor = getVersionComponent(1)) {
808 if (
auto Subminor = getVersionComponent(2)) {
821 const char *
Name = CompilerUsed ?
"llvm.compiler.used" :
"llvm.used";
828 GlobalValue *
G = cast<GlobalValue>(Op->stripPointerCasts());
846 double Ratio = (double)BlockCount / NumCounts;
855 if (
const auto *MD =
getModuleFlag(
"darwin.target_variant.triple"))
856 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...
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
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.
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)
PointerType * getType() const
Global values are always pointers.
@ 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)
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.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
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.
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)
Class to represent pointers.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
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.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
static IntegerType * getInt32Ty(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 ...
This struct is a compact representation of a valid (non-zero power of two) alignment.