[llvm-commits] [llvm] r59552 - in /llvm/trunk: include/llvm/LinkAllPasses.h include/llvm/Transforms/IPO.h lib/Transforms/IPO/StripSymbols.cpp
Devang Patel
dpatel at apple.com
Tue Nov 18 13:34:39 PST 2008
Author: dpatel
Date: Tue Nov 18 15:34:39 2008
New Revision: 59552
URL: http://llvm.org/viewvc/llvm-project?rev=59552&view=rev
Log:
Add new helper pass that strips all symbol names except debugging information.
This pass makes it easier to test wheter debugging info. influences optimization passes or not.
Modified:
llvm/trunk/include/llvm/LinkAllPasses.h
llvm/trunk/include/llvm/Transforms/IPO.h
llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp
Modified: llvm/trunk/include/llvm/LinkAllPasses.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/LinkAllPasses.h?rev=59552&r1=59551&r2=59552&view=diff
==============================================================================
--- llvm/trunk/include/llvm/LinkAllPasses.h (original)
+++ llvm/trunk/include/llvm/LinkAllPasses.h Tue Nov 18 15:34:39 2008
@@ -102,6 +102,7 @@
(void) llvm::createSimplifyHalfPowrLibCallsPass();
(void) llvm::createSingleLoopExtractorPass();
(void) llvm::createStripSymbolsPass();
+ (void) llvm::createStripNonDebugSymbolsPass();
(void) llvm::createStripDeadPrototypesPass();
(void) llvm::createTailCallEliminationPass();
(void) llvm::createTailDuplicationPass();
Modified: llvm/trunk/include/llvm/Transforms/IPO.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Transforms/IPO.h?rev=59552&r1=59551&r2=59552&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Transforms/IPO.h (original)
+++ llvm/trunk/include/llvm/Transforms/IPO.h Tue Nov 18 15:34:39 2008
@@ -34,6 +34,13 @@
ModulePass *createStripSymbolsPass(bool OnlyDebugInfo = false);
//===----------------------------------------------------------------------===//
+//
+// These functions removes symbols from functions and modules.
+// Only debugging information is not removed.
+//
+ModulePass *createStripNonDebugSymbolsPass();
+
+//===----------------------------------------------------------------------===//
/// 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=59552&r1=59551&r2=59552&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/StripSymbols.cpp Tue Nov 18 15:34:39 2008
@@ -40,13 +40,18 @@
explicit StripSymbols(bool ODI = false)
: ModulePass(&ID), OnlyDebugInfo(ODI) {}
- /// StripSymbolNames - Strip symbol names.
- bool StripSymbolNames(Module &M);
+ virtual bool runOnModule(Module &M);
+
+ virtual void getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+ }
+ };
- // StripDebugInfo - Strip debug info in the module if it exists.
- // To do this, we remove llvm.dbg.func.start, llvm.dbg.stoppoint, and
- // llvm.dbg.region.end calls, and any globals they point to if now dead.
- bool StripDebugInfo(Module &M);
+ class VISIBILITY_HIDDEN StripNonDebugSymbols : public ModulePass {
+ public:
+ static char ID; // Pass identification, replacement for typeid
+ explicit StripNonDebugSymbols()
+ : ModulePass(&ID) {}
virtual bool runOnModule(Module &M);
@@ -64,6 +69,14 @@
return new StripSymbols(OnlyDebugInfo);
}
+char StripNonDebugSymbols::ID = 0;
+static RegisterPass<StripNonDebugSymbols>
+Y("strip-nondebug", "Strip all symbols, except dbg symbols, from a module");
+
+ModulePass *llvm::createStripNonDebugSymbolsPass() {
+ return new StripNonDebugSymbols();
+}
+
/// 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) {
@@ -96,28 +109,26 @@
// Strip the symbol table of its names.
//
-static void StripSymtab(ValueSymbolTable &ST) {
+static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo) {
for (ValueSymbolTable::iterator VI = ST.begin(), VE = ST.end(); VI != VE; ) {
Value *V = VI->getValue();
++VI;
if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasInternalLinkage()) {
- // Set name to "", removing from symbol table!
- V->setName("");
+ if (!PreserveDbgInfo || strncmp(V->getNameStart(), "llvm.dbg", 8))
+ // Set name to "", removing from symbol table!
+ V->setName("");
}
}
}
-bool StripSymbols::runOnModule(Module &M) {
- bool Changed = false;
- Changed |= StripDebugInfo(M);
- Changed |= StripSymbolNames(M);
- return Changed;
-}
-
// Strip the symbol table of its names.
-static void StripTypeSymtab(TypeSymbolTable &ST) {
- for (TypeSymbolTable::iterator TI = ST.begin(), E = ST.end(); TI != E; )
- ST.remove(TI++);
+static void StripTypeSymtab(TypeSymbolTable &ST, bool PreserveDbgInfo) {
+ for (TypeSymbolTable::iterator TI = ST.begin(), E = ST.end(); TI != E; ) {
+ if (PreserveDbgInfo && strncmp(TI->first.c_str(), "llvm.dbg", 8) == 0)
+ ++TI;
+ else
+ ST.remove(TI++);
+ }
}
/// Find values that are marked as llvm.used.
@@ -143,10 +154,7 @@
}
/// StripSymbolNames - Strip symbol names.
-bool StripSymbols::StripSymbolNames(Module &M) {
-
- if (OnlyDebugInfo)
- return false;
+bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {
SmallPtrSet<const GlobalValue*, 8> llvmUsedValues;
findUsedValues(M, llvmUsedValues);
@@ -154,17 +162,19 @@
for (Module::global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
- I->setName(""); // Internal symbols can't participate in linkage
+ if (!PreserveDbgInfo || strncmp(I->getNameStart(), "llvm.dbg", 8))
+ I->setName(""); // Internal symbols can't participate in linkage
}
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0)
- I->setName(""); // Internal symbols can't participate in linkage
- StripSymtab(I->getValueSymbolTable());
+ if (!PreserveDbgInfo || strncmp(I->getNameStart(), "llvm.dbg", 8))
+ I->setName(""); // Internal symbols can't participate in linkage
+ StripSymtab(I->getValueSymbolTable(), PreserveDbgInfo);
}
// Remove all names from types.
- StripTypeSymtab(M.getTypeSymbolTable());
+ StripTypeSymtab(M.getTypeSymbolTable(), PreserveDbgInfo);
return true;
}
@@ -172,7 +182,7 @@
// StripDebugInfo - Strip debug info in the module if it exists.
// To do this, we remove llvm.dbg.func.start, llvm.dbg.stoppoint, and
// llvm.dbg.region.end calls, and any globals they point to if now dead.
-bool StripSymbols::StripDebugInfo(Module &M) {
+bool StripDebugInfo(Module &M) {
Function *FuncStart = M.getFunction("llvm.dbg.func.start");
Function *StopPoint = M.getFunction("llvm.dbg.stoppoint");
@@ -302,3 +312,16 @@
return true;
}
+
+bool StripSymbols::runOnModule(Module &M) {
+ bool Changed = false;
+ Changed |= StripDebugInfo(M);
+ if (!OnlyDebugInfo)
+ Changed |= StripSymbolNames(M, false);
+ return Changed;
+}
+
+bool StripNonDebugSymbols::runOnModule(Module &M) {
+ return StripSymbolNames(M, true);
+}
+
More information about the llvm-commits
mailing list