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);
97 if (!materialized_use_empty()) {
98 dbgs() <<
"While deleting: " << *VTy <<
" %" <<
getName() <<
"\n";
99 for (
auto *U :
users())
100 dbgs() <<
"Use still stuck around after Def is destroyed:" << *
U <<
"\n";
111void Value::deleteValue() {
112 switch (getValueID()) {
113#define HANDLE_VALUE(Name) \
114 case Value::Name##Val: \
115 delete static_cast<Name *>(this); \
117#define HANDLE_MEMORY_VALUE(Name) \
118 case Value::Name##Val: \
119 static_cast<DerivedUser *>(this)->DeleteValue( \
120 static_cast<DerivedUser *>(this)); \
122#define HANDLE_CONSTANT(Name) \
123 case Value::Name##Val: \
124 llvm_unreachable("constants should be destroyed with destroyConstant"); \
126#define HANDLE_INSTRUCTION(Name)
127#include "llvm/IR/Value.def"
129#define HANDLE_INST(N, OPC, CLASS) \
130 case Value::InstructionVal + Instruction::OPC: \
131 delete static_cast<CLASS *>(this); \
133#define HANDLE_USER_INST(N, OPC, CLASS)
134#include "llvm/IR/Instruction.def"
141void Value::destroyValueName() {
147 setValueName(
nullptr);
150bool Value::hasNUses(
unsigned N)
const {
158bool Value::hasNUsesOrMore(
unsigned N)
const {
166bool Value::hasOneUser()
const {
171 return std::equal(++user_begin(), user_end(), user_begin());
176Use *Value::getSingleUndroppableUse() {
178 for (Use &U : uses()) {
179 if (!
U.getUser()->isDroppable()) {
188User *Value::getUniqueUndroppableUser() {
190 for (
auto *U :
users()) {
191 if (!
U->isDroppable()) {
192 if (Result && Result != U)
200bool Value::hasNUndroppableUses(
unsigned int N)
const {
204bool Value::hasNUndroppableUsesOrMore(
unsigned int N)
const {
208void Value::dropDroppableUses(
209 llvm::function_ref<
bool(
const Use *)> ShouldDrop) {
210 SmallVector<Use *, 8> ToBeEdited;
211 for (Use &U : uses())
212 if (
U.getUser()->isDroppable() && ShouldDrop(&U))
214 for (Use *U : ToBeEdited)
215 dropDroppableUse(*U);
218void Value::dropDroppableUsesIn(User &Usr) {
221 if (UsrOp.get() ==
this)
222 dropDroppableUse(UsrOp);
226void Value::dropDroppableUse(Use &U) {
227 if (
auto *Assume = dyn_cast<AssumeInst>(
U.getUser())) {
228 unsigned OpNo =
U.getOperandNo();
230 U.set(ConstantInt::getTrue(
Assume->getContext()));
232 U.set(PoisonValue::get(
U.get()->getType()));
233 CallInst::BundleOpInfo &BOI =
Assume->getBundleOpInfoForOperand(OpNo);
234 BOI.
Tag =
Assume->getContext().pImpl->getOrInsertBundleTag(
"ignore");
242bool Value::isUsedInBasicBlock(
const BasicBlock *BB)
const {
243 assert(hasUseList() &&
"ConstantData has no use-list");
251 BasicBlock::const_iterator BI = BB->
begin(), BE = BB->
end();
252 const_user_iterator UI = user_begin(), UE = user_end();
253 for (; BI != BE && UI != UE; ++BI, ++UI) {
258 const auto *
User = dyn_cast<Instruction>(*UI);
259 if (User &&
User->getParent() == BB)
265unsigned Value::getNumUses()
const {
269 return (
unsigned)std::distance(use_begin(), use_end());
274 if (Instruction *
I = dyn_cast<Instruction>(V)) {
275 if (BasicBlock *
P =
I->getParent())
276 if (Function *PP =
P->getParent())
277 ST = PP->getValueSymbolTable();
278 }
else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
280 ST =
P->getValueSymbolTable();
281 }
else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
282 if (
Module *
P = GV->getParent())
283 ST = &
P->getValueSymbolTable();
284 }
else if (Argument *
A = dyn_cast<Argument>(V)) {
285 if (Function *
P =
A->getParent())
286 ST =
P->getValueSymbolTable();
288 assert(isa<Constant>(V) &&
"Unknown value type!");
295 if (!HasName)
return nullptr;
300 "No name entry found!");
305void Value::setValueName(ValueName *VN) {
309 "HasName bit out of sync!");
322StringRef Value::getName()
const {
327 return StringRef(
"", 0);
328 return getValueName()->getKey();
331void Value::setNameImpl(
const Twine &NewName) {
333 !
getContext().shouldDiscardValueNames() || isa<GlobalValue>(
this);
337 if (!NeedNewName && !hasName())
344 SmallString<256> NameData;
345 StringRef NameRef = NeedNewName ? NewName.
toStringRef(NameData) :
"";
346 assert(!NameRef.
contains(0) &&
"Null bytes are not allowed in names");
352 assert(!
getType()->isVoidTy() &&
"Cannot assign a name to void values!");
355 ValueSymbolTable *
ST;
361 if (!NameRef.
empty()) {
372 setValueName(NewValueName);
373 getValueName()->setValue(
this);
378 if (!NameRef.
empty())
379 NewValueName =
ST->createValueName(NameRef,
this);
385 ST->removeValueName(getValueName());
393 assert(NeedNewName && NewValueName !=
nullptr);
394 setValueName(NewValueName);
397void Value::setName(
const Twine &NewName) {
398 setNameImpl(NewName);
399 if (Function *
F = dyn_cast<Function>(
this))
400 F->updateAfterNameChange();
403void Value::takeName(
Value *V) {
404 assert(V !=
this &&
"Illegal call to this->takeName(this)!");
405 ValueSymbolTable *
ST =
nullptr;
412 if (
V->hasName())
V->setName(
"");
418 ST->removeValueName(getValueName());
425 if (!
V->hasName())
return;
437 ValueSymbolTable *VST;
439 assert(!Failure &&
"V has a name, so it should have a ST!"); (void)Failure;
445 setValueName(
V->getValueName());
446 V->setValueName(
nullptr);
447 getValueName()->setValue(
this);
455 VST->removeValueName(
V->getValueName());
456 setValueName(
V->getValueName());
457 V->setValueName(
nullptr);
458 getValueName()->setValue(
this);
461 ST->reinsertValue(
this);
464std::string Value::getNameOrAsOperand()
const {
469 raw_string_ostream OS(BBName);
470 printAsOperand(OS,
false);
474void Value::assertModuleIsMaterializedImpl()
const {
476 const GlobalValue *GV = dyn_cast<GlobalValue>(
this);
487static bool contains(SmallPtrSetImpl<ConstantExpr *> &Cache, ConstantExpr *Expr,
489 if (!Cache.
insert(Expr).second)
495 auto *
CE = dyn_cast<ConstantExpr>(O);
508 auto *
C = dyn_cast<Constant>(V);
512 auto *
CE = dyn_cast<ConstantExpr>(Expr);
516 SmallPtrSet<ConstantExpr *, 4> Cache;
521void Value::doRAUW(
Value *New, ReplaceMetadataUses ReplaceMetaUses) {
522 assert(hasUseList() &&
"Cannot replace constant data");
523 assert(New &&
"Value::replaceAllUsesWith(<null>) is invalid!");
525 "this->replaceAllUsesWith(expr(this)) is NOT valid!");
527 "replaceAllUses of value with new value of different type!");
531 ValueHandleBase::ValueIsRAUWd(
this, New);
532 if (ReplaceMetaUses == ReplaceMetadataUses::Yes && isUsedByMetadata())
533 ValueAsMetadata::handleRAUW(
this, New);
535 while (!materialized_use_empty()) {
539 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
540 if (!isa<GlobalValue>(
C)) {
541 C->handleOperandChange(
this, New);
549 if (BasicBlock *BB = dyn_cast<BasicBlock>(
this))
553void Value::replaceAllUsesWith(
Value *New) {
554 doRAUW(New, ReplaceMetadataUses::Yes);
557void Value::replaceNonMetadataUsesWith(
Value *New) {
558 doRAUW(New, ReplaceMetadataUses::No);
561bool Value::replaceUsesWithIf(
Value *New,
562 llvm::function_ref<
bool(Use &U)> ShouldReplace) {
563 assert(New &&
"Value::replaceUsesWithIf(<null>) is invalid!");
565 "replaceUses of value with new value of different type!");
567 SmallVector<TrackingVH<Constant>, 8> Consts;
568 SmallPtrSet<Constant *, 8> Visited;
572 if (!ShouldReplace(U))
578 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
579 if (!isa<GlobalValue>(
C)) {
588 while (!Consts.
empty()) {
600 SmallVector<DbgVariableRecord *> DPUsers;
602 for (
auto *DVR : DPUsers) {
603 DbgMarker *Marker = DVR->getMarker();
605 DVR->replaceVariableLocationOp(V, New);
611void Value::replaceUsesOutsideBlock(
Value *New, BasicBlock *BB) {
612 assert(New &&
"Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
614 "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
616 "replaceUses of value with new value of different type!");
617 assert(BB &&
"Basic block that may contain a use of 'New' must be defined\n");
620 replaceUsesWithIf(New, [BB](Use &U) {
621 auto *
I = dyn_cast<Instruction>(
U.getUser());
623 return !
I ||
I->getParent() != BB;
629enum PointerStripKind {
631 PSK_ZeroIndicesAndAliases,
632 PSK_ZeroIndicesSameRepresentation,
633 PSK_ForAliasAnalysis,
634 PSK_InBoundsConstantIndices,
641template <Po
interStripKind StripKind>
645 if (!
V->getType()->isPointerTy())
650 SmallPtrSet<const Value *, 4> Visited;
655 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
657 case PSK_ZeroIndices:
658 case PSK_ZeroIndicesAndAliases:
659 case PSK_ZeroIndicesSameRepresentation:
660 case PSK_ForAliasAnalysis:
661 if (!
GEP->hasAllZeroIndices())
664 case PSK_InBoundsConstantIndices:
665 if (!
GEP->hasAllConstantIndices())
669 if (!
GEP->isInBounds())
673 V =
GEP->getPointerOperand();
674 }
else if (Operator::getOpcode(V) == Instruction::BitCast) {
675 Value *NewV = cast<Operator>(V)->getOperand(0);
676 if (!NewV->getType()->isPointerTy())
679 }
else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
680 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
683 V = cast<Operator>(V)->getOperand(0);
684 }
else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
685 V = cast<GlobalAlias>(V)->getAliasee();
686 }
else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
687 cast<PHINode>(V)->getNumIncomingValues() == 1) {
688 V = cast<PHINode>(V)->getIncomingValue(0);
690 if (
const auto *
Call = dyn_cast<CallBase>(V)) {
691 if (
const Value *RV =
Call->getReturnedArgOperand()) {
698 if (StripKind == PSK_ForAliasAnalysis &&
699 (
Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
700 Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
701 V =
Call->getArgOperand(0);
707 assert(
V->getType()->isPointerTy() &&
"Unexpected operand type!");
708 }
while (Visited.
insert(V).second);
713const Value *Value::stripPointerCasts()
const {
717const Value *Value::stripPointerCastsAndAliases()
const {
721const Value *Value::stripPointerCastsSameRepresentation()
const {
725const Value *Value::stripInBoundsConstantOffsets()
const {
729const Value *Value::stripPointerCastsForAliasAnalysis()
const {
733const Value *Value::stripAndAccumulateConstantOffsets(
734 const DataLayout &
DL, APInt &Offset,
bool AllowNonInbounds,
735 bool AllowInvariantGroup,
736 function_ref<
bool(
Value &, APInt &)> ExternalAnalysis,
737 bool LookThroughIntToPtr)
const {
738 if (!
getType()->isPtrOrPtrVectorTy())
743 "The offset bit width does not match the DL specification.");
747 SmallPtrSet<const Value *, 4> Visited;
751 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
753 if (!AllowNonInbounds && !
GEP->isInBounds())
762 APInt GEPOffset(
DL.getIndexTypeSizeInBits(
V->getType()), 0);
763 if (!
GEP->accumulateConstantOffset(
DL, GEPOffset, ExternalAnalysis))
769 if (GEPOffset.getSignificantBits() >
BitWidth)
774 APInt GEPOffsetST = GEPOffset.sextOrTrunc(
BitWidth);
775 if (!ExternalAnalysis) {
778 bool Overflow =
false;
782 Offset = std::move(OldOffset);
786 V =
GEP->getPointerOperand();
787 }
else if (Operator::getOpcode(V) == Instruction::BitCast ||
788 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
789 V = cast<Operator>(V)->getOperand(0);
790 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
791 if (!GA->isInterposable())
792 V = GA->getAliasee();
793 }
else if (
const auto *
Call = dyn_cast<CallBase>(V)) {
794 if (
const Value *RV =
Call->getReturnedArgOperand())
796 if (AllowInvariantGroup &&
Call->isLaunderOrStripInvariantGroup())
797 V =
Call->getArgOperand(0);
798 }
else if (
auto *Int2Ptr = dyn_cast<Operator>(V)) {
800 if (!AllowNonInbounds || !LookThroughIntToPtr || !Int2Ptr ||
801 Int2Ptr->getOpcode() != Instruction::IntToPtr ||
802 Int2Ptr->getOperand(0)->getType()->getScalarSizeInBits() !=
BitWidth)
805 auto *
Add = dyn_cast<AddOperator>(Int2Ptr->getOperand(0));
809 auto *Ptr2Int = dyn_cast<PtrToIntOperator>(
Add->getOperand(0));
810 auto *CI = dyn_cast<ConstantInt>(
Add->getOperand(1));
815 V = Ptr2Int->getOperand(0);
817 assert(
V->getType()->isPtrOrPtrVectorTy() &&
"Unexpected operand type!");
818 }
while (Visited.
insert(V).second);
824Value::stripInBoundsOffsets(function_ref<
void(
const Value *)> Func)
const {
828bool Value::canBeFreed()
const {
833 if (isa<Constant>(
this))
838 if (
auto *
A = dyn_cast<Argument>(
this)) {
839 if (
A->hasPointeeInMemoryValueAttr())
847 if (
F->doesNotFreeMemory() &&
F->hasNoSync())
851 if (isa<IntToPtrInst>(
this) && getMetadata(LLVMContext::MD_nofree))
855 if (
auto *
I = dyn_cast<Instruction>(
this))
856 F =
I->getFunction();
857 if (
auto *
A = dyn_cast<Argument>(
this))
872 const auto &GCName =
F->getGC();
873 if (GCName ==
"statepoint-example") {
874 auto *PT = cast<PointerType>(this->
getType());
875 if (PT->getAddressSpace() != 1)
885 for (
auto &Fn : *
F->getParent())
886 if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
893uint64_t Value::getPointerDereferenceableBytes(
const DataLayout &
DL,
895 bool &CanBeFreed)
const {
898 uint64_t DerefBytes = 0;
901 if (
const Argument *
A = dyn_cast<Argument>(
this)) {
902 DerefBytes =
A->getDereferenceableBytes();
903 if (DerefBytes == 0) {
905 if (
Type *ArgMemTy =
A->getPointeeInMemoryValueType()) {
906 if (ArgMemTy->isSized()) {
908 DerefBytes =
DL.getTypeStoreSize(ArgMemTy).getKnownMinValue();
913 if (DerefBytes == 0) {
914 DerefBytes =
A->getDereferenceableOrNullBytes();
917 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
918 DerefBytes =
Call->getRetDereferenceableBytes();
919 if (DerefBytes == 0) {
920 DerefBytes =
Call->getRetDereferenceableOrNullBytes();
923 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
924 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
925 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
928 if (DerefBytes == 0) {
930 LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
931 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
936 }
else if (
auto *IP = dyn_cast<IntToPtrInst>(
this)) {
937 if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
938 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
941 if (DerefBytes == 0) {
943 IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
944 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
949 }
else if (
auto *AI = dyn_cast<AllocaInst>(
this)) {
950 if (std::optional<TypeSize>
Size = AI->getAllocationSize(
DL)) {
951 DerefBytes =
Size->getKnownMinValue();
955 }
else if (
auto *GV = dyn_cast<GlobalVariable>(
this)) {
959 DerefBytes =
DL.getTypeStoreSize(GV->
getValueType()).getFixedValue();
967Align Value::getPointerAlignment(
const DataLayout &
DL)
const {
969 if (
const Function *
F = dyn_cast<Function>(
this)) {
970 Align FunctionPtrAlign =
DL.getFunctionPtrAlign().valueOrOne();
971 switch (
DL.getFunctionPtrAlignType()) {
972 case DataLayout::FunctionPtrAlignType::Independent:
973 return FunctionPtrAlign;
974 case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
975 return std::max(FunctionPtrAlign,
F->getAlign().valueOrOne());
978 }
else if (
auto *GVar = dyn_cast<GlobalVariable>(
this)) {
979 const MaybeAlign Alignment(GVar->getAlign());
981 Type *ObjectType = GVar->getValueType();
982 if (ObjectType->isSized()) {
986 if (GVar->isStrongDefinitionForLinker())
987 return DL.getPreferredAlign(GVar);
989 return DL.getABITypeAlign(ObjectType);
992 return Alignment.valueOrOne();
993 }
else if (
const Argument *
A = dyn_cast<Argument>(
this)) {
994 const MaybeAlign Alignment =
A->getParamAlign();
995 if (!Alignment &&
A->hasStructRetAttr()) {
997 Type *EltTy =
A->getParamStructRetType();
998 if (EltTy->isSized())
999 return DL.getABITypeAlign(EltTy);
1002 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
this)) {
1003 return AI->getAlign();
1004 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
1005 MaybeAlign Alignment =
Call->getRetAlign();
1006 if (!Alignment &&
Call->getCalledFunction())
1007 Alignment =
Call->getCalledFunction()->getAttributes().getRetAlignment();
1009 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
1010 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
1011 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
1014 }
else if (
auto *CE = dyn_cast<ConstantExpr>(
this)) {
1016 if (
CE->getOpcode() == Instruction::IntToPtr &&
1017 isa<ConstantInt>(
CE->getOperand(0))) {
1018 ConstantInt *IntPtr = cast<ConstantInt>(
CE->getOperand(0));
1022 return Align(TrailingZeros < Value::MaxAlignmentExponent
1023 ? uint64_t(1) << TrailingZeros
1024 : Value::MaximumAlignment);
1030static std::optional<int64_t>
1034 for (
unsigned i = 1; i != Idx; ++i, ++GTI)
1039 for (
unsigned i = Idx, e =
GEP->getNumOperands(); i != e; ++i, ++GTI) {
1040 ConstantInt *OpC = dyn_cast<ConstantInt>(
GEP->getOperand(i));
1042 return std::nullopt;
1055 if (
Size.isScalable())
1056 return std::nullopt;
1063std::optional<int64_t> Value::getPointerOffsetFrom(
const Value *Other,
1064 const DataLayout &
DL)
const {
1066 const Value *Ptr2 =
this;
1067 APInt Offset1(
DL.getIndexTypeSizeInBits(Ptr1->getType()), 0);
1068 APInt Offset2(
DL.getIndexTypeSizeInBits(Ptr2->getType()), 0);
1069 Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(
DL, Offset1,
true);
1070 Ptr2 = Ptr2->stripAndAccumulateConstantOffsets(
DL, Offset2,
true);
1074 return Offset2.getSExtValue() - Offset1.getSExtValue();
1076 const GEPOperator *GEP1 = dyn_cast<GEPOperator>(Ptr1);
1077 const GEPOperator *GEP2 = dyn_cast<GEPOperator>(Ptr2);
1086 return std::nullopt;
1096 if (!IOffset1 || !IOffset2)
1097 return std::nullopt;
1098 return *IOffset2 - *IOffset1 + Offset2.getSExtValue() -
1099 Offset1.getSExtValue();
1102const Value *Value::DoPHITranslation(
const BasicBlock *CurBB,
1103 const BasicBlock *PredBB)
const {
1104 auto *PN = dyn_cast<PHINode>(
this);
1105 if (PN && PN->getParent() == CurBB)
1106 return PN->getIncomingValueForBlock(PredBB);
1110void Value::reverseUseList() {
1111 if (!UseList || !UseList->Next)
1115 Use *Head = UseList;
1116 Use *Current = UseList->Next;
1117 Head->Next =
nullptr;
1120 Current->Next = Head;
1121 Head->Prev = &Current->Next;
1126 Head->Prev = &UseList;
1129bool Value::isSwiftError()
const {
1130 auto *Arg = dyn_cast<Argument>(
this);
1132 return Arg->hasSwiftErrorAttr();
1133 auto *Alloca = dyn_cast<AllocaInst>(
this);
1136 return Alloca->isSwiftError();
1143void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1144 assert(List &&
"Handle list is null?");
1151 Next->setPrevPtr(&Next);
1152 assert(getValPtr() ==
Next->getValPtr() &&
"Added to wrong list?");
1156void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1157 assert(List &&
"Must insert after existing node");
1160 setPrevPtr(&
List->Next);
1163 Next->setPrevPtr(&Next);
1166void ValueHandleBase::AddToUseList() {
1167 assert(getValPtr() &&
"Null pointer doesn't have a use list!");
1169 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1171 if (getValPtr()->HasValueHandle) {
1175 assert(Entry &&
"Value doesn't have any handles?");
1176 AddToExistingUseList(&Entry);
1185 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1188 ValueHandleBase *&
Entry = Handles[getValPtr()];
1189 assert(!Entry &&
"Value really did already have handles?");
1190 AddToExistingUseList(&Entry);
1191 getValPtr()->HasValueHandle =
true;
1196 Handles.
size() == 1) {
1201 for (DenseMap<Value*, ValueHandleBase*>::iterator
I = Handles.
begin(),
1202 E = Handles.
end();
I !=
E; ++
I) {
1203 assert(
I->second &&
I->first ==
I->second->getValPtr() &&
1204 "List invariant broken!");
1205 I->second->setPrevPtr(&
I->second);
1209void ValueHandleBase::RemoveFromUseList() {
1210 assert(getValPtr() && getValPtr()->HasValueHandle &&
1211 "Pointer doesn't have a use list!");
1214 ValueHandleBase **PrevPtr = getPrevPtr();
1215 assert(*PrevPtr ==
this &&
"List invariant broken");
1219 assert(
Next->getPrevPtr() == &Next &&
"List invariant broken");
1220 Next->setPrevPtr(PrevPtr);
1227 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1228 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1230 Handles.
erase(getValPtr());
1231 getValPtr()->HasValueHandle =
false;
1235void ValueHandleBase::ValueIsDeleted(
Value *V) {
1236 assert(
V->HasValueHandle &&
"Should only be called if ValueHandles present");
1240 LLVMContextImpl *pImpl =
V->getContext().pImpl;
1242 assert(Entry &&
"Value bit set but no entries exist");
1253 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1254 Iterator.RemoveFromUseList();
1255 Iterator.AddToExistingUseListAfter(Entry);
1256 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1258 switch (
Entry->getKind()) {
1265 Entry->operator=(
nullptr);
1269 static_cast<CallbackVH*
>(
Entry)->deleted();
1275 if (
V->HasValueHandle) {
1277 dbgs() <<
"While deleting: " << *
V->getType() <<
" %" <<
V->getName()
1288void ValueHandleBase::ValueIsRAUWd(
Value *Old,
Value *New) {
1289 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
1290 assert(Old != New &&
"Changing value into itself!");
1291 assert(Old->getType() ==
New->getType() &&
1292 "replaceAllUses of value with new value of different type!");
1296 LLVMContextImpl *pImpl = Old->getContext().pImpl;
1299 assert(Entry &&
"Value bit set but no entries exist");
1305 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1306 Iterator.RemoveFromUseList();
1307 Iterator.AddToExistingUseListAfter(Entry);
1308 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1310 switch (
Entry->getKind()) {
1321 static_cast<CallbackVH*
>(
Entry)->allUsesReplacedWith(New);
1329 if (Old->HasValueHandle)
1331 switch (
Entry->getKind()) {
1333 dbgs() <<
"After RAUW from " << *Old->getType() <<
" %"
1334 << Old->getName() <<
" to " << *
New->getType() <<
" %"
1335 <<
New->getName() <<
"\n";
1337 "A weak tracking value handle still pointed to the old value!\n");
1345void 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.