diff options
| author | Dibyendu Majumdar <dibyendumajumdar@users.noreply.github.com> | 2024-05-02 22:08:06 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-02 14:08:06 -0700 |
| commit | 0caf37adc5f8c1600f13d80aaf77361f407c9694 (patch) | |
| tree | 30498744a348cbefb727d680b13793fdd10463ca /chapter06 | |
| parent | e31c37890a86aedfb209cf543baf05b1b60a27d2 (diff) | |
| download | Simple-0caf37adc5f8c1600f13d80aaf77361f407c9694.tar.gz Simple-0caf37adc5f8c1600f13d80aaf77361f407c9694.zip | |
Documentation updates (#76)
* More clearly explain why we do not have an AST in the implementation
* Improve the description of type lattice.
Cross reference to future chapters.
* Minor update
* Add lattice visual
Revise the text describing meet.
* minor update
* Add a lattice visual to the text
* Update the lattice visual.
Add description of the new edges in the SoN graph
Diffstat (limited to 'chapter06')
| -rw-r--r-- | chapter06/README.md | 31 | ||||
| -rw-r--r-- | chapter06/docs/build-graphs.sh | 2 | ||||
| -rw-r--r-- | chapter06/docs/lattice.gv | 64 | ||||
| -rw-r--r-- | chapter06/docs/lattice.svg | 206 |
4 files changed, 290 insertions, 13 deletions
diff --git a/chapter06/README.md b/chapter06/README.md index d3fe6ed9..6f7f3baa 100644 --- a/chapter06/README.md +++ b/chapter06/README.md @@ -4,11 +4,11 @@ In this chapter we do not add new language features. Our goal is to add peephole ## Type System Revision -We now need to extend the type system to introduce another lattice structure, in addition to the Integer lattice. -As before we denote "top" by T and "bottom" by ⊥. +We now need to extend the type system to introduce another lattice structure, in addition to the Integer sub-lattice. +As before we denote "Top" by T and "Bottom" by ⊥. -* "ctrl" represents a live control, whereas "~ctrl" represents a dead control. -* "INT" refers to the integer type. +* "Ctrl" represents a live control, whereas "~Ctrl" represents a dead control. +* "INT" refers to an integer value, note that integer values have their own sub-lattice. | | ⊥ | Ctrl | ~Ctrl | T | INT | |-------|---|------|-------|-------|-----| @@ -17,11 +17,16 @@ As before we denote "top" by T and "bottom" by ⊥. | ~Ctrl | ⊥ | Ctrl | ~Ctrl | ~Ctrl | ⊥ | | ⊥ | ⊥ | ⊥ | ⊥ | ⊥ | ⊥ | -* "top" meets any type is that type, -* "bottom" meets any type is "bottom", -* "top", "bottom", "ctrl", "~ctrl" are classed as simple types, -* "ctrl" meets "~ctrl" is "ctrl" -* Unless covered above, a simple type meets non-simple results in "bottom" +* "Top" meets any type is that type, +* "Bottom" meets any type is "Bottom", +* "Top", "Bottom", "Ctrl", "~Ctrl" are classed as simple types, +* "Ctrl" meets "~Ctrl" is "Ctrl" +* Unless covered above, a simple type meets non-simple results in "Bottom" + +The entire revised Lattice is shown below: + + + ## Peephole of `if` @@ -33,7 +38,7 @@ As before we denote "top" by T and "bottom" by ⊥. * When we peephole an `If` node we test if the predicate is a constant. If so, then one branch or the other dead, depending on if the constant is `0` or not. * When we add the `Proj` nodes, in this scenario, we already know one of the projections is dead. The peephole of the - relevant `Proj` node replaces the `Proj` with a `Constant` of type "~ctrl" indicating dead control. + relevant `Proj` node replaces the `Proj` with a `Constant` of type "~Ctrl" indicating dead control. * At this point our dead code elimination would kill the `If` node since it has no uses - but we cannot do that because we need to continue the parse. The important observation is that *we __can__ kill the `If` node after __both__ @@ -41,11 +46,11 @@ As before we denote "top" by T and "bottom" by ⊥. only see the `Proj` nodes. * To ensure this, we add a dummy user to `If` before creating the first `Proj` and remove it immediately after, allowing the second `Proj` to trigger a dead code elimination of the `If`. -* The live `Proj` gets replaced by the parent of `If`, whereas the dead `Proj` gets replaced by "~ctrl". +* The live `Proj` gets replaced by the parent of `If`, whereas the dead `Proj` gets replaced by "~Ctrl". * The parsing then continues as normal. * The other changes are when we reach the merge point with a dead control. * Again keeping with our strategy we merge as normal, including creating `Phi` nodes. -* The `Region` may have have one of its inputs as "~ctrl". This will be seen +* The `Region` may have have one of its inputs as "~Ctrl". This will be seen by the `Phi` which then optimizes itself. If the `Phi` has just one live input, the `Phi` peephole replaces itself with the remaining input. * Finally, at the end, when the `Region` node is peepholed, we see that it has only one live input and no Phi uses @@ -60,7 +65,7 @@ deleted. Conversely, we cannot collapse a Region until it has no dependent `Phi`s. When processing `If` we do not remove control inputs to a `Region`, instead the -dead control input is simply set to `Constant(~ctrl)`. The peephole logic in +dead control input is simply set to `Constant(~Ctrl)`. The peephole logic in a `Phi` notices this and replaces itself with the live input. ## Discussion diff --git a/chapter06/docs/build-graphs.sh b/chapter06/docs/build-graphs.sh index 5238dbfc..44d2de3a 100644 --- a/chapter06/docs/build-graphs.sh +++ b/chapter06/docs/build-graphs.sh @@ -9,3 +9,5 @@ dot -Tsvg 06-graph3-false.gv > 06-graph3-false.svg dot -Tsvg 06-graph4-nonconst.gv > 06-graph4-nonconst.svg dot -Tsvg 06-graph4-true.gv > 06-graph4-true.svg dot -Tsvg 06-graph4-arg2.gv > 06-graph4-arg2.svg +dot -Tsvg lattice.gv > lattice.svg + diff --git a/chapter06/docs/lattice.gv b/chapter06/docs/lattice.gv new file mode 100644 index 00000000..2cf27452 --- /dev/null +++ b/chapter06/docs/lattice.gv @@ -0,0 +1,64 @@ +digraph Lattice { + // Define nodes + splines=false; + node [shape=circle, style=filled, fillcolor=lightblue]; + nodesep=0.6; + + TOP [label="⊤"]; + BOT [label="⊥"]; + + XCTRL [label="~Ctrl"]; + CTRL [label="Ctrl"]; + + INT_TOP [label="IntTop"]; + INT_BOT [label="IntBot"]; + + INT_MIN [label="-n"]; + INT_MINDOTS [label="..." shape=none style=none]; + INT_MINUS [label="-1"]; + INT_ZERO [label="0"]; + INT_PLUS [label="1"]; + INT_MAXDOTS [label="..." shape=none style=none]; + INT_MAX [label="+n"]; + + TUPLE [label="TUPLE"]; + + // Define edges + edge [arrowhead=none]; + + TOP -> INT_TOP; + INT_TOP -> INT_MIN; + INT_TOP -> INT_MINDOTS; + INT_TOP -> INT_MINUS; + INT_TOP -> INT_ZERO; + INT_TOP -> INT_PLUS; + INT_TOP -> INT_MAXDOTS; + INT_TOP -> INT_MAX; + INT_MIN -> INT_BOT; + INT_MINDOTS -> INT_BOT; + INT_MINUS -> INT_BOT; + INT_ZERO -> INT_BOT; + INT_PLUS -> INT_BOT; + INT_MAXDOTS -> INT_BOT; + INT_MAX -> INT_BOT; + INT_BOT -> BOT; + + INT_MIN -> INT_MINDOTS -> INT_MINUS -> INT_ZERO -> INT_PLUS -> INT_MAXDOTS -> INT_MAX [style=invis]; + + TOP -> TUPLE; + TUPLE -> BOT; + + TOP -> XCTRL; + XCTRL -> CTRL; + CTRL -> BOT; + + // Additional customization + {rank=same; TOP} + {rank=same; INT_TOP; XCTRL} + {rank=same; INT_MIN; INT_MINDOTS; + INT_MINUS; INT_ZERO; + INT_PLUS; INT_MAXDOTS; + INT_MAX; TUPLE} + {rank=same; INT_BOT; CTRL} + {rank=same; BOT;} +}
\ No newline at end of file diff --git a/chapter06/docs/lattice.svg b/chapter06/docs/lattice.svg new file mode 100644 index 00000000..713b54c1 --- /dev/null +++ b/chapter06/docs/lattice.svg @@ -0,0 +1,206 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" + "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<!-- Generated by graphviz version 2.43.0 (0) + --> +<!-- Title: Lattice Pages: 1 --> +<svg width="702pt" height="478pt" + viewBox="0.00 0.00 702.04 478.27" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> +<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 474.27)"> +<title>Lattice</title> +<polygon fill="white" stroke="transparent" points="-4,4 -4,-474.27 698.04,-474.27 698.04,4 -4,4"/> +<!-- TOP --> +<g id="node1" class="node"> +<title>TOP</title> +<ellipse fill="lightblue" stroke="black" cx="277.5" cy="-450.77" rx="19.5" ry="19.5"/> +<text text-anchor="middle" x="277.5" y="-447.07" font-family="Times,serif" font-size="14.00">⊤</text> +</g> +<!-- XCTRL --> +<g id="node3" class="node"> +<title>XCTRL</title> +<ellipse fill="lightblue" stroke="black" cx="46.5" cy="-354.98" rx="36.29" ry="36.29"/> +<text text-anchor="middle" x="46.5" y="-351.28" font-family="Times,serif" font-size="14.00">~Ctrl</text> +</g> +<!-- TOP->XCTRL --> +<g id="edge25" class="edge"> +<title>TOP->XCTRL</title> +<path fill="none" stroke="black" d="M259.76,-442.57C221.3,-426.95 129.74,-389.78 80.01,-369.59"/> +</g> +<!-- INT_TOP --> +<g id="node5" class="node"> +<title>INT_TOP</title> +<ellipse fill="lightblue" stroke="black" cx="277.5" cy="-354.98" rx="40.09" ry="40.09"/> +<text text-anchor="middle" x="277.5" y="-351.28" font-family="Times,serif" font-size="14.00">IntTop</text> +</g> +<!-- TOP->INT_TOP --> +<g id="edge1" class="edge"> +<title>TOP->INT_TOP</title> +<path fill="none" stroke="black" d="M277.5,-431.24C277.5,-420.99 277.5,-407.84 277.5,-395.42"/> +</g> +<!-- TUPLE --> +<g id="node14" class="node"> +<title>TUPLE</title> +<ellipse fill="lightblue" stroke="black" cx="650.5" cy="-235.14" rx="43.59" ry="43.59"/> +<text text-anchor="middle" x="650.5" y="-231.44" font-family="Times,serif" font-size="14.00">TUPLE</text> +</g> +<!-- TOP->TUPLE --> +<g id="edge23" class="edge"> +<title>TOP->TUPLE</title> +<path fill="none" stroke="black" d="M294.49,-440.95C350.93,-408.32 533.03,-303.05 612.65,-257.02"/> +</g> +<!-- BOT --> +<g id="node2" class="node"> +<title>BOT</title> +<ellipse fill="lightblue" stroke="black" cx="277.5" cy="-19.5" rx="19.5" ry="19.5"/> +<text text-anchor="middle" x="277.5" y="-15.8" font-family="Times,serif" font-size="14.00">⊥</text> +</g> +<!-- CTRL --> +<g id="node4" class="node"> +<title>CTRL</title> +<ellipse fill="lightblue" stroke="black" cx="50.5" cy="-115.29" rx="28.7" ry="28.7"/> +<text text-anchor="middle" x="50.5" y="-111.59" font-family="Times,serif" font-size="14.00">Ctrl</text> +</g> +<!-- XCTRL->CTRL --> +<g id="edge26" class="edge"> +<title>XCTRL->CTRL</title> +<path fill="none" stroke="black" d="M47.11,-318.58C47.9,-270.77 49.29,-187.82 50.02,-144.12"/> +</g> +<!-- CTRL->BOT --> +<g id="edge27" class="edge"> +<title>CTRL->BOT</title> +<path fill="none" stroke="black" d="M76.98,-103.35C123.76,-84.02 219.83,-44.32 259.63,-27.88"/> +</g> +<!-- INT_MIN --> +<g id="node7" class="node"> +<title>INT_MIN</title> +<ellipse fill="lightblue" stroke="black" cx="19.5" cy="-235.14" rx="19.5" ry="19.5"/> +<text text-anchor="middle" x="19.5" y="-231.44" font-family="Times,serif" font-size="14.00">-n</text> +</g> +<!-- INT_TOP->INT_MIN --> +<g id="edge2" class="edge"> +<title>INT_TOP->INT_MIN</title> +<path fill="none" stroke="black" d="M241.08,-337.34C184.83,-311.65 78.92,-263.28 37.12,-244.18"/> +</g> +<!-- INT_MINDOTS --> +<g id="node8" class="node"> +<title>INT_MINDOTS</title> +<text text-anchor="middle" x="108.5" y="-231.44" font-family="Times,serif" font-size="14.00">...</text> +</g> +<!-- INT_TOP->INT_MINDOTS --> +<g id="edge3" class="edge"> +<title>INT_TOP->INT_MINDOTS</title> +<path fill="none" stroke="black" d="M244.91,-331.26C212.21,-308.45 162.56,-273.83 133.04,-253.25"/> +</g> +<!-- INT_MINUS --> +<g id="node9" class="node"> +<title>INT_MINUS</title> +<ellipse fill="lightblue" stroke="black" cx="197.5" cy="-235.14" rx="19.5" ry="19.5"/> +<text text-anchor="middle" x="197.5" y="-231.44" font-family="Times,serif" font-size="14.00">-1</text> +</g> +<!-- INT_TOP->INT_MINUS --> +<g id="edge4" class="edge"> +<title>INT_TOP->INT_MINUS</title> +<path fill="none" stroke="black" d="M255.21,-321.15C239.86,-298.54 220.15,-269.51 208.19,-251.89"/> +</g> +<!-- INT_ZERO --> +<g id="node10" class="node"> +<title>INT_ZERO</title> +<ellipse fill="lightblue" stroke="black" cx="277.5" cy="-235.14" rx="18" ry="18"/> +<text text-anchor="middle" x="277.5" y="-231.44" font-family="Times,serif" font-size="14.00">0</text> +</g> +<!-- INT_TOP->INT_ZERO --> +<g id="edge5" class="edge"> +<title>INT_TOP->INT_ZERO</title> +<path fill="none" stroke="black" d="M277.5,-314.41C277.5,-293.68 277.5,-269.36 277.5,-253.39"/> +</g> +<!-- INT_PLUS --> +<g id="node11" class="node"> +<title>INT_PLUS</title> +<ellipse fill="lightblue" stroke="black" cx="356.5" cy="-235.14" rx="18" ry="18"/> +<text text-anchor="middle" x="356.5" y="-231.44" font-family="Times,serif" font-size="14.00">1</text> +</g> +<!-- INT_TOP->INT_PLUS --> +<g id="edge6" class="edge"> +<title>INT_TOP->INT_PLUS</title> +<path fill="none" stroke="black" d="M299.5,-321.15C315.03,-298 335.07,-268.1 346.78,-250.63"/> +</g> +<!-- INT_MAXDOTS --> +<g id="node12" class="node"> +<title>INT_MAXDOTS</title> +<text text-anchor="middle" x="444.5" y="-231.44" font-family="Times,serif" font-size="14.00">...</text> +</g> +<!-- INT_TOP->INT_MAXDOTS --> +<g id="edge7" class="edge"> +<title>INT_TOP->INT_MAXDOTS</title> +<path fill="none" stroke="black" d="M310.09,-330.98C342.46,-308.14 391.33,-273.65 420.37,-253.16"/> +</g> +<!-- INT_MAX --> +<g id="node13" class="node"> +<title>INT_MAX</title> +<ellipse fill="lightblue" stroke="black" cx="539.5" cy="-235.14" rx="24.9" ry="24.9"/> +<text text-anchor="middle" x="539.5" y="-231.44" font-family="Times,serif" font-size="14.00">+n</text> +</g> +<!-- INT_TOP->INT_MAX --> +<g id="edge8" class="edge"> +<title>INT_TOP->INT_MAX</title> +<path fill="none" stroke="black" d="M313.93,-337.59C369.05,-312.8 471.99,-266.5 517.22,-246.16"/> +</g> +<!-- INT_BOT --> +<g id="node6" class="node"> +<title>INT_BOT</title> +<ellipse fill="lightblue" stroke="black" cx="277.5" cy="-115.29" rx="40.09" ry="40.09"/> +<text text-anchor="middle" x="277.5" y="-111.59" font-family="Times,serif" font-size="14.00">IntBot</text> +</g> +<!-- INT_BOT->BOT --> +<g id="edge16" class="edge"> +<title>INT_BOT->BOT</title> +<path fill="none" stroke="black" d="M277.5,-74.79C277.5,-62.37 277.5,-49.25 277.5,-39.01"/> +</g> +<!-- INT_MIN->INT_BOT --> +<g id="edge9" class="edge"> +<title>INT_MIN->INT_BOT</title> +<path fill="none" stroke="black" d="M37.23,-226.04C79.13,-206.9 184.92,-158.58 241.11,-132.91"/> +</g> +<!-- INT_MIN->INT_MINDOTS --> +<!-- INT_MINDOTS->INT_BOT --> +<g id="edge10" class="edge"> +<title>INT_MINDOTS->INT_BOT</title> +<path fill="none" stroke="black" d="M133.07,-217C162.55,-196.45 212.07,-161.91 244.77,-139.11"/> +</g> +<!-- INT_MINDOTS->INT_MINUS --> +<!-- INT_MINUS->INT_BOT --> +<g id="edge11" class="edge"> +<title>INT_MINUS->INT_BOT</title> +<path fill="none" stroke="black" d="M208.29,-218.24C220.23,-200.65 239.81,-171.81 255.1,-149.29"/> +</g> +<!-- INT_MINUS->INT_ZERO --> +<!-- INT_ZERO->INT_BOT --> +<g id="edge12" class="edge"> +<title>INT_ZERO->INT_BOT</title> +<path fill="none" stroke="black" d="M277.5,-217C277.5,-201.04 277.5,-176.66 277.5,-155.88"/> +</g> +<!-- INT_ZERO->INT_PLUS --> +<!-- INT_PLUS->INT_BOT --> +<g id="edge13" class="edge"> +<title>INT_PLUS->INT_BOT</title> +<path fill="none" stroke="black" d="M346.81,-219.69C335.11,-202.23 315.06,-172.33 299.53,-149.16"/> +</g> +<!-- INT_PLUS->INT_MAXDOTS --> +<!-- INT_MAXDOTS->INT_BOT --> +<g id="edge14" class="edge"> +<title>INT_MAXDOTS->INT_BOT</title> +<path fill="none" stroke="black" d="M420.22,-217C391.18,-196.51 342.45,-162.13 310.14,-139.33"/> +</g> +<!-- INT_MAXDOTS->INT_MAX --> +<!-- INT_MAX->INT_BOT --> +<g id="edge15" class="edge"> +<title>INT_MAX->INT_BOT</title> +<path fill="none" stroke="black" d="M517.16,-224.09C471.99,-203.77 369.42,-157.64 314.25,-132.82"/> +</g> +<!-- TUPLE->BOT --> +<g id="edge24" class="edge"> +<title>TUPLE->BOT</title> +<path fill="none" stroke="black" d="M612.68,-213.27C533.04,-167.23 350.75,-61.85 294.41,-29.27"/> +</g> +</g> +</svg> |
