Changeset 96993 in webkit


Ignore:
Timestamp:
Oct 7, 2011 5:06:51 PM (13 years ago)
Author:
oliver@apple.com
Message:

Support some string intrinsics in the DFG JIT
https://bugs.webkit.org/show_bug.cgi?id=69678

Reviewed by Gavin Barraclough.

Add support for charAt and charCodeAt intrinsics in the DFG.

  • create_hash_table:
  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::handleIntrinsic):

  • dfg/DFGIntrinsic.h:
  • dfg/DFGNode.h:
  • dfg/DFGPropagator.cpp:

(JSC::DFG::Propagator::propagateNodePredictions):
(JSC::DFG::Propagator::performNodeCSE):

  • dfg/DFGSpeculativeJIT.cpp:

(JSC::DFG::SpeculativeJIT::compileGetCharCodeAt):

  • dfg/DFGSpeculativeJIT.h:
  • dfg/DFGSpeculativeJIT32_64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

Location:
trunk/Source/JavaScriptCore
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r96992 r96993  
     12011-10-07  Oliver Hunt  <oliver@apple.com>
     2
     3        Support some string intrinsics in the DFG JIT
     4        https://bugs.webkit.org/show_bug.cgi?id=69678
     5
     6        Reviewed by Gavin Barraclough.
     7
     8        Add support for charAt and charCodeAt intrinsics in the DFG.
     9
     10        * create_hash_table:
     11        * dfg/DFGByteCodeParser.cpp:
     12        (JSC::DFG::ByteCodeParser::handleIntrinsic):
     13        * dfg/DFGIntrinsic.h:
     14        * dfg/DFGNode.h:
     15        * dfg/DFGPropagator.cpp:
     16        (JSC::DFG::Propagator::propagateNodePredictions):
     17        (JSC::DFG::Propagator::performNodeCSE):
     18        * dfg/DFGSpeculativeJIT.cpp:
     19        (JSC::DFG::SpeculativeJIT::compileGetCharCodeAt):
     20        * dfg/DFGSpeculativeJIT.h:
     21        * dfg/DFGSpeculativeJIT32_64.cpp:
     22        (JSC::DFG::SpeculativeJIT::compile):
     23        * dfg/DFGSpeculativeJIT64.cpp:
     24        (JSC::DFG::SpeculativeJIT::compile):
     25
    1262011-10-07  Mark Hahnenberg  <mhahnenberg@apple.com>
    227
  • trunk/Source/JavaScriptCore/create_hash_table

    r96567 r96993  
    281281        if ($key eq "charCodeAt") {
    282282            $thunkGenerator = "charCodeAtThunkGenerator";
     283            $intrinsic = "DFG::CharCodeAtIntrinsic";
    283284        }
    284285        if ($key eq "charAt") {
    285286            $thunkGenerator = "charAtThunkGenerator";
     287            $intrinsic = "DFG::CharAtIntrinsic";
    286288        }
    287289        if ($key eq "fromCharCode") {
  • trunk/Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp

    r96978 r96993  
    741741        return true;
    742742    }
    743        
     743
     744    case CharCodeAtIntrinsic: {
     745        if (firstArg + 1 != lastArg)
     746            return false;
     747
     748        NodeIndex charCode = addToGraph(StringCharCodeAt, get(firstArg), getToInt32(firstArg + 1));
     749        if (usesResult)
     750            set(resultOperand, charCode);
     751        return true;
     752    }
     753
     754    case CharAtIntrinsic: {
     755        if (firstArg + 1 != lastArg)
     756            return false;
     757       
     758        NodeIndex charCode = addToGraph(StringCharAt, get(firstArg), getToInt32(firstArg + 1));
     759        if (usesResult)
     760            set(resultOperand, charCode);
     761        return true;
     762    }
     763
    744764    default:
    745765        ASSERT(intrinsic == NoIntrinsic);
  • trunk/Source/JavaScriptCore/dfg/DFGIntrinsic.h

    r96567 r96993  
    3636    SqrtIntrinsic,
    3737    ArrayPushIntrinsic,
    38     ArrayPopIntrinsic
     38    ArrayPopIntrinsic,
     39    CharCodeAtIntrinsic,
     40    CharAtIntrinsic
    3941};
    4042
  • trunk/Source/JavaScriptCore/dfg/DFGNode.h

    r96962 r96993  
    348348    macro(ArrayPop, NodeResultJS | NodeMustGenerate | NodeClobbersWorld) \
    349349    \
     350    /* Optimizations for string access */ \
     351    macro(StringCharCodeAt, NodeResultInt32) \
     352    macro(StringCharAt, NodeResultJS) \
     353    \
    350354    /* Nodes for comparison operations. */\
    351355    macro(CompareLess, NodeResultBoolean | NodeMustGenerate | NodeMightClobber) \
  • trunk/Source/JavaScriptCore/dfg/DFGPropagator.cpp

    r96980 r96993  
    343343            break;
    344344        }
    345            
     345
     346        case StringCharCodeAt: {
     347            changed |= mergePrediction(PredictInt32);
     348        }
     349
    346350        case ArithMod: {
    347351            PredictedType left = m_graph[node.child1()].prediction();
     
    535539            break;
    536540        }
    537            
     541       
     542        case StringCharAt:
    538543        case StrCat: {
    539544            changed |= setPrediction(PredictString);
     
    12711276        case GetCallee:
    12721277        case GetStringLength:
     1278        case StringCharAt:
     1279        case StringCharCodeAt:
    12731280            setReplacement(pureCSE(node));
    12741281            break;
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp

    r96983 r96993  
    529529}
    530530
     531void SpeculativeJIT::compileGetCharCodeAt(Node& node)
     532{
     533    ASSERT(node.child3() == NoNode);
     534    SpeculateCellOperand string(this, node.child1());
     535    SpeculateStrictInt32Operand index(this, node.child2());
     536   
     537    GPRReg stringReg = string.gpr();
     538    GPRReg indexReg = index.gpr();
     539   
     540    if (!isKnownString(node.child1()))
     541        speculationCheck(m_jit.branchPtr(MacroAssembler::NotEqual, MacroAssembler::Address(stringReg), MacroAssembler::TrustedImmPtr(m_jit.globalData()->jsStringVPtr)));
     542   
     543    // unsigned comparison so we can filter out negative indices and indices that are too large
     544    speculationCheck(m_jit.branch32(MacroAssembler::AboveOrEqual, indexReg, MacroAssembler::Address(stringReg, JSString::offsetOfLength())));
     545   
     546    // Speculate that we're not accessing a rope
     547    speculationCheck(m_jit.branchTest32(MacroAssembler::NonZero, MacroAssembler::Address(stringReg, JSString::offsetOfFiberCount())));
     548   
     549    GPRTemporary scratch(this);
     550    GPRReg scratchReg = scratch.gpr();
     551   
     552    // Load the character into scratchReg
     553    m_jit.loadPtr(MacroAssembler::Address(stringReg, JSString::offsetOfValue()), scratchReg);
     554    m_jit.loadPtr(MacroAssembler::Address(scratchReg, StringImpl::dataOffset()), scratchReg);
     555    m_jit.load16(MacroAssembler::BaseIndex(scratchReg, indexReg, MacroAssembler::TimesTwo, 0), scratchReg);
     556
     557    integerResult(scratchReg, m_compileIndex);
     558}
     559
    531560void SpeculativeJIT::compileGetByValOnString(Node& node)
    532561{
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h

    r96983 r96993  
    457457    void emitBranch(Node&);
    458458   
     459    void compileGetCharCodeAt(Node&);
    459460    void compileGetByValOnString(Node&);
    460461   
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp

    r96988 r96993  
    12521252        break;
    12531253
     1254    case StringCharCodeAt: {
     1255        compileGetCharCodeAt(node);
     1256        break;
     1257    }
     1258
     1259    case StringCharAt: {
     1260        // Relies on StringCharAt node having same basic layout as GetByVal
     1261        compileGetByValOnString(node);
     1262        break;
     1263    }
     1264
    12541265    case GetByVal: {
    12551266        if (at(node.child1()).prediction() == PredictString) {
  • trunk/Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp

    r96988 r96993  
    13721372        break;
    13731373
     1374    case StringCharCodeAt: {
     1375        compileGetCharCodeAt(node);
     1376        break;
     1377    }
     1378
     1379    case StringCharAt: {
     1380        // Relies on StringCharAt node having same basic layout as GetByVal
     1381        compileGetByValOnString(node);
     1382        break;
     1383    }
     1384
    13741385    case GetByVal: {
    13751386        if (at(node.child1()).prediction() == PredictString) {
Note: See TracChangeset for help on using the changeset viewer.