[llvm] [ValueTypes][NFC] Generate EVT::getTypeForEVT from GenVT.inc (PR #96608)
Kito Cheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 06:32:08 PDT 2024
https://github.com/kito-cheng updated https://github.com/llvm/llvm-project/pull/96608
>From 2f66ab6add847936b7788909fc5962c229bdcc29 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Tue, 25 Jun 2024 16:37:37 +0800
Subject: [PATCH 1/9] [ValueTypes][NFC] Generate EVT::getTypeForEVT from
GenVT.inc
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.
---
llvm/include/llvm/CodeGen/ValueTypes.td | 26 +-
llvm/lib/CodeGen/ValueTypes.cpp | 364 +-----------------------
llvm/utils/TableGen/VTEmitter.cpp | 14 +
3 files changed, 35 insertions(+), 369 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/ValueTypes.td b/llvm/include/llvm/CodeGen/ValueTypes.td
index 963b6a71de380..6b091d36ae6f3 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.td
+++ b/llvm/include/llvm/CodeGen/ValueTypes.td
@@ -14,6 +14,7 @@
class ValueType<int size, int value> {
string Namespace = "MVT";
string LLVMName = NAME;
+ string LLVMTyForEVT = "";
int Size = size;
int Value = value;
int nElem = 1;
@@ -34,16 +35,22 @@ class VTAny<int value> : ValueType<0, value> {
class VTInt<int size, int value>
: ValueType<size, value> {
+ let LLVMTyForEVT = !strconcat("Type::getIntNTy(Context, ",
+ !cast<string>(size), ")");
let isInteger = true;
}
-class VTFP<int size, int value>
+class VTFP<int size, string LLVMTy, int value>
: ValueType<size, value> {
+ let LLVMTyForEVT = !strconcat("Type::get", LLVMTy, "(Context)");
let isFP = true;
}
class VTVec<int nelem, ValueType elt, int value>
: ValueType<!mul(nelem, elt.Size), value> {
+ let LLVMTyForEVT = !strconcat("FixedVectorType::get(",
+ elt.LLVMTyForEVT, ", ",
+ !cast<string>(nelem), ")");
let nElem = nelem;
let ElementType = elt;
let isInteger = elt.isInteger;
@@ -53,6 +60,9 @@ class VTVec<int nelem, ValueType elt, int value>
class VTScalableVec<int nelem, ValueType elt, int value>
: VTVec<nelem, elt, value> {
+ let LLVMTyForEVT = !strconcat("ScalableVectorType::get(",
+ elt.LLVMTyForEVT, ", ",
+ !cast<string>(nelem), ")");
let isScalable = true;
}
@@ -71,13 +81,13 @@ def i32 : VTInt<32, 7>; // 32-bit integer value
def i64 : VTInt<64, 8>; // 64-bit integer value
def i128 : VTInt<128, 9>; // 128-bit integer value
-def bf16 : VTFP<16, 10>; // 16-bit brain floating point value
-def f16 : VTFP<16, 11>; // 16-bit floating point value
-def f32 : VTFP<32, 12>; // 32-bit floating point value
-def f64 : VTFP<64, 13>; // 64-bit floating point value
-def f80 : VTFP<80, 14>; // 80-bit floating point value
-def f128 : VTFP<128, 15>; // 128-bit floating point value
-def ppcf128 : VTFP<128, 16>; // PPC 128-bit floating point value
+def bf16 : VTFP<16, "BFloatTy", 10>; // 16-bit brain floating point value
+def f16 : VTFP<16, "HalfTy", 11>; // 16-bit floating point value
+def f32 : VTFP<32, "FloatTy", 12>; // 32-bit floating point value
+def f64 : VTFP<64, "DoubleTy", 13>; // 64-bit floating point value
+def f80 : VTFP<80, "X86_FP80Ty", 14>; // 80-bit floating point value
+def f128 : VTFP<128, "FP128Ty", 15>; // 128-bit floating point value
+def ppcf128 : VTFP<128, "PPC_FP128Ty", 16>; // PPC 128-bit floating point value
def v1i1 : VTVec<1, i1, 17>; // 1 x i1 vector value
def v2i1 : VTVec<2, i1, 18>; // 2 x i1 vector value
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..0cf0c18244aa9 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -130,6 +130,20 @@ 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;
+ auto LLVMTyForEVT = VT->getValueAsString("LLVMTyForEVT");
+ if (LLVMTyForEVT.empty())
+ continue;
+
+ OS << " GET_VT_EVT("
+ << VT->getValueAsString("LLVMName") << ", "
+ << LLVMTyForEVT << ")\n";
+ }
+ OS << "#endif\n\n";
}
static TableGen::Emitter::OptClass<VTEmitter> X("gen-vt", "Generate ValueType");
>From 72aa2f3b1c2392ab5f1a422930251cd06347b36c Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Tue, 25 Jun 2024 18:19:12 +0800
Subject: [PATCH 2/9] fixup, move code gen logic to tablegen
---
llvm/include/llvm/CodeGen/ValueTypes.td | 14 +++--------
llvm/utils/TableGen/VTEmitter.cpp | 32 +++++++++++++++++++++----
2 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/ValueTypes.td b/llvm/include/llvm/CodeGen/ValueTypes.td
index 6b091d36ae6f3..a5e297b77030e 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.td
+++ b/llvm/include/llvm/CodeGen/ValueTypes.td
@@ -14,7 +14,7 @@
class ValueType<int size, int value> {
string Namespace = "MVT";
string LLVMName = NAME;
- string LLVMTyForEVT = "";
+ string LLVMTy = "";
int Size = size;
int Value = value;
int nElem = 1;
@@ -35,22 +35,17 @@ class VTAny<int value> : ValueType<0, value> {
class VTInt<int size, int value>
: ValueType<size, value> {
- let LLVMTyForEVT = !strconcat("Type::getIntNTy(Context, ",
- !cast<string>(size), ")");
let isInteger = true;
}
-class VTFP<int size, string LLVMTy, int value>
+class VTFP<int size, string llvmty, int value>
: ValueType<size, value> {
- let LLVMTyForEVT = !strconcat("Type::get", LLVMTy, "(Context)");
+ let LLVMTy = llvmty;
let isFP = true;
}
class VTVec<int nelem, ValueType elt, int value>
: ValueType<!mul(nelem, elt.Size), value> {
- let LLVMTyForEVT = !strconcat("FixedVectorType::get(",
- elt.LLVMTyForEVT, ", ",
- !cast<string>(nelem), ")");
let nElem = nelem;
let ElementType = elt;
let isInteger = elt.isInteger;
@@ -60,9 +55,6 @@ class VTVec<int nelem, ValueType elt, int value>
class VTScalableVec<int nelem, ValueType elt, int value>
: VTVec<nelem, elt, value> {
- let LLVMTyForEVT = !strconcat("ScalableVectorType::get(",
- elt.LLVMTyForEVT, ", ",
- !cast<string>(nelem), ")");
let isScalable = true;
}
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 0cf0c18244aa9..478e4d47fb8d0 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -13,6 +13,7 @@
#include <array>
#include <cassert>
#include <map>
+#include <string>
using namespace llvm;
namespace {
@@ -135,13 +136,34 @@ void VTEmitter::run(raw_ostream &OS) {
for (const auto *VT : VTsByNumber) {
if (!VT)
continue;
- auto LLVMTyForEVT = VT->getValueAsString("LLVMTyForEVT");
- if (LLVMTyForEVT.empty())
+ auto LLVMTy = VT->getValueAsString("LLVMTy");
+ bool IsInteger = VT->getValueAsBit("isInteger");
+ bool IsVector = VT->getValueAsBit("isVector");
+
+ if (LLVMTy.empty() && !(IsInteger || IsVector))
continue;
- OS << " GET_VT_EVT("
- << VT->getValueAsString("LLVMName") << ", "
- << LLVMTyForEVT << ")\n";
+ OS << " GET_VT_EVT(" << VT->getValueAsString("LLVMName") << ", ";
+
+ if (IsVector)
+ OS << (VT->getValueAsBit("isScalable") ? "Scalable" : "Fixed")
+ << "VectorType::get(";
+
+ auto OutputVT = IsVector ? VT->getValueAsDef("ElementType") : VT;
+ auto OutputLLVMTy = OutputVT->getValueAsString("LLVMTy");
+
+ if (!OutputLLVMTy.empty())
+ OS << "Type::get" << OutputLLVMTy << "(Context)";
+ else if (OutputVT->getValueAsBit("isInteger"))
+ OS << "Type::getIntNTy(Context, " << OutputVT->getValueAsInt("Size")
+ << ")";
+ else
+ llvm_unreachable("unhandled case");
+
+ if (IsVector)
+ OS << ", " << VT->getValueAsInt("nElem") << ")";
+
+ OS << ")\n";
}
OS << "#endif\n\n";
}
>From a1df60347a83eea0abd347dce0187540ba079d2a Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Tue, 25 Jun 2024 20:39:27 +0800
Subject: [PATCH 3/9] fixup, remove LLVMTy from ValueTypes.td, all derive from
existing info in ValueType
---
llvm/include/llvm/CodeGen/ValueTypes.td | 18 ++++++++---------
llvm/utils/TableGen/VTEmitter.cpp | 27 +++++++++++++++++--------
2 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/llvm/include/llvm/CodeGen/ValueTypes.td b/llvm/include/llvm/CodeGen/ValueTypes.td
index a5e297b77030e..963b6a71de380 100644
--- a/llvm/include/llvm/CodeGen/ValueTypes.td
+++ b/llvm/include/llvm/CodeGen/ValueTypes.td
@@ -14,7 +14,6 @@
class ValueType<int size, int value> {
string Namespace = "MVT";
string LLVMName = NAME;
- string LLVMTy = "";
int Size = size;
int Value = value;
int nElem = 1;
@@ -38,9 +37,8 @@ class VTInt<int size, int value>
let isInteger = true;
}
-class VTFP<int size, string llvmty, int value>
+class VTFP<int size, int value>
: ValueType<size, value> {
- let LLVMTy = llvmty;
let isFP = true;
}
@@ -73,13 +71,13 @@ def i32 : VTInt<32, 7>; // 32-bit integer value
def i64 : VTInt<64, 8>; // 64-bit integer value
def i128 : VTInt<128, 9>; // 128-bit integer value
-def bf16 : VTFP<16, "BFloatTy", 10>; // 16-bit brain floating point value
-def f16 : VTFP<16, "HalfTy", 11>; // 16-bit floating point value
-def f32 : VTFP<32, "FloatTy", 12>; // 32-bit floating point value
-def f64 : VTFP<64, "DoubleTy", 13>; // 64-bit floating point value
-def f80 : VTFP<80, "X86_FP80Ty", 14>; // 80-bit floating point value
-def f128 : VTFP<128, "FP128Ty", 15>; // 128-bit floating point value
-def ppcf128 : VTFP<128, "PPC_FP128Ty", 16>; // PPC 128-bit floating point value
+def bf16 : VTFP<16, 10>; // 16-bit brain floating point value
+def f16 : VTFP<16, 11>; // 16-bit floating point value
+def f32 : VTFP<32, 12>; // 32-bit floating point value
+def f64 : VTFP<64, 13>; // 64-bit floating point value
+def f80 : VTFP<80, 14>; // 80-bit floating point value
+def f128 : VTFP<128, 15>; // 128-bit floating point value
+def ppcf128 : VTFP<128, 16>; // PPC 128-bit floating point value
def v1i1 : VTVec<1, i1, 17>; // 1 x i1 vector value
def v2i1 : VTVec<2, i1, 18>; // 2 x i1 vector value
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 478e4d47fb8d0..173910db3404d 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -136,11 +136,11 @@ void VTEmitter::run(raw_ostream &OS) {
for (const auto *VT : VTsByNumber) {
if (!VT)
continue;
- auto LLVMTy = VT->getValueAsString("LLVMTy");
bool IsInteger = VT->getValueAsBit("isInteger");
bool IsVector = VT->getValueAsBit("isVector");
+ bool IsFP = VT->getValueAsBit("isFP");
- if (LLVMTy.empty() && !(IsInteger || IsVector))
+ if (!(IsInteger || IsVector || IsFP))
continue;
OS << " GET_VT_EVT(" << VT->getValueAsString("LLVMName") << ", ";
@@ -150,12 +150,23 @@ void VTEmitter::run(raw_ostream &OS) {
<< "VectorType::get(";
auto OutputVT = IsVector ? VT->getValueAsDef("ElementType") : VT;
- auto OutputLLVMTy = OutputVT->getValueAsString("LLVMTy");
-
- if (!OutputLLVMTy.empty())
- OS << "Type::get" << OutputLLVMTy << "(Context)";
- else if (OutputVT->getValueAsBit("isInteger"))
- OS << "Type::getIntNTy(Context, " << OutputVT->getValueAsInt("Size")
+ 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"))
+ OS << "Type::getIntNTy(Context, " << OutputVTSize
<< ")";
else
llvm_unreachable("unhandled case");
>From 0e9da7f827c00a4faf6a50bb1bd77a2a09d89d45 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Tue, 25 Jun 2024 20:43:03 +0800
Subject: [PATCH 4/9] fixup, format and remove unused header file
---
llvm/utils/TableGen/VTEmitter.cpp | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 173910db3404d..a903e7012b82e 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -13,7 +13,6 @@
#include <array>
#include <cassert>
#include <map>
-#include <string>
using namespace llvm;
namespace {
@@ -73,7 +72,7 @@ void VTEmitter::run(raw_ostream &OS) {
bool IsFP = VT->getValueAsBit("isFP");
bool IsVector = VT->getValueAsBit("isVector");
bool IsScalable = VT->getValueAsBit("isScalable");
- bool IsNormalValueType = VT->getValueAsBit("isNormalValueType");
+ bool IsNormalValueType = VT->getValueAsBit("isNormalValueType");
int64_t NElem = IsVector ? VT->getValueAsInt("nElem") : 0;
StringRef EltName = IsVector ? VT->getValueAsDef("ElementType")->getName()
: "INVALID_SIMPLE_VALUE_TYPE";
@@ -156,18 +155,27 @@ void VTEmitter::run(raw_ostream &OS) {
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;
+ 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"))
- OS << "Type::getIntNTy(Context, " << OutputVTSize
- << ")";
+ OS << "Type::getIntNTy(Context, " << OutputVTSize << ")";
else
llvm_unreachable("unhandled case");
>From 4e8d56873f80dae382071e487c7d84908040b08d Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Tue, 25 Jun 2024 20:43:55 +0800
Subject: [PATCH 5/9] fixup, don't touch unrelated code
---
llvm/utils/TableGen/VTEmitter.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index a903e7012b82e..7b269f0329fa1 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -72,7 +72,7 @@ void VTEmitter::run(raw_ostream &OS) {
bool IsFP = VT->getValueAsBit("isFP");
bool IsVector = VT->getValueAsBit("isVector");
bool IsScalable = VT->getValueAsBit("isScalable");
- bool IsNormalValueType = VT->getValueAsBit("isNormalValueType");
+ bool IsNormalValueType = VT->getValueAsBit("isNormalValueType");
int64_t NElem = IsVector ? VT->getValueAsInt("nElem") : 0;
StringRef EltName = IsVector ? VT->getValueAsDef("ElementType")->getName()
: "INVALID_SIMPLE_VALUE_TYPE";
>From 2219667cb7457fd1086f92868f2e9477b95ebf05 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Tue, 25 Jun 2024 21:20:14 +0800
Subject: [PATCH 6/9] fixup, address comment
---
llvm/utils/TableGen/VTEmitter.cpp | 96 +++++++++++++++++--------------
1 file changed, 54 insertions(+), 42 deletions(-)
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 7b269f0329fa1..302c97a6f5dfa 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -7,12 +7,15 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <array>
#include <cassert>
+#include <cstring>
#include <map>
+#include <string>
using namespace llvm;
namespace {
@@ -29,6 +32,54 @@ class VTEmitter {
} // End anonymous namespace.
+std::string VTtoGetLLVMTyString(const Record *VT) {
+ bool IsVector = VT->getValueAsBit("isVector");
+ std::string GetLLVMTyString;
+ if (IsVector)
+ GetLLVMTyString +=
+ (Twine(VT->getValueAsBit("isScalable") ? "Scalable" : "Fixed") +
+ "VectorType::get(")
+ .str();
+
+ 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;
+ }
+ GetLLVMTyString += (Twine("Type::get") + FloatTy + "(Context)").str();
+ } else if (OutputVT->getValueAsBit("isInteger"))
+ GetLLVMTyString +=
+ (Twine("Type::getIntNTy(Context, ") + Twine(OutputVTSize) + ")").str();
+ else
+ llvm_unreachable("Unhandled case");
+
+ if (IsVector)
+ GetLLVMTyString +=
+ (Twine(", ") + std::to_string(VT->getValueAsInt("nElem")) + ")").str();
+
+ return GetLLVMTyString;
+}
+
void VTEmitter::run(raw_ostream &OS) {
emitSourceFileHeader("ValueTypes Source Fragment", OS, Records);
@@ -139,50 +190,11 @@ void VTEmitter::run(raw_ostream &OS) {
bool IsVector = VT->getValueAsBit("isVector");
bool IsFP = VT->getValueAsBit("isFP");
- if (!(IsInteger || IsVector || IsFP))
+ if (!IsInteger && !IsVector && !IsFP)
continue;
- OS << " GET_VT_EVT(" << VT->getValueAsString("LLVMName") << ", ";
-
- 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"))
- OS << "Type::getIntNTy(Context, " << OutputVTSize << ")";
- else
- llvm_unreachable("unhandled case");
-
- if (IsVector)
- OS << ", " << VT->getValueAsInt("nElem") << ")";
-
- OS << ")\n";
+ OS << " GET_VT_EVT(" << VT->getValueAsString("LLVMName") << ", "
+ << VTtoGetLLVMTyString(VT) << ")\n";
}
OS << "#endif\n\n";
}
>From ff2686232f0c05608de973409168dff806047d31 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Tue, 25 Jun 2024 21:24:05 +0800
Subject: [PATCH 7/9] fixup, remove unused header
---
llvm/utils/TableGen/VTEmitter.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 302c97a6f5dfa..ced1520a8278e 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -13,7 +13,6 @@
#include "llvm/TableGen/TableGenBackend.h"
#include <array>
#include <cassert>
-#include <cstring>
#include <map>
#include <string>
using namespace llvm;
>From 11bc0bfd966466ed42325b2ef96b1ad8c6f19db1 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Tue, 25 Jun 2024 21:25:52 +0800
Subject: [PATCH 8/9] fixup, minor tweak
---
llvm/utils/TableGen/VTEmitter.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index ced1520a8278e..6d252ad47fe70 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -50,7 +50,7 @@ std::string VTtoGetLLVMTyString(const Record *VT) {
default:
llvm_unreachable("Unhandled case");
case 16:
- FloatTy = OutputVTName == "bf16" ? "BFloatTy" : "HalfTy";
+ FloatTy = (OutputVTName == "bf16") ? "BFloatTy" : "HalfTy";
break;
case 32:
FloatTy = "FloatTy";
@@ -62,7 +62,7 @@ std::string VTtoGetLLVMTyString(const Record *VT) {
FloatTy = "X86_FP80Ty";
break;
case 128:
- FloatTy = OutputVTName == "ppcf128" ? "PPC_FP128Ty" : "FP128Ty";
+ FloatTy = (OutputVTName == "ppcf128") ? "PPC_FP128Ty" : "FP128Ty";
break;
}
GetLLVMTyString += (Twine("Type::get") + FloatTy + "(Context)").str();
>From 1423b888adce93b098b7d5ea4f52c830a1dc5da7 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Tue, 25 Jun 2024 21:31:41 +0800
Subject: [PATCH 9/9] fixup, Drop Twine and std::string
---
llvm/utils/TableGen/VTEmitter.cpp | 26 +++++++++-----------------
1 file changed, 9 insertions(+), 17 deletions(-)
diff --git a/llvm/utils/TableGen/VTEmitter.cpp b/llvm/utils/TableGen/VTEmitter.cpp
index 6d252ad47fe70..62f513fa85f36 100644
--- a/llvm/utils/TableGen/VTEmitter.cpp
+++ b/llvm/utils/TableGen/VTEmitter.cpp
@@ -7,14 +7,12 @@
//===----------------------------------------------------------------------===//
#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/TableGen/Record.h"
#include "llvm/TableGen/TableGenBackend.h"
#include <array>
#include <cassert>
#include <map>
-#include <string>
using namespace llvm;
namespace {
@@ -31,14 +29,11 @@ class VTEmitter {
} // End anonymous namespace.
-std::string VTtoGetLLVMTyString(const Record *VT) {
+static void VTtoGetLLVMTyString(raw_ostream &OS, const Record *VT) {
bool IsVector = VT->getValueAsBit("isVector");
- std::string GetLLVMTyString;
if (IsVector)
- GetLLVMTyString +=
- (Twine(VT->getValueAsBit("isScalable") ? "Scalable" : "Fixed") +
- "VectorType::get(")
- .str();
+ OS << (VT->getValueAsBit("isScalable") ? "Scalable" : "Fixed")
+ << "VectorType::get(";
auto OutputVT = IsVector ? VT->getValueAsDef("ElementType") : VT;
int64_t OutputVTSize = OutputVT->getValueAsInt("Size");
@@ -65,18 +60,14 @@ std::string VTtoGetLLVMTyString(const Record *VT) {
FloatTy = (OutputVTName == "ppcf128") ? "PPC_FP128Ty" : "FP128Ty";
break;
}
- GetLLVMTyString += (Twine("Type::get") + FloatTy + "(Context)").str();
+ OS << "Type::get" << FloatTy << "(Context)";
} else if (OutputVT->getValueAsBit("isInteger"))
- GetLLVMTyString +=
- (Twine("Type::getIntNTy(Context, ") + Twine(OutputVTSize) + ")").str();
+ OS << "Type::getIntNTy(Context, " << OutputVTSize << ")";
else
llvm_unreachable("Unhandled case");
if (IsVector)
- GetLLVMTyString +=
- (Twine(", ") + std::to_string(VT->getValueAsInt("nElem")) + ")").str();
-
- return GetLLVMTyString;
+ OS << ", " << VT->getValueAsInt("nElem") << ")";
}
void VTEmitter::run(raw_ostream &OS) {
@@ -192,8 +183,9 @@ void VTEmitter::run(raw_ostream &OS) {
if (!IsInteger && !IsVector && !IsFP)
continue;
- OS << " GET_VT_EVT(" << VT->getValueAsString("LLVMName") << ", "
- << VTtoGetLLVMTyString(VT) << ")\n";
+ OS << " GET_VT_EVT(" << VT->getValueAsString("LLVMName") << ", ";
+ VTtoGetLLVMTyString(OS, VT);
+ OS << ")\n";
}
OS << "#endif\n\n";
}
More information about the llvm-commits
mailing list