h8300.c (stack_pointer_operand): New.
authorKazu Hirata <kazu@cs.umass.edu>
Thu, 2 Jan 2003 14:59:30 +0000 (14:59 +0000)
committerKazu Hirata <kazu@gcc.gnu.org>
Thu, 2 Jan 2003 14:59:30 +0000 (14:59 +0000)
* 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
gcc/config/h8300/h8300-protos.h
gcc/config/h8300/h8300.c
gcc/config/h8300/h8300.md

index e7626684028f342ece7ac234388b36e32c83f511..99cb08285080e4a0432bef09651d8c44c379d95f 100644 (file)
@@ -1,3 +1,13 @@
+2003-01-02  Kazu Hirata  <kazu@cs.umass.edu>
+
+       * 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 <s.bosscher@student.tudelft.nl>
 
        * objc/Make-lang.in, objc/config-lang.in, objc/lang-specs.h,
index f3242375cdd9f9048aa7a203e0a53c2fe62841a0..0aa2315aea1ec8d09e642bd2a223d84e9ae02fe6 100644 (file)
@@ -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));
index 4313143215bcf0ace5e11acf49e0147bd21fdad2..7da1780bbf92f257dd370ca3f59d8a785f180e85 100644 (file)
@@ -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
index cce5181ab117c1ead750abe74a32d0994d7ab3ce..70b98581293fa0f694e82162d2b0dedb01372eed 100644 (file)
@@ -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).
   [(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")