Skip to content

Commit

Permalink
Modify CFG block list dict accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcere committed Sep 10, 2024
1 parent 30ebc4b commit 9514a3a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/liveness/layout_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
import heapq
import itertools
from typing import Dict, List, Type, Any, Set, Tuple
from typing import Dict, List, Type, Any, Set, Tuple, Optional
import networkx as nx
from pathlib import Path

Expand Down Expand Up @@ -179,15 +179,15 @@ def var_order_repr(block_name: str, var_info: Dict[str, int]):
return '\n'.join(text_format)


def print_stacks(block_name: str, block: CFGBlock):
text_format = [f"{block_name}:", f"Src: {block.input_stack}", f"Tgt: {block.output_stack}"]
def print_stacks(block_name: str, json_dict: Dict[str, Any]):
text_format = [f"{block_name}:", f"Src: {json_dict[block_name]['src_ws']}", f"Tgt: {json_dict[block_name]['tgt_ws']}"]
return '\n'.join(text_format)


class LayoutGeneration:

def __init__(self, object_id, block_list: CFGBlockList, liveness_info: Dict[str, LivenessAnalysisInfo], name: Path,
cfg_graph: nx.Graph = None):
cfg_graph: Optional[nx.Graph] = None):
self._id = object_id
self._block_list = block_list
self._liveness_info = liveness_info
Expand Down Expand Up @@ -309,10 +309,6 @@ def _construct_code_from_block(self, block: CFGBlock, input_stacks: Dict[str, Li
block_json[subblock_name]["src_ws"] = input_stack
block_json[subblock_name]["tgt_ws"] = output_stack

# TODO: temporal hack to output the input and output stacks
block.input_stack = input_stack
block.output_stack = output_stack

return block_json

def _construct_code_from_block_list(self):
Expand Down Expand Up @@ -341,8 +337,8 @@ def _construct_code_from_block_list(self):
# Retrieve the block
current_block = self._block_list.get_block(block_name)

block_specification = self._construct_code_from_block(current_block, input_stacks, output_stacks, combined_stacks)

block_specification = self._construct_code_from_block(current_block, input_stacks,
output_stacks, combined_stacks)
json_info.update(block_specification)

successors = [possible_successor for possible_successor in
Expand All @@ -359,9 +355,9 @@ def build_layout(self):
"""
json_info = self._construct_code_from_block_list()

renamed_graph = information_on_graph(self._cfg_graph, {block_name: print_stacks(block_name, block)
for block_name, block in
self._block_list.blocks.items()})
renamed_graph = information_on_graph(self._cfg_graph, {block_name: print_stacks(block_name, json_info[block_name])
for block_name in
self._block_list.blocks})

nx.nx_agraph.write_dot(renamed_graph, Path(self._dir.parent).joinpath(self._dir.stem + "_stacks.dot"))
return json_info
Expand Down
2 changes: 2 additions & 0 deletions src/parser/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ def modify_cfg_block_list(self, f: Callable[[CFGBlockList], CFGBlockList]) -> No
"""
for object_id, cfg_object in self.objectCFG.items():
cfg_object.blocks = f(cfg_object.blocks)
self.block_list[object_id] = cfg_object.blocks

# We also consider the information per function
for function_name, cfg_function in cfg_object.functions.items():
cfg_function.blocks = f(cfg_function.blocks)
self.block_list[function_name] = cfg_function.blocks

subobject = self.get_subobject()

Expand Down
6 changes: 6 additions & 0 deletions src/parser/optimizable_block_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def compute_sub_block_list(block_list: CFGBlockList) -> CFGBlockList:
new_block_list.add_block(cfg_block)

update_edges_cfg(new_block_list, modified_blocks)

# Finally, we update the initial start block with the new format
modified_start_block = modified_blocks.get(block_list.start_block, None)
if modified_start_block is not None:
new_block_list.start_block = modified_start_block[0]

return new_block_list


Expand Down

0 comments on commit 9514a3a

Please sign in to comment.