MIPS: unwind, don't save/restore hi/lo for R6

HI/LO registers have been removed in MIPSr6. Save and restore them only for pre-R6.

We keep the memory space for the registers so that we can use the same register indexes for
r6 and pre-r6.

Fixes: #60682

Reviewed By: compnerd

Differential Revision: https://reviews.llvm.org/D156283
This commit is contained in:
YunQiang Su 2023-08-19 00:35:25 -04:00 committed by Brad Smith
parent 974c639329
commit 22a84020d2
4 changed files with 25 additions and 2 deletions

View File

@ -876,6 +876,9 @@ enum {
UNW_MIPS_F29 = 61,
UNW_MIPS_F30 = 62,
UNW_MIPS_F31 = 63,
// HI,LO have been dropped since r6, we keep them here.
// So, when we add DSP/MSA etc, we can use the same register indexes
// for r6 and pre-r6.
UNW_MIPS_HI = 64,
UNW_MIPS_LO = 65,
};

View File

@ -2869,7 +2869,7 @@ inline bool Registers_mips_o32::validRegister(int regNum) const {
return false;
if (regNum <= UNW_MIPS_R31)
return true;
#if __mips_isa_rev != 6
#if __mips_isa_rev < 6
if (regNum == UNW_MIPS_HI)
return true;
if (regNum == UNW_MIPS_LO)
@ -2903,10 +2903,12 @@ inline uint32_t Registers_mips_o32::getRegister(int regNum) const {
return _registers.__pc;
case UNW_REG_SP:
return _registers.__r[29];
#if __mips_isa_rev < 6
case UNW_MIPS_HI:
return _registers.__hi;
case UNW_MIPS_LO:
return _registers.__lo;
#endif
}
_LIBUNWIND_ABORT("unsupported mips_o32 register");
}
@ -2936,11 +2938,13 @@ inline void Registers_mips_o32::setRegister(int regNum, uint32_t value) {
case UNW_REG_SP:
_registers.__r[29] = value;
return;
#if __mips_isa_rev < 6
case UNW_MIPS_HI:
_registers.__hi = value;
return;
case UNW_MIPS_LO:
_registers.__lo = value;
#endif
return;
}
_LIBUNWIND_ABORT("unsupported mips_o32 register");
@ -3120,10 +3124,12 @@ inline const char *Registers_mips_o32::getRegisterName(int regNum) {
return "$f30";
case UNW_MIPS_F31:
return "$f31";
#if __mips_isa_rev < 6
case UNW_MIPS_HI:
return "$hi";
case UNW_MIPS_LO:
return "$lo";
#endif
default:
return "unknown register";
}
@ -3193,7 +3199,7 @@ inline bool Registers_mips_newabi::validRegister(int regNum) const {
return false;
if (regNum <= UNW_MIPS_R31)
return true;
#if __mips_isa_rev != 6
#if __mips_isa_rev < 6
if (regNum == UNW_MIPS_HI)
return true;
if (regNum == UNW_MIPS_LO)
@ -3212,10 +3218,12 @@ inline uint64_t Registers_mips_newabi::getRegister(int regNum) const {
return _registers.__pc;
case UNW_REG_SP:
return _registers.__r[29];
#if __mips_isa_rev < 6
case UNW_MIPS_HI:
return _registers.__hi;
case UNW_MIPS_LO:
return _registers.__lo;
#endif
}
_LIBUNWIND_ABORT("unsupported mips_newabi register");
}
@ -3233,12 +3241,14 @@ inline void Registers_mips_newabi::setRegister(int regNum, uint64_t value) {
case UNW_REG_SP:
_registers.__r[29] = value;
return;
#if __mips_isa_rev < 6
case UNW_MIPS_HI:
_registers.__hi = value;
return;
case UNW_MIPS_LO:
_registers.__lo = value;
return;
#endif
}
_LIBUNWIND_ABORT("unsupported mips_newabi register");
}
@ -3417,10 +3427,12 @@ inline const char *Registers_mips_newabi::getRegisterName(int regNum) {
return "$f30";
case UNW_MIPS_F31:
return "$f31";
#if __mips_isa_rev < 6
case UNW_MIPS_HI:
return "$hi";
case UNW_MIPS_LO:
return "$lo";
#endif
default:
return "unknown register";
}

View File

@ -993,11 +993,13 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind18Registers_mips_o326jumptoEv)
ldc1 $f31, (4 * 36 + 8 * 31)($4)
#endif
#endif
#if __mips_isa_rev < 6
// restore hi and lo
lw $8, (4 * 33)($4)
mthi $8
lw $8, (4 * 34)($4)
mtlo $8
#endif
// r0 is zero
lw $1, (4 * 1)($4)
lw $2, (4 * 2)($4)
@ -1054,11 +1056,13 @@ DEFINE_LIBUNWIND_FUNCTION(_ZN9libunwind21Registers_mips_newabi6jumptoEv)
ldc1 $f\i, (280+8*\i)($4)
.endr
#endif
#if __mips_isa_rev < 6
// restore hi and lo
ld $8, (8 * 33)($4)
mthi $8
ld $8, (8 * 34)($4)
mtlo $8
#endif
// r0 is zero
ld $1, (8 * 1)($4)
ld $2, (8 * 2)($4)

View File

@ -174,11 +174,13 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
sw $31, (4 * 31)($4)
# Store return address to pc
sw $31, (4 * 32)($4)
#if __mips_isa_rev < 6
# hi and lo
mfhi $8
sw $8, (4 * 33)($4)
mflo $8
sw $8, (4 * 34)($4)
#endif
#ifdef __mips_hard_float
#if __mips_fpr != 64
sdc1 $f0, (4 * 36 + 8 * 0)($4)
@ -255,11 +257,13 @@ DEFINE_LIBUNWIND_FUNCTION(__unw_getcontext)
.endr
# Store return address to pc
sd $31, (8 * 32)($4)
#if __mips_isa_rev < 6
# hi and lo
mfhi $8
sd $8, (8 * 33)($4)
mflo $8
sd $8, (8 * 34)($4)
#endif
#ifdef __mips_hard_float
.irp i,FROM_0_TO_31
sdc1 $f\i, (280+8*\i)($4)