-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] Add __builtin_vectorelements to get number of elements in vector #69010
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
df8d0a5
550f0ca
eb387d6
6e8f1f0
323c018
1acc0b5
bbc063b
f19e1de
8d78389
b1ff89a
2c51c60
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5126,6 +5126,14 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity, | |
Diags.Report(DiagID); | ||
return; | ||
} | ||
case UETT_VectorElements: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We probably need the equivilent here for the MicrosoftMangle.cpp as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know. But none of the other There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, SGTM at least, I just know this pattern of 'cannot yet mangle...' shows up primarily in the MicrosoftMangle, so figured it might need to be covered. There is some funny-business as to how much each mangles of expressions in template arguments. This gets me thinking further though,the constexprness of this likely means you may need to mangle this. I'm open if others are to letting it be done in a follow-up however. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @philnik777 I'm adding you here because of your recent commit that adds I'm happy to address this for |
||
DiagnosticsEngine &Diags = Context.getDiags(); | ||
unsigned DiagID = Diags.getCustomDiagID( | ||
DiagnosticsEngine::Error, | ||
"cannot yet mangle __builtin_vectorelements expression"); | ||
Diags.Report(DiagID); | ||
return; | ||
} | ||
} | ||
break; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// RUN: %clang_cc1 -O1 -triple aarch64 -target-feature +neon %s -emit-llvm -disable-llvm-passes -o - | FileCheck --check-prefixes=CHECK,NEON %s | ||
// RUN: %clang_cc1 -O1 -triple aarch64 -target-feature +sve %s -emit-llvm -disable-llvm-passes -o - | FileCheck --check-prefixes=CHECK,SVE %s | ||
// RUN: %clang_cc1 -O1 -triple riscv64 -target-feature +v %s -emit-llvm -disable-llvm-passes -o - | FileCheck --check-prefixes=CHECK,RISCV %s | ||
|
||
// Note that this does not make sense to check for x86 SIMD types, because | ||
// __m128i, __m256i, and __m512i do not specify the element type. There are no | ||
// "logical" number of elements in them. | ||
|
||
typedef int int1 __attribute__((vector_size(4))); | ||
typedef int int4 __attribute__((vector_size(16))); | ||
typedef int int8 __attribute__((vector_size(32))); | ||
typedef int int16 __attribute__((vector_size(64))); | ||
typedef float float2 __attribute__((vector_size(8))); | ||
typedef long extLong4 __attribute__((ext_vector_type(4))); | ||
|
||
|
||
int test_builtin_vectorelements_int1() { | ||
// CHECK-LABEL: i32 @test_builtin_vectorelements_int1( | ||
// CHECK: ret i32 1 | ||
return __builtin_vectorelements(int1); | ||
} | ||
|
||
int test_builtin_vectorelements_int4() { | ||
// CHECK-LABEL: i32 @test_builtin_vectorelements_int4( | ||
// CHECK: ret i32 4 | ||
return __builtin_vectorelements(int4); | ||
} | ||
|
||
int test_builtin_vectorelements_int8() { | ||
// CHECK-LABEL: i32 @test_builtin_vectorelements_int8( | ||
// CHECK: ret i32 8 | ||
return __builtin_vectorelements(int8); | ||
} | ||
|
||
int test_builtin_vectorelements_int16() { | ||
// CHECK-LABEL: i32 @test_builtin_vectorelements_int16( | ||
// CHECK: ret i32 16 | ||
return __builtin_vectorelements(int16); | ||
} | ||
|
||
int test_builtin_vectorelements_float2() { | ||
// CHECK-LABEL: i32 @test_builtin_vectorelements_float2( | ||
// CHECK: ret i32 2 | ||
return __builtin_vectorelements(float2); | ||
} | ||
|
||
int test_builtin_vectorelements_extLong4() { | ||
// CHECK-LABEL: i32 @test_builtin_vectorelements_extLong4( | ||
// CHECK: ret i32 4 | ||
return __builtin_vectorelements(extLong4); | ||
} | ||
|
||
int test_builtin_vectorelements_multiply_constant() { | ||
// CHECK-LABEL: i32 @test_builtin_vectorelements_multiply_constant( | ||
// CHECK: ret i32 32 | ||
return __builtin_vectorelements(int16) * 2; | ||
} | ||
|
||
|
||
#if defined(__ARM_NEON) | ||
#include <arm_neon.h> | ||
|
||
int test_builtin_vectorelements_neon32x4() { | ||
// NEON: i32 @test_builtin_vectorelements_neon32x4( | ||
// NEON: ret i32 4 | ||
return __builtin_vectorelements(uint32x4_t); | ||
} | ||
|
||
int test_builtin_vectorelements_neon64x1() { | ||
// NEON: i32 @test_builtin_vectorelements_neon64x1( | ||
// NEON: ret i32 1 | ||
return __builtin_vectorelements(uint64x1_t); | ||
} | ||
#endif | ||
|
||
#if defined(__ARM_FEATURE_SVE) | ||
#include <arm_sve.h> | ||
|
||
long test_builtin_vectorelements_sve32() { | ||
// SVE: i64 @test_builtin_vectorelements_sve32( | ||
// SVE: [[VSCALE:%.+]] = call i64 @llvm.vscale.i64() | ||
// SVE: [[RES:%.+]] = mul i64 [[VSCALE]], 4 | ||
// SVE: ret i64 [[RES]] | ||
return __builtin_vectorelements(svuint32_t); | ||
} | ||
|
||
long test_builtin_vectorelements_sve8() { | ||
// SVE: i64 @test_builtin_vectorelements_sve8( | ||
// SVE: [[VSCALE:%.+]] = call i64 @llvm.vscale.i64() | ||
// SVE: [[RES:%.+]] = mul i64 [[VSCALE]], 16 | ||
// SVE: ret i64 [[RES]] | ||
return __builtin_vectorelements(svuint8_t); | ||
} | ||
#endif | ||
|
||
#if defined(__riscv) | ||
#include <riscv_vector.h> | ||
|
||
long test_builtin_vectorelements_riscv8() { | ||
// RISCV: i64 @test_builtin_vectorelements_riscv8( | ||
// RISCV: [[VSCALE:%.+]] = call i64 @llvm.vscale.i64() | ||
// RISCV: [[RES:%.+]] = mul i64 [[VSCALE]], 8 | ||
// RISCV: ret i64 [[RES]] | ||
return __builtin_vectorelements(vuint8m1_t); | ||
} | ||
|
||
long test_builtin_vectorelements_riscv64() { | ||
// RISCV: i64 @test_builtin_vectorelements_riscv64( | ||
// RISCV: [[VSCALE:%.+]] = call i64 @llvm.vscale.i64() | ||
// RISCV: ret i64 [[VSCALE]] | ||
return __builtin_vectorelements(vuint64m1_t); | ||
} | ||
|
||
long test_builtin_vectorelements_riscv32m2() { | ||
// RISCV: i64 @test_builtin_vectorelements_riscv32m2( | ||
// RISCV: [[VSCALE:%.+]] = call i64 @llvm.vscale.i64() | ||
// RISCV: [[RES:%.+]] = mul i64 [[VSCALE]], 4 | ||
// RISCV: ret i64 [[RES]] | ||
return __builtin_vectorelements(vuint32m2_t); | ||
} | ||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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}} | ||
} | ||
|
Uh oh!
There was an error while loading. Please reload this page.