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

Sander de Smalen via cfe-commits cfe-commits at lists.llvm.org
Fri Nov 29 13:30:08 PST 2024


================
@@ -50,20 +50,30 @@ using TypeSpec = std::string;
 
 namespace {
 class SVEType {
-  bool Float, Signed, Immediate, Void, Constant, Pointer, BFloat, MFloat;
-  bool DefaultType, IsScalable, Predicate, PredicatePattern, PrefetchOp,
-      Svcount;
+
+  enum TypeKind {
+    Void,
+    Float,
+    SInt,
+    UInt,
+    BFloat16,
+    MFloat8,
+    Svcount,
+    PrefetchOp,
+    PredicatePattern,
+    Predicate
+  };
+  TypeKind Kind;
+  bool Immediate, Constant, Pointer, DefaultType, IsScalable;
   unsigned Bitwidth, ElementBitwidth, NumVectors;
 
 public:
   SVEType() : SVEType("", 'v') {}
 
   SVEType(StringRef TS, char CharMod, unsigned NumVectors = 1)
-      : Float(false), Signed(true), Immediate(false), Void(false),
-        Constant(false), Pointer(false), BFloat(false), MFloat(false),
-        DefaultType(false), IsScalable(true), Predicate(false),
-        PredicatePattern(false), PrefetchOp(false), Svcount(false),
-        Bitwidth(128), ElementBitwidth(~0U), NumVectors(NumVectors) {
+      : Kind(SInt), Immediate(false), Constant(false), Pointer(false),
----------------
sdesmalen-arm wrote:

Right, I see what you mean!

For "default to SInt if there is currently no type set", I guess you mean doing something like this?
```
case 'i':
  if (Kind == Invalid)
    Kind = SInt;
  ElementBitwidth = 32;
  break;
```

While it's not that different from initialising `Kind` as `SInt`, it would allow for adding checks that something like `QUi` is not a valid typespec, something that currently goes undiagnosed.

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


More information about the cfe-commits mailing list