llvm.org GIT mirror llvm / 263da12
Reverts commit r301424, r301425 and r301426 Commits were: "Use WeakVH instead of WeakTrackingVH in AliasSetTracker's UnkownInsts" "Add a new WeakVH value handle; NFC" "Rename WeakVH to WeakTrackingVH; NFC" The changes assumed pointers are 8 byte aligned on all architectures. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@301429 91177308-0d34-0410-b5e6-96231b3b80d8 Sanjoy Das 3 years ago
40 changed file(s) with 210 addition(s) and 279 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 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.
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.
21612161
21622162 .. _dss_intervalmap:
21632163
4242
4343 /// \brief Vector of weak value handles to calls of the @llvm.assume
4444 /// intrinsic.
45 SmallVectorTrackingVH, 4> AssumeHandles;
45 SmallVectorVH, 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 SmallVectorTrackingVH, 1> &getOrInsertAffectedValues(Value *V);
69 SmallVectorVH, 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 MutableArrayRefTrackingVH> assumptions() {
122 MutableArrayRefVH> assumptions() {
123123 if (!Scanned)
124124 scanFunction();
125125 return AssumeHandles;
126126 }
127127
128128 /// \brief Access the list of assumptions which affect this value.
129 MutableArrayRefTrackingVH> assumptionsFor(const Value *V) {
129 MutableArrayRefVH> 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 MutableArrayRefTrackingVH>();
135 return MutableArrayRefVH>();
136136
137137 return AVI->second;
138138 }
645645 LazyCallGraph::SCC *C = &InitialC;
646646
647647 // Collect value handles for all of the indirect call sites.
648 SmallVectorTrackingVH, 8> CallHandles;
648 SmallVectorVH, 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 SmallVectorImplTrackingVH> &CallHandles) {
660 SmallVectorImplVH> &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(WeakTrackingVH(&I));
673 CallHandles.push_back(WeakVH(&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 = [&](WeakTrackingVH &CallH) {
701 auto IsDevirtualizedHandle = [&](WeakVH &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::pairTrackingVH, CallGraphNode *> CallRecord;
174 typedef std::pairVH, 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 WeakTrackingVH OperandValToReplace;
82 WeakVH 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::pairTrackingVH, WeakTrackingVH> WeakEvalType;
237 typedef std::pairVH, WeakVH> 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 SmallVectorImplTrackingVH> &DeadInsts,
191 SmallVectorImplVH> &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 { Assert, Callback, Tracking, Weak, WeakTracking };
36 enum HandleBaseKind {
37 Assert,
38 Callback,
39 Tracking,
40 Weak
41 };
3742
3843 ValueHandleBase(const ValueHandleBase &RHS)
3944 : ValueHandleBase(RHS.PrevPair.getInt(), RHS) {}
4550 }
4651
4752 private:
48 PointerIntPair3, HandleBaseKind> PrevPair;
53 PointerIntPair2, HandleBaseKind> PrevPair;
4954 ValueHandleBase *Next;
5055
5156 Value* V;
125130 void AddToUseList();
126131 };
127132
128 /// \brief A nullable Value handle that is nullable.
129 ///
130 /// This is a value handle that points to a value, and nulls itself
131 /// out if that value is deleted.
133 /// \brief Value handle that is nullable, but tries to track the Value.
134 ///
135 /// This is a value handle that tries hard to point to a Value, even across
136 /// RAUW operations, but will null itself out if the value is destroyed. this
137 /// is useful for advisory sorts of information, but should not be used as the
138 /// key of a map (since the map would have to rearrange itself when the pointer
139 /// changes).
132140 class WeakVH : public ValueHandleBase {
133141 public:
134142 WeakVH() : ValueHandleBase(Weak) {}
135143 WeakVH(Value *P) : ValueHandleBase(Weak, P) {}
136144 WeakVH(const WeakVH &RHS)
137 : ValueHandleBase(Weak, RHS) {}
145 : ValueHandleBase(Weak, RHS) {}
138146
139147 WeakVH &operator=(const WeakVH &RHS) = default;
140148
159167 template <> struct simplify_type {
160168 typedef Value *SimpleType;
161169 static SimpleType getSimplifiedValue(const WeakVH &WVH) { return WVH; }
162 };
163
164 /// \brief Value handle that is nullable, but tries to track the Value.
165 ///
166 /// This is a value handle that tries hard to point to a Value, even across
167 /// RAUW operations, but will null itself out if the value is destroyed. this
168 /// is useful for advisory sorts of information, but should not be used as the
169 /// key of a map (since the map would have to rearrange itself when the pointer
170 /// changes).
171 class WeakTrackingVH : public ValueHandleBase {
172 public:
173 WeakTrackingVH() : ValueHandleBase(WeakTracking) {}
174 WeakTrackingVH(Value *P) : ValueHandleBase(WeakTracking, P) {}
175 WeakTrackingVH(const WeakTrackingVH &RHS)
176 : ValueHandleBase(WeakTracking, RHS) {}
177
178 WeakTrackingVH &operator=(const WeakTrackingVH &RHS) = default;
179
180 Value *operator=(Value *RHS) {
181 return ValueHandleBase::operator=(RHS);
182 }
183 Value *operator=(const ValueHandleBase &RHS) {
184 return ValueHandleBase::operator=(RHS);
185 }
186
187 operator Value*() const {
188 return getValPtr();
189 }
190 };
191
192 // Specialize simplify_type to allow WeakTrackingVH to participate in
193 // dyn_cast, isa, etc.
194 template <> struct simplify_type {
195 typedef Value *SimpleType;
196 static SimpleType getSimplifiedValue(WeakTrackingVH &WVH) { return WVH; }
197 };
198 template <> struct simplify_type {
199 typedef Value *SimpleType;
200 static SimpleType getSimplifiedValue(const WeakTrackingVH &WVH) {
201 return WVH;
202 }
203170 };
204171
205172 /// \brief Value handle that asserts if the Value is deleted.
391358 ///
392359 /// Called when this->getValPtr() is destroyed, inside ~Value(), so you
393360 /// may call any non-virtual Value method on getValPtr(), but no subclass
394 /// methods. If WeakTrackingVH were implemented as a CallbackVH, it would use
395 /// this method to call setValPtr(NULL). AssertingVH would use this method to
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
396363 /// cause an assertion failure.
397364 ///
398365 /// All implementations must remove the reference from this object to the
402369 /// \brief Callback for Value RAUW.
403370 ///
404371 /// Called when this->getValPtr()->replaceAllUsesWith(new_value) is called,
405 /// _before_ any of the uses have actually been replaced. If WeakTrackingVH
406 /// were implemented as a CallbackVH, it would use this method to call
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
407374 /// setValPtr(new_value). AssertingVH would do nothing in this method.
408375 virtual void allUsesReplacedWith(Value *) {}
409376 };
166166 // foo(a + b);
167167 // if (p2)
168168 // bar(a + b);
169 DenseMapTrackingVH, 2>> SeenExprs;
169 DenseMapVH, 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::vectorTrackingVH> OperandBundleCallSites;
76 std::vectorVH> 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 SmallVectorTrackingVH, 8> InlinedCalls;
194 SmallVectorVH, 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, SmallVectorImplTrackingVH> &Dead,
48 LoopInfo *LI, SmallVectorImplVH> &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, SmallVectorImplTrackingVH> &Dead);
54 LoopInfo *LI, SmallVectorImplVH> &Dead);
5555
5656 } // end namespace llvm
5757
2222
2323 class Value;
2424 class Instruction;
25 typedef ValueMapTrackingVH> ValueToValueMapTy;
25 typedef ValueMapVH> 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 WeakTrackingVHList;
43 typedef MapVector WeakTrackingVHListMap;
42 typedef SmallVector WeakVHList;
43 typedef MapVector WeakVHListMap;
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 WeakTrackingVHListMap GEPs;
113 WeakVHListMap GEPs;
114114 };
115115 }
116116
2828 cl::desc("Enable verification of assumption cache"),
2929 cl::init(false));
3030
31 SmallVector &
32 AssumptionCache::getOrInsertAffectedValues(Value *V) {
31 SmallVector &AssumptionCache::getOrInsertAffectedValues(Value *V) {
3332 // Try using find_as first to avoid creating extra value handles just for the
3433 // purpose of doing the lookup.
3534 auto AVI = AffectedValues.find_as(V);
3635 if (AVI != AffectedValues.end())
3736 return AVI->second;
3837
39 auto AVIP = AffectedValues.insert(
40 {AffectedValueCallbackVH(V, this), SmallVector()});
38 auto AVIP = AffectedValues.insert({
39 AffectedValueCallbackVH(V, this), SmallVector()});
4140 return AVIP.first->second;
4241 }
4342
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 WeakTrackingVH nulled it out.
206 // entirely and the WeakVH 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. WeakTrackingVH should save us for this, so
350 // abort if this happens.
349 // they are dangling pointers. WeakVH should save us for this, so abort if
350 // 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
1775 SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
1776 SmallVectorImpl &DeadInsts,
1777 const TargetTransformInfo *TTI) {
1774 unsigned SCEVExpander::replaceCongruentIVs(Loop *L, const DominatorTree *DT,
1775 SmallVectorImpl &DeadInsts,
1776 const TargetTransformInfo *TTI) {
17781777 // Find integer phis in order of increasing width.
17791778 SmallVector Phis;
17801779 for (auto &I : *L->getHeader()) {
5757 if (Idx >= size())
5858 resize(Idx + 1);
5959
60 WeakTrackingVH &OldV = ValuePtrs[Idx];
60 WeakVH &OldV = ValuePtrs[Idx];
6161 if (!OldV) {
6262 OldV = V;
6363 return;
1919 class Constant;
2020
2121 class BitcodeReaderValueList {
22 std::vectorTrackingVH> ValuePtrs;
22 std::vectorVH> 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 WeakTrackingVH to hold onto it in case
2229 // this happens.
2228 // invalidate our iterator. Use a WeakVH to hold onto it in case this
2229 // happens.
22302230 Value *CurValue = &*CurInstIterator;
2231 WeakTrackingVH IterHandle(CurValue);
2231 WeakVH 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 WeakTrackingVH to hold onto it in case this happens.
4444 // Use a WeakVH to hold onto it in case this happens.
44454445 Value *CurValue = &*CurInstIterator;
4446 WeakTrackingVH IterHandle(CurValue);
4446 WeakVH IterHandle(CurValue);
44474447 BasicBlock *BB = CurInstIterator->getParent();
44484448
44494449 RecursivelyDeleteTriviallyDeadInstructions(Repl, TLInfo);
825825 Entry->operator=(DenseMapInfo::getTombstoneKey());
826826 break;
827827 case Weak:
828 case WeakTracking:
829 // WeakTracking and Weak just go to null, which unlinks them
830 // from the list.
828 // Weak just goes to null, which will unlink it from the list.
831829 Entry->operator=(nullptr);
832830 break;
833831 case Callback:
875873
876874 switch (Entry->getKind()) {
877875 case Assert:
878 case Weak:
879 // Asserting and Weak handles do not follow RAUW implicitly.
876 // Asserting handle does not follow RAUW implicitly.
880877 break;
881878 case Tracking:
882 // Tracking goes to new value like a WeakTrackingVH. Note that this may
883 // make it something incompatible with its templated type. We don't want
884 // to have a virtual (or inline) interface to handle this though, so
885 // instead we make the TrackingVH accessors guarantee that a client never
886 // sees this value.
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.
887883
888884 LLVM_FALLTHROUGH;
889 case WeakTracking:
890 // WeakTracking goes to the new value, which will unlink it from Old's
891 // list.
885 case Weak:
886 // Weak goes to the new value, which will unlink it from Old's list.
892887 Entry->operator=(New);
893888 break;
894889 case Callback:
905900 for (Entry = pImpl->ValueHandles[Old]; Entry; Entry = Entry->Next)
906901 switch (Entry->getKind()) {
907902 case Tracking:
908 case WeakTracking:
903 case Weak:
909904 dbgs() << "After RAUW from " << *Old->getType() << " %"
910905 << Old->getName() << " to " << *New->getType() << " %"
911906 << New->getName() << "\n";
7676
7777 void insertElse(BranchInst *Term);
7878
79 Value *
80 handleLoopCondition(Value *Cond, PHINode *Broken, llvm::Loop *L,
81 BranchInst *Term,
82 SmallVectorImpl &LoopPhiConditions);
79 Value *handleLoopCondition(Value *Cond, PHINode *Broken,
80 llvm::Loop *L, BranchInst *Term,
81 SmallVectorImpl &LoopPhiConditions);
8382
8483 void handleLoop(BranchInst *Term);
8584
212211
213212 /// \brief Recursively handle the condition leading to a loop
214213 Value *SIAnnotateControlFlow::handleLoopCondition(
215 Value *Cond, PHINode *Broken, llvm::Loop *L, BranchInst *Term,
216 SmallVectorImpl &LoopPhiConditions) {
214 Value *Cond, PHINode *Broken,
215 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(WeakTrackingVH(Phi));
283 LoopPhiConditions.push_back(WeakVH(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 SmallVectorTrackingVH, 8> LoopPhiConditions;
325 SmallVectorVH, 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 (WeakTrackingVH Val : reverse(LoopPhiConditions)) {
335 for (WeakVH 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 SmallVectorTrackingVH, 8> WUsers(CE->user_begin(), CE->user_end());
130 SmallVectorVH,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 (WeakTrackingVH WU = WUsers.pop_back_val()) {
134 if (WeakVH 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 SmallVectorTrackingVH, 8> WUsers;
161 SmallVectorVH,8> WUsers;
162162 for (User *U : GV->users())
163163 if (!isa(U))
164 WUsers.push_back(WeakTrackingVH(U));
164 WUsers.push_back(WeakVH(U));
165165 while (!WUsers.empty())
166 if (WeakTrackingVH WU = WUsers.pop_back_val()) {
166 if (WeakVH 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 SmallVectorTrackingVH, 8> WorkList(V->user_begin(), V->user_end());
241 SmallVectorVH, 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::vectorTrackingVH> Deferred;
209 std::vectorVH> 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::vectorTrackingVH> &Worklist);
213 bool doSanityCheck(std::vectorVH> &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::vectorTrackingVH> &Worklist) {
285 bool MergeFunctions::doSanityCheck(std::vectorVH> &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::vector::iterator I = Worklist.begin(),
294 E = Worklist.end();
293 for (std::vector::iterator I = Worklist.begin(), E = Worklist.end();
295294 I != E && i < Max; ++I, ++i) {
296295 unsigned j = i;
297 for (std::vector::iterator J = I; J != E && j < Max;
298 ++J, ++j) {
296 for (std::vector::iterator J = I; J != E && j < Max; ++J, ++j) {
299297 Function *F1 = cast(*I);
300298 Function *F2 = cast(*J);
301299 int Res1 = FunctionComparator(F1, F2, &GlobalNumbers).compare();
313311 continue;
314312
315313 unsigned k = j;
316 for (std::vectorTrackingVH>::iterator K = J; K != E && k < Max;
314 for (std::vectorVH>::iterator K = J; K != E && k < Max;
317315 ++k, ++K, ++TripleNumber) {
318316 if (K == J)
319317 continue;
382380 // consider merging it. Otherwise it is dropped and never considered again.
383381 if ((I != S && std::prev(I)->first == I->first) ||
384382 (std::next(I) != IE && std::next(I)->first == I->first) ) {
385 Deferred.push_back(WeakTrackingVH(I->second));
383 Deferred.push_back(WeakVH(I->second));
386384 }
387385 }
388386
389387 do {
390 std::vectorTrackingVH> Worklist;
388 std::vectorVH> Worklist;
391389 Deferred.swap(Worklist);
392390
393391 DEBUG(doSanityCheck(Worklist));
396394 DEBUG(dbgs() << "size of worklist: " << Worklist.size() << '\n');
397395
398396 // Insert functions and merge them.
399 for (WeakTrackingVH &I : Worklist) {
397 for (WeakVH &I : Worklist) {
400398 if (!I)
401399 continue;
402400 Function *F = cast(I);
19471947 return isAllocLikeFn(V, TLI) && V != AI;
19481948 }
19491949
1950 static bool isAllocSiteRemovable(Instruction *AI,
1951 SmallVectorImpl &Users,
1952 const TargetLibraryInfo *TLI) {
1950 static bool
1951 isAllocSiteRemovable(Instruction *AI, 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 SmallVectorTrackingVH, 64> Users;
2036 SmallVectorVH, 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 SmallVectorTrackingVH, 16> DeadInsts;
99 SmallVectorVH, 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 WeakTrackingVH to observe whether this happens.
418 WeakTrackingVH WeakPH = PN;
417 // Use a WeakVH to observe whether this happens.
418 WeakVH 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 SmallVectorTrackingVH, 8> PHIs;
453 SmallVectorVH, 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 SmallVectorImplTrackingVH> &DeadInsts;
903 SmallVectorImplVH> &DeadInsts;
904904
905905 SmallPtrSet Widened;
906906 SmallVector NarrowIVUsers;
940940 }
941941
942942 public:
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) {
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) {
950957 assert(L->getHeader() == OrigPhi->getParent() && "Phi must be an IV");
951958 ExtendKindMap[OrigPhi] = WI.IsSigned ? SignExtended : ZeroExtended;
952959 }
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 WeakTrackingVH InstPtr(&*I);
501 WeakVH 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 SmallVectorTrackingVH, 16> Blocks(L.blocks());
42 SmallVectorVH, 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(SmallVectorImplTrackingVH> &DeadInsts) {
902 DeleteTriviallyDeadInstructions(SmallVectorImplVH> &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 SmallVectorImplTrackingVH> &DeadInsts);
1847 SmallVectorImplVH> &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, const Formula &F,
1923 BasicBlock::iterator IP, SCEVExpander &Rewriter,
1924 SmallVectorImpl &DeadInsts) const;
1922 Value *Expand(const LSRUse &LU, const LSRFixup &LF,
1923 const Formula &F,
1924 BasicBlock::iterator IP,
1925 SCEVExpander &Rewriter,
1926 SmallVectorImpl &DeadInsts) const;
19251927 void RewriteForPHI(PHINode *PN, const LSRUse &LU, const LSRFixup &LF,
1926 const Formula &F, SCEVExpander &Rewriter,
1927 SmallVectorImpl &DeadInsts) const;
1928 void Rewrite(const LSRUse &LU, const LSRFixup &LF, const Formula &F,
1928 const Formula &F,
1929 SCEVExpander &Rewriter,
1930 SmallVectorImpl &DeadInsts) const;
1931 void Rewrite(const LSRUse &LU, const LSRFixup &LF,
1932 const Formula &F,
19291933 SCEVExpander &Rewriter,
1930 SmallVectorImplTrackingVH> &DeadInsts) const;
1934 SmallVectorImplVH> &DeadInsts) const;
19311935 void ImplementSolution(const SmallVectorImpl &Solution);
19321936
19331937 public:
30093013 /// Generate an add or subtract for each IVInc in a chain to materialize the IV
30103014 /// user's operand from the previous IV user's operand.
30113015 void LSRInstance::GenerateIVChain(const IVChain &Chain, SCEVExpander &Rewriter,
3012 SmallVectorImplTrackingVH> &DeadInsts) {
3016 SmallVectorImplVH> &DeadInsts) {
30133017 // Find the new IVOperand for the head of the chain. It may have been replaced
30143018 // by LSR.
30153019 const IVInc &Head = Chain.Incs[0];
47544758
47554759 /// Emit instructions for the leading candidate expression for this LSRUse (this
47564760 /// is called "expanding").
4757 Value *LSRInstance::Expand(const LSRUse &LU, const LSRFixup &LF,
4758 const Formula &F, BasicBlock::iterator IP,
4761 Value *LSRInstance::Expand(const LSRUse &LU,
4762 const LSRFixup &LF,
4763 const Formula &F,
4764 BasicBlock::iterator IP,
47594765 SCEVExpander &Rewriter,
4760 SmallVectorImplTrackingVH> &DeadInsts) const {
4766 SmallVectorImplVH> &DeadInsts) const {
47614767 if (LU.RigidFormula)
47624768 return LF.OperandValToReplace;
47634769
49324938 /// Helper for Rewrite. PHI nodes are special because the use of their operands
49334939 /// effectively happens in their predecessor blocks, so the expression may need
49344940 /// to be expanded in multiple places.
4935 void LSRInstance::RewriteForPHI(
4936 PHINode *PN, const LSRUse &LU, const LSRFixup &LF, const Formula &F,
4937 SCEVExpander &Rewriter, SmallVectorImpl &DeadInsts) const {
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 {
49384947 DenseMap Inserted;
49394948 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
49404949 if (PN->getIncomingValue(i) == LF.OperandValToReplace) {
50065015 /// Emit instructions for the leading candidate expression for this LSRUse (this
50075016 /// is called "expanding"), and update the UserInst to reference the newly
50085017 /// expanded value.
5009 void LSRInstance::Rewrite(const LSRUse &LU, const LSRFixup &LF,
5010 const Formula &F, SCEVExpander &Rewriter,
5011 SmallVectorImpl &DeadInsts) const {
5018 void LSRInstance::Rewrite(const LSRUse &LU,
5019 const LSRFixup &LF,
5020 const Formula &F,
5021 SCEVExpander &Rewriter,
5022 SmallVectorImpl &DeadInsts) const {
50125023 // First, find an insertion point that dominates UserInst. For PHI nodes,
50135024 // find the nearest block which dominates all the relevant uses.
50145025 if (PHINode *PN = dyn_cast(LF.UserInst)) {
50465057 const SmallVectorImpl &Solution) {
50475058 // Keep track of instructions we may have made dead, so that
50485059 // we can remove them after we are done working.
5049 SmallVectorTrackingVH, 16> DeadInsts;
5060 SmallVectorVH, 16> DeadInsts;
50505061
50515062 SCEVExpander Rewriter(SE, L->getHeader()->getModule()->getDataLayout(),
50525063 "lsr");
52965307 // Remove any extra phis created by processing inner loops.
52975308 Changed |= DeleteDeadPHIs(L->getHeader());
52985309 if (EnablePhiElim && L->isLoopSimplifyForm()) {
5299 SmallVectorTrackingVH, 16> DeadInsts;
5310 SmallVectorVH, 16> DeadInsts;
53005311 const DataLayout &DL = L->getHeader()->getModule()->getDataLayout();
53015312 SCEVExpander Rewriter(SE, DL, "lsr");
53025313 #ifndef NDEBUG
12301230 LoopProcessWorklist.push_back(NewLoop);
12311231 redoLoop = true;
12321232
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);
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);
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 WeakTrackingVH, that entry will be
214 // replaced with nullptr.
213 // If SeenExprs constains I's WeakVH, that entry will be replaced with
214 // 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(WeakTrackingVH(&*I));
221 SeenExprs[NewSCEV].push_back(WeakVH(&*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(WeakTrackingVH(&*I));
241 SeenExprs[OldSCEV].push_back(WeakVH(&*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 WeakTrackingVHs, so a candidate can be nullptr if it's
497 // removed during rewriting.
496 // Candidates stores WeakVHs, so a candidate can be nullptr if it's removed
497 // 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 SmallVectorImplTrackingVH> &Ops) {
984 SmallVectorImplVH> &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 SmallVectorTrackingVH, 4> NewMulOps;
1561 SmallVectorVH, 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 WeakTrackingVH for the PHIs to delete.
81 SmallVector PHIs;
80 // or RAUW'd undef, so use an array of WeakVH 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 WeakTrackingVH &BBEntry = VMap[BB];
247 WeakVH &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 // WeakTrackingVH in the VMap. Notably, we rely on that so that if we coalesce
549 // WeakVH 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 WeakTrackingVH PhiIt = &BB->front();
563 WeakVH 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 WeakTrackingVH.
1521 // updates the CallGraph if present, because it uses a WeakVH.
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 SmallVectorTrackingVH, 16> DeadInsts;
759 SmallVectorVH, 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 SmallVectorImplTrackingVH> &DeadInsts;
53 SmallVectorImplVH> &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, SmallVectorImplTrackingVH> &Dead,
703 LoopInfo *LI, SmallVectorImplVH> &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, SmallVectorImplTrackingVH> &Dead) {
713 LoopInfo *LI, SmallVectorImplVH> &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 WeakTrackingVH array.
3901 /// the WeakVH 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 WeakTrackingVH
3904 /// array.
3905 static bool hasValueBeenRAUWed(ArrayRef VL,
3906 ArrayRef VH, unsigned SliceBegin,
3907 unsigned SliceSize) {
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) {
39083906 VL = VL.slice(SliceBegin, SliceSize);
39093907 VH = VH.slice(SliceBegin, SliceSize);
39103908 return !std::equal(VL.begin(), VL.end(), VH.begin());
39223920 return false;
39233921
39243922 // Keep track of values that were deleted by vectorizing in the loop below.
3925 SmallVectorTrackingVH, 8> TrackValues(Chain.begin(), Chain.end());
3923 SmallVectorVH, 8> TrackValues(Chain.begin(), Chain.end());
39263924
39273925 bool Changed = false;
39283926 // Look for profitable vectorizable trees at all offsets, starting at zero.
41084106 bool Changed = false;
41094107
41104108 // Keep track of values that were deleted by vectorizing in the loop below.
4111 SmallVectorTrackingVH, 8> TrackValues(VL.begin(), VL.end());
4109 SmallVectorVH, 8> TrackValues(VL.begin(), VL.end());
41124110
41134111 unsigned NextInst = 0, MaxInst = VL.size();
41144112 for (unsigned VF = MaxVF; NextInst + 1 < MaxInst && VF >= MinVF;
47354733
47364734 namespace {
47374735 /// Tracks instructons and its children.
4738 class WeakTrackingVHWithLevel final : public CallbackVH {
4736 class WeakVHWithLevel final : public CallbackVH {
47394737 /// Operand index of the instruction currently beeing analized.
47404738 unsigned Level = 0;
47414739 /// Is this the instruction that should be vectorized, or are we now
47444742 bool IsInitial = true;
47454743
47464744 public:
4747 explicit WeakTrackingVHWithLevel() = default;
4748 WeakTrackingVHWithLevel(Value *V) : CallbackVH(V){};
4745 explicit WeakVHWithLevel() = default;
4746 WeakVHWithLevel(Value *V) : CallbackVH(V){};
47494747 /// Restart children analysis each time it is repaced by the new instruction.
47504748 void allUsesReplacedWith(Value *New) override {
47514749 setValPtr(New);
47724770 cast(getValPtr())->getNumOperands() > Level);
47734771 return cast(getValPtr())->getOperand(Level++);
47744772 }
4775 virtual ~WeakTrackingVHWithLevel() = default;
4773 virtual ~WeakVHWithLevel() = default;
47764774 };
47774775 } // namespace
47784776
47944792
47954793 if (Root->getParent() != BB)
47964794 return false;
4797 SmallVectorTrackingVHWithLevel, 8> Stack(1, Root);
4795 SmallVectorVHWithLevel, 8> Stack(1, Root);
47984796 SmallSet VisitedInstrs;
47994797 bool Res = false;
48004798 while (!Stack.empty()) {
50705068 SetVector Candidates(GEPList.begin(), GEPList.end());
50715069
50725070 // Some of the candidates may have already been vectorized after we
5073 // initially collected them. If so, the WeakTrackingVHs will have
5074 // nullified the values, so remove them from the set of candidates.
5071 // initially collected them. If so, the WeakVHs will have nullified the
5072 // values, so remove them from the set of candidates.
50755073 Candidates.remove(nullptr);
50765074
50775075 // Remove from the set of candidates all pairs of getelementptrs with
+0
-25
test/Analysis/AliasSet/unknown-inst-tracking.ll less more
None ; RUN: opt -S -licm -loop-unswitch < %s | FileCheck %s
1
2 ; This test checks for a crash. See PR32587.
3
4 @global = external global i32
5
6 declare i32 @f_1(i8, i32 returned)
7
8 define i32 @f_0() {
9 ; CHECK-LABEL: @f_0(
10 bb:
11 br label %bb1
12
13 bb1: ; preds = %bb3, %bb
14 %tmp = load i32, i32* @global
15 %tmp2 = select i1 false, i16 1, i16 0
16 br label %bb3
17
18 bb3: ; preds = %bb3, %bb1
19 %tmp4 = phi i8 [ 0, %bb1 ], [ %tmp6, %bb3 ]
20 %tmp5 = icmp eq i16 %tmp2, 0
21 %tmp6 = select i1 %tmp5, i8 %tmp4, i8 1
22 %tmp7 = tail call i32 @f_1(i8 %tmp6, i32 1)
23 br i1 false, label %bb1, label %bb3
24 }
4343 // doesn't matter which method.
4444 EXPECT_EQ(Type::getInt32Ty(Context), WVH->getType());
4545 EXPECT_EQ(Type::getInt32Ty(Context), (*WVH).getType());
46
47 WVH = BitcastV.get();
48 BitcastV->replaceAllUsesWith(ConstantV);
49 EXPECT_EQ(WVH, BitcastV.get());
50 BitcastV.reset();
51 EXPECT_EQ(WVH, nullptr);
52 }
53
54 TEST_F(ValueHandle, WeakTrackingVH_BasicOperation) {
55 WeakTrackingVH WVH(BitcastV.get());
56 EXPECT_EQ(BitcastV.get(), WVH);
57 WVH = ConstantV;
58 EXPECT_EQ(ConstantV, WVH);
59
60 // Make sure I can call a method on the underlying Value. It
61 // doesn't matter which method.
62 EXPECT_EQ(Type::getInt32Ty(Context), WVH->getType());
63 EXPECT_EQ(Type::getInt32Ty(Context), (*WVH).getType());
64 }
65
66 TEST_F(ValueHandle, WeakTrackingVH_Comparisons) {
67 WeakTrackingVH BitcastWVH(BitcastV.get());
68 WeakTrackingVH ConstantWVH(ConstantV);
46 }
47
48 TEST_F(ValueHandle, WeakVH_Comparisons) {
49 WeakVH BitcastWVH(BitcastV.get());
50 WeakVH ConstantWVH(ConstantV);
6951
7052 EXPECT_TRUE(BitcastWVH == BitcastWVH);
7153 EXPECT_TRUE(BitcastV.get() == BitcastWVH);
9678 EXPECT_EQ(BV >= CV, BitcastWVH >= ConstantV);
9779 }
9880
99 TEST_F(ValueHandle, WeakTrackingVH_FollowsRAUW) {
100 WeakTrackingVH WVH(BitcastV.get());
101 WeakTrackingVH WVH_Copy(WVH);
102 WeakTrackingVH WVH_Recreated(BitcastV.get());
81 TEST_F(ValueHandle, WeakVH_FollowsRAUW) {
82 WeakVH WVH(BitcastV.get());
83 WeakVH WVH_Copy(WVH);
84 WeakVH WVH_Recreated(BitcastV.get());
10385 BitcastV->replaceAllUsesWith(ConstantV);
10486 EXPECT_EQ(ConstantV, WVH);
10587 EXPECT_EQ(ConstantV, WVH_Copy);
10688 EXPECT_EQ(ConstantV, WVH_Recreated);
10789 }
10890
109 TEST_F(ValueHandle, WeakTrackingVH_NullOnDeletion) {
110 WeakTrackingVH WVH(BitcastV.get());
111 WeakTrackingVH WVH_Copy(WVH);
112 WeakTrackingVH WVH_Recreated(BitcastV.get());
91 TEST_F(ValueHandle, WeakVH_NullOnDeletion) {
92 WeakVH WVH(BitcastV.get());
93 WeakVH WVH_Copy(WVH);
94 WeakVH WVH_Recreated(BitcastV.get());
11395 BitcastV.reset();
11496 Value *null_value = nullptr;
11597 EXPECT_EQ(null_value, WVH);
360342
361343 class DestroyingVH final : public CallbackVH {
362344 public:
363 std::unique_ptrTrackingVH> ToClear[2];
345 std::unique_ptrVH> ToClear[2];
364346 DestroyingVH(Value *V) {
365 ToClear[0].reset(new WeakTrackingVH(V));
347 ToClear[0].reset(new WeakVH(V));
366348 setValPtr(V);
367 ToClear[1].reset(new WeakTrackingVH(V));
349 ToClear[1].reset(new WeakVH(V));
368350 }
369351 void deleted() override {
370352 ToClear[0].reset();
378360 };
379361
380362 {
381 WeakTrackingVH ShouldBeVisited1(BitcastV.get());
363 WeakVH ShouldBeVisited1(BitcastV.get());
382364 DestroyingVH C(BitcastV.get());
383 WeakTrackingVH ShouldBeVisited2(BitcastV.get());
365 WeakVH ShouldBeVisited2(BitcastV.get());
384366
385367 BitcastV->replaceAllUsesWith(ConstantV);
386368 EXPECT_EQ(ConstantV, static_cast(ShouldBeVisited1));
388370 }
389371
390372 {
391 WeakTrackingVH ShouldBeVisited1(BitcastV.get());
373 WeakVH ShouldBeVisited1(BitcastV.get());
392374 DestroyingVH C(BitcastV.get());
393 WeakTrackingVH ShouldBeVisited2(BitcastV.get());
375 WeakVH ShouldBeVisited2(BitcastV.get());
394376
395377 BitcastV.reset();
396378 EXPECT_EQ(nullptr, static_cast(ShouldBeVisited1));