Add support for memmove
[oota-llvm.git] / lib / Analysis / DataStructure / Steensgaard.cpp
index 2f370258ff766af93c18c6580dcf530fafcf8bd8..8bf917f0483dfaf45020b3118656201e83674f0d 100644 (file)
@@ -1,4 +1,11 @@
 //===- Steensgaard.cpp - Context Insensitive Alias Analysis ---------------===//
+// 
+//                     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.
+// 
+//===----------------------------------------------------------------------===//
 //
 // This pass uses the data structure graphs to implement a simple context
 // insensitive alias analysis.  It does this by computing the local analysis
@@ -11,7 +18,7 @@
 #include "llvm/Analysis/DSGraph.h"
 #include "llvm/Analysis/AliasAnalysis.h"
 #include "llvm/Module.h"
-#include "Support/Statistic.h"
+#include "Support/Debug.h"
 
 namespace {
   class Steens : public Pass, public AliasAnalysis {
@@ -77,7 +84,7 @@ namespace {
 void Steens::ResolveFunctionCall(Function *F, const DSCallSite &Call,
                                  DSNodeHandle &RetVal) {
   assert(ResultGraph != 0 && "Result graph not allocated!");
-  hash_map<Value*, DSNodeHandle> &ValMap = ResultGraph->getScalarMap();
+  DSGraph::ScalarMapTy &ValMap = ResultGraph->getScalarMap();
 
   // Handle the return value of the function...
   if (Call.getRetVal().getNode() && RetVal.getNode())
@@ -87,7 +94,7 @@ void Steens::ResolveFunctionCall(Function *F, const DSCallSite &Call,
   unsigned PtrArgIdx = 0;
   for (Function::aiterator AI = F->abegin(), AE = F->aend();
        AI != AE && PtrArgIdx < Call.getNumPtrArgs(); ++AI) {
-    hash_map<Value*, DSNodeHandle>::iterator I = ValMap.find(AI);
+    DSGraph::ScalarMapTy::iterator I = ValMap.find(AI);
     if (I != ValMap.end())    // If its a pointer argument...
       I->second.mergeWith(Call.getPtrArg(PtrArgIdx++));
   }
@@ -103,15 +110,15 @@ bool Steens::run(Module &M) {
   LocalDataStructures &LDS = getAnalysis<LocalDataStructures>();
 
   // Create a new, empty, graph...
-  ResultGraph = new DSGraph();
-  GlobalsGraph = new DSGraph();
+  ResultGraph = new DSGraph(getTargetData());
+  GlobalsGraph = new DSGraph(getTargetData());
   ResultGraph->setGlobalsGraph(GlobalsGraph);
   ResultGraph->setPrintAuxCalls();
 
   // RetValMap - Keep track of the return values for all functions that return
   // valid pointers.
   //
-  hash_map<Function*, DSNodeHandle> RetValMap;
+  DSGraph::ReturnNodesTy RetValMap;
 
   // Loop over the rest of the module, merging graphs for non-external functions
   // into this graph.
@@ -119,23 +126,17 @@ bool Steens::run(Module &M) {
   unsigned Count = 0;
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
     if (!I->isExternal()) {
-      hash_map<Value*, DSNodeHandle> ValMap;
+      DSGraph::ScalarMapTy ValMap;
       {  // Scope to free NodeMap memory ASAP
-        hash_map<const DSNode*, DSNodeHandle> NodeMap;
+        DSGraph::NodeMapTy NodeMap;
         const DSGraph &FDSG = LDS.getDSGraph(*I);
-        DSNodeHandle RetNode = ResultGraph->cloneInto(FDSG, ValMap, NodeMap);
-
-        // Keep track of the return node of the function's graph if it returns a
-        // value...
-        //
-        if (RetNode.getNode())
-          RetValMap[I] = RetNode;
+        ResultGraph->cloneInto(FDSG, ValMap, RetValMap, NodeMap);
       }
 
       // Incorporate the inlined Function's ScalarMap into the global
       // ScalarMap...
-      hash_map<Value*, DSNodeHandle> &GVM = ResultGraph->getScalarMap();
-      for (hash_map<Value*, DSNodeHandle>::iterator I = ValMap.begin(),
+      DSGraph::ScalarMapTy &GVM = ResultGraph->getScalarMap();
+      for (DSGraph::ScalarMapTy::iterator I = ValMap.begin(),
              E = ValMap.end(); I != E; ++I)
         GVM[I->first].mergeWith(I->second);
 
@@ -208,12 +209,12 @@ AliasAnalysis::AliasResult Steens::alias(const Value *V1, unsigned V1Size,
   // FIXME: HANDLE Size argument!
   assert(ResultGraph && "Result graph has not been computed yet!");
 
-  hash_map<Value*, DSNodeHandle> &GSM = ResultGraph->getScalarMap();
+  DSGraph::ScalarMapTy &GSM = ResultGraph->getScalarMap();
 
-  hash_map<Value*, DSNodeHandle>::iterator I = GSM.find(const_cast<Value*>(V1));
+  DSGraph::ScalarMapTy::iterator I = GSM.find(const_cast<Value*>(V1));
   if (I != GSM.end() && I->second.getNode()) {
     DSNodeHandle &V1H = I->second;
-    hash_map<Value*, DSNodeHandle>::iterator J=GSM.find(const_cast<Value*>(V2));
+    DSGraph::ScalarMapTy::iterator J=GSM.find(const_cast<Value*>(V2));
     if (J != GSM.end() && J->second.getNode()) {
       DSNodeHandle &V2H = J->second;
       // If the two pointers point to different data structure graph nodes, they