Adds a new `__builtin_vectorelements()` function which returns the number of elements for a given vector either at compile-time for fixed-sized vectors, e.g., created via `__attribute__((vector_size(N)))` or at runtime via a call to `@llvm.vscale.i32()` for scalable vectors, e.g., SVE or RISCV V. The new builtin follows a similar path as `sizeof()`, as it essentially does the same thing but for the number of elements in vector instead of the number of bytes. This allows us to re-use a lot of the existing logic to handle types etc. A small side addition is `Type::isSizelessVectorType()`, which we need to distinguish between sizeless vectors (SVE, RISCV V) and sizeless types (WASM). This is the [corresponding discussion](https://discourse.llvm.org/t/new-builtin-function-to-get-number-of-lanes-in-simd-vectors/73911).
18 lines
608 B
C
18 lines
608 B
C
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
|
|
|
typedef double vector4double __attribute__((__vector_size__(32)));
|
|
typedef float vector8float __attribute__((__vector_size__(32)));
|
|
|
|
vector8float foo1(vector4double x) {
|
|
return __builtin_convertvector(x, vector8float); // expected-error {{same number of elements}}
|
|
}
|
|
|
|
float foo2(vector4double x) {
|
|
return __builtin_convertvector(x, float); // expected-error {{second argument to __builtin_convertvector must be of vector type}}
|
|
}
|
|
|
|
vector8float foo3(double x) {
|
|
return __builtin_convertvector(x, vector8float); // expected-error {{must be a vector}}
|
|
}
|
|
|