Skip to content

Commit 9e9def0

Browse files
schuayCommit Bot
authored andcommitted
[arm64] Remove x18 from allocatable registers
The arm64 ABI defines x18 as a platform register, and as such platforms may reserve it for their own purposes. This CL unconditionally removes x18 from the allocatable register list (previously it was only excluded from arm64 Windows). If, for some reason, we want to keep x18 allocatable on some platforms, we can explicitly enable it for specific platforms in the future. Bug: v8:8940,v8:9140 Change-Id: I28c4f6aad714e21a0a54bab6041c13a1b28fd467 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1564194 Reviewed-by: Clemens Hammacher <[email protected]> Reviewed-by: Jaroslav Sevcik <[email protected]> Commit-Queue: Jakob Gruber <[email protected]> Cr-Commit-Position: refs/heads/master@{#60870}
1 parent 1a48254 commit 9e9def0

6 files changed

Lines changed: 32 additions & 78 deletions

File tree

src/arm64/assembler-arm64.cc

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,9 @@ CPURegList CPURegList::GetCalleeSavedV(int size) {
109109

110110

111111
CPURegList CPURegList::GetCallerSaved(int size) {
112-
#if defined(V8_OS_WIN)
113-
// x18 is reserved as platform register on Windows arm64.
112+
// x18 is the platform register and is reserved for the use of platform ABIs.
114113
// Registers x0-x17 and lr (x30) are caller-saved.
115114
CPURegList list = CPURegList(CPURegister::kRegister, size, 0, 17);
116-
#else
117-
// Registers x0-x18 and lr (x30) are caller-saved.
118-
CPURegList list = CPURegList(CPURegister::kRegister, size, 0, 18);
119-
#endif
120115
list.Combine(lr);
121116
return list;
122117
}
@@ -149,13 +144,7 @@ CPURegList CPURegList::GetSafepointSavedRegisters() {
149144
list.Remove(16);
150145
list.Remove(17);
151146

152-
// Don't add x18 to safepoint list on Windows arm64 because it is reserved
153-
// as platform register.
154-
#if !defined(V8_OS_WIN)
155-
// Add x18 to the safepoint list, as although it's not in kJSCallerSaved, it
156-
// is a caller-saved register according to the procedure call standard.
157-
list.Combine(18);
158-
#endif
147+
// x18 is the platform register and is reserved for the use of platform ABIs.
159148

160149
// Add the link register (x30) to the safepoint list.
161150
list.Combine(30);

src/arm64/deoptimizer-arm64.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ void CopyRegListToFrame(MacroAssembler* masm, const Register& dst,
5555
masm->Sub(dst, dst, dst_offset);
5656
}
5757

58+
// TODO(jgruber): There's a hack here to explicitly skip restoration of the
59+
// so-called 'arm64 platform register' x18. The register may be in use by the
60+
// OS, thus we should not clobber it. Instead of this hack, it would be nicer
61+
// not to add x18 to the list of saved registers in the first place. The
62+
// complication here is that we require `reg_list.Count() % 2 == 0` in multiple
63+
// spots.
5864
void RestoreRegList(MacroAssembler* masm, const CPURegList& reg_list,
5965
const Register& src_base, int src_offset) {
6066
DCHECK_EQ(reg_list.Count() % 2, 0);
@@ -68,23 +74,19 @@ void RestoreRegList(MacroAssembler* masm, const CPURegList& reg_list,
6874
Register src = temps.AcquireX();
6975
masm->Add(src, src_base, src_offset);
7076

71-
#if defined(V8_OS_WIN)
72-
// x18 is reserved as platform register on Windows.
77+
// x18 is the platform register and is reserved for the use of platform ABIs.
7378
restore_list.Remove(x18);
74-
#endif
7579

7680
// Restore every register in restore_list from src.
7781
while (!restore_list.IsEmpty()) {
7882
CPURegister reg0 = restore_list.PopLowestIndex();
7983
CPURegister reg1 = restore_list.PopLowestIndex();
8084
int offset0 = reg0.code() * reg_size;
8185

82-
#if defined(V8_OS_WIN)
8386
if (reg1 == NoCPUReg) {
8487
masm->Ldr(reg0, MemOperand(src, offset0));
8588
break;
8689
}
87-
#endif
8890

8991
int offset1 = reg1.code() * reg_size;
9092

src/arm64/macro-assembler-arm64.cc

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,15 @@ int TurboAssembler::RequiredStackSizeForCallerSaved(SaveFPRegsMode fp_mode,
4848
// However, we leave it in the argument list to mirror the prototype for
4949
// Push/PopCallerSaved().
5050

51-
#if defined(V8_OS_WIN)
52-
// X18 is excluded from caller-saved register list on Windows ARM64 which
53-
// makes caller-saved registers in odd number. padreg is used accordingly
54-
// to maintain the alignment.
51+
// X18 is excluded from caller-saved register list on ARM64 which makes
52+
// caller-saved registers in odd number. padreg is used accordingly to
53+
// maintain the alignment.
5554
DCHECK_EQ(list.Count() % 2, 1);
5655
if (exclusion.Is(no_reg)) {
5756
bytes += kXRegSizeInBits / 8;
5857
} else {
5958
bytes -= kXRegSizeInBits / 8;
6059
}
61-
#else
62-
DCHECK_EQ(list.Count() % 2, 0);
63-
USE(exclusion);
64-
#endif
6560

6661
bytes += list.Count() * kXRegSizeInBits / 8;
6762

@@ -77,21 +72,13 @@ int TurboAssembler::PushCallerSaved(SaveFPRegsMode fp_mode,
7772
int bytes = 0;
7873
auto list = kCallerSaved;
7974

80-
#if defined(V8_OS_WIN)
81-
// X18 is excluded from caller-saved register list on Windows ARM64, use
82-
// padreg accordingly to maintain alignment.
75+
// X18 is excluded from caller-saved register list on ARM64, use padreg
76+
// accordingly to maintain alignment.
8377
if (!exclusion.Is(no_reg)) {
8478
list.Remove(exclusion);
8579
} else {
8680
list.Combine(padreg);
8781
}
88-
#else
89-
if (!exclusion.Is(no_reg)) {
90-
// Replace the excluded register with padding to maintain alignment.
91-
list.Remove(exclusion);
92-
list.Combine(padreg);
93-
}
94-
#endif
9582

9683
DCHECK_EQ(list.Count() % 2, 0);
9784
PushCPURegList(list);
@@ -115,21 +102,13 @@ int TurboAssembler::PopCallerSaved(SaveFPRegsMode fp_mode, Register exclusion) {
115102

116103
auto list = kCallerSaved;
117104

118-
#if defined(V8_OS_WIN)
119-
// X18 is excluded from caller-saved register list on Windows ARM64, use
120-
// padreg accordingly to maintain alignment.
105+
// X18 is excluded from caller-saved register list on ARM64, use padreg
106+
// accordingly to maintain alignment.
121107
if (!exclusion.Is(no_reg)) {
122108
list.Remove(exclusion);
123109
} else {
124110
list.Combine(padreg);
125111
}
126-
#else
127-
if (!exclusion.Is(no_reg)) {
128-
// Replace the excluded register with padding to maintain alignment.
129-
list.Remove(exclusion);
130-
list.Combine(padreg);
131-
}
132-
#endif
133112

134113
DCHECK_EQ(list.Count() % 2, 0);
135114
PopCPURegList(list);
@@ -3408,14 +3387,20 @@ void MacroAssembler::Printf(const char * format,
34083387
TmpList()->set_list(0);
34093388
FPTmpList()->set_list(0);
34103389

3390+
// x18 is the platform register and is reserved for the use of platform ABIs.
3391+
// It is not part of the kCallerSaved list, but we add it here anyway to
3392+
// ensure `reg_list.Count() % 2 == 0` which is required in multiple spots.
3393+
CPURegList saved_registers = kCallerSaved;
3394+
saved_registers.Combine(x18.code());
3395+
34113396
// Preserve all caller-saved registers as well as NZCV.
34123397
// PushCPURegList asserts that the size of each list is a multiple of 16
34133398
// bytes.
3414-
PushCPURegList(kCallerSaved);
3399+
PushCPURegList(saved_registers);
34153400
PushCPURegList(kCallerSavedV);
34163401

34173402
// We can use caller-saved registers as scratch values (except for argN).
3418-
CPURegList tmp_list = kCallerSaved;
3403+
CPURegList tmp_list = saved_registers;
34193404
CPURegList fp_tmp_list = kCallerSavedV;
34203405
tmp_list.Remove(arg0, arg1, arg2, arg3);
34213406
fp_tmp_list.Remove(arg0, arg1, arg2, arg3);
@@ -3435,7 +3420,8 @@ void MacroAssembler::Printf(const char * format,
34353420
// to PrintfNoPreserve as an argument.
34363421
Register arg_sp = temps.AcquireX();
34373422
Add(arg_sp, sp,
3438-
kCallerSaved.TotalSizeInBytes() + kCallerSavedV.TotalSizeInBytes());
3423+
saved_registers.TotalSizeInBytes() +
3424+
kCallerSavedV.TotalSizeInBytes());
34393425
if (arg0_sp) arg0 = Register::Create(arg_sp.code(), arg0.SizeInBits());
34403426
if (arg1_sp) arg1 = Register::Create(arg_sp.code(), arg1.SizeInBits());
34413427
if (arg2_sp) arg2 = Register::Create(arg_sp.code(), arg2.SizeInBits());
@@ -3460,7 +3446,7 @@ void MacroAssembler::Printf(const char * format,
34603446
}
34613447

34623448
PopCPURegList(kCallerSavedV);
3463-
PopCPURegList(kCallerSaved);
3449+
PopCPURegList(saved_registers);
34643450

34653451
TmpList()->set_list(old_tmp_list);
34663452
FPTmpList()->set_list(old_fp_tmp_list);

src/arm64/register-arm64.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,13 @@ namespace internal {
2828
R(x16) R(x17) R(x18) R(x19) R(x20) R(x21) R(x22) R(x23) \
2929
R(x24) R(x25) R(x26) R(x27) R(x28) R(x29) R(x30) R(x31)
3030

31-
#if defined(V8_OS_WIN)
32-
// x18 is reserved as platform register on Windows ARM64.
31+
// x18 is the platform register and is reserved for the use of platform ABIs.
32+
// It is known to be reserved by the OS at least on Windows and iOS.
3333
#define ALLOCATABLE_GENERAL_REGISTERS(R) \
3434
R(x0) R(x1) R(x2) R(x3) R(x4) R(x5) R(x6) R(x7) \
3535
R(x8) R(x9) R(x10) R(x11) R(x12) R(x13) R(x14) R(x15) \
3636
R(x19) R(x20) R(x21) R(x22) R(x23) R(x24) R(x25) \
3737
R(x27) R(x28)
38-
#else
39-
#define ALLOCATABLE_GENERAL_REGISTERS(R) \
40-
R(x0) R(x1) R(x2) R(x3) R(x4) R(x5) R(x6) R(x7) \
41-
R(x8) R(x9) R(x10) R(x11) R(x12) R(x13) R(x14) R(x15) \
42-
R(x18) R(x19) R(x20) R(x21) R(x22) R(x23) R(x24) R(x25) \
43-
R(x27) R(x28)
44-
#endif
4538

4639
#define FLOAT_REGISTERS(V) \
4740
V(s0) V(s1) V(s2) V(s3) V(s4) V(s5) V(s6) V(s7) \
@@ -729,12 +722,7 @@ constexpr Register kJSFunctionRegister = x1;
729722
constexpr Register kContextRegister = cp;
730723
constexpr Register kAllocateSizeRegister = x1;
731724

732-
#if defined(V8_OS_WIN)
733-
// x18 is reserved as platform register on Windows ARM64.
734725
constexpr Register kSpeculationPoisonRegister = x23;
735-
#else
736-
constexpr Register kSpeculationPoisonRegister = x18;
737-
#endif
738726

739727
constexpr Register kInterpreterAccumulatorRegister = x0;
740728
constexpr Register kInterpreterBytecodeOffsetRegister = x19;

src/builtins/arm64/builtins-arm64.cc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,15 +1281,9 @@ void Builtins::Generate_InterpreterEntryTrampoline(MacroAssembler* masm) {
12811281
__ Mov(
12821282
kInterpreterDispatchTableRegister,
12831283
ExternalReference::interpreter_dispatch_table_address(masm->isolate()));
1284-
#if defined(V8_OS_WIN)
12851284
__ Ldrb(x23, MemOperand(kInterpreterBytecodeArrayRegister,
12861285
kInterpreterBytecodeOffsetRegister));
12871286
__ Mov(x1, Operand(x23, LSL, kSystemPointerSizeLog2));
1288-
#else
1289-
__ Ldrb(x18, MemOperand(kInterpreterBytecodeArrayRegister,
1290-
kInterpreterBytecodeOffsetRegister));
1291-
__ Mov(x1, Operand(x18, LSL, kSystemPointerSizeLog2));
1292-
#endif
12931287
__ Ldr(kJavaScriptCallCodeStartRegister,
12941288
MemOperand(kInterpreterDispatchTableRegister, x1));
12951289
__ Call(kJavaScriptCallCodeStartRegister);
@@ -1534,15 +1528,9 @@ static void Generate_InterpreterEnterBytecode(MacroAssembler* masm) {
15341528
__ SmiUntag(kInterpreterBytecodeOffsetRegister);
15351529

15361530
// Dispatch to the target bytecode.
1537-
#if defined(V8_OS_WIN)
15381531
__ Ldrb(x23, MemOperand(kInterpreterBytecodeArrayRegister,
15391532
kInterpreterBytecodeOffsetRegister));
15401533
__ Mov(x1, Operand(x23, LSL, kSystemPointerSizeLog2));
1541-
#else
1542-
__ Ldrb(x18, MemOperand(kInterpreterBytecodeArrayRegister,
1543-
kInterpreterBytecodeOffsetRegister));
1544-
__ Mov(x1, Operand(x18, LSL, kSystemPointerSizeLog2));
1545-
#endif
15461534
__ Ldr(kJavaScriptCallCodeStartRegister,
15471535
MemOperand(kInterpreterDispatchTableRegister, x1));
15481536
__ Jump(kJavaScriptCallCodeStartRegister);

src/wasm/baseline/liftoff-assembler-defs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ constexpr RegList kLiftoffAssemblerFpCacheRegs =
6060

6161
#elif V8_TARGET_ARCH_ARM64
6262

63-
// x16: ip0, x17: ip1, x26: root, x27: cp, x29: fp, x30: lr, x31: xzr.
63+
// x16: ip0, x17: ip1, x18: platform register, x26: root, x27: cp, x29: fp,
64+
// x30: lr, x31: xzr.
6465
constexpr RegList kLiftoffAssemblerGpCacheRegs =
6566
CPURegister::ListOf<x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12,
66-
x13, x14, x15, x18, x19, x20, x21, x22, x23, x24, x25,
67+
x13, x14, x15, x19, x20, x21, x22, x23, x24, x25,
6768
x28>();
6869

6970
// d15: fp_zero, d30-d31: macro-assembler scratch V Registers.

0 commit comments

Comments
 (0)