LLVM: lib/IR/DebugLoc.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
10#include "llvm/Config/llvm-config.h"
12
13using namespace llvm;
14
15#if LLVM_ENABLE_DEBUGLOC_TRACKING_ORIGIN
17
18DbgLocOrigin::DbgLocOrigin(bool ShouldCollectTrace) {
19 if (!ShouldCollectTrace)
20 return;
21 auto &[Depth, StackTrace] = StackTraces.emplace_back();
22 Depth = sys::getStackTrace(StackTrace);
23}
24void DbgLocOrigin::addTrace() {
25
26
27
28
29 if (StackTraces.empty())
30 return;
31 auto &[Depth, StackTrace] = StackTraces.emplace_back();
32 Depth = sys::getStackTrace(StackTrace);
33}
34#endif
35
36#if LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
37DILocAndCoverageTracking::DILocAndCoverageTracking(const DILocation *L)
39 Kind(DebugLocKind::Normal) {}
40#endif
41
42
43
44
47
51
53 assert(get() && "Expected valid DebugLoc");
54 return get()->getLine();
55}
56
58 assert(get() && "Expected valid DebugLoc");
59 return get()->getColumn();
60}
61
63 assert(get() && "Expected valid DebugLoc");
64 return get()->getScope();
65}
66
68 assert(get() && "Expected valid DebugLoc");
69 return get()->getInlinedAt();
70}
71
75
77
80 return DILocation::get(SP->getContext(), SP->getScopeLine(), 0, SP);
81
83}
84
87 return Loc->isImplicitCode();
88 return true;
89}
90
93 Loc->setImplicitCode(ImplicitCode);
94}
95
101
102
103
104 for (DILocation *Loc = RootLoc; Loc; Loc = Loc->getInlinedAt()) {
105 if (auto It = Cache.find(Loc); It != Cache.end()) {
107 break;
108 }
110 }
111
112 DILocation *UpdatedLoc = CachedResult;
113 if (!UpdatedLoc) {
114
115
118 *LocToUpdate->getScope(), NewSP, Ctx, Cache);
119 UpdatedLoc = DILocation::get(Ctx, LocToUpdate->getLine(),
120 LocToUpdate->getColumn(), NewScope);
121 Cache[LocToUpdate] = UpdatedLoc;
122 }
123
124
125
127 UpdatedLoc =
128 DILocation::get(Ctx, LocToUpdate->getLine(), LocToUpdate->getColumn(),
129 LocToUpdate->getScope(), UpdatedLoc);
130 Cache[LocToUpdate] = UpdatedLoc;
131 }
132
133 return UpdatedLoc;
134}
135
142
143
144 while (DILocation *IA = CurInlinedAt->getInlinedAt()) {
145
146 if (auto *Found = Cache[IA]) {
148 break;
149 }
150
151 InlinedAtLocations.push_back(IA);
152 CurInlinedAt = IA;
153 }
154
155
156
157
158
161 Ctx, MD->getLine(), MD->getColumn(), MD->getScope(), Last);
162
164}
165
167 if (Locs.empty())
169 if (Locs.size() == 1)
170 return Locs[0];
174 if (!Merged)
175 break;
176 }
177 return Merged;
178}
180 if (!LocA || !LocB) {
181
182
183#if LLVM_ENABLE_DEBUGLOC_TRACKING_COVERAGE
184 if (!LocA && LocA.getKind() == DebugLocKind::Normal)
185 return LocA;
186 if (!LocB && LocB.getKind() == DebugLocKind::Normal)
187 return LocB;
188#endif
189 if (!LocA)
190 return LocA;
191 return LocB;
192 }
194}
195
196#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
198#endif
199
201 if (!Loc)
202 return;
203
204
206 OS << Scope->getFilename();
209 OS << ':' << getCol();
210
212 OS << " @[ ";
213 InlinedAtDL.print(OS);
214 OS << " ]";
215 }
216}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
size_t size() const
size - Get the array size.
bool empty() const
empty - Check if the array is empty.
static LLVM_ABI DILocalScope * cloneScopeForSubprogram(DILocalScope &RootScope, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Traverses the scope chain rooted at RootScope until it hits a Subprogram, recreating the chain with "...
static LLVM_ABI DILocation * getMergedLocation(DILocation *LocA, DILocation *LocB)
Attempts to merge LocA and LocB into a single location; see DebugLoc::getMergedLocation for more deta...
Base class for scope-like contexts.
Subprogram description. Uses SubclassData1.
LLVM_ABI void setImplicitCode(bool ImplicitCode)
Definition DebugLoc.cpp:91
LLVM_ABI unsigned getLine() const
Definition DebugLoc.cpp:52
LLVM_ABI DebugLoc getFnDebugLoc() const
Find the debug info location for the start of the function.
Definition DebugLoc.cpp:76
LLVM_ABI DILocation * get() const
Get the underlying DILocation.
Definition DebugLoc.cpp:48
LLVM_ABI MDNode * getScope() const
Definition DebugLoc.cpp:62
static LLVM_ABI DebugLoc appendInlinedAt(const DebugLoc &DL, DILocation *InlinedAt, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Rebuild the entire inlined-at chain for this instruction so that the top of the chain now is inlined-...
Definition DebugLoc.cpp:136
static LLVM_ABI DebugLoc getMergedLocation(DebugLoc LocA, DebugLoc LocB)
When two instructions are combined into a single instruction we also need to combine the original loc...
Definition DebugLoc.cpp:179
LLVM_ABI void print(raw_ostream &OS) const
prints source location /path/to/file.exe:line:col @[inlined at]
Definition DebugLoc.cpp:200
static LLVM_ABI DebugLoc getMergedLocations(ArrayRef< DebugLoc > Locs)
Try to combine the vector of locations passed as input in a single one.
Definition DebugLoc.cpp:166
LLVM_ABI unsigned getCol() const
Definition DebugLoc.cpp:57
static LLVM_ABI DebugLoc replaceInlinedAtSubprogram(const DebugLoc &DL, DISubprogram &NewSP, LLVMContext &Ctx, DenseMap< const MDNode *, MDNode * > &Cache)
Rebuild the entire inline-at chain by replacing the subprogram at the end of the chain with NewSP.
Definition DebugLoc.cpp:96
LLVM_ABI bool isImplicitCode() const
Check if the DebugLoc corresponds to an implicit code.
Definition DebugLoc.cpp:85
LLVM_ABI void dump() const
Definition DebugLoc.cpp:197
LLVM_ABI DILocation * getInlinedAt() const
Definition DebugLoc.cpp:67
LLVM_ABI MDNode * getInlinedAtScope() const
Get the fully inlined-at scope for a DebugLoc.
Definition DebugLoc.cpp:72
This is an important class for using LLVM in a threaded context.
static MDTuple * getDistinct(LLVMContext &Context, ArrayRef< Metadata * > MDs)
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class implements an extremely fast bulk output stream that can only output to a stream.
This is an optimization pass for GlobalISel generic memory operations.
auto drop_begin(T &&RangeOrContainer, size_t N=1)
Return a range covering RangeOrContainer with the first N elements excluded.
TypedTrackingMDRef< MDNode > TrackingMDNodeRef
auto cast_or_null(const Y &Val)
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
LLVM_ABI DISubprogram * getDISubprogram(const MDNode *Scope)
Find subprogram that is enclosing this scope.