@@ -27,6 +27,21 @@ namespace llvm {
27
27
class Function ;
28
28
29
29
#if LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING
30
+ #if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING
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
30
45
// Used to represent different "kinds" of DebugLoc, expressing that the
31
46
// instruction it is part of is either normal and should contain a valid
32
47
// DILocation, or otherwise describing the reason why the instruction does
@@ -55,22 +70,29 @@ namespace llvm {
55
70
Temporary
56
71
};
57
72
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 {
61
81
public:
62
82
DebugLocKind Kind;
63
83
// Default constructor for empty DebugLocs.
64
84
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.
67
88
DILocAndCoverageTracking (const MDNode *Loc)
68
- : TrackingMDNodeRef(const_cast <MDNode *>(Loc)),
89
+ : TrackingMDNodeRef(const_cast <MDNode *>(Loc)), DbgLocOrigin(!Loc),
69
90
Kind(DebugLocKind::Normal) {}
70
91
LLVM_ABI DILocAndCoverageTracking (const DILocation *Loc);
71
92
// Explicit DebugLocKind, which always means a nullptr MDNode*.
72
93
DILocAndCoverageTracking (DebugLocKind Kind)
73
- : TrackingMDNodeRef(nullptr ), Kind(Kind) {}
94
+ : TrackingMDNodeRef(nullptr ),
95
+ DbgLocOrigin(Kind == DebugLocKind::Normal), Kind(Kind) {}
74
96
};
75
97
template <> struct simplify_type <DILocAndCoverageTracking> {
76
98
using SimpleType = MDNode *;
@@ -142,6 +164,19 @@ namespace llvm {
142
164
static inline DebugLoc getDropped () { return DebugLoc (); }
143
165
#endif // LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING
144
166
167
+ #if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING
168
+ const DbgLocOrigin::StackTracesTy &getOriginStackTraces () const {
169
+ return Loc.getOriginStackTraces ();
170
+ }
171
+ DebugLoc getCopied () const {
172
+ DebugLoc NewDL = *this ;
173
+ NewDL.Loc .addTrace ();
174
+ return NewDL;
175
+ }
176
+ #else
177
+ DebugLoc getCopied () const { return *this ; }
178
+ #endif
179
+
145
180
// / Get the underlying \a DILocation.
146
181
// /
147
182
// / \pre !*this or \c isa<DILocation>(getAsMDNode()).
0 commit comments