[Mlir-commits] [mlir] [mlir][ArmSVE] Add convert_to/from_svbool ops (PR #68586)

Andrzej WarzyƄski llvmlistbot at llvm.org
Wed Oct 11 08:28:20 PDT 2023


================
@@ -481,10 +500,39 @@ class IsScalableVectorOfLengthPred<list<int> allowedLengths> :
                            == }]
                          # allowedlength>)>]>;
 
+// Normalizes an index so it can be bounds checked.
+// Negative values are mapped to their absolute value.
+//  - These are used to index in reverse (i.e. index -1 would be the last element)
+// Positive values are mapped to their value + 1.
+//  - This results the same range of values as the negative indices
+// This allows bounds checking to be: len(list) >= NormalizeIndex<idx>.ret.
+class NormalizeIndex<int value> {
+  int ret = !if(!lt(value, 0), !sub(0, value), !add(value, 1));
+}
+
+// Whether the n-th dim of the shape matches the given `size`.
+// Negative values index in reverse.
+class IsNthDimSizeIsOneOfPred<int n, list<int> allowedSizes>
+  : And<[
+      CPred<"::llvm::cast<::mlir::ShapedType>($_self).getRank() >= " # NormalizeIndex<n>.ret>,
+      CPred<"::llvm::is_contained(ArrayRef<int64_t>({" # !interleave(allowedSizes, ", ") # "}), "
+        # "::llvm::cast<::mlir::ShapedType>($_self).getDimSize("
+        #   !if(!lt(n, 0),
+              "::llvm::cast<::mlir::ShapedType>($_self).getRank() + " # n,
+              "" # n)
+        # "))">]>;
+
 // Whether the shape of a vector matches the given `shape` list.
----------------
banach-space wrote:

I wouldn't "mix" `IsVectorOfShape` (which is fairly basic) with the new definitions (which are quite complex)

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


More information about the Mlir-commits mailing list