Skip to content

Commit ae7b20b

Browse files
committed
[clang][NFC] Refactor VectorType::VectorKind
This patch moves `VectorKind` to namespace scope, and make it complete at the point its bit-field is declared. It also converts it to a scoped enum.
1 parent 1344b65 commit ae7b20b

23 files changed

+231
-244
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,12 +1493,12 @@ class ASTContext : public RefCountedBase<ASTContext> {
14931493
///
14941494
/// \pre \p VectorType must be a built-in type.
14951495
QualType getVectorType(QualType VectorType, unsigned NumElts,
1496-
VectorType::VectorKind VecKind) const;
1496+
VectorKind VecKind) const;
14971497
/// Return the unique reference to the type for a dependently sized vector of
14981498
/// the specified element type.
14991499
QualType getDependentVectorType(QualType VectorType, Expr *SizeExpr,
15001500
SourceLocation AttrLoc,
1501-
VectorType::VectorKind VecKind) const;
1501+
VectorKind VecKind) const;
15021502

15031503
/// Return the unique reference to an extended vector type
15041504
/// of the specified element type and size.

clang/include/clang/AST/PropertiesBase.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def TypeOfKind : EnumPropertyType<"TypeOfKind">;
142142
def UInt32 : CountPropertyType<"uint32_t">;
143143
def UInt64 : CountPropertyType<"uint64_t">;
144144
def UnaryTypeTransformKind : EnumPropertyType<"UnaryTransformType::UTTKind">;
145-
def VectorKind : EnumPropertyType<"VectorType::VectorKind">;
145+
def VectorKind : EnumPropertyType<"VectorKind">;
146146

147147
def ExceptionSpecInfo : PropertyType<"FunctionProtoType::ExceptionSpecInfo"> {
148148
let BufferElementTypes = [ QualType ];

clang/include/clang/AST/Type.h

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,6 +1601,35 @@ enum class ElaboratedTypeKeyword {
16011601
None
16021602
};
16031603

1604+
enum class VectorKind {
1605+
/// not a target-specific vector type
1606+
Generic,
1607+
1608+
/// is AltiVec vector
1609+
AltiVecVector,
1610+
1611+
/// is AltiVec 'vector Pixel'
1612+
AltiVecPixel,
1613+
1614+
/// is AltiVec 'vector bool ...'
1615+
AltiVecBool,
1616+
1617+
/// is ARM Neon vector
1618+
Neon,
1619+
1620+
/// is ARM Neon polynomial vector
1621+
NeonPoly,
1622+
1623+
/// is AArch64 SVE fixed-length data vector
1624+
SveFixedLengthData,
1625+
1626+
/// is AArch64 SVE fixed-length predicate vector
1627+
SveFixedLengthPredicate,
1628+
1629+
/// is RISC-V RVV fixed-length data vector
1630+
RVVFixedLengthData,
1631+
};
1632+
16041633
/// The base class of the type hierarchy.
16051634
///
16061635
/// A central concept with types is that each type always has a canonical
@@ -3452,36 +3481,6 @@ class DependentSizedExtVectorType : public Type, public llvm::FoldingSetNode {
34523481
/// Since the constructor takes the number of vector elements, the
34533482
/// client is responsible for converting the size into the number of elements.
34543483
class VectorType : public Type, public llvm::FoldingSetNode {
3455-
public:
3456-
enum VectorKind {
3457-
/// not a target-specific vector type
3458-
GenericVector,
3459-
3460-
/// is AltiVec vector
3461-
AltiVecVector,
3462-
3463-
/// is AltiVec 'vector Pixel'
3464-
AltiVecPixel,
3465-
3466-
/// is AltiVec 'vector bool ...'
3467-
AltiVecBool,
3468-
3469-
/// is ARM Neon vector
3470-
NeonVector,
3471-
3472-
/// is ARM Neon polynomial vector
3473-
NeonPolyVector,
3474-
3475-
/// is AArch64 SVE fixed-length data vector
3476-
SveFixedLengthDataVector,
3477-
3478-
/// is AArch64 SVE fixed-length predicate vector
3479-
SveFixedLengthPredicateVector,
3480-
3481-
/// is RISC-V RVV fixed-length data vector
3482-
RVVFixedLengthDataVector,
3483-
};
3484-
34853484
protected:
34863485
friend class ASTContext; // ASTContext creates these.
34873486

@@ -3516,7 +3515,7 @@ class VectorType : public Type, public llvm::FoldingSetNode {
35163515
ID.AddPointer(ElementType.getAsOpaquePtr());
35173516
ID.AddInteger(NumElements);
35183517
ID.AddInteger(TypeClass);
3519-
ID.AddInteger(VecKind);
3518+
ID.AddInteger(llvm::to_underlying(VecKind));
35203519
}
35213520

35223521
static bool classof(const Type *T) {
@@ -3541,14 +3540,14 @@ class DependentVectorType : public Type, public llvm::FoldingSetNode {
35413540
SourceLocation Loc;
35423541

35433542
DependentVectorType(QualType ElementType, QualType CanonType, Expr *SizeExpr,
3544-
SourceLocation Loc, VectorType::VectorKind vecKind);
3543+
SourceLocation Loc, VectorKind vecKind);
35453544

35463545
public:
35473546
Expr *getSizeExpr() const { return SizeExpr; }
35483547
QualType getElementType() const { return ElementType; }
35493548
SourceLocation getAttributeLoc() const { return Loc; }
3550-
VectorType::VectorKind getVectorKind() const {
3551-
return VectorType::VectorKind(VectorTypeBits.VecKind);
3549+
VectorKind getVectorKind() const {
3550+
return VectorKind(VectorTypeBits.VecKind);
35523551
}
35533552

35543553
bool isSugared() const { return false; }
@@ -3564,7 +3563,7 @@ class DependentVectorType : public Type, public llvm::FoldingSetNode {
35643563

35653564
static void Profile(llvm::FoldingSetNodeID &ID, const ASTContext &Context,
35663565
QualType ElementType, const Expr *SizeExpr,
3567-
VectorType::VectorKind VecKind);
3566+
VectorKind VecKind);
35683567
};
35693568

35703569
/// ExtVectorType - Extended vector type. This type is created using
@@ -3577,7 +3576,8 @@ class ExtVectorType : public VectorType {
35773576
friend class ASTContext; // ASTContext creates these.
35783577

35793578
ExtVectorType(QualType vecType, unsigned nElements, QualType canonType)
3580-
: VectorType(ExtVector, vecType, nElements, canonType, GenericVector) {}
3579+
: VectorType(ExtVector, vecType, nElements, canonType,
3580+
VectorKind::Generic) {}
35813581

35823582
public:
35833583
static int getPointAccessorIdx(char c) {

clang/lib/AST/ASTContext.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1935,14 +1935,14 @@ TypeInfo ASTContext::getTypeInfoImpl(const Type *T) const {
19351935
uint64_t TargetVectorAlign = Target->getMaxVectorAlign();
19361936
if (TargetVectorAlign && TargetVectorAlign < Align)
19371937
Align = TargetVectorAlign;
1938-
if (VT->getVectorKind() == VectorType::SveFixedLengthDataVector)
1938+
if (VT->getVectorKind() == VectorKind::SveFixedLengthData)
19391939
// Adjust the alignment for fixed-length SVE vectors. This is important
19401940
// for non-power-of-2 vector lengths.
19411941
Align = 128;
1942-
else if (VT->getVectorKind() == VectorType::SveFixedLengthPredicateVector)
1942+
else if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)
19431943
// Adjust the alignment for fixed-length SVE predicates.
19441944
Align = 16;
1945-
else if (VT->getVectorKind() == VectorType::RVVFixedLengthDataVector)
1945+
else if (VT->getVectorKind() == VectorKind::RVVFixedLengthData)
19461946
// Adjust the alignment for fixed-length RVV vectors.
19471947
Align = std::min<unsigned>(64, Width);
19481948
break;
@@ -4004,7 +4004,7 @@ QualType ASTContext::getScalableVectorType(QualType EltTy, unsigned NumElts,
40044004
/// getVectorType - Return the unique reference to a vector type of
40054005
/// the specified element type and size. VectorType must be a built-in type.
40064006
QualType ASTContext::getVectorType(QualType vecType, unsigned NumElts,
4007-
VectorType::VectorKind VecKind) const {
4007+
VectorKind VecKind) const {
40084008
assert(vecType->isBuiltinType() ||
40094009
(vecType->isBitIntType() &&
40104010
// Only support _BitInt elements with byte-sized power of 2 NumBits.
@@ -4036,10 +4036,9 @@ QualType ASTContext::getVectorType(QualType vecType, unsigned NumElts,
40364036
return QualType(New, 0);
40374037
}
40384038

4039-
QualType
4040-
ASTContext::getDependentVectorType(QualType VecType, Expr *SizeExpr,
4041-
SourceLocation AttrLoc,
4042-
VectorType::VectorKind VecKind) const {
4039+
QualType ASTContext::getDependentVectorType(QualType VecType, Expr *SizeExpr,
4040+
SourceLocation AttrLoc,
4041+
VectorKind VecKind) const {
40434042
llvm::FoldingSetNodeID ID;
40444043
DependentVectorType::Profile(ID, *this, getCanonicalType(VecType), SizeExpr,
40454044
VecKind);
@@ -4088,7 +4087,7 @@ QualType ASTContext::getExtVectorType(QualType vecType,
40884087
// Check if we've already instantiated a vector of this type.
40894088
llvm::FoldingSetNodeID ID;
40904089
VectorType::Profile(ID, vecType, NumElts, Type::ExtVector,
4091-
VectorType::GenericVector);
4090+
VectorKind::Generic);
40924091
void *InsertPos = nullptr;
40934092
if (VectorType *VTP = VectorTypes.FindNodeOrInsertPos(ID, InsertPos))
40944093
return QualType(VTP, 0);
@@ -9396,16 +9395,16 @@ bool ASTContext::areCompatibleVectorTypes(QualType FirstVec,
93969395
const auto *Second = SecondVec->castAs<VectorType>();
93979396
if (First->getNumElements() == Second->getNumElements() &&
93989397
hasSameType(First->getElementType(), Second->getElementType()) &&
9399-
First->getVectorKind() != VectorType::AltiVecPixel &&
9400-
First->getVectorKind() != VectorType::AltiVecBool &&
9401-
Second->getVectorKind() != VectorType::AltiVecPixel &&
9402-
Second->getVectorKind() != VectorType::AltiVecBool &&
9403-
First->getVectorKind() != VectorType::SveFixedLengthDataVector &&
9404-
First->getVectorKind() != VectorType::SveFixedLengthPredicateVector &&
9405-
Second->getVectorKind() != VectorType::SveFixedLengthDataVector &&
9406-
Second->getVectorKind() != VectorType::SveFixedLengthPredicateVector &&
9407-
First->getVectorKind() != VectorType::RVVFixedLengthDataVector &&
9408-
Second->getVectorKind() != VectorType::RVVFixedLengthDataVector)
9398+
First->getVectorKind() != VectorKind::AltiVecPixel &&
9399+
First->getVectorKind() != VectorKind::AltiVecBool &&
9400+
Second->getVectorKind() != VectorKind::AltiVecPixel &&
9401+
Second->getVectorKind() != VectorKind::AltiVecBool &&
9402+
First->getVectorKind() != VectorKind::SveFixedLengthData &&
9403+
First->getVectorKind() != VectorKind::SveFixedLengthPredicate &&
9404+
Second->getVectorKind() != VectorKind::SveFixedLengthData &&
9405+
Second->getVectorKind() != VectorKind::SveFixedLengthPredicate &&
9406+
First->getVectorKind() != VectorKind::RVVFixedLengthData &&
9407+
Second->getVectorKind() != VectorKind::RVVFixedLengthData)
94099408
return true;
94109409

94119410
return false;
@@ -9432,12 +9431,12 @@ bool ASTContext::areCompatibleSveTypes(QualType FirstType,
94329431
if (const auto *VT = SecondType->getAs<VectorType>()) {
94339432
// Predicates have the same representation as uint8 so we also have to
94349433
// check the kind to make these types incompatible.
9435-
if (VT->getVectorKind() == VectorType::SveFixedLengthPredicateVector)
9434+
if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)
94369435
return BT->getKind() == BuiltinType::SveBool;
9437-
else if (VT->getVectorKind() == VectorType::SveFixedLengthDataVector)
9436+
else if (VT->getVectorKind() == VectorKind::SveFixedLengthData)
94389437
return VT->getElementType().getCanonicalType() ==
94399438
FirstType->getSveEltType(*this);
9440-
else if (VT->getVectorKind() == VectorType::GenericVector)
9439+
else if (VT->getVectorKind() == VectorKind::Generic)
94419440
return getTypeSize(SecondType) == getSVETypeSize(*this, BT) &&
94429441
hasSameType(VT->getElementType(),
94439442
getBuiltinVectorTypeInfo(BT).ElementType);
@@ -9463,24 +9462,23 @@ bool ASTContext::areLaxCompatibleSveTypes(QualType FirstType,
94639462
return false;
94649463

94659464
const auto *VecTy = SecondType->getAs<VectorType>();
9466-
if (VecTy &&
9467-
(VecTy->getVectorKind() == VectorType::SveFixedLengthDataVector ||
9468-
VecTy->getVectorKind() == VectorType::GenericVector)) {
9465+
if (VecTy && (VecTy->getVectorKind() == VectorKind::SveFixedLengthData ||
9466+
VecTy->getVectorKind() == VectorKind::Generic)) {
94699467
const LangOptions::LaxVectorConversionKind LVCKind =
94709468
getLangOpts().getLaxVectorConversions();
94719469

94729470
// Can not convert between sve predicates and sve vectors because of
94739471
// different size.
94749472
if (BT->getKind() == BuiltinType::SveBool &&
9475-
VecTy->getVectorKind() == VectorType::SveFixedLengthDataVector)
9473+
VecTy->getVectorKind() == VectorKind::SveFixedLengthData)
94769474
return false;
94779475

94789476
// If __ARM_FEATURE_SVE_BITS != N do not allow GNU vector lax conversion.
94799477
// "Whenever __ARM_FEATURE_SVE_BITS==N, GNUT implicitly
94809478
// converts to VLAT and VLAT implicitly converts to GNUT."
94819479
// ACLE Spec Version 00bet6, 3.7.3.2. Behavior common to vectors and
94829480
// predicates.
9483-
if (VecTy->getVectorKind() == VectorType::GenericVector &&
9481+
if (VecTy->getVectorKind() == VectorKind::Generic &&
94849482
getTypeSize(SecondType) != getSVETypeSize(*this, BT))
94859483
return false;
94869484

@@ -9527,8 +9525,8 @@ bool ASTContext::areCompatibleRVVTypes(QualType FirstType,
95279525
auto IsValidCast = [this](QualType FirstType, QualType SecondType) {
95289526
if (const auto *BT = FirstType->getAs<BuiltinType>()) {
95299527
if (const auto *VT = SecondType->getAs<VectorType>()) {
9530-
if (VT->getVectorKind() == VectorType::RVVFixedLengthDataVector ||
9531-
VT->getVectorKind() == VectorType::GenericVector)
9528+
if (VT->getVectorKind() == VectorKind::RVVFixedLengthData ||
9529+
VT->getVectorKind() == VectorKind::Generic)
95329530
return FirstType->isRVVVLSBuiltinType() &&
95339531
getTypeSize(SecondType) == getRVVTypeSize(*this, BT) &&
95349532
hasSameType(VT->getElementType(),
@@ -9558,7 +9556,7 @@ bool ASTContext::areLaxCompatibleRVVTypes(QualType FirstType,
95589556
return false;
95599557

95609558
const auto *VecTy = SecondType->getAs<VectorType>();
9561-
if (VecTy && VecTy->getVectorKind() == VectorType::GenericVector) {
9559+
if (VecTy && VecTy->getVectorKind() == VectorKind::Generic) {
95629560
const LangOptions::LaxVectorConversionKind LVCKind =
95639561
getLangOpts().getLaxVectorConversions();
95649562

@@ -11398,8 +11396,7 @@ static QualType DecodeTypeFromStr(const char *&Str, const ASTContext &Context,
1139811396
assert(!RequiresICE && "Can't require vector ICE");
1139911397

1140011398
// TODO: No way to make AltiVec vectors in builtins yet.
11401-
Type = Context.getVectorType(ElementType, NumElements,
11402-
VectorType::GenericVector);
11399+
Type = Context.getVectorType(ElementType, NumElements, VectorKind::Generic);
1140311400
break;
1140411401
}
1140511402
case 'E': {

0 commit comments

Comments
 (0)