Skip to content

Commit

Permalink
Minor formatting changes to "Detecting Loops"
Browse files Browse the repository at this point in the history
  • Loading branch information
artagnon committed Jul 17, 2016
1 parent 6c09d6e commit d2579f4
Show file tree
Hide file tree
Showing 12 changed files with 18 additions and 26 deletions.
30 changes: 16 additions & 14 deletions _posts/2016-07-16-detecting-loops.md
Expand Up @@ -55,26 +55,28 @@ Let's call the first number "DFS number", and the second number "topo number",
to indicate that this is the order that topological sort would have produced, in
the absence of backedges (topological sort is meaningless when there are loops).

First pass: number everything.
**First pass**: do the dfs, and number everything.

Second pass: find the backedge. When
**Second pass**: find the backedge. When
`start_time[destination] < start_time[source]` and
`end_time[destination] > end_time[source]`, we have a
backedge from source to destination.

Third pass: find all the nodes in the loop. Here, we walk backwards from the
**Third pass**: find all the nodes in the loop. Here, we walk backwards from the
source of the backedge until the loop header, and take everything that's "nested
within" the loop header start and end times. In the no loop case, there's
nothing to do since no backedges were detected. In the early exit case, "2/7"
and "4/5" are nested within "1/8", and we never reach "exit target" by walking
backward from the source of the backedge. In the multi-entry case, we correctly
detect that "1/8" is not nested within "2/7", while "3/6" and "4/5" are: when a
node reached via a backward walk doesn't nest within the header, the loop is
classified as "irreducible". In the cuddled loops case, everything nests within
"1/8", and the inner loop consists of "4/5", "3/6", and "2/7", all of which nest
within "2/7". Finally, the shared header case is again detected as two nested
loops: a loop is identified by a unique backedge, not a unique header. The
analysis is weak in that these cases are indistinguishable from normal nested
loops.
nothing to do since no backedges were detected. In the early exit case, `2/7`
and `4/5` are nested within `1/8`, and we never reach `exit target` by walking
backward from the source of the backedge.

In the multi-entry case, we correctly detect that `1/8` is not nested within
`2/7`, while `3/6` and `4/5` are: when a node reached via a backward walk
doesn't nest within the header, the loop is classified as *irreducible*.

In the cuddled loops case, everything nests within `1/8`, and the inner loop
consists of `4/5`, `3/6`, and `2/7`, all of which nest within `2/7`. Finally,
the shared header case is again detected as two nested loops: a loop is
identified by a unique backedge, not a unique header. The analysis is weak in
that these cases are indistinguishable from normal nested loops.

[^1]: Hat tip to Sanjoy for pointing out the fifth case.
1 change: 0 additions & 1 deletion _posts/cuddled-loops-dfs.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
"1/8"; /* root node */
"1/8" -> "2/7";
"2/7" -> "3/6";
Expand Down
1 change: 0 additions & 1 deletion _posts/cuddled-loops.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
headerA; /* root node */
headerA -> "bodyA or headerB";
"bodyA or headerB" -> "footerA or bodyB";
Expand Down
1 change: 0 additions & 1 deletion _posts/early-exit-dfs.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
"1/8"; /* root node */
"1/8" -> "2/7";
"2/7" -> "4/5";
Expand Down
1 change: 0 additions & 1 deletion _posts/early-exit.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
header; /* root node */
header -> body;
body -> footer;
Expand Down
1 change: 0 additions & 1 deletion _posts/multi-entry-dfs.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
"1/8"; /* root node */
"1/8" -> "4/5";
"1/8" -> "2/7";
Expand Down
1 change: 0 additions & 1 deletion _posts/multi-entry.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
"entry source"; /* root node */
"entry source" -> header;
"entry source" -> footer;
Expand Down
1 change: 0 additions & 1 deletion _posts/no-loops-dfs.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
"1/8" /* root node */
"1/8" -> "4/5";
"1/8" -> "2/7";
Expand Down
1 change: 0 additions & 1 deletion _posts/no-loops.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
node1 /* root node */
node1 -> node2;
node1 -> node3;
Expand Down
1 change: 0 additions & 1 deletion _posts/shared-header-dfs.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
"1/8" /* root node */
"1/8" -> "2/7";
"2/7" -> "3/6";
Expand Down
1 change: 0 additions & 1 deletion _posts/shared-header.gv
@@ -1,5 +1,4 @@
digraph {
size="5,10";
"shared header" /* root node */
"shared header" -> body;
body -> footerA;
Expand Down
4 changes: 2 additions & 2 deletions deploy.sh
@@ -1,8 +1,8 @@
#!/bin/bash

jekyll build
for filename in _posts/*.gv; do
basefilename=$(basename "${filename%.*}")
dot -Tpng <"$filename" >"assets/$basefilename.png"
done
done &&
jekyll build &&
rsync --progress -av _site/ artagnon_artagnon@ssh.phx.nearlyfreespeech.net:/home/public/

0 comments on commit d2579f4

Please sign in to comment.