diff options
author | YAMAMOTO Takashi <yamamoto@midokura.com> | 2024-02-14 08:52:11 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-13 15:52:11 -0800 |
commit | 78516ae1febad02ebf3162f5db9debc8904e8e74 (patch) | |
tree | 76d37b492ef1866cae24b182859c374b563a087a /src | |
parent | 32a27828b5b8312e3a289f3310585720b14ebbd8 (diff) | |
download | binaryen-78516ae1febad02ebf3162f5db9debc8904e8e74.tar.gz binaryen-78516ae1febad02ebf3162f5db9debc8904e8e74.tar.bz2 binaryen-78516ae1febad02ebf3162f5db9debc8904e8e74.zip |
Fix --spill-pointers for the stack growing down (#6294)
The LLVM wasm backend grows the stack downwards, and this pass did not
fully account for that before.
Diffstat (limited to 'src')
-rw-r--r-- | src/abi/stack.h | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/abi/stack.h b/src/abi/stack.h index 93a6e4cc1..752aecae4 100644 --- a/src/abi/stack.h +++ b/src/abi/stack.h @@ -38,9 +38,6 @@ inline Index stackAlign(Index size) { // Allocate some space on the stack, and assign it to a local. // The local will have the same constant value in all the function, so you can // just local.get it anywhere there. -// -// FIXME: This function assumes that the stack grows upward, per the convention -// used by fastcomp. The stack grows downward when using the WASM backend. inline void getStackSpace(Index local, Function* func, Index size, Module& wasm) { @@ -55,22 +52,25 @@ getStackSpace(Index local, Function* func, Index size, Module& wasm) { // TODO: find existing stack usage, and add on top of that - carefully Builder builder(wasm); auto* block = builder.makeBlock(); - block->list.push_back(builder.makeLocalSet( - local, builder.makeGlobalGet(stackPointer->name, pointerType))); // TODO: add stack max check Expression* added; if (pointerType == Type::i32) { // The stack goes downward in the LLVM wasm backend. - added = builder.makeBinary(SubInt32, - builder.makeLocalGet(local, pointerType), - builder.makeConst(int32_t(size))); + added = + builder.makeBinary(SubInt32, + builder.makeGlobalGet(stackPointer->name, pointerType), + builder.makeConst(int32_t(size))); } else { WASM_UNREACHABLE("unhandled pointerType"); } - block->list.push_back(builder.makeGlobalSet(stackPointer->name, added)); + block->list.push_back(builder.makeGlobalSet( + stackPointer->name, builder.makeLocalTee(local, added, pointerType))); auto makeStackRestore = [&]() { - return builder.makeGlobalSet(stackPointer->name, - builder.makeLocalGet(local, pointerType)); + return builder.makeGlobalSet( + stackPointer->name, + builder.makeBinary(AddInt32, + builder.makeLocalGet(local, pointerType), + builder.makeConst(int32_t(size)))); }; // add stack restores to the returns FindAllPointers<Return> finder(func->body); |