Skip to content

Commit 3f43abc

Browse files
committed
[RISCV] Reduce dependency on RISCV::RVVBitsPerBlock for calculating vector size for -mrvv-vector-bits.
We can use the minimum value of the BuiltinType's ElementCount and the element size. This needs to be done to support LMUL!=1 types anyway. I did have to make an ordering change in the error checks in HandleRISCVRVVVectorBitsTypeAttr to check if the type is an RVV VLS type before checking the size.
1 parent d3b3304 commit 3f43abc

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
#include "llvm/Support/MD5.h"
8686
#include "llvm/Support/MathExtras.h"
8787
#include "llvm/Support/raw_ostream.h"
88-
#include "llvm/TargetParser/RISCVTargetParser.h"
8988
#include "llvm/TargetParser/Triple.h"
9089
#include <algorithm>
9190
#include <cassert>
@@ -9581,7 +9580,14 @@ bool ASTContext::areLaxCompatibleSveTypes(QualType FirstType,
95819580
static uint64_t getRVVTypeSize(ASTContext &Context, const BuiltinType *Ty) {
95829581
assert(Ty->isRVVVLSBuiltinType() && "Invalid RVV Type");
95839582
auto VScale = Context.getTargetInfo().getVScaleRange(Context.getLangOpts());
9584-
return VScale ? VScale->first * llvm::RISCV::RVVBitsPerBlock : 0;
9583+
if (!VScale)
9584+
return 0;
9585+
9586+
ASTContext::BuiltinVectorTypeInfo Info = Context.getBuiltinVectorTypeInfo(Ty);
9587+
9588+
unsigned EltSize = Context.getTypeSize(Info.ElementType);
9589+
unsigned MinElts = Info.EC.getKnownMinValue();
9590+
return VScale->first * MinElts * EltSize;
95859591
}
95869592

95879593
bool ASTContext::areCompatibleRVVTypes(QualType FirstType,

clang/lib/Sema/SemaType.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8320,31 +8320,32 @@ static void HandleRISCVRVVVectorBitsTypeAttr(QualType &CurType,
83208320
if (!verifyValidIntegerConstantExpr(S, Attr, RVVVectorSizeInBits))
83218321
return;
83228322

8323+
// Attribute can only be attached to a single RVV vector type.
8324+
if (!CurType->isRVVVLSBuiltinType()) {
8325+
S.Diag(Attr.getLoc(), diag::err_attribute_invalid_rvv_type)
8326+
<< Attr << CurType;
8327+
Attr.setInvalid();
8328+
return;
8329+
}
8330+
83238331
unsigned VecSize = static_cast<unsigned>(RVVVectorSizeInBits.getZExtValue());
83248332

8333+
ASTContext::BuiltinVectorTypeInfo Info =
8334+
S.Context.getBuiltinVectorTypeInfo(CurType->getAs<BuiltinType>());
8335+
unsigned EltSize = S.Context.getTypeSize(Info.ElementType);
8336+
unsigned MinElts = Info.EC.getKnownMinValue();
8337+
83258338
// The attribute vector size must match -mrvv-vector-bits.
8326-
// FIXME: Add support for types with LMUL!=1. Need to make sure size passed
8327-
// to attribute is equal to LMUL*VScaleMin*RVVBitsPerBlock.
8328-
if (VecSize != VScale->first * llvm::RISCV::RVVBitsPerBlock) {
8339+
if (VecSize != VScale->first * MinElts * EltSize) {
83298340
S.Diag(Attr.getLoc(), diag::err_attribute_bad_rvv_vector_size)
83308341
<< VecSize << VScale->first * llvm::RISCV::RVVBitsPerBlock;
83318342
Attr.setInvalid();
83328343
return;
83338344
}
83348345

8335-
// Attribute can only be attached to a single RVV vector type.
8336-
if (!CurType->isRVVVLSBuiltinType()) {
8337-
S.Diag(Attr.getLoc(), diag::err_attribute_invalid_rvv_type)
8338-
<< Attr << CurType;
8339-
Attr.setInvalid();
8340-
return;
8341-
}
8342-
8343-
QualType EltType = CurType->getRVVEltType(S.Context);
8344-
unsigned TypeSize = S.Context.getTypeSize(EltType);
83458346
VectorType::VectorKind VecKind = VectorType::RVVFixedLengthDataVector;
8346-
VecSize /= TypeSize;
8347-
CurType = S.Context.getVectorType(EltType, VecSize, VecKind);
8347+
VecSize /= EltSize;
8348+
CurType = S.Context.getVectorType(Info.ElementType, VecSize, VecKind);
83488349
}
83498350

83508351
/// Handle OpenCL Access Qualifier Attribute.

0 commit comments

Comments
 (0)