Skip to content

Commit 212baeb

Browse files
[NFC][DebugInfo] Factor out debug location code
This patch moves, into its own function, the code computing a `FileAndLocation` for the instruction being lowered (SIL>LLVM IR). Control flows is simplified as a result. (cherry picked from commit e9fbb17)
1 parent aa30273 commit 212baeb

File tree

1 file changed

+43
-32
lines changed

1 file changed

+43
-32
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
344344
IRGenDebugInfoFormat getDebugInfoFormat() { return Opts.DebugInfoFormat; }
345345

346346
private:
347+
/// Convert a SILLocation into the corresponding LLVM Loc.
348+
FileAndLocation computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc);
349+
347350
static StringRef getFilenameFromDC(const DeclContext *DC) {
348351
if (auto *LF = dyn_cast<LoadedFile>(DC))
349352
return LF->getFilename();
@@ -2614,6 +2617,45 @@ bool IRGenDebugInfoImpl::lineEntryIsSane(FileAndLocation DL,
26142617
}
26152618
#endif
26162619

2620+
IRGenDebugInfoImpl::FileAndLocation
2621+
IRGenDebugInfoImpl::computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc) {
2622+
// NOTE: In CodeView, zero is not an artificial line location. We try to
2623+
// avoid those line locations near user code to reduce the number
2624+
// of breaks in the linetables.
2625+
SILFunction *Fn = DS->getInlinedFunction();
2626+
if (Fn && (Fn->isThunk() || Fn->isTransparent()))
2627+
return {0, 0, CompilerGeneratedFile};
2628+
2629+
// Reuse the last source location if we are still in the same scope to get a
2630+
// more contiguous line table.
2631+
if (DS == LastScope && Loc.isHiddenFromDebugInfo())
2632+
return LastFileAndLocation;
2633+
2634+
// If the scope has not changed and the line number is either zero or
2635+
// artificial, we want to keep the most recent debug location.
2636+
if (DS == LastScope &&
2637+
(Loc.is<ArtificialUnreachableLocation>() || Loc.isLineZero(SM)) &&
2638+
Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2639+
return LastFileAndLocation;
2640+
2641+
FileAndLocation L;
2642+
// Decode the location.
2643+
if (!Loc.isInPrologue() ||
2644+
Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2645+
L = decodeFileAndLocation(Loc);
2646+
2647+
// Otherwise use a line 0 artificial location, but the file from the
2648+
// location. If we are emitting CodeView, we do not want to use line zero
2649+
// since it does not represent an artificial line location.
2650+
if (Loc.isHiddenFromDebugInfo() &&
2651+
Opts.DebugInfoFormat != IRGenDebugInfoFormat::CodeView) {
2652+
L.Line = 0;
2653+
L.Column = 0;
2654+
}
2655+
2656+
return L;
2657+
}
2658+
26172659
void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
26182660
const SILDebugScope *DS,
26192661
SILLocation Loc) {
@@ -2622,38 +2664,7 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
26222664
if (!Scope)
26232665
return;
26242666

2625-
// NOTE: In CodeView, zero is not an artificial line location. We try to
2626-
// avoid those line locations near user code to reduce the number
2627-
// of breaks in the linetables.
2628-
FileAndLocation L;
2629-
SILFunction *Fn = DS->getInlinedFunction();
2630-
if (Fn && (Fn->isThunk() || Fn->isTransparent())) {
2631-
L = {0, 0, CompilerGeneratedFile};
2632-
} else if (DS == LastScope && Loc.isHiddenFromDebugInfo()) {
2633-
// Reuse the last source location if we are still in the same
2634-
// scope to get a more contiguous line table.
2635-
L = LastFileAndLocation;
2636-
} else if (DS == LastScope &&
2637-
(Loc.is<ArtificialUnreachableLocation>() || Loc.isLineZero(SM)) &&
2638-
Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView) {
2639-
// If the scope has not changed and the line number is either zero or
2640-
// artificial, we want to keep the most recent debug location.
2641-
L = LastFileAndLocation;
2642-
} else {
2643-
// Decode the location.
2644-
if (!Loc.isInPrologue() ||
2645-
Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2646-
L = decodeFileAndLocation(Loc);
2647-
2648-
// Otherwise use a line 0 artificial location, but the file from the
2649-
// location. If we are emitting CodeView, we do not want to use line zero
2650-
// since it does not represent an artificial line location.
2651-
if (Loc.isHiddenFromDebugInfo() &&
2652-
Opts.DebugInfoFormat != IRGenDebugInfoFormat::CodeView) {
2653-
L.Line = 0;
2654-
L.Column = 0;
2655-
}
2656-
}
2667+
FileAndLocation L = computeLLVMLoc(DS, Loc);
26572668

26582669
if (L.getFilename() != Scope->getFilename()) {
26592670
// We changed files in the middle of a scope. This happens, for

0 commit comments

Comments
 (0)