Skip to content

Commit 5e0d894

Browse files
MachineEnv generic lifetime
1 parent 0d59759 commit 5e0d894

File tree

14 files changed

+50
-49
lines changed

14 files changed

+50
-49
lines changed

src/checker.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ impl CheckerState {
430430
alloc: Allocation,
431431
val: &CheckerValue,
432432
allocs: &[Allocation],
433-
checker: &Checker<'a, F>,
433+
checker: &Checker<'a, '_, F>,
434434
) -> Result<(), CheckerError> {
435435
if alloc == Allocation::none() {
436436
return Err(CheckerError::MissingAllocation { inst, op });
@@ -465,7 +465,7 @@ impl CheckerState {
465465
&self,
466466
pos: InstPosition,
467467
checkinst: &CheckerInst,
468-
checker: &Checker<'a, F>,
468+
checker: &Checker<'a, '_, F>,
469469
) -> Result<(), CheckerError> {
470470
let default_val = Default::default();
471471
match checkinst {
@@ -627,7 +627,7 @@ impl CheckerState {
627627
op: Operand,
628628
alloc: Allocation,
629629
allocs: &[Allocation],
630-
checker: &Checker<'a, F>,
630+
checker: &Checker<'a, '_, F>,
631631
) -> Result<(), CheckerError> {
632632
match op.constraint() {
633633
OperandConstraint::Any => {}
@@ -691,21 +691,21 @@ pub(crate) enum CheckerInst {
691691
}
692692

693693
#[derive(Debug)]
694-
pub struct Checker<'a, F: Function> {
694+
pub struct Checker<'a, 'r, F: Function> {
695695
f: &'a F,
696696
bb_in: FxHashMap<Block, CheckerState>,
697697
bb_insts: FxHashMap<Block, Vec<CheckerInst>>,
698698
edge_insts: FxHashMap<(Block, Block), Vec<CheckerInst>>,
699-
machine_env: &'a MachineEnv,
699+
machine_env: &'a MachineEnv<'r>,
700700
stack_pregs: PRegSet,
701701
}
702702

703-
impl<'a, F: Function> Checker<'a, F> {
703+
impl<'a, 'r, F: Function> Checker<'a, 'r, F> {
704704
/// Create a new checker for the given function, initializing CFG
705705
/// info immediately. The client should call the `add_*()`
706706
/// methods to add abstract instructions to each BB before
707707
/// invoking `run()` to check for errors.
708-
pub fn new(f: &'a F, machine_env: &'a MachineEnv) -> Checker<'a, F> {
708+
pub fn new(f: &'a F, machine_env: &'a MachineEnv<'r>) -> Checker<'a, 'r, F> {
709709
let mut bb_in = FxHashMap::default();
710710
let mut bb_insts = FxHashMap::default();
711711
let mut edge_insts = FxHashMap::default();

src/fastalloc/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl RealFunction {
140140
}
141141
}
142142

143-
fn mach_env(no_of_regs: usize) -> MachineEnv {
143+
fn mach_env(no_of_regs: usize) -> MachineEnv<'static> {
144144
MachineEnv {
145145
preferred_regs_by_class: [
146146
Vec::leak(

src/fuzzing/func.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -624,30 +624,32 @@ impl core::fmt::Debug for Func {
624624
}
625625
}
626626

627-
pub fn machine_env() -> MachineEnv {
628-
fn regs(r: core::ops::Range<usize>, c: RegClass) -> Vec<PReg> {
629-
r.map(|i| PReg::new(i, c)).collect()
627+
pub fn machine_env() -> MachineEnv<'static> {
628+
fn regs(r: core::ops::Range<usize>, c: RegClass) -> &'static [PReg] {
629+
Vec::leak(r.map(|i| PReg::new(i, c)).collect())
630630
}
631-
let preferred_regs_by_class: [Vec<PReg>; 3] = [
631+
let preferred_regs_by_class: [&'static [PReg]; 3] = [
632632
regs(0..24, RegClass::Int),
633633
regs(0..24, RegClass::Float),
634634
regs(0..24, RegClass::Vector),
635635
];
636-
let non_preferred_regs_by_class: [Vec<PReg>; 3] = [
636+
let non_preferred_regs_by_class: [&'static [PReg]; 3] = [
637637
regs(24..32, RegClass::Int),
638638
regs(24..32, RegClass::Float),
639639
regs(24..32, RegClass::Vector),
640640
];
641641
let scratch_by_class: [Option<PReg>; 3] = [None, None, None];
642-
let fixed_stack_slots = (32..63)
643-
.flat_map(|i| {
644-
[
645-
PReg::new(i, RegClass::Int),
646-
PReg::new(i, RegClass::Float),
647-
PReg::new(i, RegClass::Vector),
648-
]
649-
})
650-
.collect();
642+
let fixed_stack_slots = Vec::leak(
643+
(32..63)
644+
.flat_map(|i| {
645+
[
646+
PReg::new(i, RegClass::Int),
647+
PReg::new(i, RegClass::Float),
648+
PReg::new(i, RegClass::Vector),
649+
]
650+
})
651+
.collect(),
652+
);
651653
// Register 63 is reserved for use as a fixed non-allocatable register.
652654
MachineEnv {
653655
preferred_regs_by_class,

src/ion/data_structures.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,27 +497,27 @@ impl Ctx {
497497
}
498498
}
499499

500-
pub struct Env<'a, F: Function> {
500+
pub struct Env<'a, 'r, F: Function> {
501501
pub func: &'a F,
502-
pub env: &'a MachineEnv,
502+
pub env: &'a MachineEnv<'r>,
503503
pub ctx: &'a mut Ctx,
504504
}
505505

506-
impl<'a, F: Function> Deref for Env<'a, F> {
506+
impl<'a, F: Function> Deref for Env<'a, '_, F> {
507507
type Target = Ctx;
508508

509509
fn deref(&self) -> &Self::Target {
510510
self.ctx
511511
}
512512
}
513513

514-
impl<'a, F: Function> DerefMut for Env<'a, F> {
514+
impl<'a, F: Function> DerefMut for Env<'a, '_, F> {
515515
fn deref_mut(&mut self) -> &mut Self::Target {
516516
self.ctx
517517
}
518518
}
519519

520-
impl<'a, F: Function> Env<'a, F> {
520+
impl<'a, F: Function> Env<'a, '_, F> {
521521
/// Get the VReg (with bundled RegClass) from a vreg index.
522522
#[inline]
523523
pub fn vreg(&self, index: VRegIndex) -> VReg {

src/ion/dump.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use alloc::{string::String, vec::Vec};
77
use super::Env;
88
use crate::{Block, Function, ProgPoint};
99

10-
impl<'a, F: Function> Env<'a, F> {
10+
impl<'a, F: Function> Env<'a, '_, F> {
1111
pub fn dump_state(&self) {
1212
trace!("Bundles:");
1313
for (i, b) in self.bundles.iter().enumerate() {

src/ion/liveranges.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl core::ops::Add<SpillWeight> for SpillWeight {
9494
}
9595
}
9696

97-
impl<'a, F: Function> Env<'a, F> {
97+
impl<'a, F: Function> Env<'a, '_, F> {
9898
pub fn create_pregs_and_vregs(&mut self) {
9999
// Create PRegs from the env.
100100
self.pregs.resize(

src/ion/merge.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use crate::{
2222
};
2323
use alloc::format;
2424

25-
impl<'a, F: Function> Env<'a, F> {
25+
impl<'a, F: Function> Env<'a, '_, F> {
2626
pub fn merge_bundles(&mut self, from: LiveBundleIndex, to: LiveBundleIndex) -> bool {
2727
if from == to {
2828
// Merge bundle into self -- trivial merge.

src/ion/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ pub(crate) mod dump;
3535
pub(crate) mod moves;
3636
pub(crate) mod spill;
3737

38-
impl<'a, F: Function> Env<'a, F> {
39-
pub(crate) fn new(func: &'a F, env: &'a MachineEnv, ctx: &'a mut Ctx) -> Self {
38+
impl<'a, 'r, F: Function> Env<'a, 'r, F> {
39+
pub(crate) fn new(func: &'a F, env: &'a MachineEnv<'r>, ctx: &'a mut Ctx) -> Self {
4040
let ninstrs = func.num_insts();
4141
let nblocks = func.num_blocks();
4242

src/ion/moves.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use alloc::vec::Vec;
3333
use hashbrown::hash_map::Entry;
3434
use smallvec::{smallvec, SmallVec};
3535

36-
impl<'a, F: Function> Env<'a, F> {
36+
impl<'a, F: Function> Env<'a, '_, F> {
3737
pub fn is_start_of_block(&self, pos: ProgPoint) -> bool {
3838
let block = self.ctx.cfginfo.insn_block[pos.inst().index()];
3939
pos == self.ctx.cfginfo.block_entry[block.index()]
@@ -171,7 +171,7 @@ impl<'a, F: Function> Env<'a, F> {
171171
// and moves go at start of `to`.
172172
#[inline(always)]
173173
fn choose_move_location<'a, F: Function>(
174-
env: &Env<'a, F>,
174+
env: &Env<'a, '_, F>,
175175
from: Block,
176176
to: Block,
177177
) -> (ProgPoint, InsertMovePrio) {
@@ -787,7 +787,7 @@ impl<'a, F: Function> Env<'a, F> {
787787
let mut redundant_moves = RedundantMoveEliminator::default();
788788

789789
fn redundant_move_process_side_effects<'a, F: Function>(
790-
this: &Env<'a, F>,
790+
this: &Env<'a, '_, F>,
791791
redundant_moves: &mut RedundantMoveEliminator,
792792
from: ProgPoint,
793793
to: ProgPoint,

src/ion/process.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pub enum AllocRegResult<'a> {
3636
ConflictHighCost,
3737
}
3838

39-
impl<'a, F: Function> Env<'a, F> {
39+
impl<'a, F: Function> Env<'a, '_, F> {
4040
pub fn process_bundles(&mut self) -> Result<(), RegAllocError> {
4141
while let Some((bundle, reg_hint)) = self.ctx.allocation_queue.pop() {
4242
self.ctx.output.stats.process_bundle_count += 1;

0 commit comments

Comments
 (0)