+/* Return a hash value for the pointer pointed to by DEF. */
+
+static hashval_t
+leading_ptr_hash (const void *def)
+{
+ return htab_hash_pointer (*(const void *const *) def);
+}
+
+/* Return true if DEF1 and DEF2 are pointers to the same pointer. */
+
+static int
+leading_ptr_eq_p (const void *def1, const void *def2)
+{
+ return *(const void *const *) def1 == *(const void *const *) def2;
+}
+
+/* Associate PTR with the file position given by FILENAME and LINENO. */
+
+static void
+set_rtx_ptr_loc (const void *ptr, const char *filename, int lineno)
+{
+ struct ptr_loc *loc;
+
+ loc = (struct ptr_loc *) obstack_alloc (&ptr_loc_obstack,
+ sizeof (struct ptr_loc));
+ loc->ptr = ptr;
+ loc->filename = filename;
+ loc->lineno = lineno;
+ *htab_find_slot (ptr_locs, loc, INSERT) = loc;
+}
+
+/* Return the position associated with pointer PTR. Return null if no
+ position was set. */
+
+static const struct ptr_loc *
+get_rtx_ptr_loc (const void *ptr)
+{
+ return (const struct ptr_loc *) htab_find (ptr_locs, &ptr);
+}
+
+/* Associate NEW_PTR with the same file position as OLD_PTR. */
+
+void
+copy_rtx_ptr_loc (const void *new_ptr, const void *old_ptr)
+{
+ const struct ptr_loc *loc = get_rtx_ptr_loc (old_ptr);
+ if (loc != 0)
+ set_rtx_ptr_loc (new_ptr, loc->filename, loc->lineno);
+}
+
+/* If PTR is associated with a known file position, print a #line
+ directive for it. */
+
+void
+print_rtx_ptr_loc (const void *ptr)
+{
+ const struct ptr_loc *loc = get_rtx_ptr_loc (ptr);
+ if (loc != 0)
+ printf ("#line %d \"%s\"\n", loc->lineno, loc->filename);
+}
+
+/* Return a condition that satisfies both COND1 and COND2. Either string
+ may be null or empty. */
+
+const char *
+join_c_conditions (const char *cond1, const char *cond2)
+{
+ char *result;
+ const void **entry;
+
+ if (cond1 == 0 || cond1[0] == 0)
+ return cond2;
+
+ if (cond2 == 0 || cond2[0] == 0)
+ return cond1;
+
+ result = concat ("(", cond1, ") && (", cond2, ")", NULL);
+ obstack_ptr_grow (&joined_conditions_obstack, result);
+ obstack_ptr_grow (&joined_conditions_obstack, cond1);
+ obstack_ptr_grow (&joined_conditions_obstack, cond2);
+ entry = obstack_finish (&joined_conditions_obstack);
+ *htab_find_slot (joined_conditions, entry, INSERT) = entry;
+ return result;
+}
+
+/* Print condition COND, wrapped in brackets. If COND was created by
+ join_c_conditions, recursively invoke this function for the original
+ conditions and join the result with "&&". Otherwise print a #line
+ directive for COND if its original file position is known. */
+
+void
+print_c_condition (const char *cond)
+{
+ const void **halves = htab_find (joined_conditions, &cond);
+ if (halves != 0)
+ {
+ printf ("(");
+ print_c_condition (halves[1]);
+ printf (" && ");
+ print_c_condition (halves[2]);
+ printf (")");
+ }
+ else
+ {
+ putc ('\n', stdout);
+ print_rtx_ptr_loc (cond);
+ printf ("(%s)", cond);
+ }
+}
+