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

Chris Lattner lattner at cs.uiuc.edu
Sat Jun 28 17:12:01 PDT 2003


Changes in directory llvm/lib/Analysis/DataStructure:

DataStructureOpt.cpp updated: 1.1 -> 1.2

---
Log message:

Drop references to globals who do exist in the globals graph, but are never
read or written to.  Keep track of how many times this happens.  This should
be good for deleting things like references to type information in C++ classes



---
Diffs of the changes:

Index: llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp
diff -u llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp:1.1 llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp:1.2
--- llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp:1.1	Sat Jun 28 16:54:55 2003
+++ llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp	Sat Jun 28 17:10:58 2003
@@ -14,6 +14,8 @@
 namespace {
   Statistic<>
   NumGlobalsConstanted("ds-opt", "Number of globals marked constant");
+  Statistic<>
+  NumGlobalsIsolated("ds-opt", "Number of globals with references dropped");
 
   class DSOpt : public Pass {
     TDDataStructures *TD;
@@ -60,8 +62,21 @@
         // can delete it.  We don't ACTUALLY want to delete the global, just
         // remove anything that references the global: later passes will take
         // care of nuking it.
-        I->replaceAllUsesWith(Constant::getNullValue((Type*)I->getType()));
+        if (!I->use_empty()) {
+          I->replaceAllUsesWith(Constant::getNullValue((Type*)I->getType()));
+          ++NumGlobalsIsolated;
+        }
       } else if (GNode && GNode->isComplete()) {
+
+        // If the node has not been read or written, and it is not externally
+        // visible, kill any references to it so it can be DCE'd.
+        if (!GNode->isModified() && !GNode->isRead() &&I->hasInternalLinkage()){
+          if (!I->use_empty()) {
+            I->replaceAllUsesWith(Constant::getNullValue((Type*)I->getType()));
+            ++NumGlobalsIsolated;
+          }
+        }
+
         // We expect that there will almost always be a node for this global.
         // If there is, and the node doesn't have the M bit set, we can set the
         // 'constant' bit on the global.





More information about the llvm-commits mailing list