Skip to content

Commit

Permalink
[JSC] Simplify resolve_scope for ClosureVar
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=275671
rdar://130166983

Reviewed by Justin Michaud.

Due to profiled result, we already know local scope depth at this point.
Emit sequence of load instead of loop for smaller local scope depth.

* Source/JavaScriptCore/jit/JITPropertyAccess.cpp:
(JSC::JIT::emit_op_resolve_scope):

Canonical link: https://commits.webkit.org/280191@main
  • Loading branch information
Constellation committed Jun 20, 2024
1 parent 2e6697f commit 2cf423a
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions Source/JavaScriptCore/jit/JITPropertyAccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,13 +946,18 @@ void JIT::emit_op_resolve_scope(const JSInstruction* currentInstruction)
else {
emitGetVirtualRegisterPayload(scope, scopeGPR);
if (profiledResolveType == ClosureVar) {
load32FromMetadata(bytecode, OpResolveScope::Metadata::offsetOfLocalScopeDepth(), scratch1GPR);
static_assert(scopeGPR == returnValueGPR);
Jump done = branchTest32(Zero, scratch1GPR);
auto loop = label();
loadPtr(Address(returnValueGPR, JSScope::offsetOfNext()), returnValueGPR);
branchSub32(NonZero, scratch1GPR, TrustedImm32(1), scratch1GPR).linkTo(loop, this);
done.link(this);
unsigned localScopeDepth = bytecode.metadata(m_profiledCodeBlock).m_localScopeDepth;
if (localScopeDepth < 8) {
for (unsigned index = 0; index < localScopeDepth; ++index)
loadPtr(Address(returnValueGPR, JSScope::offsetOfNext()), returnValueGPR);
} else {
ASSERT(localScopeDepth >= 8);
load32FromMetadata(bytecode, OpResolveScope::Metadata::offsetOfLocalScopeDepth(), scratch1GPR);
auto loop = label();
loadPtr(Address(returnValueGPR, JSScope::offsetOfNext()), returnValueGPR);
branchSub32(NonZero, scratch1GPR, TrustedImm32(1), scratch1GPR).linkTo(loop, this);
}
} else {
uint32_t metadataOffset = m_profiledCodeBlock->metadataTable()->offsetInMetadataTable(bytecode);
addPtr(TrustedImm32(metadataOffset), s_metadataGPR, metadataGPR);
Expand Down

0 comments on commit 2cf423a

Please sign in to comment.