From fadd991f87dbd5752e9b6a2cce300dfe7cc8af25 Mon Sep 17 00:00:00 2001
From: Chen Gang <gang.chen.5...@gmail.com>
Date: Sun, 11 Oct 2015 22:59:35 +0800
Subject: [PATCH] gcc/ira.c: Check !HAVE_FP_INSTEAD_INSNS when frame pointer is 
needed and as global register

For some architectures (e.g. bfin), when this case occurs, they will use
another instructions instead of frame pointer (e.g. LINK for bfin), so
they can still generate correct output assembly code.

2015-10-11  Chen Gang  <gang.chen.5...@gmail.com>

        gcc/
        * config.in: Add HAVE_FP_INSTEAD_INSNS.
        * configure: Check HAVE_FP_INSTEAD_INSNS to set 0 or 1.
        * ira.c: Check !HAVE_FP_INSTEAD_INSNS when frame pointer is
        needed and as global register.
---
 gcc/config.in |  5 +++++
 gcc/configure | 18 ++++++++++++++++++
 gcc/ira.c     |  3 ++-
 3 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/gcc/config.in b/gcc/config.in
index 093478c..97f5957 100644
--- a/gcc/config.in
+++ b/gcc/config.in
@@ -1154,6 +1154,11 @@
 #undef HAVE_FWRITE_UNLOCKED
 #endif
 
+/* Define 0/1 if your machine supports frame pointer instead instructions. */
+#ifndef USED_FOR_TARGET
+#undef HAVE_FP_INSTEAD_INSNS
+#endif
+
 
 /* Define if your assembler supports specifying the alignment of objects
    allocated using the GAS .comm command. */
diff --git a/gcc/configure b/gcc/configure
index f6ae9906..a1aa430 100755
--- a/gcc/configure
+++ b/gcc/configure
@@ -22356,6 +22356,24 @@ fi
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_as_flags">&5
 $as_echo "$gcc_cv_as_flags">&6; }
 
+# Check if the target have frame pointer instead instructions
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking target frame pointer instead 
instructions">&5
+$as_echo_n "checking target frame pointer instead instructions...">&6; }
+case "$cpu_type" in
+  bfin)
+    gcc_cv_fp_instead="yes"
+    ;;
+  *)
+    gcc_cv_fp_instead="no"
+    ;;
+esac
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gcc_cv_fp_instead">&5
+$as_echo "$gcc_cv_fp_instead">&6; }
+
+cat>>confdefs.h <<_ACEOF
+#define HAVE_FP_INSTEAD_INSNS `if test $gcc_cv_fp_instead = yes; then echo 1; 
else echo 0; fi`
+_ACEOF
+
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking assembler for .balign and 
.p2align">&5
 $as_echo_n "checking assembler for .balign and .p2align... ">&6; }
 if test "${gcc_cv_as_balign_and_p2align+set}" = set; then :
diff --git a/gcc/ira.c b/gcc/ira.c
index 28517c1..998d11b 100644
--- a/gcc/ira.c
+++ b/gcc/ira.c
@@ -5471,7 +5471,8 @@ do_reload (void)
      register.  Often we can get away with letting the user appropriate
      the frame pointer, but we should let them know when code generation
      makes that impossible.  */
-  if (global_regs[HARD_FRAME_POINTER_REGNUM] && frame_pointer_needed)
+  if (global_regs[HARD_FRAME_POINTER_REGNUM] && frame_pointer_needed
+      && !HAVE_FP_INSTEAD_INSNS)
     {
       tree decl = global_regs_decl[HARD_FRAME_POINTER_REGNUM];
       error_at (DECL_SOURCE_LOCATION (current_function_decl),
-- 
1.9.3

                                          

Reply via email to