13#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H
14#define LLVM_LIB_CODEGEN_ASMPRINTER_CODEVIEWDEBUG_H
35#include <unordered_map>
74 std::memcpy(&Val, &DR,
sizeof(Val));
80 std::memcpy(&DR, &Val,
sizeof(Val));
85 static_assert(
sizeof(
uint64_t) ==
sizeof(LocalVarDef));
93 bool EmitDebugGlobalHashes =
false;
98 static LocalVarDef createDefRangeMem(
uint16_t CVRegister,
int Offset);
101 struct LocalVariable {
106 bool UseReferenceType =
false;
107 std::optional<APSInt> ConstantValue;
110 struct CVGlobalVariable {
111 const DIGlobalVariable *DIGV;
112 PointerUnion<const GlobalVariable *, const DIExpression *> GVInfo;
116 SmallVector<LocalVariable, 1> InlinedLocals;
117 SmallVector<const DILocation *, 1> ChildSites;
118 const DISubprogram *
Inlinee =
nullptr;
122 unsigned SiteFuncId = 0;
126 struct LexicalBlock {
127 SmallVector<LocalVariable, 1>
Locals;
128 SmallVector<CVGlobalVariable, 1>
Globals;
129 SmallVector<LexicalBlock *, 1>
Children;
137 struct FunctionInfo {
138 FunctionInfo() =
default;
141 FunctionInfo(
const FunctionInfo &FI) =
delete;
145 std::unordered_map<const DILocation *, InlineSite> InlineSites;
148 SmallVector<const DILocation *, 1> ChildSites;
150 SmallVector<LocalVariable, 1>
Locals;
151 SmallVector<CVGlobalVariable, 1>
Globals;
153 std::unordered_map<const DILexicalBlockBase*, LexicalBlock> LexicalBlocks;
156 SmallVector<LexicalBlock *, 1> ChildBlocks;
158 std::vector<std::pair<MCSymbol *, MDNode *>> Annotations;
159 std::vector<std::tuple<const MCSymbol *, const MCSymbol *, const DIType *>>
165 unsigned LastFileId = 0;
168 unsigned FrameSize = 0;
171 unsigned ParamSize = 0;
174 unsigned CSRSize = 0;
177 int OffsetAdjustment = 0;
181 codeview::EncodedFramePtrReg EncodedLocalFramePtrReg =
182 codeview::EncodedFramePtrReg::None;
186 codeview::EncodedFramePtrReg EncodedParamFramePtrReg =
187 codeview::EncodedFramePtrReg::None;
189 codeview::FrameProcedureOptions FrameProcOpts;
191 bool HasStackRealignment =
false;
193 bool HaveLineInfo =
false;
195 bool HasFramePointer =
false;
197 FunctionInfo *CurFn =
nullptr;
204 DenseMap<const DIGlobalVariable *, uint64_t> CVGlobalVariableOffsets;
210 DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables;
214 typedef SmallVector<CVGlobalVariable, 1> GlobalVariableList;
215 DenseMap<const DIScope*, std::unique_ptr<GlobalVariableList> > ScopeGlobals;
218 SmallVector<CVGlobalVariable, 1> ComdatVariables;
221 SmallVector<CVGlobalVariable, 1> GlobalVariables;
224 SmallVector<const DIDerivedType *, 4> StaticConstMembers;
229 DenseSet<MCSectionCOFF *> ComdatDebugSections;
236 void switchToDebugSectionForSymbol(
const MCSymbol *GVSym);
240 unsigned NextFuncId = 0;
242 InlineSite &getInlineSite(
const DILocation *InlinedAt,
243 const DISubprogram *Inlinee);
245 codeview::TypeIndex getFuncIdForSubprogram(
const DISubprogram *SP);
247 void calculateRanges(LocalVariable &Var,
252 MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo;
256 DenseMap<StringRef, unsigned> FileIdMap;
259 SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;
267 DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex>
272 DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;
276 SmallVector<const DICompositeType *, 4> DeferredCompleteTypes;
279 unsigned TypeEmissionLevel = 0;
281 codeview::TypeIndex VBPType;
283 const DISubprogram *CurrentSubprogram =
nullptr;
287 std::vector<std::pair<std::string, const DIType *>> LocalUDTs;
288 std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;
290 using FileToFilepathMapTy = std::map<const DIFile *, std::string>;
291 FileToFilepathMapTy FileToFilepathMap;
293 StringRef getFullFilepath(
const DIFile *File);
295 unsigned maybeRecordFile(
const DIFile *
F);
297 void maybeRecordLocation(
const DebugLoc &
DL,
const MachineFunction *MF);
301 void setCurrentSubprogram(
const DISubprogram *SP) {
302 CurrentSubprogram = SP;
309 void emitCodeViewMagicVersion();
311 void emitTypeInformation();
313 void emitTypeGlobalHashes();
317 void emitCompilerInformation();
319 void emitBuildInfo();
321 void emitInlineeLinesSubsection();
323 void emitDebugInfoForThunk(
const Function *GV,
327 void emitDebugInfoForFunction(
const Function *GV, FunctionInfo &FI);
329 void emitDebugInfoForRetainedTypes();
331 void emitDebugInfoForUDTs(
332 const std::vector<std::pair<std::string, const DIType *>> &UDTs);
334 void collectDebugInfoForGlobals();
335 void emitDebugInfoForGlobals();
336 void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals);
337 void emitConstantSymbolRecord(
const DIType *DTy, APSInt &Value,
339 void emitDebugInfoForGlobal(
const CVGlobalVariable &CVGV);
340 void emitStaticConstMemberList();
346 void endCVSubsection(MCSymbol *EndLabel);
351 void endSymbolRecord(MCSymbol *SymEnd);
358 void emitInlinedCallSite(
const FunctionInfo &FI,
const DILocation *InlinedAt,
363 void collectGlobalVariableInfo();
364 void collectVariableInfo(
const DISubprogram *SP);
366 void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed);
370 void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes,
371 SmallVectorImpl<LexicalBlock *> &
Blocks,
372 SmallVectorImpl<LocalVariable> &Locals,
373 SmallVectorImpl<CVGlobalVariable> &Globals);
374 void collectLexicalBlockInfo(LexicalScope &Scope,
375 SmallVectorImpl<LexicalBlock *> &ParentBlocks,
376 SmallVectorImpl<LocalVariable> &ParentLocals,
377 SmallVectorImpl<CVGlobalVariable> &ParentGlobals);
381 void recordLocalVariable(LocalVariable &&Var,
const LexicalScope *LS);
384 void emitLocalVariableList(
const FunctionInfo &FI,
385 ArrayRef<LocalVariable> Locals);
388 void emitLocalVariable(
const FunctionInfo &FI,
const LocalVariable &Var);
391 void emitLexicalBlockList(ArrayRef<LexicalBlock *>
Blocks,
392 const FunctionInfo& FI);
395 void emitLexicalBlock(
const LexicalBlock &
Block,
const FunctionInfo& FI);
399 codeview::TypeIndex getTypeIndex(
const DIType *Ty,
400 const DIType *ClassTy =
nullptr);
403 getTypeIndexForThisPtr(
const DIDerivedType *PtrTy,
404 const DISubroutineType *SubroutineTy);
406 codeview::TypeIndex getTypeIndexForReferenceTo(
const DIType *Ty);
408 codeview::TypeIndex getMemberFunctionType(
const DISubprogram *SP,
409 const DICompositeType *Class);
411 codeview::TypeIndex getScopeIndex(
const DIScope *Scope);
413 codeview::TypeIndex getVBPTypeIndex();
415 void addToUDTs(
const DIType *Ty);
417 void addUDTSrcLine(
const DIType *Ty, codeview::TypeIndex TI);
419 codeview::TypeIndex lowerType(
const DIType *Ty,
const DIType *ClassTy);
420 codeview::TypeIndex lowerTypeAlias(
const DIDerivedType *Ty);
421 codeview::TypeIndex lowerTypeArray(
const DICompositeType *Ty);
422 codeview::TypeIndex lowerTypeString(
const DIStringType *Ty);
423 codeview::TypeIndex lowerTypeBasic(
const DIBasicType *Ty);
424 codeview::TypeIndex lowerTypePointer(
425 const DIDerivedType *Ty,
427 codeview::TypeIndex lowerTypeMemberPointer(
428 const DIDerivedType *Ty,
430 codeview::TypeIndex lowerTypeModifier(
const DIDerivedType *Ty);
431 codeview::TypeIndex lowerTypeFunction(
const DISubroutineType *Ty);
432 codeview::TypeIndex lowerTypeVFTableShape(
const DIDerivedType *Ty);
433 codeview::TypeIndex lowerTypeMemberFunction(
434 const DISubroutineType *Ty,
const DIType *ClassTy,
int ThisAdjustment,
437 codeview::TypeIndex lowerTypeEnum(
const DICompositeType *Ty);
438 codeview::TypeIndex lowerTypeClass(
const DICompositeType *Ty);
439 codeview::TypeIndex lowerTypeUnion(
const DICompositeType *Ty);
446 codeview::TypeIndex getCompleteTypeIndex(
const DIType *Ty);
448 codeview::TypeIndex lowerCompleteTypeClass(
const DICompositeType *Ty);
449 codeview::TypeIndex lowerCompleteTypeUnion(
const DICompositeType *Ty);
451 struct TypeLoweringScope;
453 void emitDeferredCompleteTypes();
455 void collectMemberInfo(ClassInfo &
Info,
const DIDerivedType *DDTy);
456 ClassInfo collectClassInfo(
const DICompositeType *Ty);
461 std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool>
462 lowerRecordFieldList(
const DICompositeType *Ty);
465 codeview::TypeIndex recordTypeIndexForDINode(
const DINode *
Node,
466 codeview::TypeIndex TI,
467 const DIType *ClassTy =
nullptr);
473 collectParentScopeNames(
const DIScope *Scope,
474 SmallVectorImpl<StringRef> &ParentScopeNames);
475 std::string getFullyQualifiedName(
const DIScope *Scope, StringRef
Name);
476 std::string getFullyQualifiedName(
const DIScope *Scope);
478 unsigned getPointerSizeInBytes();
482 void beginFunctionImpl(
const MachineFunction *MF)
override;
485 void endFunctionImpl(
const MachineFunction *)
override;
495 void beginModule(
Module *M)
override;
500 void endModule()
override;
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This file defines the BumpPtrAllocator interface.
Analysis containing CSE Info
#define LLVM_LIBRARY_VISIBILITY
LLVM_LIBRARY_VISIBILITY - If a class marked with this attribute is linked into a shared library,...
static void clear(coro::Shape &Shape)
This file defines the DenseMap class.
This file defines the DenseSet and SmallDenseSet classes.
DenseMap< Block *, BlockRelaxAux > Blocks
This file implements a map that provides insertion order iteration.
This file defines the PointerUnion class, which is a discriminated union of pointer types.
This file implements a set that has insertion order iteration characteristics.
This file defines the SmallVector class.
This class is intended to be used as a driving class for all asm writers.
Allocate memory in an ever growing pool, as if by bump-pointer.
Collects and handles line tables information in a CodeView format.
bool moduleIsInFortran()
Check if the current module is in Fortran.
void setSymbolSize(const MCSymbol *, uint64_t) override
For symbols that have a size designated (e.g.
SmallVector< Entry, 4 > Entries
std::pair< const DINode *, const DILocation * > InlinedEntity
Base class for debug information backends.
Streaming machine code generation interface.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Representation of each machine instruction.
This class implements a map that also provides access to all stored values in a deterministic order.
A Module instance is used to store all the information related to an LLVM module.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
PointerOptions
Equivalent to misc lfPointerAttr bitfields.
CPUType
These values correspond to the CV_CPU_TYPE_e enumeration, and are documented here: https://msdn....
SymbolKind
Duplicate copy of the above enum, but using the official CV names.
SourceLanguage
These values correspond to the CV_CFL_LANG enumeration in the Microsoft Debug Interface Access SDK.
This is an optimization pass for GlobalISel generic memory operations.
std::tuple< uint64_t, uint32_t > InlineSite
int DataOffset
Offset of variable data in memory.
static uint64_t toOpaqueValue(const LocalVarDef DR)
int InMemory
Indicates that variable data is stored in memory relative to the specified register.
static LocalVarDef createFromOpaqueValue(uint64_t Val)
uint16_t CVRegister
Register containing the data or the register base of the memory location containing the data.
uint16_t StructOffset
Offset into aggregate.
uint16_t IsSubfield
Non-zero if this is a piece of an aggregate.
static bool isEqual(const CodeViewDebug::LocalVarDef &LHS, const CodeViewDebug::LocalVarDef &RHS)
static CodeViewDebug::LocalVarDef getEmptyKey()
static unsigned getHashValue(const CodeViewDebug::LocalVarDef &DR)
static CodeViewDebug::LocalVarDef getTombstoneKey()
An information struct used to provide DenseMap with the various necessary components for a given valu...