[libc-commits] [libc] [libc] Template the writing mode for the writer class (PR #111559)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Tue Oct 8 14:54:00 PDT 2024


michaelrj-google wrote:

I'm not a fan of templating the writer for basically the reasons described: It means that the converter code is duplicated for each printf variant, of which we currently have three but there may be more (see `syslog` and `dprintf`). Also, templating the converter just feels wrong to me since the converter isn't actually changing based on the template parameter.

That being said, I recognize that this is an important optimization for GPUs, so I have an alternate suggestion. Instead of templating the whole writer, only template `overflow_write`, then call it with a `switch` statement. This may seem like it's the same as before, but it has an important distinction: If we remove a `case` from the `switch` then that entire code path gets removed. Next, we add compile options to remove the `case`s that call the function pointer, and turn it on for GPUs, which makes it just a direct call.

Would that solution work for you?

https://github.com/llvm/llvm-project/pull/111559


More information about the libc-commits mailing list