Skip to content

Commit

Permalink
Enable ir_graph representation while dataflow analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
joscao committed Oct 27, 2023
1 parent af8ec9f commit 306c875
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions loki/visitors/ir_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,19 @@ def __add_node(self, node, **kwargs):
"""
label = kwargs.get("label", "")
if label == "":
label = self.format_node(repr(node))
try:
comment = "\nlive: " + ", ".join(
str(symbol) for symbol in node.live_symbols
)
comment += "\ndefines: " + ", ".join(
str(symbol) for symbol in node.defines_symbols
)
comment += "\nuses: " + ", ".join(
str(symbol) for symbol in node.uses_symbols
)
label = self.format_node(repr(node), comment)
except (RuntimeError, KeyError, AttributeError) as _:
label = self.format_node(repr(node))

shape = kwargs.get("shape", "oval")

Expand Down Expand Up @@ -321,8 +333,7 @@ def visit_Conditional(self, o, **kwargs):
return node_edge_info


def ir_graph(
ir, show_comments=False, show_expressions=False, linewidth=40, symgen=str):
def ir_graph(ir, show_comments=False, show_expressions=False, linewidth=40, symgen=str):
"""
Pretty-print the given IR using :class:`GraphCollector`.
Expand All @@ -342,8 +353,12 @@ def ir_graph(
log = "[Loki::Graph Visualization] Created graph visualization in {:.2f}s"

with Timer(text=log):
graph_representation = GraphCollector(show_comments, show_expressions, linewidth, symgen)
node_edge_info = [item for item in graph_representation.visit(ir) if item is not None]
graph_representation = GraphCollector(
show_comments, show_expressions, linewidth, symgen
)
node_edge_info = [
item for item in graph_representation.visit(ir) if item is not None
]

graph = Digraph()
graph.attr(rankdir="LR")
Expand Down

0 comments on commit 306c875

Please sign in to comment.