Skip to content

Commit 9807305

Browse files
authored
[RISCV] Refactor checkRVVTypeSupport to use BuiltinVectorTypeInfo. (llvm#74949)
We can decompose the type into ElementType and MinSize and use those to perform the checks. This is more efficient than using isRVVType. This also fixes a bug that we didn't disallow vbool64_t on Zve32x.
1 parent 2dccf11 commit 9807305

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6170,25 +6170,28 @@ bool Sema::CheckWebAssemblyBuiltinFunctionCall(const TargetInfo &TI,
61706170

61716171
void Sema::checkRVVTypeSupport(QualType Ty, SourceLocation Loc, Decl *D) {
61726172
const TargetInfo &TI = Context.getTargetInfo();
6173+
6174+
ASTContext::BuiltinVectorTypeInfo Info =
6175+
Context.getBuiltinVectorTypeInfo(Ty->castAs<BuiltinType>());
6176+
unsigned EltSize = Context.getTypeSize(Info.ElementType);
6177+
unsigned MinElts = Info.EC.getKnownMinValue();
6178+
61736179
// (ELEN, LMUL) pairs of (8, mf8), (16, mf4), (32, mf2), (64, m1) requires at
61746180
// least zve64x
6175-
if ((Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ false) ||
6176-
Ty->isRVVType(/* ElementCount */ 1)) &&
6181+
if (((EltSize == 64 && Info.ElementType->isIntegerType()) || MinElts == 1) &&
61776182
!TI.hasFeature("zve64x"))
61786183
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64x";
6179-
if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ true) &&
6180-
!TI.hasFeature("zvfh") && !TI.hasFeature("zvfhmin"))
6184+
if (Info.ElementType->isFloat16Type() && !TI.hasFeature("zvfh") &&
6185+
!TI.hasFeature("zvfhmin"))
61816186
Diag(Loc, diag::err_riscv_type_requires_extension, D)
61826187
<< Ty << "zvfh or zvfhmin";
6183-
// Check if enabled zvfbfmin for BFloat16
6184-
if (Ty->isRVVType(/* Bitwidth */ 16, /* IsFloat */ false,
6185-
/* IsBFloat */ true) &&
6188+
if (Info.ElementType->isBFloat16Type() &&
61866189
!TI.hasFeature("experimental-zvfbfmin"))
61876190
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zvfbfmin";
6188-
if (Ty->isRVVType(/* Bitwidth */ 32, /* IsFloat */ true) &&
6191+
if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Float) &&
61896192
!TI.hasFeature("zve32f"))
61906193
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve32f";
6191-
if (Ty->isRVVType(/* Bitwidth */ 64, /* IsFloat */ true) &&
6194+
if (Info.ElementType->isSpecificBuiltinType(BuiltinType::Double) &&
61926195
!TI.hasFeature("zve64d"))
61936196
Diag(Loc, diag::err_riscv_type_requires_extension, D) << Ty << "zve64d";
61946197
// Given that caller already checked isRVVType() before calling this function,

clang/test/Sema/riscv-vector-zve32x-check.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,3 @@ __rvv_bool32_t vbool32 () { /* expected-error {{RISC-V type '__rvv_bool32_t' req
9797

9898
return b32; /* expected-error {{RISC-V type '__rvv_bool32_t' requires the 'zve32x' extension}} */
9999
}
100-
101-
__rvv_bool64_t vbool64 () { /* expected-error {{RISC-V type '__rvv_bool64_t' requires the 'zve32x' extension}} */
102-
__rvv_bool64_t b64; /* expected-error {{RISC-V type '__rvv_bool64_t' requires the 'zve32x' extension}} */
103-
104-
(void)b64; /* expected-error {{RISC-V type '__rvv_bool64_t' requires the 'zve32x' extension}} */
105-
106-
return b64; /* expected-error {{RISC-V type '__rvv_bool64_t' requires the 'zve32x' extension}} */
107-
}

clang/test/Sema/riscv-vector-zve64x-check.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,11 @@ __rvv_int64m1_t foo64() { /* expected-error {{RISC-V type '__rvv_int64m1_t' requ
3737

3838
return i64m1; /* expected-error {{RISC-V type '__rvv_int64m1_t' requires the 'zve64x' extension}} */
3939
}
40+
41+
__rvv_bool64_t vbool64 () { /* expected-error {{RISC-V type '__rvv_bool64_t' requires the 'zve64x' extension}} */
42+
__rvv_bool64_t b64; /* expected-error {{RISC-V type '__rvv_bool64_t' requires the 'zve64x' extension}} */
43+
44+
(void)b64; /* expected-error {{RISC-V type '__rvv_bool64_t' requires the 'zve64x' extension}} */
45+
46+
return b64; /* expected-error {{RISC-V type '__rvv_bool64_t' requires the 'zve64x' extension}} */
47+
}

0 commit comments

Comments
 (0)