[llvm-commits] [poolalloc] r96630 - in /poolalloc/trunk: include/dsa/DSGraphTraits.h include/dsa/DSNode.h include/dsa/DSSupport.h lib/DSA/ lib/DSA/DataStructure.cpp lib/DSA/Local.cpp lib/DSA/Printer.cpp lib/DSA/TopDownClosure.cpp

Andrew Lenharth alenhar2 at cs.uiuc.edu
Thu Feb 18 16:08:06 PST 2010


Author: alenhar2
Date: Thu Feb 18 18:08:04 2010
New Revision: 96630

URL: http://llvm.org/viewvc/llvm-project?rev=96630&view=rev
Log:
Time region is long since uninteresting.  Make pointer tracking byte offset based (handles missaligned pointers, readies for union type inference).  Rudarmentary first class aggregate support (partial anyway).

Modified:
    poolalloc/trunk/include/dsa/DSGraphTraits.h
    poolalloc/trunk/include/dsa/DSNode.h
    poolalloc/trunk/include/dsa/DSSupport.h
    poolalloc/trunk/lib/DSA/   (props changed)
    poolalloc/trunk/lib/DSA/DataStructure.cpp
    poolalloc/trunk/lib/DSA/Local.cpp
    poolalloc/trunk/lib/DSA/Printer.cpp
    poolalloc/trunk/lib/DSA/TopDownClosure.cpp

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

==============================================================================
--- poolalloc/trunk/include/dsa/DSGraphTraits.h (original)
+++ poolalloc/trunk/include/dsa/DSGraphTraits.h Thu Feb 18 18:08:04 2010
@@ -34,10 +34,10 @@
   DSNodeIterator(NodeTy *N) : Node(N), Offset(0) {}   // begin iterator
   DSNodeIterator(NodeTy *N, bool) : Node(N) {         // Create end iterator
     if (N != 0) {
-      Offset = N->getNumLinks() << DS::PointerShift;
+      Offset = N->getNumLinks();
       if (Offset == 0 && Node->getForwardNode() &&
           Node->isDeadNode())        // Model Forward link
-        Offset += DS::PointerSize;
+        Offset += 1;
     } else {
       Offset = 0;
     }
@@ -66,7 +66,7 @@
   pointer operator->() const { return operator*(); }
 
   _Self& operator++() {                // Preincrement
-    Offset += (1 << DS::PointerShift);
+    Offset += 1;
     return *this;
   }
   _Self operator++(int) { // Postincrement

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

==============================================================================
--- poolalloc/trunk/include/dsa/DSNode.h (original)
+++ poolalloc/trunk/include/dsa/DSNode.h Thu Feb 18 18:08:04 2010
@@ -195,28 +195,19 @@
   /// hasLink - Return true if this memory object has a link in slot LinkNo
   ///
   bool hasLink(unsigned Offset) const {
-    assert((Offset & ((1 << DS::PointerShift)-1)) == 0 &&
-           "Pointer offset not aligned correctly!");
-    unsigned Index = Offset >> DS::PointerShift;
-    assert(Index < Links.size() && "Link index is out of range!");
-    return Links[Index].getNode();
+    assert(Offset < Links.size() && "Link index is out of range!");
+    return Links[Offset].getNode();
   }
 
   /// getLink - Return the link at the specified offset.
   ///
   DSNodeHandle &getLink(unsigned Offset) {
-    assert((Offset & ((1 << DS::PointerShift)-1)) == 0 &&
-           "Pointer offset not aligned correctly!");
-    unsigned Index = Offset >> DS::PointerShift;
-    assert(Index < Links.size() && "Link index is out of range!");
-    return Links[Index];
+    assert(Offset < Links.size() && "Link index is out of range!");
+    return Links[Offset];
   }
   const DSNodeHandle &getLink(unsigned Offset) const {
-    assert((Offset & ((1 << DS::PointerShift)-1)) == 0 &&
-           "Pointer offset not aligned correctly!");
-    unsigned Index = Offset >> DS::PointerShift;
-    assert(Index < Links.size() && "Link index is out of range!");
-    return Links[Index];
+    assert(Offset < Links.size() && "Link index is out of range!");
+    return Links[Offset];
   }
 
   /// getNumLinks - Return the number of links in a node...
@@ -264,17 +255,10 @@
   /// instead one of the higher level methods should be used, below.
   ///
   void setLink(unsigned Offset, const DSNodeHandle &NH) {
-    assert((Offset & ((1 << DS::PointerShift)-1)) == 0 &&
-           "Pointer offset not aligned correctly!");
-    unsigned Index = Offset >> DS::PointerShift;
-    assert(Index < Links.size() && "Link index is out of range!");
-    Links[Index] = NH;
+    assert(Offset < Links.size() && "Link index is out of range!");
+    Links[Offset] = NH;
   }
 
-  /// getPointerSize - Return the size of a pointer for the current target.
-  ///
-  unsigned getPointerSize() const { return DS::PointerSize; }
-
   /// addEdgeTo - Add an edge from the current node to the specified node.  This
   /// can cause merging of nodes in the graph.
   ///

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

==============================================================================
--- poolalloc/trunk/include/dsa/DSSupport.h (original)
+++ poolalloc/trunk/include/dsa/DSSupport.h Thu Feb 18 18:08:04 2010
@@ -30,16 +30,10 @@
 class DSGraph;                 // A graph for a function
 class ReachabilityCloner;
 
-namespace DS { // FIXME: After the paper, this should get cleaned up
-  enum { PointerShift = 2,     // 64bit ptrs = 3, 32 bit ptrs = 2
-         PointerSize = 1 << PointerShift
-  };
-
   /// isPointerType - Return true if this first class type is big enough to hold
   /// a pointer.
   ///
   bool isPointerType(const Type *Ty);
-}
 
 //===----------------------------------------------------------------------===//
 /// DSNodeHandle - Implement a "handle" to a data structure node that takes care

Propchange: poolalloc/trunk/lib/DSA/

------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Feb 18 18:08:04 2010
@@ -0,0 +1 @@
+.dep.inc

Modified: poolalloc/trunk/lib/DSA/DataStructure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/DataStructure.cpp?rev=96630&r1=96629&r2=96630&view=diff

==============================================================================
--- poolalloc/trunk/lib/DSA/DataStructure.cpp (original)
+++ poolalloc/trunk/lib/DSA/DataStructure.cpp Thu Feb 18 18:08:04 2010
@@ -53,25 +53,6 @@
                 cl::init(256));
 }
 
-#if 0
-#define TIME_REGION(VARNAME, DESC) \
-   NamedRegionTimer VARNAME(DESC)
-#else
-#define TIME_REGION(VARNAME, DESC)
-#endif
-
-using namespace DS;
-
-//
-// Function: DS::isPointerType()
-//
-// Description:
-//  This returns whether the given type is a pointer.
-//
-bool DS::isPointerType(const Type *Ty) {
-  return isa<llvm::PointerType>(Ty);
-}
-
 /// isForwarding - Return true if this NodeHandle is forwarding to another
 /// one.
 bool DSNodeHandle::isForwarding() const {
@@ -587,7 +568,7 @@
     // If this node would have to have an unreasonable number of fields, just
     // collapse it.  This can occur for fortran common blocks, which have stupid
     // things like { [100000000 x double], [1000000 x double] }.
-    unsigned NumFields = (NewTySize+DS::PointerSize-1) >> DS::PointerShift;
+    unsigned NumFields = NewTySize;
     if (NumFields > DSAFieldLimit) {
       foldNodeCompletely();
       return true;
@@ -615,7 +596,7 @@
     // If this node would have to have an unreasonable number of fields, just
     // collapse it.  This can occur for fortran common blocks, which have stupid
     // things like { [100000000 x double], [1000000 x double] }.
-    unsigned NumFields = (NewTySize+Offset+DS::PointerSize-1) >> DS::PointerShift;
+    unsigned NumFields = NewTySize+Offset;
     if (NumFields > DSAFieldLimit) {
       foldNodeCompletely();
       return true;
@@ -1010,7 +991,7 @@
   // Make all of the outgoing links of N now be outgoing links of CurNodeH.
   //
   for (unsigned i = 0; i < N->getNumLinks(); ++i) {
-    DSNodeHandle &Link = N->getLink(i << DS::PointerShift);
+    DSNodeHandle &Link = N->getLink(i);
     if (Link.getNode()) {
       // Compute the offset into the current node at which to
       // merge this link.  In the common case, this is a linear
@@ -1021,7 +1002,7 @@
       unsigned MergeOffset = 0;
       DSNode *CN = CurNodeH.getNode();
       if (CN->Size != 1)
-        MergeOffset = ((i << DS::PointerShift)+NOffset) % CN->getSize();
+        MergeOffset = (i+NOffset) % CN->getSize();
       CN->addEdgeTo(MergeOffset, Link);
     }
   }
@@ -1148,7 +1129,7 @@
   // reason, we must always go through NH.
   DN = 0;
   for (unsigned i = 0, e = SN->getNumLinks(); i != e; ++i) {
-    const DSNodeHandle &SrcEdge = SN->getLink(i << DS::PointerShift);
+    const DSNodeHandle &SrcEdge = SN->getLink(i);
     if (!SrcEdge.isNull()) {
       const DSNodeHandle &DestEdge = getClonedNH(SrcEdge);
       // Compute the offset into the current node at which to
@@ -1160,7 +1141,7 @@
       unsigned MergeOffset = 0;
       DSNode *CN = NH.getNode();
       if (CN->getSize() != 1)
-        MergeOffset = ((i << DS::PointerShift)+NH.getOffset()) % CN->getSize();
+        MergeOffset = (i + NH.getOffset()) % CN->getSize();
       CN->addEdgeTo(MergeOffset, DestEdge);
     }
   }
@@ -1354,7 +1335,7 @@
   // For this reason, we must always go through NH.
   DN = 0;
   for (unsigned i = 0, e = SN->getNumLinks(); i != e; ++i) {
-    const DSNodeHandle &SrcEdge = SN->getLink(i << DS::PointerShift);
+    const DSNodeHandle &SrcEdge = SN->getLink(i);
     if (!SrcEdge.isNull()) {
       // Compute the offset into the current node at which to
       // merge this link.  In the common case, this is a linear
@@ -1364,7 +1345,7 @@
       // links at offset zero.
       DSNode *CN = SCNH.getNode();
       unsigned MergeOffset =
-        ((i << DS::PointerShift)+SCNH.getOffset()) % CN->getSize();
+        (i+SCNH.getOffset()) % CN->getSize();
 
       DSNodeHandle Tmp = CN->getLink(MergeOffset);
       if (!Tmp.isNull()) {
@@ -1379,7 +1360,7 @@
 
         unsigned MergeOffset = 0;
         CN = SCNH.getNode();
-        MergeOffset = ((i << DS::PointerShift)+SCNH.getOffset()) %CN->getSize();
+        MergeOffset = (i + SCNH.getOffset()) %CN->getSize();
         CN->getLink(MergeOffset).mergeWith(Tmp);
       }
     }
@@ -1586,7 +1567,6 @@
 /// The CloneFlags member controls various aspects of the cloning process.
 ///
 void DSGraph::cloneInto( DSGraph* G, unsigned CloneFlags) {
-  TIME_REGION(X, "cloneInto");
   assert(G != this && "Cannot clone graph into itself!");
 
   NodeMapTy OldNodeMap;
@@ -1831,8 +1811,6 @@
 void DSGraph::mergeInGraph(const DSCallSite &CS,
                            std::vector<DSNodeHandle> &Args,
                            const DSGraph &Graph, unsigned CloneFlags) {
-  TIME_REGION(X, "mergeInGraph");
-
   assert((CloneFlags & DontCloneCallNodes) &&
          "Doesn't support copying of call nodes!");
 
@@ -2239,8 +2217,6 @@
 // we don't have to perform any non-trivial analysis here.
 //
 void DSGraph::removeTriviallyDeadNodes(bool updateForwarders) {
-  TIME_REGION(X, "removeTriviallyDeadNodes");
-
   if (updateForwarders) {
     /// NOTE: This code is disabled.  This slows down DSA on 177.mesa
     /// substantially!
@@ -2248,26 +2224,22 @@
     // Loop over all of the nodes in the graph, calling getNode on each field.
     // This will cause all nodes to update their forwarding edges, causing
     // forwarded nodes to be delete-able.
-    { TIME_REGION(X, "removeTriviallyDeadNodes:node_iterate");
-      for (node_iterator NI = node_begin(), E = node_end(); NI != E; ++NI) {
-        DSNode &N = *NI;
-        for (unsigned l = 0, e = N.getNumLinks(); l != e; ++l)
-          N.getLink(l*N.getPointerSize()).getNode();
-      }
+    for (node_iterator NI = node_begin(), E = node_end(); NI != E; ++NI) {
+      DSNode &N = *NI;
+      for (unsigned l = 0, e = N.getNumLinks(); l != e; ++l)
+        N.getLink(l).getNode();
     }
     
     // NOTE: This code is disabled.  Though it should, in theory, allow us to
     // remove more nodes down below, the scan of the scalar map is incredibly
     // expensive for certain programs (with large SCCs).  In the future, if we can
     // make the scalar map scan more efficient, then we can reenable this.
-    { TIME_REGION(X, "removeTriviallyDeadNodes:scalarmap");
-      
-      // Likewise, forward any edges from the scalar nodes.  While we are at it,
-      // clean house a bit.
-      for (DSScalarMap::iterator I = ScalarMap.begin(),E = ScalarMap.end();I != E;){
-        I->second.getNode();
-        ++I;
-      }
+
+    // Likewise, forward any edges from the scalar nodes.  While we are at it,
+    // clean house a bit.
+    for (DSScalarMap::iterator I = ScalarMap.begin(), E = ScalarMap.end(); I != E;) {
+      I->second.getNode();
+      ++I;
     }
   }
 
@@ -2411,8 +2383,6 @@
   // merging...
   removeTriviallyDeadNodes();
 
-  TIME_REGION(X, "removeDeadNodes");
-
   // FIXME: Merge non-trivially identical call nodes...
 
   // Alive - a set that holds all nodes found to be reachable/alive.
@@ -2430,10 +2400,9 @@
                               DSGraph::StripIncompleteBit);
 
   // Mark all nodes reachable by (non-global) scalar nodes as alive...
-{ TIME_REGION(Y, "removeDeadNodes:scalarscan");
   for (DSScalarMap::iterator I = ScalarMap.begin(), E = ScalarMap.end();
-       I != E; ++I)
-    if (isa<GlobalValue>(I->first)) {             // Keep track of global nodes
+          I != E; ++I)
+    if (isa<GlobalValue > (I->first)) { // Keep track of global nodes
       assert(!I->second.isNull() && "Null global node?");
       assert(I->second.getNode()->isGlobalNode() && "Should be a global node!");
       GlobalNodes.push_back(std::make_pair(I->first, I->second.getNode()));
@@ -2450,7 +2419,6 @@
     } else {
       I->second.getNode()->markReachableNodes(Alive);
     }
-}
 
   // The return values are alive as well.
   for (ReturnNodesTy::iterator I = ReturnNodes.begin(), E = ReturnNodes.end();
@@ -2643,7 +2611,7 @@
   unsigned N2Size = N2->getSize();
   if (N2Size == 0) return;   // No edges to map to.
 
-  for (unsigned i = 0, e = N1->getSize(); i < e; i += DS::PointerSize) {
+  for (unsigned i = 0, e = N1->getSize(); i < e; ++i) {
     const DSNodeHandle &N1NH = N1->getLink(i);
     // Don't call N2->getLink if not needed (avoiding crash if N2Idx is not
     // aligned right).
@@ -2724,7 +2692,6 @@
 /// nodes reachable from them from the globals graph into the current graph.
 ///
 void DSGraph::updateFromGlobalGraph() {
-  TIME_REGION(X, "updateFromGlobalGraph");
   ReachabilityCloner RC(this, GlobalsGraph, 0);
 
   // Clone the non-up-to-date global nodes into this graph.

Modified: poolalloc/trunk/lib/DSA/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Local.cpp?rev=96630&r1=96629&r2=96630&view=diff

==============================================================================
--- poolalloc/trunk/lib/DSA/Local.cpp (original)
+++ poolalloc/trunk/lib/DSA/Local.cpp Thu Feb 18 18:08:04 2010
@@ -110,6 +110,8 @@
     void visitPtrToIntInst(PtrToIntInst &I);
     void visitBitCastInst(BitCastInst &I);
     void visitCmpInst(CmpInst &I);
+    void visitInsertValueInst(InsertValueInst& I);
+    void visitExtractValueInst(ExtractValueInst& I);
 
     //the nasty ones
     void visitGetElementPtrInst(User &GEP);
@@ -388,7 +390,31 @@
 }
 
 void GraphBuilder::visitCmpInst(CmpInst &I) {
-  //Should this merge or not?  I don't think so.
+  //Address can escape through cmps
+}
+
+void GraphBuilder::visitInsertValueInst(InsertValueInst& I) {
+  setDestTo(I, createNode()->setAllocaMarker());
+
+  const Type *StoredTy = I.getInsertedValueOperand()->getType();
+  DSNodeHandle Dest = getValueDest(I);
+  Dest.mergeWith(getValueDest(*I.getAggregateOperand()));
+
+  // Mark that the node is written to...
+  Dest.getNode()->setModifiedMarker();
+
+  // Ensure a type-record exists...
+  Dest.getNode()->mergeTypeInfo(StoredTy, 0); //FIXME: calculate offset
+  Dest.getNode()->foldNodeCompletely();
+
+  // Avoid adding edges from null, or processing non-"pointer" stores
+  if (isa<PointerType>(StoredTy))
+    Dest.addEdgeTo(getValueDest(*I.getInsertedValueOperand()));
+}
+
+void GraphBuilder::visitExtractValueInst(ExtractValueInst& I) {
+  assert(0 && "Not supported yet");
+  abort();
 }
 
 void GraphBuilder::visitGetElementPtrInst(User &GEP) {

Modified: poolalloc/trunk/lib/DSA/Printer.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/Printer.cpp?rev=96630&r1=96629&r2=96630&view=diff

==============================================================================
--- poolalloc/trunk/lib/DSA/Printer.cpp (original)
+++ poolalloc/trunk/lib/DSA/Printer.cpp Thu Feb 18 18:08:04 2010
@@ -132,13 +132,13 @@
   static bool edgeTargetsEdgeSource(const void *Node,
                                     DSNode::const_iterator I) {
     unsigned O = I.getNode()->getLink(I.getOffset()).getOffset();
-    return (O >> DS::PointerShift) != 0;
+    return O != 0;
   }
 
   static DSNode::const_iterator getEdgeTarget(const DSNode *Node,
                                               DSNode::const_iterator I) {
     unsigned O = I.getNode()->getLink(I.getOffset()).getOffset();
-    unsigned LinkNo = O >> DS::PointerShift;
+    unsigned LinkNo = O;
     const DSNode *N = *I;
     DSNode::const_iterator R = N->begin();
     for (; LinkNo; --LinkNo)
@@ -174,7 +174,7 @@
           
           // Add edge from return node to real destination
           DSNode *DestNode = I->second.getNode();
-          int EdgeDest = I->second.getOffset() >> DS::PointerShift;
+          int EdgeDest = I->second.getOffset();
           if (EdgeDest == 0) EdgeDest = -1;
           GW.emitEdge(I->first, -1, DestNode,
                       EdgeDest, "arrowtail=tee,color=gray63");
@@ -196,7 +196,7 @@
 
         // Add edge from return node to real destination
         DSNode *RetNode = I->second.getNode();
-        int RetEdgeDest = I->second.getOffset() >> DS::PointerShift;;
+        int RetEdgeDest = I->second.getOffset();
         if (RetEdgeDest == 0) RetEdgeDest = -1;
         GW.emitEdge((void*)I->first, -1, RetNode,
                     RetEdgeDest, "arrowtail=tee,color=gray63");
@@ -220,7 +220,7 @@
                         &EdgeSourceCaptions);
 
       if (DSNode *N = Call.getRetVal().getNode()) {
-        int EdgeDest = Call.getRetVal().getOffset() >> DS::PointerShift;
+        int EdgeDest = Call.getRetVal().getOffset();
         if (EdgeDest == 0) EdgeDest = -1;
         GW.emitEdge(&Call, 0, N, EdgeDest, "color=gray63,tailclip=false");
       }
@@ -234,7 +234,7 @@
 
       for (unsigned j = 0, e = Call.getNumPtrArgs(); j != e; ++j)
         if (DSNode *N = Call.getPtrArg(j).getNode()) {
-          int EdgeDest = Call.getPtrArg(j).getOffset() >> DS::PointerShift;
+          int EdgeDest = Call.getPtrArg(j).getOffset();
           if (EdgeDest == 0) EdgeDest = -1;
           GW.emitEdge(&Call, j+2, N, EdgeDest, "color=gray63,tailclip=false");
         }

Modified: poolalloc/trunk/lib/DSA/TopDownClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/TopDownClosure.cpp?rev=96630&r1=96629&r2=96630&view=diff

==============================================================================
--- poolalloc/trunk/lib/DSA/TopDownClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/TopDownClosure.cpp Thu Feb 18 18:08:04 2010
@@ -51,7 +51,7 @@
   Visited.insert(N);
 
   for (unsigned i = 0, e = N->getNumLinks(); i != e; ++i) {
-    DSNodeHandle &NH = N->getLink(i*N->getPointerSize());
+    DSNodeHandle &NH = N->getLink(i);
     if (DSNode *NN = NH.getNode()) {
       std::vector<const Function*> Functions;
       NN->addFullFunctionList(Functions);





More information about the llvm-commits mailing list