Bug 1485162 - Baldr: remove confusing StackDecrementForCall() overloads (r=bbouvier)
authorLuke Wagner <luke@mozilla.com>
Thu, 23 Aug 2018 11:23:52 -0500
changeset 831143 5ff39f587a0de8a75ab92bc16b58c759cffdb42c
parent 831142 249688402db2fea2a16fb6eb4d6de33abf5bd1c4
child 831144 e4a245dc212abd00595bb4e4489096c6daefc73c
push id118868
push userbmo:zjz@zjz.name
push dateFri, 24 Aug 2018 07:04:39 +0000
reviewersbbouvier
bugs1485162
milestone63.0a1
Bug 1485162 - Baldr: remove confusing StackDecrementForCall() overloads (r=bbouvier)
js/src/wasm/WasmBaselineCompile.cpp
js/src/wasm/WasmStubs.cpp
--- a/js/src/wasm/WasmBaselineCompile.cpp
+++ b/js/src/wasm/WasmBaselineCompile.cpp
@@ -1007,17 +1007,17 @@ using ScratchI8 = ScratchI32;
 BaseLocalIter::BaseLocalIter(const ValTypeVector& locals, size_t argsLength, bool debugEnabled)
   : locals_(locals),
     argsLength_(argsLength),
     argsRange_(locals.begin(), argsLength),
     argsIter_(argsRange_),
     index_(0),
     localSize_(debugEnabled ? DebugFrame::offsetOfFrame() : 0),
     reservedSize_(localSize_),
-    frameOffset_(0),
+    frameOffset_(UINT32_MAX),
     mirType_(MIRType::Undefined),
     done_(false)
 {
     MOZ_ASSERT(argsLength <= locals.length());
     settle();
 }
 
 int32_t
--- a/js/src/wasm/WasmStubs.cpp
+++ b/js/src/wasm/WasmStubs.cpp
@@ -48,40 +48,26 @@ FinishOffsets(MacroAssembler& masm, Offs
 
 static void
 AssertStackAlignment(MacroAssembler& masm, uint32_t alignment, uint32_t addBeforeAssert = 0)
 {
     MOZ_ASSERT((sizeof(Frame) + masm.framePushed() + addBeforeAssert) % alignment == 0);
     masm.assertStackAlignment(alignment, addBeforeAssert);
 }
 
-static unsigned
-StackDecrementForCall(MacroAssembler& masm, uint32_t alignment, unsigned bytesToPush)
-{
-    return StackDecrementForCall(alignment, sizeof(Frame) + masm.framePushed(), bytesToPush);
-}
-
 template <class VectorT>
 static unsigned
 StackArgBytes(const VectorT& args)
 {
     ABIArgIter<VectorT> iter(args);
     while (!iter.done())
         iter++;
     return iter.stackBytesConsumedSoFar();
 }
 
-template <class VectorT>
-static unsigned
-StackDecrementForCall(MacroAssembler& masm, uint32_t alignment, const VectorT& args,
-                      unsigned extraBytes = 0)
-{
-    return StackDecrementForCall(masm, alignment, StackArgBytes(args) + extraBytes);
-}
-
 static void
 SetupABIArguments(MacroAssembler& masm, const FuncExport& fe, Register argv, Register scratch)
 {
     // Copy parameters out of argv and into the registers/stack-slots specified by
     // the system ABI.
     for (ABIArgValTypeIter iter(fe.funcType().args()); !iter.done(); iter++) {
         unsigned argOffset = iter.index() * sizeof(ExportArg);
         Address src(argv, argOffset);
@@ -558,17 +544,19 @@ GenerateJitEntry(MacroAssembler& masm, s
     MOZ_ALWAYS_TRUE(coerceArgTypes.append(MIRType::Pointer));
     MOZ_ALWAYS_TRUE(coerceArgTypes.append(MIRType::Pointer));
     unsigned oolBytesNeeded = StackArgBytes(coerceArgTypes);
 
     unsigned bytesNeeded = Max(normalBytesNeeded, oolBytesNeeded);
 
     // Note the jit caller ensures the stack is aligned *after* the call
     // instruction.
-    unsigned frameSize = StackDecrementForCall(WasmStackAlignment, 0, bytesNeeded);
+    unsigned frameSize = StackDecrementForCall(WasmStackAlignment,
+                                               masm.framePushed(),
+                                               bytesNeeded);
 
 #ifdef ENABLE_WASM_GC
     unsigned savedTlsOffset = frameSize - sizeof(void*);
 #endif
 
     // Reserve stack space for wasm ABI arguments, set up like this:
     // <-- ABI args | padding
     masm.reserveStack(frameSize);
@@ -993,17 +981,20 @@ FillArgumentArray(MacroAssembler& masm, 
 static bool
 GenerateImportFunction(jit::MacroAssembler& masm, const FuncImport& fi, FuncTypeIdDesc funcTypeId,
                        FuncOffsets* offsets)
 {
     AssertExpectedSP(masm);
 
     GenerateFunctionPrologue(masm, funcTypeId, Nothing(), offsets);
 
-    unsigned framePushed = StackDecrementForCall(masm, WasmStackAlignment, fi.funcType().args());
+    MOZ_ASSERT(masm.framePushed() == 0);
+    unsigned framePushed = StackDecrementForCall(WasmStackAlignment,
+                                                 sizeof(Frame),  // pushed by prologue
+                                                 StackArgBytes(fi.funcType().args()));
     masm.wasmReserveStackChecked(framePushed, BytecodeOffset(0));
     MOZ_ASSERT(masm.framePushed() == framePushed);
 
     // The argument register state is already setup by our caller. We just need
     // to be sure not to clobber it before the call.
     Register scratch = ABINonArgReg0;
 
     // Copy our frame's stack arguments to the callee frame's stack argument.
@@ -1080,17 +1071,19 @@ GenerateImportInterpExit(MacroAssembler&
     MOZ_ALWAYS_TRUE(invokeArgTypes.append(typeArray, ArrayLength(typeArray)));
 
     // At the point of the call, the stack layout shall be (sp grows to the left):
     //   | stack args | padding | Value argv[] | padding | retaddr | caller stack args |
     // The padding between stack args and argv ensures that argv is aligned. The
     // padding between argv and retaddr ensures that sp is aligned.
     unsigned argOffset = AlignBytes(StackArgBytes(invokeArgTypes), sizeof(double));
     unsigned argBytes = Max<size_t>(1, fi.funcType().args().length()) * sizeof(Value);
-    unsigned framePushed = StackDecrementForCall(masm, ABIStackAlignment, argOffset + argBytes);
+    unsigned framePushed = StackDecrementForCall(ABIStackAlignment,
+                                                 sizeof(Frame),  // pushed by prologue
+                                                 argOffset + argBytes);
 
     GenerateExitPrologue(masm, framePushed, ExitReason::Fixed::ImportInterp, offsets);
 
     // Fill the argument array.
     unsigned offsetToCallerStackArgs = sizeof(Frame) + masm.framePushed();
     Register scratch = ABINonArgReturnReg0;
     FillArgumentArray(masm, fi.funcType().args(), argOffset, offsetToCallerStackArgs, scratch, ToValue(false));
 
@@ -1190,27 +1183,27 @@ GenerateImportInterpExit(MacroAssembler&
 static bool
 GenerateImportJitExit(MacroAssembler& masm, const FuncImport& fi, Label* throwLabel,
                       JitExitOffsets* offsets)
 {
     AssertExpectedSP(masm);
     masm.setFramePushed(0);
 
     // JIT calls use the following stack layout (sp grows to the left):
-    //   | retaddr | descriptor | callee | argc | this | arg1..N |
-    // After the JIT frame, the global register (if present) is saved since the
-    // JIT's ABI does not preserve non-volatile regs. Also, unlike most ABIs,
-    // the JIT ABI requires that sp be JitStackAlignment-aligned *after* pushing
-    // the return address.
+    //   | WasmToJSJitFrameLayout | this | arg1..N |
+    // Unlike most ABIs, the JIT ABI requires that sp be JitStackAlignment-
+    // aligned *after* pushing the return address.
     static_assert(WasmStackAlignment >= JitStackAlignment, "subsumes");
     const unsigned sizeOfRetAddr = sizeof(void*);
     const unsigned sizeOfPreFrame = WasmToJSJitFrameLayout::Size() - sizeOfRetAddr;
     const unsigned sizeOfThisAndArgs = (1 + fi.funcType().args().length()) * sizeof(Value);
     const unsigned totalJitFrameBytes = sizeOfRetAddr + sizeOfPreFrame + sizeOfThisAndArgs;
-    const unsigned jitFramePushed = StackDecrementForCall(masm, JitStackAlignment, totalJitFrameBytes) -
+    const unsigned jitFramePushed = StackDecrementForCall(JitStackAlignment,
+                                                          sizeof(Frame),  // pushed by prologue
+                                                          totalJitFrameBytes) -
                                     sizeOfRetAddr;
     const unsigned sizeOfThisAndArgsAndPadding = jitFramePushed - sizeOfPreFrame;
 
     // On ARM64 we must align the SP to a 16-byte boundary.
 #ifdef JS_CODEGEN_ARM64
     const unsigned frameAlignExtra = sizeof(void*);
 #else
     const unsigned frameAlignExtra = 0;
@@ -1455,17 +1448,19 @@ struct ABIFunctionArgs
 bool
 wasm::GenerateBuiltinThunk(MacroAssembler& masm, ABIFunctionType abiType, ExitReason exitReason,
                            void* funcPtr, CallableOffsets* offsets)
 {
     AssertExpectedSP(masm);
     masm.setFramePushed(0);
 
     ABIFunctionArgs args(abiType);
-    uint32_t framePushed = StackDecrementForCall(masm, ABIStackAlignment, args);
+    uint32_t framePushed = StackDecrementForCall(ABIStackAlignment,
+                                                 sizeof(Frame),  // pushed by prologue
+                                                 StackArgBytes(args));
 
     GenerateExitPrologue(masm, framePushed, exitReason, offsets);
 
     // Copy out and convert caller arguments, if needed.
     unsigned offsetToCallerStackArgs = sizeof(Frame) + masm.framePushed();
     Register scratch = ABINonArgReturnReg0;
     for (ABIArgIter<ABIFunctionArgs> i(args); !i.done(); i++) {
         if (i->argInRegister()) {