Changeset 189917 in webkit


Ignore:
Timestamp:
Sep 17, 2015 10:38:08 AM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Save and restore callee save registers in WebAssembly
https://bugs.webkit.org/show_bug.cgi?id=149247

Patch by Sukolsak Sakshuwong <Sukolsak Sakshuwong> on 2015-09-17
Reviewed by Michael Saboff.

Save callee save registers when entering WebAssembly functions
and restore them when returning.

  • jit/RegisterSet.cpp:

(JSC::RegisterSet::webAssemblyCalleeSaveRegisters):

  • jit/RegisterSet.h:
  • wasm/WASMFunctionCompiler.h:

(JSC::WASMFunctionCompiler::startFunction):
(JSC::WASMFunctionCompiler::endFunction):
(JSC::WASMFunctionCompiler::buildReturn):
(JSC::WASMFunctionCompiler::localAddress):
(JSC::WASMFunctionCompiler::temporaryAddress):
(JSC::WASMFunctionCompiler::boxArgumentsAndAdjustStackPointer):
(JSC::WASMFunctionCompiler::callAndUnboxResult):

Location:
trunk/Source/JavaScriptCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r189892 r189917  
     12015-09-17  Sukolsak Sakshuwong  <sukolsak@gmail.com>
     2
     3        Save and restore callee save registers in WebAssembly
     4        https://bugs.webkit.org/show_bug.cgi?id=149247
     5
     6        Reviewed by Michael Saboff.
     7
     8        Save callee save registers when entering WebAssembly functions
     9        and restore them when returning.
     10
     11        * jit/RegisterSet.cpp:
     12        (JSC::RegisterSet::webAssemblyCalleeSaveRegisters):
     13        * jit/RegisterSet.h:
     14        * wasm/WASMFunctionCompiler.h:
     15        (JSC::WASMFunctionCompiler::startFunction):
     16        (JSC::WASMFunctionCompiler::endFunction):
     17        (JSC::WASMFunctionCompiler::buildReturn):
     18        (JSC::WASMFunctionCompiler::localAddress):
     19        (JSC::WASMFunctionCompiler::temporaryAddress):
     20        (JSC::WASMFunctionCompiler::boxArgumentsAndAdjustStackPointer):
     21        (JSC::WASMFunctionCompiler::callAndUnboxResult):
     22
    1232015-09-16  Sukolsak Sakshuwong  <sukolsak@gmail.com>
    224
  • trunk/Source/JavaScriptCore/jit/RegisterSet.cpp

    r189575 r189917  
    275275}
    276276
     277#if ENABLE(WEBASSEMBLY)
     278RegisterSet RegisterSet::webAssemblyCalleeSaveRegisters()
     279{
     280    RegisterSet result;
     281#if CPU(X86)
     282#elif CPU(X86_64)
     283#if !OS(WINDOWS)
     284    ASSERT(GPRInfo::regCS3 == GPRInfo::tagTypeNumberRegister);
     285    ASSERT(GPRInfo::regCS4 == GPRInfo::tagMaskRegister);
     286    result.set(GPRInfo::regCS3);
     287    result.set(GPRInfo::regCS4);
     288#else
     289    ASSERT(GPRInfo::regCS5 == GPRInfo::tagTypeNumberRegister);
     290    ASSERT(GPRInfo::regCS6 == GPRInfo::tagMaskRegister);
     291    result.set(GPRInfo::regCS5);
     292    result.set(GPRInfo::regCS6);
     293#endif
     294#elif CPU(ARM_THUMB2)
     295#elif CPU(ARM_TRADITIONAL)
     296#elif CPU(ARM64)
     297    ASSERT(GPRInfo::regCS8 == GPRInfo::tagTypeNumberRegister);
     298    ASSERT(GPRInfo::regCS9 == GPRInfo::tagMaskRegister);
     299    result.set(GPRInfo::regCS8);
     300    result.set(GPRInfo::regCS9);
     301#elif CPU(MIPS)
     302#elif CPU(SH4)
     303#else
     304    UNREACHABLE_FOR_PLATFORM();
     305#endif
     306    return result;
     307}
     308#endif
     309
    277310RegisterSet RegisterSet::allGPRs()
    278311{
  • trunk/Source/JavaScriptCore/jit/RegisterSet.h

    r189575 r189917  
    5555    static RegisterSet dfgCalleeSaveRegisters(); // Registers saved and used by the DFG JIT.
    5656    static RegisterSet ftlCalleeSaveRegisters(); // Registers that might be saved and used by the FTL JIT.
     57#if ENABLE(WEBASSEMBLY)
     58    static RegisterSet webAssemblyCalleeSaveRegisters(); // Registers saved and used by the WebAssembly JIT.
     59#endif
    5760    static RegisterSet stubUnavailableRegisters(); // The union of callee saves and special registers.
    5861    static RegisterSet allGPRs();
  • trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h

    r189892 r189917  
    9292    void startFunction(const Vector<WASMType>& arguments, uint32_t numberOfI32LocalVariables, uint32_t numberOfF32LocalVariables, uint32_t numberOfF64LocalVariables)
    9393    {
     94        m_calleeSaveSpace = WTF::roundUpToMultipleOf(sizeof(StackSlot), RegisterSet::webAssemblyCalleeSaveRegisters().numberOfSetRegisters() * sizeof(void*));
     95        m_codeBlock->setCalleeSaveRegisters(RegisterSet::webAssemblyCalleeSaveRegisters());
     96
    9497        emitFunctionPrologue();
    9598        emitPutImmediateToCallFrameHeader(m_codeBlock, JSStack::CodeBlock);
     
    97100        m_beginLabel = label();
    98101
    99         addPtr(TrustedImm32(-WTF::roundUpToMultipleOf(stackAlignmentRegisters(), m_stackHeight) * sizeof(StackSlot) - maxFrameExtentForSlowPathCall), GPRInfo::callFrameRegister, GPRInfo::regT1);
     102        addPtr(TrustedImm32(-m_calleeSaveSpace - WTF::roundUpToMultipleOf(stackAlignmentRegisters(), m_stackHeight) * sizeof(StackSlot) - maxFrameExtentForSlowPathCall), GPRInfo::callFrameRegister, GPRInfo::regT1);
    100103        m_stackOverflow = branchPtr(Above, AbsoluteAddress(m_vm->addressOfStackLimit()), GPRInfo::regT1);
    101104
    102105        move(GPRInfo::regT1, stackPointerRegister);
    103106        checkStackPointerAlignment();
     107
     108        emitSaveCalleeSaves();
     109        emitMaterializeTagCheckRegisters();
    104110
    105111        m_numberOfLocals = arguments.size() + numberOfI32LocalVariables + numberOfF32LocalVariables + numberOfF64LocalVariables;
     
    160166#endif
    161167        moveTrustedValue(jsUndefined(), returnValueRegs);
     168        emitRestoreCalleeSaves();
    162169        emitFunctionEpilogue();
    163170        ret();
     
    184191        if (!m_exceptionChecks.empty()) {
    185192            m_exceptionChecks.link(this);
     193
     194            copyCalleeSavesToVMCalleeSavesBuffer();
    186195
    187196            // lookupExceptionHandler is passed two arguments, the VM and the exec (the CallFrame*).
     
    290299            ASSERT_NOT_REACHED();
    291300        }
     301        emitRestoreCalleeSaves();
    292302        emitFunctionEpilogue();
    293303        ret();
     
    805815    {
    806816        ASSERT(localIndex < m_numberOfLocals);
    807         return Address(GPRInfo::callFrameRegister, -(localIndex + 1) * sizeof(StackSlot));
     817        return Address(GPRInfo::callFrameRegister, -m_calleeSaveSpace - (localIndex + 1) * sizeof(StackSlot));
    808818    }
    809819
     
    811821    {
    812822        ASSERT(m_numberOfLocals + temporaryIndex < m_stackHeight);
    813         return Address(GPRInfo::callFrameRegister, -(m_numberOfLocals + temporaryIndex + 1) * sizeof(StackSlot));
     823        return Address(GPRInfo::callFrameRegister, -m_calleeSaveSpace - (m_numberOfLocals + temporaryIndex + 1) * sizeof(StackSlot));
    814824    }
    815825
     
    914924    {
    915925        size_t argumentCount = arguments.size();
    916         int stackOffset = -WTF::roundUpToMultipleOf(stackAlignmentRegisters(), m_numberOfLocals + m_tempStackTop + argumentCount + 1 + JSStack::CallFrameHeaderSize);
     926        int stackOffset = -m_calleeSaveSpace - WTF::roundUpToMultipleOf(stackAlignmentRegisters(), m_numberOfLocals + m_tempStackTop + argumentCount + 1 + JSStack::CallFrameHeaderSize);
    917927
    918928        storeTrustedValue(jsUndefined(), Address(GPRInfo::callFrameRegister, (stackOffset + CallFrame::thisArgumentOffset()) * sizeof(Register)));
     
    967977
    968978        end.link(this);
    969         addPtr(TrustedImm32(-WTF::roundUpToMultipleOf(stackAlignmentRegisters(), m_stackHeight) * sizeof(StackSlot) - maxFrameExtentForSlowPathCall), GPRInfo::callFrameRegister, stackPointerRegister);
     979        addPtr(TrustedImm32(-m_calleeSaveSpace - WTF::roundUpToMultipleOf(stackAlignmentRegisters(), m_stackHeight) * sizeof(StackSlot) - maxFrameExtentForSlowPathCall), GPRInfo::callFrameRegister, stackPointerRegister);
    970980        checkStackPointerAlignment();
    971981
     
    10491059    unsigned m_numberOfLocals;
    10501060    unsigned m_tempStackTop { 0 };
     1061    unsigned m_calleeSaveSpace;
    10511062
    10521063    Vector<JumpTarget> m_breakTargets;
Note: See TracChangeset for help on using the changeset viewer.