Changeset 43331 in webkit for trunk/JavaScriptCore/jit


Ignore:
Timestamp:
May 6, 2009, 5:06:07 PM (16 years ago)
Author:
[email protected]
Message:

2009-05-06 Gavin Barraclough <[email protected]>

Reviewed by Maciej Stachowiak & Darin Adler.

Improve string concatenation (as coded in JS as a sequence of adds).

Detect patterns corresponding to string concatenation, and change the bytecode
generation to emit a new op_strcat instruction. By handling the full set of
additions within a single function we do not need allocate JSString wrappers
for intermediate results, and we can calculate the size of the output string
prior to allocating storage, in order to prevent reallocation of the buffer.

1.5%-2% progression on Sunspider, largely due to a 30% progression on date-format-xparb.

  • bytecode/CodeBlock.cpp: (JSC::CodeBlock::dump):

Add new opcodes.

  • bytecode/Opcode.h:

Add new opcodes.

  • bytecompiler/BytecodeGenerator.cpp: (JSC::BytecodeGenerator::emitStrcat): (JSC::BytecodeGenerator::emitToPrimitive):

Add generation of new opcodes.

  • bytecompiler/BytecodeGenerator.h:

Add generation of new opcodes.

  • interpreter/Interpreter.cpp: (JSC::Interpreter::privateExecute):

Add implmentation of new opcodes.

  • jit/JIT.cpp: (JSC::JIT::privateCompileMainPass): (JSC::JIT::privateCompileSlowCases):

Add implmentation of new opcodes.

  • jit/JITStubs.cpp: (JSC::JITStubs::cti_op_to_primitive): (JSC::JITStubs::cti_op_strcat):

Add implmentation of new opcodes.

  • jit/JITStubs.h:

Add implmentation of new opcodes.

  • parser/Nodes.cpp: (JSC::BinaryOpNode::emitStrcat): (JSC::BinaryOpNode::emitBytecode): (JSC::ReadModifyResolveNode::emitBytecode):

Add generation of new opcodes.

  • parser/Nodes.h: (JSC::ExpressionNode::): (JSC::AddNode::):

Add methods to allow identification of add nodes.

  • parser/ResultType.h: (JSC::ResultType::definitelyIsString): (JSC::ResultType::forAdd):

Fix error in detection of adds that will produce string results.

  • runtime/Operations.h: (JSC::concatenateStrings):

Add implmentation of new opcodes.

  • runtime/UString.cpp: (JSC::UString::appendNumeric):

Add methods to append numbers to an existing string.

  • runtime/UString.h: (JSC::UString::Rep::createEmptyBuffer): (JSC::UString::BaseString::BaseString):

Add support for creating an empty string with a non-zero capacity available in the BaseString.

Location:
trunk/JavaScriptCore/jit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/jit/JIT.cpp

    r43276 r43331  
    464464            NEXT_OPCODE(op_construct_verify);
    465465        }
     466        case op_to_primitive: {
     467            int dst = currentInstruction[1].u.operand;
     468            int src = currentInstruction[2].u.operand;
     469
     470            emitGetVirtualRegister(src, regT0);
     471           
     472            Jump isImm = emitJumpIfNotJSCell(regT0);
     473            addSlowCase(branchPtr(NotEqual, Address(regT0), ImmPtr(m_globalData->jsStringVPtr)));
     474            isImm.link(this);
     475
     476            if (dst != src)
     477                emitPutVirtualRegister(dst);
     478
     479            NEXT_OPCODE(op_to_primitive);
     480        }
     481        case op_strcat: {
     482            emitPutJITStubArgConstant(currentInstruction[2].u.operand, 1);
     483            emitPutJITStubArgConstant(currentInstruction[3].u.operand, 2);
     484            emitCTICall(JITStubs::cti_op_strcat);
     485            emitPutVirtualRegister(currentInstruction[1].u.operand);
     486
     487            NEXT_OPCODE(op_strcat);
     488        }
    466489        case op_get_by_val: {
    467490            emitGetVirtualRegisters(currentInstruction[2].u.operand, regT0, currentInstruction[3].u.operand, regT1);
     
    11671190            NEXT_OPCODE(op_construct_verify);
    11681191        }
     1192        case op_to_primitive: {
     1193            linkSlowCase(iter);
     1194
     1195            emitPutJITStubArg(regT0, 1);
     1196            emitCTICall(JITStubs::cti_op_to_primitive);
     1197            emitPutVirtualRegister(currentInstruction[1].u.operand);
     1198
     1199            NEXT_OPCODE(op_to_primitive);
     1200        }
    11691201        case op_get_by_val: {
    11701202            // The slow case that handles accesses to arrays (below) may jump back up to here.
  • trunk/JavaScriptCore/jit/JITStubs.cpp

    r43273 r43331  
    21962196}
    21972197
     2198EncodedJSValue JITStubs::cti_op_to_primitive(STUB_ARGS)
     2199{
     2200    BEGIN_STUB_FUNCTION();
     2201
     2202    return JSValue::encode(ARG_src1.toPrimitive(ARG_callFrame));
     2203}
     2204
     2205EncodedJSValue JITStubs::cti_op_strcat(STUB_ARGS)
     2206{
     2207    BEGIN_STUB_FUNCTION();
     2208
     2209    return JSValue::encode(concatenateStrings(ARG_callFrame, &ARG_callFrame->registers()[ARG_int1], ARG_int2));
     2210}
     2211
    21982212EncodedJSValue JITStubs::cti_op_nstricteq(STUB_ARGS)
    21992213{
  • trunk/JavaScriptCore/jit/JITStubs.h

    r43273 r43331  
    212212        static EncodedJSValue JIT_STUB cti_op_rshift(STUB_ARGS);
    213213        static EncodedJSValue JIT_STUB cti_op_stricteq(STUB_ARGS);
     214        static EncodedJSValue JIT_STUB cti_op_strcat(STUB_ARGS);
     215        static EncodedJSValue JIT_STUB cti_op_to_primitive(STUB_ARGS);
    214216        static EncodedJSValue JIT_STUB cti_op_sub(STUB_ARGS);
    215217        static EncodedJSValue JIT_STUB cti_op_throw(STUB_ARGS);
Note: See TracChangeset for help on using the changeset viewer.