Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ cranelift-object = { path = "cranelift/object", version = "0.95.0" }
cranelift-jit = { path = "cranelift/jit", version = "0.95.0" }
cranelift-fuzzgen = { path = "cranelift/fuzzgen" }
cranelift-bforest = { path = "cranelift/bforest", version = "0.95.0" }
cranelift-control = { path = "cranelift/control", version = "0.95.0" }
cranelift = { path = "cranelift/umbrella", version = "0.95.0" }

winch-codegen = { path = "winch/codegen", version = "=0.6.0" }
Expand Down
3 changes: 3 additions & 0 deletions cranelift/codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ capstone = { workspace = true, optional = true }
cranelift-codegen-shared = { path = "./shared", version = "0.95.0" }
cranelift-entity = { workspace = true }
cranelift-bforest = { workspace = true }
cranelift-control = { workspace = true }
hashbrown = { workspace = true, features = ["raw"] }
target-lexicon = { workspace = true }
log = { workspace = true }
Expand Down Expand Up @@ -113,6 +114,8 @@ isle-errors = ["cranelift-isle/fancy-errors"]
# inspection, rather than inside of target/.
isle-in-source-tree = []

chaos = ["cranelift-control/chaos"]

[badges]
maintenance = { status = "experimental" }

Expand Down
12 changes: 9 additions & 3 deletions cranelift/codegen/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use crate::{timing, CompileError};
#[cfg(feature = "souper-harvest")]
use alloc::string::String;
use alloc::vec::Vec;
use cranelift_control::ControlPlane;

#[cfg(feature = "souper-harvest")]
use crate::souper_harvest::do_souper_harvest;
Expand All @@ -56,29 +57,34 @@ pub struct Context {

/// Flag: do we want a disassembly with the CompiledCode?
pub want_disasm: bool,

/// Only used during fuzz-testing. Otherwise, this is a zero-sized struct
/// and compiled away. See [cranelift_control].
control_plane: ControlPlane,
}

impl Context {
/// Allocate a new compilation context.
///
/// The returned instance should be reused for compiling multiple functions in order to avoid
/// needless allocator thrashing.
pub fn new() -> Self {
Self::for_function(Function::new())
pub fn new(control_plane: ControlPlane) -> Self {
Self::for_function(Function::new(), control_plane)
}

/// Allocate a new compilation context with an existing Function.
///
/// The returned instance should be reused for compiling multiple functions in order to avoid
/// needless allocator thrashing.
pub fn for_function(func: Function) -> Self {
pub fn for_function(func: Function, control_plane: ControlPlane) -> Self {
Self {
func,
cfg: ControlFlowGraph::new(),
domtree: DominatorTree::new(),
loop_analysis: LoopAnalysis::new(),
compiled_code: None,
want_disasm: false,
control_plane,
}
}

Expand Down
24 changes: 20 additions & 4 deletions cranelift/codegen/src/isa/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use crate::result::CodegenResult;
use crate::settings as shared_settings;
use alloc::{boxed::Box, vec::Vec};
use core::fmt;
use cranelift_control::ControlPlane;
use regalloc2::MachineEnv;
use target_lexicon::{Aarch64Architecture, Architecture, OperatingSystem, Triple};

Expand All @@ -34,6 +35,9 @@ pub struct AArch64Backend {
flags: shared_settings::Flags,
isa_flags: aarch64_settings::Flags,
machine_env: MachineEnv,
/// Only used during fuzz-testing. Otherwise, this is a zero-sized struct
/// and compiled away. See [cranelift_control].
control_plane: ControlPlane,
}

impl AArch64Backend {
Expand All @@ -42,13 +46,15 @@ impl AArch64Backend {
triple: Triple,
flags: shared_settings::Flags,
isa_flags: aarch64_settings::Flags,
control_plane: ControlPlane,
) -> AArch64Backend {
let machine_env = create_reg_env(&flags);
AArch64Backend {
triple,
flags,
isa_flags,
machine_env,
control_plane,
}
}

Expand All @@ -62,7 +68,15 @@ impl AArch64Backend {
let emit_info = EmitInfo::new(self.flags.clone());
let sigs = SigSet::new::<abi::AArch64MachineDeps>(func, &self.flags)?;
let abi = abi::AArch64Callee::new(func, self, &self.isa_flags, &sigs)?;
compile::compile::<AArch64Backend>(func, domtree, self, abi, emit_info, sigs)
compile::compile::<AArch64Backend>(
func,
domtree,
self,
abi,
emit_info,
sigs,
self.control_plane.clone(),
)
}
}

Expand Down Expand Up @@ -231,14 +245,16 @@ impl fmt::Display for AArch64Backend {
}

/// Create a new `isa::Builder`.
pub fn isa_builder(triple: Triple) -> IsaBuilder {
pub fn isa_builder(triple: Triple, control_plane: ControlPlane) -> IsaBuilder {
assert!(triple.architecture == Architecture::Aarch64(Aarch64Architecture::Aarch64));
IsaBuilder {
triple,
control_plane,
setup: aarch64_settings::builder(),
constructor: |triple, shared_flags, builder| {
constructor: |triple, shared_flags, builder, control_plane| {
let isa_flags = aarch64_settings::Flags::new(&shared_flags, builder);
let backend = AArch64Backend::new_with_flags(triple, shared_flags, isa_flags);
let backend =
AArch64Backend::new_with_flags(triple, shared_flags, isa_flags, control_plane);
Ok(backend.wrapped())
},
}
Expand Down
41 changes: 29 additions & 12 deletions cranelift/codegen/src/isa/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use crate::CodegenResult;
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use core::fmt;
use core::fmt::{Debug, Formatter};
use cranelift_control::ControlPlane;
use target_lexicon::{triple, Architecture, PointerWidth, Triple};

// This module is made public here for benchmarking purposes. No guarantees are
Expand All @@ -80,10 +81,10 @@ mod call_conv;
/// Returns a builder that can create a corresponding `TargetIsa`
/// or `Err(LookupError::SupportDisabled)` if not enabled.
macro_rules! isa_builder {
($name: ident, $cfg_terms: tt, $triple: ident) => {{
($name: ident, $cfg_terms: tt, $triple: ident, $control_plane: ident) => {{
#[cfg $cfg_terms]
{
Ok($name::isa_builder($triple))
Ok($name::isa_builder($triple, $control_plane))
}
#[cfg(not $cfg_terms)]
{
Expand All @@ -94,14 +95,20 @@ macro_rules! isa_builder {

/// Look for an ISA for the given `triple`.
/// Return a builder that can create a corresponding `TargetIsa`.
pub fn lookup(triple: Triple) -> Result<Builder, LookupError> {
pub fn lookup(triple: Triple, control_plane: ControlPlane) -> Result<Builder, LookupError> {
match triple.architecture {
Architecture::X86_64 => {
isa_builder!(x64, (feature = "x86"), triple)
isa_builder!(x64, (feature = "x86"), triple, control_plane)
}
Architecture::Aarch64 { .. } => {
isa_builder!(aarch64, (feature = "arm64"), triple, control_plane)
}
Architecture::S390x { .. } => {
isa_builder!(s390x, (feature = "s390x"), triple, control_plane)
}
Architecture::Riscv64 { .. } => {
isa_builder!(riscv64, (feature = "riscv64"), triple, control_plane)
}
Architecture::Aarch64 { .. } => isa_builder!(aarch64, (feature = "arm64"), triple),
Architecture::S390x { .. } => isa_builder!(s390x, (feature = "s390x"), triple),
Architecture::Riscv64 { .. } => isa_builder!(riscv64, (feature = "riscv64"), triple),
_ => Err(LookupError::Unsupported),
}
}
Expand All @@ -113,9 +120,9 @@ pub const ALL_ARCHITECTURES: &[&str] = &["x86_64", "aarch64", "s390x", "riscv64"

/// Look for a supported ISA with the given `name`.
/// Return a builder that can create a corresponding `TargetIsa`.
pub fn lookup_by_name(name: &str) -> Result<Builder, LookupError> {
pub fn lookup_by_name(name: &str, control_plane: ControlPlane) -> Result<Builder, LookupError> {
use alloc::str::FromStr;
lookup(triple!(name))
lookup(triple!(name), control_plane)
}

/// Describes reason for target lookup failure
Expand Down Expand Up @@ -154,8 +161,11 @@ pub type Builder = IsaBuilder<CodegenResult<OwnedTargetIsa>>;
#[derive(Clone)]
pub struct IsaBuilder<T> {
triple: Triple,
/// Only used during fuzz-testing. Otherwise, this is a zero-sized struct
/// and compiled away. See [cranelift_control].
control_plane: ControlPlane,
setup: settings::Builder,
constructor: fn(Triple, settings::Flags, &settings::Builder) -> T,
constructor: fn(Triple, settings::Flags, &settings::Builder, ControlPlane) -> T,
}

impl<T> IsaBuilder<T> {
Expand All @@ -164,11 +174,13 @@ impl<T> IsaBuilder<T> {
/// function to generate the ISA from its components.
pub fn new(
triple: Triple,
control_plane: ControlPlane,
setup: settings::Builder,
constructor: fn(Triple, settings::Flags, &settings::Builder) -> T,
constructor: fn(Triple, settings::Flags, &settings::Builder, ControlPlane) -> T,
) -> Self {
IsaBuilder {
triple,
control_plane,
setup,
constructor,
}
Expand All @@ -191,7 +203,12 @@ impl<T> IsaBuilder<T> {
/// platform-independent features, like general SIMD support, may
/// need certain ISA extensions to be enabled.
pub fn finish(&self, shared_flags: settings::Flags) -> T {
(self.constructor)(self.triple.clone(), shared_flags, &self.setup)
(self.constructor)(
self.triple.clone(),
shared_flags,
&self.setup,
self.control_plane.clone(),
)
}
}

Expand Down
Loading