public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ralf Guetlein <ralf.guetlein@aranea.de>
To: gcc-help@gcc.gnu.org
Cc: pmw@uk.research.att.com
Subject: Re: Functions using attribute `noreturn'...
Date: Sat, 01 Apr 2000 00:00:00 -0000	[thread overview]
Message-ID: <38988C3C.636FCE9D@aranea.de> (raw)
Message-ID: <20000401000000.m62G7QKyP3YGbXGf4COK3V-1OX3oj_pzj7nxsmWBq5c@z> (raw)

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

             reply	other threads:[~2000-04-01  0:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-02-02 11:56 Ralf Guetlein [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=38988C3C.636FCE9D@aranea.de \
    --to=ralf.guetlein@aranea.de \
    --cc=gcc-help@gcc.gnu.org \
    --cc=pmw@uk.research.att.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).