summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-06-28 22:10:58 +0000
committerChris Lattner <sabre@nondot.org>2003-06-28 22:10:58 +0000
commitc7ba69d8b440c040abc3f8df444c583e612f527e (patch)
treed6931ddeef6724ff9b947f133419154ab43ae6d3 /llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp
parent856a6cbb8081b9a99443cd51a65050b90906590a (diff)
downloadbcm5719-llvm-c7ba69d8b440c040abc3f8df444c583e612f527e.tar.gz
bcm5719-llvm-c7ba69d8b440c040abc3f8df444c583e612f527e.zip
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 llvm-svn: 6946
Diffstat (limited to 'llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp')
-rw-r--r--llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp17
1 files changed, 16 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp b/llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp
index ad5b8947edc..297979a72a0 100644
--- a/llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp
+++ b/llvm/lib/Analysis/DataStructure/DataStructureOpt.cpp
@@ -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 @@ bool DSOpt::OptimizeGlobals(Module &M) {
// 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.
OpenPOWER on IntegriCloud