[PATCH] D80705: [MLIR] Add TensorFromElementsOp to Standard ops.

Alexander Belyaev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 28 15:25:46 PDT 2020


pifon2a marked an inline comment as done.
pifon2a added inline comments.


================
Comment at: mlir/include/mlir/Dialect/StandardOps/IR/Ops.td:1556
+    }]>];
+
+  let hasCanonicalizer = 1;
----------------
rriddle wrote:
> herhut wrote:
> > pifon2a wrote:
> > > herhut wrote:
> > > > Would `let assemblyFormat = "`(` $elements `)` attr-dict `:` type($result)";` work?
> > > no, it wouldn't. It would need to know the elements type to parse it. Can I use assemblyFormat for printing only and a custom parser?
> > Answer is, it does not because the operand types cannot be deduced with the given traits.
> You can do that with TypesMatchWith, this is common:
> https://github.com/llvm/llvm-project/blob/0073c293a401774ac96b4b3d27f05e13f379f98e/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td#L484
> https://github.com/llvm/llvm-project/blob/0073c293a401774ac96b4b3d27f05e13f379f98e/mlir/include/mlir/Dialect/StandardOps/IR/Ops.td#L1479
I might be doing smth wrong, but if i have the following op:

```mlir
def TensorFromElementsOp : Std_Op<"tensor_from_elements",
    [NoSideEffect, SameOperandsAndResultElementType,
     TypesMatchWith<"value type matches element type of memref",
                    "result", "elements",
                    "$_self.cast<RankedTensorType>().getElementType()">
    ]> {

  let arguments = (ins Variadic<AnyType>:$elements);
  let results = (outs AnyTensor:$result);

  let assemblyFormat = "`(` $elements `)` attr-dict `:` type($result)";
}
```
then the operands will be resolved with a wrong `resolveOperands` overload. It should use 
```
  ParseResult resolveOperands(ArrayRef<OperandType> operands, Type type,
                              SmallVectorImpl<Value> &result)
```
instead of
```
ParseResult resolveOperands(ArrayRef<OperandType> operands,
                              ArrayRef<Type> types, llvm::SMLoc loc,
                              SmallVectorImpl<Value> &result)
```


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D80705





More information about the llvm-commits mailing list