summaryrefslogtreecommitdiffstats
path: root/content/zettel/3a8a.md
blob: 4a51e13c8cc28659a54444a21466e452f1863bc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
+++
title = "Phi instructions"
author = "Yann Herklotz"
tags = []
categories = []
backlinks = ["3a8"]
forwardlinks = ["3a8b", "3a8a1"]
zettelid = "3a8a"
+++

One main difference between normal intermediate languages and SSA forms
are phi nodes, which are needed to transform branching statements. By
default, the translation from a non-SSA form to an SSA form can just be
done by labelling each variable with an index, and then each new
assignment to that variable increments the index by one. The last index
is then used by each instruction that uses that variable, which means
that the transformation is semantics preserving.

However, this is not the case when one can have multiple branches from
multiple locations to a block. In this case, one needs to add phi
instructions to assign the right value to the register. The phi
instructions is defined as a function which returns the argument
according to which predecessor executed the instruction.

This means that branching instructions can be executed correctly.