Skip to content

Commit

Permalink
Remove ArgumentPurpose::StackLimit (#8700)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottt committed May 28, 2024
1 parent 689f7d4 commit e852bce
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 430 deletions.
9 changes: 0 additions & 9 deletions cranelift/codegen/src/ir/extfunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,6 @@ pub enum ArgumentPurpose {
/// This is a pointer to a context struct containing details about the current sandbox. It is
/// used as a base pointer for `vmctx` global values.
VMContext,

/// A stack limit pointer.
///
/// This is a pointer to a stack limit. It is used to check the current stack pointer
/// against. Can only appear once in a signature.
StackLimit,
}

impl fmt::Display for ArgumentPurpose {
Expand All @@ -265,7 +259,6 @@ impl fmt::Display for ArgumentPurpose {
Self::StructArgument(size) => return write!(f, "sarg({})", size),
Self::StructReturn => "sret",
Self::VMContext => "vmctx",
Self::StackLimit => "stack_limit",
})
}
}
Expand All @@ -277,7 +270,6 @@ impl FromStr for ArgumentPurpose {
"normal" => Ok(Self::Normal),
"sret" => Ok(Self::StructReturn),
"vmctx" => Ok(Self::VMContext),
"stack_limit" => Ok(Self::StackLimit),
_ if s.starts_with("sarg(") => {
if !s.ends_with(")") {
return Err(());
Expand Down Expand Up @@ -374,7 +366,6 @@ mod tests {
(ArgumentPurpose::Normal, "normal"),
(ArgumentPurpose::StructReturn, "sret"),
(ArgumentPurpose::VMContext, "vmctx"),
(ArgumentPurpose::StackLimit, "stack_limit"),
(ArgumentPurpose::StructArgument(42), "sarg(42)"),
];
for &(e, n) in &all_purpose {
Expand Down
4 changes: 1 addition & 3 deletions cranelift/codegen/src/isa/aarch64/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ impl ABIMachineSpec for AArch64MachineDeps {

if matches!(
param.purpose,
ir::ArgumentPurpose::StructArgument(_)
| ir::ArgumentPurpose::StructReturn
| ir::ArgumentPurpose::StackLimit
ir::ArgumentPurpose::StructArgument(_) | ir::ArgumentPurpose::StructReturn
) {
assert!(
call_conv != isa::CallConv::Tail,
Expand Down
10 changes: 3 additions & 7 deletions cranelift/codegen/src/machinst/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1164,13 +1164,9 @@ impl<M: ABIMachineSpec> Callee<M> {
// stack limit. This can either be specified as a special-purpose
// argument or as a global value which often calculates the stack limit
// from the arguments.
let stack_limit =
get_special_purpose_param_register(f, sigs, sig, ir::ArgumentPurpose::StackLimit)
.map(|reg| (reg, smallvec![]))
.or_else(|| {
f.stack_limit
.map(|gv| gen_stack_limit::<M>(f, sigs, sig, gv))
});
let stack_limit = f
.stack_limit
.map(|gv| gen_stack_limit::<M>(f, sigs, sig, gv));

let tail_args_size = sigs[sig].sized_stack_arg_space;

Expand Down
130 changes: 0 additions & 130 deletions cranelift/filetests/filetests/isa/aarch64/stack-limit.clif
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,6 @@ block0:
; block0: ; offset 0x0
; ret

function %stack_limit_leaf_zero(i64 stack_limit) {
block0(v0: i64):
return
}

; VCode:
; block0:
; ret
;
; Disassembled:
; block0: ; offset 0x0
; ret

function %stack_limit_gv_leaf_zero(i64 vmctx) {
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0
Expand All @@ -45,42 +32,6 @@ block0(v0: i64):
; block0: ; offset 0x0
; ret

function %stack_limit_call_zero(i64 stack_limit) {
fn0 = %foo()
block0(v0: i64):
call fn0()
return
}

; VCode:
; stp fp, lr, [sp, #-16]!
; mov fp, sp
; add x16, x0, #16
; subs xzr, sp, x16, UXTX
; b.lo #trap=stk_ovf
; block0:
; load_ext_name x0, TestCase(%foo)+0
; blr x0
; ldp fp, lr, [sp], #16
; ret
;
; Disassembled:
; block0: ; offset 0x0
; stp x29, x30, [sp, #-0x10]!
; mov x29, sp
; add x16, x0, #0x10
; cmp sp, x16
; b.lo #0x30
; block1: ; offset 0x14
; ldr x0, #0x1c
; b #0x24
; .byte 0x00, 0x00, 0x00, 0x00 ; reloc_external Abs8 %foo 0
; .byte 0x00, 0x00, 0x00, 0x00
; blr x0
; ldp x29, x30, [sp], #0x10
; ret
; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf

function %stack_limit_gv_call_zero(i64 vmctx) {
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0
Expand Down Expand Up @@ -125,87 +76,6 @@ block0(v0: i64):
; ret
; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf

function %stack_limit(i64 stack_limit) {
ss0 = explicit_slot 168
block0(v0: i64):
return
}

; VCode:
; stp fp, lr, [sp, #-16]!
; mov fp, sp
; add x16, x0, #176
; subs xzr, sp, x16, UXTX
; b.lo #trap=stk_ovf
; sub sp, sp, #176
; block0:
; add sp, sp, #176
; ldp fp, lr, [sp], #16
; ret
;
; Disassembled:
; block0: ; offset 0x0
; stp x29, x30, [sp, #-0x10]!
; mov x29, sp
; add x16, x0, #0xb0
; cmp sp, x16
; b.lo #0x24
; sub sp, sp, #0xb0
; block1: ; offset 0x18
; add sp, sp, #0xb0
; ldp x29, x30, [sp], #0x10
; ret
; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf

function %huge_stack_limit(i64 stack_limit) {
ss0 = explicit_slot 400000
block0(v0: i64):
return
}

; VCode:
; stp fp, lr, [sp, #-16]!
; mov fp, sp
; subs xzr, sp, x0, UXTX
; b.lo #trap=stk_ovf
; movz w17, #6784
; movk w17, w17, #6, LSL #16
; add x16, x0, x17, UXTX
; subs xzr, sp, x16, UXTX
; b.lo #trap=stk_ovf
; movz w16, #6784
; movk w16, w16, #6, LSL #16
; sub sp, sp, x16, UXTX
; block0:
; movz w16, #6784
; movk w16, w16, #6, LSL #16
; add sp, sp, x16, UXTX
; ldp fp, lr, [sp], #16
; ret
;
; Disassembled:
; block0: ; offset 0x0
; stp x29, x30, [sp, #-0x10]!
; mov x29, sp
; cmp sp, x0
; b.lo #0x44
; mov w17, #0x1a80
; movk w17, #6, lsl #16
; add x16, x0, x17, uxtx
; cmp sp, x16
; b.lo #0x48
; mov w16, #0x1a80
; movk w16, #6, lsl #16
; sub sp, sp, x16
; block1: ; offset 0x30
; mov w16, #0x1a80
; movk w16, #6, lsl #16
; add sp, sp, x16
; ldp x29, x30, [sp], #0x10
; ret
; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf
; .byte 0x1f, 0xc1, 0x00, 0x00 ; trap: stk_ovf

function %limit_preamble(i64 vmctx) {
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0
Expand Down
154 changes: 0 additions & 154 deletions cranelift/filetests/filetests/isa/riscv64/stack-limit.clif
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,6 @@ block0:
; block0: ; offset 0x0
; ret

function %stack_limit_leaf_zero(i64 stack_limit) {
block0(v0: i64):
return
}

; VCode:
; block0:
; ret
;
; Disassembled:
; block0: ; offset 0x0
; ret

function %stack_limit_gv_leaf_zero(i64 vmctx) {
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0
Expand All @@ -46,49 +33,6 @@ block0(v0: i64):
; block0: ; offset 0x0
; ret

function %stack_limit_call_zero(i64 stack_limit) {
fn0 = %foo()
block0(v0: i64):
call fn0()
return
}

; VCode:
; addi sp,sp,-16
; sd ra,8(sp)
; sd fp,0(sp)
; mv fp,sp
; addi t6,a0,16
; trap_if stk_ovf##(sp ult t6)
; block0:
; load_sym a0,%foo+0
; callind a0
; ld ra,8(sp)
; ld fp,0(sp)
; addi sp,sp,16
; ret
;
; Disassembled:
; block0: ; offset 0x0
; addi sp, sp, -0x10
; sd ra, 8(sp)
; sd s0, 0(sp)
; mv s0, sp
; addi t6, a0, 0x10
; bgeu sp, t6, 8
; .byte 0x00, 0x00, 0x00, 0x00 ; trap: stk_ovf
; block1: ; offset 0x1c
; auipc a0, 0
; ld a0, 0xc(a0)
; j 0xc
; .byte 0x00, 0x00, 0x00, 0x00 ; reloc_external Abs8 %foo 0
; .byte 0x00, 0x00, 0x00, 0x00
; jalr a0
; ld ra, 8(sp)
; ld s0, 0(sp)
; addi sp, sp, 0x10
; ret

function %stack_limit_gv_call_zero(i64 vmctx) {
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0
Expand Down Expand Up @@ -140,104 +84,6 @@ block0(v0: i64):
; addi sp, sp, 0x10
; ret

function %stack_limit(i64 stack_limit) {
ss0 = explicit_slot 168
block0(v0: i64):
return
}

; VCode:
; addi sp,sp,-16
; sd ra,8(sp)
; sd fp,0(sp)
; mv fp,sp
; addi t6,a0,176
; trap_if stk_ovf##(sp ult t6)
; addi sp,sp,-176
; block0:
; addi sp,sp,176
; ld ra,8(sp)
; ld fp,0(sp)
; addi sp,sp,16
; ret
;
; Disassembled:
; block0: ; offset 0x0
; addi sp, sp, -0x10
; sd ra, 8(sp)
; sd s0, 0(sp)
; mv s0, sp
; addi t6, a0, 0xb0
; bgeu sp, t6, 8
; .byte 0x00, 0x00, 0x00, 0x00 ; trap: stk_ovf
; addi sp, sp, -0xb0
; block1: ; offset 0x20
; addi sp, sp, 0xb0
; ld ra, 8(sp)
; ld s0, 0(sp)
; addi sp, sp, 0x10
; ret

function %huge_stack_limit(i64 stack_limit) {
ss0 = explicit_slot 400000
block0(v0: i64):
return
}

; VCode:
; addi sp,sp,-16
; sd ra,8(sp)
; sd fp,0(sp)
; mv fp,sp
; trap_if stk_ovf##(sp ult a0)
; lui t5,98
; addi t5,t5,-1408
; add t6,t5,a0
; trap_if stk_ovf##(sp ult t6)
; lui a0,98
; addi a0,a0,-1408
; call %Probestack
; lui t6,-98
; addi t6,t6,1408
; add sp,sp,t6
; block0:
; lui t6,98
; addi t6,t6,-1408
; add sp,sp,t6
; ld ra,8(sp)
; ld fp,0(sp)
; addi sp,sp,16
; ret
;
; Disassembled:
; block0: ; offset 0x0
; addi sp, sp, -0x10
; sd ra, 8(sp)
; sd s0, 0(sp)
; mv s0, sp
; bgeu sp, a0, 8
; .byte 0x00, 0x00, 0x00, 0x00 ; trap: stk_ovf
; lui t5, 0x62
; addi t5, t5, -0x580
; add t6, t5, a0
; bgeu sp, t6, 8
; .byte 0x00, 0x00, 0x00, 0x00 ; trap: stk_ovf
; lui a0, 0x62
; addi a0, a0, -0x580
; auipc ra, 0 ; reloc_external RiscvCallPlt %Probestack 0
; jalr ra
; lui t6, 0xfff9e
; addi t6, t6, 0x580
; add sp, sp, t6
; block1: ; offset 0x48
; lui t6, 0x62
; addi t6, t6, -0x580
; add sp, sp, t6
; ld ra, 8(sp)
; ld s0, 0(sp)
; addi sp, sp, 0x10
; ret

function %limit_preamble(i64 vmctx) {
gv0 = vmctx
gv1 = load.i64 notrap aligned gv0
Expand Down
Loading

0 comments on commit e852bce

Please sign in to comment.