Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cranelift-codegen): remove OnceLock #8489

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
11 changes: 2 additions & 9 deletions cranelift/codegen/src/isa/aarch64/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ use alloc::boxed::Box;
use alloc::vec::Vec;
use regalloc2::{MachineEnv, PReg, PRegSet};
use smallvec::{smallvec, SmallVec};
use std::sync::OnceLock;

// We use a generic implementation that factors out AArch64 and x64 ABI commonalities, because
// these ABIs are very similar.
Expand Down Expand Up @@ -1154,14 +1153,8 @@ impl ABIMachineSpec for AArch64MachineDeps {
s.nominal_sp_to_fp
}

fn get_machine_env(flags: &settings::Flags, _call_conv: isa::CallConv) -> &MachineEnv {
if flags.enable_pinned_reg() {
static MACHINE_ENV: OnceLock<MachineEnv> = OnceLock::new();
MACHINE_ENV.get_or_init(|| create_reg_env(true))
} else {
static MACHINE_ENV: OnceLock<MachineEnv> = OnceLock::new();
MACHINE_ENV.get_or_init(|| create_reg_env(false))
}
fn get_machine_env(flags: &settings::Flags) -> MachineEnv {
create_reg_env(flags.enable_pinned_reg())
}

fn get_regs_clobbered_by_call(_call_conv: isa::CallConv) -> PRegSet {
Expand Down
6 changes: 2 additions & 4 deletions cranelift/codegen/src/isa/riscv64/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use alloc::vec::Vec;
use regalloc2::{MachineEnv, PReg, PRegSet};

use smallvec::{smallvec, SmallVec};
use std::sync::OnceLock;

/// Support for the Riscv64 ABI from the callee side (within a function body).
pub(crate) type Riscv64Callee = Callee<Riscv64MachineDeps>;
Expand Down Expand Up @@ -704,9 +703,8 @@ impl ABIMachineSpec for Riscv64MachineDeps {
s.nominal_sp_to_fp
}

fn get_machine_env(_flags: &settings::Flags, _call_conv: isa::CallConv) -> &MachineEnv {
static MACHINE_ENV: OnceLock<MachineEnv> = OnceLock::new();
MACHINE_ENV.get_or_init(create_reg_enviroment)
fn get_machine_env(_flags: &settings::Flags) -> MachineEnv {
create_reg_enviroment()
}

fn get_regs_clobbered_by_call(_call_conv_of_callee: isa::CallConv) -> PRegSet {
Expand Down
6 changes: 2 additions & 4 deletions cranelift/codegen/src/isa/s390x/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ use crate::{CodegenError, CodegenResult};
use alloc::vec::Vec;
use regalloc2::{MachineEnv, PRegSet};
use smallvec::{smallvec, SmallVec};
use std::sync::OnceLock;

// We use a generic implementation that factors out ABI commonalities.

Expand Down Expand Up @@ -786,9 +785,8 @@ impl ABIMachineSpec for S390xMachineDeps {
s.initial_sp_offset
}

fn get_machine_env(_flags: &settings::Flags, _call_conv: isa::CallConv) -> &MachineEnv {
static MACHINE_ENV: OnceLock<MachineEnv> = OnceLock::new();
MACHINE_ENV.get_or_init(create_machine_env)
fn get_machine_env(_flags: &settings::Flags) -> MachineEnv {
create_machine_env()
}

fn get_regs_clobbered_by_call(_call_conv_of_callee: isa::CallConv) -> PRegSet {
Expand Down
11 changes: 2 additions & 9 deletions cranelift/codegen/src/isa/x64/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use alloc::vec::Vec;
use args::*;
use regalloc2::{MachineEnv, PReg, PRegSet};
use smallvec::{smallvec, SmallVec};
use std::sync::OnceLock;

/// This is the limit for the size of argument and return-value areas on the
/// stack. We place a reasonable limit here to avoid integer overflow issues
Expand Down Expand Up @@ -936,14 +935,8 @@ impl ABIMachineSpec for X64ABIMachineSpec {
s.nominal_sp_to_fp()
}

fn get_machine_env(flags: &settings::Flags, _call_conv: isa::CallConv) -> &MachineEnv {
if flags.enable_pinned_reg() {
static MACHINE_ENV: OnceLock<MachineEnv> = OnceLock::new();
MACHINE_ENV.get_or_init(|| create_reg_env_systemv(true))
} else {
static MACHINE_ENV: OnceLock<MachineEnv> = OnceLock::new();
MACHINE_ENV.get_or_init(|| create_reg_env_systemv(false))
}
fn get_machine_env(flags: &settings::Flags) -> MachineEnv {
create_reg_env_systemv(flags.enable_pinned_reg())
}

fn get_regs_clobbered_by_call(call_conv_of_callee: isa::CallConv) -> PRegSet {
Expand Down
10 changes: 7 additions & 3 deletions cranelift/codegen/src/machinst/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ pub trait ABIMachineSpec {
fn get_nominal_sp_to_fp(s: &<Self::I as MachInstEmit>::State) -> i64;

/// Get the ABI-dependent MachineEnv for managing register allocation.
fn get_machine_env(flags: &settings::Flags, call_conv: isa::CallConv) -> &MachineEnv;
fn get_machine_env(flags: &settings::Flags) -> MachineEnv;

/// Get all caller-save registers, that is, registers that we expect
/// not to be saved across a call to a callee with the given ABI.
Expand Down Expand Up @@ -1118,6 +1118,7 @@ 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>)>,
machine_env: MachineEnv,

_mach: PhantomData<M>,
}
Expand Down Expand Up @@ -1227,6 +1228,8 @@ impl<M: ABIMachineSpec> Callee<M> {

let tail_args_size = sigs[sig].sized_stack_arg_space;

let machine_env = M::get_machine_env(&flags);

Ok(Self {
ir_sig: ensure_struct_return_ptr_is_returned(&f.signature),
sig,
Expand All @@ -1244,6 +1247,7 @@ impl<M: ABIMachineSpec> Callee<M> {
isa_flags: isa_flags.clone(),
is_leaf: f.is_leaf(),
stack_limit,
machine_env,
_mach: PhantomData,
})
}
Expand Down Expand Up @@ -1449,8 +1453,8 @@ impl<M: ABIMachineSpec> Callee<M> {
}

/// Get the ABI-dependent MachineEnv for managing register allocation.
pub fn machine_env(&self, sigs: &SigSet) -> &MachineEnv {
M::get_machine_env(&self.flags, self.call_conv(sigs))
pub fn machine_env(&self) -> &MachineEnv {
&self.machine_env
}

/// The offsets of all sized stack slots (not spill slots) for debuginfo purposes.
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/machinst/vcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ impl<I: VCodeInst> VCode<I> {

/// Get the ABI-dependent MachineEnv for managing register allocation.
pub fn machine_env(&self) -> &MachineEnv {
self.abi.machine_env(&self.sigs)
self.abi.machine_env()
}

/// Get the number of blocks. Block indices will be in the range `0 ..
Expand Down
Loading