Large diffs are not rendered by default.

15 changes: 11 additions & 4 deletions llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,24 @@ using namespace llvm;
#define DEBUG_TYPE "wasm"

// Emscripten's asm.js-style exception handling
static cl::opt<bool> EnableEmExceptionHandling(
static cl::opt<bool> EnableEmException(
"enable-emscripten-cxx-exceptions",
cl::desc("WebAssembly Emscripten-style exception handling"),
cl::init(false));

// Emscripten's asm.js-style setjmp/longjmp handling
static cl::opt<bool> EnableEmSjLj(
"enable-emscripten-sjlj",
cl::desc("WebAssembly Emscripten-style setjmp/longjmp 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(
initializeWebAssemblyLowerEmscriptenEHSjLjPass(
*PassRegistry::getPassRegistry());
}

Expand Down Expand Up @@ -160,8 +166,9 @@ void WebAssemblyPassConfig::addIRPasses() {
addPass(createWebAssemblyOptimizeReturned());

// Handle exceptions.
if (EnableEmExceptionHandling)
addPass(createWebAssemblyLowerEmscriptenExceptions());
if (EnableEmException || EnableEmSjLj)
addPass(createWebAssemblyLowerEmscriptenEHSjLj(EnableEmException,
EnableEmSjLj));

TargetPassConfig::addIRPasses();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
; RUN: opt < %s -wasm-lower-em-exceptions -emscripten-cxx-exceptions-whitelist=do_catch -S | FileCheck %s
; RUN: opt < %s -wasm-lower-em-ehsjlj -emscripten-cxx-exceptions-whitelist=do_catch -S | FileCheck %s

define void @dont_catch() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
; CHECK-LABEL: @dont_catch(
Expand Down
16 changes: 8 additions & 8 deletions llvm/test/CodeGen/WebAssembly/lower-em-exceptions.ll
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
; RUN: opt < %s -wasm-lower-em-exceptions -S | FileCheck %s
; RUN: opt < %s -wasm-lower-em-ehsjlj -S | FileCheck %s

@_ZTIi = external constant i8*
@_ZTIc = external constant i8*
; CHECK: @[[__THREW__:__THREW__.*]] = global i1 false
; CHECK: @[[THREWVALUE:threwValue.*]] = global i32 0
; CHECK: @[[TEMPRET0:tempRet0.*]] = global i32 0
; CHECK: @[[THREWVALUE:__threwValue.*]] = global i32 0
; CHECK: @[[TEMPRET0:__tempRet0.*]] = global i32 0

; Test invoke instruction with clauses (try-catch block)
define void @clause() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
Expand Down Expand Up @@ -170,12 +170,12 @@ declare void @__cxa_call_unexpected(i8*)
; setThrew function creation
; CHECK-LABEL: define void @setThrew(i1 %threw, i32 %value) {
; CHECK: entry:
; CHECK-NEXT: %__THREW__.val = load i1, i1* @__THREW__
; CHECK-NEXT: %cmp = icmp eq i1 %__THREW__.val, false
; CHECK-NEXT: %[[__THREW__]].val = load i1, i1* @[[__THREW__]]
; CHECK-NEXT: %cmp = icmp eq i1 %[[__THREW__]].val, false
; CHECK-NEXT: br i1 %cmp, label %if.then, label %if.end
; CHECK: if.then:
; CHECK-NEXT: store i1 %threw, i1* @__THREW__
; CHECK-NEXT: store i32 %value, i32* @threwValue
; CHECK-NEXT: store i1 %threw, i1* @[[__THREW__]]
; CHECK-NEXT: store i32 %value, i32* @[[THREWVALUE]]
; CHECK-NEXT: br label %if.end
; CHECK: if.end:
; CHECK-NEXT: ret void
Expand All @@ -184,6 +184,6 @@ declare void @__cxa_call_unexpected(i8*)
; setTempRet0 function creation
; CHECK-LABEL: define void @setTempRet0(i32 %value) {
; CHECK: entry:
; CHECK-NEXT: store i32 %value, i32* @tempRet0
; CHECK-NEXT: store i32 %value, i32* @[[TEMPRET0]]
; CHECK-NEXT: ret void
; CHECK: }