1db17bf38SDimitry Andric //===- llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h --------------*- C++ -*-===// 23ca95b02SDimitry Andric // 33ca95b02SDimitry Andric // The LLVM Compiler Infrastructure 43ca95b02SDimitry Andric // 53ca95b02SDimitry Andric // This file is distributed under the University of Illinois Open Source 63ca95b02SDimitry Andric // License. See LICENSE.TXT for details. 73ca95b02SDimitry Andric // 83ca95b02SDimitry Andric //===----------------------------------------------------------------------===// 93ca95b02SDimitry Andric // 103ca95b02SDimitry Andric // This file contains support for writing Microsoft CodeView debug info. 113ca95b02SDimitry Andric // 123ca95b02SDimitry Andric //===----------------------------------------------------------------------===// 133ca95b02SDimitry Andric 143ca95b02SDimitry Andric #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H 153ca95b02SDimitry Andric #define LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H 163ca95b02SDimitry Andric 17db17bf38SDimitry Andric #include "llvm/ADT/ArrayRef.h" 183ca95b02SDimitry Andric #include "llvm/ADT/DenseMap.h" 19db17bf38SDimitry Andric #include "llvm/ADT/DenseSet.h" 20db17bf38SDimitry Andric #include "llvm/ADT/MapVector.h" 21db17bf38SDimitry Andric #include "llvm/ADT/SetVector.h" 22db17bf38SDimitry Andric #include "llvm/ADT/SmallVector.h" 23*b5893f02SDimitry Andric #include "llvm/CodeGen/DbgEntityHistoryCalculator.h" 24*b5893f02SDimitry Andric #include "llvm/CodeGen/DebugHandlerBase.h" 25db17bf38SDimitry Andric #include "llvm/DebugInfo/CodeView/CodeView.h" 262cab237bSDimitry Andric #include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h" 273ca95b02SDimitry Andric #include "llvm/DebugInfo/CodeView/TypeIndex.h" 283ca95b02SDimitry Andric #include "llvm/IR/DebugLoc.h" 29db17bf38SDimitry Andric #include "llvm/Support/Allocator.h" 30db17bf38SDimitry Andric #include "llvm/Support/Compiler.h" 31db17bf38SDimitry Andric #include <cstdint> 32db17bf38SDimitry Andric #include <map> 33db17bf38SDimitry Andric #include <string> 34db17bf38SDimitry Andric #include <tuple> 35db17bf38SDimitry Andric #include <unordered_map> 36db17bf38SDimitry Andric #include <utility> 37db17bf38SDimitry Andric #include <vector> 383ca95b02SDimitry Andric 393ca95b02SDimitry Andric namespace llvm { 403ca95b02SDimitry Andric 413ca95b02SDimitry Andric struct ClassInfo; 42db17bf38SDimitry Andric class StringRef; 43db17bf38SDimitry Andric class AsmPrinter; 44db17bf38SDimitry Andric class Function; 45db17bf38SDimitry Andric class GlobalVariable; 46db17bf38SDimitry Andric class MCSectionCOFF; 47db17bf38SDimitry Andric class MCStreamer; 48db17bf38SDimitry Andric class MCSymbol; 49db17bf38SDimitry Andric class MachineFunction; 503ca95b02SDimitry Andric 514ba319b5SDimitry Andric /// Collects and handles line tables information in a CodeView format. 523ca95b02SDimitry Andric class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase { 533ca95b02SDimitry Andric MCStreamer &OS; 54db17bf38SDimitry Andric BumpPtrAllocator Allocator; 552cab237bSDimitry Andric codeview::GlobalTypeTableBuilder TypeTable; 563ca95b02SDimitry Andric 57*b5893f02SDimitry Andric /// Whether to emit type record hashes into .debug$H. 58*b5893f02SDimitry Andric bool EmitDebugGlobalHashes = false; 59*b5893f02SDimitry Andric 60*b5893f02SDimitry Andric /// The codeview CPU type used by the translation unit. 61*b5893f02SDimitry Andric codeview::CPUType TheCPU; 62*b5893f02SDimitry Andric 633ca95b02SDimitry Andric /// Represents the most general definition range. 643ca95b02SDimitry Andric struct LocalVarDefRange { 653ca95b02SDimitry Andric /// Indicates that variable data is stored in memory relative to the 663ca95b02SDimitry Andric /// specified register. 673ca95b02SDimitry Andric int InMemory : 1; 683ca95b02SDimitry Andric 693ca95b02SDimitry Andric /// Offset of variable data in memory. 703ca95b02SDimitry Andric int DataOffset : 31; 713ca95b02SDimitry Andric 72d88c1a5aSDimitry Andric /// Non-zero if this is a piece of an aggregate. 73d88c1a5aSDimitry Andric uint16_t IsSubfield : 1; 74d88c1a5aSDimitry Andric 75d88c1a5aSDimitry Andric /// Offset into aggregate. 76d88c1a5aSDimitry Andric uint16_t StructOffset : 15; 773ca95b02SDimitry Andric 783ca95b02SDimitry Andric /// Register containing the data or the register base of the memory 793ca95b02SDimitry Andric /// location containing the data. 803ca95b02SDimitry Andric uint16_t CVRegister; 813ca95b02SDimitry Andric 823ca95b02SDimitry Andric /// Compares all location fields. This includes all fields except the label 833ca95b02SDimitry Andric /// ranges. isDifferentLocationLocalVarDefRange843ca95b02SDimitry Andric bool isDifferentLocation(LocalVarDefRange &O) { 853ca95b02SDimitry Andric return InMemory != O.InMemory || DataOffset != O.DataOffset || 86d88c1a5aSDimitry Andric IsSubfield != O.IsSubfield || StructOffset != O.StructOffset || 87d88c1a5aSDimitry Andric CVRegister != O.CVRegister; 883ca95b02SDimitry Andric } 893ca95b02SDimitry Andric 903ca95b02SDimitry Andric SmallVector<std::pair<const MCSymbol *, const MCSymbol *>, 1> Ranges; 913ca95b02SDimitry Andric }; 923ca95b02SDimitry Andric 933ca95b02SDimitry Andric static LocalVarDefRange createDefRangeMem(uint16_t CVRegister, int Offset); 943ca95b02SDimitry Andric 953ca95b02SDimitry Andric /// Similar to DbgVariable in DwarfDebug, but not dwarf-specific. 963ca95b02SDimitry Andric struct LocalVariable { 973ca95b02SDimitry Andric const DILocalVariable *DIVar = nullptr; 983ca95b02SDimitry Andric SmallVector<LocalVarDefRange, 1> DefRanges; 992cab237bSDimitry Andric bool UseReferenceType = false; 1003ca95b02SDimitry Andric }; 1013ca95b02SDimitry Andric 102*b5893f02SDimitry Andric struct CVGlobalVariable { 103*b5893f02SDimitry Andric const DIGlobalVariable *DIGV; 104*b5893f02SDimitry Andric const GlobalVariable *GV; 105*b5893f02SDimitry Andric }; 106*b5893f02SDimitry Andric 1073ca95b02SDimitry Andric struct InlineSite { 1083ca95b02SDimitry Andric SmallVector<LocalVariable, 1> InlinedLocals; 1093ca95b02SDimitry Andric SmallVector<const DILocation *, 1> ChildSites; 1103ca95b02SDimitry Andric const DISubprogram *Inlinee = nullptr; 1113ca95b02SDimitry Andric 1123ca95b02SDimitry Andric /// The ID of the inline site or function used with .cv_loc. Not a type 1133ca95b02SDimitry Andric /// index. 1143ca95b02SDimitry Andric unsigned SiteFuncId = 0; 1153ca95b02SDimitry Andric }; 1163ca95b02SDimitry Andric 1174ba319b5SDimitry Andric // Combines information from DILexicalBlock and LexicalScope. 1184ba319b5SDimitry Andric struct LexicalBlock { 1194ba319b5SDimitry Andric SmallVector<LocalVariable, 1> Locals; 120*b5893f02SDimitry Andric SmallVector<CVGlobalVariable, 1> Globals; 1214ba319b5SDimitry Andric SmallVector<LexicalBlock *, 1> Children; 1224ba319b5SDimitry Andric const MCSymbol *Begin; 1234ba319b5SDimitry Andric const MCSymbol *End; 1244ba319b5SDimitry Andric StringRef Name; 1254ba319b5SDimitry Andric }; 1264ba319b5SDimitry Andric 1273ca95b02SDimitry Andric // For each function, store a vector of labels to its instructions, as well as 1283ca95b02SDimitry Andric // to the end of the function. 1293ca95b02SDimitry Andric struct FunctionInfo { 1304ba319b5SDimitry Andric FunctionInfo() = default; 1314ba319b5SDimitry Andric 1324ba319b5SDimitry Andric // Uncopyable. 1334ba319b5SDimitry Andric FunctionInfo(const FunctionInfo &FI) = delete; 1344ba319b5SDimitry Andric 1353ca95b02SDimitry Andric /// Map from inlined call site to inlined instructions and child inlined 1363ca95b02SDimitry Andric /// call sites. Listed in program order. 1373ca95b02SDimitry Andric std::unordered_map<const DILocation *, InlineSite> InlineSites; 1383ca95b02SDimitry Andric 1393ca95b02SDimitry Andric /// Ordered list of top-level inlined call sites. 1403ca95b02SDimitry Andric SmallVector<const DILocation *, 1> ChildSites; 1413ca95b02SDimitry Andric 1423ca95b02SDimitry Andric SmallVector<LocalVariable, 1> Locals; 143*b5893f02SDimitry Andric SmallVector<CVGlobalVariable, 1> Globals; 1443ca95b02SDimitry Andric 1454ba319b5SDimitry Andric std::unordered_map<const DILexicalBlockBase*, LexicalBlock> LexicalBlocks; 1464ba319b5SDimitry Andric 1474ba319b5SDimitry Andric // Lexical blocks containing local variables. 1484ba319b5SDimitry Andric SmallVector<LexicalBlock *, 1> ChildBlocks; 1494ba319b5SDimitry Andric 1502cab237bSDimitry Andric std::vector<std::pair<MCSymbol *, MDNode *>> Annotations; 1512cab237bSDimitry Andric 1523ca95b02SDimitry Andric const MCSymbol *Begin = nullptr; 1533ca95b02SDimitry Andric const MCSymbol *End = nullptr; 1543ca95b02SDimitry Andric unsigned FuncId = 0; 1553ca95b02SDimitry Andric unsigned LastFileId = 0; 156*b5893f02SDimitry Andric 157*b5893f02SDimitry Andric /// Number of bytes allocated in the prologue for all local stack objects. 158*b5893f02SDimitry Andric unsigned FrameSize = 0; 159*b5893f02SDimitry Andric 160*b5893f02SDimitry Andric /// Number of bytes of parameters on the stack. 161*b5893f02SDimitry Andric unsigned ParamSize = 0; 162*b5893f02SDimitry Andric 163*b5893f02SDimitry Andric /// Number of bytes pushed to save CSRs. 164*b5893f02SDimitry Andric unsigned CSRSize = 0; 165*b5893f02SDimitry Andric 166*b5893f02SDimitry Andric /// Adjustment to apply on x86 when using the VFRAME frame pointer. 167*b5893f02SDimitry Andric int OffsetAdjustment = 0; 168*b5893f02SDimitry Andric 169*b5893f02SDimitry Andric /// Two-bit value indicating which register is the designated frame pointer 170*b5893f02SDimitry Andric /// register for local variables. Included in S_FRAMEPROC. 171*b5893f02SDimitry Andric codeview::EncodedFramePtrReg EncodedLocalFramePtrReg = 172*b5893f02SDimitry Andric codeview::EncodedFramePtrReg::None; 173*b5893f02SDimitry Andric 174*b5893f02SDimitry Andric /// Two-bit value indicating which register is the designated frame pointer 175*b5893f02SDimitry Andric /// register for stack parameters. Included in S_FRAMEPROC. 176*b5893f02SDimitry Andric codeview::EncodedFramePtrReg EncodedParamFramePtrReg = 177*b5893f02SDimitry Andric codeview::EncodedFramePtrReg::None; 178*b5893f02SDimitry Andric 179*b5893f02SDimitry Andric codeview::FrameProcedureOptions FrameProcOpts; 180*b5893f02SDimitry Andric 181*b5893f02SDimitry Andric bool HasStackRealignment = false; 182*b5893f02SDimitry Andric 1833ca95b02SDimitry Andric bool HaveLineInfo = false; 1843ca95b02SDimitry Andric }; 185db17bf38SDimitry Andric FunctionInfo *CurFn = nullptr; 1863ca95b02SDimitry Andric 1874ba319b5SDimitry Andric // Map used to seperate variables according to the lexical scope they belong 1884ba319b5SDimitry Andric // in. This is populated by recordLocalVariable() before 1894ba319b5SDimitry Andric // collectLexicalBlocks() separates the variables between the FunctionInfo 1904ba319b5SDimitry Andric // and LexicalBlocks. 1914ba319b5SDimitry Andric DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables; 1924ba319b5SDimitry Andric 193*b5893f02SDimitry Andric // Map to separate global variables according to the lexical scope they 194*b5893f02SDimitry Andric // belong in. A null local scope represents the global scope. 195*b5893f02SDimitry Andric typedef SmallVector<CVGlobalVariable, 1> GlobalVariableList; 196*b5893f02SDimitry Andric DenseMap<const DIScope*, std::unique_ptr<GlobalVariableList> > ScopeGlobals; 197*b5893f02SDimitry Andric 198*b5893f02SDimitry Andric // Array of global variables which need to be emitted into a COMDAT section. 199*b5893f02SDimitry Andric SmallVector<CVGlobalVariable, 1> ComdatVariables; 200*b5893f02SDimitry Andric 201*b5893f02SDimitry Andric // Array of non-COMDAT global variables. 202*b5893f02SDimitry Andric SmallVector<CVGlobalVariable, 1> GlobalVariables; 203*b5893f02SDimitry Andric 2043ca95b02SDimitry Andric /// The set of comdat .debug$S sections that we've seen so far. Each section 2053ca95b02SDimitry Andric /// must start with a magic version number that must only be emitted once. 2063ca95b02SDimitry Andric /// This set tracks which sections we've already opened. 2073ca95b02SDimitry Andric DenseSet<MCSectionCOFF *> ComdatDebugSections; 2083ca95b02SDimitry Andric 2093ca95b02SDimitry Andric /// Switch to the appropriate .debug$S section for GVSym. If GVSym, the symbol 2103ca95b02SDimitry Andric /// of an emitted global value, is in a comdat COFF section, this will switch 2113ca95b02SDimitry Andric /// to a new .debug$S section in that comdat. This method ensures that the 2123ca95b02SDimitry Andric /// section starts with the magic version number on first use. If GVSym is 2133ca95b02SDimitry Andric /// null, uses the main .debug$S section. 2143ca95b02SDimitry Andric void switchToDebugSectionForSymbol(const MCSymbol *GVSym); 2153ca95b02SDimitry Andric 2163ca95b02SDimitry Andric /// The next available function index for use with our .cv_* directives. Not 2173ca95b02SDimitry Andric /// to be confused with type indices for LF_FUNC_ID records. 2183ca95b02SDimitry Andric unsigned NextFuncId = 0; 2193ca95b02SDimitry Andric 2203ca95b02SDimitry Andric InlineSite &getInlineSite(const DILocation *InlinedAt, 2213ca95b02SDimitry Andric const DISubprogram *Inlinee); 2223ca95b02SDimitry Andric 2233ca95b02SDimitry Andric codeview::TypeIndex getFuncIdForSubprogram(const DISubprogram *SP); 2243ca95b02SDimitry Andric 2252cab237bSDimitry Andric void calculateRanges(LocalVariable &Var, 2262cab237bSDimitry Andric const DbgValueHistoryMap::InstrRanges &Ranges); 2272cab237bSDimitry Andric 2283ca95b02SDimitry Andric static void collectInlineSiteChildren(SmallVectorImpl<unsigned> &Children, 2293ca95b02SDimitry Andric const FunctionInfo &FI, 2303ca95b02SDimitry Andric const InlineSite &Site); 2313ca95b02SDimitry Andric 2323ca95b02SDimitry Andric /// Remember some debug info about each function. Keep it in a stable order to 2333ca95b02SDimitry Andric /// emit at the end of the TU. 2344ba319b5SDimitry Andric MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo; 2353ca95b02SDimitry Andric 2362cab237bSDimitry Andric /// Map from full file path to .cv_file id. Full paths are built from DIFiles 2372cab237bSDimitry Andric /// and are stored in FileToFilepathMap; 2382cab237bSDimitry Andric DenseMap<StringRef, unsigned> FileIdMap; 2393ca95b02SDimitry Andric 2403ca95b02SDimitry Andric /// All inlined subprograms in the order they should be emitted. 2413ca95b02SDimitry Andric SmallSetVector<const DISubprogram *, 4> InlinedSubprograms; 2423ca95b02SDimitry Andric 2433ca95b02SDimitry Andric /// Map from a pair of DI metadata nodes and its DI type (or scope) that can 2443ca95b02SDimitry Andric /// be nullptr, to CodeView type indices. Primarily indexed by 2453ca95b02SDimitry Andric /// {DIType*, DIType*} and {DISubprogram*, DIType*}. 2463ca95b02SDimitry Andric /// 2473ca95b02SDimitry Andric /// The second entry in the key is needed for methods as DISubroutineType 2483ca95b02SDimitry Andric /// representing static method type are shared with non-method function type. 2493ca95b02SDimitry Andric DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex> 2503ca95b02SDimitry Andric TypeIndices; 2513ca95b02SDimitry Andric 2523ca95b02SDimitry Andric /// Map from DICompositeType* to complete type index. Non-record types are 2533ca95b02SDimitry Andric /// always looked up in the normal TypeIndices map. 2543ca95b02SDimitry Andric DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices; 2553ca95b02SDimitry Andric 2563ca95b02SDimitry Andric /// Complete record types to emit after all active type lowerings are 2573ca95b02SDimitry Andric /// finished. 2583ca95b02SDimitry Andric SmallVector<const DICompositeType *, 4> DeferredCompleteTypes; 2593ca95b02SDimitry Andric 2603ca95b02SDimitry Andric /// Number of type lowering frames active on the stack. 2613ca95b02SDimitry Andric unsigned TypeEmissionLevel = 0; 2623ca95b02SDimitry Andric 2633ca95b02SDimitry Andric codeview::TypeIndex VBPType; 2643ca95b02SDimitry Andric 2653ca95b02SDimitry Andric const DISubprogram *CurrentSubprogram = nullptr; 2663ca95b02SDimitry Andric 2673ca95b02SDimitry Andric // The UDTs we have seen while processing types; each entry is a pair of type 2683ca95b02SDimitry Andric // index and type name. 2692cab237bSDimitry Andric std::vector<std::pair<std::string, const DIType *>> LocalUDTs; 2702cab237bSDimitry Andric std::vector<std::pair<std::string, const DIType *>> GlobalUDTs; 2713ca95b02SDimitry Andric 272db17bf38SDimitry Andric using FileToFilepathMapTy = std::map<const DIFile *, std::string>; 2733ca95b02SDimitry Andric FileToFilepathMapTy FileToFilepathMap; 274db17bf38SDimitry Andric 2754ba319b5SDimitry Andric StringRef getFullFilepath(const DIFile *File); 2763ca95b02SDimitry Andric 2773ca95b02SDimitry Andric unsigned maybeRecordFile(const DIFile *F); 2783ca95b02SDimitry Andric 2793ca95b02SDimitry Andric void maybeRecordLocation(const DebugLoc &DL, const MachineFunction *MF); 2803ca95b02SDimitry Andric 2813ca95b02SDimitry Andric void clear(); 2823ca95b02SDimitry Andric setCurrentSubprogram(const DISubprogram * SP)2833ca95b02SDimitry Andric void setCurrentSubprogram(const DISubprogram *SP) { 2843ca95b02SDimitry Andric CurrentSubprogram = SP; 2853ca95b02SDimitry Andric LocalUDTs.clear(); 2863ca95b02SDimitry Andric } 2873ca95b02SDimitry Andric 2883ca95b02SDimitry Andric /// Emit the magic version number at the start of a CodeView type or symbol 2894ba319b5SDimitry Andric /// section. Appears at the front of every .debug$S or .debug$T or .debug$P 2904ba319b5SDimitry Andric /// section. 2913ca95b02SDimitry Andric void emitCodeViewMagicVersion(); 2923ca95b02SDimitry Andric 2933ca95b02SDimitry Andric void emitTypeInformation(); 2943ca95b02SDimitry Andric 2952cab237bSDimitry Andric void emitTypeGlobalHashes(); 2962cab237bSDimitry Andric 297d88c1a5aSDimitry Andric void emitCompilerInformation(); 298d88c1a5aSDimitry Andric 299*b5893f02SDimitry Andric void emitBuildInfo(); 300*b5893f02SDimitry Andric 3013ca95b02SDimitry Andric void emitInlineeLinesSubsection(); 3023ca95b02SDimitry Andric 3034ba319b5SDimitry Andric void emitDebugInfoForThunk(const Function *GV, 3044ba319b5SDimitry Andric FunctionInfo &FI, 3054ba319b5SDimitry Andric const MCSymbol *Fn); 3064ba319b5SDimitry Andric 3073ca95b02SDimitry Andric void emitDebugInfoForFunction(const Function *GV, FunctionInfo &FI); 3083ca95b02SDimitry Andric 3093ca95b02SDimitry Andric void emitDebugInfoForRetainedTypes(); 3103ca95b02SDimitry Andric 3112cab237bSDimitry Andric void 3122cab237bSDimitry Andric emitDebugInfoForUDTs(ArrayRef<std::pair<std::string, const DIType *>> UDTs); 3133ca95b02SDimitry Andric 314*b5893f02SDimitry Andric void emitDebugInfoForGlobals(); 315*b5893f02SDimitry Andric void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals); 316d88c1a5aSDimitry Andric void emitDebugInfoForGlobal(const DIGlobalVariable *DIGV, 317d88c1a5aSDimitry Andric const GlobalVariable *GV, MCSymbol *GVSym); 3183ca95b02SDimitry Andric 3193ca95b02SDimitry Andric /// Opens a subsection of the given kind in a .debug$S codeview section. 3203ca95b02SDimitry Andric /// Returns an end label for use with endCVSubsection when the subsection is 3213ca95b02SDimitry Andric /// finished. 32289cb50c9SDimitry Andric MCSymbol *beginCVSubsection(codeview::DebugSubsectionKind Kind); 3233ca95b02SDimitry Andric void endCVSubsection(MCSymbol *EndLabel); 3243ca95b02SDimitry Andric 325*b5893f02SDimitry Andric /// Opens a symbol record of the given kind. Returns an end label for use with 326*b5893f02SDimitry Andric /// endSymbolRecord. 327*b5893f02SDimitry Andric MCSymbol *beginSymbolRecord(codeview::SymbolKind Kind); 328*b5893f02SDimitry Andric void endSymbolRecord(MCSymbol *SymEnd); 329*b5893f02SDimitry Andric 330*b5893f02SDimitry Andric /// Emits an S_END, S_INLINESITE_END, or S_PROC_ID_END record. These records 331*b5893f02SDimitry Andric /// are empty, so we emit them with a simpler assembly sequence that doesn't 332*b5893f02SDimitry Andric /// involve labels. 333*b5893f02SDimitry Andric void emitEndSymbolRecord(codeview::SymbolKind EndKind); 334*b5893f02SDimitry Andric 3353ca95b02SDimitry Andric void emitInlinedCallSite(const FunctionInfo &FI, const DILocation *InlinedAt, 3363ca95b02SDimitry Andric const InlineSite &Site); 3373ca95b02SDimitry Andric 338*b5893f02SDimitry Andric using InlinedEntity = DbgValueHistoryMap::InlinedEntity; 3393ca95b02SDimitry Andric 340*b5893f02SDimitry Andric void collectGlobalVariableInfo(); 3413ca95b02SDimitry Andric void collectVariableInfo(const DISubprogram *SP); 3423ca95b02SDimitry Andric 343*b5893f02SDimitry Andric void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed); 3443ca95b02SDimitry Andric 3454ba319b5SDimitry Andric // Construct the lexical block tree for a routine, pruning emptpy lexical 3464ba319b5SDimitry Andric // scopes, and populate it with local variables. 3474ba319b5SDimitry Andric void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes, 3484ba319b5SDimitry Andric SmallVectorImpl<LexicalBlock *> &Blocks, 349*b5893f02SDimitry Andric SmallVectorImpl<LocalVariable> &Locals, 350*b5893f02SDimitry Andric SmallVectorImpl<CVGlobalVariable> &Globals); 3514ba319b5SDimitry Andric void collectLexicalBlockInfo(LexicalScope &Scope, 3524ba319b5SDimitry Andric SmallVectorImpl<LexicalBlock *> &ParentBlocks, 353*b5893f02SDimitry Andric SmallVectorImpl<LocalVariable> &ParentLocals, 354*b5893f02SDimitry Andric SmallVectorImpl<CVGlobalVariable> &ParentGlobals); 3554ba319b5SDimitry Andric 3563ca95b02SDimitry Andric /// Records information about a local variable in the appropriate scope. In 3573ca95b02SDimitry Andric /// particular, locals from inlined code live inside the inlining site. 3584ba319b5SDimitry Andric void recordLocalVariable(LocalVariable &&Var, const LexicalScope *LS); 3593ca95b02SDimitry Andric 3603ca95b02SDimitry Andric /// Emits local variables in the appropriate order. 361*b5893f02SDimitry Andric void emitLocalVariableList(const FunctionInfo &FI, 362*b5893f02SDimitry Andric ArrayRef<LocalVariable> Locals); 3633ca95b02SDimitry Andric 3643ca95b02SDimitry Andric /// Emits an S_LOCAL record and its associated defined ranges. 365*b5893f02SDimitry Andric void emitLocalVariable(const FunctionInfo &FI, const LocalVariable &Var); 3663ca95b02SDimitry Andric 3674ba319b5SDimitry Andric /// Emits a sequence of lexical block scopes and their children. 3684ba319b5SDimitry Andric void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks, 3694ba319b5SDimitry Andric const FunctionInfo& FI); 3704ba319b5SDimitry Andric 3714ba319b5SDimitry Andric /// Emit a lexical block scope and its children. 3724ba319b5SDimitry Andric void emitLexicalBlock(const LexicalBlock &Block, const FunctionInfo& FI); 3734ba319b5SDimitry Andric 3743ca95b02SDimitry Andric /// Translates the DIType to codeview if necessary and returns a type index 3753ca95b02SDimitry Andric /// for it. 3763ca95b02SDimitry Andric codeview::TypeIndex getTypeIndex(DITypeRef TypeRef, 3773ca95b02SDimitry Andric DITypeRef ClassTyRef = DITypeRef()); 3783ca95b02SDimitry Andric 379*b5893f02SDimitry Andric codeview::TypeIndex 380*b5893f02SDimitry Andric getTypeIndexForThisPtr(const DIDerivedType *PtrTy, 381*b5893f02SDimitry Andric const DISubroutineType *SubroutineTy); 382*b5893f02SDimitry Andric 3832cab237bSDimitry Andric codeview::TypeIndex getTypeIndexForReferenceTo(DITypeRef TypeRef); 3842cab237bSDimitry Andric 3853ca95b02SDimitry Andric codeview::TypeIndex getMemberFunctionType(const DISubprogram *SP, 3863ca95b02SDimitry Andric const DICompositeType *Class); 3873ca95b02SDimitry Andric 3883ca95b02SDimitry Andric codeview::TypeIndex getScopeIndex(const DIScope *Scope); 3893ca95b02SDimitry Andric 3903ca95b02SDimitry Andric codeview::TypeIndex getVBPTypeIndex(); 3913ca95b02SDimitry Andric 3922cab237bSDimitry Andric void addToUDTs(const DIType *Ty); 3933ca95b02SDimitry Andric 3944ba319b5SDimitry Andric void addUDTSrcLine(const DIType *Ty, codeview::TypeIndex TI); 3954ba319b5SDimitry Andric 3963ca95b02SDimitry Andric codeview::TypeIndex lowerType(const DIType *Ty, const DIType *ClassTy); 3973ca95b02SDimitry Andric codeview::TypeIndex lowerTypeAlias(const DIDerivedType *Ty); 3983ca95b02SDimitry Andric codeview::TypeIndex lowerTypeArray(const DICompositeType *Ty); 3993ca95b02SDimitry Andric codeview::TypeIndex lowerTypeBasic(const DIBasicType *Ty); 4004ba319b5SDimitry Andric codeview::TypeIndex lowerTypePointer( 4014ba319b5SDimitry Andric const DIDerivedType *Ty, 4024ba319b5SDimitry Andric codeview::PointerOptions PO = codeview::PointerOptions::None); 4034ba319b5SDimitry Andric codeview::TypeIndex lowerTypeMemberPointer( 4044ba319b5SDimitry Andric const DIDerivedType *Ty, 4054ba319b5SDimitry Andric codeview::PointerOptions PO = codeview::PointerOptions::None); 4063ca95b02SDimitry Andric codeview::TypeIndex lowerTypeModifier(const DIDerivedType *Ty); 4073ca95b02SDimitry Andric codeview::TypeIndex lowerTypeFunction(const DISubroutineType *Ty); 408d88c1a5aSDimitry Andric codeview::TypeIndex lowerTypeVFTableShape(const DIDerivedType *Ty); 409*b5893f02SDimitry Andric codeview::TypeIndex lowerTypeMemberFunction( 410*b5893f02SDimitry Andric const DISubroutineType *Ty, const DIType *ClassTy, int ThisAdjustment, 411*b5893f02SDimitry Andric bool IsStaticMethod, 412*b5893f02SDimitry Andric codeview::FunctionOptions FO = codeview::FunctionOptions::None); 4133ca95b02SDimitry Andric codeview::TypeIndex lowerTypeEnum(const DICompositeType *Ty); 4143ca95b02SDimitry Andric codeview::TypeIndex lowerTypeClass(const DICompositeType *Ty); 4153ca95b02SDimitry Andric codeview::TypeIndex lowerTypeUnion(const DICompositeType *Ty); 4163ca95b02SDimitry Andric 4173ca95b02SDimitry Andric /// Symbol records should point to complete types, but type records should 4183ca95b02SDimitry Andric /// always point to incomplete types to avoid cycles in the type graph. Only 4193ca95b02SDimitry Andric /// use this entry point when generating symbol records. The complete and 4203ca95b02SDimitry Andric /// incomplete type indices only differ for record types. All other types use 4213ca95b02SDimitry Andric /// the same index. 4223ca95b02SDimitry Andric codeview::TypeIndex getCompleteTypeIndex(DITypeRef TypeRef); 4233ca95b02SDimitry Andric 4243ca95b02SDimitry Andric codeview::TypeIndex lowerCompleteTypeClass(const DICompositeType *Ty); 4253ca95b02SDimitry Andric codeview::TypeIndex lowerCompleteTypeUnion(const DICompositeType *Ty); 4263ca95b02SDimitry Andric 4273ca95b02SDimitry Andric struct TypeLoweringScope; 4283ca95b02SDimitry Andric 4293ca95b02SDimitry Andric void emitDeferredCompleteTypes(); 4303ca95b02SDimitry Andric 4313ca95b02SDimitry Andric void collectMemberInfo(ClassInfo &Info, const DIDerivedType *DDTy); 4323ca95b02SDimitry Andric ClassInfo collectClassInfo(const DICompositeType *Ty); 4333ca95b02SDimitry Andric 4343ca95b02SDimitry Andric /// Common record member lowering functionality for record types, which are 4353ca95b02SDimitry Andric /// structs, classes, and unions. Returns the field list index and the member 4363ca95b02SDimitry Andric /// count. 4373ca95b02SDimitry Andric std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool> 4383ca95b02SDimitry Andric lowerRecordFieldList(const DICompositeType *Ty); 4393ca95b02SDimitry Andric 4403ca95b02SDimitry Andric /// Inserts {{Node, ClassTy}, TI} into TypeIndices and checks for duplicates. 4413ca95b02SDimitry Andric codeview::TypeIndex recordTypeIndexForDINode(const DINode *Node, 4423ca95b02SDimitry Andric codeview::TypeIndex TI, 4433ca95b02SDimitry Andric const DIType *ClassTy = nullptr); 4443ca95b02SDimitry Andric 4453ca95b02SDimitry Andric unsigned getPointerSizeInBytes(); 4463ca95b02SDimitry Andric 4477a7e6055SDimitry Andric protected: 4484ba319b5SDimitry Andric /// Gather pre-function debug information. 4497a7e6055SDimitry Andric void beginFunctionImpl(const MachineFunction *MF) override; 4507a7e6055SDimitry Andric 4514ba319b5SDimitry Andric /// Gather post-function debug information. 4527a7e6055SDimitry Andric void endFunctionImpl(const MachineFunction *) override; 4537a7e6055SDimitry Andric 4543ca95b02SDimitry Andric public: 4554ba319b5SDimitry Andric CodeViewDebug(AsmPrinter *AP); 4563ca95b02SDimitry Andric setSymbolSize(const MCSymbol *,uint64_t)457db17bf38SDimitry Andric void setSymbolSize(const MCSymbol *, uint64_t) override {} 4583ca95b02SDimitry Andric 4594ba319b5SDimitry Andric /// Emit the COFF section that holds the line table information. 4603ca95b02SDimitry Andric void endModule() override; 4613ca95b02SDimitry Andric 4624ba319b5SDimitry Andric /// Process beginning of an instruction. 4633ca95b02SDimitry Andric void beginInstruction(const MachineInstr *MI) override; 4643ca95b02SDimitry Andric }; 4653ca95b02SDimitry Andric 466db17bf38SDimitry Andric } // end namespace llvm 467db17bf38SDimitry Andric 468db17bf38SDimitry Andric #endif // LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H 469