[ValueTypes] Add EVT::isFixedLengthVector

Summary:
Related to D75672, this patch adds EVT::isFixedLengthVector to determine
if the underlying vector type is of fixed length.

An assert is introduced in EVT::getVectorNumElements that triggers for
types that aren't fixed length. This is currently guarded by a flag
added D75297 that is off by default and has been renamed to the more
generic ENABLE_STRICT_FIXED_SIZE_VECTORS.

Ideally we want to get rid of getVectorNumElements but a quick grep
shows there are >350 uses in lib/CodeGen and 75 in lib/Target/AArch64
alone. All of these probably aren't EVT::getVectorNumElements (some may
be the MVT equivalent), but there are many places to fixup and having
the assert on by default would make the SVE upstreaming effort
difficult.

Reviewers: sdesmalen, efriedma, ctetreau, huntergr, rengolin

Reviewed By: efriedma

Subscribers: mgorny, kristof.beyls, hiraditya, danielkiss, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D76376
This commit is contained in:
Cullen Rhodes 2020-03-18 16:51:45 +00:00
parent 6e0aaafbc7
commit 5c296df0c0
5 changed files with 24 additions and 4 deletions

View File

@ -418,7 +418,7 @@ option(LLVM_ENABLE_EXPENSIVE_CHECKS "Enable expensive checks" OFF)
# Enabling this flag makes it easier to find cases where the compiler makes
# assumptions on the size being 'fixed size', when building tests for
# SVE/SVE2 or other scalable vector architectures.
option(LLVM_ENABLE_STRICT_IMPLICIT_CONVERSION_TYPESIZE
option(LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS
"Enable assertions that type is not scalable in implicit conversion from TypeSize to uint64_t" OFF)
set(LLVM_ABI_BREAKING_CHECKS "WITH_ASSERTS" CACHE STRING

View File

@ -95,8 +95,8 @@ if(LLVM_ENABLE_EXPENSIVE_CHECKS)
endif()
endif()
if (LLVM_ENABLE_STRICT_IMPLICIT_CONVERSION_TYPESIZE)
add_definitions(-DSTRICT_IMPLICIT_CONVERSION_TYPESIZE)
if (LLVM_ENABLE_STRICT_FIXED_SIZE_VECTORS)
add_definitions(-DSTRICT_FIXED_SIZE_VECTORS)
endif()
string(TOUPPER "${LLVM_ABI_BREAKING_CHECKS}" uppercase_LLVM_ABI_BREAKING_CHECKS)

View File

@ -19,6 +19,7 @@
#include "llvm/Support/MachineValueType.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/TypeSize.h"
#include "llvm/Support/WithColor.h"
#include <cassert>
#include <cstdint>
#include <string>
@ -163,6 +164,11 @@ namespace llvm {
return V.isScalableVector();
}
bool isFixedLengthVector() const {
return isSimple() ? V.isFixedLengthVector()
: isExtendedFixedLengthVector();
}
/// Return true if this is a 16-bit vector type.
bool is16BitVector() const {
return isSimple() ? V.is16BitVector() : isExtended16BitVector();
@ -273,7 +279,16 @@ namespace llvm {
/// Given a vector type, return the number of elements it contains.
unsigned getVectorNumElements() const {
#ifdef STRICT_FIXED_SIZE_VECTORS
assert(isFixedLengthVector() && "Invalid vector type!");
#else
assert(isVector() && "Invalid vector type!");
if (isScalableVector())
WithColor::warning()
<< "Possible incorrect use of EVT::getVectorNumElements() for "
"scalable vector. Scalable flag may be dropped, use"
"EVT::getVectorElementCount() instead\n";
#endif
if (isSimple())
return V.getVectorNumElements();
return getExtendedVectorNumElements();
@ -442,6 +457,7 @@ namespace llvm {
bool isExtended512BitVector() const LLVM_READONLY;
bool isExtended1024BitVector() const LLVM_READONLY;
bool isExtended2048BitVector() const LLVM_READONLY;
bool isExtendedFixedLengthVector() const LLVM_READONLY;
EVT getExtendedVectorElementType() const;
unsigned getExtendedVectorNumElements() const LLVM_READONLY;
TypeSize getExtendedSizeInBits() const LLVM_READONLY;

View File

@ -165,7 +165,7 @@ public:
// bail out early for scalable vectors and use getFixedSize()
// }
operator uint64_t() const {
#ifdef STRICT_IMPLICIT_CONVERSION_TYPESIZE
#ifdef STRICT_FIXED_SIZE_VECTORS
return getFixedSize();
#else
if (isScalable())

View File

@ -92,6 +92,10 @@ bool EVT::isExtended2048BitVector() const {
return isExtendedVector() && getExtendedSizeInBits() == 2048;
}
bool EVT::isExtendedFixedLengthVector() const {
return isExtendedVector() && !cast<VectorType>(LLVMTy)->isScalable();
}
EVT EVT::getExtendedVectorElementType() const {
assert(isExtended() && "Type is not extended!");
return EVT::getEVT(cast<VectorType>(LLVMTy)->getElementType());