[llvm-commits] CVS: llvm-poolalloc/include/dsa/DSGraph.h DataStructure.h

Andrew Lenharth alenhar2 at cs.uiuc.edu
Wed Apr 11 10:38:04 PDT 2007



Changes in directory llvm-poolalloc/include/dsa:

DSGraph.h updated: 1.113 -> 1.114
DataStructure.h updated: 1.99 -> 1.100
---
Log message:

Minor refactoring, and cutting out stuff that should be (and is) in another branch

---
Diffs of the changes:  (+77 -184)

 DSGraph.h       |  113 ++++++------------------------------------
 DataStructure.h |  148 ++++++++++++++++++++++----------------------------------
 2 files changed, 77 insertions(+), 184 deletions(-)


Index: llvm-poolalloc/include/dsa/DSGraph.h
diff -u llvm-poolalloc/include/dsa/DSGraph.h:1.113 llvm-poolalloc/include/dsa/DSGraph.h:1.114
--- llvm-poolalloc/include/dsa/DSGraph.h:1.113	Wed Dec 13 23:51:06 2006
+++ llvm-poolalloc/include/dsa/DSGraph.h	Wed Apr 11 12:37:43 2007
@@ -18,14 +18,12 @@
 #include "dsa/DSNode.h"
 #include "llvm/ADT/hash_map"
 #include "llvm/ADT/EquivalenceClasses.h"
-#include "poolalloc/Config/config.h"
 
 #include <list>
 #include <map>
 #include <iostream>
 namespace llvm {
 
-  //typedef map<const DSNode *, Value*> PoolDescriptorMapType;
 
 class GlobalValue;
 
@@ -174,63 +172,6 @@
   DSNodeHandle &AddGlobal(GlobalValue *GV);
 };
 
-
-#ifdef LLVA_KERNEL
-class MetaPool;
-class MetaPoolHandle {
-  MetaPool *Rep;
-  Instruction * Creator;
-public:
-  MetaPoolHandle(MetaPool *mp, Instruction * Maker = 0);
-  
-  MetaPool *getMetaPool() {
-    return Rep;
-  }
-  void setMetaPool(MetaPool *v) {
-    Rep = v;
-  }
-  ~MetaPoolHandle() {
-    //do nothing for now
-  }
-  const std::string &getName();
-  Value *getMetaPoolValue();
-  void merge(MetaPoolHandle *other);
-};
-
-  class MetaPool {
-    Value *MPD;
-    hash_set<MetaPoolHandle *> HandleSet;
-    
-  public:
-    MetaPool(Value *mpd) : MPD(mpd) {
-    }
-    void addMetaPoolHandles(hash_set<MetaPoolHandle *> & mpHS) {
-      HandleSet.insert(mpHS.begin(), mpHS.end());
-    }
-    hash_set<MetaPoolHandle *>& getHandleSet() {
-      return HandleSet;
-    }
-    Value * getMetaPoolValue() {
-      return MPD;
-    }
-    void setMetaPoolValue(Value *V) {
-      MPD = V;
-    }
-    void insert(MetaPoolHandle *mph) {
-      HandleSet.insert(mph);
-    }
-    const std::string& getName() {
-      return MPD->getName();
-    }
-    ~MetaPool() {
-      HandleSet.clear();
-    }
-  };
-
-#endif
-  
-
-  
 //===----------------------------------------------------------------------===//
 /// DSGraph - The graph that represents a function.
 ///
@@ -280,21 +221,15 @@
   /// constructed for.
   const TargetData &TD;
 
-#ifdef LLVA_KERNEL
-  hash_map<const DSNode*, MetaPoolHandle*> PoolDescriptors;
-#endif  
-
-  
-
   void operator=(const DSGraph &); // DO NOT IMPLEMENT
   DSGraph(const DSGraph&);         // DO NOT IMPLEMENT
 public:
   // Create a new, empty, DSGraph.
-  DSGraph(EquivalenceClasses<GlobalValue*> &ECs, const TargetData &td)
-    : GlobalsGraph(0), PrintAuxCalls(false), ScalarMap(ECs), TD(td) { }
-  // Compute the local DSGraph
-  DSGraph(EquivalenceClasses<GlobalValue*> &ECs, const TargetData &TD,
-          Function &F, DSGraph *GlobalsGraph);
+  DSGraph(EquivalenceClasses<GlobalValue*> &ECs, const TargetData &td,
+          DSGraph *GG = 0) 
+    :GlobalsGraph(GG), PrintAuxCalls(false), 
+     ScalarMap(ECs), TD(td)
+  { }
 
   // Copy ctor - If you want to capture the node mapping between the source and
   // destination graph, you may optionally do this by specifying a map to record
@@ -311,31 +246,6 @@
   DSGraph *getGlobalsGraph() const { return GlobalsGraph; }
   void setGlobalsGraph(DSGraph *G) { GlobalsGraph = G; }
 
-#ifdef LLVA_KERNEL
-#if 1
-  hash_map<const DSNode *, MetaPoolHandle*>& getPoolDescriptorsMap() {
-    return PoolDescriptors;
-  }
-  MetaPoolHandle *getPoolForNode(const DSNode *N) {
-    if (PoolDescriptors.count(N) > 0) {
-      return PoolDescriptors[N];
-    }
-    return 0;
-  }
-#else
-  hash_map<const DSNodeHandle *, MetaPoolHandle*>& getPoolDescriptorsMap() {
-    return PoolDescriptors;
-  }
-  MetaPoolHandle *getPoolForNode(const DSNodeHandle *N) {
-    if (PoolDescriptors.count(N) > 0) {
-      return PoolDescriptors[N];
-    }
-    return 0;
-  }
-#endif
-
-#endif  
-
   /// getGlobalECs - Return the set of equivalence classes that the global
   /// variables in the program form.
   EquivalenceClasses<GlobalValue*> &getGlobalECs() const {
@@ -418,6 +328,15 @@
     return I->second;
   }
 
+  bool hasNodeForValue(Value* V) const {
+    ScalarMapTy::const_iterator I = ScalarMap.find(V);
+    return I != ScalarMap.end();
+  }
+
+  void eraseNodeForValue(Value* V) {
+    ScalarMap.erase(V);
+  }
+
   /// retnodes_* iterator methods: expose iteration over return nodes in the
   /// graph, which are also the set of functions incorporated in this graph.
   typedef ReturnNodesTy::const_iterator retnodes_iterator;
@@ -445,6 +364,10 @@
     return I->second;
   }
 
+  DSNodeHandle& getOrCreateReturnNodeFor(Function& F) {
+    return ReturnNodes[&F];
+  }
+
   /// containsFunction - Return true if this DSGraph contains information for
   /// the specified function.
   bool containsFunction(Function *F) const {


Index: llvm-poolalloc/include/dsa/DataStructure.h
diff -u llvm-poolalloc/include/dsa/DataStructure.h:1.99 llvm-poolalloc/include/dsa/DataStructure.h:1.100
--- llvm-poolalloc/include/dsa/DataStructure.h:1.99	Wed Dec 13 23:51:06 2006
+++ llvm-poolalloc/include/dsa/DataStructure.h	Wed Apr 11 12:37:43 2007
@@ -20,7 +20,6 @@
 #include "llvm/ADT/hash_map"
 #include "llvm/ADT/hash_set"
 #include "llvm/ADT/EquivalenceClasses.h"
-#include "poolalloc/Config/config.h"
 
 namespace llvm {
 
@@ -31,41 +30,53 @@
 class DSCallSite;
 class DSNode;
 class DSNodeHandle;
-typedef std::map<const DSNode *, Value*> PoolDescriptorMapType;
 
 FunctionPass *createDataStructureStatsPass();
 FunctionPass *createDataStructureGraphCheckerPass();
 
-// FIXME: move this stuff to a private header
-namespace DataStructureAnalysis {
-  /// isPointerType - Return true if this first class type is big enough to hold
-  /// a pointer.
-  ///
-  bool isPointerType(const Type *Ty);
-}
+class DataStructures : public ModulePass {
 
-// LocalDataStructures - The analysis that computes the local data structure
-// graphs for all of the functions in the program.
-//
-// FIXME: This should be a Function pass that can be USED by a Pass, and would
-// be automatically preserved.  Until we can do that, this is a Pass.
-//
-class LocalDataStructures : public ModulePass {
+  /// TargetData, comes in handy
+  TargetData* TD;
+
+  /// Pass to get Graphs from
+  DataStructures* GraphSource;
+
+  /// Do we clone Graphs or steal them?
+  bool Clone;
+
+  void buildGlobalECs(std::set<GlobalValue*>& ECGlobals);
+
+  void eliminateUsesOfECGlobals(DSGraph& G, const std::set<GlobalValue*> &ECGlobals);
+
+protected:
   // DSInfo, one graph for each function
   hash_map<Function*, DSGraph*> DSInfo;
-  DSGraph *GlobalsGraph;
 
-#ifdef LLVA_KERNEL
-  Function *AddPoolDescToMetaPool;
-#endif  
+  /// The Globals Graph contains all information on the globals
+  DSGraph *GlobalsGraph;
 
   /// GlobalECs - The equivalence classes for each global value that is merged
   /// with other global values in the DSGraphs.
   EquivalenceClasses<GlobalValue*> GlobalECs;
-public:
-  ~LocalDataStructures() { releaseMemory(); }
 
-  virtual bool runOnModule(Module &M);
+
+  void setGraphSource(DataStructures* D) {
+    assert(!GraphSource && "Already have a Graph");
+    GraphSource = D;
+  }
+
+  void setGraphClone(bool clone) {
+    Clone = clone;
+  }
+
+  void setTargetData(TargetData& T) {
+    TD = &T;
+  }
+
+  void formGlobalECs();
+
+public:
 
   bool hasGraph(const Function &F) const {
     return DSInfo.find(const_cast<Function*>(&F)) != DSInfo.end();
@@ -80,10 +91,33 @@
     return *I->second;
   }
 
+  DSGraph& getOrCreateGraph(Function* F);
+
   DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
 
   EquivalenceClasses<GlobalValue*> &getGlobalECs() { return GlobalECs; }
 
+  TargetData& getTargetData() const { return *TD; }
+
+  /// deleteValue/copyValue - Interfaces to update the DSGraphs in the program.
+  /// These correspond to the interfaces defined in the AliasAnalysis class.
+  void deleteValue(Value *V);
+  void copyValue(Value *From, Value *To);
+};
+
+
+// LocalDataStructures - The analysis that computes the local data structure
+// graphs for all of the functions in the program.
+//
+// FIXME: This should be a Function pass that can be USED by a Pass, and would
+// be automatically preserved.  Until we can do that, this is a Pass.
+//
+class LocalDataStructures : public DataStructures {
+public:
+  ~LocalDataStructures() { releaseMemory(); }
+
+  virtual bool runOnModule(Module &M);
+
   /// print - Print out the analysis results...
   ///
   void print(std::ostream &O, const Module *M) const;
@@ -106,53 +140,19 @@
 /// data structure graphs for all of the functions in the program.  This pass
 /// only performs a "Bottom Up" propagation (hence the name).
 ///
-class BUDataStructures : public ModulePass {
+class BUDataStructures : public DataStructures {
 protected:
-  // DSInfo, one graph for each function
-  hash_map<Function*, DSGraph*> DSInfo;
-  DSGraph *GlobalsGraph;
   std::set<std::pair<Instruction*, Function*> > ActualCallees;
 
   // This map is only maintained during construction of BU Graphs
   std::map<std::vector<Function*>,
            std::pair<DSGraph*, std::vector<DSNodeHandle> > > *IndCallGraphMap;
 
-  /// GlobalECs - The equivalence classes for each global value that is merged
-  /// with other global values in the DSGraphs.
-  EquivalenceClasses<GlobalValue*> GlobalECs;
-
-  std::map<CallSite, std::vector<Function*> > AlreadyInlined;
-
 public:
   ~BUDataStructures() { releaseMyMemory(); }
 
   virtual bool runOnModule(Module &M);
 
-  bool hasGraph(const Function &F) const {
-    return DSInfo.find(const_cast<Function*>(&F)) != DSInfo.end();
-  }
-
-  /// getDSGraph - Return the data structure graph for the specified function.
-  ///
-  DSGraph &getDSGraph(const Function &F) const {
-    hash_map<Function*, DSGraph*>::const_iterator I =
-      DSInfo.find(const_cast<Function*>(&F));
-    if (I != DSInfo.end())
-      return *I->second;
-    return const_cast<BUDataStructures*>(this)->
-                   CreateGraphForExternalFunction(F);
-  }
-  
-  /// DSGraphExists - Is the DSGraph computed for this function?
-  ///
-  bool doneDSGraph(const Function *F) const {
-    return (DSInfo.find(const_cast<Function*>(F)) != DSInfo.end());
-  }
-
-  DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
-
-  EquivalenceClasses<GlobalValue*> &getGlobalECs() { return GlobalECs; }
-
   DSGraph &CreateGraphForExternalFunction(const Function &F);
 
   /// deleteValue/copyValue - Interfaces to update the DSGraphs in the program.
@@ -191,8 +191,6 @@
 private:
   void calculateGraph(DSGraph &G);
 
-  DSGraph &getOrCreateGraph(Function *F);
-
   unsigned calculateGraphs(Function *F, std::vector<Function*> &Stack,
                            unsigned &NextID,
                            hash_map<Function*, unsigned> &ValMap);
@@ -203,17 +201,10 @@
 /// for each function using the closed graphs for the callers computed
 /// by the bottom-up pass.
 ///
-class TDDataStructures : public ModulePass {
-  // DSInfo, one graph for each function
-  hash_map<Function*, DSGraph*> DSInfo;
+class TDDataStructures : public DataStructures {
   hash_set<Function*> ArgsRemainIncomplete;
-  DSGraph *GlobalsGraph;
   BUDataStructures *BUInfo;
 
-  /// GlobalECs - The equivalence classes for each global value that is merged
-  /// with other global values in the DSGraphs.
-  EquivalenceClasses<GlobalValue*> GlobalECs;
-
   /// CallerCallEdges - For a particular graph, we keep a list of these records
   /// which indicates which graphs call this function and from where.
   struct CallerCallEdge {
@@ -245,10 +236,6 @@
 
   virtual bool runOnModule(Module &M);
 
-  bool hasGraph(const Function &F) const {
-    return DSInfo.find(const_cast<Function*>(&F)) != DSInfo.end();
-  }
-
   /// getDSGraph - Return the data structure graph for the specified function.
   ///
   DSGraph &getDSGraph(const Function &F) const {
@@ -259,10 +246,6 @@
         getOrCreateDSGraph(const_cast<Function&>(F));
   }
 
-  DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
-  EquivalenceClasses<GlobalValue*> &getGlobalECs() { return GlobalECs; }
-
-
   /// deleteValue/copyValue - Interfaces to update the DSGraphs in the program.
   /// These correspond to the interfaces defined in the AliasAnalysis class.
   void deleteValue(Value *V);
@@ -302,19 +285,6 @@
 struct CompleteBUDataStructures : public BUDataStructures {
   virtual bool runOnModule(Module &M);
 
-  bool hasGraph(const Function &F) const {
-    return DSInfo.find(const_cast<Function*>(&F)) != DSInfo.end();
-  }
-
-  /// getDSGraph - Return the data structure graph for the specified function.
-  ///
-  DSGraph &getDSGraph(const Function &F) const {
-    hash_map<Function*, DSGraph*>::const_iterator I =
-      DSInfo.find(const_cast<Function*>(&F));
-    assert(I != DSInfo.end() && "Function not in module!");
-    return *I->second;
-  }
-
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
     AU.setPreservesAll();
     AU.addRequired<BUDataStructures>();






More information about the llvm-commits mailing list