43 assert(Ty &&
"Value defined with a null type: Error!");
47 Value::Value(
Type *ty,
unsigned scid)
48 : VTy(
checkType(ty)), UseList(nullptr), SubclassID(scid),
49 HasValueHandle(0), SubclassOptionalData(0), SubclassData(0),
50 NumUserOperands(0), IsUsedByMD(
false), HasName(
false) {
56 "invalid CallInst type!");
57 else if (SubclassID != BasicBlockVal &&
58 (SubclassID < ConstantFirstVal || SubclassID > ConstantLastVal))
60 "Cannot create non-first-class values except for constants!");
70 #ifndef NDEBUG // Only in -g mode...
77 dbgs() <<
"While deleting: " << *VTy <<
" %" <<
getName() <<
"\n";
78 for (
auto *U :
users())
79 dbgs() <<
"Use still stuck around after Def is destroyed:" << *U <<
"\n";
82 assert(
use_empty() &&
"Uses remain when a value is destroyed!");
89 void Value::destroyValueName() {
100 if (UI == E)
return false;
108 if (UI == E)
return false;
122 for (; BI != BE && UI != UE; ++BI, ++UI) {
124 if (std::find(BI->op_begin(), BI->op_end(),
this) != BI->op_end())
143 ST = &PP->getValueSymbolTable();
144 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
146 ST = &
P->getValueSymbolTable();
147 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
148 if (
Module *
P = GV->getParent())
149 ST = &
P->getValueSymbolTable();
150 }
else if (
Argument *
A = dyn_cast<Argument>(V)) {
152 ST = &
P->getValueSymbolTable();
154 assert(isa<Constant>(V) &&
"Unknown value type!");
166 "No name entry found!");
175 "HasName bit out of sync!");
197 void Value::setNameImpl(
const Twine &NewName) {
205 "Null bytes are not allowed in names");
211 assert(!
getType()->isVoidTy() &&
"Cannot assign a name to void values!");
219 if (NameRef.
empty()) {
251 setNameImpl(NewName);
252 if (
Function *
F = dyn_cast<Function>(
this))
253 F->recalculateIntrinsicID();
291 assert(!Failure &&
"V has a name, so it should have a ST!"); (void)Failure;
313 ST->reinsertValue(
this);
319 if (!Cache.
insert(Expr).second)
352 assert(New &&
"Value::replaceAllUsesWith(<null>) is invalid!");
354 "this->replaceAllUsesWith(expr(this)) is NOT valid!");
356 "replaceAllUses of value with new value of different type!");
368 if (
auto *
C = dyn_cast<Constant>(U.
getUser())) {
369 if (!isa<GlobalValue>(
C)) {
370 C->handleOperandChange(
this, New, &U);
378 if (
BasicBlock *BB = dyn_cast<BasicBlock>(
this))
379 BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
385 assert(New &&
"Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
387 "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
389 "replaceUses of value with new value of different type!");
390 assert(BB &&
"Basic block that may contain a use of 'New' must be defined\n");
397 if (Usr && Usr->getParent() == BB)
408 PSK_ZeroIndicesAndAliases,
409 PSK_InBoundsConstantIndices,
413 template <Po
interStripKind StripKind>
414 static Value *stripPointerCastsAndOffsets(
Value *V) {
426 case PSK_ZeroIndicesAndAliases:
427 case PSK_ZeroIndices:
428 if (!
GEP->hasAllZeroIndices())
431 case PSK_InBoundsConstantIndices:
432 if (!
GEP->hasAllConstantIndices())
436 if (!
GEP->isInBounds())
440 V =
GEP->getPointerOperand();
443 V = cast<Operator>(V)->getOperand(0);
444 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
445 if (StripKind == PSK_ZeroIndices || GA->mayBeOverridden())
447 V = GA->getAliasee();
452 }
while (Visited.
insert(V).second);
459 return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(
this);
463 return stripPointerCastsAndOffsets<PSK_ZeroIndices>(
this);
467 return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(
this);
476 getType())->getAddressSpace()) &&
477 "The offset must have exactly as many bits as our pointer.");
486 if (!
GEP->isInBounds())
488 APInt GEPOffset(Offset);
489 if (!
GEP->accumulateConstantOffset(DL, GEPOffset))
492 V =
GEP->getPointerOperand();
495 V = cast<Operator>(V)->getOperand(0);
496 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
497 V = GA->getAliasee();
502 }
while (Visited.insert(V).second);
508 return stripPointerCastsAndOffsets<PSK_InBounds>(
this);
522 if (!UseList || !UseList->Next)
527 Use *Current = UseList->Next;
528 Head->Next =
nullptr;
530 Use *Next = Current->Next;
531 Current->Next = Head;
532 Head->setPrev(&Current->Next);
537 Head->setPrev(&UseList);
545 assert(List &&
"Handle list is null?");
552 Next->setPrevPtr(&Next);
553 assert(V == Next->V &&
"Added to wrong list?");
557 void ValueHandleBase::AddToExistingUseListAfter(
ValueHandleBase *List) {
558 assert(List &&
"Must insert after existing node");
561 setPrevPtr(&List->Next);
564 Next->setPrevPtr(&Next);
567 void ValueHandleBase::AddToUseList() {
568 assert(V &&
"Null pointer doesn't have a use list!");
572 if (V->HasValueHandle) {
576 assert(Entry &&
"Value doesn't have any handles?");
577 AddToExistingUseList(&Entry);
590 assert(!Entry &&
"Value really did already have handles?");
591 AddToExistingUseList(&Entry);
592 V->HasValueHandle =
true;
597 Handles.
size() == 1) {
603 E = Handles.
end();
I != E; ++
I) {
604 assert(
I->second &&
I->first ==
I->second->V &&
605 "List invariant broken!");
606 I->second->setPrevPtr(&
I->second);
610 void ValueHandleBase::RemoveFromUseList() {
611 assert(V && V->HasValueHandle &&
612 "Pointer doesn't have a use list!");
616 assert(*PrevPtr ==
this &&
"List invariant broken");
620 assert(Next->getPrevPtr() == &Next &&
"List invariant broken");
621 Next->setPrevPtr(PrevPtr);
632 V->HasValueHandle =
false;
638 assert(V->HasValueHandle &&
"Should only be called if ValueHandles present");
644 assert(Entry &&
"Value bit set but no entries exist");
656 Iterator.RemoveFromUseList();
657 Iterator.AddToExistingUseListAfter(Entry);
658 assert(Entry->Next == &Iterator &&
"Loop invariant broken.");
660 switch (Entry->getKind()) {
670 Entry->operator=(
nullptr);
680 if (V->HasValueHandle) {
681 #ifndef NDEBUG // Only in +Asserts mode...
695 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
696 assert(Old != New &&
"Changing value into itself!");
698 "replaceAllUses of value with new value of different type!");
705 assert(Entry &&
"Value bit set but no entries exist");
712 Iterator.RemoveFromUseList();
713 Iterator.AddToExistingUseListAfter(Entry);
714 assert(Entry->Next == &Iterator &&
"Loop invariant broken.");
716 switch (Entry->getKind()) {
729 Entry->operator=(New);
733 static_cast<CallbackVH*
>(Entry)->allUsesReplacedWith(New);
741 if (Old->HasValueHandle)
742 for (Entry = pImpl->ValueHandles[Old]; Entry; Entry = Entry->Next)
743 switch (Entry->getKind()) {
746 dbgs() <<
"After RAUW from " << *Old->
getType() <<
" %"
758 void CallbackVH::anchor() {}
This is the common base class of value handles.
use_iterator_impl< Use > use_iterator
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.
static void ValueIsDeleted(Value *V)
Value * stripInBoundsConstantOffsets()
Strip off pointer casts and all-constant inbounds GEPs.
LLVM Argument representation.
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. ...
void setValue(const ValueTy &V)
bool hasNUses(unsigned N) const
Return true if this Value has exactly N users.
static StringMapEntry * Create(StringRef Key, AllocatorTy &Allocator, InitType &&InitVal)
Create - Create a StringMapEntry for the specified key and default construct the value.
StringRef getName() const
Return a constant reference to the value's name.
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...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
A Use represents the edge between a Value definition and its users.
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
void setName(const Twine &Name)
Change the name of the value.
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
DenseMap< const Value *, ValueName * > ValueNames
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
Accumulate offsets from stripInBoundsConstantOffsets().
void Destroy(AllocatorTy &Allocator)
Destroy - Destroy this StringMapEntry, releasing memory back to the specified allocator.
ConstantExpr - a constant value that is initialized with an expression using other constant values...
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool isFirstClassType() const
isFirstClassType - Return true if the type is "first class", meaning it is a valid type for a Value...
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
static void ValueIsRAUWd(Value *Old, Value *New)
void takeName(Value *V)
Transfer the name from V to this value.
ValueName * getValueName() const
Value * stripPointerCastsNoFollowAliases()
Strip off pointer casts and all-zero GEPs.
bool erase(const KeyT &Val)
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.
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Value * stripInBoundsOffsets()
Strip off pointer casts and inbounds GEPs.
bool isUsedByMetadata() const
Return true if there is metadata referencing this value.
unsigned getBitWidth() const
Return the number of bits in the APInt.
ValueHandlesTy ValueHandles
User * getUser() const
Returns the User that contains this Use.
bool isPointerTy() const
isPointerTy - True if this is an instance of PointerType.
LLVMContext & getContext() const
All values hold a context through their type.
use_iterator_impl< const Use > const_use_iterator
bool isUsedInBasicBlock(const BasicBlock *BB) const
Check if this value is used in the specified basic block.
LLVMContextImpl *const pImpl
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
Translate PHI node to its predecessor from the given basic block.
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class for arbitrary precision integers.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
iterator_range< user_iterator > users()
LLVM_ATTRIBUTE_UNUSED_RESULT std::enable_if< !is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the DenseMap's...
bool isStructTy() const
isStructTy - True if this is an instance of StructType.
unsigned getOpcode() const
Return the opcode for this Instruction or ConstantExpr.
void reverseUseList()
Reverse the use-list.
user_iterator_impl< const User > const_user_iterator
unsigned getPointerSizeInBits(unsigned AS=0) const
Layout pointer size, in bits FIXME: The defaults need to be removed once all of the backends/clients ...
static bool getSymTab(Value *V, ValueSymbolTable *&ST)
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.
bool hasNUsesOrMore(unsigned N) const
Return true if this value has N users or more.
user_iterator user_begin()
LLVM Value Representation.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
void setValueName(ValueName *VN)
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"...
unsigned getNumUses() const
This method computes the number of uses of this Value.
const BasicBlock * getParent() const
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
bool empty() const
empty - Check if the string is empty.