upleb.uk

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

summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorBloh09 <104168236+Bloh09@users.noreply.github.com>2026-11-22 18:25:27 -0800
committerBloh09 <104168236+Bloh09@users.noreply.github.com>2026-11-22 18:25:27 -0800
commita54ea0eebf1ad46c021a7b919963944b52e7d2fe (patch)
treeac9facdc6af4f7b267b22ee4eb49d5f850461751 /tools
parent03b09a086592a197db64d91655c6e65c30764d96 (diff)
wave64_emulate_opt: keep a folded EXECZ region's exits to the join, so a scalar branch there skips the rest
find_local_exec_folds built the region's sub-CFG from edges inside the region only. An s_cbranch_scc0/scc1 (or any branch) from inside the region straight to the join lost that edge, so cfg_structure.structure placed the next block without a %pc guard and emit_folded_region ran it on the exit path too. Edges to the join now go to an exit node that is dropped from the tree. Test and design.md row added. AI-assisted.
Diffstat (limited to 'tools')
-rw-r--r--tools/wave64_emulate_opt.py27
1 files changed, 25 insertions, 2 deletions
diff --git a/tools/wave64_emulate_opt.py b/tools/wave64_emulate_opt.py
index d3e4138f9..e14ef9bd3 100644
--- a/tools/wave64_emulate_opt.py
+++ b/tools/wave64_emulate_opt.py
@@ -652,6 +652,26 @@ def _map_tree_ids(tree, mapping):
652 return out 652 return out
653 653
654 654
655def _drop_tree_block(tree, b):
656 """Iterative copy of a cfg_structure tree without `("block", b)`, b being a sink with no successors: in
657 `structure` its only node is `("guard", b, [("block", b)])`, which is dropped whole."""
658 out = []
659 stack = [(tree, out)]
660 while stack:
661 src, dst = stack.pop()
662 for it in src:
663 if it[0] == "block":
664 if it[1] != b:
665 dst.append(it)
666 elif it[0] == "guard" and it[2] == [("block", b)]:
667 continue
668 else:
669 child = []
670 dst.append((it[0], it[1], child))
671 stack.append((it[2], child))
672 return out
673
674
655def _unwrap_known_pc_guards(tree, out_pcs, entry_pc=0): 675def _unwrap_known_pc_guards(tree, out_pcs, entry_pc=0):
656 """Unwrap `("guard", g, body)` nodes whenever abstract interpretation proves `%pc == g` on all incoming paths. 676 """Unwrap `("guard", g, body)` nodes whenever abstract interpretation proves `%pc == g` on all incoming paths.
657 677
@@ -872,11 +892,14 @@ def find_local_exec_folds(blocks, raw_edges, succ, lane_masks, scc_live, mask_wr
872 else: 892 else:
873 order = [run] + sorted(region - {run}) 893 order = [run] + sorted(region - {run})
874 idx_of = {u: i for i, u in enumerate(order)} 894 idx_of = {u: i for i, u in enumerate(order)}
875 sub_succ = [[idx_of[s] for s in succ[u] if s in idx_of] for u in order] 895 sub_end = len(order)
896 # An edge to `skip` (e.g. an s_cbranch_scc to the join) goes to an exit node `sub_end`, so the blocks
897 # after it in the region get a `%pc` guard; dropping the edge would run them on the exit path too.
898 sub_succ = [list(dict.fromkeys(idx_of.get(s, sub_end) for s in succ[u])) for u in order] + [[]]
876 sub_tree = cfg_structure.structure(sub_succ) 899 sub_tree = cfg_structure.structure(sub_succ)
877 if sub_tree is None: 900 if sub_tree is None:
878 continue 901 continue
879 sub_end = len(order) 902 sub_tree = _drop_tree_block(sub_tree, sub_end)
880 sub_out_pcs = {} 903 sub_out_pcs = {}
881 for i, u in enumerate(order): 904 for i, u in enumerate(order):
882 uedges = raw_edges[u] 905 uedges = raw_edges[u]