40 assert(Ty &&
"Value defined with a null type: Error!");
41 return const_cast<Type*
>(Ty);
44 Value::Value(
Type *ty,
unsigned scid)
45 : SubclassID(scid), HasValueHandle(0),
46 SubclassOptionalData(0), SubclassData(0), VTy((
Type*)
checkType(ty)),
53 "invalid CallInst type!");
57 "Cannot create non-first-class values except for constants!");
65 #ifndef NDEBUG // Only in -g mode...
73 dbgs() <<
"While deleting: " << *VTy <<
" %" <<
getName() <<
"\n";
75 dbgs() <<
"Use still stuck around after Def is destroyed:"
79 assert(
use_empty() &&
"Uses remain when a value is destroyed!");
96 if (UI == E)
return false;
107 if (UI == E)
return false;
123 for (; BI != BE && UI != UE; ++BI, ++UI) {
125 if (std::find(BI->op_begin(), BI->op_end(),
this) != BI->op_end())
148 ST = &PP->getValueSymbolTable();
149 }
else if (
BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
151 ST = &
P->getValueSymbolTable();
152 }
else if (
GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
153 if (
Module *
P = GV->getParent())
154 ST = &
P->getValueSymbolTable();
155 }
else if (
Argument *
A = dyn_cast<Argument>(V)) {
157 ST = &
P->getValueSymbolTable();
158 }
else if (isa<MDString>(V))
161 assert(isa<Constant>(V) &&
"Unknown value type!");
177 "Cannot set the name of MDString with this method!");
190 assert(!
getType()->isVoidTy() &&
"Cannot assign a name to void values!");
197 if (
Function *
F = dyn_cast<Function>(
this))
201 if (NameRef.
empty()) {
224 ST->removeValueName(Name);
233 Name = ST->createValueName(NameRef,
this);
240 assert(SubclassID !=
MDStringVal &&
"Cannot take the name of an MDString!");
255 ST->removeValueName(Name);
277 assert(!Failure &&
"V has a name, so it should have a ST!"); (void)Failure;
293 VST->removeValueName(V->Name);
299 ST->reinsertValue(
this);
304 assert(New &&
"Value::replaceAllUsesWith(<null>) is invalid!");
305 assert(New !=
this &&
"this->replaceAllUsesWith(this) is NOT valid!");
307 "replaceAllUses of value with new value of different type!");
318 if (!isa<GlobalValue>(
C)) {
319 C->replaceUsesOfWithOnConstant(
this, New, &U);
327 if (
BasicBlock *BB = dyn_cast<BasicBlock>(
this))
328 BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
335 PSK_ZeroIndicesAndAliases,
336 PSK_InBoundsConstantIndices,
340 template <Po
interStripKind StripKind>
341 static Value *stripPointerCastsAndOffsets(
Value *V) {
353 case PSK_ZeroIndicesAndAliases:
354 case PSK_ZeroIndices:
355 if (!GEP->hasAllZeroIndices())
358 case PSK_InBoundsConstantIndices:
359 if (!GEP->hasAllConstantIndices())
363 if (!GEP->isInBounds())
367 V = GEP->getPointerOperand();
370 V = cast<Operator>(V)->getOperand(0);
371 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
372 if (StripKind == PSK_ZeroIndices || GA->mayBeOverridden())
374 V = GA->getAliasee();
379 }
while (Visited.
insert(V));
386 return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(
this);
390 return stripPointerCastsAndOffsets<PSK_ZeroIndices>(
this);
394 return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(
this);
403 getType())->getAddressSpace()) &&
404 "The offset must have exactly as many bits as our pointer.");
413 if (!GEP->isInBounds())
415 APInt GEPOffset(Offset);
416 if (!GEP->accumulateConstantOffset(DL, GEPOffset))
419 V = GEP->getPointerOperand();
421 V = cast<Operator>(V)->getOperand(0);
422 }
else if (
GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
423 V = GA->getAliasee();
428 }
while (Visited.insert(V));
434 return stripPointerCastsAndOffsets<PSK_InBounds>(
this);
449 if (isa<AllocaInst>(V))
return true;
453 return !GV->hasExternalWeakLinkage();
456 if (
const Argument *
A = dyn_cast<Argument>(V))
457 return A->hasByValAttr();
460 if (
const GEPOperator *GEP = dyn_cast<GEPOperator>(V)) {
462 if (!Visited.
insert(GEP->getOperand(0)))
469 E = GEP->op_end();
I != E; ++
I) {
473 if (isa<StructType>(Ty))
526 assert(List &&
"Handle list is null?");
533 Next->setPrevPtr(&Next);
534 assert(VP.getPointer() == Next->VP.getPointer() &&
"Added to wrong list?");
538 void ValueHandleBase::AddToExistingUseListAfter(
ValueHandleBase *List) {
539 assert(List &&
"Must insert after existing node");
542 setPrevPtr(&List->Next);
545 Next->setPrevPtr(&Next);
549 void ValueHandleBase::AddToUseList() {
550 assert(VP.getPointer() &&
"Null pointer doesn't have a use list!");
554 if (VP.getPointer()->HasValueHandle) {
558 assert(Entry != 0 &&
"Value doesn't have any handles?");
559 AddToExistingUseList(&Entry);
572 assert(Entry == 0 &&
"Value really did already have handles?");
573 AddToExistingUseList(&Entry);
574 VP.getPointer()->HasValueHandle =
true;
579 Handles.
size() == 1) {
585 E = Handles.
end();
I != E; ++
I) {
586 assert(
I->second &&
I->first ==
I->second->VP.getPointer() &&
587 "List invariant broken!");
588 I->second->setPrevPtr(&
I->second);
593 void ValueHandleBase::RemoveFromUseList() {
594 assert(VP.getPointer() && VP.getPointer()->HasValueHandle &&
595 "Pointer doesn't have a use list!");
599 assert(*PrevPtr ==
this &&
"List invariant broken");
603 assert(Next->getPrevPtr() == &Next &&
"List invariant broken");
604 Next->setPrevPtr(PrevPtr);
614 Handles.
erase(VP.getPointer());
615 VP.getPointer()->HasValueHandle =
false;
621 assert(V->HasValueHandle &&
"Should only be called if ValueHandles present");
627 assert(Entry &&
"Value bit set but no entries exist");
639 Iterator.RemoveFromUseList();
640 Iterator.AddToExistingUseListAfter(Entry);
641 assert(Entry->Next == &Iterator &&
"Loop invariant broken.");
643 switch (Entry->getKind()) {
663 if (V->HasValueHandle) {
664 #ifndef NDEBUG // Only in +Asserts mode...
678 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
679 assert(Old != New &&
"Changing value into itself!");
686 assert(Entry &&
"Value bit set but no entries exist");
693 Iterator.RemoveFromUseList();
694 Iterator.AddToExistingUseListAfter(Entry);
695 assert(Entry->Next == &Iterator &&
"Loop invariant broken.");
697 switch (Entry->getKind()) {
710 Entry->operator=(New);
714 static_cast<CallbackVH*
>(Entry)->allUsesReplacedWith(New);
722 if (Old->HasValueHandle)
723 for (Entry = pImpl->
ValueHandles[Old]; Entry; Entry = Entry->Next)
724 switch (Entry->getKind()) {
727 dbgs() <<
"After RAUW from " << *Old->
getType() <<
" %"
739 void CallbackVH::anchor() {}
bool isPointerIntoBucketsArray(const void *Ptr) const
static void ValueIsDeleted(Value *V)
Value * stripInBoundsConstantOffsets()
Strips off unneeded pointer casts and all-constant GEPs from the specified value, returning the origi...
LLVM Argument representation.
static bool isDereferenceablePointer(const Value *V, SmallPtrSet< const Value *, 32 > &Visited)
The main container class for the LLVM Intermediate Representation.
void setValue(const ValueTy &V)
bool hasNUses(unsigned N) const
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
StringRef getName() const
static void removeGarbageObject(void *Object)
static Type * checkType(Type *Ty)
const APInt & getValue() const
Return the constant's value.
#define llvm_unreachable(msg)
void setName(const Twine &Name)
Value * stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL, APInt &Offset)
Strips like stripInBoundsConstantOffsets but also accumulates the constant offset stripped...
uint64_t getZExtValue() const
Return the zero extended value.
void Destroy(AllocatorTy &Allocator)
LLVMContext & getContext() const
getContext - Return the LLVMContext in which this type was uniqued.
bool isFirstClassType() const
unsigned getActiveBits() const
Compute the number of active bits in the value.
void replaceAllUsesWith(Value *V)
static void ValueIsRAUWd(Value *Old, Value *New)
const void * getPointerIntoBucketsArray() const
Value * stripPointerCastsNoFollowAliases()
Strips off any unneeded pointer casts and all-zero GEPs from the specified value, returning the origi...
LLVM Basic Block Representation.
LLVM Constant Representation.
Value * stripInBoundsOffsets()
Strips off unneeded pointer casts and any in-bounds offsets from the specified value, returning the original pointer value.
uint64_t getNumElements() const
unsigned getBitWidth() const
Return the number of bits in the APInt.
ValueHandlesTy ValueHandles
IntrinsicIDCacheTy IntrinsicIDCache
LLVMContext & getContext() const
All values hold a context through their type.
bool isUsedInBasicBlock(const BasicBlock *BB) const
LLVMContextImpl *const pImpl
Class for constant integers.
Value * DoPHITranslation(const BasicBlock *CurBB, const BasicBlock *PredBB)
bool erase(const KeyT &Val)
StringRef toStringRef(SmallVectorImpl< char > &Out) const
Value * stripPointerCasts()
Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value...
static StringMapEntry * Create(const char *KeyStart, const char *KeyEnd, AllocatorTy &Allocator, InitType InitVal)
raw_ostream & dbgs()
dbgs - Return a circular-buffered debug stream.
Class for arbitrary precision integers.
Value * getIncomingValueForBlock(const BasicBlock *BB) const
unsigned getOpcode() const
bool isDereferenceablePointer() const
unsigned getPointerSizeInBits(unsigned AS=0) const
static bool getSymTab(Value *V, ValueSymbolTable *&ST)
bool hasNUsesOrMore(unsigned N) const
LLVM Value Representation.
bool isTriviallyEmpty() const
unsigned getNumUses() const
const BasicBlock * getParent() const
bool isVoidTy() const
isVoidTy - Return true if this is 'void'.
bool empty() const
empty - Check if the string is empty.
gep_type_iterator gep_type_begin(const User *GEP)