Add support for 'rename'
[oota-llvm.git] / lib / Analysis / DataStructure / DataStructureStats.cpp
index 887eb7f550a0339de12faac9034fc4030d6fbea9..a48223e0edfc43bbd45a32f6e03784654749326d 100644 (file)
@@ -1,4 +1,11 @@
 //===- DSGraphStats.cpp - Various statistics for DS Graphs ----------------===//
+// 
+//                     The LLVM Compiler Infrastructure
+//
+// This file was developed by the LLVM research group and is distributed under
+// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// 
+//===----------------------------------------------------------------------===//
 //
 //===----------------------------------------------------------------------===//
 
@@ -11,6 +18,7 @@
 #include "llvm/Support/InstVisitor.h"
 #include "Support/Statistic.h"
 #include <vector>
+using namespace llvm;
 
 namespace {
   Statistic<> TotalNumCallees("totalcallees",
@@ -33,6 +41,7 @@ namespace {
     const DSGraph *TDGraph;
 
     DSNode *getNodeForValue(Value *V);
+    bool isNodeForValueCollapsed(Value *V);
   public:
     /// Driver functions to compute the Load/Store Dep. Graph per function.
     bool runOnFunction(Function& F);
@@ -67,7 +76,7 @@ void DSGraphStats::countCallees(const Function& F) {
 
   const std::vector<DSCallSite> &callSites = TDGraph->getFunctionCalls();
   for (unsigned i = 0, N = callSites.size(); i != N; ++i)
-    if (isIndirectCallee(callSites[i].getCallInst().getCalledValue())) {
+    if (isIndirectCallee(callSites[i].getCallSite().getCalledValue())) {
       // This is an indirect function call
       const std::vector<GlobalValue*> &Callees =
         callSites[i].getCalleeNode()->getGlobals();
@@ -75,8 +84,9 @@ void DSGraphStats::countCallees(const Function& F) {
         totalNumCallees  += Callees.size();
         ++numIndirectCalls;
       } else
-        std::cerr << "WARNING: No callee in Function " << F.getName()
-                  << "at call:\n" << callSites[i].getCallInst();
+        std::cerr << "WARNING: No callee in Function '" << F.getName()
+                  << "' at call: \n"
+                  << *callSites[i].getCallSite().getInstruction();
     }
   
   TotalNumCallees  += totalNumCallees;
@@ -90,14 +100,24 @@ void DSGraphStats::countCallees(const Function& F) {
 
 DSNode *DSGraphStats::getNodeForValue(Value *V) {
   const DSGraph *G = TDGraph;
-  if (isa<GlobalValue>(V))
+  if (isa<GlobalValue>(V) || isa<Constant>(V))
     G = TDGraph->getGlobalsGraph();
 
-  return G->getNodeForValue(V).getNode();
+  const DSGraph::ScalarMapTy &ScalarMap = G->getScalarMap();
+  DSGraph::ScalarMapTy::const_iterator I = ScalarMap.find(V);
+  if (I != ScalarMap.end())
+    return I->second.getNode();
+  return 0;
+}
+
+bool DSGraphStats::isNodeForValueCollapsed(Value *V) {
+  if (DSNode *N = getNodeForValue(V))
+    return N->isNodeCompletelyFolded() || N->isIncomplete();
+  return false;
 }
 
 void DSGraphStats::visitLoad(LoadInst &LI) {
-  if (getNodeForValue(LI.getOperand(0))->isNodeCompletelyFolded()) {
+  if (isNodeForValueCollapsed(LI.getOperand(0))) {
     NumUntypedMemAccesses++;
   } else {
     NumTypedMemAccesses++;
@@ -105,7 +125,7 @@ void DSGraphStats::visitLoad(LoadInst &LI) {
 }
 
 void DSGraphStats::visitStore(StoreInst &SI) {
-  if (getNodeForValue(SI.getOperand(1))->isNodeCompletelyFolded()) {
+  if (isNodeForValueCollapsed(SI.getOperand(1))) {
     NumUntypedMemAccesses++;
   } else {
     NumTypedMemAccesses++;