Add UnitAttr in OpBase.td.
authorJing Pu <jingpu@google.com>
Thu, 18 Jul 2019 03:10:39 +0000 (20:10 -0700)
committerMehdi Amini <joker.eph@gmail.com>
Fri, 19 Jul 2019 18:39:29 +0000 (11:39 -0700)
Note that UnitAttr cannot be used for op definition yet.

PiperOrigin-RevId: 258693338

mlir/include/mlir/IR/OpBase.td
mlir/test/mlir-tblgen/pattern-multi-result-op.td

index de359f9..fac0a4e 100644 (file)
@@ -640,6 +640,14 @@ class TypeAttrBase<string retType, string description> :
 
 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<CPred<"$_self.isa<UnitAttr>()">, "unit attribute"> {
+  let storageType = [{ UnitAttr }];
+}
+
 //===----------------------------------------------------------------------===//
 // Enum attribute kinds
 
index 063d480..d250956 100644 (file)
@@ -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<OneResultOp>(
 // 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<UnitAttr>()))) return matchFailure();