From ac21c8cc9204e09fab070d2fd915e7ab583a5dac Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Wed, 12 Jun 2024 11:05:28 -0700 Subject: [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. --- src/ir/debug.h | 59 ---------------------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 src/ir/debug.h (limited to 'src/ir/debug.h') diff --git a/src/ir/debug.h b/src/ir/debug.h deleted file mode 100644 index 04838137e..000000000 --- a/src/ir/debug.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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_debug_h -#define wasm_ir_debug_h - -#include - -namespace wasm::debug { - -// Given an expression and a copy of it in another function, copy the debug -// info into the second function. -inline void copyDebugInfo(Expression* origin, - Expression* copy, - Function* originFunc, - Function* copyFunc) { - if (originFunc->debugLocations.empty()) { - return; // No debug info to copy - } - - struct Lister : public PostWalker> { - std::vector list; - void visitExpression(Expression* curr) { list.push_back(curr); } - }; - - Lister originList; - originList.walk(origin); - Lister copyList; - copyList.walk(copy); - - auto& originDebug = originFunc->debugLocations; - auto& copyDebug = copyFunc->debugLocations; - - assert(originList.list.size() == copyList.list.size()); - for (Index i = 0; i < originList.list.size(); i++) { - auto iter = originDebug.find(originList.list[i]); - if (iter != originDebug.end()) { - auto location = iter->second; - copyDebug[copyList.list[i]] = location; - } - } -}; - -} // namespace wasm::debug - -#endif // wasm_ir_debug_h -- cgit v1.2.3