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;
364 if (!NameRef.
empty()) {
369 getValueName()->setValue(
this);
378 ST->removeValueName(getValueName());
387 setValueName(
ST->createValueName(NameRef,
this));
390void Value::setName(
const Twine &NewName) {
391 setNameImpl(NewName);
392 if (Function *
F = dyn_cast<Function>(
this))
393 F->updateAfterNameChange();
396void Value::takeName(
Value *V) {
397 assert(V !=
this &&
"Illegal call to this->takeName(this)!");
398 ValueSymbolTable *
ST =
nullptr;
405 if (
V->hasName())
V->setName(
"");
411 ST->removeValueName(getValueName());
418 if (!
V->hasName())
return;
430 ValueSymbolTable *VST;
432 assert(!Failure &&
"V has a name, so it should have a ST!"); (void)Failure;
438 setValueName(
V->getValueName());
439 V->setValueName(
nullptr);
440 getValueName()->setValue(
this);
448 VST->removeValueName(
V->getValueName());
449 setValueName(
V->getValueName());
450 V->setValueName(
nullptr);
451 getValueName()->setValue(
this);
454 ST->reinsertValue(
this);
457std::string Value::getNameOrAsOperand()
const {
462 raw_string_ostream OS(BBName);
463 printAsOperand(OS,
false);
467void Value::assertModuleIsMaterializedImpl()
const {
469 const GlobalValue *GV = dyn_cast<GlobalValue>(
this);
480static bool contains(SmallPtrSetImpl<ConstantExpr *> &Cache, ConstantExpr *Expr,
482 if (!Cache.
insert(Expr).second)
488 auto *
CE = dyn_cast<ConstantExpr>(O);
501 auto *
C = dyn_cast<Constant>(V);
505 auto *
CE = dyn_cast<ConstantExpr>(Expr);
509 SmallPtrSet<ConstantExpr *, 4> Cache;
514void Value::doRAUW(
Value *New, ReplaceMetadataUses ReplaceMetaUses) {
515 assert(hasUseList() &&
"Cannot replace constant data");
516 assert(New &&
"Value::replaceAllUsesWith(<null>) is invalid!");
518 "this->replaceAllUsesWith(expr(this)) is NOT valid!");
520 "replaceAllUses of value with new value of different type!");
524 ValueHandleBase::ValueIsRAUWd(
this, New);
525 if (ReplaceMetaUses == ReplaceMetadataUses::Yes && isUsedByMetadata())
526 ValueAsMetadata::handleRAUW(
this, New);
528 while (!materialized_use_empty()) {
532 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
533 if (!isa<GlobalValue>(
C)) {
534 C->handleOperandChange(
this, New);
542 if (BasicBlock *BB = dyn_cast<BasicBlock>(
this))
546void Value::replaceAllUsesWith(
Value *New) {
547 doRAUW(New, ReplaceMetadataUses::Yes);
550void Value::replaceNonMetadataUsesWith(
Value *New) {
551 doRAUW(New, ReplaceMetadataUses::No);
554void Value::replaceUsesWithIf(
Value *New,
555 llvm::function_ref<
bool(Use &U)> ShouldReplace) {
556 assert(New &&
"Value::replaceUsesWithIf(<null>) is invalid!");
558 "replaceUses of value with new value of different type!");
560 SmallVector<TrackingVH<Constant>, 8> Consts;
561 SmallPtrSet<Constant *, 8> Visited;
564 if (!ShouldReplace(U))
568 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
569 if (!isa<GlobalValue>(
C)) {
578 while (!Consts.
empty()) {
588 SmallVector<DbgVariableRecord *> DPUsers;
590 for (
auto *DVR : DPUsers) {
591 DbgMarker *Marker = DVR->getMarker();
593 DVR->replaceVariableLocationOp(V, New);
599void Value::replaceUsesOutsideBlock(
Value *New, BasicBlock *BB) {
600 assert(New &&
"Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
602 "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
604 "replaceUses of value with new value of different type!");
605 assert(BB &&
"Basic block that may contain a use of 'New' must be defined\n");
608 replaceUsesWithIf(New, [BB](Use &U) {
609 auto *
I = dyn_cast<Instruction>(
U.getUser());
611 return !
I ||
I->getParent() != BB;
617enum PointerStripKind {
619 PSK_ZeroIndicesAndAliases,
620 PSK_ZeroIndicesSameRepresentation,
621 PSK_ForAliasAnalysis,
622 PSK_InBoundsConstantIndices,
626template <Po
interStripKind StripKind>
static void NoopCallback(
const Value *) {}
628template <Po
interStripKind StripKind>
629static const Value *stripPointerCastsAndOffsets(
631 function_ref<
void(
const Value *)> Func = NoopCallback<StripKind>) {
632 if (!
V->getType()->isPointerTy())
637 SmallPtrSet<const Value *, 4> Visited;
642 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
644 case PSK_ZeroIndices:
645 case PSK_ZeroIndicesAndAliases:
646 case PSK_ZeroIndicesSameRepresentation:
647 case PSK_ForAliasAnalysis:
648 if (!
GEP->hasAllZeroIndices())
651 case PSK_InBoundsConstantIndices:
652 if (!
GEP->hasAllConstantIndices())
656 if (!
GEP->isInBounds())
660 V =
GEP->getPointerOperand();
661 }
else if (Operator::getOpcode(V) == Instruction::BitCast) {
662 Value *NewV = cast<Operator>(V)->getOperand(0);
663 if (!NewV->getType()->isPointerTy())
666 }
else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
667 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
670 V = cast<Operator>(V)->getOperand(0);
671 }
else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
672 V = cast<GlobalAlias>(V)->getAliasee();
673 }
else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
674 cast<PHINode>(V)->getNumIncomingValues() == 1) {
675 V = cast<PHINode>(V)->getIncomingValue(0);
677 if (
const auto *
Call = dyn_cast<CallBase>(V)) {
678 if (
const Value *RV =
Call->getReturnedArgOperand()) {
685 if (StripKind == PSK_ForAliasAnalysis &&
686 (
Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
687 Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
688 V =
Call->getArgOperand(0);
694 assert(
V->getType()->isPointerTy() &&
"Unexpected operand type!");
695 }
while (Visited.
insert(V).second);
701const Value *Value::stripPointerCasts()
const {
702 return stripPointerCastsAndOffsets<PSK_ZeroIndices>(
this);
705const Value *Value::stripPointerCastsAndAliases()
const {
706 return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(
this);
709const Value *Value::stripPointerCastsSameRepresentation()
const {
710 return stripPointerCastsAndOffsets<PSK_ZeroIndicesSameRepresentation>(
this);
713const Value *Value::stripInBoundsConstantOffsets()
const {
714 return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(
this);
717const Value *Value::stripPointerCastsForAliasAnalysis()
const {
718 return stripPointerCastsAndOffsets<PSK_ForAliasAnalysis>(
this);
721const Value *Value::stripAndAccumulateConstantOffsets(
722 const DataLayout &
DL, APInt &Offset,
bool AllowNonInbounds,
723 bool AllowInvariantGroup,
724 function_ref<
bool(
Value &, APInt &)> ExternalAnalysis,
725 bool LookThroughIntToPtr)
const {
726 if (!
getType()->isPtrOrPtrVectorTy())
731 "The offset bit width does not match the DL specification.");
735 SmallPtrSet<const Value *, 4> Visited;
739 if (
auto *
GEP = dyn_cast<GEPOperator>(V)) {
741 if (!AllowNonInbounds && !
GEP->isInBounds())
750 APInt GEPOffset(
DL.getIndexTypeSizeInBits(
V->getType()), 0);
751 if (!
GEP->accumulateConstantOffset(
DL, GEPOffset, ExternalAnalysis))
757 if (GEPOffset.getSignificantBits() >
BitWidth)
762 APInt GEPOffsetST = GEPOffset.sextOrTrunc(
BitWidth);
763 if (!ExternalAnalysis) {
766 bool Overflow =
false;
774 V =
GEP->getPointerOperand();
775 }
else if (Operator::getOpcode(V) == Instruction::BitCast ||
776 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
777 V = cast<Operator>(V)->getOperand(0);
778 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
779 if (!GA->isInterposable())
780 V = GA->getAliasee();
781 }
else if (
const auto *
Call = dyn_cast<CallBase>(V)) {
782 if (
const Value *RV =
Call->getReturnedArgOperand())
784 if (AllowInvariantGroup &&
Call->isLaunderOrStripInvariantGroup())
785 V =
Call->getArgOperand(0);
786 }
else if (
auto *Int2Ptr = dyn_cast<Operator>(V)) {
788 if (!AllowNonInbounds || !LookThroughIntToPtr || !Int2Ptr ||
789 Int2Ptr->getOpcode() != Instruction::IntToPtr ||
790 Int2Ptr->getOperand(0)->getType()->getScalarSizeInBits() !=
BitWidth)
793 auto *
Add = dyn_cast<AddOperator>(Int2Ptr->getOperand(0));
797 auto *Ptr2Int = dyn_cast<PtrToIntOperator>(
Add->getOperand(0));
798 auto *CI = dyn_cast<ConstantInt>(
Add->getOperand(1));
803 V = Ptr2Int->getOperand(0);
805 assert(
V->getType()->isPtrOrPtrVectorTy() &&
"Unexpected operand type!");
806 }
while (Visited.
insert(V).second);
812Value::stripInBoundsOffsets(function_ref<
void(
const Value *)> Func)
const {
813 return stripPointerCastsAndOffsets<PSK_InBounds>(
this, Func);
816bool Value::canBeFreed()
const {
821 if (isa<Constant>(
this))
826 if (
auto *
A = dyn_cast<Argument>(
this)) {
827 if (
A->hasPointeeInMemoryValueAttr())
835 if (
F->doesNotFreeMemory() &&
F->hasNoSync())
839 if (isa<IntToPtrInst>(
this) && getMetadata(LLVMContext::MD_nofree))
843 if (
auto *
I = dyn_cast<Instruction>(
this))
844 F =
I->getFunction();
845 if (
auto *
A = dyn_cast<Argument>(
this))
860 const auto &GCName =
F->getGC();
861 if (GCName ==
"statepoint-example") {
862 auto *PT = cast<PointerType>(this->
getType());
863 if (PT->getAddressSpace() != 1)
873 for (
auto &Fn : *
F->getParent())
874 if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
881uint64_t Value::getPointerDereferenceableBytes(
const DataLayout &
DL,
883 bool &CanBeFreed)
const {
886 uint64_t DerefBytes = 0;
889 if (
const Argument *
A = dyn_cast<Argument>(
this)) {
890 DerefBytes =
A->getDereferenceableBytes();
891 if (DerefBytes == 0) {
893 if (
Type *ArgMemTy =
A->getPointeeInMemoryValueType()) {
894 if (ArgMemTy->isSized()) {
896 DerefBytes =
DL.getTypeStoreSize(ArgMemTy).getKnownMinValue();
901 if (DerefBytes == 0) {
902 DerefBytes =
A->getDereferenceableOrNullBytes();
905 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
906 DerefBytes =
Call->getRetDereferenceableBytes();
907 if (DerefBytes == 0) {
908 DerefBytes =
Call->getRetDereferenceableOrNullBytes();
911 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
912 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
913 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
916 if (DerefBytes == 0) {
918 LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
919 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
924 }
else if (
auto *IP = dyn_cast<IntToPtrInst>(
this)) {
925 if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
926 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
929 if (DerefBytes == 0) {
931 IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
932 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
937 }
else if (
auto *AI = dyn_cast<AllocaInst>(
this)) {
938 if (!AI->isArrayAllocation()) {
940 DL.getTypeStoreSize(AI->getAllocatedType()).getKnownMinValue();
944 }
else if (
auto *GV = dyn_cast<GlobalVariable>(
this)) {
948 DerefBytes =
DL.getTypeStoreSize(GV->
getValueType()).getFixedValue();
956Align Value::getPointerAlignment(
const DataLayout &
DL)
const {
958 if (
const Function *
F = dyn_cast<Function>(
this)) {
959 Align FunctionPtrAlign =
DL.getFunctionPtrAlign().valueOrOne();
960 switch (
DL.getFunctionPtrAlignType()) {
961 case DataLayout::FunctionPtrAlignType::Independent:
962 return FunctionPtrAlign;
963 case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
964 return std::max(FunctionPtrAlign,
F->getAlign().valueOrOne());
967 }
else if (
auto *GVar = dyn_cast<GlobalVariable>(
this)) {
968 const MaybeAlign Alignment(GVar->getAlign());
970 Type *ObjectType = GVar->getValueType();
971 if (ObjectType->isSized()) {
975 if (GVar->isStrongDefinitionForLinker())
976 return DL.getPreferredAlign(GVar);
978 return DL.getABITypeAlign(ObjectType);
981 return Alignment.valueOrOne();
982 }
else if (
const Argument *
A = dyn_cast<Argument>(
this)) {
983 const MaybeAlign Alignment =
A->getParamAlign();
984 if (!Alignment &&
A->hasStructRetAttr()) {
986 Type *EltTy =
A->getParamStructRetType();
987 if (EltTy->isSized())
988 return DL.getABITypeAlign(EltTy);
991 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
this)) {
992 return AI->getAlign();
993 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
994 MaybeAlign Alignment =
Call->getRetAlign();
995 if (!Alignment &&
Call->getCalledFunction())
996 Alignment =
Call->getCalledFunction()->getAttributes().getRetAlignment();
998 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
999 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
1000 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
1003 }
else if (
auto *CE = dyn_cast<ConstantExpr>(
this)) {
1005 if (
CE->getOpcode() == Instruction::IntToPtr &&
1006 isa<ConstantInt>(
CE->getOperand(0))) {
1007 ConstantInt *IntPtr = cast<ConstantInt>(
CE->getOperand(0));
1011 return Align(TrailingZeros < Value::MaxAlignmentExponent
1012 ? uint64_t(1) << TrailingZeros
1013 : Value::MaximumAlignment);
1019static std::optional<int64_t>
1023 for (
unsigned i = 1; i != Idx; ++i, ++GTI)
1028 for (
unsigned i = Idx, e =
GEP->getNumOperands(); i != e; ++i, ++GTI) {
1029 ConstantInt *OpC = dyn_cast<ConstantInt>(
GEP->getOperand(i));
1031 return std::nullopt;
1044 if (
Size.isScalable())
1045 return std::nullopt;
1052std::optional<int64_t> Value::getPointerOffsetFrom(
const Value *Other,
1053 const DataLayout &
DL)
const {
1055 const Value *Ptr2 =
this;
1056 APInt Offset1(
DL.getIndexTypeSizeInBits(Ptr1->getType()), 0);
1057 APInt Offset2(
DL.getIndexTypeSizeInBits(Ptr2->getType()), 0);
1058 Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(
DL, Offset1,
true);
1059 Ptr2 = Ptr2->stripAndAccumulateConstantOffsets(
DL, Offset2,
true);
1063 return Offset2.getSExtValue() - Offset1.getSExtValue();
1065 const GEPOperator *GEP1 = dyn_cast<GEPOperator>(Ptr1);
1066 const GEPOperator *GEP2 = dyn_cast<GEPOperator>(Ptr2);
1075 return std::nullopt;
1085 if (!IOffset1 || !IOffset2)
1086 return std::nullopt;
1087 return *IOffset2 - *IOffset1 + Offset2.getSExtValue() -
1088 Offset1.getSExtValue();
1091const Value *Value::DoPHITranslation(
const BasicBlock *CurBB,
1092 const BasicBlock *PredBB)
const {
1093 auto *PN = dyn_cast<PHINode>(
this);
1094 if (PN && PN->getParent() == CurBB)
1095 return PN->getIncomingValueForBlock(PredBB);
1099LLVMContext &Value::getContext()
const {
return VTy->getContext(); }
1101void Value::reverseUseList() {
1102 if (!UseList || !UseList->Next)
1106 Use *Head = UseList;
1107 Use *Current = UseList->Next;
1108 Head->Next =
nullptr;
1111 Current->Next = Head;
1112 Head->Prev = &Current->Next;
1117 Head->Prev = &UseList;
1120bool Value::isSwiftError()
const {
1121 auto *Arg = dyn_cast<Argument>(
this);
1123 return Arg->hasSwiftErrorAttr();
1124 auto *Alloca = dyn_cast<AllocaInst>(
this);
1127 return Alloca->isSwiftError();
1134void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1135 assert(List &&
"Handle list is null?");
1142 Next->setPrevPtr(&Next);
1143 assert(getValPtr() ==
Next->getValPtr() &&
"Added to wrong list?");
1147void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1148 assert(List &&
"Must insert after existing node");
1151 setPrevPtr(&
List->Next);
1154 Next->setPrevPtr(&Next);
1157void ValueHandleBase::AddToUseList() {
1158 assert(getValPtr() &&
"Null pointer doesn't have a use list!");
1160 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1162 if (getValPtr()->HasValueHandle) {
1166 assert(Entry &&
"Value doesn't have any handles?");
1167 AddToExistingUseList(&Entry);
1176 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1179 ValueHandleBase *&
Entry = Handles[getValPtr()];
1180 assert(!Entry &&
"Value really did already have handles?");
1181 AddToExistingUseList(&Entry);
1182 getValPtr()->HasValueHandle =
true;
1187 Handles.
size() == 1) {
1192 for (DenseMap<Value*, ValueHandleBase*>::iterator
I = Handles.
begin(),
1193 E = Handles.
end();
I !=
E; ++
I) {
1194 assert(
I->second &&
I->first ==
I->second->getValPtr() &&
1195 "List invariant broken!");
1196 I->second->setPrevPtr(&
I->second);
1200void ValueHandleBase::RemoveFromUseList() {
1201 assert(getValPtr() && getValPtr()->HasValueHandle &&
1202 "Pointer doesn't have a use list!");
1205 ValueHandleBase **PrevPtr = getPrevPtr();
1206 assert(*PrevPtr ==
this &&
"List invariant broken");
1210 assert(
Next->getPrevPtr() == &Next &&
"List invariant broken");
1211 Next->setPrevPtr(PrevPtr);
1218 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1219 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1221 Handles.
erase(getValPtr());
1222 getValPtr()->HasValueHandle =
false;
1226void ValueHandleBase::ValueIsDeleted(
Value *V) {
1227 assert(
V->HasValueHandle &&
"Should only be called if ValueHandles present");
1231 LLVMContextImpl *pImpl =
V->getContext().pImpl;
1233 assert(Entry &&
"Value bit set but no entries exist");
1244 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1245 Iterator.RemoveFromUseList();
1246 Iterator.AddToExistingUseListAfter(Entry);
1247 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1249 switch (
Entry->getKind()) {
1256 Entry->operator=(
nullptr);
1260 static_cast<CallbackVH*
>(
Entry)->deleted();
1266 if (
V->HasValueHandle) {
1268 dbgs() <<
"While deleting: " << *
V->getType() <<
" %" <<
V->getName()
1279void ValueHandleBase::ValueIsRAUWd(
Value *Old,
Value *New) {
1280 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
1281 assert(Old != New &&
"Changing value into itself!");
1282 assert(Old->getType() ==
New->getType() &&
1283 "replaceAllUses of value with new value of different type!");
1287 LLVMContextImpl *pImpl = Old->getContext().pImpl;
1290 assert(Entry &&
"Value bit set but no entries exist");
1296 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1297 Iterator.RemoveFromUseList();
1298 Iterator.AddToExistingUseListAfter(Entry);
1299 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1301 switch (
Entry->getKind()) {
1312 static_cast<CallbackVH*
>(
Entry)->allUsesReplacedWith(New);
1320 if (Old->HasValueHandle)
1322 switch (
Entry->getKind()) {
1324 dbgs() <<
"After RAUW from " << *Old->getType() <<
" %"
1325 << Old->getName() <<
" to " << *
New->getType() <<
" %"
1326 <<
New->getName() <<
"\n";
1328 "A weak tracking value handle still pointed to the old value!\n");
1336void 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 bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
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 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.
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM_ABI bool isDroppable() const
A droppable user is a user for which uses can be dropped without affecting correctness and should be ...
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.