[llvm-commits] CVS: llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp

Chris Lattner lattner at cs.uiuc.edu
Tue Mar 15 09:14:22 PST 2005



Changes in directory llvm/lib/Analysis/DataStructure:

EquivClassGraphs.cpp updated: 1.29 -> 1.30
---
Log message:

Finally fix (the right way) the problem where functions like this:

void foo() {
  G = 1;
}

would have an empty DSGraph even though G (a global) is directly used
in the function.


---
Diffs of the changes:  (+24 -0)

 EquivClassGraphs.cpp |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+)


Index: llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp
diff -u llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp:1.29 llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp:1.30
--- llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp:1.29	Tue Mar 15 10:55:04 2005
+++ llvm/lib/Analysis/DataStructure/EquivClassGraphs.cpp	Tue Mar 15 11:14:09 2005
@@ -16,6 +16,7 @@
 
 #define DEBUG_TYPE "ECGraphs"
 #include "llvm/Analysis/DataStructure/EquivClassGraphs.h"
+#include "llvm/DerivedTypes.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
 #include "llvm/Analysis/DataStructure/DSGraph.h"
@@ -123,6 +124,29 @@
                                   DSGraph::IgnoreGlobals);
   }
 
+  // Final processing.  Note that dead node elimination may actually remove
+  // globals from a function graph that are immediately used.  If there are no
+  // scalars pointing to the node (e.g. because the only use is a direct store
+  // to a scalar global) we have to make sure to rematerialize the globals back
+  // into the graphs here, or clients will break!
+  for (Module::global_iterator GI = M.global_begin(), E = M.global_end();
+       GI != E; ++GI)
+    // This only happens to first class typed globals.
+    if (GI->getType()->getElementType()->isFirstClassType())
+      for (Value::use_iterator UI = GI->use_begin(), E = GI->use_end();
+           UI != E; ++UI)
+        // This only happens to direct uses by instructions.
+        if (Instruction *User = dyn_cast<Instruction>(*UI)) {
+          DSGraph &DSG = getOrCreateGraph(*User->getParent()->getParent());
+          if (!DSG.getScalarMap().count(GI)) {
+            // If this global does not exist in the graph, but it is immediately
+            // used by an instruction in the graph, clone it over from the
+            // globals graph.
+            ReachabilityCloner RC(DSG, *GlobalsGraph, 0);
+            RC.getClonedNH(GlobalsGraph->getNodeForValue(GI));
+          }
+        }
+
   return false;
 }
 






More information about the llvm-commits mailing list