diff options
-rw-r--r-- | src/ir/debug.h | 59 | ||||
-rw-r--r-- | src/passes/Inlining.cpp | 17 | ||||
-rw-r--r-- | test/debugInfo.asm.js | 15 | ||||
-rw-r--r-- | test/debugInfo.fromasm | 17 | ||||
-rw-r--r-- | test/debugInfo.fromasm.clamp | 17 | ||||
-rw-r--r-- | test/debugInfo.fromasm.clamp.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.clamp.no-opts | 37 | ||||
-rw-r--r-- | test/debugInfo.fromasm.clamp.no-opts.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.imprecise | 17 | ||||
-rw-r--r-- | test/debugInfo.fromasm.imprecise.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.imprecise.no-opts | 37 | ||||
-rw-r--r-- | test/debugInfo.fromasm.imprecise.no-opts.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.no-opts | 37 | ||||
-rw-r--r-- | test/debugInfo.fromasm.no-opts.map | 2 | ||||
-rw-r--r-- | test/debugInfo.fromasm.read-written | 17 |
16 files changed, 269 insertions, 13 deletions
diff --git a/src/ir/debug.h b/src/ir/debug.h new file mode 100644 index 000000000..d4ecf2b70 --- /dev/null +++ b/src/ir/debug.h @@ -0,0 +1,59 @@ +/* + * 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 <wasm-traversal.h> + +namespace wasm { + +namespace 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) { + struct Lister : public PostWalker<Lister, UnifiedExpressionVisitor<Lister>> { + std::vector<Expression*> 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 debug + +} // namespace wasm + +#endif // wasm_ir_debug_h diff --git a/src/passes/Inlining.cpp b/src/passes/Inlining.cpp index 5ed68a783..2aa800d62 100644 --- a/src/passes/Inlining.cpp +++ b/src/passes/Inlining.cpp @@ -32,6 +32,7 @@ #include <atomic> +#include "ir/debug.h" #include "ir/literal-utils.h" #include "ir/module-utils.h" #include "ir/utils.h" @@ -175,7 +176,7 @@ doInlining(Module* module, Function* into, InliningAction& action) { auto* block = Builder(*module).makeBlock(); block->name = Name(std::string("__inlined_func$") + from->name.str); *action.callSite = block; - // set up a locals mapping + // Prepare to update the inlined code's locals and other things. struct Updater : public PostWalker<Updater> { std::map<Index, Index> localMapping; Name returnName; @@ -193,33 +194,37 @@ doInlining(Module* module, Function* into, InliningAction& action) { } updater; updater.returnName = block->name; updater.builder = &builder; + // Set up a locals mapping for (Index i = 0; i < from->getNumLocals(); i++) { updater.localMapping[i] = builder.addVar(into, from->getLocalType(i)); } - // assign the operands into the params + // Assign the operands into the params for (Index i = 0; i < from->params.size(); i++) { block->list.push_back( builder.makeLocalSet(updater.localMapping[i], call->operands[i])); } - // zero out the vars (as we may be in a loop, and may depend on their + // Zero out the vars (as we may be in a loop, and may depend on their // zero-init value for (Index i = 0; i < from->vars.size(); i++) { block->list.push_back( builder.makeLocalSet(updater.localMapping[from->getVarIndexBase() + i], LiteralUtils::makeZero(from->vars[i], *module))); } - // generate and update the inlined contents + // Generate and update the inlined contents auto* contents = ExpressionManipulator::copy(from->body, *module); + if (!from->debugLocations.empty()) { + debug::copyDebugInfo(from->body, contents, from, into); + } updater.walk(contents); block->list.push_back(contents); block->type = call->type; - // if the function returned a value, we just set the block containing the + // If the function returned a value, we just set the block containing the // inlined code to have that type. or, if the function was void and // contained void, that is fine too. a bad case is a void function in which // we have unreachable code, so we would be replacing a void call with an // unreachable; we need to handle if (contents->type == unreachable && block->type == none) { - // make the block reachable by adding a break to it + // Make the block reachable by adding a break to it block->list.push_back(builder.makeBreak(block->name)); } return block; diff --git a/test/debugInfo.asm.js b/test/debugInfo.asm.js index bfdc85780..18555a8b9 100644 --- a/test/debugInfo.asm.js +++ b/test/debugInfo.asm.js @@ -84,6 +84,19 @@ function () { function nofile() { nofile(); //@line 1337 } - return { add: add, ret: ret, opts: opts, fib: fib, switch_reach: switch_reach, nofile: nofile }; + function inlineMe(x, y) { + x = x | 0; + y = y | 0; + x = x + y | 0; //@line 120 "inline_me.c" + y = x + y | 0; //@line 121 "inline_me.c" + x = x + y | 0; //@line 122 "inline_me.c" + return x | 0; //@line 123 "inline_me.c" + } + function inlineInto(x, y) { + x = x | 0; + y = y | 0; + return inlineMe(x | 0, y | 0) | 0; //@line 125 "inline_me.c" + } + return { add: add, ret: ret, opts: opts, fib: fib, switch_reach: switch_reach, nofile: nofile, inlineInto: inlineInto }; } diff --git a/test/debugInfo.fromasm b/test/debugInfo.fromasm index 7d1771d00..ae555542a 100644 --- a/test/debugInfo.fromasm +++ b/test/debugInfo.fromasm @@ -8,6 +8,7 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (export "nofile" (func $nofile)) + (export "inlineInto" (func $inlineInto)) (func $add (; 0 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) ;;@ tests/other_file.cpp:314159:0 (i32.add @@ -169,4 +170,20 @@ ;;@ (unknown):1337:0 (call $nofile) ) + (func $inlineInto (; 6 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + ;;@ inline_me.c:125:0 + (i32.add + ;;@ inline_me.c:120:0 + (local.tee $0 + (i32.add + (local.get $0) + (local.get $1) + ) + ) + (i32.add + (local.get $0) + (local.get $1) + ) + ) + ) ) diff --git a/test/debugInfo.fromasm.clamp b/test/debugInfo.fromasm.clamp index 7d1771d00..ae555542a 100644 --- a/test/debugInfo.fromasm.clamp +++ b/test/debugInfo.fromasm.clamp @@ -8,6 +8,7 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (export "nofile" (func $nofile)) + (export "inlineInto" (func $inlineInto)) (func $add (; 0 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) ;;@ tests/other_file.cpp:314159:0 (i32.add @@ -169,4 +170,20 @@ ;;@ (unknown):1337:0 (call $nofile) ) + (func $inlineInto (; 6 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + ;;@ inline_me.c:125:0 + (i32.add + ;;@ inline_me.c:120:0 + (local.tee $0 + (i32.add + (local.get $0) + (local.get $1) + ) + ) + (i32.add + (local.get $0) + (local.get $1) + ) + ) + ) ) diff --git a/test/debugInfo.fromasm.clamp.map b/test/debugInfo.fromasm.clamp.map index e49a7309c..253ec1006 100644 --- a/test/debugInfo.fromasm.clamp.map +++ b/test/debugInfo.fromasm.clamp.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"qIC8ylTA,QC7vlTA,OAkDA,UCjGA,AADA,EADA,+BCEA,cAKA,QAJA,OADA,0BAKA,sECsi1DA,KCrvyDA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)","inline_me.c"],"names":[],"mappings":"mJC8ylTA,QC7vlTA,OAkDA,UCjGA,AADA,EADA,+BCEA,cAKA,QAJA,OADA,0BAKA,sECsi1DA,KCrvyDA,KC5rCA,AALA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.clamp.no-opts b/test/debugInfo.fromasm.clamp.no-opts index 29521dd22..29525fb89 100644 --- a/test/debugInfo.fromasm.clamp.no-opts +++ b/test/debugInfo.fromasm.clamp.no-opts @@ -11,6 +11,7 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (export "nofile" (func $nofile)) + (export "inlineInto" (func $inlineInto)) (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) ;;@ tests/hello_world.c:5:0 (local.set $x @@ -287,4 +288,40 @@ ;;@ (unknown):1337:0 (call $nofile) ) + (func $inlineMe (; 7 ;) (param $x i32) (param $y i32) (result i32) + ;;@ inline_me.c:120:0 + (local.set $x + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ;;@ inline_me.c:121:0 + (local.set $y + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ;;@ inline_me.c:122:0 + (local.set $x + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ;;@ inline_me.c:123:0 + (return + (local.get $x) + ) + ) + (func $inlineInto (; 8 ;) (param $x i32) (param $y i32) (result i32) + ;;@ inline_me.c:125:0 + (return + (call $inlineMe + (local.get $x) + (local.get $y) + ) + ) + ) ) diff --git a/test/debugInfo.fromasm.clamp.no-opts.map b/test/debugInfo.fromasm.clamp.no-opts.map index 091513249..ae1c41157 100644 --- a/test/debugInfo.fromasm.clamp.no-opts.map +++ b/test/debugInfo.fromasm.clamp.no-opts.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"sLAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,0ICsi1DA,MCrvyDA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)","inline_me.c"],"names":[],"mappings":"qMAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,0ICsi1DA,MCrvyDA,KCjsCA,OACA,OACA,OACA,MAEA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.imprecise b/test/debugInfo.fromasm.imprecise index a643cce56..3ceab1574 100644 --- a/test/debugInfo.fromasm.imprecise +++ b/test/debugInfo.fromasm.imprecise @@ -5,6 +5,7 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (export "nofile" (func $nofile)) + (export "inlineInto" (func $inlineInto)) (func $add (; 0 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) ;;@ tests/other_file.cpp:314159:0 (i32.add @@ -161,4 +162,20 @@ ;;@ (unknown):1337:0 (call $nofile) ) + (func $inlineInto (; 6 ;) (; has Stack IR ;) (param $0 i32) (param $1 i32) (result i32) + ;;@ inline_me.c:125:0 + (i32.add + ;;@ inline_me.c:120:0 + (local.tee $0 + (i32.add + (local.get $0) + (local.get $1) + ) + ) + (i32.add + (local.get $0) + (local.get $1) + ) + ) + ) ) diff --git a/test/debugInfo.fromasm.imprecise.map b/test/debugInfo.fromasm.imprecise.map index 316bdc518..7a9fde6e8 100644 --- a/test/debugInfo.fromasm.imprecise.map +++ b/test/debugInfo.fromasm.imprecise.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"4FC8ylTA,QC7vlTA,OAkDA,QCnGA,OACA,OACA,aCAA,cAKA,QAJA,OADA,0BAKA,sECsi1DA,KCrvyDA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)","inline_me.c"],"names":[],"mappings":"0GC8ylTA,QC7vlTA,OAkDA,QCnGA,OACA,OACA,aCAA,cAKA,QAJA,OADA,0BAKA,sECsi1DA,KCrvyDA,KC5rCA,AALA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.imprecise.no-opts b/test/debugInfo.fromasm.imprecise.no-opts index f24d2ba9c..b4c1b517e 100644 --- a/test/debugInfo.fromasm.imprecise.no-opts +++ b/test/debugInfo.fromasm.imprecise.no-opts @@ -11,6 +11,7 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (export "nofile" (func $nofile)) + (export "inlineInto" (func $inlineInto)) (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) ;;@ tests/hello_world.c:5:0 (local.set $x @@ -275,4 +276,40 @@ ;;@ (unknown):1337:0 (call $nofile) ) + (func $inlineMe (; 6 ;) (param $x i32) (param $y i32) (result i32) + ;;@ inline_me.c:120:0 + (local.set $x + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ;;@ inline_me.c:121:0 + (local.set $y + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ;;@ inline_me.c:122:0 + (local.set $x + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ;;@ inline_me.c:123:0 + (return + (local.get $x) + ) + ) + (func $inlineInto (; 7 ;) (param $x i32) (param $y i32) (result i32) + ;;@ inline_me.c:125:0 + (return + (call $inlineMe + (local.get $x) + (local.get $y) + ) + ) + ) ) diff --git a/test/debugInfo.fromasm.imprecise.no-opts.map b/test/debugInfo.fromasm.imprecise.no-opts.map index bce1d3419..4bc2b7738 100644 --- a/test/debugInfo.fromasm.imprecise.no-opts.map +++ b/test/debugInfo.fromasm.imprecise.no-opts.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"qLAIA,IACA,ICyylTA,aC7vlTA,OAkDA,SCnGA,OACA,OACA,sBCAA,4BAKA,QAJA,OADA,8CAKA,0ICsi1DA,MCrvyDA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)","inline_me.c"],"names":[],"mappings":"oMAIA,IACA,ICyylTA,aC7vlTA,OAkDA,SCnGA,OACA,OACA,sBCAA,4BAKA,QAJA,OADA,8CAKA,0ICsi1DA,MCrvyDA,KCjsCA,OACA,OACA,OACA,MAEA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.map b/test/debugInfo.fromasm.map index e49a7309c..253ec1006 100644 --- a/test/debugInfo.fromasm.map +++ b/test/debugInfo.fromasm.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"qIC8ylTA,QC7vlTA,OAkDA,UCjGA,AADA,EADA,+BCEA,cAKA,QAJA,OADA,0BAKA,sECsi1DA,KCrvyDA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)","inline_me.c"],"names":[],"mappings":"mJC8ylTA,QC7vlTA,OAkDA,UCjGA,AADA,EADA,+BCEA,cAKA,QAJA,OADA,0BAKA,sECsi1DA,KCrvyDA,KC5rCA,AALA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.no-opts b/test/debugInfo.fromasm.no-opts index 29521dd22..29525fb89 100644 --- a/test/debugInfo.fromasm.no-opts +++ b/test/debugInfo.fromasm.no-opts @@ -11,6 +11,7 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (export "nofile" (func $nofile)) + (export "inlineInto" (func $inlineInto)) (func $add (; 0 ;) (param $x i32) (param $y i32) (result i32) ;;@ tests/hello_world.c:5:0 (local.set $x @@ -287,4 +288,40 @@ ;;@ (unknown):1337:0 (call $nofile) ) + (func $inlineMe (; 7 ;) (param $x i32) (param $y i32) (result i32) + ;;@ inline_me.c:120:0 + (local.set $x + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ;;@ inline_me.c:121:0 + (local.set $y + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ;;@ inline_me.c:122:0 + (local.set $x + (i32.add + (local.get $x) + (local.get $y) + ) + ) + ;;@ inline_me.c:123:0 + (return + (local.get $x) + ) + ) + (func $inlineInto (; 8 ;) (param $x i32) (param $y i32) (result i32) + ;;@ inline_me.c:125:0 + (return + (call $inlineMe + (local.get $x) + (local.get $y) + ) + ) + ) ) diff --git a/test/debugInfo.fromasm.no-opts.map b/test/debugInfo.fromasm.no-opts.map index 091513249..ae1c41157 100644 --- a/test/debugInfo.fromasm.no-opts.map +++ b/test/debugInfo.fromasm.no-opts.map @@ -1 +1 @@ -{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"sLAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,0ICsi1DA,MCrvyDA"}
\ No newline at end of file +{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)","inline_me.c"],"names":[],"mappings":"qMAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,0ICsi1DA,MCrvyDA,KCjsCA,OACA,OACA,OACA,MAEA"}
\ No newline at end of file diff --git a/test/debugInfo.fromasm.read-written b/test/debugInfo.fromasm.read-written index 2cc9a03de..362d828a3 100644 --- a/test/debugInfo.fromasm.read-written +++ b/test/debugInfo.fromasm.read-written @@ -11,6 +11,7 @@ (export "fib" (func $fib)) (export "switch_reach" (func $switch_reach)) (export "nofile" (func $nofile)) + (export "inlineInto" (func $inlineInto)) (func $add (; 0 ;) (type $0) (param $0 i32) (param $1 i32) (result i32) ;;@ tests/other_file.cpp:314159:0 (i32.add @@ -175,5 +176,21 @@ ;;@ (unknown):1337:0 (call $nofile) ) + (func $inlineInto (; 6 ;) (type $0) (param $0 i32) (param $1 i32) (result i32) + ;;@ inline_me.c:120:0 + (i32.add + (local.tee $0 + (i32.add + (local.get $0) + (local.get $1) + ) + ) + (i32.add + (local.get $0) + (local.get $1) + ) + ) + ;;@ inline_me.c:125:0 + ) ) |