• Home
  • Raw
  • Download

Lines Matching +full:llvm +full:- +full:strip

1 //===- StripSymbols.cpp - Strip symbols and debug info from a module ------===//
3 // The LLVM Compiler Infrastructure
8 //===----------------------------------------------------------------------===//
18 // only be used in situations where the 'strip' utility would be used, such as
21 //===----------------------------------------------------------------------===//
23 #include "llvm/Transforms/IPO.h"
24 #include "llvm/ADT/SmallPtrSet.h"
25 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DebugInfo.h"
27 #include "llvm/IR/DerivedTypes.h"
28 #include "llvm/IR/Instructions.h"
29 #include "llvm/IR/Module.h"
30 #include "llvm/IR/TypeFinder.h"
31 #include "llvm/IR/ValueSymbolTable.h"
32 #include "llvm/Pass.h"
33 #include "llvm/Transforms/Utils/Local.h"
34 using namespace llvm;
100 INITIALIZE_PASS(StripSymbols, "strip",
101 "Strip all symbols from a module", false, false)
103 ModulePass *llvm::createStripSymbolsPass(bool OnlyDebugInfo) { in createStripSymbolsPass()
108 INITIALIZE_PASS(StripNonDebugSymbols, "strip-nondebug",
109 "Strip all symbols, except dbg symbols, from a module",
112 ModulePass *llvm::createStripNonDebugSymbolsPass() { in createStripNonDebugSymbolsPass()
117 INITIALIZE_PASS(StripDebugDeclare, "strip-debug-declare",
118 "Strip all llvm.dbg.declare intrinsics", false, false)
120 ModulePass *llvm::createStripDebugDeclarePass() { in createStripDebugDeclarePass()
125 INITIALIZE_PASS(StripDeadDebugInfo, "strip-dead-debug-info",
126 "Strip debug info for unused symbols", false, false)
128 ModulePass *llvm::createStripDeadDebugInfoPass() { in createStripDeadDebugInfoPass()
132 /// OnlyUsedBy - Return true if V is only used by Usr.
134 for (User *U : V->users()) in OnlyUsedBy()
142 assert(C->use_empty() && "Constant is not dead!"); in RemoveDeadConstant()
144 for (Value *Op : C->operands()) in RemoveDeadConstant()
148 if (!GV->hasLocalLinkage()) return; // Don't delete non-static globals. in RemoveDeadConstant()
149 GV->eraseFromParent(); in RemoveDeadConstant()
152 if (isa<CompositeType>(C->getType())) in RemoveDeadConstant()
153 C->destroyConstant(); in RemoveDeadConstant()
160 // Strip the symbol table of its names.
164 Value *V = VI->getValue(); in StripSymtab()
166 if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) { in StripSymtab()
167 if (!PreserveDbgInfo || !V->getName().startswith("llvm.dbg")) in StripSymtab()
169 V->setName(""); in StripSymtab()
174 // Strip any named types of their names.
181 if (STy->isLiteral() || STy->getName().empty()) continue; in StripTypeNames()
183 if (PreserveDbgInfo && STy->getName().startswith("llvm.dbg")) in StripTypeNames()
186 STy->setName(""); in StripTypeNames()
190 /// Find values that are marked as llvm.used.
196 ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer()); in findUsedValues()
198 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i) in findUsedValues()
200 dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts())) in findUsedValues()
204 /// StripSymbolNames - Strip symbol names.
208 findUsedValues(M.getGlobalVariable("llvm.used"), llvmUsedValues); in StripSymbolNames()
209 findUsedValues(M.getGlobalVariable("llvm.compiler.used"), llvmUsedValues); in StripSymbolNames()
213 if (I->hasLocalLinkage() && llvmUsedValues.count(&*I) == 0) in StripSymbolNames()
214 if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg")) in StripSymbolNames()
215 I->setName(""); // Internal symbols can't participate in linkage in StripSymbolNames()
220 if (!PreserveDbgInfo || !I.getName().startswith("llvm.dbg")) in StripSymbolNames()
253 Function *Declare = M.getFunction("llvm.dbg.declare"); in runOnModule()
257 while (!Declare->use_empty()) { in runOnModule()
258 CallInst *CI = cast<CallInst>(Declare->user_back()); in runOnModule()
259 Value *Arg1 = CI->getArgOperand(0); in runOnModule()
260 Value *Arg2 = CI->getArgOperand(1); in runOnModule()
261 assert(CI->use_empty() && "llvm.dbg intrinsic should have void result"); in runOnModule()
262 CI->eraseFromParent(); in runOnModule()
263 if (Arg1->use_empty()) { in runOnModule()
269 if (Arg2->use_empty()) in runOnModule()
273 Declare->eraseFromParent(); in runOnModule()
280 if (GV->hasLocalLinkage()) in runOnModule()
292 /// Debugging information is encoded in llvm IR using metadata. This is designed
327 for (DIGlobalVariable *DIG : DIC->getGlobalVariables()) { in runOnModule()
334 if (DIG->getVariable()) in runOnModule()
343 DIC->replaceGlobalVariables(MDTuple::get(C, LiveGlobalVariables)); in runOnModule()