2018-08-27 23:45:51 +08:00
|
|
|
; RUN: not llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -exception-model=wasm
|
|
|
|
; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-keep-registers -exception-model=wasm -mattr=+exception-handling | FileCheck -allow-deprecated-dag-overlap %s
|
2017-06-30 08:43:15 +08:00
|
|
|
|
|
|
|
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
|
2018-05-11 01:49:11 +08:00
|
|
|
target triple = "wasm32-unknown-unknown"
|
2017-06-30 08:43:15 +08:00
|
|
|
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
%struct.Cleanup = type { i8 }
|
|
|
|
|
|
|
|
@_ZTIi = external constant i8*
|
|
|
|
|
2017-06-30 08:43:15 +08:00
|
|
|
declare void @llvm.wasm.throw(i32, i8*)
|
|
|
|
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
; CHECK-LABEL: test_throw:
|
2017-06-30 08:43:15 +08:00
|
|
|
; CHECK-NEXT: i32.const $push0=, 0
|
|
|
|
; CHECK-NEXT: throw 0, $pop0
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
define void @test_throw() {
|
2017-06-30 08:43:15 +08:00
|
|
|
call void @llvm.wasm.throw(i32 0, i8* null)
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2018-06-25 09:07:11 +08:00
|
|
|
; CHECK-LABEL: test_catch_rethrow:
|
2018-08-22 05:23:07 +08:00
|
|
|
; CHECK: get_global $push{{.+}}=, __stack_pointer@GLOBAL
|
2018-08-17 07:50:59 +08:00
|
|
|
; CHECK: try
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
; CHECK: call foo@FUNCTION
|
|
|
|
; CHECK: i32.catch $push{{.+}}=, 0
|
2018-08-22 05:23:07 +08:00
|
|
|
; CHECK: set_global __stack_pointer@GLOBAL
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
; CHECK-DAG: i32.store __wasm_lpad_context
|
|
|
|
; CHECK-DAG: i32.store __wasm_lpad_context+4
|
|
|
|
; CHECK: i32.call $push{{.+}}=, _Unwind_CallPersonality@FUNCTION
|
|
|
|
; CHECK: i32.call $push{{.+}}=, __cxa_begin_catch@FUNCTION
|
|
|
|
; CHECK: call __cxa_end_catch@FUNCTION
|
|
|
|
; CHECK: call __cxa_rethrow@FUNCTION
|
2018-06-25 09:07:11 +08:00
|
|
|
; CHECK-NEXT: rethrow
|
2018-08-17 07:50:59 +08:00
|
|
|
; CHECK: end_try
|
2018-06-25 09:07:11 +08:00
|
|
|
define void @test_catch_rethrow() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
entry:
|
|
|
|
invoke void @foo()
|
|
|
|
to label %try.cont unwind label %catch.dispatch
|
|
|
|
|
|
|
|
catch.dispatch: ; preds = %entry
|
|
|
|
%0 = catchswitch within none [label %catch.start] unwind to caller
|
|
|
|
|
|
|
|
catch.start: ; preds = %catch.dispatch
|
|
|
|
%1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*)]
|
|
|
|
%2 = call i8* @llvm.wasm.get.exception(token %1)
|
|
|
|
%3 = call i32 @llvm.wasm.get.ehselector(token %1)
|
|
|
|
%4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
|
|
|
|
%matches = icmp eq i32 %3, %4
|
|
|
|
br i1 %matches, label %catch, label %rethrow
|
|
|
|
|
|
|
|
catch: ; preds = %catch.start
|
|
|
|
%5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ]
|
|
|
|
call void @__cxa_end_catch() [ "funclet"(token %1) ]
|
|
|
|
catchret from %1 to label %try.cont
|
|
|
|
|
|
|
|
rethrow: ; preds = %catch.start
|
|
|
|
call void @__cxa_rethrow() [ "funclet"(token %1) ]
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
try.cont: ; preds = %entry, %catch
|
2017-06-30 08:43:15 +08:00
|
|
|
ret void
|
|
|
|
}
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
|
|
|
|
; CHECK-LABEL: test_cleanup:
|
2018-08-17 07:50:59 +08:00
|
|
|
; CHECK: try
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
; CHECK: call foo@FUNCTION
|
2018-06-25 09:07:11 +08:00
|
|
|
; CHECK: catch_all
|
2018-08-22 05:23:07 +08:00
|
|
|
; CHECK: set_global __stack_pointer@GLOBAL
|
2018-08-15 06:14:51 +08:00
|
|
|
; CHECK: i32.call $push{{.+}}=, _ZN7CleanupD1Ev@FUNCTION
|
2018-06-25 09:07:11 +08:00
|
|
|
; CHECK: rethrow
|
2018-08-17 07:50:59 +08:00
|
|
|
; CHECK: end_try
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
define void @test_cleanup() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
|
|
|
|
entry:
|
|
|
|
%c = alloca %struct.Cleanup, align 1
|
|
|
|
invoke void @foo()
|
|
|
|
to label %invoke.cont unwind label %ehcleanup
|
|
|
|
|
|
|
|
invoke.cont: ; preds = %entry
|
|
|
|
%call = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c)
|
|
|
|
ret void
|
|
|
|
|
|
|
|
ehcleanup: ; preds = %entry
|
|
|
|
%0 = cleanuppad within none []
|
|
|
|
%call1 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %0) ]
|
|
|
|
cleanupret from %0 unwind to caller
|
|
|
|
}
|
|
|
|
|
2018-06-25 09:07:11 +08:00
|
|
|
; - Tests multple terminate pads are merged into one
|
|
|
|
; - Tests a catch_all terminate pad is created after a catch terminate pad
|
|
|
|
|
|
|
|
; CHECK-LABEL: test_terminatepad
|
|
|
|
; CHECK: i32.catch
|
|
|
|
; CHECK: call __clang_call_terminate@FUNCTION
|
|
|
|
; CHECK: unreachable
|
|
|
|
; CHECK: catch_all
|
|
|
|
; CHECK: call _ZSt9terminatev@FUNCTION
|
|
|
|
; CHECK-NOT: call __clang_call_terminate@FUNCTION
|
|
|
|
define hidden i32 @test_terminatepad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
|
|
|
|
entry:
|
|
|
|
%c = alloca %struct.Cleanup, align 1
|
|
|
|
%c1 = alloca %struct.Cleanup, align 1
|
|
|
|
invoke void @foo()
|
|
|
|
to label %invoke.cont unwind label %ehcleanup
|
|
|
|
|
|
|
|
invoke.cont: ; preds = %entry
|
|
|
|
%call = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1)
|
|
|
|
to label %try.cont unwind label %catch.dispatch
|
|
|
|
|
|
|
|
ehcleanup: ; preds = %entry
|
|
|
|
%0 = cleanuppad within none []
|
|
|
|
%call4 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c1) [ "funclet"(token %0) ]
|
|
|
|
to label %invoke.cont3 unwind label %terminate
|
|
|
|
|
|
|
|
invoke.cont3: ; preds = %ehcleanup
|
|
|
|
cleanupret from %0 unwind label %catch.dispatch
|
|
|
|
|
|
|
|
catch.dispatch: ; preds = %invoke.cont3, %invoke.cont
|
|
|
|
%1 = catchswitch within none [label %catch.start] unwind label %ehcleanup7
|
|
|
|
|
|
|
|
catch.start: ; preds = %catch.dispatch
|
|
|
|
%2 = catchpad within %1 [i8* null]
|
|
|
|
%3 = call i8* @llvm.wasm.get.exception(token %2)
|
|
|
|
%4 = call i32 @llvm.wasm.get.ehselector(token %2)
|
|
|
|
%5 = call i8* @__cxa_begin_catch(i8* %3) [ "funclet"(token %2) ]
|
|
|
|
invoke void @__cxa_end_catch() [ "funclet"(token %2) ]
|
|
|
|
to label %invoke.cont5 unwind label %ehcleanup7
|
|
|
|
|
|
|
|
invoke.cont5: ; preds = %catch.start
|
|
|
|
catchret from %2 to label %try.cont
|
|
|
|
|
|
|
|
try.cont: ; preds = %invoke.cont5, %invoke.cont
|
|
|
|
%call6 = call %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c)
|
|
|
|
ret i32 0
|
|
|
|
|
|
|
|
ehcleanup7: ; preds = %catch.start, %catch.dispatch
|
|
|
|
%6 = cleanuppad within none []
|
|
|
|
%call9 = invoke %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* %c) [ "funclet"(token %6) ]
|
|
|
|
to label %invoke.cont8 unwind label %terminate10
|
|
|
|
|
|
|
|
invoke.cont8: ; preds = %ehcleanup7
|
|
|
|
cleanupret from %6 unwind to caller
|
|
|
|
|
|
|
|
terminate: ; preds = %ehcleanup
|
|
|
|
%7 = cleanuppad within %0 []
|
|
|
|
%8 = call i8* @llvm.wasm.get.exception(token %7)
|
|
|
|
call void @__clang_call_terminate(i8* %8) [ "funclet"(token %7) ]
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
terminate10: ; preds = %ehcleanup7
|
|
|
|
%9 = cleanuppad within %6 []
|
|
|
|
%10 = call i8* @llvm.wasm.get.exception(token %9)
|
|
|
|
call void @__clang_call_terminate(i8* %10) [ "funclet"(token %9) ]
|
|
|
|
unreachable
|
|
|
|
}
|
|
|
|
|
2018-08-22 03:44:11 +08:00
|
|
|
; Tests prologues and epilogues are not generated within EH scopes.
|
|
|
|
; They should not be treated as funclets; BBs starting with a catch instruction
|
|
|
|
; should not have a prologue, and BBs ending with a catchret/cleanupret should
|
|
|
|
; not have an epilogue. This is separate from __stack_pointer restoring
|
|
|
|
; instructions after a catch instruction.
|
|
|
|
|
|
|
|
; CHECK-LABEL: test_no_prolog_epilog_in_ehpad
|
|
|
|
; CHECK: try
|
|
|
|
; CHECK: call foo@FUNCTION
|
|
|
|
; CHECK: i32.catch
|
|
|
|
; CHECK-NOT: get_global $push{{.+}}=, __stack_pointer@GLOBAL
|
2018-08-22 05:23:07 +08:00
|
|
|
; CHECK: set_global __stack_pointer@GLOBAL
|
2018-08-22 03:44:11 +08:00
|
|
|
; CHECK: try
|
|
|
|
; CHECK: call foo@FUNCTION
|
|
|
|
; CHECK: catch_all
|
2018-08-22 04:04:42 +08:00
|
|
|
; CHECK-NOT: get_global $push{{.+}}=, __stack_pointer@GLOBAL
|
2018-08-22 05:23:07 +08:00
|
|
|
; CHECK: set_global __stack_pointer@GLOBAL
|
2018-08-22 03:44:11 +08:00
|
|
|
; CHECK: call __cxa_end_catch@FUNCTION
|
|
|
|
; CHECK-NOT: set_global __stack_pointer@GLOBAL, $pop{{.+}}
|
|
|
|
; CHECK: end_try
|
|
|
|
; CHECK-NOT: set_global __stack_pointer@GLOBAL, $pop{{.+}}
|
|
|
|
; CHECK: end_try
|
|
|
|
define void @test_no_prolog_epilog_in_ehpad() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
|
|
|
|
entry:
|
|
|
|
%stack_var = alloca i32, align 4
|
|
|
|
call void @bar(i32* %stack_var)
|
|
|
|
invoke void @foo()
|
|
|
|
to label %try.cont unwind label %catch.dispatch
|
|
|
|
|
|
|
|
catch.dispatch: ; preds = %entry
|
|
|
|
%0 = catchswitch within none [label %catch.start] unwind to caller
|
|
|
|
|
|
|
|
catch.start: ; preds = %catch.dispatch
|
|
|
|
%1 = catchpad within %0 [i8* bitcast (i8** @_ZTIi to i8*)]
|
|
|
|
%2 = call i8* @llvm.wasm.get.exception(token %1)
|
|
|
|
%3 = call i32 @llvm.wasm.get.ehselector(token %1)
|
|
|
|
%4 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*))
|
|
|
|
%matches = icmp eq i32 %3, %4
|
|
|
|
br i1 %matches, label %catch, label %rethrow
|
|
|
|
|
|
|
|
catch: ; preds = %catch.start
|
|
|
|
%5 = call i8* @__cxa_begin_catch(i8* %2) [ "funclet"(token %1) ]
|
|
|
|
%6 = bitcast i8* %5 to float*
|
|
|
|
%7 = load float, float* %6, align 4
|
|
|
|
invoke void @foo() [ "funclet"(token %1) ]
|
|
|
|
to label %invoke.cont1 unwind label %ehcleanup
|
|
|
|
|
|
|
|
invoke.cont1: ; preds = %catch
|
|
|
|
call void @__cxa_end_catch() [ "funclet"(token %1) ]
|
|
|
|
catchret from %1 to label %try.cont
|
|
|
|
|
|
|
|
rethrow: ; preds = %catch.start
|
|
|
|
call void @__cxa_rethrow() [ "funclet"(token %1) ]
|
|
|
|
unreachable
|
|
|
|
|
|
|
|
try.cont: ; preds = %entry, %invoke.cont1
|
|
|
|
ret void
|
|
|
|
|
|
|
|
ehcleanup: ; preds = %catch
|
|
|
|
%8 = cleanuppad within %1 []
|
|
|
|
call void @__cxa_end_catch() [ "funclet"(token %8) ]
|
|
|
|
cleanupret from %8 unwind to caller
|
|
|
|
}
|
|
|
|
|
2018-08-23 05:13:49 +08:00
|
|
|
; When a function does not have stack-allocated objects, it does not need to
|
|
|
|
; store SP back to __stack_pointer global at the epilog.
|
|
|
|
|
|
|
|
; CHECK-LABEL: no_sp_writeback
|
|
|
|
; CHECK: try
|
|
|
|
; CHECK: call foo@FUNCTION
|
|
|
|
; CHECK: end_try
|
|
|
|
; CHECK-NOT: set_global __stack_pointer@GLOBAL
|
|
|
|
; CHECK: return
|
|
|
|
define void @no_sp_writeback() personality i8* bitcast (i32 (...)* @__gxx_wasm_personality_v0 to i8*) {
|
|
|
|
entry:
|
|
|
|
invoke void @foo()
|
|
|
|
to label %try.cont unwind label %catch.dispatch
|
|
|
|
|
|
|
|
catch.dispatch: ; preds = %entry
|
|
|
|
%0 = catchswitch within none [label %catch.start] unwind to caller
|
|
|
|
|
|
|
|
catch.start: ; preds = %catch.dispatch
|
|
|
|
%1 = catchpad within %0 [i8* null]
|
|
|
|
%2 = call i8* @llvm.wasm.get.exception(token %1)
|
|
|
|
%3 = call i32 @llvm.wasm.get.ehselector(token %1)
|
|
|
|
%4 = call i8* @__cxa_begin_catch(i8* %2) #2 [ "funclet"(token %1) ]
|
|
|
|
call void @__cxa_end_catch() [ "funclet"(token %1) ]
|
|
|
|
catchret from %1 to label %try.cont
|
|
|
|
|
|
|
|
try.cont: ; preds = %entry, %catch.start
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
declare void @foo()
|
2018-08-22 03:44:11 +08:00
|
|
|
declare void @bar(i32*)
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
declare i32 @__gxx_wasm_personality_v0(...)
|
|
|
|
declare i8* @llvm.wasm.get.exception(token)
|
|
|
|
declare i32 @llvm.wasm.get.ehselector(token)
|
|
|
|
declare i32 @llvm.eh.typeid.for(i8*)
|
|
|
|
declare i8* @__cxa_begin_catch(i8*)
|
|
|
|
declare void @__cxa_end_catch()
|
|
|
|
declare void @__cxa_rethrow()
|
|
|
|
declare void @__clang_call_terminate(i8*)
|
2018-06-25 09:07:11 +08:00
|
|
|
declare void @_ZSt9terminatev()
|
[WebAssembly] Support instruction selection for catching exceptions
Summary:
This lowers exception catching-related instructions:
1. Lowers `wasm.catch` intrinsic to `catch` instruction
2. Removes `catchpad` and `cleanuppad` instructions; they are not
necessary after isel phase. (`MachineBasicBlock::isEHFuncletEntry()` or
`MachineBasicBlock::isEHPad()` can be used instead.)
3. Lowers `catchret` and `cleanupret` instructions to pseudo `catchret`
and `cleanupret` instructions in isel, which will be replaced with other
instructions in `WebAssemblyExceptionPrepare` pass.
4. Adds 'WebAssemblyExceptionPrepare` pass, which is for running various
transformation for EH. Currently this pass only replaces `catchret` and
`cleanupret` instructions into appropriate wasm instructions to make
this patch successfully run until the end.
Currently this does not handle lowering of intrinsics related to LSDA
info generation (`wasm.landingpad.index` and `wasm.lsda`), because they
cannot be tested without implementing `EHStreamer`'s wasm-specific
handlers. They are marked as TODO, which is needed to make isel pass.
Also this does not generate `try` and `end_try` markers yet, which will
be handled in later patches.
This patch is based on the first wasm EH proposal.
(https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md)
Reviewers: dschuff, majnemer
Subscribers: jfb, sbc100, jgravelle-google, sunfish, llvm-commits
Differential Revision: https://reviews.llvm.org/D44090
llvm-svn: 333705
2018-06-01 06:25:54 +08:00
|
|
|
declare %struct.Cleanup* @_ZN7CleanupD1Ev(%struct.Cleanup* returned)
|