/* Generate code from machine description to perform peephole optimizations.
- Copyright (C) 1987, 1989, 1992, 1997, 1998, 1999, 2000, 2003, 2004,
- 2007, 2010, 2012 Free Software Foundation, Inc.
+ Copyright (C) 1987-2022 Free Software Foundation, Inc.
This file is part of GCC.
static int n_operands;
-static void gen_peephole (rtx, int);
static void match_rtx (rtx, struct link *, int);
static void print_path (struct link *);
static void print_code (RTX_CODE);
\f
static void
-gen_peephole (rtx peep, int insn_code_number)
+gen_peephole (md_rtx_info *info)
{
+ rtx peep = info->def;
int ninsns = XVECLEN (peep, 0);
int i;
if (i > 0)
{
printf (" do { insn = NEXT_INSN (insn);\n");
- printf (" if (insn == 0) goto L%d; }\n",
- insn_code_number);
+ printf (" if (insn == 0) goto L%d; }\n", info->index);
printf (" while (NOTE_P (insn)\n");
printf ("\t || (NONJUMP_INSN_P (insn)\n");
printf ("\t && (GET_CODE (PATTERN (insn)) == USE\n");
printf ("\t\t || GET_CODE (PATTERN (insn)) == CLOBBER)));\n");
printf (" if (LABEL_P (insn)\n\
- || BARRIER_P (insn))\n goto L%d;\n",
- insn_code_number);
+ || BARRIER_P (insn))\n goto L%d;\n", info->index);
}
printf (" pat = PATTERN (insn);\n");
/* Walk the insn's pattern, remembering at all times the path
down to the walking point. */
- match_rtx (XVECEXP (peep, 0, i), NULL, insn_code_number);
+ match_rtx (XVECEXP (peep, 0, i), NULL, info->index);
}
/* We get this far if the pattern matches.
if (XSTR (peep, 1) && XSTR (peep, 1)[0])
printf (" if (! (%s)) goto L%d;\n",
- XSTR (peep, 1), insn_code_number);
+ XSTR (peep, 1), info->index);
/* If that matches, construct new pattern and put it in the first insn.
This new pattern will never be matched.
/* Record this define_peephole's insn code in the insn,
as if it had been recognized to match this. */
- printf (" INSN_CODE (ins1) = %d;\n",
- insn_code_number);
+ printf (" INSN_CODE (ins1) = %d;\n", info->index);
/* Delete the remaining insns. */
if (ninsns > 1)
cannot be zero. */
printf (" return NEXT_INSN (insn);\n");
- printf (" L%d:\n\n", insn_code_number);
+ printf (" L%d:\n\n", info->index);
}
\f
static void
printf (" if (XINT (x, %d) != %d) goto L%d;\n",
i, XINT (x, i), fail_label);
}
+ else if (fmt[i] == 'r')
+ {
+ gcc_assert (i == 0);
+ printf (" if (REGNO (x) != %d) goto L%d;\n",
+ REGNO (x), fail_label);
+ }
else if (fmt[i] == 'w')
{
/* Make sure that at run time `x' is the RTX we want to test. */
printf (" if (strcmp (XSTR (x, %d), \"%s\")) goto L%d;\n",
i, XSTR (x, i), fail_label);
}
+ else if (fmt[i] == 'p')
+ /* Not going to support subregs for legacy define_peeholes. */
+ gcc_unreachable ();
}
}
{
const char *p1;
for (p1 = GET_RTX_NAME (code); *p1; p1++)
- putchar (TOUPPER(*p1));
+ putchar (TOUPPER (*p1));
}
-extern int main (int, char **);
+extern int main (int, const char **);
int
-main (int argc, char **argv)
+main (int argc, const char **argv)
{
- rtx desc;
-
max_opno = -1;
progname = "genpeep";
printf ("/* Generated automatically by the program `genpeep'\n\
from the machine description file `md'. */\n\n");
+ printf ("#define IN_TARGET_CODE 1\n");
printf ("#include \"config.h\"\n");
printf ("#include \"system.h\"\n");
printf ("#include \"coretypes.h\"\n");
- printf ("#include \"tm.h\"\n");
- printf ("#include \"insn-config.h\"\n");
+ printf ("#include \"backend.h\"\n");
+ printf ("#include \"tree.h\"\n");
printf ("#include \"rtl.h\"\n");
+ printf ("#include \"insn-config.h\"\n");
+ printf ("#include \"alias.h\"\n");
+ printf ("#include \"varasm.h\"\n");
+ printf ("#include \"stor-layout.h\"\n");
+ printf ("#include \"calls.h\"\n");
+ printf ("#include \"memmodel.h\"\n");
printf ("#include \"tm_p.h\"\n");
printf ("#include \"regs.h\"\n");
printf ("#include \"output.h\"\n");
printf ("#include \"recog.h\"\n");
printf ("#include \"except.h\"\n");
- printf ("#include \"function.h\"\n");
printf ("#include \"diagnostic-core.h\"\n");
printf ("#include \"flags.h\"\n");
printf ("#include \"tm-constrs.h\"\n\n");
- printf ("#ifdef HAVE_peephole\n");
printf ("extern rtx peep_operand[];\n\n");
printf ("#define operands peep_operand\n\n");
- printf ("rtx\npeephole (rtx ins1)\n{\n");
- printf (" rtx insn ATTRIBUTE_UNUSED, x ATTRIBUTE_UNUSED, pat ATTRIBUTE_UNUSED;\n\n");
+ printf ("rtx_insn *\npeephole (rtx_insn *ins1)\n{\n");
+ printf (" rtx_insn *insn ATTRIBUTE_UNUSED;\n");
+ printf (" rtx x ATTRIBUTE_UNUSED, pat ATTRIBUTE_UNUSED;\n\n");
/* Early out: no peepholes for insns followed by barriers. */
printf (" if (NEXT_INSN (ins1)\n");
/* Read the machine description. */
- while (1)
- {
- int line_no;
- int insn_code_number;
-
- desc = read_md_rtx (&line_no, &insn_code_number);
- if (desc == NULL)
+ md_rtx_info info;
+ while (read_md_rtx (&info))
+ switch (GET_CODE (info.def))
+ {
+ case DEFINE_PEEPHOLE:
+ gen_peephole (&info);
break;
- if (GET_CODE (desc) == DEFINE_PEEPHOLE)
- gen_peephole (desc, insn_code_number);
- }
+ default:
+ break;
+ }
printf (" return 0;\n}\n\n");
max_opno = 1;
printf ("rtx peep_operand[%d];\n", max_opno + 1);
- printf ("#endif\n");
fflush (stdout);
return (ferror (stdout) != 0 ? FATAL_EXIT_CODE : SUCCESS_EXIT_CODE);