From c8295de4a66adcc610c315df69286f02c306a1c9 Mon Sep 17 00:00:00 2001 From: George Mitenkov Date: Fri, 26 Jun 2020 10:29:05 -0400 Subject: [PATCH] [MLIR][SPIRVToLLVM] Conversion for bitrverse and bitcount ops Implemented conversion for `spv.BitReverse` and `spv.BitCount`. Since ODS generates builders in a different way for LLVM dialect intrinsics, I added attributes to build method in `DirectConversionPattern` class. The tests for these ops are in `bitwise-ops-to-llvm.mlir`. Differential Revision: https://reviews.llvm.org/D82286 --- .../Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp | 5 +++- .../SPIRVToLLVM/bitwise-ops-to-llvm.mlir | 32 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp index 297e73a..6178b53 100644 --- a/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp +++ b/mlir/lib/Conversion/SPIRVToLLVM/ConvertSPIRVToLLVM.cpp @@ -72,7 +72,8 @@ public: auto dstType = this->typeConverter.convertType(operation.getType()); if (!dstType) return failure(); - rewriter.template replaceOpWithNewOp(operation, dstType, operands); + rewriter.template replaceOpWithNewOp(operation, dstType, operands, + operation.getAttrs()); return success(); } }; @@ -340,6 +341,8 @@ void mlir::populateSPIRVToLLVMConversionPatterns( DirectConversionPattern, // Bitwise ops + DirectConversionPattern, + DirectConversionPattern, DirectConversionPattern, DirectConversionPattern, DirectConversionPattern, diff --git a/mlir/test/Conversion/SPIRVToLLVM/bitwise-ops-to-llvm.mlir b/mlir/test/Conversion/SPIRVToLLVM/bitwise-ops-to-llvm.mlir index 1341040..fb276d4 100644 --- a/mlir/test/Conversion/SPIRVToLLVM/bitwise-ops-to-llvm.mlir +++ b/mlir/test/Conversion/SPIRVToLLVM/bitwise-ops-to-llvm.mlir @@ -1,6 +1,38 @@ // RUN: mlir-opt -convert-spirv-to-llvm %s | FileCheck %s //===----------------------------------------------------------------------===// +// spv.BitCount +//===----------------------------------------------------------------------===// + +func @bitcount_scalar(%arg0: i16) { + // CHECK: %{{.*}} = "llvm.intr.ctpop"(%{{.*}}) : (!llvm.i16) -> !llvm.i16 + %0 = spv.BitCount %arg0: i16 + return +} + +func @bitcount_vector(%arg0: vector<3xi32>) { + // CHECK: %{{.*}} = "llvm.intr.ctpop"(%{{.*}}) : (!llvm<"<3 x i32>">) -> !llvm<"<3 x i32>"> + %0 = spv.BitCount %arg0: vector<3xi32> + return +} + +//===----------------------------------------------------------------------===// +// spv.BitReverse +//===----------------------------------------------------------------------===// + +func @bitreverse_scalar(%arg0: i64) { + // CHECK: %{{.*}} = "llvm.intr.bitreverse"(%{{.*}}) : (!llvm.i64) -> !llvm.i64 + %0 = spv.BitReverse %arg0: i64 + return +} + +func @bitreverse_vector(%arg0: vector<4xi32>) { + // CHECK: %{{.*}} = "llvm.intr.bitreverse"(%{{.*}}) : (!llvm<"<4 x i32>">) -> !llvm<"<4 x i32>"> + %0 = spv.BitReverse %arg0: vector<4xi32> + return +} + +//===----------------------------------------------------------------------===// // spv.BitwiseAnd //===----------------------------------------------------------------------===// -- 2.7.4