aboutsummaryrefslogtreecommitdiff
path: root/gcc/recog.c
diff options
context:
space:
mode:
authorRichard Henderson <rth@cygnus.com>1999-08-31 13:37:09 -0700
committerRichard Henderson <rth@gcc.gnu.org>1999-08-31 13:37:09 -0700
commitede7cd44999a94c3eeb6708db37d6939045b554e (patch)
treeafdcdc35501714ae0479a8139d1ee32d313b0176 /gcc/recog.c
parent4dfeccf9d064821bede6f09da2949499f19c68c4 (diff)
downloadgcc-ede7cd44999a94c3eeb6708db37d6939045b554e.zip
gcc-ede7cd44999a94c3eeb6708db37d6939045b554e.tar.gz
gcc-ede7cd44999a94c3eeb6708db37d6939045b554e.tar.bz2
backport: Makefile.in (STAGESTUFF): Add *.peephole2.
Merge peephole2 from new_ia32_branch: * Makefile.in (STAGESTUFF): Add *.peephole2. (mostlyclean): Likewise. (recog.o): Depend on resource.h. * final.c (peephole): Conditionalize decl on HAVE_peephole. (final_scan_insn): Likewise for the invocation of peephole. * genconfig.c (main): Look for peephole and peephole2 patterns. Emit HAVE_peephole* accordingly. * genpeep.c (main): Conditionalize entire output on HAVE_peephole. * flags.h (flag_peephole2): Declare. * toplev.c: New pass peephole2. New flag -fpeephole2. * genattrtab.c (main): Count DEFINE_PEEPHOLE2. * gencodes.c (main): Likewise. * genextract.c (main): Likewise. * genoutput.c (main): Likewise. * genemit.c (max_operand_1): Look for the max scratch operand. (gen_rtx_scratch): New. (gen_exp): Use it, and pass on new arg subroutine_type. (gen_expand): Take max scratch into account. (gen_split): Emit peephole2 functions. (output_peephole2_scratch): New. (main): Include hard-reg-set.h and resource.h. Handle peephole2. * genrecog.c (routine_type): Add PEEPHOLE2. (IS_SPLIT): New. (make_insn_sequence): Match outer parallel for peep2. Discard top level scratches and dups. (add_to_sequence): New args insn_type and top. Update all callers. Handle toplevel peep2 matching insns. (write_subroutine): Handle peep2. (write_tree_1): Likewise. (write_tree): Likewise. (main): Likewise. (change_state): New arg afterward. Update all callers. Handle matching separate insns. * recog.c (recog_next_insn): New. (peephole2_optimize): New. * rtl.def (DEFINE_PEEPHOLE2): New. * resource.c (find_free_register): New argument last_insn. Use it to find a register available through the entire span. * resource.h (find_free_register): Update prototype. From-SVN: r29015
Diffstat (limited to 'gcc/recog.c')
-rw-r--r--gcc/recog.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/gcc/recog.c b/gcc/recog.c
index f41c3d1..95c93d4 100644
--- a/gcc/recog.c
+++ b/gcc/recog.c
@@ -34,6 +34,8 @@ Boston, MA 02111-1307, USA. */
#include "real.h"
#include "toplev.h"
#include "basic-block.h"
+#include "output.h"
+#include "resource.h"
#ifndef STACK_PUSH_CODE
#ifdef STACK_GROWS_DOWNWARD
@@ -2688,3 +2690,69 @@ split_block_insns (b, do_split)
break;
}
}
+
+#ifdef HAVE_peephole2
+/* Return the Nth non-note insn after INSN, or return NULL_RTX if it does
+ not exist. Used by the recognizer to find the next insn to match in a
+ multi-insn pattern. */
+rtx
+recog_next_insn (insn, n)
+ rtx insn;
+ int n;
+{
+ while (insn != NULL_RTX && n > 0)
+ {
+ insn = next_nonnote_insn (insn);
+
+ if (insn == NULL_RTX)
+ return insn;
+
+ if (GET_RTX_CLASS (GET_CODE (insn)) != 'i')
+ return NULL_RTX;
+
+ n--;
+ }
+
+ return insn;
+}
+
+/* Perform the peephole2 optimization pass. */
+void
+peephole2_optimize (dump_file)
+ FILE *dump_file ATTRIBUTE_UNUSED;
+{
+ rtx insn;
+ rtx epilogue_insn = 0;
+
+ for (insn = get_last_insn (); insn != NULL_RTX; insn = PREV_INSN (insn))
+ {
+ if (GET_CODE (insn) == NOTE
+ && NOTE_LINE_NUMBER (insn) == NOTE_INSN_EPILOGUE_BEG)
+ {
+ epilogue_insn = insn;
+ break;
+ }
+ }
+
+ init_resource_info (epilogue_insn);
+
+ for (insn = get_insns (); insn != NULL;
+ insn = next_nonnote_insn (insn))
+ {
+ if (GET_CODE (insn) == INSN || GET_CODE (insn) == JUMP_INSN)
+ {
+ rtx last_insn;
+ rtx before = PREV_INSN (insn);
+
+ rtx try = peephole2_insns (PATTERN (insn), insn, &last_insn);
+ if (try != NULL)
+ {
+ replace_insns (insn, last_insn, try, NULL_RTX);
+ insn = NEXT_INSN (before);
+ }
+ }
+ }
+
+ free_resource_info ();
+}
+#endif