[mlir][spirv] Add convenience builders for AddICarry and SubIBorrow
authorJakub Kuderski <kubak@google.com>
Thu, 25 Aug 2022 20:54:26 +0000 (16:54 -0400)
committerJakub Kuderski <kubak@google.com>
Thu, 25 Aug 2022 20:55:24 +0000 (16:55 -0400)
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
mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp

index 7ce34dc..beed00e 100644 (file)
@@ -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;
 }
 
index 9b7621f..6ca37c6 100644 (file)
@@ -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<spirv::IAddCarryOp>(
-      loc, resultTy, adaptor.getLhs(), adaptor.getRhs());
+      loc, adaptor.getLhs(), adaptor.getRhs());
 
   Value sumResult = rewriter.create<spirv::CompositeExtractOp>(
       loc, result, llvm::makeArrayRef(0));