1 //===--- DebugInfo.cpp - Debug Information Helper Classes -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the helper classes used to build and interpret debug
11 // information in LLVM IR form.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/IR/DebugInfo.h"
16 #include "LLVMContextImpl.h"
17 #include "llvm/ADT/STLExtras.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/SmallString.h"
20 #include "llvm/ADT/StringSwitch.h"
21 #include "llvm/Analysis/ValueTracking.h"
22 #include "llvm/IR/Constants.h"
23 #include "llvm/IR/DIBuilder.h"
24 #include "llvm/IR/DerivedTypes.h"
25 #include "llvm/IR/Instructions.h"
26 #include "llvm/IR/IntrinsicInst.h"
27 #include "llvm/IR/Intrinsics.h"
28 #include "llvm/IR/GVMaterializer.h"
29 #include "llvm/IR/Module.h"
30 #include "llvm/IR/ValueHandle.h"
31 #include "llvm/Support/Debug.h"
32 #include "llvm/Support/Dwarf.h"
33 #include "llvm/Support/raw_ostream.h"
35 using namespace llvm::dwarf;
37 //===----------------------------------------------------------------------===//
39 //===----------------------------------------------------------------------===//
41 unsigned DIDescriptor::getFlag(StringRef Flag) {
42 return StringSwitch<unsigned>(Flag)
43 #define HANDLE_DI_FLAG(ID, NAME) .Case("DIFlag" #NAME, Flag##NAME)
44 #include "llvm/IR/DebugInfoFlags.def"
48 const char *DIDescriptor::getFlagString(unsigned Flag) {
52 #define HANDLE_DI_FLAG(ID, NAME) \
54 return "DIFlag" #NAME;
55 #include "llvm/IR/DebugInfoFlags.def"
59 unsigned DIDescriptor::splitFlags(unsigned Flags,
60 SmallVectorImpl<unsigned> &SplitFlags) {
61 // Accessibility flags need to be specially handled, since they're packed
63 if (unsigned A = Flags & FlagAccessibility) {
65 SplitFlags.push_back(FlagPrivate);
66 else if (A == FlagProtected)
67 SplitFlags.push_back(FlagProtected);
69 SplitFlags.push_back(FlagPublic);
73 #define HANDLE_DI_FLAG(ID, NAME) \
74 if (unsigned Bit = Flags & ID) { \
75 SplitFlags.push_back(Bit); \
78 #include "llvm/IR/DebugInfoFlags.def"
83 static Metadata *getField(const MDNode *DbgNode, unsigned Elt) {
84 if (!DbgNode || Elt >= DbgNode->getNumOperands())
86 return DbgNode->getOperand(Elt);
89 static MDNode *getNodeField(const MDNode *DbgNode, unsigned Elt) {
90 return dyn_cast_or_null<MDNode>(getField(DbgNode, Elt));
93 DIDescriptor DIDescriptor::getDescriptorField(unsigned Elt) const {
94 MDNode *Field = getNodeField(DbgNode, Elt);
95 return DIDescriptor(Field);
98 /// \brief Return the size reported by the variable's type.
99 unsigned DIVariable::getSizeInBits(const DITypeIdentifierMap &Map) {
100 DIType Ty = getType().resolve(Map);
101 // Follow derived types until we reach a type that
102 // reports back a size.
103 while (isa<MDDerivedType>(Ty) && !Ty.getSizeInBits()) {
104 DIDerivedType DT = cast<MDDerivedType>(Ty);
105 Ty = DT.getTypeDerivedFrom().resolve(Map);
107 assert(Ty.getSizeInBits() && "type with size 0");
108 return Ty.getSizeInBits();
111 bool DIExpression::isBitPiece() const {
112 unsigned N = getNumElements();
113 return N >=3 && getElement(N-3) == dwarf::DW_OP_bit_piece;
116 uint64_t DIExpression::getBitPieceOffset() const {
117 assert(isBitPiece() && "not a piece");
118 return getElement(getNumElements()-2);
121 uint64_t DIExpression::getBitPieceSize() const {
122 assert(isBitPiece() && "not a piece");
123 return getElement(getNumElements()-1);
126 DIExpression::iterator DIExpression::Operand::getNext() const {
131 //===----------------------------------------------------------------------===//
132 // Simple Descriptor Constructors and other Methods
133 //===----------------------------------------------------------------------===//
135 void DIDescriptor::replaceAllUsesWith(LLVMContext &, DIDescriptor D) {
136 assert(DbgNode && "Trying to replace an unverified type!");
137 assert(DbgNode->isTemporary() && "Expected temporary node");
138 TempMDNode Temp(get());
140 // Since we use a TrackingVH for the node, its easy for clients to manufacture
141 // legitimate situations where they want to replaceAllUsesWith() on something
142 // which, due to uniquing, has merged with the source. We shield clients from
143 // this detail by allowing a value to be replaced with replaceAllUsesWith()
145 if (Temp.get() == D.get()) {
146 DbgNode = MDNode::replaceWithUniqued(std::move(Temp));
150 Temp->replaceAllUsesWith(D.get());
154 void DIDescriptor::replaceAllUsesWith(MDNode *D) {
155 assert(DbgNode && "Trying to replace an unverified type!");
156 assert(DbgNode != D && "This replacement should always happen");
157 assert(DbgNode->isTemporary() && "Expected temporary node");
158 TempMDNode Node(get());
159 Node->replaceAllUsesWith(D);
163 /// \brief Check if a value can be a reference to a type.
164 static bool isTypeRef(const Metadata *MD) {
167 if (auto *S = dyn_cast<MDString>(MD))
168 return !S->getString().empty();
169 return isa<MDType>(MD);
172 /// \brief Check if a value can be a ScopeRef.
173 static bool isScopeRef(const Metadata *MD) {
176 if (auto *S = dyn_cast<MDString>(MD))
177 return !S->getString().empty();
178 return isa<MDScope>(MD);
181 /// \brief Check if a value can be a DescriptorRef.
182 static bool isDescriptorRef(const Metadata *MD) {
185 if (auto *S = dyn_cast<MDString>(MD))
186 return !S->getString().empty();
187 return isa<MDNode>(MD);
191 void DICompositeType::setArraysHelper(MDNode *Elements, MDNode *TParams) {
192 TypedTrackingMDRef<MDCompositeTypeBase> N(get());
194 N->replaceElements(cast<MDTuple>(Elements));
196 N->replaceTemplateParams(cast<MDTuple>(TParams));
200 DIScopeRef DIScope::getRef() const { return MDScopeRef::get(get()); }
202 void DICompositeType::setContainingType(DICompositeType ContainingType) {
203 TypedTrackingMDRef<MDCompositeTypeBase> N(get());
204 N->replaceVTableHolder(MDTypeRef::get(ContainingType));
208 bool DIVariable::isInlinedFnArgument(const Function *CurFn) {
209 assert(CurFn && "Invalid function");
210 DISubprogram SP = dyn_cast<MDSubprogram>(getContext());
213 // This variable is not inlined function argument if its scope
214 // does not describe current function.
215 return !SP.describes(CurFn);
218 Function *DISubprogram::getFunction() const {
220 if (auto *C = dyn_cast_or_null<ConstantAsMetadata>(N->getFunction()))
221 return dyn_cast<Function>(C->getValue());
225 bool DISubprogram::describes(const Function *F) {
226 assert(F && "Invalid function");
227 if (F == getFunction())
229 StringRef Name = getLinkageName();
232 if (F->getName() == Name)
237 GlobalVariable *DIGlobalVariable::getGlobal() const {
238 return dyn_cast_or_null<GlobalVariable>(getConstant());
241 DIScopeRef DIScope::getContext() const {
242 if (DIType T = dyn_cast<MDType>(*this))
243 return T.getContext();
245 if (DISubprogram SP = dyn_cast<MDSubprogram>(*this))
246 return DIScopeRef(SP.getContext());
248 if (DILexicalBlock LB = dyn_cast<MDLexicalBlockBase>(*this))
249 return DIScopeRef(LB.getContext());
251 if (DINameSpace NS = dyn_cast<MDNamespace>(*this))
252 return DIScopeRef(NS.getContext());
254 assert((isa<MDFile>(*this) || isa<MDCompileUnit>(*this)) &&
255 "Unhandled type of scope.");
256 return DIScopeRef(nullptr);
259 StringRef DIScope::getName() const {
260 if (DIType T = dyn_cast<MDType>(*this))
262 if (DISubprogram SP = dyn_cast<MDSubprogram>(*this))
264 if (DINameSpace NS = dyn_cast<MDNamespace>(*this))
266 assert((isa<MDLexicalBlockBase>(*this) || isa<MDFile>(*this) ||
267 isa<MDCompileUnit>(*this)) &&
268 "Unhandled type of scope.");
272 StringRef DIScope::getFilename() const {
274 if (auto *F = N->getFile())
275 return F->getFilename();
279 StringRef DIScope::getDirectory() const {
281 if (auto *F = N->getFile())
282 return F->getDirectory();
286 void DICompileUnit::replaceSubprograms(DIArray Subprograms) {
287 get()->replaceSubprograms(cast_or_null<MDTuple>(Subprograms.get()));
290 void DICompileUnit::replaceGlobalVariables(DIArray GlobalVariables) {
291 get()->replaceGlobalVariables(cast_or_null<MDTuple>(GlobalVariables.get()));
294 DILocation DILocation::copyWithNewScope(LLVMContext &Ctx,
295 DILexicalBlockFile NewScope) {
296 assert(NewScope && "Expected valid scope");
298 const auto *Old = cast<MDLocation>(DbgNode);
299 return DILocation(MDLocation::get(Ctx, Old->getLine(), Old->getColumn(),
300 NewScope, Old->getInlinedAt()));
303 unsigned DILocation::computeNewDiscriminator(LLVMContext &Ctx) {
304 std::pair<const char *, unsigned> Key(getFilename().data(), getLineNumber());
305 return ++Ctx.pImpl->DiscriminatorTable[Key];
308 DIVariable llvm::createInlinedVariable(MDNode *DV, MDNode *InlinedScope,
309 LLVMContext &VMContext) {
310 return cast<MDLocalVariable>(DV)
311 ->withInline(cast_or_null<MDLocation>(InlinedScope));
314 DIVariable llvm::cleanseInlinedVariable(MDNode *DV, LLVMContext &VMContext) {
315 return cast<MDLocalVariable>(DV)->withoutInline();
318 DISubprogram llvm::getDISubprogram(const MDNode *Scope) {
319 if (auto *LocalScope = dyn_cast_or_null<MDLocalScope>(Scope))
320 return LocalScope->getSubprogram();
324 DISubprogram llvm::getDISubprogram(const Function *F) {
325 // We look for the first instr that has a debug annotation leading back to F.
326 for (auto &BB : *F) {
327 auto Inst = std::find_if(BB.begin(), BB.end(), [](const Instruction &Inst) {
328 return Inst.getDebugLoc();
330 if (Inst == BB.end())
332 DebugLoc DLoc = Inst->getDebugLoc();
333 const MDNode *Scope = DLoc.getInlinedAtScope();
334 DISubprogram Subprogram = getDISubprogram(Scope);
335 return Subprogram.describes(F) ? Subprogram : DISubprogram();
338 return DISubprogram();
341 DICompositeType llvm::getDICompositeType(DIType T) {
342 if (auto *C = dyn_cast_or_null<MDCompositeTypeBase>(T))
345 if (auto *D = dyn_cast_or_null<MDDerivedTypeBase>(T)) {
346 // This function is currently used by dragonegg and dragonegg does
347 // not generate identifier for types, so using an empty map to resolve
348 // DerivedFrom should be fine.
349 DITypeIdentifierMap EmptyMap;
350 return getDICompositeType(
351 DIDerivedType(D).getTypeDerivedFrom().resolve(EmptyMap));
358 llvm::generateDITypeIdentifierMap(const NamedMDNode *CU_Nodes) {
359 DITypeIdentifierMap Map;
360 for (unsigned CUi = 0, CUe = CU_Nodes->getNumOperands(); CUi != CUe; ++CUi) {
361 DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(CUi));
362 DIArray Retain = CU.getRetainedTypes();
363 for (unsigned Ti = 0, Te = Retain.getNumElements(); Ti != Te; ++Ti) {
364 if (!isa<MDCompositeType>(Retain.getElement(Ti)))
366 DICompositeType Ty = cast<MDCompositeType>(Retain.getElement(Ti));
367 if (MDString *TypeId = Ty.getIdentifier()) {
368 // Definition has priority over declaration.
369 // Try to insert (TypeId, Ty) to Map.
370 std::pair<DITypeIdentifierMap::iterator, bool> P =
371 Map.insert(std::make_pair(TypeId, Ty));
372 // If TypeId already exists in Map and this is a definition, replace
373 // whatever we had (declaration or definition) with the definition.
374 if (!P.second && !Ty.isForwardDecl())
375 P.first->second = Ty;
382 //===----------------------------------------------------------------------===//
383 // DebugInfoFinder implementations.
384 //===----------------------------------------------------------------------===//
386 void DebugInfoFinder::reset() {
393 TypeIdentifierMap.clear();
394 TypeMapInitialized = false;
397 void DebugInfoFinder::InitializeTypeMap(const Module &M) {
398 if (!TypeMapInitialized)
399 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
400 TypeIdentifierMap = generateDITypeIdentifierMap(CU_Nodes);
401 TypeMapInitialized = true;
405 void DebugInfoFinder::processModule(const Module &M) {
406 InitializeTypeMap(M);
407 if (NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu")) {
408 for (unsigned i = 0, e = CU_Nodes->getNumOperands(); i != e; ++i) {
409 DICompileUnit CU = cast<MDCompileUnit>(CU_Nodes->getOperand(i));
411 DIArray GVs = CU.getGlobalVariables();
412 for (unsigned i = 0, e = GVs.getNumElements(); i != e; ++i) {
413 DIGlobalVariable DIG = cast<MDGlobalVariable>(GVs.getElement(i));
414 if (addGlobalVariable(DIG)) {
415 processScope(DIG.getContext());
416 processType(DIG.getType().resolve(TypeIdentifierMap));
419 DIArray SPs = CU.getSubprograms();
420 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i)
421 processSubprogram(cast<MDSubprogram>(SPs.getElement(i)));
422 DIArray EnumTypes = CU.getEnumTypes();
423 for (unsigned i = 0, e = EnumTypes.getNumElements(); i != e; ++i)
424 processType(cast<MDType>(EnumTypes.getElement(i)));
425 DIArray RetainedTypes = CU.getRetainedTypes();
426 for (unsigned i = 0, e = RetainedTypes.getNumElements(); i != e; ++i)
427 processType(cast<MDType>(RetainedTypes.getElement(i)));
428 DIArray Imports = CU.getImportedEntities();
429 for (unsigned i = 0, e = Imports.getNumElements(); i != e; ++i) {
430 DIImportedEntity Import = cast<MDImportedEntity>(Imports.getElement(i));
431 DIDescriptor Entity = Import.getEntity().resolve(TypeIdentifierMap);
432 if (auto *T = dyn_cast<MDType>(Entity))
434 else if (auto *SP = dyn_cast<MDSubprogram>(Entity))
435 processSubprogram(SP);
436 else if (auto *NS = dyn_cast<MDNamespace>(Entity))
437 processScope(NS->getScope());
443 void DebugInfoFinder::processLocation(const Module &M, DILocation Loc) {
446 InitializeTypeMap(M);
447 processScope(Loc.getScope());
448 processLocation(M, Loc.getOrigLocation());
451 void DebugInfoFinder::processType(DIType DT) {
454 processScope(DT.getContext().resolve(TypeIdentifierMap));
455 if (DICompositeType DCT = dyn_cast<MDCompositeTypeBase>(DT)) {
456 processType(DCT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
457 if (DISubroutineType ST = dyn_cast<MDSubroutineType>(DCT)) {
458 DITypeArray DTA = ST.getTypeArray();
459 for (unsigned i = 0, e = DTA.getNumElements(); i != e; ++i)
460 processType(DTA.getElement(i).resolve(TypeIdentifierMap));
463 DIArray DA = DCT.getElements();
464 for (unsigned i = 0, e = DA.getNumElements(); i != e; ++i) {
465 DIDescriptor D = DA.getElement(i);
466 if (DIType T = dyn_cast<MDType>(D))
468 else if (DISubprogram SP = dyn_cast<MDSubprogram>(D))
469 processSubprogram(SP);
471 } else if (DIDerivedType DDT = dyn_cast<MDDerivedTypeBase>(DT)) {
472 processType(DDT.getTypeDerivedFrom().resolve(TypeIdentifierMap));
476 void DebugInfoFinder::processScope(DIScope Scope) {
479 if (DIType Ty = dyn_cast<MDType>(Scope)) {
483 if (DICompileUnit CU = dyn_cast<MDCompileUnit>(Scope)) {
487 if (DISubprogram SP = dyn_cast<MDSubprogram>(Scope)) {
488 processSubprogram(SP);
491 if (!addScope(Scope))
493 if (DILexicalBlock LB = dyn_cast<MDLexicalBlockBase>(Scope)) {
494 processScope(LB.getContext());
495 } else if (DINameSpace NS = dyn_cast<MDNamespace>(Scope)) {
496 processScope(NS.getContext());
500 void DebugInfoFinder::processSubprogram(DISubprogram SP) {
501 if (!addSubprogram(SP))
503 processScope(SP.getContext().resolve(TypeIdentifierMap));
504 processType(SP.getType());
505 DIArray TParams = SP.getTemplateParams();
506 for (unsigned I = 0, E = TParams.getNumElements(); I != E; ++I) {
507 DIDescriptor Element = TParams.getElement(I);
508 if (DITemplateTypeParameter TType =
509 dyn_cast<MDTemplateTypeParameter>(Element)) {
510 processType(TType.getType().resolve(TypeIdentifierMap));
511 } else if (DITemplateValueParameter TVal =
512 dyn_cast<MDTemplateValueParameter>(Element)) {
513 processType(TVal.getType().resolve(TypeIdentifierMap));
518 void DebugInfoFinder::processDeclare(const Module &M,
519 const DbgDeclareInst *DDI) {
520 MDNode *N = dyn_cast<MDNode>(DDI->getVariable());
523 InitializeTypeMap(M);
525 DIVariable DV = dyn_cast<MDLocalVariable>(N);
529 if (!NodesSeen.insert(DV).second)
531 processScope(DV.getContext());
532 processType(DV.getType().resolve(TypeIdentifierMap));
535 void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
536 MDNode *N = dyn_cast<MDNode>(DVI->getVariable());
539 InitializeTypeMap(M);
541 DIVariable DV = dyn_cast<MDLocalVariable>(N);
545 if (!NodesSeen.insert(DV).second)
547 processScope(DV.getContext());
548 processType(DV.getType().resolve(TypeIdentifierMap));
551 bool DebugInfoFinder::addType(DIType DT) {
555 if (!NodesSeen.insert(DT).second)
562 bool DebugInfoFinder::addCompileUnit(DICompileUnit CU) {
565 if (!NodesSeen.insert(CU).second)
572 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariable DIG) {
576 if (!NodesSeen.insert(DIG).second)
583 bool DebugInfoFinder::addSubprogram(DISubprogram SP) {
587 if (!NodesSeen.insert(SP).second)
594 bool DebugInfoFinder::addScope(DIScope Scope) {
597 // FIXME: Ocaml binding generates a scope with no content, we treat it
599 if (Scope->getNumOperands() == 0)
601 if (!NodesSeen.insert(Scope).second)
603 Scopes.push_back(Scope);
607 //===----------------------------------------------------------------------===//
608 // DIDescriptor: dump routines for all descriptors.
609 //===----------------------------------------------------------------------===//
611 void DIDescriptor::dump() const {
616 void DIDescriptor::print(raw_ostream &OS) const {
622 static void printDebugLoc(DebugLoc DL, raw_ostream &CommentOS,
623 const LLVMContext &Ctx) {
627 DIScope Scope = cast<MDScope>(DL.getScope());
628 // Omit the directory, because it's likely to be long and uninteresting.
629 CommentOS << Scope.getFilename();
630 CommentOS << ':' << DL.getLine();
631 if (DL.getCol() != 0)
632 CommentOS << ':' << DL.getCol();
634 DebugLoc InlinedAtDL = DL.getInlinedAt();
639 printDebugLoc(InlinedAtDL, CommentOS, Ctx);
643 void DIVariable::printExtendedName(raw_ostream &OS) const {
644 const LLVMContext &Ctx = DbgNode->getContext();
645 StringRef Res = getName();
647 OS << Res << "," << getLineNumber();
648 if (auto *InlinedAt = get()->getInlinedAt()) {
649 if (DebugLoc InlinedAtDL = InlinedAt) {
651 printDebugLoc(InlinedAtDL, OS, Ctx);
657 template <> DIRef<DIDescriptor>::DIRef(const Metadata *V) : Val(V) {
658 assert(isDescriptorRef(V) &&
659 "DIDescriptorRef should be a MDString or MDNode");
661 template <> DIRef<DIScope>::DIRef(const Metadata *V) : Val(V) {
662 assert(isScopeRef(V) && "DIScopeRef should be a MDString or MDNode");
664 template <> DIRef<DIType>::DIRef(const Metadata *V) : Val(V) {
665 assert(isTypeRef(V) && "DITypeRef should be a MDString or MDNode");
669 DIDescriptorRef DIDescriptor::getFieldAs<DIDescriptorRef>(unsigned Elt) const {
670 return DIDescriptorRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
673 DIScopeRef DIDescriptor::getFieldAs<DIScopeRef>(unsigned Elt) const {
674 return DIScopeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
676 template <> DITypeRef DIDescriptor::getFieldAs<DITypeRef>(unsigned Elt) const {
677 return DITypeRef(cast_or_null<Metadata>(getField(DbgNode, Elt)));
682 DIRef<DIDescriptor>::resolve(const DITypeIdentifierMap &Map) const {
683 return DIDescriptor(DebugNodeRef(Val).resolve(Map));
686 DIScope DIRef<DIScope>::resolve(const DITypeIdentifierMap &Map) const {
687 return MDScopeRef(Val).resolve(Map);
690 DIType DIRef<DIType>::resolve(const DITypeIdentifierMap &Map) const {
691 return MDTypeRef(Val).resolve(Map);
694 bool llvm::stripDebugInfo(Function &F) {
695 bool Changed = false;
696 for (BasicBlock &BB : F) {
697 for (Instruction &I : BB) {
698 if (I.getDebugLoc()) {
700 I.setDebugLoc(DebugLoc());
707 bool llvm::StripDebugInfo(Module &M) {
708 bool Changed = false;
710 // Remove all of the calls to the debugger intrinsics, and remove them from
712 if (Function *Declare = M.getFunction("llvm.dbg.declare")) {
713 while (!Declare->use_empty()) {
714 CallInst *CI = cast<CallInst>(Declare->user_back());
715 CI->eraseFromParent();
717 Declare->eraseFromParent();
721 if (Function *DbgVal = M.getFunction("llvm.dbg.value")) {
722 while (!DbgVal->use_empty()) {
723 CallInst *CI = cast<CallInst>(DbgVal->user_back());
724 CI->eraseFromParent();
726 DbgVal->eraseFromParent();
730 for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
731 NME = M.named_metadata_end(); NMI != NME;) {
732 NamedMDNode *NMD = NMI;
734 if (NMD->getName().startswith("llvm.dbg.")) {
735 NMD->eraseFromParent();
740 for (Function &F : M)
741 Changed |= stripDebugInfo(F);
743 if (GVMaterializer *Materializer = M.getMaterializer())
744 Materializer->setStripDebugInfo();
749 unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
750 if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
751 M.getModuleFlag("Debug Info Version")))
752 return Val->getZExtValue();
756 llvm::DenseMap<const llvm::Function *, llvm::DISubprogram>
757 llvm::makeSubprogramMap(const Module &M) {
758 DenseMap<const Function *, DISubprogram> R;
760 NamedMDNode *CU_Nodes = M.getNamedMetadata("llvm.dbg.cu");
764 for (MDNode *N : CU_Nodes->operands()) {
765 DICompileUnit CUNode = cast<MDCompileUnit>(N);
766 DIArray SPs = CUNode.getSubprograms();
767 for (unsigned i = 0, e = SPs.getNumElements(); i != e; ++i) {
768 DISubprogram SP = cast<MDSubprogram>(SPs.getElement(i));
769 if (Function *F = SP.getFunction())
770 R.insert(std::make_pair(F, SP));