<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Oct 6, 2014 at 7:18 AM, Zach Davis <span dir="ltr"><<a href="mailto:zdavkeos@gmail.com" target="_blank">zdavkeos@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">>> Hi,<br>>><br>>> Recently I have started writing a preprocessor that wraps the C<br>>> preprocessor for optimizing calls to sprintf, since it is the one of the<br>>> bottlenecks of my application.<br>>> <a href="https://github.com/kazuho/qrintf" target="_blank">https://github.com/kazuho/qrintf</a><br>>><br>>> For GCC, it was easy for me to override the default C preprocessor, by<br>>> using its `-no-integrated-cpp` and `-wrapper` options (how I have done it<br>>> can be found in the `qrinf-gcc` and `qrintf-gcc-wrapper` files included in<br>>> the above repository).<br>>><br>>> However I have so far been unable to find a similar command-line option<br>>> for Clang.  Is there any way to post-process the output of the preprocessor<br>>> in Clang?  Or do I need to modify the source code of Clang itself?<br>>><br>>> Thank you in advance.<br>>><br>>> PS. BTW it would be great if compile-time optimization of sprintf goes<br>>> into Clang.  Is there any chance of such possibility?<br>>><br>><br>> In the general case, it's not possible to optimize sprintf fully, because<br>> its behavior depends on the current locale (this affects %d and %u, which<br>> it looks like you optimize) and it might have libc-specific extensions, but<br>> LLVM does optimize in some simple cases: for instance, a sprintf containing<br>> no % is optimized into memcpy. I expect patches would be accepted to<br>> implement further cases, such as handling %s and %c.<br><br> ...for instance, a sprintf containing no % is optimized into memcpy...<br><br>Could you point out where this happens? I'm not having any luck finding it.</div></blockquote><div><br></div><div>lib/Transforms/Utils/SimplifyLibCalls.cpp; search for optimizeSPrintF.</div></div></div></div>