Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
clang/lib/Sema/SemaExpr.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 7,969 Lines • ▼ Show 20 Lines | auto ValidScalableConversion = [](QualType FirstType, QualType SecondType) { | ||||
return VecTy && | return VecTy && | ||||
VecTy->getVectorKind() == VectorType::SveFixedLengthDataVector; | VecTy->getVectorKind() == VectorType::SveFixedLengthDataVector; | ||||
}; | }; | ||||
return ValidScalableConversion(srcTy, destTy) || | return ValidScalableConversion(srcTy, destTy) || | ||||
ValidScalableConversion(destTy, srcTy); | ValidScalableConversion(destTy, srcTy); | ||||
} | } | ||||
/// Are the two types RVV-bitcast-compatible types? I.e. is bitcasting from the | |||||
/// first RVV type (e.g. an RVV scalable type) to the second type (e.g. an RVV | |||||
/// VLS type) allowed? | |||||
/// | |||||
/// This will also return false if the two given types do not make sense from | |||||
/// the perspective of RVV bitcasts. | |||||
bool Sema::isValidRVVBitcast(QualType srcTy, QualType destTy) { | |||||
assert(srcTy->isVectorType() || destTy->isVectorType()); | |||||
auto ValidScalableConversion = [](QualType FirstType, QualType SecondType) { | |||||
if (!FirstType->isRVVSizelessBuiltinType()) | |||||
return false; | |||||
const auto *VecTy = SecondType->getAs<VectorType>(); | |||||
return VecTy && | |||||
VecTy->getVectorKind() == VectorType::RVVFixedLengthDataVector; | |||||
}; | |||||
return ValidScalableConversion(srcTy, destTy) || | |||||
ValidScalableConversion(destTy, srcTy); | |||||
} | |||||
/// Are the two types matrix types and do they have the same dimensions i.e. | /// Are the two types matrix types and do they have the same dimensions i.e. | ||||
/// do they have the same number of rows and the same number of columns? | /// do they have the same number of rows and the same number of columns? | ||||
bool Sema::areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy) { | bool Sema::areMatrixTypesOfTheSameDimension(QualType srcTy, QualType destTy) { | ||||
if (!destTy->isMatrixType() || !srcTy->isMatrixType()) | if (!destTy->isMatrixType() || !srcTy->isMatrixType()) | ||||
return false; | return false; | ||||
const ConstantMatrixType *matSrcType = srcTy->getAs<ConstantMatrixType>(); | const ConstantMatrixType *matSrcType = srcTy->getAs<ConstantMatrixType>(); | ||||
const ConstantMatrixType *matDestType = destTy->getAs<ConstantMatrixType>(); | const ConstantMatrixType *matDestType = destTy->getAs<ConstantMatrixType>(); | ||||
▲ Show 20 Lines • Show All 1,916 Lines • ▼ Show 20 Lines | if (LHSType->isVectorType() || RHSType->isVectorType()) { | ||||
if ((LHSType->isSVESizelessBuiltinType() && RHSType->isVectorType()) || | if ((LHSType->isSVESizelessBuiltinType() && RHSType->isVectorType()) || | ||||
(LHSType->isVectorType() && RHSType->isSVESizelessBuiltinType())) | (LHSType->isVectorType() && RHSType->isSVESizelessBuiltinType())) | ||||
if (Context.areCompatibleSveTypes(LHSType, RHSType) || | if (Context.areCompatibleSveTypes(LHSType, RHSType) || | ||||
Context.areLaxCompatibleSveTypes(LHSType, RHSType)) { | Context.areLaxCompatibleSveTypes(LHSType, RHSType)) { | ||||
Kind = CK_BitCast; | Kind = CK_BitCast; | ||||
return Compatible; | return Compatible; | ||||
} | } | ||||
// Allow assignments between fixed-length and sizeless RVV vectors. | |||||
if ((LHSType->isRVVSizelessBuiltinType() && RHSType->isVectorType()) || | |||||
(LHSType->isVectorType() && RHSType->isRVVSizelessBuiltinType())) { | |||||
if (Context.areCompatibleRVVTypes(LHSType, RHSType) || | |||||
Context.areLaxCompatibleRVVTypes(LHSType, RHSType)) { | |||||
Kind = CK_BitCast; | |||||
return Compatible; | |||||
} | |||||
} | |||||
return Incompatible; | return Incompatible; | ||||
} | } | ||||
// Diagnose attempts to convert between __ibm128, __float128 and long double | // Diagnose attempts to convert between __ibm128, __float128 and long double | ||||
// where such conversions currently can't be handled. | // where such conversions currently can't be handled. | ||||
if (unsupportedTypeConversion(*this, LHSType, RHSType)) | if (unsupportedTypeConversion(*this, LHSType, RHSType)) | ||||
return Incompatible; | return Incompatible; | ||||
▲ Show 20 Lines • Show All 845 Lines • ▼ Show 20 Lines | if (!IsCompAssign && | ||||
LHSVecType->getVectorKind() == VectorType::AltiVecBool && | LHSVecType->getVectorKind() == VectorType::AltiVecBool && | ||||
RHSVecType->getVectorKind() == VectorType::AltiVecVector && | RHSVecType->getVectorKind() == VectorType::AltiVecVector && | ||||
RHSVecType->getElementType()->isIntegerType()) { | RHSVecType->getElementType()->isIntegerType()) { | ||||
LHS = ImpCastExprToType(LHS.get(), RHSType, CK_BitCast); | LHS = ImpCastExprToType(LHS.get(), RHSType, CK_BitCast); | ||||
return RHSType; | return RHSType; | ||||
} | } | ||||
} | } | ||||
// Expressions containing fixed-length and sizeless SVE vectors are invalid | // Expressions containing fixed-length and sizeless SVE/RVV vectors are | ||||
// since the ambiguity can affect the ABI. | // invalid since the ambiguity can affect the ABI. | ||||
auto IsSveConversion = [](QualType FirstType, QualType SecondType) { | auto IsSveRVVConversion = [](QualType FirstType, QualType SecondType, | ||||
unsigned &SVEorRVV) { | |||||
const VectorType *VecType = SecondType->getAs<VectorType>(); | const VectorType *VecType = SecondType->getAs<VectorType>(); | ||||
return FirstType->isSizelessBuiltinType() && VecType && | SVEorRVV = 0; | ||||
(VecType->getVectorKind() == VectorType::SveFixedLengthDataVector || | if (FirstType->isSizelessBuiltinType() && VecType) { | ||||
VecType->getVectorKind() == | if (VecType->getVectorKind() == VectorType::SveFixedLengthDataVector || | ||||
VectorType::SveFixedLengthPredicateVector); | VecType->getVectorKind() == VectorType::SveFixedLengthPredicateVector) | ||||
return true; | |||||
if (VecType->getVectorKind() == VectorType::RVVFixedLengthDataVector) { | |||||
SVEorRVV = 1; | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
}; | }; | ||||
if (IsSveConversion(LHSType, RHSType) || IsSveConversion(RHSType, LHSType)) { | unsigned SVEorRVV; | ||||
Diag(Loc, diag::err_typecheck_sve_ambiguous) << LHSType << RHSType; | if (IsSveRVVConversion(LHSType, RHSType, SVEorRVV) || | ||||
IsSveRVVConversion(RHSType, LHSType, SVEorRVV)) { | |||||
Diag(Loc, diag::err_typecheck_sve_rvv_ambiguous) | |||||
<< SVEorRVV << LHSType << RHSType; | |||||
return QualType(); | return QualType(); | ||||
} | } | ||||
// Expressions containing GNU and SVE or RVV (fixed or sizeless) vectors are | // Expressions containing GNU and SVE or RVV (fixed or sizeless) vectors are | ||||
// invalid since the ambiguity can affect the ABI. | // invalid since the ambiguity can affect the ABI. | ||||
auto IsSveRVVGnuConversion = [](QualType FirstType, QualType SecondType, | auto IsSveRVVGnuConversion = [](QualType FirstType, QualType SecondType, | ||||
unsigned &SVEorRVV) { | unsigned &SVEorRVV) { | ||||
const VectorType *FirstVecType = FirstType->getAs<VectorType>(); | const VectorType *FirstVecType = FirstType->getAs<VectorType>(); | ||||
const VectorType *SecondVecType = SecondType->getAs<VectorType>(); | const VectorType *SecondVecType = SecondType->getAs<VectorType>(); | ||||
SVEorRVV = 0; | SVEorRVV = 0; | ||||
if (FirstVecType && SecondVecType) | if (FirstVecType && SecondVecType) { | ||||
return FirstVecType->getVectorKind() == VectorType::GenericVector && | if (FirstVecType->getVectorKind() == VectorType::GenericVector) { | ||||
(SecondVecType->getVectorKind() == | if (SecondVecType->getVectorKind() == | ||||
VectorType::SveFixedLengthDataVector || | VectorType::SveFixedLengthDataVector || | ||||
SecondVecType->getVectorKind() == | SecondVecType->getVectorKind() == | ||||
VectorType::SveFixedLengthPredicateVector); | VectorType::SveFixedLengthPredicateVector) | ||||
return true; | |||||
if (SecondVecType->getVectorKind() == | |||||
VectorType::RVVFixedLengthDataVector) { | |||||
SVEorRVV = 1; | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
if (SecondVecType && | if (SecondVecType && | ||||
SecondVecType->getVectorKind() == VectorType::GenericVector) { | SecondVecType->getVectorKind() == VectorType::GenericVector) { | ||||
if (FirstType->isSVESizelessBuiltinType()) | if (FirstType->isSVESizelessBuiltinType()) | ||||
return true; | return true; | ||||
if (FirstType->isRVVSizelessBuiltinType()) { | if (FirstType->isRVVSizelessBuiltinType()) { | ||||
SVEorRVV = 1; | SVEorRVV = 1; | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
}; | }; | ||||
unsigned SVEorRVV; | |||||
if (IsSveRVVGnuConversion(LHSType, RHSType, SVEorRVV) || | if (IsSveRVVGnuConversion(LHSType, RHSType, SVEorRVV) || | ||||
IsSveRVVGnuConversion(RHSType, LHSType, SVEorRVV)) { | IsSveRVVGnuConversion(RHSType, LHSType, SVEorRVV)) { | ||||
Diag(Loc, diag::err_typecheck_sve_rvv_gnu_ambiguous) | Diag(Loc, diag::err_typecheck_sve_rvv_gnu_ambiguous) | ||||
<< SVEorRVV << LHSType << RHSType; | << SVEorRVV << LHSType << RHSType; | ||||
return QualType(); | return QualType(); | ||||
} | } | ||||
// If there's a vector type and a scalar, try to convert the scalar to | // If there's a vector type and a scalar, try to convert the scalar to | ||||
▲ Show 20 Lines • Show All 10,491 Lines • Show Last 20 Lines |