mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-24 21:56:04 +00:00

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).
24 lines
977 B
C
24 lines
977 B
C
// RUN: %clang_cc1 -triple aarch64 -fsyntax-only -verify -disable-llvm-passes %s
|
|
|
|
void test_builtin_vectorelements() {
|
|
__builtin_vectorelements(int); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
|
|
__builtin_vectorelements(float); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
|
|
__builtin_vectorelements(long*); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
|
|
|
|
int a;
|
|
__builtin_vectorelements(a); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
|
|
|
|
typedef int veci4 __attribute__((vector_size(16)));
|
|
(void) __builtin_vectorelements(veci4);
|
|
|
|
veci4 vec;
|
|
(void) __builtin_vectorelements(vec);
|
|
|
|
typedef veci4 some_other_vec;
|
|
(void) __builtin_vectorelements(some_other_vec);
|
|
|
|
struct Foo { int a; };
|
|
__builtin_vectorelements(struct Foo); // expected-error {{argument to __builtin_vectorelements must be of vector type}}
|
|
}
|
|
|