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

JitArm64: Hardcode fewer registers in EmitBackpatchRoutine #13256

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

JosJuice
Copy link
Member

This cuts down on how much callers have to think about what registers EmitBackpatchRoutine is using. Also, by allocating registers dynamically instead of using a fixed set of registers, we improve codegen in cases where the fixed registers are taken but other registers are free.

(These improvements don't apply to the emitting_routine == true case, where everything still works like before by necessity.)

Preparation for the next commit, which will make EmitBackpatchRoutine
allocate registers on its own. Because the register allocation will
change during the call to EmitBackpatchRoutine, the set of GPRs/FPRs to
push can't be computed prior to the call, so let's compute them during
the call instead.
This cuts down on how much callers have to think about what registers
EmitBackpatchRoutine is using. Also, by allocating registers dynamically
instead of using a fixed set of registers, we improve codegen in cases
where the fixed registers are taken but other registers are free.

(These improvements don't apply to the emitting_routine == true case,
where everything still works like before by necessity.)
When EmitBackpatchRoutine emits slow access code for a load, RS must not
be in scratch_gprs/scratch_fprs if we have memchecks (otherwise the
memcheck exit won't be able to save RS properly), and RS must be in
scratch_gprs/scratch_fprs if we don't have memchecks (otherwise RS will
be restored to the value it had before the load, overwriting the result
of the load). Let's save callers from having to think about this by
embedding the relevant logic inside EmitBackpatchRoutine.
There's no reason why this register should be 64-bit. It always contains
a 32-bit value, since guest addresses are 32-bit.
This is possible now that EmitBackpatchRoutine lets the caller choose
addr register.

Note: The removed MOV is actually traded for one added MOV in farcode.
I'm adding a new function to the register cache called
GetRegWithPreference. If the passed-in register is unlocked, it gets
locked. Otherwise, GetReg is called. The function also has a
GetScopedRegWithPreference variant.

Then, I'm making JitArm64 call this function when allocating an address
register for use with EmitBackpatchRoutine. This way, when register
pressure is low we can use the optimal register, and when register
pressure is high (but not completely full) we can sacrifice a bit of
farcode size for not having to evict a register from the register cache.
@JosJuice JosJuice force-pushed the jitarm64-backpatch-registers branch from 337c0fc to 7417efe Compare December 30, 2024 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant