Skip to content

Commit 6174bab

Browse files
authored
Merge pull request #29 from kc611/regions
Added region heirarchy and fixed region rendering
2 parents 2a59a96 + a86040f commit 6174bab

File tree

10 files changed

+491
-153
lines changed

10 files changed

+491
-153
lines changed

numba_rvsdg/core/datastructures/basic_block.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@
77

88

99
@dataclass(frozen=True)
10-
class BasicBlock:
10+
class Block:
1111
name_gen: InitVar[NameGenerator]
12-
"""Block Name Generator associated with this BasicBlock.
12+
"""Block Name Generator associated with this Block.
1313
Note: This is an initialization only argument and not
1414
a class attribute."""
1515

16-
block_name: BlockName = field(init=False)
17-
"""Unique name identifier for this block"""
18-
1916
label: Label
2017
"""The corresponding Label for this block."""
2118

22-
def __post_init__(self, name_gen):
19+
20+
@dataclass(frozen=True)
21+
class BasicBlock(Block):
22+
23+
block_name: BlockName = field(init=False)
24+
"""Unique name identifier for this block"""
25+
26+
def __post_init__(self, name_gen: NameGenerator):
2327
block_name = name_gen.new_block_name(label=self.label)
2428
object.__setattr__(self, "block_name", block_name)
2529

numba_rvsdg/core/datastructures/flow_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def build_basicblocks(self: "FlowInfo", end_offset=None) -> "SCFG":
9494
targets = [names[o] for o in self.jump_insts[term_offset]]
9595

9696
block_name = names[begin]
97-
scfg.add_connections(block_name, targets, [])
97+
scfg.add_connections(block_name, targets)
9898

9999
scfg.check_graph()
100100
return scfg

numba_rvsdg/core/datastructures/labels.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ class ControlLabel(Label):
1919
pass
2020

2121

22+
@dataclass(frozen=True, order=True)
23+
class RegionLabel(Label):
24+
pass
25+
26+
2227
@dataclass(frozen=True, order=True)
2328
class SyntheticBranch(ControlLabel):
2429
pass
@@ -59,6 +64,16 @@ class SynthenticAssignment(ControlLabel):
5964
pass
6065

6166

67+
@dataclass(frozen=True, order=True)
68+
class LoopRegionLabel(RegionLabel):
69+
pass
70+
71+
72+
@dataclass(frozen=True, order=True)
73+
class MetaRegionLabel(RegionLabel):
74+
pass
75+
76+
6277
# Maybe we can register new labels over here instead of static lists
6378
label_types = {
6479
"label": Label,
@@ -83,15 +98,24 @@ def get_label_class(label_type_string):
8398

8499

85100
@dataclass(frozen=True, order=True)
86-
class BlockName:
101+
class Name:
87102
name: str
88-
...
103+
104+
def __repr__(self):
105+
return self.name
106+
107+
def __str__(self):
108+
return self.name
89109

90110

91111
@dataclass(frozen=True, order=True)
92-
class RegionName:
93-
name: str
94-
...
112+
class BlockName(Name):
113+
pass
114+
115+
116+
@dataclass(frozen=True, order=True)
117+
class RegionName(Name):
118+
pass
95119

96120

97121
@dataclass
@@ -117,10 +141,10 @@ def new_block_name(self, label: str) -> BlockName:
117141
self.block_index += 1
118142
return BlockName(str(label).lower().split("(")[0] + "_" + str(ret))
119143

120-
def new_region_name(self, kind: str) -> RegionName:
144+
def new_region_name(self, label: str) -> RegionName:
121145
ret = self.region_index
122146
self.region_index += 1
123-
return RegionName(str(kind).lower().split("(")[0] + "_" + str(ret))
147+
return RegionName(str(label).lower().split("(")[0] + "_" + str(ret))
124148

125149
def new_var_name(self) -> str:
126150
variable_name = chr(self.variable_index)
Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,47 @@
1-
from dataclasses import dataclass, field, InitVar
1+
from dataclasses import dataclass, field
2+
from numba_rvsdg.core.datastructures.basic_block import Block
23

34
from numba_rvsdg.core.datastructures.labels import NameGenerator, RegionName, BlockName
45

56

67
@dataclass(frozen=True)
7-
class Region:
8-
name_gen: InitVar[NameGenerator]
9-
"""Region Name Generator associated with this Region.
10-
Note: This is an initialization only argument and not
11-
a class attribute."""
12-
8+
class Region(Block):
139
region_name: RegionName = field(init=False)
1410
"""Unique name identifier for this region"""
1511

16-
kind: str
12+
def __post_init__(self, name_gen: NameGenerator):
13+
region_name = name_gen.new_region_name(self.label)
14+
object.__setattr__(self, "region_name", region_name)
15+
16+
17+
@dataclass(frozen=True)
18+
class LoopRegion(Region):
1719
header: BlockName
1820
exiting: BlockName
21+
...
1922

20-
def __post_init__(self, name_gen):
21-
region_name = name_gen.new_region_name(kind=self.kind)
22-
object.__setattr__(self, "region_name", region_name)
23+
24+
@dataclass(frozen=True)
25+
class MetaRegion(Region):
26+
...
27+
28+
29+
# TODO: Register new regions over here
30+
region_types = {
31+
"loop": LoopRegion
32+
}
33+
34+
35+
def get_region_class(region_type_string: str):
36+
if region_type_string in region_types:
37+
return region_types[region_type_string]
38+
else:
39+
raise TypeError(f"Region Type {region_type_string} not recognized.")
40+
41+
42+
def get_region_class_str(region: Region):
43+
for key, value in region_types.items():
44+
if isinstance(region, value):
45+
return key
46+
else:
47+
raise TypeError(f"Region Type of {region} not recognized.")

0 commit comments

Comments
 (0)