diff --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt --- a/llvm/CMakeLists.txt +++ b/llvm/CMakeLists.txt @@ -418,7 +418,7 @@ # 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 diff --git a/llvm/cmake/modules/HandleLLVMOptions.cmake b/llvm/cmake/modules/HandleLLVMOptions.cmake --- a/llvm/cmake/modules/HandleLLVMOptions.cmake +++ b/llvm/cmake/modules/HandleLLVMOptions.cmake @@ -95,8 +95,8 @@ 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) diff --git a/llvm/include/llvm/CodeGen/ValueTypes.h b/llvm/include/llvm/CodeGen/ValueTypes.h --- a/llvm/include/llvm/CodeGen/ValueTypes.h +++ b/llvm/include/llvm/CodeGen/ValueTypes.h @@ -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 #include #include @@ -163,6 +164,11 @@ 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 @@ /// 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 @@ 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; diff --git a/llvm/include/llvm/Support/TypeSize.h b/llvm/include/llvm/Support/TypeSize.h --- a/llvm/include/llvm/Support/TypeSize.h +++ b/llvm/include/llvm/Support/TypeSize.h @@ -165,7 +165,7 @@ // 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()) diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp --- a/llvm/lib/CodeGen/ValueTypes.cpp +++ b/llvm/lib/CodeGen/ValueTypes.cpp @@ -92,6 +92,10 @@ return isExtendedVector() && getExtendedSizeInBits() == 2048; } +bool EVT::isExtendedFixedLengthVector() const { + return isExtendedVector() && !cast(LLVMTy)->isScalable(); +} + EVT EVT::getExtendedVectorElementType() const { assert(isExtended() && "Type is not extended!"); return EVT::getEVT(cast(LLVMTy)->getElementType());