[PATCH] D78995: [SveEmitter] NFCI: Describe splat operands like any other modifier

Sander de Smalen via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 28 05:51:34 PDT 2020


sdesmalen created this revision.
sdesmalen added reviewers: SjoerdMeijer, efriedma.
Herald added a subscriber: tschuett.
Herald added a reviewer: rengolin.

For scalar operands that need to be splat to a vector,
this patch adds a bool to the SVEType struct so that the
`applyModifier` function sets the value appropriately.
This makes the implementation/meaning of the modifiers more
transparent.


https://reviews.llvm.org/D78995

Files:
  clang/utils/TableGen/SveEmitter.cpp


Index: clang/utils/TableGen/SveEmitter.cpp
===================================================================
--- clang/utils/TableGen/SveEmitter.cpp
+++ clang/utils/TableGen/SveEmitter.cpp
@@ -65,6 +65,7 @@
 
 class SVEType {
   TypeSpec TS;
+  bool IsSplat;
   bool Float, Signed, Immediate, Void, Constant, Pointer;
   bool DefaultType, IsScalable, Predicate, PredicatePattern, PrefetchOp;
   unsigned Bitwidth, ElementBitwidth, NumVectors;
@@ -73,10 +74,10 @@
   SVEType() : SVEType(TypeSpec(), 'v') {}
 
   SVEType(TypeSpec TS, char CharMod)
-      : TS(TS), Float(false), Signed(true), Immediate(false), Void(false),
-        Constant(false), Pointer(false), DefaultType(false), IsScalable(true),
-        Predicate(false), PredicatePattern(false), PrefetchOp(false),
-        Bitwidth(128), ElementBitwidth(~0U), NumVectors(1) {
+      : TS(TS), IsSplat(false), Float(false), Signed(true), Immediate(false),
+        Void(false), Constant(false), Pointer(false), DefaultType(false),
+        IsScalable(true), Predicate(false), PredicatePattern(false),
+        PrefetchOp(false), Bitwidth(128), ElementBitwidth(~0U), NumVectors(1) {
     if (!TS.empty())
       applyTypespec();
     applyModifier(CharMod);
@@ -99,6 +100,7 @@
   bool isPredicatePattern() const { return PredicatePattern; }
   bool isPrefetchOp() const { return PrefetchOp; }
   bool isConstant() const { return Constant; }
+  bool isSplat() const { return IsSplat; }
   unsigned getElementSizeInBits() const { return ElementBitwidth; }
   unsigned getNumVectors() const { return NumVectors; }
 
@@ -210,17 +212,14 @@
 
   /// Return true if the intrinsic takes a splat operand.
   bool hasSplat() const {
-    // These prototype modifiers are described in arm_sve.td.
-    return Proto.find_first_of("ajfrKLR") != std::string::npos;
+    return llvm::any_of(getTypes(), [](const SVEType &T) { return T.isSplat(); });
   }
 
   /// Return the parameter index of the splat operand.
   unsigned getSplatIdx() const {
-    // These prototype modifiers are described in arm_sve.td.
-    auto Idx = Proto.find_first_of("ajfrKLR");
-    assert(Idx != std::string::npos && Idx > 0 &&
-           "Prototype has no splat operand");
-    return Idx - 1;
+    return std::distance(
+        &Types[1], //Types.begin(),
+        llvm::find_if(getTypes(), [](const SVEType &T) { return T.isSplat(); }));
   }
 
   /// Emits the intrinsic declaration to the ostream.
@@ -505,8 +504,10 @@
     Bitwidth = 16;
     ElementBitwidth = 1;
     break;
-  case 's':
   case 'a':
+    IsSplat = true;
+    LLVM_FALLTHROUGH;
+  case 's':
     Bitwidth = ElementBitwidth;
     NumVectors = 0;
     break;
@@ -578,6 +579,7 @@
     ElementBitwidth = 64;
     break;
   case 'j':
+    IsSplat = true;
     ElementBitwidth = Bitwidth = 64;
     NumVectors = 0;
     break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78995.260600.patch
Type: text/x-patch
Size: 2822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200428/163eeea3/attachment.bin>


More information about the cfe-commits mailing list