Ignore:
Timestamp:
Aug 6, 2008, 3:37:34 AM (17 years ago)
Author:
[email protected]
Message:

2008-08-06 Cameron Zwarich <[email protected]>

Reviewed by Maciej.

Bug 20286: Load constants all at once instead of using op_load
<https://bugs.webkit.org/show_bug.cgi?id=20286>

Load constants all at once into temporary registers instead of using
individual instances of op_load.

This is a 2.6% speedup on SunSpider.

JavaScriptCore:

  • JavaScriptCore.exp:
  • VM/CodeBlock.cpp: (KJS::CodeBlock::dump): (KJS::CodeBlock::mark):
  • VM/CodeBlock.h:
  • VM/CodeGenerator.cpp: (KJS::CodeGenerator::CodeGenerator): (KJS::CodeGenerator::newTemporary): (KJS::CodeGenerator::addConstant): (KJS::CodeGenerator::addUnexpectedConstant): (KJS::CodeGenerator::emitLoad): (KJS::CodeGenerator::emitUnexpectedLoad): (KJS::CodeGenerator::emitNewError):
  • VM/CodeGenerator.h:
  • VM/Machine.cpp: (KJS::slideRegisterWindowForCall): (KJS::Machine::unwindCallFrame): (KJS::Machine::throwException): (KJS::Machine::execute): (KJS::Machine::privateExecute):
  • VM/Machine.h:
  • VM/Opcode.h:
  • VM/RegisterID.h: (KJS::RegisterID::RegisterID): (KJS::RegisterID::makeConstant): (KJS::RegisterID::isTemporary):
  • kjs/NodeInfo.h:
  • kjs/Parser.cpp: (KJS::Parser::didFinishParsing):
  • kjs/Parser.h: (KJS::Parser::parse):
  • kjs/grammar.y:
  • kjs/nodes.cpp: (KJS::NullNode::emitCode): (KJS::BooleanNode::emitCode): (KJS::NumberNode::emitCode): (KJS::StringNode::emitCode): (KJS::ArrayNode::emitCode): (KJS::DeleteResolveNode::emitCode): (KJS::DeleteValueNode::emitCode): (KJS::VoidNode::emitCode): (KJS::ConstDeclNode::emitCodeSingle): (KJS::ReturnNode::emitCode): (KJS::ScopeNode::ScopeNode): (KJS::ProgramNode::ProgramNode): (KJS::ProgramNode::create): (KJS::EvalNode::EvalNode): (KJS::EvalNode::create): (KJS::FunctionBodyNode::FunctionBodyNode): (KJS::FunctionBodyNode::create): (KJS::FunctionBodyNode::emitCode):
  • kjs/nodes.h: (KJS::ScopeNode::neededConstants):

LayoutTests:

  • fast/js/constant-count-expected.txt: Added.
  • fast/js/constant-count.html: Added.
  • fast/js/deep-recursion-test.html:
  • fast/js/resources/constant-count.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/VM/CodeGenerator.cpp

    r35533 r35593  
    203203    // FIXME: Move code that modifies the global object to Machine::execute.
    204204   
     205    m_codeBlock->numConstants = programNode->neededConstants();
    205206    m_codeBlock->numVars = 1; // Allocate space for "this"
    206207
     
    263264    , m_lastOpcodeID(op_end)
    264265{
     266    m_codeBlock->numConstants = functionBody->neededConstants();
     267
    265268    const Node::FunctionStack& functionStack = functionBody->functionStack();
    266269    for (size_t i = 0; i < functionStack.size(); ++i) {
     
    307310    , m_lastOpcodeID(op_end)
    308311{
     312    m_codeBlock->numConstants = evalNode->neededConstants();
    309313    m_codeBlock->numVars = 1; // Allocate space for "this"
    310314}
     
    382386
    383387    // Allocate new register ID.
    384     m_temporaries.append(m_temporaries.size());
     388    m_temporaries.append(m_temporaries.size() + m_codeBlock->numConstants);
    385389    m_codeBlock->numTemporaries = max<int>(m_codeBlock->numTemporaries, m_temporaries.size());
    386390    return &m_temporaries.last();
     
    521525}
    522526
    523 unsigned CodeGenerator::addConstant(JSValue* v)
    524 {
    525     pair<JSValueMap::iterator, bool> result = m_jsValueMap.add(v, m_codeBlock->registers.size());
    526     if (result.second) // new entry
    527         m_codeBlock->registers.append(v);
    528 
    529     return result.first->second;
     527RegisterID* CodeGenerator::addConstant(JSValue* v)
     528{
     529    pair<JSValueMap::iterator, bool> result = m_jsValueMap.add(v, m_codeBlock->constantRegisters.size());
     530    if (result.second) {
     531        m_constants.append(m_codeBlock->constantRegisters.size());
     532        m_constants.last().makeConstant();
     533        m_codeBlock->constantRegisters.append(v);
     534        ASSERT(m_codeBlock->constantRegisters.size() <= (unsigned) m_codeBlock->numConstants);
     535        return &m_constants.last();
     536    }
     537
     538    return &m_constants[result.first->second];
     539}
     540
     541unsigned CodeGenerator::addUnexpectedConstant(JSValue* v)
     542{
     543    int index = m_codeBlock->regexps.size();
     544    m_codeBlock->unexpectedConstants.append(v);
     545    return index;
    530546}
    531547
     
    594610RegisterID* CodeGenerator::emitLoad(RegisterID* dst, bool b)
    595611{
    596     emitOpcode(op_load);
    597     instructions().append(dst->index());
    598     instructions().append(addConstant(jsBoolean(b)));
    599     return dst;
     612    return emitLoad(dst, jsBoolean(b));
    600613}
    601614
    602615RegisterID* CodeGenerator::emitLoad(RegisterID* dst, double d)
    603616{
    604     emitOpcode(op_load);
    605     instructions().append(dst->index());
    606     instructions().append(addConstant(jsNumber(globalExec(), d)));
    607     return dst;
     617    return emitLoad(dst, jsNumber(globalExec(), d));
    608618}
    609619
    610620RegisterID* CodeGenerator::emitLoad(RegisterID* dst, JSValue* v)
    611621{
    612     emitOpcode(op_load);
    613     instructions().append(dst->index());
    614     instructions().append(addConstant(v));
     622    RegisterID* constantID = addConstant(v);
     623    if (dst)
     624        return emitMove(dst, constantID);
     625    return constantID;
     626}
     627
     628RegisterID* CodeGenerator::emitUnexpectedLoad(RegisterID* dst, bool b)
     629{
     630    emitOpcode(op_unexpected_load);
     631    instructions().append(dst->index());
     632    instructions().append(addUnexpectedConstant(jsBoolean(b)));
    615633    return dst;
    616634}
     
    11331151    instructions().append(dst->index());
    11341152    instructions().append(static_cast<int>(type));
    1135     instructions().append(addConstant(message));
     1153    instructions().append(addUnexpectedConstant(message));
    11361154    return dst;
    11371155}
Note: See TracChangeset for help on using the changeset viewer.