[llvm-commits] [poolalloc] r72398 - in /poolalloc/trunk: include/dsa/DataStructure.h lib/DSA/Basic.cpp

Haohui Mai mai4 at uiuc.edu
Mon May 25 13:58:52 PDT 2009


Author: mai4
Date: Mon May 25 15:58:52 2009
New Revision: 72398

URL: http://llvm.org/viewvc/llvm-project?rev=72398&view=rev
Log:
Add a basic version of DSA which assumes all pointers points to every possible
objects.

Added:
    poolalloc/trunk/lib/DSA/Basic.cpp
Modified:
    poolalloc/trunk/include/dsa/DataStructure.h

Modified: poolalloc/trunk/include/dsa/DataStructure.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=72398&r1=72397&r2=72398&view=diff

==============================================================================
--- poolalloc/trunk/include/dsa/DataStructure.h (original)
+++ poolalloc/trunk/include/dsa/DataStructure.h Mon May 25 15:58:52 2009
@@ -170,6 +170,24 @@
   void copyValue(Value *From, Value *To);
 };
 
+// BasicDataStructures - The analysis is a dummy one -- all pointers can points
+// to all possible locations.
+//
+class BasicDataStructures : public DataStructures {
+public:
+  static char ID;
+  BasicDataStructures() : DataStructures((intptr_t)&ID, "basic.") {}
+  ~BasicDataStructures() { releaseMemory(); }
+
+  virtual bool runOnModule(Module &M);
+
+  /// getAnalysisUsage - This obviously provides a data structure graph.
+  ///
+  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+    AU.addRequired<TargetData>();
+    AU.setPreservesAll();
+  }
+};
 
 // LocalDataStructures - The analysis that computes the local data structure
 // graphs for all of the functions in the program.

Added: poolalloc/trunk/lib/DSA/Basic.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Basic.cpp?rev=72398&view=auto

==============================================================================
--- poolalloc/trunk/lib/DSA/Basic.cpp (added)
+++ poolalloc/trunk/lib/DSA/Basic.cpp Mon May 25 15:58:52 2009
@@ -0,0 +1,73 @@
+//===- Basic.cpp ----------------------------------------------------------===//
+//
+//                     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.
+//
+//===----------------------------------------------------------------------===//
+//
+// Implementation of the basic data structure analysis pass. It simply assumes
+// that all pointers can points to all possible locations.
+//
+//===----------------------------------------------------------------------===//
+
+#include "dsa/DataStructure.h"
+#include "dsa/DSGraph.h"
+
+#include "llvm/Module.h"
+#include "llvm/DerivedTypes.h"
+#include "llvm/Constants.h"
+#include "llvm/Instructions.h"
+#include "llvm/Intrinsics.h"
+#include "llvm/Support/InstIterator.h"
+#include "llvm/Support/InstVisitor.h"
+#include "llvm/Support/GetElementPtrTypeIterator.h"
+
+using namespace llvm;
+
+static RegisterPass<BasicDataStructures>
+X("dsa-basic", "Basic Data Structure Analysis(No Analysis)");
+
+char BasicDataStructures::ID = 0;
+
+bool BasicDataStructures::runOnModule(Module &M) {
+  init(&getAnalysis<TargetData>());
+
+  DSNode * GVNodeInternal = new DSNode(PointerType::getUnqual(Type::Int8Ty), GlobalsGraph);
+  DSNode * GVNodeExternal = new DSNode(PointerType::getUnqual(Type::Int8Ty), GlobalsGraph);
+  for (Module::global_iterator I = M.global_begin(), E = M.global_end();
+       I != E; ++I) {
+    if (I->isDeclaration()) {
+      GlobalsGraph->getNodeForValue(&*I).mergeWith(GVNodeExternal);
+    } else {
+      GlobalsGraph->getNodeForValue(&*I).mergeWith(GVNodeInternal);
+    }
+  }
+
+  GVNodeInternal->foldNodeCompletely();
+  GVNodeInternal->maskNodeTypes(DSNode::IncompleteNode);
+
+  GVNodeExternal->foldNodeCompletely();
+
+  // Next step, iterate through the nodes in the globals graph, unioning
+  // together the globals into equivalence classes.
+  formGlobalECs();
+
+  for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
+    if (!F->isDeclaration()) {
+      DSGraph* G = new DSGraph(GlobalECs, getTargetData(), GlobalsGraph);
+      DSNode * Node = new DSNode(PointerType::getUnqual(Type::Int8Ty), G);
+      for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
+        G->getNodeForValue(&*I).mergeWith(Node);
+      }
+
+      Node->foldNodeCompletely();
+      Node->maskNodeTypes(DSNode::IncompleteNode);
+
+      setDSGraph(*F, G);
+    }
+  }
+ 
+  return false;
+}





More information about the llvm-commits mailing list