Richard Osborne
2011-Feb-02 18:11 UTC
[LLVMdev] Implementing platform specific library call simplification
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. 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? Thanks, Richard -- Richard Osborne | XMOS http://www.xmos.com
Chris Lattner
2011-Feb-13 08:24 UTC
[LLVMdev] Implementing platform specific library call simplification
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. -Chris
NAKAMURA Takumi
2011-Feb-13 10:31 UTC
[LLVMdev] Implementing platform specific library call simplification
Chris and all, IMHO I think SimplifyLibcall and similar might be provided by rather clang (and frontends), than LLVM itself. Frontends might know better than LLVM (as backend infrastructure). ...Takumi
Chris Lattner
2011-Feb-24 07:21 UTC
[LLVMdev] Implementing platform specific library call simplification
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
Possibly Parallel Threads
- [LLVMdev] Implementing platform specific library call simplification
- [LLVMdev] Implementing platform specific library call simplification
- [LLVMdev] Implementing platform specific library call simplification
- [LLVMdev] Implementing platform specific library call simplification
- [RFC] Canonicalize libcalls to intrinsics