Skip to content

Commit

Permalink
Cherry-pick d077f1d. rdar://122689419
Browse files Browse the repository at this point in the history
    [JSC] Enable Megamorphic Cache for enumerator_put_by_val / enumerator_get_by_val in upper tiers
    https://bugs.webkit.org/show_bug.cgi?id=269129
    rdar://122689419

    Reviewed by Mark Lam.

    This patch enables embedded DFG / FTL megamorphic cache for enumerator_put_by_val / enumerator_get_by_val.
    We obtain PutByStatus / GetByStatus, and if it says "this was megamorphic in lower tiers", then we use PutByValMegamorphic / GetByValMegamorphic.

    * Source/JavaScriptCore/bytecode/PutByStatus.cpp:
    (JSC::PutByStatus::computeFromLLInt):
    * Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:
    (JSC::DFG::ByteCodeParser::parseBlock):

    Canonical link: https://commits.webkit.org/274421@main

Identifier: 272448.552@safari-7618.1.15.11-branch
  • Loading branch information
Constellation authored and Dan Robson committed Feb 13, 2024
1 parent 56a875d commit 5013c18
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions Source/JavaScriptCore/bytecode/PutByStatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ PutByStatus PutByStatus::computeFromLLInt(CodeBlock* profiledBlock, BytecodeInde
switch (instruction->opcodeID()) {
case op_put_by_id:
break;
case op_enumerator_put_by_val:
case op_put_by_val:
case op_put_by_val_direct:
return PutByStatus(NoInformation);
Expand Down
22 changes: 22 additions & 0 deletions Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9231,6 +9231,16 @@ void ByteCodeParser::parseBlock(unsigned limit)
}

GetByStatus getByStatus = GetByStatus::computeFor(m_inlineStackTop->m_profiledBlock, m_inlineStackTop->m_baselineMap, m_icContextStack, currentCodeOrigin());
if (getByStatus.isMegamorphic()) {
SpeculatedType prediction = getPrediction();
addVarArgChild(base);
addVarArgChild(propertyName);
addVarArgChild(nullptr); // Leave room for property storage.
Node* getByVal = addToGraph(Node::VarArg, GetByValMegamorphic, OpInfo(arrayMode.asWord()), OpInfo(prediction));
m_exitOK = false; // GetByVal must be treated as if it clobbers exit state, since FixupPhase may make it generic.
set(bytecode.m_dst, getByVal);
NEXT_OPCODE(op_enumerator_get_by_val);
}

// FIXME: Checking for a BadConstantValue causes us to always use the Generic variant if we switched from IndexedMode -> IndexedMode + OwnStructureMode even though that might be fine.
if (!seenModes.containsAny({ JSPropertyNameEnumerator::GenericMode, JSPropertyNameEnumerator::HasSeenOwnStructureModeStructureMismatch })
Expand Down Expand Up @@ -9335,6 +9345,18 @@ void ByteCodeParser::parseBlock(unsigned limit)
}

// FIXME: Checking for a BadConstantValue causes us to always use the Generic variant if we switched from IndexedMode -> IndexedMode + OwnStructureMode even though that might be fine.
PutByStatus putByStatus = PutByStatus::computeFor(m_inlineStackTop->m_profiledBlock, m_inlineStackTop->m_baselineMap, m_icContextStack, currentCodeOrigin());
if (putByStatus.isMegamorphic()) {
addVarArgChild(base);
addVarArgChild(propertyName);
addVarArgChild(value);
addVarArgChild(nullptr); // Leave room for property storage.
addVarArgChild(nullptr); // Leave room for length.
addToGraph(Node::VarArg, PutByValMegamorphic, OpInfo(arrayMode.asWord()), OpInfo(bytecode.m_ecmaMode));
m_exitOK = false; // PutByVal and PutByValDirect must be treated as if they clobber exit state, since FixupPhase may make them generic.
NEXT_OPCODE(op_enumerator_put_by_val);
}

if (!seenModes.containsAny({ JSPropertyNameEnumerator::GenericMode, JSPropertyNameEnumerator::HasSeenOwnStructureModeStructureMismatch })
&& !m_inlineStackTop->m_exitProfile.hasExitSite(m_currentIndex, BadConstantValue)) {
Node* modeTest = addToGraph(SameValue, mode, jsConstant(jsNumber(static_cast<uint8_t>(JSPropertyNameEnumerator::GenericMode))));
Expand Down

0 comments on commit 5013c18

Please sign in to comment.