+2014-11-20 Trevor Saunders <tsaunders@mozilla.com>
+
+ * hash-map.h (hash_map::iterator): New class.
+ (hash_map::begin): New method.
+ (hash_map::end): Likewise.
+ * alias.c, config/alpha/alpha.c, dwarf2asm.c, omp-low.c, tree.h:
+ replace splay_tree with hash_map.
+
2014-11-20 Trevor Saunders <tsaunders@mozilla.com>
* hash-table.h (hash_table::hash_table): Call alloc_entries.
#include "flags.h"
#include "diagnostic-core.h"
#include "cselib.h"
-#include "splay-tree.h"
+#include "hash-map.h"
#include "langhooks.h"
#include "timevar.h"
#include "dumpfile.h"
However, this is no actual entry for alias set zero. It is an
error to attempt to explicitly construct a subset of zero. */
+struct alias_set_traits : default_hashmap_traits
+{
+ template<typename T>
+ static bool
+ is_empty (T &e)
+ {
+ return e.m_key == INT_MIN;
+ }
+
+ template<typename T>
+ static bool
+ is_deleted (T &e)
+ {
+ return e.m_key == (INT_MIN + 1);
+ }
+
+ template<typename T> static void mark_empty (T &e) { e.m_key = INT_MIN; }
+
+ template<typename T>
+ static void
+ mark_deleted (T &e)
+ {
+ e.m_key = INT_MIN + 1;
+ }
+};
+
struct GTY(()) alias_set_entry_d {
/* The alias set number, as stored in MEM_ALIAS_SET. */
alias_set_type alias_set;
continuing our example above, the children here will be all of
`int', `double', `float', and `struct S'. */
- splay_tree GTY((param1_is (int), param2_is (int))) children;
+ hash_map<int, int, alias_set_traits> *children;
};
typedef struct alias_set_entry_d *alias_set_entry;
machine_mode);
static rtx find_base_value (rtx);
static int mems_in_disjoint_alias_sets_p (const_rtx, const_rtx);
-static int insert_subset_children (splay_tree_node, void*);
static alias_set_entry get_alias_set_entry (alias_set_type);
static tree decl_for_component_ref (tree);
static int write_dependence_p (const_rtx,
return ! alias_sets_conflict_p (MEM_ALIAS_SET (mem1), MEM_ALIAS_SET (mem2));
}
-/* Insert the NODE into the splay tree given by DATA. Used by
- record_alias_subset via splay_tree_foreach. */
-
-static int
-insert_subset_children (splay_tree_node node, void *data)
-{
- splay_tree_insert ((splay_tree) data, node->key, node->value);
-
- return 0;
-}
-
/* Return true if the first alias set is a subset of the second. */
bool
ase = get_alias_set_entry (set2);
if (ase != 0
&& (ase->has_zero_child
- || splay_tree_lookup (ase->children,
- (splay_tree_key) set1)))
+ || ase->children->get (set1)))
return true;
return false;
}
ase = get_alias_set_entry (set1);
if (ase != 0
&& (ase->has_zero_child
- || splay_tree_lookup (ase->children,
- (splay_tree_key) set2)))
+ || ase->children->get (set2)))
return 1;
/* Now do the same, but with the alias sets reversed. */
ase = get_alias_set_entry (set2);
if (ase != 0
&& (ase->has_zero_child
- || splay_tree_lookup (ase->children,
- (splay_tree_key) set1)))
+ || ase->children->get (set1)))
return 1;
/* The two alias sets are distinct and neither one is the
superset_entry = ggc_cleared_alloc<alias_set_entry_d> ();
superset_entry->alias_set = superset;
superset_entry->children
- = splay_tree_new_ggc (splay_tree_compare_ints,
- ggc_alloc_splay_tree_scalar_scalar_splay_tree_s,
- ggc_alloc_splay_tree_scalar_scalar_splay_tree_node_s);
+ = hash_map<int, int, alias_set_traits>::create_ggc (64);
superset_entry->has_zero_child = 0;
(*alias_sets)[superset] = superset_entry;
}
if (subset_entry->has_zero_child)
superset_entry->has_zero_child = 1;
- splay_tree_foreach (subset_entry->children, insert_subset_children,
- superset_entry->children);
+ hash_map<int, int, alias_set_traits>::iterator iter
+ = subset_entry->children->begin ();
+ for (; iter != subset_entry->children->end (); ++iter)
+ superset_entry->children->put ((*iter).first, (*iter).second);
}
/* Enter the SUBSET itself as a child of the SUPERSET. */
- splay_tree_insert (superset_entry->children,
- (splay_tree_key) subset, 0);
+ superset_entry->children->put (subset, 0);
}
}
#include "common/common-target.h"
#include "debug.h"
#include "langhooks.h"
-#include "splay-tree.h"
+#include "hash-map.h"
#include "hash-table.h"
#include "predict.h"
#include "dominance.h"
struct GTY(()) alpha_links;
+struct string_traits : default_hashmap_traits
+{
+ static bool equal_keys (const char *const &a, const char *const &b)
+ {
+ return strcmp (a, b) == 0;
+ }
+};
+
struct GTY(()) machine_function
{
/* For flag_reorder_blocks_and_partition. */
bool uses_condition_handler;
/* Linkage entries. */
- splay_tree GTY ((param1_is (char *), param2_is (struct alpha_links *)))
- links;
+ hash_map<const char *, alpha_links *, string_traits> *links;
};
/* How to allocate a 'struct machine_function'. */
if (cfun->machine->links)
{
- splay_tree_node lnode;
-
/* Is this name already defined? */
- lnode = splay_tree_lookup (cfun->machine->links, (splay_tree_key) name);
- if (lnode)
- al = (struct alpha_links *) lnode->value;
+ alpha_links *slot = cfun->machine->links->get (name);
+ if (slot)
+ al = *slot;
}
else
- cfun->machine->links = splay_tree_new_ggc
- ((splay_tree_compare_fn) strcmp,
- ggc_alloc_splay_tree_str_alpha_links_splay_tree_s,
- ggc_alloc_splay_tree_str_alpha_links_splay_tree_node_s);
+ cfun->machine->links
+ = hash_map<const char *, alpha_links *, string_traits>::create_ggc (64);
if (al == NULL)
{
al->func = func;
al->linkage = gen_rtx_SYMBOL_REF (Pmode, ggc_strdup (linksym));
- splay_tree_insert (cfun->machine->links,
- (splay_tree_key) ggc_strdup (name),
- (splay_tree_value) al);
+ cfun->machine->links->put (ggc_strdup (name), al);
}
al->rkind = rflag ? KIND_CODEADDR : KIND_LINKAGE;
}
static int
-alpha_write_one_linkage (splay_tree_node node, void *data)
+alpha_write_one_linkage (const char *name, alpha_links *link, FILE *steam)
{
- const char *const name = (const char *) node->key;
- struct alpha_links *link = (struct alpha_links *) node->value;
- FILE *stream = (FILE *) data;
-
ASM_OUTPUT_INTERNAL_LABEL (stream, XSTR (link->linkage, 0));
if (link->rkind == KIND_CODEADDR)
{
if (cfun->machine->links)
{
- splay_tree_foreach (cfun->machine->links, alpha_write_one_linkage, stream);
- /* splay_tree_delete (func->links); */
+ hash_map<const char *, alpha_links *, string_traits>::iterator iter
+ = cfun->machine->links->begin ();
+ for (; iter != cfun->machine->links->end (); ++iter)
+ alpha_write_one_linkage ((*iter).first, (*iter).second, stream);
}
}
#include "target.h"
#include "dwarf2asm.h"
#include "dwarf2.h"
-#include "splay-tree.h"
+#include "hash-map.h"
#include "ggc.h"
#include "tm_p.h"
}
#endif /* 0 */
\f
-static int dw2_output_indirect_constant_1 (splay_tree_node, void *);
-
-static GTY((param1_is (char *), param2_is (tree))) splay_tree indirect_pool;
+static GTY(()) hash_map<const char *, tree> *indirect_pool;
static GTY(()) int dw2_const_labelno;
# define USE_LINKONCE_INDIRECT 0
#endif
-/* Comparison function for a splay tree in which the keys are strings.
- K1 and K2 have the dynamic type "const char *". Returns <0, 0, or
+/* Compare two std::pair<const char *, tree> by their first element.
+ Returns <0, 0, or
>0 to indicate whether K1 is less than, equal to, or greater than
K2, respectively. */
static int
-splay_tree_compare_strings (splay_tree_key k1, splay_tree_key k2)
+compare_strings (const void *a, const void *b)
{
- const char *s1 = (const char *)k1;
- const char *s2 = (const char *)k2;
+ const char *s1 = ((const std::pair<const char *, tree> *) a)->first;
+ const char *s2 = ((const std::pair<const char *, tree> *) b)->first;
int ret;
if (s1 == s2)
rtx
dw2_force_const_mem (rtx x, bool is_public)
{
- splay_tree_node node;
const char *key;
tree decl_id;
if (! indirect_pool)
- /* We use strcmp, rather than just comparing pointers, so that the
- sort order will not depend on the host system. */
- indirect_pool = splay_tree_new_ggc (splay_tree_compare_strings,
- ggc_alloc_splay_tree_str_tree_node_splay_tree_s,
- ggc_alloc_splay_tree_str_tree_node_splay_tree_node_s);
+ indirect_pool = hash_map<const char *, tree>::create_ggc (64);
gcc_assert (GET_CODE (x) == SYMBOL_REF);
key = XSTR (x, 0);
- node = splay_tree_lookup (indirect_pool, (splay_tree_key) key);
- if (node)
- decl_id = (tree) node->value;
+ tree *slot = indirect_pool->get (key);
+ if (slot)
+ decl_id = *slot;
else
{
tree id;
if (id)
TREE_SYMBOL_REFERENCED (id) = 1;
- splay_tree_insert (indirect_pool, (splay_tree_key) key,
- (splay_tree_value) decl_id);
+ indirect_pool->put (key, decl_id);
}
return gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (decl_id));
}
-/* A helper function for dw2_output_indirect_constants called through
- splay_tree_foreach. Emit one queued constant to memory. */
+/* A helper function for dw2_output_indirect_constants. Emit one queued
+ constant to memory. */
static int
-dw2_output_indirect_constant_1 (splay_tree_node node,
- void *data ATTRIBUTE_UNUSED)
+dw2_output_indirect_constant_1 (const char *sym, tree id)
{
- const char *sym;
rtx sym_ref;
- tree id, decl;
-
- sym = (const char *) node->key;
- id = (tree) node->value;
+ tree decl;
decl = build_decl (UNKNOWN_LOCATION, VAR_DECL, id, ptr_type_node);
SET_DECL_ASSEMBLER_NAME (decl, id);
void
dw2_output_indirect_constants (void)
{
- if (indirect_pool)
- splay_tree_foreach (indirect_pool, dw2_output_indirect_constant_1, NULL);
+ if (!indirect_pool)
+ return;
+
+ auto_vec<std::pair<const char *, tree> > temp (indirect_pool->elements ());
+ for (hash_map<const char *, tree>::iterator iter = indirect_pool->begin ();
+ iter != indirect_pool->end (); ++iter)
+ temp.quick_push (*iter);
+
+ temp.qsort (compare_strings);
+
+ for (unsigned int i = 0; i < temp.length (); i++)
+ dw2_output_indirect_constant_1 (temp[i].first, temp[i].second);
}
/* Like dw2_asm_output_addr_rtx, but encode the pointer as directed.
#define hash_map_h
#include <new>
+#include <utility>
#include "hash-table.h"
/* implement default behavior for traits when types allow it. */
size_t elements () const { return m_table.elements (); }
+ class iterator
+ {
+ public:
+ explicit iterator (const typename hash_table<hash_entry>::iterator &iter) :
+ m_iter (iter) {}
+
+ iterator &operator++ ()
+ {
+ ++m_iter;
+ return *this;
+ }
+
+ std::pair<Key, Value> operator* ()
+ {
+ hash_entry &e = *m_iter;
+ return std::pair<Key, Value> (e.m_key, e.m_value);
+ }
+
+ bool
+ operator != (const iterator &other) const
+ {
+ return m_iter != other.m_iter;
+ }
+
+ private:
+ typename hash_table<hash_entry>::iterator m_iter;
+ };
+
+ /* Standard iterator retrieval methods. */
+
+ iterator begin () const { return iterator (m_table.begin ()); }
+ iterator end () const { return iterator (m_table.end ()); }
+
private:
template<typename T, typename U, typename V> friend void gt_ggc_mx (hash_map<T, U, V> *);
requires that languages coordinate a symbol name. It is therefore
best put here in common code. */
-static GTY((param1_is (tree), param2_is (tree)))
- splay_tree critical_name_mutexes;
+static GTY(()) hash_map<tree, tree> *critical_name_mutexes;
static void
lower_omp_critical (gimple_stmt_iterator *gsi_p, omp_context *ctx)
if (name)
{
tree decl;
- splay_tree_node n;
if (!critical_name_mutexes)
- critical_name_mutexes
- = splay_tree_new_ggc (splay_tree_compare_pointers,
- ggc_alloc_splay_tree_tree_node_tree_node_splay_tree_s,
- ggc_alloc_splay_tree_tree_node_tree_node_splay_tree_node_s);
+ critical_name_mutexes = hash_map<tree, tree>::create_ggc (10);
- n = splay_tree_lookup (critical_name_mutexes, (splay_tree_key) name);
+ tree *n = critical_name_mutexes->get (name);
if (n == NULL)
{
char *new_str;
varpool_node::finalize_decl (decl);
- splay_tree_insert (critical_name_mutexes, (splay_tree_key) name,
- (splay_tree_value) decl);
+ critical_name_mutexes->put (name, decl);
}
else
- decl = (tree) n->value;
+ decl = *n;
lock = builtin_decl_explicit (BUILT_IN_GOMP_CRITICAL_NAME_START);
lock = build_call_expr_loc (loc, lock, 1, build_fold_addr_expr_loc (loc, decl));
return (wi::lshift (wi::to_offset (DECL_FIELD_OFFSET (field)), BITS_PER_UNIT_LOG)
+ wi::to_offset (DECL_FIELD_BIT_OFFSET (field))).to_shwi ();
}
+
+extern void gt_ggc_mx (tree &);
+extern void gt_pch_nx (tree &);
+extern void gt_pch_nx (tree &, gt_pointer_operator, void *);
+
#endif /* GCC_TREE_H */