Skip to content

Commit

Permalink
Cranellift: remove Baldrdash support and related features.
Browse files Browse the repository at this point in the history
As noted in Mozilla's bugzilla bug 1781425 [1], the SpiderMonkey team
has recently determined that their current form of integration with
Cranelift is too hard to maintain, and they have chosen to remove it
from their codebase. If and when they decide to build updated support
for Cranelift, they will adopt different approaches to several details
of the integration.

In the meantime, after discussion with the SpiderMonkey folks, they
agree that it makes sense to remove the bits of Cranelift that exist
to support the integration ("Baldrdash"), as they will not need
them. Many of these bits are difficult-to-maintain special cases that
are not actually tested in Cranelift proper: for example, the
Baldrdash integration required Cranelift to emit function bodies
without prologues/epilogues, and instead communicate very precise
information about the expected frame size and layout, then stitched
together something post-facto. This was brittle and caused a lot of
incidental complexity ("fallthrough returns", the resulting special
logic in block-ordering); this is just one example. As another
example, one particular Baldrdash ABI variant processed stack args in
reverse order, so our ABI code had to support both traversal
orders. We had a number of other Baldrdash-specific settings as well
that did various special things.

This PR removes Baldrdash ABI support, the `fallthrough_return`
instruction, and pulls some threads to remove now-unused bits as a
result of those two, with the  understanding that the SpiderMonkey folks
will build new functionality as needed in the future and we can perhaps
find cleaner abstractions to make it all work.

[1] https://bugzilla.mozilla.org/show_bug.cgi?id=1781425
  • Loading branch information
cfallin committed Aug 1, 2022
1 parent 8e9e9c5 commit 14407fc
Show file tree
Hide file tree
Showing 50 changed files with 179 additions and 1,082 deletions.
4 changes: 0 additions & 4 deletions cranelift/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ Cranelift is designed to be a code generator for WebAssembly, but it is
general enough to be useful elsewhere too. The initial planned uses that
affected its design are:

- [WebAssembly compiler for the SpiderMonkey engine in
Firefox](spidermonkey.md#phase-1-webassembly).
- [Backend for the IonMonkey JavaScript JIT compiler in
Firefox](spidermonkey.md#phase-2-ionmonkey).
- [Debug build backend for the Rust compiler](rustc.md).
- [Wasmtime non-Web wasm engine](https://github.com/bytecodealliance/wasmtime).

Expand Down
9 changes: 0 additions & 9 deletions cranelift/codegen/meta/src/isa/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,8 @@ fn define_settings(shared: &SettingGroup) -> SettingGroup {
// back in the shared SettingGroup, and use it in x86 instruction predicates.

let is_pic = shared.get_bool("is_pic");
let emit_all_ones_funcaddrs = shared.get_bool("emit_all_ones_funcaddrs");
settings.add_predicate("is_pic", predicate!(is_pic));
settings.add_predicate("not_is_pic", predicate!(!is_pic));
settings.add_predicate(
"all_ones_funcaddrs_and_not_is_pic",
predicate!(emit_all_ones_funcaddrs && !is_pic),
);
settings.add_predicate(
"not_all_ones_funcaddrs_and_not_is_pic",
predicate!(!emit_all_ones_funcaddrs && !is_pic),
);

// Presets corresponding to x86 CPUs.

Expand Down
18 changes: 0 additions & 18 deletions cranelift/codegen/meta/src/shared/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,24 +332,6 @@ fn define_control_flow(
.is_terminator(true),
);

let rvals = &Operand::new("rvals", &entities.varargs).with_doc("return values");
ig.push(
Inst::new(
"fallthrough_return",
r#"
Return from the function by fallthrough.
This is a specialized instruction for use where one wants to append
a custom epilogue, which will then perform the real return. This
instruction has no encoding.
"#,
&formats.multiary,
)
.operands_in(vec![rvals])
.is_return(true)
.is_terminator(true),
);

let FN = &Operand::new("FN", &entities.func_ref)
.with_doc("function to call, declared by `function`");
let args = &Operand::new("args", &entities.varargs).with_doc("call arguments");
Expand Down
34 changes: 2 additions & 32 deletions cranelift/codegen/meta/src/shared/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ pub(crate) fn define() -> SettingGroup {
"avoid_div_traps",
"Generate explicit checks around native division instructions to avoid their trapping.",
r#"
This is primarily used by SpiderMonkey which doesn't install a signal
handler for SIGFPE, but expects a SIGILL trap for division by zero.
Generate explicit checks around native division instructions to
avoid their trapping.
On ISAs like ARM where the native division instructions don't trap,
this setting has no effect - explicit checks are always inserted.
Expand Down Expand Up @@ -175,8 +175,6 @@ pub(crate) fn define() -> SettingGroup {
vec!["none", "elf_gd", "macho", "coff"],
);

// Settings specific to the `baldrdash` calling convention.

settings.add_enum(
"libcall_call_conv",
"Defines the calling convention to use for LibCalls call expansion.",
Expand All @@ -196,29 +194,10 @@ pub(crate) fn define() -> SettingGroup {
"system_v",
"windows_fastcall",
"apple_aarch64",
"baldrdash_system_v",
"baldrdash_windows",
"baldrdash_2020",
"probestack",
],
);

settings.add_num(
"baldrdash_prologue_words",
"Number of pointer-sized words pushed by the baldrdash prologue.",
r#"
Functions with the `baldrdash` calling convention don't generate their
own prologue and epilogue. They depend on externally generated code
that pushes a fixed number of words in the prologue and restores them
in the epilogue.
This setting configures the number of pointer-sized words pushed on the
stack when the Cranelift-generated code is entered. This includes the
pushed return address on x86.
"#,
0,
);

settings.add_bool(
"enable_llvm_abi_extensions",
"Enable various ABI extensions defined by LLVM's behavior.",
Expand Down Expand Up @@ -277,15 +256,6 @@ pub(crate) fn define() -> SettingGroup {
false,
);

// BaldrMonkey requires that not-yet-relocated function addresses be encoded
// as all-ones bitpatterns.
settings.add_bool(
"emit_all_ones_funcaddrs",
"Emit not-yet-relocated function addresses as all-ones bit patterns.",
"",
false,
);

// Stack probing options.

settings.add_bool(
Expand Down
43 changes: 1 addition & 42 deletions cranelift/codegen/src/ir/extfunc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,6 @@ impl fmt::Display for AbiParam {
/// particulars of the target's ABI, and the CLIF should be platform-independent, these attributes
/// specify *how* to extend (according to the signedness of the original program) rather than
/// *whether* to extend.
///
/// For example, on x86-64, the SystemV ABI does not require extensions of narrow values, so these
/// `ArgumentExtension` attributes are ignored; but in the Baldrdash (SpiderMonkey) ABI on the same
/// platform, all narrow values *are* extended, so these attributes may lead to extra
/// zero/sign-extend instructions in the generated machine code.
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
#[cfg_attr(feature = "enable-serde", derive(Serialize, Deserialize))]
pub enum ArgumentExtension {
Expand Down Expand Up @@ -297,20 +292,6 @@ pub enum ArgumentPurpose {
/// 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,

/// A callee TLS value.
///
/// In the Baldrdash-2020 calling convention, the stack upon entry to the callee contains the
/// TLS-register values for the caller and the callee. This argument is used to provide the
/// value for the callee.
CalleeTLS,

/// A caller TLS value.
///
/// In the Baldrdash-2020 calling convention, the stack upon entry to the callee contains the
/// TLS-register values for the caller and the callee. This argument is used to provide the
/// value for the caller.
CallerTLS,
}

impl fmt::Display for ArgumentPurpose {
Expand All @@ -325,8 +306,6 @@ impl fmt::Display for ArgumentPurpose {
Self::VMContext => "vmctx",
Self::SignatureId => "sigid",
Self::StackLimit => "stack_limit",
Self::CalleeTLS => "callee_tls",
Self::CallerTLS => "caller_tls",
})
}
}
Expand Down Expand Up @@ -405,7 +384,7 @@ impl ExtFuncData {
#[cfg(test)]
mod tests {
use super::*;
use crate::ir::types::{B8, F32, I32};
use crate::ir::types::I32;
use alloc::string::ToString;

#[test]
Expand Down Expand Up @@ -447,28 +426,8 @@ mod tests {
CallConv::Cold,
CallConv::SystemV,
CallConv::WindowsFastcall,
CallConv::BaldrdashSystemV,
CallConv::BaldrdashWindows,
CallConv::Baldrdash2020,
] {
assert_eq!(Ok(cc), cc.to_string().parse())
}
}

#[test]
fn signatures() {
let mut sig = Signature::new(CallConv::BaldrdashSystemV);
assert_eq!(sig.to_string(), "() baldrdash_system_v");
sig.params.push(AbiParam::new(I32));
assert_eq!(sig.to_string(), "(i32) baldrdash_system_v");
sig.returns.push(AbiParam::new(F32));
assert_eq!(sig.to_string(), "(i32) -> f32 baldrdash_system_v");
sig.params.push(AbiParam::new(I32.by(4).unwrap()));
assert_eq!(sig.to_string(), "(i32, i32x4) -> f32 baldrdash_system_v");
sig.returns.push(AbiParam::new(B8));
assert_eq!(
sig.to_string(),
"(i32, i32x4) -> f32, b8 baldrdash_system_v"
);
}
}
Loading

0 comments on commit 14407fc

Please sign in to comment.