Skip to content

[CodeGenTypes] Speed up getVectorElementType and getVectorMinNumElements #95282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 28 additions & 30 deletions llvm/include/llvm/CodeGenTypes/MachineValueType.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace llvm {
// are considered extended value types.
INVALID_SIMPLE_VALUE_TYPE = 0,

#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc) Ty = n,
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, NElem, EltTy) Ty = n,
#define GET_VT_RANGES
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
Expand Down Expand Up @@ -171,9 +171,9 @@ namespace llvm {
/// Return true if this is an overloaded type for TableGen.
bool isOverloaded() const {
switch (SimpleTy) {
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc) \
case Ty: \
return Any;
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, NElem, EltTy) \
case Ty: \
return Any;
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
default:
Expand Down Expand Up @@ -252,30 +252,28 @@ namespace llvm {
}

MVT getVectorElementType() const {
switch (SimpleTy) {
default:
llvm_unreachable("Not a vector MVT!");

#define GET_VT_VECATTR(Ty, Sc, nElem, ElTy, ElSz) \
case Ty: \
return ElTy;
assert(SimpleTy >= FIRST_VALUETYPE && SimpleTy <= LAST_VALUETYPE);
static constexpr SimpleValueType EltTyTable[] = {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, NElem, EltTy) EltTy,
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_VECATTR
}
#undef GET_VT_ATTR
};
SimpleValueType VT = EltTyTable[SimpleTy - FIRST_VALUETYPE];
assert(VT != INVALID_SIMPLE_VALUE_TYPE && "Not a vector MVT!");
return VT;
}

/// Given a vector type, return the minimum number of elements it contains.
unsigned getVectorMinNumElements() const {
switch (SimpleTy) {
default:
llvm_unreachable("Not a vector MVT!");

#define GET_VT_VECATTR(Ty, Sc, nElem, ElTy, ElSz) \
case Ty: \
return nElem;
assert(SimpleTy >= FIRST_VALUETYPE && SimpleTy <= LAST_VALUETYPE);
static constexpr uint16_t NElemTable[] = {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, NElem, EltTy) NElem,
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_VECATTR
}
#undef GET_VT_ATTR
};
unsigned NElem = NElemTable[SimpleTy - FIRST_VALUETYPE];
assert(NElem != 0 && "Not a vector MVT!");
return NElem;
}

ElementCount getVectorElementCount() const {
Expand All @@ -298,8 +296,8 @@ namespace llvm {
/// base size.
TypeSize getSizeInBits() const {
static constexpr TypeSize SizeTable[] = {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc) \
TypeSize(Sz, Sc || Ty == aarch64svcount /* FIXME: Not in the td. */),
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, NElem, EltTy) \
TypeSize(Sz, Sc || Ty == aarch64svcount /* FIXME: Not in the td. */),
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
};
Expand Down Expand Up @@ -420,19 +418,19 @@ namespace llvm {
}

static MVT getFloatingPointVT(unsigned BitWidth) {
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc) \
if (FP == 3 && sz == BitWidth) \
return Ty;
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, NElem, EltTy) \
if (FP == 3 && sz == BitWidth) \
return Ty;
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR

llvm_unreachable("Bad bit width!");
}

static MVT getIntegerVT(unsigned BitWidth) {
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc) \
if (Int == 3 && sz == BitWidth) \
return Ty;
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, NElem, EltTy) \
if (Int == 3 && sz == BitWidth) \
return Ty;
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR

Expand Down
2 changes: 1 addition & 1 deletion llvm/utils/TableGen/Common/CodeGenTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ StringRef llvm::getName(MVT::SimpleValueType T) {
StringRef llvm::getEnumName(MVT::SimpleValueType T) {
// clang-format off
switch (T) {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc) \
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, NElem, EltTy) \
case MVT::Ty: return "MVT::" # Ty;
#include "llvm/CodeGen/GenVT.inc"
default: llvm_unreachable("ILLEGAL VALUE TYPE!");
Expand Down
7 changes: 6 additions & 1 deletion llvm/utils/TableGen/VTEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ void VTEmitter::run(raw_ostream &OS) {
bool IsVector = VT->getValueAsBit("isVector");
bool IsScalable = VT->getValueAsBit("isScalable");
bool IsNormalValueType = VT->getValueAsBit("isNormalValueType");
int64_t NElem = IsVector ? VT->getValueAsInt("nElem") : 0;
StringRef EltName = IsVector ? VT->getValueAsDef("ElementType")->getName()
: "INVALID_SIMPLE_VALUE_TYPE";

UpdateVTRange("INTEGER_FIXEDLEN_VECTOR_VALUETYPE", Name,
IsInteger && IsVector && !IsScalable);
Expand All @@ -97,7 +100,9 @@ void VTEmitter::run(raw_ostream &OS) {
<< (IsInteger ? Name[0] == 'i' ? 3 : 1 : 0) << ", "
<< (IsFP ? Name[0] == 'f' ? 3 : 1 : 0) << ", "
<< IsVector << ", "
<< IsScalable << ")\n";
<< IsScalable << ", "
<< NElem << ", "
<< EltName << ")\n";
// clang-format on
}
OS << "#endif\n\n";
Expand Down
Loading