1fb69e66cSEugene Zelenko //===- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h --------------*- C++ -*-===// 270f5bc99SReid Kleckner // 32946cd70SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 42946cd70SChandler Carruth // See https://llvm.org/LICENSE.txt for license information. 52946cd70SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 670f5bc99SReid Kleckner // 770f5bc99SReid Kleckner //===----------------------------------------------------------------------===// 870f5bc99SReid Kleckner // 970f5bc99SReid Kleckner // This file contains support for writing Microsoft CodeView debug info. 1070f5bc99SReid Kleckner // 1170f5bc99SReid Kleckner //===----------------------------------------------------------------------===// 1270f5bc99SReid Kleckner 1370f5bc99SReid Kleckner #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H 1470f5bc99SReid Kleckner #define LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H 1570f5bc99SReid Kleckner 16fb69e66cSEugene Zelenko #include "llvm/ADT/ArrayRef.h" 1770f5bc99SReid Kleckner #include "llvm/ADT/DenseMap.h" 18fb69e66cSEugene Zelenko #include "llvm/ADT/DenseSet.h" 19fb69e66cSEugene Zelenko #include "llvm/ADT/MapVector.h" 20fb69e66cSEugene Zelenko #include "llvm/ADT/SetVector.h" 21fb69e66cSEugene Zelenko #include "llvm/ADT/SmallVector.h" 2261b189e0SYonghong Song #include "llvm/CodeGen/DbgEntityHistoryCalculator.h" 2361b189e0SYonghong Song #include "llvm/CodeGen/DebugHandlerBase.h" 24fb69e66cSEugene Zelenko #include "llvm/DebugInfo/CodeView/CodeView.h" 25048f8f99SZachary Turner #include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h" 26f3b9ba49SReid Kleckner #include "llvm/DebugInfo/CodeView/TypeIndex.h" 2770f5bc99SReid Kleckner #include "llvm/IR/DebugLoc.h" 28fb69e66cSEugene Zelenko #include "llvm/Support/Allocator.h" 29fb69e66cSEugene Zelenko #include "llvm/Support/Compiler.h" 30fb69e66cSEugene Zelenko #include <cstdint> 31fb69e66cSEugene Zelenko #include <map> 32fb69e66cSEugene Zelenko #include <string> 33fb69e66cSEugene Zelenko #include <tuple> 34fb69e66cSEugene Zelenko #include <unordered_map> 35fb69e66cSEugene Zelenko #include <utility> 36fb69e66cSEugene Zelenko #include <vector> 3770f5bc99SReid Kleckner 3870f5bc99SReid Kleckner namespace llvm { 39f9c275feSReid Kleckner 4076c9eb99SAmjad Aboud struct ClassInfo; 41fb69e66cSEugene Zelenko class StringRef; 42fb69e66cSEugene Zelenko class AsmPrinter; 43fb69e66cSEugene Zelenko class Function; 44fb69e66cSEugene Zelenko class GlobalVariable; 45fb69e66cSEugene Zelenko class MCSectionCOFF; 46fb69e66cSEugene Zelenko class MCStreamer; 47fb69e66cSEugene Zelenko class MCSymbol; 48fb69e66cSEugene Zelenko class MachineFunction; 49f9c275feSReid Kleckner 505f8f34e4SAdrian Prantl /// Collects and handles line tables information in a CodeView format. 51f9c275feSReid Kleckner class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase { 52dac21b43SReid Kleckner MCStreamer &OS; 53fb69e66cSEugene Zelenko BumpPtrAllocator Allocator; 54048f8f99SZachary Turner codeview::GlobalTypeTableBuilder TypeTable; 55f9c275feSReid Kleckner 5675557716SReid Kleckner /// Whether to emit type record hashes into .debug$H. 5775557716SReid Kleckner bool EmitDebugGlobalHashes = false; 5875557716SReid Kleckner 599ea2c012SReid Kleckner /// The codeview CPU type used by the translation unit. 609ea2c012SReid Kleckner codeview::CPUType TheCPU; 619ea2c012SReid Kleckner 62876330d5SReid Kleckner /// Represents the most general definition range. 63876330d5SReid Kleckner struct LocalVarDefRange { 64876330d5SReid Kleckner /// Indicates that variable data is stored in memory relative to the 65876330d5SReid Kleckner /// specified register. 66876330d5SReid Kleckner int InMemory : 1; 67876330d5SReid Kleckner 68876330d5SReid Kleckner /// Offset of variable data in memory. 69876330d5SReid Kleckner int DataOffset : 31; 70876330d5SReid Kleckner 712b3e6428SReid Kleckner /// Non-zero if this is a piece of an aggregate. 722b3e6428SReid Kleckner uint16_t IsSubfield : 1; 732b3e6428SReid Kleckner 742b3e6428SReid Kleckner /// Offset into aggregate. 752b3e6428SReid Kleckner uint16_t StructOffset : 15; 76876330d5SReid Kleckner 77876330d5SReid Kleckner /// Register containing the data or the register base of the memory 78876330d5SReid Kleckner /// location containing the data. 79876330d5SReid Kleckner uint16_t CVRegister; 80876330d5SReid Kleckner 81876330d5SReid Kleckner /// Compares all location fields. This includes all fields except the label 82876330d5SReid Kleckner /// ranges. 83876330d5SReid Kleckner bool isDifferentLocation(LocalVarDefRange &O) { 84876330d5SReid Kleckner return InMemory != O.InMemory || DataOffset != O.DataOffset || 852b3e6428SReid Kleckner IsSubfield != O.IsSubfield || StructOffset != O.StructOffset || 862b3e6428SReid Kleckner CVRegister != O.CVRegister; 87876330d5SReid Kleckner } 88876330d5SReid Kleckner 89876330d5SReid Kleckner SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 1> Ranges; 90876330d5SReid Kleckner }; 91876330d5SReid Kleckner 92876330d5SReid Kleckner static LocalVarDefRange createDefRangeMem(uint16_t CVRegister, int Offset); 93876330d5SReid Kleckner 94f9c275feSReid Kleckner /// Similar to DbgVariable in DwarfDebug, but not dwarf-specific. 95f9c275feSReid Kleckner struct LocalVariable { 96f9c275feSReid Kleckner const DILocalVariable *DIVar = nullptr; 97876330d5SReid Kleckner SmallVector<LocalVarDefRange, 1> DefRanges; 9808f5fd51SReid Kleckner bool UseReferenceType = false; 99f9c275feSReid Kleckner }; 10070f5bc99SReid Kleckner 101b17464e4SBrock Wyma struct CVGlobalVariable { 102b17464e4SBrock Wyma const DIGlobalVariable *DIGV; 103b17464e4SBrock Wyma const GlobalVariable *GV; 104b17464e4SBrock Wyma }; 105b17464e4SBrock Wyma 106f3b9ba49SReid Kleckner struct InlineSite { 107f9c275feSReid Kleckner SmallVector<LocalVariable, 1> InlinedLocals; 108f9c275feSReid Kleckner SmallVector<const DILocation *, 1> ChildSites; 109f3b9ba49SReid Kleckner const DISubprogram *Inlinee = nullptr; 110c29b4f07SReid Kleckner 111c29b4f07SReid Kleckner /// The ID of the inline site or function used with .cv_loc. Not a type 112c29b4f07SReid Kleckner /// index. 113f3b9ba49SReid Kleckner unsigned SiteFuncId = 0; 114f3b9ba49SReid Kleckner }; 115f3b9ba49SReid Kleckner 1165a791ee4SReid Kleckner // Combines information from DILexicalBlock and LexicalScope. 1175a791ee4SReid Kleckner struct LexicalBlock { 1185a791ee4SReid Kleckner SmallVector<LocalVariable, 1> Locals; 119b17464e4SBrock Wyma SmallVector<CVGlobalVariable, 1> Globals; 1205a791ee4SReid Kleckner SmallVector<LexicalBlock *, 1> Children; 1215a791ee4SReid Kleckner const MCSymbol *Begin; 1225a791ee4SReid Kleckner const MCSymbol *End; 1235a791ee4SReid Kleckner StringRef Name; 1245a791ee4SReid Kleckner }; 1255a791ee4SReid Kleckner 12670f5bc99SReid Kleckner // For each function, store a vector of labels to its instructions, as well as 12770f5bc99SReid Kleckner // to the end of the function. 12870f5bc99SReid Kleckner struct FunctionInfo { 12955baeefdSReid Kleckner FunctionInfo() = default; 13055baeefdSReid Kleckner 13155baeefdSReid Kleckner // Uncopyable. 13255baeefdSReid Kleckner FunctionInfo(const FunctionInfo &FI) = delete; 13355baeefdSReid Kleckner 134f3b9ba49SReid Kleckner /// Map from inlined call site to inlined instructions and child inlined 135f3b9ba49SReid Kleckner /// call sites. Listed in program order. 136f9c275feSReid Kleckner std::unordered_map<const DILocation *, InlineSite> InlineSites; 137f9c275feSReid Kleckner 138f9c275feSReid Kleckner /// Ordered list of top-level inlined call sites. 139f9c275feSReid Kleckner SmallVector<const DILocation *, 1> ChildSites; 140f9c275feSReid Kleckner 141f9c275feSReid Kleckner SmallVector<LocalVariable, 1> Locals; 142b17464e4SBrock Wyma SmallVector<CVGlobalVariable, 1> Globals; 143f3b9ba49SReid Kleckner 1445a791ee4SReid Kleckner std::unordered_map<const DILexicalBlockBase*, LexicalBlock> LexicalBlocks; 1455a791ee4SReid Kleckner 1465a791ee4SReid Kleckner // Lexical blocks containing local variables. 1475a791ee4SReid Kleckner SmallVector<LexicalBlock *, 1> ChildBlocks; 1485a791ee4SReid Kleckner 149e33c94f1SReid Kleckner std::vector<std::pair<MCSymbol *, MDNode *>> Annotations; 15068c91994SAmy Huang std::vector<std::tuple<MCSymbol *, MCSymbol *, DIType *>> HeapAllocSites; 151e33c94f1SReid Kleckner 1521fcd610cSReid Kleckner const MCSymbol *Begin = nullptr; 1531fcd610cSReid Kleckner const MCSymbol *End = nullptr; 1542214ed89SReid Kleckner unsigned FuncId = 0; 155f3b9ba49SReid Kleckner unsigned LastFileId = 0; 1569ea2c012SReid Kleckner 1579ea2c012SReid Kleckner /// Number of bytes allocated in the prologue for all local stack objects. 1589ea2c012SReid Kleckner unsigned FrameSize = 0; 1599ea2c012SReid Kleckner 1609ea2c012SReid Kleckner /// Number of bytes of parameters on the stack. 1619ea2c012SReid Kleckner unsigned ParamSize = 0; 1629ea2c012SReid Kleckner 1639ea2c012SReid Kleckner /// Number of bytes pushed to save CSRs. 1649ea2c012SReid Kleckner unsigned CSRSize = 0; 1659ea2c012SReid Kleckner 1662bcb288aSReid Kleckner /// Adjustment to apply on x86 when using the VFRAME frame pointer. 1672bcb288aSReid Kleckner int OffsetAdjustment = 0; 1682bcb288aSReid Kleckner 1699ea2c012SReid Kleckner /// Two-bit value indicating which register is the designated frame pointer 1709ea2c012SReid Kleckner /// register for local variables. Included in S_FRAMEPROC. 1719ea2c012SReid Kleckner codeview::EncodedFramePtrReg EncodedLocalFramePtrReg = 1729ea2c012SReid Kleckner codeview::EncodedFramePtrReg::None; 1739ea2c012SReid Kleckner 1749ea2c012SReid Kleckner /// Two-bit value indicating which register is the designated frame pointer 1759ea2c012SReid Kleckner /// register for stack parameters. Included in S_FRAMEPROC. 1769ea2c012SReid Kleckner codeview::EncodedFramePtrReg EncodedParamFramePtrReg = 1779ea2c012SReid Kleckner codeview::EncodedFramePtrReg::None; 1789ea2c012SReid Kleckner 1799ea2c012SReid Kleckner codeview::FrameProcedureOptions FrameProcOpts; 1809ea2c012SReid Kleckner 181d5e4ec74SReid Kleckner bool HasStackRealignment = false; 182d5e4ec74SReid Kleckner 1832214ed89SReid Kleckner bool HaveLineInfo = false; 1849533af4fSReid Kleckner }; 185fb69e66cSEugene Zelenko FunctionInfo *CurFn = nullptr; 18670f5bc99SReid Kleckner 1875a791ee4SReid Kleckner // Map used to seperate variables according to the lexical scope they belong 1885a791ee4SReid Kleckner // in. This is populated by recordLocalVariable() before 1895a791ee4SReid Kleckner // collectLexicalBlocks() separates the variables between the FunctionInfo 1905a791ee4SReid Kleckner // and LexicalBlocks. 1915a791ee4SReid Kleckner DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables; 1925a791ee4SReid Kleckner 193b17464e4SBrock Wyma // Map to separate global variables according to the lexical scope they 194b17464e4SBrock Wyma // belong in. A null local scope represents the global scope. 195b17464e4SBrock Wyma typedef SmallVector<CVGlobalVariable, 1> GlobalVariableList; 196b17464e4SBrock Wyma DenseMap<const DIScope*, std::unique_ptr<GlobalVariableList> > ScopeGlobals; 197b17464e4SBrock Wyma 198b17464e4SBrock Wyma // Array of global variables which need to be emitted into a COMDAT section. 199b17464e4SBrock Wyma SmallVector<CVGlobalVariable, 1> ComdatVariables; 200b17464e4SBrock Wyma 201b17464e4SBrock Wyma // Array of non-COMDAT global variables. 202b17464e4SBrock Wyma SmallVector<CVGlobalVariable, 1> GlobalVariables; 203b17464e4SBrock Wyma 2045d122f87SReid Kleckner /// The set of comdat .debug$S sections that we've seen so far. Each section 2055d122f87SReid Kleckner /// must start with a magic version number that must only be emitted once. 2065d122f87SReid Kleckner /// This set tracks which sections we've already opened. 2075d122f87SReid Kleckner DenseSet<MCSectionCOFF *> ComdatDebugSections; 2085d122f87SReid Kleckner 2095d122f87SReid Kleckner /// Switch to the appropriate .debug$S section for GVSym. If GVSym, the symbol 2105d122f87SReid Kleckner /// of an emitted global value, is in a comdat COFF section, this will switch 2115d122f87SReid Kleckner /// to a new .debug$S section in that comdat. This method ensures that the 2125d122f87SReid Kleckner /// section starts with the magic version number on first use. If GVSym is 2135d122f87SReid Kleckner /// null, uses the main .debug$S section. 2145d122f87SReid Kleckner void switchToDebugSectionForSymbol(const MCSymbol *GVSym); 2155d122f87SReid Kleckner 216fbd7787dSReid Kleckner /// The next available function index for use with our .cv_* directives. Not 217fbd7787dSReid Kleckner /// to be confused with type indices for LF_FUNC_ID records. 2182214ed89SReid Kleckner unsigned NextFuncId = 0; 21970f5bc99SReid Kleckner 220876330d5SReid Kleckner InlineSite &getInlineSite(const DILocation *InlinedAt, 221876330d5SReid Kleckner const DISubprogram *Inlinee); 222f3b9ba49SReid Kleckner 22375c3ebfaSDavid Majnemer codeview::TypeIndex getFuncIdForSubprogram(const DISubprogram *SP); 2242280f932SReid Kleckner 225223303c5SBob Haarman void calculateRanges(LocalVariable &Var, 2266feef56dSDavid Stenberg const DbgValueHistoryMap::Entries &Entries); 227223303c5SBob Haarman 2281fcd610cSReid Kleckner static void collectInlineSiteChildren(SmallVectorImpl<unsigned> &Children, 2291fcd610cSReid Kleckner const FunctionInfo &FI, 2301fcd610cSReid Kleckner const InlineSite &Site); 2311fcd610cSReid Kleckner 2322214ed89SReid Kleckner /// Remember some debug info about each function. Keep it in a stable order to 2332214ed89SReid Kleckner /// emit at the end of the TU. 23455baeefdSReid Kleckner MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo; 23570f5bc99SReid Kleckner 236bc6f52daSReid Kleckner /// Map from full file path to .cv_file id. Full paths are built from DIFiles 237bc6f52daSReid Kleckner /// and are stored in FileToFilepathMap; 238bc6f52daSReid Kleckner DenseMap<StringRef, unsigned> FileIdMap; 23970f5bc99SReid Kleckner 240fbd7787dSReid Kleckner /// All inlined subprograms in the order they should be emitted. 2412280f932SReid Kleckner SmallSetVector<const DISubprogram *, 4> InlinedSubprograms; 242f3b9ba49SReid Kleckner 24376c9eb99SAmjad Aboud /// Map from a pair of DI metadata nodes and its DI type (or scope) that can 24476c9eb99SAmjad Aboud /// be nullptr, to CodeView type indices. Primarily indexed by 24576c9eb99SAmjad Aboud /// {DIType*, DIType*} and {DISubprogram*, DIType*}. 24676c9eb99SAmjad Aboud /// 24776c9eb99SAmjad Aboud /// The second entry in the key is needed for methods as DISubroutineType 24876c9eb99SAmjad Aboud /// representing static method type are shared with non-method function type. 24976c9eb99SAmjad Aboud DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex> 25076c9eb99SAmjad Aboud TypeIndices; 251f3b9ba49SReid Kleckner 252a8d57407SReid Kleckner /// Map from DICompositeType* to complete type index. Non-record types are 253a8d57407SReid Kleckner /// always looked up in the normal TypeIndices map. 254a8d57407SReid Kleckner DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices; 255a8d57407SReid Kleckner 256643dd836SReid Kleckner /// Complete record types to emit after all active type lowerings are 257643dd836SReid Kleckner /// finished. 258643dd836SReid Kleckner SmallVector<const DICompositeType *, 4> DeferredCompleteTypes; 259643dd836SReid Kleckner 260643dd836SReid Kleckner /// Number of type lowering frames active on the stack. 261643dd836SReid Kleckner unsigned TypeEmissionLevel = 0; 262643dd836SReid Kleckner 2639f7f3e1eSReid Kleckner codeview::TypeIndex VBPType; 2649f7f3e1eSReid Kleckner 2653128b10cSDavid Majnemer const DISubprogram *CurrentSubprogram = nullptr; 2663128b10cSDavid Majnemer 2673128b10cSDavid Majnemer // The UDTs we have seen while processing types; each entry is a pair of type 2683128b10cSDavid Majnemer // index and type name. 269a7b04174SZachary Turner std::vector<std::pair<std::string, const DIType *>> LocalUDTs; 270a7b04174SZachary Turner std::vector<std::pair<std::string, const DIType *>> GlobalUDTs; 2713128b10cSDavid Majnemer 272fb69e66cSEugene Zelenko using FileToFilepathMapTy = std::map<const DIFile *, std::string>; 2739533af4fSReid Kleckner FileToFilepathMapTy FileToFilepathMap; 274fb69e66cSEugene Zelenko 275cb0bab86SFangrui Song StringRef getFullFilepath(const DIFile *File); 27670f5bc99SReid Kleckner 2772214ed89SReid Kleckner unsigned maybeRecordFile(const DIFile *F); 2782214ed89SReid Kleckner 279bdc4956bSBenjamin Kramer void maybeRecordLocation(const DebugLoc &DL, const MachineFunction *MF); 28070f5bc99SReid Kleckner 28176c9eb99SAmjad Aboud void clear(); 2823128b10cSDavid Majnemer 2833128b10cSDavid Majnemer void setCurrentSubprogram(const DISubprogram *SP) { 2843128b10cSDavid Majnemer CurrentSubprogram = SP; 2853128b10cSDavid Majnemer LocalUDTs.clear(); 28670f5bc99SReid Kleckner } 28770f5bc99SReid Kleckner 2885d122f87SReid Kleckner /// Emit the magic version number at the start of a CodeView type or symbol 289d9e96741SAlexandre Ganea /// section. Appears at the front of every .debug$S or .debug$T or .debug$P 290d9e96741SAlexandre Ganea /// section. 2915d122f87SReid Kleckner void emitCodeViewMagicVersion(); 2925d122f87SReid Kleckner 293f3b9ba49SReid Kleckner void emitTypeInformation(); 294f3b9ba49SReid Kleckner 295048f8f99SZachary Turner void emitTypeGlobalHashes(); 296048f8f99SZachary Turner 297c64acfd4SAdrian McCarthy void emitCompilerInformation(); 298c64acfd4SAdrian McCarthy 299810687cbSReid Kleckner void emitBuildInfo(); 300810687cbSReid Kleckner 3015d122f87SReid Kleckner void emitInlineeLinesSubsection(); 3021fcd610cSReid Kleckner 30394ece8fbSBrock Wyma void emitDebugInfoForThunk(const Function *GV, 30494ece8fbSBrock Wyma FunctionInfo &FI, 30594ece8fbSBrock Wyma const MCSymbol *Fn); 30694ece8fbSBrock Wyma 3072214ed89SReid Kleckner void emitDebugInfoForFunction(const Function *GV, FunctionInfo &FI); 30870f5bc99SReid Kleckner 309b510b458SHans Wennborg void emitDebugInfoForRetainedTypes(); 310b510b458SHans Wennborg 311a7b04174SZachary Turner void 312a7b04174SZachary Turner emitDebugInfoForUDTs(ArrayRef<std::pair<std::string, const DIType *>> UDTs); 3133128b10cSDavid Majnemer 314b17464e4SBrock Wyma void emitDebugInfoForGlobals(); 315b17464e4SBrock Wyma void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals); 316d4135bbcSPeter Collingbourne void emitDebugInfoForGlobal(const DIGlobalVariable *DIGV, 317d4135bbcSPeter Collingbourne const GlobalVariable *GV, MCSymbol *GVSym); 3186f3406dfSReid Kleckner 3196f3406dfSReid Kleckner /// Opens a subsection of the given kind in a .debug$S codeview section. 3206f3406dfSReid Kleckner /// Returns an end label for use with endCVSubsection when the subsection is 3216f3406dfSReid Kleckner /// finished. 3228c099fe0SZachary Turner MCSymbol *beginCVSubsection(codeview::DebugSubsectionKind Kind); 3236f3406dfSReid Kleckner void endCVSubsection(MCSymbol *EndLabel); 3246f3406dfSReid Kleckner 3255bf71d11SReid Kleckner /// Opens a symbol record of the given kind. Returns an end label for use with 3265bf71d11SReid Kleckner /// endSymbolRecord. 3275bf71d11SReid Kleckner MCSymbol *beginSymbolRecord(codeview::SymbolKind Kind); 3285bf71d11SReid Kleckner void endSymbolRecord(MCSymbol *SymEnd); 3295bf71d11SReid Kleckner 3305bf71d11SReid Kleckner /// Emits an S_END, S_INLINESITE_END, or S_PROC_ID_END record. These records 3315bf71d11SReid Kleckner /// are empty, so we emit them with a simpler assembly sequence that doesn't 3325bf71d11SReid Kleckner /// involve labels. 3335bf71d11SReid Kleckner void emitEndSymbolRecord(codeview::SymbolKind EndKind); 3345bf71d11SReid Kleckner 335f3b9ba49SReid Kleckner void emitInlinedCallSite(const FunctionInfo &FI, const DILocation *InlinedAt, 336f3b9ba49SReid Kleckner const InlineSite &Site); 337f3b9ba49SReid Kleckner 338760c1ab1SHsiangkai Wang using InlinedEntity = DbgValueHistoryMap::InlinedEntity; 339876330d5SReid Kleckner 340b17464e4SBrock Wyma void collectGlobalVariableInfo(); 341876330d5SReid Kleckner void collectVariableInfo(const DISubprogram *SP); 342876330d5SReid Kleckner 343760c1ab1SHsiangkai Wang void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed); 344876330d5SReid Kleckner 3455a791ee4SReid Kleckner // Construct the lexical block tree for a routine, pruning emptpy lexical 3465a791ee4SReid Kleckner // scopes, and populate it with local variables. 3475a791ee4SReid Kleckner void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes, 3485a791ee4SReid Kleckner SmallVectorImpl<LexicalBlock *> &Blocks, 349b17464e4SBrock Wyma SmallVectorImpl<LocalVariable> &Locals, 350b17464e4SBrock Wyma SmallVectorImpl<CVGlobalVariable> &Globals); 3515a791ee4SReid Kleckner void collectLexicalBlockInfo(LexicalScope &Scope, 3525a791ee4SReid Kleckner SmallVectorImpl<LexicalBlock *> &ParentBlocks, 353b17464e4SBrock Wyma SmallVectorImpl<LocalVariable> &ParentLocals, 354b17464e4SBrock Wyma SmallVectorImpl<CVGlobalVariable> &ParentGlobals); 3555a791ee4SReid Kleckner 356876330d5SReid Kleckner /// Records information about a local variable in the appropriate scope. In 357876330d5SReid Kleckner /// particular, locals from inlined code live inside the inlining site. 3585a791ee4SReid Kleckner void recordLocalVariable(LocalVariable &&Var, const LexicalScope *LS); 359f9c275feSReid Kleckner 36010dd55c5SReid Kleckner /// Emits local variables in the appropriate order. 3619ea2c012SReid Kleckner void emitLocalVariableList(const FunctionInfo &FI, 3629ea2c012SReid Kleckner ArrayRef<LocalVariable> Locals); 36310dd55c5SReid Kleckner 36410dd55c5SReid Kleckner /// Emits an S_LOCAL record and its associated defined ranges. 3659ea2c012SReid Kleckner void emitLocalVariable(const FunctionInfo &FI, const LocalVariable &Var); 366f9c275feSReid Kleckner 3675a791ee4SReid Kleckner /// Emits a sequence of lexical block scopes and their children. 3685a791ee4SReid Kleckner void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks, 3695a791ee4SReid Kleckner const FunctionInfo& FI); 3705a791ee4SReid Kleckner 3715a791ee4SReid Kleckner /// Emit a lexical block scope and its children. 3725a791ee4SReid Kleckner void emitLexicalBlock(const LexicalBlock &Block, const FunctionInfo& FI); 3735a791ee4SReid Kleckner 3745acacbb0SReid Kleckner /// Translates the DIType to codeview if necessary and returns a type index 3755acacbb0SReid Kleckner /// for it. 376*da82ce99SFangrui Song codeview::TypeIndex getTypeIndex(const DIType *Ty, 377*da82ce99SFangrui Song const DIType *ClassTy = nullptr); 3785acacbb0SReid Kleckner 379c68f8957SZachary Turner codeview::TypeIndex 380c168c6f8SReid Kleckner getTypeIndexForThisPtr(const DIDerivedType *PtrTy, 381c68f8957SZachary Turner const DISubroutineType *SubroutineTy); 382c68f8957SZachary Turner 383*da82ce99SFangrui Song codeview::TypeIndex getTypeIndexForReferenceTo(const DIType *Ty); 384223303c5SBob Haarman 3850c5d874bSReid Kleckner codeview::TypeIndex getMemberFunctionType(const DISubprogram *SP, 3860c5d874bSReid Kleckner const DICompositeType *Class); 3870c5d874bSReid Kleckner 3880c5d874bSReid Kleckner codeview::TypeIndex getScopeIndex(const DIScope *Scope); 3890c5d874bSReid Kleckner 3909f7f3e1eSReid Kleckner codeview::TypeIndex getVBPTypeIndex(); 3919f7f3e1eSReid Kleckner 392a7b04174SZachary Turner void addToUDTs(const DIType *Ty); 3934b63a98dSHans Wennborg 394122d9e79SAaron Smith void addUDTSrcLine(const DIType *Ty, codeview::TypeIndex TI); 395122d9e79SAaron Smith 39676c9eb99SAmjad Aboud codeview::TypeIndex lowerType(const DIType *Ty, const DIType *ClassTy); 397d065e23dSDavid Majnemer codeview::TypeIndex lowerTypeAlias(const DIDerivedType *Ty); 398f3c3c132SAdrian McCarthy codeview::TypeIndex lowerTypeArray(const DICompositeType *Ty); 3995acacbb0SReid Kleckner codeview::TypeIndex lowerTypeBasic(const DIBasicType *Ty); 4003acdc677SReid Kleckner codeview::TypeIndex lowerTypePointer( 4013acdc677SReid Kleckner const DIDerivedType *Ty, 4023acdc677SReid Kleckner codeview::PointerOptions PO = codeview::PointerOptions::None); 4033acdc677SReid Kleckner codeview::TypeIndex lowerTypeMemberPointer( 4043acdc677SReid Kleckner const DIDerivedType *Ty, 4053acdc677SReid Kleckner codeview::PointerOptions PO = codeview::PointerOptions::None); 4065acacbb0SReid Kleckner codeview::TypeIndex lowerTypeModifier(const DIDerivedType *Ty); 40775c3ebfaSDavid Majnemer codeview::TypeIndex lowerTypeFunction(const DISubroutineType *Ty); 4089dac4731SReid Kleckner codeview::TypeIndex lowerTypeVFTableShape(const DIDerivedType *Ty); 409802b033dSAaron Smith codeview::TypeIndex lowerTypeMemberFunction( 410802b033dSAaron Smith const DISubroutineType *Ty, const DIType *ClassTy, int ThisAdjustment, 411802b033dSAaron Smith bool IsStaticMethod, 412802b033dSAaron Smith codeview::FunctionOptions FO = codeview::FunctionOptions::None); 413979cb888SDavid Majnemer codeview::TypeIndex lowerTypeEnum(const DICompositeType *Ty); 414a8d57407SReid Kleckner codeview::TypeIndex lowerTypeClass(const DICompositeType *Ty); 415a8d57407SReid Kleckner codeview::TypeIndex lowerTypeUnion(const DICompositeType *Ty); 416a8d57407SReid Kleckner 417a8d57407SReid Kleckner /// Symbol records should point to complete types, but type records should 418a8d57407SReid Kleckner /// always point to incomplete types to avoid cycles in the type graph. Only 419a8d57407SReid Kleckner /// use this entry point when generating symbol records. The complete and 420a8d57407SReid Kleckner /// incomplete type indices only differ for record types. All other types use 421a8d57407SReid Kleckner /// the same index. 422*da82ce99SFangrui Song codeview::TypeIndex getCompleteTypeIndex(const DIType *Ty); 423a8d57407SReid Kleckner 424a8d57407SReid Kleckner codeview::TypeIndex lowerCompleteTypeClass(const DICompositeType *Ty); 425a8d57407SReid Kleckner codeview::TypeIndex lowerCompleteTypeUnion(const DICompositeType *Ty); 426a8d57407SReid Kleckner 427643dd836SReid Kleckner struct TypeLoweringScope; 428643dd836SReid Kleckner 429643dd836SReid Kleckner void emitDeferredCompleteTypes(); 430643dd836SReid Kleckner 43176c9eb99SAmjad Aboud void collectMemberInfo(ClassInfo &Info, const DIDerivedType *DDTy); 4321ab7eac8SReid Kleckner ClassInfo collectClassInfo(const DICompositeType *Ty); 43376c9eb99SAmjad Aboud 434a8d57407SReid Kleckner /// Common record member lowering functionality for record types, which are 435a8d57407SReid Kleckner /// structs, classes, and unions. Returns the field list index and the member 436a8d57407SReid Kleckner /// count. 437820ca540SAdrian McCarthy std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool> 438a8d57407SReid Kleckner lowerRecordFieldList(const DICompositeType *Ty); 439a8d57407SReid Kleckner 44076c9eb99SAmjad Aboud /// Inserts {{Node, ClassTy}, TI} into TypeIndices and checks for duplicates. 4410c5d874bSReid Kleckner codeview::TypeIndex recordTypeIndexForDINode(const DINode *Node, 4420c5d874bSReid Kleckner codeview::TypeIndex TI, 44376c9eb99SAmjad Aboud const DIType *ClassTy = nullptr); 44476c9eb99SAmjad Aboud 44576c9eb99SAmjad Aboud unsigned getPointerSizeInBytes(); 4465acacbb0SReid Kleckner 447b2fbb4b2SDavid Blaikie protected: 4485f8f34e4SAdrian Prantl /// Gather pre-function debug information. 449b2fbb4b2SDavid Blaikie void beginFunctionImpl(const MachineFunction *MF) override; 450b2fbb4b2SDavid Blaikie 4515f8f34e4SAdrian Prantl /// Gather post-function debug information. 452b2fbb4b2SDavid Blaikie void endFunctionImpl(const MachineFunction *) override; 453b2fbb4b2SDavid Blaikie 45470f5bc99SReid Kleckner public: 455cb0bab86SFangrui Song CodeViewDebug(AsmPrinter *AP); 45670f5bc99SReid Kleckner 457fb69e66cSEugene Zelenko void setSymbolSize(const MCSymbol *, uint64_t) override {} 45870f5bc99SReid Kleckner 4595f8f34e4SAdrian Prantl /// Emit the COFF section that holds the line table information. 46070f5bc99SReid Kleckner void endModule() override; 46170f5bc99SReid Kleckner 4625f8f34e4SAdrian Prantl /// Process beginning of an instruction. 46370f5bc99SReid Kleckner void beginInstruction(const MachineInstr *MI) override; 46470f5bc99SReid Kleckner }; 46570f5bc99SReid Kleckner 466fb69e66cSEugene Zelenko } // end namespace llvm 467fb69e66cSEugene Zelenko 468fb69e66cSEugene Zelenko #endif // LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H 469