44 cl::desc(
"Maximum size for the name of non-global values."));
50 assert(Ty &&
"Value defined with a null type: Error!");
55 : VTy(
checkType(ty)), UseList(nullptr), SubclassID(scid),
56 HasValueHandle(0), SubclassOptionalData(0), SubclassData(0),
57 NumUserOperands(0), IsUsedByMD(
false), HasName(
false) {
58 static_assert(ConstantFirstVal == 0,
"!(SubclassID < ConstantFirstVal)");
64 "invalid CallInst type!");
65 else if (SubclassID != BasicBlockVal &&
66 ( SubclassID > ConstantLastVal))
68 "Cannot create non-first-class values except for constants!");
69 static_assert(
sizeof(
Value) == 2 *
sizeof(
void *) + 2 *
sizeof(
unsigned),
80 #ifndef NDEBUG // Only in -g mode... 87 dbgs() <<
"While deleting: " << *VTy <<
" %" <<
getName() <<
"\n";
88 for (
auto *U :
users())
89 dbgs() <<
"Use still stuck around after Def is destroyed:" << *U <<
"\n";
101 #define HANDLE_VALUE(Name) \ 102 case Value::Name##Val: \ 103 delete static_cast<Name *>(this); \ 105 #define HANDLE_MEMORY_VALUE(Name) \ 106 case Value::Name##Val: \ 107 static_cast<DerivedUser *>(this)->DeleteValue( \ 108 static_cast<DerivedUser *>(this)); \ 110 #define HANDLE_INSTRUCTION(Name) 111 #include "llvm/IR/Value.def" 113 #define HANDLE_INST(N, OPC, CLASS) \ 114 case Value::InstructionVal + Instruction::OPC: \ 115 delete static_cast<CLASS *>(this); \ 117 #define HANDLE_USER_INST(N, OPC, CLASS) 118 #include "llvm/IR/Instruction.def" 125 void Value::destroyValueName() {
136 if (UI ==
E)
return false;
144 if (UI ==
E)
return false;
158 for (; BI != BE && UI != UE; ++BI, ++UI) {
164 if (
User &&
User->getParent() == BB)
179 ST = PP->getValueSymbolTable();
180 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
182 ST =
P->getValueSymbolTable();
183 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
184 if (
Module *
P = GV->getParent())
185 ST = &
P->getValueSymbolTable();
186 }
else if (
Argument *A = dyn_cast<Argument>(V)) {
188 ST =
P->getValueSymbolTable();
190 assert(isa<Constant>(V) &&
"Unknown value type!");
202 "No name entry found!");
211 "HasName bit out of sync!");
233 void Value::setNameImpl(
const Twine &NewName) {
235 if (
getContext().shouldDiscardValueNames() && !isa<GlobalValue>(
this))
245 "Null bytes are not allowed in names");
256 assert(!
getType()->isVoidTy() &&
"Cannot assign a name to void values!");
264 if (NameRef.
empty()) {
296 setNameImpl(NewName);
297 if (
Function *
F = dyn_cast<Function>(
this))
298 F->recalculateIntrinsicID();
336 assert(!Failure &&
"V has a name, so it should have a ST!"); (void)Failure;
358 ST->reinsertValue(
this);
376 if (!Cache.
insert(Expr).second)
408 void Value::doRAUW(
Value *New,
bool NoMetadata) {
409 assert(New &&
"Value::replaceAllUsesWith(<null>) is invalid!");
411 "this->replaceAllUsesWith(expr(this)) is NOT valid!");
413 "replaceAllUses of value with new value of different type!");
425 if (
auto *
C = dyn_cast<Constant>(U.
getUser())) {
426 if (!isa<GlobalValue>(
C)) {
427 C->handleOperandChange(
this, New);
435 if (
BasicBlock *BB = dyn_cast<BasicBlock>(
this))
436 BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
450 assert(New &&
"Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
452 "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
454 "replaceUses of value with new value of different type!");
455 assert(BB &&
"Basic block that may contain a use of 'New' must be defined\n");
462 if (Usr && Usr->getParent() == BB)
472 PSK_ZeroIndicesAndAliases,
473 PSK_ZeroIndicesAndAliasesAndInvariantGroups,
474 PSK_InBoundsConstantIndices,
478 template <Po
interStripKind StripKind>
479 static const Value *stripPointerCastsAndOffsets(
const Value *V) {
489 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
491 case PSK_ZeroIndicesAndAliases:
492 case PSK_ZeroIndicesAndAliasesAndInvariantGroups:
493 case PSK_ZeroIndices:
494 if (!
GEP->hasAllZeroIndices())
497 case PSK_InBoundsConstantIndices:
498 if (!
GEP->hasAllConstantIndices())
502 if (!
GEP->isInBounds())
506 V =
GEP->getPointerOperand();
509 V = cast<Operator>(V)->getOperand(0);
510 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
511 if (StripKind == PSK_ZeroIndices || GA->isInterposable())
513 V = GA->getAliasee();
516 if (
const Value *RV = CS.getReturnedArgOperand()) {
523 if (StripKind == PSK_ZeroIndicesAndAliasesAndInvariantGroups &&
524 (CS.getIntrinsicID() == Intrinsic::launder_invariant_group ||
525 CS.getIntrinsicID() == Intrinsic::strip_invariant_group)) {
526 V = CS.getArgOperand(0);
533 }
while (Visited.
insert(V).second);
540 return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(
this);
544 return stripPointerCastsAndOffsets<PSK_ZeroIndices>(
this);
548 return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(
this);
552 return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliasesAndInvariantGroups>(
563 getType())->getAddressSpace()) &&
564 "The offset bit width does not match the DL specification.");
570 const Value *V =
this;
572 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
573 if (!
GEP->isInBounds())
575 APInt GEPOffset(Offset);
576 if (!
GEP->accumulateConstantOffset(DL, GEPOffset))
579 V =
GEP->getPointerOperand();
581 V = cast<Operator>(V)->getOperand(0);
582 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
583 V = GA->getAliasee();
586 if (
const Value *RV = CS.getReturnedArgOperand()) {
594 }
while (Visited.insert(V).second);
600 return stripPointerCastsAndOffsets<PSK_InBounds>(
this);
604 bool &CanBeNull)
const {
607 uint64_t DerefBytes = 0;
609 if (
const Argument *A = dyn_cast<Argument>(
this)) {
610 DerefBytes = A->getDereferenceableBytes();
611 if (DerefBytes == 0 && (A->hasByValAttr() || A->hasStructRetAttr())) {
612 Type *PT = cast<PointerType>(A->getType())->getElementType();
616 if (DerefBytes == 0) {
617 DerefBytes = A->getDereferenceableOrNullBytes();
622 if (DerefBytes == 0) {
626 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
628 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
631 if (DerefBytes == 0) {
634 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
639 }
else if (
auto *AI = dyn_cast<AllocaInst>(
this)) {
640 if (!AI->isArrayAllocation()) {
644 }
else if (
auto *GV = dyn_cast<GlobalVariable>(
this)) {
645 if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
659 if (
auto *GO = dyn_cast<GlobalObject>(
this)) {
662 if (isa<Function>(GO))
664 Align = GO->getAlignment();
666 if (
auto *GVar = dyn_cast<GlobalVariable>(GO)) {
667 Type *ObjectType = GVar->getValueType();
672 if (GVar->isStrongDefinitionForLinker())
679 }
else if (
const Argument *A = dyn_cast<Argument>(
this)) {
680 Align = A->getParamAlignment();
682 if (!Align && A->hasStructRetAttr()) {
684 Type *EltTy = cast<PointerType>(A->getType())->getElementType();
688 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
this)) {
689 Align = AI->getAlignment();
691 Type *AllocatedType = AI->getAllocatedType();
696 Align = CS.getAttributes().getRetAlignment();
697 else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this))
699 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
709 if (PN && PN->getParent() == CurBB)
717 if (!UseList || !UseList->Next)
722 Use *Current = UseList->Next;
723 Head->Next =
nullptr;
725 Use *Next = Current->Next;
726 Current->Next = Head;
727 Head->setPrev(&Current->Next);
732 Head->setPrev(&UseList);
738 return Arg->hasSwiftErrorAttr();
750 assert(List &&
"Handle list is null?");
757 Next->setPrevPtr(&Next);
758 assert(getValPtr() == Next->getValPtr() &&
"Added to wrong list?");
762 void ValueHandleBase::AddToExistingUseListAfter(
ValueHandleBase *List) {
763 assert(List &&
"Must insert after existing node");
766 setPrevPtr(&List->Next);
769 Next->setPrevPtr(&Next);
772 void ValueHandleBase::AddToUseList() {
773 assert(getValPtr() &&
"Null pointer doesn't have a use list!");
777 if (getValPtr()->HasValueHandle) {
781 assert(Entry &&
"Value doesn't have any handles?");
782 AddToExistingUseList(&Entry);
795 assert(!Entry &&
"Value really did already have handles?");
796 AddToExistingUseList(&Entry);
797 getValPtr()->HasValueHandle =
true;
802 Handles.
size() == 1) {
808 E = Handles.
end();
I !=
E; ++
I) {
809 assert(
I->second &&
I->first ==
I->second->getValPtr() &&
810 "List invariant broken!");
811 I->second->setPrevPtr(&
I->second);
816 assert(getValPtr() && getValPtr()->HasValueHandle &&
817 "Pointer doesn't have a use list!");
821 assert(*PrevPtr ==
this &&
"List invariant broken");
825 assert(Next->getPrevPtr() == &Next &&
"List invariant broken");
826 Next->setPrevPtr(PrevPtr);
836 Handles.
erase(getValPtr());
837 getValPtr()->HasValueHandle =
false;
842 assert(V->HasValueHandle &&
"Should only be called if ValueHandles present");
848 assert(Entry &&
"Value bit set but no entries exist");
860 Iterator.RemoveFromUseList();
861 Iterator.AddToExistingUseListAfter(Entry);
862 assert(Entry->Next == &Iterator &&
"Loop invariant broken.");
864 switch (Entry->getKind()) {
871 Entry->operator=(
nullptr);
881 if (V->HasValueHandle) {
882 #ifndef NDEBUG // Only in +Asserts mode... 895 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
896 assert(Old != New &&
"Changing value into itself!");
898 "replaceAllUses of value with new value of different type!");
905 assert(Entry &&
"Value bit set but no entries exist");
912 Iterator.RemoveFromUseList();
913 Iterator.AddToExistingUseListAfter(Entry);
914 assert(Entry->Next == &Iterator &&
"Loop invariant broken.");
916 switch (Entry->getKind()) {
923 Entry->operator=(New);
927 static_cast<CallbackVH*
>(Entry)->allUsesReplacedWith(New);
935 if (Old->HasValueHandle)
936 for (Entry = pImpl->ValueHandles[Old]; Entry; Entry = Entry->Next)
937 switch (Entry->getKind()) {
939 dbgs() <<
"After RAUW from " << *Old->
getType() <<
" %" 943 "A weak tracking value handle still pointed to the old value!\n");
951 void CallbackVH::anchor() {}
This is the common base class of value handles.
A parsed version of the target data layout string in and methods for querying it. ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
This class provides a symbol table of name/value pairs.
static void ValueIsDeleted(Value *V)
unsigned getIndexSizeInBits(unsigned AS) const
Size in bits of index used for address calculation in getelementptr.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
This class represents an incoming formal argument to a Function.
unsigned getValueID() const
Return an ID for the concrete type of this object.
const Value * stripInBoundsOffsets() const
Strip off pointer casts and inbounds GEPs.
Compute iterated dominance frontiers using a linear time algorithm.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
A Module instance is used to store all the information related to an LLVM module. ...
bool isSized(SmallPtrSetImpl< Type *> *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
void setValue(const ValueTy &V)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t size() const
size - Get the string size.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
bool isSwiftError() const
Return true if this alloca is used as a swifterror argument to a call.
LLVMContext & getContext() const
All values hold a context through their type.
void deleteValue()
Delete a pointer to a generic Value.
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
An instruction for reading from memory.
use_iterator_impl< const Use > const_use_iterator
const Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB) const
Translate PHI node to its predecessor from the given basic block.
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
iterator begin()
Instruction iterator methods.
static Type * checkType(Type *Ty)
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
A Use represents the edge between a Value definition and its users.
void setName(const Twine &Name)
Change the name of the value.
void assertModuleIsMaterializedImpl() const
DenseMap< const Value *, ValueName * > ValueNames
static StringMapEntry * Create(StringRef Key, AllocatorTy &Allocator, InitTy &&... InitVals)
Create a StringMapEntry for the specified key construct the value using InitiVals.
void Destroy(AllocatorTy &Allocator)
Destroy - Destroy this StringMapEntry, releasing memory back to the specified allocator.
User * getUser() const LLVM_READONLY
Returns the User that contains this Use.
A constant value that is initialized with an expression using other constant values.
Type * getType() const
All values are typed, get the type of this value.
bool isFirstClassType() const
Return true if the type is "first class", meaning it is a valid type for a Value. ...
bool isSwiftError() const
Return true if this value is a swifterror value.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static void ValueIsRAUWd(Value *Old, Value *New)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE StringRef substr(size_t Start, size_t N=npos) const
Return a reference to the substring from [Start, Start + N).
void takeName(Value *V)
Transfer the name from V to this value.
use_iterator_impl< Use > use_iterator
bool isVoidTy() const
Return true if this is 'void'.
initializer< Ty > init(const Ty &Val)
bool erase(const KeyT &Val)
void RemoveFromUseList()
Remove this ValueHandle from its current use list.
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
LLVM Basic Block Representation.
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
void replaceNonMetadataUsesWith(Value *V)
Change non-metadata uses of this to point to a new Value.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
This file contains the declarations for the subclasses of Constant, which represent the different fla...
bool isPointerTy() const
True if this is an instance of PointerType.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
unsigned getPrefTypeAlignment(Type *Ty) const
Returns the preferred stack/global alignment for the specified type.
bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
ValueHandlesTy ValueHandles
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
Value(Type *Ty, unsigned scid)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
LLVMContextImpl *const pImpl
Iterator for intrusive lists based on ilist_node.
static cl::opt< unsigned > NonGlobalValueMaxNameSize("non-global-value-max-name-size", cl::Hidden, cl::init(1024), cl::desc("Maximum size for the name of non-global values."))
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
This is the shared class of boolean and integer constants.
bool materialized_use_empty() const
Module.h This file contains the declarations for the Module class.
ValueName * getValueName() const
unsigned getABITypeAlignment(Type *Ty) const
Returns the minimum ABI-required alignment for the specified type.
uint64_t getPointerDereferenceableBytes(const DataLayout &DL, bool &CanBeNull) const
Returns the number of bytes known to be dereferenceable for the pointer value.
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the DenseMap's...
const Value * stripPointerCastsAndInvariantGroups() const
Strip off pointer casts, all-zero GEPs, aliases and invariant group info.
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
unsigned getPreferredAlignment(const GlobalVariable *GV) const
Returns the preferred alignment of the specified global.
const Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset) const
Accumulate offsets from stripInBoundsConstantOffsets().
Class for arbitrary precision integers.
iterator_range< user_iterator > users()
user_iterator_impl< const User > const_user_iterator
amdgpu Simplify well known AMD library false Value Value * Arg
void reverseUseList()
Reverse the use-list.
bool isMaterialized() const
unsigned getNumUses() const
This method computes the number of uses of this Value.
const Value * stripPointerCastsNoFollowAliases() const
Strip off pointer casts and all-zero GEPs.
StringRef getName() const
Return a constant reference to the value's name.
Establish a view to a call site for examination.
LLVM_NODISCARD size_t find_first_of(char C, size_t From=0) const
Find the first character in the string that is C, or npos if not found.
static bool getSymTab(Value *V, ValueSymbolTable *&ST)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
~Value()
Value's destructor should be virtual by design, but that would require that Value and all of its subc...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
user_iterator user_begin()
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
uint64_t getTypeStoreSize(Type *Ty) const
Returns the maximum number of bytes that may be overwritten by storing the specified type...
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
void setValueName(ValueName *VN)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Value handle with callbacks on RAUW and destruction.
StringRef - Represent a constant reference to a string, i.e.
void replaceUsesOutsideBlock(Value *V, BasicBlock *BB)
replaceUsesOutsideBlock - Go through the uses list for this definition and make each use point to "V"...
const Value * stripInBoundsConstantOffsets() const
Strip off pointer casts and all-constant inbounds GEPs.
static bool contains(SmallPtrSetImpl< ConstantExpr *> &Cache, ConstantExpr *Expr, Constant *C)
bool isStructTy() const
True if this is an instance of StructType.
an instruction to allocate memory on the stack
bool is_contained(R &&Range, const E &Element)
Wrapper function around std::find to detect if an element exists in a container.