@@ -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,32 @@ 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_COVERAGE_TRACKING
168
+ DebugLoc (DebugLocKind Kind) : Loc(Kind) {}
169
+ DebugLocKind getKind () const { return Loc.Kind ; }
170
+ #endif
171
+
172
+ #if LLVM_ENABLE_DEBUGLOC_ORIGIN_TRACKING
173
+ #if !LLVM_ENABLE_DEBUGLOC_COVERAGE_TRACKING
174
+ #error Cannot enable DebugLoc origin-tracking without coverage-tracking!
175
+ #endif
176
+
177
+ const DbgLocOrigin::StackTracesTy &getOriginStackTraces () const {
178
+ return Loc.getOriginStackTraces ();
179
+ }
180
+ DebugLoc getCopied () const {
181
+ DebugLoc NewDL = *this ;
182
+ NewDL.Loc .addTrace ();
183
+ return NewDL;
184
+ }
185
+ #else
186
+ DebugLoc getCopied () const { return *this ; }
187
+ #endif
188
+
189
+ static DebugLoc getTemporary ();
190
+ static DebugLoc getUnknown ();
191
+ static DebugLoc getLineZero ();
192
+
145
193
// / Get the underlying \a DILocation.
146
194
// /
147
195
// / \pre !*this or \c isa<DILocation>(getAsMDNode()).
0 commit comments