[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 16:18:19 PDT 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rG57a7cd7a138f: [shape] Add inferReturnTypes to a couple ops. (authored by silvas).

Changed prior to commit:
  https://reviews.llvm.org/D78822?vs=259941&id=260024#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D78822/new/

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
@@ -92,6 +92,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;
@@ -175,6 +183,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().dyn_cast<ShapedType>();
   if (!type || !type.hasStaticShape())
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:
@@ -317,7 +318,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.260024.patch
Type: text/x-patch
Size: 2323 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200424/abf04a24/attachment.bin>


More information about the llvm-commits mailing list