74 :
Context(C), Materializer(), ModuleID(MID), SourceFileName(MID), DL(
"") {
77 Context.addModule(
this);
81 Context.removeModule(
this);
190 bool AllowLocal)
const {
193 if (AllowLocal || !Result->hasLocalLinkage())
210 GV = CreateGlobalCallback();
211 assert(GV &&
"The CreateGlobalCallback is expected to create a global");
264 NMD->setParent(
this);
278 if (
ConstantInt *Behavior = mdconst::dyn_extract_or_null<ConstantInt>(MD)) {
279 uint64_t Val = Behavior->getLimitedValue();
292 if (!ModFlags)
return;
296 if (
Flag->getNumOperands() >= 3 &&
298 dyn_cast_or_null<MDString>(
Flag->getOperand(1))) {
314 if (Key == MFE.Key->getString())
356 "Invalid number of operands for module flag!");
359 "Invalid operand types for module flag!");
372 return cast<DICompileUnit>(CUs->getOperand(Idx));
375 return cast<DICompileUnit>(CUs->getOperand(Idx));
378 void Module::debug_compile_units_iterator::SkipNoDebugCUs() {
379 while (CUs && (Idx < CUs->getNumOperands()) &&
405 "Module already has a GVMaterializer. Call materializeAll" 406 " to clear it out before setting another one.");
407 Materializer.reset(GVM);
414 return Materializer->materialize(GV);
420 std::unique_ptr<GVMaterializer> M = std::move(Materializer);
421 return M->materializeModule();
427 return Materializer->materializeMetadata();
439 return Materializer->getIdentifiedStructTypes();
441 std::vector<StructType *>
Ret;
443 SrcStructTypes.
run(*
this,
true);
444 Ret.assign(SrcStructTypes.
begin(), SrcStructTypes.
end());
460 GV.dropAllReferences();
463 GA.dropAllReferences();
466 GIF.dropAllReferences();
471 cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"NumRegisterParameters"));
474 return cast<ConstantInt>(Val->getValue())->getZExtValue();
478 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"Dwarf Version"));
481 return cast<ConstantInt>(Val->getValue())->getZExtValue();
485 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"CodeView"));
488 return cast<ConstantInt>(Val->getValue())->getZExtValue();
492 unsigned NumInstrs = 0;
494 NumInstrs +=
F.getInstructionCount();
501 return &
Entry.second;
505 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"PIC Level"));
511 cast<ConstantInt>(Val->getValue())->getZExtValue());
519 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"PIE Level"));
525 cast<ConstantInt>(Val->getValue())->getZExtValue());
533 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"Code Model"));
539 cast<ConstantInt>(Val->getValue())->getZExtValue());
563 OwnedMemoryBuffer = std::move(MB);
567 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"RtLibUseGOT"));
568 return Val && (cast<ConstantInt>(Val->getValue())->getZExtValue() > 0);
590 auto *CM = dyn_cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"SDK Version"));
593 auto *Arr = dyn_cast_or_null<ConstantDataArray>(CM->getValue());
597 if (
Index >= Arr->getNumElements())
599 return (
unsigned)Arr->getElementAsInteger(
Index);
601 auto Major = getVersionComponent(0);
605 if (
auto Minor = getVersionComponent(1)) {
607 if (
auto Subminor = getVersionComponent(2)) {
616 const char *Name = CompilerUsed ?
"llvm.compiler.used" :
"llvm.used";
Pass interface - Implemented by all 'passes'.
bool isIntrinsic() const
isIntrinsic - Returns true if the function's name starts with "llvm.".
A parsed version of the target data layout string in and methods for querying it. ...
This class provides a symbol table of name/value pairs.
llvm::Error materializeAll()
Make sure all GlobalValues in this Module are fully read and clear the Materializer.
void reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
iterator erase(iterator where)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This class represents lattice values for constants.
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
A Module instance is used to store all the information related to an LLVM module. ...
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
static MDString * get(LLVMContext &Context, StringRef Str)
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
void push_back(const T &Elt)
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
void addOperand(MDNode *M)
DICompileUnit * operator->() const
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.
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space...
Metadata * getProfileSummary(bool IsCS)
Returns profile summary metadata.
An efficient, type-erasing, non-owning reference to a callable.
This file contains the declaration of the Comdat class, which represents a single COMDAT in LLVM...
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
Externally visible function.
void setDataLayout(StringRef Desc)
Set the data layout.
Optional< CodeModel::Model > getCodeModel() const
Returns the code model (tiny, small, kernel, medium or large model)
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
const MDOperand & getOperand(unsigned I) const
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type. ...
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
getMDKindNames - Populate client supplied SmallVector with the name for custom metadata IDs registere...
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
unsigned getInstructionCount()
Returns the number of non-debug IR instructions in the module.
This file contains the simple types necessary to represent the attributes associated with functions a...
Class to represent function types.
void setRtLibUseGOT()
Set that PLT should be avoid for RTLib calls.
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type. ...
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining...
iterator_range< op_iterator > operands()
Class to represent pointers.
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata *> MDs)
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
iterator_range< iterator > functions()
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
The instances of the Type class are immutable: once they are created, they are never changed...
This is an important class for using LLVM in a threaded context.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
getOperandBundleTags - Populate client supplied SmallVector with the bundle tags registered in this L...
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
unsigned getMajor() const
Retrieve the major version number.
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
unsigned getAddressSpace() const
void setCodeModel(CodeModel::Model CL)
Set the code model (tiny, small, kernel, medium or large)
self_iterator getIterator()
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
Optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
std::vector< StructType * > getIdentifiedStructTypes() const
GlobalVariable * collectUsedGlobalVariables(const Module &M, SmallPtrSetImpl< GlobalValue *> &Set, bool CompilerUsed)
Given "llvm.used" or "llvm.compiler.used" as a global name, collect the initializer elements of that ...
static ErrorSuccess success()
Create a success value.
This is the shared class of boolean and integer constants.
void run(const Module &M, bool onlyNamed)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB...
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
void dropAllReferences()
dropAllReferences() - This method causes all the subinstructions to "let go" of all references that t...
unsigned getProgramAddressSpace() const
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.
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
void setAttributes(AttributeList Attrs)
Set the attribute list for this Function.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
A range adaptor for a pair of iterators.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings"...
ConstantArray - Constant Array Declarations.
void push_back(pointer val)
StringRef getName() const
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
DICompileUnit * operator*() const
A random number generator.
Represents a version number in the form major[.minor[.subminor[.build]]].
Constant * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
static IntegerType * getInt32Ty(LLVMContext &C)
void setSDKVersion(const VersionTuple &V)
Attach a build SDK version metadata to this module.
std::unique_ptr< RandomNumberGenerator > createRNG(const Pass *P) const
Get a RandomNumberGenerator salted for use with this module.
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
~Module()
The module destructor. This will dropAllReferences.
void setPIELevel(PIELevel::Level PL)
Set the PIE level (small or large model)
iterator_range< ifunc_iterator > ifuncs()
void setOwnedMemoryBuffer(std::unique_ptr< MemoryBuffer > MB)
Take ownership of the given memory buffer.
Value * lookup(StringRef Name) const
This method finds the value with the given Name in the the symbol table.
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
unsigned getNumberRegisterParameters() const
Returns the Number of Register ParametersDwarf Version by checking module flags.
bool hasInitializer() const
Definitions have initializers, declarations don't.
Lightweight error class with error context and mandatory checking.
Defines the llvm::VersionTuple class, which represents a version in the form major[.minor[.subminor]].
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
iterator_range< global_iterator > globals()
iterator_range< global_object_iterator > global_objects()
StringRef - Represent a constant reference to a string, i.e.
Optional< unsigned > getSubminor() const
Retrieve the subminor version number, if provided.
VersionTuple getSDKVersion() const
Get the build SDK version metadata.
void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind)
Attach profile summary metadata to this module.
unsigned getNumOperands() const
Return number of MDNode operands.
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type. ...
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
llvm::Error materializeMetadata()
PointerType * getType() const
Global values are always pointers.
iterator_range< alias_iterator > aliases()
iterator_range< global_value_iterator > global_values()