@@ -27,6 +27,21 @@ namespace llvm {
2727 class Function ;
2828
2929#if LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
30+ #if LLVM_ENABLE_DEBUGLOC_TRACKING_ORIGIN
31+ struct DbgLocOrigin {
32+ static constexpr unsigned long MaxDepth = 16 ;
33+ using StackTracesTy =
34+ SmallVector<std::pair<int , std::array<void *, MaxDepth>>, 0 >;
35+ StackTracesTy StackTraces;
36+ DbgLocOrigin (bool ShouldCollectTrace);
37+ void addTrace ();
38+ const StackTracesTy &getOriginStackTraces () const { return StackTraces; };
39+ };
40+ #else
41+ struct DbgLocOrigin {
42+ DbgLocOrigin (bool ) {}
43+ };
44+ #endif
3045 // Used to represent different "kinds" of DebugLoc, expressing that the
3146 // instruction it is part of is either normal and should contain a valid
3247 // DILocation, or otherwise describing the reason why the instruction does
@@ -55,22 +70,29 @@ namespace llvm {
5570 Temporary
5671 };
5772
58- // Extends TrackingMDNodeRef to also store a DebugLocKind, allowing Debugify
59- // to ignore intentionally-empty DebugLocs.
60- class DILocAndCoverageTracking : public TrackingMDNodeRef {
73+ // Extends TrackingMDNodeRef to also store a DebugLocKind and Origin,
74+ // allowing Debugify to ignore intentionally-empty DebugLocs and display the
75+ // code responsible for generating unintentionally-empty DebugLocs.
76+ // Currently we only need to track the Origin of this DILoc when using a
77+ // DebugLoc that is not annotated (i.e. has DebugLocKind::Normal) and has a
78+ // null DILocation, so only collect the origin stacktrace in those cases.
79+ class DILocAndCoverageTracking : public TrackingMDNodeRef ,
80+ public DbgLocOrigin {
6181 public:
6282 DebugLocKind Kind;
6383 // Default constructor for empty DebugLocs.
6484 DILocAndCoverageTracking ()
65- : TrackingMDNodeRef(nullptr ), Kind(DebugLocKind::Normal) {}
66- // Valid or nullptr MDNode*, normal DebugLocKind.
85+ : TrackingMDNodeRef(nullptr ), DbgLocOrigin(true ),
86+ Kind (DebugLocKind::Normal) {}
87+ // Valid or nullptr MDNode*, no annotative DebugLocKind.
6788 DILocAndCoverageTracking (const MDNode *Loc)
68- : TrackingMDNodeRef(const_cast <MDNode *>(Loc)),
89+ : TrackingMDNodeRef(const_cast <MDNode *>(Loc)), DbgLocOrigin(!Loc),
6990 Kind(DebugLocKind::Normal) {}
7091 LLVM_ABI DILocAndCoverageTracking (const DILocation *Loc);
7192 // Explicit DebugLocKind, which always means a nullptr MDNode*.
7293 DILocAndCoverageTracking (DebugLocKind Kind)
73- : TrackingMDNodeRef(nullptr ), Kind(Kind) {}
94+ : TrackingMDNodeRef(nullptr ),
95+ DbgLocOrigin(Kind == DebugLocKind::Normal), Kind(Kind) {}
7496 };
7597 template <> struct simplify_type <DILocAndCoverageTracking> {
7698 using SimpleType = MDNode *;
@@ -187,6 +209,19 @@ namespace llvm {
187209#endif // LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
188210 }
189211
212+ #if LLVM_ENABLE_DEBUGLOC_TRACKING_ORIGIN
213+ const DbgLocOrigin::StackTracesTy &getOriginStackTraces () const {
214+ return Loc.getOriginStackTraces ();
215+ }
216+ DebugLoc getCopied () const {
217+ DebugLoc NewDL = *this ;
218+ NewDL.Loc .addTrace ();
219+ return NewDL;
220+ }
221+ #else
222+ DebugLoc getCopied () const { return *this ; }
223+ #endif
224+
190225 // / Get the underlying \a DILocation.
191226 // /
192227 // / \pre !*this or \c isa<DILocation>(getAsMDNode()).
0 commit comments