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.
Details
Diff Detail
Event Timeline
Re-add .clang-format and revert all changes. I didn't know this file was already in the repo.
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. |
lib/Target/WebAssembly/WebAssemblyLowerEmscriptenExceptions.cpp | ||
---|---|---|
109 | 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. | |
149 | Also update the description string. | |
366 | 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 | 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. |
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.