summaryrefslogtreecommitdiff
path: root/gcc/read-rtl.c
diff options
context:
space:
mode:
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-04 11:10:35 +0000
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>2005-03-04 11:10:35 +0000
commit9e959634efbd40dadab240f0f730661e9e4fe68e (patch)
tree023da1eca2bd7656ce3641b1d6d446908d801399 /gcc/read-rtl.c
parent3d577bfc01526c8ac818ff358a38ee3fb85d633a (diff)
downloadgcc-9e959634efbd40dadab240f0f730661e9e4fe68e.tar.gz
* rtl.h (copy_rtx_ptr_loc, print_rtx_ptr_loc, join_c_conditions)
(print_c_condition): Declare. * read-rtl.c (ptr_loc): New structure. (ptr_locs, ptr_loc_obstack, joined_conditions) (joined_conditions_obstack): New variables. (leading_ptr_hash, leading_ptr_eq_p, set_rtx_ptr_loc) (get_rtx_ptr_loc, copy_rtx_ptr_loc, print_rtx_ptr_loc) (join_c_conditions, print_c_condition): New functions. (apply_macro_to_string): Associate the new string with the same source location as the old one. (add_condition_to_string): Use join_c_conditions. (read_string): Use set_rtx_ptr_loc to record a filename and line number for the string. (read_rtx): Initialize the new variables above. * genattrtab.c (write_test_expr, write_attr_value): Use print_c_condition. * genconditions.c (write_header): Don't define MAYBE_EVAL. Move its comment above the GCC_VERSION check. (write_one_condition): Use print_rtx_ptr_loc and print_c_condition. Inline the definition of MAYBE_EVAL. * genemit.c (gen_expand, gen_split): Use print_rtx_ptr_loc. * genoutput.c (process_template): Likewise. * genpreds.c (write_predicate_subfunction): Likewise. (write_predicate_expr): Use print_c_condition. * genrecog.c (write_cond): Likewise. * gensupport.c (process_rtx): Use join_c_conditions to join the conditions of a define_insn_and_split. Record a source location for the string after the "&&". (alter_test_for_insn): Use join_c_conditions. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95883 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/read-rtl.c')
-rw-r--r--gcc/read-rtl.c162
1 files changed, 151 insertions, 11 deletions
diff --git a/gcc/read-rtl.c b/gcc/read-rtl.c
index 6006745c3dd..e2ea54a6ed2 100644
--- a/gcc/read-rtl.c
+++ b/gcc/read-rtl.c
@@ -79,6 +79,14 @@ struct macro_group {
void (*apply_macro) (rtx, int);
};
+/* Associates PTR (which can be a string, etc.) with the file location
+ specified by FILENAME and LINENO. */
+struct ptr_loc {
+ const void *ptr;
+ const char *filename;
+ int lineno;
+};
+
/* If CODE is the number of a code macro, return a real rtx code that
has the same format. Return CODE otherwise. */
#define BELLWETHER_CODE(CODE) \
@@ -105,6 +113,10 @@ static struct map_value **add_map_value (struct map_value **,
int, const char *);
static void initialize_macros (void);
static void read_name (char *, FILE *);
+static hashval_t leading_ptr_hash (const void *);
+static int leading_ptr_eq_p (const void *, const void *);
+static void set_rtx_ptr_loc (const void *, const char *, int);
+static const struct ptr_loc *get_rtx_ptr_loc (const void *);
static char *read_string (FILE *, int);
static char *read_quoted_string (FILE *);
static char *read_braced_string (FILE *);
@@ -127,6 +139,22 @@ static enum rtx_code *bellwether_codes;
/* Obstack used for allocating RTL strings. */
static struct obstack string_obstack;
+/* A table of ptr_locs, hashed on the PTR field. */
+static htab_t ptr_locs;
+
+/* An obstack for the above. Plain xmalloc is a bit heavyweight for a
+ small structure like ptr_loc. */
+static struct obstack ptr_loc_obstack;
+
+/* A hash table of triples (A, B, C), where each of A, B and C is a condition
+ and A is equivalent to "B && C". This is used to keep track of the source
+ of conditions that are made up of separate rtx strings (such as the split
+ condition of a define_insn_and_split). */
+static htab_t joined_conditions;
+
+/* An obstack for allocating joined_conditions entries. */
+static struct obstack joined_conditions_obstack;
+
/* Subroutines of read_rtx. */
/* The current line number for the file. */
@@ -285,7 +313,9 @@ apply_macro_to_string (const char *string, struct mapping *macro, int value)
if (base != copy)
{
obstack_grow (&string_obstack, base, strlen (base) + 1);
- return (char *) obstack_finish (&string_obstack);
+ copy = obstack_finish (&string_obstack);
+ copy_rtx_ptr_loc (copy, string);
+ return copy;
}
return string;
}
@@ -396,16 +426,9 @@ uses_macro_p (rtx x, struct mapping *macro)
static const char *
add_condition_to_string (const char *original, const char *extra)
{
- char *result;
-
- if (original == 0 || original[0] == 0)
- return extra;
-
- if ((original[0] == '&' && original[1] == '&') || extra[0] == 0)
+ if (original != 0 && original[0] == '&' && original[1] == '&')
return original;
-
- asprintf (&result, "(%s) && (%s)", original, extra);
- return result;
+ return join_c_conditions (original, extra);
}
/* Like add_condition, but applied to all conditions in rtx X. */
@@ -568,6 +591,116 @@ initialize_macros (void)
}
}
+/* 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);
+ }
+}
+
/* Read chars from INFILE until a non-whitespace char
and return that. Comments, both Lisp style and C style,
are treated as whitespace.
@@ -801,7 +934,7 @@ read_string (FILE *infile, int star_if_braced)
{
char *stringbuf;
int saw_paren = 0;
- int c;
+ int c, old_lineno;
c = read_skip_spaces (infile);
if (c == '(')
@@ -810,6 +943,7 @@ read_string (FILE *infile, int star_if_braced)
c = read_skip_spaces (infile);
}
+ old_lineno = read_rtx_lineno;
if (c == '"')
stringbuf = read_quoted_string (infile);
else if (c == '{')
@@ -828,6 +962,7 @@ read_string (FILE *infile, int star_if_braced)
fatal_expected_char (infile, ')', c);
}
+ set_rtx_ptr_loc (stringbuf, read_rtx_filename, old_lineno);
return stringbuf;
}
@@ -1094,6 +1229,11 @@ read_rtx (FILE *infile, rtx *x, int *lineno)
initialize_macros ();
obstack_init (&string_obstack);
queue_head = rtx_alloc (EXPR_LIST);
+ ptr_locs = htab_create (161, leading_ptr_hash, leading_ptr_eq_p, 0);
+ obstack_init (&ptr_loc_obstack);
+ joined_conditions = htab_create (161, leading_ptr_hash,
+ leading_ptr_eq_p, 0);
+ obstack_init (&joined_conditions_obstack);
}
if (queue_next == 0)