Skip to content

Commit

Permalink
[wasm] Switch to the LLVM wasm backend. (mono/mono#14734)
Browse files Browse the repository at this point in the history
* [wasm] Switch to the llvm wasm backend.

* [wasm] Packager changes for the wasm backend.

* -s EMULATED_FUNCTION_POINTERS=1 no longer needed.
* Run wasm-strip on the final binary.
* Run opt during AOT.
* Disable the dynamic build for now, it doesn't seem to work with the wasm backend.

* [wasm] Use STACK_MAX instead of STACK_BASE for the bottom limit of the stack.

* [aot] Handle llvmopts= in llvmonly mode as well.

* [wasm] Disable an assertion which is no longer true with the wasm backend.

* [wasm] Disable computed gotos in the interpreter, the wasm backend doesn't support it.

Fix llvm target layout so its compatible with clang compiled code.

* [wasm] Pass llvm-path to the cross compiler.

* [wasm] Fix some problems with the dynamic build, still doesn't work. Fix packaging.

* [wasm] Pass -s DISABLE_EXCEPTION_CATCHING=0 to the runtime build, otherwise catch clauses are not generated in llvm-runtime.cpp.

* [aot] Allow llvmopts= argument multiple times.

* Bump emscripten version to 1.38.34.

* [wasm] Add emscripten-core/emscripten#8457 as a patch.

* [wasm] Compile the aot .bc files to .o in a separate step using emcc, this will help with incremental compilation later.

* [wasm] Source emsdk_set_env.sh instead of emsdk_env.sh the latter calls emsdk construct_env to construct emsdk_set_env.sh which is racy.


Commit migrated from mono/mono@1653239
  • Loading branch information
vargaz authored Jun 8, 2019
1 parent 3e8b9bc commit 71e0b86
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
15 changes: 11 additions & 4 deletions src/mono/mono/mini/aot-compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -8071,7 +8071,13 @@ mono_aot_parse_options (const char *aot_options, MonoAotOptions *opts)
} else if (!strcmp (arg, "verbose")) {
opts->verbose = TRUE;
} else if (str_begins_with (arg, "llvmopts=")){
opts->llvm_opts = g_strdup (arg + strlen ("llvmopts="));
if (opts->llvm_opts) {
char *s = g_strdup_printf ("%s %s", opts->llvm_opts, arg + strlen ("llvmopts="));
g_free (opts->llvm_opts);
opts->llvm_opts = s;
} else {
opts->llvm_opts = g_strdup (arg + strlen ("llvmopts="));
}
} else if (str_begins_with (arg, "llvmllc=")){
opts->llvm_llc = g_strdup (arg + strlen ("llvmllc="));
} else if (!strcmp (arg, "deterministic")) {
Expand Down Expand Up @@ -9666,9 +9672,10 @@ emit_llvm_file (MonoAotCompile *acfg)
#else
opts = g_strdup ("-targetlibinfo -no-aa -basicaa -notti -instcombine -simplifycfg -inline-cost -inline -sroa -domtree -early-cse -lazy-value-info -correlated-propagation -simplifycfg -instcombine -simplifycfg -reassociate -domtree -loops -loop-simplify -lcssa -loop-rotate -licm -lcssa -loop-unswitch -instcombine -scalar-evolution -loop-simplify -lcssa -indvars -loop-idiom -loop-deletion -loop-unroll -memdep -gvn -memdep -memcpyopt -sccp -instcombine -lazy-value-info -correlated-propagation -domtree -memdep -adce -simplifycfg -instcombine -strip-dead-prototypes -domtree -verify -place-safepoints -spp-all-backedges");
#endif
if (acfg->aot_opts.llvm_opts) {
opts = g_strdup_printf ("%s %s", opts, acfg->aot_opts.llvm_opts);
}
}

if (acfg->aot_opts.llvm_opts) {
opts = g_strdup_printf ("%s %s", opts, acfg->aot_opts.llvm_opts);
}

command = g_strdup_printf ("\"%sopt\" -f %s -o \"%s\" \"%s\"", acfg->aot_opts.llvm_path, opts, optbc, tempbc);
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/aot-runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -2797,7 +2797,7 @@ compute_llvm_code_range (MonoAotModule *amodule, guint8 **code_start, guint8 **c
addr = get_method (i);
gsize val = (gsize)addr;
if (val) {
g_assert (val > prev);
//g_assert (val > prev);
if (val < min)
min = val;
else if (val > max)
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/interp/interp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2802,7 +2802,7 @@ static int opcode_counts[512];
#define DUMP_INSTR()
#endif

#ifdef __GNUC__
#if defined(__GNUC__) && !defined(TARGET_WASM)
#define USE_COMPUTED_GOTO 1
#endif
#if USE_COMPUTED_GOTO
Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/mini/mini-wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ typedef struct {
#define MONO_ARCH_HAS_REGISTER_ICALL 1
#define MONO_ARCH_HAVE_PATCH_CODE_NEW 1
#define MONO_ARCH_HAVE_SDB_TRAMPOLINES 1
#define MONO_ARCH_LLVM_TARGET_LAYOUT "e-p:32:32-i64:64-v128:32:128-n32-S128"
#define MONO_ARCH_LLVM_TARGET_TRIPLE "wasm32-unknown-unknown-wasm"
#define MONO_ARCH_LLVM_TARGET_LAYOUT "e-m:e-p:32:32-i64:64-n32:64-S128"
#define MONO_ARCH_LLVM_TARGET_TRIPLE "wasm32-unknown-emscripten"

void mono_wasm_debugger_init (void);

Expand Down
4 changes: 2 additions & 2 deletions src/mono/mono/utils/mono-threads-wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ EMSCRIPTEN_KEEPALIVE
static int
wasm_get_stack_base (void)
{
// Return the bottom limit of the stack
return EM_ASM_INT ({
return STACK_BASE;
return STACK_MAX;
});
}

Expand All @@ -32,7 +33,6 @@ wasm_get_stack_size (void)
});
}


int
mono_thread_info_get_system_max_stack_size (void)
{
Expand Down

0 comments on commit 71e0b86

Please sign in to comment.