forked from bytecodealliance/wasmtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pulley: Implement interpreter-to-host calls
This commit is an initial stab at implementing interpreter-to-host communication in Pulley. The basic problem is that Pulley needs the ability to call back into Wasmtime to implement tasks such as `memory.grow`, imported functions, etc. For native platforms this is a simple `call_indirect` operation in Cranelift but the story for Pulley must be different because it's effectively switching from interpreted code to native code. The initial idea for this in bytecodealliance#9651 is replaced here and looks mostly similar but with a few changes. The overall structure of how this works is: * A new `call_indirect_host` opcode is added to Pulley. * Function signatures that can be called from Pulley bytecode are statically enumerated at build-time. * This enables the implementation of `call_indirect_host` to take an immediate of which signature is being used and cast the function pointer to the right type. * A new pulley-specific relocation is added to Cranelift for this opcode. * `RelocDistance::Far` calls to a name trigger the use of `call_indirect_host`. * The relocation is filled in by Wasmtime after compilation where the signature number is inserted. * A new `NS_*` value for user-function namespaces is reserved in `wasmtime-cranelift` for this new namespace of functions. * Code generation for Pulley in `wasmtime-cranelift` now has Pulley-specific handling of the wasm-to-host transition where all previous `call_indirect` instructions are replaced with a call to a "backend intrinsic" which gets lowered to a `call_indirect_host`. Note that most of this still isn't hooked up everywhere in Wasmtime. That means that the testing here is pretty light at this time. It'll require a fair bit more work to get everything fully integrated from Wasmtime in Pulley. This is expected to be one of the significant remaining chunks of work and should help unblock future testing (or make those diffs smaller ideally).
- Loading branch information
1 parent
60ab850
commit 0ea4d86
Showing
20 changed files
with
400 additions
and
61 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
cranelift/filetests/filetests/isa/pulley64/call_indirect_host.clif
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
test compile precise-output | ||
target pulley64 | ||
|
||
function %call_indirect_host() { | ||
fn0 = u10:0() system_v | ||
block0: | ||
call fn0() | ||
return | ||
} | ||
|
||
; VCode: | ||
; x30 = xconst8 -16 | ||
; x27 = xadd32 x27, x30 | ||
; store64 sp+8, x28 // flags = notrap aligned | ||
; store64 sp+0, x29 // flags = notrap aligned | ||
; x29 = xmov x27 | ||
; block0: | ||
; indirect_call_host CallInfo { dest: User(userextname0), uses: [], defs: [], clobbers: PRegSet { bits: [65535, 65279, 4294967295, 0] }, callee_conv: SystemV, caller_conv: Fast, callee_pop_size: 0 } | ||
; x28 = load64_u sp+8 // flags = notrap aligned | ||
; x29 = load64_u sp+0 // flags = notrap aligned | ||
; x30 = xconst8 16 | ||
; x27 = xadd32 x27, x30 | ||
; ret | ||
; | ||
; Disassembled: | ||
; 0: 14 1e f0 xconst8 spilltmp0, -16 | ||
; 3: 18 7b 7b xadd32 sp, sp, spilltmp0 | ||
; 6: 32 1b 08 1c store64_offset8 sp, 8, lr | ||
; a: 30 1b 1d store64 sp, fp | ||
; d: 11 1d 1b xmov fp, sp | ||
; 10: 43 03 00 00 call_indirect_host 0 | ||
; 14: 2b 1c 1b 08 load64_offset8 lr, sp, 8 | ||
; 18: 28 1d 1b load64 fp, sp | ||
; 1b: 14 1e 10 xconst8 spilltmp0, 16 | ||
; 1e: 18 7b 7b xadd32 sp, sp, spilltmp0 | ||
; 21: 00 ret | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.