mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-14 07:31:53 +00:00
Add asm.js-style setjmp/longjmp handling for wasm
Summary: This patch adds asm.js-style setjmp/longjmp handling support for WebAssembly. It also uses JavaScript's try and catch mechanism. Reviewers: jpp, dschuff Subscribers: jfb, dschuff Differential Revision: https://reviews.llvm.org/D23928 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280302 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
27e101d577
commit
01601df1ce
@ -29,5 +29,5 @@ has_disassembler = 1
|
||||
type = Library
|
||||
name = WebAssemblyCodeGen
|
||||
parent = WebAssembly
|
||||
required_libraries = Analysis AsmPrinter CodeGen Core MC Scalar SelectionDAG Support Target WebAssemblyAsmPrinter WebAssemblyDesc WebAssemblyInfo
|
||||
required_libraries = Analysis AsmPrinter CodeGen Core MC Scalar SelectionDAG Support Target TransformUtils WebAssemblyAsmPrinter WebAssemblyDesc WebAssemblyInfo
|
||||
add_to_library_groups = WebAssembly
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -165,7 +165,14 @@ void WebAssemblyPassConfig::addIRPasses() {
|
||||
if (getOptLevel() != CodeGenOpt::None)
|
||||
addPass(createWebAssemblyOptimizeReturned());
|
||||
|
||||
// Handle exceptions.
|
||||
// If exception handling is not enabled, we lower invokes into calls and
|
||||
// simplify CFG to delete unreachable landingpad blocks.
|
||||
if (!EnableEmException) {
|
||||
addPass(createLowerInvokePass());
|
||||
addPass(createCFGSimplificationPass());
|
||||
}
|
||||
|
||||
// Handle exceptions and setjmp/longjmp if enabled.
|
||||
if (EnableEmException || EnableEmSjLj)
|
||||
addPass(createWebAssemblyLowerEmscriptenEHSjLj(EnableEmException,
|
||||
EnableEmSjLj));
|
||||
|
61
test/CodeGen/WebAssembly/lower-em-ehsjlj-options.ll
Normal file
61
test/CodeGen/WebAssembly/lower-em-ehsjlj-options.ll
Normal file
@ -0,0 +1,61 @@
|
||||
; RUN: llc < %s -enable-emscripten-cxx-exceptions | FileCheck %s --check-prefix=EH
|
||||
; RUN: llc < %s -enable-emscripten-sjlj | FileCheck %s --check-prefix=SJLJ
|
||||
; RUN: llc < %s | FileCheck %s --check-prefix=NONE
|
||||
|
||||
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
|
||||
target triple = "wasm32-unknown-unknown"
|
||||
|
||||
%struct.__jmp_buf_tag = type { [6 x i32], i32, [32 x i32] }
|
||||
|
||||
define hidden void @exception() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
|
||||
; EH-LABEL: type exception,@function
|
||||
; NONE-LABEL: type exception,@function
|
||||
entry:
|
||||
invoke void @foo()
|
||||
to label %try.cont unwind label %lpad
|
||||
; EH: call __invoke_void@FUNCTION
|
||||
; NONE: call foo@FUNCTION
|
||||
|
||||
lpad: ; preds = %entry
|
||||
%0 = landingpad { i8*, i32 }
|
||||
catch i8* null
|
||||
%1 = extractvalue { i8*, i32 } %0, 0
|
||||
%2 = extractvalue { i8*, i32 } %0, 1
|
||||
%3 = call i8* @__cxa_begin_catch(i8* %1) #2
|
||||
call void @__cxa_end_catch()
|
||||
br label %try.cont
|
||||
|
||||
try.cont: ; preds = %entry, %lpad
|
||||
ret void
|
||||
}
|
||||
|
||||
define hidden void @setjmp_longjmp() {
|
||||
; SJLJ-LABEL: type setjmp_longjmp,@function
|
||||
; NONE-LABEL: type setjmp_longjmp,@function
|
||||
entry:
|
||||
%buf = alloca [1 x %struct.__jmp_buf_tag], align 16
|
||||
%arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
|
||||
%call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay) #0
|
||||
%arraydecay1 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
|
||||
call void @longjmp(%struct.__jmp_buf_tag* %arraydecay1, i32 1) #1
|
||||
unreachable
|
||||
; SJLJ: i32.call ${{[a-zA-Z0-9]+}}=, saveSetjmp@FUNCTION
|
||||
; SJLJ: i32.call ${{[a-zA-Z0-9]+}}=, testSetjmp@FUNCTION
|
||||
; NONE: i32.call ${{[a-zA-Z0-9]+}}=, setjmp@FUNCTION
|
||||
; NONE: call longjmp@FUNCTION
|
||||
}
|
||||
|
||||
declare void @foo()
|
||||
declare i32 @__gxx_personality_v0(...)
|
||||
declare i8* @__cxa_begin_catch(i8*)
|
||||
declare void @__cxa_end_catch()
|
||||
; Function Attrs: returns_twice
|
||||
declare i32 @setjmp(%struct.__jmp_buf_tag*) #0
|
||||
; Function Attrs: noreturn
|
||||
declare void @longjmp(%struct.__jmp_buf_tag*, i32) #1
|
||||
declare i8* @malloc(i32)
|
||||
declare void @free(i8*)
|
||||
|
||||
attributes #0 = { returns_twice }
|
||||
attributes #1 = { noreturn }
|
||||
attributes #2 = { nounwind }
|
@ -1,5 +1,8 @@
|
||||
; RUN: opt < %s -wasm-lower-em-ehsjlj -emscripten-cxx-exceptions-whitelist=do_catch -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
|
||||
target triple = "wasm32-unknown-unknown"
|
||||
|
||||
define void @dont_catch() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
|
||||
; CHECK-LABEL: @dont_catch(
|
||||
entry:
|
||||
@ -34,7 +37,7 @@ entry:
|
||||
invoke void @foo()
|
||||
to label %invoke.cont unwind label %lpad
|
||||
; CHECK: entry:
|
||||
; CHECK-NEXT: store i1 false, i1*
|
||||
; CHECK-NEXT: store i32 0, i32*
|
||||
; CHECK-NEXT: call void @__invoke_void(void ()* @foo)
|
||||
|
||||
invoke.cont: ; preds = %entry
|
||||
|
@ -1,10 +1,13 @@
|
||||
; RUN: opt < %s -wasm-lower-em-ehsjlj -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
|
||||
target triple = "wasm32-unknown-unknown"
|
||||
|
||||
@_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-DAG: @[[__THREW__:__THREW__.*]] = global i32 0
|
||||
; CHECK-DAG: @[[THREWVALUE:__threwValue.*]] = global i32 0
|
||||
; CHECK-DAG: @[[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*) {
|
||||
@ -13,11 +16,12 @@ entry:
|
||||
invoke void @foo(i32 3)
|
||||
to label %invoke.cont unwind label %lpad
|
||||
; CHECK: entry:
|
||||
; CHECK-NEXT: store i1 false, i1* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i32 0, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: call void @__invoke_void_i32(void (i32)* @foo, i32 3)
|
||||
; CHECK-NEXT: %[[__THREW__VAL:.*]] = load i1, i1* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i1 false, i1* @[[__THREW__]]
|
||||
; CHECK-NEXT: br i1 %[[__THREW__VAL]], label %lpad, label %invoke.cont
|
||||
; CHECK-NEXT: %[[__THREW__VAL:.*]] = load i32, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i32 0, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: %cmp = icmp eq i32 %[[__THREW__VAL]], 1
|
||||
; CHECK-NEXT: br i1 %cmp, label %lpad, label %invoke.cont
|
||||
|
||||
invoke.cont: ; preds = %entry
|
||||
br label %try.cont
|
||||
@ -68,11 +72,12 @@ entry:
|
||||
invoke void @foo(i32 3)
|
||||
to label %invoke.cont unwind label %lpad
|
||||
; CHECK: entry:
|
||||
; CHECK-NEXT: store i1 false, i1* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i32 0, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: call void @__invoke_void_i32(void (i32)* @foo, i32 3)
|
||||
; CHECK-NEXT: %[[__THREW__VAL:.*]] = load i1, i1* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i1 false, i1* @[[__THREW__]]
|
||||
; CHECK-NEXT: br i1 %[[__THREW__VAL]], label %lpad, label %invoke.cont
|
||||
; CHECK-NEXT: %[[__THREW__VAL:.*]] = load i32, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i32 0, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: %cmp = icmp eq i32 %[[__THREW__VAL]], 1
|
||||
; CHECK-NEXT: br i1 %cmp, label %lpad, label %invoke.cont
|
||||
|
||||
invoke.cont: ; preds = %entry
|
||||
ret void
|
||||
@ -118,7 +123,7 @@ entry:
|
||||
%0 = invoke noalias i8* @bar(i8 signext 1, i8 zeroext 2)
|
||||
to label %invoke.cont unwind label %lpad
|
||||
; CHECK: entry:
|
||||
; CHECK-NEXT: store i1 false, i1* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i32 0, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: %0 = call noalias i8* @"__invoke_i8*_i8_i8"(i8* (i8, i8)* @bar, i8 signext 1, i8 zeroext 2)
|
||||
|
||||
invoke.cont: ; preds = %entry
|
||||
@ -162,19 +167,19 @@ declare i8* @__cxa_begin_catch(i8*)
|
||||
declare void @__cxa_end_catch()
|
||||
declare void @__cxa_call_unexpected(i8*)
|
||||
|
||||
; JS glue functions and invoke wrappers registration
|
||||
; CHECK: declare void @__resumeException(i8*)
|
||||
; CHECK: declare void @__invoke_void_i32(void (i32)*, i32)
|
||||
; CHECK: declare i8* @__cxa_find_matching_catch_4(i8*, i8*)
|
||||
; JS glue functions and invoke wrappers declaration
|
||||
; CHECK-DAG: declare void @__resumeException(i8*)
|
||||
; CHECK-DAG: declare void @__invoke_void_i32(void (i32)*, i32)
|
||||
; CHECK-DAG: declare i8* @__cxa_find_matching_catch_4(i8*, i8*)
|
||||
|
||||
; setThrew function creation
|
||||
; CHECK-LABEL: define void @setThrew(i1 %threw, i32 %value) {
|
||||
; CHECK-LABEL: define void @setThrew(i32 %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 i32, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: %cmp = icmp eq i32 %[[__THREW__]].val, 0
|
||||
; 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 %threw, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i32 %value, i32* @[[THREWVALUE]]
|
||||
; CHECK-NEXT: br label %if.end
|
||||
; CHECK: if.end:
|
||||
|
213
test/CodeGen/WebAssembly/lower-em-sjlj.ll
Normal file
213
test/CodeGen/WebAssembly/lower-em-sjlj.ll
Normal file
@ -0,0 +1,213 @@
|
||||
; RUN: opt < %s -wasm-lower-em-ehsjlj -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
|
||||
target triple = "wasm32-unknown-unknown"
|
||||
|
||||
%struct.__jmp_buf_tag = type { [6 x i32], i32, [32 x i32] }
|
||||
|
||||
@global_var = hidden global i32 0, align 4
|
||||
; CHECK-DAG: @[[__THREW__:__THREW__.*]] = global i32 0
|
||||
; CHECK-DAG: @[[THREWVALUE:__threwValue.*]] = global i32 0
|
||||
; CHECK-DAG: @[[TEMPRET0:__tempRet0.*]] = global i32 0
|
||||
|
||||
; Test a simple setjmp - longjmp sequence
|
||||
define hidden void @setjmp_longjmp() {
|
||||
; CHECK-LABEL: @setjmp_longjmp
|
||||
entry:
|
||||
%buf = alloca [1 x %struct.__jmp_buf_tag], align 16
|
||||
%arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
|
||||
%call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay) #0
|
||||
%arraydecay1 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
|
||||
call void @longjmp(%struct.__jmp_buf_tag* %arraydecay1, i32 1) #1
|
||||
unreachable
|
||||
; CHECK: entry:
|
||||
; CHECK-NEXT: %[[MALLOCCALL:.*]] = tail call i8* @malloc(i32 40)
|
||||
; CHECK-NEXT: %[[SETJMP_TABLE:.*]] = bitcast i8* %[[MALLOCCALL]] to i32*
|
||||
; CHECK-NEXT: store i32 0, i32* %[[SETJMP_TABLE]]
|
||||
; CHECK-NEXT: %[[SETJMP_TABLE_SIZE:.*]] = add i32 4, 0
|
||||
; CHECK-NEXT: %[[BUF:.*]] = alloca [1 x %struct.__jmp_buf_tag]
|
||||
; CHECK-NEXT: %[[ARRAYDECAY:.*]] = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %[[BUF]], i32 0, i32 0
|
||||
; CHECK-NEXT: %[[SETJMP_TABLE1:.*]] = call i32* @saveSetjmp(%struct.__jmp_buf_tag* %[[ARRAYDECAY]], i32 1, i32* %[[SETJMP_TABLE]], i32 %[[SETJMP_TABLE_SIZE]])
|
||||
; CHECK-NEXT: %[[SETJMP_TABLE_SIZE1:.*]] = load i32, i32* @[[TEMPRET0]]
|
||||
; CHECK-NEXT: br label %entry.split
|
||||
|
||||
; CHECK: entry.split:
|
||||
; CHECK-NEXT: phi i32 [ 0, %entry ], [ %[[LONGJMP_RESULT:.*]], %if.end ]
|
||||
; CHECK-NEXT: %[[ARRAYDECAY1:.*]] = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %[[BUF]], i32 0, i32 0
|
||||
; CHECK-NEXT: store i32 0, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: call void @"__invoke_void_%struct.__jmp_buf_tag*_i32"(void (%struct.__jmp_buf_tag*, i32)* @emscripten_longjmp_jmpbuf, %struct.__jmp_buf_tag* %[[ARRAYDECAY1]], i32 1)
|
||||
; CHECK-NEXT: %[[__THREW__VAL:.*]] = load i32, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i32 0, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: %[[CMP0:.*]] = icmp ne i32 %__THREW__.val, 0
|
||||
; CHECK-NEXT: %[[THREWVALUE_VAL:.*]] = load i32, i32* @[[THREWVALUE]]
|
||||
; CHECK-NEXT: %[[CMP1:.*]] = icmp ne i32 %[[THREWVALUE_VAL]], 0
|
||||
; CHECK-NEXT: %[[CMP:.*]] = and i1 %[[CMP0]], %[[CMP1]]
|
||||
; CHECK-NEXT: br i1 %[[CMP]], label %if.then1, label %if.else1
|
||||
|
||||
; CHECK: entry.split.split:
|
||||
; CHECK-NEXT: unreachable
|
||||
|
||||
; CHECK: if.then1:
|
||||
; CHECK-NEXT: %[[__THREW__VAL_I32P:.*]] = inttoptr i32 %[[__THREW__VAL]] to i32*
|
||||
; CHECK-NEXT: %[[__THREW__VAL_I32P_LOADED:.*]] = load i32, i32* %[[__THREW__VAL_I32P]]
|
||||
; CHECK-NEXT: %[[LABEL:.*]] = call i32 @testSetjmp(i32 %[[__THREW__VAL_I32P_LOADED]], i32* %[[SETJMP_TABLE1]], i32 %[[SETJMP_TABLE_SIZE1]])
|
||||
; CHECK-NEXT: %[[CMP:.*]] = icmp eq i32 %[[LABEL]], 0
|
||||
; CHECK-NEXT: br i1 %[[CMP]], label %if.then2, label %if.end2
|
||||
|
||||
; CHECK: if.else1:
|
||||
; CHECK-NEXT: br label %if.end
|
||||
|
||||
; CHECK: if.end:
|
||||
; CHECK-NEXT: %[[LABEL_PHI:.*]] = phi i32 [ %[[LABEL:.*]], %if.end2 ], [ -1, %if.else1 ]
|
||||
; CHECK-NEXT: %[[LONGJMP_RESULT]] = load i32, i32* @[[TEMPRET0]]
|
||||
; CHECK-NEXT: switch i32 %[[LABEL_PHI]], label %entry.split.split [
|
||||
; CHECK-NEXT: i32 1, label %entry.split
|
||||
; CHECK-NEXT: ]
|
||||
|
||||
; CHECK: if.then2:
|
||||
; CHECK-NEXT: call void @emscripten_longjmp(i32 %[[__THREW__VAL]], i32 %[[THREWVALUE_VAL]])
|
||||
; CHECK-NEXT: unreachable
|
||||
|
||||
; CHECK: if.end2:
|
||||
; CHECK-NEXT: store i32 %[[THREWVALUE_VAL]], i32* @[[TEMPRET0]]
|
||||
; CHECK-NEXT: br label %if.end
|
||||
}
|
||||
|
||||
; Test a case of a function call (which is not longjmp) after a setjmp
|
||||
define hidden void @setjmp_other() {
|
||||
; CHECK-LABEL: @setjmp_other
|
||||
entry:
|
||||
%buf = alloca [1 x %struct.__jmp_buf_tag], align 16
|
||||
%arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
|
||||
%call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay) #0
|
||||
call void @foo()
|
||||
ret void
|
||||
; CHECK: entry:
|
||||
; CHECK: %[[SETJMP_TABLE:.*]] = call i32* @saveSetjmp(
|
||||
|
||||
; CHECK: entry.split:
|
||||
; CHECK: call void @__invoke_void(void ()* @foo)
|
||||
|
||||
; CHECK: entry.split.split:
|
||||
; CHECK-NEXT: %[[BUF:.*]] = bitcast i32* %[[SETJMP_TABLE]] to i8*
|
||||
; CHECK-NEXT: tail call void @free(i8* %[[BUF]])
|
||||
; CHECK-NEXT: ret void
|
||||
}
|
||||
|
||||
; Test a case when a function call is within try-catch, after a setjmp
|
||||
define hidden void @exception_and_longjmp() #3 personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
|
||||
; CHECK-LABEL: @exception_and_longjmp
|
||||
entry:
|
||||
%buf = alloca [1 x %struct.__jmp_buf_tag], align 16
|
||||
%arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
|
||||
%call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay) #0
|
||||
invoke void @foo()
|
||||
to label %try.cont unwind label %lpad
|
||||
|
||||
; CHECK: entry.split:
|
||||
; CHECK: store i32 0, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: call void @__invoke_void(void ()* @foo)
|
||||
; CHECK-NEXT: %[[__THREW__VAL:.*]] = load i32, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: store i32 0, i32* @[[__THREW__]]
|
||||
; CHECK-NEXT: %[[CMP0:.*]] = icmp ne i32 %[[__THREW__VAL]], 0
|
||||
; CHECK-NEXT: %[[THREWVALUE_VAL:.*]] = load i32, i32* @[[THREWVALUE]]
|
||||
; CHECK-NEXT: %[[CMP1:.*]] = icmp ne i32 %[[THREWVALUE_VAL]], 0
|
||||
; CHECK-NEXT: %[[CMP:.*]] = and i1 %[[CMP0]], %[[CMP1]]
|
||||
; CHECK-NEXT: br i1 %[[CMP]], label %if.then1, label %if.else1
|
||||
|
||||
; CHECK: entry.split.split:
|
||||
; CHECK-NEXT: %[[CMP:.*]] = icmp eq i32 %[[__THREW__VAL]], 1
|
||||
; CHECK-NEXT: br i1 %[[CMP]], label %lpad, label %try.cont
|
||||
|
||||
lpad: ; preds = %entry
|
||||
%0 = landingpad { i8*, i32 }
|
||||
catch i8* null
|
||||
%1 = extractvalue { i8*, i32 } %0, 0
|
||||
%2 = extractvalue { i8*, i32 } %0, 1
|
||||
%3 = call i8* @__cxa_begin_catch(i8* %1) #2
|
||||
call void @__cxa_end_catch()
|
||||
br label %try.cont
|
||||
|
||||
try.cont: ; preds = %entry, %lpad
|
||||
ret void
|
||||
}
|
||||
|
||||
; Test SSA validity
|
||||
define hidden void @ssa(i32 %n) {
|
||||
; CHECK-LABEL: @ssa
|
||||
entry:
|
||||
%buf = alloca [1 x %struct.__jmp_buf_tag], align 16
|
||||
%cmp = icmp sgt i32 %n, 5
|
||||
br i1 %cmp, label %if.then, label %if.end
|
||||
; CHECK: entry:
|
||||
; CHECK: %[[SETJMP_TABLE0:.*]] = bitcast i8*
|
||||
; CHECK: %[[SETJMP_TABLE_SIZE0:.*]] = add i32 4, 0
|
||||
|
||||
if.then: ; preds = %entry
|
||||
%0 = load i32, i32* @global_var, align 4
|
||||
%arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
|
||||
%call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay) #0
|
||||
store i32 %0, i32* @global_var, align 4
|
||||
br label %if.end
|
||||
; CHECK: if.then:
|
||||
; CHECK: %[[VAR0:.*]] = load i32, i32* @global_var, align 4
|
||||
; CHECK: %[[SETJMP_TABLE1:.*]] = call i32* @saveSetjmp(
|
||||
; CHECK-NEXT: %[[SETJMP_TABLE_SIZE1:.*]] = load i32, i32* @[[TEMPRET0]]
|
||||
|
||||
; CHECK: if.then.split:
|
||||
; CHECK: %[[VAR1:.*]] = phi i32 [ %[[VAR0]], %if.then ], [ %[[VAR2:.*]], %if.end3 ]
|
||||
; CHECK: %[[SETJMP_TABLE_SIZE2:.*]] = phi i32 [ %[[SETJMP_TABLE_SIZE1]], %if.then ], [ %[[SETJMP_TABLE_SIZE3:.*]], %if.end3 ]
|
||||
; CHECK: %[[SETJMP_TABLE2:.*]] = phi i32* [ %[[SETJMP_TABLE1]], %if.then ], [ %[[SETJMP_TABLE3:.*]], %if.end3 ]
|
||||
; CHECK: store i32 %[[VAR1]], i32* @global_var, align 4
|
||||
|
||||
if.end: ; preds = %if.then, %entry
|
||||
%arraydecay1 = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
|
||||
call void @longjmp(%struct.__jmp_buf_tag* %arraydecay1, i32 5) #1
|
||||
unreachable
|
||||
; CHECK: if.end:
|
||||
; CHECK: %[[VAR2]] = phi i32 [ %[[VAR1]], %if.then.split ], [ undef, %entry ]
|
||||
; CHECK: %[[SETJMP_TABLE_SIZE3]] = phi i32 [ %[[SETJMP_TABLE_SIZE2]], %if.then.split ], [ %[[SETJMP_TABLE_SIZE0]], %entry ]
|
||||
; CHECK: %[[SETJMP_TABLE3]] = phi i32* [ %[[SETJMP_TABLE2]], %if.then.split ], [ %[[SETJMP_TABLE0]], %entry ]
|
||||
}
|
||||
|
||||
; Test a case when a function only calls other functions that are neither setjmp nor longjmp
|
||||
define hidden void @only_other_func() {
|
||||
entry:
|
||||
call void @foo()
|
||||
ret void
|
||||
; CHECK: call void @foo()
|
||||
}
|
||||
|
||||
; Test a case when a function only calls longjmp and not setjmp
|
||||
define hidden void @only_longjmp() {
|
||||
entry:
|
||||
%buf = alloca [1 x %struct.__jmp_buf_tag], align 16
|
||||
%arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %buf, i32 0, i32 0
|
||||
call void @longjmp(%struct.__jmp_buf_tag* %arraydecay, i32 5) #1
|
||||
unreachable
|
||||
; CHECK: %[[ARRAYDECAY:.*]] = getelementptr inbounds
|
||||
; CHECK-NEXT: call void @emscripten_longjmp_jmpbuf(%struct.__jmp_buf_tag* %[[ARRAYDECAY]], i32 5) #1
|
||||
}
|
||||
|
||||
declare void @foo()
|
||||
; Function Attrs: returns_twice
|
||||
declare i32 @setjmp(%struct.__jmp_buf_tag*) #0
|
||||
; Function Attrs: noreturn
|
||||
declare void @longjmp(%struct.__jmp_buf_tag*, i32) #1
|
||||
declare i32 @__gxx_personality_v0(...)
|
||||
declare i8* @__cxa_begin_catch(i8*)
|
||||
declare void @__cxa_end_catch()
|
||||
declare i8* @malloc(i32)
|
||||
declare void @free(i8*)
|
||||
|
||||
; JS glue functions and invoke wrappers declaration
|
||||
; CHECK-DAG: declare i32* @saveSetjmp(%struct.__jmp_buf_tag*, i32, i32*, i32)
|
||||
; CHECK-DAG: declare i32 @testSetjmp(i32, i32*, i32)
|
||||
; CHECK-DAG: declare void @emscripten_longjmp_jmpbuf(%struct.__jmp_buf_tag*, i32)
|
||||
; CHECK-DAG: declare void @emscripten_longjmp(i32, i32)
|
||||
; CHECK-DAG: declare void @__invoke_void(void ()*)
|
||||
; CHECK-DAG: declare void @"__invoke_void_%struct.__jmp_buf_tag*_i32"(void (%struct.__jmp_buf_tag*, i32)*, %struct.__jmp_buf_tag*, i32)
|
||||
|
||||
attributes #0 = { returns_twice }
|
||||
attributes #1 = { noreturn }
|
||||
attributes #2 = { nounwind }
|
Loading…
Reference in New Issue
Block a user