Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DebugInfo] Change lowering of SIL instructions to use line 0 when appropriate #77655

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

felipepiovezan
Copy link
Contributor

This patch performs two NFC refactors to make the code control flow legible, and then fixes an issue where incorrect line numbers causes poor debugging experience.

felipepiovezan added a commit to felipepiovezan/llvm-project that referenced this pull request Nov 15, 2024
With [0], more accurate line numbers are generated; as such, some LLDB
tests need to be updated.

[0]: swiftlang/swift#77655
@felipepiovezan
Copy link
Contributor Author

@@ -341,6 +341,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
IRGenDebugInfoFormat getDebugInfoFormat() { return Opts.DebugInfoFormat; }

private:
FileAndLocation computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short Doxygen comment?

@@ -342,6 +342,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {

private:
FileAndLocation computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc);
FileAndLocation computeLLVMLocCodeView(const SILDebugScope *DS,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and here

@@ -2613,11 +2615,24 @@ bool IRGenDebugInfoImpl::lineEntryIsSane(FileAndLocation DL,
}
#endif

/// In CodeView, zero is not an artificial line location. We try to avoid those
/// line locations near user code to reduce the number of breaks in the
/// linetables.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be in the declaration I think

@adrian-prantl
Copy link
Contributor

The actual change looks good!

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.
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.
Prior to this commit, when lowering SIL instructions that should are
"hidden" for the purposes of debugging, the compiler just attaches the
location of the previous instruction in the name of keeping a simpler
line table.

However, this is wrong for many reasons. One such reason is this: at the
start of a basic block, inheriting the previous debug location will
almost certainly cause the instruction to have a random location in the
code, as it will depend on whatever BB was visited previously.

Other examples can be seen in the tests affect by this commit, which
changes lowering to use Line 0 instead of the line number of the
previous instruction.

CodeView doesn't handle line 0 the same way DWARF does, so this commit
preserves the old behavior for the CodeView path.

rdar://139826231&110187845
@felipepiovezan
Copy link
Contributor Author

addressed review comments

@felipepiovezan
Copy link
Contributor Author

@felipepiovezan
Copy link
Contributor Author

swiftlang/llvm-project#9614
@swift-ci test linux platform

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants