summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
diff options
context:
space:
mode:
authorDerek Schuff <dschuff@google.com>2016-08-01 21:34:04 +0000
committerDerek Schuff <dschuff@google.com>2016-08-01 21:34:04 +0000
commitf41f67d3d91ca7aea611fd6eb4dc11d32ff677d5 (patch)
tree415db41f5891d4c73bde4d6a2b89c2e031758676 /llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
parent4a7130a8fb77e45f3e597a132a539ac323ac6a34 (diff)
downloadbcm5719-llvm-f41f67d3d91ca7aea611fd6eb4dc11d32ff677d5.tar.gz
bcm5719-llvm-f41f67d3d91ca7aea611fd6eb4dc11d32ff677d5.zip
[WebAssembly] Add asm.js-style exception handling support
Summary: This patch includes asm.js-style exception handling support for WebAssembly. The WebAssembly MVP does not have any support for unwinding or non-local control flow. In order to support C++ exceptions, emscripten currently uses JavaScript exceptions along with some support code (written in JavaScript) that is bundled by emscripten with the generated code. This scheme lowers exception-related instructions for wasm such that wasm modules can be compatible with emscripten's existing scheme and share the support code. Patch by Heejin Ahn Differential Revision: https://reviews.llvm.org/D22958 llvm-svn: 277391
Diffstat (limited to 'llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp')
-rw-r--r--llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
index 32154af3c1c..83ef03a8c75 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
@@ -29,10 +29,20 @@ using namespace llvm;
#define DEBUG_TYPE "wasm"
+// Emscripten's asm.js-style exception handling
+static cl::opt<bool> EnableEmExceptionHandling(
+ "wasm-em-exception-handling",
+ cl::desc("WebAssembly Emscripten-style exception handling"),
+ cl::init(false));
+
extern "C" void LLVMInitializeWebAssemblyTarget() {
// Register the target.
RegisterTargetMachine<WebAssemblyTargetMachine> X(TheWebAssemblyTarget32);
RegisterTargetMachine<WebAssemblyTargetMachine> Y(TheWebAssemblyTarget64);
+
+ // Register exception handling pass to opt
+ initializeWebAssemblyLowerEmscriptenExceptionsPass(
+ *PassRegistry::getPassRegistry());
}
//===----------------------------------------------------------------------===//
@@ -149,6 +159,10 @@ void WebAssemblyPassConfig::addIRPasses() {
if (getOptLevel() != CodeGenOpt::None)
addPass(createWebAssemblyOptimizeReturned());
+ // Handle exceptions.
+ if (EnableEmExceptionHandling)
+ addPass(createWebAssemblyLowerEmscriptenExceptions());
+
TargetPassConfig::addIRPasses();
}
OpenPOWER on IntegriCloud