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 FunctionInfo *CurFn =
nullptr;
202 DenseMap<const DIGlobalVariable *, uint64_t> CVGlobalVariableOffsets;
208 DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables;
212 typedef SmallVector<CVGlobalVariable, 1> GlobalVariableList;
213 DenseMap<const DIScope*, std::unique_ptr<GlobalVariableList> > ScopeGlobals;
216 SmallVector<CVGlobalVariable, 1> ComdatVariables;
219 SmallVector<CVGlobalVariable, 1> GlobalVariables;
222 SmallVector<const DIDerivedType *, 4> StaticConstMembers;
227 DenseSet<MCSectionCOFF *> ComdatDebugSections;
234 void switchToDebugSectionForSymbol(
const MCSymbol *GVSym);
238 unsigned NextFuncId = 0;
240 InlineSite &getInlineSite(
const DILocation *InlinedAt,
241 const DISubprogram *Inlinee);
243 codeview::TypeIndex getFuncIdForSubprogram(
const DISubprogram *SP);
245 void calculateRanges(LocalVariable &Var,
250 MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo;
254 DenseMap<StringRef, unsigned> FileIdMap;
257 SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;
265 DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex>
270 DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;
274 SmallVector<const DICompositeType *, 4> DeferredCompleteTypes;
277 unsigned TypeEmissionLevel = 0;
279 codeview::TypeIndex VBPType;
281 const DISubprogram *CurrentSubprogram =
nullptr;
285 std::vector<std::pair<std::string, const DIType *>> LocalUDTs;
286 std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;
288 using FileToFilepathMapTy = std::map<const DIFile *, std::string>;
289 FileToFilepathMapTy FileToFilepathMap;
291 StringRef getFullFilepath(
const DIFile *File);
293 unsigned maybeRecordFile(
const DIFile *
F);
295 void maybeRecordLocation(
const DebugLoc &
DL,
const MachineFunction *MF);
299 void setCurrentSubprogram(
const DISubprogram *SP) {
300 CurrentSubprogram = SP;
307 void emitCodeViewMagicVersion();
309 void emitTypeInformation();
311 void emitTypeGlobalHashes();
315 void emitCompilerInformation();
317 void emitBuildInfo();
319 void emitInlineeLinesSubsection();
321 void emitDebugInfoForThunk(
const Function *GV,
325 void emitDebugInfoForFunction(
const Function *GV, FunctionInfo &FI);
327 void emitDebugInfoForRetainedTypes();
329 void emitDebugInfoForUDTs(
330 const std::vector<std::pair<std::string, const DIType *>> &UDTs);
332 void collectDebugInfoForGlobals();
333 void emitDebugInfoForGlobals();
334 void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals);
335 void emitConstantSymbolRecord(
const DIType *DTy, APSInt &Value,
337 void emitDebugInfoForGlobal(
const CVGlobalVariable &CVGV);
338 void emitStaticConstMemberList();
344 void endCVSubsection(MCSymbol *EndLabel);
349 void endSymbolRecord(MCSymbol *SymEnd);
356 void emitInlinedCallSite(
const FunctionInfo &FI,
const DILocation *InlinedAt,
361 void collectGlobalVariableInfo();
362 void collectVariableInfo(
const DISubprogram *SP);
364 void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed);
368 void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes,
369 SmallVectorImpl<LexicalBlock *> &Blocks,
370 SmallVectorImpl<LocalVariable> &Locals,
371 SmallVectorImpl<CVGlobalVariable> &Globals);
372 void collectLexicalBlockInfo(LexicalScope &Scope,
373 SmallVectorImpl<LexicalBlock *> &ParentBlocks,
374 SmallVectorImpl<LocalVariable> &ParentLocals,
375 SmallVectorImpl<CVGlobalVariable> &ParentGlobals);
379 void recordLocalVariable(LocalVariable &&Var,
const LexicalScope *LS);
382 void emitLocalVariableList(
const FunctionInfo &FI,
383 ArrayRef<LocalVariable> Locals);
386 void emitLocalVariable(
const FunctionInfo &FI,
const LocalVariable &Var);
389 void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks,
390 const FunctionInfo& FI);
393 void emitLexicalBlock(
const LexicalBlock &
Block,
const FunctionInfo& FI);
397 codeview::TypeIndex getTypeIndex(
const DIType *Ty,
398 const DIType *ClassTy =
nullptr);
401 getTypeIndexForThisPtr(
const DIDerivedType *PtrTy,
402 const DISubroutineType *SubroutineTy);
404 codeview::TypeIndex getTypeIndexForReferenceTo(
const DIType *Ty);
406 codeview::TypeIndex getMemberFunctionType(
const DISubprogram *SP,
407 const DICompositeType *Class);
409 codeview::TypeIndex getScopeIndex(
const DIScope *Scope);
411 codeview::TypeIndex getVBPTypeIndex();
413 void addToUDTs(
const DIType *Ty);
415 void addUDTSrcLine(
const DIType *Ty, codeview::TypeIndex TI);
417 codeview::TypeIndex lowerType(
const DIType *Ty,
const DIType *ClassTy);
418 codeview::TypeIndex lowerTypeAlias(
const DIDerivedType *Ty);
419 codeview::TypeIndex lowerTypeArray(
const DICompositeType *Ty);
420 codeview::TypeIndex lowerTypeString(
const DIStringType *Ty);
421 codeview::TypeIndex lowerTypeBasic(
const DIBasicType *Ty);
422 codeview::TypeIndex lowerTypePointer(
423 const DIDerivedType *Ty,
425 codeview::TypeIndex lowerTypeMemberPointer(
426 const DIDerivedType *Ty,
428 codeview::TypeIndex lowerTypeModifier(
const DIDerivedType *Ty);
429 codeview::TypeIndex lowerTypeFunction(
const DISubroutineType *Ty);
430 codeview::TypeIndex lowerTypeVFTableShape(
const DIDerivedType *Ty);
431 codeview::TypeIndex lowerTypeMemberFunction(
432 const DISubroutineType *Ty,
const DIType *ClassTy,
int ThisAdjustment,
435 codeview::TypeIndex lowerTypeEnum(
const DICompositeType *Ty);
436 codeview::TypeIndex lowerTypeClass(
const DICompositeType *Ty);
437 codeview::TypeIndex lowerTypeUnion(
const DICompositeType *Ty);
444 codeview::TypeIndex getCompleteTypeIndex(
const DIType *Ty);
446 codeview::TypeIndex lowerCompleteTypeClass(
const DICompositeType *Ty);
447 codeview::TypeIndex lowerCompleteTypeUnion(
const DICompositeType *Ty);
449 struct TypeLoweringScope;
451 void emitDeferredCompleteTypes();
453 void collectMemberInfo(ClassInfo &
Info,
const DIDerivedType *DDTy);
454 ClassInfo collectClassInfo(
const DICompositeType *Ty);
459 std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool>
460 lowerRecordFieldList(
const DICompositeType *Ty);
463 codeview::TypeIndex recordTypeIndexForDINode(
const DINode *
Node,
464 codeview::TypeIndex TI,
465 const DIType *ClassTy =
nullptr);
471 collectParentScopeNames(
const DIScope *Scope,
472 SmallVectorImpl<StringRef> &ParentScopeNames);
473 std::string getFullyQualifiedName(
const DIScope *Scope, StringRef
Name);
474 std::string getFullyQualifiedName(
const DIScope *Scope);
476 unsigned getPointerSizeInBytes();
480 void beginFunctionImpl(
const MachineFunction *MF)
override;
483 void endFunctionImpl(
const MachineFunction *)
override;
493 void beginModule(
Module *M)
override;
498 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.
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...