44 explicit StripSymbols(
bool ODI =
false)
49 bool runOnModule(
Module &M)
override;
56 class StripNonDebugSymbols :
public ModulePass {
59 explicit StripNonDebugSymbols()
64 bool runOnModule(
Module &M)
override;
74 explicit StripDebugDeclare()
79 bool runOnModule(
Module &M)
override;
89 explicit StripDeadDebugInfo()
94 bool runOnModule(
Module &M)
override;
104 "Strip all symbols from a module",
false,
false)
107 return new StripSymbols(OnlyDebugInfo);
112 "Strip all symbols, except dbg symbols, from a module",
116 return new StripNonDebugSymbols();
121 "Strip all llvm.dbg.declare intrinsics",
false,
false)
124 return new StripDebugDeclare();
129 "Strip debug info for unused symbols",
false,
false)
132 return new StripDeadDebugInfo();
151 if (!GV->hasLocalLinkage())
return;
152 GV->eraseFromParent();
153 }
else if (!isa<Function>(
C)) {
157 C->destroyConstant();
171 if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
182 StructTypes.
run(M,
false);
184 for (
unsigned i = 0,
e = StructTypes.
size(); i !=
e; ++i) {
198 if (!LLVMUsed)
return;
199 UsedValues.
insert(LLVMUsed);
214 findUsedValues(M.getGlobalVariable(
"llvm.compiler.used"), llvmUsedValues);
218 if (
I->hasLocalLinkage() && llvmUsedValues.
count(&*
I) == 0)
219 if (!PreserveDbgInfo || !
I->getName().startswith(
"llvm.dbg"))
224 if (
I.hasLocalLinkage() && llvmUsedValues.
count(&
I) == 0)
225 if (!PreserveDbgInfo || !
I.getName().startswith(
"llvm.dbg"))
227 if (
auto *Symtab =
I.getValueSymbolTable())
237 bool StripSymbols::runOnModule(
Module &M) {
241 bool Changed =
false;
248 bool StripNonDebugSymbols::runOnModule(
Module &M) {
257 Function *Declare = M.getFunction(
"llvm.dbg.declare");
258 std::vector<Constant*> DeadConstants;
265 assert(CI->
use_empty() &&
"llvm.dbg intrinsic should have void result");
267 if (Arg1->use_empty()) {
268 if (
Constant *
C = dyn_cast<Constant>(Arg1))
274 if (
Constant *
C = dyn_cast<Constant>(Arg2))
275 DeadConstants.push_back(
C);
280 while (!DeadConstants.empty()) {
282 DeadConstants.pop_back();
284 if (GV->hasLocalLinkage())
293 bool StripDebugDeclare::runOnModule(
Module &M) {
300 bool Changed =
false;
317 std::set<DIGlobalVariableExpression *> LiveGVs;
320 GV.getDebugInfo(GVEs);
321 for (
auto *GVE : GVEs)
325 std::set<DICompileUnit *> LiveCUs;
329 LiveCUs.insert(SP->getUnit());
332 bool HasDeadCUs =
false;
335 bool GlobalVariableChange =
false;
336 for (
auto *DIG : DIC->getGlobalVariables()) {
337 if (DIG->getExpression() && DIG->getExpression()->isConstant())
341 if (!VisitedSet.
insert(DIG).second)
345 if (LiveGVs.count(DIG))
348 GlobalVariableChange =
true;
351 if (!LiveGlobalVariables.
empty())
353 else if (!LiveCUs.count(DIC))
358 if (GlobalVariableChange) {
359 DIC->replaceGlobalVariables(
MDTuple::get(
C, LiveGlobalVariables));
364 LiveGlobalVariables.
clear();
369 NamedMDNode *NMD = M.getOrInsertNamedMetadata(
"llvm.dbg.cu");
371 if (!LiveCUs.empty()) {
388 bool StripDeadDebugInfo::runOnModule(
Module &M) {
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
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...
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
void initializeStripDeadDebugInfoPass(PassRegistry &)
This class represents lattice values for constants.
A Module instance is used to store all the information related to an LLVM module.
LLVM_NODISCARD bool empty() const
static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo)
void clearOperands()
Drop all references to this node's operands.
static bool StripSymbolNames(Module &M, bool PreserveDbgInfo)
StripSymbolNames - Strip symbol names.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Implements a dense probed hash-table based set.
void push_back(const T &Elt)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
void addOperand(MDNode *M)
This class represents a function call, abstracting a target machine's calling convention.
ModulePass * createStripNonDebugSymbolsPass()
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
Value * getArgOperand(unsigned i) const
void initializeStripSymbolsPass(PassRegistry &)
ModulePass * createStripDeadDebugInfoPass()
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Class to represent struct types.
Utility to find all debug info in a module.
void setName(const Twine &Name)
Change the name of the value.
mir Rename Register Operands
LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
void initializeStripNonDebugSymbolsPass(PassRegistry &)
Type * getType() const
All values are typed, get the type of this value.
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)
Value * getOperand(unsigned i) const
A set of analyses that are preserved following a run of a transformation pass.
This is an important class for using LLVM in a threaded context.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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.
StringRef getName() const
Return the name for this struct type if it has an identity.
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
static bool stripDeadDebugInfoImpl(Module &M)
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
ModulePass * createStripDebugDeclarePass()
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
INITIALIZE_PASS(StripSymbols, "strip", "Strip all symbols from a module", false, false) ModulePass *llvm
Iterator for intrusive lists based on ilist_node.
unsigned getNumOperands() const
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.
bool RecursivelyDeleteTriviallyDeadInstructions(Value *V, const TargetLibraryInfo *TLI=nullptr, MemorySSAUpdater *MSSAU=nullptr, std::function< void(Value *)> AboutToDeleteCallback=std::function< void(Value *)>())
If the specified value is a trivially dead instruction, delete it.
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
ConstantArray - Constant Array Declarations.
void push_back(pointer val)
void setPreservesAll()
Set by analyses that do not transform their input at all.
iterator_range< user_iterator > users()
iterator insert(iterator I, T &&Elt)
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)
StringRef getName() const
Return a constant reference to the value's name.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
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)
static bool stripDebugDeclareImpl(Module &M)
A container for analyses that lazily runs them and caches their results.
This header defines various interfaces for pass management in LLVM.
TypeFinder - Walk over a module, identifying all of the types that are used by the module.