This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Committed: "trap" for CRIS.


Implemented because the overhead of calling abort spills over
into the frame of the almost-never-calling function.

Tested cris-elf, committed.

gcc:

	* config/cris/cris.h (TARGET_HAS_BREAK, TARGET_TRAP_USING_BREAK8):
	New macros.
	* config/cris/cris.md ("trap"): Define, enabled for
	TARGET_TRAP_USING_BREAK8.
	* config/cris/cris.opt (mtrap-using-break8): New option.

gcc/testsuite:

	* gcc.target/cris/torture/trap-1.c,
	gcc.target/cris/torture/trap-2.c,
	gcc.target/cris/torture/trap-3.c,
	gcc.target/cris/torture/trap-v0.c,
	gcc.target/cris/torture/trap-v3.c: New tests.

diff --git gcc/config/cris/cris.h gcc/config/cris/cris.h
index 16b038d..c2475b5 100644
--- gcc/config/cris/cris.h
+++ gcc/config/cris/cris.h
@@ -302,9 +302,14 @@ extern int cris_cpu_version;
 
 #define TARGET_HAS_MUL_INSNS (cris_cpu_version >= CRIS_CPU_NG)
 #define TARGET_HAS_LZ (cris_cpu_version >= CRIS_CPU_ETRAX4)
+#define TARGET_HAS_BREAK (cris_cpu_version >= CRIS_CPU_ETRAX4)
 #define TARGET_HAS_SWAP (cris_cpu_version >= CRIS_CPU_SVINTO)
 #define TARGET_V32 (cris_cpu_version >= CRIS_CPU_V32)
 
+/* The "break" instruction was introduced with ETRAX 4.  */
+#define TARGET_TRAP_USING_BREAK8 \
+ (cris_trap_using_break8 == 2 ? TARGET_HAS_BREAK : cris_trap_using_break8)
+
 /* Node: Storage Layout */
 
 #define BITS_BIG_ENDIAN 0
diff --git gcc/config/cris/cris.md gcc/config/cris/cris.md
index 09ac8e5..0e4b62d 100644
--- gcc/config/cris/cris.md
+++ gcc/config/cris/cris.md
@@ -3944,6 +3944,14 @@
   ""
   "nop"
   [(set_attr "cc" "none")])
+
+;; Same as the gdb trap breakpoint, will cause a SIGTRAP for
+;; cris-linux* and crisv32-linux*, as intended.  Will work in
+;; freestanding environments with sufficient framework.
+(define_insn "trap"
+  [(trap_if (const_int 1) (const_int 8))]
+  "TARGET_TRAP_USING_BREAK8"
+  "break 8")
 
 ;; We need to stop accesses to the stack after the memory is
 ;; deallocated.  Unfortunately, reorg doesn't look at naked clobbers,
diff --git gcc/config/cris/cris.opt gcc/config/cris/cris.opt
index 07cf646..5c0136e 100644
--- gcc/config/cris/cris.opt
+++ gcc/config/cris/cris.opt
@@ -175,6 +175,10 @@ Target Report RejectNegative Joined Var(cris_max_stackframe_str)
 max-stackframe=
 Target Report RejectNegative Joined Undocumented Var(cris_max_stackframe_str)
 
+mtrap-using-break8
+Target Report Var(cris_trap_using_break8) Init(2)
+Emit traps as \"break 8\", default for CRIS v3 and up.  If disabled, calls to abort() are used.
+
 ; TARGET_SVINTO: Currently this just affects alignment.  FIXME:
 ; Redundant with TARGET_ALIGN_BY_32, or put machine stuff here?
 ; This and the others below could just as well be variables and

diff --git gcc/testsuite/gcc.target/cris/torture/trap-1.c gcc/testsuite/gcc.target/cris/torture/trap-1.c
new file mode 100644
index 0000000..48363fb
--- /dev/null
+++ gcc/testsuite/gcc.target/cris/torture/trap-1.c
@@ -0,0 +1,13 @@
+/* Check that "break 8" defaults according to CPU version.  */
+/* { dg-do compile } */
+/* { dg-skip-if "" { "*-*-*" } { "-march*" } { "" } } */
+/* { dg-final { scan-assembler "break 8" { target { ! cris-*-elf } } } } */
+/* { dg-final { scan-assembler-not "bsr" { target { ! cris-*-elf } } } } */
+/* { dg-final { scan-assembler-not "jsr" { target { ! cris-*-elf } } } } */
+/* { dg-final { scan-assembler-not "break\[ \t\]" { target cris-*-elf } } } */
+/* { dg-final { scan-assembler "\[jb\]sr \[_\]\?abort" { target cris-*-elf } } } */
+
+void do_trap (void)
+{
+  __builtin_trap ();
+}
diff --git gcc/testsuite/gcc.target/cris/torture/trap-2.c gcc/testsuite/gcc.target/cris/torture/trap-2.c
new file mode 100644
index 0000000..155d5fe
--- /dev/null
+++ gcc/testsuite/gcc.target/cris/torture/trap-2.c
@@ -0,0 +1,11 @@
+/* As trap-1.c but forcing on.  */
+/* { dg-do compile } */
+/* { dg-options "-mtrap-using-break8" } */
+/* { dg-final { scan-assembler "break 8" } } */
+/* { dg-final { scan-assembler-not "bsr" } } */
+/* { dg-final { scan-assembler-not "jsr" } } */
+
+void do_trap (void)
+{
+  __builtin_trap ();
+}
diff --git gcc/testsuite/gcc.target/cris/torture/trap-3.c gcc/testsuite/gcc.target/cris/torture/trap-3.c
new file mode 100644
index 0000000..dfa0924
--- /dev/null
+++ gcc/testsuite/gcc.target/cris/torture/trap-3.c
@@ -0,0 +1,10 @@
+/* Like trap-1.c and trap-2.c but force calls to abort.  */
+/* { dg-do compile } */
+/* { dg-options "-mno-trap-using-break8" } */
+/* { dg-final { scan-assembler-not "break\[ \t\]" } } */
+/* { dg-final { scan-assembler "\[jb\]sr \[_\]\?abort" } } */
+
+void do_trap (void)
+{
+  __builtin_trap ();
+}
diff --git gcc/testsuite/gcc.target/cris/torture/trap-v0.c gcc/testsuite/gcc.target/cris/torture/trap-v0.c
new file mode 100644
index 0000000..084fb28
--- /dev/null
+++ gcc/testsuite/gcc.target/cris/torture/trap-v0.c
@@ -0,0 +1,11 @@
+/* As trap-1.c but with CPU version specified, excluding.  */
+/* { dg-do compile } */
+/* { dg-skip-if "" { "*-*-*" } { "-march=*" } { "" } } */
+/* { dg-options "-march=v0" } */
+/* { dg-final { scan-assembler-not "break\[ \t\]" } } */
+/* { dg-final { scan-assembler "\[jb\]sr \[_\]\?abort" } } */
+
+void do_trap (void)
+{
+  __builtin_trap ();
+}
diff --git gcc/testsuite/gcc.target/cris/torture/trap-v3.c gcc/testsuite/gcc.target/cris/torture/trap-v3.c
new file mode 100644
index 0000000..e004c5b
--- /dev/null
+++ gcc/testsuite/gcc.target/cris/torture/trap-v3.c
@@ -0,0 +1,12 @@
+/* As trap-1.c but with CPU version specified, including.  */
+/* { dg-do compile } */
+/* { dg-skip-if "" { "*-*-*" } { "-march=*" } { "" } } */
+/* { dg-options "-march=v3" } */
+/* { dg-final { scan-assembler "break 8" } } */
+/* { dg-final { scan-assembler-not "bsr" } } */
+/* { dg-final { scan-assembler-not "jsr" } } */
+
+void do_trap (void)
+{
+  __builtin_trap ();
+}

brgds, H-P


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]