Skip to content

Commit

Permalink
removing more hashmaps
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubDoka committed Sep 24, 2024
1 parent 7b89e02 commit 09d36db
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
28 changes: 10 additions & 18 deletions src/ion/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ impl<'a, F: Function> Env<'a, F> {

let inserted_moves = &mut moves.inserted_moves;
inserted_moves.moves.clear();
let inter_block_sources = &mut moves.inter_block_sources;
inter_block_sources.clear();
let inter_block_sources = moves.inter_block_sources.repopuate(
self.func.num_blocks(),
(VRegIndex::invalid(), Allocation::none()),
);
let inter_block_dests = moves.inter_block_dests.prepare(self.func.num_blocks());
let block_param_sources = &mut moves.block_param_sources;
block_param_sources.clear();
block_param_sources.reserve(3 * self.func.num_insts());
//block_param_sources.reserve(3 * self.func.num_insts());
let block_param_dests = moves.block_param_dests.prepare(3 * self.func.num_insts());
let reuse_input_insts = moves.reuse_input_insts.prepare(self.func.num_insts() / 2);

Expand All @@ -108,8 +110,6 @@ impl<'a, F: Function> Env<'a, F> {
continue;
}

inter_block_sources.clear();

// For each range in each vreg, insert moves or
// half-moves. We also scan over `blockparam_ins` and
// `blockparam_outs`, which are sorted by (block, vreg),
Expand Down Expand Up @@ -212,17 +212,9 @@ impl<'a, F: Function> Env<'a, F> {
}
trace!("examining block with end in range: block{}", block.index());

match inter_block_sources.entry(block) {
// If the entry is already present in the map, we'll try to prefer a
// register allocation.
Entry::Occupied(mut entry) => {
if !entry.get().is_reg() {
entry.insert(alloc);
}
}
Entry::Vacant(entry) => {
entry.insert(alloc);
}
let entry = &mut inter_block_sources[block.index()];
if entry.0 != vreg || !entry.1.is_reg() {
*entry = (vreg, alloc);
}

// Scan forward in `blockparam_outs`, adding all
Expand Down Expand Up @@ -455,7 +447,7 @@ impl<'a, F: Function> Env<'a, F> {
let vreg = self.vreg(vreg);
trace!("processing inter-block moves for {}", vreg);
for dest in inter_block_dests.drain(..) {
let src = inter_block_sources[&dest.from];
let (_, src) = inter_block_sources[dest.from.index()];

trace!(
" -> moving from {} to {} between {:?} and {:?}",
Expand Down Expand Up @@ -850,7 +842,7 @@ impl<'a, F: Function> Env<'a, F> {
pub struct MoveCtx {
inserted_moves: InsertedMoves,
edits: Edits,
inter_block_sources: FxHashMap<Block, Allocation>,
inter_block_sources: Vec<(VRegIndex, Allocation)>,
block_param_sources: FxHashMap<BlockparamSourceKey, Allocation>,
inter_block_dests: Vec<InterBlockDest>,
block_param_dests: Vec<BlockparamDest>,
Expand Down
38 changes: 30 additions & 8 deletions src/ion/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,37 @@ impl<'a, F: Function> Env<'a, F> {
let preg = PReg::from_index(reg.index());
trace!(" -> bundle {:?} assigned to preg {:?}", bundle, preg);
self.ctx.bundles[bundle].allocation = Allocation::reg(preg);
for entry in &self.ctx.bundles[bundle].ranges {
let key = LiveRangeKey::from_range(&entry.range);
let res = self.ctx.pregs[reg.index()]
.allocations
.btree
.insert(key, entry.index);

// We disallow LR overlap within bundles, so this should never be possible.
debug_assert!(res.is_none());
{
let from_list = &mut self.ctx.bundles[bundle].ranges;
let to_ranges = &mut self.ctx.pregs[reg.index()].allocations.btree.values;
to_ranges.resize(
to_ranges.len() + from_list.len(),
(LiveRangeKey { from: 0, to: 0 }, LiveRangeIndex(0)), // zero out
);

let mut reader = to_ranges.len() - from_list.len();
let mut writer = to_ranges.len();

for entry in from_list.into_iter().rev() {
let prev_reader = reader;
while reader != 0 {
match entry
.range
.from
.to_index()
.cmp(&to_ranges[reader - 1].0.from)
{
core::cmp::Ordering::Less => reader -= 1,
core::cmp::Ordering::Equal => unreachable!(),
core::cmp::Ordering::Greater => break,
}
}
writer -= prev_reader - reader;
to_ranges.copy_within(reader..prev_reader, writer);
writer -= 1;
to_ranges[writer] = (LiveRangeKey::from_range(&entry.range), entry.index);
}
}

AllocRegResult::Allocated(Allocation::reg(preg))
Expand Down

0 comments on commit 09d36db

Please sign in to comment.