-
Notifications
You must be signed in to change notification settings - Fork 838
[DebugInfo] Copy debug info in call-utils.h #6652
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| /* | ||
| * Copyright 2019 WebAssembly Community Group participants | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #ifndef wasm_ir_debuginfo_h | ||
| #define wasm_ir_debuginfo_h | ||
|
|
||
| #include "wasm.h" | ||
|
|
||
| namespace wasm::debuginfo { | ||
|
|
||
| // Given an original expression and another that replaces it, copy the debuginfo | ||
| // from the former to the latter. Note the expression may not be an exclusive | ||
| // replacement of the other (the other may be replaced by several expressions, | ||
| // all of whom may end up with the same debug info). | ||
| inline void copyOriginalToReplacement(Expression* original, | ||
| Expression* replacement, | ||
| Function* func) { | ||
| auto& debugLocations = func->debugLocations; | ||
| // Early exit if there is no debug info at all. Also, leave if we already | ||
| // have debug info on the new replacement, which we don't want to trample: | ||
| // if there is no debug info we do want to copy, as a replacement operation | ||
| // suggests the new code plays the same role (it is an optimized version of | ||
| // the old), but if the code is already annotated, trust that. | ||
| if (debugLocations.empty() || debugLocations.count(replacement)) { | ||
| return; | ||
| } | ||
|
|
||
| auto iter = debugLocations.find(original); | ||
| if (iter != debugLocations.end()) { | ||
| debugLocations[replacement] = iter->second; | ||
| // Note that we do *not* erase the debug info of the expression being | ||
| // replaced, because it may still exist: we might replace | ||
| // | ||
| // (call | ||
| // (block .. | ||
| // | ||
| // with | ||
| // | ||
| // (block | ||
| // (call .. | ||
| // | ||
| // We still want the call here to have its old debug info. | ||
| // | ||
| // (In most cases, of course, we do remove the replaced expression, | ||
| // which means we accumulate unused garbage in debugLocations, but | ||
| // that's not that bad; we use arena allocation for Expressions, after | ||
| // all.) | ||
| } | ||
| } | ||
|
|
||
| // Given an expression and a copy of it in another function, copy the debug | ||
| // info into the second function. | ||
| void copyBetweenFunctions(Expression* origin, | ||
| Expression* copy, | ||
| Function* originFunc, | ||
| Function* copyFunc); | ||
| } // namespace wasm::debuginfo | ||
|
|
||
| #endif // wasm_ir_debuginfo_h |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did these
blocks andlocal.gets get the debug info? The code only seems to put the debug function for the new calls...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The outer block gets it because we replace the original instruction with the block, so the debuginfo is copied by default in
replaceCurrent(which seems like a reasonable default, and I don't think it is harmful here). But I am actually not sure why thelocal.getalso receives it... we must have specific code for that somewhere. It also seems ok to me though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the debug info was already being copied in
replaceCurrent, no? I wonder what caused the change.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I think I figured it out: these
local.gets are not actually new. They are reused from the original code before this optimization, and they all had debuginfo before, so they still have it after. CallUtils adds some additionallocal.gets, which was confusing, and those have no debug info as expected.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically
$x,$y,$zare pre-existing locals and gets, with names and debug info, and$4,$5are new locals with neither names nor debug info.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why did the
blockget new debug info then?replaceCurrentwas already coping the debug info. Also I still don’t get whylocal.gets that already existed newly got debug info. If thoselocal.gets already had debug info why was it not shown before? Other thanmakeCall, this PR does not change other things semantically, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The block gets debug info after this PR because the test had no debug info before. See line 310. Maybe a separate NFC PR that just modified the test would have made that clearer, sorry.
The
local.gets had debug info before, but by default we don't repeat debug info in the printed output:Not only the
call_refhas that debug location but all its children. We just don't print it (unlessBINARYEN_PRINT_FULL=1is set), because typically nested children have the same locations, so this makes the default text easier to read.(If a child had different debug info we'd print that, or if it was marked as having no debug info we'd add
;;@, with nothing else on that line.)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see. Also I missed the newly added debug info. Thanks for the explanation!