public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Functions using attribute `noreturn'...
@ 2000-02-02 11:56 Ralf Guetlein
  2000-04-01  0:00 ` Ralf Guetlein
  0 siblings, 1 reply; 6+ messages in thread
From: Ralf Guetlein @ 2000-02-02 11:56 UTC (permalink / raw)
  To: gcc-help; +Cc: pmw

Paul wrote

>I'm currently in the process of porting GCC and am trying to optimise my code
>for function prologues and epilogues.

May we know what target you are working on?


>To minimise the amount of code output, I would like to check to see if the
>current function is declared with the __noreturn__ attribute. If it is, then
>I don't need to do output any of the function return code or save/restore any
>registers that otherwise would be.

Not exactly...

__attribute__((noreturn)) has 2 effects:

1) It allows the compiler to issue a warning if a 'noreturn' function
returns
   (the code is apparently erroneous)

2) If a function calls a function with attribute `noreturn' in the main
path,
   the compiler knows that the caller doesn't return either.

BUT:
The attribute `noreturn' is not involved in code generation directly.
Instead, the compiler is able to recognize if there is a return path or
not,
independently of the `noreturn' attribute (E.g. if there is an endless
loop).
You have to deal with that in your function_epilogue() in the target
support
file (target.c). Find out if the last non-note insn of the current
function
is a BARRIER (that means no path leads to the epilogue). If this is the
case,
you don't need to emit an epilogue.

Your code in function_epilogue() may look like this (see h8300.c or
m68k.c):

  /* If the last insn was a BARRIER, we don't have to write any code. 
*/
if (GET_CODE (insn) == NOTE)
  insn = prev_nonnote_insn (insn);
if (insn && GET_CODE (insn) == BARRIER)
  return;

>Is there any way I can find out whether the current function has been declared
>with this attribute? (Similarly, for other attributes, such as interrupt). This
>would be in the C support code, not in the machine description (.md) file. Is
>there a GCC support routine I can call, or is it more involved?


You have to distinguish: For your `noreturn' problem see the code
snippet above.
To recognize attributes, you may use code like the following
(also taken from h8300.c):

/* Return nonzero if FUNC is an interrupt function as specified
   by the "interrupt" attribute.  */

static int
h8300_interrupt_function_p (func)
     tree func;
{
  tree a;

  if (TREE_CODE (func) != FUNCTION_DECL)
    return 0;

  a = lookup_attribute ("interrupt_handler", DECL_MACHINE_ATTRIBUTES
(func));
  return a != NULL_TREE;
}

Enjoy,
Ralf

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Functions using attribute `noreturn'...
@ 2000-02-02  9:08 Paul Webster
  2000-02-02 14:23 ` Jeffrey A Law
  2000-04-01  0:00 ` Paul Webster
  0 siblings, 2 replies; 6+ messages in thread
From: Paul Webster @ 2000-02-02  9:08 UTC (permalink / raw)
  To: gcc-help

I'm currently in the process of porting GCC and am trying to optimise my code
for function prologues and epilogues.

To minimise the amount of code output, I would like to check to see if the
current function is declared with the __noreturn__ attribute. If it is, then
I don't need to do output any of the function return code or save/restore any
registers that otherwise would be.

Is there any way I can find out whether the current function has been declared
with this attribute? (Similarly, for other attributes, such as interrupt). This
would be in the C support code, not in the machine description (.md) file. Is
there a GCC support routine I can call, or is it more involved?

Thanks in advance for any help.

   Paul


==============================================================================
                          AT&T Laboratories Cambridge
------------------------------------------------------------------------------
    Dr. Paul Webster, 24a Trumpington Street, Cambridge, CB2 1QA, England.
    Tel: +44 (0)1223 343 218                       Fax: +44 (0)1223 313542
==============================================================================

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

end of thread, other threads:[~2000-04-01  0:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-02-02 11:56 Functions using attribute `noreturn' Ralf Guetlein
2000-04-01  0:00 ` Ralf Guetlein
  -- strict thread matches above, loose matches on Subject: below --
2000-02-02  9:08 Paul Webster
2000-02-02 14:23 ` Jeffrey A Law
2000-04-01  0:00   ` Jeffrey A Law
2000-04-01  0:00 ` Paul Webster

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