Skip to content

Instantly share code, notes, and snippets.

@jcdickinson
Created January 30, 2024 23:02
Show Gist options
  • Save jcdickinson/955251e1a3e92d571fefe7f341bafbf5 to your computer and use it in GitHub Desktop.
Save jcdickinson/955251e1a3e92d571fefe7f341bafbf5 to your computer and use it in GitHub Desktop.
// Example
State {
x
cond
}
local a = state.x + 1
text a
if cond
a = state.x + 2
else
a = state.x + 1
text a
// SSA - Markers
_0 = state.x
_1 = state.cond
s0: local a1 = _0 + 1
s1: text a1
b0:
s2: a2 = _0 + 2
b1:
s3: a3 = _0 + 1
s4: br (_1, s2, s3)
s5: a4 = phi (s4, a2, a3)
s6: text a4
// To a graph
s6 -> a4
s5 -> s4, a2, a3
s4 -> _1, s2, s3
s3 -> _0
s2 -> _0
s1 -> a1, s0
s0 -> _0
a4 -> _1, a2, a3, s5
a3 -> _0
a2 -> _0
a1 -> _0
// Invert
// s6 -> a4
a4 -> s6
// s5 -> s4, a2, a3
s4 -> s5
a2 -> s5
a3 -> s5
// s4 -> _1, s2, s3
_1 -> s4
s2 -> s4
s3 -> s4
...
// Create graph from the above
_0
a1
s0
a2
s5
a3
s4
_1
a4
s6
s4
s5
s6
// Get all reachable/descendant statements from root nodes
_0 -> s0, s5, s4
_1 -> s6, s5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment