diff mbox

[1/5,ARC] Save/restore blink when in ISR.

Message ID 1490010210-9489-2-git-send-email-claziss@synopsys.com
State New
Headers show

Commit Message

Claudiu Zissulescu March 20, 2017, 11:43 a.m. UTC
BLIBK register needs to be saved/restored in a interrupt. Fix this issue.

gcc/
2016-09-21  Claudiu Zissulescu  <claziss@synopsys.com>

	* config/arc/arc.c (arc_epilogue_uses): BLINK should be also
	restored when in interrupt.
	* config/arc/arc.md (simple_return): ARCv2 rtie instruction
	doesn't have delay slot.

gcc/testsuite/
2016-09-21  Claudiu Zissulescu  <claziss@synopsys.com>

	* gcc.target/arc/interrupt-4.c: New file.
---
 gcc/config/arc/arc.c                       | 10 ++++++----
 gcc/config/arc/arc.md                      |  7 ++++++-
 gcc/testsuite/gcc.target/arc/interrupt-4.c | 15 +++++++++++++++
 3 files changed, 27 insertions(+), 5 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/arc/interrupt-4.c

Comments

Andrew Burgess March 24, 2017, 5:49 p.m. UTC | #1
* Claudiu Zissulescu <Claudiu.Zissulescu@synopsys.com> [2017-03-20 12:43:26 +0100]:

> BLIBK register needs to be saved/restored in a interrupt. Fix this issue.
> 
> gcc/
> 2016-09-21  Claudiu Zissulescu  <claziss@synopsys.com>
> 
> 	* config/arc/arc.c (arc_epilogue_uses): BLINK should be also
> 	restored when in interrupt.
> 	* config/arc/arc.md (simple_return): ARCv2 rtie instruction
> 	doesn't have delay slot.

Looks good thanks,
Andrew



> 
> gcc/testsuite/
> 2016-09-21  Claudiu Zissulescu  <claziss@synopsys.com>
> 
> 	* gcc.target/arc/interrupt-4.c: New file.
> ---
>  gcc/config/arc/arc.c                       | 10 ++++++----
>  gcc/config/arc/arc.md                      |  7 ++++++-
>  gcc/testsuite/gcc.target/arc/interrupt-4.c | 15 +++++++++++++++
>  3 files changed, 27 insertions(+), 5 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.target/arc/interrupt-4.c
> 
> diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
> index 556b587..50bfa11 100644
> --- a/gcc/config/arc/arc.c
> +++ b/gcc/config/arc/arc.c
> @@ -9513,9 +9513,10 @@ arc_can_follow_jump (const rtx_insn *follower, const rtx_insn *followee)
>     Return true if REGNO should be added to the deemed uses of the epilogue.
>  
>     We use the return address
> -   arc_return_address_regs[arc_compute_function_type (cfun)] .
> -   But also, we have to make sure all the register restore instructions
> -   are known to be live in interrupt functions.  */
> +   arc_return_address_regs[arc_compute_function_type (cfun)].  But
> +   also, we have to make sure all the register restore instructions
> +   are known to be live in interrupt functions, plus the blink
> +   register if it is clobbered by the isr.  */
>  
>  bool
>  arc_epilogue_uses (int regno)
> @@ -9528,7 +9529,8 @@ arc_epilogue_uses (int regno)
>  	{
>  	  if (!fixed_regs[regno])
>  	    return true;
> -	  return regno == arc_return_address_regs[cfun->machine->fn_type];
> +	  return ((regno == arc_return_address_regs[cfun->machine->fn_type])
> +		  || (regno == RETURN_ADDR_REGNUM));
>  	}
>        else
>  	return regno == RETURN_ADDR_REGNUM;
> diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
> index a06c2ed..b912bd4 100644
> --- a/gcc/config/arc/arc.md
> +++ b/gcc/config/arc/arc.md
> @@ -4748,7 +4748,12 @@
>    output_asm_insn (\"j%!%* [%0]%&\", &reg);
>    return \"\";
>  }
> -  [(set_attr "type" "return")
> +  [(set (attr "type")
> +	(cond [(and (eq (symbol_ref "arc_compute_function_type (cfun)")
> +			(symbol_ref "ARC_FUNCTION_ILINK1"))
> +		    (match_test "TARGET_V2"))
> +	       (const_string "brcc_no_delay_slot")]
> +	      (const_string "return")))
>     ; predicable won't help here since the canonical rtl looks different
>     ; for branches.
>     (set (attr "cond")
> diff --git a/gcc/testsuite/gcc.target/arc/interrupt-4.c b/gcc/testsuite/gcc.target/arc/interrupt-4.c
> new file mode 100644
> index 0000000..ea6596e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/arc/interrupt-4.c
> @@ -0,0 +1,15 @@
> +#if defined (__ARCHS__) || defined (__ARCEM__)
> +#define RILINK "ilink"
> +#else
> +#define RILINK "ilink1"
> +#endif
> +
> +extern int gpio_int;
> +extern int read_reg (int);
> +
> +void __attribute__ ((interrupt(RILINK)))
> +isr_handler (void)
> +{
> +  gpio_int = read_reg (1);
> +}
> +/* { dg-final { scan-assembler-times "blink" 2 } } */
> -- 
> 1.9.1
>
diff mbox

Patch

diff --git a/gcc/config/arc/arc.c b/gcc/config/arc/arc.c
index 556b587..50bfa11 100644
--- a/gcc/config/arc/arc.c
+++ b/gcc/config/arc/arc.c
@@ -9513,9 +9513,10 @@  arc_can_follow_jump (const rtx_insn *follower, const rtx_insn *followee)
    Return true if REGNO should be added to the deemed uses of the epilogue.
 
    We use the return address
-   arc_return_address_regs[arc_compute_function_type (cfun)] .
-   But also, we have to make sure all the register restore instructions
-   are known to be live in interrupt functions.  */
+   arc_return_address_regs[arc_compute_function_type (cfun)].  But
+   also, we have to make sure all the register restore instructions
+   are known to be live in interrupt functions, plus the blink
+   register if it is clobbered by the isr.  */
 
 bool
 arc_epilogue_uses (int regno)
@@ -9528,7 +9529,8 @@  arc_epilogue_uses (int regno)
 	{
 	  if (!fixed_regs[regno])
 	    return true;
-	  return regno == arc_return_address_regs[cfun->machine->fn_type];
+	  return ((regno == arc_return_address_regs[cfun->machine->fn_type])
+		  || (regno == RETURN_ADDR_REGNUM));
 	}
       else
 	return regno == RETURN_ADDR_REGNUM;
diff --git a/gcc/config/arc/arc.md b/gcc/config/arc/arc.md
index a06c2ed..b912bd4 100644
--- a/gcc/config/arc/arc.md
+++ b/gcc/config/arc/arc.md
@@ -4748,7 +4748,12 @@ 
   output_asm_insn (\"j%!%* [%0]%&\", &reg);
   return \"\";
 }
-  [(set_attr "type" "return")
+  [(set (attr "type")
+	(cond [(and (eq (symbol_ref "arc_compute_function_type (cfun)")
+			(symbol_ref "ARC_FUNCTION_ILINK1"))
+		    (match_test "TARGET_V2"))
+	       (const_string "brcc_no_delay_slot")]
+	      (const_string "return")))
    ; predicable won't help here since the canonical rtl looks different
    ; for branches.
    (set (attr "cond")
diff --git a/gcc/testsuite/gcc.target/arc/interrupt-4.c b/gcc/testsuite/gcc.target/arc/interrupt-4.c
new file mode 100644
index 0000000..ea6596e
--- /dev/null
+++ b/gcc/testsuite/gcc.target/arc/interrupt-4.c
@@ -0,0 +1,15 @@ 
+#if defined (__ARCHS__) || defined (__ARCEM__)
+#define RILINK "ilink"
+#else
+#define RILINK "ilink1"
+#endif
+
+extern int gpio_int;
+extern int read_reg (int);
+
+void __attribute__ ((interrupt(RILINK)))
+isr_handler (void)
+{
+  gpio_int = read_reg (1);
+}
+/* { dg-final { scan-assembler-times "blink" 2 } } */