numba / numba-rvsdg

Numba compatible RVSDG (Regionalized Value State Dependence Graph) utilities.
https://numba-rvsdg.readthedocs.io/
BSD 2-Clause "Simplified" License
18 stars 7 forks source link

Added region hierarchy and unique naming reference for RegionBlocks in SCFGs #61

Closed kc611 closed 1 year ago

kc611 commented 1 year ago

As titled,

This PR makes the following major changes:

Note that currently RegionBlocks share jump targets with their corresponding exiting blocks. Hence any updates made to jump targets of a RegionBlock, need to be made recursively to their corresponding exiting blocks as well.

sklam commented 1 year ago

@kc611, I discovered a bug:

Screenshot 2023-06-01 at 4 11 30 PM

reproducer:


from numba_rvsdg.core.datastructures.byte_flow import ByteFlow
from numba_rvsdg.rendering.rendering import ByteFlowRenderer

def sum1d(s, e):
    c = 0
    for i in range(s, e):
        c += i
    return c

byteflow = ByteFlow.from_bytecode(sum1d.__code__)
bcmap = byteflow.scfg.bcmap_from_bytecode(byteflow.bc)
byteflow = byteflow.restructure()

bfr = ByteFlowRenderer()
bfr.bcmap_from_bytecode(byteflow.bc)
byteflow.scfg.view("scfg")
sklam commented 1 year ago

@kc611, is https://github.com/numba/numba-rvsdg/pull/61/commits/53291b85a0c0ff44093880825b5d1190e412c783 fixing https://github.com/numba/numba-rvsdg/pull/61#issuecomment-1572791281? Let's make sure we have test for it as well.

sklam commented 1 year ago

As of https://github.com/sklam/numba/commit/2c84e4b47cf49add64924cabdc2740ca9954617e, the numba rvsdg-frontend branch is fully working with this PR.

esc commented 1 year ago

I found a file with trailing whitespace:

Screen Shot 2023-06-14 at 12 10 45

Please double check all the files touched by this PR and remove any trailing whitespace, thank you.

kc611 commented 1 year ago

I've currently fixed the trailing whitespaces from the entire project using pre-commit from the experimental branch locally.

esc commented 1 year ago

@kc611 this is fine now thank you. As a last request, please include the following test:

from numba_rvsdg.rendering.rendering import render_func

def scc(G):
    preorder = {}
    lowlink = {}
    scc_found = set()
    scc_queue = []
    out = []
    i = 0  # Preorder counter
    for source in G:
        if source not in scc_found:
            queue = [source]
            while queue:
                v = queue[-1]
                if v not in preorder:
                    i = i + 1
                    preorder[v] = i
                done = True
                for w in G[v]:
                    if w not in preorder:
                        queue.append(w)
                        done = False
                        break
                if done:
                    lowlink[v] = preorder[v]
                    for w in G[v]:
                        if w not in scc_found:
                            if preorder[w] > preorder[v]:
                                lowlink[v] = min([lowlink[v], lowlink[w]])
                            else:
                                lowlink[v] = min([lowlink[v], preorder[w]])
                    queue.pop()
                    if lowlink[v] == preorder[v]:
                        scc = {v}
                        while scc_queue and preorder[scc_queue[-1]] > preorder[v]:
                            k = scc_queue.pop()
                            scc.add(k)
                        scc_found.update(scc)
                        out.append(scc)
                    else:
                        scc_queue.append(v)
    return out

render_func(scc)

And add it such that it behaves like the other test_fig tests. Just execution when run under pytest and rendering if run as a regular Python file.

esc commented 1 year ago

@kc611 thank you for the patch.