[llvm] 3cd3b21 - [ValueTypes][NFC] Generate EVT::getTypeForEVT from GenVT.inc (#96608)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 26 23:45:42 PDT 2024
Author: Kito Cheng
Date: 2024-06-27T14:45:38+08:00
New Revision: 3cd3b2165e52b9c7fa71aaee1421c8effe4f526b
URL: https://github.com/llvm/llvm-project/commit/3cd3b2165e52b9c7fa71aaee1421c8effe4f526b
DIFF: https://github.com/llvm/llvm-project/commit/3cd3b2165e52b9c7fa71aaee1421c8effe4f526b.diff
LOG: [ValueTypes][NFC] Generate EVT::getTypeForEVT from GenVT.inc (#96608)
Most of MVT has simple mapping to the LLVM type, so it would be nice to
auto generate that from ValueTypes.td, that could reduce the effort when
we adding new MVT, especially new vector MVT with different size.
Added:
Modified:
llvm/lib/CodeGen/ValueTypes.cpp
llvm/utils/TableGen/VTEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/ValueTypes.cpp b/llvm/lib/CodeGen/ValueTypes.cpp
index df1c02c3dc67c..b0f736a49c20e 100644
--- a/llvm/lib/CodeGen/ValueTypes.cpp
+++ b/llvm/lib/CodeGen/ValueTypes.cpp
@@ -207,21 +207,6 @@ Type *EVT::getTypeForEVT(LLVMContext &Context) const {
assert(isExtended() && "Type is not extended!");
return LLVMTy;
case MVT::isVoid: return Type::getVoidTy(Context);
- case MVT::i1: return Type::getInt1Ty(Context);
- case MVT::i2: return Type::getIntNTy(Context, 2);
- case MVT::i4: return Type::getIntNTy(Context, 4);
- case MVT::i8: return Type::getInt8Ty(Context);
- case MVT::i16: return Type::getInt16Ty(Context);
- case MVT::i32: return Type::getInt32Ty(Context);
- case MVT::i64: return Type::getInt64Ty(Context);
- case MVT::i128: return IntegerType::get(Context, 128);
- case MVT::f16: return Type::getHalfTy(Context);
- case MVT::bf16: return Type::getBFloatTy(Context);
- case MVT::f32: return Type::getFloatTy(Context);
- case MVT::f64: return Type::getDoubleTy(Context);
- case MVT::f80: return Type::getX86_FP80Ty(Context);
- case MVT::f128: return Type::getFP128Ty(Context);
- case MVT::ppcf128: return Type::getPPC_FP128Ty(Context);
case MVT::x86mmx: return Type::getX86_MMXTy(Context);
case MVT::aarch64svcount:
return TargetExtType::get(Context, "aarch64.svcount");
@@ -229,353 +214,10 @@ Type *EVT::getTypeForEVT(LLVMContext &Context) const {
case MVT::i64x8: return IntegerType::get(Context, 512);
case MVT::externref: return Type::getWasm_ExternrefTy(Context);
case MVT::funcref: return Type::getWasm_FuncrefTy(Context);
- case MVT::v1i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 1);
- case MVT::v2i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 2);
- case MVT::v3i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 3);
- case MVT::v4i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 4);
- case MVT::v8i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 8);
- case MVT::v16i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 16);
- case MVT::v32i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 32);
- case MVT::v64i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 64);
- case MVT::v128i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 128);
- case MVT::v256i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 256);
- case MVT::v512i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 512);
- case MVT::v1024i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 1024);
- case MVT::v2048i1:
- return FixedVectorType::get(Type::getInt1Ty(Context), 2048);
- case MVT::v128i2:
- return FixedVectorType::get(Type::getIntNTy(Context, 2), 128);
- case MVT::v256i2:
- return FixedVectorType::get(Type::getIntNTy(Context, 2), 256);
- case MVT::v64i4:
- return FixedVectorType::get(Type::getIntNTy(Context, 4), 64);
- case MVT::v128i4:
- return FixedVectorType::get(Type::getIntNTy(Context, 4), 128);
- case MVT::v1i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 1);
- case MVT::v2i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 2);
- case MVT::v3i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 3);
- case MVT::v4i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 4);
- case MVT::v8i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 8);
- case MVT::v16i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 16);
- case MVT::v32i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 32);
- case MVT::v64i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 64);
- case MVT::v128i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 128);
- case MVT::v256i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 256);
- case MVT::v512i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 512);
- case MVT::v1024i8:
- return FixedVectorType::get(Type::getInt8Ty(Context), 1024);
- case MVT::v1i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 1);
- case MVT::v2i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 2);
- case MVT::v3i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 3);
- case MVT::v4i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 4);
- case MVT::v8i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 8);
- case MVT::v16i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 16);
- case MVT::v32i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 32);
- case MVT::v64i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 64);
- case MVT::v128i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 128);
- case MVT::v256i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 256);
- case MVT::v512i16:
- return FixedVectorType::get(Type::getInt16Ty(Context), 512);
- case MVT::v1i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 1);
- case MVT::v2i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 2);
- case MVT::v3i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 3);
- case MVT::v4i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 4);
- case MVT::v5i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 5);
- case MVT::v6i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 6);
- case MVT::v7i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 7);
- case MVT::v8i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 8);
- case MVT::v9i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 9);
- case MVT::v10i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 10);
- case MVT::v11i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 11);
- case MVT::v12i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 12);
- case MVT::v16i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 16);
- case MVT::v32i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 32);
- case MVT::v64i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 64);
- case MVT::v128i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 128);
- case MVT::v256i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 256);
- case MVT::v512i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 512);
- case MVT::v1024i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 1024);
- case MVT::v2048i32:
- return FixedVectorType::get(Type::getInt32Ty(Context), 2048);
- case MVT::v1i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 1);
- case MVT::v2i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 2);
- case MVT::v3i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 3);
- case MVT::v4i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 4);
- case MVT::v8i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 8);
- case MVT::v16i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 16);
- case MVT::v32i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 32);
- case MVT::v64i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 64);
- case MVT::v128i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 128);
- case MVT::v256i64:
- return FixedVectorType::get(Type::getInt64Ty(Context), 256);
- case MVT::v1i128:
- return FixedVectorType::get(Type::getInt128Ty(Context), 1);
- case MVT::v1f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 1);
- case MVT::v2f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 2);
- case MVT::v3f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 3);
- case MVT::v4f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 4);
- case MVT::v8f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 8);
- case MVT::v16f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 16);
- case MVT::v32f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 32);
- case MVT::v64f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 64);
- case MVT::v128f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 128);
- case MVT::v256f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 256);
- case MVT::v512f16:
- return FixedVectorType::get(Type::getHalfTy(Context), 512);
- case MVT::v2bf16:
- return FixedVectorType::get(Type::getBFloatTy(Context), 2);
- case MVT::v3bf16:
- return FixedVectorType::get(Type::getBFloatTy(Context), 3);
- case MVT::v4bf16:
- return FixedVectorType::get(Type::getBFloatTy(Context), 4);
- case MVT::v8bf16:
- return FixedVectorType::get(Type::getBFloatTy(Context), 8);
- case MVT::v16bf16:
- return FixedVectorType::get(Type::getBFloatTy(Context), 16);
- case MVT::v32bf16:
- return FixedVectorType::get(Type::getBFloatTy(Context), 32);
- case MVT::v64bf16:
- return FixedVectorType::get(Type::getBFloatTy(Context), 64);
- case MVT::v128bf16:
- return FixedVectorType::get(Type::getBFloatTy(Context), 128);
- case MVT::v1f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 1);
- case MVT::v2f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 2);
- case MVT::v3f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 3);
- case MVT::v4f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 4);
- case MVT::v5f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 5);
- case MVT::v6f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 6);
- case MVT::v7f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 7);
- case MVT::v8f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 8);
- case MVT::v9f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 9);
- case MVT::v10f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 10);
- case MVT::v11f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 11);
- case MVT::v12f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 12);
- case MVT::v16f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 16);
- case MVT::v32f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 32);
- case MVT::v64f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 64);
- case MVT::v128f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 128);
- case MVT::v256f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 256);
- case MVT::v512f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 512);
- case MVT::v1024f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 1024);
- case MVT::v2048f32:
- return FixedVectorType::get(Type::getFloatTy(Context), 2048);
- case MVT::v1f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 1);
- case MVT::v2f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 2);
- case MVT::v3f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 3);
- case MVT::v4f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 4);
- case MVT::v8f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 8);
- case MVT::v16f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 16);
- case MVT::v32f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 32);
- case MVT::v64f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 64);
- case MVT::v128f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 128);
- case MVT::v256f64:
- return FixedVectorType::get(Type::getDoubleTy(Context), 256);
- case MVT::nxv1i1:
- return ScalableVectorType::get(Type::getInt1Ty(Context), 1);
- case MVT::nxv2i1:
- return ScalableVectorType::get(Type::getInt1Ty(Context), 2);
- case MVT::nxv4i1:
- return ScalableVectorType::get(Type::getInt1Ty(Context), 4);
- case MVT::nxv8i1:
- return ScalableVectorType::get(Type::getInt1Ty(Context), 8);
- case MVT::nxv16i1:
- return ScalableVectorType::get(Type::getInt1Ty(Context), 16);
- case MVT::nxv32i1:
- return ScalableVectorType::get(Type::getInt1Ty(Context), 32);
- case MVT::nxv64i1:
- return ScalableVectorType::get(Type::getInt1Ty(Context), 64);
- case MVT::nxv1i8:
- return ScalableVectorType::get(Type::getInt8Ty(Context), 1);
- case MVT::nxv2i8:
- return ScalableVectorType::get(Type::getInt8Ty(Context), 2);
- case MVT::nxv4i8:
- return ScalableVectorType::get(Type::getInt8Ty(Context), 4);
- case MVT::nxv8i8:
- return ScalableVectorType::get(Type::getInt8Ty(Context), 8);
- case MVT::nxv16i8:
- return ScalableVectorType::get(Type::getInt8Ty(Context), 16);
- case MVT::nxv32i8:
- return ScalableVectorType::get(Type::getInt8Ty(Context), 32);
- case MVT::nxv64i8:
- return ScalableVectorType::get(Type::getInt8Ty(Context), 64);
- case MVT::nxv1i16:
- return ScalableVectorType::get(Type::getInt16Ty(Context), 1);
- case MVT::nxv2i16:
- return ScalableVectorType::get(Type::getInt16Ty(Context), 2);
- case MVT::nxv4i16:
- return ScalableVectorType::get(Type::getInt16Ty(Context), 4);
- case MVT::nxv8i16:
- return ScalableVectorType::get(Type::getInt16Ty(Context), 8);
- case MVT::nxv16i16:
- return ScalableVectorType::get(Type::getInt16Ty(Context), 16);
- case MVT::nxv32i16:
- return ScalableVectorType::get(Type::getInt16Ty(Context), 32);
- case MVT::nxv1i32:
- return ScalableVectorType::get(Type::getInt32Ty(Context), 1);
- case MVT::nxv2i32:
- return ScalableVectorType::get(Type::getInt32Ty(Context), 2);
- case MVT::nxv4i32:
- return ScalableVectorType::get(Type::getInt32Ty(Context), 4);
- case MVT::nxv8i32:
- return ScalableVectorType::get(Type::getInt32Ty(Context), 8);
- case MVT::nxv16i32:
- return ScalableVectorType::get(Type::getInt32Ty(Context), 16);
- case MVT::nxv32i32:
- return ScalableVectorType::get(Type::getInt32Ty(Context), 32);
- case MVT::nxv1i64:
- return ScalableVectorType::get(Type::getInt64Ty(Context), 1);
- case MVT::nxv2i64:
- return ScalableVectorType::get(Type::getInt64Ty(Context), 2);
- case MVT::nxv4i64:
- return ScalableVectorType::get(Type::getInt64Ty(Context), 4);
- case MVT::nxv8i64:
- return ScalableVectorType::get(Type::getInt64Ty(Context), 8);
- case MVT::nxv16i64:
- return ScalableVectorType::get(Type::getInt64Ty(Context), 16);
- case MVT::nxv32i64:
- return ScalableVectorType::get(Type::getInt64Ty(Context), 32);
- case MVT::nxv1f16:
- return ScalableVectorType::get(Type::getHalfTy(Context), 1);
- case MVT::nxv2f16:
- return ScalableVectorType::get(Type::getHalfTy(Context), 2);
- case MVT::nxv4f16:
- return ScalableVectorType::get(Type::getHalfTy(Context), 4);
- case MVT::nxv8f16:
- return ScalableVectorType::get(Type::getHalfTy(Context), 8);
- case MVT::nxv16f16:
- return ScalableVectorType::get(Type::getHalfTy(Context), 16);
- case MVT::nxv32f16:
- return ScalableVectorType::get(Type::getHalfTy(Context), 32);
- case MVT::nxv1bf16:
- return ScalableVectorType::get(Type::getBFloatTy(Context), 1);
- case MVT::nxv2bf16:
- return ScalableVectorType::get(Type::getBFloatTy(Context), 2);
- case MVT::nxv4bf16:
- return ScalableVectorType::get(Type::getBFloatTy(Context), 4);
- case MVT::nxv8bf16:
- return ScalableVectorType::get(Type::getBFloatTy(Context), 8);
- case MVT::nxv16bf16:
- return ScalableVectorType::get(Type::getBFloatTy(Context), 16);
- case MVT::nxv32bf16:
- return ScalableVectorType::get(Type::getBFloatTy(Context), 32);
- case MVT::nxv1f32:
- return ScalableVectorType::get(Type::getFloatTy(Context), 1);
- case MVT::nxv2f32:
- return ScalableVectorType::get(Type::getFloatTy(Context), 2);
- case MVT::nxv4f32:
- return ScalableVectorType::get(Type::getFloatTy(Context), 4);
- case MVT::nxv8f32:
- return ScalableVectorType::get(Type::getFloatTy(Context), 8);
- case MVT::nxv16f32:
- return ScalableVectorType::get(Type::getFloatTy(Context), 16);
- case MVT::nxv1f64:
- return ScalableVectorType::get(Type::getDoubleTy(Context), 1);
- case MVT::nxv2f64:
- return ScalableVectorType::get(Type::getDoubleTy(Context), 2);
- case MVT::nxv4f64:
- return ScalableVectorType::get(Type::getDoubleTy(Context), 4);
- case MVT::nxv8f64:
- return ScalableVectorType::get(Type::getDoubleTy(Context), 8);
case MVT::Metadata: return Type::getMetadataTy(Context);
+#define GET_VT_EVT(Ty, EVT) case MVT::Ty: return EVT;
+#include "llvm/CodeGen/GenVT.inc"
+#undef GET_VT_EVT
}
// clang-format on
}
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 3187548a29704..851a525cf48c0 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -29,6 +29,53 @@ class VTEmitter {
} // End anonymous namespace.
+static void VTtoGetLLVMTyString(raw_ostream &OS, const Record *VT) {
+ bool IsVector = VT->getValueAsBit("isVector");
+ if (IsVector)
+ OS << (VT->getValueAsBit("isScalable") ? "Scalable" : "Fixed")
+ << "VectorType::get(";
+
+ auto OutputVT = IsVector ? VT->getValueAsDef("ElementType") : VT;
+ int64_t OutputVTSize = OutputVT->getValueAsInt("Size");
+
+ if (OutputVT->getValueAsBit("isFP")) {
+ StringRef FloatTy;
+ auto OutputVTName = OutputVT->getValueAsString("LLVMName");
+ switch (OutputVTSize) {
+ default:
+ llvm_unreachable("Unhandled case");
+ case 16:
+ FloatTy = (OutputVTName == "bf16") ? "BFloatTy" : "HalfTy";
+ break;
+ case 32:
+ FloatTy = "FloatTy";
+ break;
+ case 64:
+ FloatTy = "DoubleTy";
+ break;
+ case 80:
+ FloatTy = "X86_FP80Ty";
+ break;
+ case 128:
+ FloatTy = (OutputVTName == "ppcf128") ? "PPC_FP128Ty" : "FP128Ty";
+ break;
+ }
+ OS << "Type::get" << FloatTy << "(Context)";
+ } else if (OutputVT->getValueAsBit("isInteger")) {
+ // We only have Type::getInt1Ty, Int8, Int16, Int32, Int64, and Int128
+ if ((isPowerOf2_64(OutputVTSize) && OutputVTSize >= 8 &&
+ OutputVTSize <= 128) ||
+ OutputVTSize == 1)
+ OS << "Type::getInt" << OutputVTSize << "Ty(Context)";
+ else
+ OS << "Type::getIntNTy(Context, " << OutputVTSize << ")";
+ } else
+ llvm_unreachable("Unhandled case");
+
+ if (IsVector)
+ OS << ", " << VT->getValueAsInt("nElem") << ")";
+}
+
void VTEmitter::run(raw_ostream &OS) {
emitSourceFileHeader("ValueTypes Source Fragment", OS, Records);
@@ -130,6 +177,23 @@ void VTEmitter::run(raw_ostream &OS) {
// clang-format on
}
OS << "#endif\n\n";
+
+ OS << "#ifdef GET_VT_EVT\n";
+ for (const auto *VT : VTsByNumber) {
+ if (!VT)
+ continue;
+ bool IsInteger = VT->getValueAsBit("isInteger");
+ bool IsVector = VT->getValueAsBit("isVector");
+ bool IsFP = VT->getValueAsBit("isFP");
+
+ if (!IsInteger && !IsVector && !IsFP)
+ continue;
+
+ OS << " GET_VT_EVT(" << VT->getValueAsString("LLVMName") << ", ";
+ VTtoGetLLVMTyString(OS, VT);
+ OS << ")\n";
+ }
+ OS << "#endif\n\n";
}
static TableGen::Emitter::OptClass<VTEmitter> X("gen-vt", "Generate ValueType");
More information about the llvm-commits
mailing list