//===- 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) { … } /// Replace math.cos(v) operation with vcix.v.iv(v). struct MathCosToVCIX final : OpRewritePattern<math::CosOp> { … }; // Replace math.sin(v) operation with vcix.v.sv(v, v). struct MathSinToVCIX final : OpRewritePattern<math::SinOp> { … }; // Replace math.tan(v) operation with vcix.v.sv(v, 0.0f). struct MathTanToVCIX final : OpRewritePattern<math::TanOp> { … }; // Replace math.log(v) operation with vcix.v.sv(v, 0). struct MathLogToVCIX final : OpRewritePattern<math::LogOp> { … }; struct TestMathToVCIX : PassWrapper<TestMathToVCIX, OperationPass<func::FuncOp>> { … }; } // namespace namespace test { void registerTestMathToVCIXPass() { … } } // namespace test } // namespace mlir