Skip to content

Commit 9758099

Browse files
[NFC][DebugInfo] Factor out CodeView code into its own function
CodeView has its own needs / limitations for representing line 0. However, this is adding control flow complexities that make changing the underlying logic complicated for both cases. Furthermore, the limitations above may be temporary if we change LLVM's backend; by having a separate function, we can, in the future, easily unify the code paths in the future by deleting the function.
1 parent e9fbb17 commit 9758099

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,12 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
344344
/// Convert a SILLocation into the corresponding LLVM Loc.
345345
FileAndLocation computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc);
346346

347+
/// Compute the LLVM DebugLoc when targeting CodeView. In CodeView, zero is
348+
/// not an artificial line location; attempt to avoid those line locations near
349+
/// user code to reduce the number of breaks in the linetables.
350+
FileAndLocation computeLLVMLocCodeView(const SILDebugScope *DS,
351+
SILLocation Loc);
352+
347353
static StringRef getFilenameFromDC(const DeclContext *DC) {
348354
if (auto *LF = dyn_cast<LoadedFile>(DC))
349355
return LF->getFilename();
@@ -2614,11 +2620,21 @@ bool IRGenDebugInfoImpl::lineEntryIsSane(FileAndLocation DL,
26142620
}
26152621
#endif
26162622

2623+
IRGenDebugInfoImpl::FileAndLocation
2624+
IRGenDebugInfoImpl::computeLLVMLocCodeView(const SILDebugScope *DS,
2625+
SILLocation Loc) {
2626+
// If the scope has not changed and the line number is either zero or
2627+
// artificial, we want to keep the most recent debug location.
2628+
if (DS == LastScope &&
2629+
(Loc.is<ArtificialUnreachableLocation>() || Loc.isLineZero(SM)))
2630+
return LastFileAndLocation;
2631+
2632+
// Decode the location.
2633+
return decodeFileAndLocation(Loc);
2634+
}
2635+
26172636
IRGenDebugInfoImpl::FileAndLocation
26182637
IRGenDebugInfoImpl::computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc) {
2619-
// NOTE: In CodeView, zero is not an artificial line location. We try to
2620-
// avoid those line locations near user code to reduce the number
2621-
// of breaks in the linetables.
26222638
SILFunction *Fn = DS->getInlinedFunction();
26232639
if (Fn && (Fn->isThunk() || Fn->isTransparent()))
26242640
return {0, 0, CompilerGeneratedFile};
@@ -2628,24 +2644,14 @@ IRGenDebugInfoImpl::computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc) {
26282644
if (DS == LastScope && Loc.isHiddenFromDebugInfo())
26292645
return LastFileAndLocation;
26302646

2631-
// If the scope has not changed and the line number is either zero or
2632-
// artificial, we want to keep the most recent debug location.
2633-
if (DS == LastScope &&
2634-
(Loc.is<ArtificialUnreachableLocation>() || Loc.isLineZero(SM)) &&
2635-
Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2636-
return LastFileAndLocation;
2647+
if (Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2648+
return computeLLVMLocCodeView(DS, Loc);
26372649

2638-
FileAndLocation L;
2639-
// Decode the location.
2640-
if (!Loc.isInPrologue() ||
2641-
Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2642-
L = decodeFileAndLocation(Loc);
2643-
2644-
// Otherwise use a line 0 artificial location, but the file from the
2645-
// location. If we are emitting CodeView, we do not want to use line zero
2646-
// since it does not represent an artificial line location.
2647-
if (Loc.isHiddenFromDebugInfo() &&
2648-
Opts.DebugInfoFormat != IRGenDebugInfoFormat::CodeView) {
2650+
FileAndLocation L =
2651+
Loc.isInPrologue() ? FileAndLocation() : decodeFileAndLocation(Loc);
2652+
2653+
// Otherwise use a line 0 artificial location, but the file from the location.
2654+
if (Loc.isHiddenFromDebugInfo()) {
26492655
L.Line = 0;
26502656
L.Column = 0;
26512657
}

0 commit comments

Comments
 (0)