public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* CALL_USED_REGISTERS per function basis
@ 2010-08-05 16:51 Claudiu Zissulescu
  2010-08-05 18:58 ` Richard Henderson
  2010-08-18 20:03 ` Michael Meissner
  0 siblings, 2 replies; 8+ messages in thread
From: Claudiu Zissulescu @ 2010-08-05 16:51 UTC (permalink / raw)
  To: gcc

Hi,

I want to use a different CALL_USED_REGISTER set per individual
function. The issue here is to inform a caller about the callee
CALL_USED_REGISTERS and save/restore at caller level the possible
altered registers.  This should reduce the number of saved/restored
operation in a function.

Can someone give me some pointers in this direction?

Thank you,
Claudiu

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

* Re: CALL_USED_REGISTERS per function basis
  2010-08-05 16:51 CALL_USED_REGISTERS per function basis Claudiu Zissulescu
@ 2010-08-05 18:58 ` Richard Henderson
  2010-08-09 17:39   ` Claudiu Zissulescu
  2010-08-18 20:03 ` Michael Meissner
  1 sibling, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2010-08-05 18:58 UTC (permalink / raw)
  To: Claudiu Zissulescu; +Cc: gcc

On 08/05/2010 06:48 AM, Claudiu Zissulescu wrote:
> I want to use a different CALL_USED_REGISTER set per individual
> function. The issue here is to inform a caller about the callee
> CALL_USED_REGISTERS and save/restore at caller level the possible
> altered registers.  This should reduce the number of saved/restored
> operation in a function.
> 
> Can someone give me some pointers in this direction?

A sketch of the idea:

In struct cgraph_local_info, add a HARD_REG_SET with the call-used
register set for that function.  It is initialized to the ABI.

In the various appropriate places, caller-save.c, ira-*.c, reload1.c,
sel-sched.c, and replace the bare uses of the target_hard_regs sets
with calls to something like

  HARD_REG_SET get_call_used_reg_set (const_rtx call_insn);
  HARD_REG_SET get_regs_invalidated_by_call (const_rtx call_insn);

which digs into the actual call to find the symbol_ref, and from
there to the SYMBOL_REF_DECL, to the cgraph node from whence you
can return the saved register set.  If any of that fails, you 
must return the ABI set.

At the end of compilation for a function, iterate over the function
to see what's really changed.  The set of call-clobbered registers
that might be used can change right up until at least machine_reorg.
Of course one must OR in the sets used by any callees.  Store this
collected register set back into cgraph_local_info that it may be
used during the compilation of the function's callers.

Given that cgraph has already performed a topological sort on the
set of functions to be emitted, you should in this way be able to
collect the call-used register set of most functions before they
are used by their callers.  The case of cycles is handled by assuming
the worst by the initialization to the ABI call-used set.


r~


PS: Bonus points for adding an __attribute__((call_used(register-set)))
to allow programmers to describe the behaviour of hand-written 
assembly, or force the function to save more registers in its
prologue.  The later, of course, means having to adjust the prologue
and epilogue code the target(s) you care about.  One can support
this feature without adjusting the target merely be restricting this
to hand-written assembly.  Detect this by generating an error if the
attribute is used with a function that has a body and is not merely
a declaration.

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

* Re: CALL_USED_REGISTERS per function basis
  2010-08-05 18:58 ` Richard Henderson
@ 2010-08-09 17:39   ` Claudiu Zissulescu
  2010-08-09 23:49     ` Richard Henderson
  0 siblings, 1 reply; 8+ messages in thread
From: Claudiu Zissulescu @ 2010-08-09 17:39 UTC (permalink / raw)
  To: gcc

Hi,

I am thinking (as I am not familiar with IRA) to the following
alternative to your solution:

I set to zero all CALL_USED_REGISTERS (except the fixed regs), and
then in the expand_call I set CALL_INSN_FUNCTION_USAGE to the list of
clobbered registers (given by attribute attached to a function
declaration).  Then, I should be able to achieve the same effect
without touching the IRA.

Additionally, a global variable will hold the "default"
call_used_registers for the cases when the function call used regs
attribute is not set.

What do you think about this approach?

Best regards,
Claudiu

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

* Re: CALL_USED_REGISTERS per function basis
  2010-08-09 17:39   ` Claudiu Zissulescu
@ 2010-08-09 23:49     ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2010-08-09 23:49 UTC (permalink / raw)
  To: Claudiu Zissulescu; +Cc: gcc

On 08/09/2010 07:20 AM, Claudiu Zissulescu wrote:
> I set to zero all CALL_USED_REGISTERS (except the fixed regs), and
> then in the expand_call I set CALL_INSN_FUNCTION_USAGE to the list of
> clobbered registers (given by attribute attached to a function
> declaration).  Then, I should be able to achieve the same effect
> without touching the IRA.

CALL_INSN_FUNCTION_USAGE says nothing about what registers are clobbered,
only that they are *used* by the callee.  I.e. they are arguments, either
from the user via the declaration of the function or implicit via the ABI.

Note that in some ABIs, function arguments may be in call-saved registers.
Which implies that the register containing that function argument is 
unchanged after the call.

So I don't see that this is the same effect at all.


r~

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

* Re: CALL_USED_REGISTERS per function basis
  2010-08-05 16:51 CALL_USED_REGISTERS per function basis Claudiu Zissulescu
  2010-08-05 18:58 ` Richard Henderson
@ 2010-08-18 20:03 ` Michael Meissner
  2010-08-18 21:36   ` Richard Henderson
  1 sibling, 1 reply; 8+ messages in thread
From: Michael Meissner @ 2010-08-18 20:03 UTC (permalink / raw)
  To: Claudiu Zissulescu; +Cc: gcc

On Thu, Aug 05, 2010 at 03:48:55PM +0200, Claudiu Zissulescu wrote:
> Hi,
> 
> I want to use a different CALL_USED_REGISTER set per individual
> function. The issue here is to inform a caller about the callee
> CALL_USED_REGISTERS and save/restore at caller level the possible
> altered registers.  This should reduce the number of saved/restored
> operation in a function.
> 
> Can someone give me some pointers in this direction?

In the x86 they use TARGET_EXPAND_TO_RTL_HOOK which points to the
ix86_maybe_switch_abi function.

That function is:
/* MS and SYSV ABI have different set of call used registers.  Avoid expensive
   re-initialization of init_regs each time we switch function context since
   this is needed only during RTL expansion.  */
static void
ix86_maybe_switch_abi (void)
{
  if (TARGET_64BIT &&
      call_used_regs[SI_REG] == (cfun->machine->call_abi == MS_ABI))
    reinit_regs ();
}

Going beyond the above, about 2 years ago, I and another programmer wrote the
function specific support that allows you to use attributes and pragmas to say
a particular function is compiled with non-standard options.  My intention was
that you could declare one function normally, another with SSE2 support, and a
third with SSE4 support, and that at runtime you could switch to use the
function that supported the instruction set.  This was done via the
TARGET_SET_CURRENT_FUNCTION callback, which in the x86 case is
ix86_set_current_function.  This does the target_reinit and eventually
reinit_regs.

Now, unfortunately, I've been away from the code for about 2 years, and I don't
know whether it has bit-rotted or not.

-- 
Michael Meissner, IBM
5 Technology Place Drive, M/S 2757, Westford, MA 01886-3141, USA
meissner@linux.vnet.ibm.com

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

* Re: CALL_USED_REGISTERS per function basis
  2010-08-18 20:03 ` Michael Meissner
@ 2010-08-18 21:36   ` Richard Henderson
  2010-08-19 14:03     ` Michael Meissner
  0 siblings, 1 reply; 8+ messages in thread
From: Richard Henderson @ 2010-08-18 21:36 UTC (permalink / raw)
  To: Michael Meissner, Claudiu Zissulescu, gcc

On 08/18/2010 12:06 PM, Michael Meissner wrote:
> Now, unfortunately, I've been away from the code for about 2 years, and I don't
> know whether it has bit-rotted or not.

It hasn't.  In fact, the Vectorize _cpp_clean_line thread
contains a patch that uses it.  Not quite ready to commit,
but nearly.


r~

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

* Re: CALL_USED_REGISTERS per function basis
  2010-08-18 21:36   ` Richard Henderson
@ 2010-08-19 14:03     ` Michael Meissner
  2010-08-19 22:54       ` Richard Henderson
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Meissner @ 2010-08-19 14:03 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Michael Meissner, Claudiu Zissulescu, gcc

On Wed, Aug 18, 2010 at 12:56:47PM -0700, Richard Henderson wrote:
> On 08/18/2010 12:06 PM, Michael Meissner wrote:
> > Now, unfortunately, I've been away from the code for about 2 years, and I don't
> > know whether it has bit-rotted or not.
> 
> It hasn't.  In fact, the Vectorize _cpp_clean_line thread
> contains a patch that uses it.  Not quite ready to commit,
> but nearly.

Cool.  I've been hoping to get the decks cleared, and add the power support as
well.  It would be nice to do the later stages that I had thought about for fat
binaries.

-- 
Michael Meissner, IBM
5 Technology Place Drive, M/S 2757, Westford, MA 01886-3141, USA
meissner@linux.vnet.ibm.com

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

* Re: CALL_USED_REGISTERS per function basis
  2010-08-19 14:03     ` Michael Meissner
@ 2010-08-19 22:54       ` Richard Henderson
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Henderson @ 2010-08-19 22:54 UTC (permalink / raw)
  To: Michael Meissner, Claudiu Zissulescu, gcc

On 08/18/2010 01:02 PM, Michael Meissner wrote:
> Cool.  I've been hoping to get the decks cleared, and add the power support as
> well.

Adding ppc support would be Really Nice.  At the moment I
appear to be limited to #ifdef __ALTIVEC__.


r~

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

end of thread, other threads:[~2010-08-18 21:36 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-05 16:51 CALL_USED_REGISTERS per function basis Claudiu Zissulescu
2010-08-05 18:58 ` Richard Henderson
2010-08-09 17:39   ` Claudiu Zissulescu
2010-08-09 23:49     ` Richard Henderson
2010-08-18 20:03 ` Michael Meissner
2010-08-18 21:36   ` Richard Henderson
2010-08-19 14:03     ` Michael Meissner
2010-08-19 22:54       ` Richard Henderson

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).