[llvm] [ValueTypes][NFC] Generate EVT::getTypeForEVT from GenVT.inc (PR #96608)

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 25 16:19:57 PDT 2024


================
@@ -27,6 +27,47 @@ class VTEmitter {
   void run(raw_ostream &OS);
 };
 
+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"))
+    OS << "Type::getIntNTy(Context, " << OutputVTSize << ")";
----------------
topperc wrote:

getIntNTy is slower than the special cases. Not sure if that's performance critical here or not.

https://github.com/llvm/llvm-project/pull/96608


More information about the llvm-commits mailing list