diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp +++ b/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; } diff --git a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll --- a/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll +++ b/llvm/test/CodeGen/WebAssembly/lower-em-sjlj.ll @@ -203,6 +203,24 @@ ret void } +; Test EM_ASM handling +@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()