From patchwork Tue May 29 02:02:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 161649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id EE7EBB6EF1 for ; Tue, 29 May 2012 12:02:48 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1338861770; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:Date:Message-Id:From:To: Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=5fPAazxfy1LfPIchLx6c i+HfOMc=; b=RWVrC/+4S0rXO8e8OqY/J0pk0eSQEYE6qYCcrsarWav3jGAolvb3 6HfHHi17TK80RpUnKiUli9wa1SWycd270QNPUdSaMqj8RUuaaB6oL8vu9KjJ5kwy S4jJyiGBkKZt1P3BGO1wrHjysuVJIhw7ENB1M/Z/qEB/JhK3Wadz/UY= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Received:Received:Date:Message-Id:From:To:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=vplZUxvzPOUPshrcww60DopXZqCsqh/ycUyQVW4CgoulMdGbFhy7hA/f62f8o5 6nWH1zSu0d2Ogw5i+Ljj1+q0i9WVkVYO4BIsOHOHvuIE4A2m2Cjf0lgr5fk5/vRe DtgmC8bHw+EW1MIglrMDdKUOrYbF+cLcXmOAP9KqYMMeU=; Received: (qmail 22091 invoked by alias); 29 May 2012 02:02:42 -0000 Received: (qmail 22071 invoked by uid 22791); 29 May 2012 02:02:38 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL, BAYES_00, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from anubis.se.axis.com (HELO anubis.se.axis.com) (195.60.68.12) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 29 May 2012 02:02:24 +0000 Received: from localhost (localhost [127.0.0.1]) by anubis.se.axis.com (Postfix) with ESMTP id CD16719D81 for ; Tue, 29 May 2012 04:02:20 +0200 (CEST) Received: from anubis.se.axis.com ([127.0.0.1]) by localhost (anubis.se.axis.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 75BmQf1dWd4g for ; Tue, 29 May 2012 04:02:19 +0200 (CEST) Received: from thoth.se.axis.com (thoth.se.axis.com [10.0.2.173]) by anubis.se.axis.com (Postfix) with ESMTP id 20C9619D13 for ; Tue, 29 May 2012 04:02:19 +0200 (CEST) Received: from ignucius.se.axis.com (ignucius.se.axis.com [10.88.21.50]) by thoth.se.axis.com (Postfix) with ESMTP id 0E7C834088; Tue, 29 May 2012 04:02:19 +0200 (CEST) Received: from ignucius.se.axis.com (localhost [127.0.0.1]) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) with ESMTP id q4T22Imt013051; Tue, 29 May 2012 04:02:18 +0200 Received: (from hp@localhost) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) id q4T22Is9013047; Tue, 29 May 2012 04:02:18 +0200 Date: Tue, 29 May 2012 04:02:18 +0200 Message-Id: <201205290202.q4T22Is9013047@ignucius.se.axis.com> From: Hans-Peter Nilsson To: gcc-patches@gcc.gnu.org Subject: Committed: "trap" for CRIS. MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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. brgds, H-P 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 (); +}