1 //===--- 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 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/IR/Constants.h" 20 #include "llvm/IR/DIBuilder.h" 21 #include "llvm/IR/DerivedTypes.h" 22 #include "llvm/IR/GVMaterializer.h" 23 #include "llvm/IR/Instructions.h" 24 #include "llvm/IR/IntrinsicInst.h" 25 #include "llvm/IR/Intrinsics.h" 26 #include "llvm/IR/Module.h" 27 #include "llvm/IR/ValueHandle.h" 28 #include "llvm/Support/Debug.h" 29 #include "llvm/Support/Dwarf.h" 30 #include "llvm/Support/raw_ostream.h" 31 using namespace llvm; 32 using namespace llvm::dwarf; 33 34 DISubprogram *llvm::getDISubprogram(const MDNode *Scope) { 35 if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope)) 36 return LocalScope->getSubprogram(); 37 return nullptr; 38 } 39 40 //===----------------------------------------------------------------------===// 41 // DebugInfoFinder implementations. 42 //===----------------------------------------------------------------------===// 43 44 void DebugInfoFinder::reset() { 45 CUs.clear(); 46 SPs.clear(); 47 GVs.clear(); 48 TYs.clear(); 49 Scopes.clear(); 50 NodesSeen.clear(); 51 } 52 53 void DebugInfoFinder::processModule(const Module &M) { 54 for (auto *CU : M.debug_compile_units()) { 55 addCompileUnit(CU); 56 for (auto DIG : CU->getGlobalVariables()) { 57 if (!addGlobalVariable(DIG)) 58 continue; 59 auto *GV = DIG->getVariable(); 60 processScope(GV->getScope()); 61 processType(GV->getType().resolve()); 62 } 63 for (auto *ET : CU->getEnumTypes()) 64 processType(ET); 65 for (auto *RT : CU->getRetainedTypes()) 66 if (auto *T = dyn_cast<DIType>(RT)) 67 processType(T); 68 else 69 processSubprogram(cast<DISubprogram>(RT)); 70 for (auto *Import : CU->getImportedEntities()) { 71 auto *Entity = Import->getEntity().resolve(); 72 if (auto *T = dyn_cast<DIType>(Entity)) 73 processType(T); 74 else if (auto *SP = dyn_cast<DISubprogram>(Entity)) 75 processSubprogram(SP); 76 else if (auto *NS = dyn_cast<DINamespace>(Entity)) 77 processScope(NS->getScope()); 78 else if (auto *M = dyn_cast<DIModule>(Entity)) 79 processScope(M->getScope()); 80 } 81 } 82 for (auto &F : M.functions()) { 83 if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram())) 84 processSubprogram(SP); 85 // There could be subprograms from inlined functions referenced from 86 // instructions only. Walk the function to find them. 87 for (const BasicBlock &BB : F) { 88 for (const Instruction &I : BB) { 89 if (!I.getDebugLoc()) 90 continue; 91 processLocation(M, I.getDebugLoc().get()); 92 } 93 } 94 } 95 } 96 97 void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) { 98 if (!Loc) 99 return; 100 processScope(Loc->getScope()); 101 processLocation(M, Loc->getInlinedAt()); 102 } 103 104 void DebugInfoFinder::processType(DIType *DT) { 105 if (!addType(DT)) 106 return; 107 processScope(DT->getScope().resolve()); 108 if (auto *ST = dyn_cast<DISubroutineType>(DT)) { 109 for (DITypeRef Ref : ST->getTypeArray()) 110 processType(Ref.resolve()); 111 return; 112 } 113 if (auto *DCT = dyn_cast<DICompositeType>(DT)) { 114 processType(DCT->getBaseType().resolve()); 115 for (Metadata *D : DCT->getElements()) { 116 if (auto *T = dyn_cast<DIType>(D)) 117 processType(T); 118 else if (auto *SP = dyn_cast<DISubprogram>(D)) 119 processSubprogram(SP); 120 } 121 return; 122 } 123 if (auto *DDT = dyn_cast<DIDerivedType>(DT)) { 124 processType(DDT->getBaseType().resolve()); 125 } 126 } 127 128 void DebugInfoFinder::processScope(DIScope *Scope) { 129 if (!Scope) 130 return; 131 if (auto *Ty = dyn_cast<DIType>(Scope)) { 132 processType(Ty); 133 return; 134 } 135 if (auto *CU = dyn_cast<DICompileUnit>(Scope)) { 136 addCompileUnit(CU); 137 return; 138 } 139 if (auto *SP = dyn_cast<DISubprogram>(Scope)) { 140 processSubprogram(SP); 141 return; 142 } 143 if (!addScope(Scope)) 144 return; 145 if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) { 146 processScope(LB->getScope()); 147 } else if (auto *NS = dyn_cast<DINamespace>(Scope)) { 148 processScope(NS->getScope()); 149 } else if (auto *M = dyn_cast<DIModule>(Scope)) { 150 processScope(M->getScope()); 151 } 152 } 153 154 void DebugInfoFinder::processSubprogram(DISubprogram *SP) { 155 if (!addSubprogram(SP)) 156 return; 157 processScope(SP->getScope().resolve()); 158 processType(SP->getType()); 159 for (auto *Element : SP->getTemplateParams()) { 160 if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) { 161 processType(TType->getType().resolve()); 162 } else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) { 163 processType(TVal->getType().resolve()); 164 } 165 } 166 } 167 168 void DebugInfoFinder::processDeclare(const Module &M, 169 const DbgDeclareInst *DDI) { 170 auto *N = dyn_cast<MDNode>(DDI->getVariable()); 171 if (!N) 172 return; 173 174 auto *DV = dyn_cast<DILocalVariable>(N); 175 if (!DV) 176 return; 177 178 if (!NodesSeen.insert(DV).second) 179 return; 180 processScope(DV->getScope()); 181 processType(DV->getType().resolve()); 182 } 183 184 void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) { 185 auto *N = dyn_cast<MDNode>(DVI->getVariable()); 186 if (!N) 187 return; 188 189 auto *DV = dyn_cast<DILocalVariable>(N); 190 if (!DV) 191 return; 192 193 if (!NodesSeen.insert(DV).second) 194 return; 195 processScope(DV->getScope()); 196 processType(DV->getType().resolve()); 197 } 198 199 bool DebugInfoFinder::addType(DIType *DT) { 200 if (!DT) 201 return false; 202 203 if (!NodesSeen.insert(DT).second) 204 return false; 205 206 TYs.push_back(const_cast<DIType *>(DT)); 207 return true; 208 } 209 210 bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) { 211 if (!CU) 212 return false; 213 if (!NodesSeen.insert(CU).second) 214 return false; 215 216 CUs.push_back(CU); 217 return true; 218 } 219 220 bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) { 221 if (!NodesSeen.insert(DIG).second) 222 return false; 223 224 GVs.push_back(DIG); 225 return true; 226 } 227 228 bool DebugInfoFinder::addSubprogram(DISubprogram *SP) { 229 if (!SP) 230 return false; 231 232 if (!NodesSeen.insert(SP).second) 233 return false; 234 235 SPs.push_back(SP); 236 return true; 237 } 238 239 bool DebugInfoFinder::addScope(DIScope *Scope) { 240 if (!Scope) 241 return false; 242 // FIXME: Ocaml binding generates a scope with no content, we treat it 243 // as null for now. 244 if (Scope->getNumOperands() == 0) 245 return false; 246 if (!NodesSeen.insert(Scope).second) 247 return false; 248 Scopes.push_back(Scope); 249 return true; 250 } 251 252 static llvm::MDNode *stripDebugLocFromLoopID(llvm::MDNode *N) { 253 assert(N->op_begin() != N->op_end() && "Missing self reference?"); 254 255 // if there is no debug location, we do not have to rewrite this MDNode. 256 if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) { 257 return isa<DILocation>(Op.get()); 258 })) 259 return N; 260 261 // If there is only the debug location without any actual loop metadata, we 262 // can remove the metadata. 263 if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) { 264 return !isa<DILocation>(Op.get()); 265 })) 266 return nullptr; 267 268 SmallVector<Metadata *, 4> Args; 269 // Reserve operand 0 for loop id self reference. 270 auto TempNode = MDNode::getTemporary(N->getContext(), None); 271 Args.push_back(TempNode.get()); 272 // Add all non-debug location operands back. 273 for (auto Op = N->op_begin() + 1; Op != N->op_end(); Op++) { 274 if (!isa<DILocation>(*Op)) 275 Args.push_back(*Op); 276 } 277 278 // Set the first operand to itself. 279 MDNode *LoopID = MDNode::get(N->getContext(), Args); 280 LoopID->replaceOperandWith(0, LoopID); 281 return LoopID; 282 } 283 284 bool llvm::stripDebugInfo(Function &F) { 285 bool Changed = false; 286 if (F.getSubprogram()) { 287 Changed = true; 288 F.setSubprogram(nullptr); 289 } 290 291 llvm::DenseMap<llvm::MDNode*, llvm::MDNode*> LoopIDsMap; 292 for (BasicBlock &BB : F) { 293 for (auto II = BB.begin(), End = BB.end(); II != End;) { 294 Instruction &I = *II++; // We may delete the instruction, increment now. 295 if (isa<DbgInfoIntrinsic>(&I)) { 296 I.eraseFromParent(); 297 Changed = true; 298 continue; 299 } 300 if (I.getDebugLoc()) { 301 Changed = true; 302 I.setDebugLoc(DebugLoc()); 303 } 304 } 305 306 auto *TermInst = BB.getTerminator(); 307 if (auto *LoopID = TermInst->getMetadata(LLVMContext::MD_loop)) { 308 auto *NewLoopID = LoopIDsMap.lookup(LoopID); 309 if (!NewLoopID) 310 NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID); 311 if (NewLoopID != LoopID) 312 TermInst->setMetadata(LLVMContext::MD_loop, NewLoopID); 313 } 314 } 315 return Changed; 316 } 317 318 bool llvm::StripDebugInfo(Module &M) { 319 bool Changed = false; 320 321 for (Module::named_metadata_iterator NMI = M.named_metadata_begin(), 322 NME = M.named_metadata_end(); NMI != NME;) { 323 NamedMDNode *NMD = &*NMI; 324 ++NMI; 325 326 // We're stripping debug info, and without them, coverage information 327 // doesn't quite make sense. 328 if (NMD->getName().startswith("llvm.dbg.") || 329 NMD->getName() == "llvm.gcov") { 330 NMD->eraseFromParent(); 331 Changed = true; 332 } 333 } 334 335 for (Function &F : M) 336 Changed |= stripDebugInfo(F); 337 338 for (auto &GV : M.globals()) { 339 SmallVector<MDNode *, 1> MDs; 340 GV.getMetadata(LLVMContext::MD_dbg, MDs); 341 if (!MDs.empty()) { 342 GV.eraseMetadata(LLVMContext::MD_dbg); 343 Changed = true; 344 } 345 } 346 347 if (GVMaterializer *Materializer = M.getMaterializer()) 348 Materializer->setStripDebugInfo(); 349 350 return Changed; 351 } 352 353 namespace { 354 355 /// Helper class to downgrade -g metadata to -gline-tables-only metadata. 356 class DebugTypeInfoRemoval { 357 DenseMap<Metadata *, Metadata *> Replacements; 358 359 public: 360 /// The (void)() type. 361 MDNode *EmptySubroutineType; 362 363 private: 364 /// Remember what linkage name we originally had before stripping. If we end 365 /// up making two subprograms identical who originally had different linkage 366 /// names, then we need to make one of them distinct, to avoid them getting 367 /// uniqued. Maps the new node to the old linkage name. 368 DenseMap<DISubprogram *, StringRef> NewToLinkageName; 369 370 // TODO: Remember the distinct subprogram we created for a given linkage name, 371 // so that we can continue to unique whenever possible. Map <newly created 372 // node, old linkage name> to the first (possibly distinct) mdsubprogram 373 // created for that combination. This is not strictly needed for correctness, 374 // but can cut down on the number of MDNodes and let us diff cleanly with the 375 // output of -gline-tables-only. 376 377 public: 378 DebugTypeInfoRemoval(LLVMContext &C) 379 : EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0, 380 MDNode::get(C, {}))) {} 381 382 Metadata *map(Metadata *M) { 383 if (!M) 384 return nullptr; 385 auto Replacement = Replacements.find(M); 386 if (Replacement != Replacements.end()) 387 return Replacement->second; 388 389 return M; 390 } 391 MDNode *mapNode(Metadata *N) { return dyn_cast_or_null<MDNode>(map(N)); } 392 393 /// Recursively remap N and all its referenced children. Does a DF post-order 394 /// traversal, so as to remap bottoms up. 395 void traverseAndRemap(MDNode *N) { traverse(N); } 396 397 private: 398 // Create a new DISubprogram, to replace the one given. 399 DISubprogram *getReplacementSubprogram(DISubprogram *MDS) { 400 auto *FileAndScope = cast_or_null<DIFile>(map(MDS->getFile())); 401 StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : ""; 402 DISubprogram *Declaration = nullptr; 403 auto *Type = cast_or_null<DISubroutineType>(map(MDS->getType())); 404 DITypeRef ContainingType(map(MDS->getContainingType())); 405 auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit())); 406 auto Variables = nullptr; 407 auto TemplateParams = nullptr; 408 409 // Make a distinct DISubprogram, for situations that warrent it. 410 auto distinctMDSubprogram = [&]() { 411 return DISubprogram::getDistinct( 412 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName, 413 FileAndScope, MDS->getLine(), Type, MDS->isLocalToUnit(), 414 MDS->isDefinition(), MDS->getScopeLine(), ContainingType, 415 MDS->getVirtuality(), MDS->getVirtualIndex(), 416 MDS->getThisAdjustment(), MDS->getFlags(), MDS->isOptimized(), Unit, 417 TemplateParams, Declaration, Variables); 418 }; 419 420 if (MDS->isDistinct()) 421 return distinctMDSubprogram(); 422 423 auto *NewMDS = DISubprogram::get( 424 MDS->getContext(), FileAndScope, MDS->getName(), LinkageName, 425 FileAndScope, MDS->getLine(), Type, MDS->isLocalToUnit(), 426 MDS->isDefinition(), MDS->getScopeLine(), ContainingType, 427 MDS->getVirtuality(), MDS->getVirtualIndex(), MDS->getThisAdjustment(), 428 MDS->getFlags(), MDS->isOptimized(), Unit, TemplateParams, Declaration, 429 Variables); 430 431 StringRef OldLinkageName = MDS->getLinkageName(); 432 433 // See if we need to make a distinct one. 434 auto OrigLinkage = NewToLinkageName.find(NewMDS); 435 if (OrigLinkage != NewToLinkageName.end()) { 436 if (OrigLinkage->second == OldLinkageName) 437 // We're good. 438 return NewMDS; 439 440 // Otherwise, need to make a distinct one. 441 // TODO: Query the map to see if we already have one. 442 return distinctMDSubprogram(); 443 } 444 445 NewToLinkageName.insert({NewMDS, MDS->getLinkageName()}); 446 return NewMDS; 447 } 448 449 /// Create a new compile unit, to replace the one given 450 DICompileUnit *getReplacementCU(DICompileUnit *CU) { 451 // Drop skeleton CUs. 452 if (CU->getDWOId()) 453 return nullptr; 454 455 auto *File = cast_or_null<DIFile>(map(CU->getFile())); 456 MDTuple *EnumTypes = nullptr; 457 MDTuple *RetainedTypes = nullptr; 458 MDTuple *GlobalVariables = nullptr; 459 MDTuple *ImportedEntities = nullptr; 460 return DICompileUnit::getDistinct( 461 CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(), 462 CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(), 463 CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes, 464 RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(), 465 CU->getDWOId(), CU->getSplitDebugInlining(), 466 CU->getDebugInfoForProfiling()); 467 } 468 469 DILocation *getReplacementMDLocation(DILocation *MLD) { 470 auto *Scope = map(MLD->getScope()); 471 auto *InlinedAt = map(MLD->getInlinedAt()); 472 if (MLD->isDistinct()) 473 return DILocation::getDistinct(MLD->getContext(), MLD->getLine(), 474 MLD->getColumn(), Scope, InlinedAt); 475 return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(), 476 Scope, InlinedAt); 477 } 478 479 /// Create a new generic MDNode, to replace the one given 480 MDNode *getReplacementMDNode(MDNode *N) { 481 SmallVector<Metadata *, 8> Ops; 482 Ops.reserve(N->getNumOperands()); 483 for (auto &I : N->operands()) 484 if (I) 485 Ops.push_back(map(I)); 486 auto *Ret = MDNode::get(N->getContext(), Ops); 487 return Ret; 488 } 489 490 /// Attempt to re-map N to a newly created node. 491 void remap(MDNode *N) { 492 if (Replacements.count(N)) 493 return; 494 495 auto doRemap = [&](MDNode *N) -> MDNode * { 496 if (!N) 497 return nullptr; 498 if (auto *MDSub = dyn_cast<DISubprogram>(N)) { 499 remap(MDSub->getUnit()); 500 return getReplacementSubprogram(MDSub); 501 } 502 if (isa<DISubroutineType>(N)) 503 return EmptySubroutineType; 504 if (auto *CU = dyn_cast<DICompileUnit>(N)) 505 return getReplacementCU(CU); 506 if (isa<DIFile>(N)) 507 return N; 508 if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N)) 509 // Remap to our referenced scope (recursively). 510 return mapNode(MDLB->getScope()); 511 if (auto *MLD = dyn_cast<DILocation>(N)) 512 return getReplacementMDLocation(MLD); 513 514 // Otherwise, if we see these, just drop them now. Not strictly necessary, 515 // but this speeds things up a little. 516 if (isa<DINode>(N)) 517 return nullptr; 518 519 return getReplacementMDNode(N); 520 }; 521 Replacements[N] = doRemap(N); 522 } 523 524 /// Do the remapping traversal. 525 void traverse(MDNode *); 526 }; 527 528 } // Anonymous namespace. 529 530 void DebugTypeInfoRemoval::traverse(MDNode *N) { 531 if (!N || Replacements.count(N)) 532 return; 533 534 // To avoid cycles, as well as for efficiency sake, we will sometimes prune 535 // parts of the graph. 536 auto prune = [](MDNode *Parent, MDNode *Child) { 537 if (auto *MDS = dyn_cast<DISubprogram>(Parent)) 538 return Child == MDS->getVariables().get(); 539 return false; 540 }; 541 542 SmallVector<MDNode *, 16> ToVisit; 543 DenseSet<MDNode *> Opened; 544 545 // Visit each node starting at N in post order, and map them. 546 ToVisit.push_back(N); 547 while (!ToVisit.empty()) { 548 auto *N = ToVisit.back(); 549 if (!Opened.insert(N).second) { 550 // Close it. 551 remap(N); 552 ToVisit.pop_back(); 553 continue; 554 } 555 for (auto &I : N->operands()) 556 if (auto *MDN = dyn_cast_or_null<MDNode>(I)) 557 if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) && 558 !isa<DICompileUnit>(MDN)) 559 ToVisit.push_back(MDN); 560 } 561 } 562 563 bool llvm::stripNonLineTableDebugInfo(Module &M) { 564 bool Changed = false; 565 566 // First off, delete the debug intrinsics. 567 auto RemoveUses = [&](StringRef Name) { 568 if (auto *DbgVal = M.getFunction(Name)) { 569 while (!DbgVal->use_empty()) 570 cast<Instruction>(DbgVal->user_back())->eraseFromParent(); 571 DbgVal->eraseFromParent(); 572 Changed = true; 573 } 574 }; 575 RemoveUses("llvm.dbg.declare"); 576 RemoveUses("llvm.dbg.value"); 577 578 // Delete non-CU debug info named metadata nodes. 579 for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end(); 580 NMI != NME;) { 581 NamedMDNode *NMD = &*NMI; 582 ++NMI; 583 // Specifically keep dbg.cu around. 584 if (NMD->getName() == "llvm.dbg.cu") 585 continue; 586 } 587 588 // Drop all dbg attachments from global variables. 589 for (auto &GV : M.globals()) 590 GV.eraseMetadata(LLVMContext::MD_dbg); 591 592 DebugTypeInfoRemoval Mapper(M.getContext()); 593 auto remap = [&](llvm::MDNode *Node) -> llvm::MDNode * { 594 if (!Node) 595 return nullptr; 596 Mapper.traverseAndRemap(Node); 597 auto *NewNode = Mapper.mapNode(Node); 598 Changed |= Node != NewNode; 599 Node = NewNode; 600 return NewNode; 601 }; 602 603 // Rewrite the DebugLocs to be equivalent to what 604 // -gline-tables-only would have created. 605 for (auto &F : M) { 606 if (auto *SP = F.getSubprogram()) { 607 Mapper.traverseAndRemap(SP); 608 auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP)); 609 Changed |= SP != NewSP; 610 F.setSubprogram(NewSP); 611 } 612 for (auto &BB : F) { 613 for (auto &I : BB) { 614 auto remapDebugLoc = [&](DebugLoc DL) -> DebugLoc { 615 auto *Scope = DL.getScope(); 616 MDNode *InlinedAt = DL.getInlinedAt(); 617 Scope = remap(Scope); 618 InlinedAt = remap(InlinedAt); 619 return DebugLoc::get(DL.getLine(), DL.getCol(), Scope, InlinedAt); 620 }; 621 622 if (I.getDebugLoc() != DebugLoc()) 623 I.setDebugLoc(remapDebugLoc(I.getDebugLoc())); 624 625 // Remap DILocations in untyped MDNodes (e.g., llvm.loop). 626 SmallVector<std::pair<unsigned, MDNode *>, 2> MDs; 627 I.getAllMetadata(MDs); 628 for (auto Attachment : MDs) 629 if (auto *T = dyn_cast_or_null<MDTuple>(Attachment.second)) 630 for (unsigned N = 0; N < T->getNumOperands(); ++N) 631 if (auto *Loc = dyn_cast_or_null<DILocation>(T->getOperand(N))) 632 if (Loc != DebugLoc()) 633 T->replaceOperandWith(N, remapDebugLoc(Loc)); 634 } 635 } 636 } 637 638 // Create a new llvm.dbg.cu, which is equivalent to the one 639 // -gline-tables-only would have created. 640 for (auto &NMD : M.getNamedMDList()) { 641 SmallVector<MDNode *, 8> Ops; 642 for (MDNode *Op : NMD.operands()) 643 Ops.push_back(remap(Op)); 644 645 if (!Changed) 646 continue; 647 648 NMD.clearOperands(); 649 for (auto *Op : Ops) 650 if (Op) 651 NMD.addOperand(Op); 652 } 653 return Changed; 654 } 655 656 unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) { 657 if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>( 658 M.getModuleFlag("Debug Info Version"))) 659 return Val->getZExtValue(); 660 return 0; 661 } 662