Lines Matching +full:mc +full:- +full:sid

1 //===- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp ----------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
33 #include "llvm/Config/llvm-config.h"
52 #include "llvm/MC/MCAsmInfo.h"
53 #include "llvm/MC/MCContext.h"
54 #include "llvm/MC/MCSectionCOFF.h"
55 #include "llvm/MC/MCStreamer.h"
56 #include "llvm/MC/MCSymbol.h"
85 void emitBytes(StringRef Data) override { OS->emitBytes(Data); } in emitBytes()
88 OS->emitIntValueInHex(Value, Size); in emitIntValue()
91 void emitBinaryData(StringRef Data) override { OS->emitBinaryData(Data); } in emitBinaryData()
93 void AddComment(const Twine &T) override { OS->AddComment(T); } in AddComment()
95 void AddRawComment(const Twine &T) override { OS->emitRawComment(T); } in AddRawComment()
97 bool isVerboseAsm() override { return OS->isVerboseAsm(); } in isVerboseAsm()
134 : DebugHandlerBase(AP), OS(*Asm->OutStreamer), TypeTable(Allocator) {} in CodeViewDebug()
141 StringRef Dir = File->getDirectory(), Filename = File->getFilename(); in getFullFilepath()
143 // If this is a Unix-style path, just use it as is. Don't try to canonicalize in getFullFilepath()
175 // path should be well-formatted, e.g. start with a drive letter, etc. in getFullFilepath()
182 size_t PrevSlash = Filepath.rfind('\\', Cursor - 1); in getFullFilepath()
187 Filepath.erase(PrevSlash, Cursor + 3 - PrevSlash); in getFullFilepath()
208 if (F->getChecksum()) { in maybeRecordFile()
209 std::string Checksum = fromHex(F->getChecksum()->Value); in maybeRecordFile()
214 switch (F->getChecksum()->Kind) { in maybeRecordFile()
231 return Insertion.first->second; in maybeRecordFile()
237 auto SiteInsertion = CurFn->InlineSites.insert({InlinedAt, InlineSite()}); in getInlineSite()
238 InlineSite *Site = &SiteInsertion.first->second; in getInlineSite()
240 unsigned ParentFuncId = CurFn->FuncId; in getInlineSite()
241 if (const DILocation *OuterIA = InlinedAt->getInlinedAt()) in getInlineSite()
243 getInlineSite(OuterIA, InlinedAt->getScope()->getSubprogram()) in getInlineSite()
246 Site->SiteFuncId = NextFuncId++; in getInlineSite()
248 Site->SiteFuncId, ParentFuncId, maybeRecordFile(InlinedAt->getFile()), in getInlineSite()
249 InlinedAt->getLine(), InlinedAt->getColumn(), SMLoc()); in getInlineSite()
250 Site->Inlinee = Inlinee; in getInlineSite()
254 if (InlinedAt->getInlinedAt() == nullptr) in getInlineSite()
255 CurFn->Inlinees.insert(InlineeIdx); in getInlineSite()
261 StringRef ScopeName = Scope->getName(); in getPrettyScopeName()
265 switch (Scope->getTag()) { in getPrettyScopeName()
270 return "<unnamed-tag>"; in getPrettyScopeName()
294 Scope = Scope->getScope(); in collectParentScopeNames()
318 --CVD.TypeEmissionLevel; in ~TypeLoweringScope()
335 const DIScope *Scope = Ty->getScope(); in getFullyQualifiedName()
344 // which can trigger a link-time error with the linker in in getScopeIndex()
358 return I->second; in getScopeIndex()
362 StringIdRecord SID(TypeIndex(), ScopeName); in getScopeIndex() local
363 auto TI = TypeTable.writeLeafType(SID); in getScopeIndex()
374 for (int i = Name.size() - 1; i >= 0; --i) { in removeTemplateArgs()
378 --OpenBrackets; in removeTemplateArgs()
392 return I->second; in getFuncIdForSubprogram()
397 StringRef DisplayName = removeTemplateArgs(SP->getName()); in getFuncIdForSubprogram()
399 const DIScope *Scope = SP->getScope(); in getFuncIdForSubprogram()
412 FuncIdRecord FuncId(ParentScope, getTypeIndex(SP->getType()), DisplayName); in getFuncIdForSubprogram()
420 return ((DCTy->getFlags() & DINode::FlagNonTrivial) == DINode::FlagNonTrivial); in isNonTrivial()
429 if (auto TypeArray = Ty->getTypeArray()) { in getFunctionOptions()
441 if (ClassTy && isNonTrivial(ClassTy) && SPName == ClassTy->getName()) { in getFunctionOptions()
454 if (SP->getDeclaration()) in getMemberFunctionType()
455 SP = SP->getDeclaration(); in getMemberFunctionType()
456 assert(!SP->getDeclaration() && "should use declaration as key"); in getMemberFunctionType()
462 return I->second; in getMemberFunctionType()
468 const bool IsStaticMethod = (SP->getFlags() & DINode::FlagStaticMember) != 0; in getMemberFunctionType()
470 FunctionOptions FO = getFunctionOptions(SP->getType(), Class, SP->getName()); in getMemberFunctionType()
472 SP->getType(), Class, SP->getThisAdjustment(), IsStaticMethod, FO); in getMemberFunctionType()
486 return MMI->getModule()->getDataLayout().getPointerSizeInBits() / 8; in getPointerSizeInBytes()
491 if (const DILocation *InlinedAt = LS->getInlinedAt()) { in recordLocalVariable()
493 const DISubprogram *Inlinee = Var.DIVar->getScope()->getSubprogram(); in recordLocalVariable()
514 const DIScope *Scope = DL->getScope(); in maybeRecordLocation()
528 if (!CurFn->HaveLineInfo) in maybeRecordLocation()
529 CurFn->HaveLineInfo = true; in maybeRecordLocation()
531 if (PrevInstLoc.get() && PrevInstLoc->getFile() == DL->getFile()) in maybeRecordLocation()
532 FileId = CurFn->LastFileId; in maybeRecordLocation()
534 FileId = CurFn->LastFileId = maybeRecordFile(DL->getFile()); in maybeRecordLocation()
537 unsigned FuncId = CurFn->FuncId; in maybeRecordLocation()
538 if (const DILocation *SiteLoc = DL->getInlinedAt()) { in maybeRecordLocation()
544 getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()).SiteFuncId; in maybeRecordLocation()
548 while ((SiteLoc = Loc->getInlinedAt())) { in maybeRecordLocation()
550 getInlineSite(SiteLoc, Loc->getScope()->getSubprogram()); in maybeRecordLocation()
556 addLocIfNotPresent(CurFn->ChildSites, Loc); in maybeRecordLocation()
561 DL->getFilename(), SMLoc()); in maybeRecordLocation()
616 if (!MMI->hasDebugInfo() || in beginModule()
617 !Asm->getObjFileLowering().getCOFFDebugSymbolsSection()) { in beginModule()
622 TheCPU = mapArchToCVCPUType(Triple(M->getTargetTriple()).getArch()); in beginModule()
625 const MDNode *Node = *M->debug_compile_units_begin(); in beginModule()
628 CurrentSourceLanguage = MapDWLangToCVLang(CU->getSourceLanguage()); in beginModule()
634 mdconst::extract_or_null<ConstantInt>(M->getModuleFlag("CodeViewGHash")); in beginModule()
635 EmitDebugGlobalHashes = GH && !GH->isZero(); in beginModule()
639 if (!Asm || !MMI->hasDebugInfo()) in endModule()
643 // with a 4-byte control code (e.g. 0xF1, 0xF2, etc) and then a 4-byte length in endModule()
644 // of the payload followed by the payload itself. The subsections are 4-byte in endModule()
658 // Emit per-function debug information. in endModule()
660 if (!P.first->isDeclarationForLinker()) in endModule()
717 S.take_front(MaxRecordLength - MaxFixedRecordLength - 1)); in emitNullTerminatedSymbolName()
727 OS.switchSection(Asm->getObjFileLowering().getCOFFDebugTypesSection()); in emitTypeInformation()
760 OS.switchSection(Asm->getObjFileLowering().getCOFFGlobalTypeHashesSection()); in emitTypeGlobalHashes()
773 // Emit an EOL-comment describing which TypeIndex this hash corresponds in emitTypeGlobalHashes()
791 StringRef PathRef(Asm->TM.Options.ObjectFilenameForDebug); in emitObjName()
794 if (PathRef.empty() || PathRef == "-") { in emitObjName()
824 V.Part[N] += C - '0'; in parseVersion()
844 if (MMI->getModule()->getProfileSummary(/*IsCS*/ false) != nullptr) { in emitCompilerInformation()
848 ArchType Arch = Triple(MMI->getModule()->getTargetTriple()).getArch(); in emitCompilerInformation()
849 if (Asm->TM.Options.Hotpatch || Arch == ArchType::thumb || in emitCompilerInformation()
860 NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); in emitCompilerInformation()
861 const MDNode *Node = *CUs->operands().begin(); in emitCompilerInformation()
864 StringRef CompilerVersion = CU->getProducer(); in emitCompilerInformation()
884 OS.AddComment("Null-terminated compiler version string"); in emitCompilerInformation()
901 if (!StringRef(Args[0]).contains("-cc1")) { in flattenCommandLine()
902 llvm::sys::printArg(OS, "-cc1", /*Quote=*/true); in flattenCommandLine()
909 if (Arg == "-main-file-name" || Arg == "-o") { in flattenCommandLine()
913 if (Arg.starts_with("-object-file-name") || Arg == MainFilename) in flattenCommandLine()
915 // Skip fmessage-length for reproduciability. in flattenCommandLine()
916 if (Arg.starts_with("-fmessage-length")) in flattenCommandLine()
930 // - Absolute path of current directory in emitBuildInfo()
931 // - Compiler path in emitBuildInfo()
932 // - Main source file path, relative to CWD or absolute in emitBuildInfo()
933 // - Type server PDB file in emitBuildInfo()
934 // - Canonical compiler command line in emitBuildInfo()
939 NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); in emitBuildInfo()
940 const MDNode *Node = *CUs->operands().begin(); // FIXME: Multiple CUs. in emitBuildInfo()
942 const DIFile *MainSourceFile = CU->getFile(); in emitBuildInfo()
944 getStringIdTypeIdx(TypeTable, MainSourceFile->getDirectory()); in emitBuildInfo()
946 getStringIdTypeIdx(TypeTable, MainSourceFile->getFilename()); in emitBuildInfo()
950 if (Asm->TM.Options.MCOptions.Argv0 != nullptr) { in emitBuildInfo()
952 getStringIdTypeIdx(TypeTable, Asm->TM.Options.MCOptions.Argv0); in emitBuildInfo()
954 TypeTable, flattenCommandLine(Asm->TM.Options.MCOptions.CommandLineArgs, in emitBuildInfo()
955 MainSourceFile->getFilename())); in emitBuildInfo()
989 unsigned FileId = maybeRecordFile(SP->getFile()); in emitInlineeLinesSubsection()
990 OS.AddComment("Inlined function " + SP->getName() + " starts at " + in emitInlineeLinesSubsection()
991 SP->getFilename() + Twine(':') + Twine(SP->getLine())); in emitInlineeLinesSubsection()
998 OS.emitInt32(SP->getLine()); in emitInlineeLinesSubsection()
1020 unsigned FileId = maybeRecordFile(Site.Inlinee->getFile()); in emitInlinedCallSite()
1021 unsigned StartLineNum = Site.Inlinee->getLine(); in emitInlinedCallSite()
1035 emitInlinedCallSite(FI, ChildSite, I->second); in emitInlinedCallSite()
1044 // comdat key. A section may be comdat because of -ffunction-sections or in switchToDebugSectionForSymbol()
1047 GVSym ? dyn_cast<MCSectionCOFF>(&GVSym->getSection()) : nullptr; in switchToDebugSectionForSymbol()
1048 const MCSymbol *KeySym = GVSec ? GVSec->getCOMDATSymbol() : nullptr; in switchToDebugSectionForSymbol()
1051 Asm->getObjFileLowering().getCOFFDebugSymbolsSection()); in switchToDebugSectionForSymbol()
1068 std::string(GlobalValue::dropLLVMManglingEscape(GV->getName())); in emitDebugInfoForThunk()
1108 const MCSymbol *Fn = Asm->getSymbol(GV); in emitDebugInfoForFunction()
1115 auto *SP = GV->getSubprogram(); in emitDebugInfoForFunction()
1119 if (SP->isThunk()) { in emitDebugInfoForFunction()
1126 if (!SP->getName().empty()) in emitDebugInfoForFunction()
1127 FuncName = getFullyQualifiedName(SP->getScope(), SP->getName()); in emitDebugInfoForFunction()
1131 FuncName = std::string(GlobalValue::dropLLVMManglingEscape(GV->getName())); in emitDebugInfoForFunction()
1133 // Emit FPO data, but only on 32-bit x86. No other platforms use it. in emitDebugInfoForFunction()
1134 if (Triple(MMI->getModule()->getTargetTriple()).getArch() == Triple::x86) in emitDebugInfoForFunction()
1141 SymbolKind ProcKind = GV->hasLocalLinkage() ? SymbolKind::S_LPROC32_ID in emitDebugInfoForFunction()
1161 OS.emitInt32(getFuncIdForSubprogram(GV->getSubprogram()).getIndex()); in emitDebugInfoForFunction()
1170 if (GV->hasFnAttribute(Attribute::NoReturn)) in emitDebugInfoForFunction()
1172 if (GV->hasFnAttribute(Attribute::NoInline)) in emitDebugInfoForFunction()
1175 // Emit the function display name as a null-terminated string. in emitDebugInfoForFunction()
1184 OS.emitInt32(FI.FrameSize - FI.CSRSize); in emitDebugInfoForFunction()
1211 emitInlinedCallSite(FI, InlinedAt, I->second); in emitDebugInfoForFunction()
1221 OS.emitInt16(Strs->getNumOperands()); in emitDebugInfoForFunction()
1222 for (Metadata *MD : Strs->operands()) { in emitDebugInfoForFunction()
1225 StringRef Str = cast<MDString>(MD)->getString(); in emitDebugInfoForFunction()
1226 assert(Str.data()[Str.size()] == '\0' && "non-nullterminated MDString"); in emitDebugInfoForFunction()
1265 DR.InMemory = -1; in createDefRangeMem()
1276 const MachineFunction &MF = *Asm->MF; in collectVariableInfoFromMFTable()
1285 assert(VI.Var->isValidLocationForIntrinsic(VI.Loc) && in collectVariableInfoFromMFTable()
1286 "Expected inlined-at fields to agree"); in collectVariableInfoFromMFTable()
1288 Processed.insert(InlinedEntity(VI.Var, VI.Loc->getInlinedAt())); in collectVariableInfoFromMFTable()
1301 if (VI.Expr->getNumElements() == 1 && in collectVariableInfoFromMFTable()
1302 VI.Expr->getElement(0) == llvm::dwarf::DW_OP_deref) in collectVariableInfoFromMFTable()
1304 else if (!VI.Expr->extractIfOffset(ExprOffset)) in collectVariableInfoFromMFTable()
1311 TFI->getFrameIndexReference(*Asm->MF, VI.getStackSlot(), FrameReg); in collectVariableInfoFromMFTable()
1312 uint16_t CVReg = TRI->getCodeViewRegNum(FrameReg); in collectVariableInfoFromMFTable()
1324 for (const InsnRange &Range : Scope->getRanges()) { in collectVariableInfoFromMFTable()
1327 End = End ? End : Asm->getFunctionEnd(); in collectVariableInfoFromMFTable()
1348 const TargetRegisterInfo *TRI = Asm->MF->getSubtarget().getRegisterInfo(); in calculateRanges()
1356 assert(DVInst->isDebugValue() && "Invalid History entry"); in calculateRanges()
1368 auto Op = DVInst->getDebugOperand(0); in calculateRanges()
1384 Location->LoadChain.pop_back(); in calculateRanges()
1397 if (Location->Register == 0 || Location->LoadChain.size() > 1) in calculateRanges()
1400 // Codeview can only express byte-aligned offsets, ensure that we have a in calculateRanges()
1401 // byte-boundaried location. in calculateRanges()
1402 if (Location->FragmentInfo) in calculateRanges()
1403 if (Location->FragmentInfo->OffsetInBits % 8) in calculateRanges()
1407 DR.CVRegister = TRI->getCodeViewRegNum(Location->Register); in calculateRanges()
1408 DR.InMemory = !Location->LoadChain.empty(); in calculateRanges()
1410 !Location->LoadChain.empty() ? Location->LoadChain.back() : 0; in calculateRanges()
1411 if (Location->FragmentInfo) { in calculateRanges()
1413 DR.StructOffset = Location->FragmentInfo->OffsetInBits / 8; in calculateRanges()
1428 End = Asm->getFunctionEnd(); in calculateRanges()
1445 // Grab the variable info that was squirreled away in the MMI side-table. in collectVariableInfo()
1460 Scope = LScopes.findInlinedScope(DIVar->getScope(), InlinedAt); in collectVariableInfo()
1462 Scope = LScopes.findLexicalScope(DIVar->getScope()); in collectVariableInfo()
1476 const TargetSubtargetInfo &TSI = MF->getSubtarget(); in beginFunctionImpl()
1478 const MachineFrameInfo &MFI = MF->getFrameInfo(); in beginFunctionImpl()
1479 const Function &GV = MF->getFunction(); in beginFunctionImpl()
1482 CurFn = Insertion.first->second.get(); in beginFunctionImpl()
1483 CurFn->FuncId = NextFuncId++; in beginFunctionImpl()
1484 CurFn->Begin = Asm->getFunctionBegin(); in beginFunctionImpl()
1487 // callee-saved registers were used. For targets that don't use a PUSH in beginFunctionImpl()
1489 CurFn->CSRSize = MFI.getCVBytesOfCalleeSavedRegisters(); in beginFunctionImpl()
1490 CurFn->FrameSize = MFI.getStackSize(); in beginFunctionImpl()
1491 CurFn->OffsetAdjustment = MFI.getOffsetAdjustment(); in beginFunctionImpl()
1492 CurFn->HasStackRealignment = TRI->hasStackRealignment(*MF); in beginFunctionImpl()
1496 CurFn->EncodedParamFramePtrReg = EncodedFramePtrReg::None; // None. in beginFunctionImpl()
1497 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::None; // None. in beginFunctionImpl()
1498 if (CurFn->FrameSize > 0) { in beginFunctionImpl()
1499 if (!TSI.getFrameLowering()->hasFP(*MF)) { in beginFunctionImpl()
1500 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::StackPtr; in beginFunctionImpl()
1501 CurFn->EncodedParamFramePtrReg = EncodedFramePtrReg::StackPtr; in beginFunctionImpl()
1503 CurFn->HasFramePointer = true; in beginFunctionImpl()
1505 CurFn->EncodedParamFramePtrReg = EncodedFramePtrReg::FramePtr; in beginFunctionImpl()
1506 if (CurFn->HasStackRealignment) { in beginFunctionImpl()
1508 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::StackPtr; in beginFunctionImpl()
1512 CurFn->EncodedLocalFramePtrReg = EncodedFramePtrReg::FramePtr; in beginFunctionImpl()
1521 if (MF->exposesReturnsTwice()) in beginFunctionImpl()
1524 if (MF->hasInlineAsm()) in beginFunctionImpl()
1547 FPO |= FrameProcedureOptions(uint32_t(CurFn->EncodedLocalFramePtrReg) << 14U); in beginFunctionImpl()
1548 FPO |= FrameProcedureOptions(uint32_t(CurFn->EncodedParamFramePtrReg) << 16U); in beginFunctionImpl()
1549 if (Asm->TM.getOptLevel() != CodeGenOptLevel::None && !GV.hasOptSize() && in beginFunctionImpl()
1557 CurFn->FrameProcOpts = FPO; in beginFunctionImpl()
1559 OS.emitCVFuncIdDirective(CurFn->FuncId); in beginFunctionImpl()
1561 // Find the end of the function prolog. First known non-DBG_VALUE and in beginFunctionImpl()
1562 // non-frame setup location marks the beginning of the function body. in beginFunctionImpl()
1579 // Record beginning of function if we have a non-empty prologue. in beginFunctionImpl()
1596 bool isThumb = Triple(MMI->getModule()->getTargetTriple()).getArch() == in beginFunctionImpl()
1606 if (T->getTag() == dwarf::DW_TAG_typedef) { in shouldEmitUdt()
1607 if (DIScope *Scope = T->getScope()) { in shouldEmitUdt()
1608 switch (Scope->getTag()) { in shouldEmitUdt()
1621 if (!T || T->isForwardDecl()) in shouldEmitUdt()
1627 T = DT->getBaseType(); in shouldEmitUdt()
1634 if (Ty->getName().empty()) in addToUDTs()
1641 collectParentScopeNames(Ty->getScope(), ParentScopeNames); in addToUDTs()
1662 switch (Ty->getTag()) { in lowerType()
1670 if (cast<DIDerivedType>(Ty)->getName() == "__vtbl_ptr_type") in lowerType()
1702 if (Ty->getName() == "decltype(nullptr)") in lowerType()
1712 TypeIndex UnderlyingTypeIndex = getTypeIndex(Ty->getBaseType()); in lowerTypeAlias()
1713 StringRef TypeName = Ty->getName(); in lowerTypeAlias()
1728 const DIType *ElementType = Ty->getBaseType(); in lowerTypeArray()
1738 DINodeArray Elements = Ty->getElements(); in lowerTypeArray()
1739 for (int i = Elements.size() - 1; i >= 0; --i) { in lowerTypeArray()
1741 assert(Element->getTag() == dwarf::DW_TAG_subrange_type); in lowerTypeArray()
1744 int64_t Count = -1; in lowerTypeArray()
1747 // Otherwise, if it has an upperboud, use (upperbound - lowerbound + 1), in lowerTypeArray()
1750 if (auto *CI = dyn_cast_if_present<ConstantInt *>(Subrange->getCount())) in lowerTypeArray()
1751 Count = CI->getSExtValue(); in lowerTypeArray()
1753 Subrange->getUpperBound())) { in lowerTypeArray()
1756 auto *LI = dyn_cast_if_present<ConstantInt *>(Subrange->getLowerBound()); in lowerTypeArray()
1757 Lowerbound = (LI) ? LI->getSExtValue() : Lowerbound; in lowerTypeArray()
1758 Count = UI->getSExtValue() - Lowerbound + 1; in lowerTypeArray()
1761 // Forward declarations of arrays without a size and VLAs use a count of -1. in lowerTypeArray()
1765 if (Count == -1) in lowerTypeArray()
1774 (i == 0 && ElementSize == 0) ? Ty->getSizeInBits() / 8 : ElementSize; in lowerTypeArray()
1776 StringRef Name = (i == 0) ? Ty->getName() : ""; in lowerTypeArray()
1791 uint64_t ArraySize = Ty->getSizeInBits() >> 3; in lowerTypeString()
1792 StringRef Name = Ty->getName(); in lowerTypeString()
1809 Kind = static_cast<dwarf::TypeKind>(Ty->getEncoding()); in lowerTypeBasic()
1810 ByteSize = Ty->getSizeInBits() / 8; in lowerTypeBasic()
1884 // Apply some fixups based on the source-level type name. in lowerTypeBasic()
1889 (Ty->getName() == "long int" || Ty->getName() == "long")) in lowerTypeBasic()
1891 if (STK == SimpleTypeKind::UInt32 && (Ty->getName() == "long unsigned int" || in lowerTypeBasic()
1892 Ty->getName() == "unsigned long")) in lowerTypeBasic()
1895 (Ty->getName() == "wchar_t" || Ty->getName() == "__wchar_t")) in lowerTypeBasic()
1899 Ty->getName() == "char") in lowerTypeBasic()
1907 TypeIndex PointeeTI = getTypeIndex(Ty->getBaseType()); in lowerTypePointer()
1913 Ty->getTag() == dwarf::DW_TAG_pointer_type) { in lowerTypePointer()
1914 SimpleTypeMode Mode = Ty->getSizeInBits() == 64 in lowerTypePointer()
1921 Ty->getSizeInBits() == 64 ? PointerKind::Near64 : PointerKind::Near32; in lowerTypePointer()
1923 switch (Ty->getTag()) { in lowerTypePointer()
1936 if (Ty->isObjectPointer()) in lowerTypePointer()
1939 PointerRecord PR(PointeeTI, PK, PM, PO, Ty->getSizeInBits() / 8); in lowerTypePointer()
1978 assert(Ty->getTag() == dwarf::DW_TAG_ptr_to_member_type); in lowerTypeMemberPointer()
1979 bool IsPMF = isa<DISubroutineType>(Ty->getBaseType()); in lowerTypeMemberPointer()
1980 TypeIndex ClassTI = getTypeIndex(Ty->getClassType()); in lowerTypeMemberPointer()
1982 getTypeIndex(Ty->getBaseType(), IsPMF ? Ty->getClassType() : nullptr); in lowerTypeMemberPointer()
1988 assert(Ty->getSizeInBits() / 8 <= 0xff && "pointer size too big"); in lowerTypeMemberPointer()
1989 uint8_t SizeInBytes = Ty->getSizeInBits() / 8; in lowerTypeMemberPointer()
1991 ClassTI, translatePtrToMemberRep(SizeInBytes, IsPMF, Ty->getFlags())); in lowerTypeMemberPointer()
2017 switch (BaseTy->getTag()) { in lowerTypeModifier()
2036 BaseTy = cast<DIDerivedType>(BaseTy)->getBaseType(); in lowerTypeModifier()
2044 switch (BaseTy->getTag()) { in lowerTypeModifier()
2059 // metadata could contain restrict wrappers around non-pointer types. in lowerTypeModifier()
2069 for (const DIType *ArgType : Ty->getTypeArray()) in lowerTypeFunction()
2088 CallingConvention CC = dwarfCCToCodeView(Ty->getCC()); in lowerTypeFunction()
2104 DITypeRefArray ReturnAndArgs = Ty->getTypeArray(); in lowerTypeMemberFunction()
2120 if (PtrTy->getTag() == dwarf::DW_TAG_pointer_type) { in lowerTypeMemberFunction()
2137 CallingConvention CC = dwarfCCToCodeView(Ty->getCC()); in lowerTypeMemberFunction()
2146 Ty->getSizeInBits() / (8 * Asm->MAI->getCodePointerSize()); in lowerTypeVFTableShape()
2167 if (SP->isArtificial()) in translateMethodOptionFlags()
2177 if (SP->getFlags() & DINode::FlagStaticMember) in translateMethodKindFlags()
2180 switch (SP->getVirtuality()) { in translateMethodKindFlags()
2196 switch (Ty->getTag()) { in getRecordKind()
2214 if (!Ty->getIdentifier().empty()) in getCommonClassOptions()
2220 const DIScope *ImmediateScope = Ty->getScope(); in getCommonClassOptions()
2224 // Put the Scoped flag on function-local types. MSVC puts this flag for enum in getCommonClassOptions()
2228 if (Ty->getTag() == dwarf::DW_TAG_enumeration_type) { in getCommonClassOptions()
2233 Scope = Scope->getScope()) { in getCommonClassOptions()
2245 switch (Ty->getTag()) { in addUDTSrcLine()
2255 if (const auto *File = Ty->getFile()) { in addUDTSrcLine()
2259 UdtSourceLineRecord USLR(TI, SIDI, Ty->getLine()); in addUDTSrcLine()
2269 if (Ty->isForwardDecl()) { in lowerTypeEnum()
2274 for (const DINode *Element : Ty->getElements()) { in lowerTypeEnum()
2280 APSInt(Enumerator->getValue(), true), in lowerTypeEnum()
2281 Enumerator->getName()); in lowerTypeEnum()
2291 EnumRecord ER(EnumeratorCount, CO, FTI, FullName, Ty->getIdentifier(), in lowerTypeEnum()
2292 getTypeIndex(Ty->getBaseType())); in lowerTypeEnum()
2300 //===----------------------------------------------------------------------===//
2302 //===----------------------------------------------------------------------===//
2313 // MethodName -> MethodsList
2344 if (!DDTy->getName().empty()) { in collectMemberInfo()
2348 if ((DDTy->getFlags() & DINode::FlagStaticMember) == in collectMemberInfo()
2350 if (DDTy->getConstant() && (isa<ConstantInt>(DDTy->getConstant()) || in collectMemberInfo()
2351 isa<ConstantFP>(DDTy->getConstant()))) in collectMemberInfo()
2362 assert((DDTy->getOffsetInBits() % 8) == 0 && "Unnamed bitfield member!"); in collectMemberInfo()
2363 uint64_t Offset = DDTy->getOffsetInBits(); in collectMemberInfo()
2364 const DIType *Ty = DDTy->getBaseType(); in collectMemberInfo()
2367 switch (Ty->getTag()) { in collectMemberInfo()
2372 Ty = cast<DIDerivedType>(Ty)->getBaseType(); in collectMemberInfo()
2393 DINodeArray Elements = Ty->getElements(); in collectClassInfo()
2400 Info.Methods[SP->getRawName()].push_back(SP); in collectClassInfo()
2402 if (DDTy->getTag() == dwarf::DW_TAG_member) { in collectClassInfo()
2404 } else if (DDTy->getTag() == dwarf::DW_TAG_inheritance) { in collectClassInfo()
2406 } else if (DDTy->getTag() == dwarf::DW_TAG_pointer_type && in collectClassInfo()
2407 DDTy->getName() == "__vtbl_ptr_type") { in collectClassInfo()
2409 } else if (DDTy->getTag() == dwarf::DW_TAG_typedef) { in collectClassInfo()
2411 } else if (DDTy->getTag() == dwarf::DW_TAG_friend) { in collectClassInfo()
2426 return Ty->getName().empty() && Ty->getIdentifier().empty() && in shouldAlwaysEmitCompleteClassType()
2427 !Ty->isForwardDecl(); in shouldAlwaysEmitCompleteClassType()
2433 // be named by the front-end and should not be "unnamed". C unnamed in lowerTypeClass()
2440 if (I != CompleteTypeIndices.end() && I->second == TypeIndex()) in lowerTypeClass()
2452 FullName, Ty->getIdentifier()); in lowerTypeClass()
2454 if (!Ty->isForwardDecl()) in lowerTypeClass()
2476 // debug information. For now checking a class's non-triviality seems enough. in lowerCompleteTypeClass()
2483 uint64_t SizeInBytes = Ty->getSizeInBits() / 8; in lowerCompleteTypeClass()
2486 SizeInBytes, FullName, Ty->getIdentifier()); in lowerCompleteTypeClass()
2504 UnionRecord UR(0, CO, TypeIndex(), 0, FullName, Ty->getIdentifier()); in lowerTypeUnion()
2506 if (!Ty->isForwardDecl()) in lowerTypeUnion()
2522 uint64_t SizeInBytes = Ty->getSizeInBits() / 8; in lowerCompleteTypeUnion()
2526 Ty->getIdentifier()); in lowerCompleteTypeUnion()
2549 if (I->getFlags() & DINode::FlagVirtual) { in lowerRecordFieldList()
2551 unsigned VBPtrOffset = I->getVBPtrOffset(); in lowerRecordFieldList()
2553 unsigned VBTableIndex = I->getOffsetInBits() / 4; in lowerRecordFieldList()
2554 …auto RecordKind = (I->getFlags() & DINode::FlagIndirectVirtualBase) == DINode::FlagIndirectVirtual… in lowerRecordFieldList()
2558 RecordKind, translateAccessFlags(Ty->getTag(), I->getFlags()), in lowerRecordFieldList()
2559 getTypeIndex(I->getBaseType()), getVBPTypeIndex(), VBPtrOffset, in lowerRecordFieldList()
2565 assert(I->getOffsetInBits() % 8 == 0 && in lowerRecordFieldList()
2567 BaseClassRecord BCR(translateAccessFlags(Ty->getTag(), I->getFlags()), in lowerRecordFieldList()
2568 getTypeIndex(I->getBaseType()), in lowerRecordFieldList()
2569 I->getOffsetInBits() / 8); in lowerRecordFieldList()
2578 TypeIndex MemberBaseType = getTypeIndex(Member->getBaseType()); in lowerRecordFieldList()
2579 StringRef MemberName = Member->getName(); in lowerRecordFieldList()
2581 translateAccessFlags(Ty->getTag(), Member->getFlags()); in lowerRecordFieldList()
2583 if (Member->isStaticMember()) { in lowerRecordFieldList()
2591 if ((Member->getFlags() & DINode::FlagArtificial) && in lowerRecordFieldList()
2592 Member->getName().starts_with("_vptr$")) { in lowerRecordFieldList()
2593 VFPtrRecord VFPR(getTypeIndex(Member->getBaseType())); in lowerRecordFieldList()
2601 Member->getOffsetInBits() + MemberInfo.BaseOffset; in lowerRecordFieldList()
2602 if (Member->isBitField()) { in lowerRecordFieldList()
2605 dyn_cast_or_null<ConstantInt>(Member->getStorageOffsetInBits())) { in lowerRecordFieldList()
2606 MemberOffsetInBits = CI->getZExtValue() + MemberInfo.BaseOffset; in lowerRecordFieldList()
2608 StartBitOffset -= MemberOffsetInBits; in lowerRecordFieldList()
2609 BitFieldRecord BFR(MemberBaseType, Member->getSizeInBits(), in lowerRecordFieldList()
2622 StringRef Name = MethodItr.first->getString(); in lowerRecordFieldList()
2627 bool Introduced = SP->getFlags() & DINode::FlagIntroducedVirtual; in lowerRecordFieldList()
2629 unsigned VFTableOffset = -1; in lowerRecordFieldList()
2631 VFTableOffset = SP->getVirtualIndex() * getPointerSizeInBytes(); in lowerRecordFieldList()
2634 MethodType, translateAccessFlags(Ty->getTag(), SP->getFlags()), in lowerRecordFieldList()
2655 NestedTypeRecord R(getTypeIndex(Nested), Nested->getName()); in lowerRecordFieldList()
2688 // get-or-create style insertion that caches the hash lookup across the in getTypeIndex()
2692 return I->second; in getTypeIndex()
2702 assert(PtrTy->getTag() == dwarf::DW_TAG_pointer_type && in getTypeIndexForThisPtr()
2706 if (SubroutineTy->getFlags() & DINode::DIFlags::FlagLValueReference) in getTypeIndexForThisPtr()
2708 else if (SubroutineTy->getFlags() & DINode::DIFlags::FlagRValueReference) in getTypeIndexForThisPtr()
2718 return I->second; in getTypeIndexForThisPtr()
2730 Ty->getSizeInBits() / 8); in getTypeIndexForReferenceTo()
2742 if (Ty->getTag() == dwarf::DW_TAG_typedef) in getCompleteTypeIndex()
2744 while (Ty->getTag() == dwarf::DW_TAG_typedef) in getCompleteTypeIndex()
2745 Ty = cast<DIDerivedType>(Ty)->getBaseType(); in getCompleteTypeIndex()
2747 // If this is a non-record type, the complete type index is the same as the in getCompleteTypeIndex()
2749 switch (Ty->getTag()) { in getCompleteTypeIndex()
2766 if (!CTy->getName().empty() || !CTy->getIdentifier().empty()) { in getCompleteTypeIndex()
2772 if (CTy->isForwardDecl()) in getCompleteTypeIndex()
2781 return InsertResult.first->second; in getCompleteTypeIndex()
2784 switch (CTy->getTag()) { in getCompleteTypeIndex()
2823 if (L.DIVar->isParameter()) in emitLocalVariableList()
2826 return L->DIVar->getArg() < R->DIVar->getArg(); in emitLocalVariableList()
2831 // Next emit all non-parameters in the order that we found them. in emitLocalVariableList()
2833 if (!L.DIVar->isParameter()) { in emitLocalVariableList()
2837 const DIType *Ty = L.DIVar->getType(); in emitLocalVariableList()
2839 emitConstantSymbolRecord(Ty, Val, std::string(L.DIVar->getName())); in emitLocalVariableList()
2853 if (Var.DIVar->isParameter()) in emitLocalVariable()
2860 ? getTypeIndexForReferenceTo(Var.DIVar->getType()) in emitLocalVariable()
2861 : getCompleteTypeIndex(Var.DIVar->getType()); in emitLocalVariable()
2866 emitNullTerminatedSymbolName(OS, Var.DIVar->getName()); in emitLocalVariable()
2881 // 32-bit x86 call sequences often use PUSH instructions, which disrupt in emitLocalVariable()
2882 // ESP-relative offsets. Use the virtual frame pointer, VFRAME or $T0, in emitLocalVariable()
2993 LI != ScopeVariables.end() ? &LI->second : nullptr; in collectLexicalBlockInfo()
2996 GI != ScopeGlobals.end() ? GI->second.get() : nullptr; in collectLexicalBlockInfo()
3028 ParentLocals.append(Locals->begin(), Locals->end()); in collectLexicalBlockInfo()
3030 ParentGlobals.append(Globals->begin(), Globals->end()); in collectLexicalBlockInfo()
3041 auto BlockInsertion = CurFn->LexicalBlocks.insert({DILB, LexicalBlock()}); in collectLexicalBlockInfo()
3049 LexicalBlock &Block = BlockInsertion.first->second; in collectLexicalBlockInfo()
3054 Block.Name = DILB->getName(); in collectLexicalBlockInfo()
3067 const Function &GV = MF->getFunction(); in endFunctionImpl()
3076 CurFn->ChildBlocks, in endFunctionImpl()
3077 CurFn->Locals, in endFunctionImpl()
3078 CurFn->Globals); in endFunctionImpl()
3086 // Thunks are compiler-generated and probably won't have source correlation. in endFunctionImpl()
3087 if (!CurFn->HaveLineInfo && !GV.getSubprogram()->isThunk()) { in endFunctionImpl()
3097 CurFn->HeapAllocSites.push_back(std::make_tuple(getLabelBeforeInsn(&MI), in endFunctionImpl()
3104 bool isThumb = Triple(MMI->getModule()->getTargetTriple()).getArch() == in endFunctionImpl()
3108 CurFn->Annotations = MF->getCodeViewAnnotations(); in endFunctionImpl()
3110 CurFn->End = Asm->getFunctionEnd(); in endFunctionImpl()
3115 // Usable locations are valid with non-zero line numbers. A line number of zero
3127 if (!Asm || !CurFn || MI->isDebugInstr() || in beginInstruction()
3128 MI->getFlag(MachineInstr::FrameSetup)) in beginInstruction()
3133 DebugLoc DL = MI->getDebugLoc(); in beginInstruction()
3134 if (!isUsableDebugLoc(DL) && MI->getParent() != PrevInstBB) { in beginInstruction()
3135 for (const auto &NextMI : *MI->getParent()) { in beginInstruction()
3145 PrevInstBB = MI->getParent(); in beginInstruction()
3151 maybeRecordLocation(DL, Asm->MF); in beginInstruction()
3155 MCSymbol *BeginLabel = MMI->getContext().createTempSymbol(), in beginCVSubsection()
3156 *EndLabel = MMI->getContext().createTempSymbol(); in beginCVSubsection()
3166 // Every subsection must be aligned to a 4-byte boundary. in endCVSubsection()
3178 MCSymbol *BeginLabel = MMI->getContext().createTempSymbol(), in beginSymbolRecord()
3179 *EndLabel = MMI->getContext().createTempSymbol(); in beginSymbolRecord()
3227 for (const GlobalVariable &GV : MMI->getModule()->globals()) { in collectGlobalVariableInfo()
3234 NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); in collectGlobalVariableInfo()
3235 for (const MDNode *Node : CUs->operands()) { in collectGlobalVariableInfo()
3237 for (const auto *GVE : CU->getGlobalVariables()) { in collectGlobalVariableInfo()
3238 const DIGlobalVariable *DIGV = GVE->getVariable(); in collectGlobalVariableInfo()
3239 const DIExpression *DIE = GVE->getExpression(); in collectGlobalVariableInfo()
3244 if (DIGV->getName().empty()) continue; in collectGlobalVariableInfo()
3246 if ((DIE->getNumElements() == 2) && in collectGlobalVariableInfo()
3247 (DIE->getElement(0) == dwarf::DW_OP_plus_uconst)) in collectGlobalVariableInfo()
3253 std::make_pair(DIGV, DIE->getElement(1))); in collectGlobalVariableInfo()
3256 if (GlobalMap.count(GVE) == 0 && DIE->isConstant()) { in collectGlobalVariableInfo()
3262 if (!GV || GV->isDeclarationForLinker()) in collectGlobalVariableInfo()
3265 DIScope *Scope = DIGV->getScope(); in collectGlobalVariableInfo()
3273 Insertion.first->second = std::make_unique<GlobalVariableList>(); in collectGlobalVariableInfo()
3274 VariableList = Insertion.first->second.get(); in collectGlobalVariableInfo()
3275 } else if (GV->hasComdat()) in collectGlobalVariableInfo()
3282 VariableList->emplace_back(std::move(CVGV)); in collectGlobalVariableInfo()
3290 const DIScope *Scope = DIGV->getScope(); in collectDebugInfoForGlobals()
3291 getCompleteTypeIndex(DIGV->getType()); in collectDebugInfoForGlobals()
3292 getFullyQualifiedName(Scope, DIGV->getName()); in collectDebugInfoForGlobals()
3297 const DIScope *Scope = DIGV->getScope(); in collectDebugInfoForGlobals()
3298 getCompleteTypeIndex(DIGV->getType()); in collectDebugInfoForGlobals()
3299 getFullyQualifiedName(Scope, DIGV->getName()); in collectDebugInfoForGlobals()
3320 MCSymbol *GVSym = Asm->getSymbol(GV); in emitDebugInfoForGlobals()
3322 Twine(GlobalValue::dropLLVMManglingEscape(GV->getName()))); in emitDebugInfoForGlobals()
3332 NamedMDNode *CUs = MMI->getModule()->getNamedMetadata("llvm.dbg.cu"); in emitDebugInfoForRetainedTypes()
3333 for (const MDNode *Node : CUs->operands()) { in emitDebugInfoForRetainedTypes()
3334 for (auto *Ty : cast<DICompileUnit>(Node)->getRetainedTypes()) { in emitDebugInfoForRetainedTypes()
3374 const DIScope *Scope = DTy->getScope(); in emitStaticConstMemberList()
3378 dyn_cast_or_null<ConstantInt>(DTy->getConstant())) in emitStaticConstMemberList()
3379 Value = APSInt(CI->getValue(), in emitStaticConstMemberList()
3380 DebugHandlerBase::isUnsignedDIType(DTy->getBaseType())); in emitStaticConstMemberList()
3382 dyn_cast_or_null<ConstantFP>(DTy->getConstant())) in emitStaticConstMemberList()
3383 Value = APSInt(CFP->getValueAPF().bitcastToAPInt(), true); in emitStaticConstMemberList()
3387 emitConstantSymbolRecord(DTy->getBaseType(), Value, in emitStaticConstMemberList()
3388 getFullyQualifiedName(Scope, DTy->getName())); in emitStaticConstMemberList()
3397 dwarf::Tag T = (dwarf::Tag)Ty->getTag(); in isFloatDIType()
3403 assert(DTy->getBaseType() && "Expected valid base type"); in isFloatDIType()
3404 return isFloatDIType(DTy->getBaseType()); in isFloatDIType()
3408 return (BTy->getEncoding() == dwarf::DW_ATE_float); in isFloatDIType()
3414 const DIScope *Scope = DIGV->getScope(); in emitDebugInfoForGlobal()
3417 DIGV->getRawStaticDataMemberDeclaration())) in emitDebugInfoForGlobal()
3418 Scope = MemberDecl->getScope(); in emitDebugInfoForGlobal()
3424 ? std::string(DIGV->getName()) in emitDebugInfoForGlobal()
3425 : getFullyQualifiedName(Scope, DIGV->getName()); in emitDebugInfoForGlobal()
3431 MCSymbol *GVSym = Asm->getSymbol(GV); in emitDebugInfoForGlobal()
3432 SymbolKind DataSym = GV->isThreadLocal() in emitDebugInfoForGlobal()
3433 ? (DIGV->isLocalToUnit() ? SymbolKind::S_LTHREAD32 in emitDebugInfoForGlobal()
3435 : (DIGV->isLocalToUnit() ? SymbolKind::S_LDATA32 in emitDebugInfoForGlobal()
3439 OS.emitInt32(getCompleteTypeIndex(DIGV->getType()).getIndex()); in emitDebugInfoForGlobal()
3456 assert(DIE->isConstant() && in emitDebugInfoForGlobal()
3460 bool isUnsigned = isFloatDIType(DIGV->getType()) in emitDebugInfoForGlobal()
3462 : DebugHandlerBase::isUnsignedDIType(DIGV->getType()); in emitDebugInfoForGlobal()
3463 APSInt Value(APInt(/*BitWidth=*/64, DIE->getElement(1)), isUnsigned); in emitDebugInfoForGlobal()
3464 emitConstantSymbolRecord(DIGV->getType(), Value, QualifiedName); in emitDebugInfoForGlobal()
3472 auto JTI = MF->getJumpTableInfo(); in forEachJumpTableBranch()
3473 if (JTI && !JTI->isEmpty()) { in forEachJumpTableBranch()
3475 auto UsedJTs = llvm::SmallBitVector(JTI->getJumpTables().size()); in forEachJumpTableBranch()
3480 if (LastMI != MBB.end() && LastMI->isIndirectBranch()) { in forEachJumpTableBranch()
3485 // interferes with this process *but* the resulting pseudo-instruction in forEachJumpTableBranch()
3488 for (const auto &MO : LastMI->operands()) { in forEachJumpTableBranch()
3503 if (I->isJumpTableDebugInfo()) { in forEachJumpTableBranch()
3504 unsigned Index = I->getOperand(0).getImm(); in forEachJumpTableBranch()
3536 // For label-difference jump tables, find the base expression. in collectDebugInfoForJumpTables()
3560 Asm->getCodeViewJumpTableInfo(JumpTableIndex, &BranchMI, Branch); in collectDebugInfoForJumpTables()
3564 CurFn->JumpTables.push_back( in collectDebugInfoForJumpTables()
3566 MF->getJTISymbol(JumpTableIndex, MMI->getContext()), in collectDebugInfoForJumpTables()
3606 (MaxRecordLength - sizeof(SymbolKind) - sizeof(uint32_t)) / in emitInlinees()
3616 std::min(ChunkSize, SortedInlinees.size() - CurrentIndex); in emitInlinees()