diff options
author | Lawrence Benson <github@lawben.com> | 2023-10-19 10:45:08 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-19 10:45:08 +0200 |
commit | de65b6bec6771fe50f3aa73fdb79594f675be456 (patch) | |
tree | 1495aadc56a0816cebc7260ff0082efb7df30b13 /clang/lib/Sema/SemaChecking.cpp | |
parent | 9ea2fd245739fe7d8f49014f90d2311387bf7682 (diff) | |
download | llvm-de65b6bec6771fe50f3aa73fdb79594f675be456.zip llvm-de65b6bec6771fe50f3aa73fdb79594f675be456.tar.gz llvm-de65b6bec6771fe50f3aa73fdb79594f675be456.tar.bz2 |
[Clang] Add __builtin_vectorelements to get number of elements in vector (#69010)
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).
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index cd7c26a..f3c55d0 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -8752,8 +8752,9 @@ ExprResult Sema::SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo, diag::err_convertvector_non_vector) << E->getSourceRange()); if (!DstTy->isVectorType() && !DstTy->isDependentType()) - return ExprError(Diag(BuiltinLoc, - diag::err_convertvector_non_vector_type)); + return ExprError(Diag(BuiltinLoc, diag::err_builtin_non_vector_type) + << "second" + << "__builtin_convertvector"); if (!SrcTy->isDependentType() && !DstTy->isDependentType()) { unsigned SrcElts = SrcTy->castAs<VectorType>()->getNumElements(); |