Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix entry tier-up SIMD check in BBQ baseline JIT #10383

Conversation

ddegazio
Copy link
Contributor

@ddegazio ddegazio commented Feb 20, 2023

f6adb76

Fix entry tier-up SIMD check in BBQ baseline JIT
https://bugs.webkit.org/show_bug.cgi?id=252590
rdar://105689397

Currently, the new WebAssembly BBQ baseline JIT always passes false for the isSIMD
parameter when calling into the OMG tier-up trigger thunk. This patch makes it so
we track whether the function is a SIMD function using notifyFunctionUsesSIMD(),
and pass that into the thunk generator, ensuring we preserve any SIMD registers
used to pass arguments to the function.

Reviewed by Yusuke Suzuki.

* Source/JavaScriptCore/wasm/WasmBBQJIT.cpp:
(JSC::Wasm::BBQJIT::emitEntryTierUpCheck):
(JSC::Wasm::BBQJIT::notifyFunctionUsesSIMD):

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

701f658

Misc iOS, tvOS & watchOS macOS Linux Windows
βœ… πŸ§ͺ style   πŸ›  ios   πŸ›  mac   πŸ›  wpe   πŸ›  wincairo
  πŸ›  ios-sim βœ… πŸ›  mac-AS-debug   πŸ›  gtk
βœ… πŸ§ͺ webkitperl   πŸ§ͺ ios-wk2   πŸ§ͺ api-mac   πŸ§ͺ gtk-wk2
  πŸ§ͺ api-ios   πŸ§ͺ mac-wk1   πŸ§ͺ api-gtk
  πŸ›  πŸ§ͺ jsc   πŸ›  tv   πŸ§ͺ mac-wk2   πŸ›  jsc-armv7
  πŸ›  πŸ§ͺ jsc-arm64   πŸ›  tv-sim   πŸ§ͺ mac-AS-debug-wk2   πŸ§ͺ jsc-armv7-tests
  πŸ›  watch   πŸ§ͺ mac-wk2-stress   πŸ›  jsc-mips
  πŸ›  watch-sim   πŸ§ͺ jsc-mips-tests
βœ… πŸ›  πŸ§ͺ unsafe-merge

@ddegazio ddegazio requested a review from a team as a code owner February 20, 2023 20:40
@ddegazio ddegazio self-assigned this Feb 20, 2023
@ddegazio ddegazio added the WebAssembly For bugs in JavaScript WebAssembly label Feb 20, 2023
@@ -5733,13 +5733,13 @@ class BBQJIT {
Jump tierUp = m_jit.branchAdd32(CCallHelpers::PositiveOrZero, TrustedImm32(TierUpCount::functionEntryIncrement()), Address(m_scratchGPR));
MacroAssembler::Label tierUpResume = m_jit.label();
auto functionIndex = m_functionIndex;
addLatePath([tierUp, tierUpResume, functionIndex](BBQJIT&, CCallHelpers& jit) {
bool isSIMD = m_isSIMD;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should get this when late path is executed. notifyFunctionUsesSIMD is not called yet when emitEntryTierUpCheck is called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be called before addTopLevel, so it'll be true if any of our arguments or locals are SIMD (which I think is all we need to handle entry tier-up correctly?). But I do agree it's a better, less fragile solution to move the capture (although capturing members is a pain). I'll fix it up.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is possible that body can include SIMD operations and it generates V128 temp (not local).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be resolved in the latest push!

tierUp.link(&jit);
jit.move(TrustedImm32(functionIndex), GPRInfo::argumentGPR1);
MacroAssembler::Call call = jit.nearCall();
jit.jump(tierUpResume);

bool isSIMD = false; // TODO: Support SIMD
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, here, let's get m_isSIMD from BBQJIT.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So,

bool isSIMD = generator.m_isSIMD;

and capture this bool in jit.addLinkTask's lambda.
generator should be BBQJIT& which is passed to addLatePath's lambda.

@ddegazio ddegazio force-pushed the eng/Fix-entry-tier-up-SIMD-check-in-BBQ-baseline-JIT branch from 10436be to 44c6953 Compare February 20, 2023 20:50
Comment on lines 5742 to 5743
jit.addLinkTask([=, this] (LinkBuffer& linkBuffer) {
MacroAssembler::repatchNearCall(linkBuffer.locationOfNearCall<NoPtrTag>(call), CodeLocationLabel<JITThunkPtrTag>(Thunks::singleton().stub(triggerOMGEntryTierUpThunkGenerator(this->m_isSIMD)).code()));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we cannot use this in LinkTask since BBQJIT is already destroyed at that time.
So, see https://github.com/WebKit/WebKit/pull/10383/files#r1112305847, let's get isSIMD at that time, and pass it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good catch! Sorry, makes sense.

@@ -5733,15 +5733,14 @@ class BBQJIT {
Jump tierUp = m_jit.branchAdd32(CCallHelpers::PositiveOrZero, TrustedImm32(TierUpCount::functionEntryIncrement()), Address(m_scratchGPR));
MacroAssembler::Label tierUpResume = m_jit.label();
auto functionIndex = m_functionIndex;
addLatePath([tierUp, tierUpResume, functionIndex](BBQJIT&, CCallHelpers& jit) {
addLatePath([tierUp, tierUpResume, functionIndex, this](BBQJIT&, CCallHelpers& jit) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of capturing this, use BBQJIT&'s parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably best. Added it in the latest push.

@ddegazio ddegazio force-pushed the eng/Fix-entry-tier-up-SIMD-check-in-BBQ-baseline-JIT branch from 44c6953 to 701f658 Compare February 20, 2023 21:02
Copy link
Member

@Constellation Constellation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r=me

@Constellation Constellation added the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Feb 20, 2023
@Constellation
Copy link
Member

Land it since new BBQ is not tested yet.

https://bugs.webkit.org/show_bug.cgi?id=252590
rdar://105689397

Currently, the new WebAssembly BBQ baseline JIT always passes false for the isSIMD
parameter when calling into the OMG tier-up trigger thunk. This patch makes it so
we track whether the function is a SIMD function using notifyFunctionUsesSIMD(),
and pass that into the thunk generator, ensuring we preserve any SIMD registers
used to pass arguments to the function.

Reviewed by Yusuke Suzuki.

* Source/JavaScriptCore/wasm/WasmBBQJIT.cpp:
(JSC::Wasm::BBQJIT::emitEntryTierUpCheck):
(JSC::Wasm::BBQJIT::notifyFunctionUsesSIMD):

Canonical link: https://commits.webkit.org/260562@main
@webkit-early-warning-system webkit-early-warning-system force-pushed the eng/Fix-entry-tier-up-SIMD-check-in-BBQ-baseline-JIT branch from 701f658 to f6adb76 Compare February 20, 2023 21:16
@webkit-early-warning-system webkit-early-warning-system merged commit f6adb76 into WebKit:main Feb 20, 2023
@webkit-commit-queue
Copy link
Collaborator

Committed 260562@main (f6adb76): https://commits.webkit.org/260562@main

Reviewed commits have been landed. Closing PR #10383 and removing active labels.

@webkit-commit-queue webkit-commit-queue removed the unsafe-merge-queue Applied to send a pull request to merge-queue, but skip building and testing label Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebAssembly For bugs in JavaScript WebAssembly
Projects
None yet
4 participants