76 constexpr static int32_t
NoDeref = INT32_MIN;
118 bool EmitDebugGlobalHashes =
false;
129 static LocalVarDef createDefRangeMem(
uint16_t CVRegister,
int Offset,
130 int32_t DerefOffset);
133 struct LocalVariable {
138 std::optional<APSInt> ConstantValue;
141 struct CVGlobalVariable {
142 const DIGlobalVariable *DIGV;
143 PointerUnion<const GlobalVariable *, const DIExpression *> GVInfo;
147 SmallVector<LocalVariable, 1> InlinedLocals;
148 SmallVector<const DILocation *, 1> ChildSites;
149 const DISubprogram *
Inlinee =
nullptr;
153 unsigned SiteFuncId = 0;
157 struct LexicalBlock {
158 SmallVector<LocalVariable, 1>
Locals;
159 SmallVector<CVGlobalVariable, 1> Globals;
160 SmallVector<LexicalBlock *, 1>
Children;
166 struct JumpTableInfo {
167 codeview::JumpTableEntrySize EntrySize;
173 std::vector<const MCSymbol *> Cases;
178 struct FunctionInfo {
179 FunctionInfo() =
default;
182 FunctionInfo(
const FunctionInfo &FI) =
delete;
186 std::unordered_map<const DILocation *, InlineSite> InlineSites;
189 SmallVector<const DILocation *, 1> ChildSites;
192 SmallSet<codeview::TypeIndex, 1> Inlinees;
194 SmallVector<LocalVariable, 1>
Locals;
195 SmallVector<CVGlobalVariable, 1> Globals;
197 std::unordered_map<const DILexicalBlockBase*, LexicalBlock> LexicalBlocks;
200 SmallVector<LexicalBlock *, 1> ChildBlocks;
202 std::vector<std::pair<MCSymbol *, MDNode *>> Annotations;
203 std::vector<std::tuple<const MCSymbol *, const MCSymbol *, const DIType *>>
206 std::vector<JumpTableInfo> JumpTables;
211 unsigned LastFileId = 0;
214 unsigned FrameSize = 0;
217 unsigned ParamSize = 0;
220 unsigned CSRSize = 0;
223 int OffsetAdjustment = 0;
227 codeview::EncodedFramePtrReg EncodedLocalFramePtrReg =
228 codeview::EncodedFramePtrReg::None;
232 codeview::EncodedFramePtrReg EncodedParamFramePtrReg =
233 codeview::EncodedFramePtrReg::None;
235 codeview::FrameProcedureOptions FrameProcOpts;
237 bool HasStackRealignment =
false;
239 bool HaveLineInfo =
false;
241 bool HasFramePointer =
false;
243 FunctionInfo *CurFn =
nullptr;
245 codeview::SourceLanguage CurrentSourceLanguage =
246 codeview::SourceLanguage::Masm;
250 DenseMap<const DIGlobalVariable *, uint64_t> CVGlobalVariableOffsets;
256 DenseMap<const LexicalScope *, SmallVector<LocalVariable, 1>> ScopeVariables;
260 typedef SmallVector<CVGlobalVariable, 1> GlobalVariableList;
261 DenseMap<const DIScope*, std::unique_ptr<GlobalVariableList> > ScopeGlobals;
264 SmallVector<CVGlobalVariable, 1> ComdatVariables;
267 SmallVector<CVGlobalVariable, 1> GlobalVariables;
270 SmallVector<const DIDerivedType *, 4> StaticConstMembers;
275 DenseSet<MCSectionCOFF *> ComdatDebugSections;
282 void switchToDebugSectionForSymbol(
const MCSymbol *GVSym);
286 unsigned NextFuncId = 0;
288 InlineSite &getInlineSite(
const DILocation *InlinedAt,
289 const DISubprogram *Inlinee);
291 codeview::TypeIndex getFuncIdForSubprogram(
const DISubprogram *SP);
293 void calculateRanges(LocalVariable &Var,
294 const DbgValueHistoryMap::Entries &Entries);
298 MapVector<const Function *, std::unique_ptr<FunctionInfo>> FnDebugInfo;
302 DenseMap<StringRef, unsigned> FileIdMap;
305 SmallSetVector<const DISubprogram *, 4> InlinedSubprograms;
313 DenseMap<std::pair<const DINode *, const DIType *>, codeview::TypeIndex>
318 DenseMap<const DICompositeType *, codeview::TypeIndex> CompleteTypeIndices;
322 SmallVector<const DICompositeType *, 4> DeferredCompleteTypes;
325 unsigned TypeEmissionLevel = 0;
327 codeview::TypeIndex VBPType;
329 const DISubprogram *CurrentSubprogram =
nullptr;
333 std::vector<std::pair<std::string, const DIType *>> LocalUDTs;
334 std::vector<std::pair<std::string, const DIType *>> GlobalUDTs;
336 using FileToFilepathMapTy = std::map<const DIFile *, std::string>;
337 FileToFilepathMapTy FileToFilepathMap;
339 StringRef getFullFilepath(
const DIFile *File);
341 unsigned maybeRecordFile(
const DIFile *
F);
343 void maybeRecordLocation(
const DebugLoc &
DL,
const MachineFunction *MF);
347 void setCurrentSubprogram(
const DISubprogram *SP) {
348 CurrentSubprogram =
SP;
355 void emitCodeViewMagicVersion();
357 void emitTypeInformation();
359 void emitTypeGlobalHashes();
363 void emitCompilerInformation();
365 void emitSecureHotPatchInformation();
367 void emitBuildInfo();
369 void emitInlineeLinesSubsection();
371 void emitDebugInfoForThunk(
const Function *GV,
375 void emitDebugInfoForFunction(
const Function *GV, FunctionInfo &FI);
377 void emitDebugInfoForRetainedTypes();
379 void emitDebugInfoForUDTs(
380 const std::vector<std::pair<std::string, const DIType *>> &UDTs);
382 void collectDebugInfoForGlobals();
383 void emitDebugInfoForGlobals();
384 void emitGlobalVariableList(ArrayRef<CVGlobalVariable> Globals);
385 void emitConstantSymbolRecord(
const DIType *DTy, APSInt &
Value,
386 const std::string &QualifiedName);
387 void emitDebugInfoForGlobal(
const CVGlobalVariable &CVGV);
388 void emitStaticConstMemberList();
393 MCSymbol *beginCVSubsection(codeview::DebugSubsectionKind Kind);
394 void endCVSubsection(MCSymbol *EndLabel);
398 MCSymbol *beginSymbolRecord(codeview::SymbolKind Kind);
399 void endSymbolRecord(MCSymbol *SymEnd);
404 void emitEndSymbolRecord(codeview::SymbolKind EndKind);
406 void emitInlinedCallSite(
const FunctionInfo &FI,
const DILocation *InlinedAt,
407 const InlineSite &Site);
409 void emitInlinees(
const SmallSet<codeview::TypeIndex, 1> &Inlinees);
411 using InlinedEntity = DbgValueHistoryMap::InlinedEntity;
413 void collectGlobalVariableInfo();
414 void collectVariableInfo(
const DISubprogram *SP);
416 void collectVariableInfoFromMFTable(DenseSet<InlinedEntity> &Processed);
420 void collectLexicalBlockInfo(SmallVectorImpl<LexicalScope *> &Scopes,
421 SmallVectorImpl<LexicalBlock *> &Blocks,
422 SmallVectorImpl<LocalVariable> &Locals,
423 SmallVectorImpl<CVGlobalVariable> &Globals);
424 void collectLexicalBlockInfo(LexicalScope &Scope,
425 SmallVectorImpl<LexicalBlock *> &ParentBlocks,
426 SmallVectorImpl<LocalVariable> &ParentLocals,
427 SmallVectorImpl<CVGlobalVariable> &ParentGlobals);
431 void recordLocalVariable(LocalVariable &&Var,
const LexicalScope *LS);
434 void emitLocalVariableList(
const FunctionInfo &FI,
435 ArrayRef<LocalVariable> Locals);
438 void emitLocalVariable(
const FunctionInfo &FI,
const LocalVariable &Var);
441 void emitLexicalBlockList(ArrayRef<LexicalBlock *> Blocks,
442 const FunctionInfo& FI);
445 void emitLexicalBlock(
const LexicalBlock &Block,
const FunctionInfo& FI);
449 codeview::TypeIndex getTypeIndex(
const DIType *Ty,
450 const DIType *ClassTy =
nullptr);
453 getTypeIndexForThisPtr(
const DIDerivedType *PtrTy,
454 const DISubroutineType *SubroutineTy);
456 codeview::TypeIndex getMemberFunctionType(
const DISubprogram *SP,
457 const DICompositeType *Class);
459 codeview::TypeIndex getScopeIndex(
const DIScope *Scope);
461 codeview::TypeIndex getVBPTypeIndex();
463 void addToUDTs(
const DIType *Ty);
465 void addUDTSrcLine(
const DIType *Ty, codeview::TypeIndex TI);
467 codeview::TypeIndex lowerType(
const DIType *Ty,
const DIType *ClassTy);
468 codeview::TypeIndex lowerTypeAlias(
const DIDerivedType *Ty);
469 codeview::TypeIndex lowerTypeArray(
const DICompositeType *Ty);
470 codeview::TypeIndex lowerTypeString(
const DIStringType *Ty);
471 codeview::TypeIndex lowerTypeBasic(
const DIBasicType *Ty);
472 codeview::TypeIndex lowerTypePointer(
473 const DIDerivedType *Ty,
474 codeview::PointerOptions PO = codeview::PointerOptions::None);
475 codeview::TypeIndex lowerTypeMemberPointer(
476 const DIDerivedType *Ty,
477 codeview::PointerOptions PO = codeview::PointerOptions::None);
478 codeview::TypeIndex lowerTypeModifier(
const DIDerivedType *Ty);
479 codeview::TypeIndex lowerTypeFunction(
const DISubroutineType *Ty);
480 codeview::TypeIndex lowerTypeVFTableShape(
const DIDerivedType *Ty);
481 codeview::TypeIndex lowerTypeMemberFunction(
482 const DISubroutineType *Ty,
const DIType *ClassTy,
int ThisAdjustment,
484 codeview::FunctionOptions FO = codeview::FunctionOptions::None);
485 codeview::TypeIndex lowerTypeEnum(
const DICompositeType *Ty);
486 codeview::TypeIndex lowerTypeClass(
const DICompositeType *Ty);
487 codeview::TypeIndex lowerTypeUnion(
const DICompositeType *Ty);
494 codeview::TypeIndex getCompleteTypeIndex(
const DIType *Ty);
496 codeview::TypeIndex lowerCompleteTypeClass(
const DICompositeType *Ty);
497 codeview::TypeIndex lowerCompleteTypeUnion(
const DICompositeType *Ty);
499 struct TypeLoweringScope;
501 void emitDeferredCompleteTypes();
503 void collectMemberInfo(ClassInfo &Info,
const DIDerivedType *DDTy);
504 ClassInfo collectClassInfo(
const DICompositeType *Ty);
509 std::tuple<codeview::TypeIndex, codeview::TypeIndex, unsigned, bool>
510 lowerRecordFieldList(
const DICompositeType *Ty);
513 codeview::TypeIndex recordTypeIndexForDINode(
const DINode *Node,
514 codeview::TypeIndex TI,
515 const DIType *ClassTy =
nullptr);
521 collectParentScopeNames(
const DIScope *Scope,
522 SmallVectorImpl<StringRef> &ParentScopeNames);
523 std::string getFullyQualifiedName(
const DIScope *Scope, StringRef Name);
524 std::string getFullyQualifiedName(
const DIScope *Scope);
526 unsigned getPointerSizeInBytes();
528 void discoverJumpTableBranches(
const MachineFunction *MF,
bool isThumb);
529 void collectDebugInfoForJumpTables(
const MachineFunction *MF,
bool isThumb);
530 void emitDebugInfoForJumpTables(
const FunctionInfo &FI);
534 void beginFunctionImpl(
const MachineFunction *MF)
override;
537 void endFunctionImpl(
const MachineFunction *)
override;
541 return CurrentSourceLanguage == codeview::SourceLanguage::Fortran;
547 void beginModule(
Module *M)
override;
550 void endModule()
override;