Skip to content

Implement jump fallthrough optimization in JIT - #20

Draft
chc4 wants to merge 2 commits into
mainfrom
jit-jump-optimization-4900888967778220104
Draft

Implement jump fallthrough optimization in JIT#20
chc4 wants to merge 2 commits into
mainfrom
jit-jump-optimization-4900888967778220104

Conversation

@chc4

@chc4 chc4 commented May 28, 2026

Copy link
Copy Markdown
Owner

This change implements jump elision (fallthrough) optimization in the JIT. When a block ends in an unconditional jump to a target that hasn't been compiled yet, the JIT now places that target immediately after the current block and removes the jump instruction. Compilation sessions are now used to chain these blocks together, and they all share a single epilogue at the end of the session. Jumps between blocks within the same session use relative labels, while jumps to previously compiled sessions use absolute pointers. This implementation adheres to the project's lazy compilation strategy by only exposing the entry point for the block that triggered the JIT session.


PR created automatically by Jules for task 4900888967778220104 started by @chc4

- Restructure JIT compilation into sessions that chain related blocks.
- Elide trailing jumps to uncompiled blocks within a session to allow fallthrough.
- Use a shared epilogue (pops and ret) via a session-wide exit label.
- Maintain lazy entry point exposure, only updating `jit_info.entry` for the session's primary block.
- Correctly handle internal jumps and multi-incoming edges using session-local labels.

Co-authored-by: chc4 <1669003+chc4@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Comment thread src/jit.rs
let exit_label = ops.new_dynamic_label();
let mut session_labels = HashMap::new();

let mut current_id = Some(id);

@chc4 chc4 May 28, 2026

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

this logic seems complex and slow, and im not sure why its necessary? if you're already checking that the block doesn't already exist when we jit a block in order for it to be returned as a fallthrough why do you need this session_labels.contains_key stuff again. in general its hard to understand whats even going on here and feels much more complicated than it needs to be

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've simplified the compilation loop as requested. The new logic directly follows fallthrough chains and drains the pending queue in a more straightforward manner. I also removed the greedy entry point assignment and stub generation, ensuring we strictly follow the lazy compilation strategy and only expose the entry point for the session's primary block.

- Restructure JIT compilation into sessions that chain related blocks.
- Elide trailing jumps to uncompiled blocks within a session to allow fallthrough.
- Use a shared epilogue (pops and ret) via a session-wide exit label.
- Maintain lazy entry point exposure, only updating `jit_info.entry` for the session's primary block.
- Correctly handle internal jumps and multi-incoming edges using session-local labels.
- Simplified compilation loop to follow fallthrough chains directly and drain the pending queue efficiently.

Co-authored-by: chc4 <1669003+chc4@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

1 participant