[llvm-commits] [poolalloc] r99173 - in /poolalloc/trunk: include/dsa/DSCallGraph.h include/dsa/DSGraphTraits.h include/dsa/DSNode.h include/dsa/DataStructure.h include/dsa/keyiterator.h lib/DSA/BottomUpClosure.cpp lib/DSA/Local.cpp lib/DSA/Printer.cpp

Andrew Lenharth andrewl at lenharth.org
Mon Mar 22 07:42:05 PDT 2010


Author: alenhar2
Date: Mon Mar 22 09:42:05 2010
New Revision: 99173

URL: http://llvm.org/viewvc/llvm-project?rev=99173&view=rev
Log:
simplify and update callgraph after BU

Modified:
    poolalloc/trunk/include/dsa/DSCallGraph.h
    poolalloc/trunk/include/dsa/DSGraphTraits.h
    poolalloc/trunk/include/dsa/DSNode.h
    poolalloc/trunk/include/dsa/DataStructure.h
    poolalloc/trunk/include/dsa/keyiterator.h
    poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
    poolalloc/trunk/lib/DSA/Local.cpp
    poolalloc/trunk/lib/DSA/Printer.cpp

Modified: poolalloc/trunk/include/dsa/DSCallGraph.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DSCallGraph.h?rev=99173&r1=99172&r2=99173&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DSCallGraph.h (original)
+++ poolalloc/trunk/include/dsa/DSCallGraph.h Mon Mar 22 09:42:05 2010
@@ -46,6 +46,8 @@
   //Functions we know about that aren't called
   svset<const llvm::Function*> knownRoots;
 
+  svset<llvm::CallSite> completeCS;
+
   //Types for SCC construction
   typedef std::map<const llvm::Function*, unsigned> TFMap;
   typedef std::vector<const llvm::Function*> TFStack;
@@ -147,6 +149,14 @@
     return ii->second.size();
   }
 
+  void callee_mark_complete(llvm::CallSite CS) {
+    completeCS.insert(CS);
+  }
+
+  bool callee_is_complete(llvm::CallSite CS) const {
+    return completeCS.find(CS) != completeCS.end();
+  }
+
   unsigned size() const {
     unsigned sum = 0;
     for (ActualCalleesTy::const_iterator ii = ActualCallees.begin(),

Modified: poolalloc/trunk/include/dsa/DSGraphTraits.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DSGraphTraits.h?rev=99173&r1=99172&r2=99173&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DSGraphTraits.h (original)
+++ poolalloc/trunk/include/dsa/DSGraphTraits.h Mon Mar 22 09:42:05 2010
@@ -27,57 +27,42 @@
 template<typename NodeTy>
 class DSNodeIterator : public std::iterator<std::forward_iterator_tag, const DSNode, ptrdiff_t> {
   friend class DSNode;
-  NodeTy * const Node;
-  unsigned Offset;
+
+  DSNode::const_edge_iterator NH;
 
   typedef DSNodeIterator<NodeTy> _Self;
 
-  DSNodeIterator(NodeTy *N) : Node(N), Offset(0) {}   // begin iterator
-  DSNodeIterator(NodeTy *N, bool) : Node(N) {         // Create end iterator
-    if (N != 0) {
-      Offset = N->getSize();
-      if (Offset == 0 && Node->isForwarding() &&
-          Node->isDeadNode())        // Model Forward link
-        Offset += 1;
-    } else {
-      Offset = 0;
-    }
-  }
+  DSNodeIterator(NodeTy *N) : NH(N->edge_begin()) {}   // begin iterator
+  DSNodeIterator(NodeTy *N, bool) : NH(N->edge_end()) {}  // Create end iterator
+
 public:
-  DSNodeIterator(const DSNodeHandle &NH)
-    : Node(NH.getNode()), Offset(NH.getOffset()) {}
+//  DSNodeIterator(const DSNodeHandle &NH)
+//    : Node(NH.getNode()), Offset(NH.getOffset()) {}
 
   bool operator==(const _Self& x) const {
-    return Offset == x.Offset;
+    return NH == x.NH;
   }
   bool operator!=(const _Self& x) const { return !operator==(x); }
 
   const _Self &operator=(const _Self &I) {
-    assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
-    Offset = I.Offset;
+    NH = I.NH;
     return *this;
   }
 
   pointer operator*() const {
-    if (Node->isDeadNode())
-      return Node->getForwardNode();
-    else if (Node->hasLink(Offset))
-      return Node->getLink(Offset).getNode();
-    else
-      return 0;
+    return NH->second.getNode();
   }
   pointer operator->() const { return operator*(); }
 
   _Self& operator++() {                // Preincrement
-    Offset += 1;
+    ++NH;
     return *this;
   }
   _Self operator++(int) { // Postincrement
     _Self tmp = *this; ++*this; return tmp;
   }
 
-  unsigned getOffset() const { return Offset; }
-  const DSNode *getNode() const { return Node; }
+  unsigned getOffset() const { return NH->first; }
 };
 
 // Provide iterators for DSNode...

Modified: poolalloc/trunk/include/dsa/DSNode.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DSNode.h?rev=99173&r1=99172&r2=99173&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DSNode.h (original)
+++ poolalloc/trunk/include/dsa/DSNode.h Mon Mar 22 09:42:05 2010
@@ -22,7 +22,8 @@
 #include <set>
 #include "dsa/svset.h"
 #include "dsa/super_set.h"
-#include "DSGraph.h"
+#include "dsa/keyiterator.h"
+#include "dsa/DSGraph.h"
 
 namespace llvm {
 

Modified: poolalloc/trunk/include/dsa/DataStructure.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/DataStructure.h?rev=99173&r1=99172&r2=99173&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/DataStructure.h (original)
+++ poolalloc/trunk/include/dsa/DataStructure.h Mon Mar 22 09:42:05 2010
@@ -202,12 +202,7 @@
 class BUDataStructures : public DataStructures {
 protected:
 
-  // This map is only maintained during construction of BU Graphs
-  std::map<std::vector<const Function*>,
-           std::pair<DSGraph*, std::vector<DSNodeHandle> > > IndCallGraphMap;
-
   const char* debugname;
-  bool useCallGraph;
 
   EntryPointAnalysis* EP;
 
@@ -215,11 +210,10 @@
   static char ID;
   //Child constructor (CBU)
   BUDataStructures(intptr_t CID, const char* name, const char* printname)
-    : DataStructures(CID, printname), debugname(name), useCallGraph(true) {}
+    : DataStructures(CID, printname), debugname(name) {}
   //main constructor
   BUDataStructures() 
-    : DataStructures((intptr_t)&ID, "bu."), debugname("dsa-bu"),
-      useCallGraph(false) {}
+    : DataStructures((intptr_t)&ID, "bu."), debugname("dsa-bu") {}
   ~BUDataStructures() { releaseMemory(); }
 
   virtual bool runOnModule(Module &M);

Modified: poolalloc/trunk/include/dsa/keyiterator.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/dsa/keyiterator.h?rev=99173&r1=99172&r2=99173&view=diff
==============================================================================
--- poolalloc/trunk/include/dsa/keyiterator.h (original)
+++ poolalloc/trunk/include/dsa/keyiterator.h Mon Mar 22 09:42:05 2010
@@ -14,6 +14,161 @@
 #ifndef LLVM_KEYITERATOR_H
 #define	LLVM_KEYITERATOR_H
 
+#include <functional>
+
+//From SGI's STL
+
+// select1st and select2nd are extensions: they are not part of the standard.
+
+template <class _Pair>
+class _Select1st : public std::unary_function<_Pair, typename _Pair::first_type> {
+public:
+
+  const typename _Pair::first_type & operator()(const _Pair& __x) const {
+    return __x.first;
+  }
+};
+
+template <class _Pair>
+class _Select2nd : public std::unary_function<_Pair, typename _Pair::second_type> {
+public:
+
+  const typename _Pair::second_type & operator()(const _Pair& __x) const {
+    return __x.second;
+  }
+};
+
+template <class _Pair> class select1st : public _Select1st<_Pair> {
+};
+
+template <class _Pair> class select2nd : public _Select2nd<_Pair> {
+};
+
+
+// ref_mapped_iterator - This is a simple iterator adapter that causes a
+// function to be dereferenced whenever operator* is invoked on the iterator.
+// It is assumed that the function returns a valid reference, which differs
+// from llvm::mapped_iterator from which this was derived (copied)
+
+template <class RootIt, class UnaryFunc>
+class ref_mapped_iterator {
+  RootIt current;
+  UnaryFunc Fn;
+public:
+  typedef typename std::iterator_traits<RootIt>::iterator_category
+  iterator_category;
+  typedef typename std::iterator_traits<RootIt>::difference_type
+  difference_type;
+  typedef typename UnaryFunc::result_type value_type;
+
+  typedef typename UnaryFunc::result_type *pointer;
+  typedef typename UnaryFunc::result_type& reference;
+
+  typedef RootIt iterator_type;
+  typedef ref_mapped_iterator<RootIt, UnaryFunc> _Self;
+
+  inline const RootIt &getCurrent() const {
+    return current;
+  }
+
+  inline const UnaryFunc &getFunc() const {
+    return Fn;
+  }
+
+  inline explicit ref_mapped_iterator(const RootIt &I, UnaryFunc F)
+  : current(I), Fn(F) { }
+
+  inline ref_mapped_iterator(const ref_mapped_iterator &It)
+  : current(It.current), Fn(It.Fn) { }
+
+  inline reference operator*() const { // All this work to do this
+    return Fn(*current); // little change
+  }
+
+  _Self & operator++() {
+    ++current;
+    return *this;
+  }
+
+  _Self & operator--() {
+    --current;
+    return *this;
+  }
+
+  _Self operator++(int) {
+    _Self __tmp = *this;
+    ++current;
+    return __tmp;
+  }
+
+  _Self operator--(int) {
+    _Self __tmp = *this;
+    --current;
+    return __tmp;
+  }
+
+  _Self operator+(difference_type n) const {
+    return _Self(current + n, Fn);
+  }
+
+  _Self & operator+=(difference_type n) {
+    current += n;
+    return *this;
+  }
+
+  _Self operator-(difference_type n) const {
+    return _Self(current - n, Fn);
+  }
+
+  _Self & operator-=(difference_type n) {
+    current -= n;
+    return *this;
+  }
+
+  reference operator[](difference_type n) const {
+    return *(*this +n);
+  }
+
+  inline bool operator!=(const _Self &X) const {
+    return !operator==(X);
+  }
+
+  inline bool operator==(const _Self &X) const {
+    return current == X.current;
+  }
+
+  inline bool operator<(const _Self &X) const {
+    return current < X.current;
+  }
+
+  inline difference_type operator-(const _Self &X) const {
+    return current - X.current;
+  }
+};
+
+template <class Iter>
+class KeyIterator
+: public ref_mapped_iterator<Iter, select1st<typename Iter::value_type> > {
+  typedef select1st<typename Iter::value_type> FunTy;
+public:
+
+  KeyIterator(const Iter I)
+  : ref_mapped_iterator<Iter, select1st<typename Iter::value_type> >(I, FunTy()) { }
+};
+
+template <class Iter>
+class ValueIterator
+: public ref_mapped_iterator<Iter, select2nd<typename Iter::value_type> > {
+  typedef select2nd<typename Iter::value_type> FunTy;
+public:
+
+  ValueIterator(const Iter I)
+  : ref_mapped_iterator<Iter, select2nd<typename Iter::value_type> >(I, FunTy()) { }
+};
+
+
+#if 0
+
 template<class Iter>
 class KeyIterator {
   Iter I;
@@ -87,6 +242,8 @@
     return I != RHS.I;
   }
 };
+#endif
+
 
 #endif	/* LLVM_KEYITERATOR_H */
 

Modified: poolalloc/trunk/lib/DSA/BottomUpClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/BottomUpClosure.cpp?rev=99173&r1=99172&r2=99173&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/BottomUpClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/BottomUpClosure.cpp Mon Mar 22 09:42:05 2010
@@ -83,56 +83,10 @@
   }
 
 
-  return false;
-
-  std::vector<const Function*> EntryPoints;
-  EP = &getAnalysis<EntryPointAnalysis>();
-  EP->findEntryPoints(M, EntryPoints);
-
-  #if 0
-
-  std::vector<const Function*> Stack;
-  std::map<const Function*, unsigned> ValMap;
-  unsigned NextID = 1;
-
   std::vector<const Function*> EntryPoints;
   EP = &getAnalysis<EntryPointAnalysis>();
   EP->findEntryPoints(M, EntryPoints);
 
-  for (std::vector<const Function*>::iterator ii = EntryPoints.begin(),
-          ee = EntryPoints.end(); ii != ee; ++ii)
-    if (!hasDSGraph(**ii)) {
-      errs() << debugname << ": Main Function: " << (*ii)->getName() << "\n";
-      calculateGraphs(*ii, Stack, NextID, ValMap);
-      //CloneAuxIntoGlobal(getDSGraph(**ii));
-    }
-
-  errs() << "done main Funcs\n";
-
-  // Calculate the graphs for any functions that are unreachable from main...
-  for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
-    if (!I->isDeclaration() && !hasDSGraph(*I)) {
-      //DEBUG(
-            if (EntryPoints.size())
-            errs() << debugname << ": Function unreachable from main: "
-            << I->getName() << "\n";
-      //);
-      calculateGraphs(I, Stack, NextID, ValMap); // Calculate all graphs.
-      //CloneAuxIntoGlobal(getDSGraph(*I));
-    }
-
-  errs() << "done unreachable Funcs\n";
-  #endif
-
-  // If we computed any temporary indcallgraphs, free them now.
-  for (std::map<std::vector<const Function*>,
-         std::pair<DSGraph*, std::vector<DSNodeHandle> > >::iterator I =
-         IndCallGraphMap.begin(), E = IndCallGraphMap.end(); I != E; ++I) {
-    I->second.second.clear();  // Drop arg refs into the graph.
-    delete I->second.first;
-  }
-  IndCallGraphMap.clear();
-
   // At the end of the bottom-up pass, the globals graph becomes complete.
   // FIXME: This is not the right way to do this, but it is sorta better than
   // nothing!  In particular, externally visible globals and unresolvable call
@@ -216,6 +170,8 @@
 
   marked.insert(F);
   calculateGraph(G);
+  //once calculated, we can update the callgraph
+  G->buildCallGraph(callgraph);
   return G;
 }
 
@@ -278,25 +234,6 @@
 void BUDataStructures::calculateGraph(DSGraph* Graph) {
   DEBUG(Graph->AssertGraphOK(); Graph->getGlobalsGraph()->AssertGraphOK());
 
-  // If this graph contains the main function, clone the globals graph into this
-  // graph before we inline callees and other fun stuff.
-  bool ContainsMain = false;
-  DSGraph::ReturnNodesTy &ReturnNodes = Graph->getReturnNodes();
-
-  for (DSGraph::ReturnNodesTy::iterator I = ReturnNodes.begin(),
-       E = ReturnNodes.end(); I != E; ++I)
-    if (EP->isEntryPoint(I->first)) {
-      ContainsMain = true;
-      break;
-    }
-
-   // If this graph contains main, copy the contents of the globals graph over.
-   // Note that this is *required* for correctness.  If a callee contains a use
-   // of a global, we have to make sure to link up nodes due to global-argument
-   // bindings.
-   if (ContainsMain)
-    cloneGlobalsInto(Graph);
-
   // Move our call site list into TempFCs so that inline call sites go into the
   // new call site list and doesn't invalidate our iterators!
   std::list<DSCallSite> TempFCs;
@@ -410,8 +347,7 @@
   // Clone the global nodes into this graph.
   for (DSScalarMap::global_iterator I = Graph->getScalarMap().global_begin(),
        E = Graph->getScalarMap().global_end(); I != E; ++I)
-    if (isa<GlobalVariable > (*I))
-      RC.getClonedNH(GG->getNodeForValue(*I));
+    RC.getClonedNH(GG->getNodeForValue(*I));
 }
 
 //For all graphs

Modified: poolalloc/trunk/lib/DSA/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Local.cpp?rev=99173&r1=99172&r2=99173&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Local.cpp (original)
+++ poolalloc/trunk/lib/DSA/Local.cpp Mon Mar 22 09:42:05 2010
@@ -953,10 +953,12 @@
     // Add initializers for all of the globals to the globals graph.
     for (Module::global_iterator I = M.global_begin(), E = M.global_end();
          I != E; ++I)
-      if (I->isDeclaration())
-        GGB.mergeExternalGlobal(I);
-      else
-        GGB.mergeInGlobalInitializer(I);
+      if (!(I->hasSection() && I->getSection() == "llvm.metadata")) {
+        if (I->isDeclaration())
+          GGB.mergeExternalGlobal(I);
+        else
+          GGB.mergeInGlobalInitializer(I);
+      }
     // Add Functions to the globals graph.
     for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
       if (I->hasAddressTaken())

Modified: poolalloc/trunk/lib/DSA/Printer.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Printer.cpp?rev=99173&r1=99172&r2=99173&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/Printer.cpp (original)
+++ poolalloc/trunk/lib/DSA/Printer.cpp Mon Mar 22 09:42:05 2010
@@ -145,18 +145,21 @@
 
   static bool edgeTargetsEdgeSource(const void *Node,
                                     DSNode::const_iterator I) {
-    unsigned O = I.getNode()->getLink(I.getOffset()).getOffset();
+    unsigned O = I->getLink(I.getOffset()).getOffset();
     return O != 0;
   }
 
   static std::string getEdgeSourceLabel(const void* Node,
                                         DSNode::const_iterator I) {
-    return "*";
+    std::string S;
+    llvm::raw_string_ostream O(S);
+    O << I.getOffset();
+    return O.str();
   }
 
   static DSNode::const_iterator getEdgeTarget(const DSNode *Node,
                                               DSNode::const_iterator I) {
-    unsigned O = I.getNode()->getLink(I.getOffset()).getOffset();
+    unsigned O = I->getLink(I.getOffset()).getOffset();
     unsigned LinkNo = O;
     const DSNode *N = *I;
     DSNode::const_iterator R = N->begin();





More information about the llvm-commits mailing list