From f759a1f96084462fdd12f0b937e04ae39f74e015 Mon Sep 17 00:00:00 2001 From: YAMAMOTO Takashi Date: Wed, 17 May 2023 10:56:35 +0900 Subject: [PATCH] A few changes related to WAMRC_LLC_COMPILER (#2218) Print `target triple` for wamrc and set target triple for the LLVM module. And update document. --- core/iwasm/compilation/aot_llvm.c | 3 +++ doc/build_wasm_app.md | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index dc3fe7f5..7a2f89b0 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -2007,6 +2007,7 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) os_printf("Create AoT compiler with:\n"); os_printf(" target: %s\n", comp_ctx->target_arch); os_printf(" target cpu: %s\n", cpu); + os_printf(" target triple: %s\n", triple_norm); os_printf(" cpu features: %s\n", features); os_printf(" opt level: %d\n", opt_level); os_printf(" size level: %d\n", size_level); @@ -2025,6 +2026,8 @@ aot_create_comp_context(AOTCompData *comp_data, aot_comp_option_t option) break; } + LLVMSetTarget(comp_ctx->module, triple_norm); + if (!LLVMTargetHasTargetMachine(target)) { snprintf(buf, sizeof(buf), "no target machine for this target (%s).", triple_norm); diff --git a/doc/build_wasm_app.md b/doc/build_wasm_app.md index 40f1b89d..4475824d 100644 --- a/doc/build_wasm_app.md +++ b/doc/build_wasm_app.md @@ -394,7 +394,7 @@ Examples: wamrc -o test.aot test.wasm ### Usage example ``` bash -WAMRC_LLC_COMPILER= ./wamrc -o test.aot test.wasm +WAMRC_LLC_COMPILER=/usr/local/opt/llvm@14/bin/clang WAMRC_LLC_FLAGS="--target=x86_64-pc-linux-gnu -mcmodel=medium -c -O3" ./wamrc -o test.aot test.wasm ``` > Note: `wamrc` will verify whether the specified file exists and executable. If verification failed, `wamrc` will report a warning and fallback to normal pipeline. Since the verification is based on file, you **must specify the absolute path to the binary** even if it's in `$PATH` @@ -403,6 +403,8 @@ WAMRC_LLC_COMPILER= ./wamrc -o test.aot test.wasm > Note: the `LLC` and `ASM` in the env name just means this compiler will be used to compile the `LLVM IR file`/`assembly file` to object file, usually passing the compiler driver is the simplest way. (e.g. for LLVM toolchain, you don't need to pass `/usr/bin/llc`, using `/usr/bin/clang` is OK) +> Note: You might need to set `WAMRC_LLC_FLAGS`/`WAMRC_ASM_FLAGS` to match whatever the `wamrc` command would automatically do. In the above example, `-mcmodel=medium` corresponds to `wamrc --size-level=1`, which is the default of `wamrc` on macOS. + Run WASM app in WAMR mini product build =======================================