2 days ago

Is implementing a clang style @target_clones capability for LDC a big ask?

@target_clones only works on a per-function basis within a single CPU family currently but can easily be employed in modules intended for multi CPU family use by selecting the @target_clones string from within version(CPU_family_predefine) statements. This might be useful for the front end, runtime, and Phobos as well as to code written with auto vectorization in mind.

There are manual workarounds and extensions, such as library versioning with eager or late (LTO) target binding, so it might not be worth more than a modest effort but I thought I'd ask.

2 days ago

On Sunday, 13 April 2025 at 18:09:03 UTC, Bruce Carneal wrote:

>

Is implementing a clang style @target_clones capability for LDC a big ask?

Yes I believe this is a lot of work.
Generating multiple functions out of the same source with different target settings is probably fairly easy (if not trivial). The problem is generating the ifunc resolver function. I looked into this when @target was added. It is unfortunate that the ifunc resolver function code (with all the complexity of which target attribute should be tested first) is all in clang library, not in LLVM library.
If one would want to implement it, my proposal would be to get into LLVM and convince clang/LLVM to move the target attribute and ifunc resolver code into the LLVM library, such that it can be used by more frontends than just clang.

-Johan