llvm.org GIT mirror llvm / d0cf26e
Rename WeakVH to WeakTrackingVH; NFC Summary: I plan to use WeakVH to mean "nulls itself out on deletion, but does not track RAUW" in a subsequent commit. Reviewers: dblaikie, davide Reviewed By: davide Subscribers: arsenm, mehdi_amini, mcrosier, mzolotukhin, jfb, llvm-commits, nhaehnle Differential Revision: https://reviews.llvm.org/D32266 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301424 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 3 years ago
40 changed file(s) with 204 addition(s) and 217 deletion(s). Raw diff Collapse all Expand all
21552155 ValueMap is a wrapper around a :ref:`DenseMap ` mapping
21562156 ``Value*``\ s (or subclasses) to another type. When a Value is deleted or
21572157 RAUW'ed, ValueMap will update itself so the new version of the key is mapped to
2158 the same value, just as if the key were a WeakVH. You can configure exactly how
2159 this happens, and what else happens on these two events, by passing a ``Config``
2160 parameter to the ValueMap template.
2158 the same value, just as if the key were a WeakTrackingVH. You can configure
2159 exactly how this happens, and what else happens on these two events, by passing
2160 a ``Config`` parameter to the ValueMap template.
21612161
21622162 .. _dss_intervalmap:
21632163
120120 AliasSet *Forward;
121121
122122 /// All instructions without a specific address in this alias set.
123 /// In rare cases this vector can have a null'ed out WeakVH
123 /// In rare cases this vector can have a null'ed out WeakTrackingVH
124124 /// instances (can happen if some other loop pass deletes an
125125 /// instruction in this list).
126 std::vectorVH> UnknownInsts;
126 std::vectorTrackingVH> UnknownInsts;
127127
128128 /// Number of nodes pointing to this AliasSet plus the number of AliasSets
129129 /// forwarding to it.
4242
4343 /// \brief Vector of weak value handles to calls of the @llvm.assume
4444 /// intrinsic.
45 SmallVectorVH, 4> AssumeHandles;
45 SmallVectorTrackingVH, 4> AssumeHandles;
4646
4747 class AffectedValueCallbackVH final : public CallbackVH {
4848 AssumptionCache *AC;
6161 /// \brief A map of values about which an assumption might be providing
6262 /// information to the relevant set of assumptions.
6363 using AffectedValuesMap =
64 DenseMap,
65 AffectedValueCallbackVH::DMI>;
64 DenseMap,
65 AffectedValueCallbackVH::DMI>;
6666 AffectedValuesMap AffectedValues;
6767
6868 /// Get the vector of assumptions which affect a value from the cache.
69 SmallVectorVH, 1> &getOrInsertAffectedValues(Value *V);
69 SmallVectorTrackingVH, 1> &getOrInsertAffectedValues(Value *V);
7070
7171 /// Copy affected values in the cache for OV to be affected values for NV.
7272 void copyAffectedValuesInCache(Value *OV, Value *NV);
119119 /// FIXME: We should replace this with pointee_iterator>
120120 /// when we can write that to filter out the null values. Then caller code
121121 /// will become simpler.
122 MutableArrayRefVH> assumptions() {
122 MutableArrayRefTrackingVH> assumptions() {
123123 if (!Scanned)
124124 scanFunction();
125125 return AssumeHandles;
126126 }
127127
128128 /// \brief Access the list of assumptions which affect this value.
129 MutableArrayRefVH> assumptionsFor(const Value *V) {
129 MutableArrayRefTrackingVH> assumptionsFor(const Value *V) {
130130 if (!Scanned)
131131 scanFunction();
132132
133133 auto AVI = AffectedValues.find_as(const_cast(V));
134134 if (AVI == AffectedValues.end())
135 return MutableArrayRefVH>();
135 return MutableArrayRefTrackingVH>();
136136
137137 return AVI->second;
138138 }
645645 LazyCallGraph::SCC *C = &InitialC;
646646
647647 // Collect value handles for all of the indirect call sites.
648 SmallVectorVH, 8> CallHandles;
648 SmallVectorTrackingVH, 8> CallHandles;
649649
650650 // Struct to track the counts of direct and indirect calls in each function
651651 // of the SCC.
657657 // Put value handles on all of the indirect calls and return the number of
658658 // direct calls for each function in the SCC.
659659 auto ScanSCC = [](LazyCallGraph::SCC &C,
660 SmallVectorImplVH> &CallHandles) {
660 SmallVectorImplTrackingVH> &CallHandles) {
661661 assert(CallHandles.empty() && "Must start with a clear set of handles.");
662662
663663 SmallVector CallCounts;
670670 ++Count.Direct;
671671 } else {
672672 ++Count.Indirect;
673 CallHandles.push_back(WeakVH(&I));
673 CallHandles.push_back(WeakTrackingVH(&I));
674674 }
675675 }
676676 }
698698 "Cannot have changed the size of the SCC!");
699699
700700 // Check whether any of the handles were devirtualized.
701 auto IsDevirtualizedHandle = [&](WeakVH &CallH) {
701 auto IsDevirtualizedHandle = [&](WeakTrackingVH &CallH) {
702702 if (!CallH)
703703 return false;
704704 auto CS = CallSite(CallH);
171171 public:
172172 /// \brief A pair of the calling instruction (a call or invoke)
173173 /// and the call graph node being called.
174 typedef std::pairVH, CallGraphNode *> CallRecord;
174 typedef std::pairTrackingVH, CallGraphNode *> CallRecord;
175175
176176 public:
177177 typedef std::vector CalledFunctionsVector;
7979
8080 /// OperandValToReplace - The Value of the operand in the user instruction
8181 /// that this IVStrideUse is representing.
82 WeakVH OperandValToReplace;
82 WeakTrackingVH OperandValToReplace;
8383
8484 /// PostIncLoops - The set of loops for which Expr has been adjusted to
8585 /// use post-inc mode. This corresponds with SCEVExpander's post-inc concept.
234234 : public InstVisitor {
235235
236236 typedef IRBuilder BuilderTy;
237 typedef std::pairVH, WeakVH> WeakEvalType;
237 typedef std::pairTrackingVH, WeakTrackingVH> WeakEvalType;
238238 typedef DenseMap CacheMapTy;
239239 typedef SmallPtrSet PtrSetTy;
240240
188188 /// replace congruent phis with their most canonical representative. Return
189189 /// the number of phis eliminated.
190190 unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT,
191 SmallVectorImplVH> &DeadInsts,
191 SmallVectorImplTrackingVH> &DeadInsts,
192192 const TargetTransformInfo *TTI = nullptr);
193193
194194 /// Insert code to directly compute the specified SCEV expression into the
3333 ///
3434 /// This is to avoid having a vtable for the light-weight handle pointers. The
3535 /// fully general Callback version does have a vtable.
36 enum HandleBaseKind {
37 Assert,
38 Callback,
39 Tracking,
40 Weak
41 };
36 enum HandleBaseKind { Assert, Callback, Tracking, WeakTracking };
4237
4338 ValueHandleBase(const ValueHandleBase &RHS)
4439 : ValueHandleBase(RHS.PrevPair.getInt(), RHS) {}
137132 /// is useful for advisory sorts of information, but should not be used as the
138133 /// key of a map (since the map would have to rearrange itself when the pointer
139134 /// changes).
140 class WeakVH : public ValueHandleBase {
141 public:
142 WeakVH() : ValueHandleBase(Weak) {}
143 WeakVH(Value *P) : ValueHandleBase(Weak, P) {}
144 WeakVH(const WeakVH &RHS)
145 : ValueHandleBase(Weak, RHS) {}
146
147 WeakVH &operator=(const WeakVH &RHS) = default;
135 class WeakTrackingVH : public ValueHandleBase {
136 public:
137 WeakTrackingVH() : ValueHandleBase(WeakTracking) {}
138 WeakTrackingVH(Value *P) : ValueHandleBase(WeakTracking, P) {}
139 WeakTrackingVH(const WeakTrackingVH &RHS)
140 : ValueHandleBase(WeakTracking, RHS) {}
141
142 WeakTrackingVH &operator=(const WeakTrackingVH &RHS) = default;
148143
149144 Value *operator=(Value *RHS) {
150145 return ValueHandleBase::operator=(RHS);
158153 }
159154 };
160155
161 // Specialize simplify_type to allow WeakVH to participate in
156 // Specialize simplify_type to allow WeakTrackingVH to participate in
162157 // dyn_cast, isa, etc.
163 template <> struct simplify_typeVH> {
158 template <> struct simplify_typeTrackingVH> {
164159 typedef Value *SimpleType;
165 static SimpleType getSimplifiedValue(WeakVH &WVH) { return WVH; }
166 };
167 template <> struct simplify_type {
160 static SimpleType getSimplifiedValue(WeakTrackingVH &WVH) { return WVH; }
161 };
162 template <> struct simplify_type {
168163 typedef Value *SimpleType;
169 static SimpleType getSimplifiedValue(const WeakVH &WVH) { return WVH; }
164 static SimpleType getSimplifiedValue(const WeakTrackingVH &WVH) {
165 return WVH;
166 }
170167 };
171168
172169 /// \brief Value handle that asserts if the Value is deleted.
358355 ///
359356 /// Called when this->getValPtr() is destroyed, inside ~Value(), so you
360357 /// may call any non-virtual Value method on getValPtr(), but no subclass
361 /// methods. If WeakVH were implemented as a CallbackVH, it would use this
362 /// method to call setValPtr(NULL). AssertingVH would use this method to
358 /// methods. If WeakTrackingVH were implemented as a CallbackVH, it would use
359 /// this method to call setValPtr(NULL). AssertingVH would use this method to
363360 /// cause an assertion failure.
364361 ///
365362 /// All implementations must remove the reference from this object to the
369366 /// \brief Callback for Value RAUW.
370367 ///
371368 /// Called when this->getValPtr()->replaceAllUsesWith(new_value) is called,
372 /// _before_ any of the uses have actually been replaced. If WeakVH were
373 /// implemented as a CallbackVH, it would use this method to call
369 /// _before_ any of the uses have actually been replaced. If WeakTrackingVH
370 /// were implemented as a CallbackVH, it would use this method to call
374371 /// setValPtr(new_value). AssertingVH would do nothing in this method.
375372 virtual void allUsesReplacedWith(Value *) {}
376373 };
166166 // foo(a + b);
167167 // if (p2)
168168 // bar(a + b);
169 DenseMapVH, 2>> SeenExprs;
169 DenseMapTrackingVH, 2>> SeenExprs;
170170 };
171171 } // namespace llvm
172172
7373 /// All cloned call sites that have operand bundles attached are appended to
7474 /// this vector. This vector may contain nulls or undefs if some of the
7575 /// originally inserted callsites were DCE'ed after they were cloned.
76 std::vectorVH> OperandBundleCallSites;
76 std::vectorTrackingVH> OperandBundleCallSites;
7777
7878 ClonedCodeInfo() = default;
7979 };
191191
192192 /// InlinedCalls - InlineFunction fills this in with callsites that were
193193 /// inlined from the callee. This is only filled in if CG is non-null.
194 SmallVectorVH, 8> InlinedCalls;
194 SmallVectorTrackingVH, 8> InlinedCalls;
195195
196196 /// All of the new call sites inlined into the caller.
197197 ///
4545 /// simplifyUsersOfIV - Simplify instructions that use this induction variable
4646 /// by using ScalarEvolution to analyze the IV's recurrence.
4747 bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT,
48 LoopInfo *LI, SmallVectorImplVH> &Dead,
48 LoopInfo *LI, SmallVectorImplTrackingVH> &Dead,
4949 IVVisitor *V = nullptr);
5050
5151 /// SimplifyLoopIVs - Simplify users of induction variables within this
5252 /// loop. This does not actually change or add IVs.
5353 bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT,
54 LoopInfo *LI, SmallVectorImplVH> &Dead);
54 LoopInfo *LI, SmallVectorImplTrackingVH> &Dead);
5555
5656 } // end namespace llvm
5757
2222
2323 class Value;
2424 class Instruction;
25 typedef ValueMapVH> ValueToValueMapTy;
25 typedef ValueMapTrackingVH> ValueToValueMapTy;
2626
2727 /// This is a class that can be implemented by clients to remap types when
2828 /// cloning constants and instructions.
3939 struct SLPVectorizerPass : public PassInfoMixin {
4040 typedef SmallVector StoreList;
4141 typedef MapVector StoreListMap;
42 typedef SmallVector WeakVHList;
43 typedef MapVector WeakVHListMap;
42 typedef SmallVector WeakTrackingVHList;
43 typedef MapVector WeakTrackingVHListMap;
4444
4545 ScalarEvolution *SE = nullptr;
4646 TargetTransformInfo *TTI = nullptr;
110110 StoreListMap Stores;
111111
112112 /// The getelementptr instructions in a basic block organized by base pointer.
113 WeakVHListMap GEPs;
113 WeakTrackingVHListMap GEPs;
114114 };
115115 }
116116
2828 cl::desc("Enable verification of assumption cache"),
2929 cl::init(false));
3030
31 SmallVectorVH, 1> &AssumptionCache::getOrInsertAffectedValues(Value *V) {
31 SmallVectorTrackingVH, 1> &
32 AssumptionCache::getOrInsertAffectedValues(Value *V) {
3233 // Try using find_as first to avoid creating extra value handles just for the
3334 // purpose of doing the lookup.
3435 auto AVI = AffectedValues.find_as(V);
3536 if (AVI != AffectedValues.end())
3637 return AVI->second;
3738
38 auto AVIP = AffectedValues.insert({
39 AffectedValueCallbackVH(V, this), SmallVector()});
39 auto AVIP = AffectedValues.insert(
40 {AffectedValueCallbackVH(V, this), SmallVector()});
4041 return AVIP.first->second;
4142 }
4243
203203 // Get the set of call sites currently in the function.
204204 for (CallGraphNode::iterator I = CGN->begin(), E = CGN->end(); I != E; ) {
205205 // If this call site is null, then the function pass deleted the call
206 // entirely and the WeakVH nulled it out.
206 // entirely and the WeakTrackingVH nulled it out.
207207 if (!I->first ||
208208 // If we've already seen this call site, then the FunctionPass RAUW'd
209209 // one call with another, which resulted in two "uses" in the edge
344344 if (NumIndirectRemoved > NumIndirectAdded &&
345345 NumDirectRemoved < NumDirectAdded)
346346 DevirtualizedCall = true;
347
347
348348 // After scanning this function, if we still have entries in callsites, then
349 // they are dangling pointers. WeakVH should save us for this, so abort if
350 // this happens.
349 // they are dangling pointers. WeakTrackingVH should save us for this, so
350 // abort if this happens.
351351 assert(CallSites.empty() && "Dangling pointers found in call sites map");
352352
353353 // Periodically do an explicit clear to remove tombstones when processing
17711771 ///
17721772 /// This does not depend on any SCEVExpander state but should be used in
17731773 /// the same context that SCEVExpander is used.
1774 unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
1775 SmallVectorImpl &DeadInsts,
1776 const TargetTransformInfo *TTI) {
1774 unsigned
1775 SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
1776 SmallVectorImpl &DeadInsts,
1777 const TargetTransformInfo *TTI) {
17771778 // Find integer phis in order of increasing width.
17781779 SmallVector Phis;
17791780 for (auto &I : *L->getHeader()) {
5757 if (Idx >= size())
5858 resize(Idx + 1);
5959
60 WeakVH &OldV = ValuePtrs[Idx];
60 WeakTrackingVH &OldV = ValuePtrs[Idx];
6161 if (!OldV) {
6262 OldV = V;
6363 return;
1919 class Constant;
2020
2121 class BitcodeReaderValueList {
22 std::vectorVH> ValuePtrs;
22 std::vectorTrackingVH> ValuePtrs;
2323
2424 /// As we resolve forward-referenced constants, we add information about them
2525 /// to this vector. This allows us to resolve them in bulk instead of
22252225 ConstantInt *RetVal =
22262226 lowerObjectSizeCall(II, *DL, TLInfo, /*MustSucceed=*/true);
22272227 // Substituting this can cause recursive simplifications, which can
2228 // invalidate our iterator. Use a WeakVH to hold onto it in case this
2229 // happens.
2228 // invalidate our iterator. Use a WeakTrackingVH to hold onto it in case
2229 // this happens.
22302230 Value *CurValue = &*CurInstIterator;
2231 WeakVH IterHandle(CurValue);
2231 WeakTrackingVH IterHandle(CurValue);
22322232
22332233 replaceAndRecursivelySimplify(CI, RetVal, TLInfo, nullptr);
22342234
44414441 // using it.
44424442 if (Repl->use_empty()) {
44434443 // This can cause recursive deletion, which can invalidate our iterator.
4444 // Use a WeakVH to hold onto it in case this happens.
4444 // Use a WeakTrackingVH to hold onto it in case this happens.
44454445 Value *CurValue = &*CurInstIterator;
4446 WeakVH IterHandle(CurValue);
4446 WeakTrackingVH IterHandle(CurValue);
44474447 BasicBlock *BB = CurInstIterator->getParent();
44484448
44494449 RecursivelyDeleteTriviallyDeadInstructions(Repl, TLInfo);
824824 // pointer.
825825 Entry->operator=(DenseMapInfo::getTombstoneKey());
826826 break;
827 case Weak:
828 // Weak just goes to null, which will unlink it from the list.
827 case WeakTracking:
828 // WeakTracking just goes to null, which will unlink it from the list.
829829 Entry->operator=(nullptr);
830830 break;
831831 case Callback:
876876 // Asserting handle does not follow RAUW implicitly.
877877 break;
878878 case Tracking:
879 // Tracking goes to new value like a WeakVH. Note that this may make it
880 // something incompatible with its templated type. We don't want to have a
881 // virtual (or inline) interface to handle this though, so instead we make
882 // the TrackingVH accessors guarantee that a client never sees this value.
879 // Tracking goes to new value like a WeakTrackingVH. Note that this may
880 // make it something incompatible with its templated type. We don't want
881 // to have a virtual (or inline) interface to handle this though, so
882 // instead we make the TrackingVH accessors guarantee that a client never
883 // sees this value.
883884
884885 LLVM_FALLTHROUGH;
885 case Weak:
886 // Weak goes to the new value, which will unlink it from Old's list.
886 case WeakTracking:
887 // WeakTracking goes to the new value, which will unlink it from Old's
888 // list.
887889 Entry->operator=(New);
888890 break;
889891 case Callback:
900902 for (Entry = pImpl->ValueHandles[Old]; Entry; Entry = Entry->Next)
901903 switch (Entry->getKind()) {
902904 case Tracking:
903 case Weak:
905 case WeakTracking:
904906 dbgs() << "After RAUW from " << *Old->getType() << " %"
905907 << Old->getName() << " to " << *New->getType() << " %"
906908 << New->getName() << "\n";
7676
7777 void insertElse(BranchInst *Term);
7878
79 Value *handleLoopCondition(Value *Cond, PHINode *Broken,
80 llvm::Loop *L, BranchInst *Term,
81 SmallVectorImpl &LoopPhiConditions);
79 Value *
80 handleLoopCondition(Value *Cond, PHINode *Broken, llvm::Loop *L,
81 BranchInst *Term,
82 SmallVectorImpl &LoopPhiConditions);
8283
8384 void handleLoop(BranchInst *Term);
8485
211212
212213 /// \brief Recursively handle the condition leading to a loop
213214 Value *SIAnnotateControlFlow::handleLoopCondition(
214 Value *Cond, PHINode *Broken,
215 llvm::Loop *L, BranchInst *Term,
216 SmallVectorImpl &LoopPhiConditions) {
215 Value *Cond, PHINode *Broken, llvm::Loop *L, BranchInst *Term,
216 SmallVectorImpl &LoopPhiConditions) {
217217
218218 // Only search through PHI nodes which are inside the loop. If we try this
219219 // with PHI nodes that are outside of the loop, we end up inserting new PHI
280280 NewPhi->setIncomingValue(i, PhiArg);
281281 }
282282
283 LoopPhiConditions.push_back(WeakVH(Phi));
283 LoopPhiConditions.push_back(WeakTrackingVH(Phi));
284284 return Ret;
285285 }
286286
322322 BasicBlock *Target = Term->getSuccessor(1);
323323 PHINode *Broken = PHINode::Create(Int64, 0, "phi.broken", &Target->front());
324324
325 SmallVectorVH, 8> LoopPhiConditions;
325 SmallVectorTrackingVH, 8> LoopPhiConditions;
326326 Value *Cond = Term->getCondition();
327327 Term->setCondition(BoolTrue);
328328 Value *Arg = handleLoopCondition(Cond, Broken, L, Term, LoopPhiConditions);
332332
333333 Term->setCondition(CallInst::Create(Loop, Arg, "", Term));
334334
335 for (WeakVH Val : reverse(LoopPhiConditions)) {
335 for (WeakTrackingVH Val : reverse(LoopPhiConditions)) {
336336 if (PHINode *Cond = cast_or_null(Val))
337337 eraseIfUnused(Cond);
338338 }
127127
128128 static bool replaceConstantExprOp(ConstantExpr *CE, Pass *P) {
129129 do {
130 SmallVectorVH,8> WUsers(CE->user_begin(), CE->user_end());
130 SmallVectorTrackingVH, 8> WUsers(CE->user_begin(), CE->user_end());
131131 std::sort(WUsers.begin(), WUsers.end());
132132 WUsers.erase(std::unique(WUsers.begin(), WUsers.end()), WUsers.end());
133133 while (!WUsers.empty())
134 if (WeakVH WU = WUsers.pop_back_val()) {
134 if (WeakTrackingVH WU = WUsers.pop_back_val()) {
135135 if (PHINode *PN = dyn_cast(WU)) {
136136 for (int I = 0, E = PN->getNumIncomingValues(); I < E; ++I)
137137 if (PN->getIncomingValue(I) == CE) {
158158 }
159159
160160 static bool rewriteNonInstructionUses(GlobalVariable *GV, Pass *P) {
161 SmallVectorVH,8> WUsers;
161 SmallVectorTrackingVH, 8> WUsers;
162162 for (User *U : GV->users())
163163 if (!isa(U))
164 WUsers.push_back(WeakVH(U));
164 WUsers.push_back(WeakTrackingVH(U));
165165 while (!WUsers.empty())
166 if (WeakVH WU = WUsers.pop_back_val()) {
166 if (WeakTrackingVH WU = WUsers.pop_back_val()) {
167167 ConstantExpr *CE = dyn_cast(WU);
168168 if (!CE || !replaceConstantExprOp(CE, P))
169169 return false;
238238 // we delete a constant array, we may also be holding pointer to one of its
239239 // elements (or an element of one of its elements if we're dealing with an
240240 // array of arrays) in the worklist.
241 SmallVectorVH, 8> WorkList(V->user_begin(), V->user_end());
241 SmallVectorTrackingVH, 8> WorkList(V->user_begin(), V->user_end());
242242 while (!WorkList.empty()) {
243243 Value *UV = WorkList.pop_back_val();
244244 if (!UV)
206206
207207 /// A work queue of functions that may have been modified and should be
208208 /// analyzed again.
209 std::vectorVH> Deferred;
209 std::vectorTrackingVH> Deferred;
210210
211211 /// Checks the rules of order relation introduced among functions set.
212212 /// Returns true, if sanity check has been passed, and false if failed.
213 bool doSanityCheck(std::vectorVH> &Worklist);
213 bool doSanityCheck(std::vectorTrackingVH> &Worklist);
214214
215215 /// Insert a ComparableFunction into the FnTree, or merge it away if it's
216216 /// equal to one that's already present.
282282 return new MergeFunctions();
283283 }
284284
285 bool MergeFunctions::doSanityCheck(std::vectorVH> &Worklist) {
285 bool MergeFunctions::doSanityCheck(std::vectorTrackingVH> &Worklist) {
286286 if (const unsigned Max = NumFunctionsForSanityCheck) {
287287 unsigned TripleNumber = 0;
288288 bool Valid = true;
290290 dbgs() << "MERGEFUNC-SANITY: Started for first " << Max << " functions.\n";
291291
292292 unsigned i = 0;
293 for (std::vectorVH>::iterator I = Worklist.begin(), E = Worklist.end();
293 for (std::vectorTrackingVH>::iterator I = Worklist.begin(),
294 E = Worklist.end();
294295 I != E && i < Max; ++I, ++i) {
295296 unsigned j = i;
296 for (std::vectorVH>::iterator J = I; J != E && j < Max; ++J, ++j) {
297 for (std::vectorTrackingVH>::iterator J = I; J != E && j < Max;
298 ++J, ++j) {
297299 Function *F1 = cast(*I);
298300 Function *F2 = cast(*J);
299301 int Res1 = FunctionComparator(F1, F2, &GlobalNumbers).compare();
311313 continue;
312314
313315 unsigned k = j;
314 for (std::vectorVH>::iterator K = J; K != E && k < Max;
316 for (std::vectorTrackingVH>::iterator K = J; K != E && k < Max;
315317 ++k, ++K, ++TripleNumber) {
316318 if (K == J)
317319 continue;
380382 // consider merging it. Otherwise it is dropped and never considered again.
381383 if ((I != S && std::prev(I)->first == I->first) ||
382384 (std::next(I) != IE && std::next(I)->first == I->first) ) {
383 Deferred.push_back(WeakVH(I->second));
385 Deferred.push_back(WeakTrackingVH(I->second));
384386 }
385387 }
386388
387389 do {
388 std::vectorVH> Worklist;
390 std::vectorTrackingVH> Worklist;
389391 Deferred.swap(Worklist);
390392
391393 DEBUG(doSanityCheck(Worklist));
394396 DEBUG(dbgs() << "size of worklist: " << Worklist.size() << '\n');
395397
396398 // Insert functions and merge them.
397 for (WeakVH &I : Worklist) {
399 for (WeakTrackingVH &I : Worklist) {
398400 if (!I)
399401 continue;
400402 Function *F = cast(I);
19471947 return isAllocLikeFn(V, TLI) && V != AI;
19481948 }
19491949
1950 static bool
1951 isAllocSiteRemovable(Instruction *AI, SmallVectorImpl &Users,
1952 const TargetLibraryInfo *TLI) {
1950 static bool isAllocSiteRemovable(Instruction *AI,
1951 SmallVectorImpl &Users,
1952 const TargetLibraryInfo *TLI) {
19531953 SmallVector Worklist;
19541954 Worklist.push_back(AI);
19551955
20332033 // If we have a malloc call which is only used in any amount of comparisons
20342034 // to null and free calls, delete the calls and replace the comparisons with
20352035 // true or false as appropriate.
2036 SmallVectorVH, 64> Users;
2036 SmallVectorTrackingVH, 64> Users;
20372037 if (isAllocSiteRemovable(&MI, Users, &TLI)) {
20382038 for (unsigned i = 0, e = Users.size(); i != e; ++i) {
20392039 // Lowering all @llvm.objectsize calls first because they may
9696 TargetLibraryInfo *TLI;
9797 const TargetTransformInfo *TTI;
9898
99 SmallVectorVH, 16> DeadInsts;
99 SmallVectorTrackingVH, 16> DeadInsts;
100100 bool Changed = false;
101101
102102 bool isValidRewrite(Value *FromVal, Value *ToVal);
414414 Compare->getName());
415415
416416 // In the following deletions, PN may become dead and may be deleted.
417 // Use a WeakVH to observe whether this happens.
418 WeakVH WeakPH = PN;
417 // Use a WeakTrackingVH to observe whether this happens.
418 WeakTrackingVH WeakPH = PN;
419419
420420 // Delete the old floating point exit comparison. The branch starts using the
421421 // new comparison.
450450 //
451451 BasicBlock *Header = L->getHeader();
452452
453 SmallVectorVH, 8> PHIs;
453 SmallVectorTrackingVH, 8> PHIs;
454454 for (BasicBlock::iterator I = Header->begin();
455455 PHINode *PN = dyn_cast(I); ++I)
456456 PHIs.push_back(PN);
900900 PHINode *WidePhi;
901901 Instruction *WideInc;
902902 const SCEV *WideIncExpr;
903 SmallVectorImplVH> &DeadInsts;
903 SmallVectorImplTrackingVH> &DeadInsts;
904904
905905 SmallPtrSet Widened;
906906 SmallVector NarrowIVUsers;
940940 }
941941
942942 public:
943 WidenIV(const WideIVInfo &WI, LoopInfo *LInfo,
944 ScalarEvolution *SEv, DominatorTree *DTree,
945 SmallVectorImpl &DI, bool HasGuards) :
946 OrigPhi(WI.NarrowIV),
947 WideType(WI.WidestNativeType),
948 LI(LInfo),
949 L(LI->getLoopFor(OrigPhi->getParent())),
950 SE(SEv),
951 DT(DTree),
952 HasGuards(HasGuards),
953 WidePhi(nullptr),
954 WideInc(nullptr),
955 WideIncExpr(nullptr),
956 DeadInsts(DI) {
943 WidenIV(const WideIVInfo &WI, LoopInfo *LInfo, ScalarEvolution *SEv,
944 DominatorTree *DTree, SmallVectorImpl &DI,
945 bool HasGuards)
946 : OrigPhi(WI.NarrowIV), WideType(WI.WidestNativeType), LI(LInfo),
947 L(LI->getLoopFor(OrigPhi->getParent())), SE(SEv), DT(DTree),
948 HasGuards(HasGuards), WidePhi(nullptr), WideInc(nullptr),
949 WideIncExpr(nullptr), DeadInsts(DI) {
957950 assert(L->getHeader() == OrigPhi->getParent() && "Phi must be an IV");
958951 ExtendKindMap[OrigPhi] = WI.IsSigned ? SignExtended : ZeroExtended;
959952 }
498498 Instruction *Inst = &*I++;
499499 // Look for memset instructions, which may be optimized to a larger memset.
500500 if (MemSetInst *MSI = dyn_cast(Inst)) {
501 WeakVH InstPtr(&*I);
501 WeakTrackingVH InstPtr(&*I);
502502 if (!processLoopMemSet(MSI, BECount))
503503 continue;
504504 MadeChange = true;
3939 bool Changed = false;
4040 // Copy blocks into a temporary array to avoid iterator invalidation issues
4141 // as we remove them.
42 SmallVectorVH, 16> Blocks(L.blocks());
42 SmallVectorTrackingVH, 16> Blocks(L.blocks());
4343
4444 for (auto &Block : Blocks) {
4545 // Attempt to merge blocks in the trivial case. Don't modify blocks which
899899 /// If any of the instructions is the specified set are trivially dead, delete
900900 /// them and see if this makes any of their operands subsequently dead.
901901 static bool
902 DeleteTriviallyDeadInstructions(SmallVectorImplVH> &DeadInsts) {
902 DeleteTriviallyDeadInstructions(SmallVectorImplTrackingVH> &DeadInsts) {
903903 bool Changed = false;
904904
905905 while (!DeadInsts.empty()) {
18441844 void FinalizeChain(IVChain &Chain);
18451845 void CollectChains();
18461846 void GenerateIVChain(const IVChain &Chain, SCEVExpander &Rewriter,
1847 SmallVectorImplVH> &DeadInsts);
1847 SmallVectorImplTrackingVH> &DeadInsts);
18481848
18491849 void CollectInterestingTypesAndFactors();
18501850 void CollectFixupsAndInitialFormulae();
19191919 const LSRUse &LU,
19201920 SCEVExpander &Rewriter) const;
19211921
1922 Value *Expand(const LSRUse &LU, const LSRFixup &LF,
1923 const Formula &F,
1924 BasicBlock::iterator IP,
1925 SCEVExpander &Rewriter,
1926 SmallVectorImpl &DeadInsts) const;
1922 Value *Expand(const LSRUse &LU, const LSRFixup &LF, const Formula &F,
1923 BasicBlock::iterator IP, SCEVExpander &Rewriter,
1924 SmallVectorImpl &DeadInsts) const;
19271925 void RewriteForPHI(PHINode *PN, const LSRUse &LU, const LSRFixup &LF,
1928 const Formula &F,
1929 SCEVExpander &Rewriter,
1930 SmallVectorImpl &DeadInsts) const;
1931 void Rewrite(const LSRUse &LU, const LSRFixup &LF,
1932 const Formula &F,
1926 const Formula &F, SCEVExpander &Rewriter,
1927 SmallVectorImpl &DeadInsts) const;
1928 void Rewrite(const LSRUse &LU, const LSRFixup &LF, const Formula &F,
19331929 SCEVExpander &Rewriter,
1934 SmallVectorImplVH> &DeadInsts) const;
1930 SmallVectorImplTrackingVH> &DeadInsts) const;
19351931 void ImplementSolution(const SmallVectorImpl &Solution);
19361932
19371933 public:
30133009 /// Generate an add or subtract for each IVInc in a chain to materialize the IV
30143010 /// user's operand from the previous IV user's operand.
30153011 void LSRInstance::GenerateIVChain(const IVChain &Chain, SCEVExpander &Rewriter,
3016 SmallVectorImplVH> &DeadInsts) {
3012 SmallVectorImplTrackingVH> &DeadInsts) {
30173013 // Find the new IVOperand for the head of the chain. It may have been replaced
30183014 // by LSR.
30193015 const IVInc &Head = Chain.Incs[0];
47584754
47594755 /// Emit instructions for the leading candidate expression for this LSRUse (this
47604756 /// is called "expanding").
4761 Value *LSRInstance::Expand(const LSRUse &LU,
4762 const LSRFixup &LF,
4763 const Formula &F,
4764 BasicBlock::iterator IP,
4757 Value *LSRInstance::Expand(const LSRUse &LU, const LSRFixup &LF,
4758 const Formula &F, BasicBlock::iterator IP,
47654759 SCEVExpander &Rewriter,
4766 SmallVectorImplVH> &DeadInsts) const {
4760 SmallVectorImplTrackingVH> &DeadInsts) const {
47674761 if (LU.RigidFormula)
47684762 return LF.OperandValToReplace;
47694763
49384932 /// Helper for Rewrite. PHI nodes are special because the use of their operands
49394933 /// effectively happens in their predecessor blocks, so the expression may need
49404934 /// to be expanded in multiple places.
4941 void LSRInstance::RewriteForPHI(PHINode *PN,
4942 const LSRUse &LU,
4943 const LSRFixup &LF,
4944 const Formula &F,
4945 SCEVExpander &Rewriter,
4946 SmallVectorImpl &DeadInsts) const {
4935 void LSRInstance::RewriteForPHI(
4936 PHINode *PN, const LSRUse &LU, const LSRFixup &LF, const Formula &F,
4937 SCEVExpander &Rewriter, SmallVectorImpl &DeadInsts) const {
49474938 DenseMap Inserted;
49484939 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
49494940 if (PN->getIncomingValue(i) == LF.OperandValToReplace) {
50155006 /// Emit instructions for the leading candidate expression for this LSRUse (this
50165007 /// is called "expanding"), and update the UserInst to reference the newly
50175008 /// expanded value.
5018 void LSRInstance::Rewrite(const LSRUse &LU,
5019 const LSRFixup &LF,
5020 const Formula &F,
5021 SCEVExpander &Rewriter,
5022 SmallVectorImpl &DeadInsts) const {
5009 void LSRInstance::Rewrite(const LSRUse &LU, const LSRFixup &LF,
5010 const Formula &F, SCEVExpander &Rewriter,
5011 SmallVectorImpl &DeadInsts) const {
50235012 // First, find an insertion point that dominates UserInst. For PHI nodes,
50245013 // find the nearest block which dominates all the relevant uses.
50255014 if (PHINode *PN = dyn_cast(LF.UserInst)) {
50575046 const SmallVectorImpl &Solution) {
50585047 // Keep track of instructions we may have made dead, so that
50595048 // we can remove them after we are done working.
5060 SmallVectorVH, 16> DeadInsts;
5049 SmallVectorTrackingVH, 16> DeadInsts;
50615050
50625051 SCEVExpander Rewriter(SE, L->getHeader()->getModule()->getDataLayout(),
50635052 "lsr");
53075296 // Remove any extra phis created by processing inner loops.
53085297 Changed |= DeleteDeadPHIs(L->getHeader());
53095298 if (EnablePhiElim && L->isLoopSimplifyForm()) {
5310 SmallVectorVH, 16> DeadInsts;
5299 SmallVectorTrackingVH, 16> DeadInsts;
53115300 const DataLayout &DL = L->getHeader()->getModule()->getDataLayout();
53125301 SCEVExpander Rewriter(SE, DL, "lsr");
53135302 #ifndef NDEBUG
12301230 LoopProcessWorklist.push_back(NewLoop);
12311231 redoLoop = true;
12321232
1233 // Keep a WeakVH holding onto LIC. If the first call to RewriteLoopBody
1234 // deletes the instruction (for example by simplifying a PHI that feeds into
1235 // the condition that we're unswitching on), we don't rewrite the second
1236 // iteration.
1237 WeakVH LICHandle(LIC);
1233 // Keep a WeakTrackingVH holding onto LIC. If the first call to
1234 // RewriteLoopBody deletes the instruction (for example by simplifying a PHI
1235 // that feeds into the condition that we're unswitching on), we don't rewrite
1236 // the second iteration.
1237 WeakTrackingVH LICHandle(LIC);
12381238
12391239 // Now we rewrite the original code to know that the condition is true and the
12401240 // new code to know that the condition is false.
210210 Changed = true;
211211 SE->forgetValue(&*I);
212212 I->replaceAllUsesWith(NewI);
213 // If SeenExprs constains I's WeakVH, that entry will be replaced with
214 // nullptr.
213 // If SeenExprs constains I's WeakTrackingVH, that entry will be
214 // replaced with nullptr.
215215 RecursivelyDeleteTriviallyDeadInstructions(&*I, TLI);
216216 I = NewI->getIterator();
217217 }
218218 // Add the rewritten instruction to SeenExprs; the original instruction
219219 // is deleted.
220220 const SCEV *NewSCEV = SE->getSCEV(&*I);
221 SeenExprs[NewSCEV].push_back(WeakVH(&*I));
221 SeenExprs[NewSCEV].push_back(WeakTrackingVH(&*I));
222222 // Ideally, NewSCEV should equal OldSCEV because tryReassociate(I)
223223 // is equivalent to I. However, ScalarEvolution::getSCEV may
224224 // weaken nsw causing NewSCEV not to equal OldSCEV. For example, suppose
238238 //
239239 // This improvement is exercised in @reassociate_gep_nsw in nary-gep.ll.
240240 if (NewSCEV != OldSCEV)
241 SeenExprs[OldSCEV].push_back(WeakVH(&*I));
241 SeenExprs[OldSCEV].push_back(WeakTrackingVH(&*I));
242242 }
243243 }
244244 }
493493 // future instruction either. Therefore, we pop it out of the stack. This
494494 // optimization makes the algorithm O(n).
495495 while (!Candidates.empty()) {
496 // Candidates stores WeakVHs, so a candidate can be nullptr if it's removed
497 // during rewriting.
496 // Candidates stores WeakTrackingVHs, so a candidate can be nullptr if it's
497 // removed during rewriting.
498498 if (Value *Candidate = Candidates.back()) {
499499 Instruction *CandidateInstruction = cast(Candidate);
500500 if (DT->dominates(CandidateInstruction, Dominatee))
981981 /// Emit a tree of add instructions, summing Ops together
982982 /// and returning the result. Insert the tree before I.
983983 static Value *EmitAddTreeOfValues(Instruction *I,
984 SmallVectorImplVH> &Ops){
984 SmallVectorImplTrackingVH> &Ops) {
985985 if (Ops.size() == 1) return Ops.back();
986986
987987 Value *V1 = Ops.back();
15581558 ? BinaryOperator::CreateAdd(MaxOccVal, MaxOccVal)
15591559 : BinaryOperator::CreateFAdd(MaxOccVal, MaxOccVal);
15601560
1561 SmallVectorVH, 4> NewMulOps;
1561 SmallVectorTrackingVH, 4> NewMulOps;
15621562 for (unsigned i = 0; i != Ops.size(); ++i) {
15631563 // Only try to remove factors from expressions we're allowed to.
15641564 BinaryOperator *BOp =
7777
7878 bool llvm::DeleteDeadPHIs(BasicBlock *BB, const TargetLibraryInfo *TLI) {
7979 // Recursively deleting a PHI may cause multiple PHIs to be deleted
80 // or RAUW'd undef, so use an array of WeakVH for the PHIs to delete.
81 SmallVector PHIs;
80 // or RAUW'd undef, so use an array of WeakTrackingVH for the PHIs to delete.
81 SmallVector PHIs;
8282 for (BasicBlock::iterator I = BB->begin();
8383 PHINode *PN = dyn_cast(I); ++I)
8484 PHIs.push_back(PN);
244244 void PruningFunctionCloner::CloneBlock(const BasicBlock *BB,
245245 BasicBlock::const_iterator StartingInst,
246246 std::vector &ToClone){
247 WeakVH &BBEntry = VMap[BB];
247 WeakTrackingVH &BBEntry = VMap[BB];
248248
249249 // Have we already cloned this block?
250250 if (BBEntry) return;
546546 // Make a second pass over the PHINodes now that all of them have been
547547 // remapped into the new function, simplifying the PHINode and performing any
548548 // recursive simplifications exposed. This will transparently update the
549 // WeakVH in the VMap. Notably, we rely on that so that if we coalesce
549 // WeakTrackingVH in the VMap. Notably, we rely on that so that if we coalesce
550550 // two PHINodes, the iteration over the old PHIs remains valid, and the
551551 // mapping will just map us to the new node (which may not even be a PHI
552552 // node).
560560 // that can be removed.
561561 BB->removePredecessor(Pred, true);
562562
563 WeakVH PhiIt = &BB->front();
563 WeakTrackingVH PhiIt = &BB->front();
564564 while (PHINode *PN = dyn_cast(PhiIt)) {
565565 PhiIt = &*++BasicBlock::iterator(cast(PhiIt));
566566 Value *OldPhiIt = PhiIt;
15181518 II->setAttributes(CI->getAttributes());
15191519
15201520 // Make sure that anything using the call now uses the invoke! This also
1521 // updates the CallGraph if present, because it uses a WeakVH.
1521 // updates the CallGraph if present, because it uses a WeakTrackingVH.
15221522 CI->replaceAllUsesWith(II);
15231523
15241524 // Delete the original call
756756
757757 // Simplify any new induction variables in the partially unrolled loop.
758758 if (SE && !CompletelyUnroll && Count > 1) {
759 SmallVectorVH, 16> DeadInsts;
759 SmallVectorTrackingVH, 16> DeadInsts;
760760 simplifyLoopIVs(L, SE, DT, LI, DeadInsts);
761761
762762 // Aggressively clean up dead instructions that simplifyLoopIVs already
5050 ScalarEvolution *SE;
5151 DominatorTree *DT;
5252
53 SmallVectorImplVH> &DeadInsts;
53 SmallVectorImplTrackingVH> &DeadInsts;
5454
5555 bool Changed;
5656
5757 public:
5858 SimplifyIndvar(Loop *Loop, ScalarEvolution *SE, DominatorTree *DT,
59 LoopInfo *LI,SmallVectorImplVH> &Dead)
59 LoopInfo *LI, SmallVectorImplVH> &Dead)
6060 : L(Loop), LI(LI), SE(SE), DT(DT), DeadInsts(Dead), Changed(false) {
6161 assert(LI && "IV simplification requires LoopInfo");
6262 }
700700 /// Simplify instructions that use this induction variable
701701 /// by using ScalarEvolution to analyze the IV's recurrence.
702702 bool simplifyUsersOfIV(PHINode *CurrIV, ScalarEvolution *SE, DominatorTree *DT,
703 LoopInfo *LI, SmallVectorImplVH> &Dead,
703 LoopInfo *LI, SmallVectorImplTrackingVH> &Dead,
704704 IVVisitor *V) {
705705 SimplifyIndvar SIV(LI->getLoopFor(CurrIV->getParent()), SE, DT, LI, Dead);
706706 SIV.simplifyUsers(CurrIV, V);
710710 /// Simplify users of induction variables within this
711711 /// loop. This does not actually change or add IVs.
712712 bool simplifyLoopIVs(Loop *L, ScalarEvolution *SE, DominatorTree *DT,
713 LoopInfo *LI, SmallVectorImplVH> &Dead) {
713 LoopInfo *LI, SmallVectorImplTrackingVH> &Dead) {
714714 bool Changed = false;
715715 for (BasicBlock::iterator I = L->getHeader()->begin(); isa(I); ++I) {
716716 Changed |= simplifyUsersOfIV(cast(I), SE, DT, LI, Dead);
38983898 }
38993899
39003900 /// \brief Check that the Values in the slice in VL array are still existent in
3901 /// the WeakVH array.
3901 /// the WeakTrackingVH array.
39023902 /// Vectorization of part of the VL array may cause later values in the VL array
3903 /// to become invalid. We track when this has happened in the WeakVH array.
3904 static bool hasValueBeenRAUWed(ArrayRef VL, ArrayRef VH,
3905 unsigned SliceBegin, unsigned SliceSize) {
3903 /// to become invalid. We track when this has happened in the WeakTrackingVH
3904 /// array.
3905 static bool hasValueBeenRAUWed(ArrayRef VL,
3906 ArrayRef VH, unsigned SliceBegin,
3907 unsigned SliceSize) {
39063908 VL = VL.slice(SliceBegin, SliceSize);
39073909 VH = VH.slice(SliceBegin, SliceSize);
39083910 return !std::equal(VL.begin(), VL.end(), VH.begin());
39203922 return false;
39213923
39223924 // Keep track of values that were deleted by vectorizing in the loop below.
3923 SmallVectorVH, 8> TrackValues(Chain.begin(), Chain.end());
3925 SmallVectorTrackingVH, 8> TrackValues(Chain.begin(), Chain.end());
39243926
39253927 bool Changed = false;
39263928 // Look for profitable vectorizable trees at all offsets, starting at zero.
41064108 bool Changed = false;
41074109
41084110 // Keep track of values that were deleted by vectorizing in the loop below.
4109 SmallVectorVH, 8> TrackValues(VL.begin(), VL.end());
4111 SmallVectorTrackingVH, 8> TrackValues(VL.begin(), VL.end());
41104112
41114113 unsigned NextInst = 0, MaxInst = VL.size();
41124114 for (unsigned VF = MaxVF; NextInst + 1 < MaxInst && VF >= MinVF;
47334735
47344736 namespace {
47354737 /// Tracks instructons and its children.
4736 class WeakVHWithLevel final : public CallbackVH {
4738 class WeakTrackingVHWithLevel final : public CallbackVH {
47374739 /// Operand index of the instruction currently beeing analized.
47384740 unsigned Level = 0;
47394741 /// Is this the instruction that should be vectorized, or are we now
47424744 bool IsInitial = true;
47434745
47444746 public:
4745 explicit WeakVHWithLevel() = default;
4746 WeakVHWithLevel(Value *V) : CallbackVH(V){};
4747 explicit WeakTrackingVHWithLevel() = default;
4748 WeakTrackingVHWithLevel(Value *V) : CallbackVH(V){};
47474749 /// Restart children analysis each time it is repaced by the new instruction.
47484750 void allUsesReplacedWith(Value *New) override {
47494751 setValPtr(New);
47704772 cast(getValPtr())->getNumOperands() > Level);
47714773 return cast(getValPtr())->getOperand(Level++);
47724774 }
4773 virtual ~WeakVHWithLevel() = default;
4775 virtual ~WeakTrackingVHWithLevel() = default;
47744776 };
47754777 } // namespace
47764778
47924794
47934795 if (Root->getParent() != BB)
47944796 return false;
4795 SmallVectorVHWithLevel, 8> Stack(1, Root);
4797 SmallVectorTrackingVHWithLevel, 8> Stack(1, Root);
47964798 SmallSet VisitedInstrs;
47974799 bool Res = false;
47984800 while (!Stack.empty()) {
50685070 SetVector Candidates(GEPList.begin(), GEPList.end());
50695071
50705072 // Some of the candidates may have already been vectorized after we
5071 // initially collected them. If so, the WeakVHs will have nullified the
5072 // values, so remove them from the set of candidates.
5073 // initially collected them. If so, the WeakTrackingVHs will have
5074 // nullified the values, so remove them from the set of candidates.
50735075 Candidates.remove(nullptr);
50745076
50755077 // Remove from the set of candidates all pairs of getelementptrs with
3333 ConcreteCallbackVH(Value *V) : CallbackVH(V) {}
3434 };
3535
36 TEST_F(ValueHandle, WeakVH_BasicOperation) {
37 WeakVH WVH(BitcastV.get());
36 TEST_F(ValueHandle, WeakTrackingVH_BasicOperation) {
37 WeakTrackingVH WVH(BitcastV.get());
3838 EXPECT_EQ(BitcastV.get(), WVH);
3939 WVH = ConstantV;
4040 EXPECT_EQ(ConstantV, WVH);
4545 EXPECT_EQ(Type::getInt32Ty(Context), (*WVH).getType());
4646 }
4747
48 TEST_F(ValueHandle, WeakVH_Comparisons) {
49 WeakVH BitcastWVH(BitcastV.get());
50 WeakVH ConstantWVH(ConstantV);
48 TEST_F(ValueHandle, WeakTrackingVH_Comparisons) {
49 WeakTrackingVH BitcastWVH(BitcastV.get());
50 WeakTrackingVH ConstantWVH(ConstantV);
5151
5252 EXPECT_TRUE(BitcastWVH == BitcastWVH);
5353 EXPECT_TRUE(BitcastV.get() == BitcastWVH);
7878 EXPECT_EQ(BV >= CV, BitcastWVH >= ConstantV);
7979 }
8080
81 TEST_F(ValueHandle, WeakVH_FollowsRAUW) {
82 WeakVH WVH(BitcastV.get());
83 WeakVH WVH_Copy(WVH);
84 WeakVH WVH_Recreated(BitcastV.get());
81 TEST_F(ValueHandle, WeakTrackingVH_FollowsRAUW) {
82 WeakTrackingVH WVH(BitcastV.get());
83 WeakTrackingVH WVH_Copy(WVH);
84 WeakTrackingVH WVH_Recreated(BitcastV.get());
8585 BitcastV->replaceAllUsesWith(ConstantV);
8686 EXPECT_EQ(ConstantV, WVH);
8787 EXPECT_EQ(ConstantV, WVH_Copy);
8888 EXPECT_EQ(ConstantV, WVH_Recreated);
8989 }
9090
91 TEST_F(ValueHandle, WeakVH_NullOnDeletion) {
92 WeakVH WVH(BitcastV.get());
93 WeakVH WVH_Copy(WVH);
94 WeakVH WVH_Recreated(BitcastV.get());
91 TEST_F(ValueHandle, WeakTrackingVH_NullOnDeletion) {
92 WeakTrackingVH WVH(BitcastV.get());
93 WeakTrackingVH WVH_Copy(WVH);
94 WeakTrackingVH WVH_Recreated(BitcastV.get());
9595 BitcastV.reset();
9696 Value *null_value = nullptr;
9797 EXPECT_EQ(null_value, WVH);
342342
343343 class DestroyingVH final : public CallbackVH {
344344 public:
345 std::unique_ptrVH> ToClear[2];
345 std::unique_ptrTrackingVH> ToClear[2];
346346 DestroyingVH(Value *V) {
347 ToClear[0].reset(new WeakVH(V));
347 ToClear[0].reset(new WeakTrackingVH(V));
348348 setValPtr(V);
349 ToClear[1].reset(new WeakVH(V));
349 ToClear[1].reset(new WeakTrackingVH(V));
350350 }
351351 void deleted() override {
352352 ToClear[0].reset();
360360 };
361361
362362 {
363 WeakVH ShouldBeVisited1(BitcastV.get());
363 WeakTrackingVH ShouldBeVisited1(BitcastV.get());
364364 DestroyingVH C(BitcastV.get());
365 WeakVH ShouldBeVisited2(BitcastV.get());
365 WeakTrackingVH ShouldBeVisited2(BitcastV.get());
366366
367367 BitcastV->replaceAllUsesWith(ConstantV);
368368 EXPECT_EQ(ConstantV, static_cast(ShouldBeVisited1));
370370 }
371371
372372 {
373 WeakVH ShouldBeVisited1(BitcastV.get());
373 WeakTrackingVH ShouldBeVisited1(BitcastV.get());
374374 DestroyingVH C(BitcastV.get());
375 WeakVH ShouldBeVisited2(BitcastV.get());
375 WeakTrackingVH ShouldBeVisited2(BitcastV.get());
376376
377377 BitcastV.reset();
378378 EXPECT_EQ(nullptr, static_cast(ShouldBeVisited1));