From f3ab0ccd00db3bb26851d3e1cf4a789fe7fa6e2c Mon Sep 17 00:00:00 2001 From: MaheshRavishankar Date: Tue, 25 Jan 2022 11:44:54 -0800 Subject: [PATCH] [mlir][Linalg] Add couple of convenience methods to `LinalgInterface`. Add methods to - Get block argument that is tied with an opOperand - Get the yield value that is tied with a output opOperand. Differential Revision: https://reviews.llvm.org/D118085 --- .../mlir/Dialect/Linalg/IR/LinalgInterfaces.td | 31 ++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td index 413c2cc..f40f82e 100644 --- a/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td +++ b/mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td @@ -643,6 +643,19 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> { >, InterfaceMethod< /*desc=*/[{ + Return the block argument for an `opOperand`. + }], + /*retTy=*/"BlockArgument", + /*methodName=*/"getTiedBlockArgument", + /*args=*/(ins "OpOperand *":$opOperand), + /*methodBody=*/"", + /*defaultImplementation=*/[{ + assert(opOperand->getOwner() == this->getOperation()); + return getBlock()->getArgument(opOperand->getOperandNumber()); + }] + >, + InterfaceMethod< + /*desc=*/[{ Return the input or output indexing map for `opOperand`. }], /*retTy=*/"AffineMap", @@ -672,6 +685,24 @@ def LinalgStructuredInterface : OpInterface<"LinalgOp"> { return this->getOperation()->getResult(resultIndex); }] >, + InterfaceMethod< + /*desc=*/[{ + Return the value yielded by the region corresponding to an output + `opOperand`. + }], + /*retTy=*/"OpOperand *", + /*methodName=*/"getTiedYieldValue", + /*args=*/(ins "OpOperand*":$opOperand), + /*methodBody=*/"", + /*defaultImplementation=*/[{ + assert(opOperand->getOwner() == this->getOperation()); + int64_t resultIndex = opOperand->getOperandNumber() - getNumInputs(); + assert(resultIndex >= 0 && + resultIndex < this->getOperation()->getNumResults()); + Operation *yieldOp = getBlock()->getTerminator(); + return &yieldOp->getOpOperand(resultIndex); + }] + >, //===------------------------------------------------------------------===// // Other interface methods. //===------------------------------------------------------------------===// -- 2.7.4