Skip to content

refactor(graph): give natural-loop discovery one owner in graph.Loops - #347

Merged
siyul-park merged 2 commits into
mainfrom
refactor/graph-loops
Nov 19, 2026
Merged

siyul-park merged 2 commits into
mainfrom
refactor/graph-loops

Conversation

@siyul-park

Copy link
Copy Markdown
Owner

Summary

  • Headers → Body → Preheader was re-walked in five places: LICM, BCE, the bytecode emitter's layout, compile's scan, and analysis.Headers. graph.Loops(g, d) []Loop now returns each natural loop with its body and preheader (-1 when none), innermost first — the order LICM sorted into. It replaces the exported Headers, Body, Preheader (net −1 exported symbol).
  • LICM and BCE reached into each other's files (BCE's def-site index loops/site, LICM's inlet). Their shared loop machinery moves to transform/loop.go as nest.
  • DCE keeps its own index on purpose: it indexes only the reachable blocks it walks, which the shared index does not.
  • graph/loop_test.go is one TestLoops owner (acyclic, single, nested order, merged back edges, non-dominating back edge, preheader present, three no-preheader shapes).

Second of the pipeline structural cleanups (after #346).

Evidence

  • No golden or expected output changed in transform, compile, or arm64 tests.
  • make benchmark-diff base=4d26392 (interleaved, n=6): geomean +0.29%; no significant change on any jit row. The only significant rows are threaded or optimized kernels whose code this PR cannot reach (threaded handlers are untouched; optimized output is unchanged), so they read as machine noise.

Test plan

  • go test ./internal/graph ./analysis ./internal/ssa ./internal/transform ./internal/jit/... ./interp ./optimize
  • make check
  • git diff --check
  • grep -rn 'graph\.\(Headers\|Body\|Preheader\)' → none

🤖 Generated with Claude Code

Headers → Body → Preheader was re-walked by LICM, BCE, the bytecode
emitter, compile's scan, and analysis.Headers. graph.Loops now returns
each natural loop with its body and preheader, innermost first (the
order LICM sorted into), replacing the three exported walkers.

LICM and BCE reached into each other's files (BCE's def-site index,
LICM's inlet). Their shared loop machinery moves to transform/loop.go
as nest. DCE keeps its own index: it indexes only reachable blocks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1988871a-f8ba-4248-8a14-40ae51170230
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@siyul-park
siyul-park merged commit 5a3ef12 into main Nov 19, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant