[llvm-branch-commits] [llvm-branch] r223627 - Merging r222338:

David Majnemer david.majnemer at gmail.com
Mon Dec 8 00:48:10 PST 2014


Author: majnemer
Date: Mon Dec  8 02:48:09 2014
New Revision: 223627

URL: http://llvm.org/viewvc/llvm-project?rev=223627&view=rev
Log:
Merging r222338:
------------------------------------------------------------------------
r222338 | majnemer | 2014-11-19 01:41:05 -0800 (Wed, 19 Nov 2014) | 16 lines

AliasSetTracker: UnknownInsts should contribute to the refcount

AliasSetTracker::addUnknown may create an AliasSet devoid of pointers
just to contain an instruction if no suitable AliasSet already exists.
It will then AliasSet::addUnknownInst and we will be done.

However, it's possible for addUnknown to choose an existing AliasSet to
addUnknownInst.
If this were to occur, we are in a bit of a pickle: removing pointers
from the AliasSet can cause the entire AliasSet to become destroyed,
taking our unknown instructions out with them.

Instead, keep track whether or not our AliasSet has any unknown
instructions.

This fixes PR21582.
------------------------------------------------------------------------

Added:
    llvm/branches/release_35/test/Transforms/LICM/PR21582.ll
      - copied unchanged from r222338, llvm/trunk/test/Transforms/LICM/PR21582.ll
Modified:
    llvm/branches/release_35/   (props changed)
    llvm/branches/release_35/include/llvm/Analysis/AliasSetTracker.h
    llvm/branches/release_35/lib/Analysis/AliasSetTracker.cpp

Propchange: llvm/branches/release_35/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Dec  8 02:48:09 2014
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,213653,213665,213726,213749,213773,213793,213798-213799,213815,213847,213880,213883-213884,213894-213896,213899,213915,213966,213999,214060,214129,214180,214287,214331,214423,214429,214519,214670,214674,214679,215685,215711,215806,216064,216262,216531,216920,217257,218745,221009,221408,221453,223163,223170-223171
+/llvm/trunk:155241,213653,213665,213726,213749,213773,213793,213798-213799,213815,213847,213880,213883-213884,213894-213896,213899,213915,213966,213999,214060,214129,214180,214287,214331,214423,214429,214519,214670,214674,214679,215685,215711,215806,216064,216262,216531,216920,217257,218745,221009,221408,221453,222338,223163,223170-223171

Modified: llvm/branches/release_35/include/llvm/Analysis/AliasSetTracker.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_35/include/llvm/Analysis/AliasSetTracker.h?rev=223627&r1=223626&r2=223627&view=diff
==============================================================================
--- llvm/branches/release_35/include/llvm/Analysis/AliasSetTracker.h (original)
+++ llvm/branches/release_35/include/llvm/Analysis/AliasSetTracker.h Mon Dec  8 02:48:09 2014
@@ -253,13 +253,16 @@ private:
                   const MDNode *TBAAInfo,
                   bool KnownMustAlias = false);
   void addUnknownInst(Instruction *I, AliasAnalysis &AA);
-  void removeUnknownInst(Instruction *I) {
+  void removeUnknownInst(AliasSetTracker &AST, Instruction *I) {
+    bool WasEmpty = UnknownInsts.empty();
     for (size_t i = 0, e = UnknownInsts.size(); i != e; ++i)
       if (UnknownInsts[i] == I) {
         UnknownInsts[i] = UnknownInsts.back();
         UnknownInsts.pop_back();
         --i; --e;  // Revisit the moved entry.
       }
+    if (!WasEmpty && UnknownInsts.empty())
+      dropRef(AST);
   }
   void setVolatile() { Volatile = true; }
 

Modified: llvm/branches/release_35/lib/Analysis/AliasSetTracker.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_35/lib/Analysis/AliasSetTracker.cpp?rev=223627&r1=223626&r2=223627&view=diff
==============================================================================
--- llvm/branches/release_35/lib/Analysis/AliasSetTracker.cpp (original)
+++ llvm/branches/release_35/lib/Analysis/AliasSetTracker.cpp Mon Dec  8 02:48:09 2014
@@ -55,12 +55,16 @@ void AliasSet::mergeSetIn(AliasSet &AS,
       AliasTy = MayAlias;
   }
 
+  bool ASHadUnknownInsts = false;
   if (UnknownInsts.empty()) {            // Merge call sites...
-    if (!AS.UnknownInsts.empty())
+    if (!AS.UnknownInsts.empty()) {
       std::swap(UnknownInsts, AS.UnknownInsts);
+      addRef();
+    }
   } else if (!AS.UnknownInsts.empty()) {
     UnknownInsts.insert(UnknownInsts.end(), AS.UnknownInsts.begin(), AS.UnknownInsts.end());
     AS.UnknownInsts.clear();
+    ASHadUnknownInsts = true;
   }
 
   AS.Forward = this;  // Forward across AS now...
@@ -76,6 +80,8 @@ void AliasSet::mergeSetIn(AliasSet &AS,
     AS.PtrListEnd = &AS.PtrList;
     assert(*AS.PtrListEnd == nullptr && "End of list is not null?");
   }
+  if (ASHadUnknownInsts)
+    AS.dropRef(AST);
 }
 
 void AliasSetTracker::removeAliasSet(AliasSet *AS) {
@@ -123,6 +129,8 @@ void AliasSet::addPointer(AliasSetTracke
 }
 
 void AliasSet::addUnknownInst(Instruction *I, AliasAnalysis &AA) {
+  if (UnknownInsts.empty())
+    addRef();
   UnknownInsts.push_back(I);
 
   if (!I->mayWriteToMemory()) {
@@ -218,13 +226,14 @@ AliasSet *AliasSetTracker::findAliasSetF
                                                   uint64_t Size,
                                                   const MDNode *TBAAInfo) {
   AliasSet *FoundSet = nullptr;
-  for (iterator I = begin(), E = end(); I != E; ++I) {
-    if (I->Forward || !I->aliasesPointer(Ptr, Size, TBAAInfo, AA)) continue;
+  for (iterator I = begin(), E = end(); I != E;) {
+    iterator Cur = I++;
+    if (Cur->Forward || !Cur->aliasesPointer(Ptr, Size, TBAAInfo, AA)) continue;
     
     if (!FoundSet) {      // If this is the first alias set ptr can go into.
-      FoundSet = I;       // Remember it.
+      FoundSet = Cur;     // Remember it.
     } else {              // Otherwise, we must merge the sets.
-      FoundSet->mergeSetIn(*I, *this);     // Merge in contents.
+      FoundSet->mergeSetIn(*Cur, *this);     // Merge in contents.
     }
   }
 
@@ -246,14 +255,14 @@ bool AliasSetTracker::containsPointer(Va
 
 AliasSet *AliasSetTracker::findAliasSetForUnknownInst(Instruction *Inst) {
   AliasSet *FoundSet = nullptr;
-  for (iterator I = begin(), E = end(); I != E; ++I) {
-    if (I->Forward || !I->aliasesUnknownInst(Inst, AA))
+  for (iterator I = begin(), E = end(); I != E;) {
+    iterator Cur = I++;
+    if (Cur->Forward || !Cur->aliasesUnknownInst(Inst, AA))
       continue;
-    
     if (!FoundSet)            // If this is the first alias set ptr can go into.
-      FoundSet = I;           // Remember it.
-    else if (!I->Forward)     // Otherwise, we must merge the sets.
-      FoundSet->mergeSetIn(*I, *this);     // Merge in contents.
+      FoundSet = Cur;         // Remember it.
+    else if (!Cur->Forward)   // Otherwise, we must merge the sets.
+      FoundSet->mergeSetIn(*Cur, *this);     // Merge in contents.
   }
   return FoundSet;
 }
@@ -393,6 +402,8 @@ void AliasSetTracker::add(const AliasSet
 /// tracker.
 void AliasSetTracker::remove(AliasSet &AS) {
   // Drop all call sites.
+  if (!AS.UnknownInsts.empty())
+    AS.dropRef(*this);
   AS.UnknownInsts.clear();
   
   // Clear the alias set.
@@ -489,10 +500,10 @@ void AliasSetTracker::deleteValue(Value
   if (Instruction *Inst = dyn_cast<Instruction>(PtrVal)) {
     if (Inst->mayReadOrWriteMemory()) {
       // Scan all the alias sets to see if this call site is contained.
-      for (iterator I = begin(), E = end(); I != E; ++I) {
-        if (I->Forward) continue;
-        
-        I->removeUnknownInst(Inst);
+      for (iterator I = begin(), E = end(); I != E;) {
+        iterator Cur = I++;
+        if (!Cur->Forward)
+          Cur->removeUnknownInst(*this, Inst);
       }
     }
   }





More information about the llvm-branch-commits mailing list