clang: lib/CodeGen/CGDebugInfo.h Source File (original) (raw)
63
65 const llvm::codegenoptions::DebugInfoKind DebugKind;
66 bool DebugTypeExtRefs;
67 llvm::DIBuilder DBuilder;
68 llvm::DICompileUnit *TheCU = nullptr;
69 ModuleMap *ClangModuleMap = nullptr;
72 llvm::MDNode *CurInlinedAt = nullptr;
73 llvm::DIType *VTablePtrType = nullptr;
74 llvm::DIType *ClassTy = nullptr;
75 llvm::DICompositeType *ObjTy = nullptr;
76 llvm::DIType *SelTy = nullptr;
77#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
78 llvm::DIType *SingletonId = nullptr;
79#include "clang/Basic/OpenCLImageTypes.def"
80 llvm::DIType *OCLSamplerDITy = nullptr;
81 llvm::DIType *OCLEventDITy = nullptr;
82 llvm::DIType *OCLClkEventDITy = nullptr;
83 llvm::DIType *OCLQueueDITy = nullptr;
84 llvm::DIType *OCLNDRangeDITy = nullptr;
85 llvm::DIType *OCLReserveIDDITy = nullptr;
86#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
87 llvm::DIType *Id##Ty = nullptr;
88#include "clang/Basic/OpenCLExtensionTypes.def"
89#define WASM_TYPE(Name, Id, SingletonId) llvm::DIType *SingletonId = nullptr;
90#include "clang/Basic/WebAssemblyReferenceTypes.def"
91#define AMDGPU_TYPE(Name, Id, SingletonId, Width, Align) \
92 llvm::DIType *SingletonId = nullptr;
93#include "clang/Basic/AMDGPUTypes.def"
94#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
95 llvm::DIType *SingletonId = nullptr;
96#include "clang/Basic/HLSLIntangibleTypes.def"
97
98
99 llvm::DenseMap<const void *, llvm::TrackingMDRef> TypeCache;
100
101
102
103 llvm::SmallDenseMap<QualType, llvm::Metadata *> SizeExprCache;
104
105
108
109 public:
111 std::string remapPath(StringRef Path) const override {
112 return Self.remapDIPath(Path);
113 }
114 };
115 PrintingCallbacks PrintCB = {*this};
116
117 struct ObjCInterfaceCacheEntry {
118 const ObjCInterfaceType *Type;
119 llvm::DIType *Decl;
120 llvm::DIFile *Unit;
121 ObjCInterfaceCacheEntry(const ObjCInterfaceType *Type, llvm::DIType *Decl,
122 llvm::DIFile *Unit)
123 : Type(Type), Decl(Decl), Unit(Unit) {}
124 };
125
126
127 llvm::SmallVector<ObjCInterfaceCacheEntry, 32> ObjCInterfaceCache;
128
129
130
131
132 llvm::DenseMap<const ObjCInterfaceDecl *,
133 std::vector<llvm::PointerIntPair<llvm::DISubprogram *, 1>>>
134 ObjCMethodCache;
135
136
137 llvm::DenseMap<const Module *, llvm::TrackingMDRef> ModuleCache;
138
139
140 std::vector<void *> RetainedTypes;
141
142
143 std::vector<std::pair<const TagType *, llvm::TrackingMDRef>> ReplaceMap;
144
145
146
147 std::vector<std::pair<const DeclaratorDecl *, llvm::TrackingMDRef>>
148 FwdDeclReplaceMap;
149
150
151 std::vector<llvm::TypedTrackingMDRefllvm::DIScope> LexicalBlockStack;
152 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> RegionMap;
153
154
155
156 std::vector FnBeginRegionCount;
157
158
159
160 llvm::BumpPtrAllocator DebugInfoNames;
161
162 llvm::DenseMap<const char *, llvm::TrackingMDRef> DIFileCache;
163 llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> SPCache;
164
165
166
167 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> DeclCache;
168 llvm::DenseMap<const Decl *, llvm::TrackingMDRef> ImportedDeclCache;
169 llvm::DenseMap<const NamespaceDecl *, llvm::TrackingMDRef> NamespaceCache;
170 llvm::DenseMap<const NamespaceAliasDecl *, llvm::TrackingMDRef>
171 NamespaceAliasCache;
172 llvm::DenseMap<const Decl *, llvm::TypedTrackingMDRefllvm::DIDerivedType>
173 StaticDataMemberCache;
174
175 using ParamDecl2StmtTy = llvm::DenseMap<const ParmVarDecl *, const Stmt *>;
176 using Param2DILocTy =
177 llvm::DenseMap<const ParmVarDecl *, llvm::DILocalVariable *>;
178
179
180 ParamDecl2StmtTy CoroutineParameterMappings;
181
182 Param2DILocTy ParamDbgMappings;
183
184
185
186
187 struct {
191 } KeyInstructionsInfo;
192
193private:
194
195
196
197
198 llvm::DIType *CreateType(const BuiltinType *Ty);
199 llvm::DIType *CreateType(const ComplexType *Ty);
200 llvm::DIType *CreateType(const BitIntType *Ty);
201 llvm::DIType *CreateQualifiedType(QualType Ty, llvm::DIFile *Fg);
203 llvm::DIFile *Fg);
204 llvm::DIType *CreateType(const TypedefType *Ty, llvm::DIFile *Fg);
205 llvm::DIType *CreateType(const TemplateSpecializationType *Ty,
206 llvm::DIFile *Fg);
208 llvm::DIType *CreateType(const PointerType *Ty, llvm::DIFile *F);
209 llvm::DIType *CreateType(const BlockPointerType *Ty, llvm::DIFile *F);
210 llvm::DIType *CreateType(const FunctionType *Ty, llvm::DIFile *F);
211 llvm::DIType *CreateType(const HLSLAttributedResourceType *Ty,
212 llvm::DIFile *F);
213 llvm::DIType *CreateType(const HLSLInlineSpirvType *Ty, llvm::DIFile *F);
214
215 llvm::DIType *CreateType(const RecordType *Tyg);
216
217
218
219
220
221
222
223 std::pair<llvm::DIType *, llvm::DIType *>
224 CreateTypeDefinition(const RecordType *Ty);
225 llvm::DICompositeType *CreateLimitedType(const RecordType *Ty);
226 void CollectContainingType(const CXXRecordDecl *RD,
227 llvm::DICompositeType *CT);
228
229 llvm::DIType *CreateType(const ObjCInterfaceType *Ty, llvm::DIFile *F);
231 llvm::DIFile *F);
232
233 llvm::DIType *CreateType(const ObjCObjectType *Ty, llvm::DIFile *F);
234 llvm::DIType *CreateType(const ObjCTypeParamType *Ty, llvm::DIFile *Unit);
235
236 llvm::DIType *CreateType(const VectorType *Ty, llvm::DIFile *F);
237 llvm::DIType *CreateType(const ConstantMatrixType *Ty, llvm::DIFile *F);
238 llvm::DIType *CreateType(const ArrayType *Ty, llvm::DIFile *F);
239 llvm::DIType *CreateType(const LValueReferenceType *Ty, llvm::DIFile *F);
240 llvm::DIType *CreateType(const RValueReferenceType *Ty, llvm::DIFile *Unit);
241 llvm::DIType *CreateType(const MemberPointerType *Ty, llvm::DIFile *F);
242 llvm::DIType *CreateType(const AtomicType *Ty, llvm::DIFile *F);
243 llvm::DIType *CreateType(const PipeType *Ty, llvm::DIFile *F);
244
245 llvm::DIType *CreateEnumType(const EnumType *Ty);
246 llvm::DIType *CreateTypeDefinition(const EnumType *Ty);
247
248
249
250
251
252
253 llvm::DIType *CreateSelfType(const QualType &QualTy, llvm::DIType *Ty);
254
255
256
257
258 llvm::DIType *getTypeOrNull(const QualType);
259
260
261
262
263 llvm::DISubroutineType *getOrCreateMethodType(const CXXMethodDecl *Method,
264 llvm::DIFile *F);
265
266 llvm::DISubroutineType *
268 llvm::DIFile *F, QualType FNType);
269
270 llvm::DISubroutineType *
272 llvm::DIFile *Unit, bool SkipFirst = false);
273 llvm::DISubroutineType *
274 getOrCreateFunctionType(const Decl *D, QualType FnType, llvm::DIFile *F);
275
276 llvm::DIType *getOrCreateVTablePtrType(llvm::DIFile *F);
277
278
279 llvm::DINamespace *getOrCreateNamespace(const NamespaceDecl *N);
280 llvm::DIType *CreatePointerLikeType(llvm::dwarf::Tag Tag, const Type *Ty,
281 QualType PointeeTy, llvm::DIFile *F);
282 llvm::DIType *getOrCreateStructPtrType(StringRef Name, llvm::DIType *&Cache);
283
284
285
287 llvm::DIFile *F,
288 llvm::DIType *RecordTy);
289
290
291
292
293 void CollectCXXMemberFunctions(const CXXRecordDecl *Decl, llvm::DIFile *F,
295 llvm::DIType *T);
296
297
298
299
302 llvm::DIType *RecordTy);
303
304
305
306 void CollectCXXBasesAux(
311 llvm::DINode::DIFlags StartingFlags);
312
313
314
315
316 llvm::DIType *GetPreferredNameType(const CXXRecordDecl *RD,
317 llvm::DIFile *Unit);
318
319 struct TemplateArgs {
322 };
323
324 llvm::DINodeArray CollectTemplateParams(std::optional Args,
325 llvm::DIFile *Unit);
326
327
328 llvm::DINodeArray CollectFunctionTemplateParams(const FunctionDecl *FD,
329 llvm::DIFile *Unit);
330
331
332
333 llvm::DINodeArray CollectVarTemplateParams(const VarDecl *VD,
334 llvm::DIFile *Unit);
335
339
340
341
342 llvm::DINodeArray CollectCXXTemplateParams(const RecordDecl *TS,
343 llvm::DIFile *F);
344
345
346 llvm::DINodeArray CollectBTFDeclTagAnnotations(const Decl *D);
347
348 llvm::DIType *createFieldType(StringRef name, QualType type,
350 uint64_t offsetInBits, uint32_t AlignInBits,
351 llvm::DIFile *tunit, llvm::DIScope *scope,
353 llvm::DINodeArray Annotations = nullptr);
354
355 llvm::DIType *createFieldType(StringRef name, QualType type,
357 uint64_t offsetInBits, llvm::DIFile *tunit,
358 llvm::DIScope *scope,
360 return createFieldType(name, type, loc, AS, offsetInBits, 0, tunit, scope,
361 RD);
362 }
363
364
365 llvm::DIDerivedType *createBitFieldType(const FieldDecl *BitFieldDecl,
366 llvm::DIScope *RecordTy,
367 const RecordDecl *RD);
368
369
370
371 llvm::DIDerivedType *createBitFieldSeparatorIfNeeded(
372 const FieldDecl *BitFieldDecl, const llvm::DIDerivedType *BitFieldDI,
374
375
376 llvm::StringMap<llvm::DISubprogram *> InlinedSubprogramMap;
377
378
379
380 llvm::DISubprogram *createInlinedSubprogram(StringRef FuncName,
381 llvm::DIFile *FileScope);
382
383
384
385 void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl,
386 SmallVectorImpl<llvm::Metadata *> &E,
387 llvm::DIType *RecordTy);
388 llvm::DIDerivedType *CreateRecordStaticField(const VarDecl *Var,
389 llvm::DIType *RecordTy,
390 const RecordDecl *RD);
391 void CollectRecordNormalField(const FieldDecl *Field, uint64_t OffsetInBits,
392 llvm::DIFile *F,
393 SmallVectorImpl<llvm::Metadata *> &E,
394 llvm::DIType *RecordTy, const RecordDecl *RD);
395 void CollectRecordNestedType(const TypeDecl *RD,
396 SmallVectorImpl<llvm::Metadata *> &E);
397 void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile *F,
398 SmallVectorImpl<llvm::Metadata *> &E,
399 llvm::DICompositeType *RecordTy);
400 llvm::StringRef GetLambdaCaptureName(const LambdaCapture &Capture);
401
402
403
404 void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile *F,
405 SmallVectorImpl<llvm::Metadata *> &EltTys);
406
407
408
409 void CreateLexicalBlock(SourceLocation Loc);
410
411
412
413
414
415
416
417 void AppendAddressSpaceXDeref(unsigned AddressSpace,
418 SmallVectorImpl<uint64_t> &Expr) const;
419
420
421
422
423
424 uint64_t collectDefaultElementTypesForBlockPointer(
425 const BlockPointerType *Ty, llvm::DIFile *Unit,
426 llvm::DIDerivedType *DescTy, unsigned LineNo,
427 SmallVectorImpl<llvm::Metadata *> &EltTys);
428
429
430
431 void collectDefaultFieldsForBlockLiteralDeclare(
432 const CGBlockInfo &Block, const ASTContext &Context, SourceLocation Loc,
433 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
434 SmallVectorImpl<llvm::Metadata *> &Fields);
435
436public:
439
441
442
443 std::string remapDIPath(StringRef) const;
444
445
447 SizeExprCache[Ty] = SizeExpr;
448 }
449
450
451
452
453 void setDwoId(uint64_t Signature);
454
455
456
457
459
460
461
462
464
465
466
467
469
470
471
473
474
475
476 void setInlinedAt(llvm::MDNode *InlinedAt) { CurInlinedAt = InlinedAt; }
477
478
479 llvm::MDNode *getInlinedAt() const { return CurInlinedAt; }
480
481
483
484
485
486
488
491
492
493
494
495
498 llvm::Function *Fn, bool CurFnIsThunk);
499
500
502
504
505
506
508 QualType FnType, llvm::Function *Fn = nullptr);
509
510
511
515
516
518
519
520
522
523
524
526
527
528
529
530
531 llvm::DILocalVariable *
534 const bool UsePointerValue = false);
535
536
538
539
540
543 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint = nullptr);
544
545
546
547 llvm::DILocalVariable *
549 CGBuilderTy &Builder, bool UsePointerValue = false);
550
551
552
554 StringRef Name, unsigned ArgNo,
555 llvm::AllocaInst *LocalAddr,
557
558
560
561
563
564
566
567
568
569
572
573
575
576
578
579
581
582
584
585
587
588
590
591
593
594
596
597
598
599
600
601
604
605
607
608
610
611
613
614
616
617
620
626
629
630
631
632 llvm::DIMacro *CreateMacro(llvm::DIMacroFile *Parent, unsigned MType,
634 StringRef Value);
635
636
640
643 return CoroutineParameterMappings;
644 }
645
646
647
648
649
650
651
652
653
655 StringRef Category,
656 StringRef FailureMsg);
657
658
659
660
661
663 StringRef FuncName);
664
665
667
668
669
671 llvm::Value *Backup);
672
673
674
676 llvm::Value *Backup, uint64_t Atom);
677
678
680
681
682
684
685private:
686
687
688
689
690 void addInstSourceAtomMetadata(llvm::Instruction *I, uint64_t Group,
691 uint8_t Rank);
692
693
694
695
696 llvm::DILocalVariable *EmitDeclare(const VarDecl *decl, llvm::Value *AI,
697 std::optional ArgNo,
699 const bool UsePointerValue = false);
700
701
702
703
704 llvm::DILocalVariable *EmitDeclare(const BindingDecl *decl, llvm::Value *AI,
705 std::optional ArgNo,
707 const bool UsePointerValue = false);
708
709 struct BlockByRefType {
710
711 llvm::DIType *BlockByRefWrapper;
712
713 llvm::DIType *WrappedType;
714 };
715
717 std::string GetName(const Decl *, bool Qualified = false) const;
718
719
720 BlockByRefType EmitTypeForVarWithBlocksAttr(const VarDecl *VD,
721 uint64_t *OffSet);
722
723
724 llvm::DIScope *getDeclContextDescriptor(const Decl *D);
725
726 llvm::DIScope *getContextDescriptor(const Decl *Context,
728
729 llvm::DIScope *getCurrentContextDescriptor(const Decl *Decl);
730
731
732 llvm::DICompositeType *getOrCreateRecordFwdDecl(const RecordType *,
733 llvm::DIScope *);
734
735
736 StringRef getCurrentDirname();
737
738
739 void CreateCompileUnit();
740
741
742 std::optionalllvm::DIFile::ChecksumKind
744
745
747
748
749
751
752
753 llvm::DIFile *
754 createFile(StringRef FileName,
755 std::optional<llvm::DIFile::ChecksumInfo> CSInfo,
756 std::optional Source);
757
758
759 llvm::DIType *getOrCreateType(QualType Ty, llvm::DIFile *Fg);
760
761
762
764 bool CreateSkeletonCU);
765
766
767 llvm::DIModule *getParentModuleOrNull(const Decl *D);
768
769
770
771 llvm::DICompositeType *getOrCreateLimitedType(const RecordType *Ty);
772
773
774 llvm::DIType *CreateTypeNode(QualType Ty, llvm::DIFile *Fg);
775
776
777 llvm::DIType *CreateMemberType(llvm::DIFile *Unit, QualType FType,
778 StringRef Name, uint64_t *Offset);
779
780
781
782 llvm::DINode *getDeclarationOrDefinition(const Decl *D);
783
784
785
786 llvm::DISubprogram *getFunctionDeclaration(const Decl *D);
787
788
789
790
791
792
793
794 llvm::DISubprogram *
795 getObjCMethodDeclaration(const Decl *D, llvm::DISubroutineType *FnType,
796 unsigned LineNo, llvm::DINode::DIFlags Flags,
797 llvm::DISubprogram::DISPFlags SPFlags);
798
799
800
801
802
803 llvm::DIDerivedType *
804 getOrCreateStaticDataMemberDeclarationOrNull(const VarDecl *D);
805
806
807 llvm::DISubprogram *getFunctionFwdDeclOrStub(GlobalDecl GD, bool Stub);
808
809
810
811 llvm::DISubprogram *getFunctionForwardDeclaration(GlobalDecl GD);
812
813
814
815 llvm::DISubprogram *getFunctionStub(GlobalDecl GD);
816
817
818
819 llvm::DIGlobalVariable *
820 getGlobalVariableForwardDeclaration(const VarDecl *VD);
821
822
823
824
825
826
827
828
829 llvm::DIGlobalVariableExpression *
830 CollectAnonRecordDecls(const RecordDecl *RD, llvm::DIFile *Unit,
831 unsigned LineNo, StringRef LinkageName,
832 llvm::GlobalVariable *Var, llvm::DIScope *DContext);
833
834
836
837
838
839
841
842
843
844 StringRef getObjCMethodName(const ObjCMethodDecl *FD);
845
846
847
848 StringRef getSelectorName(Selector S);
849
850
851 StringRef getClassName(const RecordDecl *RD);
852
853
855
856
857
858 StringRef getDynamicInitializerName(const VarDecl *VD,
860 llvm::Function *InitFn);
861
862
863
865
866
867
868
869 unsigned getColumnNumber(SourceLocation Loc, bool Force = false);
870
871
872
873 void collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
874 StringRef &Name, StringRef &LinkageName,
875 llvm::DIScope *&FDContext,
876 llvm::DINodeArray &TParamsArray,
877 llvm::DINode::DIFlags &Flags);
878
879
880 void collectVarDeclProps(const VarDecl *VD, llvm::DIFile *&Unit,
881 unsigned &LineNo, QualType &T, StringRef &Name,
882 StringRef &LinkageName,
883 llvm::MDTuple *&TemplateParameters,
884 llvm::DIScope *&VDContext);
885
886
887
888 llvm::DIExpression *createConstantValueExpression(const clang::ValueDecl *VD,
890
891
892
893
894 StringRef internString(StringRef A, StringRef B = StringRef()) {
895 char *Data = DebugInfoNames.Allocate<char>(A.size() + B.size());
896 if (!A.empty())
897 std::memcpy(Data, A.data(), A.size());
898 if (!B.empty())
899 std::memcpy(Data + A.size(), B.data(), B.size());
900 return StringRef(Data, A.size() + B.size());
901 }
902
903
904
905 llvm::StringRef GetMethodLinkageName(const CXXMethodDecl *Method) const;
906};
910class ApplyDebugLocation {
911private:
912 void init(SourceLocation TemporaryLocation, bool DefaultToEmpty = false);
913 ApplyDebugLocation(CodeGenFunction &CGF, bool DefaultToEmpty,
915
916 llvm::DebugLoc OriginalLocation;
918
919public:
920
923 ApplyDebugLocation(CodeGenFunction &CGF, llvm::DebugLoc Loc);
925 Other.CGF = nullptr;
926 }
927
928
930 if (this != &Other) {
932 Other.CGF = nullptr;
933 }
934 return *this;
935 }
936
938
939
940
941
942
943
944
945
946
947
948
949
953
954
955
959 return ApplyDebugLocation(CGF, false, TemporaryLocation);
960 }
961
962
963
964
965
966
970};
976
977public:
978
979
980
982
986};