AOT/JIT native stack bound check improvement (#2244)

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.
This commit is contained in:
YAMAMOTO Takashi
2023-06-22 08:27:07 +09:00
committed by GitHub
parent 8797c751a5
commit cd7941cc39
12 changed files with 1348 additions and 252 deletions

View File

@ -6,6 +6,7 @@
#include <llvm-c/TargetMachine.h>
#include <llvm/ADT/None.h>
#include <llvm/ADT/Optional.h>
#include <llvm/IR/Instructions.h>
#if LLVM_VERSION_MAJOR >= 14
#include <llvm/MC/TargetRegistry.h>
#else
@ -112,3 +113,20 @@ LLVMCreateTargetMachineWithOpts(LLVMTargetRef ctarget, const char *triple,
opts, rm, cm, ol, jit);
return reinterpret_cast<LLVMTargetMachineRef>(targetmachine);
}
/* https://reviews.llvm.org/D153107 */
#if LLVM_VERSION_MAJOR < 17
using namespace llvm;
LLVMTailCallKind
LLVMGetTailCallKind(LLVMValueRef Call)
{
return (LLVMTailCallKind)unwrap<CallInst>(Call)->getTailCallKind();
}
void
LLVMSetTailCallKind(LLVMValueRef Call, LLVMTailCallKind kind)
{
unwrap<CallInst>(Call)->setTailCallKind((CallInst::TailCallKind)kind);
}
#endif