Skip to content

Commit

Permalink
Merge pull request #169 from esc/rename_to_numba_scfg
Browse files Browse the repository at this point in the history
Rename from `numba_rvsdg` to `numba_scfg`
  • Loading branch information
esc authored Feb 7, 2025
2 parents 611b612 + 40167cd commit c8c0d7a
Show file tree
Hide file tree
Showing 35 changed files with 105 additions and 99 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

- uses: actions/upload-artifact@v4
with:
path: ./wheelhouse/numba_rvsdg-*.whl
path: ./wheelhouse/numba_scfg-*.whl

build-sdist:
# Build a source package. This is actually easy.
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
run: make conda-install
- name: Lint code with pre-commit
run: make lint
- name: Install numba_rvsdg with pip
- name: Install numba_scfg with pip
run: make build
- name: Run pytest and print coverage Report
run: make test
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*.pyc
numba_rvsdg.egg-info
numba_scfg.egg-info
.pytest_cache
*__pycache__
.coverage
Expand Down
26 changes: 16 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
# numba-rvsdg
# numba-scfg

Numba compatible RVSDG (Regionalized Value State Dependence Graph) utilities.
Numba compatible SCFG (Structured Control Flow Graph) utilities.

## About

This repository contains Numba compatible utilities for working with RVSDGs
(Regionalized Value State Dependency Graphs). RVSDGs are a type of
Intermediary Representation (IR) suitable for regularizing Python bytecode
within Numba.
This repository contains Numba compatible utilities for working with SCFG
(Structured Control FLow Graphs). SCFGs are a type of Intermediary
Representation (IR) suitable for regularizing Python source and bytecode.

The code in this repository is an implementation of the CFG restructuring
algorithms in Bahmann 2015, specifically those from section 4.1 and 4.2: namely
"loop restructuring" and "branch restructuring". These are interesting for
Numba because they serve to clearly identify regions within the Python
bytecode.
Numba because they serve to clearly identify regions within the Python source
and bytecode.

Note: The project was previously known as `numba-rvsdg` and was renamed to
`numba-scfg` in early 2025. The original scope was to implement Regional Value
State Dependence Graphs (RVSDG), where SCFGs are necessary intermediary for the
transformation from Python to RVSDG. Over time, it became evident that the SCFG
transformations are important and reusable enough in their own right to warrant
their own package and so this package was renamed.


## Development

Expand All @@ -22,7 +29,7 @@ be:

```
$ make conda-env # setup conda environment
$ conda activate numba-rvsdg # activate it
$ conda activate numba-scfg # activate it
$ make conda-install # install dependencies
$ make # lint, build and test the project
```
Expand All @@ -33,7 +40,6 @@ development commands.

## References

* `Reismann2020` -- https://arxiv.org/pdf/1912.05036.pdf -- Describes the concept of RVSDGs
* `Bahmann2015` -- https://dl.acm.org/doi/pdf/10.1145/2693261 -- Describes the transformation
algorithms implemented

Expand Down
8 changes: 4 additions & 4 deletions conda-recipes/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set VERSION_SUFFIX = "" %} # debug version suffix, appended to the version

package:
name: numba-rvsdg
name: numba-scfg
# GIT_DESCRIBE_TAG may not be set
version: {{ "%s%s" % (environ.get('GIT_DESCRIBE_TAG', ''), VERSION_SUFFIX) }}

Expand Down Expand Up @@ -29,10 +29,10 @@ test:
requires:
- pytest
commands:
- pytest --pyargs numba_rvsdg
- pytest --pyargs numba_scfg

about:
summary: Numba Compatible RVSDG utilities
home: https://github.com/numba/numba-rvsdg
summary: Numba Compatible SCFG utilities
home: https://github.com/numba/numba-scfg
license: Simplified BSD License
license_file: LICENSE
10 changes: 5 additions & 5 deletions docs/source/reference/datastructures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@ Datastructures API Reference
BasicBlocks
===========

.. automodule:: numba_rvsdg.core.datastructures.basic_block
.. automodule:: numba_scfg.core.datastructures.basic_block
:members:

ByteFlow
========

.. automodule:: numba_rvsdg.core.datastructures.byte_flow
.. automodule:: numba_scfg.core.datastructures.byte_flow
:members:

FlowInfo
========

.. automodule:: numba_rvsdg.core.datastructures.flow_info
.. automodule:: numba_scfg.core.datastructures.flow_info
:members:

SCFG classes
============

.. automodule:: numba_rvsdg.core.datastructures.scfg
.. automodule:: numba_scfg.core.datastructures.scfg
:members:

AST Transforms
==============

.. automodule:: numba_rvsdg.core.datastructures.ast_transforms
.. automodule:: numba_scfg.core.datastructures.ast_transforms
:members:
2 changes: 1 addition & 1 deletion docs/source/reference/rendering.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Rendering API Reference
=======================

.. automodule:: numba_rvsdg.rendering.rendering
.. automodule:: numba_scfg.rendering.rendering
:members:
4 changes: 2 additions & 2 deletions docs/source/reference/transformations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Graph Transformation API Reference
==================================

.. automodule:: numba_rvsdg.core.transformations
:members:
.. automodule:: numba_scfg.core.transformations
:members:
4 changes: 2 additions & 2 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ build:
test:
# Activate using the sys.monitoring implementation of coverage.
# Needs at least coverage veraion 7.4.0 to work.
COVERAGE_CORE=sysmon coverage run -m pytest --pyargs numba_rvsdg
COVERAGE_CORE=sysmon coverage run -m pytest --pyargs numba_scfg
coverage report
lint:
pre-commit run --verbose --all-files
docs:
cd docs && make html
conda-env:
conda create -n numba-rvsdg
conda create -n numba-scfg
conda-install:
conda install python=3.12 python-graphviz pyyaml pytest sphinx sphinx_rtd_theme coverage pre-commit
clean:
Expand Down
4 changes: 2 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ show_error_context = True
namespace_packages = True
strict = True
files =
numba_rvsdg
numba_scfg
exclude =
numba_rvsdg/tests|conf.py
numba_scfg/tests|conf.py
4 changes: 0 additions & 4 deletions numba_rvsdg/__init__.py

This file was deleted.

4 changes: 4 additions & 0 deletions numba_scfg/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from numba_scfg.core.datastructures.ast_transforms import ( # noqa
AST2SCFG,
SCFG2AST,
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from dataclasses import dataclass
from collections import defaultdict

from numba_rvsdg.core.datastructures.scfg import SCFG
from numba_rvsdg.core.datastructures.basic_block import (
from numba_scfg.core.datastructures.scfg import SCFG
from numba_scfg.core.datastructures.basic_block import (
PythonASTBlock,
RegionBlock,
SyntheticHead,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Tuple, Dict, List, Optional
from dataclasses import dataclass, replace, field

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


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
from dataclasses import dataclass
from typing import Callable

from numba_rvsdg.core.datastructures.scfg import SCFG
from numba_rvsdg.core.datastructures.flow_info import FlowInfo
from numba_rvsdg.core.utils import _logger, _LogWrap
from numba_scfg.core.datastructures.scfg import SCFG
from numba_scfg.core.datastructures.flow_info import FlowInfo
from numba_scfg.core.utils import _logger, _LogWrap


@dataclass(frozen=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import Set, Tuple, Dict, Sequence, Optional
from dataclasses import dataclass, field

from numba_rvsdg.core.datastructures.basic_block import PythonBytecodeBlock
from numba_rvsdg.core.datastructures import block_names
from numba_rvsdg.core.datastructures.scfg import SCFG
from numba_rvsdg.core.utils import (
from numba_scfg.core.datastructures.basic_block import PythonBytecodeBlock
from numba_scfg.core.datastructures import block_names
from numba_scfg.core.datastructures.scfg import SCFG
from numba_scfg.core.utils import (
is_conditional_jump,
_next_inst_offset,
is_unconditional_jump,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from dataclasses import dataclass, field
from collections import deque

from numba_rvsdg.core.datastructures.basic_block import (
from numba_scfg.core.datastructures.basic_block import (
BasicBlock,
SyntheticBlock,
SyntheticAssignment,
Expand All @@ -31,7 +31,7 @@
SyntheticBranch,
block_type_names,
)
from numba_rvsdg.core.datastructures.block_names import (
from numba_scfg.core.datastructures.block_names import (
block_types,
SYNTH_TAIL,
SYNTH_EXIT,
Expand Down Expand Up @@ -329,7 +329,7 @@ def compute_scc(self) -> List[Set[str]]:
This method of SCFG computes the strongly connected components of
the graph using Tarjan's algorithm. The implementation is at the
scc function from the numba_rvsdg.networkx_vendored.scc module.
scc function from the numba_scfg.networkx_vendored.scc module.
It returns a list of sets, where each set represents an SCC in
the graph. SCCs are useful for detecting loops in the graph.
Expand All @@ -338,7 +338,7 @@ def compute_scc(self) -> List[Set[str]]:
components: List[Set[str]]
A list of sets of strongly connected components/BasicBlocks.
"""
from numba_rvsdg.networkx_vendored.scc import scc
from numba_scfg.networkx_vendored.scc import scc

class GraphWrap:
def __init__(self, graph: Mapping[str, BasicBlock]) -> None:
Expand Down Expand Up @@ -563,7 +563,7 @@ def insert_SyntheticExit(
See also
--------
numba_rvsdg.core.datastructures.scfg.SCFG.insert_block
numba_scfg.core.datastructures.scfg.SCFG.insert_block
"""
self.insert_block(new_name, predecessors, successors, SyntheticExit)

Expand All @@ -578,7 +578,7 @@ def insert_SyntheticTail(
See also
--------
numba_rvsdg.core.datastructures.scfg.SCFG.insert_block
numba_scfg.core.datastructures.scfg.SCFG.insert_block
"""
self.insert_block(new_name, predecessors, successors, SyntheticTail)

Expand All @@ -593,7 +593,7 @@ def insert_SyntheticReturn(
See also
--------
numba_rvsdg.core.datastructures.scfg.SCFG.insert_block
numba_scfg.core.datastructures.scfg.SCFG.insert_block
"""
self.insert_block(new_name, predecessors, successors, SyntheticReturn)

Expand All @@ -608,7 +608,7 @@ def insert_SyntheticFill(
See also
--------
numba_rvsdg.core.datastructures.scfg.SCFG.insert_block
numba_scfg.core.datastructures.scfg.SCFG.insert_block
"""
self.insert_block(new_name, predecessors, successors, SyntheticFill)

Expand All @@ -621,7 +621,7 @@ def insert_block_and_control_blocks(
See also
--------
numba_rvsdg.core.datastructures.scfg.SCFG.insert_block
numba_scfg.core.datastructures.scfg.SCFG.insert_block
"""
# TODO: needs a diagram and documentaion
# name of the variable for this branching assignment
Expand Down Expand Up @@ -707,7 +707,7 @@ def restructure_loop(self) -> None:
"""
# Avoid cyclic imports
from numba_rvsdg.core.transformations import restructure_loop
from numba_scfg.core.transformations import restructure_loop

restructure_loop(self.region)
for region in self.iter_subregions():
Expand All @@ -723,7 +723,7 @@ def restructure_branch(self) -> None:
"""
# Avoid cyclic imports
from numba_rvsdg.core.transformations import restructure_branch
from numba_scfg.core.transformations import restructure_branch

restructure_branch(self.region)
for region in self.iter_subregions():
Expand Down Expand Up @@ -813,7 +813,7 @@ def view(self, name: Optional[str] = None) -> None:
name: str
Name to be given to the external graphviz generated PDF file.
"""
from numba_rvsdg.rendering.rendering import SCFGRenderer
from numba_scfg.rendering.rendering import SCFGRenderer

SCFGRenderer(self).view(name)

Expand Down Expand Up @@ -849,7 +849,7 @@ def from_yaml(yaml_string: str) -> "Tuple[SCFG, Dict[str, str]]":
See also
--------
numba_rvsdg.core.datastructures.scfg.SCFGIO.from_yaml()
numba_scfg.core.datastructures.scfg.SCFGIO.from_yaml()
"""
return SCFGIO.from_yaml(yaml_string)

Expand Down Expand Up @@ -884,7 +884,7 @@ def from_dict(
See also
--------
numba_rvsdg.core.datastructures.scfg.SCFGIO.from_dict()
numba_scfg.core.datastructures.scfg.SCFGIO.from_dict()
"""
return SCFGIO.from_dict(graph_dict)

Expand All @@ -906,7 +906,7 @@ def to_yaml(self) -> str:
See also
--------
numba_rvsdg.core.datastructures.scfg.SCFGIO.to_yaml()
numba_scfg.core.datastructures.scfg.SCFGIO.to_yaml()
"""
return SCFGIO.to_yaml(self)

Expand All @@ -928,7 +928,7 @@ def to_dict(self) -> Dict[str, Dict[str, Any]]:
See also
--------
numba_rvsdg.core.datastructures.scfg.SCFGIO.to_dict()
numba_scfg.core.datastructures.scfg.SCFGIO.to_dict()
"""
return SCFGIO.to_dict(self)

Expand Down
Loading

0 comments on commit c8c0d7a

Please sign in to comment.