Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
619 changes: 306 additions & 313 deletions llvm/include/llvm/CodeGen/ValueTypes.td

Large diffs are not rendered by default.

20 changes: 9 additions & 11 deletions llvm/include/llvm/CodeGenTypes/MachineValueType.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,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, Tup, NF, NElem, EltTy) \
Ty = n,
#define GET_VT_ATTR(Ty, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) Ty,
#define GET_VT_RANGES
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
Expand Down Expand Up @@ -187,7 +186,7 @@ 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, Tup, NF, NElem, EltTy) \
#define GET_VT_ATTR(Ty, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
case Ty: \
return Any;
#include "llvm/CodeGen/GenVT.inc"
Expand Down Expand Up @@ -270,7 +269,7 @@ namespace llvm {
MVT getVectorElementType() const {
assert(SimpleTy >= FIRST_VALUETYPE && SimpleTy <= LAST_VALUETYPE);
static constexpr SimpleValueType EltTyTable[] = {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
#define GET_VT_ATTR(Ty, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
EltTy,
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
Expand All @@ -284,7 +283,7 @@ namespace llvm {
unsigned getVectorMinNumElements() const {
assert(SimpleTy >= FIRST_VALUETYPE && SimpleTy <= LAST_VALUETYPE);
static constexpr uint16_t NElemTable[] = {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
#define GET_VT_ATTR(Ty, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
NElem,
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
Expand Down Expand Up @@ -314,7 +313,7 @@ namespace llvm {
/// base size.
TypeSize getSizeInBits() const {
static constexpr TypeSize SizeTable[] = {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
#define GET_VT_ATTR(Ty, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
TypeSize(Sz, Sc || Tup || Ty == aarch64svcount /* FIXME: Not in the td. \
*/),
#include "llvm/CodeGen/GenVT.inc"
Expand Down Expand Up @@ -437,7 +436,7 @@ namespace llvm {
}

static MVT getFloatingPointVT(unsigned BitWidth) {
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
#define GET_VT_ATTR(Ty, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
if (FP == 3 && sz == BitWidth) \
return Ty;
#include "llvm/CodeGen/GenVT.inc"
Expand All @@ -447,7 +446,7 @@ namespace llvm {
}

static MVT getIntegerVT(unsigned BitWidth) {
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
#define GET_VT_ATTR(Ty, sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
if (Int == 3 && sz == BitWidth) \
return Ty;
#include "llvm/CodeGen/GenVT.inc"
Expand Down Expand Up @@ -477,7 +476,7 @@ namespace llvm {
}

static MVT getRISCVVectorTupleVT(unsigned Sz, unsigned NFields) {
#define GET_VT_ATTR(Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF, nElem, EltTy) \
#define GET_VT_ATTR(Ty, sz, Any, Int, FP, Vec, Sc, Tup, NF, nElem, EltTy) \
if (Tup && sz == Sz && NF == NFields) \
return Ty;
#include "llvm/CodeGen/GenVT.inc"
Expand All @@ -491,8 +490,7 @@ namespace llvm {
assert(isRISCVVectorTuple() && SimpleTy >= FIRST_VALUETYPE &&
SimpleTy <= LAST_VALUETYPE);
static constexpr uint8_t NFTable[] = {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
NF,
#define GET_VT_ATTR(Ty, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) NF,
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
};
Expand Down
4 changes: 2 additions & 2 deletions llvm/include/llvm/Target/Target.td
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class HwModeSelect<list<HwMode> Ms, int ObjectsLength> {
// objects could be used. This is specifically applicable to selection
// patterns.
class ValueTypeByHwMode<list<HwMode> Ms, list<ValueType> Ts>
: HwModeSelect<Ms, !size(Ts)>, ValueType<0, 0> {
: HwModeSelect<Ms, !size(Ts)>, ValueType<0, "INVALID_SIMPLE_VALUE_TYPE"> {
// The length of this list must be the same as the length of Ms.
list<ValueType> Objects = Ts;
}
Expand All @@ -73,7 +73,7 @@ class ValueTypeByHwMode<list<HwMode> Ms, list<ValueType> Ts>
// patterns.
class PtrValueTypeByHwMode<ValueTypeByHwMode scalar, int addrspace>
: HwModeSelect<scalar.Modes, !size(scalar.Objects)>,
PtrValueType<ValueType<0, 0>, addrspace> {
PtrValueType<ValueType<0, "INVALID_SIMPLE_VALUE_TYPE">, addrspace> {
// The length of this list must be the same as the length of Ms.
list<ValueType> Objects = scalar.Objects;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/Target/SPIRV/SPIRVRegisterInfo.td
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let Namespace = "SPIRV" in {
def p64 : PtrValueType <i64, 0>;

class VTPtrVec<int nelem, PtrValueType ptr>
: VTVec<nelem, ValueType<ptr.Size, ptr.Value>, ptr.Value> {
: VTVec<nelem, ValueType<ptr.Size, ptr.LLVMName>, ptr.LLVMName> {
int isPointer = true;
}

Expand Down
17 changes: 9 additions & 8 deletions llvm/utils/TableGen/Basic/VTEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,14 @@ void VTEmitter::run(raw_ostream &OS) {
emitSourceFileHeader("ValueTypes Source Fragment", OS, Records);

std::vector<const Record *> VTsByNumber{512};
for (auto *VT : Records.getAllDerivedDefinitions("ValueType")) {
auto Number = VT->getValueAsInt("Value");
assert(0 <= Number && Number < (int)VTsByNumber.size() &&
"ValueType should be uint16_t");
assert(!VTsByNumber[Number] && "Duplicate ValueType");
unsigned Number = 0;
std::vector<const Record *> Defs(
Records.getAllDerivedDefinitions("ValueType"));
// Emit VTs in the order they were declared so that VTRanges stay contiguous.
llvm::sort(Defs, LessRecordByID());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine!

for (auto *VT : Defs) {
++Number;
assert(Number < VTsByNumber.size() && "ValueType should be uint16_t");
VTsByNumber[Number] = VT;
}

Expand All @@ -120,13 +123,12 @@ void VTEmitter::run(raw_ostream &OS) {
}
};

OS << "#ifdef GET_VT_ATTR // (Ty, n, sz, Any, Int, FP, Vec, Sc, Tup, NF, "
OS << "#ifdef GET_VT_ATTR // (Ty, sz, Any, Int, FP, Vec, Sc, Tup, NF, "
"NElem, EltTy)\n";
for (const auto *VT : VTsByNumber) {
if (!VT)
continue;
auto Name = VT->getValueAsString("LLVMName");
auto Value = VT->getValueAsInt("Value");
bool IsInteger = VT->getValueAsBit("isInteger");
bool IsFP = VT->getValueAsBit("isFP");
bool IsVector = VT->getValueAsBit("isVector");
Expand Down Expand Up @@ -158,7 +160,6 @@ void VTEmitter::run(raw_ostream &OS) {
// clang-format off
OS << " GET_VT_ATTR("
<< Name << ", "
<< Value << ", "
<< VT->getValueAsInt("Size") << ", "
<< VT->getValueAsBit("isOverloaded") << ", "
<< (IsInteger ? Name[0] == 'i' ? 3 : 1 : 0) << ", "
Expand Down
11 changes: 9 additions & 2 deletions llvm/utils/TableGen/Common/CodeGenTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "CodeGenRegisters.h"
#include "CodeGenSchedule.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/ErrorHandling.h"
Expand All @@ -42,15 +43,21 @@ static cl::opt<unsigned>
/// Returns the MVT that the specified TableGen
/// record corresponds to.
MVT llvm::getValueType(const Record *Rec) {
return (MVT::SimpleValueType)Rec->getValueAsInt("Value");
return StringSwitch<MVT>(Rec->getValueAsString("LLVMName"))
#define GET_VT_ATTR(Ty, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
.Case(#Ty, MVT::Ty)
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
.Case("INVALID_SIMPLE_VALUE_TYPE", MVT::INVALID_SIMPLE_VALUE_TYPE);
}

StringRef llvm::getEnumName(MVT T) {
// clang-format off
switch (T.SimpleTy) {
#define GET_VT_ATTR(Ty, N, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
#define GET_VT_ATTR(Ty, Sz, Any, Int, FP, Vec, Sc, Tup, NF, NElem, EltTy) \
case MVT::Ty: return "MVT::" # Ty;
#include "llvm/CodeGen/GenVT.inc"
#undef GET_VT_ATTR
default: llvm_unreachable("ILLEGAL VALUE TYPE!");
}
// clang-format on
Expand Down
Loading