Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed ByteFlow and FlowInfo #84

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
63e1194
Added from_yaml, to_yaml, from_dict and to_dict conversion for new fo…
kc611 Jun 29, 2023
1d9689a
Refactored test suite to match the new functions
kc611 Jun 29, 2023
dae773c
Added region identification and printing capabilities to to_yaml and …
kc611 Jun 29, 2023
0ea0e6c
Adapted tests to the changes
kc611 Jun 29, 2023
4213e58
Fixed no head detected test failure
kc611 Jun 29, 2023
1f5d955
Added block type identification capability to from_dict and from_yaml
kc611 Jul 1, 2023
ac2802e
Added yaml based block building capabilities to SCFG
kc611 Jul 3, 2023
7a3b4c2
Automated Bahmann paper figure tests
kc611 Jul 3, 2023
e1097ad
Adapted test suite to changes
kc611 Jul 3, 2023
fcdc9b9
refactor YAML writing to use indent for readability
esc Jul 5, 2023
8cd3009
Apply suggestions from code review
kc611 Jul 6, 2023
462c716
Used isinstance instead of string comparison in to_dict method
kc611 Jul 6, 2023
e4dd79c
Added equality assertions for synthetic assignments and synthetic bra…
kc611 Jul 6, 2023
d7e907b
Changed jump targets and backedges replacement login in basic blocks
kc611 Jul 7, 2023
d28a326
Adapted core datastructures to basic block logic changes
kc611 Jul 7, 2023
0b95844
Adapted transformations to basic block changes
kc611 Jul 7, 2023
7ce552e
Adapted rendering to basic block changes
kc611 Jul 7, 2023
f04eeb9
Adapted tests to basic block changes
kc611 Jul 7, 2023
2c68abf
Removed Byteflow and FlowInfo and moved respective methods to SCFG
kc611 Jul 7, 2023
018aa54
Simplified graph rendering
kc611 Jul 7, 2023
9000b38
Adapted tests according to the changes
kc611 Jul 7, 2023
709453e
Adapted simulator to changes
kc611 Jul 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 59 additions & 45 deletions numba_rvsdg/core/datastructures/basic_block.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import dis
from typing import Tuple, Dict, List
from dataclasses import dataclass, replace
from dataclasses import dataclass, replace, field

from numba_rvsdg.core.utils import _next_inst_offset
from numba_rvsdg.core.datastructures import block_names


@dataclass(frozen=True)
Expand All @@ -19,15 +20,20 @@ class BasicBlock:
_jump_targets: Tuple[str]
Jump targets (branch destinations) for this block.

backedges: Tuple[str]
Backedges for this block.
backedges: Tuple[bool]
Indicates if the Jump target at the particular index
is a backedge or not.
"""

name: str

_jump_targets: Tuple[str] = tuple()

backedges: Tuple[str] = tuple()
backedges: Tuple[bool] = field(init=False)

def __post_init__(self):
backedges = tuple([False] * len(self._jump_targets))
object.__setattr__(self, "backedges", backedges)

@property
def is_exiting(self) -> bool:
Expand Down Expand Up @@ -69,32 +75,27 @@ def jump_targets(self) -> Tuple[str]:

"""
acc = []
for j in self._jump_targets:
if j not in self.backedges:
for idx, j in enumerate(self._jump_targets):
if not self.backedges[idx]:
acc.append(j)
return tuple(acc)

def declare_backedge(self, target: str) -> "BasicBlock":
def declare_backedge(self, target: str):
"""Declare one of the jump targets as a backedge of this block.

Parameters
----------
target: str
The jump target that is to be declared as a backedge.

Returns
-------
basic_block: BasicBlock
The resulting block.

"""
if target in self.jump_targets:
assert not self.backedges
return replace(self, backedges=(target,))
return self
assert target in self._jump_targets
idx = self._jump_targets.index(target)
current_backedges = list(self.backedges)
current_backedges[idx] = True
object.__setattr__(self, "backedges", tuple(current_backedges))

def replace_jump_targets(self, jump_targets: Tuple) -> "BasicBlock":
"""Replaces jump targets of this block by the given tuple.
def change_jump_targets(self, jump_targets: Tuple):
"""Changes jump targets of this block by the given tuple.

This method replaces the jump targets of the current BasicBlock.
The provided jump targets must be in the same order as their
Expand All @@ -108,34 +109,18 @@ def replace_jump_targets(self, jump_targets: Tuple) -> "BasicBlock":
----------
jump_targets: Tuple
The new jump target tuple. Must be ordered.

Returns
-------
basic_block: BasicBlock
The resulting BasicBlock.

"""
return replace(self, _jump_targets=jump_targets)
is_backedge = {}
new_backedges = []

def replace_backedges(self, backedges: Tuple) -> "BasicBlock":
"""Replaces back edges of this block by the given tuple.
for idx, i in enumerate(self.backedges):
is_backedge[self._jump_targets[idx]] = i

This method replaces the back edges of the current BasicBlock.
The provided back edges must be in the same order as their
intended original replacements.
for i in jump_targets:
new_backedges.append(is_backedge.get(i, False))

Parameters
----------
backedges: Tuple
The new back edges tuple. Must be ordered.

Returns
-------
basic_block: BasicBlock
The resulting BasicBlock.

"""
return replace(self, backedges=backedges)
object.__setattr__(self, "_jump_targets", jump_targets)
object.__setattr__(self, "backedges", new_backedges)


@dataclass(frozen=True)
Expand All @@ -156,6 +141,8 @@ class PythonBytecodeBlock(BasicBlock):

end: int = None

bcmap: dis.Bytecode = None

def get_instructions(
self, bcmap: Dict[int, dis.Instruction]
) -> List[dis.Instruction]:
Expand Down Expand Up @@ -233,8 +220,8 @@ class SyntheticFill(SyntheticBlock):

@dataclass(frozen=True)
class SyntheticAssignment(SyntheticBlock):
"""The SyntheticAssignment class represents a artificially added assignment block
in a structured control flow graph (SCFG).
"""The SyntheticAssignment class represents a artificially added
assignment block in a structured control flow graph (SCFG).

This block is responsible for giving variables their values,
once the respective block is executed.
Expand Down Expand Up @@ -384,3 +371,30 @@ def replace_exiting(self, new_exiting):
The new exiting block of the region represented by the RegionBlock.
"""
object.__setattr__(self, "exiting", new_exiting)

def replace_parent(self, new_parent):
"""This method performs a inplace replacement of the parent region
block.

Parameters
----------
new_exiting: str
The new exiting block of the region represented by the RegionBlock.
"""
object.__setattr__(self, "parent", new_parent)


block_type_names = {
block_names.BASIC: BasicBlock,
block_names.PYTHON_BYTECODE: PythonBytecodeBlock,
block_names.SYNTH_HEAD: SyntheticHead,
block_names.SYNTH_BRANCH: SyntheticBranch,
block_names.SYNTH_TAIL: SyntheticTail,
block_names.SYNTH_EXIT: SyntheticExit,
block_names.SYNTH_ASSIGN: SyntheticAssignment,
block_names.SYNTH_RETURN: SyntheticReturn,
block_names.SYNTH_EXIT_LATCH: SyntheticExitingLatch,
block_names.SYNTH_EXIT_BRANCH: SyntheticExitBranch,
block_names.SYNTH_FILL: SyntheticFill,
block_names.REGION: RegionBlock,
}
18 changes: 18 additions & 0 deletions numba_rvsdg/core/datastructures/block_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,21 @@
SYNTH_RETURN = "synth_return"
SYNTH_EXIT_LATCH = "synth_exit_latch"
SYNTH_FILL = "synth_fill"
SYNTH_EXIT_BRANCH = "synth_exit_branch"

REGION = "region"

block_types = {
BASIC,
PYTHON_BYTECODE,
SYNTH_HEAD,
SYNTH_BRANCH,
SYNTH_TAIL,
SYNTH_EXIT,
SYNTH_ASSIGN,
SYNTH_RETURN,
SYNTH_EXIT_LATCH,
SYNTH_EXIT_BRANCH,
SYNTH_FILL,
REGION,
}
153 changes: 0 additions & 153 deletions numba_rvsdg/core/datastructures/byte_flow.py

This file was deleted.

Loading