[llvm-commits] annotate known function declarations in SimplifyLibCalls pass

Nick Lewycky nicholas at mxc.ca
Thu Jan 1 17:49:33 PST 2009


This patch modifies SimplifyLibCalls to run a post-pass that adds 
attributes to many well-known functions. I'm sending this out for review 
because there's a lot of decisions I made that should be checked before 
the commit:

a) The choice of functions annotated. I tried to include only C99 and 
popular POSIX functions that don't already get all of their annotations 
from headers when used in llvm-gcc. This includes for example, 
'nocapture' on the FILE* going into functions like fseek or fclose. I 
also include the "largefile" extensions such as fseeko, etc.

Additionally, some functions can be created by the simplify-libcalls 
pass itself. Instead of annotating them at the point of creation, I just 
annotate them in doFinalization even though the annotations don't 
include nocapture.

There may be large categories of functions that I missed. Please let me 
know.

b) The annotations included. It sets readonly/readnone, nounwind and the 
appropriate nocapture, but not noalias. My thinking was that if we've 
matched the function we may as well add all the other attributes while 
we're at it. I'm not entirely sure if it would be safe for me to pick my 
own llvm-gcc's output and copy the noalias's seen there, so it doesn't 
add any noalias bits on parameters.

I do mark noalias on return in a few places, malloc, calloc, realloc 
(which is also nocapture!) as well as fopen and fdopen. For fopen and 
fdopen, I know that file handles can be seeked to different places 
individually, even when the same file is opened twice with the same 
permissions, so I conclude that it's impossible for fopen to return the 
same FILE* twice.

c) The way function names are matched. This is a copy of the logic in 
SelectionDAGBuild.cpp. We could probably do a much better job here and 
share more code. There's a distressing amount of copy-pasting as it's 
currently written.

Thanks,
Nick

-------------- next part --------------
A non-text attachment was scrubbed...
Name: annotate-libcalls.patch
Type: text/x-patch
Size: 17718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20090101/b09aa307/attachment.bin>


More information about the llvm-commits mailing list