Go to the documentation of this file.
46 explicit StripSymbols(
bool ODI =
false)
51 bool runOnModule(
Module &M)
override;
58 class StripNonDebugSymbols :
public ModulePass {
61 explicit StripNonDebugSymbols()
66 bool runOnModule(
Module &M)
override;
76 explicit StripDebugDeclare()
81 bool runOnModule(
Module &M)
override;
91 explicit StripDeadDebugInfo()
96 bool runOnModule(
Module &M)
override;
106 "Strip all symbols from a module",
false,
false)
109 return new StripSymbols(OnlyDebugInfo);
114 "Strip all symbols, except dbg symbols, from a module",
118 return new StripNonDebugSymbols();
123 "Strip all llvm.dbg.declare intrinsics",
false,
false)
126 return new StripDebugDeclare();
131 "Strip debug info for unused symbols",
false,
false)
134 return new StripDeadDebugInfo();
147 assert(
C->use_empty() &&
"Constant is not dead!");
153 if (!GV->hasLocalLinkage())
return;
154 GV->eraseFromParent();
155 }
else if (!isa<Function>(
C)) {
157 if (isa<StructType>(
C->getType()) || isa<ArrayType>(
C->getType()) ||
158 isa<VectorType>(
C->getType()))
159 C->destroyConstant();
173 if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
184 StructTypes.
run(
M,
false);
187 if (STy->isLiteral() || STy->getName().empty())
continue;
189 if (PreserveDbgInfo && STy->getName().startswith(
"llvm.dbg"))
199 if (!LLVMUsed)
return;
200 UsedValues.
insert(LLVMUsed);
215 findUsedValues(
M.getGlobalVariable(
"llvm.compiler.used"), llvmUsedValues);
218 if (GV.hasLocalLinkage() && !llvmUsedValues.
contains(&GV))
219 if (!PreserveDbgInfo || !GV.getName().startswith(
"llvm.dbg"))
224 if (
I.hasLocalLinkage() && !llvmUsedValues.
contains(&
I))
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");
268 if (
Constant *
C = dyn_cast<Constant>(Arg1))
269 DeadConstants.push_back(
C);
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) {
308 auto InS = VisitedScopes.
insert(Scope);
312 if (
const auto *SP = dyn_cast<DISubprogram>(Scope)) {
314 LiveCUs.insert(SP->getUnit());
317 if (
const auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
319 if (SP && SP->getUnit())
320 LiveCUs.insert(SP->getUnit());
329 std::set<DICompileUnit *> &LiveCUs,
331 if (!Loc || !Loc->getInlinedAt())
338 bool Changed =
false;
355 std::set<DIGlobalVariableExpression *> LiveGVs;
358 GV.getDebugInfo(GVEs);
359 for (
auto *GVE : GVEs)
363 std::set<DICompileUnit *> LiveCUs;
367 for (
const Function &Fn :
M.functions()) {
371 if (!
I->getDebugLoc())
378 bool HasDeadCUs =
false;
381 bool GlobalVariableChange =
false;
382 for (
auto *DIG : DIC->getGlobalVariables()) {
383 if (DIG->getExpression() && DIG->getExpression()->isConstant())
387 if (!VisitedSet.
insert(DIG).second)
391 if (LiveGVs.count(DIG))
392 LiveGlobalVariables.push_back(DIG);
394 GlobalVariableChange =
true;
397 if (!LiveGlobalVariables.empty())
399 else if (!LiveCUs.count(DIC))
404 if (GlobalVariableChange) {
405 DIC->replaceGlobalVariables(
MDTuple::get(
C, LiveGlobalVariables));
410 LiveGlobalVariables.
clear();
415 NamedMDNode *NMD =
M.getOrInsertNamedMetadata(
"llvm.dbg.cu");
417 if (!LiveCUs.empty()) {
434 bool StripDeadDebugInfo::runOnModule(
Module &M) {
A set of analyses that are preserved following a run of a transformation pass.
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 StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
This is an optimization pass for GlobalISel generic memory operations.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
static bool stripDeadDebugInfoImpl(Module &M)
static void collectCUsForInlinedFuncs(const DILocation *Loc, std::set< DICompileUnit * > &LiveCUs, SmallPtrSet< const DIScope *, 8 > &VisitedScopes)
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
void initializeStripDeadDebugInfoPass(PassRegistry &)
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
std::pair< iterator, bool > insert(const ValueT &V)
Utility to find all debug info in a module.
ModulePass * createStripDebugDeclarePass()
static bool OnlyUsedBy(Value *V, Value *Usr)
OnlyUsedBy - Return true if V is only used by Usr.
static void collectCUsWithScope(const DIScope *Scope, std::set< DICompileUnit * > &LiveCUs, SmallPtrSet< const DIScope *, 8 > &VisitedScopes)
Collects compilation units referenced by functions or lexical scopes.
static void RemoveDeadConstant(Constant *C)
void addOperand(MDNode *M)
void initializeStripDebugDeclarePass(PassRegistry &)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool startswith(StringRef Prefix) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static void findUsedValues(GlobalVariable *LLVMUsed, SmallPtrSetImpl< const GlobalValue * > &UsedValues)
Find values that are marked as llvm.used.
(vector float) vec_cmpeq(*A, *B) C
Represent the analysis usage information of a pass.
ConstantArray - Constant Array Declarations.
void setName(const Twine &Name)
Change the name of the value.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
mir Rename Register Operands
Implements a dense probed hash-table based set.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
This is an important base class in LLVM.
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
This is an important class for using LLVM in a threaded context.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
A Module instance is used to store all the information related to an LLVM module.
ModulePass * createStripSymbolsPass(bool OnlyDebugInfo=false)
Class to represent struct types.
void run(const Module &M, bool onlyNamed)
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
ModulePass * createStripDeadDebugInfoPass()
StringRef getName() const
Return a constant reference to the value's name.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
INITIALIZE_PASS(StripSymbols, "strip", "Strip all symbols from a module", false, false) ModulePass *llvm
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
void setPreservesAll()
Set by analyses that do not transform their input at all.
Base class for scope-like contexts.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo)
ModulePass * createStripNonDebugSymbolsPass()
inst_iterator inst_end(Function *F)
static bool stripDebugDeclareImpl(Module &M)
void initializeStripSymbolsPass(PassRegistry &)
unsigned getNumOperands() const
This class provides a symbol table of name/value pairs.
Value * getArgOperand(unsigned i) const
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
A container for analyses that lazily runs them and caches their results.
This class represents a function call, abstracting a target machine's calling convention.
inst_iterator inst_begin(Function *F)
Value * getOperand(unsigned i) const
void clearOperands()
Drop all references to this node's operands.
static void StripTypeNames(Module &M, bool PreserveDbgInfo)
bool contains(ConstPtrType Ptr) const
LLVM Value Representation.
iterator_range< user_iterator > users()
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
iterator insert(iterator I, T &&Elt)
static bool StripSymbolNames(Module &M, bool PreserveDbgInfo)
StripSymbolNames - Strip symbol names.
void initializeStripNonDebugSymbolsPass(PassRegistry &)