--- a/js/src/wasm/WasmBaselineCompile.cpp
+++ b/js/src/wasm/WasmBaselineCompile.cpp
@@ -2192,21 +2192,20 @@ class BaseCompiler
call.abi.setUseHardFp(call.hardFP);
#endif
}
call.frameAlignAdjustment = ComputeByteAlignment(masm.framePushed() + sizeof(Frame),
JitStackAlignment);
}
- void endCall(FunctionCall& call)
+ void endCall(FunctionCall& call, size_t stackSpace)
{
size_t adjustment = call.stackArgAreaSize + call.frameAlignAdjustment;
- if (adjustment)
- masm.freeStack(adjustment);
+ masm.freeStack(stackSpace + adjustment);
if (call.reloadMachineStateAfter) {
loadFromFramePtr(WasmTlsReg, frameOffsetFromSlot(tlsSlot_, MIRType::Pointer));
masm.loadWasmPinnedRegsFromTls();
}
}
// TODO / OPTIMIZE (Bug 1316821): This is expensive; let's roll the iterator
@@ -5739,23 +5738,19 @@ BaseCompiler::emitCall()
if (!iter_.readCallReturn(sig.ret()))
return false;
if (import)
callImport(env_.funcImportGlobalDataOffsets[funcIndex], baselineCall);
else
callDefinition(funcIndex, baselineCall);
- endCall(baselineCall);
-
- // TODO / OPTIMIZE (bug 1316827): It would be better to merge this
- // freeStack() into the one in endCall, if we can.
+ endCall(baselineCall, stackSpace);
popValueStackBy(numArgs);
- masm.freeStack(stackSpace);
if (!IsVoid(sig.ret()))
pushReturned(baselineCall, sig.ret());
return true;
}
bool
@@ -5793,38 +5788,31 @@ BaseCompiler::emitCallIndirect(bool oldS
Stk callee = oldStyle ? peek(numArgs) : stk_.popCopy();
FunctionCall baselineCall(lineOrBytecode);
beginCall(baselineCall, UseABI::Wasm, InterModule::True);
if (!emitCallArgs(sig.args(), baselineCall))
return false;
- if (oldStyle) {
- if (!iter_.readOldCallIndirectCallee(&callee_))
- return false;
- }
+ if (oldStyle && !iter_.readOldCallIndirectCallee(&callee_))
+ return false;
if (!iter_.readCallReturn(sig.ret()))
return false;
callIndirect(sigIndex, callee, baselineCall);
- endCall(baselineCall);
+ endCall(baselineCall, stackSpace);
// For new style calls, the callee was popped off the compiler's
// stack above.
popValueStackBy(oldStyle ? numArgs + 1 : numArgs);
- // TODO / OPTIMIZE (bug 1316827): It would be better to merge this
- // freeStack() into the one in endCall, if we can.
-
- masm.freeStack(stackSpace);
-
if (!IsVoid(sig.ret()))
pushReturned(baselineCall, sig.ret());
return true;
}
bool
BaseCompiler::emitCommonMathCall(uint32_t lineOrBytecode, SymbolicAddress callee,
@@ -5841,23 +5829,19 @@ BaseCompiler::emitCommonMathCall(uint32_
if (!emitCallArgs(signature, baselineCall))
return false;
if (!iter_.readCallReturn(retType))
return false;
builtinCall(callee, baselineCall);
- endCall(baselineCall);
-
- // TODO / OPTIMIZE (bug 1316827): It would be better to merge this
- // freeStack() into the one in endCall, if we can.
+ endCall(baselineCall, stackSpace);
popValueStackBy(numArgs);
- masm.freeStack(stackSpace);
pushReturned(baselineCall, retType);
return true;
}
bool
BaseCompiler::emitUnaryMathBuiltinCall(SymbolicAddress callee, ValType operandType)
@@ -6645,20 +6629,19 @@ BaseCompiler::emitGrowMemory()
FunctionCall baselineCall(lineOrBytecode);
beginCall(baselineCall, UseABI::System, InterModule::True);
ABIArg instanceArg = reservePointerArgument(baselineCall);
startCallArgs(baselineCall, stackArgAreaSize(SigI_));
passArg(baselineCall, ValType::I32, peek(0));
builtinInstanceMethodCall(SymbolicAddress::GrowMemory, instanceArg, baselineCall);
- endCall(baselineCall);
+ endCall(baselineCall, stackSpace);
popValueStackBy(numArgs);
- masm.freeStack(stackSpace);
pushReturned(baselineCall, ExprType::I32);
return true;
}
bool
BaseCompiler::emitCurrentMemory()
@@ -6675,17 +6658,17 @@ BaseCompiler::emitCurrentMemory()
FunctionCall baselineCall(lineOrBytecode);
beginCall(baselineCall, UseABI::System, InterModule::False);
ABIArg instanceArg = reservePointerArgument(baselineCall);
startCallArgs(baselineCall, stackArgAreaSize(Sig_));
builtinInstanceMethodCall(SymbolicAddress::CurrentMemory, instanceArg, baselineCall);
- endCall(baselineCall);
+ endCall(baselineCall, 0);
pushReturned(baselineCall, ExprType::I32);
return true;
}
bool
BaseCompiler::emitBody()