mirror of https://github.com/llvm/circt.git
[MSFT] [Python] Physically locate an op (#937)
Adds an API call to physically place an op's sub-entity.
This commit is contained in:
parent
b67f1dcdde
commit
c15faa7fc4
|
@ -0,0 +1,26 @@
|
|||
//===-- circt-c/Dialect/MSFT.h - C API for MSFT dialect -----------*- C -*-===//
|
||||
//
|
||||
// This header declares the C interface for registering and accessing the
|
||||
// MSFT dialect. A dialect should be registered with a context to make it
|
||||
// available to users of the context. These users must load the dialect
|
||||
// before using any of its attributes, operations or types. Parser and pass
|
||||
// manager can load registered dialects automatically.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef CIRCT_C_DIALECT_MSFT_H
|
||||
#define CIRCT_C_DIALECT_MSFT_H
|
||||
|
||||
#include "mlir-c/Registration.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
MLIR_DECLARE_CAPI_DIALECT_REGISTRATION(MSFT, msft);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // CIRCT_C_DIALECT_MSFT_H
|
|
@ -1,7 +1,35 @@
|
|||
# REQUIRES: bindings_python
|
||||
# RUN: %PYTHON% %s | FileCheck %s
|
||||
|
||||
import circt
|
||||
from circt import msft
|
||||
from circt.dialects import rtl
|
||||
|
||||
# CHECK: Successfully imported circt.msft
|
||||
print("Successfully imported circt.msft")
|
||||
from mlir.ir import *
|
||||
|
||||
with Context() as ctx, Location.unknown():
|
||||
circt.register_dialects(ctx)
|
||||
|
||||
m = Module.create()
|
||||
with InsertionPoint(m.body):
|
||||
# CHECK: rtl.module @MyWidget()
|
||||
# CHECK: rtl.output
|
||||
op = rtl.RTLModuleOp(
|
||||
name='MyWidget',
|
||||
input_ports=[],
|
||||
output_ports=[],
|
||||
body_builder=lambda module: rtl.OutputOp([])
|
||||
)
|
||||
top = rtl.RTLModuleOp(
|
||||
name='top',
|
||||
input_ports=[],
|
||||
output_ports=[],
|
||||
body_builder=lambda module: rtl.OutputOp([])
|
||||
)
|
||||
|
||||
with InsertionPoint.at_block_terminator(top.body.blocks[0]):
|
||||
inst = rtl.InstanceOp([], Attribute.parse('"widget"'), Attribute.parse("@MyWidget"), [], Attribute.parse("{}"))
|
||||
msft.locate(inst.operation, "mem", devtype=msft.M20K, x=50, y=100, num=1)
|
||||
# CHECK: rtl.instance "widget" @MyWidget() {"loc:mem" = #msft.physloc<M20K, 50, 100, 1>, parameters = {}} : () -> ()
|
||||
|
||||
m.operation.print()
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "circt-c/Dialect/Comb.h"
|
||||
#include "circt-c/Dialect/ESI.h"
|
||||
#include "circt-c/Dialect/MSFT.h"
|
||||
#include "circt-c/Dialect/RTL.h"
|
||||
#include "circt-c/Dialect/SV.h"
|
||||
#include "circt-c/ExportVerilog.h"
|
||||
|
@ -45,6 +46,10 @@ PYBIND11_MODULE(_circt, m) {
|
|||
mlirDialectHandleRegisterDialect(esi, context);
|
||||
mlirDialectHandleLoadDialect(esi, context);
|
||||
|
||||
MlirDialectHandle msft = mlirGetDialectHandle__msft__();
|
||||
mlirDialectHandleRegisterDialect(msft, context);
|
||||
mlirDialectHandleLoadDialect(msft, context);
|
||||
|
||||
MlirDialectHandle rtl = mlirGetDialectHandle__rtl__();
|
||||
mlirDialectHandleRegisterDialect(rtl, context);
|
||||
mlirDialectHandleLoadDialect(rtl, context);
|
||||
|
|
|
@ -19,6 +19,7 @@ add_mlir_python_extension(CIRCTBindingsPythonExtension _circt
|
|||
LINK_LIBS
|
||||
CIRCTCAPIComb
|
||||
CIRCTCAPIESI
|
||||
CIRCTCAPIMSFT
|
||||
CIRCTCAPIRTL
|
||||
CIRCTCAPISV
|
||||
CIRCTCAPIExportVerilog
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "DialectModules.h"
|
||||
|
||||
#include "circt/Dialect/MSFT/MSFTAttributes.h"
|
||||
#include "circt/Support/LLVM.h"
|
||||
|
||||
#include "mlir/CAPI/IR.h"
|
||||
|
@ -19,12 +20,34 @@
|
|||
namespace py = pybind11;
|
||||
|
||||
using namespace circt;
|
||||
using namespace circt::msft;
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// Functions that translate from something Pybind11 understands to MLIR C++.
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
static void addPhysLocationAttr(MlirOperation cOp, std::string entityName,
|
||||
DeviceType type, uint64_t x, uint64_t y,
|
||||
uint64_t num) {
|
||||
|
||||
Operation *op = unwrap(cOp);
|
||||
MLIRContext *ctxt = op->getContext();
|
||||
PhysLocationAttr loc =
|
||||
PhysLocationAttr::get(ctxt, DeviceTypeAttr::get(ctxt, type), x, y, num);
|
||||
SmallString<64> entity("loc:");
|
||||
entity.append(entityName);
|
||||
op->setAttr(entity, loc);
|
||||
}
|
||||
|
||||
/// Populate the msft python module.
|
||||
void circt::python::populateDialectMSFTSubmodule(py::module &m) {
|
||||
m.doc() = "MSFT dialect Python native extension";
|
||||
m.def("locate", &addPhysLocationAttr,
|
||||
"Attach a physical location to an op's entity.",
|
||||
py::arg("op_to_locate"), py::arg("entity_within"), py::arg("devtype"),
|
||||
py::arg("x"), py::arg("y"), py::arg("num"));
|
||||
py::enum_<DeviceType>(m, "DeviceType")
|
||||
.value("M20K", DeviceType::M20K)
|
||||
.value("DSP", DeviceType::DSP)
|
||||
.export_values();
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
set(LLVM_OPTIONAL_SOURCES
|
||||
Comb.cpp
|
||||
ESI.cpp
|
||||
MSFT.cpp
|
||||
RTL.cpp
|
||||
SV.cpp
|
||||
)
|
||||
|
@ -30,6 +31,18 @@ add_circt_library(CIRCTCAPIESI
|
|||
CIRCTESI
|
||||
)
|
||||
|
||||
add_circt_library(CIRCTCAPIMSFT
|
||||
|
||||
MSFT.cpp
|
||||
|
||||
ADDITIONAL_HEADER_DIRS
|
||||
${MLIR_MAIN_INCLUDE_DIR}/mlir-c
|
||||
|
||||
LINK_LIBS PUBLIC
|
||||
MLIRCAPIIR
|
||||
CIRCTMSFT
|
||||
)
|
||||
|
||||
add_circt_library(CIRCTCAPIRTL
|
||||
|
||||
RTL.cpp
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
//===- MSFT.cpp - C Interface for the MSFT Dialect ------------------------===//
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "circt-c/Dialect/MSFT.h"
|
||||
#include "circt/Dialect/MSFT/MSFTDialect.h"
|
||||
#include "mlir/CAPI/IR.h"
|
||||
#include "mlir/CAPI/Registration.h"
|
||||
#include "mlir/CAPI/Support.h"
|
||||
|
||||
MLIR_DEFINE_CAPI_DIALECT_REGISTRATION(MSFT, msft, circt::msft::MSFTDialect)
|
Loading…
Reference in New Issue