@@ -27,6 +27,21 @@ namespace llvm {
27
27
class Function ;
28
28
29
29
#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
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 *;
@@ -187,6 +209,19 @@ namespace llvm {
187
209
#endif // LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
188
210
}
189
211
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
+
190
225
// / Get the underlying \a DILocation.
191
226
// /
192
227
// / \pre !*this or \c isa<DILocation>(getAsMDNode()).
0 commit comments