OSDN Git Service

in addition to merging, constantmerge should also delete trivially dead globals,
authorChris Lattner <sabre@nondot.org>
Sat, 14 Apr 2007 01:11:54 +0000 (01:11 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 14 Apr 2007 01:11:54 +0000 (01:11 +0000)
in order to clean up after simplifylibcalls.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35982 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/IPO/ConstantMerge.cpp

index 11ec09a..fc142e1 100644 (file)
@@ -61,7 +61,13 @@ bool ConstantMerge::runOnModule(Module &M) {
     // invalidating the Constant* pointers in CMap.
     //
     for (Module::global_iterator GV = M.global_begin(), E = M.global_end();
-         GV != E; ++GV)
+         GV != E; ++GV) {
+      // If this GV is dead, remove it.
+      GV->removeDeadConstantUsers();
+      if (GV->use_empty() && GV->hasInternalLinkage()) {
+        (GV++)->eraseFromParent();
+      }
+      
       // Only process constants with initializers.
       if (GV->isConstant() && GV->hasInitializer()) {
         Constant *Init = GV->getInitializer();
@@ -80,6 +86,7 @@ bool ConstantMerge::runOnModule(Module &M) {
           Slot = GV;
         }
       }
+    }
 
     if (Replacements.empty())
       return MadeChange;