[llvm-branch-commits] [llvm-branch] r82239 - in /llvm/branches/Apple/Bender-SWB: include/llvm/Transforms/Utils/Local.h lib/Transforms/IPO/ConstantMerge.cpp lib/Transforms/IPO/GlobalDCE.cpp lib/Transforms/IPO/GlobalOpt.cpp lib/Transforms/Utils/Local.cpp

Bill Wendling isanbard at gmail.com
Fri Sep 18 11:23:29 PDT 2009


Author: void
Date: Fri Sep 18 13:23:28 2009
New Revision: 82239

URL: http://llvm.org/viewvc/llvm-project?rev=82239&view=rev
Log:
Candidate patch for <rdar://problem/6824456>.

Modified:
    llvm/branches/Apple/Bender-SWB/include/llvm/Transforms/Utils/Local.h
    llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/ConstantMerge.cpp
    llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalDCE.cpp
    llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalOpt.cpp
    llvm/branches/Apple/Bender-SWB/lib/Transforms/Utils/Local.cpp

Modified: llvm/branches/Apple/Bender-SWB/include/llvm/Transforms/Utils/Local.h
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender-SWB/include/llvm/Transforms/Utils/Local.h?rev=82239&r1=82238&r2=82239&view=diff

==============================================================================
--- llvm/branches/Apple/Bender-SWB/include/llvm/Transforms/Utils/Local.h (original)
+++ llvm/branches/Apple/Bender-SWB/include/llvm/Transforms/Utils/Local.h Fri Sep 18 13:23:28 2009
@@ -22,6 +22,7 @@
 class Instruction;
 class Value;
 class Pass;
+class GlobalVariable;
 class PHINode;
 class AllocaInst;
 class ConstantExpr;
@@ -109,6 +110,10 @@
 /// RemoveDbgInfoUser - Remove an User which is representing debug info.
 void RemoveDbgInfoUser(User *U);
 
+/// IsGlobalVariableDebugInfo - Return true if GV is encoding debug info
+/// for a global variable.
+bool IsGlobalVariableDebugInfo(GlobalVariable *GV);
+
 } // End llvm namespace
 
 #endif

Modified: llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/ConstantMerge.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/ConstantMerge.cpp?rev=82239&r1=82238&r2=82239&view=diff

==============================================================================
--- llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/ConstantMerge.cpp (original)
+++ llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/ConstantMerge.cpp Fri Sep 18 13:23:28 2009
@@ -21,6 +21,7 @@
 #include "llvm/Transforms/IPO.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
+#include "llvm/Transforms/Utils/Local.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/Compiler.h"
 #include <map>
@@ -70,9 +71,11 @@
          GVI != E; ) {
       GlobalVariable *GV = GVI++;
       
-      // If this GV is dead, remove it.
-      GV->removeDeadConstantUsers();
-      if (GV->use_empty() && GV->hasLocalLinkage()) {
+      // If this GV is dead, remove it. Skip llvm.dbg.global_variable.
+      if (!IsGlobalVariableDebugInfo(GV))
+	GV->removeDeadConstantUsers();
+      if (!IsGlobalVariableDebugInfo(GV) && GV->use_empty() 
+	  && GV->hasLocalLinkage()) {
         GV->eraseFromParent();
         continue;
       }

Modified: llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalDCE.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalDCE.cpp?rev=82239&r1=82238&r2=82239&view=diff

==============================================================================
--- llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalDCE.cpp (original)
+++ llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalDCE.cpp Fri Sep 18 13:23:28 2009
@@ -20,6 +20,7 @@
 #include "llvm/Constants.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
+#include "llvm/Transforms/Utils/Local.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Support/Compiler.h"
 #include <set>
@@ -71,6 +72,10 @@
   for (Module::global_iterator I = M.global_begin(), E = M.global_end();
        I != E; ++I) {
     Changed |= RemoveUnusedGlobalValue(*I);
+    // Do not remove llvm.dbg.global_variable.
+    if (GlobalVariable *GV = dyn_cast<GlobalVariable>(I))
+      if (IsGlobalVariableDebugInfo(GV))
+	GlobalIsNeeded(I);
     // Externally visible & appending globals are needed, if they have an
     // initializer.
     if (!I->hasLocalLinkage() && !I->hasLinkOnceLinkage() &&

Modified: llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalOpt.cpp?rev=82239&r1=82238&r2=82239&view=diff

==============================================================================
--- llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/branches/Apple/Bender-SWB/lib/Transforms/IPO/GlobalOpt.cpp Fri Sep 18 13:23:28 2009
@@ -22,6 +22,7 @@
 #include "llvm/IntrinsicInst.h"
 #include "llvm/Module.h"
 #include "llvm/Pass.h"
+#include "llvm/Transforms/Utils/Local.h"
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Support/CallSite.h"
@@ -143,11 +144,22 @@
 static bool ConstantIsDead(Constant *C) {
   if (isa<GlobalValue>(C)) return false;
 
-  for (Value::use_iterator UI = C->use_begin(), E = C->use_end(); UI != E; ++UI)
+  for (Value::use_iterator UI = C->use_begin(), E = C->use_end(); UI != E; ) {
+    // Remove llvm.dbg.global_variable.
+    if (GlobalVariable *UGV = dyn_cast<GlobalVariable>(*UI)) {
+      if (IsGlobalVariableDebugInfo(UGV)) {
+	++UI;
+	if (UGV->use_empty())
+	  UGV->eraseFromParent();
+	continue;
+      }
+    }
     if (Constant *CU = dyn_cast<Constant>(*UI)) {
       if (!ConstantIsDead(CU)) return false;
     } else
       return false;
+    ++UI;
+  }
   return true;
 }
 
@@ -1538,13 +1550,21 @@
   if (GVElType == Type::Int1Ty || GVElType->isFloatingPoint() ||
       isa<PointerType>(GVElType) || isa<VectorType>(GVElType))
     return false;
-  
+
   // Walk the use list of the global seeing if all the uses are load or store.
   // If there is anything else, bail out.
-  for (Value::use_iterator I = GV->use_begin(), E = GV->use_end(); I != E; ++I)
+  for (Value::use_iterator I = GV->use_begin(), E = GV->use_end(); I != E; ) {
+    if (Constant *CC = dyn_cast<Constant>(*I))
+      if (ConstantIsDead(CC)) {
+	++I;
+        CC->destroyConstant();	
+	continue;
+      }
     if (!isa<LoadInst>(I) && !isa<StoreInst>(I))
       return false;
-  
+    ++I;
+  }
+
   DOUT << "   *** SHRINKING TO BOOL: " << *GV;
   
   // Create the new global, initializing it to false.

Modified: llvm/branches/Apple/Bender-SWB/lib/Transforms/Utils/Local.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Bender-SWB/lib/Transforms/Utils/Local.cpp?rev=82239&r1=82238&r2=82239&view=diff

==============================================================================
--- llvm/branches/Apple/Bender-SWB/lib/Transforms/Utils/Local.cpp (original)
+++ llvm/branches/Apple/Bender-SWB/lib/Transforms/Utils/Local.cpp Fri Sep 18 13:23:28 2009
@@ -317,3 +317,10 @@
   }
   CE->destroyConstant();
 }
+
+/// IsGlobalVariableDebugInfo - Return true if GV is encoding debug info
+/// for a global variable.
+bool llvm::IsGlobalVariableDebugInfo(GlobalVariable *GV) {
+  return GV->hasName() && 
+    strncmp(GV->getNameStart(), "llvm.dbg.global_variable", 24) == 0;
+}





More information about the llvm-branch-commits mailing list