From 8ccf5d5fe8ab1facea7ad7563d11edf5fb56411c Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Thu, 2 Jan 2003 14:59:30 +0000 Subject: h8300.c (stack_pointer_operand): New. * config/h8300/h8300.c (stack_pointer_operand): New. (const_int_gt_2_operand): Likewise. (const_int_ge_8_operand): Likewise. * config/h8300/h8300.md (a splitter): Likewise. (a peephole2): Likewise. * config/h8300/h8300-protos.h: Add prototypes for the new functions above. From-SVN: r60784 --- gcc/ChangeLog | 10 ++++++++++ gcc/config/h8300/h8300-protos.h | 5 ++++- gcc/config/h8300/h8300.c | 34 ++++++++++++++++++++++++++++++++++ gcc/config/h8300/h8300.md | 31 ++++++++++++++++++++++++++++++- 4 files changed, 78 insertions(+), 2 deletions(-) (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index e762668..99cb082 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2003-01-02 Kazu Hirata + + * config/h8300/h8300.c (stack_pointer_operand): New. + (const_int_gt_2_operand): Likewise. + (const_int_ge_8_operand): Likewise. + * config/h8300/h8300.md (a splitter): Likewise. + (a peephole2): Likewise. + * config/h8300/h8300-protos.h: Add prototypes for the new + functions above. + 2003-01-02 Steven Bosscher * objc/Make-lang.in, objc/config-lang.in, objc/lang-specs.h, diff --git a/gcc/config/h8300/h8300-protos.h b/gcc/config/h8300/h8300-protos.h index f324237..0aa2315 100644 --- a/gcc/config/h8300/h8300-protos.h +++ b/gcc/config/h8300/h8300-protos.h @@ -1,6 +1,6 @@ /* Definitions of target machine for GNU compiler. Hitachi H8/300 version generating coff - Copyright (C) 2000, 2002 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc. Contributed by Steve Chamberlain (sac@cygnus.com), Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com). @@ -62,8 +62,11 @@ extern int small_call_insn_operand PARAMS ((rtx, enum machine_mode)); extern int jump_address_operand PARAMS ((rtx, enum machine_mode)); extern int bit_operand PARAMS ((rtx, enum machine_mode)); extern int bit_memory_operand PARAMS ((rtx, enum machine_mode)); +extern int stack_pointer_operand PARAMS ((rtx, enum machine_mode)); extern int const_int_le_2_operand PARAMS ((rtx, enum machine_mode)); extern int const_int_le_6_operand PARAMS ((rtx, enum machine_mode)); +extern int const_int_gt_2_operand PARAMS ((rtx, enum machine_mode)); +extern int const_int_ge_8_operand PARAMS ((rtx, enum machine_mode)); extern int const_int_qi_operand PARAMS ((rtx, enum machine_mode)); extern int const_int_hi_operand PARAMS ((rtx, enum machine_mode)); extern int incdec_operand PARAMS ((rtx, enum machine_mode)); diff --git a/gcc/config/h8300/h8300.c b/gcc/config/h8300/h8300.c index 4313143..7da1780 100644 --- a/gcc/config/h8300/h8300.c +++ b/gcc/config/h8300/h8300.c @@ -1827,6 +1827,16 @@ notice_update_cc (body, insn) } } +/* Return nonzero if X is a stack pointer. */ + +int +stack_pointer_operand (x, mode) + rtx x; + enum machine_mode mode ATTRIBUTE_UNUSED; +{ + return x == stack_pointer_rtx; +} + /* Return nonzero if X is a constant whose absolute value is no greater than 2. */ @@ -1851,6 +1861,30 @@ const_int_le_6_operand (x, mode) && abs (INTVAL (x)) <= 6); } +/* Return nonzero if X is a constant whose absolute value is greater + than 2. */ + +int +const_int_gt_2_operand (x, mode) + rtx x; + enum machine_mode mode ATTRIBUTE_UNUSED; +{ + return (GET_CODE (x) == CONST_INT + && abs (INTVAL (x)) > 2); +} + +/* Return nonzero if X is a constant whose absolute value is no + smaller than 8. */ + +int +const_int_ge_8_operand (x, mode) + rtx x; + enum machine_mode mode ATTRIBUTE_UNUSED; +{ + return (GET_CODE (x) == CONST_INT + && abs (INTVAL (x)) >= 8); +} + /* Return nonzero if X is a constant expressible in QImode. */ int diff --git a/gcc/config/h8300/h8300.md b/gcc/config/h8300/h8300.md index cce5181..70b9858 100644 --- a/gcc/config/h8300/h8300.md +++ b/gcc/config/h8300/h8300.md @@ -1,6 +1,6 @@ ;; GCC machine description for Hitachi H8/300 ;; Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -;; 2001, 2002 Free Software Foundation, Inc. +;; 2001, 2002, 2003 Free Software Foundation, Inc. ;; Contributed by Steve Chamberlain (sac@cygnus.com), ;; Jim Wilson (wilson@cygnus.com), and Doug Evans (dje@cygnus.com). @@ -783,6 +783,35 @@ [(set_attr "length" "2,2,2,4,2") (set_attr "cc" "none_0hit,none_0hit,clobber,clobber,set_zn")]) +;; This splitter is very important to make the stack adjustment +;; interrupt-safe. The combination of add.b and addx is unsafe! +;; +;; We apply this split after the peephole2 pass so that we won't end +;; up creating too many adds/subs when a scratch register is +;; available, which is actually a common case because stack unrolling +;; tends to happen immediately after a function call. + +(define_split + [(set (match_operand:HI 0 "stack_pointer_operand" "") + (plus:HI (match_dup 0) + (match_operand 1 "const_int_gt_2_operand" "")))] + "TARGET_H8300 && flow2_completed" + [(const_int 0)] + "split_adds_subs (HImode, operands, 0); DONE;") + +(define_peephole2 + [(match_scratch:HI 2 "r") + (set (match_operand:HI 0 "stack_pointer_operand" "") + (plus:HI (match_dup 0) + (match_operand:HI 1 "const_int_ge_8_operand" "")))] + "TARGET_H8300" + [(set (match_dup 2) + (match_dup 1)) + (set (match_dup 0) + (plus:HI (match_dup 0) + (match_dup 2)))] + "") + (define_insn "*addhi3_h8300hs" [(set (match_operand:HI 0 "register_operand" "=r,r,r,r,r") (plus:HI (match_operand:HI 1 "register_operand" "%0,0,0,0,0") -- cgit v1.1