Skip to content

Modular printf Implementation #146159

Open
Open
@mysterymath

Description

@mysterymath

This is a tracking issue for implemenation work for RFC: printf Code Size Optimization.

This would take the form of a new clang function attribute, modular_format(<modular_impl_fn>, <impl_name>, <aspects...>). This could only be applied to functions that also bear the format attribute. It would inform the compiler that it could redirect the call to the modular version of the function, so long as it emitted a reference to a symbol corresponding to each requested aspect that it could not prove is unused by the call.

The initial implementation would support only the float aspect, which is required by any call with a floating point argument. Later likely low hanging fruit would be fixed-point support and long-long support.

The symbols referenced take the form <impl_name>_<aspect>, which allows many different front-end functions to share the same implementation. For example, fprintf, and printf would both share the implementation name __printf, and either could emit the symbol __printf_float.

Information from the clang modular_format and format attributes would be forwarded to a LLVM IR attribute modular-format. This would allow a LLVM middle-end optimization to examine the call and the format string, rewrite the call, and emit references to the necessary aspects. Aspects would be referenced using a new reloc.none intrinsic for emitting BFD_RELOC_NONE relocs.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions