Provide interface to identifiy artificial methods.
[oota-llvm.git] / lib / Analysis / IVUsers.cpp
index df9e31c1d2534d801f21900b22fa2f1f7b1cd764..9c472ae73bc13fbe097cd6f3f5f889e32e969c21 100644 (file)
@@ -128,8 +128,9 @@ static bool getSCEVStartAndStride(const SCEV *&SH, Loop *L, Loop *UseLoop,
     if (!AddRecStride->properlyDominates(Header, DT))
       return false;
 
-    DEBUG(dbgs() << "[" << L->getHeader()->getName()
-                 << "] Variable stride: " << *AddRec << "\n");
+    DEBUG(dbgs() << "[";
+          WriteAsOperand(dbgs(), L->getHeader(), /*PrintType=*/false);
+          dbgs() << "] Variable stride: " << *AddRec << "\n");
   }
 
   Stride = AddRecStride;
@@ -323,12 +324,19 @@ const SCEV *IVUsers::getReplacementExpr(const IVStrideUse &U) const {
   // the actual replacement value.
   if (U.isUseOfPostIncrementedValue())
     RetVal = SE->getAddExpr(RetVal, U.getParent()->Stride);
-  // Evaluate the expression out of the loop, if possible.
-  if (!L->contains(U.getUser())) {
-    const SCEV *ExitVal = SE->getSCEVAtScope(RetVal, L->getParentLoop());
-    if (ExitVal->isLoopInvariant(L))
-      RetVal = ExitVal;
-  }
+  return RetVal;
+}
+
+/// getCanonicalExpr - Return a SCEV expression which computes the
+/// value of the SCEV of the given IVStrideUse, ignoring the 
+/// isUseOfPostIncrementedValue flag.
+const SCEV *IVUsers::getCanonicalExpr(const IVStrideUse &U) const {
+  // Start with zero.
+  const SCEV *RetVal = SE->getIntegerSCEV(0, U.getParent()->Stride->getType());
+  // Create the basic add recurrence.
+  RetVal = SE->getAddRecExpr(RetVal, U.getParent()->Stride, L);
+  // Add the offset in a separate step, because it may be loop-variant.
+  RetVal = SE->getAddExpr(RetVal, U.getOffset());
   return RetVal;
 }
 
@@ -378,3 +386,26 @@ void IVStrideUse::deleted() {
   Parent->Users.erase(this);
   // this now dangles!
 }
+
+void IVUsersOfOneStride::print(raw_ostream &OS) const {
+  OS << "IV Users of one stride:\n";
+
+  if (Stride)
+    OS << "    Stride: " << *Stride << '\n';
+
+  OS << "    Users:\n";
+
+  unsigned Count = 1;
+
+  for (ilist<IVStrideUse>::const_iterator
+         I = Users.begin(), E = Users.end(); I != E; ++I) {
+    const IVStrideUse &SU = *I;
+    OS << "      " << Count++ << '\n';
+    OS << "        Offset: " << *SU.getOffset() << '\n';
+    OS << "         Instr: " << *SU << '\n';
+  }
+}
+
+void IVUsersOfOneStride::dump() const {
+  print(dbgs());
+}