SME streaming status overloading
We should have an overloading mechanism that dispatches to normal vs streaming implementations of a function at runtime based on the current streaming mode. As an optimization, we could set up dispatch to always call the matching implementation in a normal/streaming caller. In streaming-compatible callers, we'd have to inspect the streaming mode via the compiler-rt builtin.
Use case for this could be to provide a memcpy implementation that keeps the streaming mode active or inactive, and uses the corresponding instructions without a streaming mode change.
cc @sdesmalen-arm, @rsandifo-arm, @aemerson for SME bits cc @labrinea, as this is kind of FMV-adjacent
breadcrumb for myself: rdar://116990507
Currently, you can write something like the following. This dispatches as appropriate. It currently doesn't optimize well, but that's something we could fix. Given that, what benefit does a dedicated "overloading" feature provide?
void f_streaming() __arm_streaming;
void f_nonstreaming();
inline void f() __arm_streaming_compatible {
if (__arm_in_streaming_mode())
f_streaming();
else
f_nonstreaming();
}
(Also, I'm skeptical you'd want to use this for memcpy(); small memcpys only use streaming-compatible instructions anyway, so it's cheaper to check the size before checking whether streaming mode is enabled.)
I was thinking perhaps by comparing the caller/callee streaming attributes one could statically determine which version to call? Would that work? My patch https://github.com/llvm/llvm-project/pull/87939 compares target-features between caller and callee to achieve something similar. However, using FMV for SME streaming status overloading seems like a workaround to me. The streaming/non-streaming versions will have a dummy feature list in the attribute string and none of this information will actually be used for runtime dispatch.
How is that better than just writing it out like https://github.com/llvm/llvm-project/issues/100200#issuecomment-2246454338 ?
How is that better than just writing it out like #100200 (comment) ?
It's not. Exactly the point I was trying to make.
@labrinea I think it is impossible to use current form of FMV for the overloading of functions with different streaming attributes, as my understanding is that FMV resolves only once what version should be called at runtime, while with streaming functions it depends in the state of the program, so you would need to resolve it every time before calling a function.
@labrinea I think it is impossible to use current form of FMV for the overloading of functions with different streaming attributes, as my understanding is that FMV resolves only once what version should be called at runtime, while with streaming functions it depends in the state of the program, so you would need to resolve it every time before calling a function.
Hi Maciej. If you read my comment above I was explaining that FMV cannot do runtime dispatch based on streaming attributes, but we could create dummy FMV versions and then statically determine which version to call (never going through the ifunc resolver) based on streaming attribute comparison. As Eli highlighted this is worse than his snippet and I agree. We don't need FMV for this IMO.