[llvm-commits] [poolalloc] r57321 - in /poolalloc/trunk/include: dsa/CallTargets.h dsa/DSGraph.h dsa/DSNode.h dsa/DSSupport.h dsa/DataStructure.h poolalloc/PoolAllocate.h

Andrew Lenharth alenhar2 at cs.uiuc.edu
Wed Oct 8 23:27:33 PDT 2008


Author: alenhar2
Date: Thu Oct  9 01:27:33 2008
New Revision: 57321

URL: http://llvm.org/viewvc/llvm-project?rev=57321&view=rev
Log:
simplify and unify code.  EQ pass may be broken

Modified:
    poolalloc/trunk/include/dsa/CallTargets.h
    poolalloc/trunk/include/dsa/DSGraph.h
    poolalloc/trunk/include/dsa/DSNode.h
    poolalloc/trunk/include/dsa/DSSupport.h
    poolalloc/trunk/include/dsa/DataStructure.h
    poolalloc/trunk/include/poolalloc/PoolAllocate.h

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

==============================================================================
--- poolalloc/trunk/include/dsa/CallTargets.h (original)
+++ poolalloc/trunk/include/dsa/CallTargets.h Thu Oct  9 01:27:33 2008
@@ -24,7 +24,7 @@
 namespace llvm {
 
   class CallTargetFinder : public ModulePass {
-    std::map<CallSite, std::vector<Function*> > IndMap;
+    std::map<CallSite, std::vector<const Function*> > IndMap;
     std::set<CallSite> CompleteSites;
     std::list<CallSite> AllSites;
 
@@ -40,8 +40,8 @@
     virtual void print(std::ostream &O, const Module *M) const;
 
     // Given a CallSite, get an iterator of callees
-    std::vector<Function*>::iterator begin(CallSite cs);
-    std::vector<Function*>::iterator end(CallSite cs);
+    std::vector<const Function*>::iterator begin(CallSite cs);
+    std::vector<const Function*>::iterator end(CallSite cs);
 
     // Iterate over CallSites in program
     std::list<CallSite>::iterator cs_begin();

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

==============================================================================
--- poolalloc/trunk/include/dsa/DSGraph.h (original)
+++ poolalloc/trunk/include/dsa/DSGraph.h Thu Oct  9 01:27:33 2008
@@ -39,17 +39,17 @@
 /// globals or unique node handles active in the function.
 ///
 class DSScalarMap {
-  typedef hash_map<Value*, DSNodeHandle> ValueMapTy;
+  typedef hash_map<const Value*, DSNodeHandle> ValueMapTy;
   ValueMapTy ValueMap;
 
-  typedef hash_set<GlobalValue*> GlobalSetTy;
+  typedef hash_set<const GlobalValue*> GlobalSetTy;
   GlobalSetTy GlobalSet;
 
-  EquivalenceClasses<GlobalValue*> &GlobalECs;
+  EquivalenceClasses<const GlobalValue*> &GlobalECs;
 public:
-  DSScalarMap(EquivalenceClasses<GlobalValue*> &ECs) : GlobalECs(ECs) {}
+  DSScalarMap(EquivalenceClasses<const GlobalValue*> &ECs) : GlobalECs(ECs) {}
 
-  EquivalenceClasses<GlobalValue*> &getGlobalECs() const { return GlobalECs; }
+  EquivalenceClasses<const GlobalValue*> &getGlobalECs() const { return GlobalECs; }
 
   // Compatibility methods: provide an interface compatible with a map of
   // Value* to DSNodeHandle's.
@@ -60,56 +60,56 @@
   const_iterator begin() const { return ValueMap.begin(); }
   const_iterator end() const { return ValueMap.end(); }
 
-  GlobalValue *getLeaderForGlobal(GlobalValue *GV) const {
-    EquivalenceClasses<GlobalValue*>::iterator ECI = GlobalECs.findValue(GV);
+  const GlobalValue *getLeaderForGlobal(const GlobalValue *GV) const {
+    EquivalenceClasses<const GlobalValue*>::iterator ECI = GlobalECs.findValue(GV);
     if (ECI == GlobalECs.end()) return GV;
     return *GlobalECs.findLeader(ECI);
   }
 
 
-  iterator find(Value *V) {
+  iterator find(const Value *V) {
     iterator I = ValueMap.find(V);
     if (I != ValueMap.end()) return I;
 
-    if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
+    if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
       // If this is a global, check to see if it is equivalenced to something
       // in the map.
-      GlobalValue *Leader = getLeaderForGlobal(GV);
+      const GlobalValue *Leader = getLeaderForGlobal(GV);
       if (Leader != GV)
-        I = ValueMap.find((Value*)Leader);
+        I = ValueMap.find((const Value*)Leader);
     }
     return I;
   }
-  const_iterator find(Value *V) const {
+  const_iterator find(const Value *V) const {
     const_iterator I = ValueMap.find(V);
     if (I != ValueMap.end()) return I;
 
-    if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
+    if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
       // If this is a global, check to see if it is equivalenced to something
       // in the map.
-      GlobalValue *Leader = getLeaderForGlobal(GV);
+      const GlobalValue *Leader = getLeaderForGlobal(GV);
       if (Leader != GV)
-        I = ValueMap.find((Value*)Leader);
+        I = ValueMap.find((const Value*)Leader);
     }
     return I;
   }
 
   /// getRawEntryRef - This method can be used by clients that are aware of the
   /// global value equivalence class in effect.
-  DSNodeHandle &getRawEntryRef(Value *V) {
+  DSNodeHandle &getRawEntryRef(const Value *V) {
     std::pair<iterator,bool> IP =
       ValueMap.insert(std::make_pair(V, DSNodeHandle()));
      if (IP.second)   // Inserted the new entry into the map.
-       if (GlobalValue *GV = dyn_cast<GlobalValue>(V))
+       if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
          GlobalSet.insert(GV);
      return IP.first->second;
   }
 
-  unsigned count(Value *V) const { return ValueMap.find(V) != ValueMap.end(); }
+  unsigned count(const Value *V) const { return ValueMap.find(V) != ValueMap.end(); }
 
-  void erase(Value *V) { erase(ValueMap.find(V)); }
+  void erase(const Value *V) { erase(ValueMap.find(V)); }
 
-  void eraseIfExists(Value *V) {
+  void eraseIfExists(const Value *V) {
     iterator I = find(V);
     if (I != end()) erase(I);
   }
@@ -117,7 +117,7 @@
   /// replaceScalar - When an instruction needs to be modified, this method can
   /// be used to update the scalar map to remove the old and insert the new.
   ///
-  void replaceScalar(Value *Old, Value *New) {
+  void replaceScalar(const Value *Old, const Value *New) {
     iterator I = find(Old);
     assert(I != end() && "Old value is not in the map!");
     ValueMap.insert(std::make_pair(New, I->second));
@@ -126,7 +126,7 @@
 
   /// copyScalarIfExists - If Old exists in the scalar map, make New point to
   /// whatever Old did.
-  void copyScalarIfExists(Value *Old, Value *New) {
+  void copyScalarIfExists(const Value *Old, const Value *New) {
     iterator I = find(Old);
     if (I != end())
       ValueMap.insert(std::make_pair(New, I->second));
@@ -134,12 +134,12 @@
 
   /// operator[] - Return the DSNodeHandle for the specified value, creating a
   /// new null handle if there is no entry yet.
-  DSNodeHandle &operator[](Value *V) {
+  DSNodeHandle &operator[](const Value *V) {
     iterator I = ValueMap.find(V);
     if (I != ValueMap.end())
       return I->second;   // Return value if already exists.
 
-    if (GlobalValue *GV = dyn_cast<GlobalValue>(V))
+    if (const GlobalValue *GV = dyn_cast<GlobalValue>(V))
       return AddGlobal(GV);
 
     return ValueMap.insert(std::make_pair(V, DSNodeHandle())).first->second;
@@ -147,7 +147,7 @@
 
   void erase(iterator I) {
     assert(I != ValueMap.end() && "Cannot erase end!");
-    if (GlobalValue *GV = dyn_cast<GlobalValue>(I->first))
+    if (const GlobalValue *GV = dyn_cast<GlobalValue>(I->first))
       GlobalSet.erase(GV);
     ValueMap.erase(I);
   }
@@ -178,9 +178,9 @@
   global_iterator global_begin() const { return GlobalSet.begin(); }
   global_iterator global_end() const { return GlobalSet.end(); }
   unsigned global_size() const { return GlobalSet.size(); }
-  unsigned global_count(GlobalValue *GV) const { return GlobalSet.count(GV); }
+  unsigned global_count(const GlobalValue *GV) const { return GlobalSet.count(GV); }
 private:
-  DSNodeHandle &AddGlobal(GlobalValue *GV);
+  DSNodeHandle &AddGlobal(const GlobalValue *GV);
 };
 
 //===----------------------------------------------------------------------===//
@@ -190,7 +190,7 @@
 public:
   // Public data-type declarations...
   typedef DSScalarMap ScalarMapTy;
-  typedef hash_map<Function*, DSNodeHandle> ReturnNodesTy;
+  typedef hash_map<const Function*, DSNodeHandle> ReturnNodesTy;
   typedef ilist<DSNode> NodeListTy;
 
   /// NodeMapTy - This data type is used when cloning one graph into another to
@@ -236,7 +236,7 @@
   DSGraph(const DSGraph&);         // DO NOT IMPLEMENT
 public:
   // Create a new, empty, DSGraph.
-  DSGraph(EquivalenceClasses<GlobalValue*> &ECs, const TargetData &td,
+  DSGraph(EquivalenceClasses<const GlobalValue*> &ECs, const TargetData &td,
           DSGraph *GG = 0) 
     :GlobalsGraph(GG), PrintAuxCalls(false), 
      ScalarMap(ECs), TD(td)
@@ -250,7 +250,7 @@
   // source.  You need to set a new GlobalsGraph with the setGlobalsGraph
   // method.
   //
-  DSGraph( DSGraph &DSG, EquivalenceClasses<GlobalValue*> &ECs,
+  DSGraph( DSGraph &DSG, EquivalenceClasses<const GlobalValue*> &ECs,
           unsigned CloneFlags = 0);
   ~DSGraph();
 
@@ -259,7 +259,7 @@
 
   /// getGlobalECs - Return the set of equivalence classes that the global
   /// variables in the program form.
-  EquivalenceClasses<GlobalValue*> &getGlobalECs() const {
+  EquivalenceClasses<const GlobalValue*> &getGlobalECs() const {
     return ScalarMap.getGlobalECs();
   }
 
@@ -334,21 +334,21 @@
   /// getNodeForValue - Given a value that is used or defined in the body of the
   /// current function, return the DSNode that it points to.
   ///
-  DSNodeHandle &getNodeForValue(Value *V) { return ScalarMap[V]; }
+  DSNodeHandle &getNodeForValue(const Value *V) { return ScalarMap[V]; }
 
-  const DSNodeHandle &getNodeForValue(Value *V) const {
+  const DSNodeHandle &getNodeForValue(const Value *V) const {
     ScalarMapTy::const_iterator I = ScalarMap.find(V);
     assert(I != ScalarMap.end() &&
            "Use non-const lookup function if node may not be in the map");
     return I->second;
   }
 
-  bool hasNodeForValue(Value* V) const {
+  bool hasNodeForValue(const Value* V) const {
     ScalarMapTy::const_iterator I = ScalarMap.find(V);
     return I != ScalarMap.end();
   }
 
-  void eraseNodeForValue(Value* V) {
+  void eraseNodeForValue(const Value* V) {
     ScalarMap.erase(V);
   }
 
@@ -367,25 +367,25 @@
 
   /// getReturnNodeFor - Return the return node for the specified function.
   ///
-  DSNodeHandle &getReturnNodeFor(Function &F) {
+  DSNodeHandle &getReturnNodeFor(const Function &F) {
     ReturnNodesTy::iterator I = ReturnNodes.find(&F);
     assert(I != ReturnNodes.end() && "F not in this DSGraph!");
     return I->second;
   }
 
-  const DSNodeHandle &getReturnNodeFor(Function &F) const {
+  const DSNodeHandle &getReturnNodeFor(const Function &F) const {
     ReturnNodesTy::const_iterator I = ReturnNodes.find(&F);
     assert(I != ReturnNodes.end() && "F not in this DSGraph!");
     return I->second;
   }
 
-  DSNodeHandle& getOrCreateReturnNodeFor(Function& F) {
+  DSNodeHandle& getOrCreateReturnNodeFor(const Function& F) {
     return ReturnNodes[&F];
   }
 
   /// containsFunction - Return true if this DSGraph contains information for
   /// the specified function.
-  bool containsFunction(Function *F) const {
+  bool containsFunction(const Function *F) const {
     return ReturnNodes.count(F);
   }
 
@@ -508,7 +508,7 @@
   /// function arguments.  The vector is filled in with the return value (or
   /// null if it is not pointer compatible), followed by all of the
   /// pointer-compatible arguments.
-  void getFunctionArgumentsForCall(Function *F,
+  void getFunctionArgumentsForCall(const Function *F,
                                    std::vector<DSNodeHandle> &Args) const;
 
   /// mergeInGraph - This graph merges in the minimal number of
@@ -523,13 +523,13 @@
   /// mergeInGraph - This method is the same as the above method, but the
   /// argument bindings are provided by using the formal arguments of F.
   ///
-  void mergeInGraph(const DSCallSite &CS, Function &F, const DSGraph &Graph,
-                    unsigned CloneFlags);
+  void mergeInGraph(const DSCallSite &CS, const Function &F, 
+                    const DSGraph &Graph, unsigned CloneFlags);
 
   /// getCallSiteForArguments - Get the arguments and return value bindings for
   /// the specified function in the current graph.
   ///
-  DSCallSite getCallSiteForArguments(Function &F) const;
+  DSCallSite getCallSiteForArguments(const Function &F) const;
 
   /// getDSCallSiteForCallSite - Given an LLVM CallSite object that is live in
   /// the context of this graph, return the DSCallSite for it.
@@ -540,7 +540,7 @@
     assert((!N || N->getParentGraph() == this) &&
            "AssertNodeInGraph: Node is not in graph!");
   }
-  void AssertNodeContainsGlobal(const DSNode *N, GlobalValue *GV) const;
+  void AssertNodeContainsGlobal(const DSNode *N, const GlobalValue *GV) const;
 
   void AssertCallSiteInGraph(const DSCallSite &CS) const;
   void AssertCallNodesInGraph() const;

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

==============================================================================
--- poolalloc/trunk/include/dsa/DSNode.h (original)
+++ poolalloc/trunk/include/dsa/DSNode.h Thu Oct  9 01:27:33 2008
@@ -75,7 +75,7 @@
 
   /// Globals - The list of global values that are merged into this node.
   ///
-  std::vector<GlobalValue*> Globals;
+  std::vector<const GlobalValue*> Globals;
 
   void operator=(const DSNode &); // DO NOT IMPLEMENT
   DSNode(const DSNode &);         // DO NOT IMPLEMENT
@@ -291,34 +291,34 @@
   /// addGlobal - Add an entry for a global value to the Globals list.  This
   /// also marks the node with the 'G' flag if it does not already have it.
   ///
-  void addGlobal(GlobalValue *GV);
+  void addGlobal(const GlobalValue *GV);
 
   /// removeGlobal - Remove the specified global that is explicitly in the
   /// globals list.
-  void removeGlobal(GlobalValue *GV);
+  void removeGlobal(const GlobalValue *GV);
 
-  void mergeGlobals(const std::vector<GlobalValue*> &RHS);
-  void clearGlobals() { std::vector<GlobalValue*>().swap(Globals); }
+  void mergeGlobals(const std::vector<const GlobalValue*> &RHS);
+  void clearGlobals() { Globals.clear(); }
 
   /// getGlobalsList - Return the set of global leaders that are represented by
   /// this node.  Note that globals that are in this equivalence class but are
   /// not leaders are not returned: for that, use addFullGlobalsList().
-  const std::vector<GlobalValue*> &getGlobalsList() const { return Globals; }
+  const std::vector<const GlobalValue*> &getGlobalsList() const { return Globals; }
 
   /// addFullGlobalsList - Compute the full set of global values that are
   /// represented by this node.  Unlike getGlobalsList(), this requires fair
   /// amount of work to compute, so don't treat this method call as free.
-  void addFullGlobalsList(std::vector<GlobalValue*> &List) const;
+  void addFullGlobalsList(std::vector<const GlobalValue*> &List) const;
 
   /// addFullFunctionList - Identical to addFullGlobalsList, but only return the
   /// functions in the full list.
-  void addFullFunctionList(std::vector<Function*> &List) const;
+  void addFullFunctionList(std::vector<const Function*> &List) const;
 
   /// globals_iterator/begin/end - Provide iteration methods over the global
   /// value leaders set that is merged into this node.  Like the getGlobalsList
   /// method, these iterators do not return globals that are part of the
   /// equivalence classes for globals in this node, but aren't leaders.
-  typedef std::vector<GlobalValue*>::const_iterator globals_iterator;
+  typedef std::vector<const GlobalValue*>::const_iterator globals_iterator;
   globals_iterator globals_begin() const { return Globals.begin(); }
   globals_iterator globals_end() const { return Globals.end(); }
 

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

==============================================================================
--- poolalloc/trunk/include/dsa/DSSupport.h (original)
+++ poolalloc/trunk/include/dsa/DSSupport.h Thu Oct  9 01:27:33 2008
@@ -163,11 +163,11 @@
 /// the DSNode handles for the function arguments.
 ///
 class DSCallSite {
-  CallSite     Site;                 // Actual call site
-  Function    *CalleeF;              // The function called (direct call)
-  DSNodeHandle CalleeN;              // The function node called (indirect call)
-  DSNodeHandle RetVal;               // Returned value
-  std::vector<DSNodeHandle> CallArgs;// The pointer arguments
+  CallSite        Site;               // Actual call site
+  const Function *CalleeF;            // The function called (direct call)
+  DSNodeHandle    CalleeN;            // The function node called (indirect call)
+  DSNodeHandle    RetVal;             // Returned value
+  std::vector<DSNodeHandle> CallArgs; // The pointer arguments
 
   static void InitNH(DSNodeHandle &NH, const DSNodeHandle &Src,
                      const hash_map<const DSNode*, DSNode*> &NodeMap) {
@@ -204,7 +204,7 @@
     assert(Callee && "Null callee node specified for call site!");
     Args.swap(CallArgs);
   }
-  DSCallSite(CallSite CS, const DSNodeHandle &rv, Function *Callee,
+  DSCallSite(CallSite CS, const DSNodeHandle &rv, const Function *Callee,
              std::vector<DSNodeHandle> &Args)
     : Site(CS), CalleeF(Callee), RetVal(rv) {
     assert(Callee && "Null callee function specified for call site!");
@@ -249,7 +249,7 @@
 
 
   // Accessor functions...
-  Function           &getCaller()     const;
+  const Function     &getCaller()     const;
   CallSite            getCallSite()   const { return Site; }
         DSNodeHandle &getRetVal()           { return RetVal; }
   const DSNodeHandle &getRetVal()     const { return RetVal; }
@@ -257,7 +257,7 @@
   DSNode *getCalleeNode() const {
     assert(!CalleeF && CalleeN.getNode()); return CalleeN.getNode();
   }
-  Function *getCalleeFunc() const {
+  const Function *getCalleeFunc() const {
     assert(!CalleeN.getNode() && CalleeF); return CalleeF;
   }
 

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

==============================================================================
--- poolalloc/trunk/include/dsa/DataStructure.h (original)
+++ poolalloc/trunk/include/dsa/DataStructure.h Thu Oct  9 01:27:33 2008
@@ -37,7 +37,12 @@
 FunctionPass *createDataStructureGraphCheckerPass();
 
 class DataStructures : public ModulePass {
-
+  typedef std::map<const Instruction*, std::set<const Function*> > ActualCalleesTy;
+  typedef hash_map<const Function*, DSGraph*> DSInfoTy;
+public:
+  typedef std::set<const Function*>::const_iterator callee_iterator;
+  
+private:
   /// TargetData, comes in handy
   TargetData* TD;
 
@@ -47,60 +52,90 @@
   /// Do we clone Graphs or steal them?
   bool Clone;
 
-  void buildGlobalECs(std::set<GlobalValue*>& ECGlobals);
+  void buildGlobalECs(std::set<const GlobalValue*>& ECGlobals);
 
-  void eliminateUsesOfECGlobals(DSGraph& G, const std::set<GlobalValue*> &ECGlobals);
+  void eliminateUsesOfECGlobals(DSGraph& G, const std::set<const GlobalValue*> &ECGlobals);
 
-protected:
   // DSInfo, one graph for each function
-  hash_map<Function*, DSGraph*> DSInfo;
+  DSInfoTy DSInfo;
+
+  // Callgraph, as computed so far
+  ActualCalleesTy ActualCallees;
+
+protected:
 
   /// 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;
+  EquivalenceClasses<const GlobalValue*> GlobalECs;
 
 
-  void setGraphSource(DataStructures* D) {
-    assert(!GraphSource && "Already have a Graph");
-    GraphSource = D;
-  }
+  void init(DataStructures* D, bool clone, bool printAuxCalls);
+  void init(TargetData* T);
 
-  void setGraphClone(bool clone) {
-    Clone = clone;
-  }
+  void formGlobalECs();
 
-  void setTargetData(TargetData& T) {
-    TD = &T;
-  }
 
-  void formGlobalECs();
+  void callee_add(const Instruction* I, const Function* F) {
+    ActualCallees[I].insert(F);
+  }
 
   DataStructures(intptr_t id) 
     :ModulePass(id), TD(0), GraphSource(0), GlobalsGraph(0) {}
 
 public:
+  callee_iterator callee_begin(const Instruction *I) const {
+    ActualCalleesTy::const_iterator ii = ActualCallees.find(I);
+    assert(ii != ActualCallees.end() && "No calls for instruction");
+    return ii->second.begin();
+  }
+
+  callee_iterator callee_end(const Instruction *I) const {
+    ActualCalleesTy::const_iterator ii = ActualCallees.find(I);
+    assert(ii != ActualCallees.end() && "No calls for instruction");
+    return ii->second.end();
+  }
+
+  unsigned callee_size() const {
+    unsigned sum = 0;
+    for (ActualCalleesTy::const_iterator ii = ActualCallees.begin(),
+           ee = ActualCallees.end(); ii != ee; ++ii)
+      sum += ii->second.size();
+    return sum;
+  }
+
+  void callee_get_keys(std::vector<const Instruction*>& keys) {
+    for (ActualCalleesTy::const_iterator ii = ActualCallees.begin(),
+           ee = ActualCallees.end(); ii != ee; ++ii)
+      keys.push_back(ii->first);
+  }
+
+  virtual void releaseMemory();
 
   bool hasDSGraph(const Function &F) const {
-    return DSInfo.find(const_cast<Function*>(&F)) != DSInfo.end();
+    return DSInfo.find(&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));
+    hash_map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
     assert(I != DSInfo.end() && "Function not in module!");
     return *I->second;
   }
 
-  DSGraph& getOrCreateGraph(Function* F);
+  void setDSGraph(const Function& F, DSGraph* G) {
+    assert(!DSInfo[&F] && "DSGraph already exists");
+    DSInfo[&F] = G;
+  }
+
+  DSGraph& getOrCreateGraph(const Function* F);
 
   DSGraph &getGlobalsGraph() const { return *GlobalsGraph; }
 
-  EquivalenceClasses<GlobalValue*> &getGlobalECs() { return GlobalECs; }
+  EquivalenceClasses<const GlobalValue*> &getGlobalECs() { return GlobalECs; }
 
   TargetData& getTargetData() const { return *TD; }
 
@@ -129,15 +164,9 @@
   ///
   void print(std::ostream &O, const Module *M) const;
 
-  /// releaseMemory - if the pass pipeline is done with this pass, we can
-  /// release our memory...
-  ///
-  virtual void releaseMemory();
-
   /// getAnalysisUsage - This obviously provides a data structure graph.
   ///
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.setPreservesAll();
     AU.addRequired<TargetData>();
   }
 };
@@ -145,6 +174,7 @@
 // StdLibDataStructures - This analysis recognizes common standard c library
 // functions and generates graphs for them.
 class StdLibDataStructures : public DataStructures {
+  void eraseCallsTo(Function* F);
 public:
   static char ID;
   StdLibDataStructures() : DataStructures((intptr_t)&ID) {}
@@ -156,15 +186,9 @@
   ///
   void print(std::ostream &O, const Module *M) const;
 
-  /// releaseMemory - if the pass pipeline is done with this pass, we can
-  /// release our memory...
-  ///
-  virtual void releaseMemory();
-
   /// getAnalysisUsage - This obviously provides a data structure graph.
   ///
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.setPreservesAll();
     AU.addRequired<LocalDataStructures>();
   }
 };
@@ -175,19 +199,16 @@
 ///
 class BUDataStructures : public DataStructures {
 protected:
-  std::set<std::pair<Instruction*, Function*> > ActualCallees;
 
   // This map is only maintained during construction of BU Graphs
-  std::map<std::vector<Function*>,
+  std::map<std::vector<const Function*>,
            std::pair<DSGraph*, std::vector<DSNodeHandle> > > IndCallGraphMap;
 
-  std::set<Function*> InlinedSomewhere;
-
   BUDataStructures(intptr_t id) : DataStructures(id) {}
 public:
   static char ID;
   BUDataStructures() : DataStructures((intptr_t)&ID) {}
-  ~BUDataStructures() { releaseMyMemory(); }
+  ~BUDataStructures() { releaseMemory(); }
 
   virtual bool runOnModule(Module &M);
 
@@ -200,36 +221,19 @@
   ///
   void print(std::ostream &O, const Module *M) const;
 
-  // FIXME: Once the pass manager is straightened out, rename this to
-  // releaseMemory.
-  void releaseMyMemory();
-
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.setPreservesAll();
     AU.addRequired<StdLibDataStructures>();
   }
 
-  typedef std::set<std::pair<Instruction*, Function*> > ActualCalleesTy;
-  const ActualCalleesTy &getActualCallees() const {
-    return ActualCallees;
-  }
-
-  typedef ActualCalleesTy::const_iterator callee_iterator;
-  callee_iterator callee_begin(Instruction *I) const {
-    return ActualCallees.lower_bound(std::pair<Instruction*,Function*>(I, 0));
-  }
-
-  callee_iterator callee_end(Instruction *I) const {
-    I = (Instruction*)((char*)I + 1);
-    return ActualCallees.lower_bound(std::pair<Instruction*,Function*>(I, 0));
-  }
-
 private:
   void calculateGraph(DSGraph &G);
 
-  unsigned calculateGraphs(Function *F, std::vector<Function*> &Stack,
+  void inlineUnresolved(DSGraph &G);
+
+  unsigned calculateGraphs(const Function *F, 
+                           std::vector<const Function*> &Stack,
                            unsigned &NextID,
-                           hash_map<Function*, unsigned> &ValMap);
+                           hash_map<const Function*, unsigned> &ValMap);
 
 
   void CloneAuxIntoGlobal(DSGraph& G);
@@ -242,7 +246,7 @@
 /// by the bottom-up pass.
 ///
 class TDDataStructures : public DataStructures {
-  hash_set<Function*> ArgsRemainIncomplete;
+  hash_set<const Function*> ArgsRemainIncomplete;
   BUDataStructures *BUInfo;
 
   /// CallerCallEdges - For a particular graph, we keep a list of these records
@@ -250,9 +254,9 @@
   struct CallerCallEdge {
     DSGraph *CallerGraph;        // The graph of the caller function.
     const DSCallSite *CS;        // The actual call site.
-    Function *CalledFunction;    // The actual function being called.
+    const Function *CalledFunction;    // The actual function being called.
 
-    CallerCallEdge(DSGraph *G, const DSCallSite *cs, Function *CF)
+    CallerCallEdge(DSGraph *G, const DSCallSite *cs, const Function *CF)
       : CallerGraph(G), CS(cs), CalledFunction(CF) {}
 
     bool operator<(const CallerCallEdge &RHS) const {
@@ -269,12 +273,12 @@
   // is a sorted set of callee functions, the value is the DSGraph that holds
   // all of the caller graphs merged together, and the DSCallSite to merge with
   // the arguments for each function.
-  std::map<std::vector<Function*>, DSGraph*> IndCallMap;
+  std::map<std::vector<const Function*>, DSGraph*> IndCallMap;
 
 public:
   static char ID;
   TDDataStructures() : DataStructures((intptr_t)&ID) {}
-  ~TDDataStructures() { releaseMyMemory(); }
+  ~TDDataStructures() { releaseMemory(); }
 
   virtual bool runOnModule(Module &M);
 
@@ -282,14 +286,9 @@
   ///
   void print(std::ostream &O, const Module *M) const;
 
-  /// If the pass pipeline is done with this pass, we can release our memory...
-  ///
-  virtual void releaseMyMemory();
-
   /// getAnalysisUsage - This obviously provides a data structure graph.
   ///
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.setPreservesAll();
     AU.addRequired<BUDataStructures>();
   }
 
@@ -298,7 +297,7 @@
                                                   hash_set<DSNode*> &Visited);
 
   void InlineCallersIntoGraph(DSGraph &G);
-  void ComputePostOrder(Function &F, hash_set<DSGraph*> &Visited,
+  void ComputePostOrder(const Function &F, hash_set<DSGraph*> &Visited,
                         std::vector<DSGraph*> &PostOrder);
 };
 
@@ -308,32 +307,28 @@
 /// their callers graphs, making the result more useful for things like pool
 /// allocation.
 ///
-class CompleteBUDataStructures : public BUDataStructures {
+class CompleteBUDataStructures : public  DataStructures {
 public:
   static char ID;
-  CompleteBUDataStructures() : BUDataStructures((intptr_t)&ID) {}
-  ~CompleteBUDataStructures() { releaseMyMemory(); }
+  CompleteBUDataStructures() : DataStructures((intptr_t)&ID) {}
+  ~CompleteBUDataStructures() { releaseMemory(); }
 
   virtual bool runOnModule(Module &M);
 
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.setPreservesAll();
     AU.addRequired<BUDataStructures>();
-
-    // FIXME: TEMPORARY (remove once finalization of indirect call sites in the
-    // globals graph has been implemented in the BU pass)
-    AU.addRequired<TDDataStructures>();
   }
 
   /// print - Print out the analysis results...
   ///
   void print(std::ostream &O, const Module *M) const;
 
+  virtual void releaseMemory();
+
 private:
   unsigned calculateSCCGraphs(DSGraph &FG, std::vector<DSGraph*> &Stack,
                               unsigned &NextID,
                               hash_map<DSGraph*, unsigned> &ValMap);
-  DSGraph &getOrCreateGraph(Function &F);
   void processGraph(DSGraph &G);
 };
 
@@ -343,30 +338,16 @@
 /// DS graph for all functions in an equivalence class.  After this merging,
 /// graphs are inlined bottom-up on the SCCs of the final (CBU) call graph.
 ///
-struct EquivClassGraphs : public ModulePass {
-  CompleteBUDataStructures *CBU;
-
-  DSGraph *GlobalsGraph;
-
-  // DSInfo - one graph for each function.
-  hash_map<const Function*, DSGraph*> DSInfo;
-
-  /// ActualCallees - The actual functions callable from indirect call sites.
-  ///
-  std::set<std::pair<Instruction*, Function*> > ActualCallees;
+struct EquivClassGraphs : public DataStructures {
 
   // Equivalence class where functions that can potentially be called via the
   // same function pointer are in the same class.
-  EquivalenceClasses<Function*> FuncECs;
+  EquivalenceClasses<const Function*> FuncECs;
 
   /// OneCalledFunction - For each indirect call, we keep track of one
   /// target of the call.  This is used to find equivalence class called by
   /// a call site.
-  std::map<DSNode*, Function *> OneCalledFunction;
-
-  /// GlobalECs - The equivalence classes for each global value that is merged
-  /// with other global values in the DSGraphs.
-  EquivalenceClasses<GlobalValue*> GlobalECs;
+  std::map<DSNode*, const Function *> OneCalledFunction;
 
 public:
   static char ID;
@@ -382,49 +363,12 @@
   ///
   void print(std::ostream &O, const Module *M) const;
 
-  EquivalenceClasses<GlobalValue*> &getGlobalECs() { return GlobalECs; }
-
-  /// getDSGraph - Return the data structure graph for the specified function.
-  /// This returns the folded graph.  The folded graph is the same as the CBU
-  /// graph iff the function is in a singleton equivalence class AND all its
-  /// callees also have the same folded graph as the CBU graph.
-  ///
-  DSGraph &getDSGraph(const Function &F) const {
-    hash_map<const Function*, DSGraph*>::const_iterator I = DSInfo.find(&F);
-    assert(I != DSInfo.end() && "No graph computed for that function!");
-    return *I->second;
-  }
-
-  bool hasDSGraph(const Function &F) const {
-    return DSInfo.find(&F) != DSInfo.end();
-  }
-
   /// getSomeCalleeForCallSite - Return any one callee function at
   /// a call site.
   ///
-  Function *getSomeCalleeForCallSite(const CallSite &CS) const;
-
-  DSGraph &getGlobalsGraph() const {
-    return *GlobalsGraph;
-  }
-
-  typedef std::set<std::pair<Instruction*, Function*> > ActualCalleesTy;
-  const ActualCalleesTy &getActualCallees() const {
-    return ActualCallees;
-  }
-
-  typedef ActualCalleesTy::const_iterator callee_iterator;
-  callee_iterator callee_begin(Instruction *I) const {
-    return ActualCallees.lower_bound(std::pair<Instruction*,Function*>(I, 0));
-  }
-
-  callee_iterator callee_end(Instruction *I) const {
-    I = (Instruction*)((char*)I + 1);
-    return ActualCallees.lower_bound(std::pair<Instruction*,Function*>(I, 0));
-  }
+  const Function *getSomeCalleeForCallSite(const CallSite &CS) const;
 
   virtual void getAnalysisUsage(AnalysisUsage &AU) const {
-    AU.setPreservesAll();
     AU.addRequired<CompleteBUDataStructures>();
   }
 
@@ -436,7 +380,6 @@
                       std::map<DSGraph*, unsigned> &ValMap);
   void processGraph(DSGraph &FG);
 
-  DSGraph &getOrCreateGraph(Function &F);
 };
 
 } // End llvm namespace

Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/PoolAllocate.h?rev=57321&r1=57320&r2=57321&view=diff

==============================================================================
--- poolalloc/trunk/include/poolalloc/PoolAllocate.h (original)
+++ poolalloc/trunk/include/poolalloc/PoolAllocate.h Thu Oct  9 01:27:33 2008
@@ -113,9 +113,9 @@
   bool BoundsChecksEnabled;
 
   virtual ~PoolAllocateGroup () {return;}
-  virtual PA::FuncInfo *getFuncInfo(Function &F) { return 0;}
-  virtual PA::FuncInfo *getFuncInfoOrClone(Function &F) {return 0;}
-  virtual Function *getOrigFunctionFromClone(Function *F) const {return 0;}
+  virtual PA::FuncInfo *getFuncInfo(const Function &F) { return 0;}
+  virtual PA::FuncInfo *getFuncInfoOrClone(const Function &F) {return 0;}
+  virtual Function *getOrigFunctionFromClone(const Function *F) const {return 0;}
 
   virtual const Type * getPoolType() {return 0;}
 
@@ -151,7 +151,7 @@
   Module *CurModule;
   CallTargetFinder* CTF;
   
-  std::map<Function*, Function*> CloneToOrigMap;
+  std::map<const Function*, Function*> CloneToOrigMap;
 public:
 
   Constant *PoolInit, *PoolDestroy, *PoolAlloc, *PoolRealloc, *PoolMemAlign;
@@ -169,7 +169,7 @@
   std::map<const DSNode*, Value*> GlobalNodes;
 
 protected:
-  std::map<Function*, PA::FuncInfo> FunctionInfo;
+  std::map<const Function*, PA::FuncInfo> FunctionInfo;
 
  public:
   static char ID;
@@ -188,22 +188,22 @@
   /// getOrigFunctionFromClone - Given a pointer to a function that was cloned
   /// from another function, return the original function.  If the argument
   /// function is not a clone, return null.
-  Function *getOrigFunctionFromClone(Function *F) const {
-    std::map<Function*, Function*>::const_iterator I = CloneToOrigMap.find(F);
+  Function *getOrigFunctionFromClone(const Function *F) const {
+    std::map<const Function*, Function*>::const_iterator I = CloneToOrigMap.find(F);
     return I != CloneToOrigMap.end() ? I->second : 0;
   }
 
   /// getFuncInfo - Return the FuncInfo object for the specified function.
   ///
-  PA::FuncInfo *getFuncInfo(Function &F) {
-    std::map<Function*, PA::FuncInfo>::iterator I = FunctionInfo.find(&F);
+  PA::FuncInfo *getFuncInfo(const Function &F) {
+    std::map<const Function*, PA::FuncInfo>::iterator I = FunctionInfo.find(&F);
     return I != FunctionInfo.end() ? &I->second : 0;
   }
 
   /// getFuncInfoOrClone - Return the function info object for for the specified
   /// function.  If this function is a clone of another function, return the
   /// function info object for the original function.
-  PA::FuncInfo *getFuncInfoOrClone(Function &F) {
+  PA::FuncInfo *getFuncInfoOrClone(const Function &F) {
     // If it is cloned or not check it out.
     if (PA::FuncInfo *FI = getFuncInfo(F))
       return FI;
@@ -366,7 +366,7 @@
 class PoolAllocateSimple : public PoolAllocate {
   Value * TheGlobalPool;
   DSGraph * CombinedDSGraph;
-  EquivalenceClasses<GlobalValue*> GlobalECs;
+  EquivalenceClasses<const GlobalValue*> GlobalECs;
   TargetData * TD;
 public:
   static char ID;





More information about the llvm-commits mailing list