41 cl::desc(
"Deref attributes and metadata infer facts at definition only"));
47 assert(Ty &&
"Value defined with a null type: Error!");
49 "Cannot have values with typed pointer types");
54 : SubclassID(scid), HasValueHandle(0), SubclassOptionalData(0),
55 SubclassData(0), NumUserOperands(0), IsUsedByMD(
false), HasName(
false),
57 static_assert(ConstantFirstVal == 0,
"!(SubclassID < ConstantFirstVal)");
62 if (SubclassID >= InstructionVal)
63 OpCode = SubclassID - InstructionVal;
64 if (OpCode == Instruction::Call || OpCode == Instruction::Invoke ||
65 OpCode == Instruction::CallBr)
66 assert((VTy->isFirstClassType() || VTy->isVoidTy() || VTy->isStructTy()) &&
67 "invalid CallBase type!");
68 else if (SubclassID != BasicBlockVal &&
69 ( SubclassID > ConstantLastVal))
70 assert((VTy->isFirstClassType() || VTy->isVoidTy()) &&
71 "Cannot create non-first-class values except for constants!");
72 static_assert(
sizeof(Value) == 2 *
sizeof(
void *) + 2 *
sizeof(
unsigned),
79 ValueHandleBase::ValueIsDeleted(
this);
80 if (isUsedByMetadata())
81 ValueAsMetadata::handleDeletion(
this);
93 if (!materialized_use_empty()) {
94 dbgs() <<
"While deleting: " << *VTy <<
" %" <<
getName() <<
"\n";
95 for (
auto *U :
users())
96 dbgs() <<
"Use still stuck around after Def is destroyed:" << *
U <<
"\n";
107void Value::deleteValue() {
108 switch (getValueID()) {
109#define HANDLE_VALUE(Name) \
110 case Value::Name##Val: \
111 delete static_cast<Name *>(this); \
113#define HANDLE_MEMORY_VALUE(Name) \
114 case Value::Name##Val: \
115 static_cast<DerivedUser *>(this)->DeleteValue( \
116 static_cast<DerivedUser *>(this)); \
118#define HANDLE_CONSTANT(Name) \
119 case Value::Name##Val: \
120 llvm_unreachable("constants should be destroyed with destroyConstant"); \
122#define HANDLE_INSTRUCTION(Name)
123#include "llvm/IR/Value.def"
125#define HANDLE_INST(N, OPC, CLASS) \
126 case Value::InstructionVal + Instruction::OPC: \
127 delete static_cast<CLASS *>(this); \
129#define HANDLE_USER_INST(N, OPC, CLASS)
130#include "llvm/IR/Instruction.def"
137void Value::destroyValueName() {
143 setValueName(
nullptr);
146bool Value::hasNUses(
unsigned N)
const {
154bool Value::hasNUsesOrMore(
unsigned N)
const {
162bool Value::hasOneUser()
const {
167 return std::equal(++user_begin(), user_end(), user_begin());
172Use *Value::getSingleUndroppableUse() {
174 for (Use &U : uses()) {
175 if (!
U.getUser()->isDroppable()) {
184User *Value::getUniqueUndroppableUser() {
186 for (
auto *U :
users()) {
187 if (!
U->isDroppable()) {
188 if (Result && Result != U)
196bool Value::hasNUndroppableUses(
unsigned int N)
const {
200bool Value::hasNUndroppableUsesOrMore(
unsigned int N)
const {
204void Value::dropDroppableUses(
205 llvm::function_ref<
bool(
const Use *)> ShouldDrop) {
206 SmallVector<Use *, 8> ToBeEdited;
207 for (Use &U : uses())
208 if (
U.getUser()->isDroppable() && ShouldDrop(&U))
210 for (Use *U : ToBeEdited)
211 dropDroppableUse(*U);
214void Value::dropDroppableUsesIn(User &Usr) {
217 if (UsrOp.get() ==
this)
218 dropDroppableUse(UsrOp);
222void Value::dropDroppableUse(Use &U) {
223 if (
auto *Assume = dyn_cast<AssumeInst>(
U.getUser())) {
224 unsigned OpNo =
U.getOperandNo();
226 U.set(ConstantInt::getTrue(
Assume->getContext()));
228 U.set(PoisonValue::get(
U.get()->getType()));
229 CallInst::BundleOpInfo &BOI =
Assume->getBundleOpInfoForOperand(OpNo);
230 BOI.
Tag =
Assume->getContext().pImpl->getOrInsertBundleTag(
"ignore");
238bool Value::isUsedInBasicBlock(
const BasicBlock *BB)
const {
239 assert(hasUseList() &&
"ConstantData has no use-list");
247 BasicBlock::const_iterator BI = BB->
begin(), BE = BB->
end();
248 const_user_iterator UI = user_begin(), UE = user_end();
249 for (; BI != BE && UI != UE; ++BI, ++UI) {
254 const auto *
User = dyn_cast<Instruction>(*UI);
255 if (User &&
User->getParent() == BB)
261unsigned Value::getNumUses()
const {
265 return (
unsigned)std::distance(use_begin(), use_end());
270 if (Instruction *
I = dyn_cast<Instruction>(V)) {
271 if (BasicBlock *
P =
I->getParent())
272 if (Function *PP =
P->getParent())
273 ST = PP->getValueSymbolTable();
274 }
else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
276 ST =
P->getValueSymbolTable();
277 }
else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
278 if (
Module *
P = GV->getParent())
279 ST = &
P->getValueSymbolTable();
280 }
else if (Argument *
A = dyn_cast<Argument>(V)) {
281 if (Function *
P =
A->getParent())
282 ST =
P->getValueSymbolTable();
284 assert(isa<Constant>(V) &&
"Unknown value type!");
291 if (!HasName)
return nullptr;
296 "No name entry found!");
301void Value::setValueName(ValueName *VN) {
305 "HasName bit out of sync!");
318StringRef Value::getName()
const {
323 return StringRef(
"", 0);
324 return getValueName()->getKey();
327void Value::setNameImpl(
const Twine &NewName) {
329 !
getContext().shouldDiscardValueNames() || isa<GlobalValue>(
this);
333 if (!NeedNewName && !hasName())
340 SmallString<256> NameData;
341 StringRef NameRef = NeedNewName ? NewName.
toStringRef(NameData) :
"";
342 assert(!NameRef.
contains(0) &&
"Null bytes are not allowed in names");
348 assert(!
getType()->isVoidTy() &&
"Cannot assign a name to void values!");
351 ValueSymbolTable *
ST;
357 if (!NameRef.
empty()) {
368 setValueName(NewValueName);
369 getValueName()->setValue(
this);
374 if (!NameRef.
empty())
375 NewValueName =
ST->createValueName(NameRef,
this);
381 ST->removeValueName(getValueName());
389 assert(NeedNewName && NewValueName !=
nullptr);
390 setValueName(NewValueName);
393void Value::setName(
const Twine &NewName) {
394 setNameImpl(NewName);
395 if (Function *
F = dyn_cast<Function>(
this))
396 F->updateAfterNameChange();
399void Value::takeName(
Value *V) {
400 assert(V !=
this &&
"Illegal call to this->takeName(this)!");
401 ValueSymbolTable *
ST =
nullptr;
408 if (
V->hasName())
V->setName(
"");
414 ST->removeValueName(getValueName());
421 if (!
V->hasName())
return;
433 ValueSymbolTable *VST;
435 assert(!Failure &&
"V has a name, so it should have a ST!"); (void)Failure;
441 setValueName(
V->getValueName());
442 V->setValueName(
nullptr);
443 getValueName()->setValue(
this);
451 VST->removeValueName(
V->getValueName());
452 setValueName(
V->getValueName());
453 V->setValueName(
nullptr);
454 getValueName()->setValue(
this);
457 ST->reinsertValue(
this);
460std::string Value::getNameOrAsOperand()
const {
465 raw_string_ostream OS(BBName);
466 printAsOperand(OS,
false);
470void Value::assertModuleIsMaterializedImpl()
const {
472 const GlobalValue *GV = dyn_cast<GlobalValue>(
this);
483static bool contains(SmallPtrSetImpl<ConstantExpr *> &Cache, ConstantExpr *Expr,
485 if (!Cache.
insert(Expr).second)
491 auto *
CE = dyn_cast<ConstantExpr>(O);
504 auto *
C = dyn_cast<Constant>(V);
508 auto *
CE = dyn_cast<ConstantExpr>(Expr);
512 SmallPtrSet<ConstantExpr *, 4> Cache;
517void Value::doRAUW(
Value *New, ReplaceMetadataUses ReplaceMetaUses) {
518 assert(hasUseList() &&
"Cannot replace constant data");
519 assert(New &&
"Value::replaceAllUsesWith(<null>) is invalid!");
521 "this->replaceAllUsesWith(expr(this)) is NOT valid!");
523 "replaceAllUses of value with new value of different type!");
527 ValueHandleBase::ValueIsRAUWd(
this, New);
528 if (ReplaceMetaUses == ReplaceMetadataUses::Yes && isUsedByMetadata())
529 ValueAsMetadata::handleRAUW(
this, New);
531 while (!materialized_use_empty()) {
535 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
536 if (!isa<GlobalValue>(
C)) {
537 C->handleOperandChange(
this, New);
545 if (BasicBlock *BB = dyn_cast<BasicBlock>(
this))
549void Value::replaceAllUsesWith(
Value *New) {
550 doRAUW(New, ReplaceMetadataUses::Yes);
553void Value::replaceNonMetadataUsesWith(
Value *New) {
554 doRAUW(New, ReplaceMetadataUses::No);
557bool Value::replaceUsesWithIf(
Value *New,
558 llvm::function_ref<
bool(Use &U)> ShouldReplace) {
559 assert(New &&
"Value::replaceUsesWithIf(<null>) is invalid!");
561 "replaceUses of value with new value of different type!");
563 SmallVector<TrackingVH<Constant>, 8> Consts;
564 SmallPtrSet<Constant *, 8> Visited;
568 if (!ShouldReplace(U))
574 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
575 if (!isa<GlobalValue>(
C)) {
584 while (!Consts.
empty()) {
596 SmallVector<DbgVariableRecord *> DPUsers;
598 for (
auto *DVR : DPUsers) {
599 DbgMarker *Marker = DVR->getMarker();
601 DVR->replaceVariableLocationOp(V, New);
607void Value::replaceUsesOutsideBlock(
Value *New, BasicBlock *BB) {
608 assert(New &&
"Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
610 "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
612 "replaceUses of value with new value of different type!");
613 assert(BB &&
"Basic block that may contain a use of 'New' must be defined\n");
616 replaceUsesWithIf(New, [BB](Use &U) {
617 auto *
I = dyn_cast<Instruction>(
U.getUser());
619 return !
I ||
I->getParent() != BB;
625enum PointerStripKind {
627 PSK_ZeroIndicesAndAliases,
628 PSK_ZeroIndicesSameRepresentation,
629 PSK_ForAliasAnalysis,
630 PSK_InBoundsConstantIndices,
637template <Po
interStripKind StripKind>
641 if (!
V->getType()->isPointerTy())
646 SmallPtrSet<const Value *, 4> Visited;
651 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
653 case PSK_ZeroIndices:
654 case PSK_ZeroIndicesAndAliases:
655 case PSK_ZeroIndicesSameRepresentation:
656 case PSK_ForAliasAnalysis:
657 if (!
GEP->hasAllZeroIndices())
660 case PSK_InBoundsConstantIndices:
661 if (!
GEP->hasAllConstantIndices())
665 if (!
GEP->isInBounds())
669 V =
GEP->getPointerOperand();
670 }
else if (Operator::getOpcode(V) == Instruction::BitCast) {
671 Value *NewV = cast<Operator>(V)->getOperand(0);
672 if (!NewV->getType()->isPointerTy())
675 }
else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
676 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
679 V = cast<Operator>(V)->getOperand(0);
680 }
else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
681 V = cast<GlobalAlias>(V)->getAliasee();
682 }
else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
683 cast<PHINode>(V)->getNumIncomingValues() == 1) {
684 V = cast<PHINode>(V)->getIncomingValue(0);
686 if (
const auto *
Call = dyn_cast<CallBase>(V)) {
687 if (
const Value *RV =
Call->getReturnedArgOperand()) {
694 if (StripKind == PSK_ForAliasAnalysis &&
695 (
Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
696 Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
697 V =
Call->getArgOperand(0);
703 assert(
V->getType()->isPointerTy() &&
"Unexpected operand type!");
704 }
while (Visited.
insert(V).second);
709const Value *Value::stripPointerCasts()
const {
713const Value *Value::stripPointerCastsAndAliases()
const {
717const Value *Value::stripPointerCastsSameRepresentation()
const {
721const Value *Value::stripInBoundsConstantOffsets()
const {
725const Value *Value::stripPointerCastsForAliasAnalysis()
const {
729const Value *Value::stripAndAccumulateConstantOffsets(
730 const DataLayout &
DL, APInt &Offset,
bool AllowNonInbounds,
731 bool AllowInvariantGroup,
732 function_ref<
bool(
Value &, APInt &)> ExternalAnalysis,
733 bool LookThroughIntToPtr)
const {
734 if (!
getType()->isPtrOrPtrVectorTy())
739 "The offset bit width does not match the DL specification.");
743 SmallPtrSet<const Value *, 4> Visited;
747 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
749 if (!AllowNonInbounds && !
GEP->isInBounds())
758 APInt GEPOffset(
DL.getIndexTypeSizeInBits(
V->getType()), 0);
759 if (!
GEP->accumulateConstantOffset(
DL, GEPOffset, ExternalAnalysis))
765 if (GEPOffset.getSignificantBits() >
BitWidth)
770 APInt GEPOffsetST = GEPOffset.sextOrTrunc(
BitWidth);
771 if (!ExternalAnalysis) {
774 bool Overflow =
false;
778 Offset = std::move(OldOffset);
782 V =
GEP->getPointerOperand();
783 }
else if (Operator::getOpcode(V) == Instruction::BitCast ||
784 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
785 V = cast<Operator>(V)->getOperand(0);
786 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
787 if (!GA->isInterposable())
788 V = GA->getAliasee();
789 }
else if (
const auto *
Call = dyn_cast<CallBase>(V)) {
790 if (
const Value *RV =
Call->getReturnedArgOperand())
792 if (AllowInvariantGroup &&
Call->isLaunderOrStripInvariantGroup())
793 V =
Call->getArgOperand(0);
794 }
else if (
auto *Int2Ptr = dyn_cast<Operator>(V)) {
796 if (!AllowNonInbounds || !LookThroughIntToPtr || !Int2Ptr ||
797 Int2Ptr->getOpcode() != Instruction::IntToPtr ||
798 Int2Ptr->getOperand(0)->getType()->getScalarSizeInBits() !=
BitWidth)
801 auto *
Add = dyn_cast<AddOperator>(Int2Ptr->getOperand(0));
805 auto *Ptr2Int = dyn_cast<PtrToIntOperator>(
Add->getOperand(0));
806 auto *CI = dyn_cast<ConstantInt>(
Add->getOperand(1));
811 V = Ptr2Int->getOperand(0);
813 assert(
V->getType()->isPtrOrPtrVectorTy() &&
"Unexpected operand type!");
814 }
while (Visited.
insert(V).second);
820Value::stripInBoundsOffsets(function_ref<
void(
const Value *)> Func)
const {
824bool Value::canBeFreed()
const {
829 if (isa<Constant>(
this))
834 if (
auto *
A = dyn_cast<Argument>(
this)) {
835 if (
A->hasPointeeInMemoryValueAttr())
843 if (
F->doesNotFreeMemory() &&
F->hasNoSync())
847 if (
auto *ITP = dyn_cast<IntToPtrInst>(
this);
848 ITP && ITP->hasMetadata(LLVMContext::MD_nofree))
852 if (
auto *
I = dyn_cast<Instruction>(
this))
853 F =
I->getFunction();
854 if (
auto *
A = dyn_cast<Argument>(
this))
869 const auto &GCName =
F->getGC();
870 if (GCName ==
"statepoint-example") {
871 auto *PT = cast<PointerType>(this->
getType());
872 if (PT->getAddressSpace() != 1)
882 for (
auto &Fn : *
F->getParent())
883 if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
890uint64_t Value::getPointerDereferenceableBytes(
const DataLayout &
DL,
892 bool &CanBeFreed)
const {
895 uint64_t DerefBytes = 0;
898 if (
const Argument *
A = dyn_cast<Argument>(
this)) {
899 DerefBytes =
A->getDereferenceableBytes();
900 if (DerefBytes == 0) {
902 if (
Type *ArgMemTy =
A->getPointeeInMemoryValueType()) {
903 if (ArgMemTy->isSized()) {
905 DerefBytes =
DL.getTypeStoreSize(ArgMemTy).getKnownMinValue();
910 if (DerefBytes == 0) {
911 DerefBytes =
A->getDereferenceableOrNullBytes();
914 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
915 DerefBytes =
Call->getRetDereferenceableBytes();
916 if (DerefBytes == 0) {
917 DerefBytes =
Call->getRetDereferenceableOrNullBytes();
920 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
921 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
922 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
925 if (DerefBytes == 0) {
927 LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
928 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
933 }
else if (
auto *IP = dyn_cast<IntToPtrInst>(
this)) {
934 if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
935 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
938 if (DerefBytes == 0) {
940 IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
941 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
946 }
else if (
auto *AI = dyn_cast<AllocaInst>(
this)) {
947 if (std::optional<TypeSize>
Size = AI->getAllocationSize(
DL)) {
948 DerefBytes =
Size->getKnownMinValue();
952 }
else if (
auto *GV = dyn_cast<GlobalVariable>(
this)) {
956 DerefBytes =
DL.getTypeStoreSize(GV->
getValueType()).getFixedValue();
964Align Value::getPointerAlignment(
const DataLayout &
DL)
const {
966 if (
const Function *
F = dyn_cast<Function>(
this)) {
967 Align FunctionPtrAlign =
DL.getFunctionPtrAlign().valueOrOne();
968 switch (
DL.getFunctionPtrAlignType()) {
969 case DataLayout::FunctionPtrAlignType::Independent:
970 return FunctionPtrAlign;
971 case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
972 return std::max(FunctionPtrAlign,
F->getAlign().valueOrOne());
975 }
else if (
auto *GVar = dyn_cast<GlobalVariable>(
this)) {
976 const MaybeAlign Alignment(GVar->getAlign());
978 Type *ObjectType = GVar->getValueType();
979 if (ObjectType->isSized()) {
983 if (GVar->isStrongDefinitionForLinker())
984 return DL.getPreferredAlign(GVar);
986 return DL.getABITypeAlign(ObjectType);
989 return Alignment.valueOrOne();
990 }
else if (
const Argument *
A = dyn_cast<Argument>(
this)) {
991 const MaybeAlign Alignment =
A->getParamAlign();
992 if (!Alignment &&
A->hasStructRetAttr()) {
994 Type *EltTy =
A->getParamStructRetType();
995 if (EltTy->isSized())
996 return DL.getABITypeAlign(EltTy);
999 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
this)) {
1000 return AI->getAlign();
1001 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
1002 MaybeAlign Alignment =
Call->getRetAlign();
1003 if (!Alignment &&
Call->getCalledFunction())
1004 Alignment =
Call->getCalledFunction()->getAttributes().getRetAlignment();
1006 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
1007 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
1008 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
1011 }
else if (
auto *CE = dyn_cast<ConstantExpr>(
this)) {
1013 if (
CE->getOpcode() == Instruction::IntToPtr &&
1014 isa<ConstantInt>(
CE->getOperand(0))) {
1015 ConstantInt *IntPtr = cast<ConstantInt>(
CE->getOperand(0));
1019 return Align(TrailingZeros < Value::MaxAlignmentExponent
1020 ? uint64_t(1) << TrailingZeros
1021 : Value::MaximumAlignment);
1027static std::optional<int64_t>
1031 for (
unsigned i = 1; i != Idx; ++i, ++GTI)
1036 for (
unsigned i = Idx, e =
GEP->getNumOperands(); i != e; ++i, ++GTI) {
1037 ConstantInt *OpC = dyn_cast<ConstantInt>(
GEP->getOperand(i));
1039 return std::nullopt;
1052 if (
Size.isScalable())
1053 return std::nullopt;
1060std::optional<int64_t> Value::getPointerOffsetFrom(
const Value *Other,
1061 const DataLayout &
DL)
const {
1063 const Value *Ptr2 =
this;
1064 APInt Offset1(
DL.getIndexTypeSizeInBits(Ptr1->getType()), 0);
1065 APInt Offset2(
DL.getIndexTypeSizeInBits(Ptr2->getType()), 0);
1066 Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(
DL, Offset1,
true);
1067 Ptr2 = Ptr2->stripAndAccumulateConstantOffsets(
DL, Offset2,
true);
1071 return Offset2.getSExtValue() - Offset1.getSExtValue();
1073 const GEPOperator *GEP1 = dyn_cast<GEPOperator>(Ptr1);
1074 const GEPOperator *GEP2 = dyn_cast<GEPOperator>(Ptr2);
1083 return std::nullopt;
1093 if (!IOffset1 || !IOffset2)
1094 return std::nullopt;
1095 return *IOffset2 - *IOffset1 + Offset2.getSExtValue() -
1096 Offset1.getSExtValue();
1099const Value *Value::DoPHITranslation(
const BasicBlock *CurBB,
1100 const BasicBlock *PredBB)
const {
1101 auto *PN = dyn_cast<PHINode>(
this);
1102 if (PN && PN->getParent() == CurBB)
1103 return PN->getIncomingValueForBlock(PredBB);
1107void Value::reverseUseList() {
1108 if (!UseList || !UseList->Next)
1112 Use *Head = UseList;
1113 Use *Current = UseList->Next;
1114 Head->Next =
nullptr;
1117 Current->Next = Head;
1118 Head->Prev = &Current->Next;
1123 Head->Prev = &UseList;
1126bool Value::isSwiftError()
const {
1127 auto *Arg = dyn_cast<Argument>(
this);
1129 return Arg->hasSwiftErrorAttr();
1130 auto *Alloca = dyn_cast<AllocaInst>(
this);
1133 return Alloca->isSwiftError();
1140void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1141 assert(List &&
"Handle list is null?");
1148 Next->setPrevPtr(&Next);
1149 assert(getValPtr() ==
Next->getValPtr() &&
"Added to wrong list?");
1153void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1154 assert(List &&
"Must insert after existing node");
1157 setPrevPtr(&
List->Next);
1160 Next->setPrevPtr(&Next);
1163void ValueHandleBase::AddToUseList() {
1164 assert(getValPtr() &&
"Null pointer doesn't have a use list!");
1166 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1168 if (getValPtr()->HasValueHandle) {
1172 assert(Entry &&
"Value doesn't have any handles?");
1173 AddToExistingUseList(&Entry);
1182 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1185 ValueHandleBase *&
Entry = Handles[getValPtr()];
1186 assert(!Entry &&
"Value really did already have handles?");
1187 AddToExistingUseList(&Entry);
1188 getValPtr()->HasValueHandle =
true;
1193 Handles.
size() == 1) {
1198 for (DenseMap<Value*, ValueHandleBase*>::iterator
I = Handles.
begin(),
1199 E = Handles.
end();
I !=
E; ++
I) {
1200 assert(
I->second &&
I->first ==
I->second->getValPtr() &&
1201 "List invariant broken!");
1202 I->second->setPrevPtr(&
I->second);
1206void ValueHandleBase::RemoveFromUseList() {
1207 assert(getValPtr() && getValPtr()->HasValueHandle &&
1208 "Pointer doesn't have a use list!");
1211 ValueHandleBase **PrevPtr = getPrevPtr();
1212 assert(*PrevPtr ==
this &&
"List invariant broken");
1216 assert(
Next->getPrevPtr() == &Next &&
"List invariant broken");
1217 Next->setPrevPtr(PrevPtr);
1224 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1225 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1227 Handles.
erase(getValPtr());
1228 getValPtr()->HasValueHandle =
false;
1232void ValueHandleBase::ValueIsDeleted(
Value *V) {
1233 assert(
V->HasValueHandle &&
"Should only be called if ValueHandles present");
1237 LLVMContextImpl *pImpl =
V->getContext().pImpl;
1239 assert(Entry &&
"Value bit set but no entries exist");
1250 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1251 Iterator.RemoveFromUseList();
1252 Iterator.AddToExistingUseListAfter(Entry);
1253 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1255 switch (
Entry->getKind()) {
1262 Entry->operator=(
nullptr);
1266 static_cast<CallbackVH*
>(
Entry)->deleted();
1272 if (
V->HasValueHandle) {
1274 dbgs() <<
"While deleting: " << *
V->getType() <<
" %" <<
V->getName()
1285void ValueHandleBase::ValueIsRAUWd(
Value *Old,
Value *New) {
1286 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
1287 assert(Old != New &&
"Changing value into itself!");
1288 assert(Old->getType() ==
New->getType() &&
1289 "replaceAllUses of value with new value of different type!");
1293 LLVMContextImpl *pImpl = Old->getContext().pImpl;
1296 assert(Entry &&
"Value bit set but no entries exist");
1302 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1303 Iterator.RemoveFromUseList();
1304 Iterator.AddToExistingUseListAfter(Entry);
1305 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1307 switch (
Entry->getKind()) {
1318 static_cast<CallbackVH*
>(
Entry)->allUsesReplacedWith(New);
1326 if (Old->HasValueHandle)
1328 switch (
Entry->getKind()) {
1330 dbgs() <<
"After RAUW from " << *Old->getType() <<
" %"
1331 << Old->getName() <<
" to " << *
New->getType() <<
" %"
1332 <<
New->getName() <<
"\n";
1334 "A weak tracking value handle still pointed to the old value!\n");
1342void CallbackVH::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
static StringRef getName(Value *V)
static std::optional< int64_t > getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL)
static void NoopCallback(const Value *)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
static cl::opt< bool > UseDerefAtPointSemantics("use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false), cl::desc("Deref attributes and metadata infer facts at definition only"))
static Type * checkType(Type *Ty)
static bool getSymTab(Value *V, ValueSymbolTable *&ST)
static const Value * stripPointerCastsAndOffsets(const Value *V, function_ref< void(const Value *)> Func=NoopCallback< StripKind >)
static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB)
Replace debug record uses of MetadataAsValue(ValueAsMetadata(V)) outside BB with New.
static bool isUnDroppableUser(const User *U)
This file defines the SmallString class.
static SymbolRef::Type getType(const Symbol *Sym)
unsigned countr_zero() const
Count the number of trailing zero bits.
LLVM_ABI void replaceSuccessorsPhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block's successors to refer to basic block New instead of basic bl...
iterator begin()
Instruction iterator methods.
const Function * getParent() const
Return the enclosing method, or null if none.
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
LLVM_ABI const BasicBlock * getParent() const
bool erase(const KeyT &Val)
bool isPointerIntoBucketsArray(const void *Ptr) const
isPointerIntoBucketsArray - Return true if the specified pointer points somewhere into the DenseMap's...
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
LLVM_ABI Type * getSourceElementType() const
bool hasExternalWeakLinkage() const
Module * getParent()
Get the module that this global value is contained inside of...
Type * getValueType() const
DenseMap< const Value *, ValueName * > ValueNames
ValueHandlesTy ValueHandles
LLVMContextImpl *const pImpl
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void push_back(const T &Elt)
static StringMapEntry * create(StringRef key, AllocatorTy &allocator, InitTy &&...initVals)
constexpr bool empty() const
empty - Check if the string is empty.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
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 isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LLVM_ABI bool isDroppable() const
A droppable user is a user for which uses can be dropped without affecting correctness and should be ...
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM_ABI Value(Type *Ty, unsigned scid)
LLVM_ABI ~Value()
Value's destructor should be virtual by design, but that would require that Value and all of its subc...
StructType * getStructTypeOrNull() const
TypeSize getSequentialElementStride(const DataLayout &DL) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ CE
Windows NT (Windows on ARM)
initializer< Ty > init(const Ty &Val)
@ Assume
Do not drop type tests (default).
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
NodeAddr< FuncNode * > Func
Context & getContext() const
This is an optimization pass for GlobalISel generic memory operations.
StringMapEntry< Value * > ValueName
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool hasNItemsOrMore(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has N or more items.
bool hasNItems(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has exactly N items.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isPointerTy(const Type *T)
generic_gep_type_iterator<> gep_type_iterator
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
FunctionAddr VTableAddr Next
gep_type_iterator gep_type_begin(const User *GEP)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI void findDbgUsers(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the debug info records describing a value.
StringMapEntry< uint32_t > * Tag
The operand bundle tag, interned by LLVMContextImpl::getOrInsertBundleTag.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.