42 explicit StripSymbols(
bool ODI =
false)
47 virtual bool runOnModule(
Module &M);
54 class StripNonDebugSymbols :
public ModulePass {
57 explicit StripNonDebugSymbols()
62 virtual bool runOnModule(
Module &M);
72 explicit StripDebugDeclare()
77 virtual bool runOnModule(
Module &M);
87 explicit StripDeadDebugInfo()
92 virtual bool runOnModule(
Module &M);
102 "Strip all symbols from a module",
false,
false)
105 return new StripSymbols(OnlyDebugInfo);
110 "Strip all symbols, except dbg symbols, from a module",
114 return new StripNonDebugSymbols();
119 "Strip all llvm.dbg.declare intrinsics",
false,
false)
122 return new StripDebugDeclare();
127 "Strip debug info for unused symbols",
false,
false)
130 return new StripDeadDebugInfo();
144 assert(C->
use_empty() &&
"Constant is not dead!");
150 if (!GV->hasLocalLinkage())
return;
151 GV->eraseFromParent();
153 else if (!isa<Function>(C))
154 if (isa<CompositeType>(C->
getType()))
159 OE = Operands.end(); OI != OE; ++OI)
167 Value *V = VI->getValue();
169 if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
180 StructTypes.
run(M,
false);
182 for (
unsigned i = 0, e = StructTypes.
size(); i != e; ++i) {
196 if (LLVMUsed == 0)
return;
197 UsedValues.
insert(LLVMUsed);
216 if (
I->hasLocalLinkage() && llvmUsedValues.
count(
I) == 0)
217 if (!PreserveDbgInfo || !
I->getName().startswith(
"llvm.dbg"))
222 if (
I->hasLocalLinkage() && llvmUsedValues.
count(
I) == 0)
223 if (!PreserveDbgInfo || !
I->getName().startswith(
"llvm.dbg"))
239 bool Changed =
false;
244 while (!Declare->use_empty()) {
245 CallInst *CI = cast<CallInst>(Declare->use_back());
248 Declare->eraseFromParent();
253 while (!DbgVal->use_empty()) {
254 CallInst *CI = cast<CallInst>(DbgVal->use_back());
257 DbgVal->eraseFromParent();
276 if (!BI->getDebugLoc().isUnknown()) {
285 bool StripSymbols::runOnModule(
Module &M) {
286 bool Changed =
false;
293 bool StripNonDebugSymbols::runOnModule(
Module &M) {
297 bool StripDebugDeclare::runOnModule(
Module &M) {
300 std::vector<Constant*> DeadConstants;
307 assert(CI->
use_empty() &&
"llvm.dbg intrinsic should have void result");
309 if (Arg1->use_empty()) {
310 if (
Constant *
C = dyn_cast<Constant>(Arg1))
311 DeadConstants.push_back(
C);
316 if (
Constant *
C = dyn_cast<Constant>(Arg2))
317 DeadConstants.push_back(
C);
322 while (!DeadConstants.empty()) {
324 DeadConstants.pop_back();
326 if (GV->hasLocalLinkage())
342 bool StripDeadDebugInfo::runOnModule(
Module &M) {
343 bool Changed =
false;
365 assert(DIC.Verify() &&
"DIC must verify as a DICompileUnit.");
368 DIArray SPs = DIC.getSubprograms();
369 bool SubprogramChange =
false;
370 for (
unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
372 assert(DISP.Verify() &&
"DISP must verify as a DISubprogram.");
375 if (!VisitedSet.
insert(DISP).second)
379 if (DISP.getFunction())
382 SubprogramChange =
true;
386 DIArray GVs = DIC.getGlobalVariables();
387 bool GlobalVariableChange =
false;
390 assert(DIG.Verify() &&
"DIG must verify as DIGlobalVariable.");
393 if (!VisitedSet.
insert(DIG).second)
401 GlobalVariableChange =
true;
407 if (SubprogramChange) {
412 assert(DIC->getNumOperands() >= 10 &&
413 SPs == DIC->getOperand(9) &&
414 "DICompileUnits is expected to store Subprograms in operand "
416 DIC->replaceOperandWith(9,
MDNode::get(C, LiveSubprograms));
420 if (GlobalVariableChange) {
425 assert(DIC->getNumOperands() >= 11 &&
426 GVs == DIC->getOperand(10) &&
427 "DICompileUnits is expected to store Global Variables in operand "
429 DIC->replaceOperandWith(10,
MDNode::get(C, LiveGlobalVariables));
434 LiveSubprograms.
clear();
435 LiveGlobalVariables.
clear();
StringRef getName() const
getName - Return a constant reference to this named metadata's name.
void push_back(const T &Elt)
static PassRegistry * getPassRegistry()
iterator begin()
Get an iterator that from the beginning of the symbol table.
void initializeStripDeadDebugInfoPass(PassRegistry &)
The main container class for the LLVM Intermediate Representation.
static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo)
static bool StripSymbolNames(Module &M, bool PreserveDbgInfo)
StripSymbolNames - Strip symbol names.
unsigned getNumOperands() const
static bool StripDebugInfo(Module &M)
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=0)
named_metadata_iterator named_metadata_end()
const Constant * getInitializer() const
const GlobalVariable * getGlobalVariable(StringRef Name, bool AllowInternal=false) const
void processModule(const Module &M)
processModule - Process entire module and collect debug info.
iterator compile_unit_begin() const
static MDNode * get(LLVMContext &Context, ArrayRef< Value * > Vals)
ModulePass * createStripNonDebugSymbolsPass()
StringRef getName() const
DIArray - This descriptor holds an array of descriptors.
void initializeStripSymbolsPass(PassRegistry &)
ModulePass * createStripDeadDebugInfoPass()
void setName(const Twine &Name)
ID
LLVM Calling Convention Representation.
global_iterator global_begin()
DISubprogram - This is a wrapper for a subprogram (e.g. a function).
void initializeStripNonDebugSymbolsPass(PassRegistry &)
bool count(PtrType Ptr) const
count - Return true if the specified pointer is in the set.
static bool OnlyUsedBy(Value *V, Value *Usr)
OnlyUsedBy - Return true if V is only used by Usr.
static void RemoveDeadConstant(Constant *C)
iterator end()
Get an iterator to the end of the symbol table.
Function * getFunction(StringRef Name) const
DIDescriptor getElement(unsigned Idx) const
LLVM Constant Representation.
DIGlobalVariable - This is a wrapper for a global variable.
Value * getOperand(unsigned i) const
unsigned getNumElements() const
ModulePass * createStripDebugDeclarePass()
global_iterator global_end()
SmallPtrSetIterator - This implements a const_iterator for SmallPtrSet.
std::pair< iterator, bool > insert(const ValueT &V)
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
void run(const Module &M, bool onlyNamed)
Value * stripPointerCasts()
Strips off any unneeded pointer casts, all-zero GEPs and aliases from the specified value...
iterator compile_unit_end() const
Value * getArgOperand(unsigned i) const
virtual void destroyConstant()
StringRef getName() const
INITIALIZE_PASS(StripSymbols,"strip","Strip all symbols from a module", false, false) ModulePass *llvm
void setName(StringRef Name)
static void StripTypeNames(Module &M, bool PreserveDbgInfo)
virtual void eraseFromParent()
NamedMDListType::iterator named_metadata_iterator
The named metadata iterators.
void initializeStripDebugDeclarePass(PassRegistry &)
LLVM Value Representation.
ModulePass * createStripSymbolsPass(bool OnlyDebugInfo=false)
static void findUsedValues(GlobalVariable *LLVMUsed, SmallPtrSet< const GlobalValue *, 8 > &UsedValues)
Find values that are marked as llvm.used.
DICompileUnit - A wrapper for a compile unit.
named_metadata_iterator named_metadata_begin()
LLVMContext & getContext() const
bool empty() const
empty - Check if the string is empty.