X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=gcc%2Fgenrecog.c;h=0d8be8f760733a7d61c32472659e6b3507a06092;hb=bcf2e03f2209a347e5f0986521bc755551763b79;hp=208ea8e57f26ad87dddcfa4e56f706736c772c5d;hpb=ad85fb32ad6eca009e3f1228f99985491d95159c;p=pf3gnuchains%2Fgcc-fork.git diff --git a/gcc/genrecog.c b/gcc/genrecog.c index 208ea8e57f2..0d8be8f7607 100644 --- a/gcc/genrecog.c +++ b/gcc/genrecog.c @@ -1,12 +1,13 @@ /* Generate code from machine description to recognize rtl as insns. Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1997, 1998, - 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 + Free Software Foundation, Inc. This file is part of GCC. GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) + the Free Software Foundation; either version 3, or (at your option) any later version. GCC is distributed in the hope that it will be useful, but WITHOUT @@ -15,9 +16,8 @@ License for more details. You should have received a copy of the GNU General Public License - along with GCC; see the file COPYING. If not, write to the Free - Software Foundation, 59 Temple Place - Suite 330, Boston, MA - 02111-1307, USA. */ + along with GCC; see the file COPYING3. If not see + . */ /* This program is used to produce insn-recog.c, which contains a @@ -56,15 +56,54 @@ #include "tm.h" #include "rtl.h" #include "errors.h" +#include "read-md.h" #include "gensupport.h" - #define OUTPUT_LABEL(INDENT_STRING, LABEL_NUMBER) \ printf("%sL%d: ATTRIBUTE_UNUSED_LABEL\n", (INDENT_STRING), (LABEL_NUMBER)) -/* Holds an array of names indexed by insn_code_number. */ -static char **insn_name_ptr = 0; -static int insn_name_ptr_size = 0; +/* Ways of obtaining an rtx to be tested. */ +enum position_type { + /* PATTERN (peep2_next_insn (ARG)). */ + POS_PEEP2_INSN, + + /* XEXP (BASE, ARG). */ + POS_XEXP, + + /* XVECEXP (BASE, 0, ARG). */ + POS_XVECEXP0 +}; + +/* The position of an rtx relative to X0. Each useful position is + represented by exactly one instance of this structure. */ +struct position +{ + /* The parent rtx. This is the root position for POS_PEEP2_INSNs. */ + struct position *base; + + /* A position with the same BASE and TYPE, but with the next value + of ARG. */ + struct position *next; + + /* A list of all POS_XEXP positions that use this one as their base, + chained by NEXT fields. The first entry represents XEXP (this, 0), + the second represents XEXP (this, 1), and so on. */ + struct position *xexps; + + /* A list of POS_XVECEXP0 positions that use this one as their base, + chained by NEXT fields. The first entry represents XVECEXP (this, 0, 0), + the second represents XVECEXP (this, 0, 1), and so on. */ + struct position *xvecexp0s; + + /* The type of position. */ + enum position_type type; + + /* The argument to TYPE (shown as ARG in the position_type comments). */ + int arg; + + /* The depth of this position, with 0 as the root. */ + int depth; +}; /* A listhead of decision trees. The alternatives to a node are kept in a doubly-linked list so we can easily add nodes to the proper @@ -76,6 +115,17 @@ struct decision_head struct decision *last; }; +/* These types are roughly in the order in which we'd like to test them. */ +enum decision_type +{ + DT_num_insns, + DT_mode, DT_code, DT_veclen, + DT_elt_zero_int, DT_elt_one_int, DT_elt_zero_wide, DT_elt_zero_wide_safe, + DT_const_int, + DT_veclen_ge, DT_dup, DT_pred, DT_c_test, + DT_accept_op, DT_accept_insn +}; + /* A single test. The two accept types aren't tests per-se, but their equality (or lack thereof) does affect tree merging so it is convenient to keep them here. */ @@ -85,24 +135,19 @@ struct decision_test /* A linked list through the tests attached to a node. */ struct decision_test *next; - /* These types are roughly in the order in which we'd like to test them. */ - enum decision_type - { - DT_mode, DT_code, DT_veclen, - DT_elt_zero_int, DT_elt_one_int, DT_elt_zero_wide, DT_elt_zero_wide_safe, - DT_veclen_ge, DT_dup, DT_pred, DT_c_test, - DT_accept_op, DT_accept_insn - } type; + enum decision_type type; union { + int num_insns; /* Number if insn in a define_peephole2. */ enum machine_mode mode; /* Machine mode of node. */ RTX_CODE code; /* Code to test. */ struct { const char *name; /* Predicate to call. */ - int index; /* Index into `preds' or -1. */ + const struct pred_data *data; + /* Optimization hints for this predicate. */ enum machine_mode mode; /* Machine mode for node. */ } pred; @@ -130,7 +175,7 @@ struct decision struct decision *afterward; /* Node to test on success, but failure of successor nodes. */ - const char *position; /* String denoting position in pattern. */ + struct position *position; /* Position in pattern. */ struct decision_test *tests; /* The tests for this node. */ @@ -161,11 +206,6 @@ static int next_number; static int next_insn_code; -/* Similar, but counts all expressions in the MD file; used for - error messages. */ - -static int next_index; - /* Record the highest depth we ever have so we know how many variables to allocate in each subroutine we make. */ @@ -174,156 +214,82 @@ static int max_depth; /* The line number of the start of the pattern currently being processed. */ static int pattern_lineno; -/* Count of errors. */ -static int error_count; - -/* This table contains a list of the rtl codes that can possibly match a - predicate defined in recog.c. The function `maybe_both_true' uses it to - deduce that there are no expressions that can be matches by certain pairs - of tree nodes. Also, if a predicate can match only one code, we can - hardwire that code into the node testing the predicate. */ - -static const struct pred_table -{ - const char *const name; - const RTX_CODE codes[NUM_RTX_CODE]; -} preds[] = { - {"general_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF, - LABEL_REF, SUBREG, REG, MEM, ADDRESSOF}}, -#ifdef PREDICATE_CODES - PREDICATE_CODES -#endif - {"address_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF, - LABEL_REF, SUBREG, REG, MEM, ADDRESSOF, - PLUS, MINUS, MULT}}, - {"register_operand", {SUBREG, REG, ADDRESSOF}}, - {"pmode_register_operand", {SUBREG, REG, ADDRESSOF}}, - {"scratch_operand", {SCRATCH, REG}}, - {"immediate_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF, - LABEL_REF}}, - {"const_int_operand", {CONST_INT}}, - {"const_double_operand", {CONST_INT, CONST_DOUBLE}}, - {"nonimmediate_operand", {SUBREG, REG, MEM, ADDRESSOF}}, - {"nonmemory_operand", {CONST_INT, CONST_DOUBLE, CONST, SYMBOL_REF, - LABEL_REF, SUBREG, REG, ADDRESSOF}}, - {"push_operand", {MEM}}, - {"pop_operand", {MEM}}, - {"memory_operand", {SUBREG, MEM}}, - {"indirect_operand", {SUBREG, MEM}}, - {"comparison_operator", {EQ, NE, LE, LT, GE, GT, LEU, LTU, GEU, GTU, - UNORDERED, ORDERED, UNEQ, UNGE, UNGT, UNLE, - UNLT, LTGT}} -}; - -#define NUM_KNOWN_PREDS ARRAY_SIZE (preds) +/* The root position (x0). */ +static struct position root_pos; -static const char *const special_mode_pred_table[] = { -#ifdef SPECIAL_MODE_PREDICATES - SPECIAL_MODE_PREDICATES -#endif - "pmode_register_operand" -}; - -#define NUM_SPECIAL_MODE_PREDS ARRAY_SIZE (special_mode_pred_table) - -static struct decision *new_decision - (const char *, struct decision_head *); -static struct decision_test *new_decision_test - (enum decision_type, struct decision_test ***); -static rtx find_operand - (rtx, int); -static rtx find_matching_operand - (rtx, int); -static void validate_pattern - (rtx, rtx, rtx, int); -static struct decision *add_to_sequence - (rtx, struct decision_head *, const char *, enum routine_type, int); - -static int maybe_both_true_2 - (struct decision_test *, struct decision_test *); -static int maybe_both_true_1 - (struct decision_test *, struct decision_test *); -static int maybe_both_true - (struct decision *, struct decision *, int); - -static int nodes_identical_1 - (struct decision_test *, struct decision_test *); -static int nodes_identical - (struct decision *, struct decision *); -static void merge_accept_insn - (struct decision *, struct decision *); -static void merge_trees - (struct decision_head *, struct decision_head *); - -static void factor_tests - (struct decision_head *); -static void simplify_tests - (struct decision_head *); -static int break_out_subroutines - (struct decision_head *, int); -static void find_afterward - (struct decision_head *, struct decision *); - -static void change_state - (const char *, const char *, struct decision *, const char *); -static void print_code - (enum rtx_code); -static void write_afterward - (struct decision *, struct decision *, const char *); -static struct decision *write_switch - (struct decision *, int); -static void write_cond - (struct decision_test *, int, enum routine_type); -static void write_action - (struct decision *, struct decision_test *, int, int, - struct decision *, enum routine_type); -static int is_unconditional - (struct decision_test *, enum routine_type); -static int write_node - (struct decision *, int, enum routine_type); -static void write_tree_1 - (struct decision_head *, int, enum routine_type); -static void write_tree - (struct decision_head *, const char *, enum routine_type, int); -static void write_subroutine - (struct decision_head *, enum routine_type); -static void write_subroutines - (struct decision_head *, enum routine_type); -static void write_header - (void); - -static struct decision_head make_insn_sequence - (rtx, enum routine_type); -static void process_tree - (struct decision_head *, enum routine_type); - -static void record_insn_name - (int, const char *); - -static void debug_decision_0 - (struct decision *, int, int); -static void debug_decision_1 - (struct decision *, int); -static void debug_decision_2 - (struct decision_test *); +/* A list of all POS_PEEP2_INSNs. The entry for insn 0 is the root position, + since we are given that instruction's pattern as x0. */ +static struct position *peep2_insn_pos_list = &root_pos; + extern void debug_decision (struct decision *); extern void debug_decision_list (struct decision *); +/* Return a position with the given BASE, TYPE and ARG. NEXT_PTR + points to where the unique object that represents the position + should be stored. Create the object if it doesn't already exist, + otherwise reuse the object that is already there. */ + +static struct position * +next_position (struct position **next_ptr, struct position *base, + enum position_type type, int arg) +{ + struct position *pos; + + pos = *next_ptr; + if (!pos) + { + pos = XCNEW (struct position); + pos->base = base; + pos->type = type; + pos->arg = arg; + pos->depth = base->depth + 1; + *next_ptr = pos; + } + return pos; +} + +/* Compare positions POS1 and POS2 lexicographically. */ + +static int +compare_positions (struct position *pos1, struct position *pos2) +{ + int diff; + + diff = pos1->depth - pos2->depth; + if (diff < 0) + do + pos2 = pos2->base; + while (pos1->depth != pos2->depth); + else if (diff > 0) + do + pos1 = pos1->base; + while (pos1->depth != pos2->depth); + while (pos1 != pos2) + { + diff = (int) pos1->type - (int) pos2->type; + if (diff == 0) + diff = pos1->arg - pos2->arg; + pos1 = pos1->base; + pos2 = pos2->base; + } + return diff; +} + /* Create a new node in sequence after LAST. */ static struct decision * -new_decision (const char *position, struct decision_head *last) +new_decision (struct position *pos, struct decision_head *last) { - struct decision *new = xcalloc (1, sizeof (struct decision)); + struct decision *new_decision = XCNEW (struct decision); - new->success = *last; - new->position = xstrdup (position); - new->number = next_number++; + new_decision->success = *last; + new_decision->position = pos; + new_decision->number = next_number++; - last->first = last->last = new; - return new; + last->first = last->last = new_decision; + return new_decision; } /* Create a new test and link it in at PLACE. */ @@ -334,7 +300,7 @@ new_decision_test (enum decision_type type, struct decision_test ***pplace) struct decision_test **place = *pplace; struct decision_test *test; - test = xmalloc (sizeof (*test)); + test = XNEW (struct decision_test); test->next = *place; test->type = type; *place = test; @@ -345,19 +311,21 @@ new_decision_test (enum decision_type type, struct decision_test ***pplace) return test; } -/* Search for and return operand N. */ +/* Search for and return operand N, stop when reaching node STOP. */ static rtx -find_operand (rtx pattern, int n) +find_operand (rtx pattern, int n, rtx stop) { const char *fmt; RTX_CODE code; int i, j, len; rtx r; + if (pattern == stop) + return stop; + code = GET_CODE (pattern); if ((code == MATCH_SCRATCH - || code == MATCH_INSN || code == MATCH_OPERAND || code == MATCH_OPERATOR || code == MATCH_PARALLEL) @@ -371,18 +339,19 @@ find_operand (rtx pattern, int n) switch (fmt[i]) { case 'e': case 'u': - if ((r = find_operand (XEXP (pattern, i), n)) != NULL_RTX) + if ((r = find_operand (XEXP (pattern, i), n, stop)) != NULL_RTX) return r; break; case 'V': if (! XVEC (pattern, i)) break; - /* FALLTHRU */ + /* Fall through. */ case 'E': for (j = 0; j < XVECLEN (pattern, i); j++) - if ((r = find_operand (XVECEXP (pattern, i, j), n)) != NULL_RTX) + if ((r = find_operand (XVECEXP (pattern, i, j), n, stop)) + != NULL_RTX) return r; break; @@ -390,7 +359,7 @@ find_operand (rtx pattern, int n) break; default: - abort (); + gcc_unreachable (); } } @@ -429,7 +398,7 @@ find_matching_operand (rtx pattern, int n) case 'V': if (! XVEC (pattern, i)) break; - /* FALLTHRU */ + /* Fall through. */ case 'E': for (j = 0; j < XVECLEN (pattern, i); j++) @@ -441,7 +410,7 @@ find_matching_operand (rtx pattern, int n) break; default: - abort (); + gcc_unreachable (); } } @@ -466,14 +435,19 @@ validate_pattern (rtx pattern, rtx insn, rtx set, int set_code) { case MATCH_SCRATCH: return; - - case MATCH_INSN: + case MATCH_DUP: + case MATCH_OP_DUP: + case MATCH_PAR_DUP: + if (find_operand (insn, XINT (pattern, 0), pattern) == pattern) + error_with_line (pattern_lineno, + "operand %i duplicated before defined", + XINT (pattern, 0)); + break; case MATCH_OPERAND: case MATCH_OPERATOR: { const char *pred_name = XSTR (pattern, 1); - int allows_non_lvalue = 1, allows_non_const = 1; - int special_mode_pred = 0; + const struct pred_data *pred; const char *c_test; if (GET_CODE (insn) == DEFINE_INSN) @@ -483,55 +457,14 @@ validate_pattern (rtx pattern, rtx insn, rtx set, int set_code) if (pred_name[0] != 0) { - for (i = 0; i < NUM_KNOWN_PREDS; i++) - if (! strcmp (preds[i].name, pred_name)) - break; - - if (i < NUM_KNOWN_PREDS) - { - int j; - - allows_non_lvalue = allows_non_const = 0; - for (j = 0; preds[i].codes[j] != 0; j++) - { - RTX_CODE c = preds[i].codes[j]; - if (c != LABEL_REF - && c != SYMBOL_REF - && c != CONST_INT - && c != CONST_DOUBLE - && c != CONST - && c != HIGH - && c != CONSTANT_P_RTX) - allows_non_const = 1; - - if (c != REG - && c != SUBREG - && c != MEM - && c != ADDRESSOF - && c != CONCAT - && c != PARALLEL - && c != STRICT_LOW_PART) - allows_non_lvalue = 1; - } - } - else - { -#ifdef PREDICATE_CODES - /* If the port has a list of the predicates it uses but - omits one, warn. */ - message_with_line (pattern_lineno, - "warning: `%s' not in PREDICATE_CODES", - pred_name); -#endif - } - - for (i = 0; i < NUM_SPECIAL_MODE_PREDS; ++i) - if (strcmp (pred_name, special_mode_pred_table[i]) == 0) - { - special_mode_pred = 1; - break; - } + pred = lookup_predicate (pred_name); + if (!pred) + message_with_line (pattern_lineno, + "warning: unknown predicate '%s'", + pred_name); } + else + pred = 0; if (code == MATCH_OPERAND) { @@ -564,59 +497,47 @@ validate_pattern (rtx pattern, rtx insn, rtx set, int set_code) && find_matching_operand (insn, XINT (pattern, 0))) ; else - { - message_with_line (pattern_lineno, - "operand %d missing in-out reload", - XINT (pattern, 0)); - error_count++; - } - } - else if (constraints0 != '=' && constraints0 != '+') - { - message_with_line (pattern_lineno, - "operand %d missing output reload", + error_with_line (pattern_lineno, + "operand %d missing in-out reload", XINT (pattern, 0)); - error_count++; } + else if (constraints0 != '=' && constraints0 != '+') + error_with_line (pattern_lineno, + "operand %d missing output reload", + XINT (pattern, 0)); } } /* Allowing non-lvalues in destinations -- particularly CONST_INT -- while not likely to occur at runtime, results in less efficient code from insn-recog.c. */ - if (set - && pred_name[0] != '\0' - && allows_non_lvalue) - { - message_with_line (pattern_lineno, - "warning: destination operand %d allows non-lvalue", - XINT (pattern, 0)); - } - - /* A modeless MATCH_OPERAND can be handy when we can - check for multiple modes in the c_test. In most other cases, - it is a mistake. Only DEFINE_INSN is eligible, since SPLIT - and PEEP2 can FAIL within the output pattern. Exclude - address_operand, since its mode is related to the mode of - the memory not the operand. Exclude the SET_DEST of a call - instruction, as that is a common idiom. */ + if (set && pred && pred->allows_non_lvalue) + message_with_line (pattern_lineno, + "warning: destination operand %d " + "allows non-lvalue", + XINT (pattern, 0)); + + /* A modeless MATCH_OPERAND can be handy when we can check for + multiple modes in the c_test. In most other cases, it is a + mistake. Only DEFINE_INSN is eligible, since SPLIT and + PEEP2 can FAIL within the output pattern. Exclude special + predicates, which check the mode themselves. Also exclude + predicates that allow only constants. Exclude the SET_DEST + of a call instruction, as that is a common idiom. */ if (GET_MODE (pattern) == VOIDmode && code == MATCH_OPERAND && GET_CODE (insn) == DEFINE_INSN - && allows_non_const - && ! special_mode_pred - && pred_name[0] != '\0' - && strcmp (pred_name, "address_operand") != 0 + && pred + && !pred->special + && pred->allows_non_const && strstr (c_test, "operands") == NULL && ! (set && GET_CODE (set) == SET && GET_CODE (SET_SRC (set)) == CALL)) - { - message_with_line (pattern_lineno, - "warning: operand %d missing mode?", - XINT (pattern, 0)); - } + message_with_line (pattern_lineno, + "warning: operand %d missing mode?", + XINT (pattern, 0)); return; } @@ -638,12 +559,12 @@ validate_pattern (rtx pattern, rtx insn, rtx set, int set_code) if (GET_CODE (dest) == MATCH_DUP || GET_CODE (dest) == MATCH_OP_DUP || GET_CODE (dest) == MATCH_PAR_DUP) - dest = find_operand (insn, XINT (dest, 0)); + dest = find_operand (insn, XINT (dest, 0), NULL); if (GET_CODE (src) == MATCH_DUP || GET_CODE (src) == MATCH_OP_DUP || GET_CODE (src) == MATCH_PAR_DUP) - src = find_operand (insn, XINT (src, 0)); + src = find_operand (insn, XINT (src, 0), NULL); dmode = GET_MODE (dest); smode = GET_MODE (src); @@ -657,12 +578,9 @@ validate_pattern (rtx pattern, rtx insn, rtx set, int set_code) /* The operands of a SET must have the same mode unless one is VOIDmode. */ else if (dmode != VOIDmode && smode != VOIDmode && dmode != smode) - { - message_with_line (pattern_lineno, - "mode mismatch in set: %smode vs %smode", - GET_MODE_NAME (dmode), GET_MODE_NAME (smode)); - error_count++; - } + error_with_line (pattern_lineno, + "mode mismatch in set: %smode vs %smode", + GET_MODE_NAME (dmode), GET_MODE_NAME (smode)); /* If only one of the operands is VOIDmode, and PC or CC0 is not involved, it's probably a mistake. */ @@ -671,7 +589,8 @@ validate_pattern (rtx pattern, rtx insn, rtx set, int set_code) && GET_CODE (dest) != CC0 && GET_CODE (src) != PC && GET_CODE (src) != CC0 - && GET_CODE (src) != CONST_INT) + && !CONST_INT_P (src) + && GET_CODE (src) != CALL) { const char *which; which = (dmode == VOIDmode ? "destination" : "source"); @@ -702,12 +621,9 @@ validate_pattern (rtx pattern, rtx insn, rtx set, int set_code) case LABEL_REF: if (GET_MODE (XEXP (pattern, 0)) != VOIDmode) - { - message_with_line (pattern_lineno, - "operand to label_ref %smode not VOIDmode", - GET_MODE_NAME (GET_MODE (XEXP (pattern, 0)))); - error_count++; - } + error_with_line (pattern_lineno, + "operand to label_ref %smode not VOIDmode", + GET_MODE_NAME (GET_MODE (XEXP (pattern, 0)))); break; default: @@ -733,7 +649,7 @@ validate_pattern (rtx pattern, rtx insn, rtx set, int set_code) break; default: - abort (); + gcc_unreachable (); } } } @@ -744,36 +660,32 @@ validate_pattern (rtx pattern, rtx insn, rtx set, int set_code) LAST is a pointer to the listhead in the previous node in the chain (or in the calling function, for the first node). - POSITION is the string representing the current position in the insn. + POSITION is the current position in the insn. INSN_TYPE is the type of insn for which we are emitting code. A pointer to the final node in the chain is returned. */ static struct decision * -add_to_sequence (rtx pattern, struct decision_head *last, const char *position, - enum routine_type insn_type, int top) +add_to_sequence (rtx pattern, struct decision_head *last, + struct position *pos, enum routine_type insn_type, int top) { RTX_CODE code; - struct decision *this, *sub; + struct decision *this_decision, *sub; struct decision_test *test; struct decision_test **place; - char *subpos; + struct position *subpos, **subpos_ptr; size_t i; const char *fmt; - int depth = strlen (position); int len; enum machine_mode mode; + enum position_type pos_type; - if (depth > max_depth) - max_depth = depth; - - subpos = xmalloc (depth + 2); - strcpy (subpos, position); - subpos[depth + 1] = 0; + if (pos->depth > max_depth) + max_depth = pos->depth; - sub = this = new_decision (position, last); - place = &this->tests; + sub = this_decision = new_decision (pos, last); + place = &this_decision->tests; restart: mode = GET_MODE (pattern); @@ -785,18 +697,32 @@ add_to_sequence (rtx pattern, struct decision_head *last, const char *position, /* Toplevel peephole pattern. */ if (insn_type == PEEPHOLE2 && top) { - /* We don't need the node we just created -- unlink it. */ - last->first = last->last = NULL; + int num_insns; - for (i = 0; i < (size_t) XVECLEN (pattern, 0); i++) + /* Check we have sufficient insns. This avoids complications + because we then know peep2_next_insn never fails. */ + num_insns = XVECLEN (pattern, 0); + if (num_insns > 1) + { + test = new_decision_test (DT_num_insns, &place); + test->u.num_insns = num_insns; + last = &sub->success; + } + else { - /* Which insn we're looking at is represented by A-Z. We don't - ever use 'A', however; it is always implied. */ + /* We don't need the node we just created -- unlink it. */ + last->first = last->last = NULL; + } - subpos[depth] = (i > 0 ? 'A' + i : 0); + subpos_ptr = &peep2_insn_pos_list; + for (i = 0; i < (size_t) XVECLEN (pattern, 0); i++) + { + subpos = next_position (subpos_ptr, &root_pos, + POS_PEEP2_INSN, i); sub = add_to_sequence (XVECEXP (pattern, 0, i), last, subpos, insn_type, 0); last = &sub->success; + subpos_ptr = &subpos->next; } goto ret; } @@ -812,16 +738,15 @@ add_to_sequence (rtx pattern, struct decision_head *last, const char *position, beyond the end of the vector. */ test = new_decision_test (DT_veclen_ge, &place); test->u.veclen = XVECLEN (pattern, 2); - /* FALLTHRU */ + /* Fall through. */ case MATCH_OPERAND: case MATCH_SCRATCH: case MATCH_OPERATOR: - case MATCH_INSN: { - const char *pred_name; RTX_CODE was_code = code; - int allows_const_int = 1; + const char *pred_name; + bool allows_const_int = true; if (code == MATCH_SCRATCH) { @@ -839,62 +764,64 @@ add_to_sequence (rtx pattern, struct decision_head *last, const char *position, if (pred_name[0] != 0) { + const struct pred_data *pred; + test = new_decision_test (DT_pred, &place); test->u.pred.name = pred_name; test->u.pred.mode = mode; - /* See if we know about this predicate and save its number. - If we do, and it only accepts one code, note that fact. - - If we know that the predicate does not allow CONST_INT, - we know that the only way the predicate can match is if - the modes match (here we use the kludge of relying on the - fact that "address_operand" accepts CONST_INT; otherwise, - it would have to be a special case), so we can test the - mode (but we need not). This fact should considerably - simplify the generated code. */ - - for (i = 0; i < NUM_KNOWN_PREDS; i++) - if (! strcmp (preds[i].name, pred_name)) - break; + /* See if we know about this predicate. + If we do, remember it for use below. - if (i < NUM_KNOWN_PREDS) + We can optimize the generated code a little if either + (a) the predicate only accepts one code, or (b) the + predicate does not allow CONST_INT, in which case it + can match only if the modes match. */ + pred = lookup_predicate (pred_name); + if (pred) { - int j; - - test->u.pred.index = i; - - if (preds[i].codes[1] == 0 && code == UNKNOWN) - code = preds[i].codes[0]; - - allows_const_int = 0; - for (j = 0; preds[i].codes[j] != 0; j++) - if (preds[i].codes[j] == CONST_INT) - { - allows_const_int = 1; - break; - } + test->u.pred.data = pred; + allows_const_int = pred->codes[CONST_INT]; + if (was_code == MATCH_PARALLEL + && pred->singleton != PARALLEL) + message_with_line (pattern_lineno, + "predicate '%s' used in match_parallel " + "does not allow only PARALLEL", pred->name); + else + code = pred->singleton; } else - test->u.pred.index = -1; + message_with_line (pattern_lineno, + "warning: unknown predicate '%s' in '%s' expression", + pred_name, GET_RTX_NAME (was_code)); } /* Can't enforce a mode if we allow const_int. */ if (allows_const_int) mode = VOIDmode; - /* Accept the operand, ie. record it in `operands'. */ + /* Accept the operand, i.e. record it in `operands'. */ test = new_decision_test (DT_accept_op, &place); test->u.opno = XINT (pattern, 0); if (was_code == MATCH_OPERATOR || was_code == MATCH_PARALLEL) { - char base = (was_code == MATCH_OPERATOR ? '0' : 'a'); + if (was_code == MATCH_OPERATOR) + { + pos_type = POS_XEXP; + subpos_ptr = &pos->xexps; + } + else + { + pos_type = POS_XVECEXP0; + subpos_ptr = &pos->xvecexp0s; + } for (i = 0; i < (size_t) XVECLEN (pattern, 2); i++) { - subpos[depth] = i + base; + subpos = next_position (subpos_ptr, pos, pos_type, i); sub = add_to_sequence (XVECEXP (pattern, 2, i), &sub->success, subpos, insn_type, 0); + subpos_ptr = &subpos->next; } } goto fini; @@ -909,11 +836,13 @@ add_to_sequence (rtx pattern, struct decision_head *last, const char *position, test = new_decision_test (DT_accept_op, &place); test->u.opno = XINT (pattern, 0); + subpos_ptr = &pos->xexps; for (i = 0; i < (size_t) XVECLEN (pattern, 1); i++) { - subpos[depth] = i + '0'; + subpos = next_position (subpos_ptr, pos, POS_XEXP, i); sub = add_to_sequence (XVECEXP (pattern, 1, i), &sub->success, subpos, insn_type, 0); + subpos_ptr = &subpos->next; } goto fini; @@ -941,18 +870,18 @@ add_to_sequence (rtx pattern, struct decision_head *last, const char *position, { if (fmt[i] == 'i') { - if (i == 0) + gcc_assert (i < 2); + + if (!i) { test = new_decision_test (DT_elt_zero_int, &place); test->u.intval = XINT (pattern, i); } - else if (i == 1) + else { test = new_decision_test (DT_elt_one_int, &place); test->u.intval = XINT (pattern, i); } - else - abort (); } else if (fmt[i] == 'w') { @@ -962,16 +891,14 @@ add_to_sequence (rtx pattern, struct decision_head *last, const char *position, = ((int) XWINT (pattern, i) == XWINT (pattern, i)) ? DT_elt_zero_wide_safe : DT_elt_zero_wide; - if (i != 0) - abort (); + gcc_assert (!i); test = new_decision_test (type, &place); test->u.intval = XWINT (pattern, i); } else if (fmt[i] == 'E') { - if (i != 0) - abort (); + gcc_assert (!i); test = new_decision_test (DT_veclen, &place); test->u.veclen = XVECLEN (pattern, i); @@ -979,24 +906,29 @@ add_to_sequence (rtx pattern, struct decision_head *last, const char *position, } /* Now test our sub-patterns. */ + subpos_ptr = &pos->xexps; for (i = 0; i < (size_t) len; i++) { + subpos = next_position (subpos_ptr, pos, POS_XEXP, i); switch (fmt[i]) { case 'e': case 'u': - subpos[depth] = '0' + i; sub = add_to_sequence (XEXP (pattern, i), &sub->success, subpos, insn_type, 0); break; case 'E': { + struct position *subpos2, **subpos2_ptr; int j; + + subpos2_ptr = &pos->xvecexp0s; for (j = 0; j < XVECLEN (pattern, i); j++) { - subpos[depth] = 'a' + j; + subpos2 = next_position (subpos2_ptr, pos, POS_XVECEXP0, j); sub = add_to_sequence (XVECEXP (pattern, i, j), - &sub->success, subpos, insn_type, 0); + &sub->success, subpos2, insn_type, 0); + subpos2_ptr = &subpos2->next; } break; } @@ -1008,8 +940,9 @@ add_to_sequence (rtx pattern, struct decision_head *last, const char *position, break; default: - abort (); + gcc_unreachable (); } + subpos_ptr = &subpos->next; } fini: @@ -1017,24 +950,22 @@ add_to_sequence (rtx pattern, struct decision_head *last, const char *position, before any of the nodes we may have added above. */ if (code != UNKNOWN) { - place = &this->tests; + place = &this_decision->tests; test = new_decision_test (DT_code, &place); test->u.code = code; } if (mode != VOIDmode) { - place = &this->tests; + place = &this_decision->tests; test = new_decision_test (DT_mode, &place); test->u.mode = mode; } /* If we didn't insert any tests or accept nodes, hork. */ - if (this->tests == NULL) - abort (); + gcc_assert (this_decision->tests); ret: - free (subpos); return sub; } @@ -1048,6 +979,12 @@ maybe_both_true_2 (struct decision_test *d1, struct decision_test *d2) { switch (d1->type) { + case DT_num_insns: + if (d1->u.num_insns == d2->u.num_insns) + return 1; + else + return -1; + case DT_mode: return d1->u.mode == d2->u.mode; @@ -1099,39 +1036,28 @@ maybe_both_true_2 (struct decision_test *d1, struct decision_test *d2) separate DT_mode that will make maybe_both_true_1 return 0. */ } - if (d1->u.pred.index >= 0) + if (d1->u.pred.data) { /* If D2 tests a code, see if it is in the list of valid codes for D1's predicate. */ if (d2->type == DT_code) { - const RTX_CODE *c = &preds[d1->u.pred.index].codes[0]; - while (*c != 0) - { - if (*c == d2->u.code) - break; - ++c; - } - if (*c == 0) + if (!d1->u.pred.data->codes[d2->u.code]) return 0; } /* Otherwise see if the predicates have any codes in common. */ - else if (d2->type == DT_pred && d2->u.pred.index >= 0) + else if (d2->type == DT_pred && d2->u.pred.data) { - const RTX_CODE *c1 = &preds[d1->u.pred.index].codes[0]; - int common = 0; + bool common = false; + int c; - while (*c1 != 0 && !common) - { - const RTX_CODE *c2 = &preds[d2->u.pred.index].codes[0]; - while (*c2 != 0 && !common) - { - common = (*c1 == *c2); - ++c2; - } - ++c1; - } + for (c = 0; c < NUM_RTX_CODE; c++) + if (d1->u.pred.data->codes[c] && d2->u.pred.data->codes[c]) + { + common = true; + break; + } if (!common) return 0; @@ -1205,16 +1131,15 @@ maybe_both_true (struct decision *d1, struct decision *d2, of a node's success nodes (from the loop at the end of this function). Skip forward until we come to a position that matches. - Due to the way position strings are constructed, we know that iterating - forward from the lexically lower position (e.g. "00") will run into - the lexically higher position (e.g. "1") and not the other way around. - This saves a bit of effort. */ + Due to the way positions are constructed, we know that iterating + forward from the lexically lower position will run into the lexically + higher position and not the other way around. This saves a bit + of effort. */ - cmp = strcmp (d1->position, d2->position); + cmp = compare_positions (d1->position, d2->position); if (cmp != 0) { - if (toplevel) - abort (); + gcc_assert (!toplevel); /* If the d2->position was lexically lower, swap. */ if (cmp > 0) @@ -1258,6 +1183,9 @@ nodes_identical_1 (struct decision_test *d1, struct decision_test *d2) { switch (d1->type) { + case DT_num_insns: + return d1->u.num_insns == d2->u.num_insns; + case DT_mode: return d1->u.mode == d2->u.mode; @@ -1292,7 +1220,7 @@ nodes_identical_1 (struct decision_test *d1, struct decision_test *d2) return 1; default: - abort (); + gcc_unreachable (); } } @@ -1323,7 +1251,7 @@ nodes_identical (struct decision *d1, struct decision *d2) invoked. */ if (d1->success.first && d2->success.first - && strcmp (d1->success.first->position, d2->success.first->position)) + && d1->success.first->position != d2->success.first->position) return 0; return 1; @@ -1369,12 +1297,11 @@ merge_accept_insn (struct decision *oldd, struct decision *addd) } else { - message_with_line (add->u.insn.lineno, "`%s' matches `%s'", - get_insn_name (add->u.insn.code_number), - get_insn_name (old->u.insn.code_number)); + error_with_line (add->u.insn.lineno, "`%s' matches `%s'", + get_insn_name (add->u.insn.code_number), + get_insn_name (old->u.insn.code_number)); message_with_line (old->u.insn.lineno, "previous definition of `%s'", get_insn_name (old->u.insn.code_number)); - error_count++; } } @@ -1394,8 +1321,7 @@ merge_trees (struct decision_head *oldh, struct decision_head *addh) } /* Trying to merge bits at different positions isn't possible. */ - if (strcmp (oldh->first->position, addh->first->position)) - abort (); + gcc_assert (oldh->first->position == addh->first->position); for (add = addh->first; add ; add = next) { @@ -1472,7 +1398,7 @@ factor_tests (struct decision_head *head) for (first = head->first; first && first->next; first = next) { enum decision_type type; - struct decision *new, *old_last; + struct decision *new_dec, *old_last; type = first->tests->type; next = first->next; @@ -1495,8 +1421,8 @@ factor_tests (struct decision_head *head) below our first test. */ if (first->tests->next != NULL) { - new = new_decision (first->position, &first->success); - new->tests = first->tests->next; + new_dec = new_decision (first->position, &first->success); + new_dec->tests = first->tests->next; first->tests->next = NULL; } @@ -1513,14 +1439,14 @@ factor_tests (struct decision_head *head) if (next->tests->next != NULL) { - new = new_decision (next->position, &next->success); - new->tests = next->tests->next; + new_dec = new_decision (next->position, &next->success); + new_dec->tests = next->tests->next; next->tests->next = NULL; } - new = next; + new_dec = next; next = next->next; - new->next = NULL; - h.first = h.last = new; + new_dec->next = NULL; + h.first = h.last = new_dec; merge_trees (head, &h); } @@ -1654,57 +1580,31 @@ find_afterward (struct decision_head *head, struct decision *real_afterward) match multiple insns and we try to step past the end of the stream. */ static void -change_state (const char *oldpos, const char *newpos, - struct decision *afterward, const char *indent) +change_state (struct position *oldpos, struct position *newpos, + const char *indent) { - int odepth = strlen (oldpos); - int ndepth = strlen (newpos); - int depth; - int old_has_insn, new_has_insn; + while (oldpos->depth > newpos->depth) + oldpos = oldpos->base; - /* Pop up as many levels as necessary. */ - for (depth = odepth; strncmp (oldpos, newpos, depth) != 0; --depth) - continue; + if (oldpos != newpos) + switch (newpos->type) + { + case POS_PEEP2_INSN: + printf ("%stem = peep2_next_insn (%d);\n", indent, newpos->arg); + printf ("%sx%d = PATTERN (tem);\n", indent, newpos->depth); + break; - /* Hunt for the last [A-Z] in both strings. */ - for (old_has_insn = odepth - 1; old_has_insn >= 0; --old_has_insn) - if (ISUPPER (oldpos[old_has_insn])) - break; - for (new_has_insn = ndepth - 1; new_has_insn >= 0; --new_has_insn) - if (ISUPPER (newpos[new_has_insn])) - break; + case POS_XEXP: + change_state (oldpos, newpos->base, indent); + printf ("%sx%d = XEXP (x%d, %d);\n", + indent, newpos->depth, newpos->depth - 1, newpos->arg); + break; - /* Go down to desired level. */ - while (depth < ndepth) - { - /* It's a different insn from the first one. */ - if (ISUPPER (newpos[depth])) - { - /* We can only fail if we're moving down the tree. */ - if (old_has_insn >= 0 && oldpos[old_has_insn] >= newpos[depth]) - { - printf ("%stem = peep2_next_insn (%d);\n", - indent, newpos[depth] - 'A'); - } - else - { - printf ("%stem = peep2_next_insn (%d);\n", - indent, newpos[depth] - 'A'); - printf ("%sif (tem == NULL_RTX)\n", indent); - if (afterward) - printf ("%s goto L%d;\n", indent, afterward->number); - else - printf ("%s goto ret0;\n", indent); - } - printf ("%sx%d = PATTERN (tem);\n", indent, depth + 1); - } - else if (ISLOWER (newpos[depth])) + case POS_XVECEXP0: + change_state (oldpos, newpos->base, indent); printf ("%sx%d = XVECEXP (x%d, 0, %d);\n", - indent, depth + 1, depth, newpos[depth] - 'a'); - else - printf ("%sx%d = XEXP (x%d, %c);\n", - indent, depth + 1, depth, newpos[depth]); - ++depth; + indent, newpos->depth, newpos->depth - 1, newpos->arg); + break; } } @@ -1729,7 +1629,7 @@ write_afterward (struct decision *start, struct decision *afterward, printf("%sgoto ret0;\n", indent); else { - change_state (start->position, afterward->position, NULL, indent); + change_state (start->position, afterward->position, indent); printf ("%sgoto L%d;\n", indent, afterward->number); } } @@ -1813,22 +1713,23 @@ write_switch (struct decision *start, int depth) else ret = p; - while (p && p->tests->type == DT_pred - && p->tests->u.pred.index >= 0) + while (p && p->tests->type == DT_pred && p->tests->u.pred.data) { - const RTX_CODE *c; + const struct pred_data *data = p->tests->u.pred.data; + int c; - for (c = &preds[p->tests->u.pred.index].codes[0]; *c ; ++c) - if (codemap[(int) *c] != 0) + for (c = 0; c < NUM_RTX_CODE; c++) + if (codemap[c] && data->codes[c]) goto pred_done; - for (c = &preds[p->tests->u.pred.index].codes[0]; *c ; ++c) - { - printf (" case "); - print_code (*c); - printf (":\n"); - codemap[(int) *c] = 1; - } + for (c = 0; c < NUM_RTX_CODE; c++) + if (data->codes[c]) + { + fputs (" case ", stdout); + print_code ((enum rtx_code) c); + fputs (":\n", stdout); + codemap[c] = 1; + } printf (" goto L%d;\n", p->number); p->need_label = 1; @@ -1891,7 +1792,7 @@ write_switch (struct decision *start, int depth) printf ("(int) XWINT (x%d, 0)", depth); break; default: - abort (); + gcc_unreachable (); } printf (")\n%s {\n", indent); @@ -1924,7 +1825,7 @@ write_switch (struct decision *start, int depth) print_host_wide_int (p->tests->u.intval); break; default: - abort (); + gcc_unreachable (); } printf (":\n%s goto L%d;\n", indent, p->success.first->number); p->success.first->need_label = 1; @@ -1954,6 +1855,10 @@ write_cond (struct decision_test *p, int depth, { switch (p->type) { + case DT_num_insns: + printf ("peep2_current_count >= %d", p->u.num_insns); + break; + case DT_mode: printf ("GET_MODE (x%d) == %smode", depth, GET_MODE_NAME (p->u.mode)); break; @@ -1981,6 +1886,11 @@ write_cond (struct decision_test *p, int depth, print_host_wide_int (p->u.intval); break; + case DT_const_int: + printf ("x%d == const_int_rtx[MAX_SAVED_CONST_INT + (%d)]", + depth, (int) p->u.intval); + break; + case DT_veclen_ge: printf ("XVECLEN (x%d, 0) >= %d", depth, p->u.veclen); break; @@ -1995,25 +1905,17 @@ write_cond (struct decision_test *p, int depth, break; case DT_c_test: - printf ("(%s)", p->u.c_test); + print_c_condition (p->u.c_test); break; case DT_accept_insn: - switch (subroutine_type) - { - case RECOG: - if (p->u.insn.num_clobbers_to_add == 0) - abort (); - printf ("pnum_clobbers != NULL"); - break; - - default: - abort (); - } + gcc_assert (subroutine_type == RECOG); + gcc_assert (p->u.insn.num_clobbers_to_add); + printf ("pnum_clobbers != NULL"); break; default: - abort (); + gcc_unreachable (); } } @@ -2048,14 +1950,12 @@ write_action (struct decision *p, struct decision_test *test, if (test->next) { test = test->next; - if (test->type != DT_accept_insn) - abort (); + gcc_assert (test->type == DT_accept_insn); } } /* Sanity check that we're now at the end of the list of tests. */ - if (test->next) - abort (); + gcc_assert (!test->next); if (test->type == DT_accept_insn) { @@ -2065,22 +1965,25 @@ write_action (struct decision *p, struct decision_test *test, if (test->u.insn.num_clobbers_to_add != 0) printf ("%s*pnum_clobbers = %d;\n", indent, test->u.insn.num_clobbers_to_add); - printf ("%sreturn %d;\n", indent, test->u.insn.code_number); + printf ("%sreturn %d; /* %s */\n", indent, + test->u.insn.code_number, + get_insn_name (test->u.insn.code_number)); break; case SPLIT: - printf ("%sreturn gen_split_%d (operands);\n", + printf ("%sreturn gen_split_%d (insn, operands);\n", indent, test->u.insn.code_number); break; case PEEPHOLE2: { - int match_len = 0, i; + int match_len = 0; + struct position *pos; - for (i = strlen (p->position) - 1; i >= 0; --i) - if (ISUPPER (p->position[i])) + for (pos = p->position; pos; pos = pos->base) + if (pos->type == POS_PEEP2_INSN) { - match_len = p->position[i] - 'A'; + match_len = pos->arg; break; } printf ("%s*_pmatch_len = %d;\n", indent, match_len); @@ -2091,7 +1994,7 @@ write_action (struct decision *p, struct decision_test *test, break; default: - abort (); + gcc_unreachable (); } } else @@ -2126,7 +2029,7 @@ is_unconditional (struct decision_test *t, enum routine_type subroutine_type) case PEEPHOLE2: return -1; default: - abort (); + gcc_unreachable (); } } @@ -2143,6 +2046,23 @@ write_node (struct decision *p, int depth, struct decision_test *test, *last_test; int uncond; + /* Scan the tests and simplify comparisons against small + constants. */ + for (test = p->tests; test; test = test->next) + { + if (test->type == DT_code + && test->u.code == CONST_INT + && test->next + && test->next->type == DT_elt_zero_wide_safe + && -MAX_SAVED_CONST_INT <= test->next->u.intval + && test->next->u.intval <= MAX_SAVED_CONST_INT) + { + test->type = DT_const_int; + test->u.intval = test->next->u.intval; + test->next = test->next->next; + } + } + last_test = test = p->tests; uncond = is_unconditional (test, subroutine_type); if (uncond == 0) @@ -2152,11 +2072,8 @@ write_node (struct decision *p, int depth, while ((test = test->next) != NULL) { - int uncond2; - last_test = test; - uncond2 = is_unconditional (test, subroutine_type); - if (uncond2 != 0) + if (is_unconditional (test, subroutine_type)) break; printf ("\n && "); @@ -2208,7 +2125,7 @@ write_tree_1 (struct decision_head *head, int depth, position at the node that branched to this node. */ static void -write_tree (struct decision_head *head, const char *prevpos, +write_tree (struct decision_head *head, struct position *prevpos, enum routine_type type, int initial) { struct decision *p = head->first; @@ -2239,7 +2156,7 @@ write_tree (struct decision_head *head, const char *prevpos, else printf (" if (tem >= 0)\n return tem;\n"); - change_state (p->position, p->afterward->position, NULL, " "); + change_state (p->position, p->afterward->position, " "); printf (" goto L%d;\n", p->afterward->number); } else @@ -2250,10 +2167,8 @@ write_tree (struct decision_head *head, const char *prevpos, } else { - int depth = strlen (p->position); - - change_state (prevpos, p->position, head->last->afterward, " "); - write_tree_1 (head, depth, type); + change_state (prevpos, p->position, " "); + write_tree_1 (head, p->position->depth, type); for (p = head->first; p; p = p->next) if (p->success.first) @@ -2309,7 +2224,7 @@ peephole2%s (rtx x0 ATTRIBUTE_UNUSED,\n\trtx insn ATTRIBUTE_UNUSED,\n\tint *_pma printf (" recog_data.insn = NULL_RTX;\n"); if (head->first) - write_tree (head, "", type, 1); + write_tree (head, &root_pos, type, 1); else printf (" goto ret0;\n"); @@ -2350,13 +2265,14 @@ write_header (void) #include \"function.h\"\n\ #include \"insn-config.h\"\n\ #include \"recog.h\"\n\ -#include \"real.h\"\n\ #include \"output.h\"\n\ #include \"flags.h\"\n\ #include \"hard-reg-set.h\"\n\ #include \"resource.h\"\n\ -#include \"toplev.h\"\n\ +#include \"diagnostic-core.h\"\n\ #include \"reload.h\"\n\ +#include \"regs.h\"\n\ +#include \"tm-constrs.h\"\n\ \n"); puts ("\n\ @@ -2405,15 +2321,12 @@ make_insn_sequence (rtx insn, enum routine_type type) struct decision *last; struct decision_test *test, **place; struct decision_head head; - char c_test_pos[2]; + struct position *c_test_pos, **pos_ptr; /* We should never see an insn whose C test is false at compile time. */ - if (truth == 0) - abort (); + gcc_assert (truth); - record_insn_name (next_insn_code, (type == RECOG ? XSTR (insn, 0) : NULL)); - - c_test_pos[0] = '\0'; + c_test_pos = &root_pos; if (type == PEEPHOLE2) { int i, j; @@ -2425,19 +2338,20 @@ make_insn_sequence (rtx insn, enum routine_type type) x = rtx_alloc (PARALLEL); PUT_MODE (x, VOIDmode); XVEC (x, 0) = rtvec_alloc (XVECLEN (insn, 0)); + pos_ptr = &peep2_insn_pos_list; for (i = j = 0; i < XVECLEN (insn, 0); i++) { rtx tmp = XVECEXP (insn, 0, i); if (GET_CODE (tmp) != MATCH_SCRATCH && GET_CODE (tmp) != MATCH_DUP) { + c_test_pos = next_position (pos_ptr, &root_pos, + POS_PEEP2_INSN, j); XVECEXP (x, 0, j) = tmp; j++; + pos_ptr = &c_test_pos->next; } } XVECLEN (x, 0) = j; - - c_test_pos[0] = 'A' + j - 1; - c_test_pos[1] = '\0'; } else if (XVECLEN (insn, type == RECOG) == 1) x = XVECEXP (insn, type == RECOG, 0); @@ -2451,7 +2365,7 @@ make_insn_sequence (rtx insn, enum routine_type type) validate_pattern (x, insn, NULL_RTX, 0); memset(&head, 0, sizeof(head)); - last = add_to_sequence (x, &head, "", type, 1); + last = add_to_sequence (x, &head, &root_pos, type, 1); /* Find the end of the test chain on the last node. */ for (test = last->tests; test->next; test = test->next) @@ -2492,32 +2406,33 @@ make_insn_sequence (rtx insn, enum routine_type type) { rtx y = XVECEXP (x, 0, i - 1); if (GET_CODE (y) != CLOBBER - || (GET_CODE (XEXP (y, 0)) != REG + || (!REG_P (XEXP (y, 0)) && GET_CODE (XEXP (y, 0)) != MATCH_SCRATCH)) break; } if (i != XVECLEN (x, 0)) { - rtx new; + rtx new_rtx; struct decision_head clobber_head; /* Build a similar insn without the clobbers. */ if (i == 1) - new = XVECEXP (x, 0, 0); + new_rtx = XVECEXP (x, 0, 0); else { int j; - new = rtx_alloc (PARALLEL); - XVEC (new, 0) = rtvec_alloc (i); + new_rtx = rtx_alloc (PARALLEL); + XVEC (new_rtx, 0) = rtvec_alloc (i); for (j = i - 1; j >= 0; j--) - XVECEXP (new, 0, j) = XVECEXP (x, 0, j); + XVECEXP (new_rtx, 0, j) = XVECEXP (x, 0, j); } /* Recognize it. */ memset (&clobber_head, 0, sizeof(clobber_head)); - last = add_to_sequence (new, &clobber_head, "", type, 1); + last = add_to_sequence (new_rtx, &clobber_head, &root_pos, + type, 1); /* Find the end of the test chain on the last node. */ for (test = last->tests; test->next; test = test->next) @@ -2528,7 +2443,7 @@ make_insn_sequence (rtx insn, enum routine_type type) place = &test->next; if (test->type == DT_accept_op) { - last = new_decision ("", &last->success); + last = new_decision (&root_pos, &last->success); place = &last->tests; } @@ -2552,7 +2467,7 @@ make_insn_sequence (rtx insn, enum routine_type type) case SPLIT: /* Define the subroutine we will call below and emit in genemit. */ - printf ("extern rtx gen_split_%d (rtx *);\n", next_insn_code); + printf ("extern rtx gen_split_%d (rtx, rtx *);\n", next_insn_code); break; case PEEPHOLE2: @@ -2607,14 +2522,10 @@ main (int argc, char **argv) memset (&split_tree, 0, sizeof split_tree); memset (&peephole2_tree, 0, sizeof peephole2_tree); - if (argc <= 1) - fatal ("no input file name"); - - if (init_md_reader_args (argc, argv) != SUCCESS_EXIT_CODE) + if (!init_rtx_reader_args (argc, argv)) return (FATAL_EXIT_CODE); next_insn_code = 0; - next_index = 0; write_header (); @@ -2626,26 +2537,28 @@ main (int argc, char **argv) if (desc == NULL) break; - if (GET_CODE (desc) == DEFINE_INSN) + switch (GET_CODE (desc)) { + case DEFINE_INSN: h = make_insn_sequence (desc, RECOG); merge_trees (&recog_tree, &h); - } - else if (GET_CODE (desc) == DEFINE_SPLIT) - { + break; + + case DEFINE_SPLIT: h = make_insn_sequence (desc, SPLIT); merge_trees (&split_tree, &h); - } - else if (GET_CODE (desc) == DEFINE_PEEPHOLE2) - { + break; + + case DEFINE_PEEPHOLE2: h = make_insn_sequence (desc, PEEPHOLE2); merge_trees (&peephole2_tree, &h); - } - next_index++; + default: + /* do nothing */; + } } - if (error_count) + if (have_error) return FATAL_EXIT_CODE; puts ("\n\n"); @@ -2658,52 +2571,14 @@ main (int argc, char **argv) return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE); } -/* Define this so we can link with print-rtl.o to get debug_rtx function. */ -const char * -get_insn_name (int code) -{ - if (code < insn_name_ptr_size) - return insn_name_ptr[code]; - else - return NULL; -} - -static void -record_insn_name (int code, const char *name) -{ - static const char *last_real_name = "insn"; - static int last_real_code = 0; - char *new; - - if (insn_name_ptr_size <= code) - { - int new_size; - new_size = (insn_name_ptr_size ? insn_name_ptr_size * 2 : 512); - insn_name_ptr = xrealloc (insn_name_ptr, sizeof(char *) * new_size); - memset (insn_name_ptr + insn_name_ptr_size, 0, - sizeof(char *) * (new_size - insn_name_ptr_size)); - insn_name_ptr_size = new_size; - } - - if (!name || name[0] == '\0') - { - new = xmalloc (strlen (last_real_name) + 10); - sprintf (new, "%s+%d", last_real_name, code - last_real_code); - } - else - { - last_real_name = new = xstrdup (name); - last_real_code = code; - } - - insn_name_ptr[code] = new; -} - static void debug_decision_2 (struct decision_test *test) { switch (test->type) { + case DT_num_insns: + fprintf (stderr, "num_insns=%d", test->u.num_insns); + break; case DT_mode: fprintf (stderr, "mode=%s", GET_MODE_NAME (test->u.mode)); break; @@ -2752,7 +2627,7 @@ debug_decision_2 (struct decision_test *test) break; default: - abort (); + gcc_unreachable (); } } @@ -2810,13 +2685,13 @@ debug_decision_0 (struct decision *d, int indent, int maxdepth) debug_decision_0 (n, indent + 2, maxdepth - 1); } -void +DEBUG_FUNCTION void debug_decision (struct decision *d) { debug_decision_0 (d, 0, 1000000); } -void +DEBUG_FUNCTION void debug_decision_list (struct decision *d) { while (d)