Browse Source

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.
YAMAMOTO Takashi 2 năm trước cách đây
mục cha
commit
f759a1f960
2 tập tin đã thay đổi với 6 bổ sung1 xóa
  1. 3 0
      core/iwasm/compilation/aot_llvm.c
  2. 3 1
      doc/build_wasm_app.md

+ 3 - 0
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);

+ 3 - 1
doc/build_wasm_app.md

@@ -394,7 +394,7 @@ Examples: wamrc -o test.aot test.wasm
 
 ### Usage example
 ``` bash
-WAMRC_LLC_COMPILER=<path/to/your/compiler/driver> ./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=<path/to/your/compiler/driver> ./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
 =======================================