diff --git a/cranelift/docs/langref.rst b/cranelift/docs/langref.rst index 2758a1c7b8..0eb2c0896c 100644 --- a/cranelift/docs/langref.rst +++ b/cranelift/docs/langref.rst @@ -546,8 +546,6 @@ instructions before instruction selection:: When Cretonne code is running in a sandbox, it can also be necessary to include stack overflow checks in the prologue. -.. autoinst:: stack_check - Global variables ---------------- diff --git a/cranelift/filetests/isa/x86/legalize-memory.cton b/cranelift/filetests/isa/x86/legalize-memory.cton index 13375e124d..9762aa1f6c 100644 --- a/cranelift/filetests/isa/x86/legalize-memory.cton +++ b/cranelift/filetests/isa/x86/legalize-memory.cton @@ -108,17 +108,3 @@ ebb0(v0: i32, v999: i64): ; nextln: v2 = load.f32 v1+0x7fff_ffff return v2 } - -; Stack overflow check. -; The stack limit is stored in a pointer-sized global variable. -function %stkchk(i64 vmctx) baldrdash { - gv0 = vmctx+64 - -ebb0(v0: i64): - ; check: ebb0( - stack_check gv0 - ; check: $(limit=$V) = load.i64 notrap aligned - ; check: $(flags=$V) = ifcmp_sp $limit - ; check: trapif uge $flags, stk_ovf - return -} diff --git a/lib/codegen/meta/base/instructions.py b/lib/codegen/meta/base/instructions.py index 3107c9ca41..485de44c5e 100644 --- a/lib/codegen/meta/base/instructions.py +++ b/lib/codegen/meta/base/instructions.py @@ -668,27 +668,6 @@ copy_special = Instruction( ins=(src, dst), other_side_effects=True) -GV = Operand( - 'GV', entities.global_var, doc=r""" - Global variable containing the stack limit. - """) - -stack_check = Instruction( - 'stack_check', r""" - Check for stack overflow. - - Read the stack limit from ``GV`` and compare it to the stack pointer. If - the stack pointer has reached or exceeded the limit, generate a trap with a - ``stk_ovf`` code. - - The global variable must be accessible and naturally aligned for a - pointer-sized value. - - `stack_check` is an alternative way to detect stack overflow, when using - a calling convention that doesn't perform stack probes. - """, - ins=GV, can_trap=True) - delta = Operand('delta', Int) adjust_sp_down = Instruction( 'adjust_sp_down', r""" diff --git a/lib/codegen/meta/base/legalize.py b/lib/codegen/meta/base/legalize.py index 0a7e8ea7b3..ad396af747 100644 --- a/lib/codegen/meta/base/legalize.py +++ b/lib/codegen/meta/base/legalize.py @@ -287,7 +287,6 @@ for ty, minus_zero in [ # Expansions using CPU flags. -expand_flags.custom_legalize(insts.stack_check, 'expand_stack_check') expand_flags.legalize( insts.trapnz(x, c), diff --git a/lib/codegen/src/legalizer/mod.rs b/lib/codegen/src/legalizer/mod.rs index b3d6d6c0ce..9dcc2dff2f 100644 --- a/lib/codegen/src/legalizer/mod.rs +++ b/lib/codegen/src/legalizer/mod.rs @@ -269,35 +269,3 @@ fn expand_fconst( }; pos.func.dfg.replace(inst).bitcast(ty, ival); } - -/// Expand the stack check instruction. -pub fn expand_stack_check( - inst: ir::Inst, - func: &mut ir::Function, - _cfg: &mut ControlFlowGraph, - isa: &TargetIsa, -) { - use ir::condcodes::IntCC; - - let gv = match func.dfg[inst] { - ir::InstructionData::UnaryGlobalVar { global_var, .. } => global_var, - _ => panic!("Want stack_check: {}", func.dfg.display_inst(inst, isa)), - }; - let ptr_ty = isa.pointer_type(); - - let mut pos = FuncCursor::new(func).at_inst(inst); - pos.use_srcloc(inst); - - let limit_addr = pos.ins().global_addr(ptr_ty, gv); - - let mut mflags = ir::MemFlags::new(); - mflags.set_aligned(); - mflags.set_notrap(); - let limit = pos.ins().load(ptr_ty, mflags, limit_addr, 0); - let cflags = pos.ins().ifcmp_sp(limit); - pos.func.dfg.replace(inst).trapif( - IntCC::UnsignedGreaterThanOrEqual, - cflags, - ir::TrapCode::StackOverflow, - ); -}