From e678cbae4d0f1522c5db8cc24a82672dbc8f0ca9 Mon Sep 17 00:00:00 2001 From: Jakub Kuderski Date: Thu, 25 Aug 2022 16:54:26 -0400 Subject: [PATCH] [mlir][spirv] Add convenience builders for AddICarry and SubIBorrow This is so that we do not have to spell out long structure types every time we create these ops. Reviewed By: antiagainst Differential Revision: https://reviews.llvm.org/D132629 --- mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td | 16 ++++++++++++++++ .../Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp | 4 +--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td index 7ce34dc..beed00e 100644 --- a/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td +++ b/mlir/include/mlir/Dialect/SPIRV/IR/SPIRVArithmeticOps.td @@ -354,6 +354,14 @@ def SPV_IAddCarryOp : SPV_BinaryOp<"IAddCarry", SPV_AnyStruct:$result ); + let builders = [ + OpBuilder<(ins "Value":$operand1, "Value":$operand2), [{ + build($_builder, $_state, + ::mlir::spirv::StructType::get({operand1.getType(), operand1.getType()}), + operand1, operand2); + }]> + ]; + let hasVerifier = 1; } @@ -485,6 +493,14 @@ def SPV_ISubBorrowOp : SPV_BinaryOp<"ISubBorrow", SPV_AnyStruct, SPV_Integer, SPV_AnyStruct:$result ); + let builders = [ + OpBuilder<(ins "Value":$operand1, "Value":$operand2), [{ + build($_builder, $_state, + ::mlir::spirv::StructType::get({operand1.getType(), operand1.getType()}), + operand1, operand2); + }]> + ]; + let hasVerifier = 1; } diff --git a/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp b/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp index 9b7621f..6ca37c6 100644 --- a/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp +++ b/mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp @@ -854,11 +854,9 @@ LogicalResult AddICarryOpPattern::matchAndRewrite(arith::AddUICarryOp op, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const { Type dstElemTy = adaptor.getLhs().getType(); - auto resultTy = spirv::StructType::get({dstElemTy, dstElemTy}); - Location loc = op->getLoc(); Value result = rewriter.create( - loc, resultTy, adaptor.getLhs(), adaptor.getRhs()); + loc, adaptor.getLhs(), adaptor.getRhs()); Value sumResult = rewriter.create( loc, result, llvm::makeArrayRef(0)); -- 2.7.4