1//===- CodeGen/ValueTypes.h - Low-Level Target independ. types --*- C++ -*-===// 3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4// See https://llvm.org/LICENSE.txt for license information. 5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7//===----------------------------------------------------------------------===// 9// This file defines the set of low-level target independent types which various 10// values in the code generator are. This allows the target specific behavior 11// of instructions to be described to target independent passes. 13//===----------------------------------------------------------------------===// 15#ifndef LLVM_CODEGEN_VALUETYPES_H 16#define LLVM_CODEGEN_VALUETYPES_H 32 /// Extended Value Type. Capable of holding value types which are not native 33 /// for any processor (such as the i12345 type), as well as the types an MVT 41constexprEVT() =
default;
52return LLVMTy != VT.LLVMTy;
56 /// Returns the EVT that represents a floating-point type with the given 57 /// number of bits. There are two floating-point types with 128 bits - this 58 /// returns f128 rather than ppcf128. 63 /// Returns the EVT that represents an integer with the given number of 69return getExtendedIntegerVT(Context,
BitWidth);
72 /// Returns the EVT that represents a vector NumElements in length, where 73 /// each element is of type VT. 75bool IsScalable =
false) {
79return getExtendedVectorVT(Context, VT, NumElements, IsScalable);
82 /// Returns the EVT that represents a vector EC.Min elements in length, 83 /// where each element is of type VT. 88return getExtendedVectorVT(Context, VT, EC);
91 /// Return a vector with the same number of elements as this vector, but 92 /// with the element type converted to an integer type with the same 97return changeExtendedVectorElementTypeToInteger();
100 /// Return a VT for a vector type whose attributes match ourselves 101 /// with the exception of the element type that is chosen by the caller. 105"Can't change simple vector VT to have extended element VT");
108return changeExtendedVectorElementType(EltVT);
111 /// Return a VT for a type whose attributes match ourselves with the 112 /// exception of the element type that is chosen by the caller. 118 /// Return the type converted to an equivalently sized integer or vector 119 /// with integer element type. Similar to changeVectorElementTypeToInteger, 120 /// but also handles scalars. 127return changeExtendedTypeToInteger();
130 /// Test if the given EVT has zero size, this will fail if called on a 136 /// Test if the given EVT is simple (as opposed to being extended). 141 /// Test if the given EVT is extended (as opposed to being simple). 146 /// Return true if this is a FP or a vector FP type. 148returnisSimple() ? V.isFloatingPoint() : isExtendedFloatingPoint();
151 /// Return true if this is an integer or a vector integer type. 153returnisSimple() ? V.isInteger() : isExtendedInteger();
156 /// Return true if this is an integer, but not a vector. 158returnisSimple() ? V.isScalarInteger() : isExtendedScalarInteger();
161 /// Return true if this is a vector type where the runtime 162 /// length is machine dependent 164returnisSimple() && V.isScalableTargetExtVT();
167 /// Return true if this is a vector value type. 169returnisSimple() ? V.isVector() : isExtendedVector();
172 /// Return true if this is a vector type where the runtime 173 /// length is machine dependent 175returnisSimple() ? V.isScalableVector() : isExtendedScalableVector();
178 /// Return true if this is a vector value type. 182returnisSimple() ? V.isFixedLengthVector()
183 : isExtendedFixedLengthVector();
186 /// Return true if the type is a scalable type. 191 /// Return true if this is a 16-bit vector type. 193returnisSimple() ? V.is16BitVector() : isExtended16BitVector();
196 /// Return true if this is a 32-bit vector type. 198returnisSimple() ? V.is32BitVector() : isExtended32BitVector();
201 /// Return true if this is a 64-bit vector type. 203returnisSimple() ? V.is64BitVector() : isExtended64BitVector();
206 /// Return true if this is a 128-bit vector type. 208returnisSimple() ? V.is128BitVector() : isExtended128BitVector();
211 /// Return true if this is a 256-bit vector type. 213returnisSimple() ? V.is256BitVector() : isExtended256BitVector();
216 /// Return true if this is a 512-bit vector type. 218returnisSimple() ? V.is512BitVector() : isExtended512BitVector();
221 /// Return true if this is a 1024-bit vector type. 223returnisSimple() ? V.is1024BitVector() : isExtended1024BitVector();
226 /// Return true if this is a 2048-bit vector type. 228returnisSimple() ? V.is2048BitVector() : isExtended2048BitVector();
231 /// Return true if this is an overloaded type for TableGen. 233return (V == MVT::iAny || V == MVT::fAny || V == MVT::vAny ||
237 /// Return true if the bit size is a multiple of 8. 242 /// Return true if the size is a power-of-two number of bytes. 247return BitSize >= 8 && !(BitSize & (BitSize - 1));
250 /// Return true if this has the same number of bits as VT. 252if (EVT::operator==(VT))
returntrue;
256 /// Return true if we know at compile time this has more bits than VT. 261 /// Return true if we know at compile time this has more than or the same 267 /// Return true if we know at compile time this has fewer bits than VT. 272 /// Return true if we know at compile time this has fewer than or the same 278 /// Return true if this has more bits than VT. 280if (EVT::operator==(VT))
returnfalse;
282"Comparison between scalable and fixed types");
286 /// Return true if this has no less bits than VT. 288if (EVT::operator==(VT))
returntrue;
290"Comparison between scalable and fixed types");
294 /// Return true if this has less bits than VT. 296if (EVT::operator==(VT))
returnfalse;
298"Comparison between scalable and fixed types");
302 /// Return true if this has no more bits than VT. 304if (EVT::operator==(VT))
returntrue;
306"Comparison between scalable and fixed types");
310 /// Return the SimpleValueType held in the specified simple EVT. 316 /// If this is a vector type, return the element type, otherwise return 322 /// Given a vector type, return the type of each element. 326return V.getVectorElementType();
327return getExtendedVectorElementType();
330 /// Given a vector type, return the number of elements it contains. 336"Possible incorrect use of EVT::getVectorNumElements() for " 337"scalable vector. Scalable flag may be dropped, use " 338"EVT::getVectorElementCount() instead");
340returnisSimple() ? V.getVectorNumElements()
341 : getExtendedVectorNumElements();
344// Given a (possibly scalable) vector type, return the ElementCount 348return V.getVectorElementCount();
350return getExtendedVectorElementCount();
353 /// Given a vector type, return the minimum number of elements it contains. 358 /// Given a RISCV vector tuple type, return the num_fields. 360return V.getRISCVVectorTupleNumFields();
363 /// Return the size of the specified value type in bits. 365 /// If the value type is a scalable vector type, the scalable property will 366 /// be set and the runtime size will be a positive integer multiple of the 370return V.getSizeInBits();
371return getExtendedSizeInBits();
374 /// Return the size of the specified fixed width value type in bits. The 375 /// function will assert if the type is scalable. 384 /// Return the number of bytes overwritten by a store of the specified value 387 /// If the value type is a scalable vector type, the scalable property will 388 /// be set and the runtime size will be a positive integer multiple of the 395// Return the number of bytes overwritten by a store of this value type or 396// this value type's element type in the case of a vector. 401 /// Return the number of bits overwritten by a store of the specified value 404 /// If the value type is a scalable vector type, the scalable property will 405 /// be set and the runtime size will be a positive integer multiple of the 411 /// Rounds the bit-width of the given integer EVT up to the nearest power of 412 /// two (and at least to eight), and returns the integer EVT with that 422 /// Finds the smallest simple value type that is greater than or equal to 423 /// half the width of this EVT. If no simple value type can be found, an 424 /// extended integer value type of half the size (rounded up) is returned. 428for (
unsigned IntVT = MVT::FIRST_INTEGER_VALUETYPE;
429 IntVT <= MVT::LAST_INTEGER_VALUETYPE; ++IntVT) {
437 /// Return a VT for an integer vector type with the size of the 438 /// elements doubled. The typed returned may be an extended type. 445// Return a VT for a vector type with the same element type but 446// half the number of elements. The type returned may be an 451assert(EltCnt.isKnownEven() &&
"Splitting vector, but not in half!");
455// Return a VT for a vector type with the same element type but 456// double the number of elements. The type returned may be an 464 /// Returns true if the given vector is a power of 2. 467return !(NElts & (NElts - 1));
470 /// Widens the length of the given vector EVT up to the nearest power of 2 471 /// and returns that type. 484 /// This function returns value type as a string, e.g. "i32". 487 /// Support for debugging, callable in GDB: VT.dump() 490 /// Implement operator<<. 495 /// This method returns an LLVM type corresponding to the specified EVT. 496 /// For integer types, this returns an unsigned type. Note that this will 497 /// abort for types that cannot be represented. 500 /// Return the value type corresponding to the specified type. 501 /// If HandleUnknown is true, unknown types are returned as Other, 502 /// otherwise they are invalid. 503 /// NB: This includes pointer types, which require a DataLayout to convert 504 /// to a concrete value type. 511return (intptr_t)(LLVMTy);
514 /// A meaningless but well-behaved order, useful for constructing 518if (L.V.SimpleTy == R.V.SimpleTy)
519return L.LLVMTy < R.LLVMTy;
521return L.V.SimpleTy < R.V.SimpleTy;
525 /// Returns an APFloat semantics tag appropriate for the value type. If this 526 /// is a vector type, the element semantics are returned. 530// Methods for handling the Extended-type case in functions above. 531// These are all out-of-line to prevent users of this header file 532// from having a dependency on Type.h. 533EVT changeExtendedTypeToInteger()
const;
534EVT changeExtendedVectorElementType(
EVT EltVT)
const;
535EVT changeExtendedVectorElementTypeToInteger()
const;
555EVT getExtendedVectorElementType()
const;
565}
// end namespace llvm 567#endif// LLVM_CODEGEN_VALUETYPES_H assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static constexpr ElementCount get(ScalarTy MinVal, bool Scalable)
This is an important class for using LLVM in a threaded context.
static MVT getFloatingPointVT(unsigned BitWidth)
@ INVALID_SIMPLE_VALUE_TYPE
MVT changeVectorElementType(MVT EltVT) const
Return a VT for a vector type whose attributes match ourselves with the exception of the element type...
MVT changeTypeToInteger()
Return the type converted to an equivalently sized integer or vector with integer element type.
static MVT getVectorVT(MVT VT, unsigned NumElements)
static MVT getIntegerVT(unsigned BitWidth)
MVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
The instances of the Type class are immutable: once they are created, they are never changed.
constexpr bool isKnownMultipleOf(ScalarTy RHS) const
This function tells the caller whether the element count is known at compile time to be a multiple of...
constexpr ScalarTy getFixedValue() const
static constexpr bool isKnownLE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
static constexpr bool isKnownLT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
constexpr bool isScalable() const
Returns whether the quantity is scaled by a runtime quantity (vscale).
constexpr ScalarTy getKnownMinValue() const
Returns the minimum value this quantity can represent.
constexpr bool isZero() const
static constexpr bool isKnownGT(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
static constexpr bool isKnownGE(const FixedOrScalableQuantity &LHS, const FixedOrScalableQuantity &RHS)
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
This is an optimization pass for GlobalISel generic memory operations.
unsigned Log2_32_Ceil(uint32_t Value)
Return the ceil log base 2 of the specified value, 32 if the value is zero.
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
void reportInvalidSizeRequest(const char *Msg)
Reports a diagnostic message to indicate an invalid size request has been done on a scalable vector.
constexpr unsigned BitWidth
A meaningless but well-behaved order, useful for constructing containers.
bool operator()(EVT L, EVT R) const
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
EVT getPow2VectorType(LLVMContext &Context) const
Widens the length of the given vector EVT up to the nearest power of 2 and returns that type.
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
constexpr EVT(MVT::SimpleValueType SVT)
intptr_t getRawBits() const
bool knownBitsLE(EVT VT) const
Return true if we know at compile time this has fewer than or the same bits as VT.
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT.
EVT changeTypeToInteger() const
Return the type converted to an equivalently sized integer or vector with integer element type.
uint64_t getScalarStoreSize() const
bool isOverloaded() const
Return true if this is an overloaded type for TableGen.
bool bitsGT(EVT VT) const
Return true if this has more bits than VT.
bool bitsLT(EVT VT) const
Return true if this has less bits than VT.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
ElementCount getVectorElementCount() const
EVT getDoubleNumVectorElementsVT(LLVMContext &Context) const
bool is32BitVector() const
Return true if this is a 32-bit vector type.
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
bool isByteSized() const
Return true if the bit size is a multiple of 8.
EVT changeElementType(EVT EltVT) const
Return a VT for a type whose attributes match ourselves with the exception of the element type that i...
bool is1024BitVector() const
Return true if this is a 1024-bit vector type.
bool knownBitsGT(EVT VT) const
Return true if we know at compile time this has more bits than VT.
unsigned getVectorMinNumElements() const
Given a vector type, return the minimum number of elements it contains.
unsigned getRISCVVectorTupleNumFields() const
Given a RISCV vector tuple type, return the num_fields.
uint64_t getScalarSizeInBits() const
EVT getHalfSizedIntegerVT(LLVMContext &Context) const
Finds the smallest simple value type that is greater than or equal to half the width of this EVT.
bool isPow2VectorType() const
Returns true if the given vector is a power of 2.
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Return the value type corresponding to the specified type.
TypeSize getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
void dump() const
Support for debugging, callable in GDB: VT.dump()
bool is128BitVector() const
Return true if this is a 128-bit vector type.
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
bool is2048BitVector() const
Return true if this is a 2048-bit vector type.
bool isRISCVVectorTuple() const
Return true if this is a vector value type.
uint64_t getFixedSizeInBits() const
Return the size of the specified fixed width value type in bits.
EVT widenIntegerVectorElementType(LLVMContext &Context) const
Return a VT for an integer vector type with the size of the elements doubled.
bool knownBitsLT(EVT VT) const
Return true if we know at compile time this has fewer bits than VT.
bool isScalableVT() const
Return true if the type is a scalable type.
bool is512BitVector() const
Return true if this is a 512-bit vector type.
bool isFixedLengthVector() const
std::string getEVTString() const
This function returns value type as a string, e.g. "i32".
static EVT getFloatingPointVT(unsigned BitWidth)
Returns the EVT that represents a floating-point type with the given number of bits.
bool operator!=(EVT VT) const
EVT getRoundIntegerType(LLVMContext &Context) const
Rounds the bit-width of the given integer EVT up to the nearest power of two (and at least to eight),...
bool isVector() const
Return true if this is a vector value type.
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
bool is16BitVector() const
Return true if this is a 16-bit vector type.
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
bool is256BitVector() const
Return true if this is a 256-bit vector type.
bool bitsEq(EVT VT) const
Return true if this has the same number of bits as VT.
Type * getTypeForEVT(LLVMContext &Context) const
This method returns an LLVM type corresponding to the specified EVT.
bool isRound() const
Return true if the size is a power-of-two number of bytes.
static EVT getVectorVT(LLVMContext &Context, EVT VT, ElementCount EC)
Returns the EVT that represents a vector EC.Min elements in length, where each element is of type VT.
bool isScalableVector() const
Return true if this is a vector type where the runtime length is machine dependent.
bool knownBitsGE(EVT VT) const
Return true if we know at compile time this has more than or the same bits as VT.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
bool isExtended() const
Test if the given EVT is extended (as opposed to being simple).
void print(raw_ostream &OS) const
Implement operator<<.
bool isScalableTargetExtVT() const
Return true if this is a vector type where the runtime length is machine dependent.
bool isScalarInteger() const
Return true if this is an integer, but not a vector.
EVT changeVectorElementType(EVT EltVT) const
Return a VT for a vector type whose attributes match ourselves with the exception of the element type...
const fltSemantics & getFltSemantics() const
Returns an APFloat semantics tag appropriate for the value type.
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
bool operator==(EVT VT) const
bool isZeroSized() const
Test if the given EVT has zero size, this will fail if called on a scalable type.
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
EVT getHalfNumVectorElementsVT(LLVMContext &Context) const
bool isInteger() const
Return true if this is an integer or a vector integer type.
bool is64BitVector() const
Return true if this is a 64-bit vector type.