diff options
author | Devang Patel <dpatel@apple.com> | 2008-11-18 21:13:41 +0000 |
---|---|---|
committer | Devang Patel <dpatel@apple.com> | 2008-11-18 21:13:41 +0000 |
commit | 2d53e2dfbd990f43ef083bf5bcee4e5c24a56a20 (patch) | |
tree | 4bc8ab28ce36e7f8222dc67653d9447ec9345cda /lib/Transforms/IPO | |
parent | ea8d78c8e9c4bc0ca6bf957daa9cf5e3bbbe8bd4 (diff) | |
download | external_llvm-2d53e2dfbd990f43ef083bf5bcee4e5c24a56a20.zip external_llvm-2d53e2dfbd990f43ef083bf5bcee4e5c24a56a20.tar.gz external_llvm-2d53e2dfbd990f43ef083bf5bcee4e5c24a56a20.tar.bz2 |
Remove even more llvm.dbg variables.
Remove all dead globals from llvm.metadata.
Ignore linkonce linkage for selected llvm.dbg values.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@59547 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/IPO')
-rw-r--r-- | lib/Transforms/IPO/StripSymbols.cpp | 83 |
1 files changed, 50 insertions, 33 deletions
diff --git a/lib/Transforms/IPO/StripSymbols.cpp b/lib/Transforms/IPO/StripSymbols.cpp index a073cce..d25e758 100644 --- a/lib/Transforms/IPO/StripSymbols.cpp +++ b/lib/Transforms/IPO/StripSymbols.cpp @@ -114,20 +114,15 @@ bool StripSymbols::runOnModule(Module &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++); } -/// StripSymbolNames - Strip symbol names. -bool StripSymbols::StripSymbolNames(Module &M) { - - if (OnlyDebugInfo) - return false; - - SmallPtrSet<const GlobalValue*, 8> llvmUsedValues; +/// Find values that are marked as llvm.used. +void findUsedValues(Module &M, + SmallPtrSet<const GlobalValue*, 8>& llvmUsedValues) { if (GlobalVariable *LLVMUsed = M.getGlobalVariable("llvm.used")) { llvmUsedValues.insert(LLVMUsed); // Collect values that are preserved as per explicit request. @@ -145,7 +140,17 @@ bool StripSymbols::StripSymbolNames(Module &M) { } } } - +} + +/// StripSymbolNames - Strip symbol names. +bool StripSymbols::StripSymbolNames(Module &M) { + + if (OnlyDebugInfo) + return false; + + SmallPtrSet<const GlobalValue*, 8> llvmUsedValues; + findUsedValues(M, llvmUsedValues); + for (Module::global_iterator I = M.global_begin(), E = M.global_end(); I != E; ++I) { if (I->hasInternalLinkage() && llvmUsedValues.count(I) == 0) @@ -175,7 +180,7 @@ bool StripSymbols::StripDebugInfo(Module &M) { Function *RegionEnd = M.getFunction("llvm.dbg.region.end"); Function *Declare = M.getFunction("llvm.dbg.declare"); - std::vector<GlobalVariable*> DeadGlobals; + std::vector<Constant*> DeadConstants; // Remove all of the calls to the debugger intrinsics, and remove them from // the module. @@ -186,8 +191,8 @@ bool StripSymbols::StripDebugInfo(Module &M) { assert(CI->use_empty() && "llvm.dbg intrinsic should have void result"); CI->eraseFromParent(); if (Arg->use_empty()) - if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Arg)) - DeadGlobals.push_back(GV); + if (Constant *C = dyn_cast<Constant>(Arg)) + DeadConstants.push_back(C); } FuncStart->eraseFromParent(); } @@ -198,8 +203,8 @@ bool StripSymbols::StripDebugInfo(Module &M) { assert(CI->use_empty() && "llvm.dbg intrinsic should have void result"); CI->eraseFromParent(); if (Arg->use_empty()) - if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Arg)) - DeadGlobals.push_back(GV); + if (Constant *C = dyn_cast<Constant>(Arg)) + DeadConstants.push_back(C); } StopPoint->eraseFromParent(); } @@ -210,8 +215,8 @@ bool StripSymbols::StripDebugInfo(Module &M) { assert(CI->use_empty() && "llvm.dbg intrinsic should have void result"); CI->eraseFromParent(); if (Arg->use_empty()) - if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Arg)) - DeadGlobals.push_back(GV); + if (Constant *C = dyn_cast<Constant>(Arg)) + DeadConstants.push_back(C); } RegionStart->eraseFromParent(); } @@ -222,8 +227,8 @@ bool StripSymbols::StripDebugInfo(Module &M) { assert(CI->use_empty() && "llvm.dbg intrinsic should have void result"); CI->eraseFromParent(); if (Arg->use_empty()) - if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Arg)) - DeadGlobals.push_back(GV); + if (Constant *C = dyn_cast<Constant>(Arg)) + DeadConstants.push_back(C); } RegionEnd->eraseFromParent(); } @@ -234,12 +239,15 @@ bool StripSymbols::StripDebugInfo(Module &M) { assert(CI->use_empty() && "llvm.dbg intrinsic should have void result"); CI->eraseFromParent(); if (Arg->use_empty()) - if (GlobalVariable *GV = dyn_cast<GlobalVariable>(Arg)) - DeadGlobals.push_back(GV); + if (Constant *C = dyn_cast<GlobalVariable>(Arg)) + DeadConstants.push_back(C); } Declare->eraseFromParent(); } + SmallPtrSet<const GlobalValue*, 8> llvmUsedValues; + findUsedValues(M, llvmUsedValues); + // llvm.dbg.compile_units and llvm.dbg.subprograms are marked as linkonce // but since we are removing all debug information, make them internal now. if (Constant *C = M.getNamedGlobal("llvm.dbg.compile_units")) @@ -249,29 +257,38 @@ bool StripSymbols::StripDebugInfo(Module &M) { if (Constant *C = M.getNamedGlobal("llvm.dbg.subprograms")) if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) GV->setLinkage(GlobalValue::InternalLinkage); + + if (Constant *C = M.getNamedGlobal("llvm.dbg.global_variables")) + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) + GV->setLinkage(GlobalValue::InternalLinkage); // Delete all dbg variables. const Type *DbgVTy = M.getTypeByName("llvm.dbg.variable.type"); const Type *DbgGVTy = M.getTypeByName("llvm.dbg.global_variable.type"); if (DbgVTy || DbgGVTy) for (Module::global_iterator I = M.global_begin(), E = M.global_end(); - I != E; ++I) - if (GlobalVariable *GV = dyn_cast<GlobalVariable>(I)) - if (GV->hasName() && GV->use_empty() - && !strncmp(GV->getNameStart(), "llvm.dbg", 8) - && (GV->getType()->getElementType() == DbgVTy - || GV->getType()->getElementType() == DbgGVTy)) - DeadGlobals.push_back(GV); + I != E; ++I) { + GlobalVariable *GV = dyn_cast<GlobalVariable>(I); + if (!GV) continue; + if (GV->use_empty() && llvmUsedValues.count(I) == 0 + && (!GV->hasSection() + || strcmp(GV->getSection().c_str(), "llvm.metadata") == 0)) + DeadConstants.push_back(GV); + } - if (DeadGlobals.empty()) + if (DeadConstants.empty()) return false; // Delete any internal globals that were only used by the debugger intrinsics. - while (!DeadGlobals.empty()) { - GlobalVariable *GV = DeadGlobals.back(); - DeadGlobals.pop_back(); - if (GV->hasInternalLinkage()) - RemoveDeadConstant(GV); + while (!DeadConstants.empty()) { + Constant *C = DeadConstants.back(); + DeadConstants.pop_back(); + if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) { + if (GV->hasInternalLinkage()) + RemoveDeadConstant(GV); + } + else + RemoveDeadConstant(C); } // Remove all llvm.dbg types. |