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)) {
548 BlockAddress::lookup(BB)->handleOperandChange(
this, New);
552void Value::replaceAllUsesWith(
Value *New) {
553 doRAUW(New, ReplaceMetadataUses::Yes);
556void Value::replaceNonMetadataUsesWith(
Value *New) {
557 doRAUW(New, ReplaceMetadataUses::No);
560bool Value::replaceUsesWithIf(
Value *New,
561 llvm::function_ref<
bool(Use &U)> ShouldReplace) {
562 assert(New &&
"Value::replaceUsesWithIf(<null>) is invalid!");
564 "replaceUses of value with new value of different type!");
566 SmallVector<TrackingVH<Constant>, 8> Consts;
567 SmallPtrSet<Constant *, 8> Visited;
571 if (!ShouldReplace(U))
577 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
578 if (!isa<GlobalValue>(
C)) {
587 while (!Consts.
empty()) {
599 SmallVector<DbgVariableRecord *> DPUsers;
601 for (
auto *DVR : DPUsers) {
602 DbgMarker *Marker = DVR->getMarker();
604 DVR->replaceVariableLocationOp(V, New);
610void Value::replaceUsesOutsideBlock(
Value *New, BasicBlock *BB) {
611 assert(New &&
"Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
613 "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
615 "replaceUses of value with new value of different type!");
616 assert(BB &&
"Basic block that may contain a use of 'New' must be defined\n");
619 replaceUsesWithIf(New, [BB](Use &U) {
620 auto *
I = dyn_cast<Instruction>(
U.getUser());
622 return !
I ||
I->getParent() != BB;
628enum PointerStripKind {
630 PSK_ZeroIndicesAndAliases,
631 PSK_ZeroIndicesSameRepresentation,
632 PSK_ForAliasAnalysis,
633 PSK_InBoundsConstantIndices,
640template <Po
interStripKind StripKind>
644 if (!
V->getType()->isPointerTy())
649 SmallPtrSet<const Value *, 4> Visited;
654 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
656 case PSK_ZeroIndices:
657 case PSK_ZeroIndicesAndAliases:
658 case PSK_ZeroIndicesSameRepresentation:
659 case PSK_ForAliasAnalysis:
660 if (!
GEP->hasAllZeroIndices())
663 case PSK_InBoundsConstantIndices:
664 if (!
GEP->hasAllConstantIndices())
668 if (!
GEP->isInBounds())
672 V =
GEP->getPointerOperand();
673 }
else if (Operator::getOpcode(V) == Instruction::BitCast) {
674 Value *NewV = cast<Operator>(V)->getOperand(0);
675 if (!NewV->getType()->isPointerTy())
678 }
else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
679 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
682 V = cast<Operator>(V)->getOperand(0);
683 }
else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
684 V = cast<GlobalAlias>(V)->getAliasee();
685 }
else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
686 cast<PHINode>(V)->getNumIncomingValues() == 1) {
687 V = cast<PHINode>(V)->getIncomingValue(0);
689 if (
const auto *
Call = dyn_cast<CallBase>(V)) {
690 if (
const Value *RV =
Call->getReturnedArgOperand()) {
697 if (StripKind == PSK_ForAliasAnalysis &&
698 (
Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
699 Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
700 V =
Call->getArgOperand(0);
706 assert(
V->getType()->isPointerTy() &&
"Unexpected operand type!");
707 }
while (Visited.
insert(V).second);
712const Value *Value::stripPointerCasts()
const {
716const Value *Value::stripPointerCastsAndAliases()
const {
720const Value *Value::stripPointerCastsSameRepresentation()
const {
724const Value *Value::stripInBoundsConstantOffsets()
const {
728const Value *Value::stripPointerCastsForAliasAnalysis()
const {
732const Value *Value::stripAndAccumulateConstantOffsets(
733 const DataLayout &
DL, APInt &Offset,
bool AllowNonInbounds,
734 bool AllowInvariantGroup,
735 function_ref<
bool(
Value &, APInt &)> ExternalAnalysis,
736 bool LookThroughIntToPtr)
const {
737 if (!
getType()->isPtrOrPtrVectorTy())
742 "The offset bit width does not match the DL specification.");
746 SmallPtrSet<const Value *, 4> Visited;
750 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
752 if (!AllowNonInbounds && !
GEP->isInBounds())
761 APInt GEPOffset(
DL.getIndexTypeSizeInBits(
V->getType()), 0);
762 if (!
GEP->accumulateConstantOffset(
DL, GEPOffset, ExternalAnalysis))
768 if (GEPOffset.getSignificantBits() >
BitWidth)
773 APInt GEPOffsetST = GEPOffset.sextOrTrunc(
BitWidth);
774 if (!ExternalAnalysis) {
777 bool Overflow =
false;
781 Offset = std::move(OldOffset);
785 V =
GEP->getPointerOperand();
786 }
else if (Operator::getOpcode(V) == Instruction::BitCast ||
787 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
788 V = cast<Operator>(V)->getOperand(0);
789 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
790 if (!GA->isInterposable())
791 V = GA->getAliasee();
792 }
else if (
const auto *
Call = dyn_cast<CallBase>(V)) {
793 if (
const Value *RV =
Call->getReturnedArgOperand())
795 if (AllowInvariantGroup &&
Call->isLaunderOrStripInvariantGroup())
796 V =
Call->getArgOperand(0);
797 }
else if (
auto *Int2Ptr = dyn_cast<Operator>(V)) {
799 if (!AllowNonInbounds || !LookThroughIntToPtr || !Int2Ptr ||
800 Int2Ptr->getOpcode() != Instruction::IntToPtr ||
801 Int2Ptr->getOperand(0)->getType()->getScalarSizeInBits() !=
BitWidth)
804 auto *
Add = dyn_cast<AddOperator>(Int2Ptr->getOperand(0));
808 auto *Ptr2Int = dyn_cast<PtrToIntOperator>(
Add->getOperand(0));
809 auto *CI = dyn_cast<ConstantInt>(
Add->getOperand(1));
814 V = Ptr2Int->getOperand(0);
816 assert(
V->getType()->isPtrOrPtrVectorTy() &&
"Unexpected operand type!");
817 }
while (Visited.
insert(V).second);
823Value::stripInBoundsOffsets(function_ref<
void(
const Value *)> Func)
const {
827bool Value::canBeFreed()
const {
832 if (isa<Constant>(
this))
837 if (
auto *
A = dyn_cast<Argument>(
this)) {
838 if (
A->hasPointeeInMemoryValueAttr())
845 if (
F->doesNotFreeMemory())
851 if ((
A->hasNoFreeAttr() ||
A->onlyReadsMemory()) &&
A->hasNoAliasAttr())
855 if (
auto *ITP = dyn_cast<IntToPtrInst>(
this);
856 ITP && ITP->hasMetadata(LLVMContext::MD_nofree))
860 if (
auto *
I = dyn_cast<Instruction>(
this))
861 F =
I->getFunction();
862 if (
auto *
A = dyn_cast<Argument>(
this))
877 const auto &GCName =
F->getGC();
878 if (GCName ==
"statepoint-example") {
879 auto *PT = cast<PointerType>(this->
getType());
880 if (PT->getAddressSpace() != 1)
890 for (
auto &Fn : *
F->getParent())
891 if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
898uint64_t Value::getPointerDereferenceableBytes(
const DataLayout &
DL,
900 bool &CanBeFreed)
const {
903 uint64_t DerefBytes = 0;
906 if (
const Argument *
A = dyn_cast<Argument>(
this)) {
907 DerefBytes =
A->getDereferenceableBytes();
908 if (DerefBytes == 0) {
910 if (
Type *ArgMemTy =
A->getPointeeInMemoryValueType()) {
911 if (ArgMemTy->isSized()) {
913 DerefBytes =
DL.getTypeStoreSize(ArgMemTy).getKnownMinValue();
918 if (DerefBytes == 0) {
919 DerefBytes =
A->getDereferenceableOrNullBytes();
922 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
923 DerefBytes =
Call->getRetDereferenceableBytes();
924 if (DerefBytes == 0) {
925 DerefBytes =
Call->getRetDereferenceableOrNullBytes();
928 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
929 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
930 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
933 if (DerefBytes == 0) {
935 LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
936 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
941 }
else if (
auto *IP = dyn_cast<IntToPtrInst>(
this)) {
942 if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
943 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
946 if (DerefBytes == 0) {
948 IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
949 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
954 }
else if (
auto *AI = dyn_cast<AllocaInst>(
this)) {
955 if (std::optional<TypeSize>
Size = AI->getAllocationSize(
DL)) {
956 DerefBytes =
Size->getKnownMinValue();
960 }
else if (
auto *GV = dyn_cast<GlobalVariable>(
this)) {
964 DerefBytes =
DL.getTypeStoreSize(GV->
getValueType()).getFixedValue();
972Align Value::getPointerAlignment(
const DataLayout &
DL)
const {
974 if (
const Function *
F = dyn_cast<Function>(
this)) {
975 Align FunctionPtrAlign =
DL.getFunctionPtrAlign().valueOrOne();
976 switch (
DL.getFunctionPtrAlignType()) {
977 case DataLayout::FunctionPtrAlignType::Independent:
978 return FunctionPtrAlign;
979 case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
980 return std::max(FunctionPtrAlign,
F->getAlign().valueOrOne());
983 }
else if (
auto *GVar = dyn_cast<GlobalVariable>(
this)) {
984 const MaybeAlign Alignment(GVar->getAlign());
986 Type *ObjectType = GVar->getValueType();
987 if (ObjectType->isSized()) {
991 if (GVar->isStrongDefinitionForLinker())
992 return DL.getPreferredAlign(GVar);
994 return DL.getABITypeAlign(ObjectType);
997 return Alignment.valueOrOne();
998 }
else if (
const Argument *
A = dyn_cast<Argument>(
this)) {
999 const MaybeAlign Alignment =
A->getParamAlign();
1000 if (!Alignment &&
A->hasStructRetAttr()) {
1002 Type *EltTy =
A->getParamStructRetType();
1003 if (EltTy->isSized())
1004 return DL.getABITypeAlign(EltTy);
1007 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
this)) {
1008 return AI->getAlign();
1009 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
1010 MaybeAlign Alignment =
Call->getRetAlign();
1011 if (!Alignment &&
Call->getCalledFunction())
1012 Alignment =
Call->getCalledFunction()->getAttributes().getRetAlignment();
1014 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
1015 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
1016 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
1019 }
else if (
auto *CE = dyn_cast<ConstantExpr>(
this)) {
1021 if (
CE->getOpcode() == Instruction::IntToPtr &&
1022 isa<ConstantInt>(
CE->getOperand(0))) {
1023 ConstantInt *IntPtr = cast<ConstantInt>(
CE->getOperand(0));
1027 return Align(TrailingZeros < Value::MaxAlignmentExponent
1028 ? uint64_t(1) << TrailingZeros
1029 : Value::MaximumAlignment);
1035static std::optional<int64_t>
1039 for (
unsigned i = 1; i != Idx; ++i, ++GTI)
1044 for (
unsigned i = Idx, e =
GEP->getNumOperands(); i != e; ++i, ++GTI) {
1045 ConstantInt *OpC = dyn_cast<ConstantInt>(
GEP->getOperand(i));
1047 return std::nullopt;
1060 if (
Size.isScalable())
1061 return std::nullopt;
1068std::optional<int64_t> Value::getPointerOffsetFrom(
const Value *Other,
1069 const DataLayout &
DL)
const {
1071 const Value *Ptr2 =
this;
1072 APInt Offset1(
DL.getIndexTypeSizeInBits(Ptr1->getType()), 0);
1073 APInt Offset2(
DL.getIndexTypeSizeInBits(Ptr2->getType()), 0);
1074 Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(
DL, Offset1,
true);
1075 Ptr2 = Ptr2->stripAndAccumulateConstantOffsets(
DL, Offset2,
true);
1079 return Offset2.getSExtValue() - Offset1.getSExtValue();
1081 const GEPOperator *GEP1 = dyn_cast<GEPOperator>(Ptr1);
1082 const GEPOperator *GEP2 = dyn_cast<GEPOperator>(Ptr2);
1091 return std::nullopt;
1101 if (!IOffset1 || !IOffset2)
1102 return std::nullopt;
1103 return *IOffset2 - *IOffset1 + Offset2.getSExtValue() -
1104 Offset1.getSExtValue();
1107const Value *Value::DoPHITranslation(
const BasicBlock *CurBB,
1108 const BasicBlock *PredBB)
const {
1109 auto *PN = dyn_cast<PHINode>(
this);
1110 if (PN && PN->getParent() == CurBB)
1111 return PN->getIncomingValueForBlock(PredBB);
1115void Value::reverseUseList() {
1116 if (!UseList || !UseList->Next)
1120 Use *Head = UseList;
1121 Use *Current = UseList->Next;
1122 Head->Next =
nullptr;
1125 Current->Next = Head;
1126 Head->Prev = &Current->Next;
1131 Head->Prev = &UseList;
1134bool Value::isSwiftError()
const {
1135 auto *Arg = dyn_cast<Argument>(
this);
1137 return Arg->hasSwiftErrorAttr();
1138 auto *Alloca = dyn_cast<AllocaInst>(
this);
1141 return Alloca->isSwiftError();
1148void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1149 assert(List &&
"Handle list is null?");
1156 Next->setPrevPtr(&Next);
1157 assert(getValPtr() ==
Next->getValPtr() &&
"Added to wrong list?");
1161void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1162 assert(List &&
"Must insert after existing node");
1165 setPrevPtr(&
List->Next);
1168 Next->setPrevPtr(&Next);
1171void ValueHandleBase::AddToUseList() {
1172 assert(getValPtr() &&
"Null pointer doesn't have a use list!");
1174 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1176 if (getValPtr()->HasValueHandle) {
1180 assert(Entry &&
"Value doesn't have any handles?");
1181 AddToExistingUseList(&Entry);
1190 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1193 ValueHandleBase *&
Entry = Handles[getValPtr()];
1194 assert(!Entry &&
"Value really did already have handles?");
1195 AddToExistingUseList(&Entry);
1196 getValPtr()->HasValueHandle =
true;
1201 Handles.
size() == 1) {
1206 for (
auto I = Handles.
begin(),
E = Handles.
end();
I !=
E; ++
I) {
1207 assert(
I->second &&
I->first ==
I->second->getValPtr() &&
1208 "List invariant broken!");
1209 I->second->setPrevPtr(&
I->second);
1213void ValueHandleBase::RemoveFromUseList() {
1214 assert(getValPtr() && getValPtr()->HasValueHandle &&
1215 "Pointer doesn't have a use list!");
1218 ValueHandleBase **PrevPtr = getPrevPtr();
1219 assert(*PrevPtr ==
this &&
"List invariant broken");
1223 assert(
Next->getPrevPtr() == &Next &&
"List invariant broken");
1224 Next->setPrevPtr(PrevPtr);
1231 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1232 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1235 Handles.
erase(getValPtr(), [](
auto &Bucket) {
1236 Bucket.second->setPrevPtr(&Bucket.second);
1238 getValPtr()->HasValueHandle =
false;
1242void ValueHandleBase::ValueIsDeleted(
Value *V) {
1243 assert(
V->HasValueHandle &&
"Should only be called if ValueHandles present");
1247 LLVMContextImpl *pImpl =
V->getContext().pImpl;
1249 assert(Entry &&
"Value bit set but no entries exist");
1260 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1261 Iterator.RemoveFromUseList();
1262 Iterator.AddToExistingUseListAfter(Entry);
1263 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1265 switch (
Entry->getKind()) {
1272 Entry->operator=(
nullptr);
1276 static_cast<CallbackVH*
>(
Entry)->deleted();
1282 if (
V->HasValueHandle) {
1284 dbgs() <<
"While deleting: " << *
V->getType() <<
" %" <<
V->getName()
1295void ValueHandleBase::ValueIsRAUWd(
Value *Old,
Value *New) {
1296 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
1297 assert(Old != New &&
"Changing value into itself!");
1298 assert(Old->getType() ==
New->getType() &&
1299 "replaceAllUses of value with new value of different type!");
1303 LLVMContextImpl *pImpl = Old->getContext().pImpl;
1306 assert(Entry &&
"Value bit set but no entries exist");
1312 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1313 Iterator.RemoveFromUseList();
1314 Iterator.AddToExistingUseListAfter(Entry);
1315 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1317 switch (
Entry->getKind()) {
1328 static_cast<CallbackVH*
>(
Entry)->allUsesReplacedWith(New);
1336 if (Old->HasValueHandle)
1338 switch (
Entry->getKind()) {
1340 dbgs() <<
"After RAUW from " << *Old->getType() <<
" %"
1341 << Old->getName() <<
" to " << *
New->getType() <<
" %"
1342 <<
New->getName() <<
"\n";
1344 "A weak tracking value handle still pointed to the old value!\n");
1352void 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.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
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
Return true if the specified pointer points somewhere into the DenseMap's array of buckets (i....
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
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)
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.