bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.4k stars 1.3k forks source link

[meta] Migrate instruction selection to ISLE #3713

Closed fitzgen closed 2 years ago

fitzgen commented 2 years ago

This is a meta issue to track the migration from hand-written instruction selection and lowering over to using the ISLE DSL.

As you port lowering for a clif opcode over to ISLE, please check the associated box (or leave a comment, if you don't have edit permissions and I or someone else can check the box for you). Hopefully this will help us focus our porting efforts and finish the migration in a timely manner, as well as avoid stepping on each others toes by having two people accidentally port the same opcode lowerings.

cc @alexcrichton @cfallin @abrown @jlb6740 @uweigand @sparker-arm @akirilov-arm

x86_64 -- DONE!

* [x] `Opcode::Clz` * [x] `Opcode::Ctz` * [x] `Opcode::Popcnt` * [x] `Opcode::Bitrev` * [x] `Opcode::IsNull` * [x] `Opcode::IsInvalid` * [x] `Opcode::Uextend` * [x] `Opcode::Sextend` * [x] `Opcode::Breduce` * [x] `Opcode::Bextend` * [x] `Opcode::Ireduce` * [x] `Opcode::Bint` * [x] `Opcode::Icmp` * [x] `Opcode::Fcmp` * [x] `Opcode::FallthroughReturn` * [x] `Opcode::Return` * [x] `Opcode::Call` * [x] `Opcode::CallIndirect` * [x] `Opcode::Debugtrap` * [x] `Opcode::Trapif` * [x] `Opcode::Trapff` * [x] `Opcode::WideningPairwiseDotProductS` * [x] `Opcode::Fadd` * [x] `Opcode::Fsub` * [x] `Opcode::Fmul` * [x] `Opcode::Fdiv` * [x] `Opcode::Fmin` * [x] `Opcode::Fmax` * [x] `Opcode::FminPseudo` * [x] `Opcode::FmaxPseudo` * [x] `Opcode::Sqrt` * [x] `Opcode::Fpromote` * [x] `Opcode::FvpromoteLow` * [x] `Opcode::Fdemote` * [x] `Opcode::Fvdemote` * [x] `Opcode::FcvtFromSint` * [x] `Opcode::FcvtLowFromSint` * [x] `Opcode::FcvtFromUint` * [x] `Opcode::FcvtToUint` * [x] `Opcode::FcvtToUintSat` * [x] `Opcode::FcvtToSint` * [x] `Opcode::FcvtToSintSat` * [x] `Opcode::IaddPairwise` * [x] `Opcode::UwidenHigh` * [x] `Opcode::UwidenLow` * [x] `Opcode::SwidenHigh` * [x] `Opcode::SwidenLow` * [x] `Opcode::Snarrow` * [x] `Opcode::Unarrow` * [x] `Opcode::Bitcast` * [x] `Opcode::Fabs` * [x] `Opcode::Fneg` * [x] `Opcode::Fcopysign` * [x] `Opcode::Ceil` * [x] `Opcode::Floor` * [x] `Opcode::Nearest` * [x] `Opcode::Trunc` * [x] `Opcode::Load` * [x] `Opcode::Uload8` * [x] `Opcode::Sload8` * [x] `Opcode::Uload16` * [x] `Opcode::Sload16` * [x] `Opcode::Uload32` * [x] `Opcode::Sload32` * [x] `Opcode::Sload8x8` * [x] `Opcode::Uload8x8` * [x] `Opcode::Sload16x4` * [x] `Opcode::Uload16x4` * [x] `Opcode::Sload32x2` * [x] `Opcode::Uload32x2` * [x] `Opcode::Store` * [x] `Opcode::Istore8` * [x] `Opcode::Istore16` * [x] `Opcode::Istore32` * [x] `Opcode::AtomicRmw` * [x] `Opcode::AtomicCas` * [x] `Opcode::AtomicLoad` * [x] `Opcode::AtomicStore` * [x] `Opcode::Fence` * [x] `Opcode::FuncAddr` * [x] `Opcode::SymbolValue` * [x] `Opcode::StackAddr` * [x] `Opcode::Select` * [x] `Opcode::Selectif` * [x] `Opcode::SelectifSpectreGuard` * [x] `Opcode::Udiv` * [x] `Opcode::Urem` * [x] `Opcode::Sdiv` * [x] `Opcode::Srem` * [x] `Opcode::Umulhi` * [x] `Opcode::Smulhi` * [x] `Opcode::GetPinnedReg` * [x] `Opcode::SetPinnedReg` * [x] `Opcode::Vconst` * [x] `Opcode::RawBitcast` * [x] `Opcode::Shuffle` * [x] `Opcode::Swizzle` * [x] `Opcode::Insertlane` * [x] `Opcode::Extractlane` * [x] `Opcode::ScalarToVector` * [x] `Opcode::Splat` * [x] `Opcode::VanyTrue` * [x] `Opcode::VallTrue` * [x] `Opcode::VhighBits` * [x] `Opcode::Iconcat` * [x] `Opcode::Isplit` * [x] `Opcode::TlsValue` * [x] `Opcode::SqmulRoundSat` * [x] `Opcode::Uunarrow`

aarch64 -- DONE!

* [x] `Opcode::Load` * [x] `Opcode::Uload8` * [x] `Opcode::Sload8` * [x] `Opcode::Uload16` * [x] `Opcode::Sload16` * [x] `Opcode::Uload32` * [x] `Opcode::Sload32` * [x] `Opcode::Sload8x8` * [x] `Opcode::Uload8x8` * [x] `Opcode::Sload16x4` * [x] `Opcode::Uload16x4` * [x] `Opcode::Sload32x2` * [x] `Opcode::Uload32x2` * [x] `Opcode::Store` * [x] `Opcode::Istore8` * [x] `Opcode::Istore16` * [x] `Opcode::Istore32` * [x] `Opcode::StackAddr` * [x] `Opcode::AtomicRmw` * [x] `Opcode::AtomicCas` * [x] `Opcode::AtomicLoad` * [x] `Opcode::AtomicStore` * [x] `Opcode::Fence` * [x] `Opcode::Select` * [x] `Opcode::Selectif` * [x] `Opcode::SelectifSpectreGuard` * [x] `Opcode::Bitselect` * [x] `Opcode::Vselect` * [x] `Opcode::Trueif` * [x] `Opcode::Trueff` * [x] `Opcode::IsNull` * [x] `Opcode::IsInvalid` * [x] `Opcode::Copy` * [x] `Opcode::Breduce` * [x] `Opcode::Ireduce` * [x] `Opcode::Bextend` * [x] `Opcode::Bmask` * [x] `Opcode::Bint` * [x] `Opcode::Bitcast` * [x] `Opcode::FallthroughReturn` * [x] `Opcode::Return` * [x] `Opcode::Icmp` * [x] `Opcode::Fcmp` * [x] `Opcode::Debugtrap` * [x] `Opcode::Trap` * [x] `Opcode::ResumableTrap` * [x] `Opcode::Trapif` * [x] `Opcode::Trapff` * [x] `Opcode::FuncAddr` * [x] `Opcode::SymbolValue` * [x] `Opcode::Call` * [x] `Opcode::CallIndirect` * [x] `Opcode::GetPinnedReg` * [x] `Opcode::SetPinnedReg` * [x] `Opcode::Vconst` * [x] `Opcode::RawBitcast` * [x] `Opcode::Extractlane` * [x] `Opcode::Insertlane` * [x] `Opcode::Splat` * [x] `Opcode::ScalarToVector` * [x] `Opcode::VallTrue` * [x] `Opcode::VanyTrue` * [x] `Opcode::VhighBits` * [x] `Opcode::Shuffle` * [x] `Opcode::Swizzle` * [x] `Opcode::Isplit` * [x] `Opcode::Iconcat` * [x] `Opcode::Imax` * [x] `Opcode::Umax` * [x] `Opcode::Umin` * [x] `Opcode::Imin` * [x] `Opcode::IaddPairwise` * [x] `Opcode::WideningPairwiseDotProductS` * [x] `Opcode::Fadd` * [x] `Opcode::Fsub` * [x] `Opcode::Fmul` * [x] `Opcode::Fdiv` * [x] `Opcode::Fmin` * [x] `Opcode::Fmax` * [x] `Opcode::FminPseudo` * [x] `Opcode::FmaxPseudo` * [x] `Opcode::Sqrt` * [x] `Opcode::Fneg` * [x] `Opcode::Fabs` * [x] `Opcode::Fpromote` * [x] `Opcode::Fdemote` * [x] `Opcode::Ceil` * [x] `Opcode::Floor` * [x] `Opcode::Trunc` * [x] `Opcode::Nearest` * [x] `Opcode::Fma` * [x] `Opcode::Fcopysign` * [x] `Opcode::FcvtToUint` * [x] `Opcode::FcvtToSint` * [x] `Opcode::FcvtFromUint` * [x] `Opcode::FcvtFromSint` * [x] `Opcode::FcvtToUintSat` * [x] `Opcode::FcvtToSintSat` * [x] `Opcode::IaddIfcout` * [x] `Opcode::Iabs` * [x] `Opcode::AvgRound` * [x] `Opcode::Snarrow` * [x] `Opcode::Unarrow` * [x] `Opcode::Uunarrow` * [x] `Opcode::SwidenLow` * [x] `Opcode::SwidenHigh` * [x] `Opcode::UwidenLow` * [x] `Opcode::UwidenHigh` * [x] `Opcode::TlsValue` * [x] `Opcode::SqmulRoundSato` * [x] `Opcode::FcvtLowFromSint` * [x] `Opcode::FvpromoteLow` * [x] `Opcode::Fvdemote` * [x] Branches

s390x -- DONE!

* [x] Calls * [x] Returns * [x] Traps * [x] Branches
github-actions[bot] commented 2 years ago

Subscribe to Label Action

cc @cfallin, @fitzgen

This issue or pull request has been labeled: "isle" Thus the following users have been cc'd because of the following labels: * cfallin: isle * fitzgen: isle To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file. [Learn more.](https://github.com/bytecodealliance/subscribe-to-label-action)
uweigand commented 2 years ago

I'm looking into the remaining issues on s390x. Specifically, I already have patches for branches and traps, which I'll submit shortly. For calls and returns, the issues really are cross-platform - I suspect we'll have to move those to ISLE for all targets at the same time ...

For reference, here's the list of issues I've noticed:

sparker-arm commented 2 years ago

I'm picking up AtomicRMW for AArch64.

cfallin commented 2 years ago

I'm going to start working down the x86_64 opcode list from the top -- clz/btz/popcnt/bitrev to start, I think. @abrown let me know what your next plans are and we can make sure not to duplicate work!

abrown commented 2 years ago

Just for the record, I am working on x64's icmp, fcmp and select instructions.

jlb6740 commented 2 years ago

Thanks @abrown. @abrown @cfallin for the record, I'd like to get started with something simple. I'd like to claim fabs and fneg.

abrown commented 2 years ago

I'm looking at loads and stores next, FYI.

sparker-arm commented 2 years ago

I'm picking up AtomicCas and IaddPairwise for aarch64.

cfallin commented 2 years ago

@abrown are you still planning to take a look at stores on x64? I'm happy to take those first thing Mon if you haven't started yet, as I've got some isel improvements I want to do that involve them (load-op-store patterns). If you're close then no worries though!

abrown commented 2 years ago

Well, I haven't started stores yet... so take them if you want to!

sparker-arm commented 2 years ago

I've also picked up snarrow, unarrow, uunarrow and fvdemote.

sparker-arm commented 2 years ago

I've started on icmp, which doesn't look like it's going to be fun!

elliottt commented 2 years ago

I've finished up translating icmp for x64

uweigand commented 2 years ago

Transition to ISLE is now complete for s390x. All opcodes are now lowered via ISLE.

sparker-arm commented 2 years ago

I've made a PR for the aarch64 min/max instructions

afonso360 commented 2 years ago

Last week we also merged bmask/bextend/ireduce/breduce for aarch64

dheaton-arm commented 2 years ago

I've picked up iabs for aarch64.

dheaton-arm commented 2 years ago

And also picked up swizzle and scalartovector.

Edit: also planning to do fadd down to fma.

elliottt commented 2 years ago

I'm working on finishing the x64 migration to ISLE. Feel free to grab instructions if you'd like to work on them, otherwise I'll continue working down the list.

cfallin commented 2 years ago

@dheaton-arm I'm planning to help push the aarch64 work to completion; I'm hoping to tackle some of the trickier remaining ones (loads and stores, with amode lowering; calls; branches; icmp/fcmp and flags users). Is that OK or have you already started on some of these?

dheaton-arm commented 2 years ago

I've already started on icmp and fcmp, but everything you've mentioned before those should be fine.

akirilov-arm commented 2 years ago

@cfallin I have an upcoming patch that moves the AMode enum definition to ISLE, but I don't plan to touch the actual lowering rules for loads and stores. We already have the amode helper in ISLE, so the latter bit should be doable without waiting for my patch to land (of course, AMode lowering itself would depend on it).

My patch changes quite a lot of code because, as far as I can tell, enum definitions in ISLE always result in enums with named fields, while the existing AMode enum has unnamed fields.

cfallin commented 2 years ago

OK great, I'll take loads/stores themselves, calls, and branches. Lowering of flags-using instructions will intersect with how we do icmp/fcmp so I'll hold off on those. Thanks!

My patch changes quite a lot of code because, as far as I can tell, enum definitions in ISLE always result in enums with named fields, while the existing AMode enum has unnamed fields.

Yep, but there's no fundamental reason for that, it was just a "build it as we need it" sort of thing. We could look at supporting unnamed-field enum variants if it's simpler; it would probably be a 1-2 day refactor.

cfallin commented 2 years ago

Put up PRs for call/ret and loads/stores today; the remaining instructions on aarch64 that don't depend on flags or pattern-matching with icmp/fcmp somehow are:

I'm happy to do all of these tomorrow, unless someone else objects or has partial work here, then I can do the branch and flags-related ones (trueif/trueff, selectif/selectff/select, brif/brff/brz/brnz) once @dheaton-arm 's icmp/fcmp work is done.

elliottt commented 2 years ago

The x86_64 backend has been migrated to ISLE :tada:

dheaton-arm commented 2 years ago

I'm happy to do all of these tomorrow, unless someone else objects or has partial work here, then I can do the branch and flags-related ones (trueif/trueff, selectif/selectff/select, brif/brff/brz/brnz) once @dheaton-arm 's icmp/fcmp work is done.

@cfallin Just as a heads up, after my icmp patch I've been working on true{if,ff} and select{_,if,if_spectreguard}. I haven't started on the br* ops though. :)

cfallin commented 2 years ago

@dheaton-arm great! I shifted over to some regalloc semantics cleanup work but I can come back and do br* ops next, likely Thu or Fri, unless you want to claim then before then!

dheaton-arm commented 2 years ago

@dheaton-arm great! I shifted over to some regalloc semantics cleanup work but I can come back and do br* ops next, likely Thu or Fri, unless you want to claim then before then!

I'm starting on the branch ops now, assuming you haven't yet. (Starting with jump and br_icmp..brff.)

cfallin commented 2 years ago

@dheaton-arm that sounds great; I didn't get to it last week as the regalloc stuff took longer than expected. Please feel free to grab all the branch ops and let me know if you need any help with any of the infra for that!

dheaton-arm commented 2 years ago

The AArch64 backend has now been fully ported to ISLE.

fitzgen commented 2 years ago

Unless I'm missing something, that means we can close this issue! Thanks so much to everyone who helped make this migration happen!

cfallin commented 2 years ago

Thanks so much @dheaton-arm and other Arm folks (@akirilov-arm, @sparker-arm) for your contributions to this effort! It is great that we finally have everything in the DSL; this is going to enable us to make a bunch more improvements in the future, and really does help a lot.