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

Parse the AOT IR at compile-time #1089

Open
ltratt opened this issue Apr 5, 2024 · 3 comments
Open

Parse the AOT IR at compile-time #1089

ltratt opened this issue Apr 5, 2024 · 3 comments
Assignees

Comments

@ltratt
Copy link
Contributor

ltratt commented Apr 5, 2024

I'm not quite sure how much time it takes us to parse the AOT IR in (with deku), so this may be a low priority thing --- but we can almost certainly reduce the run-time ART IR "parse time" cost to zero.

At the moment every time we run a yk interpreter, we use deku to parse the AOT IR into Rust structs. Instead of this, we can probably do the deku phase at compile-time (which might mean "link-time"). In essence, each struct in aot_ir.rs would be both deku-fied and serde-fied e.g.:

#[deku_derive(DekuRead)]
#[derive(Deserialize, Serialize)]
struct S { ... }

At compile-time/link-time, we would read in all the IR serialised by ykllvm, probably slurping it straight out of an executable. We'd then use deku to parse that data into struct instances, and then use serde to deserialise things back into the executable. At run-time we would then use serde's zero-copy to reference the data in the read-only part of the executable without ever parsing/copying anything.

@vext01
Copy link
Contributor

vext01 commented Apr 5, 2024

I wonder if there's a zero copy serialisation format with implementations in both C++ and Rust?

@ltratt
Copy link
Contributor Author

ltratt commented Apr 5, 2024

I wonder if there's a zero copy serialisation format with implementations in both C++ and Rust?

I think that would be hard, in the sense that you'd probably end up with some very non-idiomatic Rust structs (since C++ would probably dominate). It would also mean rewriting more of our code, whereas I think the approach I'm suggesting might only take a very simple Rust program that opens an executable, imports yk, and that's about it.

@ltratt
Copy link
Contributor Author

ltratt commented Apr 5, 2024

Good news: a quick experiment suggests that you can do things like:

#[deku_derive(DekuRead)]
#[derive(Clone, Copy, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub(crate) struct FuncIdx(usize);
index!(FuncIdx);

and it works. I haven't pushed this all the way through, but I think this means this will end up being fairly easy. My guess is that using something like goblin to read the executable, slurp in the existing "ykllvm.yk_ir section and deku -> serde it, won't be too difficult.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants