Hi, say I've a LLVM module with a call instruction. The called function is "pure", that is it has no side-effects at all. How can I communicate this to LLVM, so that the function call can be removed if the return value is never used? Thanks, Volodya
On Sun, 4 Jun 2006, Vladimir Prus wrote:> say I've a LLVM module with a call instruction. The called function is > "pure", that is it has no side-effects at all. How can I communicate this > to LLVM, so that the function call can be removed if the return value is > never used?There isn't a way to do this from the source code yet. However, if this is a standard library function, you can add it to the end of lib/Analysis/BasicAliasAnalysis.cpp. Search of "isspace". -Chris -- http://nondot.org/sabre/ http://llvm.org/
On Sun, 2006-06-04 at 11:49 -0500, Chris Lattner wrote:> On Sun, 4 Jun 2006, Vladimir Prus wrote: > > say I've a LLVM module with a call instruction. The called function is > > "pure", that is it has no side-effects at all. How can I communicate this > > to LLVM, so that the function call can be removed if the return value is > > never used? > > There isn't a way to do this from the source code yet. However, if this > is a standard library function, you can add it to the end of > lib/Analysis/BasicAliasAnalysis.cpp. Search of "isspace".That's a bit of a hack. Can we not deduce "pure" functions conservatively? Basically, anything that doesn't do any load or store outside of its parameters and no malloc or free? Maybe a few other constraints. Sounds fairly easy to deduce and might be useful for optimization. Reid. -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20060604/4d6d36dd/attachment.sig>
Chris Lattner wrote:> On Sun, 4 Jun 2006, Vladimir Prus wrote: >> say I've a LLVM module with a call instruction. The called function is >> "pure", that is it has no side-effects at all. How can I communicate this >> to LLVM, so that the function call can be removed if the return value is >> never used? > > There isn't a way to do this from the source code yet. However, if this > is a standard library function, you can add it to the end of > lib/Analysis/BasicAliasAnalysis.cpp. Search of "isspace".No, it's not a library function. Besides, what is "library" function? Do you mean libc as of specific revision ;-) It would be nicer to have a method to declare function as pure without modifying the code. - Volodya