Skip to content

Commit

Permalink
Fix and extend in-place interpreter OSR
Browse files Browse the repository at this point in the history
https://bugs.webkit.org/show_bug.cgi?id=260212
rdar://113919529

Reviewed by Yusuke Suzuki.

Fixed a bug where loop OSR did not trigger in the in-place interpreter after the first iteration because the PC was set to the instruction after the loop, rather than the loop itself. This resolves quicksort-wasm in JS2 performance issues locally.
Added epilogue OSR implementation to the in-place interpreter.

* Source/JavaScriptCore/llint/InPlaceInterpreter.asm:
* Source/JavaScriptCore/runtime/OptionsList.h:
* Source/JavaScriptCore/wasm/WasmIPIntGenerator.cpp:
(JSC::Wasm::IPIntGenerator::addLoop):
* Source/JavaScriptCore/wasm/WasmSlowPaths.cpp:
(JSC::LLInt::WASM_IPINT_EXTERN_CPP_DECL):
* Source/JavaScriptCore/wasm/WasmSlowPaths.h:

Canonical link: https://commits.webkit.org/266927@main
  • Loading branch information
danlliu authored and Constellation committed Aug 15, 2023
1 parent 1705f9a commit 7cada16
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Source/JavaScriptCore/llint/InPlaceInterpreter.asm
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ macro ipintLoopOSR(increment)
.continue:
end

macro ipintEpilogueOSR(increment)
loadp WasmCodeBlock[cfr], ws0
baddis increment, Wasm::IPIntCallee::m_tierUpCounter + Wasm::LLIntTierUpCounter::m_counter[ws0], .continue

move cfr, a1
operationCall(macro() cCall2(_ipint_extern_epilogue_osr) end)
.continue:
end

########################
# In-Place Interpreter #
########################
Expand Down Expand Up @@ -689,6 +698,7 @@ instructionLabel(_end)
advancePC(1)
nextIPIntInstruction()
.ipint_end_ret:
ipintEpilogueOSR(10)
addq MC, PM
uintDispatch()

Expand Down
5 changes: 3 additions & 2 deletions Source/JavaScriptCore/runtime/OptionsList.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,10 @@ bool canUseWebAssemblyFastMemory();
v(Bool, useWebAssemblyTailCalls, false, Normal, "Allow the new instructions from the wasm tail calls spec.") \
v(Bool, useWasmIPInt, false, Normal, "Use the in-place interpereter for WASM instead of LLInt.") \
v(Bool, useWasmIPIntPrologueOSR, true, Normal, "Allow IPInt to tier up during function prologues") \
v(Bool, useWasmIPIntLoopOSR, true, Normal, "Allow IPInt to tier up during function prologues") \
v(Bool, useWasmIPIntLoopOSR, true, Normal, "Allow IPInt to tier up during loop iterations") \
v(Bool, useWasmIPIntEpilogueOSR, true, Normal, "Allow IPInt to tier up during function epilogues") \
v(Bool, wasmIPIntTiersUpToBBQ, true, Normal, "Allow IPInt to tier up to BBQ") \
v(Bool, wasmIPIntTiersUpToOMG, false, Normal, "Allow IPInt to tier up to OMG")
v(Bool, wasmIPIntTiersUpToOMG, true, Normal, "Allow IPInt to tier up to OMG")


enum OptionEquivalence {
Expand Down
6 changes: 2 additions & 4 deletions Source/JavaScriptCore/wasm/WasmIPIntGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -996,12 +996,10 @@ PartialResult WARN_UNUSED_RETURN IPIntGenerator::addLoop(BlockSignature signatur

// Allocate space in metadata
auto size = m_metadata->m_metadata.size();
block.m_pc = m_parser->currentOpcodeStartingOffset() - m_metadata->m_bytecodeOffset;
block.m_mc = size;
m_metadata->addBlankSpace(1);
WRITE_TO_METADATA(m_metadata->m_metadata.data() + size, getCurrentInstructionLength(), uint8_t);
// No -1 because we can just have it directly go to the instruction after
// No point running `loop` since in IPInt it's just a nop
block.m_pc = m_parser->offset() - m_metadata->m_bytecodeOffset;
block.m_mc = m_metadata->m_metadata.size();

// Loop OSR

Expand Down
17 changes: 17 additions & 0 deletions Source/JavaScriptCore/wasm/WasmSlowPaths.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,23 @@ WASM_SLOW_PATH_DECL(epilogue_osr)
WASM_END_IMPL();
}

WASM_IPINT_EXTERN_CPP_DECL(epilogue_osr, CallFrame* callFrame)
{
Wasm::IPIntCallee* callee = IPINT_CALLEE();

if (!shouldJIT(callee)) {
callee->tierUpCounter().deferIndefinitely();
WASM_RETURN_TWO(nullptr, nullptr);
}
if (!Options::useWasmIPIntEpilogueOSR())
WASM_RETURN_TWO(nullptr, nullptr);

dataLogLnIf(Options::verboseOSR(), *callee, ": Entered epilogue_osr with tierUpCounter = ", callee->tierUpCounter());

jitCompileAndSetHeuristics(callee, instance);
WASM_RETURN_TWO(nullptr, nullptr);
}

WASM_SLOW_PATH_DECL(simd_go_straight_to_bbq_osr)
{
UNUSED_PARAM(pc);
Expand Down
1 change: 1 addition & 0 deletions Source/JavaScriptCore/wasm/WasmSlowPaths.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ WASM_IPINT_EXTERN_CPP_HIDDEN_DECL(prologue_osr, CallFrame* callFrame);
WASM_SLOW_PATH_HIDDEN_DECL(loop_osr);
WASM_IPINT_EXTERN_CPP_HIDDEN_DECL(loop_osr, CallFrame* callFrame, uint32_t pc, uint64_t* pl);
WASM_SLOW_PATH_HIDDEN_DECL(epilogue_osr);
WASM_IPINT_EXTERN_CPP_HIDDEN_DECL(epilogue_osr, CallFrame* callFrame);
WASM_SLOW_PATH_HIDDEN_DECL(simd_go_straight_to_bbq_osr);
#endif

Expand Down

0 comments on commit 7cada16

Please sign in to comment.