-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MSFT] Python bindings for ops and changes to make them work
- Adds python bindings for MSFTModuleOp and InstanceOp. - Re-use as much as possible from `circt.hw._hw_ops_ext`. Required changes to ODS definitions. - Found and fixed some bugs.
- Loading branch information
Showing
9 changed files
with
140 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
//===-- MSFTOps.td - Entry point for MSFTOps bindings ------*- tablegen -*-===// | ||
// | ||
// 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 BINDINGS_PYTHON_MSFT_OPS | ||
#define BINDINGS_PYTHON_MSFT_OPS | ||
|
||
include "mlir/Bindings/Python/Attributes.td" | ||
include "circt/Dialect/MSFT/MSFT.td" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# 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 | ||
|
||
from circt.dialects import msft as _msft | ||
import circt.dialects._hw_ops_ext as _hw_ext | ||
import circt.support as support | ||
|
||
import mlir.ir as _ir | ||
|
||
|
||
class InstanceBuilder(support.NamedValueOpView): | ||
"""Helper class to incrementally construct an instance of a module.""" | ||
|
||
def __init__(self, | ||
module, | ||
name, | ||
input_port_mapping, | ||
*, | ||
results=None, | ||
sym_name=None, | ||
loc=None, | ||
ip=None): | ||
self.module = module | ||
instance_name = _ir.StringAttr.get(name) | ||
module_name = _ir.FlatSymbolRefAttr.get(_ir.StringAttr(module.name).value) | ||
if sym_name: | ||
sym_name = _ir.StringAttr.get(sym_name) | ||
pre_args = [instance_name, module_name] | ||
if results is None: | ||
results = module.type.results | ||
|
||
super().__init__(_msft.InstanceOp, | ||
results, | ||
input_port_mapping, | ||
pre_args, [], | ||
loc=loc, | ||
ip=ip) | ||
|
||
def create_default_value(self, index, data_type, arg_name): | ||
type = self.module.type.inputs[index] | ||
return support.BackedgeBuilder.create(type, | ||
arg_name, | ||
self, | ||
instance_of=self.module) | ||
|
||
def operand_names(self): | ||
arg_names = _ir.ArrayAttr(self.module.attributes["argNames"]) | ||
arg_name_attrs = map(_ir.StringAttr, arg_names) | ||
return list(map(lambda s: s.value, arg_name_attrs)) | ||
|
||
def result_names(self): | ||
arg_names = _ir.ArrayAttr(self.module.attributes["resultNames"]) | ||
arg_name_attrs = map(_ir.StringAttr, arg_names) | ||
return list(map(lambda s: s.value, arg_name_attrs)) | ||
|
||
|
||
class MSFTModuleOp(_hw_ext.ModuleLike): | ||
|
||
def __init__( | ||
self, | ||
name, | ||
input_ports=[], | ||
output_ports=[], | ||
parameters={}, | ||
loc=None, | ||
ip=None, | ||
): | ||
attrs = {"parameters": _ir.DictAttr.get(parameters)} | ||
super().__init__(name, | ||
input_ports, | ||
output_ports, | ||
attributes=attrs, | ||
loc=loc, | ||
ip=ip) | ||
|
||
def create(self, name: str, results=None, loc=None, ip=None, **kwargs): | ||
return InstanceBuilder(self, name, kwargs, results=results, loc=loc, ip=ip) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# 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 | ||
|
||
from ._msft_ops_gen import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters