From 1f9258bea5ff10ed93bb28b11319af0ca4c557b3 Mon Sep 17 00:00:00 2001 From: Chris Fallin Date: Wed, 12 May 2021 01:06:27 -0700 Subject: [PATCH] Detect undefined liveins. --- src/ion/mod.rs | 17 +++++++++++++++-- src/lib.rs | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ion/mod.rs b/src/ion/mod.rs index 459f069..7c3adaf 100644 --- a/src/ion/mod.rs +++ b/src/ion/mod.rs @@ -1163,7 +1163,7 @@ impl<'a, F: Function> Env<'a, F> { self.liveins[block.index()].get(vreg.index()) } - fn compute_liveness(&mut self) { + fn compute_liveness(&mut self) -> Result<(), RegAllocError> { // Create initial LiveIn and LiveOut bitsets. for _ in 0..self.func.blocks() { self.liveins.push(BitVec::new()); @@ -1226,6 +1226,17 @@ impl<'a, F: Function> Env<'a, F> { self.liveins[block.index()] = live; } + // Check that there are no liveins to the entry block. (The + // client should create a virtual intsruction that defines any + // PReg liveins if necessary.) + if self.liveins[self.func.entry_block().index()] + .iter() + .next() + .is_some() + { + return Err(RegAllocError::EntryLivein); + } + let mut num_ranges = 0; for &vreg in self.func.reftype_vregs() { @@ -1827,6 +1838,8 @@ impl<'a, F: Function> Env<'a, F> { self.stats.initial_liverange_count = self.ranges.len(); self.stats.blockparam_ins_count = self.blockparam_ins.len(); self.stats.blockparam_outs_count = self.blockparam_outs.len(); + + Ok(()) } fn compute_hot_code(&mut self) { @@ -4549,7 +4562,7 @@ impl<'a, F: Function> Env<'a, F> { pub(crate) fn init(&mut self) -> Result<(), RegAllocError> { self.create_pregs_and_vregs(); self.compute_hot_code(); - self.compute_liveness(); + self.compute_liveness()?; self.merge_vreg_bundles(); self.queue_bundles(); if log::log_enabled!(log::Level::Debug) { diff --git a/src/lib.rs b/src/lib.rs index f6f0139..961be75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -981,6 +981,8 @@ pub enum RegAllocError { /// Invalid branch: operand count does not match sum of block /// params of successor blocks. Branch(Inst), + /// A VReg is live-in on entry; this is not allowed. + EntryLivein, } impl std::fmt::Display for RegAllocError {