Skip to content

Commit cb4fb3a

Browse files
[NFC] Move areCompatibleSveTypes etc. from ASTContext to SemaARM. (#145429)
In preparation for making these functions interact with the current context; see #144611.
1 parent cc75671 commit cb4fb3a

File tree

7 files changed

+109
-104
lines changed

7 files changed

+109
-104
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2524,15 +2524,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
25242524
/// types.
25252525
bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
25262526

2527-
/// Return true if the given types are an SVE builtin and a VectorType that
2528-
/// is a fixed-length representation of the SVE builtin for a specific
2529-
/// vector-length.
2530-
bool areCompatibleSveTypes(QualType FirstType, QualType SecondType);
2531-
2532-
/// Return true if the given vector types are lax-compatible SVE vector types,
2533-
/// false otherwise.
2534-
bool areLaxCompatibleSveTypes(QualType FirstType, QualType SecondType);
2535-
25362527
/// Return true if the given types are an RISC-V vector builtin type and a
25372528
/// VectorType that is a fixed-length representation of the RISC-V vector
25382529
/// builtin type for a specific vector-length.

clang/include/clang/Sema/SemaARM.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ class SemaARM : public SemaBase {
8282
void handleInterruptSaveFPAttr(Decl *D, const ParsedAttr &AL);
8383

8484
void CheckSMEFunctionDefAttributes(const FunctionDecl *FD);
85+
86+
/// Return true if the given types are an SVE builtin and a VectorType that
87+
/// is a fixed-length representation of the SVE builtin for a specific
88+
/// vector-length.
89+
bool areCompatibleSveTypes(QualType FirstType, QualType SecondType);
90+
91+
/// Return true if the given vector types are lax-compatible SVE vector types,
92+
/// false otherwise.
93+
bool areLaxCompatibleSveTypes(QualType FirstType, QualType SecondType);
8594
};
8695

8796
SemaARM::ArmStreamingType getArmStreamingFnType(const FunctionDecl *FD);

clang/lib/AST/ASTContext.cpp

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -10510,87 +10510,6 @@ bool ASTContext::areCompatibleVectorTypes(QualType FirstVec,
1051010510
return false;
1051110511
}
1051210512

10513-
/// getSVETypeSize - Return SVE vector or predicate register size.
10514-
static uint64_t getSVETypeSize(ASTContext &Context, const BuiltinType *Ty) {
10515-
assert(Ty->isSveVLSBuiltinType() && "Invalid SVE Type");
10516-
if (Ty->getKind() == BuiltinType::SveBool ||
10517-
Ty->getKind() == BuiltinType::SveCount)
10518-
return (Context.getLangOpts().VScaleMin * 128) / Context.getCharWidth();
10519-
return Context.getLangOpts().VScaleMin * 128;
10520-
}
10521-
10522-
bool ASTContext::areCompatibleSveTypes(QualType FirstType,
10523-
QualType SecondType) {
10524-
auto IsValidCast = [this](QualType FirstType, QualType SecondType) {
10525-
if (const auto *BT = FirstType->getAs<BuiltinType>()) {
10526-
if (const auto *VT = SecondType->getAs<VectorType>()) {
10527-
// Predicates have the same representation as uint8 so we also have to
10528-
// check the kind to make these types incompatible.
10529-
if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)
10530-
return BT->getKind() == BuiltinType::SveBool;
10531-
else if (VT->getVectorKind() == VectorKind::SveFixedLengthData)
10532-
return VT->getElementType().getCanonicalType() ==
10533-
FirstType->getSveEltType(*this);
10534-
else if (VT->getVectorKind() == VectorKind::Generic)
10535-
return getTypeSize(SecondType) == getSVETypeSize(*this, BT) &&
10536-
hasSameType(VT->getElementType(),
10537-
getBuiltinVectorTypeInfo(BT).ElementType);
10538-
}
10539-
}
10540-
return false;
10541-
};
10542-
10543-
return IsValidCast(FirstType, SecondType) ||
10544-
IsValidCast(SecondType, FirstType);
10545-
}
10546-
10547-
bool ASTContext::areLaxCompatibleSveTypes(QualType FirstType,
10548-
QualType SecondType) {
10549-
auto IsLaxCompatible = [this](QualType FirstType, QualType SecondType) {
10550-
const auto *BT = FirstType->getAs<BuiltinType>();
10551-
if (!BT)
10552-
return false;
10553-
10554-
const auto *VecTy = SecondType->getAs<VectorType>();
10555-
if (VecTy && (VecTy->getVectorKind() == VectorKind::SveFixedLengthData ||
10556-
VecTy->getVectorKind() == VectorKind::Generic)) {
10557-
const LangOptions::LaxVectorConversionKind LVCKind =
10558-
getLangOpts().getLaxVectorConversions();
10559-
10560-
// Can not convert between sve predicates and sve vectors because of
10561-
// different size.
10562-
if (BT->getKind() == BuiltinType::SveBool &&
10563-
VecTy->getVectorKind() == VectorKind::SveFixedLengthData)
10564-
return false;
10565-
10566-
// If __ARM_FEATURE_SVE_BITS != N do not allow GNU vector lax conversion.
10567-
// "Whenever __ARM_FEATURE_SVE_BITS==N, GNUT implicitly
10568-
// converts to VLAT and VLAT implicitly converts to GNUT."
10569-
// ACLE Spec Version 00bet6, 3.7.3.2. Behavior common to vectors and
10570-
// predicates.
10571-
if (VecTy->getVectorKind() == VectorKind::Generic &&
10572-
getTypeSize(SecondType) != getSVETypeSize(*this, BT))
10573-
return false;
10574-
10575-
// If -flax-vector-conversions=all is specified, the types are
10576-
// certainly compatible.
10577-
if (LVCKind == LangOptions::LaxVectorConversionKind::All)
10578-
return true;
10579-
10580-
// If -flax-vector-conversions=integer is specified, the types are
10581-
// compatible if the elements are integer types.
10582-
if (LVCKind == LangOptions::LaxVectorConversionKind::Integer)
10583-
return VecTy->getElementType().getCanonicalType()->isIntegerType() &&
10584-
FirstType->getSveEltType(*this)->isIntegerType();
10585-
}
10586-
10587-
return false;
10588-
};
10589-
10590-
return IsLaxCompatible(FirstType, SecondType) ||
10591-
IsLaxCompatible(SecondType, FirstType);
10592-
}
10593-
1059410513
/// getRVVTypeSize - Return RVV vector register size.
1059510514
static uint64_t getRVVTypeSize(ASTContext &Context, const BuiltinType *Ty) {
1059610515
assert(Ty->isRVVVLSBuiltinType() && "Invalid RVV Type");

clang/lib/Sema/SemaARM.cpp

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,4 +1409,88 @@ void SemaARM::CheckSMEFunctionDefAttributes(const FunctionDecl *FD) {
14091409
}
14101410
}
14111411

1412+
/// getSVETypeSize - Return SVE vector or predicate register size.
1413+
static uint64_t getSVETypeSize(ASTContext &Context, const BuiltinType *Ty) {
1414+
assert(Ty->isSveVLSBuiltinType() && "Invalid SVE Type");
1415+
if (Ty->getKind() == BuiltinType::SveBool ||
1416+
Ty->getKind() == BuiltinType::SveCount)
1417+
return (Context.getLangOpts().VScaleMin * 128) / Context.getCharWidth();
1418+
return Context.getLangOpts().VScaleMin * 128;
1419+
}
1420+
1421+
bool SemaARM::areCompatibleSveTypes(QualType FirstType, QualType SecondType) {
1422+
auto IsValidCast = [this](QualType FirstType, QualType SecondType) {
1423+
if (const auto *BT = FirstType->getAs<BuiltinType>()) {
1424+
if (const auto *VT = SecondType->getAs<VectorType>()) {
1425+
ASTContext &Context = getASTContext();
1426+
// Predicates have the same representation as uint8 so we also have to
1427+
// check the kind to make these types incompatible.
1428+
if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)
1429+
return BT->getKind() == BuiltinType::SveBool;
1430+
else if (VT->getVectorKind() == VectorKind::SveFixedLengthData)
1431+
return VT->getElementType().getCanonicalType() ==
1432+
FirstType->getSveEltType(Context);
1433+
else if (VT->getVectorKind() == VectorKind::Generic)
1434+
return Context.getTypeSize(SecondType) ==
1435+
getSVETypeSize(Context, BT) &&
1436+
Context.hasSameType(
1437+
VT->getElementType(),
1438+
Context.getBuiltinVectorTypeInfo(BT).ElementType);
1439+
}
1440+
}
1441+
return false;
1442+
};
1443+
1444+
return IsValidCast(FirstType, SecondType) ||
1445+
IsValidCast(SecondType, FirstType);
1446+
}
1447+
1448+
bool SemaARM::areLaxCompatibleSveTypes(QualType FirstType,
1449+
QualType SecondType) {
1450+
auto IsLaxCompatible = [this](QualType FirstType, QualType SecondType) {
1451+
const auto *BT = FirstType->getAs<BuiltinType>();
1452+
if (!BT)
1453+
return false;
1454+
1455+
const auto *VecTy = SecondType->getAs<VectorType>();
1456+
if (VecTy && (VecTy->getVectorKind() == VectorKind::SveFixedLengthData ||
1457+
VecTy->getVectorKind() == VectorKind::Generic)) {
1458+
const LangOptions::LaxVectorConversionKind LVCKind =
1459+
getLangOpts().getLaxVectorConversions();
1460+
ASTContext &Context = getASTContext();
1461+
1462+
// Can not convert between sve predicates and sve vectors because of
1463+
// different size.
1464+
if (BT->getKind() == BuiltinType::SveBool &&
1465+
VecTy->getVectorKind() == VectorKind::SveFixedLengthData)
1466+
return false;
1467+
1468+
// If __ARM_FEATURE_SVE_BITS != N do not allow GNU vector lax conversion.
1469+
// "Whenever __ARM_FEATURE_SVE_BITS==N, GNUT implicitly
1470+
// converts to VLAT and VLAT implicitly converts to GNUT."
1471+
// ACLE Spec Version 00bet6, 3.7.3.2. Behavior common to vectors and
1472+
// predicates.
1473+
if (VecTy->getVectorKind() == VectorKind::Generic &&
1474+
Context.getTypeSize(SecondType) != getSVETypeSize(Context, BT))
1475+
return false;
1476+
1477+
// If -flax-vector-conversions=all is specified, the types are
1478+
// certainly compatible.
1479+
if (LVCKind == LangOptions::LaxVectorConversionKind::All)
1480+
return true;
1481+
1482+
// If -flax-vector-conversions=integer is specified, the types are
1483+
// compatible if the elements are integer types.
1484+
if (LVCKind == LangOptions::LaxVectorConversionKind::Integer)
1485+
return VecTy->getElementType().getCanonicalType()->isIntegerType() &&
1486+
FirstType->getSveEltType(Context)->isIntegerType();
1487+
}
1488+
1489+
return false;
1490+
};
1491+
1492+
return IsLaxCompatible(FirstType, SecondType) ||
1493+
IsLaxCompatible(SecondType, FirstType);
1494+
}
1495+
14121496
} // namespace clang

clang/lib/Sema/SemaChecking.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12055,10 +12055,10 @@ void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
1205512055
// Strip vector types.
1205612056
if (isa<VectorType>(Source)) {
1205712057
if (Target->isSveVLSBuiltinType() &&
12058-
(Context.areCompatibleSveTypes(QualType(Target, 0),
12059-
QualType(Source, 0)) ||
12060-
Context.areLaxCompatibleSveTypes(QualType(Target, 0),
12061-
QualType(Source, 0))))
12058+
(ARM().areCompatibleSveTypes(QualType(Target, 0),
12059+
QualType(Source, 0)) ||
12060+
ARM().areLaxCompatibleSveTypes(QualType(Target, 0),
12061+
QualType(Source, 0))))
1206212062
return;
1206312063

1206412064
if (Target->isRVVVLSBuiltinType() &&
@@ -12118,10 +12118,10 @@ void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
1211812118
const Type *OriginalTarget = Context.getCanonicalType(T).getTypePtr();
1211912119
// Handle conversion from scalable to fixed when msve-vector-bits is
1212012120
// specified
12121-
if (Context.areCompatibleSveTypes(QualType(OriginalTarget, 0),
12122-
QualType(Source, 0)) ||
12123-
Context.areLaxCompatibleSveTypes(QualType(OriginalTarget, 0),
12124-
QualType(Source, 0)))
12121+
if (ARM().areCompatibleSveTypes(QualType(OriginalTarget, 0),
12122+
QualType(Source, 0)) ||
12123+
ARM().areLaxCompatibleSveTypes(QualType(OriginalTarget, 0),
12124+
QualType(Source, 0)))
1212512125
return;
1212612126

1212712127
// If the vector cast is cast between two vectors of the same size, it is

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
#include "clang/Sema/ParsedTemplate.h"
5252
#include "clang/Sema/Scope.h"
5353
#include "clang/Sema/ScopeInfo.h"
54+
#include "clang/Sema/SemaARM.h"
5455
#include "clang/Sema/SemaCUDA.h"
5556
#include "clang/Sema/SemaFixItUtils.h"
5657
#include "clang/Sema/SemaHLSL.h"
@@ -9397,8 +9398,8 @@ AssignConvertType Sema::CheckAssignmentConstraints(QualType LHSType,
93979398
// Allow assignments between fixed-length and sizeless SVE vectors.
93989399
if ((LHSType->isSVESizelessBuiltinType() && RHSType->isVectorType()) ||
93999400
(LHSType->isVectorType() && RHSType->isSVESizelessBuiltinType()))
9400-
if (Context.areCompatibleSveTypes(LHSType, RHSType) ||
9401-
Context.areLaxCompatibleSveTypes(LHSType, RHSType)) {
9401+
if (ARM().areCompatibleSveTypes(LHSType, RHSType) ||
9402+
ARM().areLaxCompatibleSveTypes(LHSType, RHSType)) {
94029403
Kind = CK_BitCast;
94039404
return AssignConvertType::Compatible;
94049405
}

clang/lib/Sema/SemaOverload.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "clang/Sema/Initialization.h"
3131
#include "clang/Sema/Lookup.h"
3232
#include "clang/Sema/Overload.h"
33+
#include "clang/Sema/SemaARM.h"
3334
#include "clang/Sema/SemaCUDA.h"
3435
#include "clang/Sema/SemaObjC.h"
3536
#include "clang/Sema/Template.h"
@@ -2180,8 +2181,8 @@ static bool IsVectorConversion(Sema &S, QualType FromType, QualType ToType,
21802181

21812182
if (ToType->isSVESizelessBuiltinType() ||
21822183
FromType->isSVESizelessBuiltinType())
2183-
if (S.Context.areCompatibleSveTypes(FromType, ToType) ||
2184-
S.Context.areLaxCompatibleSveTypes(FromType, ToType)) {
2184+
if (S.ARM().areCompatibleSveTypes(FromType, ToType) ||
2185+
S.ARM().areLaxCompatibleSveTypes(FromType, ToType)) {
21852186
ICK = ICK_SVE_Vector_Conversion;
21862187
return true;
21872188
}
@@ -4735,9 +4736,9 @@ CompareStandardConversionSequences(Sema &S, SourceLocation Loc,
47354736
if (SCS1.Second == ICK_SVE_Vector_Conversion &&
47364737
SCS2.Second == ICK_SVE_Vector_Conversion) {
47374738
bool SCS1IsCompatibleSVEVectorConversion =
4738-
S.Context.areCompatibleSveTypes(SCS1.getFromType(), SCS1.getToType(2));
4739+
S.ARM().areCompatibleSveTypes(SCS1.getFromType(), SCS1.getToType(2));
47394740
bool SCS2IsCompatibleSVEVectorConversion =
4740-
S.Context.areCompatibleSveTypes(SCS2.getFromType(), SCS2.getToType(2));
4741+
S.ARM().areCompatibleSveTypes(SCS2.getFromType(), SCS2.getToType(2));
47414742

47424743
if (SCS1IsCompatibleSVEVectorConversion !=
47434744
SCS2IsCompatibleSVEVectorConversion)

0 commit comments

Comments
 (0)