[arm64] Remove template argument of PushCPURegList and friends

Callee saved registers do not include the LR anymore, so we can
now remove the last place where we pass a non-default template
argument to PushCPURegList/PopCPURegList (in the code generator).
This makes the template argument redundant, so we can remove the
template altogether.

Change-Id: I07f0c0a10840817df8a5afc1dc74330e290ce5bf
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3571816
Reviewed-by: Jakob Linke <jgruber@chromium.org>
Commit-Queue: Georgia Kouveli <georgia.kouveli@arm.com>
Cr-Commit-Position: refs/heads/main@{#79842}
This commit is contained in:
Georgia Kouveli 2022-04-06 13:57:51 +01:00 committed by V8 LUCI CQ
parent 6fb4e02c78
commit 16b5fc3c57
6 changed files with 58 additions and 86 deletions

View File

@ -1241,58 +1241,6 @@ void TurboAssembler::Peek(const CPURegister& dst, const Operand& offset) {
#endif
}
template <TurboAssembler::StoreLRMode lr_mode>
void TurboAssembler::PushCPURegList(CPURegList registers) {
DCHECK_IMPLIES((lr_mode == kDontStoreLR), !registers.IncludesAliasOf(lr));
#ifdef V8_ENABLE_CONTROL_FLOW_INTEGRITY
if (lr_mode == kSignLR && registers.IncludesAliasOf(lr)) {
Pacibsp();
}
#endif
int size = registers.RegisterSizeInBytes();
DCHECK_EQ(0, (size * registers.Count()) % 16);
// Push up to four registers at a time.
while (!registers.IsEmpty()) {
int count_before = registers.Count();
const CPURegister& src0 = registers.PopHighestIndex();
const CPURegister& src1 = registers.PopHighestIndex();
const CPURegister& src2 = registers.PopHighestIndex();
const CPURegister& src3 = registers.PopHighestIndex();
int count = count_before - registers.Count();
PushHelper(count, size, src0, src1, src2, src3);
}
}
template <TurboAssembler::LoadLRMode lr_mode>
void TurboAssembler::PopCPURegList(CPURegList registers) {
int size = registers.RegisterSizeInBytes();
DCHECK_EQ(0, (size * registers.Count()) % 16);
#ifdef V8_ENABLE_CONTROL_FLOW_INTEGRITY
bool contains_lr = registers.IncludesAliasOf(lr);
DCHECK_IMPLIES((lr_mode == kDontLoadLR), !contains_lr);
#endif
// Pop up to four registers at a time.
while (!registers.IsEmpty()) {
int count_before = registers.Count();
const CPURegister& dst0 = registers.PopLowestIndex();
const CPURegister& dst1 = registers.PopLowestIndex();
const CPURegister& dst2 = registers.PopLowestIndex();
const CPURegister& dst3 = registers.PopLowestIndex();
int count = count_before - registers.Count();
PopHelper(count, size, dst0, dst1, dst2, dst3);
}
#ifdef V8_ENABLE_CONTROL_FLOW_INTEGRITY
if (lr_mode == kAuthLR && contains_lr) {
Autibsp();
}
#endif
}
void TurboAssembler::Claim(int64_t count, uint64_t unit_size) {
DCHECK_GE(count, 0);
uint64_t size = count * unit_size;

View File

@ -56,6 +56,46 @@ constexpr int kStackSavedSavedFPSizeInBits = kDRegSizeInBits;
} // namespace
void TurboAssembler::PushCPURegList(CPURegList registers) {
// If LR was stored here, we would need to sign it if
// V8_ENABLE_CONTROL_FLOW_INTEGRITY is on.
DCHECK(!registers.IncludesAliasOf(lr));
int size = registers.RegisterSizeInBytes();
DCHECK_EQ(0, (size * registers.Count()) % 16);
// Push up to four registers at a time.
while (!registers.IsEmpty()) {
int count_before = registers.Count();
const CPURegister& src0 = registers.PopHighestIndex();
const CPURegister& src1 = registers.PopHighestIndex();
const CPURegister& src2 = registers.PopHighestIndex();
const CPURegister& src3 = registers.PopHighestIndex();
int count = count_before - registers.Count();
PushHelper(count, size, src0, src1, src2, src3);
}
}
void TurboAssembler::PopCPURegList(CPURegList registers) {
int size = registers.RegisterSizeInBytes();
DCHECK_EQ(0, (size * registers.Count()) % 16);
// If LR was loaded here, we would need to authenticate it if
// V8_ENABLE_CONTROL_FLOW_INTEGRITY is on.
DCHECK(!registers.IncludesAliasOf(lr));
// Pop up to four registers at a time.
while (!registers.IsEmpty()) {
int count_before = registers.Count();
const CPURegister& dst0 = registers.PopLowestIndex();
const CPURegister& dst1 = registers.PopLowestIndex();
const CPURegister& dst2 = registers.PopLowestIndex();
const CPURegister& dst3 = registers.PopLowestIndex();
int count = count_before - registers.Count();
PopHelper(count, size, dst0, dst1, dst2, dst3);
}
}
int TurboAssembler::RequiredStackSizeForCallerSaved(SaveFPRegsMode fp_mode,
Register exclusion) const {
auto list = kCallerSaved;
@ -79,7 +119,7 @@ int TurboAssembler::PushCallerSaved(SaveFPRegsMode fp_mode,
list.Remove(exclusion);
list.Align();
PushCPURegList<kDontStoreLR>(list);
PushCPURegList(list);
int bytes = list.TotalSizeInBytes();
@ -106,7 +146,7 @@ int TurboAssembler::PopCallerSaved(SaveFPRegsMode fp_mode, Register exclusion) {
list.Remove(exclusion);
list.Align();
PopCPURegList<kDontLoadLR>(list);
PopCPURegList(list);
bytes += list.TotalSizeInBytes();
return bytes;
@ -3574,7 +3614,7 @@ void TurboAssembler::Printf(const char* format, CPURegister arg0,
// Preserve all caller-saved registers as well as NZCV.
// PushCPURegList asserts that the size of each list is a multiple of 16
// bytes.
PushCPURegList<kDontStoreLR>(saved_registers);
PushCPURegList(saved_registers);
PushCPURegList(kCallerSavedV);
// We can use caller-saved registers as scratch values (except for argN).
@ -3627,7 +3667,7 @@ void TurboAssembler::Printf(const char* format, CPURegister arg0,
}
PopCPURegList(kCallerSavedV);
PopCPURegList<kDontLoadLR>(saved_registers);
PopCPURegList(saved_registers);
TmpList()->set_bits(old_tmp_list);
FPTmpList()->set_bits(old_fp_tmp_list);

View File

@ -862,15 +862,7 @@ class V8_EXPORT_PRIVATE TurboAssembler : public TurboAssemblerBase {
// kSRegSizeInBits are supported.
//
// Otherwise, (Push|Pop)(CPU|X|W|D|S)RegList is preferred.
//
// The methods take an optional LoadLRMode or StoreLRMode template argument.
// When control flow integrity measures are enabled and the link register is
// included in 'registers', passing kSignLR to PushCPURegList will sign the
// link register before pushing the list, and passing kAuthLR to
// PopCPURegList will authenticate it after popping the list.
template <StoreLRMode lr_mode = kDontStoreLR>
void PushCPURegList(CPURegList registers);
template <LoadLRMode lr_mode = kDontLoadLR>
void PopCPURegList(CPURegList registers);
// Calculate how much stack space (in bytes) are required to store caller
@ -1752,31 +1744,23 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
tbx(vd, vn, vn2, vn3, vn4, vm);
}
// For the 'lr_mode' template argument of the following methods, see
// PushCPURegList/PopCPURegList.
template <StoreLRMode lr_mode = kDontStoreLR>
inline void PushSizeRegList(RegList registers, unsigned reg_size) {
PushCPURegList<lr_mode>(CPURegList(reg_size, registers));
PushCPURegList(CPURegList(reg_size, registers));
}
template <StoreLRMode lr_mode = kDontStoreLR>
inline void PushSizeRegList(DoubleRegList registers, unsigned reg_size) {
PushCPURegList<lr_mode>(CPURegList(reg_size, registers));
PushCPURegList(CPURegList(reg_size, registers));
}
template <LoadLRMode lr_mode = kDontLoadLR>
inline void PopSizeRegList(RegList registers, unsigned reg_size) {
PopCPURegList<lr_mode>(CPURegList(reg_size, registers));
PopCPURegList(CPURegList(reg_size, registers));
}
template <LoadLRMode lr_mode = kDontLoadLR>
inline void PopSizeRegList(DoubleRegList registers, unsigned reg_size) {
PopCPURegList<lr_mode>(CPURegList(reg_size, registers));
PopCPURegList(CPURegList(reg_size, registers));
}
template <StoreLRMode lr_mode = kDontStoreLR>
inline void PushXRegList(RegList regs) {
PushSizeRegList<lr_mode>(regs, kXRegSizeInBits);
PushSizeRegList(regs, kXRegSizeInBits);
}
template <LoadLRMode lr_mode = kDontLoadLR>
inline void PopXRegList(RegList regs) {
PopSizeRegList<lr_mode>(regs, kXRegSizeInBits);
PopSizeRegList(regs, kXRegSizeInBits);
}
inline void PushWRegList(RegList regs) {
PushSizeRegList(regs, kWRegSizeInBits);

View File

@ -3203,7 +3203,7 @@ void CodeGenerator::AssembleConstructFrame() {
__ PushCPURegList(saves_fp);
// Save registers.
__ PushCPURegList<TurboAssembler::kSignLR>(saves);
__ PushCPURegList(saves);
if (returns != 0) {
__ Claim(returns);
@ -3221,7 +3221,7 @@ void CodeGenerator::AssembleReturn(InstructionOperand* additional_pop_count) {
// Restore registers.
CPURegList saves =
CPURegList(kXRegSizeInBits, call_descriptor->CalleeSavedRegisters());
__ PopCPURegList<TurboAssembler::kAuthLR>(saves);
__ PopCPURegList(saves);
// Restore fp registers.
CPURegList saves_fp =

View File

@ -813,7 +813,7 @@ Handle<HeapObject> RegExpMacroAssemblerARM64::GetCode(Handle<String> source) {
CPURegList registers_to_retain = kCalleeSaved;
DCHECK_EQ(registers_to_retain.Count(), kNumCalleeSavedRegisters);
__ PushCPURegList<TurboAssembler::kDontStoreLR>(registers_to_retain);
__ PushCPURegList(registers_to_retain);
__ Push<TurboAssembler::kSignLR>(lr, fp);
__ PushCPURegList(argument_registers);
@ -1128,7 +1128,7 @@ Handle<HeapObject> RegExpMacroAssemblerARM64::GetCode(Handle<String> source) {
__ Pop<TurboAssembler::kAuthLR>(fp, lr);
// Restore registers.
__ PopCPURegList<TurboAssembler::kDontLoadLR>(registers_to_retain);
__ PopCPURegList(registers_to_retain);
__ Ret();

View File

@ -12381,7 +12381,7 @@ static void PushPopSimpleHelper(int reg_count, int reg_size,
}
break;
case PushPopRegList:
__ PushSizeRegList<TurboAssembler::kDontStoreLR>(list, reg_size);
__ PushSizeRegList(list, reg_size);
break;
}
@ -12406,7 +12406,7 @@ static void PushPopSimpleHelper(int reg_count, int reg_size,
}
break;
case PushPopRegList:
__ PopSizeRegList<TurboAssembler::kDontLoadLR>(list, reg_size);
__ PopSizeRegList(list, reg_size);
break;
}
}
@ -12740,8 +12740,8 @@ TEST(push_pop) {
__ PopXRegList({});
// Don't push/pop x18 (platform register) or lr
RegList all_regs = RegList::FromBits(0xFFFFFFFF) - RegList{x18, lr};
__ PushXRegList<TurboAssembler::kDontStoreLR>(all_regs);
__ PopXRegList<TurboAssembler::kDontLoadLR>(all_regs);
__ PushXRegList(all_regs);
__ PopXRegList(all_regs);
__ Drop(12);
END();