Skip to content

Commit f6d6166

Browse files
committed
[NFC] Move areCompatibleSveTypes etc. from ASTContext to SemaARM.
In preparation for making these functions interact with the current context; see llvm#144611.
1 parent b1f5e26 commit f6d6166

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
@@ -2486,15 +2486,6 @@ class ASTContext : public RefCountedBase<ASTContext> {
24862486
/// types.
24872487
bool areCompatibleVectorTypes(QualType FirstVec, QualType SecondVec);
24882488

2489-
/// Return true if the given types are an SVE builtin and a VectorType that
2490-
/// is a fixed-length representation of the SVE builtin for a specific
2491-
/// vector-length.
2492-
bool areCompatibleSveTypes(QualType FirstType, QualType SecondType);
2493-
2494-
/// Return true if the given vector types are lax-compatible SVE vector types,
2495-
/// false otherwise.
2496-
bool areLaxCompatibleSveTypes(QualType FirstType, QualType SecondType);
2497-
24982489
/// Return true if the given types are an RISC-V vector builtin type and a
24992490
/// VectorType that is a fixed-length representation of the RISC-V vector
25002491
/// 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
@@ -10443,87 +10443,6 @@ bool ASTContext::areCompatibleVectorTypes(QualType FirstVec,
1044310443
return false;
1044410444
}
1044510445

10446-
/// getSVETypeSize - Return SVE vector or predicate register size.
10447-
static uint64_t getSVETypeSize(ASTContext &Context, const BuiltinType *Ty) {
10448-
assert(Ty->isSveVLSBuiltinType() && "Invalid SVE Type");
10449-
if (Ty->getKind() == BuiltinType::SveBool ||
10450-
Ty->getKind() == BuiltinType::SveCount)
10451-
return (Context.getLangOpts().VScaleMin * 128) / Context.getCharWidth();
10452-
return Context.getLangOpts().VScaleMin * 128;
10453-
}
10454-
10455-
bool ASTContext::areCompatibleSveTypes(QualType FirstType,
10456-
QualType SecondType) {
10457-
auto IsValidCast = [this](QualType FirstType, QualType SecondType) {
10458-
if (const auto *BT = FirstType->getAs<BuiltinType>()) {
10459-
if (const auto *VT = SecondType->getAs<VectorType>()) {
10460-
// Predicates have the same representation as uint8 so we also have to
10461-
// check the kind to make these types incompatible.
10462-
if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate)
10463-
return BT->getKind() == BuiltinType::SveBool;
10464-
else if (VT->getVectorKind() == VectorKind::SveFixedLengthData)
10465-
return VT->getElementType().getCanonicalType() ==
10466-
FirstType->getSveEltType(*this);
10467-
else if (VT->getVectorKind() == VectorKind::Generic)
10468-
return getTypeSize(SecondType) == getSVETypeSize(*this, BT) &&
10469-
hasSameType(VT->getElementType(),
10470-
getBuiltinVectorTypeInfo(BT).ElementType);
10471-
}
10472-
}
10473-
return false;
10474-
};
10475-
10476-
return IsValidCast(FirstType, SecondType) ||
10477-
IsValidCast(SecondType, FirstType);
10478-
}
10479-
10480-
bool ASTContext::areLaxCompatibleSveTypes(QualType FirstType,
10481-
QualType SecondType) {
10482-
auto IsLaxCompatible = [this](QualType FirstType, QualType SecondType) {
10483-
const auto *BT = FirstType->getAs<BuiltinType>();
10484-
if (!BT)
10485-
return false;
10486-
10487-
const auto *VecTy = SecondType->getAs<VectorType>();
10488-
if (VecTy && (VecTy->getVectorKind() == VectorKind::SveFixedLengthData ||
10489-
VecTy->getVectorKind() == VectorKind::Generic)) {
10490-
const LangOptions::LaxVectorConversionKind LVCKind =
10491-
getLangOpts().getLaxVectorConversions();
10492-
10493-
// Can not convert between sve predicates and sve vectors because of
10494-
// different size.
10495-
if (BT->getKind() == BuiltinType::SveBool &&
10496-
VecTy->getVectorKind() == VectorKind::SveFixedLengthData)
10497-
return false;
10498-
10499-
// If __ARM_FEATURE_SVE_BITS != N do not allow GNU vector lax conversion.
10500-
// "Whenever __ARM_FEATURE_SVE_BITS==N, GNUT implicitly
10501-
// converts to VLAT and VLAT implicitly converts to GNUT."
10502-
// ACLE Spec Version 00bet6, 3.7.3.2. Behavior common to vectors and
10503-
// predicates.
10504-
if (VecTy->getVectorKind() == VectorKind::Generic &&
10505-
getTypeSize(SecondType) != getSVETypeSize(*this, BT))
10506-
return false;
10507-
10508-
// If -flax-vector-conversions=all is specified, the types are
10509-
// certainly compatible.
10510-
if (LVCKind == LangOptions::LaxVectorConversionKind::All)
10511-
return true;
10512-
10513-
// If -flax-vector-conversions=integer is specified, the types are
10514-
// compatible if the elements are integer types.
10515-
if (LVCKind == LangOptions::LaxVectorConversionKind::Integer)
10516-
return VecTy->getElementType().getCanonicalType()->isIntegerType() &&
10517-
FirstType->getSveEltType(*this)->isIntegerType();
10518-
}
10519-
10520-
return false;
10521-
};
10522-
10523-
return IsLaxCompatible(FirstType, SecondType) ||
10524-
IsLaxCompatible(SecondType, FirstType);
10525-
}
10526-
1052710446
/// getRVVTypeSize - Return RVV vector register size.
1052810447
static uint64_t getRVVTypeSize(ASTContext &Context, const BuiltinType *Ty) {
1052910448
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
@@ -12057,10 +12057,10 @@ void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
1205712057
// Strip vector types.
1205812058
if (isa<VectorType>(Source)) {
1205912059
if (Target->isSveVLSBuiltinType() &&
12060-
(Context.areCompatibleSveTypes(QualType(Target, 0),
12061-
QualType(Source, 0)) ||
12062-
Context.areLaxCompatibleSveTypes(QualType(Target, 0),
12063-
QualType(Source, 0))))
12060+
(ARM().areCompatibleSveTypes(QualType(Target, 0),
12061+
QualType(Source, 0)) ||
12062+
ARM().areLaxCompatibleSveTypes(QualType(Target, 0),
12063+
QualType(Source, 0))))
1206412064
return;
1206512065

1206612066
if (Target->isRVVVLSBuiltinType() &&
@@ -12120,10 +12120,10 @@ void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
1212012120
const Type *OriginalTarget = Context.getCanonicalType(T).getTypePtr();
1212112121
// Handle conversion from scalable to fixed when msve-vector-bits is
1212212122
// specified
12123-
if (Context.areCompatibleSveTypes(QualType(OriginalTarget, 0),
12124-
QualType(Source, 0)) ||
12125-
Context.areLaxCompatibleSveTypes(QualType(OriginalTarget, 0),
12126-
QualType(Source, 0)))
12123+
if (ARM().areCompatibleSveTypes(QualType(OriginalTarget, 0),
12124+
QualType(Source, 0)) ||
12125+
ARM().areLaxCompatibleSveTypes(QualType(OriginalTarget, 0),
12126+
QualType(Source, 0)))
1212712127
return;
1212812128

1212912129
// 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"
@@ -9533,8 +9534,8 @@ AssignConvertType Sema::CheckAssignmentConstraints(QualType LHSType,
95339534
// Allow assignments between fixed-length and sizeless SVE vectors.
95349535
if ((LHSType->isSVESizelessBuiltinType() && RHSType->isVectorType()) ||
95359536
(LHSType->isVectorType() && RHSType->isSVESizelessBuiltinType()))
9536-
if (Context.areCompatibleSveTypes(LHSType, RHSType) ||
9537-
Context.areLaxCompatibleSveTypes(LHSType, RHSType)) {
9537+
if (ARM().areCompatibleSveTypes(LHSType, RHSType) ||
9538+
ARM().areLaxCompatibleSveTypes(LHSType, RHSType)) {
95389539
Kind = CK_BitCast;
95399540
return AssignConvertType::Compatible;
95409541
}

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)