From 16b5fc3c57b3b5be33451b0340c860126fa3a073 Mon Sep 17 00:00:00 2001 From: Georgia Kouveli Date: Wed, 6 Apr 2022 13:57:51 +0100 Subject: [PATCH] [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 Commit-Queue: Georgia Kouveli Cr-Commit-Position: refs/heads/main@{#79842} --- src/codegen/arm64/macro-assembler-arm64-inl.h | 52 ------------------- src/codegen/arm64/macro-assembler-arm64.cc | 48 +++++++++++++++-- src/codegen/arm64/macro-assembler-arm64.h | 28 +++------- .../backend/arm64/code-generator-arm64.cc | 4 +- .../arm64/regexp-macro-assembler-arm64.cc | 4 +- test/cctest/test-assembler-arm64.cc | 8 +-- 6 files changed, 58 insertions(+), 86 deletions(-) diff --git a/src/codegen/arm64/macro-assembler-arm64-inl.h b/src/codegen/arm64/macro-assembler-arm64-inl.h index 48b8a5f06a..3ab14821b9 100644 --- a/src/codegen/arm64/macro-assembler-arm64-inl.h +++ b/src/codegen/arm64/macro-assembler-arm64-inl.h @@ -1241,58 +1241,6 @@ void TurboAssembler::Peek(const CPURegister& dst, const Operand& offset) { #endif } -template -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 -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; diff --git a/src/codegen/arm64/macro-assembler-arm64.cc b/src/codegen/arm64/macro-assembler-arm64.cc index b3354d0383..552425edd4 100644 --- a/src/codegen/arm64/macro-assembler-arm64.cc +++ b/src/codegen/arm64/macro-assembler-arm64.cc @@ -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(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(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(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(saved_registers); + PopCPURegList(saved_registers); TmpList()->set_bits(old_tmp_list); FPTmpList()->set_bits(old_fp_tmp_list); diff --git a/src/codegen/arm64/macro-assembler-arm64.h b/src/codegen/arm64/macro-assembler-arm64.h index 022d84cb60..d185b020b7 100644 --- a/src/codegen/arm64/macro-assembler-arm64.h +++ b/src/codegen/arm64/macro-assembler-arm64.h @@ -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 void PushCPURegList(CPURegList registers); - template 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 inline void PushSizeRegList(RegList registers, unsigned reg_size) { - PushCPURegList(CPURegList(reg_size, registers)); + PushCPURegList(CPURegList(reg_size, registers)); } - template inline void PushSizeRegList(DoubleRegList registers, unsigned reg_size) { - PushCPURegList(CPURegList(reg_size, registers)); + PushCPURegList(CPURegList(reg_size, registers)); } - template inline void PopSizeRegList(RegList registers, unsigned reg_size) { - PopCPURegList(CPURegList(reg_size, registers)); + PopCPURegList(CPURegList(reg_size, registers)); } - template inline void PopSizeRegList(DoubleRegList registers, unsigned reg_size) { - PopCPURegList(CPURegList(reg_size, registers)); + PopCPURegList(CPURegList(reg_size, registers)); } - template inline void PushXRegList(RegList regs) { - PushSizeRegList(regs, kXRegSizeInBits); + PushSizeRegList(regs, kXRegSizeInBits); } - template inline void PopXRegList(RegList regs) { - PopSizeRegList(regs, kXRegSizeInBits); + PopSizeRegList(regs, kXRegSizeInBits); } inline void PushWRegList(RegList regs) { PushSizeRegList(regs, kWRegSizeInBits); diff --git a/src/compiler/backend/arm64/code-generator-arm64.cc b/src/compiler/backend/arm64/code-generator-arm64.cc index 289fa08633..0aadd024e4 100644 --- a/src/compiler/backend/arm64/code-generator-arm64.cc +++ b/src/compiler/backend/arm64/code-generator-arm64.cc @@ -3203,7 +3203,7 @@ void CodeGenerator::AssembleConstructFrame() { __ PushCPURegList(saves_fp); // Save registers. - __ PushCPURegList(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(saves); + __ PopCPURegList(saves); // Restore fp registers. CPURegList saves_fp = diff --git a/src/regexp/arm64/regexp-macro-assembler-arm64.cc b/src/regexp/arm64/regexp-macro-assembler-arm64.cc index 812f4f98fd..e1330b0255 100644 --- a/src/regexp/arm64/regexp-macro-assembler-arm64.cc +++ b/src/regexp/arm64/regexp-macro-assembler-arm64.cc @@ -813,7 +813,7 @@ Handle RegExpMacroAssemblerARM64::GetCode(Handle source) { CPURegList registers_to_retain = kCalleeSaved; DCHECK_EQ(registers_to_retain.Count(), kNumCalleeSavedRegisters); - __ PushCPURegList(registers_to_retain); + __ PushCPURegList(registers_to_retain); __ Push(lr, fp); __ PushCPURegList(argument_registers); @@ -1128,7 +1128,7 @@ Handle RegExpMacroAssemblerARM64::GetCode(Handle source) { __ Pop(fp, lr); // Restore registers. - __ PopCPURegList(registers_to_retain); + __ PopCPURegList(registers_to_retain); __ Ret(); diff --git a/test/cctest/test-assembler-arm64.cc b/test/cctest/test-assembler-arm64.cc index fea98df487..897a4a70f9 100644 --- a/test/cctest/test-assembler-arm64.cc +++ b/test/cctest/test-assembler-arm64.cc @@ -12381,7 +12381,7 @@ static void PushPopSimpleHelper(int reg_count, int reg_size, } break; case PushPopRegList: - __ PushSizeRegList(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(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(all_regs); - __ PopXRegList(all_regs); + __ PushXRegList(all_regs); + __ PopXRegList(all_regs); __ Drop(12); END();