2022-01-13 10:53:21 +01:00
|
|
|
//===- DialectPDL.cpp - 'pdl' dialect submodule ---------------------------===//
|
|
|
|
|
//
|
|
|
|
|
// 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-c/Dialect/PDL.h"
|
|
|
|
|
#include "mlir-c/IR.h"
|
2024-12-20 23:32:32 -05:00
|
|
|
#include "mlir/Bindings/Python/Nanobind.h"
|
2025-08-21 04:44:23 -07:00
|
|
|
#include "mlir/Bindings/Python/NanobindAdaptors.h"
|
2022-01-13 10:53:21 +01:00
|
|
|
|
2024-12-20 23:32:32 -05:00
|
|
|
namespace nb = nanobind;
|
2022-01-13 10:53:21 +01:00
|
|
|
using namespace llvm;
|
|
|
|
|
using namespace mlir;
|
|
|
|
|
using namespace mlir::python;
|
2024-12-20 23:32:32 -05:00
|
|
|
using namespace mlir::python::nanobind_adaptors;
|
2022-01-13 10:53:21 +01:00
|
|
|
|
2025-08-21 04:44:56 -07:00
|
|
|
static void populateDialectPDLSubmodule(const nanobind::module_ &m) {
|
2022-01-13 10:53:21 +01:00
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
// PDLType
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
auto pdlType = mlir_type_subclass(m, "PDLType", mlirTypeIsAPDLType);
|
|
|
|
|
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
// AttributeType
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
auto attributeType =
|
|
|
|
|
mlir_type_subclass(m, "AttributeType", mlirTypeIsAPDLAttributeType);
|
|
|
|
|
attributeType.def_classmethod(
|
|
|
|
|
"get",
|
2025-08-21 04:45:30 -07:00
|
|
|
[](const nb::object &cls, MlirContext ctx) {
|
2022-01-13 10:53:21 +01:00
|
|
|
return cls(mlirPDLAttributeTypeGet(ctx));
|
|
|
|
|
},
|
2024-12-20 23:32:32 -05:00
|
|
|
"Get an instance of AttributeType in given context.", nb::arg("cls"),
|
2025-09-08 12:16:35 -07:00
|
|
|
nb::arg("context") = nb::none());
|
2022-01-13 10:53:21 +01:00
|
|
|
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
// OperationType
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
auto operationType =
|
|
|
|
|
mlir_type_subclass(m, "OperationType", mlirTypeIsAPDLOperationType);
|
|
|
|
|
operationType.def_classmethod(
|
|
|
|
|
"get",
|
2025-08-21 04:45:30 -07:00
|
|
|
[](const nb::object &cls, MlirContext ctx) {
|
2022-01-13 10:53:21 +01:00
|
|
|
return cls(mlirPDLOperationTypeGet(ctx));
|
|
|
|
|
},
|
2024-12-20 23:32:32 -05:00
|
|
|
"Get an instance of OperationType in given context.", nb::arg("cls"),
|
2025-09-08 12:16:35 -07:00
|
|
|
nb::arg("context") = nb::none());
|
2022-01-13 10:53:21 +01:00
|
|
|
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
// RangeType
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
auto rangeType = mlir_type_subclass(m, "RangeType", mlirTypeIsAPDLRangeType);
|
|
|
|
|
rangeType.def_classmethod(
|
|
|
|
|
"get",
|
2025-08-21 04:45:30 -07:00
|
|
|
[](const nb::object &cls, MlirType elementType) {
|
2022-01-13 10:53:21 +01:00
|
|
|
return cls(mlirPDLRangeTypeGet(elementType));
|
|
|
|
|
},
|
|
|
|
|
"Gets an instance of RangeType in the same context as the provided "
|
|
|
|
|
"element type.",
|
2024-12-20 23:32:32 -05:00
|
|
|
nb::arg("cls"), nb::arg("element_type"));
|
2022-01-13 10:53:21 +01:00
|
|
|
rangeType.def_property_readonly(
|
|
|
|
|
"element_type",
|
|
|
|
|
[](MlirType type) { return mlirPDLRangeTypeGetElementType(type); },
|
2025-09-20 14:47:32 -04:00
|
|
|
nb::sig(
|
|
|
|
|
"def element_type(self) -> " MAKE_MLIR_PYTHON_QUALNAME("ir.Type")),
|
2022-01-13 10:53:21 +01:00
|
|
|
"Get the element type.");
|
|
|
|
|
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
// TypeType
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
auto typeType = mlir_type_subclass(m, "TypeType", mlirTypeIsAPDLTypeType);
|
|
|
|
|
typeType.def_classmethod(
|
|
|
|
|
"get",
|
2025-08-21 04:45:30 -07:00
|
|
|
[](const nb::object &cls, MlirContext ctx) {
|
2022-01-13 10:53:21 +01:00
|
|
|
return cls(mlirPDLTypeTypeGet(ctx));
|
|
|
|
|
},
|
2024-12-20 23:32:32 -05:00
|
|
|
"Get an instance of TypeType in given context.", nb::arg("cls"),
|
2025-09-08 12:16:35 -07:00
|
|
|
nb::arg("context") = nb::none());
|
2022-01-13 10:53:21 +01:00
|
|
|
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
// ValueType
|
|
|
|
|
//===-------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
|
|
auto valueType = mlir_type_subclass(m, "ValueType", mlirTypeIsAPDLValueType);
|
|
|
|
|
valueType.def_classmethod(
|
|
|
|
|
"get",
|
2025-08-21 04:45:30 -07:00
|
|
|
[](const nb::object &cls, MlirContext ctx) {
|
2022-01-13 10:53:21 +01:00
|
|
|
return cls(mlirPDLValueTypeGet(ctx));
|
|
|
|
|
},
|
2024-12-20 23:32:32 -05:00
|
|
|
"Get an instance of TypeType in given context.", nb::arg("cls"),
|
2025-09-08 12:16:35 -07:00
|
|
|
nb::arg("context") = nb::none());
|
2022-01-13 10:53:21 +01:00
|
|
|
}
|
|
|
|
|
|
2024-12-20 23:32:32 -05:00
|
|
|
NB_MODULE(_mlirDialectsPDL, m) {
|
2022-01-13 10:53:21 +01:00
|
|
|
m.doc() = "MLIR PDL dialect.";
|
|
|
|
|
populateDialectPDLSubmodule(m);
|
|
|
|
|
}
|