[Mlir-commits] [mlir] [MLIR][VCIX] Support VCIX intrinsics in LLVMIR dialect (PR #75875)

Diego Caballero llvmlistbot at llvm.org
Tue Feb 6 11:56:21 PST 2024


================
@@ -0,0 +1,271 @@
+//===- TestMathToVCIXConversion.cpp - Test conversion to VCIX ops -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "mlir/Dialect/Arith/IR/Arith.h"
+#include "mlir/Dialect/Func/IR/FuncOps.h"
+#include "mlir/Dialect/LLVMIR/VCIXDialect.h"
+#include "mlir/Dialect/Math/IR/Math.h"
+#include "mlir/Dialect/Vector/IR/VectorOps.h"
+#include "mlir/IR/PatternMatch.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Pass/PassManager.h"
+#include "mlir/Transforms/GreedyPatternRewriteDriver.h"
+
+namespace mlir {
+namespace {
+
+/// Return number of extracts required to make input VectorType \vt legal and
+/// also return thatlegal vector type.
+/// For fixed vectors nothing special is needed. Scalable vectors are legalizes
+/// according to LLVM's encoding:
+// https://lists.llvm.org/pipermail/llvm-dev/2020-October/145850.html
+static std::pair<unsigned, VectorType> legalizeVectorType(const Type &type)
+{
+  VectorType vt = type.cast<VectorType>();
+  // To simplify test pass, avoid multi-dimensional vectors.
+  if (!vt || vt.getRank() != 1)
+    return {0, nullptr};
+
+  if (!vt.isScalable())
+    return {1, vt};
+
+  Type eltTy = vt.getElementType();
+  unsigned sew = 0;
+  if (eltTy.isF32())
+    sew = 32;
+  else if (eltTy.isF64())
+    sew = 64;
+  else if (auto intTy = eltTy.dyn_cast<IntegerType>())
+    sew = intTy.getWidth();
+  else
+    return {0, nullptr};
+
+  unsigned eltCount = vt.getShape()[0];
+  const unsigned lmul = eltCount * sew / 64;
+
+  unsigned n = lmul > 8 ? llvm::Log2_32(lmul) - 2 : 1;
+  return {n, VectorType::get({eltCount >> (n - 1)}, eltTy, {true})};
+}
+
+// Replace math.cos(v) operation with vcix.v.iv(v)
----------------
dcaballe wrote:

`//` -> `///`. Same below. We use `///` for function documentation so that the doc is picked up by some of the tools.

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


More information about the Mlir-commits mailing list