xref: /llvm-project-15.0.7/llvm/lib/IR/Value.cpp (revision a54f4eae)
1 //===-- Value.cpp - Implement the Value class -----------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements the Value, ValueHandle, and User classes.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/IR/Value.h"
14 #include "LLVMContextImpl.h"
15 #include "llvm/ADT/DenseMap.h"
16 #include "llvm/ADT/SetVector.h"
17 #include "llvm/ADT/SmallString.h"
18 #include "llvm/IR/Constant.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/DataLayout.h"
21 #include "llvm/IR/DebugInfo.h"
22 #include "llvm/IR/DerivedTypes.h"
23 #include "llvm/IR/DerivedUser.h"
24 #include "llvm/IR/GetElementPtrTypeIterator.h"
25 #include "llvm/IR/InstrTypes.h"
26 #include "llvm/IR/Instructions.h"
27 #include "llvm/IR/IntrinsicInst.h"
28 #include "llvm/IR/Module.h"
29 #include "llvm/IR/Operator.h"
30 #include "llvm/IR/ValueHandle.h"
31 #include "llvm/IR/ValueSymbolTable.h"
32 #include "llvm/Support/CommandLine.h"
33 #include "llvm/Support/Debug.h"
34 #include "llvm/Support/ErrorHandling.h"
35 #include "llvm/Support/ManagedStatic.h"
36 #include "llvm/Support/raw_ostream.h"
37 #include <algorithm>
38 
39 using namespace llvm;
40 
41 static cl::opt<unsigned> UseDerefAtPointSemantics(
42     "use-dereferenceable-at-point-semantics", cl::Hidden, cl::init(false),
43     cl::desc("Deref attributes and metadata infer facts at definition only"));
44 
45 //===----------------------------------------------------------------------===//
46 //                                Value Class
47 //===----------------------------------------------------------------------===//
48 static inline Type *checkType(Type *Ty) {
49   assert(Ty && "Value defined with a null type: Error!");
50   return Ty;
51 }
52 
53 Value::Value(Type *ty, unsigned scid)
54     : VTy(checkType(ty)), UseList(nullptr), SubclassID(scid), HasValueHandle(0),
55       SubclassOptionalData(0), SubclassData(0), NumUserOperands(0),
56       IsUsedByMD(false), HasName(false), HasMetadata(false) {
57   static_assert(ConstantFirstVal == 0, "!(SubclassID < ConstantFirstVal)");
58   // FIXME: Why isn't this in the subclass gunk??
59   // Note, we cannot call isa<CallInst> before the CallInst has been
60   // constructed.
61   unsigned OpCode = 0;
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 < ConstantFirstVal ||*/ 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),
73                 "Value too big");
74 }
75 
76 Value::~Value() {
77   // Notify all ValueHandles (if present) that this value is going away.
78   if (HasValueHandle)
79     ValueHandleBase::ValueIsDeleted(this);
80   if (isUsedByMetadata())
81     ValueAsMetadata::handleDeletion(this);
82 
83   // Remove associated metadata from context.
84   if (HasMetadata)
85     clearMetadata();
86 
87 #ifndef NDEBUG      // Only in -g mode...
88   // Check to make sure that there are no uses of this value that are still
89   // around when the value is destroyed.  If there are, then we have a dangling
90   // reference and something is wrong.  This code is here to print out where
91   // the value is still being referenced.
92   //
93   // Note that use_empty() cannot be called here, as it eventually downcasts
94   // 'this' to GlobalValue (derived class of Value), but GlobalValue has already
95   // been destructed, so accessing it is UB.
96   //
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";
101   }
102 #endif
103   assert(materialized_use_empty() && "Uses remain when a value is destroyed!");
104 
105   // If this value is named, destroy the name.  This should not be in a symtab
106   // at this point.
107   destroyValueName();
108 }
109 
110 void Value::deleteValue() {
111   switch (getValueID()) {
112 #define HANDLE_VALUE(Name)                                                     \
113   case Value::Name##Val:                                                       \
114     delete static_cast<Name *>(this);                                          \
115     break;
116 #define HANDLE_MEMORY_VALUE(Name)                                              \
117   case Value::Name##Val:                                                       \
118     static_cast<DerivedUser *>(this)->DeleteValue(                             \
119         static_cast<DerivedUser *>(this));                                     \
120     break;
121 #define HANDLE_CONSTANT(Name)                                                  \
122   case Value::Name##Val:                                                       \
123     llvm_unreachable("constants should be destroyed with destroyConstant");    \
124     break;
125 #define HANDLE_INSTRUCTION(Name)  /* nothing */
126 #include "llvm/IR/Value.def"
127 
128 #define HANDLE_INST(N, OPC, CLASS)                                             \
129   case Value::InstructionVal + Instruction::OPC:                               \
130     delete static_cast<CLASS *>(this);                                         \
131     break;
132 #define HANDLE_USER_INST(N, OPC, CLASS)
133 #include "llvm/IR/Instruction.def"
134 
135   default:
136     llvm_unreachable("attempting to delete unknown value kind");
137   }
138 }
139 
140 void Value::destroyValueName() {
141   ValueName *Name = getValueName();
142   if (Name) {
143     MallocAllocator Allocator;
144     Name->Destroy(Allocator);
145   }
146   setValueName(nullptr);
147 }
148 
149 bool Value::hasNUses(unsigned N) const {
150   return hasNItems(use_begin(), use_end(), N);
151 }
152 
153 bool Value::hasNUsesOrMore(unsigned N) const {
154   return hasNItemsOrMore(use_begin(), use_end(), N);
155 }
156 
157 bool Value::hasOneUser() const {
158   if (use_empty())
159     return false;
160   if (hasOneUse())
161     return true;
162   return std::equal(++user_begin(), user_end(), user_begin());
163 }
164 
165 static bool isUnDroppableUser(const User *U) { return !U->isDroppable(); }
166 
167 Use *Value::getSingleUndroppableUse() {
168   Use *Result = nullptr;
169   for (Use &U : uses()) {
170     if (!U.getUser()->isDroppable()) {
171       if (Result)
172         return nullptr;
173       Result = &U;
174     }
175   }
176   return Result;
177 }
178 
179 User *Value::getUniqueUndroppableUser() {
180   User *Result = nullptr;
181   for (auto *U : users()) {
182     if (!U->isDroppable()) {
183       if (Result && Result != U)
184         return nullptr;
185       Result = U;
186     }
187   }
188   return Result;
189 }
190 
191 bool Value::hasNUndroppableUses(unsigned int N) const {
192   return hasNItems(user_begin(), user_end(), N, isUnDroppableUser);
193 }
194 
195 bool Value::hasNUndroppableUsesOrMore(unsigned int N) const {
196   return hasNItemsOrMore(user_begin(), user_end(), N, isUnDroppableUser);
197 }
198 
199 void Value::dropDroppableUses(
200     llvm::function_ref<bool(const Use *)> ShouldDrop) {
201   SmallVector<Use *, 8> ToBeEdited;
202   for (Use &U : uses())
203     if (U.getUser()->isDroppable() && ShouldDrop(&U))
204       ToBeEdited.push_back(&U);
205   for (Use *U : ToBeEdited)
206     dropDroppableUse(*U);
207 }
208 
209 void Value::dropDroppableUsesIn(User &Usr) {
210   assert(Usr.isDroppable() && "Expected a droppable user!");
211   for (Use &UsrOp : Usr.operands()) {
212     if (UsrOp.get() == this)
213       dropDroppableUse(UsrOp);
214   }
215 }
216 
217 void Value::dropDroppableUse(Use &U) {
218   U.removeFromList();
219   if (auto *Assume = dyn_cast<AssumeInst>(U.getUser())) {
220     unsigned OpNo = U.getOperandNo();
221     if (OpNo == 0)
222       U.set(ConstantInt::getTrue(Assume->getContext()));
223     else {
224       U.set(UndefValue::get(U.get()->getType()));
225       CallInst::BundleOpInfo &BOI = Assume->getBundleOpInfoForOperand(OpNo);
226       BOI.Tag = Assume->getContext().pImpl->getOrInsertBundleTag("ignore");
227     }
228     return;
229   }
230 
231   llvm_unreachable("unkown droppable use");
232 }
233 
234 bool Value::isUsedInBasicBlock(const BasicBlock *BB) const {
235   // This can be computed either by scanning the instructions in BB, or by
236   // scanning the use list of this Value. Both lists can be very long, but
237   // usually one is quite short.
238   //
239   // Scan both lists simultaneously until one is exhausted. This limits the
240   // search to the shorter list.
241   BasicBlock::const_iterator BI = BB->begin(), BE = BB->end();
242   const_user_iterator UI = user_begin(), UE = user_end();
243   for (; BI != BE && UI != UE; ++BI, ++UI) {
244     // Scan basic block: Check if this Value is used by the instruction at BI.
245     if (is_contained(BI->operands(), this))
246       return true;
247     // Scan use list: Check if the use at UI is in BB.
248     const auto *User = dyn_cast<Instruction>(*UI);
249     if (User && User->getParent() == BB)
250       return true;
251   }
252   return false;
253 }
254 
255 unsigned Value::getNumUses() const {
256   return (unsigned)std::distance(use_begin(), use_end());
257 }
258 
259 static bool getSymTab(Value *V, ValueSymbolTable *&ST) {
260   ST = nullptr;
261   if (Instruction *I = dyn_cast<Instruction>(V)) {
262     if (BasicBlock *P = I->getParent())
263       if (Function *PP = P->getParent())
264         ST = PP->getValueSymbolTable();
265   } else if (BasicBlock *BB = dyn_cast<BasicBlock>(V)) {
266     if (Function *P = BB->getParent())
267       ST = P->getValueSymbolTable();
268   } else if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
269     if (Module *P = GV->getParent())
270       ST = &P->getValueSymbolTable();
271   } else if (Argument *A = dyn_cast<Argument>(V)) {
272     if (Function *P = A->getParent())
273       ST = P->getValueSymbolTable();
274   } else {
275     assert(isa<Constant>(V) && "Unknown value type!");
276     return true;  // no name is setable for this.
277   }
278   return false;
279 }
280 
281 ValueName *Value::getValueName() const {
282   if (!HasName) return nullptr;
283 
284   LLVMContext &Ctx = getContext();
285   auto I = Ctx.pImpl->ValueNames.find(this);
286   assert(I != Ctx.pImpl->ValueNames.end() &&
287          "No name entry found!");
288 
289   return I->second;
290 }
291 
292 void Value::setValueName(ValueName *VN) {
293   LLVMContext &Ctx = getContext();
294 
295   assert(HasName == Ctx.pImpl->ValueNames.count(this) &&
296          "HasName bit out of sync!");
297 
298   if (!VN) {
299     if (HasName)
300       Ctx.pImpl->ValueNames.erase(this);
301     HasName = false;
302     return;
303   }
304 
305   HasName = true;
306   Ctx.pImpl->ValueNames[this] = VN;
307 }
308 
309 StringRef Value::getName() const {
310   // Make sure the empty string is still a C string. For historical reasons,
311   // some clients want to call .data() on the result and expect it to be null
312   // terminated.
313   if (!hasName())
314     return StringRef("", 0);
315   return getValueName()->getKey();
316 }
317 
318 void Value::setNameImpl(const Twine &NewName) {
319   // Fast-path: LLVMContext can be set to strip out non-GlobalValue names
320   if (getContext().shouldDiscardValueNames() && !isa<GlobalValue>(this))
321     return;
322 
323   // Fast path for common IRBuilder case of setName("") when there is no name.
324   if (NewName.isTriviallyEmpty() && !hasName())
325     return;
326 
327   SmallString<256> NameData;
328   StringRef NameRef = NewName.toStringRef(NameData);
329   assert(NameRef.find_first_of(0) == StringRef::npos &&
330          "Null bytes are not allowed in names");
331 
332   // Name isn't changing?
333   if (getName() == NameRef)
334     return;
335 
336   assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
337 
338   // Get the symbol table to update for this object.
339   ValueSymbolTable *ST;
340   if (getSymTab(this, ST))
341     return;  // Cannot set a name on this value (e.g. constant).
342 
343   if (!ST) { // No symbol table to update?  Just do the change.
344     if (NameRef.empty()) {
345       // Free the name for this value.
346       destroyValueName();
347       return;
348     }
349 
350     // NOTE: Could optimize for the case the name is shrinking to not deallocate
351     // then reallocated.
352     destroyValueName();
353 
354     // Create the new name.
355     MallocAllocator Allocator;
356     setValueName(ValueName::Create(NameRef, Allocator));
357     getValueName()->setValue(this);
358     return;
359   }
360 
361   // NOTE: Could optimize for the case the name is shrinking to not deallocate
362   // then reallocated.
363   if (hasName()) {
364     // Remove old name.
365     ST->removeValueName(getValueName());
366     destroyValueName();
367 
368     if (NameRef.empty())
369       return;
370   }
371 
372   // Name is changing to something new.
373   setValueName(ST->createValueName(NameRef, this));
374 }
375 
376 void Value::setName(const Twine &NewName) {
377   setNameImpl(NewName);
378   if (Function *F = dyn_cast<Function>(this))
379     F->recalculateIntrinsicID();
380 }
381 
382 void Value::takeName(Value *V) {
383   ValueSymbolTable *ST = nullptr;
384   // If this value has a name, drop it.
385   if (hasName()) {
386     // Get the symtab this is in.
387     if (getSymTab(this, ST)) {
388       // We can't set a name on this value, but we need to clear V's name if
389       // it has one.
390       if (V->hasName()) V->setName("");
391       return;  // Cannot set a name on this value (e.g. constant).
392     }
393 
394     // Remove old name.
395     if (ST)
396       ST->removeValueName(getValueName());
397     destroyValueName();
398   }
399 
400   // Now we know that this has no name.
401 
402   // If V has no name either, we're done.
403   if (!V->hasName()) return;
404 
405   // Get this's symtab if we didn't before.
406   if (!ST) {
407     if (getSymTab(this, ST)) {
408       // Clear V's name.
409       V->setName("");
410       return;  // Cannot set a name on this value (e.g. constant).
411     }
412   }
413 
414   // Get V's ST, this should always succed, because V has a name.
415   ValueSymbolTable *VST;
416   bool Failure = getSymTab(V, VST);
417   assert(!Failure && "V has a name, so it should have a ST!"); (void)Failure;
418 
419   // If these values are both in the same symtab, we can do this very fast.
420   // This works even if both values have no symtab yet.
421   if (ST == VST) {
422     // Take the name!
423     setValueName(V->getValueName());
424     V->setValueName(nullptr);
425     getValueName()->setValue(this);
426     return;
427   }
428 
429   // Otherwise, things are slightly more complex.  Remove V's name from VST and
430   // then reinsert it into ST.
431 
432   if (VST)
433     VST->removeValueName(V->getValueName());
434   setValueName(V->getValueName());
435   V->setValueName(nullptr);
436   getValueName()->setValue(this);
437 
438   if (ST)
439     ST->reinsertValue(this);
440 }
441 
442 #ifndef NDEBUG
443 std::string Value::getNameOrAsOperand() const {
444   if (!getName().empty())
445     return std::string(getName());
446 
447   std::string BBName;
448   raw_string_ostream OS(BBName);
449   printAsOperand(OS, false);
450   return OS.str();
451 }
452 #endif
453 
454 void Value::assertModuleIsMaterializedImpl() const {
455 #ifndef NDEBUG
456   const GlobalValue *GV = dyn_cast<GlobalValue>(this);
457   if (!GV)
458     return;
459   const Module *M = GV->getParent();
460   if (!M)
461     return;
462   assert(M->isMaterialized());
463 #endif
464 }
465 
466 #ifndef NDEBUG
467 static bool contains(SmallPtrSetImpl<ConstantExpr *> &Cache, ConstantExpr *Expr,
468                      Constant *C) {
469   if (!Cache.insert(Expr).second)
470     return false;
471 
472   for (auto &O : Expr->operands()) {
473     if (O == C)
474       return true;
475     auto *CE = dyn_cast<ConstantExpr>(O);
476     if (!CE)
477       continue;
478     if (contains(Cache, CE, C))
479       return true;
480   }
481   return false;
482 }
483 
484 static bool contains(Value *Expr, Value *V) {
485   if (Expr == V)
486     return true;
487 
488   auto *C = dyn_cast<Constant>(V);
489   if (!C)
490     return false;
491 
492   auto *CE = dyn_cast<ConstantExpr>(Expr);
493   if (!CE)
494     return false;
495 
496   SmallPtrSet<ConstantExpr *, 4> Cache;
497   return contains(Cache, CE, C);
498 }
499 #endif // NDEBUG
500 
501 void Value::doRAUW(Value *New, ReplaceMetadataUses ReplaceMetaUses) {
502   assert(New && "Value::replaceAllUsesWith(<null>) is invalid!");
503   assert(!contains(New, this) &&
504          "this->replaceAllUsesWith(expr(this)) is NOT valid!");
505   assert(New->getType() == getType() &&
506          "replaceAllUses of value with new value of different type!");
507 
508   // Notify all ValueHandles (if present) that this value is going away.
509   if (HasValueHandle)
510     ValueHandleBase::ValueIsRAUWd(this, New);
511   if (ReplaceMetaUses == ReplaceMetadataUses::Yes && isUsedByMetadata())
512     ValueAsMetadata::handleRAUW(this, New);
513 
514   while (!materialized_use_empty()) {
515     Use &U = *UseList;
516     // Must handle Constants specially, we cannot call replaceUsesOfWith on a
517     // constant because they are uniqued.
518     if (auto *C = dyn_cast<Constant>(U.getUser())) {
519       if (!isa<GlobalValue>(C)) {
520         C->handleOperandChange(this, New);
521         continue;
522       }
523     }
524 
525     U.set(New);
526   }
527 
528   if (BasicBlock *BB = dyn_cast<BasicBlock>(this))
529     BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
530 }
531 
532 void Value::replaceAllUsesWith(Value *New) {
533   doRAUW(New, ReplaceMetadataUses::Yes);
534 }
535 
536 void Value::replaceNonMetadataUsesWith(Value *New) {
537   doRAUW(New, ReplaceMetadataUses::No);
538 }
539 
540 void Value::replaceUsesWithIf(Value *New,
541                               llvm::function_ref<bool(Use &U)> ShouldReplace) {
542   assert(New && "Value::replaceUsesWithIf(<null>) is invalid!");
543   assert(New->getType() == getType() &&
544          "replaceUses of value with new value of different type!");
545 
546   SmallVector<TrackingVH<Constant>, 8> Consts;
547   SmallPtrSet<Constant *, 8> Visited;
548 
549   for (use_iterator UI = use_begin(), E = use_end(); UI != E;) {
550     Use &U = *UI;
551     ++UI;
552     if (!ShouldReplace(U))
553       continue;
554     // Must handle Constants specially, we cannot call replaceUsesOfWith on a
555     // constant because they are uniqued.
556     if (auto *C = dyn_cast<Constant>(U.getUser())) {
557       if (!isa<GlobalValue>(C)) {
558         if (Visited.insert(C).second)
559           Consts.push_back(TrackingVH<Constant>(C));
560         continue;
561       }
562     }
563     U.set(New);
564   }
565 
566   while (!Consts.empty()) {
567     // FIXME: handleOperandChange() updates all the uses in a given Constant,
568     //        not just the one passed to ShouldReplace
569     Consts.pop_back_val()->handleOperandChange(this, New);
570   }
571 }
572 
573 /// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
574 /// with New.
575 static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB) {
576   SmallVector<DbgVariableIntrinsic *> DbgUsers;
577   findDbgUsers(DbgUsers, V);
578   for (auto *DVI : DbgUsers) {
579     if (DVI->getParent() != BB)
580       DVI->replaceVariableLocationOp(V, New);
581   }
582 }
583 
584 // Like replaceAllUsesWith except it does not handle constants or basic blocks.
585 // This routine leaves uses within BB.
586 void Value::replaceUsesOutsideBlock(Value *New, BasicBlock *BB) {
587   assert(New && "Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
588   assert(!contains(New, this) &&
589          "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
590   assert(New->getType() == getType() &&
591          "replaceUses of value with new value of different type!");
592   assert(BB && "Basic block that may contain a use of 'New' must be defined\n");
593 
594   replaceDbgUsesOutsideBlock(this, New, BB);
595   replaceUsesWithIf(New, [BB](Use &U) {
596     auto *I = dyn_cast<Instruction>(U.getUser());
597     // Don't replace if it's an instruction in the BB basic block.
598     return !I || I->getParent() != BB;
599   });
600 }
601 
602 namespace {
603 // Various metrics for how much to strip off of pointers.
604 enum PointerStripKind {
605   PSK_ZeroIndices,
606   PSK_ZeroIndicesAndAliases,
607   PSK_ZeroIndicesSameRepresentation,
608   PSK_ForAliasAnalysis,
609   PSK_InBoundsConstantIndices,
610   PSK_InBounds
611 };
612 
613 template <PointerStripKind StripKind> static void NoopCallback(const Value *) {}
614 
615 template <PointerStripKind StripKind>
616 static const Value *stripPointerCastsAndOffsets(
617     const Value *V,
618     function_ref<void(const Value *)> Func = NoopCallback<StripKind>) {
619   if (!V->getType()->isPointerTy())
620     return V;
621 
622   // Even though we don't look through PHI nodes, we could be called on an
623   // instruction in an unreachable block, which may be on a cycle.
624   SmallPtrSet<const Value *, 4> Visited;
625 
626   Visited.insert(V);
627   do {
628     Func(V);
629     if (auto *GEP = dyn_cast<GEPOperator>(V)) {
630       switch (StripKind) {
631       case PSK_ZeroIndices:
632       case PSK_ZeroIndicesAndAliases:
633       case PSK_ZeroIndicesSameRepresentation:
634       case PSK_ForAliasAnalysis:
635         if (!GEP->hasAllZeroIndices())
636           return V;
637         break;
638       case PSK_InBoundsConstantIndices:
639         if (!GEP->hasAllConstantIndices())
640           return V;
641         LLVM_FALLTHROUGH;
642       case PSK_InBounds:
643         if (!GEP->isInBounds())
644           return V;
645         break;
646       }
647       V = GEP->getPointerOperand();
648     } else if (Operator::getOpcode(V) == Instruction::BitCast) {
649       V = cast<Operator>(V)->getOperand(0);
650       if (!V->getType()->isPointerTy())
651         return V;
652     } else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
653                Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
654       // TODO: If we know an address space cast will not change the
655       //       representation we could look through it here as well.
656       V = cast<Operator>(V)->getOperand(0);
657     } else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
658       V = cast<GlobalAlias>(V)->getAliasee();
659     } else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
660                cast<PHINode>(V)->getNumIncomingValues() == 1) {
661       V = cast<PHINode>(V)->getIncomingValue(0);
662     } else {
663       if (const auto *Call = dyn_cast<CallBase>(V)) {
664         if (const Value *RV = Call->getReturnedArgOperand()) {
665           V = RV;
666           continue;
667         }
668         // The result of launder.invariant.group must alias it's argument,
669         // but it can't be marked with returned attribute, that's why it needs
670         // special case.
671         if (StripKind == PSK_ForAliasAnalysis &&
672             (Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
673              Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
674           V = Call->getArgOperand(0);
675           continue;
676         }
677       }
678       return V;
679     }
680     assert(V->getType()->isPointerTy() && "Unexpected operand type!");
681   } while (Visited.insert(V).second);
682 
683   return V;
684 }
685 } // end anonymous namespace
686 
687 const Value *Value::stripPointerCasts() const {
688   return stripPointerCastsAndOffsets<PSK_ZeroIndices>(this);
689 }
690 
691 const Value *Value::stripPointerCastsAndAliases() const {
692   return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(this);
693 }
694 
695 const Value *Value::stripPointerCastsSameRepresentation() const {
696   return stripPointerCastsAndOffsets<PSK_ZeroIndicesSameRepresentation>(this);
697 }
698 
699 const Value *Value::stripInBoundsConstantOffsets() const {
700   return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(this);
701 }
702 
703 const Value *Value::stripPointerCastsForAliasAnalysis() const {
704   return stripPointerCastsAndOffsets<PSK_ForAliasAnalysis>(this);
705 }
706 
707 const Value *Value::stripAndAccumulateConstantOffsets(
708     const DataLayout &DL, APInt &Offset, bool AllowNonInbounds,
709     function_ref<bool(Value &, APInt &)> ExternalAnalysis) const {
710   if (!getType()->isPtrOrPtrVectorTy())
711     return this;
712 
713   unsigned BitWidth = Offset.getBitWidth();
714   assert(BitWidth == DL.getIndexTypeSizeInBits(getType()) &&
715          "The offset bit width does not match the DL specification.");
716 
717   // Even though we don't look through PHI nodes, we could be called on an
718   // instruction in an unreachable block, which may be on a cycle.
719   SmallPtrSet<const Value *, 4> Visited;
720   Visited.insert(this);
721   const Value *V = this;
722   do {
723     if (auto *GEP = dyn_cast<GEPOperator>(V)) {
724       // If in-bounds was requested, we do not strip non-in-bounds GEPs.
725       if (!AllowNonInbounds && !GEP->isInBounds())
726         return V;
727 
728       // If one of the values we have visited is an addrspacecast, then
729       // the pointer type of this GEP may be different from the type
730       // of the Ptr parameter which was passed to this function.  This
731       // means when we construct GEPOffset, we need to use the size
732       // of GEP's pointer type rather than the size of the original
733       // pointer type.
734       APInt GEPOffset(DL.getIndexTypeSizeInBits(V->getType()), 0);
735       if (!GEP->accumulateConstantOffset(DL, GEPOffset, ExternalAnalysis))
736         return V;
737 
738       // Stop traversal if the pointer offset wouldn't fit in the bit-width
739       // provided by the Offset argument. This can happen due to AddrSpaceCast
740       // stripping.
741       if (GEPOffset.getMinSignedBits() > BitWidth)
742         return V;
743 
744       // External Analysis can return a result higher/lower than the value
745       // represents. We need to detect overflow/underflow.
746       APInt GEPOffsetST = GEPOffset.sextOrTrunc(BitWidth);
747       if (!ExternalAnalysis) {
748         Offset += GEPOffsetST;
749       } else {
750         bool Overflow = false;
751         APInt OldOffset = Offset;
752         Offset = Offset.sadd_ov(GEPOffsetST, Overflow);
753         if (Overflow) {
754           Offset = OldOffset;
755           return V;
756         }
757       }
758       V = GEP->getPointerOperand();
759     } else if (Operator::getOpcode(V) == Instruction::BitCast ||
760                Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
761       V = cast<Operator>(V)->getOperand(0);
762     } else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
763       if (!GA->isInterposable())
764         V = GA->getAliasee();
765     } else if (const auto *Call = dyn_cast<CallBase>(V)) {
766         if (const Value *RV = Call->getReturnedArgOperand())
767           V = RV;
768     }
769     assert(V->getType()->isPtrOrPtrVectorTy() && "Unexpected operand type!");
770   } while (Visited.insert(V).second);
771 
772   return V;
773 }
774 
775 const Value *
776 Value::stripInBoundsOffsets(function_ref<void(const Value *)> Func) const {
777   return stripPointerCastsAndOffsets<PSK_InBounds>(this, Func);
778 }
779 
780 bool Value::canBeFreed() const {
781   assert(getType()->isPointerTy());
782 
783   // Cases that can simply never be deallocated
784   // *) Constants aren't allocated per se, thus not deallocated either.
785   if (isa<Constant>(this))
786     return false;
787 
788   // Handle byval/byref/sret/inalloca/preallocated arguments.  The storage
789   // lifetime is guaranteed to be longer than the callee's lifetime.
790   if (auto *A = dyn_cast<Argument>(this)) {
791     if (A->hasPointeeInMemoryValueAttr())
792       return false;
793     // A pointer to an object in a function which neither frees, nor can arrange
794     // for another thread to free on its behalf, can not be freed in the scope
795     // of the function.  Note that this logic is restricted to memory
796     // allocations in existance before the call; a nofree function *is* allowed
797     // to free memory it allocated.
798     const Function *F = A->getParent();
799     if (F->doesNotFreeMemory() && F->hasNoSync())
800       return false;
801   }
802 
803   const Function *F = nullptr;
804   if (auto *I = dyn_cast<Instruction>(this))
805     F = I->getFunction();
806   if (auto *A = dyn_cast<Argument>(this))
807     F = A->getParent();
808 
809   if (!F)
810     return true;
811 
812   // With garbage collection, deallocation typically occurs solely at or after
813   // safepoints.  If we're compiling for a collector which uses the
814   // gc.statepoint infrastructure, safepoints aren't explicitly present
815   // in the IR until after lowering from abstract to physical machine model.
816   // The collector could chose to mix explicit deallocation and gc'd objects
817   // which is why we need the explicit opt in on a per collector basis.
818   if (!F->hasGC())
819     return true;
820 
821   const auto &GCName = F->getGC();
822   if (GCName == "statepoint-example") {
823     auto *PT = cast<PointerType>(this->getType());
824     if (PT->getAddressSpace() != 1)
825       // For the sake of this example GC, we arbitrarily pick addrspace(1) as
826       // our GC managed heap.  This must match the same check in
827       // RewriteStatepointsForGC (and probably needs better factored.)
828       return true;
829 
830     // It is cheaper to scan for a declaration than to scan for a use in this
831     // function.  Note that gc.statepoint is a type overloaded function so the
832     // usual trick of requesting declaration of the intrinsic from the module
833     // doesn't work.
834     for (auto &Fn : *F->getParent())
835       if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
836         return true;
837     return false;
838   }
839   return true;
840 }
841 
842 uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
843                                                bool &CanBeNull,
844                                                bool &CanBeFreed) const {
845   assert(getType()->isPointerTy() && "must be pointer");
846 
847   uint64_t DerefBytes = 0;
848   CanBeNull = false;
849   CanBeFreed = UseDerefAtPointSemantics && canBeFreed();
850   if (const Argument *A = dyn_cast<Argument>(this)) {
851     DerefBytes = A->getDereferenceableBytes();
852     if (DerefBytes == 0) {
853       // Handle byval/byref/inalloca/preallocated arguments
854       if (Type *ArgMemTy = A->getPointeeInMemoryValueType()) {
855         if (ArgMemTy->isSized()) {
856           // FIXME: Why isn't this the type alloc size?
857           DerefBytes = DL.getTypeStoreSize(ArgMemTy).getKnownMinSize();
858         }
859       }
860     }
861 
862     if (DerefBytes == 0) {
863       DerefBytes = A->getDereferenceableOrNullBytes();
864       CanBeNull = true;
865     }
866   } else if (const auto *Call = dyn_cast<CallBase>(this)) {
867     DerefBytes = Call->getRetDereferenceableBytes();
868     if (DerefBytes == 0) {
869       DerefBytes = Call->getRetDereferenceableOrNullBytes();
870       CanBeNull = true;
871     }
872   } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
873     if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
874       ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
875       DerefBytes = CI->getLimitedValue();
876     }
877     if (DerefBytes == 0) {
878       if (MDNode *MD =
879               LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
880         ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
881         DerefBytes = CI->getLimitedValue();
882       }
883       CanBeNull = true;
884     }
885   } else if (auto *IP = dyn_cast<IntToPtrInst>(this)) {
886     if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
887       ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
888       DerefBytes = CI->getLimitedValue();
889     }
890     if (DerefBytes == 0) {
891       if (MDNode *MD =
892               IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
893         ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
894         DerefBytes = CI->getLimitedValue();
895       }
896       CanBeNull = true;
897     }
898   } else if (auto *AI = dyn_cast<AllocaInst>(this)) {
899     if (!AI->isArrayAllocation()) {
900       DerefBytes =
901           DL.getTypeStoreSize(AI->getAllocatedType()).getKnownMinSize();
902       CanBeNull = false;
903       CanBeFreed = false;
904     }
905   } else if (auto *GV = dyn_cast<GlobalVariable>(this)) {
906     if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
907       // TODO: Don't outright reject hasExternalWeakLinkage but set the
908       // CanBeNull flag.
909       DerefBytes = DL.getTypeStoreSize(GV->getValueType()).getFixedSize();
910       CanBeNull = false;
911       CanBeFreed = false;
912     }
913   }
914   return DerefBytes;
915 }
916 
917 Align Value::getPointerAlignment(const DataLayout &DL) const {
918   assert(getType()->isPointerTy() && "must be pointer");
919   if (auto *GO = dyn_cast<GlobalObject>(this)) {
920     if (isa<Function>(GO)) {
921       Align FunctionPtrAlign = DL.getFunctionPtrAlign().valueOrOne();
922       switch (DL.getFunctionPtrAlignType()) {
923       case DataLayout::FunctionPtrAlignType::Independent:
924         return FunctionPtrAlign;
925       case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
926         return std::max(FunctionPtrAlign, GO->getAlign().valueOrOne());
927       }
928       llvm_unreachable("Unhandled FunctionPtrAlignType");
929     }
930     const MaybeAlign Alignment(GO->getAlignment());
931     if (!Alignment) {
932       if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
933         Type *ObjectType = GVar->getValueType();
934         if (ObjectType->isSized()) {
935           // If the object is defined in the current Module, we'll be giving
936           // it the preferred alignment. Otherwise, we have to assume that it
937           // may only have the minimum ABI alignment.
938           if (GVar->isStrongDefinitionForLinker())
939             return DL.getPreferredAlign(GVar);
940           else
941             return DL.getABITypeAlign(ObjectType);
942         }
943       }
944     }
945     return Alignment.valueOrOne();
946   } else if (const Argument *A = dyn_cast<Argument>(this)) {
947     const MaybeAlign Alignment = A->getParamAlign();
948     if (!Alignment && A->hasStructRetAttr()) {
949       // An sret parameter has at least the ABI alignment of the return type.
950       Type *EltTy = A->getParamStructRetType();
951       if (EltTy->isSized())
952         return DL.getABITypeAlign(EltTy);
953     }
954     return Alignment.valueOrOne();
955   } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
956     return AI->getAlign();
957   } else if (const auto *Call = dyn_cast<CallBase>(this)) {
958     MaybeAlign Alignment = Call->getRetAlign();
959     if (!Alignment && Call->getCalledFunction())
960       Alignment = Call->getCalledFunction()->getAttributes().getRetAlignment();
961     return Alignment.valueOrOne();
962   } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
963     if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
964       ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
965       return Align(CI->getLimitedValue());
966     }
967   } else if (auto *CstPtr = dyn_cast<Constant>(this)) {
968     if (auto *CstInt = dyn_cast_or_null<ConstantInt>(ConstantExpr::getPtrToInt(
969             const_cast<Constant *>(CstPtr), DL.getIntPtrType(getType()),
970             /*OnlyIfReduced=*/true))) {
971       size_t TrailingZeros = CstInt->getValue().countTrailingZeros();
972       // While the actual alignment may be large, elsewhere we have
973       // an arbitrary upper alignmet limit, so let's clamp to it.
974       return Align(TrailingZeros < Value::MaxAlignmentExponent
975                        ? uint64_t(1) << TrailingZeros
976                        : Value::MaximumAlignment);
977     }
978   }
979   return Align(1);
980 }
981 
982 const Value *Value::DoPHITranslation(const BasicBlock *CurBB,
983                                      const BasicBlock *PredBB) const {
984   auto *PN = dyn_cast<PHINode>(this);
985   if (PN && PN->getParent() == CurBB)
986     return PN->getIncomingValueForBlock(PredBB);
987   return this;
988 }
989 
990 LLVMContext &Value::getContext() const { return VTy->getContext(); }
991 
992 void Value::reverseUseList() {
993   if (!UseList || !UseList->Next)
994     // No need to reverse 0 or 1 uses.
995     return;
996 
997   Use *Head = UseList;
998   Use *Current = UseList->Next;
999   Head->Next = nullptr;
1000   while (Current) {
1001     Use *Next = Current->Next;
1002     Current->Next = Head;
1003     Head->Prev = &Current->Next;
1004     Head = Current;
1005     Current = Next;
1006   }
1007   UseList = Head;
1008   Head->Prev = &UseList;
1009 }
1010 
1011 bool Value::isSwiftError() const {
1012   auto *Arg = dyn_cast<Argument>(this);
1013   if (Arg)
1014     return Arg->hasSwiftErrorAttr();
1015   auto *Alloca = dyn_cast<AllocaInst>(this);
1016   if (!Alloca)
1017     return false;
1018   return Alloca->isSwiftError();
1019 }
1020 
1021 bool Value::isTransitiveUsedByMetadataOnly() const {
1022   if (use_empty())
1023     return false;
1024   llvm::SmallVector<const User *, 32> WorkList;
1025   llvm::SmallPtrSet<const User *, 32> Visited;
1026   WorkList.insert(WorkList.begin(), user_begin(), user_end());
1027   while (!WorkList.empty()) {
1028     const User *U = WorkList.pop_back_val();
1029     Visited.insert(U);
1030     // If it is transitively used by a global value or a non-constant value,
1031     // it's obviously not only used by metadata.
1032     if (!isa<Constant>(U) || isa<GlobalValue>(U))
1033       return false;
1034     for (const User *UU : U->users())
1035       if (!Visited.count(UU))
1036         WorkList.push_back(UU);
1037   }
1038   return true;
1039 }
1040 
1041 //===----------------------------------------------------------------------===//
1042 //                             ValueHandleBase Class
1043 //===----------------------------------------------------------------------===//
1044 
1045 void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1046   assert(List && "Handle list is null?");
1047 
1048   // Splice ourselves into the list.
1049   Next = *List;
1050   *List = this;
1051   setPrevPtr(List);
1052   if (Next) {
1053     Next->setPrevPtr(&Next);
1054     assert(getValPtr() == Next->getValPtr() && "Added to wrong list?");
1055   }
1056 }
1057 
1058 void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1059   assert(List && "Must insert after existing node");
1060 
1061   Next = List->Next;
1062   setPrevPtr(&List->Next);
1063   List->Next = this;
1064   if (Next)
1065     Next->setPrevPtr(&Next);
1066 }
1067 
1068 void ValueHandleBase::AddToUseList() {
1069   assert(getValPtr() && "Null pointer doesn't have a use list!");
1070 
1071   LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1072 
1073   if (getValPtr()->HasValueHandle) {
1074     // If this value already has a ValueHandle, then it must be in the
1075     // ValueHandles map already.
1076     ValueHandleBase *&Entry = pImpl->ValueHandles[getValPtr()];
1077     assert(Entry && "Value doesn't have any handles?");
1078     AddToExistingUseList(&Entry);
1079     return;
1080   }
1081 
1082   // Ok, it doesn't have any handles yet, so we must insert it into the
1083   // DenseMap.  However, doing this insertion could cause the DenseMap to
1084   // reallocate itself, which would invalidate all of the PrevP pointers that
1085   // point into the old table.  Handle this by checking for reallocation and
1086   // updating the stale pointers only if needed.
1087   DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
1088   const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
1089 
1090   ValueHandleBase *&Entry = Handles[getValPtr()];
1091   assert(!Entry && "Value really did already have handles?");
1092   AddToExistingUseList(&Entry);
1093   getValPtr()->HasValueHandle = true;
1094 
1095   // If reallocation didn't happen or if this was the first insertion, don't
1096   // walk the table.
1097   if (Handles.isPointerIntoBucketsArray(OldBucketPtr) ||
1098       Handles.size() == 1) {
1099     return;
1100   }
1101 
1102   // Okay, reallocation did happen.  Fix the Prev Pointers.
1103   for (DenseMap<Value*, ValueHandleBase*>::iterator I = Handles.begin(),
1104        E = Handles.end(); I != E; ++I) {
1105     assert(I->second && I->first == I->second->getValPtr() &&
1106            "List invariant broken!");
1107     I->second->setPrevPtr(&I->second);
1108   }
1109 }
1110 
1111 void ValueHandleBase::RemoveFromUseList() {
1112   assert(getValPtr() && getValPtr()->HasValueHandle &&
1113          "Pointer doesn't have a use list!");
1114 
1115   // Unlink this from its use list.
1116   ValueHandleBase **PrevPtr = getPrevPtr();
1117   assert(*PrevPtr == this && "List invariant broken");
1118 
1119   *PrevPtr = Next;
1120   if (Next) {
1121     assert(Next->getPrevPtr() == &Next && "List invariant broken");
1122     Next->setPrevPtr(PrevPtr);
1123     return;
1124   }
1125 
1126   // If the Next pointer was null, then it is possible that this was the last
1127   // ValueHandle watching VP.  If so, delete its entry from the ValueHandles
1128   // map.
1129   LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1130   DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
1131   if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
1132     Handles.erase(getValPtr());
1133     getValPtr()->HasValueHandle = false;
1134   }
1135 }
1136 
1137 void ValueHandleBase::ValueIsDeleted(Value *V) {
1138   assert(V->HasValueHandle && "Should only be called if ValueHandles present");
1139 
1140   // Get the linked list base, which is guaranteed to exist since the
1141   // HasValueHandle flag is set.
1142   LLVMContextImpl *pImpl = V->getContext().pImpl;
1143   ValueHandleBase *Entry = pImpl->ValueHandles[V];
1144   assert(Entry && "Value bit set but no entries exist");
1145 
1146   // We use a local ValueHandleBase as an iterator so that ValueHandles can add
1147   // and remove themselves from the list without breaking our iteration.  This
1148   // is not really an AssertingVH; we just have to give ValueHandleBase a kind.
1149   // Note that we deliberately do not the support the case when dropping a value
1150   // handle results in a new value handle being permanently added to the list
1151   // (as might occur in theory for CallbackVH's): the new value handle will not
1152   // be processed and the checking code will mete out righteous punishment if
1153   // the handle is still present once we have finished processing all the other
1154   // value handles (it is fine to momentarily add then remove a value handle).
1155   for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
1156     Iterator.RemoveFromUseList();
1157     Iterator.AddToExistingUseListAfter(Entry);
1158     assert(Entry->Next == &Iterator && "Loop invariant broken.");
1159 
1160     switch (Entry->getKind()) {
1161     case Assert:
1162       break;
1163     case Weak:
1164     case WeakTracking:
1165       // WeakTracking and Weak just go to null, which unlinks them
1166       // from the list.
1167       Entry->operator=(nullptr);
1168       break;
1169     case Callback:
1170       // Forward to the subclass's implementation.
1171       static_cast<CallbackVH*>(Entry)->deleted();
1172       break;
1173     }
1174   }
1175 
1176   // All callbacks, weak references, and assertingVHs should be dropped by now.
1177   if (V->HasValueHandle) {
1178 #ifndef NDEBUG      // Only in +Asserts mode...
1179     dbgs() << "While deleting: " << *V->getType() << " %" << V->getName()
1180            << "\n";
1181     if (pImpl->ValueHandles[V]->getKind() == Assert)
1182       llvm_unreachable("An asserting value handle still pointed to this"
1183                        " value!");
1184 
1185 #endif
1186     llvm_unreachable("All references to V were not removed?");
1187   }
1188 }
1189 
1190 void ValueHandleBase::ValueIsRAUWd(Value *Old, Value *New) {
1191   assert(Old->HasValueHandle &&"Should only be called if ValueHandles present");
1192   assert(Old != New && "Changing value into itself!");
1193   assert(Old->getType() == New->getType() &&
1194          "replaceAllUses of value with new value of different type!");
1195 
1196   // Get the linked list base, which is guaranteed to exist since the
1197   // HasValueHandle flag is set.
1198   LLVMContextImpl *pImpl = Old->getContext().pImpl;
1199   ValueHandleBase *Entry = pImpl->ValueHandles[Old];
1200 
1201   assert(Entry && "Value bit set but no entries exist");
1202 
1203   // We use a local ValueHandleBase as an iterator so that
1204   // ValueHandles can add and remove themselves from the list without
1205   // breaking our iteration.  This is not really an AssertingVH; we
1206   // just have to give ValueHandleBase some kind.
1207   for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
1208     Iterator.RemoveFromUseList();
1209     Iterator.AddToExistingUseListAfter(Entry);
1210     assert(Entry->Next == &Iterator && "Loop invariant broken.");
1211 
1212     switch (Entry->getKind()) {
1213     case Assert:
1214     case Weak:
1215       // Asserting and Weak handles do not follow RAUW implicitly.
1216       break;
1217     case WeakTracking:
1218       // Weak goes to the new value, which will unlink it from Old's list.
1219       Entry->operator=(New);
1220       break;
1221     case Callback:
1222       // Forward to the subclass's implementation.
1223       static_cast<CallbackVH*>(Entry)->allUsesReplacedWith(New);
1224       break;
1225     }
1226   }
1227 
1228 #ifndef NDEBUG
1229   // If any new weak value handles were added while processing the
1230   // list, then complain about it now.
1231   if (Old->HasValueHandle)
1232     for (Entry = pImpl->ValueHandles[Old]; Entry; Entry = Entry->Next)
1233       switch (Entry->getKind()) {
1234       case WeakTracking:
1235         dbgs() << "After RAUW from " << *Old->getType() << " %"
1236                << Old->getName() << " to " << *New->getType() << " %"
1237                << New->getName() << "\n";
1238         llvm_unreachable(
1239             "A weak tracking value handle still pointed to the old value!\n");
1240       default:
1241         break;
1242       }
1243 #endif
1244 }
1245 
1246 // Pin the vtable to this file.
1247 void CallbackVH::anchor() {}
1248