-
Notifications
You must be signed in to change notification settings - Fork 307
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
446 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# REQUIRES: bindings_python | ||
# RUN: %PYTHON% %s | FileCheck %s | ||
|
||
import circt | ||
|
||
from circt.dialects import rtg, rtgtest | ||
from circt.ir import Context, Location, Module, InsertionPoint, Block, StringAttr, TypeAttr | ||
from circt.passmanager import PassManager | ||
from circt import rtgtool_support as rtgtool | ||
|
||
with Context() as ctx, Location.unknown(): | ||
circt.register_dialects(ctx) | ||
m = Module.create() | ||
with InsertionPoint(m.body): | ||
cpuTy = rtgtest.CPUType.get() | ||
dictTy = rtg.DictType.get( | ||
ctx, | ||
[StringAttr.get('cpu0'), StringAttr.get('cpu1')], [cpuTy, cpuTy]) | ||
|
||
target = rtg.TargetOp('target_name', TypeAttr.get(dictTy)) | ||
targetBlock = Block.create_at_start(target.bodyRegion, []) | ||
with InsertionPoint(targetBlock): | ||
cpu0 = rtgtest.CPUDeclOp(cpuTy, 0) | ||
cpu1 = rtgtest.CPUDeclOp(cpuTy, 1) | ||
rtg.YieldOp([cpu0, cpu1]) | ||
|
||
test = rtg.TestOp('test_name', TypeAttr.get(dictTy)) | ||
Block.create_at_start(test.bodyRegion, [cpuTy, cpuTy]) | ||
|
||
# CHECK: rtg.target @target_name : !rtg.dict<cpu0: !rtgtest.cpu, cpu1: !rtgtest.cpu> { | ||
# CHECK: [[V0:%.+]] = rtgtest.cpu_decl 0 | ||
# CHECK: [[V1:%.+]] = rtgtest.cpu_decl 1 | ||
# CHECK: rtg.yield [[V0]], [[V1]] : !rtgtest.cpu, !rtgtest.cpu | ||
# CHECK: } | ||
# CHECK: rtg.test @test_name : !rtg.dict<cpu0: !rtgtest.cpu, cpu1: !rtgtest.cpu> { | ||
# CHECK: ^bb{{.*}}(%{{.*}}: !rtgtest.cpu, %{{.*}}: !rtgtest.cpu): | ||
# CHECK: } | ||
print(m) | ||
|
||
with Context() as ctx, Location.unknown(): | ||
circt.register_dialects(ctx) | ||
m = Module.create() | ||
with InsertionPoint(m.body): | ||
seq = rtg.SequenceOp('sequence_name') | ||
Block.create_at_start(seq.bodyRegion, []) | ||
|
||
test = rtg.TestOp('test_name', TypeAttr.get(rtg.DictType.get())) | ||
block = Block.create_at_start(test.bodyRegion, []) | ||
with InsertionPoint(block): | ||
seq_closure = rtg.SequenceClosureOp('sequence_name', []) | ||
rtg.InvokeSequenceOp(seq_closure) | ||
|
||
# CHECK: rtg.test @test_name : !rtg.dict<> { | ||
# CHECK-NEXT: rtg.sequence_closure | ||
# CHECK-NEXT: rtg.invoke_sequence | ||
# CHECK-NEXT: } | ||
print(m) | ||
|
||
pm = PassManager() | ||
options = rtgtool.Options( | ||
output_format=rtgtool.OutputFormat.ELABORATED_MLIR, | ||
debug_mode=True, | ||
) | ||
rtgtool.populate_randomizer_pipeline(pm, options) | ||
pm.run(m.operation) | ||
|
||
# CHECK: rtg.test @test_name : !rtg.dict<> { | ||
# CHECK-NEXT: } | ||
print(m) |
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,62 @@ | ||
//===- RTGModule.cpp - RTG API pybind module ------------------------------===// | ||
// | ||
// 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 "CIRCTModules.h" | ||
|
||
#include "circt-c/Dialect/RTG.h" | ||
|
||
#include "mlir/Bindings/Python/PybindAdaptors.h" | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/pytypes.h> | ||
#include <pybind11/stl.h> | ||
namespace py = pybind11; | ||
|
||
using namespace circt; | ||
using namespace mlir::python::adaptors; | ||
|
||
/// Populate the rtg python module. | ||
void circt::python::populateDialectRTGSubmodule(py::module &m) { | ||
m.doc() = "RTG dialect Python native extension"; | ||
|
||
mlir_type_subclass(m, "SequenceType", rtgTypeIsASequence) | ||
.def_classmethod( | ||
"get", | ||
[](py::object cls, MlirContext ctxt) { | ||
return cls(rtgSequenceTypeGet(ctxt)); | ||
}, | ||
py::arg("self"), py::arg("ctxt") = nullptr); | ||
|
||
mlir_type_subclass(m, "SetType", rtgTypeIsASet) | ||
.def_classmethod( | ||
"get", | ||
[](py::object cls, MlirType elementType) { | ||
return cls(rtgSetTypeGet(elementType)); | ||
}, | ||
py::arg("self"), py::arg("element_type")); | ||
|
||
mlir_type_subclass(m, "DictType", rtgTypeIsADict) | ||
.def_classmethod( | ||
"get", | ||
[](py::object cls, MlirContext ctxt, py::list entryNames, | ||
py::list entryTypes) { | ||
std::vector<MlirAttribute> names; | ||
std::vector<MlirType> types; | ||
for (auto type : entryNames) | ||
names.push_back(type.cast<MlirAttribute>()); | ||
for (auto type : entryTypes) | ||
types.push_back(type.cast<MlirType>()); | ||
assert(names.size() == types.size() && | ||
"number of entry names and entry types must match"); | ||
return cls( | ||
rtgDictTypeGet(ctxt, types.size(), names.data(), types.data())); | ||
}, | ||
py::arg("self"), py::arg("ctxt") = nullptr, | ||
py::arg("entry_names") = py::list(), | ||
py::arg("entry_types") = py::list()); | ||
} |
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,34 @@ | ||
//===- RTGTestModule.cpp - RTGTest API pybind module ----------------------===// | ||
// | ||
// 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 "CIRCTModules.h" | ||
|
||
#include "circt-c/Dialect/RTGTest.h" | ||
|
||
#include "mlir/Bindings/Python/PybindAdaptors.h" | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/pytypes.h> | ||
#include <pybind11/stl.h> | ||
namespace py = pybind11; | ||
|
||
using namespace circt; | ||
using namespace mlir::python::adaptors; | ||
|
||
/// Populate the rtgtest python module. | ||
void circt::python::populateDialectRTGTestSubmodule(py::module &m) { | ||
m.doc() = "RTGTest dialect Python native extension"; | ||
|
||
mlir_type_subclass(m, "CPUType", rtgtestTypeIsACPU) | ||
.def_classmethod( | ||
"get", | ||
[](py::object cls, MlirContext ctxt) { | ||
return cls(rtgtestCPUTypeGet(ctxt)); | ||
}, | ||
py::arg("self"), py::arg("ctxt") = nullptr); | ||
} |
Oops, something went wrong.