Commit Graph

7 Commits

Author SHA1 Message Date
Michael Gottesman
9568d53c8f [frozen-multimap] Add support for erasing once we have finished constructing the map.
I implemented this in a similar way to the way blotting is implemented in a blot
map vector:

1. I changed this to store (Key, Optional<Value>) pairs.

2. I made it so that once frozen, we can "erase" things from the multimap by
setting all Optional<Value> to none.

3. I changed the range we vend to be an OptionalTransformRange instead of just a
TransformRange so we skip all keys with .none values, meaning that a user will
get the nice behavior that getRange() still works after erasing.

One interesting thing to note is that one /cannot/ erase elements when
initializing the frozen multi-map since we haven't sorted it yet. At first this
seems weird, but it actually fits with the use case of this data structure:
building up state by processing IR in a readonly way and then later working with
it in a worklist like way (and perhaps checking for unhandled cases at the end
of processing).

The nice thing additional thing is that I was able to ensure that the actual
exposed API did not change in terms of how one uses it. I just changed the
underlying iterators/etc.
2020-04-28 15:03:45 -07:00
Michael Gottesman
6b88599412 Revert "Merge pull request #30327 from rintaro/revert-30289"
This reverts commit 0a6ccd802f, reversing
changes made to 7c5d74e86b.
2020-03-10 16:52:58 -07:00
Rintaro Ishizaki
fad1b431c2 Revert "[semantic-arc-opts] Implement @owned phi web elimination for phi webs with a single phi node that only have copy_value introducers."
This reverts commit 6fee59bd6a.
2020-03-10 08:43:46 -07:00
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