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)
328 bool GlobalVariableChange =
false;
329 for (
auto *DIG : DIC->getGlobalVariables()) {
330 if (DIG->getExpression() && DIG->getExpression()->isConstant())
334 if (!VisitedSet.
insert(DIG).second)
338 if (LiveGVs.count(DIG))
341 GlobalVariableChange =
true;
346 if (GlobalVariableChange) {
347 DIC->replaceGlobalVariables(
MDTuple::get(C, LiveGlobalVariables));
352 LiveGlobalVariables.
clear();
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)
static bool StripSymbolNames(Module &M, bool PreserveDbgInfo)
StripSymbolNames - Strip symbol names.
Implements a dense probed hash-table based set.
unsigned getNumOperands() const
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()
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.
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.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
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.
Value * stripPointerCasts()
Strip off pointer casts, all-zero GEPs, and aliases.
static GCRegistry::Add< ShadowStackGC > C("shadow-stack","Very portable GC for uncooperative code generators")
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)
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)
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.
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.