42 explicit StripSymbols(
bool ODI =
false)
47 bool runOnModule(
Module &M)
override;
54 class StripNonDebugSymbols :
public ModulePass {
57 explicit StripNonDebugSymbols()
62 bool runOnModule(
Module &M)
override;
72 explicit StripDebugDeclare()
77 bool runOnModule(
Module &M)
override;
87 explicit StripDeadDebugInfo()
92 bool runOnModule(
Module &M)
override;
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();
143 assert(C->
use_empty() &&
"Constant is not dead!");
147 Operands.insert(cast<Constant>(Op));
149 if (!GV->hasLocalLinkage())
return;
150 GV->eraseFromParent();
152 else if (!isa<Function>(C))
153 if (isa<CompositeType>(C->
getType()))
167 if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
178 StructTypes.
run(M,
false);
180 for (
unsigned i = 0, e = StructTypes.
size(); i != e; ++i) {
194 if (!LLVMUsed)
return;
195 UsedValues.
insert(LLVMUsed);
214 if (
I->hasLocalLinkage() && llvmUsedValues.
count(
I) == 0)
215 if (!PreserveDbgInfo || !
I->getName().startswith(
"llvm.dbg"))
220 if (
I->hasLocalLinkage() && llvmUsedValues.
count(
I) == 0)
221 if (!PreserveDbgInfo || !
I->getName().startswith(
"llvm.dbg"))
232 bool StripSymbols::runOnModule(
Module &M) {
233 bool Changed =
false;
240 bool StripNonDebugSymbols::runOnModule(
Module &M) {
244 bool StripDebugDeclare::runOnModule(
Module &M) {
247 std::vector<Constant*> DeadConstants;
254 assert(CI->
use_empty() &&
"llvm.dbg intrinsic should have void result");
256 if (Arg1->use_empty()) {
257 if (
Constant *C = dyn_cast<Constant>(Arg1))
263 if (
Constant *C = dyn_cast<Constant>(Arg2))
264 DeadConstants.push_back(C);
269 while (!DeadConstants.empty()) {
271 DeadConstants.pop_back();
273 if (GV->hasLocalLinkage())
289 bool StripDeadDebugInfo::runOnModule(
Module &M) {
290 bool Changed =
false;
310 bool SubprogramChange =
false;
313 if (!VisitedSet.
insert(DISP).second)
317 if (DISP->getFunction())
320 SubprogramChange =
true;
324 bool GlobalVariableChange =
false;
327 if (!VisitedSet.
insert(DIG).second)
332 if (DIG->getVariable())
335 GlobalVariableChange =
true;
341 if (SubprogramChange) {
342 DIC->replaceSubprograms(
MDTuple::get(C, LiveSubprograms));
346 if (GlobalVariableChange) {
347 DIC->replaceGlobalVariables(
MDTuple::get(C, LiveGlobalVariables));
352 LiveSubprograms.
clear();
353 LiveGlobalVariables.
clear();
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
void push_back(const T &Elt)
This class provides a symbol table of name/value pairs.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
iterator begin()
Get an iterator that from the beginning of the symbol table.
void initializeStripDeadDebugInfoPass(PassRegistry &)
A Module instance is used to store all the information related to an LLVM module. ...
static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo)
static bool StripSymbolNames(Module &M, bool PreserveDbgInfo)
StripSymbolNames - Strip symbol names.
DenseSet - This implements a dense probed hash-table based set.
unsigned getNumOperands() const
CallInst - This class represents a function call, abstracting a target machine's calling convention...
size_type count(PtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
void processModule(const Module &M)
Process entire module and collect debug info anchors.
ModulePass * createStripNonDebugSymbolsPass()
StringRef getName() const
Return a constant reference to the value's name.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
void initializeStripSymbolsPass(PassRegistry &)
ModulePass * createStripDeadDebugInfoPass()
void push_back(NodeTy *val)
StructType - Class to represent struct types.
bool isLiteral() const
isLiteral - Return true if this type is uniqued by structural equivalence, false if it is a struct de...
Utility to find all debug info in a module.
void setName(const Twine &Name)
Change the name of the value.
global_iterator global_begin()
void initializeStripNonDebugSymbolsPass(PassRegistry &)
static bool OnlyUsedBy(Value *V, Value *Usr)
OnlyUsedBy - Return true if V is only used by Usr.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
static void RemoveDeadConstant(Constant *C)
iterator_range< compile_unit_iterator > compile_units() const
iterator end()
Get an iterator to the end of the symbol table.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
This is an important class for using LLVM in a threaded context.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
This is an important base class in LLVM.
This file contains the declarations for the subclasses of Constant, which represent the different fla...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
Represent the analysis usage information of a pass.
Value * getOperand(unsigned i) const
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr)
RecursivelyDeleteTriviallyDeadInstructions - If the specified value is a trivially dead instruction...
ModulePass * createStripDebugDeclarePass()
global_iterator global_end()
std::pair< iterator, bool > insert(const ValueT &V)
bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
void run(const Module &M, bool onlyNamed)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Type * getType() const
All values are typed, get the type of this value.
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
ConstantArray - Constant Array Declarations.
StringRef getName() const
getName - Return the name for this struct type if it has an identity.
void setPreservesAll()
Set by analyses that do not transform their input at all.
iterator_range< user_iterator > users()
void eraseFromParent() override
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
INITIALIZE_PASS(StripSymbols,"strip","Strip all symbols from a module", false, false) ModulePass *llvm
void setName(StringRef Name)
setName - Change the name of this type to the specified name, or to a name with a suffix if there is ...
static void StripTypeNames(Module &M, bool PreserveDbgInfo)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
void destroyConstant()
Called if some element of this constant is no longer valid.
static void findUsedValues(GlobalVariable *LLVMUsed, SmallPtrSetImpl< const GlobalValue * > &UsedValues)
Find values that are marked as llvm.used.
void initializeStripDebugDeclarePass(PassRegistry &)
LLVM Value Representation.
ModulePass * createStripSymbolsPass(bool OnlyDebugInfo=false)
C - The default llvm calling convention, compatible with C.
TypeFinder - Walk over a module, identifying all of the types that are used by the module...
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
LLVMContext & getContext() const
Get the global data context.
bool empty() const
empty - Check if the string is empty.