upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/tools/cfg_structure.py
diff options
context:
space:
mode:
authorAyinaki <ayinakidev@gmail.com>2026-11-22 15:23:55 +0000
committerAyinaki <ayinakidev@gmail.com>2026-11-22 15:23:55 +0000
commit3e38c9837787c43b5c8a73e44932bb29b3243be8 (patch)
tree0677c41ee61366b4245a8303109880435644ab2f /tools/cfg_structure.py
parent89b047cd8fab50675a43d76722a6a8a881f55dc2 (diff)
rdna2spirv: bound structured nesting depth with the dispatch-loop form
spirv-val's structured-control-flow checking cost grows roughly with the cube of the nesting depth: over the 1.0.2.1 corpus the deepest block sits 118 constructs deep and about 85% of validation time is in modules nested 20 or deeper. cfg_structure.depth() measures the tree and a module deeper than MAX_STRUCTURED_DEPTH (16) is emitted in the existing flat dispatch-loop form instead, which emits the same blocks and only changes the routing. Depth 5-12 shows no gain, hence the bound at 16.
Diffstat (limited to 'tools/cfg_structure.py')
-rw-r--r--tools/cfg_structure.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/tools/cfg_structure.py b/tools/cfg_structure.py
index e8ef0a086..7b874efe1 100644
--- a/tools/cfg_structure.py
+++ b/tools/cfg_structure.py
@@ -143,6 +143,21 @@ def structure(succ):
143 143
144 144
145 145
146def depth(tree):
147 """Nesting depth of a tree from structure(): a block is depth 0 and each guard or loop adds one."""
148 best = 0
149 stack = [(tree, 0)]
150 while stack:
151 items, d = stack.pop()
152 for it in items:
153 if it[0] == "block":
154 best = max(best, d)
155 else:
156 best = max(best, d + 1)
157 stack.append((it[2], d + 1))
158 return best
159
160
146def _sccs(nodes, adj): 161def _sccs(nodes, adj):
147 """Iterative Tarjan's algorithm over `nodes` with adjacency `adj`; returns SCCs with >= 2 nodes.""" 162 """Iterative Tarjan's algorithm over `nodes` with adjacency `adj`; returns SCCs with >= 2 nodes."""
148 index, low, on_stack, stack, out = {}, {}, set(), [], [] 163 index, low, on_stack, stack, out = {}, {}, set(), [], []