[llvm-commits] [poolalloc] r111872 - in /poolalloc/trunk: include/dsa/DSGraph.h include/dsa/DataStructure.h lib/DSA/BottomUpClosure.cpp lib/DSA/DSGraph.cpp lib/DSA/Local.cpp

Will Dietz wdietz2 at illinois.edu
Mon Aug 23 17:23:58 PDT 2010


Author: wdietz2
Date: Mon Aug 23 19:23:58 2010
New Revision: 111872

URL: http://llvm.org/viewvc/llvm-project?rev=111872&view=rev
Log:
Filter callsites when evaluting termination condition of BU.
Filter callsites in the same manner across BU.
Filter callsites when building callgraph in local.
/Don't/ filter callsites in runOnModuleInternal or when building callgraphs
  while running CBU or EQBU/EQTD.

This fixes PR7929, and test case 2010-08-19-SimpleCallGraph.ll.

Modified:
    poolalloc/trunk/include/dsa/DSGraph.h
    poolalloc/trunk/include/dsa/DataStructure.h
    poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
    poolalloc/trunk/lib/DSA/DSGraph.cpp
    poolalloc/trunk/lib/DSA/Local.cpp

Modified: poolalloc/trunk/include/dsa/DSGraph.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DSGraph.h?rev=111872&r1=111871&r2=111872&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DSGraph.h (original)
+++ poolalloc/trunk/include/dsa/DSGraph.h Mon Aug 23 19:23:58 2010
@@ -337,7 +337,7 @@
   // addAuxFunctionCall - Add a call site to the AuxFunctionCallList
   void addAuxFunctionCall(DSCallSite D) { AuxFunctionCalls.push_front(D); }
 
-  void buildCallGraph(DSCallGraph& DCG) const;
+  void buildCallGraph(DSCallGraph& DCG, bool filter) const;
 
   /// removeFunction - Specify that all call sites to the function have been
   /// fully specified by a pass such as StdLibPass.

Modified: poolalloc/trunk/include/dsa/DataStructure.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=111872&r1=111871&r2=111872&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DataStructure.h (original)
+++ poolalloc/trunk/include/dsa/DataStructure.h Mon Aug 23 19:23:58 2010
@@ -212,14 +212,21 @@
   EntryPointAnalysis* EP;
 
   void cloneIntoGlobals(DSGraph* G);
+
+  // filterCallees -- Whether or not we filter out illegal callees
+  // from the CallGraph.  This is useful while doing original BU,
+  // but might be undesirable in other passes such as CBU/EQBU.
+  bool filterCallees;
 public:
   static char ID;
   //Child constructor (CBU)
-  BUDataStructures(intptr_t CID, const char* name, const char* printname)
-    : DataStructures(CID, printname), debugname(name) {}
+  BUDataStructures(intptr_t CID, const char* name, const char* printname,
+      bool filter)
+    : DataStructures(CID, printname), debugname(name), filterCallees(filter) {}
   //main constructor
-  BUDataStructures() 
-    : DataStructures((intptr_t)&ID, "bu."), debugname("dsa-bu") {}
+  BUDataStructures()
+    : DataStructures((intptr_t)&ID, "bu."), debugname("dsa-bu"),
+    filterCallees(true) {}
   ~BUDataStructures() { releaseMemory(); }
 
   virtual bool runOnModule(Module &M);
@@ -253,6 +260,12 @@
   void CloneAuxIntoGlobal(DSGraph* G);
   void cloneGlobalsInto(DSGraph* G);
   void finalizeGlobals(void);
+
+  void getAllCallees(const DSCallSite &CS,
+                     std::vector<const Function*> &Callees);
+  void getAllAuxCallees (DSGraph* G, std::vector<const Function*> & Callees);
+  void applyCallsiteFilter(const DSCallSite &DCS,
+                           std::vector<const Function*> &Callees);
 };
 
 /// CompleteBUDataStructures - This is the exact same as the bottom-up graphs,
@@ -268,7 +281,7 @@
   CompleteBUDataStructures(intptr_t CID = (intptr_t)&ID, 
                            const char* name = "dsa-cbu", 
                            const char* printname = "cbu.")
-    : BUDataStructures(CID, name, printname) {}
+    : BUDataStructures(CID, name, printname, false) {}
   ~CompleteBUDataStructures() { releaseMemory(); }
 
   virtual bool runOnModule(Module &M);

Modified: poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/BottomUpClosure.cpp?rev=111872&r1=111871&r2=111872&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/BottomUpClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/BottomUpClosure.cpp Mon Aug 23 19:23:58 2010
@@ -209,14 +209,41 @@
 }
 
 //
-// Function: GetAllCallees()
+// Function: applyCallsiteFilter
+//
+// Description:
+//  Given a DSCallSite, and a list of functions, filter out the ones
+//  that aren't callable from the given Callsite.
+//
+//  Does no filtering if 'filterCallees' is set to false.
+//
+void BUDataStructures::
+applyCallsiteFilter(const DSCallSite &DCS, std::vector<const Function*> &Callees) {
+
+  if (!filterCallees) return;
+
+  std::vector<const Function*>::iterator I = Callees.begin();
+  CallSite CS = DCS.getCallSite();
+  while(I != Callees.end()) {
+    if (functionIsCallable(CS, *I)) {
+      ++I;
+    }
+    else {
+      I = Callees.erase(I);
+    }
+  }
+}
+
+//
+// Function: getAllCallees()
 //
 // Description:
 //  Given a DSCallSite, add to the list the functions that can be called by
-//  the call site *if* it is resolvable.
+//  the call site *if* it is resolvable.  Uses 'applyCallsiteFilter' to
+//  only add the functions that are valid targets of this callsite.
 //
-static void
-GetAllCallees(const DSCallSite &CS, std::vector<const Function*> &Callees) {
+void BUDataStructures::
+getAllCallees(const DSCallSite &CS, std::vector<const Function*> &Callees) {
   //
   // FIXME: Should we check for the Unknown flag on indirect call sites?
   //
@@ -230,13 +257,22 @@
       Callees.push_back(CS.getCalleeFunc());
   } else if (!CS.getCalleeNode()->isIncompleteNode()) {
     // Get all callees.
-    if (!CS.getCalleeNode()->isExternFuncNode())
-      CS.getCalleeNode()->addFullFunctionList(Callees);
+    if (!CS.getCalleeNode()->isExternFuncNode()) {
+      // Get all the callees for this callsite
+      std::vector<const Function *> tempCallees;
+      CS.getCalleeNode()->addFullFunctionList(tempCallees);
+      // Filter out the ones that are invalid targets with respect
+      // to this particular callsite.
+      applyCallsiteFilter(CS, tempCallees);
+      // Insert the remaining callees (legal ones, if we're filtering)
+      // into the master 'Callees' list
+      Callees.insert(Callees.end(),tempCallees.begin(),tempCallees.end());
+    }
   }
 }
 
 //
-// Function: GetAllAuxCallees()
+// Function: getAllAuxCallees()
 //
 // Description:
 //  Return a list containing all of the resolvable callees in the auxiliary
@@ -251,14 +287,14 @@
 //            sites.  This list is always cleared by this function before any
 //            functions are added to it.
 //
-static void
-GetAllAuxCallees (DSGraph* G, std::vector<const Function*> & Callees) {
+void BUDataStructures::
+getAllAuxCallees (DSGraph* G, std::vector<const Function*> & Callees) {
   //
   // Clear out the list of callees.
   //
   Callees.clear();
   for (DSGraph::afc_iterator I = G->afc_begin(), E = G->afc_end(); I != E; ++I)
-    GetAllCallees(*I, Callees);
+    getAllCallees(*I, Callees);
 }
 
 //
@@ -349,7 +385,7 @@
   // graph (DSCallgraph) as we're still in the process of constructing it).
   //
   std::vector<const Function*> CalleeFunctions;
-  GetAllAuxCallees(Graph, CalleeFunctions);
+  getAllAuxCallees(Graph, CalleeFunctions);
 
   //
   // Iterate through each call target (these are the edges out of the current
@@ -404,7 +440,7 @@
     //
     // Should we revisit the graph?  Only do it if there are now new resolvable
     // callees.
-    GetAllAuxCallees (Graph, CalleeFunctions);
+    getAllAuxCallees (Graph, CalleeFunctions);
     if (!CalleeFunctions.empty()) {
       DEBUG(errs() << "Recalculating " << F->getName() << " due to new knowledge\n");
       ValMap.erase(F);
@@ -535,7 +571,7 @@
   // Now that we have new information merged into the function's DSGraph,
   // update the call graph using this new information.
   //
-  G->buildCallGraph(callgraph);
+  G->buildCallGraph(callgraph,filterCallees);
 
   //
   // Return the DSGraph associated with this function.
@@ -770,7 +806,7 @@
   //
   // Update the callgraph with the new information that we have gleaned.
   //
-  Graph->buildCallGraph(callgraph);
+  Graph->buildCallGraph(callgraph,filterCallees);
 }
 
 //For Entry Points

Modified: poolalloc/trunk/lib/DSA/DSGraph.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DSGraph.cpp?rev=111872&r1=111871&r2=111872&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/DSGraph.cpp (original)
+++ poolalloc/trunk/lib/DSA/DSGraph.cpp Mon Aug 23 19:23:58 2010
@@ -1463,7 +1463,10 @@
 //  of function calls that can be inferred from the unresolved call sites
 //  within the DSGraph.
 //
-void DSGraph::buildCallGraph(DSCallGraph& DCG) const {
+//  The parameter 'filter' determines if we should attempt to prune callees
+//  that are illegal to be called from the callsite.
+//
+void DSGraph::buildCallGraph(DSCallGraph& DCG, bool filter) const {
   //
   // Get the list of unresolved call sites.
   //
@@ -1497,7 +1500,7 @@
       //
       for (std::vector<const Function*>::iterator Fi = MaybeTargets.begin(),
            Fe = MaybeTargets.end(); Fi != Fe; ++Fi)
-        if (functionIsCallable(CS, *Fi))
+        if (!filter || functionIsCallable(CS, *Fi))
           DCG.insert(CS, *Fi);
         else
           ++NumFiltered;

Modified: poolalloc/trunk/lib/DSA/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Local.cpp?rev=111872&r1=111871&r2=111872&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Local.cpp (original)
+++ poolalloc/trunk/lib/DSA/Local.cpp Mon Aug 23 19:23:58 2010
@@ -1203,7 +1203,7 @@
       setDSGraph(*I, G);
       propagateUnknownFlag(G);
       callgraph.insureEntry(I);
-      G->buildCallGraph(callgraph);
+      G->buildCallGraph(callgraph, true);
     }
 
   GlobalsGraph->removeTriviallyDeadNodes();





More information about the llvm-commits mailing list