44 for (
User *U :
V->users())
52 assert(
C->use_empty() &&
"Constant is not dead!");
58 if (!GV->hasLocalLinkage())
return;
59 GV->eraseFromParent();
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");
158 DeadConstants.push_back(
C);
164 DeadConstants.push_back(
C);
169 while (!DeadConstants.empty()) {
171 DeadConstants.pop_back();
173 if (GV->hasLocalLinkage())
201 std::set<DIGlobalVariableExpression *> LiveGVs;
204 GV.getDebugInfo(GVEs);
205 for (
auto *GVE : GVEs)
209 std::set<DICompileUnit *> LiveCUs;
211 for (
const Function &
F : M.functions()) {
218 LiveCUs.insert(FoundCUs.begin(), FoundCUs.end());
220 bool HasDeadCUs =
false;
223 bool GlobalVariableChange =
false;
224 for (
auto *DIG : DIC->getGlobalVariables()) {
225 if (DIG->getExpression() && DIG->getExpression()->isConstant() &&
226 !Opts.strip_global_constants)
230 if (!VisitedSet.
insert(DIG).second)
234 if (LiveGVs.count(DIG))
237 GlobalVariableChange =
true;
240 if (!LiveGlobalVariables.
empty())
242 else if (!LiveCUs.count(DIC))
247 if (GlobalVariableChange) {
248 DIC->replaceGlobalVariables(
MDTuple::get(
C, LiveGlobalVariables));
253 LiveGlobalVariables.
clear();
258 NamedMDNode *NMD = M.getOrInsertNamedMetadata(
"llvm.dbg.cu");
260 if (!LiveCUs.empty()) {
309 for (
Metadata *Edge : CGProf->operands()) {
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Expand Atomic instructions
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
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.
This file defines the SmallPtrSet class.
This file defines the SmallVector 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)
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.
LLVM_ABI void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
LLVM_ABI 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.
LLVM_ABI 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 * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a distinct node.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
A Module instance is used to store all the information related to an LLVM module.
@ Append
Appends the two values, which are required to be metadata nodes.
LLVM_ABI void clearOperands()
Drop all references to this node's operands.
LLVM_ABI void addOperand(MDNode *M)
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & 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.
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.
LLVM_ABI 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.
LLVM_ABI const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
std::pair< iterator, bool > insert(const ValueT &V)
LLVM_ABI Function * getDeclarationIfExists(const Module *M, ID id)
Look up the Function declaration of the intrinsic id in the Module M and return it if it exists.
This is an optimization pass for GlobalISel generic memory operations.
StringMapEntry< Value * > ValueName
LLVM_ABI 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.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
auto cast_or_null(const Y &Val)
auto dyn_cast_or_null(const Y &Val)
const IPOOptions & getIPOOptions(const LLVMContext &C)
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
LLVM_ABI bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
DWARFExpression::Operation Op
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)