41 cl::desc(
"Removes debug compile units which reference "
42 "to non-existing global constants"));
46 for (
User *U : V->users())
54 assert(
C->use_empty() &&
"Constant is not dead!");
60 if (!GV->hasLocalLinkage())
return;
61 GV->eraseFromParent();
62 }
else if (!isa<Function>(
C)) {
64 if (isa<StructType>(
C->getType()) || isa<ArrayType>(
C->getType()) ||
65 isa<VectorType>(
C->getType()))
78 Value *V = VI->getValue();
80 if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
81 if (!PreserveDbgInfo || !V->getName().starts_with(
"llvm.dbg"))
91 StructTypes.
run(M,
false);
94 if (STy->isLiteral() || STy->getName().empty())
continue;
96 if (PreserveDbgInfo && STy->getName().starts_with(
"llvm.dbg"))
106 if (!LLVMUsed)
return;
107 UsedValues.
insert(LLVMUsed);
122 findUsedValues(M.getGlobalVariable(
"llvm.compiler.used"), llvmUsedValues);
125 if (GV.hasLocalLinkage() && !llvmUsedValues.
contains(&GV))
126 if (!PreserveDbgInfo || !GV.getName().starts_with(
"llvm.dbg"))
131 if (
I.hasLocalLinkage() && !llvmUsedValues.
contains(&
I))
132 if (!PreserveDbgInfo || !
I.getName().starts_with(
"llvm.dbg"))
134 if (
auto *Symtab =
I.getValueSymbolTable())
147 std::vector<Constant*> DeadConstants;
154 assert(CI->
use_empty() &&
"llvm.dbg intrinsic should have void result");
157 if (
Constant *
C = dyn_cast<Constant>(Arg1))
158 DeadConstants.push_back(
C);
163 if (
Constant *
C = dyn_cast<Constant>(Arg2))
164 DeadConstants.push_back(
C);
169 while (!DeadConstants.empty()) {
171 DeadConstants.pop_back();
173 if (GV->hasLocalLinkage())
183 bool Changed =
false;
200 std::set<DIGlobalVariableExpression *> LiveGVs;
203 GV.getDebugInfo(GVEs);
204 for (
auto *GVE : GVEs)
208 std::set<DICompileUnit *> LiveCUs;
210 for (
const Function &
F : M.functions()) {
211 if (
auto *SP = cast_or_null<DISubprogram>(
F.getSubprogram()))
217 LiveCUs.insert(FoundCUs.begin(), FoundCUs.end());
219 bool HasDeadCUs =
false;
222 bool GlobalVariableChange =
false;
223 for (
auto *DIG : DIC->getGlobalVariables()) {
224 if (DIG->getExpression() && DIG->getExpression()->isConstant() &&
229 if (!VisitedSet.
insert(DIG).second)
233 if (LiveGVs.count(DIG))
236 GlobalVariableChange =
true;
239 if (!LiveGlobalVariables.
empty())
241 else if (!LiveCUs.count(DIC))
246 if (GlobalVariableChange) {
247 DIC->replaceGlobalVariables(
MDTuple::get(
C, LiveGlobalVariables));
252 LiveGlobalVariables.
clear();
257 NamedMDNode *NMD = M.getOrInsertNamedMetadata(
"llvm.dbg.cu");
259 if (!LiveCUs.empty()) {
Expand Atomic instructions
This file contains the declarations for the subclasses of Constant, which represent the different fla...
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
mir Rename Register Operands
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 cl::opt< bool > StripGlobalConstants("strip-global-constants", cl::init(false), cl::Hidden, cl::desc("Removes debug compile units which reference " "to non-existing global constants"))
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.
This class represents an Operation in the Expression.
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.
InstListType::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)
@ C
The default llvm calling convention, compatible with C.
Function * getDeclarationIfExists(Module *M, ID id, ArrayRef< Type * > Tys, FunctionType *FT=nullptr)
This version supports overloaded intrinsics.
initializer< Ty > init(const Ty &Val)
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)