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/AST/ASTContext.cpp
- This file is larger than 256 KB, so syntax highlighting is disabled by default.
Show First 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | |||||
#include "llvm/Frontend/OpenMP/OMPIRBuilder.h" | #include "llvm/Frontend/OpenMP/OMPIRBuilder.h" | ||||
#include "llvm/Support/Capacity.h" | #include "llvm/Support/Capacity.h" | ||||
#include "llvm/Support/Casting.h" | #include "llvm/Support/Casting.h" | ||||
#include "llvm/Support/Compiler.h" | #include "llvm/Support/Compiler.h" | ||||
#include "llvm/Support/ErrorHandling.h" | #include "llvm/Support/ErrorHandling.h" | ||||
#include "llvm/Support/MD5.h" | #include "llvm/Support/MD5.h" | ||||
#include "llvm/Support/MathExtras.h" | #include "llvm/Support/MathExtras.h" | ||||
#include "llvm/Support/raw_ostream.h" | #include "llvm/Support/raw_ostream.h" | ||||
#include "llvm/TargetParser/RISCVTargetParser.h" | |||||
#include "llvm/TargetParser/Triple.h" | #include "llvm/TargetParser/Triple.h" | ||||
#include <algorithm> | #include <algorithm> | ||||
#include <cassert> | #include <cassert> | ||||
#include <cstddef> | #include <cstddef> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <cstdlib> | #include <cstdlib> | ||||
#include <map> | #include <map> | ||||
#include <memory> | #include <memory> | ||||
▲ Show 20 Lines • Show All 1,909 Lines • ▼ Show 20 Lines | if (TargetVectorAlign && TargetVectorAlign < Align) | ||||
Align = TargetVectorAlign; | Align = TargetVectorAlign; | ||||
if (VT->getVectorKind() == VectorType::SveFixedLengthDataVector) | if (VT->getVectorKind() == VectorType::SveFixedLengthDataVector) | ||||
// Adjust the alignment for fixed-length SVE vectors. This is important | // Adjust the alignment for fixed-length SVE vectors. This is important | ||||
// for non-power-of-2 vector lengths. | // for non-power-of-2 vector lengths. | ||||
Align = 128; | Align = 128; | ||||
else if (VT->getVectorKind() == VectorType::SveFixedLengthPredicateVector) | else if (VT->getVectorKind() == VectorType::SveFixedLengthPredicateVector) | ||||
// Adjust the alignment for fixed-length SVE predicates. | // Adjust the alignment for fixed-length SVE predicates. | ||||
Align = 16; | Align = 16; | ||||
else if (VT->getVectorKind() == VectorType::RVVFixedLengthDataVector) | |||||
// Adjust the alignment for fixed-length RVV vectors. | |||||
Align = 64; | |||||
break; | break; | ||||
} | } | ||||
case Type::ConstantMatrix: { | case Type::ConstantMatrix: { | ||||
const auto *MT = cast<ConstantMatrixType>(T); | const auto *MT = cast<ConstantMatrixType>(T); | ||||
TypeInfo ElementInfo = getTypeInfo(MT->getElementType()); | TypeInfo ElementInfo = getTypeInfo(MT->getElementType()); | ||||
// The internal layout of a matrix value is implementation defined. | // The internal layout of a matrix value is implementation defined. | ||||
// Initially be ABI compatible with arrays with respect to alignment and | // Initially be ABI compatible with arrays with respect to alignment and | ||||
▲ Show 20 Lines • Show All 7,442 Lines • ▼ Show 20 Lines | if (First->getNumElements() == Second->getNumElements() && | ||||
hasSameType(First->getElementType(), Second->getElementType()) && | hasSameType(First->getElementType(), Second->getElementType()) && | ||||
First->getVectorKind() != VectorType::AltiVecPixel && | First->getVectorKind() != VectorType::AltiVecPixel && | ||||
First->getVectorKind() != VectorType::AltiVecBool && | First->getVectorKind() != VectorType::AltiVecBool && | ||||
Second->getVectorKind() != VectorType::AltiVecPixel && | Second->getVectorKind() != VectorType::AltiVecPixel && | ||||
Second->getVectorKind() != VectorType::AltiVecBool && | Second->getVectorKind() != VectorType::AltiVecBool && | ||||
First->getVectorKind() != VectorType::SveFixedLengthDataVector && | First->getVectorKind() != VectorType::SveFixedLengthDataVector && | ||||
First->getVectorKind() != VectorType::SveFixedLengthPredicateVector && | First->getVectorKind() != VectorType::SveFixedLengthPredicateVector && | ||||
Second->getVectorKind() != VectorType::SveFixedLengthDataVector && | Second->getVectorKind() != VectorType::SveFixedLengthDataVector && | ||||
Second->getVectorKind() != VectorType::SveFixedLengthPredicateVector) | Second->getVectorKind() != VectorType::SveFixedLengthPredicateVector && | ||||
First->getVectorKind() != VectorType::RVVFixedLengthDataVector && | |||||
Second->getVectorKind() != VectorType::RVVFixedLengthDataVector) | |||||
return true; | return true; | ||||
return false; | return false; | ||||
} | } | ||||
/// getSVETypeSize - Return SVE vector or predicate register size. | /// getSVETypeSize - Return SVE vector or predicate register size. | ||||
static uint64_t getSVETypeSize(ASTContext &Context, const BuiltinType *Ty) { | static uint64_t getSVETypeSize(ASTContext &Context, const BuiltinType *Ty) { | ||||
assert(Ty->isVLSTBuiltinType() && "Invalid SVE Type"); | assert(Ty->isVLSTBuiltinType() && "Invalid SVE Type"); | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | auto IsLaxCompatible = [this](QualType FirstType, QualType SecondType) { | ||||
return false; | return false; | ||||
}; | }; | ||||
return IsLaxCompatible(FirstType, SecondType) || | return IsLaxCompatible(FirstType, SecondType) || | ||||
IsLaxCompatible(SecondType, FirstType); | IsLaxCompatible(SecondType, FirstType); | ||||
} | } | ||||
/// getRVVTypeSize - Return RVV vector register size. | |||||
static uint64_t getRVVTypeSize(ASTContext &Context, const BuiltinType *Ty) { | |||||
assert(Ty->isRVVVLSBuiltinType() && "Invalid RVV Type"); | |||||
auto VScale = Context.getTargetInfo().getVScaleRange(Context.getLangOpts()); | |||||
return VScale ? VScale->first * llvm::RISCV::RVVBitsPerBlock : 0; | |||||
} | |||||
bool ASTContext::areCompatibleRVVTypes(QualType FirstType, | |||||
QualType SecondType) { | |||||
assert( | |||||
((FirstType->isRVVSizelessBuiltinType() && SecondType->isVectorType()) || | |||||
(FirstType->isVectorType() && SecondType->isRVVSizelessBuiltinType())) && | |||||
"Expected RVV builtin type and vector type!"); | |||||
auto IsValidCast = [this](QualType FirstType, QualType SecondType) { | |||||
if (const auto *BT = FirstType->getAs<BuiltinType>()) { | |||||
if (const auto *VT = SecondType->getAs<VectorType>()) { | |||||
// Predicates have the same representation as uint8 so we also have to | |||||
// check the kind to make these types incompatible. | |||||
if (VT->getVectorKind() == VectorType::RVVFixedLengthDataVector) | |||||
return FirstType->isRVVVLSBuiltinType() && | |||||
VT->getElementType().getCanonicalType() == | |||||
FirstType->getRVVEltType(*this); | |||||
if (VT->getVectorKind() == VectorType::GenericVector) | |||||
return getTypeSize(SecondType) == getRVVTypeSize(*this, BT) && | |||||
hasSameType(VT->getElementType(), | |||||
getBuiltinVectorTypeInfo(BT).ElementType); | |||||
} | |||||
} | |||||
return false; | |||||
}; | |||||
return IsValidCast(FirstType, SecondType) || | |||||
IsValidCast(SecondType, FirstType); | |||||
} | |||||
bool ASTContext::areLaxCompatibleRVVTypes(QualType FirstType, | |||||
QualType SecondType) { | |||||
assert( | |||||
((FirstType->isRVVSizelessBuiltinType() && SecondType->isVectorType()) || | |||||
(FirstType->isVectorType() && SecondType->isRVVSizelessBuiltinType())) && | |||||
"Expected RVV builtin type and vector type!"); | |||||
auto IsLaxCompatible = [this](QualType FirstType, QualType SecondType) { | |||||
const auto *BT = FirstType->getAs<BuiltinType>(); | |||||
if (!BT) | |||||
return false; | |||||
const auto *VecTy = SecondType->getAs<VectorType>(); | |||||
if (VecTy && | |||||
(VecTy->getVectorKind() == VectorType::RVVFixedLengthDataVector || | |||||
VecTy->getVectorKind() == VectorType::GenericVector)) { | |||||
const LangOptions::LaxVectorConversionKind LVCKind = | |||||
getLangOpts().getLaxVectorConversions(); | |||||
// If __riscv_v_fixed_vlen != N do not allow GNU vector lax conversion. | |||||
if (VecTy->getVectorKind() == VectorType::GenericVector && | |||||
getTypeSize(SecondType) != getRVVTypeSize(*this, BT)) | |||||
return false; | |||||
// If -flax-vector-conversions=all is specified, the types are | |||||
// certainly compatible. | |||||
if (LVCKind == LangOptions::LaxVectorConversionKind::All) | |||||
return true; | |||||
// If -flax-vector-conversions=integer is specified, the types are | |||||
// compatible if the elements are integer types. | |||||
if (LVCKind == LangOptions::LaxVectorConversionKind::Integer) | |||||
return VecTy->getElementType().getCanonicalType()->isIntegerType() && | |||||
FirstType->getRVVEltType(*this)->isIntegerType(); | |||||
} | |||||
return false; | |||||
}; | |||||
return IsLaxCompatible(FirstType, SecondType) || | |||||
IsLaxCompatible(SecondType, FirstType); | |||||
} | |||||
bool ASTContext::hasDirectOwnershipQualifier(QualType Ty) const { | bool ASTContext::hasDirectOwnershipQualifier(QualType Ty) const { | ||||
while (true) { | while (true) { | ||||
// __strong id | // __strong id | ||||
if (const AttributedType *Attr = dyn_cast<AttributedType>(Ty)) { | if (const AttributedType *Attr = dyn_cast<AttributedType>(Ty)) { | ||||
if (Attr->getAttrKind() == attr::ObjCOwnership) | if (Attr->getAttrKind() == attr::ObjCOwnership) | ||||
return true; | return true; | ||||
Ty = Attr->getModifiedType(); | Ty = Attr->getModifiedType(); | ||||
▲ Show 20 Lines • Show All 3,945 Lines • Show Last 20 Lines |