LLVM: lib/Transforms/IPO/StripSymbols.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
38
39using namespace llvm;
40
43 cl::desc("Removes debug compile units which reference "
44 "to non-existing global constants"));
45
46
49 if (U != Usr)
50 return false;
51
52 return true;
53}
54
56 assert(C->use_empty() && "Constant is not dead!");
58 for (Value *Op : C->operands())
62 if (!GV->hasLocalLinkage()) return;
63 GV->eraseFromParent();
65
68 C->destroyConstant();
69 }
70
71
74}
75
76
77
80 Value *V = VI->getValue();
81 ++VI;
83 if (!PreserveDbgInfo || !V->getName().starts_with("llvm.dbg"))
84
85 V->setName("");
86 }
87 }
88}
89
90
93 StructTypes.run(M, false);
94
96 if (STy->isLiteral() || STy->getName().empty()) continue;
97
98 if (PreserveDbgInfo && STy->getName().starts_with("llvm.dbg"))
99 continue;
100
101 STy->setName("");
102 }
103}
104
105
108 if (!LLVMUsed) return;
109 UsedValues.insert(LLVMUsed);
110
112
113 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
116 UsedValues.insert(GV);
117}
118
119
121
123 findUsedValues(M.getGlobalVariable("llvm.used"), llvmUsedValues);
124 findUsedValues(M.getGlobalVariable("llvm.compiler.used"), llvmUsedValues);
125
127 if (GV.hasLocalLinkage() && !llvmUsedValues.contains(&GV))
128 if (!PreserveDbgInfo || !GV.getName().starts_with("llvm.dbg"))
129 GV.setName("");
130 }
131
133 if (I.hasLocalLinkage() && !llvmUsedValues.contains(&I))
134 if (!PreserveDbgInfo || .getName().starts_with("llvm.dbg"))
135 I.setName("");
136 if (auto *Symtab = I.getValueSymbolTable())
138 }
139
140
142
143 return true;
144}
145
149 std::vector<Constant*> DeadConstants;
150
151 if (Declare) {
156 assert(CI->use_empty() && "llvm.dbg intrinsic should have void result");
160 DeadConstants.push_back(C);
161 else
163 }
166 DeadConstants.push_back(C);
167 }
169 }
170
171 while (!DeadConstants.empty()) {
172 Constant *C = DeadConstants.back();
173 DeadConstants.pop_back();
175 if (GV->hasLocalLinkage())
177 } else
179 }
180
181 return true;
182}
183
186
188
189
190
191
192
194 F.processModule(M);
195
196
197
198
201
202 std::set<DIGlobalVariableExpression *> LiveGVs;
205 GV.getDebugInfo(GVEs);
206 for (auto *GVE : GVEs)
207 LiveGVs.insert(GVE);
208 }
209
210 std::set<DICompileUnit *> LiveCUs;
212 for (const Function &F : M.functions()) {
217 }
219 LiveCUs.insert(FoundCUs.begin(), FoundCUs.end());
220
221 bool HasDeadCUs = false;
223
224 bool GlobalVariableChange = false;
225 for (auto *DIG : DIC->getGlobalVariables()) {
226 if (DIG->getExpression() && DIG->getExpression()->isConstant() &&
228 LiveGVs.insert(DIG);
229
230
231 if (!VisitedSet.insert(DIG).second)
232 continue;
233
234
235 if (LiveGVs.count(DIG))
236 LiveGlobalVariables.push_back(DIG);
237 else
238 GlobalVariableChange = true;
239 }
240
241 if (!LiveGlobalVariables.empty())
242 LiveCUs.insert(DIC);
243 else if (!LiveCUs.count(DIC))
244 HasDeadCUs = true;
245
246
247
248 if (GlobalVariableChange) {
249 DIC->replaceGlobalVariables(MDTuple::get(C, LiveGlobalVariables));
251 }
252
253
254 LiveGlobalVariables.clear();
255 }
256
257 if (HasDeadCUs) {
258
259 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu");
261 if (!LiveCUs.empty()) {
264 }
266 }
267
269}
270
278
286
294
302
306 if (!CGProf)
308
310 for (Metadata *Edge : CGProf->operands()) {
314 }
318}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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.
This file defines the SmallPtrSet class.
static bool stripDeadDebugInfoImpl(Module &M)
Definition StripSymbols.cpp:184
static bool stripDebugDeclareImpl(Module &M)
Definition StripSymbols.cpp:146
static bool OnlyUsedBy(Value *V, Value *Usr)
OnlyUsedBy - Return true if V is only used by Usr.
Definition StripSymbols.cpp:47
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.
Definition StripSymbols.cpp:106
static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo)
Definition StripSymbols.cpp:78
static void StripTypeNames(Module &M, bool PreserveDbgInfo)
Definition StripSymbols.cpp:91
static bool StripSymbolNames(Module &M, bool PreserveDbgInfo)
StripSymbolNames - Strip symbol names.
Definition StripSymbols.cpp:120
static void RemoveDeadConstant(Constant *C)
Definition StripSymbols.cpp:55
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.
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.
ValueMap::iterator iterator
An iterator over a ValueMap.
LLVM Value Representation.
iterator_range< user_iterator > users()
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)
@ C
The default llvm calling convention, compatible with C.
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.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
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 - Return the argument parameter cast to the specified type.
auto cast_or_null(const Y &Val)
auto dyn_cast_or_null(const Y &Val)
bool isa(const From &Val)
isa - 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 - 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)
Definition StripSymbols.cpp:303
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition StripSymbols.cpp:295
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition StripSymbols.cpp:287
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition StripSymbols.cpp:279
LLVM_ABI PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
Definition StripSymbols.cpp:271