Copy link
@ibuclaw

ibuclaw Aug 11, 2015

Member

You can use hash_table as a suitable alternative. You'd have to provide a descriptor struct for providing hash and equality checks.

Something like:

// Hash map helper
struct d_label_hasher : typed_free_remove<d_label_entry>
{
  static inline hashval_t hash (const d_label_entry *);
  static inline bool equal (const d_label_entry *, const d_label_entry *);
}

// Hash a label statement in a d_label_entry
inline hashval_t
d_label_hasher::hash(const d_label_entry *label)
{
  return (hashval_t) ((intptr_t)label->statement >> 3);
}

// Return true if the statement in both d_label_entry's are equal.
inline bool
d_label_hasher::equal(const d_label_entry *a, const d_label_entry *b)
{
  return (a->statement == b->statement);
}

// ...
struct GTY(()) language_function
{
  // ...
  hash_table<d_label_hasher, d_label_entry> labels;
};

Note that the field is not a pointer, so needs no extra ggc allocation.