cranelift-frontend: SSA-building cleanup (#4984)

* Cleanups to cranelift-frontend SSA construction

* Encode sealed/undef_variables relationship in type

A block can't have any undef_variables if it is sealed. It's useful to
make that fact explicit in the types so that any time either value is
used, it's clear that we should think about the other one too.

In addition, encoding this fact in an enum type lets Rust apply an
optimization that reduces the size of SSABlockData by 8 bytes, making it
fit in a 64-byte cache line. I haven't taken the extra step of making
SSABlockData be 64-byte aligned because 1) it doesn't seem to have a
performance impact and b) doing so makes other structures quite a bit
bigger.

* Simplify finish_predecessors_lookup

Using Vec::drain is more concise than a combination of
iter().rev().take() followed by Vec::truncate. And in this case it
doesn't matter what order we examine the results in, because we just
want to know if they're all equal, so we might as well iterate forward
instead of in reverse.

There's no need for the ZeroOneOrMore enum. Instead, there are only two
cases: either we have a single value to use for the variable (possibly
synthesized as a constant zero), or we need to add a block parameter in
every predecessor.

Pre-filtering the results iterator to eliminate the sentinel makes it
easy to identify how many distinct definitions this variable has.
iter.next() indicates if there are any definitions at all, and then
iter.all() is a clear way to express that we want to know if the
remaining definitions are the same as the first one.

* Simplify append_jump_argument

* Avoid assigning default() into SecondaryMap

This eliminates some redundant reads and writes.

* cranelift-frontend: Construct with default()

This eliminates a bunch of boilerplate in favor of a built in `derive`
macro.

Also I'm deleting an import that had the comment "FIXME: Remove in
edition2021", which we've been using everywhere since April.

* Fix tests
This commit is contained in:
Jamey Sharp
2022-09-29 16:59:47 -07:00
committed by GitHub
parent 46e42601eb
commit 77ab99d3b0
3 changed files with 151 additions and 232 deletions

View File

@@ -19,6 +19,16 @@ where
unused: PhantomData<K>,
}
impl<K: EntityRef> Default for EntitySet<K> {
fn default() -> Self {
Self {
elems: Vec::new(),
len: 0,
unused: PhantomData,
}
}
}
/// Shared `EntitySet` implementation for all value types.
impl<K> EntitySet<K>
where
@@ -26,11 +36,7 @@ where
{
/// Create a new empty set.
pub fn new() -> Self {
Self {
elems: Vec::new(),
len: 0,
unused: PhantomData,
}
Self::default()
}
/// Creates a new empty set with the specified capacity.