This is an archive of the discontinued LLVM Phabricator instance.

Add asm.js-style exception handling support for wasm
ClosedPublic

Authored by aheejin on Jul 29 2016, 2:32 AM.

Details

Summary

This patch includes asm.js-style exception handling support for WebAssembly. To handle exceptions, this scheme lowers exception-related instructions in order to use JavaScript's try and catch mechanism.

Diff Detail

Repository
rL LLVM

Event Timeline

aheejin updated this revision to Diff 66097.Jul 29 2016, 2:32 AM
aheejin retitled this revision from to Add asm.js-style exception handling support for wasm.
aheejin updated this object.
aheejin added a reviewer: dschuff.
aheejin updated this revision to Diff 66098.Jul 29 2016, 2:37 AM

Delete .clang-format that was uploaded by a mistake

aheejin updated this revision to Diff 66100.Jul 29 2016, 2:44 AM

Re-add .clang-format and revert all changes. I didn't know this file was already in the repo.

aheejin updated this revision to Diff 66101.Jul 29 2016, 2:46 AM

Revert vimrc that was uploaded by mistake.

aheejin updated this revision to Diff 66180.Jul 29 2016, 2:55 PM

Fix typos

dschuff edited edge metadata.Jul 29 2016, 3:04 PM

First round; looks pretty good overall.

lib/Target/WebAssembly/WebAssemblyLowerExceptions.cpp
1 ↗(On Diff #66101)

Maybe we should call this WebAssemblyLowerEmscriptenExceptions so that when we want to experiment with an alternative way to do it, they can both be in the tree at the same time, and it will be unambiguous what they mean. (also applies to the string pass name).

12 ↗(On Diff #66101)

Let's call this 'Emscripten's Javascript try and catch mechanism', since there could be others.

56 ↗(On Diff #66101)

labdl -> label

125 ↗(On Diff #66101)

Let's initialize these to nullptr here, just for general paranoia.

153 ↗(On Diff #66101)

Remove the comment about emscripten builtins here.

196 ↗(On Diff #66101)

how about FindMatchingCatches.count(NumClauses)

285 ↗(On Diff #66101)

We should use the IRBuilder interface (here and below) rather than creating the instructions directly with new or FooInst::create()

314 ↗(On Diff #66101)

Here you should use auto *II = dyn_cast<InvokeInst>(...) since the type InvokeInst is already stated on that same line and it's obvious. In other cases (e.g. IntegerType *Int1Ty = Type::getInt1Ty(...) or BasicBlock *BB = BasicBlock::Create(...)) you could also use auto * if you wanted but I'd consider it optional.

325 ↗(On Diff #66101)

auto *F

415 ↗(On Diff #66101)

The wasm backend has aggregate varargs support so we should update this comment. but we can leave the code the same to be compatible with the JSBackend.

test/CodeGen/WebAssembly/lower-exceptions.ll
5 ↗(On Diff #66101)

Could we maybe make these regexes a little more specific? So we'd catch the error in case e.g. they get reordered or something.

aheejin updated this revision to Diff 66233.Jul 30 2016, 6:38 PM
aheejin marked 11 inline comments as done.
aheejin edited edge metadata.

Addressed comments

aheejin updated this revision to Diff 66234.Jul 30 2016, 6:47 PM

clang-format

dschuff added inline comments.Aug 1 2016, 10:21 AM
lib/Target/WebAssembly/WebAssemblyLowerEmscriptenExceptions.cpp
108 ↗(On Diff #66234)

let's also update this to "wasm-lower-em-exceptions" or something like that, since it also affects the pass name when run under opt.

148 ↗(On Diff #66234)

Also update the description string.

365 ↗(On Diff #66234)

Let's also use IRBuilder in this function and everywhere else (in general, it should be used wherever possible). We could construct it outside the loop and just set the insert point here. I know it seems pedantic but IRBuilder automates some useful things (e.g. constant folding) and can result in better code.

lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
33 ↗(On Diff #66234)

we should also name this flag such that it somehow refers to emscripten.

test/CodeGen/WebAssembly/lower-exceptions.ll
1 ↗(On Diff #66234)

should be 'RUN:' (i.e. it needs the colon), or it won't actually run the test.

aheejin updated this revision to Diff 66364.Aug 1 2016, 1:07 PM
aheejin marked 5 inline comments as done.

Address comments

dschuff accepted this revision.Aug 1 2016, 1:24 PM
dschuff edited edge metadata.

LGTM

This revision is now accepted and ready to land.Aug 1 2016, 1:24 PM
dschuff added a subscriber: jpp.Aug 1 2016, 1:59 PM
This revision was automatically updated to reflect the committed changes.