Region
Region dataclass
Region(
blocks: Block | Iterable[Block] = (),
parent: Statement | None = None,
*,
source: SourceInfo | None = None
)
Bases: IRNode['Statement']
Region consist of a list of Blocks
Pretty Printing
This object is pretty printable via .print()
method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blocks | Block | Iterable[Block] | A single | () |
parent | Statement | None | The parent | None |
Source code in src/kirin/ir/nodes/region.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
blocks property
blocks: RegionBlocks
Get the Blocks in the region.
Returns:
Name | Type | Description |
---|---|---|
RegionBlocks | RegionBlocks | The blocks View object of the region. |
parent_node property
writable
parent_node: Statement | None
Get the parent statement of the region.
region_index property
region_index: int
Get the index of the region within the parent scope.
Returns:
Name | Type | Description |
---|---|---|
int | int | The index of the region within the parent scope. |
__getitem__
__getitem__(block: Block) -> int
Get the index of a block within the region.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
block | Block | The block to get the index of. | required |
Raises:
Type | Description |
---|---|
ValueError | If the block does not belong to the region. |
Returns:
Name | Type | Description |
---|---|---|
int | int | The index of the block within the region. |
Source code in src/kirin/ir/nodes/region.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
|
clone
clone(
ssamap: dict[SSAValue, SSAValue] | None = None
) -> Region
Clone a region. This will clone all blocks and statements in the region. SSAValue
defined outside the region will not be cloned unless provided in ssamap
.
Source code in src/kirin/ir/nodes/region.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
|
delete
delete(safe: bool = True) -> None
Delete the Region completely from the IR graph.
Note
This method will detach + remove references of the Region.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
safe | bool | If True, raise error if there is anything that still reference components in the Region. Defaults to True. | True |
Source code in src/kirin/ir/nodes/region.py
233 234 235 236 237 238 239 240 241 242 243 |
|
detach
detach(index: int | None = None) -> None
Detach this Region from the IR tree graph.
Note
Detach only detach the Region from the IR graph. It does not remove uses that reference the Region.
Source code in src/kirin/ir/nodes/region.py
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|
drop_all_references
drop_all_references() -> None
Remove all the dependency that reference/uses this Region.
Source code in src/kirin/ir/nodes/region.py
227 228 229 230 231 |
|
is_structurally_equal
is_structurally_equal(
other: Self,
context: (
dict[IRNode | SSAValue, IRNode | SSAValue] | None
) = None,
) -> bool
Check if the Region is structurally equal to another Region.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other | Self | The other Region to compare with. | required |
context | dict[IRNode | SSAValue, IRNode | SSAValue] | None | A map of IRNode/SSAValue to hint that they are equivalent so the check will treat them as equivalent. Defaults to None. | None |
Returns:
Name | Type | Description |
---|---|---|
bool | bool | True if the Region is structurally equal to the other Region. |
Source code in src/kirin/ir/nodes/region.py
245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
|
stmts
stmts() -> Iterator[Statement]
Iterate over all the Statements in the Region. This does not walk into nested Regions.
Yields:
Type | Description |
---|---|
Statement | Iterator[Statement]: An iterator that yield Statements of Blocks in the Region. |
Source code in src/kirin/ir/nodes/region.py
291 292 293 294 295 296 297 298 |
|
verify
verify() -> None
Verify the correctness of the Region.
Raises:
Type | Description |
---|---|
ValidationError | If the Region is not correct. |
Source code in src/kirin/ir/nodes/region.py
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 |
|
verify_type
verify_type() -> None
verify the type of the node.
Source code in src/kirin/ir/nodes/region.py
339 340 341 |
|
walk
walk(
*, reverse: bool = False, region_first: bool = False
) -> Iterator[Statement]
Traversal the Statements of Blocks in the Region.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reverse | bool | If walk in the reversed manner. Defaults to False. | False |
region_first | bool | If the walk should go through the Statement first or the Region of a Statement first. Defaults to False. | False |
Yields:
Type | Description |
---|---|
Statement | Iterator[Statement]: An iterator that yield Statements of Blocks in the Region, in the specified order. |
Source code in src/kirin/ir/nodes/region.py
276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
RegionBlocks dataclass
RegionBlocks(node: NodeType, field: FieldType)
Bases: MutableSequenceView[list[Block], 'Region', Block]
A View object that contains a list of Blocks of a Region.
Description
This is a proxy object that provide safe API to manipulate the Blocks of a Region.
__setitem__
__setitem__(
idx: int | slice,
block_or_blocks: Block | Iterable[Block],
) -> None
Replace/Set the Blocks of the Region.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx | int | slice | The index or slice to replace the | required |
block_or_blocks | Block | Iterable[Block] | The Block or Blocks to replace the Blocks. | required |
Source code in src/kirin/ir/nodes/region.py
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
|
append
append(value: Block) -> None
Append a Block to the Region.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value | Block | The block to be appended. | required |
Source code in src/kirin/ir/nodes/region.py
74 75 76 77 78 79 80 81 82 |
|
insert
insert(idx: int, value: Block) -> None
Inserts a Block at the specified index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx | int | The index at which to insert the block. | required |
value | Block | The block to be inserted. | required |
Source code in src/kirin/ir/nodes/region.py
62 63 64 65 66 67 68 69 70 71 72 |
|