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())
866 if (
auto *ITP = dyn_cast<IntToPtrInst>(
this);
867 ITP && ITP->hasMetadata(LLVMContext::MD_nofree))
871 if (
auto *
I = dyn_cast<Instruction>(
this))
872 F =
I->getFunction();
873 if (
auto *
A = dyn_cast<Argument>(
this))
888 const auto &GCName =
F->getGC();
889 if (GCName ==
"statepoint-example") {
890 auto *PT = cast<PointerType>(this->
getType());
891 if (PT->getAddressSpace() != 1)
901 for (
auto &Fn : *
F->getParent())
902 if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
909uint64_t Value::getPointerDereferenceableBytes(
const DataLayout &
DL,
911 bool *CanBeFreed)
const {
914 uint64_t DerefBytes = 0;
916 bool CanNotBeFreed =
false;
917 if (
const Argument *
A = dyn_cast<Argument>(
this)) {
918 DerefBytes =
A->getDereferenceableBytes();
919 if (DerefBytes == 0) {
921 if (
Type *ArgMemTy =
A->getPointeeInMemoryValueType()) {
922 if (ArgMemTy->isSized()) {
924 DerefBytes =
DL.getTypeStoreSize(ArgMemTy).getKnownMinValue();
929 if (DerefBytes == 0) {
930 DerefBytes =
A->getDereferenceableOrNullBytes();
933 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
934 DerefBytes =
Call->getRetDereferenceableBytes();
935 if (DerefBytes == 0) {
936 DerefBytes =
Call->getRetDereferenceableOrNullBytes();
939 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
940 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
941 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
944 if (DerefBytes == 0) {
946 LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
947 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
952 }
else if (
auto *IP = dyn_cast<IntToPtrInst>(
this)) {
953 if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
954 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
957 if (DerefBytes == 0) {
959 IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
960 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
965 }
else if (
auto *AI = dyn_cast<AllocaInst>(
this)) {
966 if (std::optional<TypeSize>
Size = AI->getAllocationSize(
DL)) {
967 DerefBytes =
Size->getKnownMinValue();
969 CanNotBeFreed =
true;
971 }
else if (
auto *GV = dyn_cast<GlobalVariable>(
this)) {
975 DerefBytes =
DL.getTypeStoreSize(GV->
getValueType()).getFixedValue();
977 CanNotBeFreed =
true;
984 if (!CanNotBeFreed && DerefBytes != 0)
993Align Value::getPointerAlignment(
const DataLayout &
DL)
const {
995 if (
const Function *
F = dyn_cast<Function>(
this)) {
996 Align FunctionPtrAlign =
DL.getFunctionPtrAlign().valueOrOne();
997 switch (
DL.getFunctionPtrAlignType()) {
998 case DataLayout::FunctionPtrAlignType::Independent:
999 return FunctionPtrAlign;
1000 case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
1001 return std::max(FunctionPtrAlign,
F->getAlign().valueOrOne());
1004 }
else if (
auto *GVar = dyn_cast<GlobalVariable>(
this)) {
1005 const MaybeAlign Alignment(GVar->getAlign());
1007 Type *ObjectType = GVar->getValueType();
1008 if (ObjectType->isSized()) {
1012 if (GVar->isStrongDefinitionForLinker())
1013 return DL.getPreferredAlign(GVar);
1015 return DL.getABITypeAlign(ObjectType);
1018 return Alignment.valueOrOne();
1019 }
else if (
const Argument *
A = dyn_cast<Argument>(
this)) {
1020 const MaybeAlign Alignment =
A->getParamAlign();
1021 if (!Alignment &&
A->hasStructRetAttr()) {
1023 Type *EltTy =
A->getParamStructRetType();
1024 if (EltTy->isSized())
1025 return DL.getABITypeAlign(EltTy);
1028 }
else if (
const AllocaInst *AI = dyn_cast<AllocaInst>(
this)) {
1029 return AI->getAlign();
1030 }
else if (
const auto *
Call = dyn_cast<CallBase>(
this)) {
1031 MaybeAlign Alignment =
Call->getRetAlign();
1032 if (!Alignment &&
Call->getCalledFunction())
1033 Alignment =
Call->getCalledFunction()->getAttributes().getRetAlignment();
1035 }
else if (
const LoadInst *LI = dyn_cast<LoadInst>(
this)) {
1036 if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
1037 ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
1040 }
else if (
auto *CE = dyn_cast<ConstantExpr>(
this)) {
1042 if (
CE->getOpcode() == Instruction::IntToPtr &&
1043 isa<ConstantInt>(
CE->getOperand(0))) {
1044 ConstantInt *IntPtr = cast<ConstantInt>(
CE->getOperand(0));
1048 return Align(TrailingZeros < Value::MaxAlignmentExponent
1049 ? uint64_t(1) << TrailingZeros
1050 : Value::MaximumAlignment);
1056static std::optional<int64_t>
1060 for (
unsigned i = 1; i != Idx; ++i, ++GTI)
1065 for (
unsigned i = Idx, e =
GEP->getNumOperands(); i != e; ++i, ++GTI) {
1066 ConstantInt *OpC = dyn_cast<ConstantInt>(
GEP->getOperand(i));
1068 return std::nullopt;
1081 if (
Size.isScalable())
1082 return std::nullopt;
1089std::optional<int64_t> Value::getPointerOffsetFrom(
const Value *Other,
1090 const DataLayout &
DL)
const {
1092 const Value *Ptr2 =
this;
1093 APInt Offset1(
DL.getIndexTypeSizeInBits(Ptr1->getType()), 0);
1094 APInt Offset2(
DL.getIndexTypeSizeInBits(Ptr2->getType()), 0);
1095 Ptr1 = Ptr1->stripAndAccumulateConstantOffsets(
DL, Offset1,
true);
1096 Ptr2 = Ptr2->stripAndAccumulateConstantOffsets(
DL, Offset2,
true);
1100 return Offset2.getSExtValue() - Offset1.getSExtValue();
1102 const GEPOperator *GEP1 = dyn_cast<GEPOperator>(Ptr1);
1103 const GEPOperator *GEP2 = dyn_cast<GEPOperator>(Ptr2);
1112 return std::nullopt;
1122 if (!IOffset1 || !IOffset2)
1123 return std::nullopt;
1124 return *IOffset2 - *IOffset1 + Offset2.getSExtValue() -
1125 Offset1.getSExtValue();
1128const Value *Value::DoPHITranslation(
const BasicBlock *CurBB,
1129 const BasicBlock *PredBB)
const {
1130 auto *PN = dyn_cast<PHINode>(
this);
1131 if (PN && PN->getParent() == CurBB)
1132 return PN->getIncomingValueForBlock(PredBB);
1136void Value::reverseUseList() {
1137 if (!UseList || !UseList->Next)
1141 Use *Head = UseList;
1142 Use *Current = UseList->Next;
1143 Head->Next =
nullptr;
1146 Current->Next = Head;
1147 Head->Prev = &Current->Next;
1152 Head->Prev = &UseList;
1155bool Value::isSwiftError()
const {
1156 auto *Arg = dyn_cast<Argument>(
this);
1158 return Arg->hasSwiftErrorAttr();
1159 auto *Alloca = dyn_cast<AllocaInst>(
this);
1162 return Alloca->isSwiftError();
1169void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1170 assert(List &&
"Handle list is null?");
1177 Next->setPrevPtr(&Next);
1178 assert(getValPtr() ==
Next->getValPtr() &&
"Added to wrong list?");
1182void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1183 assert(List &&
"Must insert after existing node");
1186 setPrevPtr(&
List->Next);
1189 Next->setPrevPtr(&Next);
1192void ValueHandleBase::AddToUseList() {
1193 assert(getValPtr() &&
"Null pointer doesn't have a use list!");
1195 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1197 if (getValPtr()->HasValueHandle) {
1201 assert(Entry &&
"Value doesn't have any handles?");
1202 AddToExistingUseList(&Entry);
1211 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1214 ValueHandleBase *&
Entry = Handles[getValPtr()];
1215 assert(!Entry &&
"Value really did already have handles?");
1216 AddToExistingUseList(&Entry);
1217 getValPtr()->HasValueHandle =
true;
1222 Handles.
size() == 1) {
1227 for (
auto I = Handles.
begin(),
E = Handles.
end();
I !=
E; ++
I) {
1228 assert(
I->second &&
I->first ==
I->second->getValPtr() &&
1229 "List invariant broken!");
1230 I->second->setPrevPtr(&
I->second);
1234void ValueHandleBase::RemoveFromUseList() {
1235 assert(getValPtr() && getValPtr()->HasValueHandle &&
1236 "Pointer doesn't have a use list!");
1239 ValueHandleBase **PrevPtr = getPrevPtr();
1240 assert(*PrevPtr ==
this &&
"List invariant broken");
1244 assert(
Next->getPrevPtr() == &Next &&
"List invariant broken");
1245 Next->setPrevPtr(PrevPtr);
1252 LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1253 DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->
ValueHandles;
1256 Handles.
erase(getValPtr(), [](
auto &Bucket) {
1257 Bucket.second->setPrevPtr(&Bucket.second);
1259 getValPtr()->HasValueHandle =
false;
1263void ValueHandleBase::ValueIsDeleted(
Value *V) {
1264 assert(
V->HasValueHandle &&
"Should only be called if ValueHandles present");
1268 LLVMContextImpl *pImpl =
V->getContext().pImpl;
1270 assert(Entry &&
"Value bit set but no entries exist");
1281 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1282 Iterator.RemoveFromUseList();
1283 Iterator.AddToExistingUseListAfter(Entry);
1284 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1286 switch (
Entry->getKind()) {
1293 Entry->operator=(
nullptr);
1297 static_cast<CallbackVH*
>(
Entry)->deleted();
1303 if (
V->HasValueHandle) {
1305 dbgs() <<
"While deleting: " << *
V->getType() <<
" %" <<
V->getName()
1316void ValueHandleBase::ValueIsRAUWd(
Value *Old,
Value *New) {
1317 assert(Old->HasValueHandle &&
"Should only be called if ValueHandles present");
1318 assert(Old != New &&
"Changing value into itself!");
1319 assert(Old->getType() ==
New->getType() &&
1320 "replaceAllUses of value with new value of different type!");
1324 LLVMContextImpl *pImpl = Old->getContext().pImpl;
1327 assert(Entry &&
"Value bit set but no entries exist");
1333 for (ValueHandleBase Iterator(Assert, *Entry);
Entry;
Entry = Iterator.Next) {
1334 Iterator.RemoveFromUseList();
1335 Iterator.AddToExistingUseListAfter(Entry);
1336 assert(
Entry->Next == &Iterator &&
"Loop invariant broken.");
1338 switch (
Entry->getKind()) {
1349 static_cast<CallbackVH*
>(
Entry)->allUsesReplacedWith(New);
1357 if (Old->HasValueHandle)
1359 switch (
Entry->getKind()) {
1361 dbgs() <<
"After RAUW from " << *Old->getType() <<
" %"
1362 << Old->getName() <<
" to " << *
New->getType() <<
" %"
1363 <<
New->getName() <<
"\n";
1365 "A weak tracking value handle still pointed to the old value!\n");
1373void CallbackVH::anchor() {}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
This file defines the DenseMap class.
Module.h This file contains the declarations for the Module class.
Machine Check Debug Module
static StringRef getName(Value *V)
static std::optional< int64_t > getOffsetFromIndex(const GEPOperator *GEP, unsigned Idx, const DataLayout &DL)
static void NoopCallback(const Value *)
static bool contains(SmallPtrSetImpl< ConstantExpr * > &Cache, ConstantExpr *Expr, Constant *C)
static cl::opt< bool > UseDerefAtPointSemantics("use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false), cl::desc("Deref attributes and metadata infer facts at definition only"))
static Type * checkType(Type *Ty)
static bool getSymTab(Value *V, ValueSymbolTable *&ST)
static const Value * stripPointerCastsAndOffsets(const Value *V, function_ref< void(const Value *)> Func=NoopCallback< StripKind >)
static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB)
Replace debug record uses of MetadataAsValue(ValueAsMetadata(V)) outside BB with New.
static bool isUnDroppableUser(const User *U)
This file defines the SmallString class.
static SymbolRef::Type getType(const Symbol *Sym)
unsigned countr_zero() const
Count the number of trailing zero bits.
LLVM_ABI void replaceSuccessorsPhiUsesWith(BasicBlock *Old, BasicBlock *New)
Update all phi nodes in this basic block's successors to refer to basic block New instead of basic bl...
iterator begin()
Instruction iterator methods.
const Function * getParent() const
Return the enclosing method, or null if none.
bool hasAddressTaken() const
Returns true if there are any uses of this basic block other than direct branches,...
uint64_t getLimitedValue(uint64_t Limit=~0ULL) const
getLimitedValue - If the value is smaller than the specified limit, return it, otherwise return the l...
bool isZero() const
This is just a convenience method to make client code smaller for a common code.
int64_t getSExtValue() const
Return the constant as a 64-bit integer value after it has been sign extended as appropriate for the ...
uint64_t getZExtValue() const
Return the constant as a 64-bit unsigned integer value after it has been zero extended as appropriate...
const APInt & getValue() const
Return the constant as an APInt value reference.
LLVM_ABI const BasicBlock * getParent() const
bool erase(const KeyT &Val)
bool isPointerIntoBucketsArray(const void *Ptr) const
Return true if the specified pointer points somewhere into the DenseMap's array of buckets (i....
const void * getPointerIntoBucketsArray() const
getPointerIntoBucketsArray() - Return an opaque pointer into the buckets array.
LLVM_ABI Type * getSourceElementType() const
bool hasExternalWeakLinkage() const
Module * getParent()
Get the module that this global value is contained inside of...
Type * getValueType() const
DenseMap< const Value *, ValueName * > ValueNames
ValueHandlesTy ValueHandles
LLVMContextImpl *const pImpl
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void push_back(const T &Elt)
static StringMapEntry * create(StringRef key, AllocatorTy &allocator, InitTy &&...initVals)
constexpr bool empty() const
Check if the string is empty.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
bool isTriviallyEmpty() const
Check if this twine is trivially empty; a false return value does not necessarily mean the twine is e...
StringRef toStringRef(SmallVectorImpl< char > &Out) const
This returns the twine as a single StringRef if it can be represented as such.
bool isSized(SmallPtrSetImpl< Type * > *Visited=nullptr) const
Return true if it makes sense to take the size of this type.
LLVM_ABI bool isDroppable() const
A droppable user is a user for which uses can be dropped without affecting correctness and should be ...
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
LLVM_ABI Value(Type *Ty, unsigned scid)
LLVM_ABI ~Value()
Value's destructor should be virtual by design, but that would require that Value and all of its subc...
StructType * getStructTypeOrNull() const
TypeSize getSequentialElementStride(const DataLayout &DL) const
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
@ CE
Windows NT (Windows on ARM)
initializer< Ty > init(const Ty &Val)
llvm::unique_function< void(llvm::Expected< T >)> Callback
A Callback<T> is a void function that accepts Expected<T>.
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
NodeAddr< FuncNode * > Func
Context & getContext() const
This is an optimization pass for GlobalISel generic memory operations.
StringMapEntry< Value * > ValueName
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool hasNItemsOrMore(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has N or more items.
bool hasNItems(IterTy &&Begin, IterTy &&End, unsigned N, Pred &&ShouldBeCounted=[](const decltype(*std::declval< IterTy >()) &) { return true;}, std::enable_if_t< !std::is_base_of< std::random_access_iterator_tag, typename std::iterator_traits< std::remove_reference_t< decltype(Begin)> >::iterator_category >::value, void > *=nullptr)
Return true if the sequence [Begin, End) has exactly N items.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isPointerTy(const Type *T)
generic_gep_type_iterator<> gep_type_iterator
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
FunctionAddr VTableAddr Next
gep_type_iterator gep_type_begin(const User *GEP)
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI void findDbgUsers(Value *V, SmallVectorImpl< DbgVariableRecord * > &DbgVariableRecords)
Finds the debug info records describing a value.
StringMapEntry< uint32_t > * Tag
The operand bundle tag, interned by LLVMContextImpl::getOrInsertBundleTag.
Align valueOrOne() const
For convenience, returns a valid alignment or 1 if undefined.