[LLVMdev] Implementing platform specific library call simplification

Chris Lattner clattner at apple.com
Wed Feb 23 23:21:40 PST 2011


On Feb 13, 2011, at 12:24 AM, Chris Lattner wrote:

> On Feb 2, 2011, at 10:11 AM, Richard Osborne wrote:
>> The newlib C library provides iprintf(), a restricted version of printf 
>> without support for floating-point formatting. I'd like to add an 
>> optimization which turns calls to printf() into calls to iprintf() if 
>> the format string has no floating point specifiers.
> 
> Cool, ok.  I can see how this would be very useful for a variety of embedded systems.
> 
>> At the moment I've got this working locally by adding code to the 
>> simplify-libcalls pass. However this will break on targets where 
>> iprintf() isn't available. Is there a sensible place to add information 
>> about which library functions are available for a particular target?
> 
> I'd suggest adding a bool argument (HasIPrintf) to the createSimplifyLibCallsPass function and the pass constructor.  Then clang (or whatever is setting up the pass manager) can query the appropriate target info to pass down this flag.
> 
> Longer term, I'd like to introduce a simple interface (via TargetRegistry) for exposing target libcall info.  This would be useful to eliminate the HAVE_FLOORF etc #defines in simplifylibcalls, which break cross compilation.

Hi Richard,

Just to close the loop on this, I went ahead and added a new llvm/Target/TargetLibraryInfo.h and added it to simplifylibcalls.  TargetLibraryInfo doesn't handle all the libcalls that SimplifyLibCalls handles yet, but it should provide a starting point for iprintf: just add an iprintf enum to TargetLibraryInfo and make your transformation predicated on TLI->has(LibFunc::iprintf).

It would be great to see this go into mainline,

-Chris





More information about the llvm-dev mailing list