diff options
author | Alon Zakai <azakai@google.com> | 2024-06-12 11:05:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-12 11:05:28 -0700 |
commit | ac21c8cc9204e09fab070d2fd915e7ab583a5dac (patch) | |
tree | 190a13113804b3c6ea01dd71f44694e1b6111be0 /src/passes | |
parent | 475841dd5f0c50d7072f6dfc26dffd66e02abc10 (diff) | |
download | binaryen-ac21c8cc9204e09fab070d2fd915e7ab583a5dac.tar.gz binaryen-ac21c8cc9204e09fab070d2fd915e7ab583a5dac.tar.bz2 binaryen-ac21c8cc9204e09fab070d2fd915e7ab583a5dac.zip |
[DebugInfo] Copy debug info in call-utils.h (#6652)
We automatically copy debuginfo in replaceCurrent(), but there are a few
places that do other operations than simple replacements. call-utils.h will
turn a call_ref with a select target into two direct calls, and we were missing
the logic to copy debuginfo from the call_ref to the calls.
To make this work, refactor out the copying logic from wasm-traversal, into
debuginfo.h, and use it in call-utils.h.
debuginfo.h itself is renamed from debug.h (as now this needs to be included
from wasm-traversal, which nearly everything does, and it turns out some files
have internal stuff like a debug() helper that ends up conflicing with the old
debug namespace).
Also rename the old copyDebugInfo function to copyDebugInfoBetweenFunctions
which is more explicit. That is also moved from the header to a cpp file because
it depends on wasm-traversal (so we'd end up with recursive headers otherwise).
That is fine, as that method is called after copying a function, which is not that
frequent. The new copyDebugInfoToReplacement (which was refactored out of
wasm-traversal) is in the header because it can be called very frequently (every
single instruction we optimize) and we want it to get inlined.
Diffstat (limited to 'src/passes')
-rw-r--r-- | src/passes/Inlining.cpp | 4 | ||||
-rw-r--r-- | src/passes/call-utils.h | 14 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index 04bc6d78a..9e0d3eb67 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -31,7 +31,7 @@ #include <atomic> #include "ir/branch-utils.h" -#include "ir/debug.h" +#include "ir/debuginfo.h" #include "ir/drop.h" #include "ir/eh-utils.h" #include "ir/element-utils.h" @@ -579,7 +579,7 @@ static Expression* doInlining(Module* module, // Generate and update the inlined contents auto* contents = ExpressionManipulator::copy(from->body, *module); - debug::copyDebugInfo(from->body, contents, from, into); + debuginfo::copyBetweenFunctions(from->body, contents, from, into); updater.walk(contents); block->list.push_back(contents); block->type = retType; diff --git a/src/passes/call-utils.h b/src/passes/call-utils.h index 7f2ebfda3..10106a756 100644 --- a/src/passes/call-utils.h +++ b/src/passes/call-utils.h @@ -19,6 +19,7 @@ #include <variant> +#include "ir/debuginfo.h" #include "ir/type-updating.h" #include "wasm.h" @@ -130,14 +131,17 @@ convertToDirectCalls(T* curr, }; auto makeCall = [&](IndirectCallInfo info) -> Expression* { + Expression* ret; if (std::get_if<Trap>(&info)) { - return builder.makeUnreachable(); + ret = builder.makeUnreachable(); } else { - return builder.makeCall(std::get<Known>(info).target, - getOperands(), - curr->type, - curr->isReturn); + ret = builder.makeCall(std::get<Known>(info).target, + getOperands(), + curr->type, + curr->isReturn); } + debuginfo::copyOriginalToReplacement(curr, ret, &func); + return ret; }; auto* ifTrueCall = makeCall(ifTrueCallInfo); auto* ifFalseCall = makeCall(ifFalseCallInfo); |