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 | 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 | Let's call this 'Emscripten's Javascript try and catch mechanism', since there could be others. | |
56 | labdl -> label | |
125 | Let's initialize these to nullptr here, just for general paranoia. | |
153 | Remove the comment about emscripten builtins here. | |
196 | how about FindMatchingCatches.count(NumClauses) | |
285 | We should use the IRBuilder interface (here and below) rather than creating the instructions directly with new or FooInst::create() | |
314 | 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 | auto *F | |
415 | 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 | 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 | ||
---|---|---|
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 | we should also name this flag such that it somehow refers to emscripten. | |
test/CodeGen/WebAssembly/lower-exceptions.ll | ||
2 | should be 'RUN:' (i.e. it needs the colon), or it won't actually run the test. |
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).