blob: a2443becdd00d88c9abf380e37d88705a28405b7 [file] [log] [blame]
Bill Wendling523bea82013-11-08 08:13:15 +00001//===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file implements the helper classes used to build and interpret debug
11// information in LLVM IR form.
12//
13//===----------------------------------------------------------------------===//
14
Chandler Carruth9a4c9e52014-03-06 00:46:21 +000015#include "llvm/IR/DebugInfo.h"
Chandler Carruth442f7842014-03-04 10:07:28 +000016#include "LLVMContextImpl.h"
Bill Wendling523bea82013-11-08 08:13:15 +000017#include "llvm/ADT/STLExtras.h"
18#include "llvm/ADT/SmallPtrSet.h"
19#include "llvm/ADT/SmallString.h"
20#include "llvm/Analysis/ValueTracking.h"
21#include "llvm/IR/Constants.h"
Adrian Prantlb1416832014-08-01 22:11:58 +000022#include "llvm/IR/DIBuilder.h"
Bill Wendling523bea82013-11-08 08:13:15 +000023#include "llvm/IR/DerivedTypes.h"
24#include "llvm/IR/Instructions.h"
25#include "llvm/IR/IntrinsicInst.h"
26#include "llvm/IR/Intrinsics.h"
Rafael Espindola0d68b4c2015-03-30 21:36:43 +000027#include "llvm/IR/GVMaterializer.h"
Bill Wendling523bea82013-11-08 08:13:15 +000028#include "llvm/IR/Module.h"
Chandler Carruth4220e9c2014-03-04 11:17:44 +000029#include "llvm/IR/ValueHandle.h"
Bill Wendling523bea82013-11-08 08:13:15 +000030#include "llvm/Support/Debug.h"
31#include "llvm/Support/Dwarf.h"
Bill Wendling523bea82013-11-08 08:13:15 +000032#include "llvm/Support/raw_ostream.h"
33using namespace llvm;
34using namespace llvm::dwarf;
35
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000036DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
37 if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope))
Duncan P. N. Exon Smithdd77af82015-03-31 02:06:28 +000038 return LocalScope->getSubprogram();
39 return nullptr;
Bill Wendling523bea82013-11-08 08:13:15 +000040}
41
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000042DISubprogram *llvm::getDISubprogram(const Function *F) {
Timur Iskhodzhanoveb229ca2014-10-23 23:46:28 +000043 // We look for the first instr that has a debug annotation leading back to F.
Timur Iskhodzhanoveb229ca2014-10-23 23:46:28 +000044 for (auto &BB : *F) {
David Majnemerc758df42014-11-01 07:57:14 +000045 auto Inst = std::find_if(BB.begin(), BB.end(), [](const Instruction &Inst) {
Duncan P. N. Exon Smithab659fb32015-03-30 19:40:05 +000046 return Inst.getDebugLoc();
David Majnemerc758df42014-11-01 07:57:14 +000047 });
48 if (Inst == BB.end())
49 continue;
50 DebugLoc DLoc = Inst->getDebugLoc();
Duncan P. N. Exon Smithab659fb32015-03-30 19:40:05 +000051 const MDNode *Scope = DLoc.getInlinedAtScope();
Duncan P. N. Exon Smithed557b52015-04-17 23:20:10 +000052 auto *Subprogram = getDISubprogram(Scope);
53 return Subprogram->describes(F) ? Subprogram : nullptr;
Timur Iskhodzhanoveb229ca2014-10-23 23:46:28 +000054 }
55
Duncan P. N. Exon Smithed557b52015-04-17 23:20:10 +000056 return nullptr;
Timur Iskhodzhanoveb229ca2014-10-23 23:46:28 +000057}
58
Bill Wendling523bea82013-11-08 08:13:15 +000059DITypeIdentifierMap
60llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) {
61 DITypeIdentifierMap Map;
62 for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000063 auto *CU = cast<DICompileUnit>(CU_Nodes->getOperand(CUi));
64 DINodeArray Retain = CU->getRetainedTypes();
Duncan P. N. Exon Smith000fa2c2015-04-07 04:14:33 +000065 for (unsigned Ti = 0, Te = Retain.size(); Ti != Te; ++Ti) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000066 if (!isa<DICompositeType>(Retain[Ti]))
Bill Wendling523bea82013-11-08 08:13:15 +000067 continue;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +000068 auto *Ty = cast<DICompositeType>(Retain[Ti]);
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +000069 if (MDString *TypeId = Ty->getRawIdentifier()) {
Bill Wendling523bea82013-11-08 08:13:15 +000070 // Definition has priority over declaration.
71 // Try to insert (TypeId, Ty) to Map.
72 std::pair<DITypeIdentifierMap::iterator, bool> P =
73 Map.insert(std::make_pair(TypeId, Ty));
74 // If TypeId already exists in Map and this is a definition, replace
75 // whatever we had (declaration or definition) with the definition.
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +000076 if (!P.second && !Ty->isForwardDecl())
Bill Wendling523bea82013-11-08 08:13:15 +000077 P.first->second = Ty;
78 }
79 }
80 }
81 return Map;
82}
83
84//===----------------------------------------------------------------------===//
85// DebugInfoFinder implementations.
86//===----------------------------------------------------------------------===//
87
88void DebugInfoFinder::reset() {
89 CUs.clear();
90 SPs.clear();
91 GVs.clear();
92 TYs.clear();
93 Scopes.clear();
94 NodesSeen.clear();
95 TypeIdentifierMap.clear();
Manman Ren2085ccc2013-11-17 18:42:37 +000096 TypeMapInitialized = false;
97}
98
Manman Renb46e5502013-11-17 19:35:03 +000099void DebugInfoFinder::InitializeTypeMap(const Module &M) {
Manman Ren2085ccc2013-11-17 18:42:37 +0000100 if (!TypeMapInitialized)
101 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
102 TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
103 TypeMapInitialized = true;
104 }
Bill Wendling523bea82013-11-08 08:13:15 +0000105}
106
Bill Wendling523bea82013-11-08 08:13:15 +0000107void DebugInfoFinder::processModule(const Module &M) {
Manman Renb46e5502013-11-17 19:35:03 +0000108 InitializeTypeMap(M);
Bill Wendling523bea82013-11-08 08:13:15 +0000109 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
Bill Wendling523bea82013-11-08 08:13:15 +0000110 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000111 auto *CU = cast<DICompileUnit>(CU_Nodes->getOperand(i));
Bill Wendling523bea82013-11-08 08:13:15 +0000112 addCompileUnit(CU);
Duncan P. N. Exon Smithed557b52015-04-17 23:20:10 +0000113 for (auto *DIG : CU->getGlobalVariables()) {
Bill Wendling523bea82013-11-08 08:13:15 +0000114 if (addGlobalVariable(DIG)) {
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000115 processScope(DIG->getScope());
116 processType(DIG->getType().resolve(TypeIdentifierMap));
Bill Wendling523bea82013-11-08 08:13:15 +0000117 }
118 }
Duncan P. N. Exon Smith000fa2c2015-04-07 04:14:33 +0000119 for (auto *SP : CU->getSubprograms())
120 processSubprogram(SP);
121 for (auto *ET : CU->getEnumTypes())
122 processType(ET);
123 for (auto *RT : CU->getRetainedTypes())
124 processType(RT);
Duncan P. N. Exon Smithed557b52015-04-17 23:20:10 +0000125 for (auto *Import : CU->getImportedEntities()) {
Duncan P. N. Exon Smithde8e4272015-04-14 01:46:44 +0000126 auto *Entity = Import->getEntity().resolve(TypeIdentifierMap);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000127 if (auto *T = dyn_cast<DIType>(Entity))
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000128 processType(T);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000129 else if (auto *SP = dyn_cast<DISubprogram>(Entity))
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000130 processSubprogram(SP);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000131 else if (auto *NS = dyn_cast<DINamespace>(Entity))
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000132 processScope(NS->getScope());
Adrian Prantlab1243f2015-06-29 23:03:47 +0000133 else if (auto *M = dyn_cast<DIModule>(Entity))
134 processScope(M->getScope());
Bill Wendling523bea82013-11-08 08:13:15 +0000135 }
136 }
137 }
138}
139
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000140void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) {
Bill Wendling523bea82013-11-08 08:13:15 +0000141 if (!Loc)
142 return;
Manman Renb46e5502013-11-17 19:35:03 +0000143 InitializeTypeMap(M);
Duncan P. N. Exon Smithb7e221b2015-04-14 01:35:55 +0000144 processScope(Loc->getScope());
145 processLocation(M, Loc->getInlinedAt());
Bill Wendling523bea82013-11-08 08:13:15 +0000146}
147
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000148void DebugInfoFinder::processType(DIType *DT) {
Bill Wendling523bea82013-11-08 08:13:15 +0000149 if (!addType(DT))
150 return;
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000151 processScope(DT->getScope().resolve(TypeIdentifierMap));
Duncan P. N. Exon Smith260fa8a2015-07-24 20:56:10 +0000152 if (auto *ST = dyn_cast<DISubroutineType>(DT)) {
153 for (DITypeRef Ref : ST->getTypeArray())
154 processType(Ref.resolve(TypeIdentifierMap));
155 return;
156 }
157 if (auto *DCT = dyn_cast<DICompositeType>(DT)) {
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000158 processType(DCT->getBaseType().resolve(TypeIdentifierMap));
Anders Waldenborg1433fd42015-04-14 09:18:17 +0000159 for (Metadata *D : DCT->getElements()) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000160 if (auto *T = dyn_cast<DIType>(D))
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000161 processType(T);
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000162 else if (auto *SP = dyn_cast<DISubprogram>(D))
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000163 processSubprogram(SP);
Bill Wendling523bea82013-11-08 08:13:15 +0000164 }
Duncan P. N. Exon Smith260fa8a2015-07-24 20:56:10 +0000165 return;
166 }
167 if (auto *DDT = dyn_cast<DIDerivedType>(DT)) {
Duncan P. N. Exon Smithb1055642015-04-16 01:01:28 +0000168 processType(DDT->getBaseType().resolve(TypeIdentifierMap));
Bill Wendling523bea82013-11-08 08:13:15 +0000169 }
170}
171
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000172void DebugInfoFinder::processScope(DIScope *Scope) {
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000173 if (!Scope)
174 return;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000175 if (auto *Ty = dyn_cast<DIType>(Scope)) {
Bill Wendling523bea82013-11-08 08:13:15 +0000176 processType(Ty);
177 return;
178 }
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000179 if (auto *CU = dyn_cast<DICompileUnit>(Scope)) {
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000180 addCompileUnit(CU);
Bill Wendling523bea82013-11-08 08:13:15 +0000181 return;
182 }
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000183 if (auto *SP = dyn_cast<DISubprogram>(Scope)) {
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000184 processSubprogram(SP);
Bill Wendling523bea82013-11-08 08:13:15 +0000185 return;
186 }
187 if (!addScope(Scope))
188 return;
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000189 if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +0000190 processScope(LB->getScope());
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000191 } else if (auto *NS = dyn_cast<DINamespace>(Scope)) {
Duncan P. N. Exon Smith20caafb2015-04-14 03:01:27 +0000192 processScope(NS->getScope());
Adrian Prantlab1243f2015-06-29 23:03:47 +0000193 } else if (auto *M = dyn_cast<DIModule>(Scope)) {
194 processScope(M->getScope());
Bill Wendling523bea82013-11-08 08:13:15 +0000195 }
196}
197
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000198void DebugInfoFinder::processSubprogram(DISubprogram *SP) {
Bill Wendling523bea82013-11-08 08:13:15 +0000199 if (!addSubprogram(SP))
200 return;
Duncan P. N. Exon Smith537b4a82015-04-14 03:40:37 +0000201 processScope(SP->getScope().resolve(TypeIdentifierMap));
202 processType(SP->getType());
203 for (auto *Element : SP->getTemplateParams()) {
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000204 if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
Duncan P. N. Exon Smith20caafb2015-04-14 03:01:27 +0000205 processType(TType->getType().resolve(TypeIdentifierMap));
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000206 } else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
Duncan P. N. Exon Smith20caafb2015-04-14 03:01:27 +0000207 processType(TVal->getType().resolve(TypeIdentifierMap));
Bill Wendling523bea82013-11-08 08:13:15 +0000208 }
209 }
210}
211
Manman Ren2085ccc2013-11-17 18:42:37 +0000212void DebugInfoFinder::processDeclare(const Module &M,
213 const DbgDeclareInst *DDI) {
Duncan P. N. Exon Smithed557b52015-04-17 23:20:10 +0000214 auto *N = dyn_cast<MDNode>(DDI->getVariable());
Bill Wendling523bea82013-11-08 08:13:15 +0000215 if (!N)
216 return;
Manman Renb46e5502013-11-17 19:35:03 +0000217 InitializeTypeMap(M);
Bill Wendling523bea82013-11-08 08:13:15 +0000218
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000219 auto *DV = dyn_cast<DILocalVariable>(N);
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000220 if (!DV)
Bill Wendling523bea82013-11-08 08:13:15 +0000221 return;
222
David Blaikie70573dc2014-11-19 07:49:26 +0000223 if (!NodesSeen.insert(DV).second)
Bill Wendling523bea82013-11-08 08:13:15 +0000224 return;
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000225 processScope(DV->getScope());
226 processType(DV->getType().resolve(TypeIdentifierMap));
Bill Wendling523bea82013-11-08 08:13:15 +0000227}
228
Manman Ren2085ccc2013-11-17 18:42:37 +0000229void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
Duncan P. N. Exon Smithed557b52015-04-17 23:20:10 +0000230 auto *N = dyn_cast<MDNode>(DVI->getVariable());
Bill Wendling523bea82013-11-08 08:13:15 +0000231 if (!N)
232 return;
Manman Renb46e5502013-11-17 19:35:03 +0000233 InitializeTypeMap(M);
Bill Wendling523bea82013-11-08 08:13:15 +0000234
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000235 auto *DV = dyn_cast<DILocalVariable>(N);
Duncan P. N. Exon Smith9d1cf4c2015-04-06 23:18:49 +0000236 if (!DV)
Bill Wendling523bea82013-11-08 08:13:15 +0000237 return;
238
David Blaikie70573dc2014-11-19 07:49:26 +0000239 if (!NodesSeen.insert(DV).second)
Bill Wendling523bea82013-11-08 08:13:15 +0000240 return;
Duncan P. N. Exon Smith7348dda2015-04-14 02:22:36 +0000241 processScope(DV->getScope());
242 processType(DV->getType().resolve(TypeIdentifierMap));
Bill Wendling523bea82013-11-08 08:13:15 +0000243}
244
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000245bool DebugInfoFinder::addType(DIType *DT) {
Bill Wendling523bea82013-11-08 08:13:15 +0000246 if (!DT)
247 return false;
248
David Blaikie70573dc2014-11-19 07:49:26 +0000249 if (!NodesSeen.insert(DT).second)
Bill Wendling523bea82013-11-08 08:13:15 +0000250 return false;
251
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000252 TYs.push_back(const_cast<DIType *>(DT));
Bill Wendling523bea82013-11-08 08:13:15 +0000253 return true;
254}
255
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000256bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) {
Bill Wendling523bea82013-11-08 08:13:15 +0000257 if (!CU)
258 return false;
David Blaikie70573dc2014-11-19 07:49:26 +0000259 if (!NodesSeen.insert(CU).second)
Bill Wendling523bea82013-11-08 08:13:15 +0000260 return false;
261
262 CUs.push_back(CU);
263 return true;
264}
265
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000266bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable *DIG) {
Bill Wendling523bea82013-11-08 08:13:15 +0000267 if (!DIG)
268 return false;
269
David Blaikie70573dc2014-11-19 07:49:26 +0000270 if (!NodesSeen.insert(DIG).second)
Bill Wendling523bea82013-11-08 08:13:15 +0000271 return false;
272
273 GVs.push_back(DIG);
274 return true;
275}
276
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000277bool DebugInfoFinder::addSubprogram(DISubprogram *SP) {
Bill Wendling523bea82013-11-08 08:13:15 +0000278 if (!SP)
279 return false;
280
David Blaikie70573dc2014-11-19 07:49:26 +0000281 if (!NodesSeen.insert(SP).second)
Bill Wendling523bea82013-11-08 08:13:15 +0000282 return false;
283
284 SPs.push_back(SP);
285 return true;
286}
287
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000288bool DebugInfoFinder::addScope(DIScope *Scope) {
Bill Wendling523bea82013-11-08 08:13:15 +0000289 if (!Scope)
290 return false;
291 // FIXME: Ocaml binding generates a scope with no content, we treat it
292 // as null for now.
293 if (Scope->getNumOperands() == 0)
294 return false;
David Blaikie70573dc2014-11-19 07:49:26 +0000295 if (!NodesSeen.insert(Scope).second)
Bill Wendling523bea82013-11-08 08:13:15 +0000296 return false;
297 Scopes.push_back(Scope);
298 return true;
299}
300
Rafael Espindola0d68b4c2015-03-30 21:36:43 +0000301bool llvm::stripDebugInfo(Function &F) {
302 bool Changed = false;
Peter Collingbourned4bff302015-11-05 22:03:56 +0000303 if (F.getSubprogram()) {
304 Changed = true;
305 F.setSubprogram(nullptr);
306 }
Rafael Espindola0d68b4c2015-03-30 21:36:43 +0000307 for (BasicBlock &BB : F) {
308 for (Instruction &I : BB) {
309 if (I.getDebugLoc()) {
310 Changed = true;
311 I.setDebugLoc(DebugLoc());
312 }
313 }
314 }
315 return Changed;
316}
317
Manman Rencb14bbc2013-11-22 22:06:31 +0000318bool llvm::StripDebugInfo(Module &M) {
Manman Rencb14bbc2013-11-22 22:06:31 +0000319 bool Changed = false;
320
321 // Remove all of the calls to the debugger intrinsics, and remove them from
322 // the module.
323 if (Function *Declare = M.getFunction("llvm.dbg.declare")) {
324 while (!Declare->use_empty()) {
Chandler Carruthcdf47882014-03-09 03:16:01 +0000325 CallInst *CI = cast<CallInst>(Declare->user_back());
Manman Rencb14bbc2013-11-22 22:06:31 +0000326 CI->eraseFromParent();
327 }
328 Declare->eraseFromParent();
329 Changed = true;
330 }
331
332 if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {
333 while (!DbgVal->use_empty()) {
Chandler Carruthcdf47882014-03-09 03:16:01 +0000334 CallInst *CI = cast<CallInst>(DbgVal->user_back());
Manman Rencb14bbc2013-11-22 22:06:31 +0000335 CI->eraseFromParent();
336 }
337 DbgVal->eraseFromParent();
338 Changed = true;
339 }
340
341 for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
342 NME = M.named_metadata_end(); NMI != NME;) {
Duncan P. N. Exon Smith52888a62015-10-08 23:49:46 +0000343 NamedMDNode *NMD = &*NMI;
Manman Rencb14bbc2013-11-22 22:06:31 +0000344 ++NMI;
345 if (NMD->getName().startswith("llvm.dbg.")) {
346 NMD->eraseFromParent();
347 Changed = true;
348 }
349 }
350
Rafael Espindola0d68b4c2015-03-30 21:36:43 +0000351 for (Function &F : M)
352 Changed |= stripDebugInfo(F);
353
Rafael Espindola468b8682015-04-01 14:44:59 +0000354 if (GVMaterializer *Materializer = M.getMaterializer())
Rafael Espindola0d68b4c2015-03-30 21:36:43 +0000355 Materializer->setStripDebugInfo();
Manman Rencb14bbc2013-11-22 22:06:31 +0000356
357 return Changed;
358}
Manman Ren8b4306c2013-12-02 21:29:56 +0000359
Manman Renbd4daf82013-12-03 00:12:14 +0000360unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
David Majnemere7a9cdb2015-02-16 06:04:53 +0000361 if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
Duncan P. N. Exon Smith5bf8fef2014-12-09 18:38:53 +0000362 M.getModuleFlag("Debug Info Version")))
363 return Val->getZExtValue();
364 return 0;
Manman Ren8b4306c2013-12-02 21:29:56 +0000365}