You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rework introduction to SSA-IR in dev docs (#49796)
Primary authorship credits for this go to Oscar Smith.
This reworks the introduction to the SSA-IR section of the
manual to give a brief introduction to SSA to prepare the
reader with a short example.
We also rework the Background and IR Node types sections.
Co-authored-by: Oscar Smith <[email protected]>
Copy file name to clipboardExpand all lines: doc/src/devdocs/ssair.md
+50-4Lines changed: 50 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,53 @@
1
1
# Julia SSA-form IR
2
2
3
+
Julia uses a static single assignment intermediate representation ([SSA IR](https://en.wikipedia.org/wiki/Static_single-assignment_form)) to perform optimization.
4
+
This IR is different from LLVM IR, and unique to Julia.
5
+
It allows for Julia specific optimizations.
6
+
7
+
1. Basic blocks (regions with no control flow) are explicitly annotated.
8
+
2. if/else and loops are turned into `goto` statements.
9
+
3. lines with multiple operations are split into multiple lines by introducing variables.
10
+
11
+
For example the following Julia code:
12
+
```julia
13
+
functionfoo(x)
14
+
y =sin(x)
15
+
if x >5.0
16
+
y = y +cos(x)
17
+
end
18
+
returnexp(2) + y
19
+
end
20
+
```
21
+
when called with a `Float64` argument is translated into:
2. The `if` statement is translated into `goto #3 if not %2` which goes to the 3rd basic block if `x>5` isn't met and otherwise goes to the second basic block.
49
+
3.`%2` is an SSA value introduced to represent `x > 5`.
50
+
3
51
## Background
4
52
5
53
Beginning in Julia 0.7, parts of the compiler use a new [SSA-form](https://en.wikipedia.org/wiki/Static_single_assignment_form)
@@ -11,11 +59,9 @@ linearized (i.e. turned into a form where function arguments could only be SSA v
11
59
conditional control flow). This negated much of the usefulness of SSA form representation when performing
12
60
middle end optimizations. Some heroic effort was put into making these optimizations work without a complete SSA
13
61
form representation, but the lack of such a representation ultimately proved prohibitive.
62
+
## Categories of IR nodes
14
63
15
-
## New IR nodes
16
-
17
-
With the new IR representation, the compiler learned to handle four new IR nodes, Phi nodes, Pi
18
-
nodes as well as PhiC nodes and Upsilon nodes (the latter two are only used for exception handling).
64
+
The SSA IR representation has four categories of IR nodes: Phi, Pi, PhiC, and Upsilon nodes (the latter two are only used for exception handling).
0 commit comments