mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 23:15:16 +00:00
![YAMAMOTO Takashi](/assets/img/avatar_default.png)
Move the native stack overflow check from the caller to the callee because the former doesn't work for call_indirect and imported functions. Make the stack usage estimation more accurate. Instead of making a guess from the number of wasm locals in the function, use the LLVM's idea of the stack size of each MachineFunction. The former is inaccurate because a) it doesn't reflect optimization passes, and b) wasm locals are not the only reason to use stack. To use the post-compilation stack usage information without requiring 2-pass compilation or machine-code imm rewriting, introduce a global array to store stack consumption of each functions: For JIT, use a custom IRCompiler with an extra pass to fill the array. For AOT, use `clang -fstack-usage` equivalent because we support external llc. Re-implement function call stack usage estimation to reflect the real calling conventions better. (aot_estimate_stack_usage_for_function_call) Re-implement stack estimation logic (--enable-memory-profiling) based on the new machinery. Discussions: #2105.
35 lines
1.1 KiB
C
35 lines
1.1 KiB
C
/*
|
|
* Copyright (c)2023 YAMAMOTO Takashi. All rights reserved.
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
*/
|
|
|
|
#include <llvm/Config/llvm-config.h>
|
|
#include <llvm-c/TargetMachine.h>
|
|
|
|
LLVM_C_EXTERN_C_BEGIN
|
|
LLVMTargetMachineRef
|
|
LLVMCreateTargetMachineWithOpts(LLVMTargetRef ctarget, const char *triple,
|
|
const char *cpu, const char *features,
|
|
LLVMCodeGenOptLevel opt_level,
|
|
LLVMRelocMode reloc_mode,
|
|
LLVMCodeModel code_model,
|
|
bool EmitStackSizeSection,
|
|
const char *StackUsageOutput);
|
|
|
|
/* https://reviews.llvm.org/D153107 */
|
|
#if LLVM_VERSION_MAJOR < 17
|
|
typedef enum {
|
|
LLVMTailCallKindNone = 0,
|
|
LLVMTailCallKindTail = 1,
|
|
LLVMTailCallKindMustTail = 2,
|
|
LLVMTailCallKindNoTail = 3,
|
|
} LLVMTailCallKind;
|
|
|
|
LLVMTailCallKind
|
|
LLVMGetTailCallKind(LLVMValueRef CallInst);
|
|
void
|
|
LLVMSetTailCallKind(LLVMValueRef CallInst, LLVMTailCallKind kind);
|
|
#endif
|
|
|
|
LLVM_C_EXTERN_C_END
|