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

Switch over the compiler to use relative jumps #4443

Closed
mohammadfawaz opened this issue Apr 15, 2023 · 0 comments · Fixed by #4804
Closed

Switch over the compiler to use relative jumps #4443

mohammadfawaz opened this issue Apr 15, 2023 · 0 comments · Fixed by #4804
Assignees
Labels
compiler: codegen Everything to do with IR->ASM, register allocation, etc. enhancement New feature or request
Milestone

Comments

@mohammadfawaz
Copy link
Contributor

mohammadfawaz commented Apr 15, 2023

Once a fuel-core version that supports relative jumps is released, the compiler should switch over to use them, leading to position-independent code (PIC). This is important to support the LDC opcode. See FuelLabs/fuel-specs#451.

@mohammadfawaz mohammadfawaz added enhancement New feature or request compiler: codegen Everything to do with IR->ASM, register allocation, etc. labels Apr 15, 2023
@IGI-111 IGI-111 added this to the October 2023 milestone Jul 6, 2023
vaivaswatha added a commit that referenced this issue Jul 18, 2023
## Description

Switch the compiler to use relative jumps instead of absolute jumps.

1. The function `relocate_control_flow` is now removed. It used to move
basic blocks around in case absolute addresses crossed the easily
addressable boundary. The code movement can then avoid having to load
the address to a register and using indirect jumps. This is unlikely to
happen with relative jumps. But if it does, the existing algorithm
wouldn't work anyway. So we can add a new one when required later.
2. In the case of function call jumps, we use `$pc` to save the return
address for the callee. This is a bit inefficient as it involves 3 extra
computations: `$$reta = ($pc - $is) / 4 + offset_to_return_point`. We
could change this to the following: Since we already have a common
return point for every function, compute the relative offset from that
point to the callee return point statically and use that. We don't have
the infrastructure to do that right now, but it shouldn't be too
difficult an extension.

Fixes #4443
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: codegen Everything to do with IR->ASM, register allocation, etc. enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants