Skip to content

Commit 6767488

Browse files
authored
pulley: Remove special registers as candidates from regalloc (#9666)
* pulley: Remove special registers as candidates from regalloc This commit fixes a minor mistake where regalloc was allowed to allocate "special registers" such as the stack pointer, the frame pointer, etc. These register shouldn't participate in general-purpose register allocation, so they're removed from the list of non-preferred registers when metadata is provided to regalloc2. * Assert everything before SPECIAL_START is not special
1 parent 21477c7 commit 6767488

File tree

5 files changed

+89
-65
lines changed

5 files changed

+89
-65
lines changed

cranelift/codegen/src/isa/pulley_shared/abi.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,9 @@ fn create_reg_enviroment() -> MachineEnv {
807807
};
808808

809809
let non_preferred_regs_by_class: [Vec<PReg>; 3] = {
810-
let x_registers: Vec<PReg> = (16..32).map(|x| px_reg(x)).collect();
810+
let x_registers: Vec<PReg> = (16..XReg::SPECIAL_START)
811+
.map(|x| px_reg(x.into()))
812+
.collect();
811813
let f_registers: Vec<PReg> = (16..32).map(|x| pf_reg(x)).collect();
812814
let v_registers: Vec<PReg> = vec![];
813815
[x_registers, f_registers, v_registers]

cranelift/codegen/src/isa/pulley_shared/inst/args.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ newtype_of_reg!(XReg, WritableXReg, RegClass::Int);
122122
newtype_of_reg!(FReg, WritableFReg, RegClass::Float);
123123
newtype_of_reg!(VReg, WritableVReg, RegClass::Vector);
124124

125+
impl XReg {
126+
/// Index of the first "special" register, or the end of which registers
127+
/// regalloc is allowed to use.
128+
pub const SPECIAL_START: u8 = pulley_interpreter::regs::XReg::SPECIAL_START;
129+
}
130+
125131
pub use super::super::lower::isle::generated_code::ExtKind;
126132

127133
pub use super::super::lower::isle::generated_code::Amode;

cranelift/filetests/filetests/isa/pulley32/call.clif

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -307,32 +307,32 @@ block0:
307307
; x29 = xmov x27
308308
; x30 = xconst8 -64
309309
; x27 = xadd32 x27, x30
310-
; store64 sp+56, x16 // flags = notrap aligned
311-
; store64 sp+48, x18 // flags = notrap aligned
310+
; store64 sp+56, x18 // flags = notrap aligned
311+
; store64 sp+48, x20 // flags = notrap aligned
312312
; block0:
313313
; x0 = load_addr OutgoingArg(0)
314314
; call CallInfo { dest: TestCase(%g), uses: [CallArgPair { vreg: p0i, preg: p0i }], defs: [CallRetPair { vreg: Writable { reg: p0i }, preg: p0i }, CallRetPair { vreg: Writable { reg: p1i }, preg: p1i }, CallRetPair { vreg: Writable { reg: p2i }, preg: p2i }, CallRetPair { vreg: Writable { reg: p3i }, preg: p3i }, CallRetPair { vreg: Writable { reg: p4i }, preg: p4i }, CallRetPair { vreg: Writable { reg: p5i }, preg: p5i }, CallRetPair { vreg: Writable { reg: p6i }, preg: p6i }, CallRetPair { vreg: Writable { reg: p7i }, preg: p7i }, CallRetPair { vreg: Writable { reg: p8i }, preg: p8i }, CallRetPair { vreg: Writable { reg: p9i }, preg: p9i }, CallRetPair { vreg: Writable { reg: p10i }, preg: p10i }, CallRetPair { vreg: Writable { reg: p11i }, preg: p11i }, CallRetPair { vreg: Writable { reg: p12i }, preg: p12i }, CallRetPair { vreg: Writable { reg: p13i }, preg: p13i }, CallRetPair { vreg: Writable { reg: p14i }, preg: p14i }, CallRetPair { vreg: Writable { reg: p15i }, preg: p15i }], clobbers: PRegSet { bits: [0, 65279, 4294967295, 0] }, callee_conv: Fast, caller_conv: Fast, callee_pop_size: 0 }
315-
; x16 = xmov x13
316-
; x18 = xmov x11
317-
; x25 = load64_u OutgoingArg(0) // flags = notrap aligned
315+
; x18 = xmov x13
316+
; x20 = xmov x11
317+
; x24 = load64_u OutgoingArg(0) // flags = notrap aligned
318318
; x11 = load64_u OutgoingArg(8) // flags = notrap aligned
319319
; x13 = load64_u OutgoingArg(16) // flags = notrap aligned
320-
; x31 = load64_u OutgoingArg(24) // flags = notrap aligned
321-
; x17 = load64_u OutgoingArg(32) // flags = notrap aligned
322-
; x30 = xadd64 x0, x1
323-
; x29 = xadd64 x2, x3
320+
; x19 = load64_u OutgoingArg(24) // flags = notrap aligned
321+
; x21 = load64_u OutgoingArg(32) // flags = notrap aligned
322+
; x25 = xadd64 x0, x1
323+
; x23 = xadd64 x2, x3
324324
; x5 = xadd64 x4, x5
325325
; x6 = xadd64 x6, x7
326326
; x7 = xadd64 x8, x9
327-
; x0 = xmov x18
327+
; x0 = xmov x20
328328
; x4 = xadd64 x10, x0
329-
; x10 = xmov x16
329+
; x10 = xmov x18
330330
; x8 = xadd64 x12, x10
331331
; x14 = xadd64 x14, x15
332-
; x15 = xadd64 x25, x11
332+
; x15 = xadd64 x24, x11
333333
; x13 = xadd64 x11, x13
334-
; x0 = xadd64 x31, x17
335-
; x1 = xadd64 x30, x29
334+
; x0 = xadd64 x19, x21
335+
; x1 = xadd64 x25, x23
336336
; x2 = xadd64 x5, x6
337337
; x3 = xadd64 x7, x4
338338
; x14 = xadd64 x8, x14
@@ -344,8 +344,8 @@ block0:
344344
; x14 = xadd64 x0, x14
345345
; x13 = xadd64 x13, x13
346346
; x0 = xadd64 x14, x13
347-
; x16 = load64_u sp+56 // flags = notrap aligned
348-
; x18 = load64_u sp+48 // flags = notrap aligned
347+
; x18 = load64_u sp+56 // flags = notrap aligned
348+
; x20 = load64_u sp+48 // flags = notrap aligned
349349
; x30 = xconst8 64
350350
; x27 = xadd32 x27, x30
351351
; x28 = load64_u sp+8 // flags = notrap aligned
@@ -362,31 +362,31 @@ block0:
362362
; xmov fp, sp
363363
; xconst8 spilltmp0, -64
364364
; xadd32 sp, sp, spilltmp0
365-
; store64_offset8 sp, 56, x16
366-
; store64_offset8 sp, 48, x18
365+
; store64_offset8 sp, 56, x18
366+
; store64_offset8 sp, 48, x20
367367
; xmov x0, sp
368368
; call 0x0 // target = 0x21
369-
; xmov x16, x13
370-
; xmov x18, x11
371-
; load64 x25, sp
369+
; xmov x18, x13
370+
; xmov x20, x11
371+
; load64 x24, sp
372372
; load64_offset8 x11, sp, 8
373373
; load64_offset8 x13, sp, 16
374-
; load64_offset8 spilltmp1, sp, 24
375-
; load64_offset8 x17, sp, 32
376-
; xadd64 spilltmp0, x0, x1
377-
; xadd64 fp, x2, x3
374+
; load64_offset8 x19, sp, 24
375+
; load64_offset8 x21, sp, 32
376+
; xadd64 x25, x0, x1
377+
; xadd64 x23, x2, x3
378378
; xadd64 x5, x4, x5
379379
; xadd64 x6, x6, x7
380380
; xadd64 x7, x8, x9
381-
; xmov x0, x18
381+
; xmov x0, x20
382382
; xadd64 x4, x10, x0
383-
; xmov x10, x16
383+
; xmov x10, x18
384384
; xadd64 x8, x12, x10
385385
; xadd64 x14, x14, x15
386-
; xadd64 x15, x25, x11
386+
; xadd64 x15, x24, x11
387387
; xadd64 x13, x11, x13
388-
; xadd64 x0, spilltmp1, x17
389-
; xadd64 x1, spilltmp0, fp
388+
; xadd64 x0, x19, x21
389+
; xadd64 x1, x25, x23
390390
; xadd64 x2, x5, x6
391391
; xadd64 x3, x7, x4
392392
; xadd64 x14, x8, x14
@@ -398,8 +398,8 @@ block0:
398398
; xadd64 x14, x0, x14
399399
; xadd64 x13, x13, x13
400400
; xadd64 x0, x14, x13
401-
; load64_offset8 x16, sp, 56
402-
; load64_offset8 x18, sp, 48
401+
; load64_offset8 x18, sp, 56
402+
; load64_offset8 x20, sp, 48
403403
; xconst8 spilltmp0, 64
404404
; xadd32 sp, sp, spilltmp0
405405
; load64_offset8 lr, sp, 8

cranelift/filetests/filetests/isa/pulley64/call.clif

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -307,32 +307,32 @@ block0:
307307
; x29 = xmov x27
308308
; x30 = xconst8 -64
309309
; x27 = xadd32 x27, x30
310-
; store64 sp+56, x16 // flags = notrap aligned
311-
; store64 sp+48, x18 // flags = notrap aligned
310+
; store64 sp+56, x18 // flags = notrap aligned
311+
; store64 sp+48, x20 // flags = notrap aligned
312312
; block0:
313313
; x0 = load_addr OutgoingArg(0)
314314
; call CallInfo { dest: TestCase(%g), uses: [CallArgPair { vreg: p0i, preg: p0i }], defs: [CallRetPair { vreg: Writable { reg: p0i }, preg: p0i }, CallRetPair { vreg: Writable { reg: p1i }, preg: p1i }, CallRetPair { vreg: Writable { reg: p2i }, preg: p2i }, CallRetPair { vreg: Writable { reg: p3i }, preg: p3i }, CallRetPair { vreg: Writable { reg: p4i }, preg: p4i }, CallRetPair { vreg: Writable { reg: p5i }, preg: p5i }, CallRetPair { vreg: Writable { reg: p6i }, preg: p6i }, CallRetPair { vreg: Writable { reg: p7i }, preg: p7i }, CallRetPair { vreg: Writable { reg: p8i }, preg: p8i }, CallRetPair { vreg: Writable { reg: p9i }, preg: p9i }, CallRetPair { vreg: Writable { reg: p10i }, preg: p10i }, CallRetPair { vreg: Writable { reg: p11i }, preg: p11i }, CallRetPair { vreg: Writable { reg: p12i }, preg: p12i }, CallRetPair { vreg: Writable { reg: p13i }, preg: p13i }, CallRetPair { vreg: Writable { reg: p14i }, preg: p14i }, CallRetPair { vreg: Writable { reg: p15i }, preg: p15i }], clobbers: PRegSet { bits: [0, 65279, 4294967295, 0] }, callee_conv: Fast, caller_conv: Fast, callee_pop_size: 0 }
315-
; x16 = xmov x13
316-
; x18 = xmov x11
317-
; x25 = load64_u OutgoingArg(0) // flags = notrap aligned
315+
; x18 = xmov x13
316+
; x20 = xmov x11
317+
; x24 = load64_u OutgoingArg(0) // flags = notrap aligned
318318
; x11 = load64_u OutgoingArg(8) // flags = notrap aligned
319319
; x13 = load64_u OutgoingArg(16) // flags = notrap aligned
320-
; x31 = load64_u OutgoingArg(24) // flags = notrap aligned
321-
; x17 = load64_u OutgoingArg(32) // flags = notrap aligned
322-
; x30 = xadd64 x0, x1
323-
; x29 = xadd64 x2, x3
320+
; x19 = load64_u OutgoingArg(24) // flags = notrap aligned
321+
; x21 = load64_u OutgoingArg(32) // flags = notrap aligned
322+
; x25 = xadd64 x0, x1
323+
; x23 = xadd64 x2, x3
324324
; x5 = xadd64 x4, x5
325325
; x6 = xadd64 x6, x7
326326
; x7 = xadd64 x8, x9
327-
; x0 = xmov x18
327+
; x0 = xmov x20
328328
; x4 = xadd64 x10, x0
329-
; x10 = xmov x16
329+
; x10 = xmov x18
330330
; x8 = xadd64 x12, x10
331331
; x14 = xadd64 x14, x15
332-
; x15 = xadd64 x25, x11
332+
; x15 = xadd64 x24, x11
333333
; x13 = xadd64 x11, x13
334-
; x0 = xadd64 x31, x17
335-
; x1 = xadd64 x30, x29
334+
; x0 = xadd64 x19, x21
335+
; x1 = xadd64 x25, x23
336336
; x2 = xadd64 x5, x6
337337
; x3 = xadd64 x7, x4
338338
; x14 = xadd64 x8, x14
@@ -344,8 +344,8 @@ block0:
344344
; x14 = xadd64 x0, x14
345345
; x13 = xadd64 x13, x13
346346
; x0 = xadd64 x14, x13
347-
; x16 = load64_u sp+56 // flags = notrap aligned
348-
; x18 = load64_u sp+48 // flags = notrap aligned
347+
; x18 = load64_u sp+56 // flags = notrap aligned
348+
; x20 = load64_u sp+48 // flags = notrap aligned
349349
; x30 = xconst8 64
350350
; x27 = xadd32 x27, x30
351351
; x28 = load64_u sp+8 // flags = notrap aligned
@@ -362,31 +362,31 @@ block0:
362362
; xmov fp, sp
363363
; xconst8 spilltmp0, -64
364364
; xadd32 sp, sp, spilltmp0
365-
; store64_offset8 sp, 56, x16
366-
; store64_offset8 sp, 48, x18
365+
; store64_offset8 sp, 56, x18
366+
; store64_offset8 sp, 48, x20
367367
; xmov x0, sp
368368
; call 0x0 // target = 0x21
369-
; xmov x16, x13
370-
; xmov x18, x11
371-
; load64 x25, sp
369+
; xmov x18, x13
370+
; xmov x20, x11
371+
; load64 x24, sp
372372
; load64_offset8 x11, sp, 8
373373
; load64_offset8 x13, sp, 16
374-
; load64_offset8 spilltmp1, sp, 24
375-
; load64_offset8 x17, sp, 32
376-
; xadd64 spilltmp0, x0, x1
377-
; xadd64 fp, x2, x3
374+
; load64_offset8 x19, sp, 24
375+
; load64_offset8 x21, sp, 32
376+
; xadd64 x25, x0, x1
377+
; xadd64 x23, x2, x3
378378
; xadd64 x5, x4, x5
379379
; xadd64 x6, x6, x7
380380
; xadd64 x7, x8, x9
381-
; xmov x0, x18
381+
; xmov x0, x20
382382
; xadd64 x4, x10, x0
383-
; xmov x10, x16
383+
; xmov x10, x18
384384
; xadd64 x8, x12, x10
385385
; xadd64 x14, x14, x15
386-
; xadd64 x15, x25, x11
386+
; xadd64 x15, x24, x11
387387
; xadd64 x13, x11, x13
388-
; xadd64 x0, spilltmp1, x17
389-
; xadd64 x1, spilltmp0, fp
388+
; xadd64 x0, x19, x21
389+
; xadd64 x1, x25, x23
390390
; xadd64 x2, x5, x6
391391
; xadd64 x3, x7, x4
392392
; xadd64 x14, x8, x14
@@ -398,8 +398,8 @@ block0:
398398
; xadd64 x14, x0, x14
399399
; xadd64 x13, x13, x13
400400
; xadd64 x0, x14, x13
401-
; load64_offset8 x16, sp, 56
402-
; load64_offset8 x18, sp, 48
401+
; load64_offset8 x18, sp, 56
402+
; load64_offset8 x20, sp, 48
403403
; xconst8 spilltmp0, 64
404404
; xadd32 sp, sp, spilltmp0
405405
; load64_offset8 lr, sp, 8

pulley/src/regs.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ pub enum XReg {
8888
}
8989

9090
impl XReg {
91+
/// Index of the first "special" register.
92+
pub const SPECIAL_START: u8 = XReg::sp as u8;
93+
9194
/// Is this `x` register a special register?
9295
pub fn is_special(self) -> bool {
9396
matches!(
@@ -97,6 +100,19 @@ impl XReg {
97100
}
98101
}
99102

103+
#[test]
104+
fn assert_special_start_is_right() {
105+
for i in 0..XReg::SPECIAL_START {
106+
assert!(!XReg::new(i).unwrap().is_special());
107+
}
108+
for i in XReg::SPECIAL_START.. {
109+
match XReg::new(i) {
110+
Some(r) => assert!(r.is_special()),
111+
None => break,
112+
}
113+
}
114+
}
115+
100116
/// An `f` register: floats.
101117
#[repr(u8)]
102118
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]

0 commit comments

Comments
 (0)