[llvm-branch-commits] [mlir] e45840f - [mlir][PDL] Use ODS for defining PDL types
River Riddle via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Jan 8 12:49:42 PST 2021
Author: River Riddle
Date: 2021-01-08T12:32:28-08:00
New Revision: e45840f4af46df0f8be92790b45f9432cf8ba19e
URL: https://github.com/llvm/llvm-project/commit/e45840f4af46df0f8be92790b45f9432cf8ba19e
DIFF: https://github.com/llvm/llvm-project/commit/e45840f4af46df0f8be92790b45f9432cf8ba19e.diff
LOG: [mlir][PDL] Use ODS for defining PDL types
This removes the need to define these classes and their parser/printers in C++.
Differential Revision: https://reviews.llvm.org/D94135
Added:
mlir/include/mlir/Dialect/PDL/IR/PDLDialect.td
mlir/include/mlir/Dialect/PDL/IR/PDLOps.h
mlir/include/mlir/Dialect/PDL/IR/PDLTypes.td
Modified:
mlir/include/mlir/Dialect/PDL/IR/PDL.h
mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
mlir/include/mlir/Dialect/PDL/IR/PDLTypes.h
mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h
mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.h
mlir/lib/Dialect/PDL/IR/PDL.cpp
mlir/lib/Rewrite/FrozenRewritePatternList.cpp
Removed:
mlir/include/mlir/Dialect/PDL/IR/PDLBase.td
################################################################################
diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDL.h b/mlir/include/mlir/Dialect/PDL/IR/PDL.h
index 14136021d26c..bbc52301360d 100644
--- a/mlir/include/mlir/Dialect/PDL/IR/PDL.h
+++ b/mlir/include/mlir/Dialect/PDL/IR/PDL.h
@@ -13,11 +13,7 @@
#ifndef MLIR_DIALECT_PDL_IR_PDL_H_
#define MLIR_DIALECT_PDL_IR_PDL_H_
-#include "mlir/IR/Builders.h"
#include "mlir/IR/Dialect.h"
-#include "mlir/IR/OpImplementation.h"
-#include "mlir/IR/SymbolTable.h"
-#include "mlir/Interfaces/SideEffectInterfaces.h"
//===----------------------------------------------------------------------===//
// PDL Dialect
@@ -25,12 +21,4 @@
#include "mlir/Dialect/PDL/IR/PDLOpsDialect.h.inc"
-//===----------------------------------------------------------------------===//
-// PDL Dialect Operations
-//===----------------------------------------------------------------------===//
-
-#define GET_OP_CLASSES
-#include "mlir/Dialect/PDL/IR/PDLOps.h.inc"
-
-
#endif // MLIR_DIALECT_PDL_IR_PDL_H_
diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDLBase.td b/mlir/include/mlir/Dialect/PDL/IR/PDLDialect.td
similarity index 69%
rename from mlir/include/mlir/Dialect/PDL/IR/PDLBase.td
rename to mlir/include/mlir/Dialect/PDL/IR/PDLDialect.td
index b372e594e2e7..14a8400a79b9 100644
--- a/mlir/include/mlir/Dialect/PDL/IR/PDLBase.td
+++ b/mlir/include/mlir/Dialect/PDL/IR/PDLDialect.td
@@ -1,4 +1,4 @@
-//===- PDLBase.td - PDL base definitions -------------------*- tablegen -*-===//
+//===- PDLDialect.td - PDL dialect definition --------------*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -6,12 +6,12 @@
//
//===----------------------------------------------------------------------===//
//
-// Defines base support for MLIR PDL operations.
+// Defines the MLIR PDL dialect.
//
//===----------------------------------------------------------------------===//
-#ifndef MLIR_DIALECT_PDL_IR_PDLBASE
-#define MLIR_DIALECT_PDL_IR_PDLBASE
+#ifndef MLIR_DIALECT_PDL_IR_PDLDIALECT
+#define MLIR_DIALECT_PDL_IR_PDLDIALECT
include "mlir/IR/OpBase.td"
@@ -66,31 +66,4 @@ def PDL_Dialect : Dialect {
let cppNamespace = "::mlir::pdl";
}
-//===----------------------------------------------------------------------===//
-// PDL Types
-//===----------------------------------------------------------------------===//
-
-class PDL_Handle<string underlying> :
- DialectType<PDL_Dialect, CPred<"$_self.isa<" # underlying # ">()">,
- underlying>,
- BuildableType<"$_builder.getType<" # underlying # ">()">;
-
-// Handle for `mlir::Attribute`.
-def PDL_Attribute : PDL_Handle<"mlir::pdl::AttributeType">;
-
-// Handle for `mlir::Operation*`.
-def PDL_Operation : PDL_Handle<"mlir::pdl::OperationType">;
-
-// Handle for `mlir::Type`.
-def PDL_Type : PDL_Handle<"mlir::pdl::TypeType">;
-
-// Handle for `mlir::Value`.
-def PDL_Value : PDL_Handle<"mlir::pdl::ValueType">;
-
-// A positional value is a location on a pattern DAG, which may be an operation,
-// an attribute, or an operand/result.
-def PDL_PositionalValue :
- AnyTypeOf<[PDL_Attribute, PDL_Operation, PDL_Type, PDL_Value],
- "Positional Value">;
-
-#endif // MLIR_DIALECT_PDL_IR_PDLBASE
+#endif // MLIR_DIALECT_PDL_IR_PDLDIALECT
diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDLOps.h b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.h
new file mode 100644
index 000000000000..8e560ae09ee8
--- /dev/null
+++ b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.h
@@ -0,0 +1,29 @@
+//===- PDLOps.h - Pattern Descriptor Language Operations --------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the operations for the Pattern Descriptor Language dialect.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_DIALECT_PDL_IR_PDLOPS_H_
+#define MLIR_DIALECT_PDL_IR_PDLOPS_H_
+
+#include "mlir/Dialect/PDL/IR/PDLTypes.h"
+#include "mlir/IR/Builders.h"
+#include "mlir/IR/OpImplementation.h"
+#include "mlir/IR/SymbolTable.h"
+#include "mlir/Interfaces/SideEffectInterfaces.h"
+
+//===----------------------------------------------------------------------===//
+// PDL Dialect Operations
+//===----------------------------------------------------------------------===//
+
+#define GET_OP_CLASSES
+#include "mlir/Dialect/PDL/IR/PDLOps.h.inc"
+
+#endif // MLIR_DIALECT_PDL_IR_PDLOPS_H_
diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
index 1cbc044680e3..e4a9ebe8900d 100644
--- a/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
+++ b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.td
@@ -13,7 +13,7 @@
#ifndef MLIR_DIALECT_PDL_IR_PDLOPS
#define MLIR_DIALECT_PDL_IR_PDLOPS
-include "mlir/Dialect/PDL/IR/PDLBase.td"
+include "mlir/Dialect/PDL/IR/PDLTypes.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/IR/SymbolInterfaces.td"
diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDLTypes.h b/mlir/include/mlir/Dialect/PDL/IR/PDLTypes.h
index b3cfcc848064..a9028f3d5972 100644
--- a/mlir/include/mlir/Dialect/PDL/IR/PDLTypes.h
+++ b/mlir/include/mlir/Dialect/PDL/IR/PDLTypes.h
@@ -1,4 +1,4 @@
-//===- PDL.h - Pattern Descriptor Language Types ----------------*- C++ -*-===//
+//===- PDLTypes.h - Pattern Descriptor Language Types -----------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -15,33 +15,11 @@
#include "mlir/IR/Types.h"
-namespace mlir {
-namespace pdl {
//===----------------------------------------------------------------------===//
// PDL Dialect Types
//===----------------------------------------------------------------------===//
-/// This type represents a handle to an `mlir::Attribute`.
-struct AttributeType : public Type::TypeBase<AttributeType, Type, TypeStorage> {
- using Base::Base;
-};
-
-/// This type represents a handle to an `mlir::Operation*`.
-struct OperationType : public Type::TypeBase<OperationType, Type, TypeStorage> {
- using Base::Base;
-};
-
-/// This type represents a handle to an `mlir::Type`.
-struct TypeType : public Type::TypeBase<TypeType, Type, TypeStorage> {
- using Base::Base;
-};
-
-/// This type represents a handle to an `mlir::Value`.
-struct ValueType : public Type::TypeBase<ValueType, Type, TypeStorage> {
- using Base::Base;
-};
-
-} // end namespace pdl
-} // end namespace mlir
+#define GET_TYPEDEF_CLASSES
+#include "mlir/Dialect/PDL/IR/PDLOpsTypes.h.inc"
#endif // MLIR_DIALECT_PDL_IR_PDLTYPES_H_
diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDLTypes.td b/mlir/include/mlir/Dialect/PDL/IR/PDLTypes.td
new file mode 100644
index 000000000000..1cf0b1e25af5
--- /dev/null
+++ b/mlir/include/mlir/Dialect/PDL/IR/PDLTypes.td
@@ -0,0 +1,84 @@
+//===- PDLTypes.td - Pattern descriptor types --------------*- tablegen -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file declares the Pattern Descriptor Language dialect types.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_DIALECT_PDL_IR_PDLTYPES
+#define MLIR_DIALECT_PDL_IR_PDLTYPES
+
+include "mlir/Dialect/PDL/IR/PDLDialect.td"
+
+//===----------------------------------------------------------------------===//
+// PDL Types
+//===----------------------------------------------------------------------===//
+
+class PDL_Type<string name, string typeMnemonic> : TypeDef<PDL_Dialect, name> {
+ let mnemonic = typeMnemonic;
+}
+
+//===----------------------------------------------------------------------===//
+// pdl::AttributeType
+//===----------------------------------------------------------------------===//
+
+def PDL_Attribute : PDL_Type<"Attribute", "attribute"> {
+ let summary = "PDL handle to an `mlir::Attribute`";
+ let description = [{
+ This type represents a handle to an instance of an `mlir::Attribute`, bound
+ to a value that is usable within a PDL pattern or rewrite.
+ }];
+}
+
+//===----------------------------------------------------------------------===//
+// pdl::OperationType
+//===----------------------------------------------------------------------===//
+
+def PDL_Operation : PDL_Type<"Operation", "operation"> {
+ let summary = "PDL handle to an `mlir::Operation *`";
+ let description = [{
+ This type represents a handle to an instance of an `mlir::Operation *`,
+ bound to a value that is usable within a PDL pattern or rewrite.
+ }];
+}
+
+//===----------------------------------------------------------------------===//
+// pdl::TypeType
+//===----------------------------------------------------------------------===//
+
+def PDL_Type : PDL_Type<"Type", "type"> {
+ let summary = "PDL handle to an `mlir::Type`";
+ let description = [{
+ This type represents a handle to an instance of an `mlir::Type`, bound to a
+ value that is usable within a PDL pattern or rewrite.
+ }];
+}
+
+//===----------------------------------------------------------------------===//
+// pdl::ValueType
+//===----------------------------------------------------------------------===//
+
+def PDL_Value : PDL_Type<"Value", "value"> {
+ let summary = "PDL handle for an `mlir::Value`";
+ let description = [{
+ This type represents a handle to an instance of an `mlir::Value`, bound to a
+ value that is usable within a PDL pattern or rewrite.
+ }];
+}
+
+//===----------------------------------------------------------------------===//
+// Additional Type Constraints
+//===----------------------------------------------------------------------===//
+
+// A positional value is a location on a pattern DAG, which may be an attribute,
+// operation, or operand/result.
+def PDL_PositionalValue :
+ AnyTypeOf<[PDL_Attribute, PDL_Operation, PDL_Type, PDL_Value],
+ "Positional Value">;
+
+#endif // MLIR_DIALECT_PDL_IR_PDLTYPES
diff --git a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h
index 07c7f84c8078..a7e1d039c093 100644
--- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h
+++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterp.h
@@ -15,6 +15,7 @@
#define MLIR_DIALECT_PDLINTERP_IR_PDLINTERP_H_
#include "mlir/Dialect/PDL/IR/PDL.h"
+#include "mlir/Dialect/PDL/IR/PDLTypes.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
diff --git a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
index 6b11c0dde809..5720a624ef95 100644
--- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
+++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
@@ -13,7 +13,7 @@
#ifndef MLIR_DIALECT_PDLINTERP_IR_PDLINTERPOPS
#define MLIR_DIALECT_PDLINTERP_IR_PDLINTERPOPS
-include "mlir/Dialect/PDL/IR/PDLBase.td"
+include "mlir/Dialect/PDL/IR/PDLTypes.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
//===----------------------------------------------------------------------===//
diff --git a/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.h b/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.h
index 15ba8cca3262..1621fa96747b 100644
--- a/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.h
+++ b/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.h
@@ -15,7 +15,7 @@
#define MLIR_LIB_CONVERSION_PDLTOPDLINTERP_PREDICATETREE_H_
#include "Predicate.h"
-#include "mlir/Dialect/PDL/IR/PDL.h"
+#include "mlir/Dialect/PDL/IR/PDLOps.h"
#include "llvm/ADT/MapVector.h"
namespace mlir {
diff --git a/mlir/lib/Dialect/PDL/IR/PDL.cpp b/mlir/lib/Dialect/PDL/IR/PDL.cpp
index 7791632216c8..0268e6e80bbd 100644
--- a/mlir/lib/Dialect/PDL/IR/PDL.cpp
+++ b/mlir/lib/Dialect/PDL/IR/PDL.cpp
@@ -7,11 +7,13 @@
//===----------------------------------------------------------------------===//
#include "mlir/Dialect/PDL/IR/PDL.h"
+#include "mlir/Dialect/PDL/IR/PDLOps.h"
#include "mlir/Dialect/PDL/IR/PDLTypes.h"
#include "mlir/IR/BuiltinTypes.h"
#include "mlir/IR/DialectImplementation.h"
#include "mlir/Interfaces/InferTypeOpInterface.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/TypeSwitch.h"
using namespace mlir;
using namespace mlir::pdl;
@@ -25,38 +27,10 @@ void PDLDialect::initialize() {
#define GET_OP_LIST
#include "mlir/Dialect/PDL/IR/PDLOps.cpp.inc"
>();
- addTypes<AttributeType, OperationType, TypeType, ValueType>();
-}
-
-Type PDLDialect::parseType(DialectAsmParser &parser) const {
- StringRef keyword;
- if (parser.parseKeyword(&keyword))
- return Type();
-
- Builder &builder = parser.getBuilder();
- Type result = StringSwitch<Type>(keyword)
- .Case("attribute", builder.getType<AttributeType>())
- .Case("operation", builder.getType<OperationType>())
- .Case("type", builder.getType<TypeType>())
- .Case("value", builder.getType<ValueType>())
- .Default(Type());
- if (!result)
- parser.emitError(parser.getNameLoc(), "invalid 'pdl' type: `")
- << keyword << "'";
- return result;
-}
-
-void PDLDialect::printType(Type type, DialectAsmPrinter &printer) const {
- if (type.isa<AttributeType>())
- printer << "attribute";
- else if (type.isa<OperationType>())
- printer << "operation";
- else if (type.isa<TypeType>())
- printer << "type";
- else if (type.isa<ValueType>())
- printer << "value";
- else
- llvm_unreachable("unknown 'pdl' type");
+ addTypes<
+#define GET_TYPEDEF_LIST
+#include "mlir/Dialect/PDL/IR/PDLOpsTypes.cpp.inc"
+ >();
}
/// Returns true if the given operation is used by a "binding" pdl operation
@@ -456,3 +430,27 @@ static LogicalResult verify(TypeOp op) {
#define GET_OP_CLASSES
#include "mlir/Dialect/PDL/IR/PDLOps.cpp.inc"
+
+//===----------------------------------------------------------------------===//
+// TableGen'd type method definitions
+//===----------------------------------------------------------------------===//
+
+#define GET_TYPEDEF_CLASSES
+#include "mlir/Dialect/PDL/IR/PDLOpsTypes.cpp.inc"
+
+Type PDLDialect::parseType(DialectAsmParser &parser) const {
+ StringRef keyword;
+ if (parser.parseKeyword(&keyword))
+ return Type();
+ if (Type type = generatedTypeParser(getContext(), parser, keyword))
+ return type;
+
+ parser.emitError(parser.getNameLoc(), "invalid 'pdl' type: `")
+ << keyword << "'";
+ return Type();
+}
+
+void PDLDialect::printType(Type type, DialectAsmPrinter &printer) const {
+ if (failed(generatedTypePrinter(type, printer)))
+ llvm_unreachable("unknown 'pdl' type");
+}
diff --git a/mlir/lib/Rewrite/FrozenRewritePatternList.cpp b/mlir/lib/Rewrite/FrozenRewritePatternList.cpp
index 40d7fcde8f33..40f7aec44e51 100644
--- a/mlir/lib/Rewrite/FrozenRewritePatternList.cpp
+++ b/mlir/lib/Rewrite/FrozenRewritePatternList.cpp
@@ -9,7 +9,7 @@
#include "mlir/Rewrite/FrozenRewritePatternList.h"
#include "ByteCode.h"
#include "mlir/Conversion/PDLToPDLInterp/PDLToPDLInterp.h"
-#include "mlir/Dialect/PDL/IR/PDL.h"
+#include "mlir/Dialect/PDL/IR/PDLOps.h"
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "mlir/Pass/Pass.h"
#include "mlir/Pass/PassManager.h"
More information about the llvm-branch-commits
mailing list