On Mon, Aug 16, 2021 at 2:44 PM Thomas Schwinge <tho...@codesourcery.com> wrote:
>
> Hi!
>
> On 2021-08-09T12:02:02+0200, Richard Biener via Gcc <gcc@gcc.gnu.org> wrote:
> > On Fri, Aug 6, 2021 at 6:58 PM Thomas Schwinge <tho...@codesourcery.com> 
> > wrote:
> >> So I'm trying to do some C++...  ;-)
> >>
> >> Given:
> >>
> >>     /* A map from SSA names or var decls to record fields.  */
> >>     typedef hash_map<tree, tree> field_map_t;
> >>
> >>     /* For each propagation record type, this is a map from SSA names or 
> >> var decls
> >>        to propagate, to the field in the record type that should be used 
> >> for
> >>        transmission and reception.  */
> >>     typedef hash_map<tree, field_map_t> record_field_map_t;
> >>
> >> Thus, that's a 'hash_map<tree, hash_map<tree, tree>>'.  (I may do that,
> >> right?)  Looking through GCC implementation files, very most of all uses
> >> of 'hash_map' boil down to pointer key ('tree', for example) and
> >> pointer/integer value.
> >
> > You could use
> >
> > hash_map<tree, unsigned> record_field_map_p;
> > vec<field_map_t> maps;
> >
> > and record the index into maps which you record the actual maps.
>
> Ugh ;-) -- yes, if I remember correctly, I've spotted that pattern in a
> few GCC source files.
>
> > Alternatively use hash_map<tree, field_map_t *>
>
> ACK; see commit 049eda8274b7394523238b17ab12c3e2889f253e "Avoid 'GTY' use
> for 'gcc/omp-oacc-neuter-broadcast.cc:field_map'".  (So, actually don't
> change 'record_field_map_t' at this time.)
>
>
> > Note your code will appear to work until you end up in the situation
> > where record_field_map_t is resized because hash-map doesn't
> > std::move elements when re-hashing.
>
> I'm not understanding, would you please provide some more detail here?
>
> Did you mean "resizing" instead of "re-hashing"?

yes

>  If the latter, then
> yes, it does 'std::move' them (via 'hash_table::expand') -- see (your
> own) commit 4b9d61f79c0c0185a33048ae6cc72269cf7efa31 "add move CTOR to
> auto_vec, use auto_vec for get_loop_exit_edges".  But I guess I
> completely misunderstood?

Oh, indeed I fixed that ;)  But then hash_table doesn't have a move CTOR ...
I bet that it also was incomplete in some other way (I ended up not actually
needing this std::move stuff for hash_map/autp_vec after all...).  But the DTOR
piece should be OK with a suitable traits class I think (the ::remove
trait member
should call it).

>
>
> Grüße
>  Thomas
> -----------------
> Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 
> München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas 
> Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht 
> München, HRB 106955

Reply via email to