Skip to content

Commit 2dea3f1

Browse files
[SVE] Add new VectorType subclasses
Summary: Introduce new types for fixed width and scalable vectors. Does not remove getNumElements yet so as to not break code during transition period. Reviewers: deadalnix, efriedma, sdesmalen, craig.topper, huntergr Reviewed By: sdesmalen Subscribers: jholewinski, arsenm, jvesely, nhaehnle, mehdi_amini, rriddle, jpienaar, burmako, shauheen, antiagainst, nicolasvasilache, csigg, arpith-jacob, mgester, lucyrfox, liufengdb, kerbowa, Joonsoo, grosul1, frgossen, lldb-commits, tschuett, hiraditya, rkruppe, psnobl, llvm-commits Tags: #llvm, #lldb Differential Revision: https://reviews.llvm.org/D77587
1 parent 3df8135 commit 2dea3f1

23 files changed

+235
-152
lines changed

lldb/source/Expression/IRInterpreter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,8 @@ bool IRInterpreter::CanInterpret(llvm::Module &module, llvm::Function &function,
597597
switch (operand_type->getTypeID()) {
598598
default:
599599
break;
600-
case Type::VectorTyID: {
600+
case Type::FixedVectorTyID:
601+
case Type::ScalableVectorTyID: {
601602
LLDB_LOGF(log, "Unsupported operand type: %s",
602603
PrintType(operand_type).c_str());
603604
error.SetErrorString(unsupported_operand_error);

llvm/include/llvm-c/Core.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,11 @@ typedef enum {
157157
LLVMStructTypeKind, /**< Structures */
158158
LLVMArrayTypeKind, /**< Arrays */
159159
LLVMPointerTypeKind, /**< Pointers */
160-
LLVMVectorTypeKind, /**< SIMD 'packed' format, or other vector type */
161160
LLVMMetadataTypeKind, /**< Metadata */
162161
LLVMX86_MMXTypeKind, /**< X86 MMX */
163-
LLVMTokenTypeKind /**< Tokens */
162+
LLVMTokenTypeKind, /**< Tokens */
163+
LLVMFixedVectorTypeKind, /**< Fixed width SIMD vector type */
164+
LLVMScalableVectorTypeKind /**< Scalable SIMD vector type */
164165
} LLVMTypeKind;
165166

166167
typedef enum {

llvm/include/llvm/IR/DataLayout.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,8 @@ inline TypeSize DataLayout::getTypeSizeInBits(Type *Ty) const {
664664
// only 80 bits contain information.
665665
case Type::X86_FP80TyID:
666666
return TypeSize::Fixed(80);
667-
case Type::VectorTyID: {
667+
case Type::FixedVectorTyID:
668+
case Type::ScalableVectorTyID: {
668669
VectorType *VTy = cast<VectorType>(Ty);
669670
auto EltCnt = VTy->getElementCount();
670671
uint64_t MinBits = EltCnt.Min *

llvm/include/llvm/IR/DerivedTypes.h

+50-21
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ uint64_t Type::getArrayNumElements() const {
386386
return cast<ArrayType>(this)->getNumElements();
387387
}
388388

389-
/// Class to represent vector types.
389+
/// Base class of all SIMD vector types
390390
class VectorType : public Type {
391391
/// A fully specified VectorType is of the form <vscale x n x Ty>. 'n' is the
392392
/// minimum number of elements of type Ty contained within the vector, and
@@ -403,24 +403,22 @@ class VectorType : public Type {
403403

404404
/// The element type of the vector.
405405
Type *ContainedType;
406-
/// Minumum number of elements in the vector.
407-
uint64_t NumElements;
408406

409-
VectorType(Type *ElType, unsigned NumEl, bool Scalable = false);
410-
VectorType(Type *ElType, ElementCount EC);
407+
/// The element count of this vector
408+
ElementCount EC;
411409

412-
// If true, the total number of elements is an unknown multiple of the
413-
// minimum 'NumElements'. Otherwise the total number of elements is exactly
414-
// equal to 'NumElements'.
415-
bool Scalable;
410+
protected:
411+
VectorType(Type *ElType, ElementCount EC, Type::TypeID TID);
416412

417413
public:
418414
VectorType(const VectorType &) = delete;
419415
VectorType &operator=(const VectorType &) = delete;
420416

421-
/// For scalable vectors, this will return the minimum number of elements
422-
/// in the vector.
423-
unsigned getNumElements() const { return NumElements; }
417+
/// Get the number of elements in this vector. It does not make sense to call
418+
/// this function on a scalable vector, and this will be moved into
419+
/// FixedVectorType in a future commit
420+
unsigned getNumElements() const { return EC.Min; }
421+
424422
Type *getElementType() const { return ContainedType; }
425423

426424
/// This static method is the primary way to construct an VectorType.
@@ -430,6 +428,10 @@ class VectorType : public Type {
430428
return VectorType::get(ElementType, {NumElements, Scalable});
431429
}
432430

431+
static VectorType *get(Type *ElementType, const VectorType *Other) {
432+
return VectorType::get(ElementType, Other->getElementCount());
433+
}
434+
433435
/// This static method gets a VectorType with the same number of elements as
434436
/// the input type, and the element type is an integer type of the same width
435437
/// as the input element type.
@@ -507,26 +509,53 @@ class VectorType : public Type {
507509

508510
/// Return an ElementCount instance to represent the (possibly scalable)
509511
/// number of elements in the vector.
510-
ElementCount getElementCount() const {
511-
uint64_t MinimumEltCnt = getNumElements();
512-
assert(MinimumEltCnt <= UINT_MAX && "Too many elements in vector");
513-
return { (unsigned)MinimumEltCnt, Scalable };
514-
}
512+
ElementCount getElementCount() const { return EC; }
515513

516514
/// Returns whether or not this is a scalable vector (meaning the total
517515
/// element count is a multiple of the minimum).
518-
bool isScalable() const {
519-
return Scalable;
520-
}
516+
bool isScalable() const { return EC.Scalable; }
521517

522518
/// Methods for support type inquiry through isa, cast, and dyn_cast.
523519
static bool classof(const Type *T) {
524-
return T->getTypeID() == VectorTyID;
520+
return T->getTypeID() == FixedVectorTyID ||
521+
T->getTypeID() == ScalableVectorTyID;
525522
}
526523
};
527524

528525
bool Type::isVectorTy() const { return isa<VectorType>(this); }
529526

527+
/// Class to represent fixed width SIMD vectors
528+
class FixedVectorType : public VectorType {
529+
protected:
530+
FixedVectorType(Type *ElTy, unsigned NumElts)
531+
: VectorType(ElTy, {NumElts, false}, FixedVectorTyID) {}
532+
533+
public:
534+
static FixedVectorType *get(Type *ElementType, unsigned NumElts);
535+
536+
static bool classof(const Type *T) {
537+
return T->getTypeID() == FixedVectorTyID;
538+
}
539+
};
540+
541+
/// Class to represent scalable SIMD vectors
542+
class ScalableVectorType : public VectorType {
543+
protected:
544+
ScalableVectorType(Type *ElTy, unsigned MinNumElts)
545+
: VectorType(ElTy, {MinNumElts, true}, ScalableVectorTyID) {}
546+
547+
public:
548+
static ScalableVectorType *get(Type *ElementType, unsigned MinNumElts);
549+
550+
/// Get the minimum number of elements in this vector. The actual number of
551+
/// elements in the vector is an integer multiple of this value.
552+
uint64_t getMinNumElements() const { return getElementCount().Min; }
553+
554+
static bool classof(const Type *T) {
555+
return T->getTypeID() == ScalableVectorTyID;
556+
}
557+
};
558+
530559
/// Class to represent pointers.
531560
class PointerType : public Type {
532561
explicit PointerType(Type *ElType, unsigned AddrSpace);

llvm/include/llvm/IR/Type.h

+19-19
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,27 @@ class Type {
5454
///
5555
enum TypeID {
5656
// PrimitiveTypes - make sure LastPrimitiveTyID stays up to date.
57-
VoidTyID = 0, ///< 0: type with no size
58-
HalfTyID, ///< 1: 16-bit floating point type
59-
FloatTyID, ///< 2: 32-bit floating point type
60-
DoubleTyID, ///< 3: 64-bit floating point type
61-
X86_FP80TyID, ///< 4: 80-bit floating point type (X87)
62-
FP128TyID, ///< 5: 128-bit floating point type (112-bit mantissa)
63-
PPC_FP128TyID, ///< 6: 128-bit floating point type (two 64-bits, PowerPC)
64-
LabelTyID, ///< 7: Labels
65-
MetadataTyID, ///< 8: Metadata
66-
X86_MMXTyID, ///< 9: MMX vectors (64 bits, X86 specific)
67-
TokenTyID, ///< 10: Tokens
57+
VoidTyID = 0, ///< 0: type with no size
58+
HalfTyID, ///< 1: 16-bit floating point type
59+
FloatTyID, ///< 2: 32-bit floating point type
60+
DoubleTyID, ///< 3: 64-bit floating point type
61+
X86_FP80TyID, ///< 4: 80-bit floating point type (X87)
62+
FP128TyID, ///< 5: 128-bit floating point type (112-bit mantissa)
63+
PPC_FP128TyID, ///< 6: 128-bit floating point type (two 64-bits, PowerPC)
64+
LabelTyID, ///< 7: Labels
65+
MetadataTyID, ///< 8: Metadata
66+
X86_MMXTyID, ///< 9: MMX vectors (64 bits, X86 specific)
67+
TokenTyID, ///< 10: Tokens
6868

6969
// Derived types... see DerivedTypes.h file.
7070
// Make sure FirstDerivedTyID stays up to date!
71-
IntegerTyID, ///< 11: Arbitrary bit width integers
72-
FunctionTyID, ///< 12: Functions
73-
StructTyID, ///< 13: Structures
74-
ArrayTyID, ///< 14: Arrays
75-
PointerTyID, ///< 15: Pointers
76-
VectorTyID ///< 16: SIMD 'packed' format, or other vector type
71+
IntegerTyID, ///< 11: Arbitrary bit width integers
72+
FunctionTyID, ///< 12: Functions
73+
StructTyID, ///< 13: Structures
74+
ArrayTyID, ///< 14: Arrays
75+
PointerTyID, ///< 15: Pointers
76+
FixedVectorTyID, ///< 16: Fixed width SIMD vector type
77+
ScalableVectorTyID ///< 17: Scalable SIMD vector type
7778
};
7879

7980
private:
@@ -266,8 +267,7 @@ class Type {
266267
return true;
267268
// If it is not something that can have a size (e.g. a function or label),
268269
// it doesn't have a size.
269-
if (getTypeID() != StructTyID && getTypeID() != ArrayTyID &&
270-
getTypeID() != VectorTyID)
270+
if (getTypeID() != StructTyID && getTypeID() != ArrayTyID && !isVectorTy())
271271
return false;
272272
// Otherwise we have to try harder to decide.
273273
return isSizedDerivedType(Visited);

llvm/lib/Bitcode/Writer/BitcodeWriter.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,8 @@ void ModuleBitcodeWriter::writeTypeTable() {
949949
AbbrevToUse = ArrayAbbrev;
950950
break;
951951
}
952-
case Type::VectorTyID: {
952+
case Type::FixedVectorTyID:
953+
case Type::ScalableVectorTyID: {
953954
VectorType *VT = cast<VectorType>(T);
954955
// VECTOR [numelts, eltty] or
955956
// [numelts, eltty, scalable]

llvm/lib/CodeGen/ValueTypes.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,8 @@ MVT MVT::getVT(Type *Ty, bool HandleUnknown){
362362
case Type::FP128TyID: return MVT(MVT::f128);
363363
case Type::PPC_FP128TyID: return MVT(MVT::ppcf128);
364364
case Type::PointerTyID: return MVT(MVT::iPTR);
365-
case Type::VectorTyID: {
365+
case Type::FixedVectorTyID:
366+
case Type::ScalableVectorTyID: {
366367
VectorType *VTy = cast<VectorType>(Ty);
367368
return getVectorVT(
368369
getVT(VTy->getElementType(), /*HandleUnknown=*/ false),
@@ -380,7 +381,8 @@ EVT EVT::getEVT(Type *Ty, bool HandleUnknown){
380381
return MVT::getVT(Ty, HandleUnknown);
381382
case Type::IntegerTyID:
382383
return getIntegerVT(Ty->getContext(), cast<IntegerType>(Ty)->getBitWidth());
383-
case Type::VectorTyID: {
384+
case Type::FixedVectorTyID:
385+
case Type::ScalableVectorTyID: {
384386
VectorType *VTy = cast<VectorType>(Ty);
385387
return getVectorVT(Ty->getContext(),
386388
getEVT(VTy->getElementType(), /*HandleUnknown=*/ false),

llvm/lib/ExecutionEngine/ExecutionEngine.cpp

+19-16
Original file line numberDiff line numberDiff line change
@@ -624,17 +624,18 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
624624
}
625625
}
626626
break;
627-
case Type::VectorTyID:
628-
// if the whole vector is 'undef' just reserve memory for the value.
629-
auto* VTy = cast<VectorType>(C->getType());
630-
Type *ElemTy = VTy->getElementType();
631-
unsigned int elemNum = VTy->getNumElements();
632-
Result.AggregateVal.resize(elemNum);
633-
if (ElemTy->isIntegerTy())
634-
for (unsigned int i = 0; i < elemNum; ++i)
635-
Result.AggregateVal[i].IntVal =
636-
APInt(ElemTy->getPrimitiveSizeInBits(), 0);
637-
break;
627+
case Type::FixedVectorTyID:
628+
case Type::ScalableVectorTyID:
629+
// if the whole vector is 'undef' just reserve memory for the value.
630+
auto *VTy = cast<VectorType>(C->getType());
631+
Type *ElemTy = VTy->getElementType();
632+
unsigned int elemNum = VTy->getNumElements();
633+
Result.AggregateVal.resize(elemNum);
634+
if (ElemTy->isIntegerTy())
635+
for (unsigned int i = 0; i < elemNum; ++i)
636+
Result.AggregateVal[i].IntVal =
637+
APInt(ElemTy->getPrimitiveSizeInBits(), 0);
638+
break;
638639
}
639640
return Result;
640641
}
@@ -914,7 +915,8 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
914915
else
915916
llvm_unreachable("Unknown constant pointer type!");
916917
break;
917-
case Type::VectorTyID: {
918+
case Type::FixedVectorTyID:
919+
case Type::ScalableVectorTyID: {
918920
unsigned elemNum;
919921
Type* ElemTy;
920922
const ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(C);
@@ -1006,8 +1008,7 @@ GenericValue ExecutionEngine::getConstantValue(const Constant *C) {
10061008
break;
10071009
}
10081010
llvm_unreachable("Unknown constant pointer type!");
1009-
}
1010-
break;
1011+
} break;
10111012

10121013
default:
10131014
SmallString<256> Msg;
@@ -1046,7 +1047,8 @@ void ExecutionEngine::StoreValueToMemory(const GenericValue &Val,
10461047

10471048
*((PointerTy*)Ptr) = Val.PointerVal;
10481049
break;
1049-
case Type::VectorTyID:
1050+
case Type::FixedVectorTyID:
1051+
case Type::ScalableVectorTyID:
10501052
for (unsigned i = 0; i < Val.AggregateVal.size(); ++i) {
10511053
if (cast<VectorType>(Ty)->getElementType()->isDoubleTy())
10521054
*(((double*)Ptr)+i) = Val.AggregateVal[i].DoubleVal;
@@ -1096,7 +1098,8 @@ void ExecutionEngine::LoadValueFromMemory(GenericValue &Result,
10961098
Result.IntVal = APInt(80, y);
10971099
break;
10981100
}
1099-
case Type::VectorTyID: {
1101+
case Type::FixedVectorTyID:
1102+
case Type::ScalableVectorTyID: {
11001103
auto *VT = cast<VectorType>(Ty);
11011104
Type *ElemT = VT->getElementType();
11021105
const unsigned numElems = VT->getNumElements();

0 commit comments

Comments
 (0)