Bug 1316827 - WASM: the stack is now free'd once, even when an adjustment is needed. r=lth draft
authorMichelangelo De Simone <mdesimone@mozilla.com>
Fri, 09 Dec 2016 17:37:58 -1000
changeset 448899 d7796a180744ebdba672193dff6968ce3d69b114
parent 448260 8404d26166a35406f46ff237ed132735c98882b2
child 539418 417ac81563336d14ea896dac6f0833ef8cb09b3a
push id38480
push userbmo:mdesimone@mozilla.com
push dateTue, 13 Dec 2016 08:14:10 +0000
reviewerslth
bugs1316827
milestone53.0a1
Bug 1316827 - WASM: the stack is now free'd once, even when an adjustment is needed. r=lth MozReview-Commit-ID: IqCd9ueOA8V
js/src/wasm/WasmBaselineCompile.cpp
--- 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()