Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Issue 2562393002: [wasm] Introduce the TrapIf and TrapUnless operators to generate trap code. (Closed)

Created:
4 years ago by ahaas
Modified:
4 years ago
CC:
Michael Hablich, v8-mips-ports_googlegroups.com, v8-ppc-ports_googlegroups.com, v8-reviews_googlegroups.com, v8-x87-ports_googlegroups.com
Target Ref:
refs/pending/heads/master
Project:
v8
Visibility:
Public.

Description

[wasm] Introduce the TrapIf and TrapUnless operators to generate trap code. Some instructions in WebAssembly trap for some inputs, which means that the execution is terminated and (at least at the moment) a JavaScript exception is thrown. Examples for traps are out-of-bounds memory accesses, or integer divisions by zero. Without the TrapIf and TrapUnless operators trap check in WebAssembly introduces 5 TurboFan nodes (branch, if_true, if_false, trap-reason constant, trap-position constant), in addition to the trap condition itself. Additionally, each WebAssembly function has four TurboFan nodes (merge, effect_phi, 2 phis) whose number of inputs is linear to the number of trap checks in the function. Especially for functions with high numbers of trap checks we observe a significant slowdown in compilation time, down to 0.22 MiB/s in the sqlite benchmark instead of the average of 3 MiB/s in other benchmarks. By introducing a TrapIf common operator only a single node is necessary per trap check, in addition to the trap condition. Also the nodes which are shared between trap checks (merge, effect_phi, 2 phis) would disappear. First measurements suggest a speedup of 30-50% on average. This CL only implements TrapIf and TrapUnless on x64. The implementation is also hidden behind the --wasm-trap-if flag. Please take a special look at how the source position is transfered from the instruction selector to the code generator, and at the context that is used for the runtime call. R=titzer@chromium.org Review-Url: https://codereview.chromium.org/2562393002 Cr-Commit-Position: refs/heads/master@{#41720} Committed: https://chromium.googlesource.com/v8/v8/+/7bd61b601cc3aa637c378813f010f25e1c2f9145

Patch Set 1 #

Total comments: 14

Patch Set 2 : Comments addressed #

Patch Set 3 : Create a reference map for the frame so that the GC can deal with it #

Patch Set 4 : Record the safepoint at the right position #

Total comments: 6

Patch Set 5 : Benedikt's comments, + ud2 behind --debug-code #

Patch Set 6 : Extract DoCall function to avoid a bad stack on Windows. #

Patch Set 7 : put ud2 at the end of the generated code. #

Patch Set 8 : Copy the trap-location.js mjsunit test to use trap-if #

Total comments: 2

Patch Set 9 : Interpret TrapIf and TrapUnless as calls with respect to source positions. #

Patch Set 10 : Rename UseSourcePosition to IsSourcePositionUsed #

Unified diffs Side-by-side diffs Delta from patch set Stats (+668 lines, -181 lines) Patch
M src/assembler.h View 1 chunk +4 lines, -0 lines 0 comments Download
M src/assembler.cc View 1 chunk +6 lines, -0 lines 0 comments Download
M src/compiler/arm/code-generator-arm.cc View 2 chunks +5 lines, -0 lines 0 comments Download
M src/compiler/arm/instruction-selector-arm.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/arm64/code-generator-arm64.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/arm64/instruction-selector-arm64.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/code-generator.h View 1 2 4 chunks +7 lines, -5 lines 0 comments Download
M src/compiler/code-generator.cc View 2 chunks +8 lines, -2 lines 0 comments Download
M src/compiler/common-operator.h View 1 chunk +2 lines, -0 lines 0 comments Download
M src/compiler/common-operator.cc View 3 chunks +84 lines, -0 lines 0 comments Download
M src/compiler/ia32/code-generator-ia32.cc View 1 2 3 4 5 6 7 8 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/ia32/instruction-selector-ia32.cc View 3 4 5 6 7 8 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/instruction.cc View 1 chunk +2 lines, -0 lines 0 comments Download
M src/compiler/instruction-codes.h View 2 chunks +5 lines, -4 lines 0 comments Download
M src/compiler/instruction-selector.h View 1 2 3 4 5 6 7 8 9 2 chunks +3 lines, -0 lines 0 comments Download
M src/compiler/instruction-selector.cc View 1 2 3 4 5 6 7 8 9 4 chunks +12 lines, -4 lines 0 comments Download
M src/compiler/instruction-selector-impl.h View 1 2 3 4 5 6 7 8 5 chunks +22 lines, -1 line 0 comments Download
M src/compiler/mips/code-generator-mips.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/mips/instruction-selector-mips.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/mips64/code-generator-mips64.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/mips64/instruction-selector-mips64.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/opcodes.h View 1 2 1 chunk +2 lines, -0 lines 0 comments Download
M src/compiler/ppc/code-generator-ppc.cc View 2 chunks +5 lines, -0 lines 0 comments Download
M src/compiler/ppc/instruction-selector-ppc.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/s390/code-generator-s390.cc View 1 chunk +5 lines, -0 lines 0 comments Download
M src/compiler/s390/instruction-selector-s390.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/typer.cc View 1 2 2 chunks +4 lines, -0 lines 0 comments Download
M src/compiler/verifier.cc View 1 2 1 chunk +5 lines, -0 lines 0 comments Download
M src/compiler/wasm-compiler.cc View 1 2 chunks +45 lines, -4 lines 0 comments Download
M src/compiler/x64/code-generator-x64.cc View 1 2 3 4 5 6 7 8 3 chunks +109 lines, -89 lines 0 comments Download
M src/compiler/x64/instruction-selector-x64.cc View 1 2 3 4 5 6 7 8 4 chunks +27 lines, -6 lines 0 comments Download
M src/compiler/x87/code-generator-x87.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/compiler/x87/instruction-selector-x87.cc View 1 chunk +4 lines, -0 lines 0 comments Download
M src/external-reference-table.cc View 1 chunk +2 lines, -0 lines 0 comments Download
M src/flag-definitions.h View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -0 lines 0 comments Download
M src/runtime/runtime.h View 1 2 3 4 2 chunks +18 lines, -11 lines 0 comments Download
M src/runtime/runtime-wasm.cc View 1 3 chunks +22 lines, -4 lines 0 comments Download
M src/wasm/wasm-external-refs.h View 1 chunk +6 lines, -0 lines 0 comments Download
M src/wasm/wasm-external-refs.cc View 1 chunk +13 lines, -0 lines 0 comments Download
M src/wasm/wasm-opcodes.h View 2 chunks +2 lines, -2 lines 0 comments Download
M src/wasm/wasm-opcodes.cc View 2 chunks +14 lines, -0 lines 0 comments Download
M test/cctest/wasm/test-run-wasm.cc View 22 chunks +22 lines, -22 lines 0 comments Download
M test/cctest/wasm/test-run-wasm-64.cc View 19 chunks +19 lines, -19 lines 0 comments Download
M test/cctest/wasm/wasm-run-utils.h View 1 2 3 4 5 6 chunks +55 lines, -8 lines 0 comments Download
A test/mjsunit/wasm/trap-location-with-trap-if.js View 1 2 3 4 5 6 7 1 chunk +79 lines, -0 lines 0 comments Download

Messages

Total messages: 58 (43 generated)
ahaas
4 years ago (2016-12-12 13:51:38 UTC) #1
titzer
+bmeurer Looks mostly good. https://codereview.chromium.org/2562393002/diff/1/src/compiler/instruction-selector-impl.h File src/compiler/instruction-selector-impl.h (right): https://codereview.chromium.org/2562393002/diff/1/src/compiler/instruction-selector-impl.h#newcode477 src/compiler/instruction-selector-impl.h:477: int32_t trap_id_; // Only valid ...
4 years ago (2016-12-12 14:21:34 UTC) #7
ahaas
On 2016/12/12 at 14:21:34, titzer wrote: > +bmeurer > > Looks mostly good. > > ...
4 years ago (2016-12-12 15:40:42 UTC) #8
ahaas
https://codereview.chromium.org/2562393002/diff/1/src/compiler/instruction-selector-impl.h File src/compiler/instruction-selector-impl.h (right): https://codereview.chromium.org/2562393002/diff/1/src/compiler/instruction-selector-impl.h#newcode477 src/compiler/instruction-selector-impl.h:477: int32_t trap_id_; // Only valid if mode_ == kFlags_trap. ...
4 years ago (2016-12-13 12:38:59 UTC) #11
ahaas
There is still a problem when allocating the exception object causes a GC. There does ...
4 years ago (2016-12-13 14:20:43 UTC) #14
titzer
lgtm https://codereview.chromium.org/2562393002/diff/60001/src/compiler/wasm-compiler.cc File src/compiler/wasm-compiler.cc (right): https://codereview.chromium.org/2562393002/diff/60001/src/compiler/wasm-compiler.cc#newcode200 src/compiler/wasm-compiler.cc:200: #endif // V8_TARGET_ARCH_X64 End comment is out of ...
4 years ago (2016-12-14 10:15:04 UTC) #23
Benedikt Meurer
Definitely something that Jaro has to review. https://codereview.chromium.org/2562393002/diff/60001/src/compiler/x64/code-generator-x64.cc File src/compiler/x64/code-generator-x64.cc (right): https://codereview.chromium.org/2562393002/diff/60001/src/compiler/x64/code-generator-x64.cc#newcode2229 src/compiler/x64/code-generator-x64.cc:2229: static Condition ...
4 years ago (2016-12-14 10:34:42 UTC) #26
titzer
On 2016/12/14 10:34:42, Benedikt Meurer wrote: > Definitely something that Jaro has to review. > ...
4 years ago (2016-12-14 10:42:39 UTC) #27
ahaas
I added an ud2 instruction behind the --debug-code flag after the runtime call to make ...
4 years ago (2016-12-14 13:52:03 UTC) #30
ahaas
On 2016/12/14 at 13:52:03, ahaas wrote: > I added an ud2 instruction behind the --debug-code ...
4 years ago (2016-12-15 08:12:23 UTC) #39
Jarin
To be honest, I am not too familiar with this area of instruction-selector/code-gen. To my ...
4 years ago (2016-12-15 09:06:30 UTC) #42
ahaas
https://codereview.chromium.org/2562393002/diff/140001/src/compiler/x64/instruction-selector-x64.cc File src/compiler/x64/instruction-selector-x64.cc (right): https://codereview.chromium.org/2562393002/diff/140001/src/compiler/x64/instruction-selector-x64.cc#newcode1699 src/compiler/x64/instruction-selector-x64.cc:1699: selector->SetSourcePosition(instr, *cont->source_position()); On 2016/12/15 at 09:06:30, Jarin wrote: > ...
4 years ago (2016-12-15 11:35:18 UTC) #49
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/v2/patch-status/codereview.chromium.org/2562393002/180001
4 years ago (2016-12-15 13:29:30 UTC) #54
commit-bot: I haz the power
Committed patchset #10 (id:180001) as https://chromium.googlesource.com/v8/v8/+/7bd61b601cc3aa637c378813f010f25e1c2f9145
4 years ago (2016-12-15 13:31:36 UTC) #57
Michael Achenbach
4 years ago (2016-12-18 21:44:31 UTC) #58
Message was sent while issue was closed.
Note, this causes these ubsan failures:
https://build.chromium.org/p/client.v8/builders/V8%20Linux64%20-%20cfi/builds...

Powered by Google App Engine
This is Rietveld 408576698