From e558c040aabc7c2d935d333b11b7d94c5f1337b9 Mon Sep 17 00:00:00 2001 From: Jing Pu Date: Wed, 17 Jul 2019 20:10:39 -0700 Subject: [PATCH] Add UnitAttr in OpBase.td. Note that UnitAttr cannot be used for op definition yet. PiperOrigin-RevId: 258693338 --- mlir/include/mlir/IR/OpBase.td | 8 ++++++++ mlir/test/mlir-tblgen/pattern-multi-result-op.td | 22 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/mlir/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td index de359f9..fac0a4e 100644 --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -640,6 +640,14 @@ class TypeAttrBase : def TypeAttr : TypeAttrBase<"Type", "any type attribute">; + +// TODO(antiagainst): UnitAttr cannot be used for op definition because there +// is no valid builder and getter defined. We should add them to complete +// the definition. +def UnitAttr : Attr()">, "unit attribute"> { + let storageType = [{ UnitAttr }]; +} + //===----------------------------------------------------------------------===// // Enum attribute kinds diff --git a/mlir/test/mlir-tblgen/pattern-multi-result-op.td b/mlir/test/mlir-tblgen/pattern-multi-result-op.td index 063d480..d250956 100644 --- a/mlir/test/mlir-tblgen/pattern-multi-result-op.td +++ b/mlir/test/mlir-tblgen/pattern-multi-result-op.td @@ -1,4 +1,4 @@ -// RUN: mlir-tblgen -gen-rewriters -I %S/../../include %s | FileCheck %s +// RUN: mlir-tblgen -gen-rewriters -I %S/../../include %s | FileCheck %s --dump-input-on-failure include "mlir/IR/OpBase.td" @@ -67,3 +67,23 @@ def c : Pattern<(TwoResultOp $input), [ // CHECK-NEXT: /*input=*/interm // CHECK: auto vOneResultOp1 = rewriter.create( // CHECK: rewriter.replaceOp(op, {vOneResultOp0.getOperation()->getResult(0), vOneResultOp1.getOperation()->getResult(0)}); + + +// Test UnitAttr in rewrite patterns +// --- + +def UnitAttrOp : NS_Op<"unit_attr_op", []> { + let arguments = (ins AnyAttr:$value); + let results = (outs NoneType:$output); +} + +def NoneOp : NS_Op<"none_op", []> { + let results = (outs NoneType:$output); +} + +def d : Pat<(UnitAttrOp UnitAttr:$ignore), + (NoneOp)>; + +// CHECK-LABEL: struct d +// CHECK: PatternMatchResult match(Operation *op0) const override { +// CHECK: if (!((attr.isa()))) return matchFailure(); -- 2.7.4