Go to the documentation of this file.
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();
145 assert(
C->use_empty() &&
"Constant is not dead!");
151 if (!GV->hasLocalLinkage())
return;
152 GV->eraseFromParent();
153 }
else if (!isa<Function>(
C)) {
155 if (isa<StructType>(
C->getType()) || isa<ArrayType>(
C->getType()) ||
156 isa<VectorType>(
C->getType()))
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);
217 if (GV.hasLocalLinkage() && !llvmUsedValues.
contains(&GV))
218 if (!PreserveDbgInfo || !GV.getName().startswith(
"llvm.dbg"))
223 if (
I.hasLocalLinkage() && !llvmUsedValues.
contains(&
I))
224 if (!PreserveDbgInfo || !
I.getName().startswith(
"llvm.dbg"))
226 if (
auto *Symtab =
I.getValueSymbolTable())
236 bool StripSymbols::runOnModule(
Module &M) {
240 bool Changed =
false;
247 bool StripNonDebugSymbols::runOnModule(
Module &M) {
256 Function *Declare =
M.getFunction(
"llvm.dbg.declare");
257 std::vector<Constant*> DeadConstants;
264 assert(CI->
use_empty() &&
"llvm.dbg intrinsic should have void result");
267 if (
Constant *
C = dyn_cast<Constant>(Arg1))
268 DeadConstants.push_back(
C);
273 if (
Constant *
C = dyn_cast<Constant>(Arg2))
274 DeadConstants.push_back(
C);
279 while (!DeadConstants.empty()) {
281 DeadConstants.pop_back();
283 if (GV->hasLocalLinkage())
292 bool StripDebugDeclare::runOnModule(
Module &M) {
299 bool Changed =
false;
316 std::set<DIGlobalVariableExpression *> LiveGVs;
319 GV.getDebugInfo(GVEs);
320 for (
auto *GVE : GVEs)
324 std::set<DICompileUnit *> LiveCUs;
328 LiveCUs.insert(SP->getUnit());
331 bool HasDeadCUs =
false;
334 bool GlobalVariableChange =
false;
335 for (
auto *DIG : DIC->getGlobalVariables()) {
336 if (DIG->getExpression() && DIG->getExpression()->isConstant())
340 if (!VisitedSet.
insert(DIG).second)
344 if (LiveGVs.count(DIG))
345 LiveGlobalVariables.push_back(DIG);
347 GlobalVariableChange =
true;
350 if (!LiveGlobalVariables.empty())
352 else if (!LiveCUs.count(DIC))
357 if (GlobalVariableChange) {
358 DIC->replaceGlobalVariables(
MDTuple::get(
C, LiveGlobalVariables));
363 LiveGlobalVariables.
clear();
368 NamedMDNode *NMD =
M.getOrInsertNamedMetadata(
"llvm.dbg.cu");
370 if (!LiveCUs.empty()) {
387 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.
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
This is an optimization pass for GlobalISel generic memory operations.
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)
StringRef getName() const
Return the name for this struct type if it has an identity.
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
static bool stripDeadDebugInfoImpl(Module &M)
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()
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 bool OnlyUsedBy(Value *V, Value *Usr)
OnlyUsedBy - Return true if V is only used by Usr.
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...
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.
constexpr LLVM_NODISCARD bool empty() const
empty - Check if the string is empty.
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.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo)
ModulePass * createStripNonDebugSymbolsPass()
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.
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
bool isLiteral() const
Return true if this type is uniqued by structural equivalence, false if it is a struct definition.
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 &)