[Kanagawa] Python dialect and pass registration (#8613)

- Register the kanagawa dialect in Python bindings
- Register kanagawa dialect passes
- Add C API header and implementation for kanagawa dialect
- Add integration test for kanagawa dialect and passes

Follows the same pattern as pipeline dialect registration in commit 5c4d8ae.
This commit is contained in:
John Demme 2025-06-27 13:49:44 -07:00 committed by GitHub
parent 19a9de6b77
commit df6ca02a06
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 93 additions and 0 deletions

View File

@ -0,0 +1,25 @@
//===- Kanagawa.h - C interface for the Kanagawa 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 CIRCT_C_DIALECT_KANAGAWA_H
#define CIRCT_C_DIALECT_KANAGAWA_H
#include "mlir-c/IR.h"
#ifdef __cplusplus
extern "C" {
#endif
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(Kanagawa, kanagawa);
MLIR_CAPI_EXPORTED void registerKanagawaPasses(void);
#ifdef __cplusplus
}
#endif
#endif // CIRCT_C_DIALECT_KANAGAWA_H

View File

@ -0,0 +1,31 @@
# REQUIRES: bindings_python
# RUN: %PYTHON% %s
import circt
from circt.ir import Context, Module
from circt import passmanager
with Context() as ctx:
circt.register_dialects(ctx)
mod = Module.parse("""
kanagawa.design @foo {
kanagawa.container sym @C {
}
kanagawa.container sym @AccessChild {
%c = kanagawa.container.instance @c, <@foo::@C>
%c_ref = kanagawa.path [
#kanagawa.step<child , @c : !kanagawa.scoperef<@foo::@C>>
]
}
}
""")
# Test that we can parse kanagawa dialect IR
print("Kanagawa dialect registration and parsing successful!")
# Test that kanagawa passes are registered
pm = passmanager.PassManager.parse(
"builtin.module(kanagawa.design(kanagawa-containerize))")
print("Kanagawa passes registration successful!")

View File

@ -19,6 +19,7 @@
#include "circt-c/Dialect/HW.h"
#include "circt-c/Dialect/HWArith.h"
#include "circt-c/Dialect/Handshake.h"
#include "circt-c/Dialect/Kanagawa.h"
#include "circt-c/Dialect/LTL.h"
#include "circt-c/Dialect/MSFT.h"
#include "circt-c/Dialect/OM.h"
@ -57,6 +58,7 @@ static void registerPasses() {
registerHWArithPasses();
registerHWPasses();
registerHandshakePasses();
registerKanagawaPasses();
registerPipelinePasses();
mlirRegisterCIRCTConversionPasses();
mlirRegisterCIRCTTransformsPasses();
@ -147,6 +149,10 @@ NB_MODULE(_circt, m) {
mlirDialectHandleRegisterDialect(handshake, context);
mlirDialectHandleLoadDialect(handshake, context);
MlirDialectHandle kanagawa = mlirGetDialectHandle__kanagawa__();
mlirDialectHandleRegisterDialect(kanagawa, context);
mlirDialectHandleLoadDialect(kanagawa, context);
MlirDialectHandle ltl = mlirGetDialectHandle__ltl__();
mlirDialectHandleRegisterDialect(ltl, context);
mlirDialectHandleLoadDialect(ltl, context);

View File

@ -42,6 +42,7 @@ set(PYTHON_BINDINGS_LINK_LIBS
CIRCTCAPIHandshake
CIRCTCAPIHW
CIRCTCAPIHWArith
CIRCTCAPIKanagawa
CIRCTCAPILTL
CIRCTCAPIMSFT
CIRCTCAPIOM

View File

@ -12,6 +12,7 @@ set(LLVM_OPTIONAL_SOURCES
HW.cpp
HWArith.cpp
Handshake.cpp
Kanagawa.cpp
LLHD.cpp
LTL.cpp
MSFT.cpp
@ -132,6 +133,15 @@ add_circt_public_c_api_library(CIRCTCAPIOM
CIRCTOMEvaluator
)
add_circt_public_c_api_library(CIRCTCAPIKanagawa
Kanagawa.cpp
LINK_LIBS PUBLIC
MLIRCAPIIR
CIRCTKanagawa
CIRCTKanagawaTransforms
)
add_circt_public_c_api_library(CIRCTCAPIPipeline
Pipeline.cpp

View File

@ -0,0 +1,20 @@
//===- Kanagawa.cpp - C interface for the Kanagawa 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 "circt-c/Dialect/Kanagawa.h"
#include "circt/Dialect/Kanagawa/KanagawaDialect.h"
#include "circt/Dialect/Kanagawa/KanagawaPasses.h"
#include "mlir/CAPI/Registration.h"
using namespace circt::kanagawa;
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(Kanagawa, kanagawa,
circt::kanagawa::KanagawaDialect)
void registerKanagawaPasses() { circt::kanagawa::registerPasses(); }