diff --git a/mlir/include/mlir/Dialect/PDL/IR/PDL.h b/mlir/include/mlir/Dialect/PDL/IR/PDL.h --- 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 rename from mlir/include/mlir/Dialect/PDL/IR/PDLBase.td rename to mlir/include/mlir/Dialect/PDL/IR/PDLDialect.td --- 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 @@ let cppNamespace = "::mlir::pdl"; } -//===----------------------------------------------------------------------===// -// PDL Types -//===----------------------------------------------------------------------===// - -class PDL_Handle : - DialectType()">, - 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/PDL.h b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.h copy from mlir/include/mlir/Dialect/PDL/IR/PDL.h copy to mlir/include/mlir/Dialect/PDL/IR/PDLOps.h --- a/mlir/include/mlir/Dialect/PDL/IR/PDL.h +++ b/mlir/include/mlir/Dialect/PDL/IR/PDLOps.h @@ -1,4 +1,4 @@ -//===- PDL.h - Pattern Descriptor Language Dialect --------------*- C++ -*-===// +//===- 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. @@ -6,25 +6,19 @@ // //===----------------------------------------------------------------------===// // -// This file defines the dialect for the Pattern Descriptor Language. +// This file defines the operations for the Pattern Descriptor Language dialect. // //===----------------------------------------------------------------------===// -#ifndef MLIR_DIALECT_PDL_IR_PDL_H_ -#define MLIR_DIALECT_PDL_IR_PDL_H_ +#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/Dialect.h" #include "mlir/IR/OpImplementation.h" #include "mlir/IR/SymbolTable.h" #include "mlir/Interfaces/SideEffectInterfaces.h" -//===----------------------------------------------------------------------===// -// PDL Dialect -//===----------------------------------------------------------------------===// - -#include "mlir/Dialect/PDL/IR/PDLOpsDialect.h.inc" - //===----------------------------------------------------------------------===// // PDL Dialect Operations //===----------------------------------------------------------------------===// @@ -32,5 +26,4 @@ #define GET_OP_CLASSES #include "mlir/Dialect/PDL/IR/PDLOps.h.inc" - -#endif // MLIR_DIALECT_PDL_IR_PDL_H_ +#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 --- 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 --- 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 { - using Base::Base; -}; - -/// This type represents a handle to an `mlir::Operation*`. -struct OperationType : public Type::TypeBase { - using Base::Base; -}; - -/// This type represents a handle to an `mlir::Type`. -struct TypeType : public Type::TypeBase { - using Base::Base; -}; - -/// This type represents a handle to an `mlir::Value`. -struct ValueType : public Type::TypeBase { - using Base::Base; -}; - -} // end namespace pdl -} // end namespace mlir +#define GET_TYPEDEF_CLASSES +#include "mlir/Dialect/PDL/IR/PDLTypes.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 --- /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 : TypeDef { + 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 --- 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 --- 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/include/mlir/IR/OpBase.td b/mlir/include/mlir/IR/OpBase.td --- a/mlir/include/mlir/IR/OpBase.td +++ b/mlir/include/mlir/IR/OpBase.td @@ -345,7 +345,8 @@ Or, !if(!eq(summary, ""), !interleave(!foreach(t, allowedTypes, t.summary), " or "), - summary)>; + summary), + cppClassName>; // Integer types. diff --git a/mlir/include/mlir/TableGen/Type.h b/mlir/include/mlir/TableGen/Type.h --- a/mlir/include/mlir/TableGen/Type.h +++ b/mlir/include/mlir/TableGen/Type.h @@ -49,7 +49,7 @@ Optional getBuilderCall() const; // Return the C++ class name for this type (which may just be ::mlir::Type). - StringRef getCPPClassName() const; + std::string getCPPClassName() const; }; // Wrapper class with helper methods for accessing Types defined in TableGen. diff --git a/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.h b/mlir/lib/Conversion/PDLToPDLInterp/PredicateTree.h --- 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 --- a/mlir/lib/Dialect/PDL/IR/PDL.cpp +++ b/mlir/lib/Dialect/PDL/IR/PDL.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #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" diff --git a/mlir/lib/Rewrite/FrozenRewritePatternList.cpp b/mlir/lib/Rewrite/FrozenRewritePatternList.cpp --- 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" diff --git a/mlir/lib/TableGen/Type.cpp b/mlir/lib/TableGen/Type.cpp --- a/mlir/lib/TableGen/Type.cpp +++ b/mlir/lib/TableGen/Type.cpp @@ -11,6 +11,8 @@ //===----------------------------------------------------------------------===// #include "mlir/TableGen/Type.h" +#include "mlir/TableGen/Dialect.h" +#include "llvm/ADT/Twine.h" #include "llvm/ADT/TypeSwitch.h" #include "llvm/TableGen/Record.h" @@ -54,8 +56,19 @@ } // Return the C++ class name for this type (which may just be ::mlir::Type). -StringRef TypeConstraint::getCPPClassName() const { - return def->getValueAsString("cppClassName"); +std::string TypeConstraint::getCPPClassName() const { + StringRef className = def->getValueAsString("cppClassName"); + + // If the class name is already namespace resolved, use it. + if (className.contains("::")) + return className.str(); + + // Otherwise, check to see if there is a namespace from a dialect to prepend. + if (const llvm::RecordVal *value = def->getValue("dialect")) { + Dialect dialect(cast(value->getValue())->getDef()); + return (dialect.getCppNamespace() + "::" + className).str(); + } + return className.str(); } Type::Type(const llvm::Record *record) : TypeConstraint(record) {}