blob: 549015524c4df70f91f77fdcadd4dfa316a13dfb [file] [log] [blame]
Chris Lattnere3ad43c2004-12-02 21:25:03 +00001//===- StripSymbols.cpp - Strip symbols and debug info from a module ------===//
Misha Brukmanfd939082005-04-21 23:48:37 +00002//
Chris Lattnere3ad43c2004-12-02 21:25:03 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukmanfd939082005-04-21 23:48:37 +00007//
Chris Lattnere3ad43c2004-12-02 21:25:03 +00008//===----------------------------------------------------------------------===//
9//
Gordon Henriksenc86b6772007-11-04 16:15:04 +000010// The StripSymbols transformation implements code stripping. Specifically, it
11// can delete:
12//
13// * names for virtual registers
14// * symbols for internal globals and functions
15// * debug information
Chris Lattnere3ad43c2004-12-02 21:25:03 +000016//
Gordon Henriksenc86b6772007-11-04 16:15:04 +000017// Note that this transformation makes code much less readable, so it should
18// only be used in situations where the 'strip' utility would be used, such as
19// reducing code size or making it harder to reverse engineer code.
Chris Lattnere3ad43c2004-12-02 21:25:03 +000020//
21//===----------------------------------------------------------------------===//
22
23#include "llvm/Transforms/IPO.h"
Chris Lattnerdd0ecf62004-12-03 16:22:08 +000024#include "llvm/Constants.h"
25#include "llvm/DerivedTypes.h"
26#include "llvm/Instructions.h"
Chris Lattnere3ad43c2004-12-02 21:25:03 +000027#include "llvm/Module.h"
Chris Lattnere3ad43c2004-12-02 21:25:03 +000028#include "llvm/Pass.h"
Devang Patel13e16b62009-06-26 01:49:18 +000029#include "llvm/Analysis/DebugInfo.h"
Reid Spenceref9b9a72007-02-05 20:47:22 +000030#include "llvm/ValueSymbolTable.h"
Reid Spencer78d033e2007-01-06 07:24:44 +000031#include "llvm/TypeSymbolTable.h"
Devang Patel9adb01c2009-03-03 21:31:02 +000032#include "llvm/Transforms/Utils/Local.h"
Devang Patel8c231e52008-01-16 03:33:05 +000033#include "llvm/ADT/SmallPtrSet.h"
Chris Lattnere3ad43c2004-12-02 21:25:03 +000034using namespace llvm;
35
36namespace {
Nick Lewycky8aa9fba2009-09-03 06:43:15 +000037 class StripSymbols : public ModulePass {
Chris Lattnere3ad43c2004-12-02 21:25:03 +000038 bool OnlyDebugInfo;
39 public:
Nick Lewyckyecd94c82007-05-06 13:37:16 +000040 static char ID; // Pass identification, replacement for typeid
Dan Gohmanc2bbfc12007-08-01 15:32:29 +000041 explicit StripSymbols(bool ODI = false)
Owen Anderson90c579d2010-08-06 18:33:48 +000042 : ModulePass(ID), OnlyDebugInfo(ODI) {}
Chris Lattnere3ad43c2004-12-02 21:25:03 +000043
Devang Patelf17fc462008-11-18 21:34:39 +000044 virtual bool runOnModule(Module &M);
Devang Patel229de952008-11-14 22:49:37 +000045
Devang Patelf17fc462008-11-18 21:34:39 +000046 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
47 AU.setPreservesAll();
48 }
49 };
50
Nick Lewycky8aa9fba2009-09-03 06:43:15 +000051 class StripNonDebugSymbols : public ModulePass {
Devang Patelf17fc462008-11-18 21:34:39 +000052 public:
53 static char ID; // Pass identification, replacement for typeid
54 explicit StripNonDebugSymbols()
Owen Anderson90c579d2010-08-06 18:33:48 +000055 : ModulePass(ID) {}
Devang Patel229de952008-11-14 22:49:37 +000056
Chris Lattnere3ad43c2004-12-02 21:25:03 +000057 virtual bool runOnModule(Module &M);
58
59 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
60 AU.setPreservesAll();
61 }
62 };
Devang Patel23e528b2009-03-09 20:49:37 +000063
Nick Lewycky8aa9fba2009-09-03 06:43:15 +000064 class StripDebugDeclare : public ModulePass {
Devang Patel23e528b2009-03-09 20:49:37 +000065 public:
66 static char ID; // Pass identification, replacement for typeid
67 explicit StripDebugDeclare()
Owen Anderson90c579d2010-08-06 18:33:48 +000068 : ModulePass(ID) {}
Devang Patel23e528b2009-03-09 20:49:37 +000069
70 virtual bool runOnModule(Module &M);
71
72 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
73 AU.setPreservesAll();
74 }
75 };
Devang Patel26d14292010-07-01 19:49:20 +000076
77 class StripDeadDebugInfo : public ModulePass {
78 public:
79 static char ID; // Pass identification, replacement for typeid
80 explicit StripDeadDebugInfo()
Owen Anderson90c579d2010-08-06 18:33:48 +000081 : ModulePass(ID) {}
Devang Patel26d14292010-07-01 19:49:20 +000082
83 virtual bool runOnModule(Module &M);
84
85 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
86 AU.setPreservesAll();
87 }
88 };
Chris Lattnere3ad43c2004-12-02 21:25:03 +000089}
90
Dan Gohman844731a2008-05-13 00:00:25 +000091char StripSymbols::ID = 0;
Owen Andersond13db2c2010-07-21 22:09:45 +000092INITIALIZE_PASS(StripSymbols, "strip",
Owen Andersonce665bd2010-10-07 22:25:06 +000093 "Strip all symbols from a module", false, false)
Dan Gohman844731a2008-05-13 00:00:25 +000094
Chris Lattnere3ad43c2004-12-02 21:25:03 +000095ModulePass *llvm::createStripSymbolsPass(bool OnlyDebugInfo) {
96 return new StripSymbols(OnlyDebugInfo);
97}
98
Devang Patelf17fc462008-11-18 21:34:39 +000099char StripNonDebugSymbols::ID = 0;
Owen Andersond13db2c2010-07-21 22:09:45 +0000100INITIALIZE_PASS(StripNonDebugSymbols, "strip-nondebug",
101 "Strip all symbols, except dbg symbols, from a module",
Owen Andersonce665bd2010-10-07 22:25:06 +0000102 false, false)
Devang Patelf17fc462008-11-18 21:34:39 +0000103
104ModulePass *llvm::createStripNonDebugSymbolsPass() {
105 return new StripNonDebugSymbols();
106}
107
Devang Patel23e528b2009-03-09 20:49:37 +0000108char StripDebugDeclare::ID = 0;
Owen Andersond13db2c2010-07-21 22:09:45 +0000109INITIALIZE_PASS(StripDebugDeclare, "strip-debug-declare",
Owen Andersonce665bd2010-10-07 22:25:06 +0000110 "Strip all llvm.dbg.declare intrinsics", false, false)
Devang Patel23e528b2009-03-09 20:49:37 +0000111
112ModulePass *llvm::createStripDebugDeclarePass() {
113 return new StripDebugDeclare();
114}
115
Devang Patel26d14292010-07-01 19:49:20 +0000116char StripDeadDebugInfo::ID = 0;
Owen Andersond13db2c2010-07-21 22:09:45 +0000117INITIALIZE_PASS(StripDeadDebugInfo, "strip-dead-debug-info",
Owen Andersonce665bd2010-10-07 22:25:06 +0000118 "Strip debug info for unused symbols", false, false)
Devang Patel26d14292010-07-01 19:49:20 +0000119
120ModulePass *llvm::createStripDeadDebugInfoPass() {
121 return new StripDeadDebugInfo();
122}
123
Devang Patelbf5db812008-11-13 01:28:40 +0000124/// OnlyUsedBy - Return true if V is only used by Usr.
125static bool OnlyUsedBy(Value *V, Value *Usr) {
126 for(Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I) {
127 User *U = *I;
128 if (U != Usr)
129 return false;
130 }
131 return true;
132}
133
Chris Lattnerdd0ecf62004-12-03 16:22:08 +0000134static void RemoveDeadConstant(Constant *C) {
135 assert(C->use_empty() && "Constant is not dead!");
Chris Lattner0eeb9132009-10-28 05:14:34 +0000136 SmallPtrSet<Constant*, 4> Operands;
Chris Lattnerdd0ecf62004-12-03 16:22:08 +0000137 for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i)
138 if (isa<DerivedType>(C->getOperand(i)->getType()) &&
Devang Patelbf5db812008-11-13 01:28:40 +0000139 OnlyUsedBy(C->getOperand(i), C))
Chris Lattner0eeb9132009-10-28 05:14:34 +0000140 Operands.insert(cast<Constant>(C->getOperand(i)));
Chris Lattnerdd0ecf62004-12-03 16:22:08 +0000141 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
Rafael Espindolabb46f522009-01-15 20:18:42 +0000142 if (!GV->hasLocalLinkage()) return; // Don't delete non static globals.
Chris Lattnerdd0ecf62004-12-03 16:22:08 +0000143 GV->eraseFromParent();
144 }
145 else if (!isa<Function>(C))
Devang Patelf23de862008-11-20 01:20:42 +0000146 if (isa<CompositeType>(C->getType()))
147 C->destroyConstant();
Misha Brukmanfd939082005-04-21 23:48:37 +0000148
Chris Lattnerdd0ecf62004-12-03 16:22:08 +0000149 // If the constant referenced anything, see if we can delete it as well.
Chris Lattner0eeb9132009-10-28 05:14:34 +0000150 for (SmallPtrSet<Constant*, 4>::iterator OI = Operands.begin(),
Devang Patelbf5db812008-11-13 01:28:40 +0000151 OE = Operands.end(); OI != OE; ++OI)
152 RemoveDeadConstant(*OI);
Chris Lattnerdd0ecf62004-12-03 16:22:08 +0000153}
Chris Lattnere3ad43c2004-12-02 21:25:03 +0000154
Chris Lattner7f1444b2007-02-07 06:22:45 +0000155// Strip the symbol table of its names.
156//
Devang Patelf17fc462008-11-18 21:34:39 +0000157static void StripSymtab(ValueSymbolTable &ST, bool PreserveDbgInfo) {
Chris Lattner7f1444b2007-02-07 06:22:45 +0000158 for (ValueSymbolTable::iterator VI = ST.begin(), VE = ST.end(); VI != VE; ) {
Chris Lattnerdec628e2007-02-12 05:18:08 +0000159 Value *V = VI->getValue();
Chris Lattner7f1444b2007-02-07 06:22:45 +0000160 ++VI;
Rafael Espindolabb46f522009-01-15 20:18:42 +0000161 if (!isa<GlobalValue>(V) || cast<GlobalValue>(V)->hasLocalLinkage()) {
Daniel Dunbar460f6562009-07-26 09:48:23 +0000162 if (!PreserveDbgInfo || !V->getName().startswith("llvm.dbg"))
Devang Patelf17fc462008-11-18 21:34:39 +0000163 // Set name to "", removing from symbol table!
164 V->setName("");
Chris Lattner7f1444b2007-02-07 06:22:45 +0000165 }
166 }
167}
168
169// Strip the symbol table of its names.
Devang Patelf17fc462008-11-18 21:34:39 +0000170static void StripTypeSymtab(TypeSymbolTable &ST, bool PreserveDbgInfo) {
171 for (TypeSymbolTable::iterator TI = ST.begin(), E = ST.end(); TI != E; ) {
Benjamin Kramerb0706d12010-01-22 20:00:21 +0000172 if (PreserveDbgInfo && StringRef(TI->first).startswith("llvm.dbg"))
Devang Patelf17fc462008-11-18 21:34:39 +0000173 ++TI;
174 else
175 ST.remove(TI++);
176 }
Chris Lattner7f1444b2007-02-07 06:22:45 +0000177}
178
Devang Patel4460a7e2008-11-18 21:13:41 +0000179/// Find values that are marked as llvm.used.
Chris Lattner401e10c2009-07-20 06:14:25 +0000180static void findUsedValues(GlobalVariable *LLVMUsed,
181 SmallPtrSet<const GlobalValue*, 8> &UsedValues) {
182 if (LLVMUsed == 0) return;
183 UsedValues.insert(LLVMUsed);
184
185 ConstantArray *Inits = dyn_cast<ConstantArray>(LLVMUsed->getInitializer());
186 if (Inits == 0) return;
187
188 for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
189 if (GlobalValue *GV =
190 dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts()))
191 UsedValues.insert(GV);
Devang Patel4460a7e2008-11-18 21:13:41 +0000192}
193
194/// StripSymbolNames - Strip symbol names.
Dan Gohman7db949d2009-08-07 01:32:21 +0000195static bool StripSymbolNames(Module &M, bool PreserveDbgInfo) {
Devang Patel4460a7e2008-11-18 21:13:41 +0000196
197 SmallPtrSet<const GlobalValue*, 8> llvmUsedValues;
Chris Lattner401e10c2009-07-20 06:14:25 +0000198 findUsedValues(M.getGlobalVariable("llvm.used"), llvmUsedValues);
199 findUsedValues(M.getGlobalVariable("llvm.compiler.used"), llvmUsedValues);
Devang Patel4460a7e2008-11-18 21:13:41 +0000200
Devang Patel229de952008-11-14 22:49:37 +0000201 for (Module::global_iterator I = M.global_begin(), E = M.global_end();
202 I != E; ++I) {
Rafael Espindolabb46f522009-01-15 20:18:42 +0000203 if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
Daniel Dunbar460f6562009-07-26 09:48:23 +0000204 if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
Devang Patelf17fc462008-11-18 21:34:39 +0000205 I->setName(""); // Internal symbols can't participate in linkage
Devang Patel229de952008-11-14 22:49:37 +0000206 }
207
208 for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I) {
Rafael Espindolabb46f522009-01-15 20:18:42 +0000209 if (I->hasLocalLinkage() && llvmUsedValues.count(I) == 0)
Daniel Dunbar460f6562009-07-26 09:48:23 +0000210 if (!PreserveDbgInfo || !I->getName().startswith("llvm.dbg"))
Devang Patelf17fc462008-11-18 21:34:39 +0000211 I->setName(""); // Internal symbols can't participate in linkage
212 StripSymtab(I->getValueSymbolTable(), PreserveDbgInfo);
Devang Patel229de952008-11-14 22:49:37 +0000213 }
214
215 // Remove all names from types.
Devang Patelf17fc462008-11-18 21:34:39 +0000216 StripTypeSymtab(M.getTypeSymbolTable(), PreserveDbgInfo);
Chris Lattnere3ad43c2004-12-02 21:25:03 +0000217
Devang Patel229de952008-11-14 22:49:37 +0000218 return true;
219}
220
221// StripDebugInfo - Strip debug info in the module if it exists.
222// To do this, we remove llvm.dbg.func.start, llvm.dbg.stoppoint, and
223// llvm.dbg.region.end calls, and any globals they point to if now dead.
Dan Gohman7db949d2009-08-07 01:32:21 +0000224static bool StripDebugInfo(Module &M) {
Devang Patel229de952008-11-14 22:49:37 +0000225
Devang Patel76e3e502009-11-17 00:47:06 +0000226 bool Changed = false;
227
Devang Patele4b27562009-08-28 23:24:31 +0000228 // Remove all of the calls to the debugger intrinsics, and remove them from
229 // the module.
Devang Patel76e3e502009-11-17 00:47:06 +0000230 if (Function *Declare = M.getFunction("llvm.dbg.declare")) {
Jim Laskey4ca97572006-03-23 18:11:33 +0000231 while (!Declare->use_empty()) {
232 CallInst *CI = cast<CallInst>(Declare->use_back());
Jim Laskey4ca97572006-03-23 18:11:33 +0000233 CI->eraseFromParent();
Jim Laskey4ca97572006-03-23 18:11:33 +0000234 }
235 Declare->eraseFromParent();
Devang Patel76e3e502009-11-17 00:47:06 +0000236 Changed = true;
Jim Laskey4ca97572006-03-23 18:11:33 +0000237 }
Chris Lattnerdd0ecf62004-12-03 16:22:08 +0000238
Devang Pateldf9292c2010-02-10 21:19:56 +0000239 if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {
240 while (!DbgVal->use_empty()) {
241 CallInst *CI = cast<CallInst>(DbgVal->use_back());
242 CI->eraseFromParent();
243 }
244 DbgVal->eraseFromParent();
245 Changed = true;
246 }
247
Devang Patel444a08c2010-06-30 21:29:00 +0000248 for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
249 NME = M.named_metadata_end(); NMI != NME;) {
250 NamedMDNode *NMD = NMI;
251 ++NMI;
Devang Patele62b2032010-07-01 18:27:46 +0000252 if (NMD->getName().startswith("llvm.dbg.")) {
Devang Patel444a08c2010-06-30 21:29:00 +0000253 NMD->eraseFromParent();
Devang Patele62b2032010-07-01 18:27:46 +0000254 Changed = true;
255 }
Devang Patel69b4d1c2010-05-20 16:49:22 +0000256 }
Duncan Sandsa7065b12010-06-29 14:52:10 +0000257
Duncan Sandsa7065b12010-06-29 14:52:10 +0000258 for (Module::iterator MI = M.begin(), ME = M.end(); MI != ME; ++MI)
Devang Patel76e3e502009-11-17 00:47:06 +0000259 for (Function::iterator FI = MI->begin(), FE = MI->end(); FI != FE;
260 ++FI)
261 for (BasicBlock::iterator BI = FI->begin(), BE = FI->end(); BI != BE;
Duncan Sandsa7065b12010-06-29 14:52:10 +0000262 ++BI) {
Dan Gohman549979f2010-07-20 23:49:44 +0000263 if (!BI->getDebugLoc().isUnknown()) {
264 Changed = true;
265 BI->setDebugLoc(DebugLoc());
266 }
Duncan Sandsa7065b12010-06-29 14:52:10 +0000267 }
Devang Patelbf5db812008-11-13 01:28:40 +0000268
Duncan Sandsa7065b12010-06-29 14:52:10 +0000269 return Changed;
Chris Lattnere3ad43c2004-12-02 21:25:03 +0000270}
Devang Patelf17fc462008-11-18 21:34:39 +0000271
272bool StripSymbols::runOnModule(Module &M) {
273 bool Changed = false;
274 Changed |= StripDebugInfo(M);
275 if (!OnlyDebugInfo)
276 Changed |= StripSymbolNames(M, false);
277 return Changed;
278}
279
280bool StripNonDebugSymbols::runOnModule(Module &M) {
281 return StripSymbolNames(M, true);
282}
Devang Patel23e528b2009-03-09 20:49:37 +0000283
284bool StripDebugDeclare::runOnModule(Module &M) {
285
286 Function *Declare = M.getFunction("llvm.dbg.declare");
Devang Patel23e528b2009-03-09 20:49:37 +0000287 std::vector<Constant*> DeadConstants;
288
Dale Johannesen44252402009-03-13 22:59:47 +0000289 if (Declare) {
290 while (!Declare->use_empty()) {
291 CallInst *CI = cast<CallInst>(Declare->use_back());
Gabor Greife9af3522010-06-30 12:40:35 +0000292 Value *Arg1 = CI->getArgOperand(0);
293 Value *Arg2 = CI->getArgOperand(1);
Dale Johannesen44252402009-03-13 22:59:47 +0000294 assert(CI->use_empty() && "llvm.dbg intrinsic should have void result");
295 CI->eraseFromParent();
296 if (Arg1->use_empty()) {
297 if (Constant *C = dyn_cast<Constant>(Arg1))
298 DeadConstants.push_back(C);
299 else
Dan Gohmane66f6f12009-05-02 20:22:10 +0000300 RecursivelyDeleteTriviallyDeadInstructions(Arg1);
Dale Johannesen44252402009-03-13 22:59:47 +0000301 }
302 if (Arg2->use_empty())
303 if (Constant *C = dyn_cast<Constant>(Arg2))
304 DeadConstants.push_back(C);
Devang Patel23e528b2009-03-09 20:49:37 +0000305 }
Dale Johannesen44252402009-03-13 22:59:47 +0000306 Declare->eraseFromParent();
Devang Patel23e528b2009-03-09 20:49:37 +0000307 }
Devang Patel23e528b2009-03-09 20:49:37 +0000308
309 while (!DeadConstants.empty()) {
310 Constant *C = DeadConstants.back();
311 DeadConstants.pop_back();
312 if (GlobalVariable *GV = dyn_cast<GlobalVariable>(C)) {
313 if (GV->hasLocalLinkage())
314 RemoveDeadConstant(GV);
Chris Lattner0eeb9132009-10-28 05:14:34 +0000315 } else
Devang Patel23e528b2009-03-09 20:49:37 +0000316 RemoveDeadConstant(C);
317 }
318
319 return true;
320}
Devang Patel26d14292010-07-01 19:49:20 +0000321
322/// getRealLinkageName - If special LLVM prefix that is used to inform the asm
323/// printer to not emit usual symbol prefix before the symbol name is used then
324/// return linkage name after skipping this special LLVM prefix.
325static StringRef getRealLinkageName(StringRef LinkageName) {
326 char One = '\1';
327 if (LinkageName.startswith(StringRef(&One, 1)))
328 return LinkageName.substr(1);
329 return LinkageName;
330}
331
332bool StripDeadDebugInfo::runOnModule(Module &M) {
333 bool Changed = false;
334
335 // Debugging infomration is encoded in llvm IR using metadata. This is designed
336 // such a way that debug info for symbols preserved even if symbols are
337 // optimized away by the optimizer. This special pass removes debug info for
338 // such symbols.
339
340 // llvm.dbg.gv keeps track of debug info for global variables.
341 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.gv")) {
342 SmallVector<MDNode *, 8> MDs;
343 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
344 if (DIGlobalVariable(NMD->getOperand(i)).Verify())
345 MDs.push_back(NMD->getOperand(i));
346 else
347 Changed = true;
348 NMD->eraseFromParent();
349 NMD = NULL;
350
351 for (SmallVector<MDNode *, 8>::iterator I = MDs.begin(),
352 E = MDs.end(); I != E; ++I) {
Devang Patel1955cf12010-08-25 18:52:02 +0000353 GlobalVariable *GV = DIGlobalVariable(*I).getGlobal();
354 if (GV && M.getGlobalVariable(GV->getName(), true)) {
Devang Patel26d14292010-07-01 19:49:20 +0000355 if (!NMD)
356 NMD = M.getOrInsertNamedMetadata("llvm.dbg.gv");
357 NMD->addOperand(*I);
358 }
359 else
360 Changed = true;
361 }
362 }
363
364 // llvm.dbg.sp keeps track of debug info for subprograms.
365 if (NamedMDNode *NMD = M.getNamedMetadata("llvm.dbg.sp")) {
366 SmallVector<MDNode *, 8> MDs;
367 for (unsigned i = 0, e = NMD->getNumOperands(); i != e; ++i)
368 if (DISubprogram(NMD->getOperand(i)).Verify())
369 MDs.push_back(NMD->getOperand(i));
370 else
371 Changed = true;
372 NMD->eraseFromParent();
373 NMD = NULL;
374
375 for (SmallVector<MDNode *, 8>::iterator I = MDs.begin(),
376 E = MDs.end(); I != E; ++I) {
377 bool FnIsLive = false;
378 if (Function *F = DISubprogram(*I).getFunction())
379 if (M.getFunction(F->getName()))
380 FnIsLive = true;
381 if (FnIsLive) {
382 if (!NMD)
383 NMD = M.getOrInsertNamedMetadata("llvm.dbg.sp");
384 NMD->addOperand(*I);
385 } else {
386 // Remove llvm.dbg.lv.fnname named mdnode which may have been used
387 // to hold debug info for dead function's local variables.
388 StringRef FName = DISubprogram(*I).getLinkageName();
389 if (FName.empty())
390 FName = DISubprogram(*I).getName();
391 if (NamedMDNode *LVNMD =
392 M.getNamedMetadata(Twine("llvm.dbg.lv.",
393 getRealLinkageName(FName))))
394 LVNMD->eraseFromParent();
395 }
396 }
397 }
398
399 return Changed;
400}