42 cl::desc(
"Deref attributes and metadata infer facts at definition only"));
48 assert(Ty &&
"Value defined with a null type: Error!");
50 "Cannot have values with typed pointer types");
55 : SubclassID(scid), HasValueHandle(0), SubclassOptionalData(0),
56 SubclassData(0), NumUserOperands(0), IsUsedByMD(
false), HasName(
false),
58 static_assert(ConstantFirstVal == 0,
"!(SubclassID < ConstantFirstVal)");
63 if (SubclassID >= InstructionVal)
64 OpCode = SubclassID - InstructionVal;
65 if (OpCode == Instruction::Call || OpCode == Instruction::Invoke ||
66 OpCode == Instruction::CallBr)
67 assert((VTy->isFirstClassType() || VTy->isVoidTy() || VTy->isStructTy()) &&
68 "invalid CallBase type!");
69 else if (SubclassID != BasicBlockVal &&
70 ( SubclassID > ConstantLastVal))
71 assert((VTy->isFirstClassType() || VTy->isVoidTy()) &&
72 "Cannot create non-first-class values except for constants!");
73 static_assert(
sizeof(Value) == 2 *
sizeof(
void *) + 2 *
sizeof(
unsigned),
80 ValueHandleBase::ValueIsDeleted(
this);
81 if (isUsedByMetadata())
82 ValueAsMetadata::handleDeletion(
this);
94 if (!materialized_use_empty()) {
95 dbgs() <<
"While deleting: " << *VTy <<
" %" <<
getName() <<
"\n";
96 for (
auto *U :
users())
97 dbgs() <<
"Use still stuck around after Def is destroyed:" << *
U <<
"\n";
108void Value::deleteValue() {
109 switch (getValueID()) {
110#define HANDLE_VALUE(Name) \
111 case Value::Name##Val: \
112 delete static_cast<Name *>(this); \
114#define HANDLE_MEMORY_VALUE(Name) \
115 case Value::Name##Val: \
116 static_cast<DerivedUser *>(this)->DeleteValue( \
117 static_cast<DerivedUser *>(this)); \
119#define HANDLE_CONSTANT(Name) \
120 case Value::Name##Val: \
121 llvm_unreachable("constants should be destroyed with destroyConstant"); \
123#define HANDLE_INSTRUCTION(Name)
124#include "llvm/IR/Value.def"
126#define HANDLE_INST(N, OPC, CLASS) \
127 case addEnumValues(Value::InstructionVal, Instruction::OPC): \
128 delete static_cast<CLASS *>(this); \
130#define HANDLE_USER_INST(N, OPC, CLASS)
131#include "llvm/IR/Instruction.def"
138void Value::destroyValueName() {
144 setValueName(
nullptr);
147bool Value::hasNUses(
unsigned N)
const {
155bool Value::hasNUsesOrMore(
unsigned N)
const {
163bool Value::hasOneUser()
const {
168 return std::equal(++user_begin(), user_end(), user_begin());
173Use *Value::getSingleUndroppableUse() {
175 for (Use &U : uses()) {
176 if (!
U.getUser()->isDroppable()) {
185User *Value::getUniqueUndroppableUser() {
187 for (
auto *U :
users()) {
188 if (!
U->isDroppable()) {
189 if (Result && Result != U)
197bool Value::hasNUndroppableUses(
unsigned int N)
const {
201bool Value::hasNUndroppableUsesOrMore(
unsigned int N)
const {
205void Value::dropDroppableUses(
206 llvm::function_ref<
bool(
const Use *)> ShouldDrop) {
207 SmallVector<Use *, 8> ToBeEdited;
208 for (Use &U : uses())
209 if (
U.getUser()->isDroppable() && ShouldDrop(&U))
211 for (Use *U : ToBeEdited)
212 dropDroppableUse(*U);
215void Value::dropDroppableUsesIn(User &Usr) {
218 if (UsrOp.get() ==
this)
219 dropDroppableUse(UsrOp);
223void Value::dropDroppableUse(Use &U) {
224 if (
auto *Assume = dyn_cast<AssumeInst>(
U.getUser())) {
225 unsigned OpNo =
U.getOperandNo();
227 U.set(ConstantInt::getTrue(
Assume->getContext()));
229 U.set(PoisonValue::get(
U.get()->getType()));
230 CallInst::BundleOpInfo &BOI =
Assume->getBundleOpInfoForOperand(OpNo);
231 BOI.
Tag =
Assume->getContext().pImpl->getOrInsertBundleTag(
"ignore");
239bool Value::isUsedInBasicBlock(
const BasicBlock *BB)
const {
240 assert(hasUseList() &&
"ConstantData has no use-list");
248 BasicBlock::const_iterator BI = BB->
begin(), BE = BB->
end();
249 const_user_iterator UI = user_begin(), UE = user_end();
250 for (; BI != BE && UI != UE; ++BI, ++UI) {
255 const auto *
User = dyn_cast<Instruction>(*UI);
256 if (User &&
User->getParent() == BB)
262unsigned Value::getNumUses()
const {
266 return (
unsigned)std::distance(use_begin(), use_end());
271 if (Instruction *
I = dyn_cast<Instruction>(V)) {
272 if (BasicBlock *
P =
I->getParent())
273 if (Function *PP =
P->getParent())
274 ST = PP->getValueSymbolTable();
275 }
else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
277 ST =
P->getValueSymbolTable();
278 }
else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
279 if (
Module *
P = GV->getParent())
280 ST = &
P->getValueSymbolTable();
281 }
else if (Argument *
A = dyn_cast<Argument>(V)) {
282 if (Function *
P =
A->getParent())
283 ST =
P->getValueSymbolTable();
285 assert(isa<Constant>(V) &&
"Unknown value type!");
292 if (!HasName)
return nullptr;
297 "No name entry found!");
302void Value::setValueName(ValueName *VN) {
306 "HasName bit out of sync!");
319StringRef Value::getName()
const {
324 return StringRef(
"", 0);
325 return getValueName()->getKey();
328void Value::setNameImpl(
const Twine &NewName) {
330 !
getContext().shouldDiscardValueNames() || isa<GlobalValue>(
this);
334 if (!NeedNewName && !hasName())
341 SmallString<256> NameData;
342 StringRef NameRef = NeedNewName ? NewName.
toStringRef(NameData) :
"";
343 assert(!NameRef.
contains(0) &&
"Null bytes are not allowed in names");
349 assert(!
getType()->isVoidTy() &&
"Cannot assign a name to void values!");
352 ValueSymbolTable *
ST;
358 if (!NameRef.
empty()) {
369 setValueName(NewValueName);
370 getValueName()->setValue(
this);
375 if (!NameRef.
empty())
376 NewValueName =
ST->createValueName(NameRef,
this);
382 ST->removeValueName(getValueName());
390 assert(NeedNewName && NewValueName !=
nullptr);
391 setValueName(NewValueName);
394void Value::setName(
const Twine &NewName) {
395 setNameImpl(NewName);
396 if (Function *
F = dyn_cast<Function>(
this))
397 F->updateAfterNameChange();
400void Value::takeName(
Value *V) {
401 assert(V !=
this &&
"Illegal call to this->takeName(this)!");
402 ValueSymbolTable *
ST =
nullptr;
409 if (
V->hasName())
V->setName(
"");
415 ST->removeValueName(getValueName());
422 if (!
V->hasName())
return;
434 ValueSymbolTable *VST;
436 assert(!Failure &&
"V has a name, so it should have a ST!"); (void)Failure;
442 setValueName(
V->getValueName());
443 V->setValueName(
nullptr);
444 getValueName()->setValue(
this);
452 VST->removeValueName(
V->getValueName());
453 setValueName(
V->getValueName());
454 V->setValueName(
nullptr);
455 getValueName()->setValue(
this);
458 ST->reinsertValue(
this);
461std::string Value::getNameOrAsOperand()
const {
466 raw_string_ostream OS(BBName);
467 printAsOperand(OS,
false);
471void Value::assertModuleIsMaterializedImpl()
const {
473 const GlobalValue *GV = dyn_cast<GlobalValue>(
this);
484static bool contains(SmallPtrSetImpl<ConstantExpr *> &Cache, ConstantExpr *Expr,
486 if (!Cache.
insert(Expr).second)
492 auto *
CE = dyn_cast<ConstantExpr>(O);
505 auto *
C = dyn_cast<Constant>(V);
509 auto *
CE = dyn_cast<ConstantExpr>(Expr);
513 SmallPtrSet<ConstantExpr *, 4> Cache;
518void Value::doRAUW(
Value *New, ReplaceMetadataUses ReplaceMetaUses) {
519 assert(hasUseList() &&
"Cannot replace constant data");
520 assert(New &&
"Value::replaceAllUsesWith(<null>) is invalid!");
522 "this->replaceAllUsesWith(expr(this)) is NOT valid!");
524 "replaceAllUses of value with new value of different type!");
528 ValueHandleBase::ValueIsRAUWd(
this, New);
529 if (ReplaceMetaUses == ReplaceMetadataUses::Yes && isUsedByMetadata())
530 ValueAsMetadata::handleRAUW(
this, New);
532 while (!materialized_use_empty()) {
536 if (
auto *
C = dyn_cast<Constant>(
U.getUser())) {
537 if (!isa<GlobalValue>(
C)) {
538 C->handleOperandChange(
this, New);
546 if (BasicBlock *BB = dyn_cast<BasicBlock>(
this)) {
549 BlockAddress::lookup(BB)->handleOperandChange(
this, New);
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 const Value *Src = cast<Operator>(V)->getOperand(0);
789 if (!Src->getType()->isPtrOrPtrVectorTy())
792 }
else if (Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
793 V = cast<Operator>(V)->getOperand(0);
794 }
else if (
auto *GA = dyn_cast<GlobalAlias>(V)) {
795 if (!GA->isInterposable())
796 V = GA->getAliasee();
797 }
else if (
const auto *
Call = dyn_cast<CallBase>(V)) {
798 if (
const Value *RV =
Call->getReturnedArgOperand())
800 if (AllowInvariantGroup &&
Call->isLaunderOrStripInvariantGroup())
801 V =
Call->getArgOperand(0);
802 }
else if (
auto *Int2Ptr = dyn_cast<Operator>(V)) {
804 if (!AllowNonInbounds || !LookThroughIntToPtr || !Int2Ptr ||
805 Int2Ptr->getOpcode() != Instruction::IntToPtr ||
806 Int2Ptr->getOperand(0)->getType()->getScalarSizeInBits() !=
BitWidth)
809 auto *
Add = dyn_cast<AddOperator>(Int2Ptr->getOperand(0));
813 auto *Ptr2Int = dyn_cast<PtrToIntOperator>(
Add->getOperand(0));
814 auto *CI = dyn_cast<ConstantInt>(
Add->getOperand(1));
819 V = Ptr2Int->getOperand(0);
821 assert(
V->getType()->isPtrOrPtrVectorTy() &&
"Unexpected operand type!");
822 }
while (Visited.
insert(V).second);
828Value::stripInBoundsOffsets(function_ref<
void(
const Value *)> Func)
const {
832bool Value::canBeFreed()
const {
837 if (isa<Constant>(
this))
843 if (isa<AllocaInst>(
this))
848 if (
auto *
A = dyn_cast<Argument>(
this)) {
849 if (
A->hasPointeeInMemoryValueAttr())
856 if (
F->doesNotFreeMemory())
862 if ((
A->hasNoFreeAttr() ||
A->onlyReadsMemory()) &&
A->hasNoAliasAttr())
867 if (
A->hasAttribute(Attribute::NoFreeObj))
871 if (
auto *ITP = dyn_cast<IntToPtrInst>(
this);
872 ITP && ITP->hasMetadata(LLVMContext::MD_nofreeobj))
875 if (
auto *CB = dyn_cast<CallBase>(
this))
876 if (CB->hasRetAttr(Attribute::NoFreeObj))
880 if (
auto *
I = dyn_cast<Instruction>(
this))
881 F =
I->getFunction();
882 if (
auto *
A = dyn_cast<Argument>(
this))
897 const auto &GCName =
F->getGC();
898 if (GCName ==
"statepoint-example") {
899 auto *PT = cast<PointerType>(this->
getType());
900 if (PT->getAddressSpace() != 1)
910 for (
auto &Fn : *
F->getParent())
911 if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
918uint64_t Value::getPointerDereferenceableBytes(
const DataLayout &
DL,
920 bool *CanBeFreed)
const {
925 bool CanNotBeFreed =
false;
926 if (
const Argument *
A = dyn_cast<Argument>(
this)) {
927 DerefBytes =
A->getDereferenceableBytes();
928 if (DerefBytes == 0) {
930 if (
Type *ArgMemTy =
A->getPointeeInMemoryValueType()) {
931 if (ArgMemTy->isSized()) {
933 DerefBytes =
DL.getTypeStoreSize(ArgMemTy).getKnownMinValue();
938 if (DerefBytes == 0) {
939 DerefBytes =
A->getDereferenceableOrNullBytes();
942 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
943 DerefBytes =
Call->getRetDereferenceableBytes();
944 if (DerefBytes == 0) {
945 DerefBytes =
Call->getRetDereferenceableOrNullBytes();
948 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
949 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
950 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
953 if (DerefBytes == 0) {
955 LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
956 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
961 }
else if (
auto *IP = dyn_cast<IntToPtrInst>(
this)) {
962 if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
963 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
966 if (DerefBytes == 0) {
968 IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
969 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
974 }
else if (
auto *AI = dyn_cast<AllocaInst>(
this)) {
975 if (std::optional<TypeSize>
Size = AI->getAllocationSize(
DL)) {
976 DerefBytes =
Size->getKnownMinValue();
978 CanNotBeFreed =
true;
980 }
else if (
auto *GV = dyn_cast<GlobalVariable>(
this)) {
984 DerefBytes =
DL.getTypeStoreSize(GV->
getValueType()).getFixedValue();
986 CanNotBeFreed =
true;
993 if (!CanNotBeFreed && DerefBytes != 0)
1002Align Value::getPointerAlignment(
const DataLayout &
DL)
const {
1004 if (
const Function *
F = dyn_cast<Function>(
this)) {
1005 Align FunctionPtrAlign =
DL.getFunctionPtrAlign().valueOrOne();
1006 switch (
DL.getFunctionPtrAlignType()) {
1007 case DataLayout::FunctionPtrAlignType::Independent:
1008 return FunctionPtrAlign;
1009 case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
1010 return std::max(FunctionPtrAlign,
F->getAlign().valueOrOne());
1013 }
else if (
auto *GVar = dyn_cast<GlobalVariable>(
this)) {
1014 const MaybeAlign Alignment(GVar->getAlign());
1016 Type *ObjectType = GVar->getValueType();
1017 if (ObjectType->isSized()) {
1021 if (GVar->isStrongDefinitionForLinker())
1022 return DL.getPreferredAlign(GVar);
1024 return DL.getABITypeAlign(ObjectType);
1027 return Alignment.valueOrOne();
1028 }
else if (
const Argument *
A = dyn_cast<Argument>(
this)) {
1029 const MaybeAlign Alignment =
A->getParamAlign();
1030 if (!Alignment &&
A->hasStructRetAttr()) {
1032 Type *EltTy =
A->getParamStructRetType();
1033 if (EltTy->isSized())
1034 return DL.getABITypeAlign(EltTy);
1037 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
this)) {
1038 return AI->getAlign();
1039 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
1040 MaybeAlign Alignment =
Call->getRetAlign();
1041 if (!Alignment &&
Call->getCalledFunction())
1042 Alignment =
Call->getCalledFunction()->getAttributes().getRetAlignment();
1044 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
1045 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
1046 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
1049 }
else if (
auto *CE = dyn_cast<ConstantExpr>(
this)) {
1051 if (
CE->getOpcode() == Instruction::IntToPtr &&
1052 isa<ConstantInt>(
CE->getOperand(0))) {
1053 ConstantInt *IntPtr = cast<ConstantInt>(
CE->getOperand(0));
1057 return Align(TrailingZeros < Value::MaxAlignmentExponent
1059 : Value::MaximumAlignment);
1065static std::optional<int64_t>
1069 for (
unsigned i = 1; i != Idx; ++i, ++GTI)
1074 for (
unsigned i = Idx, e =
GEP->getNumOperands(); i != e; ++i, ++GTI) {
1075 ConstantInt *OpC = dyn_cast<ConstantInt>(
GEP->getOperand(i));
1077 return std::nullopt;
1090 if (
Size.isScalable())
1091 return std::nullopt;
1098std::optional<int64_t> Value::getPointerOffsetFrom(
const Value *Other,
1099 const DataLayout &
DL)
const {
1101 const Value *Ptr2 =
this;
1102 APInt Offset1(
DL.getIndexTypeSizeInBits(Ptr1->getType()), 0);
1103 APInt Offset2(
DL.getIndexTypeSizeInBits(Ptr2->getType()), 0);
1104 Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(
DL, Offset1,
true);
1105 Ptr2 = Ptr2->stripAndAccumulateConstantOffsets(
DL, Offset2,
true);
1109 return Offset2.getSExtValue() - Offset1.getSExtValue();
1111 const GEPOperator *GEP1 = dyn_cast<GEPOperator>(Ptr1);
1112 const GEPOperator *GEP2 = dyn_cast<GEPOperator>(Ptr2);
1121 return std::nullopt;
1131 if (!IOffset1 || !IOffset2)
1132 return std::nullopt;
1133 return *IOffset2 - *IOffset1 + Offset2.getSExtValue() -
1134 Offset1.getSExtValue();
1137const Value *Value::DoPHITranslation(
const BasicBlock *CurBB,
1138 const BasicBlock *PredBB)
const {
1139 auto *PN = dyn_cast<PHINode>(
this);
1140 if (PN && PN->getParent() == CurBB)
1141 return PN->getIncomingValueForBlock(PredBB);
1145void Value::reverseUseList() {
1146 if (!UseList || !UseList->Next)
1150 Use *Head = UseList;
1151 Use *Current = UseList->Next;
1152 Head->Next =
nullptr;
1155 Current->Next = Head;
1156 Head->Prev = &Current->Next;
1161 Head->Prev = &UseList;
1164bool Value::isSwiftError()
const {
1165 auto *Arg = dyn_cast<Argument>(
this);
1167 return Arg->hasSwiftErrorAttr();
1168 auto *Alloca = dyn_cast<AllocaInst>(
this);
1171 return Alloca->isSwiftError();
1178void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1179 assert(List &&
"Handle list is null?");
1186 Next->setPrevPtr(&Next);
1187 assert(getValPtr() ==
Next->getValPtr() &&
"Added to wrong list?");
1191void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1192 assert(List &&
"Must insert after existing node");
1195 setPrevPtr(&
List->Next);
1198 Next->setPrevPtr(&Next);
1201void ValueHandleBase::AddToUseList() {
1202 assert(getValPtr() &&
"Null pointer doesn't have a use list!");
1204 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1206 if (getValPtr()->HasValueHandle) {
1210 assert(Entry &&
"Value doesn't have any handles?");
1211 AddToExistingUseList(&Entry);
1220 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1223 ValueHandleBase *&
Entry = Handles[getValPtr()];
1224 assert(!Entry &&
"Value really did already have handles?");
1225 AddToExistingUseList(&Entry);
1226 getValPtr()->HasValueHandle =
true;
1231 Handles.
size() == 1) {
1236 for (
auto I = Handles.
begin(),
E = Handles.
end();
I !=
E; ++
I) {
1237 assert(
I->second &&
I->first ==
I->second->getValPtr() &&
1238 "List invariant broken!");
1239 I->second->setPrevPtr(&
I->second);
1243void ValueHandleBase::RemoveFromUseList() {
1244 assert(getValPtr() && getValPtr()->HasValueHandle &&
1245 "Pointer doesn't have a use list!");
1248 ValueHandleBase **PrevPtr = getPrevPtr();
1249 assert(*PrevPtr ==
this &&
"List invariant broken");
1253 assert(
Next->getPrevPtr() == &Next &&
"List invariant broken");
1254 Next->setPrevPtr(PrevPtr);
1261 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1262 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1265 Handles.
erase(getValPtr(), [](
auto &Bucket) {
1266 Bucket.second->setPrevPtr(&Bucket.second);
1268 getValPtr()->HasValueHandle =
false;
1272void ValueHandleBase::ValueIsDeleted(
Value *V) {
1273 assert(
V->HasValueHandle &&
"Should only be called if ValueHandles present");
1277 LLVMContextImpl *pImpl =
V->getContext().pImpl;
1279 assert(Entry &&
"Value bit set but no entries exist");
1290 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1291 Iterator.RemoveFromUseList();
1292 Iterator.AddToExistingUseListAfter(Entry);
1293 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1295 switch (
Entry->getKind()) {
1302 Entry->operator=(
nullptr);
1306 static_cast<CallbackVH*
>(
Entry)->deleted();
1312 if (
V->HasValueHandle) {
1314 dbgs() <<
"While deleting: " << *
V->getType() <<
" %" <<
V->getName()
1325void ValueHandleBase::ValueIsRAUWd(
Value *Old,
Value *New) {
1326 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
1327 assert(Old != New &&
"Changing value into itself!");
1328 assert(Old->getType() ==
New->getType() &&
1329 "replaceAllUses of value with new value of different type!");
1333 LLVMContextImpl *pImpl = Old->getContext().pImpl;
1336 assert(Entry &&
"Value bit set but no entries exist");
1342 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1343 Iterator.RemoveFromUseList();
1344 Iterator.AddToExistingUseListAfter(Entry);
1345 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1347 switch (
Entry->getKind()) {
1358 static_cast<CallbackVH*
>(
Entry)->allUsesReplacedWith(New);
1366 if (Old->HasValueHandle)
1368 switch (
Entry->getKind()) {
1370 dbgs() <<
"After RAUW from " << *Old->getType() <<
" %"
1371 << Old->getName() <<
" to " << *
New->getType() <<
" %"
1372 <<
New->getName() <<
"\n";
1374 "A weak tracking value handle still pointed to the old value!\n");
1382void 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)
Func getContext().diagnose(DiagnosticInfoUnsupported(Func
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 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 cl::opt< bool > UseDerefAtPointSemantics("use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(true), cl::desc("Deref attributes and metadata infer facts at definition only"))
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
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...
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.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Next
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.