Changeset 251978 in webkit


Ignore:
Timestamp:
Nov 3, 2019 8:11:43 PM (4 years ago)
Author:
Tadeu Zagallo
Message:

LLIntGenerator should not allocate temporaries in between variables
https://bugs.webkit.org/show_bug.cgi?id=203787

Reviewed by Yusuke Suzuki.

JSTests:

  • wasm/stress/local-ref.js: Added.

Source/JavaScriptCore:

The BytecodeGenerator requires that all variables must be allocated contiguously, before any
temporaries are allocated. Currently, we might end up allocating a temporary to materialize
the null constant to initialize locals of type Anyref/Funcref. Fix it by keeping track of the
locals that need to be initialized and adding a new callback to notify when we have finished
parsing locals. Only then we perform the delayed initialization of local refs.

  • wasm/WasmAirIRGenerator.cpp:

(JSC::Wasm::AirIRGenerator::didFinishParsingLocals):

  • wasm/WasmB3IRGenerator.cpp:

(JSC::Wasm::B3IRGenerator::didFinishParsingLocals):

  • wasm/WasmFunctionParser.h:

(JSC::Wasm::FunctionParser<Context>::parse):

  • wasm/WasmLLIntGenerator.cpp:

(JSC::Wasm::LLIntGenerator::addLocal):
(JSC::Wasm::LLIntGenerator::didFinishParsingLocals):

  • wasm/WasmValidate.cpp:

(JSC::Wasm::Validate::didFinishParsingLocals):

Location:
trunk
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r251967 r251978  
     12019-11-03  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        LLIntGenerator should not allocate temporaries in between variables
     4        https://bugs.webkit.org/show_bug.cgi?id=203787
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        * wasm/stress/local-ref.js: Added.
     9
    1102019-11-02  Alexey Proskuryakov  <ap@apple.com>
    211
  • trunk/Source/JavaScriptCore/ChangeLog

    r251967 r251978  
     12019-11-03  Tadeu Zagallo  <tzagallo@apple.com>
     2
     3        LLIntGenerator should not allocate temporaries in between variables
     4        https://bugs.webkit.org/show_bug.cgi?id=203787
     5
     6        Reviewed by Yusuke Suzuki.
     7
     8        The BytecodeGenerator requires that all variables must be allocated contiguously, before any
     9        temporaries are allocated. Currently, we might end up allocating a temporary to materialize
     10        the null constant to initialize locals of type Anyref/Funcref. Fix it by keeping track of the
     11        locals that need to be initialized and adding a new callback to notify when we have finished
     12        parsing locals. Only then we perform the delayed initialization of local refs.
     13
     14        * wasm/WasmAirIRGenerator.cpp:
     15        (JSC::Wasm::AirIRGenerator::didFinishParsingLocals):
     16        * wasm/WasmB3IRGenerator.cpp:
     17        (JSC::Wasm::B3IRGenerator::didFinishParsingLocals):
     18        * wasm/WasmFunctionParser.h:
     19        (JSC::Wasm::FunctionParser<Context>::parse):
     20        * wasm/WasmLLIntGenerator.cpp:
     21        (JSC::Wasm::LLIntGenerator::addLocal):
     22        (JSC::Wasm::LLIntGenerator::didFinishParsingLocals):
     23        * wasm/WasmValidate.cpp:
     24        (JSC::Wasm::Validate::didFinishParsingLocals):
     25
    1262019-11-02  Alexey Proskuryakov  <ap@apple.com>
    227
  • trunk/Source/JavaScriptCore/wasm/WasmAirIRGenerator.cpp

    r251886 r251978  
    299299    void dump(const Vector<ControlEntry>& controlStack, const Stack* expressionStack);
    300300    void setParser(FunctionParser<AirIRGenerator>* parser) { m_parser = parser; };
     301    void didFinishParsingLocals() { }
    301302
    302303    static Vector<Tmp> toTmpVector(const Vector<TypedTmp>& vector)
  • trunk/Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp

    r251886 r251978  
    244244    void dump(const Vector<ControlEntry>& controlStack, const Stack* expressionStack);
    245245    void setParser(FunctionParser<B3IRGenerator>* parser) { m_parser = parser; };
     246    void didFinishParsingLocals() { }
    246247
    247248    Value* constant(B3::Type, uint64_t bits, Optional<Origin> = WTF::nullopt);
  • trunk/Source/JavaScriptCore/wasm/WasmFunctionParser.h

    r251886 r251978  
    146146        WASM_TRY_ADD_TO_CONTEXT(addLocal(typeOfLocal, numberOfLocals));
    147147    }
     148
     149    m_context.didFinishParsingLocals();
    148150
    149151    WASM_FAIL_IF_HELPER_FAILS(parseBody());
  • trunk/Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp

    r251886 r251978  
    208208    PartialResult WARN_UNUSED_RETURN addUnreachable();
    209209
     210    void didFinishParsingLocals();
     211
    210212    void setParser(FunctionParser<LLIntGenerator>* parser) { m_parser = parser; };
    211213
     
    273275    HashMap<Label*, Vector<SwitchEntry>> m_switches;
    274276    ExpressionType m_jsNullConstant;
     277    ExpressionList m_unitializedLocals;
    275278};
    276279
     
    485488        case Type::Anyref:
    486489        case Type::Funcref:
    487             WasmMov::emit(this, local, jsNullConstant());
     490            m_unitializedLocals.append(local);
    488491            break;
    489492        default:
     
    492495    }
    493496    return { };
     497}
     498
     499void LLIntGenerator::didFinishParsingLocals()
     500{
     501    auto null = jsNullConstant();
     502    for (auto local : m_unitializedLocals)
     503        WasmMov::emit(this, local, null);
     504    m_unitializedLocals.clear();
    494505}
    495506
  • trunk/Source/JavaScriptCore/wasm/WasmValidate.cpp

    r251886 r251978  
    176176    void dump(const Vector<ControlEntry>&, const Stack*);
    177177    void setParser(FunctionParser<Validate>*) { }
     178    void didFinishParsingLocals() { }
    178179
    179180private:
Note: See TracChangeset for help on using the changeset viewer.