41 explicit StripSymbols(
bool ODI =
false)
46 bool runOnModule(
Module &M)
override;
53 class StripNonDebugSymbols :
public ModulePass {
56 explicit StripNonDebugSymbols()
61 bool runOnModule(
Module &M)
override;
71 explicit StripDebugDeclare()
76 bool runOnModule(
Module &M)
override;
86 explicit StripDeadDebugInfo()
91 bool runOnModule(
Module &M)
override;
101 "Strip all symbols from a module",
false,
false)
104 return new StripSymbols(OnlyDebugInfo);
109 "Strip all symbols, except dbg symbols, from a module",
113 return new StripNonDebugSymbols();
118 "Strip all llvm.dbg.declare intrinsics",
false,
false)
121 return new StripDebugDeclare();
126 "Strip debug info for unused symbols",
false,
false)
129 return new StripDeadDebugInfo();
146 Operands.
insert(cast<Constant>(
Op));
148 if (!GV->hasLocalLinkage())
return;
149 GV->eraseFromParent();
151 else if (!isa<Function>(C))
152 if (isa<CompositeType>(C->
getType()))
166 if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
177 StructTypes.
run(M,
false);
179 for (
unsigned i = 0, e = StructTypes.
size(); i != e; ++i) {
193 if (!LLVMUsed)
return;
194 UsedValues.
insert(LLVMUsed);
213 if (
I->hasLocalLinkage() && llvmUsedValues.
count(&*
I) == 0)
214 if (!PreserveDbgInfo || !
I->getName().startswith(
"llvm.dbg"))
219 if (
I.hasLocalLinkage() && llvmUsedValues.
count(&
I) == 0)
220 if (!PreserveDbgInfo || !
I.getName().startswith(
"llvm.dbg"))
222 if (
auto *Symtab =
I.getValueSymbolTable())
232 bool StripSymbols::runOnModule(
Module &M) {
236 bool Changed =
false;
243 bool StripNonDebugSymbols::runOnModule(
Module &M) {
250 bool StripDebugDeclare::runOnModule(
Module &M) {
255 std::vector<Constant*> DeadConstants;
262 assert(CI->
use_empty() &&
"llvm.dbg intrinsic should have void result");
264 if (Arg1->use_empty()) {
265 if (
Constant *
C = dyn_cast<Constant>(Arg1))
271 if (
Constant *
C = dyn_cast<Constant>(Arg2))
272 DeadConstants.push_back(
C);
277 while (!DeadConstants.empty()) {
279 DeadConstants.pop_back();
281 if (GV->hasLocalLinkage())
297 bool StripDeadDebugInfo::runOnModule(
Module &M) {
301 bool Changed =
false;
318 std::set<DIGlobalVariableExpression *> LiveGVs;
321 GV.getDebugInfo(GVEs);
322 for (
auto *GVE : GVEs)
326 std::set<DICompileUnit *> LiveCUs;
330 LiveCUs.insert(
SP->getUnit());
333 bool HasDeadCUs =
false;
336 bool GlobalVariableChange =
false;
337 for (
auto *DIG : DIC->getGlobalVariables()) {
338 if (DIG->getExpression() && DIG->getExpression()->isConstant())
342 if (!VisitedSet.
insert(DIG).second)
346 if (LiveGVs.count(DIG))
349 GlobalVariableChange =
true;
352 if (!LiveGlobalVariables.
empty())
354 else if (!LiveCUs.count(DIC))
359 if (GlobalVariableChange) {
360 DIC->replaceGlobalVariables(
MDTuple::get(C, LiveGlobalVariables));
365 LiveGlobalVariables.
clear();
372 if (!LiveCUs.empty()) {
SymbolTableList< Instruction >::iterator 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)
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs, and aliases.
void clearOperands()
Drop all references to this node's operands.
static bool StripSymbolNames(Module &M, bool PreserveDbgInfo)
StripSymbolNames - Strip symbol names.
Implements a dense probed hash-table based set.
unsigned getNumOperands() const
void addOperand(MDNode *M)
This class represents a function call, abstracting a target machine's calling convention.
NamedMDNode * getOrInsertNamedMetadata(StringRef Name)
Return the named MDNode in the module with the specified name.
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()
Class to represent struct types.
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition...
Utility to find all debug info in a module.
void setName(const Twine &Name)
Change the name of the value.
LLVM_NODISCARD bool empty() const
global_iterator global_begin()
void initializeStripNonDebugSymbolsPass(PassRegistry &)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
iterator_range< subprogram_iterator > subprograms() const
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(const ValueT &V)
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)
If the specified value is a trivially dead instruction, delete it.
ModulePass * createStripDebugDeclarePass()
global_iterator global_end()
Iterator for intrusive lists based on ilist_node.
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.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
Value * getArgOperand(unsigned i) const
getArgOperand/setArgOperand - Return/set the i-th call argument.
ConstantArray - Constant Array Declarations.
void push_back(pointer val)
StringRef getName() const
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()
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool empty() const
empty - Check if the string is empty.
iterator insert(iterator I, T &&Elt)
INITIALIZE_PASS(StripSymbols,"strip","Strip all symbols from a module", false, false) ModulePass *llvm
void setName(StringRef Name)
Change the name of this type to the specified name, or to a name with a suffix if there is a collisio...
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.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it...
static void findUsedValues(GlobalVariable *LLVMUsed, SmallPtrSetImpl< const GlobalValue * > &UsedValues)
Find values that are marked as llvm.used.
void initializeStripDebugDeclarePass(PassRegistry &)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
LLVM Value Representation.
ModulePass * createStripSymbolsPass(bool OnlyDebugInfo=false)
iterator_range< global_iterator > globals()
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.