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);
561void 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;
571 if (!ShouldReplace(U))
575 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
576 if (!isa<GlobalValue>(
C)) {
585 while (!Consts.
empty()) {
595 SmallVector<DbgVariableRecord *> DPUsers;
597 for (
auto *DVR : DPUsers) {
598 DbgMarker *Marker = DVR->getMarker();
600 DVR->replaceVariableLocationOp(V, New);
606void Value::replaceUsesOutsideBlock(
Value *New, BasicBlock *BB) {
607 assert(New &&
"Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
609 "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
611 "replaceUses of value with new value of different type!");
612 assert(BB &&
"Basic block that may contain a use of 'New' must be defined\n");
615 replaceUsesWithIf(New, [BB](Use &U) {
616 auto *
I = dyn_cast<Instruction>(
U.getUser());
618 return !
I ||
I->getParent() != BB;
624enum PointerStripKind {
626 PSK_ZeroIndicesAndAliases,
627 PSK_ZeroIndicesSameRepresentation,
628 PSK_ForAliasAnalysis,
629 PSK_InBoundsConstantIndices,
636template <Po
interStripKind StripKind>
640 if (!
V->getType()->isPointerTy())
645 SmallPtrSet<const Value *, 4> Visited;
650 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
652 case PSK_ZeroIndices:
653 case PSK_ZeroIndicesAndAliases:
654 case PSK_ZeroIndicesSameRepresentation:
655 case PSK_ForAliasAnalysis:
656 if (!
GEP->hasAllZeroIndices())
659 case PSK_InBoundsConstantIndices:
660 if (!
GEP->hasAllConstantIndices())
664 if (!
GEP->isInBounds())
668 V =
GEP->getPointerOperand();
669 }
else if (Operator::getOpcode(V) == Instruction::BitCast) {
670 Value *NewV = cast<Operator>(V)->getOperand(0);
671 if (!NewV->getType()->isPointerTy())
674 }
else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
675 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
678 V = cast<Operator>(V)->getOperand(0);
679 }
else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
680 V = cast<GlobalAlias>(V)->getAliasee();
681 }
else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
682 cast<PHINode>(V)->getNumIncomingValues() == 1) {
683 V = cast<PHINode>(V)->getIncomingValue(0);
685 if (
const auto *
Call = dyn_cast<CallBase>(V)) {
686 if (
const Value *RV =
Call->getReturnedArgOperand()) {
693 if (StripKind == PSK_ForAliasAnalysis &&
694 (
Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
695 Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
696 V =
Call->getArgOperand(0);
702 assert(
V->getType()->isPointerTy() &&
"Unexpected operand type!");
703 }
while (Visited.
insert(V).second);
708const Value *Value::stripPointerCasts()
const {
712const Value *Value::stripPointerCastsAndAliases()
const {
716const Value *Value::stripPointerCastsSameRepresentation()
const {
720const Value *Value::stripInBoundsConstantOffsets()
const {
724const Value *Value::stripPointerCastsForAliasAnalysis()
const {
728const Value *Value::stripAndAccumulateConstantOffsets(
729 const DataLayout &
DL, APInt &Offset,
bool AllowNonInbounds,
730 bool AllowInvariantGroup,
731 function_ref<
bool(
Value &, APInt &)> ExternalAnalysis,
732 bool LookThroughIntToPtr)
const {
733 if (!
getType()->isPtrOrPtrVectorTy())
738 "The offset bit width does not match the DL specification.");
742 SmallPtrSet<const Value *, 4> Visited;
746 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
748 if (!AllowNonInbounds && !
GEP->isInBounds())
757 APInt GEPOffset(
DL.getIndexTypeSizeInBits(
V->getType()), 0);
758 if (!
GEP->accumulateConstantOffset(
DL, GEPOffset, ExternalAnalysis))
764 if (GEPOffset.getSignificantBits() >
BitWidth)
769 APInt GEPOffsetST = GEPOffset.sextOrTrunc(
BitWidth);
770 if (!ExternalAnalysis) {
773 bool Overflow =
false;
781 V =
GEP->getPointerOperand();
782 }
else if (Operator::getOpcode(V) == Instruction::BitCast ||
783 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
784 V = cast<Operator>(V)->getOperand(0);
785 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
786 if (!GA->isInterposable())
787 V = GA->getAliasee();
788 }
else if (
const auto *
Call = dyn_cast<CallBase>(V)) {
789 if (
const Value *RV =
Call->getReturnedArgOperand())
791 if (AllowInvariantGroup &&
Call->isLaunderOrStripInvariantGroup())
792 V =
Call->getArgOperand(0);
793 }
else if (
auto *Int2Ptr = dyn_cast<Operator>(V)) {
795 if (!AllowNonInbounds || !LookThroughIntToPtr || !Int2Ptr ||
796 Int2Ptr->getOpcode() != Instruction::IntToPtr ||
797 Int2Ptr->getOperand(0)->getType()->getScalarSizeInBits() !=
BitWidth)
800 auto *
Add = dyn_cast<AddOperator>(Int2Ptr->getOperand(0));
804 auto *Ptr2Int = dyn_cast<PtrToIntOperator>(
Add->getOperand(0));
805 auto *CI = dyn_cast<ConstantInt>(
Add->getOperand(1));
810 V = Ptr2Int->getOperand(0);
812 assert(
V->getType()->isPtrOrPtrVectorTy() &&
"Unexpected operand type!");
813 }
while (Visited.
insert(V).second);
819Value::stripInBoundsOffsets(function_ref<
void(
const Value *)> Func)
const {
823bool Value::canBeFreed()
const {
828 if (isa<Constant>(
this))
833 if (
auto *
A = dyn_cast<Argument>(
this)) {
834 if (
A->hasPointeeInMemoryValueAttr())
842 if (
F->doesNotFreeMemory() &&
F->hasNoSync())
846 if (isa<IntToPtrInst>(
this) && getMetadata(LLVMContext::MD_nofree))
850 if (
auto *
I = dyn_cast<Instruction>(
this))
851 F =
I->getFunction();
852 if (
auto *
A = dyn_cast<Argument>(
this))
867 const auto &GCName =
F->getGC();
868 if (GCName ==
"statepoint-example") {
869 auto *PT = cast<PointerType>(this->
getType());
870 if (PT->getAddressSpace() != 1)
880 for (
auto &Fn : *
F->getParent())
881 if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
888uint64_t Value::getPointerDereferenceableBytes(
const DataLayout &
DL,
890 bool &CanBeFreed)
const {
893 uint64_t DerefBytes = 0;
896 if (
const Argument *
A = dyn_cast<Argument>(
this)) {
897 DerefBytes =
A->getDereferenceableBytes();
898 if (DerefBytes == 0) {
900 if (
Type *ArgMemTy =
A->getPointeeInMemoryValueType()) {
901 if (ArgMemTy->isSized()) {
903 DerefBytes =
DL.getTypeStoreSize(ArgMemTy).getKnownMinValue();
908 if (DerefBytes == 0) {
909 DerefBytes =
A->getDereferenceableOrNullBytes();
912 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
913 DerefBytes =
Call->getRetDereferenceableBytes();
914 if (DerefBytes == 0) {
915 DerefBytes =
Call->getRetDereferenceableOrNullBytes();
918 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
919 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
920 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
923 if (DerefBytes == 0) {
925 LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
926 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
931 }
else if (
auto *IP = dyn_cast<IntToPtrInst>(
this)) {
932 if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
933 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
936 if (DerefBytes == 0) {
938 IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
939 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
944 }
else if (
auto *AI = dyn_cast<AllocaInst>(
this)) {
945 if (std::optional<TypeSize>
Size = AI->getAllocationSize(
DL)) {
946 DerefBytes =
Size->getKnownMinValue();
950 }
else if (
auto *GV = dyn_cast<GlobalVariable>(
this)) {
954 DerefBytes =
DL.getTypeStoreSize(GV->
getValueType()).getFixedValue();
962Align Value::getPointerAlignment(
const DataLayout &
DL)
const {
964 if (
const Function *
F = dyn_cast<Function>(
this)) {
965 Align FunctionPtrAlign =
DL.getFunctionPtrAlign().valueOrOne();
966 switch (
DL.getFunctionPtrAlignType()) {
967 case DataLayout::FunctionPtrAlignType::Independent:
968 return FunctionPtrAlign;
969 case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
970 return std::max(FunctionPtrAlign,
F->getAlign().valueOrOne());
973 }
else if (
auto *GVar = dyn_cast<GlobalVariable>(
this)) {
974 const MaybeAlign Alignment(GVar->getAlign());
976 Type *ObjectType = GVar->getValueType();
977 if (ObjectType->isSized()) {
981 if (GVar->isStrongDefinitionForLinker())
982 return DL.getPreferredAlign(GVar);
984 return DL.getABITypeAlign(ObjectType);
987 return Alignment.valueOrOne();
988 }
else if (
const Argument *
A = dyn_cast<Argument>(
this)) {
989 const MaybeAlign Alignment =
A->getParamAlign();
990 if (!Alignment &&
A->hasStructRetAttr()) {
992 Type *EltTy =
A->getParamStructRetType();
993 if (EltTy->isSized())
994 return DL.getABITypeAlign(EltTy);
997 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
this)) {
998 return AI->getAlign();
999 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
1000 MaybeAlign Alignment =
Call->getRetAlign();
1001 if (!Alignment &&
Call->getCalledFunction())
1002 Alignment =
Call->getCalledFunction()->getAttributes().getRetAlignment();
1004 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
1005 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
1006 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
1009 }
else if (
auto *CE = dyn_cast<ConstantExpr>(
this)) {
1011 if (
CE->getOpcode() == Instruction::IntToPtr &&
1012 isa<ConstantInt>(
CE->getOperand(0))) {
1013 ConstantInt *IntPtr = cast<ConstantInt>(
CE->getOperand(0));
1017 return Align(TrailingZeros < Value::MaxAlignmentExponent
1018 ? uint64_t(1) << TrailingZeros
1019 : Value::MaximumAlignment);
1025static std::optional<int64_t>
1029 for (
unsigned i = 1; i != Idx; ++i, ++GTI)
1034 for (
unsigned i = Idx, e =
GEP->getNumOperands(); i != e; ++i, ++GTI) {
1035 ConstantInt *OpC = dyn_cast<ConstantInt>(
GEP->getOperand(i));
1037 return std::nullopt;
1050 if (
Size.isScalable())
1051 return std::nullopt;
1058std::optional<int64_t> Value::getPointerOffsetFrom(
const Value *Other,
1059 const DataLayout &
DL)
const {
1061 const Value *Ptr2 =
this;
1062 APInt Offset1(
DL.getIndexTypeSizeInBits(Ptr1->getType()), 0);
1063 APInt Offset2(
DL.getIndexTypeSizeInBits(Ptr2->getType()), 0);
1064 Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(
DL, Offset1,
true);
1065 Ptr2 = Ptr2->stripAndAccumulateConstantOffsets(
DL, Offset2,
true);
1069 return Offset2.getSExtValue() - Offset1.getSExtValue();
1071 const GEPOperator *GEP1 = dyn_cast<GEPOperator>(Ptr1);
1072 const GEPOperator *GEP2 = dyn_cast<GEPOperator>(Ptr2);
1081 return std::nullopt;
1091 if (!IOffset1 || !IOffset2)
1092 return std::nullopt;
1093 return *IOffset2 - *IOffset1 + Offset2.getSExtValue() -
1094 Offset1.getSExtValue();
1097const Value *Value::DoPHITranslation(
const BasicBlock *CurBB,
1098 const BasicBlock *PredBB)
const {
1099 auto *PN = dyn_cast<PHINode>(
this);
1100 if (PN && PN->getParent() == CurBB)
1101 return PN->getIncomingValueForBlock(PredBB);
1105void Value::reverseUseList() {
1106 if (!UseList || !UseList->Next)
1110 Use *Head = UseList;
1111 Use *Current = UseList->Next;
1112 Head->Next =
nullptr;
1115 Current->Next = Head;
1116 Head->Prev = &Current->Next;
1121 Head->Prev = &UseList;
1124bool Value::isSwiftError()
const {
1125 auto *Arg = dyn_cast<Argument>(
this);
1127 return Arg->hasSwiftErrorAttr();
1128 auto *Alloca = dyn_cast<AllocaInst>(
this);
1131 return Alloca->isSwiftError();
1138void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1139 assert(List &&
"Handle list is null?");
1146 Next->setPrevPtr(&Next);
1147 assert(getValPtr() ==
Next->getValPtr() &&
"Added to wrong list?");
1151void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1152 assert(List &&
"Must insert after existing node");
1155 setPrevPtr(&
List->Next);
1158 Next->setPrevPtr(&Next);
1161void ValueHandleBase::AddToUseList() {
1162 assert(getValPtr() &&
"Null pointer doesn't have a use list!");
1164 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1166 if (getValPtr()->HasValueHandle) {
1170 assert(Entry &&
"Value doesn't have any handles?");
1171 AddToExistingUseList(&Entry);
1180 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1183 ValueHandleBase *&
Entry = Handles[getValPtr()];
1184 assert(!Entry &&
"Value really did already have handles?");
1185 AddToExistingUseList(&Entry);
1186 getValPtr()->HasValueHandle =
true;
1191 Handles.
size() == 1) {
1196 for (DenseMap<Value*, ValueHandleBase*>::iterator
I = Handles.
begin(),
1197 E = Handles.
end();
I !=
E; ++
I) {
1198 assert(
I->second &&
I->first ==
I->second->getValPtr() &&
1199 "List invariant broken!");
1200 I->second->setPrevPtr(&
I->second);
1204void ValueHandleBase::RemoveFromUseList() {
1205 assert(getValPtr() && getValPtr()->HasValueHandle &&
1206 "Pointer doesn't have a use list!");
1209 ValueHandleBase **PrevPtr = getPrevPtr();
1210 assert(*PrevPtr ==
this &&
"List invariant broken");
1214 assert(
Next->getPrevPtr() == &Next &&
"List invariant broken");
1215 Next->setPrevPtr(PrevPtr);
1222 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1223 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1225 Handles.
erase(getValPtr());
1226 getValPtr()->HasValueHandle =
false;
1230void ValueHandleBase::ValueIsDeleted(
Value *V) {
1231 assert(
V->HasValueHandle &&
"Should only be called if ValueHandles present");
1235 LLVMContextImpl *pImpl =
V->getContext().pImpl;
1237 assert(Entry &&
"Value bit set but no entries exist");
1248 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1249 Iterator.RemoveFromUseList();
1250 Iterator.AddToExistingUseListAfter(Entry);
1251 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1253 switch (
Entry->getKind()) {
1260 Entry->operator=(
nullptr);
1264 static_cast<CallbackVH*
>(
Entry)->deleted();
1270 if (
V->HasValueHandle) {
1272 dbgs() <<
"While deleting: " << *
V->getType() <<
" %" <<
V->getName()
1283void ValueHandleBase::ValueIsRAUWd(
Value *Old,
Value *New) {
1284 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
1285 assert(Old != New &&
"Changing value into itself!");
1286 assert(Old->getType() ==
New->getType() &&
1287 "replaceAllUses of value with new value of different type!");
1291 LLVMContextImpl *pImpl = Old->getContext().pImpl;
1294 assert(Entry &&
"Value bit set but no entries exist");
1300 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1301 Iterator.RemoveFromUseList();
1302 Iterator.AddToExistingUseListAfter(Entry);
1303 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1305 switch (
Entry->getKind()) {
1316 static_cast<CallbackVH*
>(
Entry)->allUsesReplacedWith(New);
1324 if (Old->HasValueHandle)
1326 switch (
Entry->getKind()) {
1328 dbgs() <<
"After RAUW from " << *Old->getType() <<
" %"
1329 << Old->getName() <<
" to " << *
New->getType() <<
" %"
1330 <<
New->getName() <<
"\n";
1332 "A weak tracking value handle still pointed to the old value!\n");
1340void 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.