public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Preserve registers across function call (Re: CALL_USED_REGISTERS)
@ 2009-07-16  8:47 Makoto Fujiwara
  2009-07-16 15:26 ` Richard Henderson
  0 siblings, 1 reply; 3+ messages in thread
From: Makoto Fujiwara @ 2009-07-16  8:47 UTC (permalink / raw)
  To: gcc

  My name is Makoto Fujiwara, I am working a particular port
for private CPU (at the time being). The porting itself is
getting very well, I believe, say having more than 30,000 PASS
with testsuite. Although no execution available for that make check,
I am preparing gdb/sim based execution verification with separate
make check.

My question is: 

The (gccint) info says, 
-----------
If a register has 0 in `CALL_USED_REGISTERS',
 the compiler automatically saves it on function entry and
restores it on function exit, if the register is used within 
the function.
-----------
in the context attatched. ( I believe this info is with gcc-4.2.1)

But unfortunately, my port does not seem to work as described
above (no preserve code found at *.s output).  The port is
based on 4.2.1 for the moment. I know either cpu.h or cpu.md is 
wrong, but to trace the problem,

Could anyone suggest me which part of the src is taking care
of above save/restore processing ?  
  calls.c 
  function.c  -> expand_function_{start,end}()
  caller-save.c  -> save_call_clobbered_regs()
  reload1.c 
  or others ?
I believe it should be in function.c, but I can not figure out
which lines (function) to take care those things.
(or the explanation in info is obsolete ?)

Thanks in advance,
---
Makoto Fujiwara, 
Chiba, Japan, Narita Airport and Disneyland prefecture.

(attachment)
15.7.1 Basic Characteristics of Registers
-----------------------------------------

Registers have various characteristics.

 -- Macro: FIRST_PSEUDO_REGISTER
	...
 -- Macro: FIXED_REGISTERS
 	...    
 -- Macro: CALL_USED_REGISTERS
     Like `FIXED_REGISTERS' but has 1 for each register that is
     clobbered (in general) by function calls as well as for fixed
     registers.  This macro therefore identifies the registers that are
     not available for general allocation of values that must live
     across function calls.

     If a register has 0 in `CALL_USED_REGISTERS', the compiler
     automatically saves it on function entry and restores it on
     function exit, if the register is used within the function.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Preserve registers across function call (Re: CALL_USED_REGISTERS)
  2009-07-16  8:47 Preserve registers across function call (Re: CALL_USED_REGISTERS) Makoto Fujiwara
@ 2009-07-16 15:26 ` Richard Henderson
  2009-07-17  9:17   ` Makoto Fujiwara
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Henderson @ 2009-07-16 15:26 UTC (permalink / raw)
  To: Makoto Fujiwara; +Cc: gcc

On 07/16/2009 01:47 AM, Makoto Fujiwara wrote:
> Could anyone suggest me which part of the src is taking care
> of above save/restore processing ?
>    calls.c
>    function.c  ->  expand_function_{start,end}()
>    caller-save.c  ->  save_call_clobbered_regs()
>    reload1.c
>    or others ?
> I believe it should be in function.c, but I can not figure out
> which lines (function) to take care those things.
> (or the explanation in info is obsolete ?)

This saving and restoring is *not* handled in generic parts of the 
compiler.  It is handled by the prologue and epilogue patterns in your 
cpu.md file -- or, normally, by a functions in your cpu.c file, which is 
invoked by the md patterns.

Look at gcc/config/moxie/moxie.c, moxie_expand_prologue; that's probably 
the simplest port within gcc at present.


r~

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Preserve registers across function call (Re: CALL_USED_REGISTERS)
  2009-07-16 15:26 ` Richard Henderson
@ 2009-07-17  9:17   ` Makoto Fujiwara
  0 siblings, 0 replies; 3+ messages in thread
From: Makoto Fujiwara @ 2009-07-17  9:17 UTC (permalink / raw)
  To: gcc

Richard, thanks for great help,
I think it'been more than serveral weeks :-) to figure out why.
Now I am in good mood. thanks a lot, really appreciate.

The fragments of the code for mine is like follows.
(It is 4.2.1 based)

(save)

+  for (regno = 0; regno < FIRST_PSEUDO_REGISTER ; regno++)
+    {
+      if (!fixed_regs[regno] && regs_ever_live[regno] && !call_used_regs[regno])
+        {
+          insn = emit_insn (gen_pushqi (gen_rtx_REG (Pmode, regno)));
+          //      RTX_FRAME_RELATED_P (insn) = 1;
+        }
+    }

(restore)

+  for (regno = FIRST_PSEUDO_REGISTER ; regno-- > 0; ) {
+      if ((!fixed_regs[regno] )&& regs_ever_live[regno] && (!call_used_regs[regno])) {
+           insn = emit_insn (gen_popqi (gen_rtx_REG (QImode, regno)));
+           //      RTX_FRAME_RELATED_P (insn) = 1;
+         }
+  }

Why QImode ? Don't ask that for the moment, 
Thanks again,
---
Makoto Fujiwara, 
Chiba, Japan, Narita Airport and Disneyland prefecture.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-07-17  9:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-16  8:47 Preserve registers across function call (Re: CALL_USED_REGISTERS) Makoto Fujiwara
2009-07-16 15:26 ` Richard Henderson
2009-07-17  9:17   ` Makoto Fujiwara

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).