Commit Graph

4 Commits

Author SHA1 Message Date
Michael Gottesman
6fee59bd6a [semantic-arc-opts] Implement @owned phi web elimination for phi webs with a single phi node that only have copy_value introducers.
This is the most simple initial version that I can commit. The hope is that this will help to bring this up in a nice way.

I am going to handle the multiple phi node and load [copy] case later to reduce
code churn.

<rdar://problem/56720436>
2020-03-09 16:04:48 -07:00
Michael Gottesman
bc8a4db572 Revert "Revert "[basic] Add a simple vector backed 2 stage multi map.""
This reverts commit f071cf133a.

With ASAN fixes.
2020-02-16 23:14:57 -08:00
Andrew Trick
f071cf133a Revert "[basic] Add a simple vector backed 2 stage multi map." 2020-01-07 16:05:21 -08:00
Michael Gottesman
96a0c7931d [basic] Add a simple vector backed 2 stage multi map.
I have been using this in a bunch of places in the compiler and rather than
implement it by hand over and over (and maybe messing up), this commit just
commits a correct implementation.

This data structure is a map backed by a vector like data structure. It has two
phases:

1. An insertion phase when the map is mutable and one inserts (key, value) pairs
into the map. These are just appeneded into the storage array.

2. A frozen stage when the map is immutable and one can now perform map queries
on the multimap.

The map transitions from the mutable, thawed phase to the immutable, frozen
phase by performing a stable_sort of its internal storage by only the key. Since
this is a stable_sort, we know that the relative insertion order of values is
preserved if their keys equal. Thus the sorting will have created contiguous
regions in the array of values, all mapped to the same key, that are insertion
order. Thus by finding the lower_bound for a given key, we are guaranteed to get
the first element in that continguous range. We can then do a forward search to
find the end of the region, allowing us to then return an ArrayRef to these
internal values.

The reason why I keep on finding myself using this is that this map enables one
to map a key to an array of values without needing to store small vectors in a
map or use heap allocated memory, all key, value pairs are stored inline (in
potentially a single SmallVector given that one is using SmallFrozenMultiMap).
2020-01-06 16:39:42 -08:00