From 84a1e58b97e7d0a98c2bf125f61557df3ee734e2 Mon Sep 17 00:00:00 2001 From: T0b1 Date: Sun, 16 Apr 2023 13:52:37 +0200 Subject: [PATCH] try using bitmap instead of indexset --- src/ion/fast_alloc.rs | 45 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/src/ion/fast_alloc.rs b/src/ion/fast_alloc.rs index 1774dc2..358f18b 100644 --- a/src/ion/fast_alloc.rs +++ b/src/ion/fast_alloc.rs @@ -144,8 +144,8 @@ struct FastAllocState<'a, F: Function> { pub vregs: Vec, pub pregs: Vec, pub blocks: Vec, - pub liveins: Vec, - pub liveouts: Vec, + pub liveins: Vec, + pub liveouts: Vec, pub cur_stack_slot_idx: u32, pub reftype_vregs_in_pregs_count: u32, @@ -1093,6 +1093,7 @@ fn calc_use_positions_and_live_bitmaps<'a, F: Function>( calc_live_bitmaps(state, const_state) } +#[derive(Clone, Debug)] struct BlockBitmap { storage: SmallVec<[u64; 2]>, } @@ -1122,6 +1123,28 @@ impl BlockBitmap { let bit = 1u64 << (idx % 64); (self.storage[idx] & bit) != 0 } + + fn is_empty(&self) -> bool { + for &b in self.storage.iter() { + if b != 0 { + return false; + } + } + return true; + } + + pub fn union_with(&mut self, other: &Self) -> bool { + let mut changed = 0; + for (word_idx, &bits) in other.storage.iter().enumerate() { + if bits == 0 { + continue; + } + let self_word = &mut self.storage[word_idx]; + changed |= bits & !*self_word; + *self_word |= bits; + } + changed != 0 + } } // currently, copy from liveranges.rs @@ -1131,8 +1154,12 @@ fn calc_live_bitmaps<'a, F: Function>( state: &mut FastAllocState<'a, F>, const_state: &ReadOnlyData, ) -> Result<(), RegAllocError> { - state.liveins.resize(state.blocks.len(), IndexSet::new()); - state.liveouts.resize(state.blocks.len(), IndexSet::new()); + state + .liveins + .resize(state.blocks.len(), BlockBitmap::init(state.vregs.len())); + state + .liveouts + .resize(state.blocks.len(), BlockBitmap::init(state.vregs.len())); // Run a worklist algorithm to precisely compute liveins and // liveouts. @@ -1159,7 +1186,7 @@ fn calc_live_bitmaps<'a, F: Function>( if state.func.is_branch(insns.last()) { for i in 0..state.func.block_succs(block).len() { for ¶m in state.func.branch_blockparams(block, insns.last(), i) { - live.set(param.vreg(), true); + live.set(param.vreg()); } } } @@ -1171,14 +1198,14 @@ fn calc_live_bitmaps<'a, F: Function>( continue; } if op.pos() == *pos { - let was_live = live.get(op.vreg().vreg()); + let was_live = live.is_set(op.vreg().vreg()); trace!("op {:?} was_live = {}", op, was_live); match op.kind() { OperandKind::Use => { - live.set(op.vreg().vreg(), true); + live.set(op.vreg().vreg()); } OperandKind::Def => { - live.set(op.vreg().vreg(), false); + live.un_set(op.vreg().vreg()); } } } @@ -1186,7 +1213,7 @@ fn calc_live_bitmaps<'a, F: Function>( } } for &blockparam in state.func.block_params(block) { - live.set(blockparam.vreg(), false); + live.un_set(blockparam.vreg()); } for &pred in state.func.block_preds(block) {