Ignore:
Timestamp:
Nov 16, 2016, 3:34:39 PM (9 years ago)
Author:
[email protected]
Message:

Wasm function parser should use template functions for each binary and unary opcode
https://bugs.webkit.org/show_bug.cgi?id=164835

Reviewed by Mark Lam.

This patch changes the wasm function parser to call into a template specialization
for each binary/unary opcode. This change makes it easier to have custom implementations
of various opcodes. It is also, in theory a speedup since it does not require switching
on the opcode twice.

  • CMakeLists.txt:
  • DerivedSources.make:
  • wasm/WasmB3IRGenerator.cpp:

(): Deleted.

  • wasm/WasmFunctionParser.h:

(JSC::Wasm::FunctionParser<Context>::binaryCase):
(JSC::Wasm::FunctionParser<Context>::unaryCase):
(JSC::Wasm::FunctionParser<Context>::parseExpression):

  • wasm/WasmValidate.cpp:
  • wasm/generateWasm.py:

(isBinary):
(isSimple):

  • wasm/generateWasmB3IRGeneratorInlinesHeader.py: Added.

(generateSimpleCode):

  • wasm/generateWasmOpsHeader.py:

(opcodeMacroizer):

  • wasm/generateWasmValidateInlinesHeader.py:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/wasm/generateWasmValidateInlinesHeader.py

    r208238 r208821  
    6161    op = opcodes[name]
    6262    return """
    63     case UnaryOpType::""" + toCpp(name) + """: {
    64         if (value != """ + cppType(op["parameter"][0]) + """) {
    65             m_errorMessage = makeString(\"""" + name + """ expects the value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(value));
    66             return false;
    67         }
     63template<> bool Validate::addOp<OpType::""" + toCpp(name) + """>(ExpressionType value, ExpressionType& result)
     64{
     65    if (value != """ + cppType(op["parameter"][0]) + """) {
     66        m_errorMessage = makeString(\"""" + name + """ expects the value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(value));
     67        return false;
     68    }
    6869
    69         result = """ + cppType(op["return"][0]) + """;
    70         return true;
    71     }"""
     70    result = """ + cppType(op["return"][0]) + """;
     71    return true;
     72}
     73"""
    7274
    7375
     
    7577    op = opcodes[name]
    7678    return """
    77     case BinaryOpType::""" + toCpp(name) + """: {
    78         if (left != """ + cppType(op["parameter"][0]) + """) {
    79             m_errorMessage = makeString(\"""" + name + """ expects the left value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(left));
    80             return false;
    81         }
     79template<> bool Validate::addOp<OpType::""" + toCpp(name) + """>(ExpressionType left, ExpressionType right, ExpressionType& result)
     80{
     81    if (left != """ + cppType(op["parameter"][0]) + """) {
     82        m_errorMessage = makeString(\"""" + name + """ expects the left value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(left));
     83        return false;
     84    }
    8285
    83         if (right != """ + cppType(op["parameter"][1]) + """) {
    84             m_errorMessage = makeString(\"""" + name + """ expects the right value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(right));
    85             return false;
    86         }
     86    if (right != """ + cppType(op["parameter"][1]) + """) {
     87        m_errorMessage = makeString(\"""" + name + """ expects the right value to be of type: ", toString(""" + cppType(op["parameter"][0]) + """), " but got a value with type: ", toString(right));
     88        return false;
     89    }
    8790
    88         result = """ + cppType(op["return"][0]) + """;
    89         return true;
    90     }"""
    91 
     91    result = """ + cppType(op["return"][0]) + """;
     92    return true;
     93}
     94"""
    9295
    9396def loadMacro(name):
     
    123126
    124127
    125 unaryCases = "".join([op for op in wasm.opcodeIterator(isUnary, unaryMacro)])
    126 binaryCases = "".join([op for op in wasm.opcodeIterator(isBinary, binaryMacro)])
     128unarySpecializations = "".join([op for op in wasm.opcodeIterator(isUnary, unaryMacro)])
     129binarySpecializations = "".join([op for op in wasm.opcodeIterator(isBinary, binaryMacro)])
    127130loadCases = "".join([op for op in wasm.opcodeIterator(lambda op: op["category"] == "memory" and len(op["return"]) == 1, loadMacro)])
    128131storeCases = "".join([op for op in wasm.opcodeIterator(lambda op: op["category"] == "memory" and len(op["return"]) == 0, storeMacro)])
     
    137140namespace JSC { namespace Wasm {
    138141
    139 bool Validate::unaryOp(UnaryOpType op, ExpressionType value, ExpressionType& result)
    140 {
    141     switch (op) {
    142 """ + unaryCases + """
    143     }
    144 }
    145 
    146 bool Validate::binaryOp(BinaryOpType op, ExpressionType left, ExpressionType right, ExpressionType& result)
    147 {
    148     switch (op) {
    149 """ + binaryCases + """
    150     }
    151 }
     142""" + unarySpecializations + binarySpecializations + """
    152143
    153144bool Validate::load(LoadOpType op, ExpressionType pointer, ExpressionType& result, uint32_t)
Note: See TracChangeset for help on using the changeset viewer.