[Mlir-commits] [mlir] a8a2ee6 - [mlir] Introduce C API for PDL dialect types
Denys Shabalin
llvmlistbot at llvm.org
Thu Jan 13 06:29:09 PST 2022
Author: Denys Shabalin
Date: 2022-01-13T15:29:01+01:00
New Revision: a8a2ee633190559ff7ce6a081c429f281f9624a5
URL: https://github.com/llvm/llvm-project/commit/a8a2ee633190559ff7ce6a081c429f281f9624a5
DIFF: https://github.com/llvm/llvm-project/commit/a8a2ee633190559ff7ce6a081c429f281f9624a5.diff
LOG: [mlir] Introduce C API for PDL dialect types
This change introduces C API helper functions to work with PDL types.
Modification closely follow the format of the https://reviews.llvm.org/D116546.
Reviewed By: ftynse
Differential Revision: https://reviews.llvm.org/D117221
Added:
mlir/include/mlir-c/Dialect/PDL.h
mlir/lib/CAPI/Dialect/PDL.cpp
mlir/test/CAPI/pdl.c
Modified:
mlir/include/mlir-c/Dialect/Quant.h
mlir/lib/CAPI/Dialect/CMakeLists.txt
mlir/lib/CAPI/Dialect/Quant.cpp
mlir/test/CAPI/CMakeLists.txt
mlir/test/CMakeLists.txt
mlir/test/lit.cfg.py
utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
Removed:
################################################################################
diff --git a/mlir/include/mlir-c/Dialect/PDL.h b/mlir/include/mlir-c/Dialect/PDL.h
new file mode 100644
index 0000000000000..5e0a2bc955f65
--- /dev/null
+++ b/mlir/include/mlir-c/Dialect/PDL.h
@@ -0,0 +1,72 @@
+//===-- mlir-c/Dialect/PDL.h - C API for PDL Dialect --------------*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef MLIR_C_DIALECT_PDL_H
+#define MLIR_C_DIALECT_PDL_H
+
+#include "mlir-c/IR.h"
+#include "mlir-c/Registration.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(PDL, pdl);
+
+//===---------------------------------------------------------------------===//
+// PDLType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLType(MlirType type);
+
+//===---------------------------------------------------------------------===//
+// AttributeType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLAttributeType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirType mlirPDLAttributeTypeGet(MlirContext ctx);
+
+//===---------------------------------------------------------------------===//
+// OperationType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLOperationType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirType mlirPDLOperationTypeGet(MlirContext ctx);
+
+//===---------------------------------------------------------------------===//
+// RangeType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLRangeType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirType mlirPDLRangeTypeGet(MlirType elementType);
+
+//===---------------------------------------------------------------------===//
+// TypeType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLTypeType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirType mlirPDLTypeTypeGet(MlirContext ctx);
+
+//===---------------------------------------------------------------------===//
+// ValueType
+//===---------------------------------------------------------------------===//
+
+MLIR_CAPI_EXPORTED bool mlirTypeIsAPDLValueType(MlirType type);
+
+MLIR_CAPI_EXPORTED MlirType mlirPDLValueTypeGet(MlirContext ctx);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // MLIR_C_DIALECT_QUANT_H
diff --git a/mlir/include/mlir-c/Dialect/Quant.h b/mlir/include/mlir-c/Dialect/Quant.h
index c45d93af4b33a..eb529b8456d7e 100644
--- a/mlir/include/mlir-c/Dialect/Quant.h
+++ b/mlir/include/mlir-c/Dialect/Quant.h
@@ -1,4 +1,4 @@
-//===-- mlir-c/Dialect/LLVM.h - C API for LLVM --------------------*- C -*-===//
+//===-- mlir-c/Dialect/Quant.h - C API for LLVM -------------------*- C -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM
// Exceptions.
diff --git a/mlir/lib/CAPI/Dialect/CMakeLists.txt b/mlir/lib/CAPI/Dialect/CMakeLists.txt
index 1d3e2727a955e..f66f7b0b87227 100644
--- a/mlir/lib/CAPI/Dialect/CMakeLists.txt
+++ b/mlir/lib/CAPI/Dialect/CMakeLists.txt
@@ -106,3 +106,12 @@ add_mlir_upstream_c_api_library(MLIRCAPIQuant
MLIRCAPIIR
MLIRQuant
)
+
+add_mlir_upstream_c_api_library(MLIRCAPIPDL
+ PDL.cpp
+
+ PARTIAL_SOURCES_INTENDED
+ LINK_LIBS PUBLIC
+ MLIRCAPIIR
+ MLIRPDL
+)
diff --git a/mlir/lib/CAPI/Dialect/PDL.cpp b/mlir/lib/CAPI/Dialect/PDL.cpp
new file mode 100644
index 0000000000000..42b4ec24b008e
--- /dev/null
+++ b/mlir/lib/CAPI/Dialect/PDL.cpp
@@ -0,0 +1,85 @@
+//===- PDL.cpp - C Interface for PDL 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-c/Dialect/PDL.h"
+#include "mlir/CAPI/Registration.h"
+#include "mlir/Dialect/PDL/IR/PDL.h"
+#include "mlir/Dialect/PDL/IR/PDLOps.h"
+#include "mlir/Dialect/PDL/IR/PDLTypes.h"
+
+using namespace mlir;
+
+MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(PDL, pdl, pdl::PDLDialect)
+
+//===---------------------------------------------------------------------===//
+// PDLType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAPDLType(MlirType type) {
+ return unwrap(type).isa<pdl::PDLType>();
+}
+
+//===---------------------------------------------------------------------===//
+// AttributeType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAPDLAttributeType(MlirType type) {
+ return unwrap(type).isa<pdl::AttributeType>();
+}
+
+MlirType mlirPDLAttributeTypeGet(MlirContext ctx) {
+ return wrap(pdl::AttributeType::get(unwrap(ctx)));
+}
+
+//===---------------------------------------------------------------------===//
+// OperationType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAPDLOperationType(MlirType type) {
+ return unwrap(type).isa<pdl::OperationType>();
+}
+
+MlirType mlirPDLOperationTypeGet(MlirContext ctx) {
+ return wrap(pdl::OperationType::get(unwrap(ctx)));
+}
+
+//===---------------------------------------------------------------------===//
+// RangeType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAPDLRangeType(MlirType type) {
+ return unwrap(type).isa<pdl::RangeType>();
+}
+
+MlirType mlirPDLRangeTypeGet(MlirType elementType) {
+ return wrap(pdl::RangeType::get(unwrap(elementType)));
+}
+
+//===---------------------------------------------------------------------===//
+// TypeType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAPDLTypeType(MlirType type) {
+ return unwrap(type).isa<pdl::TypeType>();
+}
+
+MlirType mlirPDLTypeTypeGet(MlirContext ctx) {
+ return wrap(pdl::TypeType::get(unwrap(ctx)));
+}
+
+//===---------------------------------------------------------------------===//
+// ValueType
+//===---------------------------------------------------------------------===//
+
+bool mlirTypeIsAPDLValueType(MlirType type) {
+ return unwrap(type).isa<pdl::ValueType>();
+}
+
+MlirType mlirPDLValueTypeGet(MlirContext ctx) {
+ return wrap(pdl::ValueType::get(unwrap(ctx)));
+}
diff --git a/mlir/lib/CAPI/Dialect/Quant.cpp b/mlir/lib/CAPI/Dialect/Quant.cpp
index 3fc00a72d66b9..4835365081980 100644
--- a/mlir/lib/CAPI/Dialect/Quant.cpp
+++ b/mlir/lib/CAPI/Dialect/Quant.cpp
@@ -1,4 +1,4 @@
-//===- LLVM.cpp - C Interface for Quant dialect ---------------------------===//
+//===- Quant.cpp - C Interface for Quant dialect --------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/mlir/test/CAPI/CMakeLists.txt b/mlir/test/CAPI/CMakeLists.txt
index 6c9aa11fdfc88..8228bbb7d26f8 100644
--- a/mlir/test/CAPI/CMakeLists.txt
+++ b/mlir/test/CAPI/CMakeLists.txt
@@ -66,3 +66,11 @@ _add_capi_test_executable(mlir-capi-quant-test
MLIRCAPIRegistration
MLIRCAPIQuant
)
+
+_add_capi_test_executable(mlir-capi-pdl-test
+ pdl.c
+ LINK_LIBS PRIVATE
+ MLIRCAPIIR
+ MLIRCAPIRegistration
+ MLIRCAPIPDL
+)
diff --git a/mlir/test/CAPI/pdl.c b/mlir/test/CAPI/pdl.c
new file mode 100644
index 0000000000000..b7c59cc4579dd
--- /dev/null
+++ b/mlir/test/CAPI/pdl.c
@@ -0,0 +1,332 @@
+//===- pdl.c - Test of PDL dialect C API ----------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+// RUN: mlir-capi-pdl-test 2>&1 | FileCheck %s
+
+#include "mlir-c/Dialect/PDL.h"
+#include "mlir-c/BuiltinTypes.h"
+#include "mlir-c/IR.h"
+
+#include <assert.h>
+#include <inttypes.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+// CHECK-LABEL: testAttributeType
+void testAttributeType(MlirContext ctx) {
+ fprintf(stderr, "testAttributeType\n");
+
+ MlirType parsedType = mlirTypeParseGet(
+ ctx, mlirStringRefCreateFromCString("!pdl.attribute"));
+ MlirType constructedType = mlirPDLAttributeTypeGet(ctx);
+
+ assert(!mlirTypeIsNull(parsedType) && "couldn't parse PDLAttributeType");
+ assert(!mlirTypeIsNull(constructedType) && "couldn't construct PDLAttributeType");
+
+ // CHECK: parsedType isa PDLType: 1
+ fprintf(stderr, "parsedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(parsedType));
+ // CHECK: parsedType isa PDLAttributeType: 1
+ fprintf(stderr, "parsedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(parsedType));
+ // CHECK: parsedType isa PDLOperationType: 0
+ fprintf(stderr, "parsedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(parsedType));
+ // CHECK: parsedType isa PDLRangeType: 0
+ fprintf(stderr, "parsedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(parsedType));
+ // CHECK: parsedType isa PDLTypeType: 0
+ fprintf(stderr, "parsedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(parsedType));
+ // CHECK: parsedType isa PDLValueType: 0
+ fprintf(stderr, "parsedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(parsedType));
+
+ // CHECK: constructedType isa PDLType: 1
+ fprintf(stderr, "constructedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(constructedType));
+ // CHECK: constructedType isa PDLAttributeType: 1
+ fprintf(stderr, "constructedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(constructedType));
+ // CHECK: constructedType isa PDLOperationType: 0
+ fprintf(stderr, "constructedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(constructedType));
+ // CHECK: constructedType isa PDLRangeType: 0
+ fprintf(stderr, "constructedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(constructedType));
+ // CHECK: constructedType isa PDLTypeType: 0
+ fprintf(stderr, "constructedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(constructedType));
+ // CHECK: constructedType isa PDLValueType: 0
+ fprintf(stderr, "constructedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(constructedType));
+
+ // CHECK: equal: 1
+ fprintf(stderr, "equal: %d\n", mlirTypeEqual(parsedType, constructedType));
+
+ // CHECK: !pdl.attribute
+ mlirTypeDump(parsedType);
+ // CHECK: !pdl.attribute
+ mlirTypeDump(constructedType);
+
+ fprintf(stderr, "\n\n");
+}
+
+// CHECK-LABEL: testOperationType
+void testOperationType(MlirContext ctx) {
+ fprintf(stderr, "testOperationType\n");
+
+ MlirType parsedType = mlirTypeParseGet(
+ ctx, mlirStringRefCreateFromCString("!pdl.operation"));
+ MlirType constructedType = mlirPDLOperationTypeGet(ctx);
+
+ assert(!mlirTypeIsNull(parsedType) && "couldn't parse PDLAttributeType");
+ assert(!mlirTypeIsNull(constructedType) && "couldn't construct PDLAttributeType");
+
+ // CHECK: parsedType isa PDLType: 1
+ fprintf(stderr, "parsedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(parsedType));
+ // CHECK: parsedType isa PDLAttributeType: 0
+ fprintf(stderr, "parsedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(parsedType));
+ // CHECK: parsedType isa PDLOperationType: 1
+ fprintf(stderr, "parsedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(parsedType));
+ // CHECK: parsedType isa PDLRangeType: 0
+ fprintf(stderr, "parsedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(parsedType));
+ // CHECK: parsedType isa PDLTypeType: 0
+ fprintf(stderr, "parsedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(parsedType));
+ // CHECK: parsedType isa PDLValueType: 0
+ fprintf(stderr, "parsedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(parsedType));
+
+ // CHECK: constructedType isa PDLType: 1
+ fprintf(stderr, "constructedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(constructedType));
+ // CHECK: constructedType isa PDLAttributeType: 0
+ fprintf(stderr, "constructedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(constructedType));
+ // CHECK: constructedType isa PDLOperationType: 1
+ fprintf(stderr, "constructedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(constructedType));
+ // CHECK: constructedType isa PDLRangeType: 0
+ fprintf(stderr, "constructedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(constructedType));
+ // CHECK: constructedType isa PDLTypeType: 0
+ fprintf(stderr, "constructedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(constructedType));
+ // CHECK: constructedType isa PDLValueType: 0
+ fprintf(stderr, "constructedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(constructedType));
+
+ // CHECK: equal: 1
+ fprintf(stderr, "equal: %d\n", mlirTypeEqual(parsedType, constructedType));
+
+ // CHECK: !pdl.operation
+ mlirTypeDump(parsedType);
+ // CHECK: !pdl.operation
+ mlirTypeDump(constructedType);
+
+ fprintf(stderr, "\n\n");
+}
+
+// CHECK-LABEL: testRangeType
+void testRangeType(MlirContext ctx) {
+ fprintf(stderr, "testRangeType\n");
+
+ MlirType typeType = mlirPDLTypeTypeGet(ctx);
+ MlirType parsedType = mlirTypeParseGet(
+ ctx, mlirStringRefCreateFromCString("!pdl.range<type>"));
+ MlirType constructedType = mlirPDLRangeTypeGet(typeType);
+
+ assert(!mlirTypeIsNull(typeType) && "couldn't get PDLTypeType");
+ assert(!mlirTypeIsNull(parsedType) && "couldn't parse PDLAttributeType");
+ assert(!mlirTypeIsNull(constructedType) && "couldn't construct PDLAttributeType");
+
+ // CHECK: parsedType isa PDLType: 1
+ fprintf(stderr, "parsedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(parsedType));
+ // CHECK: parsedType isa PDLAttributeType: 0
+ fprintf(stderr, "parsedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(parsedType));
+ // CHECK: parsedType isa PDLOperationType: 0
+ fprintf(stderr, "parsedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(parsedType));
+ // CHECK: parsedType isa PDLRangeType: 1
+ fprintf(stderr, "parsedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(parsedType));
+ // CHECK: parsedType isa PDLTypeType: 0
+ fprintf(stderr, "parsedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(parsedType));
+ // CHECK: parsedType isa PDLValueType: 0
+ fprintf(stderr, "parsedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(parsedType));
+
+ // CHECK: constructedType isa PDLType: 1
+ fprintf(stderr, "constructedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(constructedType));
+ // CHECK: constructedType isa PDLAttributeType: 0
+ fprintf(stderr, "constructedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(constructedType));
+ // CHECK: constructedType isa PDLOperationType: 0
+ fprintf(stderr, "constructedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(constructedType));
+ // CHECK: constructedType isa PDLRangeType: 1
+ fprintf(stderr, "constructedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(constructedType));
+ // CHECK: constructedType isa PDLTypeType: 0
+ fprintf(stderr, "constructedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(constructedType));
+ // CHECK: constructedType isa PDLValueType: 0
+ fprintf(stderr, "constructedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(constructedType));
+
+ // CHECK: equal: 1
+ fprintf(stderr, "equal: %d\n", mlirTypeEqual(parsedType, constructedType));
+
+ // CHECK: !pdl.range<type>
+ mlirTypeDump(parsedType);
+ // CHECK: !pdl.range<type>
+ mlirTypeDump(constructedType);
+
+ fprintf(stderr, "\n\n");
+}
+
+// CHECK-LABEL: testTypeType
+void testTypeType(MlirContext ctx) {
+ fprintf(stderr, "testTypeType\n");
+
+ MlirType parsedType = mlirTypeParseGet(
+ ctx, mlirStringRefCreateFromCString("!pdl.type"));
+ MlirType constructedType = mlirPDLTypeTypeGet(ctx);
+
+ assert(!mlirTypeIsNull(parsedType) && "couldn't parse PDLAttributeType");
+ assert(!mlirTypeIsNull(constructedType) && "couldn't construct PDLAttributeType");
+
+ // CHECK: parsedType isa PDLType: 1
+ fprintf(stderr, "parsedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(parsedType));
+ // CHECK: parsedType isa PDLAttributeType: 0
+ fprintf(stderr, "parsedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(parsedType));
+ // CHECK: parsedType isa PDLOperationType: 0
+ fprintf(stderr, "parsedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(parsedType));
+ // CHECK: parsedType isa PDLRangeType: 0
+ fprintf(stderr, "parsedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(parsedType));
+ // CHECK: parsedType isa PDLTypeType: 1
+ fprintf(stderr, "parsedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(parsedType));
+ // CHECK: parsedType isa PDLValueType: 0
+ fprintf(stderr, "parsedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(parsedType));
+
+ // CHECK: constructedType isa PDLType: 1
+ fprintf(stderr, "constructedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(constructedType));
+ // CHECK: constructedType isa PDLAttributeType: 0
+ fprintf(stderr, "constructedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(constructedType));
+ // CHECK: constructedType isa PDLOperationType: 0
+ fprintf(stderr, "constructedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(constructedType));
+ // CHECK: constructedType isa PDLRangeType: 0
+ fprintf(stderr, "constructedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(constructedType));
+ // CHECK: constructedType isa PDLTypeType: 1
+ fprintf(stderr, "constructedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(constructedType));
+ // CHECK: constructedType isa PDLValueType: 0
+ fprintf(stderr, "constructedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(constructedType));
+
+ // CHECK: equal: 1
+ fprintf(stderr, "equal: %d\n", mlirTypeEqual(parsedType, constructedType));
+
+ // CHECK: !pdl.type
+ mlirTypeDump(parsedType);
+ // CHECK: !pdl.type
+ mlirTypeDump(constructedType);
+
+ fprintf(stderr, "\n\n");
+}
+
+// CHECK-LABEL: testValueType
+void testValueType(MlirContext ctx) {
+ fprintf(stderr, "testValueType\n");
+
+ MlirType parsedType = mlirTypeParseGet(
+ ctx, mlirStringRefCreateFromCString("!pdl.value"));
+ MlirType constructedType = mlirPDLValueTypeGet(ctx);
+
+ assert(!mlirTypeIsNull(parsedType) && "couldn't parse PDLAttributeType");
+ assert(!mlirTypeIsNull(constructedType) && "couldn't construct PDLAttributeType");
+
+ // CHECK: parsedType isa PDLType: 1
+ fprintf(stderr, "parsedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(parsedType));
+ // CHECK: parsedType isa PDLAttributeType: 0
+ fprintf(stderr, "parsedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(parsedType));
+ // CHECK: parsedType isa PDLOperationType: 0
+ fprintf(stderr, "parsedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(parsedType));
+ // CHECK: parsedType isa PDLRangeType: 0
+ fprintf(stderr, "parsedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(parsedType));
+ // CHECK: parsedType isa PDLTypeType: 0
+ fprintf(stderr, "parsedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(parsedType));
+ // CHECK: parsedType isa PDLValueType: 1
+ fprintf(stderr, "parsedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(parsedType));
+
+ // CHECK: constructedType isa PDLType: 1
+ fprintf(stderr, "constructedType isa PDLType: %d\n",
+ mlirTypeIsAPDLType(constructedType));
+ // CHECK: constructedType isa PDLAttributeType: 0
+ fprintf(stderr, "constructedType isa PDLAttributeType: %d\n",
+ mlirTypeIsAPDLAttributeType(constructedType));
+ // CHECK: constructedType isa PDLOperationType: 0
+ fprintf(stderr, "constructedType isa PDLOperationType: %d\n",
+ mlirTypeIsAPDLOperationType(constructedType));
+ // CHECK: constructedType isa PDLRangeType: 0
+ fprintf(stderr, "constructedType isa PDLRangeType: %d\n",
+ mlirTypeIsAPDLRangeType(constructedType));
+ // CHECK: constructedType isa PDLTypeType: 0
+ fprintf(stderr, "constructedType isa PDLTypeType: %d\n",
+ mlirTypeIsAPDLTypeType(constructedType));
+ // CHECK: constructedType isa PDLValueType: 1
+ fprintf(stderr, "constructedType isa PDLValueType: %d\n",
+ mlirTypeIsAPDLValueType(constructedType));
+
+ // CHECK: equal: 1
+ fprintf(stderr, "equal: %d\n", mlirTypeEqual(parsedType, constructedType));
+
+ // CHECK: !pdl.value
+ mlirTypeDump(parsedType);
+ // CHECK: !pdl.value
+ mlirTypeDump(constructedType);
+
+ fprintf(stderr, "\n\n");
+}
+
+int main() {
+ MlirContext ctx = mlirContextCreate();
+ mlirDialectHandleRegisterDialect(mlirGetDialectHandle__pdl__(), ctx);
+ testAttributeType(ctx);
+ testOperationType(ctx);
+ testRangeType(ctx);
+ testTypeType(ctx);
+ testValueType(ctx);
+ return EXIT_SUCCESS;
+}
diff --git a/mlir/test/CMakeLists.txt b/mlir/test/CMakeLists.txt
index 60586616c3fac..0567389b26924 100644
--- a/mlir/test/CMakeLists.txt
+++ b/mlir/test/CMakeLists.txt
@@ -75,6 +75,7 @@ set(MLIR_TEST_DEPENDS
mlir-capi-pass-test
mlir-capi-sparse-tensor-test
mlir-capi-quant-test
+ mlir-capi-pdl-test
mlir-cpu-runner
mlir-linalg-ods-yaml-gen
mlir-lsp-server
diff --git a/mlir/test/lit.cfg.py b/mlir/test/lit.cfg.py
index 088ae7535df83..0773271f29c04 100644
--- a/mlir/test/lit.cfg.py
+++ b/mlir/test/lit.cfg.py
@@ -68,6 +68,7 @@
'mlir-capi-pass-test',
'mlir-capi-sparse-tensor-test',
'mlir-capi-quant-test',
+ 'mlir-capi-pdl-test',
'mlir-cpu-runner',
'mlir-linalg-ods-yaml-gen',
'mlir-reduce',
diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
index 0b144d9920f26..a727bc312d733 100644
--- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel
@@ -514,6 +514,26 @@ mlir_c_api_cc_library(
],
)
+mlir_c_api_cc_library(
+ name = "CAPIPDL",
+ srcs = [
+ "lib/CAPI/Dialect/PDL.cpp",
+ ],
+ hdrs = [
+ "include/mlir-c/Dialect/PDL.h",
+ ],
+ header_deps = [
+ ":CAPIIRHeaders",
+ ],
+ includes = ["include"],
+ deps = [
+ ":CAPIIR",
+ ":PDLDialect",
+ ":PDLOpsIncGen",
+ ":PDLTypesIncGen",
+ ],
+)
+
mlir_c_api_cc_library(
name = "CAPIConversion",
srcs = ["lib/CAPI/Conversion/Passes.cpp"],
More information about the Mlir-commits
mailing list