From c4a0d85b722fcac63d5a9c3b68a4f3309b63af82 Mon Sep 17 00:00:00 2001 From: T0b1 Date: Sat, 15 Apr 2023 03:11:32 +0200 Subject: [PATCH] dont calc cfginfo --- src/ion/fast_alloc.rs | 24 +++++++++++------------- src/ion/mod.rs | 15 ++++++++++----- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/ion/fast_alloc.rs b/src/ion/fast_alloc.rs index 3d6141b..a8b0af6 100644 --- a/src/ion/fast_alloc.rs +++ b/src/ion/fast_alloc.rs @@ -4,12 +4,12 @@ use alloc::{string::String, vec}; use smallvec::{smallvec, SmallVec}; use std::{convert::TryFrom, println}; -use crate::InstPosition; use crate::{ cfg::CFGInfo, Allocation, Block, Edit, Function, Inst, MachineEnv, Operand, OperandConstraint, OperandKind, OperandPos, Output, PReg, PRegSet, ProgPoint, RegAllocError, RegClass, SpillSlot, VReg, }; +use crate::{postorder, InstPosition}; use super::Stats; @@ -39,7 +39,7 @@ struct ReadOnlyData { } impl ReadOnlyData { - pub fn init(func: &F, mach_env: &MachineEnv, cfg: &CFGInfo) -> Self { + pub fn init(func: &F, mach_env: &MachineEnv) -> Self { let reg_order_int = { let class = RegClass::Int as usize; let amount = mach_env.preferred_regs_by_class[class].len() @@ -63,7 +63,9 @@ impl ReadOnlyData { Self { reg_order_int, reg_order_float, - postorder: cfg.postorder.clone(), + postorder: postorder::calculate(func.num_blocks(), func.entry_block(), |b| { + func.block_succs(b) + }), } } @@ -139,11 +141,10 @@ struct FastAllocState<'a, F: Function> { pub func: &'a F, pub mach_env: &'a MachineEnv, - pub cfg: &'a CFGInfo, } impl<'a, F: Function> FastAllocState<'a, F> { - pub fn init(func: &'a F, mach_env: &'a MachineEnv, cfg: &'a CFGInfo) -> Self { + pub fn init(func: &'a F, mach_env: &'a MachineEnv) -> Self { let reftype_vregs = func.reftype_vregs(); let vregs = { @@ -162,6 +163,7 @@ impl<'a, F: Function> FastAllocState<'a, F> { pregs.resize(PReg::NUM_INDEX, PRegData::default()); for preg in &mach_env.fixed_stack_slots { + trace!("{} is a stack pseudo", preg); pregs[preg.index()].stack_pseudo = true; } pregs @@ -214,7 +216,6 @@ impl<'a, F: Function> FastAllocState<'a, F> { func, mach_env, - cfg, } } @@ -238,6 +239,7 @@ impl<'a, F: Function> FastAllocState<'a, F> { self.stack_slot_count_float }; let idx = self.cur_stack_slot_idx; + trace!("Allocated slot {} for {}", idx, vreg); self.cur_stack_slot_idx += size as u32; data.slot_idx = Some(idx); idx @@ -372,17 +374,13 @@ impl<'a, F: Function> FastAllocState<'a, F> { } } -pub fn run( - func: &F, - mach_env: &MachineEnv, - cfg: CFGInfo, -) -> Result { +pub fn run(func: &F, mach_env: &MachineEnv) -> Result { if func.multi_spillslot_named_by_last_slot() { panic!("MultiSpillslotIndexPos not supported"); } - let mut state = FastAllocState::init(func, mach_env, &cfg); - let const_state = ReadOnlyData::init(func, mach_env, &cfg); + let mut state = FastAllocState::init(func, mach_env); + let const_state = ReadOnlyData::init(func, mach_env); state.blocks[func.entry_block().index()].params_allocated = true; diff --git a/src/ion/mod.rs b/src/ion/mod.rs index 246777b..7fdae2b 100644 --- a/src/ion/mod.rs +++ b/src/ion/mod.rs @@ -36,10 +36,10 @@ pub(crate) mod process; use process::*; use smallvec::smallvec; pub(crate) mod dump; +mod fast_alloc; pub(crate) mod moves; pub(crate) mod spill; pub(crate) mod stackmap; -mod fast_alloc; impl<'a, F: Function> Env<'a, F> { pub(crate) fn new( @@ -123,17 +123,22 @@ pub fn run( enable_ssa_checker: bool, use_fast_alloc: bool, ) -> Result { - let cfginfo = CFGInfo::new(func, !use_fast_alloc)?; + let mut cfginfo = None; if enable_ssa_checker { - validate_ssa(func, &cfginfo)?; + cfginfo = Some(CFGInfo::new(func, !use_fast_alloc)?); + validate_ssa(func, cfginfo.as_ref().unwrap())?; } if use_fast_alloc { - return fast_alloc::run(func, mach_env, cfginfo); + return fast_alloc::run(func, mach_env); } - let mut env = Env::new(func, mach_env, cfginfo, enable_annotations); + if cfginfo.is_none() { + cfginfo = Some(CFGInfo::new(func, !use_fast_alloc)?); + } + + let mut env = Env::new(func, mach_env, cfginfo.take().unwrap(), enable_annotations); env.init()?; env.run()?;