commit 7a3f53369269d48cb64697322f23e4c9fa00cb4b
parent d7f8a904ac59e2fa627cc799d990f8cbc8f3251d
Author: André Bargull <andre.bargull@gmail.com>
Date: Fri, 17 Oct 2025 11:25:42 +0000
Bug 1992993 - Part 5: Avoid running out of registers in branchWithCode. r=spidermonkey-reviewers,iain
Pass an optional scratch register to avoid running out of registers.
This is a regression from bug 1988679.
Differential Revision: https://phabricator.services.mozilla.com/D267793
Diffstat:
3 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/js/src/jit/mips-shared/MacroAssembler-mips-shared.cpp b/js/src/jit/mips-shared/MacroAssembler-mips-shared.cpp
@@ -952,7 +952,8 @@ void MacroAssemblerMIPSShared::ma_b(Register lhs, Register rhs, Label* label,
UseScratchRegisterScope temps(*this);
Register scratch = temps.Acquire();
Condition cond = ma_cmp(scratch, lhs, rhs, c);
- asMasm().branchWithCode(getBranchCode(scratch, cond), label, jumpKind);
+ asMasm().branchWithCode(getBranchCode(scratch, cond), label, jumpKind,
+ scratch);
} break;
}
}
@@ -979,7 +980,8 @@ void MacroAssemblerMIPSShared::ma_b(Register lhs, Imm32 imm, Label* label,
break;
default:
Condition cond = ma_cmp(scratch, lhs, imm, c);
- asMasm().branchWithCode(getBranchCode(scratch, cond), label, jumpKind);
+ asMasm().branchWithCode(getBranchCode(scratch, cond), label, jumpKind,
+ scratch);
}
}
}
diff --git a/js/src/jit/mips64/MacroAssembler-mips64.cpp b/js/src/jit/mips64/MacroAssembler-mips64.cpp
@@ -1050,7 +1050,8 @@ void MacroAssemblerMIPS64::ma_bal(Label* label, DelaySlotFill delaySlotFill) {
}
void MacroAssemblerMIPS64::branchWithCode(InstImm code, Label* label,
- JumpKind jumpKind) {
+ JumpKind jumpKind,
+ Register branchCodeScratch) {
// simply output the pointer of one label as its id,
// notice that after one label destructor, the pointer will be reused.
spew("branch .Llabel %p", label);
@@ -1080,7 +1081,12 @@ void MacroAssemblerMIPS64::branchWithCode(InstImm code, Label* label,
UseScratchRegisterScope temps(*this);
// Handle long jump
addLongJump(nextOffset(), BufferOffset(label->offset()));
- Register scratch = temps.Acquire();
+ Register scratch = branchCodeScratch;
+ if (scratch == InvalidReg) {
+ // Request a new scratch register if |branchCodeScratch| is invalid.
+ // NB: |branchCodeScratch| must not be used before encoding |code|.
+ scratch = temps.Acquire();
+ }
ma_liPatchable(scratch, ImmWord(LabelBase::INVALID_OFFSET));
as_jr(scratch);
as_nop();
@@ -1098,7 +1104,12 @@ void MacroAssemblerMIPS64::branchWithCode(InstImm code, Label* label,
UseScratchRegisterScope temps(*this);
// No need for a "nop" here because we can clobber scratch.
addLongJump(nextOffset(), BufferOffset(label->offset()));
- Register scratch = temps.Acquire();
+ Register scratch = branchCodeScratch;
+ if (scratch == InvalidReg) {
+ // Request a new scratch register if |branchCodeScratch| is invalid.
+ // NB: |branchCodeScratch| must not be used before encoding |code|.
+ scratch = temps.Acquire();
+ }
ma_liPatchable(scratch, ImmWord(LabelBase::INVALID_OFFSET));
as_jr(scratch);
as_nop();
diff --git a/js/src/jit/mips64/MacroAssembler-mips64.h b/js/src/jit/mips64/MacroAssembler-mips64.h
@@ -193,7 +193,8 @@ class MacroAssemblerMIPS64 : public MacroAssemblerMIPSShared {
void ma_pop(Register r);
void ma_push(Register r);
- void branchWithCode(InstImm code, Label* label, JumpKind jumpKind);
+ void branchWithCode(InstImm code, Label* label, JumpKind jumpKind,
+ Register branchCodeScratch = InvalidReg);
// branches when done from within mips-specific code
void ma_b(Register lhs, ImmWord imm, Label* l, Condition c,
JumpKind jumpKind = LongJump);