[PyCDE] Add graphviz output (#1285)

This commit is contained in:
John Demme 2021-06-16 16:22:05 -07:00 committed by GitHub
parent ce119b5617
commit 2fa15a18ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 1 deletions

View File

@ -43,6 +43,12 @@ class System:
def print(self):
self.mod.operation.print()
def graph(self, short_names=True):
import mlir.all_passes_registration
pm = mlir.passmanager.PassManager.parse("view-op-graph{short-names=" +
("1" if short_names else "0") + "}")
pm.run(self.mod)
def generate(self, generator_names=[]):
pm = mlir.passmanager.PassManager.parse("run-generators{generators=" +
",".join(generator_names) + "}")

View File

@ -1,4 +1,4 @@
# RUN: %PYTHON% %s | FileCheck %s
# RUN: %PYTHON% %s 2>&1 | FileCheck %s
from __future__ import annotations
@ -86,6 +86,11 @@ class Polynomial(pycde.System):
poly = Polynomial()
poly.graph()
# CHECK-LABEL: digraph "top"
# CHECK: label="top";
# CHECK: [shape=record,label="{hw.constant\ni32\n\nvalue: 23 : i32}"];
poly.print()
# CHECK-LABEL: hw.module @top() -> (%y: i32)
# CHECK: [[REG0:%.+]] = "pycde.PolynomialCompute"(%c23_i32) {instanceName = "example", opNames = ["x"], parameters = {coefficients = [62, 42, 6], module_name = "PolyComputeForCoeff_62_42_6", unused_parameter = true}, resultNames = ["y"]} : (i32) -> i32