[clang] [Clang][AArch64]Refactor typespec handling in SveEmitter.cpp (PR #117717)

via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 27 03:22:33 PST 2024


================
@@ -424,72 +432,87 @@ const std::array<SVEEmitter::ReinterpretTypeInfo, 12> SVEEmitter::Reinterprets =
 //===----------------------------------------------------------------------===//
 
 std::string SVEType::builtin_str() const {
-  std::string S;
-  if (isVoid())
-    return "v";
+  std::string OutStr;
 
   if (isScalarPredicate())
     return "b";
 
   if (isSvcount())
     return "Qa";
 
-  if (isVoidPointer())
-    S += "v";
-  else if (!isFloatingPoint())
-    switch (ElementBitwidth) {
-    case 1: S += "b"; break;
-    case 8: S += "c"; break;
-    case 16: S += "s"; break;
-    case 32: S += "i"; break;
-    case 64: S += "Wi"; break;
-    case 128: S += "LLLi"; break;
-    default: llvm_unreachable("Unhandled case!");
-    }
-  else if (isFloat())
+  if (isVoid()) {
+    OutStr += "v";
+    if (!isPointer())
+      return OutStr;
+  } else if (isFloat()) {
     switch (ElementBitwidth) {
-    case 16: S += "h"; break;
-    case 32: S += "f"; break;
-    case 64: S += "d"; break;
-    default: llvm_unreachable("Unhandled case!");
+    case 16:
+      OutStr += "h";
+      break;
+    case 32:
+      OutStr += "f";
+      break;
+    case 64:
+      OutStr += "d";
+      break;
+    default:
+      llvm_unreachable("Unhandled float type!");
     }
-  else if (isBFloat()) {
+  } else if (isBFloat()) {
     assert(ElementBitwidth == 16 && "Not a valid BFloat.");
-    S += "y";
+    OutStr += "y";
   } else if (isMFloat()) {
     assert(ElementBitwidth == 8 && "Not a valid MFloat.");
-    S += "m";
-  }
-
-  if (!isFloatingPoint()) {
-    if ((isChar() || isPointer()) && !isVoidPointer()) {
-      // Make chars and typed pointers explicitly signed.
-      if (Signed)
-        S = "S" + S;
-      else if (!Signed)
-        S = "U" + S;
-    } else if (!isVoidPointer() && !Signed) {
-      S = "U" + S;
+    OutStr += "m";
+  } else {
----------------
SpencerAbson wrote:

Having looked at it again, it looks like is a bug with how we emit `MFloat8`. Since in the existing code, it also satisfies `!isFloatingPoint`, it would be emitted as `'c'` and not `'m'`, and there is no code in ASTContext to handle `'m'` anyway, so this patch would break something like https://github.com/llvm/llvm-project/pull/116959 - I'll need to check what our intended approach is. Thanks!

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


More information about the cfe-commits mailing list