This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
expected_retval attribute proposal
- To: egcs at egcs dot cygnus dot com, libc-hacker at sourceware dot cygnus dot com
- Subject: expected_retval attribute proposal
- From: Jan Hubicka <jh at suse dot cz>
- Date: Wed, 10 May 2000 11:03:44 +0200
Hi
One of the bits that may help somewhat to static branch prediction pass
in gcc is the knowedge that given function is returning some value
to signalize error and that error is unlikely to happen. This is
common for number of functions, so I think it may be profitable to add
attribute expected_retval (and probably also inexpected_retval)
so such functions can be marked in the glibc headers.
For example fputc can de marked as:
int fpuc (int c, FILE *stream) __attribute__ ((__inexpected_retval (EOF)));
What do you think? I basically see following drawbacks:
1) gcc already contain some generic heruistics taking such error values
into mind (such as comparing pointer against NULL).
2) it is kludge and will make glibc headers less readable
3) there are certainly places in the program where given call (feof)
fails more often than in the average case
and return value heruistics will not work well.
But still I think this is interesting bit that may improve program performance
somewhat with no extra effort from final user. Basically I am more firend of
idea of doing interprocedural analysis in gcc instead of adding such
attributes everywhere, but even with such analysis we will probably not
able to handle glibc...
Ideas? If this turns out to be acceptable hack, I will implement the gcc
part. (well and glibc part to if neccesary...)
Honya