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 /chapter04 | |
| 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 'chapter04')
| -rw-r--r-- | chapter04/README.md | 69 | ||||
| -rw-r--r-- | chapter04/docs/build-graphs.sh | 2 | ||||
| -rw-r--r-- | chapter04/docs/lattice.gv | 63 | ||||
| -rw-r--r-- | chapter04/docs/lattice.svg | 195 |
4 files changed, 293 insertions, 36 deletions
diff --git a/chapter04/README.md b/chapter04/README.md index f938f468..4ae4d432 100644 --- a/chapter04/README.md +++ b/chapter04/README.md @@ -19,22 +19,22 @@ Following are revised or new nodes |-----------|----------------|------------------------------------------------|-----------------------|----------------------------------------------------------------------------| | MultiNode | Abstract class | A node that has a tuple result | | A tuple | | Start | Control | Start of function, now a MultiNode | | A tuple with a ctrl token and an `arg` data node | -| Proj | ? | Projection nodes extract values from MultiNode | A MultiNode and index | Result is the extracted value from the input MultiNode at offset index | +| Proj | Data | Projection nodes extract values from MultiNode | A MultiNode and index | Result is the extracted value from the input MultiNode at offset index | | Bool | Data | Represents results of a comparison operator | Two data nodes | Result is a comparison, represented as integer value where 1=true, 0=false | | Not | Data | Logical not | One data node | Result converts 0 to 1 and vice versa | Below is our list of Nodes from [Chapter 3](../chapter03/README.md): -| Node Name | Type | Description | Inputs | Value | -|-----------|---------|------------------------------------|------------------------------------------------------------------|------------------------------| -| Return | Control | End of function | Predecessor control node, Data node value | Return value of the function | -| Constant | Data | Constants such as integer literals | None, however Start node is set as input to enable graph walking | Value of the constant | -| Add | Data | Add two values | Two data nodes, values are added, order not important | Result of the add operation | -| Sub | Data | Subtract a value from another | Two data nodes, values are subtracted, order matters | Result of the subtract | -| Mul | Data | Multiply two values | Two data nodes, values are multiplied, order not important | Result of the multiply | -| Div | Data | Divide a value by another | Two data nodes, values are divided, order matters | Result of the division | -| Minus | Data | Negate a value | One data node, value is negated | Result of the unary minus | -| Scope | ? | Represents scopes in the graph | All nodes that define variables | None | +| Node Name | Type | Description | Inputs | Value | +|-----------|--------------|------------------------------------|------------------------------------------------------------------|------------------------------| +| Return | Control | End of function | Predecessor control node, Data node value | Return value of the function | +| Constant | Data | Constants such as integer literals | None, however Start node is set as input to enable graph walking | Value of the constant | +| Add | Data | Add two values | Two data nodes, values are added, order not important | Result of the add operation | +| Sub | Data | Subtract a value from another | Two data nodes, values are subtracted, order matters | Result of the subtract | +| Mul | Data | Multiply two values | Two data nodes, values are multiplied, order not important | Result of the multiply | +| Div | Data | Divide a value by another | Two data nodes, values are divided, order matters | Result of the division | +| Minus | Data | Negate a value | One data node, value is negated | Result of the unary minus | +| Scope | Symbol Table | Represents scopes in the graph | All nodes that define variables | None | ## Projection Nodes @@ -51,13 +51,13 @@ Start node. ## Changes to Type System -In [Chapter 2](../chapter02/README.md) we introduced the Type System. Here is a summary of key points: +In [Chapter 2](../chapter02/README.md) we introduced the Type System. We annotate Nodes with Types. The Type annotation serves two purposes: -* it defines the set of operations allowed on the Node, and +* It defines the set of operations allowed on the Node, and * it defines the set of values the Node takes on. The type itself is identified by the Java class sub-typing relationship; all @@ -76,40 +76,37 @@ Type We mentioned in [Chapter 2](../chapter02/README.md) that the set of values associated with a Type at a specific Node can be conveniently represented as a "lattice". -Our lattice elements can be one of three types: +Our enhanced Lattice looks like this. -* the highest element is "top", denoted by T. -* The lowest is bottom, denoted by ⊥, -* All elements in the middle are constants. + -Assigning ⊥ means that the Node's value is known to be not a compile time -constant, whereas assigning T means that the Node's value may be some (as yet) -undetermined constant. The transition of the Node's type can occur from T to -some constant to ⊥. In this chapter we introduce the possibility of a program input variable named -`arg`; this variable is usually unknown so ⊥ . +`arg`; all we know about this variable is that it is some integer value, but we do not know whether it is a constant or not. To support the requirements for non-constant integer values, we enhance `TypeInteger` to -allow it to represent `Top` and `Bot` integer types in addition to the earlier constant value. +allow it to represent `IntTop` and `IntBot` integer types in addition to the earlier constant value. -Now that integer values may be constants or non-constants, we need to introduce the meet operator -in our lattice. The meet operator describes rules that define the resulting type when we combine +Now that integer values may be constants or non-constants, we need to introduce the "meet" operator +in our lattice. The `meet` operator describes rules that define the resulting type when we combine integer values. -| | ⊥ | Con1 | Con2 | T | -|------|---|------|------|------| -| ⊥ | ⊥ | ⊥ | ⊥ | ⊥ | -| Con1 | ⊥ | Con1 | ⊥ | Con1 | -| T | ⊥ | Con1 | Con2 | T | +| | IntBot | Con1 | Con2 | IntTop | +|--------|--------|--------|--------|--------| +| IntBot | IntBot | IntBot | IntBot | IntBot | +| Con1 | IntBot | Con1 | IntBot | Con1 | +| IntTop | IntBot | Con1 | Con2 | IntTop | +In the table above `Con1` and `Con2` represent two distinct integer values, and serve to explain the rules below. + +* The `meet` of `IntTop` with any integer constant is that constant. +* The `meet` of `IntBot` with any integer value is `IntBot`. +* The `meet` of any integer with itself is that integer. +* The `meet` of two unrelated integer constants is `IntBot`. + +Currently, all our integer valued nodes are either a constant or a `IntBot` integer type. +When we start optimizing loops, we will start seeing `IntTop` values. -The `meet` of `Top` with anything is that thing. -The `meet` of `Bot` with anything is `Bot`. -The `meet` of anything with itself is that thing. -The `meet` of two unrelated constants is `Bot`. -Currently, all our integer valued nodes are either a constant or a Bottom integer type. -When we start optimizing loops, we will start seeing Top values. ## `$ctrl` name binding diff --git a/chapter04/docs/build-graphs.sh b/chapter04/docs/build-graphs.sh new file mode 100644 index 00000000..d8038602 --- /dev/null +++ b/chapter04/docs/build-graphs.sh @@ -0,0 +1,2 @@ +dot -Tsvg lattice.gv > lattice.svg + diff --git a/chapter04/docs/lattice.gv b/chapter04/docs/lattice.gv new file mode 100644 index 00000000..2644448e --- /dev/null +++ b/chapter04/docs/lattice.gv @@ -0,0 +1,63 @@ +digraph Lattice { + // Define nodes + splines=false; + node [shape=circle, style=filled, fillcolor=lightblue]; + nodesep=0.6; + + TOP [label="⊤"]; + BOT [label="⊥"]; + + 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 -> CTRL; + CTRL -> BOT; + + + // Additional customization + {rank=same; TOP} + {rank=same; INT_TOP} + {rank=same; CTRL; INT_MIN; INT_MINDOTS; + INT_MINUS; INT_ZERO; + INT_PLUS; INT_MAXDOTS; + INT_MAX; TUPLE} + {rank=same; INT_BOT} + {rank=same; BOT;} +}
\ No newline at end of file diff --git a/chapter04/docs/lattice.svg b/chapter04/docs/lattice.svg new file mode 100644 index 00000000..0d403c20 --- /dev/null +++ b/chapter04/docs/lattice.svg @@ -0,0 +1,195 @@ +<?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="802pt" height="478pt" + viewBox="0.00 0.00 802.14 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 798.14,-474.27 798.14,4 -4,4"/> +<!-- TOP --> +<g id="node1" class="node"> +<title>TOP</title> +<ellipse fill="lightblue" stroke="black" cx="377.6" cy="-450.77" rx="19.5" ry="19.5"/> +<text text-anchor="middle" x="377.6" y="-447.07" font-family="Times,serif" font-size="14.00">⊤</text> +</g> +<!-- CTRL --> +<g id="node3" class="node"> +<title>CTRL</title> +<ellipse fill="lightblue" stroke="black" cx="28.6" cy="-235.14" rx="28.7" ry="28.7"/> +<text text-anchor="middle" x="28.6" y="-231.44" font-family="Times,serif" font-size="14.00">Ctrl</text> +</g> +<!-- TOP->CTRL --> +<g id="edge25" class="edge"> +<title>TOP->CTRL</title> +<path fill="none" stroke="black" d="M360.76,-440.37C304.12,-405.37 120.24,-291.76 53.28,-250.38"/> +</g> +<!-- INT_TOP --> +<g id="node4" class="node"> +<title>INT_TOP</title> +<ellipse fill="lightblue" stroke="black" cx="377.6" cy="-354.98" rx="40.09" ry="40.09"/> +<text text-anchor="middle" x="377.6" 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="M377.6,-431.24C377.6,-420.99 377.6,-407.84 377.6,-395.42"/> +</g> +<!-- TUPLE --> +<g id="node13" class="node"> +<title>TUPLE</title> +<ellipse fill="lightblue" stroke="black" cx="750.6" cy="-235.14" rx="43.59" ry="43.59"/> +<text text-anchor="middle" x="750.6" 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="M394.59,-440.95C451.03,-408.32 633.13,-303.05 712.75,-257.02"/> +</g> +<!-- BOT --> +<g id="node2" class="node"> +<title>BOT</title> +<ellipse fill="lightblue" stroke="black" cx="377.6" cy="-19.5" rx="19.5" ry="19.5"/> +<text text-anchor="middle" x="377.6" y="-15.8" font-family="Times,serif" font-size="14.00">⊥</text> +</g> +<!-- CTRL->BOT --> +<g id="edge26" class="edge"> +<title>CTRL->BOT</title> +<path fill="none" stroke="black" d="M53.14,-219.97C120.01,-178.65 304.22,-64.84 360.83,-29.86"/> +</g> +<!-- INT_MIN --> +<g id="node6" class="node"> +<title>INT_MIN</title> +<ellipse fill="lightblue" stroke="black" cx="119.6" cy="-235.14" rx="19.5" ry="19.5"/> +<text text-anchor="middle" x="119.6" 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="M341.18,-337.34C284.92,-311.65 179.02,-263.28 137.21,-244.18"/> +</g> +<!-- INT_MINDOTS --> +<g id="node7" class="node"> +<title>INT_MINDOTS</title> +<text text-anchor="middle" x="208.6" 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="M345.01,-331.26C312.3,-308.45 262.65,-273.83 233.14,-253.25"/> +</g> +<!-- INT_MINUS --> +<g id="node8" class="node"> +<title>INT_MINUS</title> +<ellipse fill="lightblue" stroke="black" cx="297.6" cy="-235.14" rx="19.5" ry="19.5"/> +<text text-anchor="middle" x="297.6" 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="M355.31,-321.15C339.96,-298.54 320.25,-269.51 308.29,-251.89"/> +</g> +<!-- INT_ZERO --> +<g id="node9" class="node"> +<title>INT_ZERO</title> +<ellipse fill="lightblue" stroke="black" cx="377.6" cy="-235.14" rx="18" ry="18"/> +<text text-anchor="middle" x="377.6" 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="M377.6,-314.41C377.6,-293.68 377.6,-269.36 377.6,-253.39"/> +</g> +<!-- INT_PLUS --> +<g id="node10" class="node"> +<title>INT_PLUS</title> +<ellipse fill="lightblue" stroke="black" cx="456.6" cy="-235.14" rx="18" ry="18"/> +<text text-anchor="middle" x="456.6" 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="M399.6,-321.15C415.13,-298 435.17,-268.1 446.88,-250.63"/> +</g> +<!-- INT_MAXDOTS --> +<g id="node11" class="node"> +<title>INT_MAXDOTS</title> +<text text-anchor="middle" x="544.6" 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="M410.19,-330.98C442.56,-308.14 491.43,-273.65 520.47,-253.16"/> +</g> +<!-- INT_MAX --> +<g id="node12" class="node"> +<title>INT_MAX</title> +<ellipse fill="lightblue" stroke="black" cx="639.6" cy="-235.14" rx="24.9" ry="24.9"/> +<text text-anchor="middle" x="639.6" 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="M414.03,-337.59C469.15,-312.8 572.09,-266.5 617.32,-246.16"/> +</g> +<!-- INT_BOT --> +<g id="node5" class="node"> +<title>INT_BOT</title> +<ellipse fill="lightblue" stroke="black" cx="377.6" cy="-115.29" rx="40.09" ry="40.09"/> +<text text-anchor="middle" x="377.6" 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="M377.6,-74.79C377.6,-62.37 377.6,-49.25 377.6,-39.01"/> +</g> +<!-- INT_MIN->INT_BOT --> +<g id="edge9" class="edge"> +<title>INT_MIN->INT_BOT</title> +<path fill="none" stroke="black" d="M137.33,-226.04C179.23,-206.9 285.02,-158.58 341.21,-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="M233.17,-217C262.65,-196.45 312.17,-161.91 344.87,-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="M308.39,-218.24C320.33,-200.65 339.91,-171.81 355.2,-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="M377.6,-217C377.6,-201.04 377.6,-176.66 377.6,-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="M446.91,-219.69C435.21,-202.23 415.16,-172.33 399.63,-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="M520.31,-217C491.28,-196.51 442.55,-162.13 410.24,-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="M617.26,-224.09C572.09,-203.77 469.52,-157.64 414.35,-132.82"/> +</g> +<!-- TUPLE->BOT --> +<g id="edge24" class="edge"> +<title>TUPLE->BOT</title> +<path fill="none" stroke="black" d="M712.78,-213.27C633.14,-167.23 450.85,-61.85 394.51,-29.27"/> +</g> +</g> +</svg> |
