mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
[SVE] Make VectorType::getNumElements() complain for scalable vectors
Summary: Piggy-back off of TypeSize's STRICT_FIXED_SIZE_VECTORS flag and: - if it is defined, assert that the vector is not scalable - if it is not defined, complain if the vector is scalable Reviewers: efriedma, sdesmalen, c-rhodes Reviewed By: sdesmalen Subscribers: hiraditya, mgorny, tschuett, rkruppe, psnobl, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D78576
This commit is contained in:
parent
196afafb83
commit
f55cc8b846
@ -423,15 +423,16 @@ endif()
|
|||||||
option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
|
option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
|
||||||
|
|
||||||
# While adding scalable vector support to LLVM, we temporarily want to
|
# While adding scalable vector support to LLVM, we temporarily want to
|
||||||
# allow an implicit conversion of TypeSize to uint64_t. This CMake flag
|
# allow an implicit conversion of TypeSize to uint64_t, and to allow
|
||||||
# enables a more strict conversion where it asserts that the type is not
|
# code to get the fixed number of elements from a possibly scalable vector.
|
||||||
# a scalable vector type.
|
# This CMake flag enables a more strict mode where it asserts that the type
|
||||||
|
# is not a scalable vector type.
|
||||||
#
|
#
|
||||||
# Enabling this flag makes it easier to find cases where the compiler makes
|
# Enabling this flag makes it easier to find cases where the compiler makes
|
||||||
# assumptions on the size being 'fixed size', when building tests for
|
# assumptions on the size being 'fixed size', when building tests for
|
||||||
# SVE/SVE2 or other scalable vector architectures.
|
# SVE/SVE2 or other scalable vector architectures.
|
||||||
option(LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS
|
option(LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS
|
||||||
"Enable assertions that type is not scalable in implicit conversion from TypeSize to uint64_t" OFF)
|
"Enable assertions that type is not scalable in implicit conversion from TypeSize to uint64_t and calls to getNumElements" OFF)
|
||||||
|
|
||||||
set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
|
set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING
|
||||||
"Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
|
"Enable abi-breaking checks. Can be WITH_ASSERTS, FORCE_ON or FORCE_OFF.")
|
||||||
|
@ -417,7 +417,21 @@ public:
|
|||||||
/// Get the number of elements in this vector. It does not make sense to call
|
/// Get the number of elements in this vector. It does not make sense to call
|
||||||
/// this function on a scalable vector, and this will be moved into
|
/// this function on a scalable vector, and this will be moved into
|
||||||
/// FixedVectorType in a future commit
|
/// FixedVectorType in a future commit
|
||||||
unsigned getNumElements() const { return EC.Min; }
|
unsigned getNumElements() const {
|
||||||
|
ElementCount EC = getElementCount();
|
||||||
|
#ifdef STRICT_FIXED_SIZE_VECTORS
|
||||||
|
assert(!EC.Scalable &&
|
||||||
|
"Request for fixed number of elements from scalable vector");
|
||||||
|
return EC.Min;
|
||||||
|
#else
|
||||||
|
if (EC.Scalable)
|
||||||
|
WithColor::warning()
|
||||||
|
<< "The code that requested the fixed number of elements has made "
|
||||||
|
"the assumption that this vector is not scalable. This assumption "
|
||||||
|
"was not correct, and this may lead to broken code\n";
|
||||||
|
return EC.Min;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
Type *getElementType() const { return ContainedType; }
|
Type *getElementType() const { return ContainedType; }
|
||||||
|
|
||||||
|
@ -653,10 +653,11 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
|
|||||||
case Type::FixedVectorTyID:
|
case Type::FixedVectorTyID:
|
||||||
case Type::ScalableVectorTyID: {
|
case Type::ScalableVectorTyID: {
|
||||||
VectorType *PTy = cast<VectorType>(Ty);
|
VectorType *PTy = cast<VectorType>(Ty);
|
||||||
|
ElementCount EC = PTy->getElementCount();
|
||||||
OS << "<";
|
OS << "<";
|
||||||
if (PTy->isScalable())
|
if (EC.Scalable)
|
||||||
OS << "vscale x ";
|
OS << "vscale x ";
|
||||||
OS << PTy->getNumElements() << " x ";
|
OS << EC.Min << " x ";
|
||||||
print(PTy->getElementType(), OS);
|
print(PTy->getElementType(), OS);
|
||||||
OS << '>';
|
OS << '>';
|
||||||
return;
|
return;
|
||||||
|
@ -644,10 +644,10 @@ static std::string getMangledTypeStr(Type* Ty) {
|
|||||||
// Ensure nested function types are distinguishable.
|
// Ensure nested function types are distinguishable.
|
||||||
Result += "f";
|
Result += "f";
|
||||||
} else if (VectorType* VTy = dyn_cast<VectorType>(Ty)) {
|
} else if (VectorType* VTy = dyn_cast<VectorType>(Ty)) {
|
||||||
if (VTy->isScalable())
|
ElementCount EC = VTy->getElementCount();
|
||||||
|
if (EC.Scalable)
|
||||||
Result += "nx";
|
Result += "nx";
|
||||||
Result += "v" + utostr(VTy->getNumElements()) +
|
Result += "v" + utostr(EC.Min) + getMangledTypeStr(VTy->getElementType());
|
||||||
getMangledTypeStr(VTy->getElementType());
|
|
||||||
} else if (Ty) {
|
} else if (Ty) {
|
||||||
switch (Ty->getTypeID()) {
|
switch (Ty->getTypeID()) {
|
||||||
default: llvm_unreachable("Unhandled type");
|
default: llvm_unreachable("Unhandled type");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user