xref: /freebsd/contrib/llvm-project/llvm/lib/IR/Value.cpp (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
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   ValueSymbolTable *ST = nullptr;
381   // If this value has a name, drop it.
382   if (hasName()) {
383     // Get the symtab this is in.
384     if (getSymTab(this, ST)) {
385       // We can't set a name on this value, but we need to clear V's name if
386       // it has one.
387       if (V->hasName()) V->setName("");
388       return;  // Cannot set a name on this value (e.g. constant).
389     }
390 
391     // Remove old name.
392     if (ST)
393       ST->removeValueName(getValueName());
394     destroyValueName();
395   }
396 
397   // Now we know that this has no name.
398 
399   // If V has no name either, we're done.
400   if (!V->hasName()) return;
401 
402   // Get this's symtab if we didn't before.
403   if (!ST) {
404     if (getSymTab(this, ST)) {
405       // Clear V's name.
406       V->setName("");
407       return;  // Cannot set a name on this value (e.g. constant).
408     }
409   }
410 
411   // Get V's ST, this should always succed, because V has a name.
412   ValueSymbolTable *VST;
413   bool Failure = getSymTab(V, VST);
414   assert(!Failure && "V has a name, so it should have a ST!"); (void)Failure;
415 
416   // If these values are both in the same symtab, we can do this very fast.
417   // This works even if both values have no symtab yet.
418   if (ST == VST) {
419     // Take the name!
420     setValueName(V->getValueName());
421     V->setValueName(nullptr);
422     getValueName()->setValue(this);
423     return;
424   }
425 
426   // Otherwise, things are slightly more complex.  Remove V's name from VST and
427   // then reinsert it into ST.
428 
429   if (VST)
430     VST->removeValueName(V->getValueName());
431   setValueName(V->getValueName());
432   V->setValueName(nullptr);
433   getValueName()->setValue(this);
434 
435   if (ST)
436     ST->reinsertValue(this);
437 }
438 
439 #ifndef NDEBUG
440 std::string Value::getNameOrAsOperand() const {
441   if (!getName().empty())
442     return std::string(getName());
443 
444   std::string BBName;
445   raw_string_ostream OS(BBName);
446   printAsOperand(OS, false);
447   return OS.str();
448 }
449 #endif
450 
451 void Value::assertModuleIsMaterializedImpl() const {
452 #ifndef NDEBUG
453   const GlobalValue *GV = dyn_cast<GlobalValue>(this);
454   if (!GV)
455     return;
456   const Module *M = GV->getParent();
457   if (!M)
458     return;
459   assert(M->isMaterialized());
460 #endif
461 }
462 
463 #ifndef NDEBUG
464 static bool contains(SmallPtrSetImpl<ConstantExpr *> &Cache, ConstantExpr *Expr,
465                      Constant *C) {
466   if (!Cache.insert(Expr).second)
467     return false;
468 
469   for (auto &O : Expr->operands()) {
470     if (O == C)
471       return true;
472     auto *CE = dyn_cast<ConstantExpr>(O);
473     if (!CE)
474       continue;
475     if (contains(Cache, CE, C))
476       return true;
477   }
478   return false;
479 }
480 
481 static bool contains(Value *Expr, Value *V) {
482   if (Expr == V)
483     return true;
484 
485   auto *C = dyn_cast<Constant>(V);
486   if (!C)
487     return false;
488 
489   auto *CE = dyn_cast<ConstantExpr>(Expr);
490   if (!CE)
491     return false;
492 
493   SmallPtrSet<ConstantExpr *, 4> Cache;
494   return contains(Cache, CE, C);
495 }
496 #endif // NDEBUG
497 
498 void Value::doRAUW(Value *New, ReplaceMetadataUses ReplaceMetaUses) {
499   assert(New && "Value::replaceAllUsesWith(<null>) is invalid!");
500   assert(!contains(New, this) &&
501          "this->replaceAllUsesWith(expr(this)) is NOT valid!");
502   assert(New->getType() == getType() &&
503          "replaceAllUses of value with new value of different type!");
504 
505   // Notify all ValueHandles (if present) that this value is going away.
506   if (HasValueHandle)
507     ValueHandleBase::ValueIsRAUWd(this, New);
508   if (ReplaceMetaUses == ReplaceMetadataUses::Yes && isUsedByMetadata())
509     ValueAsMetadata::handleRAUW(this, New);
510 
511   while (!materialized_use_empty()) {
512     Use &U = *UseList;
513     // Must handle Constants specially, we cannot call replaceUsesOfWith on a
514     // constant because they are uniqued.
515     if (auto *C = dyn_cast<Constant>(U.getUser())) {
516       if (!isa<GlobalValue>(C)) {
517         C->handleOperandChange(this, New);
518         continue;
519       }
520     }
521 
522     U.set(New);
523   }
524 
525   if (BasicBlock *BB = dyn_cast<BasicBlock>(this))
526     BB->replaceSuccessorsPhiUsesWith(cast<BasicBlock>(New));
527 }
528 
529 void Value::replaceAllUsesWith(Value *New) {
530   doRAUW(New, ReplaceMetadataUses::Yes);
531 }
532 
533 void Value::replaceNonMetadataUsesWith(Value *New) {
534   doRAUW(New, ReplaceMetadataUses::No);
535 }
536 
537 void Value::replaceUsesWithIf(Value *New,
538                               llvm::function_ref<bool(Use &U)> ShouldReplace) {
539   assert(New && "Value::replaceUsesWithIf(<null>) is invalid!");
540   assert(New->getType() == getType() &&
541          "replaceUses of value with new value of different type!");
542 
543   SmallVector<TrackingVH<Constant>, 8> Consts;
544   SmallPtrSet<Constant *, 8> Visited;
545 
546   for (Use &U : llvm::make_early_inc_range(uses())) {
547     if (!ShouldReplace(U))
548       continue;
549     // Must handle Constants specially, we cannot call replaceUsesOfWith on a
550     // constant because they are uniqued.
551     if (auto *C = dyn_cast<Constant>(U.getUser())) {
552       if (!isa<GlobalValue>(C)) {
553         if (Visited.insert(C).second)
554           Consts.push_back(TrackingVH<Constant>(C));
555         continue;
556       }
557     }
558     U.set(New);
559   }
560 
561   while (!Consts.empty()) {
562     // FIXME: handleOperandChange() updates all the uses in a given Constant,
563     //        not just the one passed to ShouldReplace
564     Consts.pop_back_val()->handleOperandChange(this, New);
565   }
566 }
567 
568 /// Replace llvm.dbg.* uses of MetadataAsValue(ValueAsMetadata(V)) outside BB
569 /// with New.
570 static void replaceDbgUsesOutsideBlock(Value *V, Value *New, BasicBlock *BB) {
571   SmallVector<DbgVariableIntrinsic *> DbgUsers;
572   findDbgUsers(DbgUsers, V);
573   for (auto *DVI : DbgUsers) {
574     if (DVI->getParent() != BB)
575       DVI->replaceVariableLocationOp(V, New);
576   }
577 }
578 
579 // Like replaceAllUsesWith except it does not handle constants or basic blocks.
580 // This routine leaves uses within BB.
581 void Value::replaceUsesOutsideBlock(Value *New, BasicBlock *BB) {
582   assert(New && "Value::replaceUsesOutsideBlock(<null>, BB) is invalid!");
583   assert(!contains(New, this) &&
584          "this->replaceUsesOutsideBlock(expr(this), BB) is NOT valid!");
585   assert(New->getType() == getType() &&
586          "replaceUses of value with new value of different type!");
587   assert(BB && "Basic block that may contain a use of 'New' must be defined\n");
588 
589   replaceDbgUsesOutsideBlock(this, New, BB);
590   replaceUsesWithIf(New, [BB](Use &U) {
591     auto *I = dyn_cast<Instruction>(U.getUser());
592     // Don't replace if it's an instruction in the BB basic block.
593     return !I || I->getParent() != BB;
594   });
595 }
596 
597 namespace {
598 // Various metrics for how much to strip off of pointers.
599 enum PointerStripKind {
600   PSK_ZeroIndices,
601   PSK_ZeroIndicesAndAliases,
602   PSK_ZeroIndicesSameRepresentation,
603   PSK_ForAliasAnalysis,
604   PSK_InBoundsConstantIndices,
605   PSK_InBounds
606 };
607 
608 template <PointerStripKind StripKind> static void NoopCallback(const Value *) {}
609 
610 template <PointerStripKind StripKind>
611 static const Value *stripPointerCastsAndOffsets(
612     const Value *V,
613     function_ref<void(const Value *)> Func = NoopCallback<StripKind>) {
614   if (!V->getType()->isPointerTy())
615     return V;
616 
617   // Even though we don't look through PHI nodes, we could be called on an
618   // instruction in an unreachable block, which may be on a cycle.
619   SmallPtrSet<const Value *, 4> Visited;
620 
621   Visited.insert(V);
622   do {
623     Func(V);
624     if (auto *GEP = dyn_cast<GEPOperator>(V)) {
625       switch (StripKind) {
626       case PSK_ZeroIndices:
627       case PSK_ZeroIndicesAndAliases:
628       case PSK_ZeroIndicesSameRepresentation:
629       case PSK_ForAliasAnalysis:
630         if (!GEP->hasAllZeroIndices())
631           return V;
632         break;
633       case PSK_InBoundsConstantIndices:
634         if (!GEP->hasAllConstantIndices())
635           return V;
636         LLVM_FALLTHROUGH;
637       case PSK_InBounds:
638         if (!GEP->isInBounds())
639           return V;
640         break;
641       }
642       V = GEP->getPointerOperand();
643     } else if (Operator::getOpcode(V) == Instruction::BitCast) {
644       V = cast<Operator>(V)->getOperand(0);
645       if (!V->getType()->isPointerTy())
646         return V;
647     } else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
648                Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
649       // TODO: If we know an address space cast will not change the
650       //       representation we could look through it here as well.
651       V = cast<Operator>(V)->getOperand(0);
652     } else if (StripKind == PSK_ZeroIndicesAndAliases && isa<GlobalAlias>(V)) {
653       V = cast<GlobalAlias>(V)->getAliasee();
654     } else if (StripKind == PSK_ForAliasAnalysis && isa<PHINode>(V) &&
655                cast<PHINode>(V)->getNumIncomingValues() == 1) {
656       V = cast<PHINode>(V)->getIncomingValue(0);
657     } else {
658       if (const auto *Call = dyn_cast<CallBase>(V)) {
659         if (const Value *RV = Call->getReturnedArgOperand()) {
660           V = RV;
661           continue;
662         }
663         // The result of launder.invariant.group must alias it's argument,
664         // but it can't be marked with returned attribute, that's why it needs
665         // special case.
666         if (StripKind == PSK_ForAliasAnalysis &&
667             (Call->getIntrinsicID() == Intrinsic::launder_invariant_group ||
668              Call->getIntrinsicID() == Intrinsic::strip_invariant_group)) {
669           V = Call->getArgOperand(0);
670           continue;
671         }
672       }
673       return V;
674     }
675     assert(V->getType()->isPointerTy() && "Unexpected operand type!");
676   } while (Visited.insert(V).second);
677 
678   return V;
679 }
680 } // end anonymous namespace
681 
682 const Value *Value::stripPointerCasts() const {
683   return stripPointerCastsAndOffsets<PSK_ZeroIndices>(this);
684 }
685 
686 const Value *Value::stripPointerCastsAndAliases() const {
687   return stripPointerCastsAndOffsets<PSK_ZeroIndicesAndAliases>(this);
688 }
689 
690 const Value *Value::stripPointerCastsSameRepresentation() const {
691   return stripPointerCastsAndOffsets<PSK_ZeroIndicesSameRepresentation>(this);
692 }
693 
694 const Value *Value::stripInBoundsConstantOffsets() const {
695   return stripPointerCastsAndOffsets<PSK_InBoundsConstantIndices>(this);
696 }
697 
698 const Value *Value::stripPointerCastsForAliasAnalysis() const {
699   return stripPointerCastsAndOffsets<PSK_ForAliasAnalysis>(this);
700 }
701 
702 const Value *Value::stripAndAccumulateConstantOffsets(
703     const DataLayout &DL, APInt &Offset, bool AllowNonInbounds,
704     bool AllowInvariantGroup,
705     function_ref<bool(Value &, APInt &)> ExternalAnalysis) const {
706   if (!getType()->isPtrOrPtrVectorTy())
707     return this;
708 
709   unsigned BitWidth = Offset.getBitWidth();
710   assert(BitWidth == DL.getIndexTypeSizeInBits(getType()) &&
711          "The offset bit width does not match the DL specification.");
712 
713   // Even though we don't look through PHI nodes, we could be called on an
714   // instruction in an unreachable block, which may be on a cycle.
715   SmallPtrSet<const Value *, 4> Visited;
716   Visited.insert(this);
717   const Value *V = this;
718   do {
719     if (auto *GEP = dyn_cast<GEPOperator>(V)) {
720       // If in-bounds was requested, we do not strip non-in-bounds GEPs.
721       if (!AllowNonInbounds && !GEP->isInBounds())
722         return V;
723 
724       // If one of the values we have visited is an addrspacecast, then
725       // the pointer type of this GEP may be different from the type
726       // of the Ptr parameter which was passed to this function.  This
727       // means when we construct GEPOffset, we need to use the size
728       // of GEP's pointer type rather than the size of the original
729       // pointer type.
730       APInt GEPOffset(DL.getIndexTypeSizeInBits(V->getType()), 0);
731       if (!GEP->accumulateConstantOffset(DL, GEPOffset, ExternalAnalysis))
732         return V;
733 
734       // Stop traversal if the pointer offset wouldn't fit in the bit-width
735       // provided by the Offset argument. This can happen due to AddrSpaceCast
736       // stripping.
737       if (GEPOffset.getMinSignedBits() > BitWidth)
738         return V;
739 
740       // External Analysis can return a result higher/lower than the value
741       // represents. We need to detect overflow/underflow.
742       APInt GEPOffsetST = GEPOffset.sextOrTrunc(BitWidth);
743       if (!ExternalAnalysis) {
744         Offset += GEPOffsetST;
745       } else {
746         bool Overflow = false;
747         APInt OldOffset = Offset;
748         Offset = Offset.sadd_ov(GEPOffsetST, Overflow);
749         if (Overflow) {
750           Offset = OldOffset;
751           return V;
752         }
753       }
754       V = GEP->getPointerOperand();
755     } else if (Operator::getOpcode(V) == Instruction::BitCast ||
756                Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
757       V = cast<Operator>(V)->getOperand(0);
758     } else if (auto *GA = dyn_cast<GlobalAlias>(V)) {
759       if (!GA->isInterposable())
760         V = GA->getAliasee();
761     } else if (const auto *Call = dyn_cast<CallBase>(V)) {
762         if (const Value *RV = Call->getReturnedArgOperand())
763           V = RV;
764         if (AllowInvariantGroup && Call->isLaunderOrStripInvariantGroup())
765           V = Call->getArgOperand(0);
766     }
767     assert(V->getType()->isPtrOrPtrVectorTy() && "Unexpected operand type!");
768   } while (Visited.insert(V).second);
769 
770   return V;
771 }
772 
773 const Value *
774 Value::stripInBoundsOffsets(function_ref<void(const Value *)> Func) const {
775   return stripPointerCastsAndOffsets<PSK_InBounds>(this, Func);
776 }
777 
778 bool Value::canBeFreed() const {
779   assert(getType()->isPointerTy());
780 
781   // Cases that can simply never be deallocated
782   // *) Constants aren't allocated per se, thus not deallocated either.
783   if (isa<Constant>(this))
784     return false;
785 
786   // Handle byval/byref/sret/inalloca/preallocated arguments.  The storage
787   // lifetime is guaranteed to be longer than the callee's lifetime.
788   if (auto *A = dyn_cast<Argument>(this)) {
789     if (A->hasPointeeInMemoryValueAttr())
790       return false;
791     // A pointer to an object in a function which neither frees, nor can arrange
792     // for another thread to free on its behalf, can not be freed in the scope
793     // of the function.  Note that this logic is restricted to memory
794     // allocations in existance before the call; a nofree function *is* allowed
795     // to free memory it allocated.
796     const Function *F = A->getParent();
797     if (F->doesNotFreeMemory() && F->hasNoSync())
798       return false;
799   }
800 
801   const Function *F = nullptr;
802   if (auto *I = dyn_cast<Instruction>(this))
803     F = I->getFunction();
804   if (auto *A = dyn_cast<Argument>(this))
805     F = A->getParent();
806 
807   if (!F)
808     return true;
809 
810   // With garbage collection, deallocation typically occurs solely at or after
811   // safepoints.  If we're compiling for a collector which uses the
812   // gc.statepoint infrastructure, safepoints aren't explicitly present
813   // in the IR until after lowering from abstract to physical machine model.
814   // The collector could chose to mix explicit deallocation and gc'd objects
815   // which is why we need the explicit opt in on a per collector basis.
816   if (!F->hasGC())
817     return true;
818 
819   const auto &GCName = F->getGC();
820   if (GCName == "statepoint-example") {
821     auto *PT = cast<PointerType>(this->getType());
822     if (PT->getAddressSpace() != 1)
823       // For the sake of this example GC, we arbitrarily pick addrspace(1) as
824       // our GC managed heap.  This must match the same check in
825       // RewriteStatepointsForGC (and probably needs better factored.)
826       return true;
827 
828     // It is cheaper to scan for a declaration than to scan for a use in this
829     // function.  Note that gc.statepoint is a type overloaded function so the
830     // usual trick of requesting declaration of the intrinsic from the module
831     // doesn't work.
832     for (auto &Fn : *F->getParent())
833       if (Fn.getIntrinsicID() == Intrinsic::experimental_gc_statepoint)
834         return true;
835     return false;
836   }
837   return true;
838 }
839 
840 uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
841                                                bool &CanBeNull,
842                                                bool &CanBeFreed) const {
843   assert(getType()->isPointerTy() && "must be pointer");
844 
845   uint64_t DerefBytes = 0;
846   CanBeNull = false;
847   CanBeFreed = UseDerefAtPointSemantics && canBeFreed();
848   if (const Argument *A = dyn_cast<Argument>(this)) {
849     DerefBytes = A->getDereferenceableBytes();
850     if (DerefBytes == 0) {
851       // Handle byval/byref/inalloca/preallocated arguments
852       if (Type *ArgMemTy = A->getPointeeInMemoryValueType()) {
853         if (ArgMemTy->isSized()) {
854           // FIXME: Why isn't this the type alloc size?
855           DerefBytes = DL.getTypeStoreSize(ArgMemTy).getKnownMinSize();
856         }
857       }
858     }
859 
860     if (DerefBytes == 0) {
861       DerefBytes = A->getDereferenceableOrNullBytes();
862       CanBeNull = true;
863     }
864   } else if (const auto *Call = dyn_cast<CallBase>(this)) {
865     DerefBytes = Call->getRetDereferenceableBytes();
866     if (DerefBytes == 0) {
867       DerefBytes = Call->getRetDereferenceableOrNullBytes();
868       CanBeNull = true;
869     }
870   } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
871     if (MDNode *MD = LI->getMetadata(LLVMContext::MD_dereferenceable)) {
872       ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
873       DerefBytes = CI->getLimitedValue();
874     }
875     if (DerefBytes == 0) {
876       if (MDNode *MD =
877               LI->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
878         ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
879         DerefBytes = CI->getLimitedValue();
880       }
881       CanBeNull = true;
882     }
883   } else if (auto *IP = dyn_cast<IntToPtrInst>(this)) {
884     if (MDNode *MD = IP->getMetadata(LLVMContext::MD_dereferenceable)) {
885       ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
886       DerefBytes = CI->getLimitedValue();
887     }
888     if (DerefBytes == 0) {
889       if (MDNode *MD =
890               IP->getMetadata(LLVMContext::MD_dereferenceable_or_null)) {
891         ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
892         DerefBytes = CI->getLimitedValue();
893       }
894       CanBeNull = true;
895     }
896   } else if (auto *AI = dyn_cast<AllocaInst>(this)) {
897     if (!AI->isArrayAllocation()) {
898       DerefBytes =
899           DL.getTypeStoreSize(AI->getAllocatedType()).getKnownMinSize();
900       CanBeNull = false;
901       CanBeFreed = false;
902     }
903   } else if (auto *GV = dyn_cast<GlobalVariable>(this)) {
904     if (GV->getValueType()->isSized() && !GV->hasExternalWeakLinkage()) {
905       // TODO: Don't outright reject hasExternalWeakLinkage but set the
906       // CanBeNull flag.
907       DerefBytes = DL.getTypeStoreSize(GV->getValueType()).getFixedSize();
908       CanBeNull = false;
909       CanBeFreed = false;
910     }
911   }
912   return DerefBytes;
913 }
914 
915 Align Value::getPointerAlignment(const DataLayout &DL) const {
916   assert(getType()->isPointerTy() && "must be pointer");
917   if (auto *GO = dyn_cast<GlobalObject>(this)) {
918     if (isa<Function>(GO)) {
919       Align FunctionPtrAlign = DL.getFunctionPtrAlign().valueOrOne();
920       switch (DL.getFunctionPtrAlignType()) {
921       case DataLayout::FunctionPtrAlignType::Independent:
922         return FunctionPtrAlign;
923       case DataLayout::FunctionPtrAlignType::MultipleOfFunctionAlign:
924         return std::max(FunctionPtrAlign, GO->getAlign().valueOrOne());
925       }
926       llvm_unreachable("Unhandled FunctionPtrAlignType");
927     }
928     const MaybeAlign Alignment(GO->getAlign());
929     if (!Alignment) {
930       if (auto *GVar = dyn_cast<GlobalVariable>(GO)) {
931         Type *ObjectType = GVar->getValueType();
932         if (ObjectType->isSized()) {
933           // If the object is defined in the current Module, we'll be giving
934           // it the preferred alignment. Otherwise, we have to assume that it
935           // may only have the minimum ABI alignment.
936           if (GVar->isStrongDefinitionForLinker())
937             return DL.getPreferredAlign(GVar);
938           else
939             return DL.getABITypeAlign(ObjectType);
940         }
941       }
942     }
943     return Alignment.valueOrOne();
944   } else if (const Argument *A = dyn_cast<Argument>(this)) {
945     const MaybeAlign Alignment = A->getParamAlign();
946     if (!Alignment && A->hasStructRetAttr()) {
947       // An sret parameter has at least the ABI alignment of the return type.
948       Type *EltTy = A->getParamStructRetType();
949       if (EltTy->isSized())
950         return DL.getABITypeAlign(EltTy);
951     }
952     return Alignment.valueOrOne();
953   } else if (const AllocaInst *AI = dyn_cast<AllocaInst>(this)) {
954     return AI->getAlign();
955   } else if (const auto *Call = dyn_cast<CallBase>(this)) {
956     MaybeAlign Alignment = Call->getRetAlign();
957     if (!Alignment && Call->getCalledFunction())
958       Alignment = Call->getCalledFunction()->getAttributes().getRetAlignment();
959     return Alignment.valueOrOne();
960   } else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
961     if (MDNode *MD = LI->getMetadata(LLVMContext::MD_align)) {
962       ConstantInt *CI = mdconst::extract<ConstantInt>(MD->getOperand(0));
963       return Align(CI->getLimitedValue());
964     }
965   } else if (auto *CstPtr = dyn_cast<Constant>(this)) {
966     if (auto *CstInt = dyn_cast_or_null<ConstantInt>(ConstantExpr::getPtrToInt(
967             const_cast<Constant *>(CstPtr), DL.getIntPtrType(getType()),
968             /*OnlyIfReduced=*/true))) {
969       size_t TrailingZeros = CstInt->getValue().countTrailingZeros();
970       // While the actual alignment may be large, elsewhere we have
971       // an arbitrary upper alignmet limit, so let's clamp to it.
972       return Align(TrailingZeros < Value::MaxAlignmentExponent
973                        ? uint64_t(1) << TrailingZeros
974                        : Value::MaximumAlignment);
975     }
976   }
977   return Align(1);
978 }
979 
980 const Value *Value::DoPHITranslation(const BasicBlock *CurBB,
981                                      const BasicBlock *PredBB) const {
982   auto *PN = dyn_cast<PHINode>(this);
983   if (PN && PN->getParent() == CurBB)
984     return PN->getIncomingValueForBlock(PredBB);
985   return this;
986 }
987 
988 LLVMContext &Value::getContext() const { return VTy->getContext(); }
989 
990 void Value::reverseUseList() {
991   if (!UseList || !UseList->Next)
992     // No need to reverse 0 or 1 uses.
993     return;
994 
995   Use *Head = UseList;
996   Use *Current = UseList->Next;
997   Head->Next = nullptr;
998   while (Current) {
999     Use *Next = Current->Next;
1000     Current->Next = Head;
1001     Head->Prev = &Current->Next;
1002     Head = Current;
1003     Current = Next;
1004   }
1005   UseList = Head;
1006   Head->Prev = &UseList;
1007 }
1008 
1009 bool Value::isSwiftError() const {
1010   auto *Arg = dyn_cast<Argument>(this);
1011   if (Arg)
1012     return Arg->hasSwiftErrorAttr();
1013   auto *Alloca = dyn_cast<AllocaInst>(this);
1014   if (!Alloca)
1015     return false;
1016   return Alloca->isSwiftError();
1017 }
1018 
1019 bool Value::isTransitiveUsedByMetadataOnly() const {
1020   if (use_empty())
1021     return false;
1022   llvm::SmallVector<const User *, 32> WorkList;
1023   llvm::SmallPtrSet<const User *, 32> Visited;
1024   WorkList.insert(WorkList.begin(), user_begin(), user_end());
1025   while (!WorkList.empty()) {
1026     const User *U = WorkList.pop_back_val();
1027     Visited.insert(U);
1028     // If it is transitively used by a global value or a non-constant value,
1029     // it's obviously not only used by metadata.
1030     if (!isa<Constant>(U) || isa<GlobalValue>(U))
1031       return false;
1032     for (const User *UU : U->users())
1033       if (!Visited.count(UU))
1034         WorkList.push_back(UU);
1035   }
1036   return true;
1037 }
1038 
1039 //===----------------------------------------------------------------------===//
1040 //                             ValueHandleBase Class
1041 //===----------------------------------------------------------------------===//
1042 
1043 void ValueHandleBase::AddToExistingUseList(ValueHandleBase **List) {
1044   assert(List && "Handle list is null?");
1045 
1046   // Splice ourselves into the list.
1047   Next = *List;
1048   *List = this;
1049   setPrevPtr(List);
1050   if (Next) {
1051     Next->setPrevPtr(&Next);
1052     assert(getValPtr() == Next->getValPtr() && "Added to wrong list?");
1053   }
1054 }
1055 
1056 void ValueHandleBase::AddToExistingUseListAfter(ValueHandleBase *List) {
1057   assert(List && "Must insert after existing node");
1058 
1059   Next = List->Next;
1060   setPrevPtr(&List->Next);
1061   List->Next = this;
1062   if (Next)
1063     Next->setPrevPtr(&Next);
1064 }
1065 
1066 void ValueHandleBase::AddToUseList() {
1067   assert(getValPtr() && "Null pointer doesn't have a use list!");
1068 
1069   LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1070 
1071   if (getValPtr()->HasValueHandle) {
1072     // If this value already has a ValueHandle, then it must be in the
1073     // ValueHandles map already.
1074     ValueHandleBase *&Entry = pImpl->ValueHandles[getValPtr()];
1075     assert(Entry && "Value doesn't have any handles?");
1076     AddToExistingUseList(&Entry);
1077     return;
1078   }
1079 
1080   // Ok, it doesn't have any handles yet, so we must insert it into the
1081   // DenseMap.  However, doing this insertion could cause the DenseMap to
1082   // reallocate itself, which would invalidate all of the PrevP pointers that
1083   // point into the old table.  Handle this by checking for reallocation and
1084   // updating the stale pointers only if needed.
1085   DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
1086   const void *OldBucketPtr = Handles.getPointerIntoBucketsArray();
1087 
1088   ValueHandleBase *&Entry = Handles[getValPtr()];
1089   assert(!Entry && "Value really did already have handles?");
1090   AddToExistingUseList(&Entry);
1091   getValPtr()->HasValueHandle = true;
1092 
1093   // If reallocation didn't happen or if this was the first insertion, don't
1094   // walk the table.
1095   if (Handles.isPointerIntoBucketsArray(OldBucketPtr) ||
1096       Handles.size() == 1) {
1097     return;
1098   }
1099 
1100   // Okay, reallocation did happen.  Fix the Prev Pointers.
1101   for (DenseMap<Value*, ValueHandleBase*>::iterator I = Handles.begin(),
1102        E = Handles.end(); I != E; ++I) {
1103     assert(I->second && I->first == I->second->getValPtr() &&
1104            "List invariant broken!");
1105     I->second->setPrevPtr(&I->second);
1106   }
1107 }
1108 
1109 void ValueHandleBase::RemoveFromUseList() {
1110   assert(getValPtr() && getValPtr()->HasValueHandle &&
1111          "Pointer doesn't have a use list!");
1112 
1113   // Unlink this from its use list.
1114   ValueHandleBase **PrevPtr = getPrevPtr();
1115   assert(*PrevPtr == this && "List invariant broken");
1116 
1117   *PrevPtr = Next;
1118   if (Next) {
1119     assert(Next->getPrevPtr() == &Next && "List invariant broken");
1120     Next->setPrevPtr(PrevPtr);
1121     return;
1122   }
1123 
1124   // If the Next pointer was null, then it is possible that this was the last
1125   // ValueHandle watching VP.  If so, delete its entry from the ValueHandles
1126   // map.
1127   LLVMContextImpl *pImpl = getValPtr()->getContext().pImpl;
1128   DenseMap<Value*, ValueHandleBase*> &Handles = pImpl->ValueHandles;
1129   if (Handles.isPointerIntoBucketsArray(PrevPtr)) {
1130     Handles.erase(getValPtr());
1131     getValPtr()->HasValueHandle = false;
1132   }
1133 }
1134 
1135 void ValueHandleBase::ValueIsDeleted(Value *V) {
1136   assert(V->HasValueHandle && "Should only be called if ValueHandles present");
1137 
1138   // Get the linked list base, which is guaranteed to exist since the
1139   // HasValueHandle flag is set.
1140   LLVMContextImpl *pImpl = V->getContext().pImpl;
1141   ValueHandleBase *Entry = pImpl->ValueHandles[V];
1142   assert(Entry && "Value bit set but no entries exist");
1143 
1144   // We use a local ValueHandleBase as an iterator so that ValueHandles can add
1145   // and remove themselves from the list without breaking our iteration.  This
1146   // is not really an AssertingVH; we just have to give ValueHandleBase a kind.
1147   // Note that we deliberately do not the support the case when dropping a value
1148   // handle results in a new value handle being permanently added to the list
1149   // (as might occur in theory for CallbackVH's): the new value handle will not
1150   // be processed and the checking code will mete out righteous punishment if
1151   // the handle is still present once we have finished processing all the other
1152   // value handles (it is fine to momentarily add then remove a value handle).
1153   for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
1154     Iterator.RemoveFromUseList();
1155     Iterator.AddToExistingUseListAfter(Entry);
1156     assert(Entry->Next == &Iterator && "Loop invariant broken.");
1157 
1158     switch (Entry->getKind()) {
1159     case Assert:
1160       break;
1161     case Weak:
1162     case WeakTracking:
1163       // WeakTracking and Weak just go to null, which unlinks them
1164       // from the list.
1165       Entry->operator=(nullptr);
1166       break;
1167     case Callback:
1168       // Forward to the subclass's implementation.
1169       static_cast<CallbackVH*>(Entry)->deleted();
1170       break;
1171     }
1172   }
1173 
1174   // All callbacks, weak references, and assertingVHs should be dropped by now.
1175   if (V->HasValueHandle) {
1176 #ifndef NDEBUG      // Only in +Asserts mode...
1177     dbgs() << "While deleting: " << *V->getType() << " %" << V->getName()
1178            << "\n";
1179     if (pImpl->ValueHandles[V]->getKind() == Assert)
1180       llvm_unreachable("An asserting value handle still pointed to this"
1181                        " value!");
1182 
1183 #endif
1184     llvm_unreachable("All references to V were not removed?");
1185   }
1186 }
1187 
1188 void ValueHandleBase::ValueIsRAUWd(Value *Old, Value *New) {
1189   assert(Old->HasValueHandle &&"Should only be called if ValueHandles present");
1190   assert(Old != New && "Changing value into itself!");
1191   assert(Old->getType() == New->getType() &&
1192          "replaceAllUses of value with new value of different type!");
1193 
1194   // Get the linked list base, which is guaranteed to exist since the
1195   // HasValueHandle flag is set.
1196   LLVMContextImpl *pImpl = Old->getContext().pImpl;
1197   ValueHandleBase *Entry = pImpl->ValueHandles[Old];
1198 
1199   assert(Entry && "Value bit set but no entries exist");
1200 
1201   // We use a local ValueHandleBase as an iterator so that
1202   // ValueHandles can add and remove themselves from the list without
1203   // breaking our iteration.  This is not really an AssertingVH; we
1204   // just have to give ValueHandleBase some kind.
1205   for (ValueHandleBase Iterator(Assert, *Entry); Entry; Entry = Iterator.Next) {
1206     Iterator.RemoveFromUseList();
1207     Iterator.AddToExistingUseListAfter(Entry);
1208     assert(Entry->Next == &Iterator && "Loop invariant broken.");
1209 
1210     switch (Entry->getKind()) {
1211     case Assert:
1212     case Weak:
1213       // Asserting and Weak handles do not follow RAUW implicitly.
1214       break;
1215     case WeakTracking:
1216       // Weak goes to the new value, which will unlink it from Old's list.
1217       Entry->operator=(New);
1218       break;
1219     case Callback:
1220       // Forward to the subclass's implementation.
1221       static_cast<CallbackVH*>(Entry)->allUsesReplacedWith(New);
1222       break;
1223     }
1224   }
1225 
1226 #ifndef NDEBUG
1227   // If any new weak value handles were added while processing the
1228   // list, then complain about it now.
1229   if (Old->HasValueHandle)
1230     for (Entry = pImpl->ValueHandles[Old]; Entry; Entry = Entry->Next)
1231       switch (Entry->getKind()) {
1232       case WeakTracking:
1233         dbgs() << "After RAUW from " << *Old->getType() << " %"
1234                << Old->getName() << " to " << *New->getType() << " %"
1235                << New->getName() << "\n";
1236         llvm_unreachable(
1237             "A weak tracking value handle still pointed to the old value!\n");
1238       default:
1239         break;
1240       }
1241 #endif
1242 }
1243 
1244 // Pin the vtable to this file.
1245 void CallbackVH::anchor() {}
1246