[llvm-commits] [llvm] r89975 - /llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp

Chris Lattner sabre at nondot.org
Thu Nov 26 15:18:49 PST 2009


Author: lattner
Date: Thu Nov 26 17:18:49 2009
New Revision: 89975

URL: http://llvm.org/viewvc/llvm-project?rev=89975&view=rev
Log:
factor some code out into some helper functions.

Modified:
    llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp

Modified: llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp?rev=89975&r1=89974&r2=89975&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp (original)
+++ llvm/trunk/lib/Analysis/MemoryDependenceAnalysis.cpp Thu Nov 26 17:18:49 2009
@@ -684,6 +684,33 @@
   }
 }
 
+/// isPHITranslatable - Return true if the specified computation is derived from
+/// a PHI node in the current block and if it is simple enough for us to handle.
+static bool isPHITranslatable(Instruction *Inst) {
+  if (isa<PHINode>(Inst))
+    return true;
+  
+  // TODO: BITCAST, GEP.
+
+  // ...
+  
+  //   cerr << "MEMDEP: Could not PHI translate: " << *Pointer;
+  //   if (isa<BitCastInst>(PtrInst) || isa<GetElementPtrInst>(PtrInst))
+  //     cerr << "OP:\t\t\t\t" << *PtrInst->getOperand(0);
+  
+  return false;
+}
+
+/// PHITranslateForPred - Given a computation that satisfied the
+/// isPHITranslatable predicate, see if we can translate the computation into
+/// the specified predecessor block.  If so, return that value.
+static Value *PHITranslateForPred(Instruction *Inst, BasicBlock *Pred) {
+  if (PHINode *PN = dyn_cast<PHINode>(Inst))
+    return PN->getIncomingValueForBlock(Pred);
+  
+  return 0;
+}
+
 
 /// getNonLocalPointerDepFromBB - Perform a dependency query based on
 /// pointer/pointeesize starting at the end of StartBB.  Add any clobber/def
@@ -827,14 +854,18 @@
       NumSortedEntries = Cache->size();
     }
     
-    // If this is directly a PHI node, just use the incoming values for each
-    // pred as the phi translated version.
-    if (PHINode *PtrPHI = dyn_cast<PHINode>(PtrInst)) {
+    // If this is a computation derived from a PHI node, use the suitably
+    // translated incoming values for each pred as the phi translated version.
+    if (isPHITranslatable(PtrInst)) {
       Cache = 0;
       
       for (BasicBlock **PI = PredCache->GetPreds(BB); *PI; ++PI) {
         BasicBlock *Pred = *PI;
-        Value *PredPtr = PtrPHI->getIncomingValueForBlock(Pred);
+        Value *PredPtr = PHITranslateForPred(PtrInst, Pred);
+        
+        // If PHI translation fails, bail out.
+        if (PredPtr == 0)
+          goto PredTranslationFailure;
         
         // Check to see if we have already visited this pred block with another
         // pointer.  If so, we can't do this lookup.  This failure can occur
@@ -881,12 +912,7 @@
       SkipFirstBlock = false;
       continue;
     }
-    
-    // TODO: BITCAST, GEP.
-    
-    //   cerr << "MEMDEP: Could not PHI translate: " << *Pointer;
-    //   if (isa<BitCastInst>(PtrInst) || isa<GetElementPtrInst>(PtrInst))
-    //     cerr << "OP:\t\t\t\t" << *PtrInst->getOperand(0);
+
   PredTranslationFailure:
     
     if (Cache == 0) {





More information about the llvm-commits mailing list