//===- PDL.cpp - Pattern Descriptor Language Dialect ----------------------===// // // 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 // //===----------------------------------------------------------------------===// #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/Interfaces/InferTypeOpInterface.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/TypeSwitch.h" #include <optional> usingnamespacemlir; usingnamespacemlir::pdl; #include "mlir/Dialect/PDL/IR/PDLOpsDialect.cpp.inc" //===----------------------------------------------------------------------===// // PDLDialect //===----------------------------------------------------------------------===// void PDLDialect::initialize() { … } //===----------------------------------------------------------------------===// // PDL Operations //===----------------------------------------------------------------------===// /// Returns true if the given operation is used by a "binding" pdl operation. static bool hasBindingUse(Operation *op) { … } /// Returns success if the given operation is not in the main matcher body or /// is used by a "binding" operation. On failure, emits an error. static LogicalResult verifyHasBindingUse(Operation *op) { … } /// Visits all the pdl.operand(s), pdl.result(s), and pdl.operation(s) /// connected to the given operation. static void visit(Operation *op, DenseSet<Operation *> &visited) { … } //===----------------------------------------------------------------------===// // pdl::ApplyNativeConstraintOp //===----------------------------------------------------------------------===// LogicalResult ApplyNativeConstraintOp::verify() { … } //===----------------------------------------------------------------------===// // pdl::ApplyNativeRewriteOp //===----------------------------------------------------------------------===// LogicalResult ApplyNativeRewriteOp::verify() { … } //===----------------------------------------------------------------------===// // pdl::AttributeOp //===----------------------------------------------------------------------===// LogicalResult AttributeOp::verify() { … } //===----------------------------------------------------------------------===// // pdl::OperandOp //===----------------------------------------------------------------------===// LogicalResult OperandOp::verify() { … } //===----------------------------------------------------------------------===// // pdl::OperandsOp //===----------------------------------------------------------------------===// LogicalResult OperandsOp::verify() { … } //===----------------------------------------------------------------------===// // pdl::OperationOp //===----------------------------------------------------------------------===// static ParseResult parseOperationOpAttributes( OpAsmParser &p, SmallVectorImpl<OpAsmParser::UnresolvedOperand> &attrOperands, ArrayAttr &attrNamesAttr) { … } static void printOperationOpAttributes(OpAsmPrinter &p, OperationOp op, OperandRange attrArgs, ArrayAttr attrNames) { … } /// Verifies that the result types of this operation, defined within a /// `pdl.rewrite`, can be inferred. static LogicalResult verifyResultTypesAreInferrable(OperationOp op, OperandRange resultTypes) { … } LogicalResult OperationOp::verify() { … } bool OperationOp::hasTypeInference() { … } bool OperationOp::mightHaveTypeInference() { … } //===----------------------------------------------------------------------===// // pdl::PatternOp //===----------------------------------------------------------------------===// LogicalResult PatternOp::verifyRegions() { … } void PatternOp::build(OpBuilder &builder, OperationState &state, std::optional<uint16_t> benefit, std::optional<StringRef> name) { … } /// Returns the rewrite operation of this pattern. RewriteOp PatternOp::getRewriter() { … } /// The default dialect is `pdl`. StringRef PatternOp::getDefaultDialect() { … } //===----------------------------------------------------------------------===// // pdl::RangeOp //===----------------------------------------------------------------------===// static ParseResult parseRangeType(OpAsmParser &p, TypeRange argumentTypes, Type &resultType) { … } static void printRangeType(OpAsmPrinter &p, RangeOp op, TypeRange argumentTypes, Type resultType) { … } LogicalResult RangeOp::verify() { … } //===----------------------------------------------------------------------===// // pdl::ReplaceOp //===----------------------------------------------------------------------===// LogicalResult ReplaceOp::verify() { … } //===----------------------------------------------------------------------===// // pdl::ResultsOp //===----------------------------------------------------------------------===// static ParseResult parseResultsValueType(OpAsmParser &p, IntegerAttr index, Type &resultType) { … } static void printResultsValueType(OpAsmPrinter &p, ResultsOp op, IntegerAttr index, Type resultType) { … } LogicalResult ResultsOp::verify() { … } //===----------------------------------------------------------------------===// // pdl::RewriteOp //===----------------------------------------------------------------------===// LogicalResult RewriteOp::verifyRegions() { … } /// The default dialect is `pdl`. StringRef RewriteOp::getDefaultDialect() { … } //===----------------------------------------------------------------------===// // pdl::TypeOp //===----------------------------------------------------------------------===// LogicalResult TypeOp::verify() { … } //===----------------------------------------------------------------------===// // pdl::TypesOp //===----------------------------------------------------------------------===// LogicalResult TypesOp::verify() { … } //===----------------------------------------------------------------------===// // TableGen'd op method definitions //===----------------------------------------------------------------------===// #define GET_OP_CLASSES #include "mlir/Dialect/PDL/IR/PDLOps.cpp.inc"