Skip to content

Commit

Permalink
feat(explorer)[PE Graph creation]: calculate loop indices as metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Jan 11, 2024
1 parent 7529efe commit 49e3965
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
24 changes: 24 additions & 0 deletions discopop_explorer/PEGraphX.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,12 @@ class LoopNode(Node):
loop_iterations: int = -1
contains_array_reduction: bool = False
loop_data: Optional[LoopData]
loop_indices: List[str]

def __init__(self, node_id: NodeID):
super().__init__(node_id)
self.type = NodeType.LOOP
self.loop_indices = []

def get_nesting_level(self, pet: PEGraphX, return_invert_result: bool = True) -> int:
"""Returns the loop nesting level for the given loop node.
Expand Down Expand Up @@ -816,6 +818,28 @@ def calculateFunctionMetadata(self) -> None:
self.g.remove_edge(edge[0], edge[1], edge[2])
print("Cleaning dependencies II done.")

def calculateLoopMetadata(self):
print("Calculating loop metadata")

# calculate loop indices
print("Calculating loop indices")
loop_nodes = self.all_nodes(LoopNode)
for loop in loop_nodes:
subtree = self.subtree_of_type(loop, CUNode)
# get variables used in loop
candidates: Set[Variable] = set()
for node in subtree:
candidates.update(node.global_vars + node.local_vars)
# identify loop indices
loop_indices: Set[Variable] = set()
for v in candidates:
if self.is_loop_index(v.name, loop.start_position(), subtree):
loop_indices.add(v)
loop.loop_indices = [v.name for v in loop_indices]
print("\tDone.")

print("Calculating loop metadata done.")

def show(self):
"""Plots the graph
Expand Down
1 change: 1 addition & 0 deletions discopop_explorer/pattern_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def detect_patterns(
self.__merge(False, True)
self.pet.map_static_and_dynamic_dependencies()
self.pet.calculateFunctionMetadata()
self.pet.calculateLoopMetadata()
res = DetectionResult(self.pet)

# reduction before doall!
Expand Down

0 comments on commit 49e3965

Please sign in to comment.