rsandifo-arm wrote:

> clang specifically diagnoses always_inline functions. So for example, say you 
> want to write something like:
> 
> ```
> #include <arm_sve.h>
> __attribute__((always_inline, target("+sve")))
> static inline void f(void* p) __arm_streaming_compatible {
>   *(svuint32_t*)p = svmul_m(svptrue_b32(), *(svuint32_t*)p, *(svuint32_t*)p);
> }
> //////////
> void g(void* p) __arm_streaming { f(p); }
> ```
> 
> Conceptually, this should be fine, but currently it's an error. (You can sort 
> of approximate it with an `#ifdef __ARM_FEATURE_SVE`, but that's pretty ugly.)

Yeah.  I think in GCC, the reason for the equivalent behaviour is that (a) the 
compiler assumes (without checking) that the contents really do require the 
given target and (b) the compiler doesn't support changes to the ISA within a 
function.  So the error is that the target mismatch caused inlining to fail, 
rather than that the mismatch occurred at all.

> But regardless of the diagnostics, if the user specifies "+sve" on a target 
> that doesn't actually have SVE, we could miscompile; for example, if you call 
> a versioned function, clang uses the features specified in the caller.

That's a good point.  I suppose it comes down to two fundamentally different 
use cases:

1. A function that can be called in either PSTATE.SM mode and “just work”.  
This is what `__arm_streaming_compatible` is currently supposed to provide.  
That is, what the function can do is determined by where the function can be 
called (which is anywhere).
2. A function that cannot be called with PSTATE.SM==0 on targets that have SME 
but not SVE.  That is, where the function can be called is determined by what 
the function can do.

Perhaps (2) could be called “streaming SVE functions”.  If the compiler is 
supposed to enforce the constraints, then the set of assumed streaming SVE 
features would need to be a property of the function type.

https://github.com/llvm/llvm-project/pull/92427
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to