diff --git a/src/coreclr/jit/codegenwasm.cpp b/src/coreclr/jit/codegenwasm.cpp index 4df06a6e5d22b0..3d7edebd7c387c 100644 --- a/src/coreclr/jit/codegenwasm.cpp +++ b/src/coreclr/jit/codegenwasm.cpp @@ -13,6 +13,8 @@ #include "gcinfoencoder.h" static const int LINEAR_MEMORY_INDEX = 0; +// stackPointer is the 0th global in our generated Wasm modules +static const int STACK_POINTER_GLOBAL = 0; #ifdef TARGET_64BIT static const instruction INS_I_load = INS_i64_load; @@ -144,16 +146,20 @@ void CodeGen::genAllocLclFrame(unsigned frameSize, regNumber initReg, bool* pIni m_compiler->unwindAllocStack(frameSize); - // TODO-WASM: reverse pinvoke frame allocation - // + unsigned initialSPLclIndex; + unsigned spLclIndex = WasmRegToIndex(spReg); if (!m_compiler->lvaGetDesc(m_compiler->lvaWasmSpArg)->lvIsParam) { - NYI_WASM("alloc local frame for reverse pinvoke"); + initialSPLclIndex = spLclIndex; + GetEmitter()->emitIns_I(INS_global_get, EA_PTRSIZE, STACK_POINTER_GLOBAL); + GetEmitter()->emitIns_I(INS_local_set, EA_PTRSIZE, initialSPLclIndex); + } + else + { + initialSPLclIndex = + WasmRegToIndex(m_compiler->lvaGetParameterABIInfo(m_compiler->lvaWasmSpArg).Segment(0).GetRegister()); } - unsigned initialSPLclIndex = - WasmRegToIndex(m_compiler->lvaGetParameterABIInfo(m_compiler->lvaWasmSpArg).Segment(0).GetRegister()); - unsigned spLclIndex = WasmRegToIndex(spReg); assert(initialSPLclIndex == spLclIndex); if (frameSize != 0) {