[llvm-commits] CVS: llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri Feb 25 13:02:20 PST 2005



Changes in directory llvm-poolalloc/lib/PoolAllocate:

PointerCompress.cpp updated: 1.28 -> 1.29
---
Log message:

initial support for pools that point to other pools.


---
Diffs of the changes:  (+44 -10)

 PointerCompress.cpp |   54 ++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 44 insertions(+), 10 deletions(-)


Index: llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp
diff -u llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.28 llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.29
--- llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp:1.28	Fri Feb 25 01:51:31 2005
+++ llvm-poolalloc/lib/PoolAllocate/PointerCompress.cpp	Fri Feb 25 15:02:07 2005
@@ -248,7 +248,8 @@
     return false;
   }
 
-  // If this has no pointer fields, don't compress.
+  // FIXME: If any non-type-safe nodes point to this one, we cannot compress it.
+#if 0
   bool HasFields = false;
   for (DSNode::const_edge_iterator I = N->edge_begin(), E = N->edge_end();
        I != E; ++I)
@@ -265,6 +266,7 @@
     DEBUG(std::cerr << "Node does not contain any pointers to compress:\n");
     return false;
   }
+#endif
 
   if (N->isArray()) {
     DEBUG(std::cerr << "Node is an array (not yet handled!):\n");
@@ -377,12 +379,11 @@
       EV = New;
     }
 
-    /// getNodeIfCompressed - If the specified value is a pointer that will be
-    /// compressed, return the DSNode corresponding to the pool it belongs to.
-    const DSNode *getNodeIfCompressed(Value *V) {
-      if (!isa<PointerType>(V->getType()) || isa<ConstantPointerNull>(V) ||
-          isa<Function>(V))
-        return false;
+    /// getMappedNodeHandle - Given a pointer value that may be cloned multiple
+    /// times (once for PA, once for PC) return the node handle in DSG, or a
+    /// null descriptor if the value didn't exist.
+    DSNodeHandle getMappedNodeHandle(Value *V) {
+      assert(isa<PointerType>(V->getType()) && "Not a pointer value!");
 
       // If this is a function clone, map the value to the original function.
       if (FCR)
@@ -392,9 +393,20 @@
       // function.
       if (!PAFuncInfo.NewToOldValueMap.empty())
         if ((V = PAFuncInfo.MapValueToOriginal(V)) == 0)
-          return 0; // Value didn't exist in the orig program (pool desc?)
+          // Value didn't exist in the orig program (pool desc?).
+          return DSNodeHandle();
+
+      return DSG.getNodeForValue(V);
+    }
 
-      DSNode *N = DSG.getNodeForValue(V).getNode();
+    /// getNodeIfCompressed - If the specified value is a pointer that will be
+    /// compressed, return the DSNode corresponding to the pool it belongs to.
+    const DSNode *getNodeIfCompressed(Value *V) {
+      if (!isa<PointerType>(V->getType()) || isa<ConstantPointerNull>(V) ||
+          isa<Function>(V))
+        return false;
+
+      DSNode *N = getMappedNodeHandle(V).getNode();
       return PoolInfo.count(N) ? N : 0;
     }
 
@@ -800,9 +812,15 @@
     if (FI = PtrComp.getPoolAlloc()->getFuncInfoOrClone(*Callee))
       CG = &PtrComp.getGraphForFunc(FI);
 
+  // CalleeCallerMap - Mapping from nodes in the callee to nodes in the caller.
+  DSGraph::NodeMapTy CalleeCallerMap;
+
   // Do we need to compress the return value?
-  if (isa<PointerType>(CI.getType()) && getNodeIfCompressed(&CI))
+  if (isa<PointerType>(CI.getType()) && getNodeIfCompressed(&CI)) {
+    DSGraph::computeNodeMapping(CG->getReturnNodeFor(FI->F),
+                                getMappedNodeHandle(&CI), CalleeCallerMap);
     PoolsToCompress.insert(CG->getReturnNodeFor(FI->F).getNode());
+  }
 
   // Find the arguments we need to compress.
   unsigned NumPoolArgs = FI ? FI->ArgNodes.size() : 0;
@@ -810,6 +828,11 @@
     if (isa<PointerType>(CI.getOperand(i)->getType()) &&
         getNodeIfCompressed(CI.getOperand(i))) {
       Argument *FormalArg = next(FI->F.abegin(), i-1-NumPoolArgs);
+
+      DSGraph::computeNodeMapping(CG->getNodeForValue(FormalArg),
+                                  getMappedNodeHandle(CI.getOperand(i)),
+                                  CalleeCallerMap);
+
       PoolsToCompress.insert(CG->getNodeForValue(FormalArg).getNode());
     }
 
@@ -818,6 +841,17 @@
   Function *Callee = CI.getCalledFunction();
   assert(Callee && "Indirect calls not implemented yet!");
 
+  // Now that we know the basic pools passed/returned through the
+  // argument/retval of the call, add the compressed pools that are reachable
+  // from them.  The CalleeCallerMap contains a mapping from callee nodes to the
+  // caller nodes they correspond to (a many-to-one mapping).
+  for (DSGraph::NodeMapTy::iterator I = CalleeCallerMap.begin(),
+         E = CalleeCallerMap.end(); I != E; ++I) {
+    // If the destination is compressed, so should the source be.
+    if (PoolInfo.count(I->second.getNode()))
+      PoolsToCompress.insert(I->first);
+  }
+
   // Get the clone of this function that uses compressed pointers instead of
   // normal pointers.
   Function *Clone = PtrComp.GetFunctionClone(Callee, PoolsToCompress, *FI, *CG);






More information about the llvm-commits mailing list