Go to the documentation of this file.
75 Context.addModule(
this);
79 Context.removeModule(
this);
87 std::unique_ptr<RandomNumberGenerator>
103 return std::unique_ptr<RandomNumberGenerator>(
152 if (!New->isIntrinsic())
154 FunctionList.push_back(New);
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));
407 void 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());
603 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"PIE Level"));
609 cast<ConstantInt>(Val->getValue())->getZExtValue());
617 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"Code Model"));
623 cast<ConstantInt>(Val->getValue())->getZExtValue());
649 auto *Val = cast_or_null<ConstantAsMetadata>(MF);
653 return cast<ConstantInt>(Val->getValue())->getZExtValue();
665 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"RtLibUseGOT"));
666 return Val && (cast<ConstantInt>(Val->getValue())->getZExtValue() > 0);
674 if (
auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"uwtable")))
675 return UWTableKind(cast<ConstantInt>(Val->getValue())->getZExtValue());
684 auto *Val = cast_or_null<ConstantAsMetadata>(
getModuleFlag(
"frame-pointer"));
686 Val ? cast<ConstantInt>(Val->getValue())->getZExtValue() : 0);
695 if (
auto *MDS = dyn_cast_or_null<MDString>(MD))
696 return MDS->getString();
707 if (
auto *MDS = dyn_cast_or_null<MDString>(MD))
708 return MDS->getString();
719 if (
auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD))
720 return CI->getSExtValue();
730 if (
auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD))
731 return CI->getZExtValue();
743 Entries.push_back(*Minor);
745 Entries.push_back(*Subminor);
749 M.addModuleFlag(Module::ModFlagBehavior::Warning,
Name,
758 auto *CM = dyn_cast_or_null<ConstantAsMetadata>(MD);
761 auto *Arr = dyn_cast_or_null<ConstantDataArray>(CM->getValue());
765 if (
Index >= Arr->getNumElements())
767 return (
unsigned)Arr->getElementAsInteger(
Index);
769 auto Major = getVersionComponent(0);
773 if (
auto Minor = getVersionComponent(1)) {
775 if (
auto Subminor = getVersionComponent(2)) {
788 const char *
Name = CompilerUsed ?
"llvm.compiler.used" :
"llvm.used";
813 double Ratio = (
double)BlockCount / NumCounts;
822 if (
const auto *MD =
getModuleFlag(
"darwin.target_variant.triple"))
823 return cast<MDString>(MD)->getString();
828 addModuleFlag(ModFlagBehavior::Override,
"darwin.target_variant.triple",
iterator_range< global_value_iterator > global_values()
NamedMDNode * getOrInsertModuleFlagsMetadata()
Returns the NamedMDNode in the module that represents module-level flags.
This is an optimization pass for GlobalISel generic memory operations.
NamedMDNode * getModuleFlagsMetadata() const
Returns the NamedMDNode in the module that represents module-level flags.
void setFramePointer(FramePointerKind Kind)
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
A parsed version of the target data layout string in and methods for querying it.
unsigned getInstructionCount() const
Returns the number of non-debug IR instructions in the module.
StringRef getStackProtectorGuard() const
Get/set what kind of stack protector guard to use.
unsigned getNumOperands() const
bool isDwarf64() const
Returns the DWARF format by checking module flags.
void push_back(pointer val)
unsigned getProgramAddressSpace() const
static ProfileSummary * getFromMD(Metadata *MD)
Construct profile summary from metdata.
iterator_range< ifunc_iterator > ifuncs()
void setMaterializer(GVMaterializer *GVM)
Sets the GVMaterializer to GVM.
@ ModFlagBehaviorFirstVal
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
into xmm2 addss xmm2 xmm1 xmm3 addss xmm3 movaps xmm0 unpcklps xmm0 ret seems silly when it could just be one addps Expand libm rounding functions main should enable SSE DAZ mode and other fast SSE modes Think about doing i64 math in SSE regs on x86 This testcase should have no SSE instructions in and only one load from a constant double
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
@ None
No unwind table requested.
unsigned getCodeViewFlag() const
Returns the CodeView Version by checking module flags.
~Module()
The module destructor. This will dropAllReferences.
StringRef getStackProtectorGuardReg() const
Get/set which register to use as the stack protector guard register.
bool getRtLibUseGOT() const
Returns true if PLT should be avoided for RTLib calls.
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Reg
All possible values of the reg field in the ModR/M byte.
static ErrorSuccess success()
Create a success value.
static Constant * getBitCast(Constant *C, Type *Ty, bool OnlyIfReduced=false)
static bool isValidModFlagBehavior(Metadata *MD, ModFlagBehavior &MFB)
Checks if Metadata represents a valid ModFlagBehavior, and stores the converted result in MFB.
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
The instances of the Type class are immutable: once they are created, they are never changed.
Optional< CodeModel::Model > getCodeModel() const
Returns the code model (tiny, small, kernel, medium or large model)
void setSDKVersion(const VersionTuple &V)
Attach a build SDK version metadata to this module.
FunctionCallee getOrInsertFunction(StringRef Name, FunctionType *T, AttributeList AttributeList)
Look up the specified function in the module symbol table.
iterator_range< global_object_iterator > global_objects()
Metadata * getProfileSummary(bool IsCS) const
Returns profile summary metadata.
void getMDKindNames(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the name for custom metadata IDs registered in this LLVMCon...
void setStackProtectorGuard(StringRef Kind)
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
A random number generator.
static IntegerType * getInt32Ty(LLVMContext &C)
void setOverrideStackAlignment(unsigned Align)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
void setPIELevel(PIELevel::Level PL)
Set the PIE level (small or large model)
bool hasInitializer() const
Definitions have initializers, declarations don't.
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 ...
VersionTuple getSDKVersion() const
Get the build SDK version metadata.
iterator erase(iterator where)
bool isPartialProfile() const
unsigned getMajor() const
Retrieve the major version number.
unsigned getNumOperands() const
Return number of MDNode operands.
static void addSDKVersionMD(const VersionTuple &V, Module &M, StringRef Name)
void setRtLibUseGOT()
Set that PLT should be avoid for RTLib calls.
void addOperand(MDNode *M)
This is the shared class of boolean and integer constants.
void setSemanticInterposition(bool)
Set whether semantic interposition is to be respected.
iterator_range< global_iterator > globals()
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
uint32_t getNumCounts() const
void setCodeModel(CodeModel::Model CL)
Set the code model (tiny, small, kernel, medium or large)
(vector float) vec_cmpeq(*A, *B) C
Metadata * getMD(LLVMContext &Context, bool AddPartialField=true, bool AddPartialProfileRatioField=true)
Return summary information as metadata.
const ValueSymbolTable & getValueSymbolTable() const
Get the symbol table of global variable and function identifiers.
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
StringRef getName() const
StringRef getDarwinTargetVariantTriple() const
Get the target variant triple which is a string describing a variant of the target host platform.
static VersionTuple getSDKVersionMD(Metadata *MD)
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.
ConstantArray - Constant Array Declarations.
Flag
These should be considered private to the implementation of the MCInstrDesc class.
Constant * getOrInsertGlobal(StringRef Name, Type *Ty, function_ref< GlobalVariable *()> CreateGlobalCallback)
Look up the specified global in the module symbol table.
unsigned size() const
The number of name/type pairs is returned.
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.
DICompileUnit * operator*() const
Represents a version number in the form major[.minor[.subminor[.build]]].
This struct is a compact representation of a valid (non-zero power of two) alignment.
FramePointerKind getFramePointer() const
Get/set whether synthesized functions should get the "frame-pointer" attribute.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
GlobalIFunc * getNamedIFunc(StringRef Name) const
Return the global ifunc in the module with the specified name, of arbitrary type.
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.
UWTableKind getUwtable() const
Get/set whether synthesized functions should get the uwtable attribute.
An efficient, type-erasing, non-owning reference to a callable.
const MDOperand & getOperand(unsigned I) const
iterator_range< alias_iterator > aliases()
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
void setPICLevel(PICLevel::Level PL)
Set the PIC level (small or large model)
This is an important base class in LLVM.
unsigned getNumberRegisterParameters() const
Returns the Number of Register ParametersDwarf Version by checking module flags.
void dropAllReferences()
This function causes all the subinstructions to "let go" of all references that they are maintaining.
Optional< unsigned > getSubminor() const
Retrieve the subminor version number, if provided.
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
This is an important class for using LLVM in a threaded context.
ValueTy lookup(StringRef Key) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
llvm::Error materializeAll()
Make sure all GlobalValues in this Module are fully read and clear the Materializer.
Class to represent pointers.
iterator_range< iterator > functions()
Comdat * getOrInsertComdat(StringRef Name)
Return the Comdat in the module with the specified name.
static MDString * get(LLVMContext &Context, StringRef Str)
void setDataLayout(StringRef Desc)
Set the data layout.
MDNode * getOperand(unsigned i) const
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Optional< unsigned > getMinor() const
Retrieve the minor version number, if provided.
StandardInstrumentations SI(Debug, VerifyEach)
const std::string & getModuleIdentifier() const
Get the module identifier which is, essentially, the name of the module.
llvm::Error materializeMetadata()
A Module instance is used to store all the information related to an LLVM module.
unsigned getOverrideStackAlignment() const
Get/set the stack alignment overridden from the default.
void setModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Like addModuleFlag but replaces the old module flag if it already exists.
void setOwnedMemoryBuffer(std::unique_ptr< MemoryBuffer > MB)
Take ownership of the given memory buffer.
Module(StringRef ModuleID, LLVMContext &C)
The Module constructor.
void setStackProtectorGuardReg(StringRef Reg)
StringRef - Represent a constant reference to a string, i.e.
void run(const Module &M, bool onlyNamed)
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
static Constant * get(LLVMContext &Context, ArrayRef< ElementTy > Elts)
get() constructor - Return a constant with array type with an element count and element type matching...
self_iterator getIterator()
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
unsigned getNumNamedValues() const
Return the number of global values in the module.
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
iterator_range< op_iterator > operands()
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
Populate client supplied SmallVector with the bundle tags registered in this LLVMContext.
bool getSemanticInterposition() const
Returns whether semantic interposition is to be respected.
llvm::Error materialize(GlobalValue *GV)
Make sure the GlobalValue is fully read.
void setUwtable(UWTableKind Kind)
DICompileUnit * operator->() const
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...
unsigned getMDKindID(StringRef Name) const
Return a unique non-zero ID for the specified metadata kind.
Lightweight error class with error context and mandatory checking.
LLVMContext & getContext() const
Get the global data context.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
void setPartialProfileRatio(double R)
unsigned getDwarfVersion() const
Returns the Dwarf Version by checking module flags.
std::vector< StructType * > getIdentifiedStructTypes() const
void getOperandBundleTags(SmallVectorImpl< StringRef > &Result) const
getOperandBundleTags - Populate client supplied SmallVector with the bundle tags registered in this L...
PIELevel::Level getPIELevel() const
Returns the PIE level (small or large model)
std::unique_ptr< RandomNumberGenerator > createRNG(const StringRef Name) const
Get a RandomNumberGenerator salted for use with this module.
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
@ ExternalLinkage
Externally visible function.
void setPartialSampleProfileRatio(const ModuleSummaryIndex &Index)
Set the partial sample profile ratio in the profile summary module flag, if applicable.
StringRef filename(StringRef path, Style style=Style::native)
Get filename.
This class provides a symbol table of name/value pairs.
void addModuleFlag(ModFlagBehavior Behavior, StringRef Key, Metadata *Val)
Add a module-level flag to the module-level flags metadata.
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.
Class to hold module path string table and global value map, and encapsulate methods for operating on...
NamedMDNode * getNamedMetadata(const Twine &Name) const
Return the first NamedMDNode in the module with the specified name.
int getStackProtectorGuardOffset() const
Get/set what offset from the stack protector to use.
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 reset(StringRef LayoutDescription)
Parse a data layout string (with fallback to default values).
A range adaptor for a pair of iterators.
A handy container for a FunctionType+Callee-pointer pair, which can be passed around as a single enti...
unsigned getMDKindID(StringRef Name) const
getMDKindID - Return a unique non-zero ID for the specified metadata kind.
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
void setStackProtectorGuardOffset(int Offset)
void eraseNamedMetadata(NamedMDNode *NMD)
Remove the given NamedMDNode from this module and delete it.
void setProfileSummary(Metadata *M, ProfileSummary::Kind Kind)
Attach profile summary metadata to this module.
StringRef getString() const
LLVM Value Representation.
void setDarwinTargetVariantTriple(StringRef T)
Set the target variant triple which is a string describing a variant of the target host platform.
ModFlagBehavior
This enumeration defines the supported behaviors of module flags.
VersionTuple getDarwinTargetVariantSDKVersion() const
Get the target variant version build SDK version metadata.
GlobalValue * getNamedValue(StringRef Name) const
Return the global value in the module with the specified name, of arbitrary type.
Optional< std::vector< StOtherPiece > > Other
Class to represent function types.