Skip to content

Commit

Permalink
only lower on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
frank-emrich committed Aug 9, 2024
1 parent 850e62e commit 2af10f9
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 1 deletion.
3 changes: 3 additions & 0 deletions cranelift/codegen/src/isa/x64/lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -3359,6 +3359,9 @@
;; Rules for `stack_switch` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(rule (lower (stack_switch store_context_ptr load_context_ptr in_payload0))
;; For the time being, stack switching is only supported on x64 Linux
(if (on_linux))

(let ((store_context_ptr Gpr (put_in_gpr store_context_ptr))
(load_context_ptr Gpr (put_in_gpr load_context_ptr))
(in_payload0 Gpr (put_in_gpr in_payload0)))
Expand Down
8 changes: 8 additions & 0 deletions cranelift/codegen/src/machinst/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ use smallvec::smallvec;
use std::collections::HashMap;
use std::marker::PhantomData;
use std::mem;
use target_lexicon::Triple;

/// A small vector of instructions (with some reasonable size); appropriate for
/// a small fixed sequence implementing one operation.
Expand Down Expand Up @@ -1035,6 +1036,8 @@ pub struct Callee<M: ABIMachineSpec> {
/// manually register-allocated and carefully only use caller-saved
/// registers and keep nothing live after this sequence of instructions.
stack_limit: Option<(Reg, SmallInstVec<M::I>)>,
// Target triple
triple: Triple,

_mach: PhantomData<M>,
}
Expand Down Expand Up @@ -1160,6 +1163,7 @@ impl<M: ABIMachineSpec> Callee<M> {
isa_flags: isa_flags.clone(),
is_leaf: f.is_leaf(),
stack_limit,
triple: isa.triple().clone(),
_mach: PhantomData,
})
}
Expand Down Expand Up @@ -1384,6 +1388,10 @@ impl<M: ABIMachineSpec> Callee<M> {
&self.dynamic_stackslots
}

pub fn triple(&self) -> &Triple {
&self.triple
}

/// Generate an instruction which copies an argument to a destination
/// register.
pub fn gen_copy_arg_to_regs(
Expand Down
8 changes: 8 additions & 0 deletions cranelift/codegen/src/machinst/isle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,14 @@ macro_rules! isle_lower_prelude_methods {
}
}

#[inline]
fn on_linux(&mut self) -> Option<()> {
match self.lower_ctx.abi().triple().operating_system {
target_lexicon::OperatingSystem::Linux => Some(()),
_ => None,
}
}

#[inline]
fn func_ref_data(&mut self, func_ref: FuncRef) -> (SigRef, ExternalName, RelocDistance) {
let funcdata = &self.lower_ctx.dfg().ext_funcs[func_ref];
Expand Down
3 changes: 3 additions & 0 deletions cranelift/codegen/src/prelude_lower.isle
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,9 @@
(decl pure partial preserve_frame_pointers () Unit)
(extern constructor preserve_frame_pointers preserve_frame_pointers)

(decl pure partial on_linux () Unit)
(extern constructor on_linux on_linux)

;;;; Helpers for accessing instruction data ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(decl box_external_name (ExternalName) BoxExternalName)
Expand Down
2 changes: 1 addition & 1 deletion cranelift/filetests/filetests/isa/x64/stack_switch.clif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
test compile precise-output
set opt_level=speed
target x86_64
target x86_64-unknown-linux-gnu


;; Test clobbering of all 14 GPRs used by Cranelift
Expand Down

0 comments on commit 2af10f9

Please sign in to comment.