[llvm-commits] [llvm] r66454 - in /llvm/trunk: include/llvm/Transforms/IPO.h lib/Transforms/IPO/StripSymbols.cpp

Devang Patel dpatel at apple.com
Mon Mar 9 13:49:38 PDT 2009


Author: dpatel
Date: Mon Mar  9 15:49:37 2009
New Revision: 66454

URL: http://llvm.org/viewvc/llvm-project?rev=66454&view=rev
Log:
Add helper pass to remove llvm.dbg.declare intrinsics.

Modified:
    llvm/trunk/include/llvm/Transforms/IPO.h
    llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp

Modified: llvm/trunk/include/llvm/Transforms/IPO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO.h?rev=66454&r1=66453&r2=66454&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO.h Mon Mar  9 15:49:37 2009
@@ -35,12 +35,17 @@
 
 //===----------------------------------------------------------------------===//
 //
-// These functions removes symbols from functions and modules.  
-// Only debugging information is not removed.
+// These functions strips symbols from functions and modules.  
+// Only debugging information is not stripped.
 //
 ModulePass *createStripNonDebugSymbolsPass();
 
 //===----------------------------------------------------------------------===//
+//
+// These pass removes llvm.dbg.declare intrinsics.
+ModulePass *createStripDebugDeclarePass();
+
+//===----------------------------------------------------------------------===//
 /// createLowerSetJmpPass - This function lowers the setjmp/longjmp intrinsics
 /// to invoke/unwind instructions.  This should really be part of the C/C++
 /// front-end, but it's so much easier to write transformations in LLVM proper.

Modified: llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp?rev=66454&r1=66453&r2=66454&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp Mon Mar  9 15:49:37 2009
@@ -60,6 +60,19 @@
       AU.setPreservesAll();
     }
   };
+
+  class VISIBILITY_HIDDEN StripDebugDeclare : public ModulePass {
+  public:
+    static char ID; // Pass identification, replacement for typeid
+    explicit StripDebugDeclare()
+      : ModulePass(&ID) {}
+
+    virtual bool runOnModule(Module &M);
+
+    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+      AU.setPreservesAll();
+    }
+  };
 }
 
 char StripSymbols::ID = 0;
@@ -78,6 +91,14 @@
   return new StripNonDebugSymbols();
 }
 
+char StripDebugDeclare::ID = 0;
+static RegisterPass<StripDebugDeclare>
+Z("strip-debug-declare", "Strip all llvm.dbg.declare intrinsics");
+
+ModulePass *llvm::createStripDebugDeclarePass() {
+  return new StripDebugDeclare();
+}
+
 /// OnlyUsedBy - Return true if V is only used by Usr.
 static bool OnlyUsedBy(Value *V, Value *Usr) {
   for(Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
@@ -343,3 +364,44 @@
 bool StripNonDebugSymbols::runOnModule(Module &M) {
   return StripSymbolNames(M, true);
 }
+
+bool StripDebugDeclare::runOnModule(Module &M) {
+
+  Function *Declare = M.getFunction("llvm.dbg.declare");
+
+  if (!Declare) 
+    return false;
+
+  std::vector<Constant*> DeadConstants;
+
+  while (!Declare->use_empty()) {
+    CallInst *CI = cast<CallInst>(Declare->use_back());
+    Value *Arg1 = CI->getOperand(1);
+    Value *Arg2 = CI->getOperand(2);
+    assert(CI->use_empty() && "llvm.dbg intrinsic should have void result");
+    CI->eraseFromParent();
+    if (Arg1->use_empty()) {
+      if (Constant *C = dyn_cast<Constant>(Arg1)) 
+        DeadConstants.push_back(C);
+      else 
+        RecursivelyDeleteTriviallyDeadInstructions(Arg1, NULL);
+    }
+    if (Arg2->use_empty())
+      if (Constant *C = dyn_cast<Constant>(Arg2)) 
+        DeadConstants.push_back(C);
+  }
+  Declare->eraseFromParent();
+
+  while (!DeadConstants.empty()) {
+    Constant *C = DeadConstants.back();
+    DeadConstants.pop_back();
+    if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
+      if (GV->hasLocalLinkage())
+        RemoveDeadConstant(GV);
+    }
+    else
+      RemoveDeadConstant(C);
+  }
+
+  return true;
+}





More information about the llvm-commits mailing list