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