[PATCH] D78822: [shape] Add inferReturnTypes to a couple ops.
Sean Silva via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 24 11:21:08 PDT 2020
silvas created this revision.
silvas added a reviewer: jpienaar.
Herald added subscribers: llvm-commits, Kayjukh, frgossen, grosul1, Joonsoo, liufengdb, aartbik, lucyrfox, mgester, arpith-jacob, nicolasvasilache, antiagainst, shauheen, rriddle, mehdi_amini.
Herald added 1 blocking reviewer(s): jpienaar.
Herald added a project: LLVM.
- ShapeOfOp
- BroadcastOp
Depends On D78821 <https://reviews.llvm.org/D78821>
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D78822
Files:
mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
mlir/lib/Dialect/Shape/IR/Shape.cpp
Index: mlir/lib/Dialect/Shape/IR/Shape.cpp
===================================================================
--- mlir/lib/Dialect/Shape/IR/Shape.cpp
+++ mlir/lib/Dialect/Shape/IR/Shape.cpp
@@ -89,6 +89,14 @@
// ShapeOfOp
//===----------------------------------------------------------------------===//
+LogicalResult ShapeOfOp::inferReturnTypes(
+ MLIRContext *context, Optional<Location> location, ValueRange operands,
+ ArrayRef<NamedAttribute> attributes, RegionRange regions,
+ SmallVectorImpl<Type> &inferredReturnTypes) {
+ inferredReturnTypes.push_back(ShapeType::get(context));
+ return success();
+}
+
OpFoldResult ShapeOfOp::fold(ArrayRef<Attribute>) {
auto type = getOperand().getType().cast<ShapedType>();
if (!type.hasStaticShape())
@@ -101,6 +109,14 @@
// BroadcastOp
//===----------------------------------------------------------------------===//
+LogicalResult BroadcastOp::inferReturnTypes(
+ MLIRContext *context, Optional<Location> location, ValueRange operands,
+ ArrayRef<NamedAttribute> attributes, RegionRange regions,
+ SmallVectorImpl<Type> &inferredReturnTypes) {
+ inferredReturnTypes.push_back(ShapeType::get(context));
+ return success();
+}
+
OpFoldResult BroadcastOp::fold(ArrayRef<Attribute> operands) {
if (!operands[0] || !operands[1])
return nullptr;
Index: mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
===================================================================
--- mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
+++ mlir/include/mlir/Dialect/Shape/IR/ShapeOps.td
@@ -130,7 +130,8 @@
let results = (outs Shape_SizeType:$result);
}
-def Shape_BroadcastOp : Shape_Op<"broadcast", []> {
+def Shape_BroadcastOp : Shape_Op<"broadcast",
+ [DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
let summary = "Returns the broadcasted output shape of two inputs";
let description = [{
Computes the broadcasted output shape following:
@@ -313,7 +314,8 @@
let regions = (region SizedRegion<1>:$body);
}
-def Shape_ShapeOfOp : Shape_Op<"shape_of", []> {
+def Shape_ShapeOfOp : Shape_Op<"shape_of",
+ [DeclareOpInterfaceMethods<InferTypeOpInterface>]> {
let summary = "Returns shape of a value or shaped type operand";
let arguments = (ins AnyTypeOf<[AnyShaped, Shape_ValueShapeType]>:$arg);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78822.259941.patch
Type: text/x-patch
Size: 2310 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200424/ce2fa634/attachment.bin>
More information about the llvm-commits
mailing list