49 if (!V->isUsedByMetadata())
59 for (
User *U : MDV->users()) {
60 if (
auto *DDI = dyn_cast<DbgDeclareInst>(U))
70 if (!V->isUsedByMetadata())
78 for (
User *U : MDV->users())
82 for (
Metadata *AL : L->getAllArgListUsers()) {
84 for (
User *U : MDV->users())
86 if (EncounteredDbgValues.
insert(DVI).second)
97 if (!V->isUsedByMetadata())
105 for (
User *U : MDV->users())
109 for (
Metadata *AL : L->getAllArgListUsers()) {
111 for (
User *U : MDV->users())
113 if (EncounteredDbgValues.
insert(DII).second)
121 if (
auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope))
135 return DILocation::get(DII->
getContext(), 0, 0, Scope, InlinedAt);
152 for (
auto *
CU : M.debug_compile_units())
153 processCompileUnit(
CU);
154 for (
auto &
F : M.functions()) {
155 if (
auto *SP = cast_or_null<DISubprogram>(
F.getSubprogram()))
166 if (!addCompileUnit(
CU))
168 for (
auto *DIG :
CU->getGlobalVariables()) {
169 if (!addGlobalVariable(DIG))
171 auto *GV = DIG->getVariable();
172 processScope(GV->getScope());
173 processType(GV->getType());
175 for (
auto *ET :
CU->getEnumTypes())
177 for (
auto *RT :
CU->getRetainedTypes())
178 if (
auto *
T = dyn_cast<DIType>(RT))
182 for (
auto *
Import :
CU->getImportedEntities()) {
183 auto *Entity =
Import->getEntity();
184 if (
auto *
T = dyn_cast<DIType>(Entity))
186 else if (
auto *SP = dyn_cast<DISubprogram>(Entity))
188 else if (
auto *NS = dyn_cast<DINamespace>(Entity))
189 processScope(NS->getScope());
190 else if (
auto *M = dyn_cast<DIModule>(Entity))
191 processScope(M->getScope());
197 if (
auto *DVI = dyn_cast<DbgVariableIntrinsic>(&
I))
200 if (
auto DbgLoc =
I.getDebugLoc())
207 processScope(Loc->getScope());
211void DebugInfoFinder::processType(
DIType *DT) {
215 if (
auto *ST = dyn_cast<DISubroutineType>(DT)) {
220 if (
auto *DCT = dyn_cast<DICompositeType>(DT)) {
221 processType(DCT->getBaseType());
223 if (
auto *
T = dyn_cast<DIType>(
D))
225 else if (
auto *SP = dyn_cast<DISubprogram>(
D))
230 if (
auto *DDT = dyn_cast<DIDerivedType>(DT)) {
231 processType(DDT->getBaseType());
235void DebugInfoFinder::processScope(
DIScope *Scope) {
238 if (
auto *Ty = dyn_cast<DIType>(Scope)) {
242 if (
auto *
CU = dyn_cast<DICompileUnit>(Scope)) {
246 if (
auto *SP = dyn_cast<DISubprogram>(Scope)) {
250 if (!addScope(Scope))
252 if (
auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
253 processScope(LB->getScope());
254 }
else if (
auto *NS = dyn_cast<DINamespace>(Scope)) {
255 processScope(NS->getScope());
256 }
else if (
auto *M = dyn_cast<DIModule>(Scope)) {
257 processScope(
M->getScope());
262 if (!addSubprogram(SP))
273 processCompileUnit(SP->getUnit());
274 processType(SP->getType());
275 for (
auto *Element : SP->getTemplateParams()) {
276 if (
auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
277 processType(TType->getType());
278 }
else if (
auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
279 processType(TVal->getType());
290 auto *DV = dyn_cast<DILocalVariable>(
N);
294 if (!NodesSeen.insert(DV).second)
296 processScope(DV->getScope());
297 processType(DV->getType());
300bool DebugInfoFinder::addType(
DIType *DT) {
304 if (!NodesSeen.insert(DT).second)
307 TYs.push_back(
const_cast<DIType *
>(DT));
314 if (!NodesSeen.insert(
CU).second)
322 if (!NodesSeen.insert(DIG).second)
333 if (!NodesSeen.insert(SP).second)
340bool DebugInfoFinder::addScope(
DIScope *Scope) {
345 if (
Scope->getNumOperands() == 0)
347 if (!NodesSeen.insert(Scope).second)
349 Scopes.push_back(Scope);
356 "Loop ID needs at least one operand");
358 "Loop ID should refer to itself");
367 else if (
Metadata *NewMD = Updater(MD))
379 MDNode *OrigLoopID =
I.getMetadata(LLVMContext::MD_loop);
383 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
391 MDNode *
N = dyn_cast_or_null<MDNode>(MD);
394 if (isa<DILocation>(
N) || Reachable.
count(
N))
398 for (
auto &OpIt :
N->operands()) {
406 return Reachable.
count(
N);
413 MDNode *
N = dyn_cast_or_null<MDNode>(MD);
416 if (isa<DILocation>(
N) || AllDILocation.
count(
N))
418 if (!DIReachable.
count(
N))
422 for (
auto &OpIt :
N->operands()) {
437 if (isa<DILocation>(MD) || AllDILocation.
count(MD))
440 if (!DIReachable.
count(MD))
443 MDNode *
N = dyn_cast_or_null<MDNode>(MD);
448 bool HasSelfRef =
false;
449 for (
unsigned i = 0; i <
N->getNumOperands(); ++i) {
452 Args.push_back(
nullptr);
453 }
else if (
A == MD) {
454 assert(i == 0 &&
"expected i==0 for self-reference");
456 Args.push_back(
nullptr);
459 Args.push_back(NewArg);
462 if (Args.empty() || (HasSelfRef && Args.size() == 1))
473 assert(!
N->operands().empty() &&
"Missing self reference?");
484 [&Visited, &DILocationReachable](
const MDOperand &Op) {
485 return isDILocationReachable(
486 Visited, DILocationReachable, Op.get());
494 [&Visited, &AllDILocation,
495 &DILocationReachable](
const MDOperand &Op) {
496 return isAllDILocation(Visited, AllDILocation,
497 DILocationReachable, Op.get());
508 bool Changed =
false;
509 if (
F.hasMetadata(LLVMContext::MD_dbg)) {
511 F.setSubprogram(
nullptr);
517 if (isa<DbgInfoIntrinsic>(&
I)) {
522 if (
I.getDebugLoc()) {
526 if (
auto *LoopID =
I.getMetadata(LLVMContext::MD_loop)) {
527 auto *NewLoopID = LoopIDsMap.
lookup(LoopID);
530 if (NewLoopID != LoopID)
531 I.setMetadata(LLVMContext::MD_loop, NewLoopID);
534 if (
I.hasMetadataOtherThanDebugLoc()) {
536 I.setMetadata(
"heapallocsite",
nullptr);
538 I.setMetadata(LLVMContext::MD_DIAssignID,
nullptr);
546 bool Changed =
false;
551 if (NMD.getName().startswith(
"llvm.dbg.") ||
552 NMD.getName() ==
"llvm.gcov") {
553 NMD.eraseFromParent();
561 for (
auto &GV : M.globals()) {
562 Changed |= GV.eraseMetadata(LLVMContext::MD_dbg);
566 Materializer->setStripDebugInfo();
574class DebugTypeInfoRemoval {
579 MDNode *EmptySubroutineType;
603 auto Replacement = Replacements.find(M);
604 if (Replacement != Replacements.end())
605 return Replacement->second;
613 void traverseAndRemap(
MDNode *
N) { traverse(
N); }
618 auto *FileAndScope = cast_or_null<DIFile>(map(MDS->
getFile()));
621 auto *
Type = cast_or_null<DISubroutineType>(map(MDS->getType()));
623 cast_or_null<DIType>(map(MDS->getContainingType()));
624 auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit()));
625 auto Variables =
nullptr;
626 auto TemplateParams =
nullptr;
629 auto distinctMDSubprogram = [&]() {
630 return DISubprogram::getDistinct(
632 FileAndScope, MDS->getLine(),
Type, MDS->getScopeLine(),
633 ContainingType, MDS->getVirtualIndex(), MDS->getThisAdjustment(),
634 MDS->getFlags(), MDS->getSPFlags(), Unit, TemplateParams, Declaration,
639 return distinctMDSubprogram();
641 auto *NewMDS = DISubprogram::get(
643 FileAndScope, MDS->getLine(),
Type, MDS->getScopeLine(), ContainingType,
644 MDS->getVirtualIndex(), MDS->getThisAdjustment(), MDS->getFlags(),
645 MDS->getSPFlags(), Unit, TemplateParams, Declaration, Variables);
647 StringRef OldLinkageName = MDS->getLinkageName();
650 auto OrigLinkage = NewToLinkageName.find(NewMDS);
651 if (OrigLinkage != NewToLinkageName.end()) {
652 if (OrigLinkage->second == OldLinkageName)
658 return distinctMDSubprogram();
661 NewToLinkageName.insert({NewMDS, MDS->getLinkageName()});
671 auto *
File = cast_or_null<DIFile>(map(
CU->getFile()));
673 MDTuple *RetainedTypes =
nullptr;
674 MDTuple *GlobalVariables =
nullptr;
675 MDTuple *ImportedEntities =
nullptr;
676 return DICompileUnit::getDistinct(
677 CU->getContext(),
CU->getSourceLanguage(), File,
CU->getProducer(),
678 CU->isOptimized(),
CU->getFlags(),
CU->getRuntimeVersion(),
680 RetainedTypes, GlobalVariables, ImportedEntities,
CU->getMacros(),
681 CU->getDWOId(),
CU->getSplitDebugInlining(),
682 CU->getDebugInfoForProfiling(),
CU->getNameTableKind(),
683 CU->getRangesBaseAddress(),
CU->getSysRoot(),
CU->getSDK());
687 auto *
Scope = map(MLD->getScope());
688 auto *InlinedAt = map(MLD->getInlinedAt());
690 return DILocation::getDistinct(MLD->
getContext(), MLD->getLine(),
691 MLD->getColumn(), Scope, InlinedAt);
692 return DILocation::get(MLD->
getContext(), MLD->getLine(), MLD->getColumn(),
700 for (
auto &
I :
N->operands())
709 if (Replacements.count(
N))
715 if (
auto *MDSub = dyn_cast<DISubprogram>(
N)) {
716 remap(MDSub->getUnit());
717 return getReplacementSubprogram(MDSub);
719 if (isa<DISubroutineType>(
N))
720 return EmptySubroutineType;
721 if (
auto *
CU = dyn_cast<DICompileUnit>(
N))
722 return getReplacementCU(
CU);
725 if (
auto *MDLB = dyn_cast<DILexicalBlockBase>(
N))
727 return mapNode(MDLB->getScope());
728 if (
auto *MLD = dyn_cast<DILocation>(
N))
729 return getReplacementMDLocation(MLD);
736 return getReplacementMDNode(
N);
738 Replacements[
N] = doRemap(
N);
747void DebugTypeInfoRemoval::traverse(
MDNode *
N) {
748 if (!
N || Replacements.count(
N))
754 if (
auto *MDS = dyn_cast<DISubprogram>(Parent))
755 return Child == MDS->getRetainedNodes().
get();
764 while (!ToVisit.
empty()) {
765 auto *
N = ToVisit.
back();
766 if (!Opened.
insert(
N).second) {
772 for (
auto &
I :
N->operands())
773 if (
auto *MDN = dyn_cast_or_null<MDNode>(
I))
774 if (!Opened.
count(MDN) && !Replacements.count(MDN) && !
prune(
N, MDN) &&
775 !isa<DICompileUnit>(MDN))
781 bool Changed =
false;
785 if (
auto *DbgVal = M.getFunction(
Name)) {
786 while (!DbgVal->use_empty())
787 cast<Instruction>(DbgVal->user_back())->eraseFromParent();
788 DbgVal->eraseFromParent();
792 RemoveUses(
"llvm.dbg.declare");
793 RemoveUses(
"llvm.dbg.label");
794 RemoveUses(
"llvm.dbg.value");
797 for (
auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
802 if (NMD->
getName() ==
"llvm.dbg.cu")
807 for (
auto &GV : M.globals())
808 GV.eraseMetadata(LLVMContext::MD_dbg);
810 DebugTypeInfoRemoval Mapper(M.getContext());
814 Mapper.traverseAndRemap(Node);
815 auto *NewNode = Mapper.mapNode(Node);
816 Changed |= Node != NewNode;
824 if (
auto *SP =
F.getSubprogram()) {
825 Mapper.traverseAndRemap(SP);
826 auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP));
827 Changed |= SP != NewSP;
828 F.setSubprogram(NewSP);
833 auto *Scope =
DL.getScope();
834 MDNode *InlinedAt =
DL.getInlinedAt();
835 Scope = remap(Scope);
836 InlinedAt = remap(InlinedAt);
842 I.setDebugLoc(remapDebugLoc(
I.getDebugLoc()));
846 if (
auto *Loc = dyn_cast_or_null<DILocation>(MD))
847 return remapDebugLoc(Loc).
get();
852 if (
I.hasMetadataOtherThanDebugLoc())
853 I.setMetadata(
"heapallocsite",
nullptr);
860 for (
auto &NMD : M.named_metadata()) {
862 for (
MDNode *Op : NMD.operands())
877 if (
auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
878 M.getModuleFlag(
"Debug Info Version")))
879 return Val->getZExtValue();
896 if (
auto *MD =
I->getMetadata(LLVMContext::MD_DIAssignID))
899 "Merging with instruction from another function not allowed");
903 if (
auto *MD =
getMetadata(LLVMContext::MD_DIAssignID))
910 for (
auto It = std::next(IDs.
begin()), End = IDs.
end(); It != End; ++It) {
926 bool MayLowerToCall =
false;
927 if (isa<CallBase>(
this)) {
928 auto *II = dyn_cast<IntrinsicInst>(
this);
933 if (!MayLowerToCall) {
962#define HANDLE_DW_LANG(ID, NAME, LOWER_BOUND, VERSION, VENDOR) \
963 case LLVMDWARFSourceLanguage##NAME: \
965#include "llvm/BinaryFormat/Dwarf.def"
972 return (DIT *)(
Ref ? unwrap<MDNode>(
Ref) :
nullptr);
1018 unwrap(
Builder)->finalizeSubprogram(unwrapDI<DISubprogram>(subprogram));
1024 LLVMBool isOptimized,
const char *Flags,
size_t FlagsLen,
1025 unsigned RuntimeVer,
const char *SplitName,
size_t SplitNameLen,
1027 LLVMBool DebugInfoForProfiling,
const char *SysRoot,
size_t SysRootLen,
1028 const char *SDK,
size_t SDKLen) {
1029 auto File = unwrapDI<DIFile>(FileRef);
1034 RuntimeVer,
StringRef(SplitName, SplitNameLen),
1036 SplitDebugInlining, DebugInfoForProfiling,
1043 size_t FilenameLen,
const char *Directory,
1044 size_t DirectoryLen) {
1051 const char *
Name,
size_t NameLen,
1052 const char *ConfigMacros,
size_t ConfigMacrosLen,
1053 const char *IncludePath,
size_t IncludePathLen,
1054 const char *APINotesFile,
size_t APINotesFileLen) {
1057 StringRef(ConfigMacros, ConfigMacrosLen),
1059 StringRef(APINotesFile, APINotesFileLen)));
1064 const char *
Name,
size_t NameLen,
1067 unwrapDI<DIScope>(ParentScope),
StringRef(
Name, NameLen), ExportSymbols));
1072 size_t NameLen,
const char *
LinkageName,
size_t LinkageNameLen,
1077 unwrapDI<DIScope>(Scope), {
Name, NameLen}, {
LinkageName, LinkageNameLen},
1078 unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty), ScopeLine,
1089 unwrapDI<DIFile>(File),
1097 unsigned Discriminator) {
1099 unwrapDI<DIFile>(File),
1110 unwrapDI<DINamespace>(NS),
1111 unwrapDI<DIFile>(File),
1124 unwrapDI<DIScope>(Scope), unwrapDI<DIImportedEntity>(ImportedEntity),
1125 unwrapDI<DIFile>(File), Line, Elts));
1131 unsigned NumElements) {
1137 unwrapDI<DIScope>(Scope), unwrapDI<DIModule>(M), unwrapDI<DIFile>(File),
1150 unwrapDI<DIScope>(Scope), unwrapDI<DINode>(Decl), unwrapDI<DIFile>(File),
1151 Line, {
Name, NameLen}, Elts));
1163 return unwrapDI<DILocation>(Location)->getLine();
1167 return unwrapDI<DILocation>(Location)->getColumn();
1171 return wrap(unwrapDI<DILocation>(Location)->
getScope());
1175 return wrap(unwrapDI<DILocation>(Location)->getInlinedAt());
1179 return wrap(unwrapDI<DIScope>(Scope)->getFile());
1183 auto Dir = unwrapDI<DIFile>(File)->getDirectory();
1189 auto Name = unwrapDI<DIFile>(File)->getFilename();
1195 if (
auto Src = unwrapDI<DIFile>(File)->getSource()) {
1207 const char *
Name,
size_t NameLen,
1208 const char *
Value,
size_t ValueLen) {
1210 unwrap(
Builder)->createMacro(unwrapDI<DIMacroFile>(ParentMacroFile), Line,
1220 unwrapDI<DIMacroFile>(ParentMacroFile), Line, unwrapDI<DIFile>(File)));
1224 const char *
Name,
size_t NameLen,
1239 unwrapDI<DIScope>(Scope), {
Name, NameLen}, unwrapDI<DIFile>(File),
1240 LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
1247 LLVMMetadataRef *Elements,
unsigned NumElements,
unsigned RunTimeLang,
1248 const char *UniqueId,
size_t UniqueIdLen) {
1252 unwrapDI<DIScope>(Scope), {
Name, NameLen}, unwrapDI<DIFile>(File),
1254 Elts, RunTimeLang, {UniqueId, UniqueIdLen}));
1262 unsigned NumSubscripts) {
1266 unwrapDI<DIType>(Ty), Subs));
1273 unsigned NumSubscripts) {
1277 unwrapDI<DIType>(Ty), Subs));
1282 size_t NameLen,
uint64_t SizeInBits,
1286 SizeInBits, Encoding,
1293 const char *
Name,
size_t NameLen) {
1295 SizeInBits, AlignInBits,
1304 unsigned NumElements,
unsigned RunTimeLang,
LLVMMetadataRef VTableHolder,
1305 const char *UniqueId,
size_t UniqueIdLen) {
1309 unwrapDI<DIScope>(Scope), {
Name, NameLen}, unwrapDI<DIFile>(File),
1311 unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang,
1312 unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen}));
1321 {
Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits,
1338 unwrapDI<DIScope>(Scope), {
Name, NameLen},
1339 unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIType>(
Type),
1346 const char *
Name,
size_t NameLen,
1352 {
Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1353 SizeInBits, AlignInBits, OffsetInBits,
1355 unwrapDI<MDNode>(PropertyNode)));
1360 const char *
Name,
size_t NameLen,
1362 const char *GetterName,
size_t GetterNameLen,
1363 const char *SetterName,
size_t SetterNameLen,
1364 unsigned PropertyAttributes,
1367 {
Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1368 {GetterName, GetterNameLen}, {SetterName, SetterNameLen},
1369 PropertyAttributes, unwrapDI<DIType>(Ty)));
1380 const char *
Name,
size_t NameLen,
1384 unwrapDI<DIType>(
Type), {
Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
1385 unwrapDI<DIScope>(Scope), AlignInBits));
1394 unwrapDI<DIType>(Ty), unwrapDI<DIType>(
BaseTy),
1403 const char *UniqueIdentifier,
size_t UniqueIdentifierLen) {
1405 Tag, {
Name, NameLen}, unwrapDI<DIScope>(Scope),
1406 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1407 AlignInBits, {UniqueIdentifier, UniqueIdentifierLen}));
1416 size_t UniqueIdentifierLen) {
1418 Tag, {
Name, NameLen}, unwrapDI<DIScope>(Scope),
1419 unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
1421 {UniqueIdentifier, UniqueIdentifierLen}));
1428 unwrapDI<DIType>(
Type)));
1435 unwrapDI<DIType>(
Type)));
1451 unwrapDI<DIType>(PointeeType),
1452 unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits,
1459 const char *
Name,
size_t NameLen,
1466 unwrapDI<DIScope>(Scope), {
Name, NameLen},
1467 unwrapDI<DIFile>(File), LineNumber,
1468 SizeInBits, OffsetInBits, StorageOffsetInBits,
1479 const char *UniqueIdentifier,
size_t UniqueIdentifierLen) {
1483 unwrapDI<DIScope>(Scope), {
Name, NameLen},
1484 unwrapDI<DIFile>(File), LineNumber,
1485 SizeInBits, AlignInBits, OffsetInBits,
1487 Elts, unwrapDI<DIType>(VTableHolder),
1488 unwrapDI<MDNode>(TemplateParamsNode),
1489 {UniqueIdentifier, UniqueIdentifierLen}));
1499 return unwrapDI<DINode>(MD)->getTag();
1503 StringRef Str = unwrap<DIType>(DType)->getName();
1509 return unwrapDI<DIType>(DType)->getSizeInBits();
1513 return unwrapDI<DIType>(DType)->getOffsetInBits();
1517 return unwrapDI<DIType>(DType)->getAlignInBits();
1521 return unwrapDI<DIType>(DType)->getLine();
1539 unsigned NumParameterTypes,
1542 NumParameterTypes});
1561 size_t NameLen,
const char *Linkage,
size_t LinkLen,
LLVMMetadataRef File,
1565 unwrapDI<DIScope>(Scope), {
Name, NameLen}, {Linkage, LinkLen},
1566 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1567 true, unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl),
1568 nullptr, AlignInBits));
1572 return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getVariable());
1577 return wrap(unwrapDI<DIGlobalVariableExpression>(GVE)->getExpression());
1581 return wrap(unwrapDI<DIVariable>(Var)->getFile());
1589 return unwrapDI<DIVariable>(Var)->getLine();
1604 auto *
Node = unwrapDI<MDNode>(TargetMetadata);
1605 Node->replaceAllUsesWith(
unwrap(Replacement));
1611 size_t NameLen,
const char *Linkage,
size_t LnkLen,
LLVMMetadataRef File,
1615 unwrapDI<DIScope>(Scope), {
Name, NameLen}, {Linkage, LnkLen},
1616 unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit,
1617 unwrapDI<MDNode>(Decl),
nullptr, AlignInBits));
1625 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1626 unwrap<DIExpression>(Expr), unwrap<DILocation>(
DL),
1627 unwrap<Instruction>(Instr)));
1634 unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
1635 unwrap<DIExpression>(Expr), unwrap<DILocation>(
DL),
1646 unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1647 unwrap<DIExpression>(Expr), unwrap<DILocation>(
DebugLoc),
1648 unwrap<Instruction>(Instr)));
1658 unwrap(Val), unwrap<DILocalVariable>(VarInfo),
1659 unwrap<DIExpression>(Expr), unwrap<DILocation>(
DebugLoc),
1668 unwrap<DIScope>(Scope), {
Name, NameLen}, unwrap<DIFile>(File),
1669 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1675 size_t NameLen,
unsigned ArgNo,
LLVMMetadataRef File,
unsigned LineNo,
1678 unwrap<DIScope>(Scope), {
Name, NameLen}, ArgNo, unwrap<DIFile>(File),
1679 LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
1684 int64_t
Lo, int64_t Count) {
1700 unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
1704 return unwrapDI<DISubprogram>(Subprogram)->getLine();
1713 unwrap<Instruction>(Inst)->setDebugLoc(
DebugLoc(unwrap<MDNode>(Loc)));
1715 unwrap<Instruction>(Inst)->setDebugLoc(
DebugLoc());
1720#define HANDLE_METADATA_LEAF(CLASS) \
1721 case Metadata::CLASS##Kind: \
1722 return (LLVMMetadataKind)LLVM##CLASS##MetadataKind;
1723#include "llvm/IR/Metadata.def"
1730 assert(
ID &&
"Expected non-null ID");
1734 auto MapIt = Map.find(
ID);
1735 if (MapIt == Map.end())
1738 return make_range(MapIt->second.begin(), MapIt->second.end());
1742 assert(
ID &&
"Expected non-null ID");
1752 return make_range(IDAsValue->user_begin(), IDAsValue->user_end());
1760 for (
auto *DAI : ToDelete)
1761 DAI->eraseFromParent();
1766 if (
auto *OldIDAsValue =
1769 OldIDAsValue->replaceAllUsesWith(NewIDAsValue);
1778 for (
auto *
I : InstVec)
1779 I->setMetadata(LLVMContext::MD_DIAssignID, New);
1786 if (
auto *DAI = dyn_cast<DbgAssignIntrinsic>(&
I))
1789 I.setMetadata(LLVMContext::MD_DIAssignID,
nullptr);
1792 for (
auto *DAI : ToDelete)
1793 DAI->eraseFromParent();
1798static std::optional<AssignmentInfo>
1801 APInt GEPOffset(
DL.getIndexTypeSizeInBits(StoreDest->
getType()), 0);
1803 DL, GEPOffset,
true);
1807 return std::nullopt;
1808 if (
const auto *Alloca = dyn_cast<AllocaInst>(
Base))
1810 return std::nullopt;
1815 const Value *StoreDest =
I->getRawDest();
1817 auto *ConstLengthInBytes = dyn_cast<ConstantInt>(
I->getLength());
1818 if (!ConstLengthInBytes)
1820 return std::nullopt;
1821 uint64_t SizeInBits = 8 * ConstLengthInBytes->getZExtValue();
1827 const Value *StoreDest =
SI->getPointerOperand();
1828 uint64_t SizeInBits =
DL.getTypeSizeInBits(
SI->getValueOperand()->getType());
1841 auto *
ID = StoreLikeInst.
getMetadata(LLVMContext::MD_DIAssignID);
1842 assert(
ID &&
"Store instruction must have DIAssignID metadata");
1847 if (!
Info.StoreToWholeAlloca) {
1850 assert(R.has_value() &&
"failed to create fragment expression");
1856 AddrExpr, VarRec.
DL);
1860#define DEBUG_TYPE "assignment-tracking"
1869 auto &Ctx = Start->getContext();
1870 auto &
Module = *Start->getModule();
1878 for (
auto BBI = Start; BBI != End; ++BBI) {
1881 std::optional<AssignmentInfo>
Info;
1882 Value *ValueComponent =
nullptr;
1883 Value *DestComponent =
nullptr;
1884 if (
auto *AI = dyn_cast<AllocaInst>(&
I)) {
1889 ValueComponent = Undef;
1891 }
else if (
auto *
SI = dyn_cast<StoreInst>(&
I)) {
1893 ValueComponent =
SI->getValueOperand();
1894 DestComponent =
SI->getPointerOperand();
1895 }
else if (
auto *
MI = dyn_cast<MemTransferInst>(&
I)) {
1898 ValueComponent = Undef;
1899 DestComponent =
MI->getOperand(0);
1900 }
else if (
auto *
MI = dyn_cast<MemSetInst>(&
I)) {
1904 auto *ConstValue = dyn_cast<ConstantInt>(
MI->getOperand(1));
1905 if (ConstValue && ConstValue->isZero())
1906 ValueComponent = ConstValue;
1908 ValueComponent = Undef;
1909 DestComponent =
MI->getOperand(0);
1915 assert(ValueComponent && DestComponent);
1919 if (!
Info.has_value()) {
1922 <<
" | SKIP: Untrackable store (e.g. through non-const gep)\n");
1928 auto LocalIt = Vars.
find(
Info->Base);
1929 if (LocalIt == Vars.
end()) {
1932 <<
" | SKIP: Base address not associated with local variable\n");
1937 cast_or_null<DIAssignID>(
I.getMetadata(LLVMContext::MD_DIAssignID));
1940 I.setMetadata(LLVMContext::MD_DIAssignID,
ID);
1943 for (
const VarRecord &R : LocalIt->second) {
1953bool AssignmentTrackingPass::runOnFunction(
Function &
F) {
1954 bool Changed =
false;
1962 for (
auto &BB :
F) {
1963 for (
auto &
I : BB) {
1974 DbgDeclares[Alloca].
insert(DDI);
1980 auto DL = std::make_unique<DataLayout>(
F.getParent());
1993 for (
auto &
P : DbgDeclares) {
2014 "debug-info-assignment-tracking";
2024 return Value && !cast<ConstantAsMetadata>(
Value)->getValue()->isZeroValue();
2033 if (!runOnFunction(
F))
2050 bool Changed =
false;
2052 Changed |= runOnFunction(
F);
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
Analysis containing CSE Info
This file contains the declarations for the subclasses of Constant, which represent the different fla...
static DIImportedEntity * createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, Metadata *NS, DIFile *File, unsigned Line, StringRef Name, DINodeArray Elements, SmallVectorImpl< TrackingMDNodeRef > &AllImportedModules)
static DISubprogram * getSubprogram(bool IsDistinct, Ts &&...Args)
static void setAssignmentTrackingModuleFlag(Module &M)
static std::optional< AssignmentInfo > getAssignmentInfoImpl(const DataLayout &DL, const Value *StoreDest, uint64_t SizeInBits)
Collect constant properies (base, size, offset) of StoreDest.
static DISubprogram::DISPFlags pack_into_DISPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized)
static Metadata * stripLoopMDLoc(const SmallPtrSetImpl< Metadata * > &AllDILocation, const SmallPtrSetImpl< Metadata * > &DIReachable, Metadata *MD)
static MDNode * updateLoopMetadataDebugLocationsImpl(MDNode *OrigLoopID, function_ref< Metadata *(Metadata *)> Updater)
static MDNode * stripDebugLocFromLoopID(MDNode *N)
static CallInst * emitDbgAssign(AssignmentInfo Info, Value *Val, Value *Dest, Instruction &StoreLikeInst, const VarRecord &VarRec, DIBuilder &DIB)
static const char * AssignmentTrackingModuleFlag
static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags)
static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang)
static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags)
static bool getAssignmentTrackingModuleFlag(const Module &M)
static bool isAllDILocation(SmallPtrSetImpl< Metadata * > &Visited, SmallPtrSetImpl< Metadata * > &AllDILocation, const SmallPtrSetImpl< Metadata * > &DIReachable, Metadata *MD)
static bool isDILocationReachable(SmallPtrSetImpl< Metadata * > &Visited, SmallPtrSetImpl< Metadata * > &Reachable, Metadata *MD)
Return true if a node is a DILocation or if a DILocation is indirectly referenced by one of the node'...
DIT * unwrapDI(LLVMMetadataRef Ref)
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
static DebugLoc getDebugLoc(MachineBasicBlock::instr_iterator FirstMI, MachineBasicBlock::instr_iterator LastMI)
Return the first found DebugLoc that has a DILocation, given a range of instructions.
Module.h This file contains the declarations for the Module class.
This header defines various interfaces for pass management in LLVM.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static SPIRV::Scope::Scope getScope(SyncScope::ID Ord)
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
static uint32_t getFlags(const Symbol *Sym)
Class for arbitrary precision integers.
uint64_t getLimitedValue(uint64_t Limit=UINT64_MAX) const
If this value is smaller than the specified limit, return it, otherwise return the limit value.
an instruction to allocate memory on the stack
Type * getAllocatedType() const
Return the type that is being allocated by the instruction.
A container for analyses that lazily runs them and caches their results.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
LLVM Basic Block Representation.
Represents analyses that only rely on functions' control flow.
This class represents a function call, abstracting a target machine's calling convention.
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
static DIAssignID * getDistinct(LLVMContext &Context)
DbgAssignIntrinsic * insertDbgAssign(Instruction *LinkedInstr, Value *Val, DILocalVariable *SrcVar, DIExpression *ValExpr, Value *Addr, DIExpression *AddrExpr, const DILocation *DL)
Insert a new llvm.dbg.assign intrinsic call.
unsigned getNumElements() const
static std::optional< DIExpression * > createFragmentExpression(const DIExpression *Expr, unsigned OffsetInBits, unsigned SizeInBits)
Create a DIExpression to describe one part of an aggregate variable that is fragmented across multipl...
A pair of DIGlobalVariable and DIExpression.
DISubprogram * getSubprogram() const
Get the subprogram for this scope.
static const DILocation * getMergedLocation(const DILocation *LocA, const DILocation *LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
Tagged DWARF-like metadata node.
Base class for scope-like contexts.
StringRef getName() const
DIScope * getScope() const
static DISPFlags toSPFlags(bool IsLocalToUnit, bool IsDefinition, bool IsOptimized, unsigned Virtuality=SPFlagNonvirtual, bool IsMainSubprogram=false)
DISPFlags
Debug info subprogram flags.
Type array for a subprogram.
DIScope * getScope() const
A parsed version of the target data layout string in and methods for querying it.
This represents the llvm.dbg.assign instruction.
This represents the llvm.dbg.declare instruction.
Value * getAddress() const
This represents the llvm.dbg.value instruction.
This is the common base class for debug info intrinsics for variables.
DILocalVariable * getVariable() const
DIExpression * getExpression() const
void processVariable(const Module &M, const DbgVariableIntrinsic &DVI)
Process DbgVariableIntrinsic.
void processInstruction(const Module &M, const Instruction &I)
Process a single instruction and collect debug info anchors.
void processModule(const Module &M)
Process entire module and collect debug info anchors.
void processSubprogram(DISubprogram *SP)
Process subprogram.
void processLocation(const Module &M, const DILocation *Loc)
Process debug info location.
void reset()
Clear all lists.
MDNode * getScope() const
DILocation * getInlinedAt() const
Identifies a unique instance of a variable.
ValueT lookup(const_arg_type_t< KeyT > Val) const
lookup - Return the entry for the specified key, or a default constructed value if no such entry exis...
iterator find(const_arg_type_t< KeyT > Val)
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Implements a dense probed hash-table based set.
BasicBlockListType::iterator iterator
DISubprogram * getSubprogram() const
Get the attached subprogram.
void mergeDIAssignID(ArrayRef< const Instruction * > SourceInstructions)
Merge the DIAssignID metadata from this instruction and those attached to instructions in SourceInstr...
void dropLocation()
Drop the instruction's debug location.
const DebugLoc & getDebugLoc() const
Return the debug location for this node as a DebugLoc.
const Function * getFunction() const
Return the function this instruction belongs to.
MDNode * getMetadata(unsigned KindID) const
Get the metadata of given kind attached to this Instruction.
void applyMergedLocation(const DILocation *LocA, const DILocation *LocB)
Merge 2 debug locations and apply it to the Instruction.
void setMetadata(unsigned KindID, MDNode *Node)
Set the metadata of the specified kind to the specified node.
void updateLocationAfterHoist()
Updates the debug location given that the instruction has been hoisted from a block to a predecessor ...
SymbolTableList< Instruction >::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void setDebugLoc(DebugLoc Loc)
Set the debug location information for this instruction.
static bool mayLowerToFunctionCall(Intrinsic::ID IID)
Check if the intrinsic might lower into a regular function call in the course of IR transformations.
DenseMap< DIAssignID *, SmallVector< Instruction *, 1 > > AssignmentIDToInstrs
Map DIAssignID -> Instructions with that attachment.
This is an important class for using LLVM in a threaded context.
LLVMContextImpl *const pImpl
void replaceOperandWith(unsigned I, Metadata *New)
Replace a specific operand.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static void deleteTemporary(MDNode *N)
Deallocate a node created by getTemporary.
const MDOperand & getOperand(unsigned I) const
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned getNumOperands() const
Return number of MDNode operands.
LLVMContext & getContext() const
Tracking metadata reference owned by Metadata.
static TempMDTuple getTemporary(LLVMContext &Context, ArrayRef< Metadata * > MDs)
Return a temporary node.
This is the common base class for memset/memcpy/memmove.
A Module instance is used to store all the information related to an LLVM module.
@ Max
Takes the max of the two values, which are required to be integers.
StringRef getName() const
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void preserveSet()
Mark an analysis set as preserved.
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
size_type count(ConstPtrType Ptr) const
count - Return 1 if the specified pointer is in the set, 0 otherwise.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void reserve(size_type N)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An instruction for storing to memory.
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
TinyPtrVector - This class is specialized for cases where there are normally 0 or 1 element in a vect...
void push_back(EltTy NewVal)
The instances of the Type class are immutable: once they are created, they are never changed.
static IntegerType * getInt1Ty(LLVMContext &C)
static UndefValue * get(Type *T)
Static factory methods - Return an 'undef' object of the specified type.
LLVM Value Representation.
Type * getType() const
All values are typed, get the type of this value.
const Value * stripAndAccumulateConstantOffsets(const DataLayout &DL, APInt &Offset, bool AllowNonInbounds, bool AllowInvariantGroup=false, function_ref< bool(Value &Value, APInt &Offset)> ExternalAnalysis=nullptr) const
Accumulate the constant offset this value has compared to a base pointer.
const Value * stripPointerCasts() const
Strip off pointer casts, all-zero GEPs and address space casts.
LLVMContext & getContext() const
All values hold a context through their type.
user_iterator_impl< User > user_iterator
std::pair< iterator, bool > insert(const ValueT &V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
An efficient, type-erasing, non-owning reference to a callable.
A range adaptor for a pair of iterators.
LLVMMetadataRef LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode)
Create debugging information entry for Objective-C instance variable.
LLVMMetadataRef LLVMDILocationGetInlinedAt(LLVMMetadataRef Location)
Get the "inline at" location associated with this debug location.
LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Insert a new llvm.dbg.value intrinsic call at the end of the given basic block.
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements)
Create an array of DI Nodes.
LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef ClassTy)
Create debugging information entry for an enumeration.
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef M, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements, unsigned NumElements)
Create a descriptor for an imported module.
LLVMMetadataRef LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type)
Create a uniqued DIType* clone with FlagObjectPointer and FlagArtificial set.
uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType)
Get the size of this DIType in bits.
LLVMDWARFMacinfoRecordType
Describes the kind of macro declaration used for LLVMDIBuilderCreateMacro.
LLVMMetadataRef LLVMDIBuilderCreateFunction(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *LinkageName, size_t LinkageNameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool IsLocalToUnit, LLVMBool IsDefinition, unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized)
Create a new descriptor for the specified subprogram.
LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder, LLVMValueRef Val, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Insert a new llvm.dbg.value intrinsic call before the given instruction.
LLVMMetadataRef LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Type)
Create debugging information entry for a bit field member.
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetVariable(LLVMMetadataRef GVE)
Retrieves the DIVariable associated with this global variable expression.
LLVMMetadataRef LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder, LLVMMetadataRef Type)
Create a uniqued DIType* clone with FlagArtificial set.
void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder)
Construct any deferred debug info descriptors.
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Discriminator)
Create a descriptor for a lexical block with a new file attached.
unsigned LLVMDISubprogramGetLine(LLVMMetadataRef Subprogram)
Get the line associated with a given subprogram.
LLVMMetadataRef LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen)
Create a DWARF unspecified type.
LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, LLVMBool ExportSymbols)
Creates a new descriptor for a namespace with the specified parent scope.
LLVMMetadataRef LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line, unsigned Column, LLVMMetadataRef Scope, LLVMMetadataRef InlinedAt)
Creates a new DebugLocation that describes a source location.
uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType)
Get the alignment of this DIType in bits.
LLVMMetadataRef LLVMDIGlobalVariableExpressionGetExpression(LLVMMetadataRef GVE)
Retrieves the DIExpression associated with this global variable expression.
LLVMMetadataRef LLVMDIVariableGetScope(LLVMMetadataRef Var)
Get the metadata of the scope associated with a given variable.
LLVMMetadataRef LLVMInstructionGetDebugLoc(LLVMValueRef Inst)
Get the debug location for the given instruction.
LLVMMetadataRef LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a c++ style reference or rvalue reference type.
LLVMMetadataRef LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope, const char *Name, size_t NameLen, const char *ConfigMacros, size_t ConfigMacrosLen, const char *IncludePath, size_t IncludePathLen, const char *APINotesFile, size_t APINotesFileLen)
Creates a new descriptor for a module with the specified parent scope.
LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M)
Construct a builder for a module, and do not allow for unresolved nodes attached to the module.
void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP)
Set the subprogram attached to a function.
LLVMDWARFSourceLanguage
Source languages known by DWARF.
LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder, int64_t LowerBound, int64_t Count)
Create a descriptor for a value range.
LLVMDIBuilderRef LLVMCreateDIBuilder(LLVMModuleRef M)
Construct a builder for a module and collect unresolved nodes attached to the module in order to reso...
void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode)
Deallocate a temporary node.
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location)
Get the local scope associated with this debug location.
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef NS, LLVMMetadataRef File, unsigned Line)
Create a descriptor for an imported namespace.
LLVMMetadataRef LLVMDIBuilderCreateTempMacroFile(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentMacroFile, unsigned Line, LLVMMetadataRef File)
Create debugging information temporary entry for a macro file.
void LLVMInstructionSetDebugLoc(LLVMValueRef Inst, LLVMMetadataRef Loc)
Set the debug location for the given instruction.
LLVMMetadataRef LLVMDIBuilderCreateEnumerator(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, int64_t Value, LLVMBool IsUnsigned)
Create debugging information entry for an enumerator.
LLVMValueRef LLVMDIBuilderInsertDeclareBefore(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMValueRef Instr)
Insert a new llvm.dbg.declare intrinsic call before the given instruction.
LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder, uint64_t *Addr, size_t Length)
Create a new descriptor for the specified variable which has a complex address expression for its add...
LLVMMetadataRef LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts)
Create debugging information entry for a vector type.
LLVMMetadataRef LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeType, LLVMMetadataRef ClassType, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags)
Create debugging information entry for a pointer to member.
unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location)
Get the column number of this debug location.
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo, LLVMMetadataRef Expr, LLVMMetadataRef DebugLoc, LLVMBasicBlockRef Block)
Insert a new llvm.dbg.declare intrinsic call at the end of the given basic block.
LLVMDIFlags
Debug info flags.
LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits)
Create a new descriptor for a local auto variable.
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data, size_t NumElements)
Create a new temporary MDNode.
LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType)
Get the flags associated with this DIType.
const char * LLVMDIFileGetDirectory(LLVMMetadataRef File, unsigned *Len)
Get the directory of a given file.
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TempTargetMetadata, LLVMMetadataRef Replacement)
Replace all uses of temporary metadata.
const char * LLVMDIFileGetFilename(LLVMMetadataRef File, unsigned *Len)
Get the name of a given file.
unsigned LLVMDebugMetadataVersion(void)
The current debug metadata version number.
unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef Module)
The version of debug metadata that's present in the provided Module.
unsigned LLVMDITypeGetLine(LLVMMetadataRef DType)
Get the source line where this DIType is declared.
LLVMMetadataRef LLVMDIVariableGetFile(LLVMMetadataRef Var)
Get the metadata of the file associated with a given variable.
LLVMMetadataRef LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef ImportedEntity, LLVMMetadataRef File, unsigned Line, LLVMMetadataRef *Elements, unsigned NumElements)
Create a descriptor for an imported module that aliases another imported entity descriptor.
LLVMMetadataRef LLVMDIBuilderCreateStaticMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal, uint32_t AlignInBits)
Create debugging information entry for a C++ static data member.
uint16_t LLVMGetDINodeTag(LLVMMetadataRef MD)
Get the dwarf::Tag of a DINode.
LLVMMetadataRef LLVMDIBuilderCreateGlobalVariableExpression(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Expr, LLVMMetadataRef Decl, uint32_t AlignInBits)
Create a new descriptor for the specified variable.
LLVMMetadataRef LLVMDIBuilderCreateTempGlobalVariableFwdDecl(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, const char *Linkage, size_t LnkLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, LLVMMetadataRef Decl, uint32_t AlignInBits)
Create a new descriptor for the specified global variable that is temporary and meant to be RAUWed.
LLVMMetadataRef LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag, LLVMMetadataRef Type)
Create debugging information entry for a qualified type, e.g.
LLVMMetadataKind LLVMGetMetadataKind(LLVMMetadataRef Metadata)
Obtain the enumerated type of a Metadata instance.
LLVMMetadataRef LLVMDIBuilderCreateUnionType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, const char *UniqueId, size_t UniqueIdLen)
Create debugging information entry for a union.
LLVMMetadataRef LLVMDIBuilderCreateForwardDecl(LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, const char *UniqueIdentifier, size_t UniqueIdentifierLen)
Create a permanent forward-declared type.
LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags)
Create a new descriptor for a function parameter variable.
LLVMMetadataRef LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder, LLVMMetadataRef File, LLVMMetadataRef *ParameterTypes, unsigned NumParameterTypes, LLVMDIFlags Flags)
Create subroutine type.
LLVMMetadataRef LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, const char *GetterName, size_t GetterNameLen, const char *SetterName, size_t SetterNameLen, unsigned PropertyAttributes, LLVMMetadataRef Ty)
Create debugging information entry for Objective-C property.
LLVMMetadataRef LLVMDIBuilderCreateMacro(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentMacroFile, unsigned Line, LLVMDWARFMacinfoRecordType RecordType, const char *Name, size_t NameLen, const char *Value, size_t ValueLen)
Create debugging information entry for a macro.
LLVMDWARFEmissionKind
The amount of debug information to emit.
LLVMMetadataRef LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size, uint32_t AlignInBits, LLVMMetadataRef Ty, LLVMMetadataRef *Subscripts, unsigned NumSubscripts)
Create debugging information entry for an array.
LLVMMetadataRef LLVMDIScopeGetFile(LLVMMetadataRef Scope)
Get the metadata of the file associated with a given scope.
void LLVMDIBuilderFinalizeSubprogram(LLVMDIBuilderRef Builder, LLVMMetadataRef Subprogram)
Finalize a specific subprogram.
LLVMMetadataRef LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder, uint64_t Value)
Create a new descriptor for the specified variable that does not have an address, but does have a con...
LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode, const char *UniqueIdentifier, size_t UniqueIdentifierLen)
Create debugging information entry for a class.
LLVMMetadataRef LLVMDIBuilderCreateMemberType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags, LLVMMetadataRef Ty)
Create debugging information entry for a member.
unsigned LLVMDILocationGetLine(LLVMMetadataRef Location)
Get the line number of this debug location.
LLVMMetadataRef LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder)
Create C++11 nullptr type.
LLVMMetadataRef LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder, LLVMMetadataRef Ty, LLVMMetadataRef BaseTy, uint64_t BaseOffset, uint32_t VBPtrOffset, LLVMDIFlags Flags)
Create debugging information entry to establish inheritance relationship between two types.
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang, LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen, LLVMBool isOptimized, const char *Flags, size_t FlagsLen, unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen, LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining, LLVMBool DebugInfoForProfiling, const char *SysRoot, size_t SysRootLen, const char *SDK, size_t SDKLen)
A CompileUnit provides an anchor for all debugging information generated during this instance of comp...
LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef Module)
Strip debug info in the module if it exists.
LLVMMetadataRef LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name, size_t NameLen, uint64_t SizeInBits, LLVMDWARFTypeEncoding Encoding, LLVMDIFlags Flags)
Create debugging information entry for a basic type.
unsigned LLVMDIVariableGetLine(LLVMMetadataRef Var)
Get the source line where this DIVariable is declared.
unsigned LLVMDWARFTypeEncoding
An LLVM DWARF type encoding.
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned Column)
Create a descriptor for a lexical block with the specified parent context.
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder, LLVMMetadataRef *Data, size_t NumElements)
Create a type array.
LLVMMetadataRef LLVMDIBuilderCreateReplaceableCompositeType(LLVMDIBuilderRef Builder, unsigned Tag, const char *Name, size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line, unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, const char *UniqueIdentifier, size_t UniqueIdentifierLen)
Create a temporary forward-declared type.
const char * LLVMDIFileGetSource(LLVMMetadataRef File, unsigned *Len)
Get the source of a given file.
uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType)
Get the offset of this DIType in bits.
LLVMMetadataRef LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, LLVMMetadataRef Decl, LLVMMetadataRef File, unsigned Line, const char *Name, size_t NameLen, LLVMMetadataRef *Elements, unsigned NumElements)
Create a descriptor for an imported function, type, or variable.
LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename, size_t FilenameLen, const char *Directory, size_t DirectoryLen)
Create a file descriptor to hold debugging information for a file.
const char * LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length)
Get the name of this DIType.
unsigned LLVMMetadataKind
LLVMMetadataRef LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Scope, uint32_t AlignInBits)
Create debugging information entry for a typedef.
LLVMMetadataRef LLVMDIBuilderCreateStructType(LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags, LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder, const char *UniqueId, size_t UniqueIdLen)
Create debugging information entry for a struct.
void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder)
Deallocates the DIBuilder and everything it owns.
LLVMMetadataRef LLVMDIBuilderCreatePointerType(LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy, uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace, const char *Name, size_t NameLen)
Create debugging information entry for a pointer.
LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func)
Get the metadata of the subprogram attached to a function.
@ LLVMGenericDINodeMetadataKind
struct LLVMOpaqueValue * LLVMValueRef
Represents an individual value in LLVM IR.
struct LLVMOpaqueContext * LLVMContextRef
The top-level container for all LLVM global data.
struct LLVMOpaqueBasicBlock * LLVMBasicBlockRef
Represents a basic block of instructions in LLVM IR.
struct LLVMOpaqueMetadata * LLVMMetadataRef
Represents an LLVM Metadata.
struct LLVMOpaqueModule * LLVMModuleRef
The top-level container for all other LLVM Intermediate Representation (IR) objects.
struct LLVMOpaqueDIBuilder * LLVMDIBuilderRef
Represents an LLVM debug info builder.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
@ C
The default llvm calling convention, compatible with C.
Assignment Tracking (at).
void deleteAll(Function *F)
Remove all Assignment Tracking related intrinsics and metadata from F.
AssignmentInstRange getAssignmentInsts(DIAssignID *ID)
Return a range of instructions (typically just one) that have ID as an attachment.
AssignmentMarkerRange getAssignmentMarkers(DIAssignID *ID)
Return a range of dbg.assign intrinsics which use \ID as an operand.
void trackAssignments(Function::iterator Start, Function::iterator End, const StorageToVarsMap &Vars, const DataLayout &DL, bool DebugPrints=false)
Track assignments to Vars between Start and End.
void deleteAssignmentMarkers(const Instruction *Inst)
Delete the llvm.dbg.assign intrinsics linked to Inst.
std::optional< AssignmentInfo > getAssignmentInfo(const DataLayout &DL, const MemIntrinsic *I)
void RAUW(DIAssignID *Old, DIAssignID *New)
Replace all uses (and attachments) of Old with New.
void prune(LinkGraph &G)
Removes dead symbols/blocks/addressables.
Scope
Defines the scope in which this symbol should be visible: Default – Visible in the public interface o...
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
TinyPtrVector< DbgDeclareInst * > FindDbgDeclareUses(Value *V)
Finds dbg.declare intrinsics declaring local variables as living in the memory that 'V' points to.
bool all_of(R &&range, UnaryPredicate P)
Provide wrappers to std::all_of which take ranges instead of having to pass begin/end explicitly.
bool stripDebugInfo(Function &F)
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
@ Import
Import information from summary.
iterator_range< early_inc_iterator_impl< detail::IterOfRange< RangeT > > > make_early_inc_range(RangeT &&Range)
Make a range that does early increment to allow mutation of the underlying range without disrupting i...
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
void findDbgUsers(SmallVectorImpl< DbgVariableIntrinsic * > &DbgInsts, Value *V)
Finds the debug info intrinsics describing a value.
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
bool stripNonLineTableDebugInfo(Module &M)
Downgrade the debug info in a module to contain only line table information.
DebugLoc getDebugValueLoc(DbgVariableIntrinsic *DII)
Produce a DebugLoc to use for each dbg.declare that is promoted to a dbg.value.
void findDbgValues(SmallVectorImpl< DbgValueInst * > &DbgValues, Value *V)
Finds the llvm.dbg.value intrinsics describing a value.
unsigned getDebugMetadataVersionFromModule(const Module &M)
Return Debug Info Metadata Version by checking module flags.
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
bool StripDebugInfo(Module &M)
Strip debug info in the module if it exists.
@ Ref
The access may reference the value stored in memory.
Attribute unwrap(LLVMAttributeRef Attr)
bool isAssignmentTrackingEnabled(const Module &M)
Return true if assignment tracking is enabled for module M.
auto count_if(R &&Range, UnaryPredicate P)
Wrapper function around std::count_if to count the number of times an element satisfying a given pred...
LLVMAttributeRef wrap(Attribute Attr)
void updateLoopMetadataDebugLocations(Instruction &I, function_ref< Metadata *(Metadata *)> Updater)
Update the debug locations contained within the MD_loop metadata attached to the instruction I,...
DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.
Helper object to track which of three possible relocation mechanisms are used for a particular value ...
Describes properties of a store that has a static size and offset into a some base storage.
Helper struct for trackAssignments, below.