41 for (
User *U : V->users())
49 assert(
C->use_empty() &&
"Constant is not dead!");
51 for (
Value *Op :
C->operands())
55 if (!GV->hasLocalLinkage())
return;
56 GV->eraseFromParent();
57 }
else if (!isa<Function>(
C)) {
59 if (isa<StructType>(
C->getType()) || isa<ArrayType>(
C->getType()) ||
60 isa<VectorType>(
C->getType()))
75 if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
76 if (!PreserveDbgInfo || !V->getName().startswith(
"llvm.dbg"))
86 StructTypes.
run(M,
false);
89 if (STy->isLiteral() || STy->getName().empty())
continue;
91 if (PreserveDbgInfo && STy->getName().startswith(
"llvm.dbg"))
101 if (!LLVMUsed)
return;
102 UsedValues.
insert(LLVMUsed);
117 findUsedValues(M.getGlobalVariable(
"llvm.compiler.used"), llvmUsedValues);
120 if (GV.hasLocalLinkage() && !llvmUsedValues.
contains(&GV))
121 if (!PreserveDbgInfo || !GV.getName().startswith(
"llvm.dbg"))
126 if (
I.hasLocalLinkage() && !llvmUsedValues.
contains(&
I))
127 if (!PreserveDbgInfo || !
I.getName().startswith(
"llvm.dbg"))
129 if (
auto *Symtab =
I.getValueSymbolTable())
141 Function *Declare = M.getFunction(
"llvm.dbg.declare");
142 std::vector<Constant*> DeadConstants;
149 assert(CI->
use_empty() &&
"llvm.dbg intrinsic should have void result");
152 if (
Constant *
C = dyn_cast<Constant>(Arg1))
158 if (
Constant *
C = dyn_cast<Constant>(Arg2))
159 DeadConstants.push_back(
C);
164 while (!DeadConstants.empty()) {
166 DeadConstants.pop_back();
168 if (GV->hasLocalLinkage())
178 bool Changed =
false;
195 std::set<DIGlobalVariableExpression *> LiveGVs;
198 GV.getDebugInfo(GVEs);
199 for (
auto *GVE : GVEs)
203 std::set<DICompileUnit *> LiveCUs;
205 for (
const Function &
F : M.functions()) {
206 if (
auto *SP = cast_or_null<DISubprogram>(
F.getSubprogram()))
212 LiveCUs.insert(FoundCUs.begin(), FoundCUs.end());
214 bool HasDeadCUs =
false;
217 bool GlobalVariableChange =
false;
218 for (
auto *DIG : DIC->getGlobalVariables()) {
219 if (DIG->getExpression() && DIG->getExpression()->isConstant())
223 if (!VisitedSet.
insert(DIG).second)
227 if (LiveGVs.count(DIG))
230 GlobalVariableChange =
true;
233 if (!LiveGlobalVariables.
empty())
235 else if (!LiveCUs.count(DIC))
240 if (GlobalVariableChange) {
241 DIC->replaceGlobalVariables(
MDTuple::get(
C, LiveGlobalVariables));
246 LiveGlobalVariables.
clear();
251 NamedMDNode *NMD = M.getOrInsertNamedMetadata(
"llvm.dbg.cu");
253 if (!LiveCUs.empty()) {
This file contains the declarations for the subclasses of Constant, which represent the different fla...
mir Rename Register Operands
Module.h This file contains the declarations for the Module class.
print must be executed print the must be executed context for all instructions
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallPtrSet class.
static bool stripDeadDebugInfoImpl(Module &M)
static bool stripDebugDeclareImpl(Module &M)
static bool OnlyUsedBy(Value *V, Value *Usr)
OnlyUsedBy - Return true if V is only used by Usr.
static void findUsedValues(GlobalVariable *LLVMUsed, SmallPtrSetImpl< const GlobalValue * > &UsedValues)
Find values that are marked as llvm.used.
static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo)
static void StripTypeNames(Module &M, bool PreserveDbgInfo)
static bool StripSymbolNames(Module &M, bool PreserveDbgInfo)
StripSymbolNames - Strip symbol names.
static void RemoveDeadConstant(Constant *C)
A container for analyses that lazily runs them and caches their results.
Represents analyses that only rely on functions' control flow.
Value * getArgOperand(unsigned i) const
This class represents a function call, abstracting a target machine's calling convention.
ConstantArray - Constant Array Declarations.
This is an important base class in LLVM.
Utility to find all debug info in a module.
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
void processSubprogram(DISubprogram *SP)
Process subprogram.
iterator_range< compile_unit_iterator > compile_units() const
Implements a dense probed hash-table based set.
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
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.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
A Module instance is used to store all the information related to an LLVM module.
void clearOperands()
Drop all references to this node's operands.
void addOperand(MDNode *M)
A set of analyses that are preserved following a run of a transformation pass.
void preserveSet()
Mark an analysis set as preserved.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
bool contains(ConstPtrType Ptr) const
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
iterator insert(iterator I, T &&Elt)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Class to represent struct types.
TypeFinder - Walk over a module, identifying all of the types that are used by the module.
void run(const Module &M, bool onlyNamed)
Value * getOperand(unsigned i) const
unsigned getNumOperands() const
This class provides a symbol table of name/value pairs.
LLVM Value Representation.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
std::pair< iterator, bool > insert(const ValueT &V)
void push_back(pointer val)
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
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.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)