Skip to content

Commit 45fd7c7

Browse files
committed
fixup! decouple tuple type and vector type
1 parent dd58bb7 commit 45fd7c7

File tree

6 files changed

+39
-18
lines changed

6 files changed

+39
-18
lines changed

llvm/include/llvm/CodeGen/ValueTypes.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,11 @@ namespace llvm {
353353
return getVectorElementCount().getKnownMinValue();
354354
}
355355

356+
/// Given a RISCV vector tuple type, return the num_fields.
357+
unsigned getRISCVVectorTupleNumFields() const {
358+
return V.getRISCVVectorTupleNumFields();
359+
}
360+
356361
/// Return the size of the specified value type in bits.
357362
///
358363
/// If the value type is a scalable vector type, the scalable property will

llvm/include/llvm/CodeGen/ValueTypes.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class ValueType<int size, int value> {
2323
bit isFP = false;
2424
bit isVector = false;
2525
bit isScalable = false;
26+
int NF = 0;
2627
bit isRISCVVecTuple = false;
2728
// Indicates this VT should be included in the
2829
// [FIRST_VALUETYPE,LAST_VALUETYPE] range.
@@ -59,8 +60,7 @@ class VTScalableVec<int nelem, ValueType elt, int value>
5960

6061
class VTVecTup<int size, int nf, ValueType dummy_elt, int value>
6162
: ValueType<size, value> {
62-
let nElem = nf;
63-
let isVector = true;
63+
let NF = nf;
6464
let ElementType = dummy_elt;
6565
let isRISCVVecTuple = true;
6666
}

llvm/include/llvm/CodeGenTypes/MachineValueType.h

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace llvm {
3838
// are considered extended value types.
3939
INVALID_SIMPLE_VALUE_TYPE = 0,
4040

41-
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NElem, EltTy) \
41+
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
4242
Ty = n,
4343
#define GET_VT_RANGES
4444
#include "llvm/CodeGen/GenVT.inc"
@@ -179,7 +179,7 @@ namespace llvm {
179179
/// Return true if this is an overloaded type for TableGen.
180180
bool isOverloaded() const {
181181
switch (SimpleTy) {
182-
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NElem, EltTy) \
182+
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
183183
case Ty: \
184184
return Any;
185185
#include "llvm/CodeGen/GenVT.inc"
@@ -262,7 +262,7 @@ namespace llvm {
262262
MVT getVectorElementType() const {
263263
assert(SimpleTy >= FIRST_VALUETYPE && SimpleTy <= LAST_VALUETYPE);
264264
static constexpr SimpleValueType EltTyTable[] = {
265-
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NElem, EltTy) \
265+
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
266266
EltTy,
267267
#include "llvm/CodeGen/GenVT.inc"
268268
#undef GET_VT_ATTR
@@ -276,7 +276,7 @@ namespace llvm {
276276
unsigned getVectorMinNumElements() const {
277277
assert(SimpleTy >= FIRST_VALUETYPE && SimpleTy <= LAST_VALUETYPE);
278278
static constexpr uint16_t NElemTable[] = {
279-
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NElem, EltTy) \
279+
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
280280
NElem,
281281
#include "llvm/CodeGen/GenVT.inc"
282282
#undef GET_VT_ATTR
@@ -306,7 +306,7 @@ namespace llvm {
306306
/// base size.
307307
TypeSize getSizeInBits() const {
308308
static constexpr TypeSize SizeTable[] = {
309-
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NElem, EltTy) \
309+
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
310310
TypeSize(Sz, Sc || Ty == aarch64svcount /* FIXME: Not in the td. */),
311311
#include "llvm/CodeGen/GenVT.inc"
312312
#undef GET_VT_ATTR
@@ -428,7 +428,7 @@ namespace llvm {
428428
}
429429

430430
static MVT getFloatingPointVT(unsigned BitWidth) {
431-
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NElem, EltTy) \
431+
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
432432
if (FP == 3 && sz == BitWidth) \
433433
return Ty;
434434
#include "llvm/CodeGen/GenVT.inc"
@@ -438,7 +438,7 @@ namespace llvm {
438438
}
439439

440440
static MVT getIntegerVT(unsigned BitWidth) {
441-
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NElem, EltTy) \
441+
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
442442
if (Int == 3 && sz == BitWidth) \
443443
return Ty;
444444
#include "llvm/CodeGen/GenVT.inc"
@@ -468,15 +468,28 @@ namespace llvm {
468468
}
469469

470470
static MVT getRISCVVectorTupleVT(unsigned Sz, unsigned NFields) {
471-
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, nElem, EltTy) \
472-
if (Tup && sz == Sz && nElem == NFields) \
471+
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF, nElem, EltTy) \
472+
if (Tup && sz == Sz && NF == NFields) \
473473
return Ty;
474474
#include "llvm/CodeGen/GenVT.inc"
475475
#undef GET_VT_ATTR
476476

477477
llvm_unreachable("Invalid RISCV vector tuple type");
478478
}
479479

480+
/// Given a RISC-V vector tuple type, return the num_fields.
481+
unsigned getRISCVVectorTupleNumFields() const {
482+
assert(isRISCVVectorTuple() && SimpleTy >= FIRST_VALUETYPE &&
483+
SimpleTy <= LAST_VALUETYPE);
484+
static constexpr uint16_t NFTable[] = {
485+
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
486+
NF,
487+
#include "llvm/CodeGen/GenVT.inc"
488+
#undef GET_VT_ATTR
489+
};
490+
return NFTable[SimpleTy - FIRST_VALUETYPE];
491+
}
492+
480493
static MVT getVectorVT(MVT VT, unsigned NumElements, bool IsScalable) {
481494
if (IsScalable)
482495
return getScalableVectorVT(VT, NumElements);

llvm/lib/CodeGen/ValueTypes.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ std::string EVT::getEVTString() const {
163163
default:
164164
if (isRISCVVectorTuple()) {
165165
unsigned Sz = getSizeInBits();
166-
unsigned NF = getVectorMinNumElements();
166+
unsigned NF = getRISCVVectorTupleNumFields();
167167
unsigned MinNumElts = Sz / (NF * 8);
168168
return "riscv_nxv" + utostr(MinNumElts) + "i8";
169169
}

llvm/utils/TableGen/Common/CodeGenTarget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ StringRef llvm::getName(MVT::SimpleValueType T) {
6363
StringRef llvm::getEnumName(MVT::SimpleValueType T) {
6464
// clang-format off
6565
switch (T) {
66-
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NElem, EltTy) \
66+
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
6767
case MVT::Ty: return "MVT::" # Ty;
6868
#include "llvm/CodeGen/GenVT.inc"
6969
default: llvm_unreachable("ILLEGAL VALUE TYPE!");

llvm/utils/TableGen/VTEmitter.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void VTEmitter::run(raw_ostream &OS) {
120120
}
121121
};
122122

123-
OS << "#ifdef GET_VT_ATTR // (Ty, n, sz, Any, Int, FP, Vec, Sc, Tup)\n";
123+
OS << "#ifdef GET_VT_ATTR // (Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF)\n";
124124
for (const auto *VT : VTsByNumber) {
125125
if (!VT)
126126
continue;
@@ -131,20 +131,21 @@ void VTEmitter::run(raw_ostream &OS) {
131131
bool IsVector = VT->getValueAsBit("isVector");
132132
bool IsScalable = VT->getValueAsBit("isScalable");
133133
bool IsRISCVVecTuple = VT->getValueAsBit("isRISCVVecTuple");
134+
int64_t NF = VT->getValueAsInt("NF");
134135
bool IsNormalValueType = VT->getValueAsBit("isNormalValueType");
135136
int64_t NElem = IsVector ? VT->getValueAsInt("nElem") : 0;
136137
StringRef EltName = IsVector ? VT->getValueAsDef("ElementType")->getName()
137138
: "INVALID_SIMPLE_VALUE_TYPE";
138139

139140
UpdateVTRange("INTEGER_FIXEDLEN_VECTOR_VALUETYPE", Name,
140-
IsInteger && IsVector && !IsScalable && !IsRISCVVecTuple);
141+
IsInteger && IsVector && !IsScalable);
141142
UpdateVTRange("INTEGER_SCALABLE_VECTOR_VALUETYPE", Name,
142143
IsInteger && IsScalable);
143144
UpdateVTRange("FP_FIXEDLEN_VECTOR_VALUETYPE", Name,
144-
IsFP && IsVector && !IsScalable && !IsRISCVVecTuple);
145+
IsFP && IsVector && !IsScalable);
145146
UpdateVTRange("FP_SCALABLE_VECTOR_VALUETYPE", Name, IsFP && IsScalable);
146147
UpdateVTRange("FIXEDLEN_VECTOR_VALUETYPE", Name,
147-
IsVector && !IsScalable && !IsRISCVVecTuple);
148+
IsVector && !IsScalable);
148149
UpdateVTRange("SCALABLE_VECTOR_VALUETYPE", Name, IsScalable);
149150
UpdateVTRange("RISCV_VECTOR_TUPLE_VALUETYPE", Name, IsRISCVVecTuple);
150151
UpdateVTRange("VECTOR_VALUETYPE", Name, IsVector);
@@ -163,6 +164,7 @@ void VTEmitter::run(raw_ostream &OS) {
163164
<< IsVector << ", "
164165
<< IsScalable << ", "
165166
<< IsRISCVVecTuple << ", "
167+
<< NF << ", "
166168
<< NElem << ", "
167169
<< EltName << ")\n";
168170
// clang-format on
@@ -201,8 +203,9 @@ void VTEmitter::run(raw_ostream &OS) {
201203
bool IsInteger = VT->getValueAsBit("isInteger");
202204
bool IsVector = VT->getValueAsBit("isVector");
203205
bool IsFP = VT->getValueAsBit("isFP");
206+
bool IsRISCVVecTuple = VT->getValueAsBit("isRISCVVecTuple");
204207

205-
if (!IsInteger && !IsVector && !IsFP)
208+
if (!IsInteger && !IsVector && !IsFP && !IsRISCVVecTuple)
206209
continue;
207210

208211
OS << " GET_VT_EVT(" << VT->getValueAsString("LLVMName") << ", ";

0 commit comments

Comments
 (0)