[llvm-commits] [poolalloc] r109644 - in /poolalloc/trunk: include/poolalloc/PoolAllocate.h lib/DSA/TopDownClosure.cpp lib/PoolAllocate/PASimple.cpp

John Criswell criswell at uiuc.edu
Wed Jul 28 13:14:37 PDT 2010


Author: criswell
Date: Wed Jul 28 15:14:37 2010
New Revision: 109644

URL: http://llvm.org/viewvc/llvm-project?rev=109644&view=rev
Log:
TopDownClosure.cpp:
Modified code so that it doesn't remove dead global nodes from the local graph.
This is important because it allows SAFECode to correctly find alignment of
the results of load instructions when the dereferenced pointer is a global.

include/poolalloc/PoolAllocate.h:
lib/PoolAllocate/PASimple.cpp:
Be more like DSA; use a separate globals graph.
Renamed function to be more descriptive.
Added comments.


Modified:
    poolalloc/trunk/include/poolalloc/PoolAllocate.h
    poolalloc/trunk/lib/DSA/TopDownClosure.cpp
    poolalloc/trunk/lib/PoolAllocate/PASimple.cpp

Modified: poolalloc/trunk/include/poolalloc/PoolAllocate.h
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/include/poolalloc/PoolAllocate.h?rev=109644&r1=109643&r2=109644&view=diff
==============================================================================
--- poolalloc/trunk/include/poolalloc/PoolAllocate.h (original)
+++ poolalloc/trunk/include/poolalloc/PoolAllocate.h Wed Jul 28 15:14:37 2010
@@ -30,6 +30,7 @@
 #include "llvm/Support/CommandLine.h"
 
 #include "dsa/DataStructure.h"
+#include "dsa/DSGraph.h"
 #include "poolalloc/Config/config.h"
 
 #include <utility>
@@ -526,7 +527,7 @@
   }
 
   virtual DSGraph* getGlobalsGraph () const {
-    return CombinedDSGraph;
+    return CombinedDSGraph->getGlobalsGraph();
   }
 
   virtual Value * getGlobalPool (const DSNode * Node) {

Modified: poolalloc/trunk/lib/DSA/TopDownClosure.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/DSA/TopDownClosure.cpp?rev=109644&r1=109643&r2=109644&view=diff
==============================================================================
--- poolalloc/trunk/lib/DSA/TopDownClosure.cpp (original)
+++ poolalloc/trunk/lib/DSA/TopDownClosure.cpp Wed Jul 28 15:14:37 2010
@@ -276,8 +276,24 @@
   Flags |= DSGraph::IgnoreGlobals | DSGraph::MarkVAStart;
   DSG->markIncompleteNodes(Flags);
 
+  //
   // Delete dead nodes.  Treat globals that are unreachable as dead also.
+  //
+  // FIXME:
+  //  Do not delete unreachable globals as the comment describes.  For its
+  //  alignment checks on the results of load instructions, SAFECode must be
+  //  able to find the DSNode of both the result of the load as well as the
+  //  pointer dereferenced by the load.  If we remove unreachable globals, then
+  //  if the dereferenced pointer is a global, its DSNode will not reachable
+  //  from the local graph's scalar map, and chaos ensues.
+  //
+  //  So, for now, just remove dead nodes but leave the globals alone.
+  //
+#if 0
   DSG->removeDeadNodes(DSGraph::RemoveUnreachableGlobals);
+#else
+  DSG->removeDeadNodes(0);
+#endif
 
   // We are done with computing the current TD Graph!  Finally, before we can
   // finish processing this function, we figure out which functions it calls and

Modified: poolalloc/trunk/lib/PoolAllocate/PASimple.cpp
URL: http://llvm.org/viewvc/llvm-project/poolalloc/trunk/lib/PoolAllocate/PASimple.cpp?rev=109644&r1=109643&r2=109644&view=diff
==============================================================================
--- poolalloc/trunk/lib/PoolAllocate/PASimple.cpp (original)
+++ poolalloc/trunk/lib/PoolAllocate/PASimple.cpp Wed Jul 28 15:14:37 2010
@@ -84,10 +84,21 @@
   AU.setPreservesAll();
 }
 
+//
+// Function: FoldNodesInDSGraph()
+//
+// Description:
+//  This function will take the specified DSGraph and fold all DSNodes within
+//  it that are marked with the heap flag.
+//
 static void
-MergeNodesInDSGraph (DSGraph & Graph) {
+FoldNodesInDSGraph (DSGraph & Graph) {
+  // Worklist of heap nodes to process
   std::vector<DSNodeHandle> HeapNodes;
 
+  //
+  // Go find all of the heap nodes.
+  //
   DSGraph::node_iterator i;
   DSGraph::node_iterator e = Graph.node_end();
   for (i = Graph.node_begin(); i != e; ++i) {
@@ -96,6 +107,9 @@
       HeapNodes.push_back (DSNodeHandle(Node));
   }
 
+  //
+  // Fold all of the heap nodes; this makes them type-unknown.
+  //
   for (unsigned i = 0; i < HeapNodes.size(); ++i)
     HeapNodes[i].getNode()->foldNodeCompletely();
   return;
@@ -124,17 +138,27 @@
   AddPoolPrototypes(&M);
 
   //
-  // Merge all of the DSNodes in the DSGraphs.
+  // Create a single DSGraph which contains all of the information found in all
+  // the DSGraphs we got from DSA.  We do this because we're going to start
+  // making modifications to the points-to results.
   //
   GlobalECs = Graphs->getGlobalECs();
-  CombinedDSGraph = new DSGraph (GlobalECs, TD, Graphs->getTypeSS(), Graphs->getGlobalsGraph());
-  //CombinedDSGraph.cloneInto (getGlobalsGraph());
+  CombinedDSGraph = new DSGraph (GlobalECs,
+                                 TD,
+                                 Graphs->getTypeSS(),
+                                 Graphs->getGlobalsGraph());
   for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
     if (Graphs->hasDSGraph (*I))
       CombinedDSGraph->cloneInto (Graphs->getDSGraph(*I));
   }
-  CombinedDSGraph->cloneInto (Graphs->getGlobalsGraph());
-  MergeNodesInDSGraph (*CombinedDSGraph);
+
+  //
+  // Now fold all of the heap nodes in our DSGraph (i.e., make them
+  // type-unknown).  We do this because heap nodes may change type if we
+  // consider the effects of dangling pointers.
+  //
+  FoldNodesInDSGraph (*CombinedDSGraph);
+  FoldNodesInDSGraph (*(CombinedDSGraph->getGlobalsGraph()));
 
   //
   // Create the global pool.
@@ -177,10 +201,9 @@
   FunctionInfo.insert (std::make_pair(&F, FInfo));
 
   //
-  // Get the DSGraph for this function.
+  // Scan through all instructions in the function and modify call sites as
+  // necessary.
   //
-  DSGraph* ECG = Graphs->getDSGraph(F);
-
   for (Function::iterator i = F.begin(), e = F.end(); i != e; ++i) {
     for (BasicBlock::iterator ii = i->begin(), ee = i->end(); ii != ee; ++ii) {
       if (CallInst * CI = dyn_cast<CallInst>(ii)) {
@@ -201,7 +224,7 @@
         //
         if (CF && (CF->isDeclaration()) && (CF->getName() == "malloc")) {
           // Associate the global pool decriptor with the DSNode
-          DSNode * Node = ECG->getNodeForValue(CI).getNode();
+          DSNode * Node = CombinedDSGraph->getNodeForValue(CI).getNode();
           FInfo.PoolDescriptors.insert(std::make_pair(Node,TheGlobalPool));
 
           // Mark the call to malloc as an instruction to delete
@@ -248,7 +271,7 @@
           CI->replaceAllUsesWith(Casted);
         } else if (CF && (CF->isDeclaration()) && (CF->getName() == "realloc")) {
           // Associate the global pool decriptor with the DSNode
-          DSNode * Node = ECG->getNodeForValue(CI).getNode();
+          DSNode * Node = CombinedDSGraph->getNodeForValue(CI).getNode();
           FInfo.PoolDescriptors.insert(std::make_pair(Node,TheGlobalPool));
 
           // Mark the realloc as an instruction to delete
@@ -294,7 +317,7 @@
           CI->replaceAllUsesWith(Casted);
         } else if (CF && (CF->isDeclaration()) && (CF->getName() == "calloc")) {
           // Associate the global pool decriptor with the DSNode
-          DSNode * Node = ECG->getNodeForValue(CI).getNode();
+          DSNode * Node = CombinedDSGraph->getNodeForValue(CI).getNode();
           FInfo.PoolDescriptors.insert(std::make_pair(Node,TheGlobalPool));
 
           // Mark the realloc as an instruction to delete
@@ -341,7 +364,7 @@
           CI->replaceAllUsesWith(Casted);
         } else if (CF && (CF->isDeclaration()) && (CF->getName() == "strdup")) {
           // Associate the global pool decriptor with the DSNode
-          DSNode * Node = ECG->getNodeForValue(CI).getNode();
+          DSNode * Node = CombinedDSGraph->getNodeForValue(CI).getNode();
           FInfo.PoolDescriptors.insert(std::make_pair(Node,TheGlobalPool));
 
           // Mark the realloc as an instruction to delete





More information about the llvm-commits mailing list