Copy link
@ibuclaw

ibuclaw Aug 11, 2015

Member

Hmm... looking at some older code, maybe htab_t (from hashtab.h) is the only viable alternative.

Same code, but with a different interface:

// d-tree.h
// ...
struct GTY(()) language_function
{
  // ...
  htab_t GTY((param_is(d_label_entry))) labels;   // might need 'struct d_label_entry'
};

// d-codegen.cc
// Hash and equality functions for the d_label_entry table.
static hashval_t
d_label_entry_hash (const void *data)
{
  const d_label_entry *label = (const d_label_entry *) data;
  return (hashval_t) ((intptr_t)label->statement >> 3);
}

static int
d_label_entry_equal (const void *a, const void *b)
{
  const d_label_entry *label_a = (const d_label_entry *) a;
  const d_label_entry *label_b = (const d_label_entry *) b;
  return (label_a->statement == label_b->statement);
}

// ...
tree
lookup_label(Statement *s, Identifier *ident)
{
  // ...
  // Create the label htab for the function on demand.
  if (!cfun->language->labels)
    cfun->language->labels = htab_create_ggc(13, d_label_entry_hash,
                                             d_label_entry_equal, NULL);

  d_label_entry search;
  search.statement = s;
  void **slot = htab_find_slot(cfun->language->labels, &search, NO_INSERT);
  if (*slot != NULL)
    return ((d_label_entry *) *slot)->label;
  else
    {
      // ...
      d_label_entry *ent = ggc_alloc_cleared_d_label_entry();
      ent->statement = s;
      ent->label = decl;

      slot = htab_find_slot(cfun->language->labels, ent, INSERT);
      gcc_assert(*slot == NULL);
      *slot = ent;

      return decl;
    }

This is just making a quick guess-work though...