MachInst backend: don't reallocate RealRegUniverses for each function
compilation. This saves ~0.14% instruction count, ~0.18% allocated bytes, and ~1.5% allocated blocks on a `clif-util wasm` compilation of `bz2.wasm` for aarch64.
This commit is contained in:
@@ -1903,10 +1903,6 @@ impl MachInst for Inst {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reg_universe(flags: &settings::Flags) -> RealRegUniverse {
|
|
||||||
create_reg_universe(flags)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
|
|||||||
@@ -25,12 +25,18 @@ use inst::create_reg_universe;
|
|||||||
pub struct AArch64Backend {
|
pub struct AArch64Backend {
|
||||||
triple: Triple,
|
triple: Triple,
|
||||||
flags: settings::Flags,
|
flags: settings::Flags,
|
||||||
|
reg_universe: RealRegUniverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AArch64Backend {
|
impl AArch64Backend {
|
||||||
/// Create a new AArch64 backend with the given (shared) flags.
|
/// Create a new AArch64 backend with the given (shared) flags.
|
||||||
pub fn new_with_flags(triple: Triple, flags: settings::Flags) -> AArch64Backend {
|
pub fn new_with_flags(triple: Triple, flags: settings::Flags) -> AArch64Backend {
|
||||||
AArch64Backend { triple, flags }
|
let reg_universe = create_reg_universe(&flags);
|
||||||
|
AArch64Backend {
|
||||||
|
triple,
|
||||||
|
flags,
|
||||||
|
reg_universe,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This performs lowering to VCode, register-allocates the code, computes block layout and
|
/// This performs lowering to VCode, register-allocates the code, computes block layout and
|
||||||
@@ -81,8 +87,8 @@ impl MachBackend for AArch64Backend {
|
|||||||
&self.flags
|
&self.flags
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reg_universe(&self) -> RealRegUniverse {
|
fn reg_universe(&self) -> &RealRegUniverse {
|
||||||
create_reg_universe(&self.flags)
|
&self.reg_universe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ mod emit_tests;
|
|||||||
pub mod regs;
|
pub mod regs;
|
||||||
|
|
||||||
use args::*;
|
use args::*;
|
||||||
use regs::{create_reg_universe_systemv, show_ireg_sized};
|
use regs::show_ireg_sized;
|
||||||
|
|
||||||
//=============================================================================
|
//=============================================================================
|
||||||
// Instructions (top level): definition
|
// Instructions (top level): definition
|
||||||
@@ -943,10 +943,6 @@ impl MachInst for Inst {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reg_universe(flags: &settings::Flags) -> RealRegUniverse {
|
|
||||||
create_reg_universe_systemv(flags)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<O: MachSectionOutput> MachInstEmit<O> for Inst {
|
impl<O: MachSectionOutput> MachInstEmit<O> for Inst {
|
||||||
|
|||||||
@@ -22,12 +22,18 @@ mod lower;
|
|||||||
pub(crate) struct X64Backend {
|
pub(crate) struct X64Backend {
|
||||||
triple: Triple,
|
triple: Triple,
|
||||||
flags: Flags,
|
flags: Flags,
|
||||||
|
reg_universe: RealRegUniverse,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl X64Backend {
|
impl X64Backend {
|
||||||
/// Create a new X64 backend with the given (shared) flags.
|
/// Create a new X64 backend with the given (shared) flags.
|
||||||
fn new_with_flags(triple: Triple, flags: Flags) -> Self {
|
fn new_with_flags(triple: Triple, flags: Flags) -> Self {
|
||||||
Self { triple, flags }
|
let reg_universe = create_reg_universe_systemv(&flags);
|
||||||
|
Self {
|
||||||
|
triple,
|
||||||
|
flags,
|
||||||
|
reg_universe,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn compile_vcode(&self, func: &Function, flags: Flags) -> CodegenResult<VCode<inst::Inst>> {
|
fn compile_vcode(&self, func: &Function, flags: Flags) -> CodegenResult<VCode<inst::Inst>> {
|
||||||
@@ -74,8 +80,8 @@ impl MachBackend for X64Backend {
|
|||||||
self.triple.clone()
|
self.triple.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reg_universe(&self) -> RealRegUniverse {
|
fn reg_universe(&self) -> &RealRegUniverse {
|
||||||
create_reg_universe_systemv(&self.flags)
|
&self.reg_universe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ use regalloc::{allocate_registers_with_opts, Algorithm, Options};
|
|||||||
|
|
||||||
/// Compile the given function down to VCode with allocated registers, ready
|
/// Compile the given function down to VCode with allocated registers, ready
|
||||||
/// for binary emission.
|
/// for binary emission.
|
||||||
pub fn compile<B: LowerBackend>(
|
pub fn compile<B: LowerBackend + MachBackend>(
|
||||||
f: &Function,
|
f: &Function,
|
||||||
b: &B,
|
b: &B,
|
||||||
abi: Box<dyn ABIBody<I = B::MInst>>,
|
abi: Box<dyn ABIBody<I = B::MInst>>,
|
||||||
@@ -21,9 +21,10 @@ where
|
|||||||
// This lowers the CL IR.
|
// This lowers the CL IR.
|
||||||
let mut vcode = Lower::new(f, abi)?.lower(b)?;
|
let mut vcode = Lower::new(f, abi)?.lower(b)?;
|
||||||
|
|
||||||
let universe = &B::MInst::reg_universe(vcode.flags());
|
debug!(
|
||||||
|
"vcode from lowering: \n{}",
|
||||||
debug!("vcode from lowering: \n{}", vcode.show_rru(Some(universe)));
|
vcode.show_rru(Some(b.reg_universe()))
|
||||||
|
);
|
||||||
|
|
||||||
// Perform register allocation.
|
// Perform register allocation.
|
||||||
let (run_checker, algorithm) = match vcode.flags().regalloc() {
|
let (run_checker, algorithm) = match vcode.flags().regalloc() {
|
||||||
@@ -40,7 +41,7 @@ where
|
|||||||
let _tt = timing::regalloc();
|
let _tt = timing::regalloc();
|
||||||
allocate_registers_with_opts(
|
allocate_registers_with_opts(
|
||||||
&mut vcode,
|
&mut vcode,
|
||||||
universe,
|
b.reg_universe(),
|
||||||
Options {
|
Options {
|
||||||
run_checker,
|
run_checker,
|
||||||
algorithm,
|
algorithm,
|
||||||
@@ -49,7 +50,7 @@ where
|
|||||||
.map_err(|err| {
|
.map_err(|err| {
|
||||||
debug!(
|
debug!(
|
||||||
"Register allocation error for vcode\n{}\nError: {:?}",
|
"Register allocation error for vcode\n{}\nError: {:?}",
|
||||||
vcode.show_rru(Some(universe)),
|
vcode.show_rru(Some(b.reg_universe())),
|
||||||
err
|
err
|
||||||
);
|
);
|
||||||
err
|
err
|
||||||
@@ -68,7 +69,7 @@ where
|
|||||||
|
|
||||||
debug!(
|
debug!(
|
||||||
"vcode after regalloc: final version:\n{}",
|
"vcode after regalloc: final version:\n{}",
|
||||||
vcode.show_rru(Some(universe))
|
vcode.show_rru(Some(b.reg_universe()))
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(vcode)
|
Ok(vcode)
|
||||||
|
|||||||
@@ -186,9 +186,6 @@ pub trait MachInst: Clone + Debug {
|
|||||||
/// BlockIndex.
|
/// BlockIndex.
|
||||||
fn with_block_offsets(&mut self, my_offset: CodeOffset, targets: &[CodeOffset]);
|
fn with_block_offsets(&mut self, my_offset: CodeOffset, targets: &[CodeOffset]);
|
||||||
|
|
||||||
/// Get the register universe for this backend.
|
|
||||||
fn reg_universe(flags: &Flags) -> RealRegUniverse;
|
|
||||||
|
|
||||||
/// Align a basic block offset (from start of function). By default, no
|
/// Align a basic block offset (from start of function). By default, no
|
||||||
/// alignment occurs.
|
/// alignment occurs.
|
||||||
fn align_basic_block(offset: CodeOffset) -> CodeOffset {
|
fn align_basic_block(offset: CodeOffset) -> CodeOffset {
|
||||||
@@ -264,7 +261,7 @@ pub trait MachBackend {
|
|||||||
fn name(&self) -> &'static str;
|
fn name(&self) -> &'static str;
|
||||||
|
|
||||||
/// Return the register universe for this backend.
|
/// Return the register universe for this backend.
|
||||||
fn reg_universe(&self) -> RealRegUniverse;
|
fn reg_universe(&self) -> &RealRegUniverse;
|
||||||
|
|
||||||
/// Machine-specific condcode info needed by TargetIsa.
|
/// Machine-specific condcode info needed by TargetIsa.
|
||||||
fn unsigned_add_overflow_condition(&self) -> IntCC {
|
fn unsigned_add_overflow_condition(&self) -> IntCC {
|
||||||
|
|||||||
Reference in New Issue
Block a user