-
Notifications
You must be signed in to change notification settings - Fork 74
fix: aot traits #2174
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: aot traits #2174
Changes from 2 commits
12526db
ec1bc3b
d7a2979
e596f98
13ce3e2
12f5b6f
c85d74d
264fb3b
f804542
2351865
e6a7bdf
699a1bc
9c80f70
bc2c37e
f9607ef
262adfd
22fbe7b
82ae792
d2ae80e
18a0127
5777172
da98543
c4b03d5
8b75845
e52f204
3ee5d93
0a3a159
26a24b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -87,6 +87,22 @@ pub enum StaticProgramError { | |
| ExecutorNotFound { opcode: VmOpcode }, | ||
| } | ||
|
|
||
| #[cfg(feature = "aot")] | ||
| #[derive(Error, Debug)] | ||
| pub enum AotError { | ||
| #[error("AOT compilation not supported for this opcode")] | ||
| NotSupported, | ||
|
|
||
| #[error("No executor found for opcode {0}")] | ||
| NoExecutorFound(VmOpcode), | ||
|
|
||
| #[error("Invalid instruction format")] | ||
| InvalidInstruction, | ||
|
|
||
| #[error("Other AOT error: {0}")] | ||
| Other(String), | ||
| } | ||
|
|
||
| /// Function pointer for interpreter execution with function signature `(pre_compute, instret, pc, | ||
| /// arg, exec_state)`. The `pre_compute: &[u8]` is a pre-computed buffer of data | ||
| /// corresponding to a single instruction. The contents of `pre_compute` are determined from the | ||
|
|
@@ -154,6 +170,18 @@ pub trait Executor<F> { | |
| ) -> Result<Handler<F, Ctx>, StaticProgramError> | ||
| where | ||
| Ctx: ExecutionCtxTrait; | ||
|
|
||
| #[cfg(feature = "aot")] | ||
| fn supports_aot_for_opcode(&self, opcode: VmOpcode) -> bool { | ||
| false | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "aot")] | ||
| pub trait AotExecutor<F>: Executor<F> { | ||
| /// Generate x86 assembly for the given instruction. Preconditions: Opcode must be supported by | ||
| /// AOT | ||
| fn generate_x86_asm(&self, inst: &Instruction<F>) -> Result<String, AotError>; | ||
| } | ||
|
|
||
| /// Trait for metered execution via a host interpreter. The trait methods provide the methods to | ||
|
|
@@ -189,6 +217,18 @@ pub trait MeteredExecutor<F> { | |
| ) -> Result<Handler<F, Ctx>, StaticProgramError> | ||
| where | ||
| Ctx: MeteredExecutionCtxTrait; | ||
|
|
||
| #[cfg(feature = "aot")] | ||
| fn supports_aot_for_opcode(&self, opcode: VmOpcode) -> bool { | ||
|
||
| false | ||
| } | ||
| } | ||
|
|
||
| #[cfg(feature = "aot")] | ||
| pub trait AotMeteredExecutor<F>: MeteredExecutor<F> { | ||
| /// Generate x86 assembly for the given instruction. Preconditions: Opcode must be supported by | ||
| /// AOT | ||
| fn generate_x86_asm(&self, inst: &Instruction<F>) -> Result<String, AotError>; | ||
| } | ||
|
|
||
| /// Trait for preflight execution via a host interpreter. The trait methods allow execution of | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need
pcto jump to a static label?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can discuss this with @GunaDD as well, but in the current example,
extern_handlerreturns the updated PC value to registerrax, and there is post-processing x86 assembly to determine where to jump next using the jump table. we can continue this convention that it should be on the onus of the generated x86 to write the next PC value torax, and then it should be able to use any type of labelUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it means we need to read the jump table based on
rax, which brings some extra overheads. If you knowpc, for most jumps you can use only 1 instruction to jump intoasm_run_pc_base_<pc>(sry the name might be inaccurate) at compile time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, if thats the case we can pivot so that this function is responsible for handling the updated PC value, and modify the fallback case that uses
extern_handlerto handle PC changes as well for consistencyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a comment to show how generated ASMs look like and what the responsibility is? I feel we are not on the same page on that.
I supposed it generates:
@GunaDD mentioned the jump instruction for the dynamic case is:
However if the jump point can be known at AOT compile time, we only need:
But we need to know the current PC in order to compute
next_pc