[PATCH] D65358: [WebAssembly] allow EM_ASM to be used with setjmp
Guanzhong Chen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 26 16:42:21 PDT 2019
quantum created this revision.
quantum added reviewers: tlively, aheejin, kripken.
Herald added subscribers: llvm-commits, sunfish, hiraditya, jgravelle-google, sbc100, dschuff.
Herald added a project: LLVM.
quantum edited the summary of this revision.
Avoid wrapping `emscripten_asm_*` calls in `__invoke_*` wrappers, which breaks
`EM_ASM`. See https://github.com/emscripten-core/emscripten/issues/8894.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D65358
Files:
llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
Index: llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
+++ llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll
@@ -203,6 +203,24 @@
ret void
}
+; Test EM_ASM handling
+ at em_asm_str = constant [32 x i8] c"{ console.log(\22hello world\22); }\00", align 1
+
+define hidden i32 @em_asm() {
+; CHECK-LABEL: @em_asm
+entry:
+ %env = alloca [1 x %struct.__jmp_buf_tag], align 16
+ %arraydecay = getelementptr inbounds [1 x %struct.__jmp_buf_tag], [1 x %struct.__jmp_buf_tag]* %env, i32 0, i32 0
+ %call = call i32 @setjmp(%struct.__jmp_buf_tag* %arraydecay)
+
+ %.compoundliteral = alloca [1 x i8], align 1
+ %arraydecay1 = getelementptr inbounds [1 x i8], [1 x i8]* %.compoundliteral, i32 0, i32 0
+; CHECK: call i32 (i8*, i8*, ...) @emscripten_asm_const_int
+; CHECK-NOT: @"__invoke_i32_i8*_i8*_..."
+ %call2 = call i32 (i8*, i8*, ...) @emscripten_asm_const_int(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @em_asm_str, i32 0, i32 0), i8* %arraydecay1)
+ ret i32 %call2
+}
+
declare void @foo()
; Function Attrs: returns_twice
declare i32 @setjmp(%struct.__jmp_buf_tag*) #0
@@ -213,6 +231,7 @@
declare void @__cxa_end_catch()
declare i8* @malloc(i32)
declare void @free(i8*)
+declare i32 @emscripten_asm_const_int(i8*, i8*, ...)
; JS glue functions and invoke wrappers declaration
; CHECK-DAG: declare i32 @getTempRet0()
Index: llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -520,6 +520,20 @@
Callee == GetTempRet0Func || Callee == SetTempRet0Func)
return false;
+ // EM_ASM related functions
+ Function *EmAsmConstIntF = M.getFunction("emscripten_asm_const_int");
+ Function *EmAsmConstDoubleF = M.getFunction("emscripten_asm_const_double");
+ Function *EmAsmConstIntSyncMainF =
+ M.getFunction("emscripten_asm_const_int_sync_on_main_thread");
+ Function *EmAsmConstDoubleSyncMainF =
+ M.getFunction("emscripten_asm_const_double_sync_on_main_thread");
+ Function *EmAsmConstAsyncMainF =
+ M.getFunction("emscripten_asm_const_async_on_main_thread");
+ if (Callee == EmAsmConstIntF || Callee == EmAsmConstDoubleF ||
+ Callee == EmAsmConstIntSyncMainF || Callee == EmAsmConstDoubleSyncMainF ||
+ Callee == EmAsmConstAsyncMainF)
+ return false;
+
// Otherwise we don't know
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65358.212024.patch
Type: text/x-patch
Size: 2604 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190726/73c62459/attachment.bin>
More information about the llvm-commits
mailing list