INF5110 – Compiler Construction
Code generation Spring 2016
1 / 123
INF5110 Compiler Construction Code generation Spring 2016 1 / 123 - - PowerPoint PPT Presentation
INF5110 Compiler Construction Code generation Spring 2016 1 / 123 Outline 1. Code generation Intro 2AC and costs of instructions Basic blocks and control-flow graphs Code generation algo Global analysis Bibs 2 / 123 Outline 1. Code
1 / 123
2 / 123
3 / 123
aThis section is based on slides from Stein Krogdahl, 2015.
4 / 123
aWhen not said otherwise: efficiency refers in the following to efficiency of
5 / 123
6 / 123
7 / 123
8 / 123
1In the 2A machine code in Louden, for instance in page 12 or the
9 / 123
10 / 123
11 / 123
12 / 123
13 / 123
14 / 123
15 / 123
16 / 123
17 / 123
18 / 123
19 / 123
2the terminology “global” is not ideal, for instance process-level analysis
20 / 123
aOtherwise: cycle/loop detection not worth much discussion
21 / 123
aalternatively: general reachability
22 / 123
23 / 123
3that’s one of pragmatic motivation for unique entry. 24 / 123
25 / 123
26 / 123
4static simulation here was done for basic blocks only and for the purpose of
27 / 123
aThat corresponds to static liveness (the notion the static liveness analysis
28 / 123
29 / 123
30 / 123
5remember: “defs” and “uses” refer to instances of definitions/assignments
31 / 123
32 / 123
33 / 123
34 / 123
35 / 123
1
2
1 36 / 123
abut if one occurrence of (say) x in a rhs x + x is live, so is the other
37 / 123
6Remember: intra-block/SLC. In the presence of loops/analysing a
38 / 123
39 / 123
40 / 123
41 / 123
42 / 123
43 / 123
7some distinguish register allocation: “should the data be held in register
44 / 123
45 / 123
46 / 123
47 / 123
48 / 123
49 / 123
50 / 123
51 / 123
52 / 123
53 / 123
54 / 123
55 / 123
56 / 123
57 / 123
58 / 123
59 / 123
60 / 123
61 / 123
8While assuming variables live, even if they are not, is safe, the opposite
9For sake of making a parallel one could: consider each line as individual
62 / 123
10For some analyses resp. algos: assumed that the only cycles in the graph
63 / 123
11to stress “approximation”: inLive and outLive contain sets of statically live
64 / 123
65 / 123
66 / 123
67 / 123
68 / 123
x:=y+8 y:=3
69 / 123
12There may be more efficient and less efficient orders of treatment. 70 / 123
x:=y+8 y:=3
71 / 123
x:=y+8 y:=3
72 / 123
x:=y+8 y:=3
73 / 123
x:=y+8 y:=3
74 / 123
x:=y+8 y:=3
75 / 123
x:=y+8 y:=3
76 / 123
x:=y+8 y:=3
77 / 123
x:=y+8 y:=3
78 / 123
x:=y+8 y:=3
79 / 123
x:=y+8 y:=3
80 / 123
x:=y+8 y:=3
81 / 123
x:=y+8 y:=3
82 / 123
x:=y+8 y:=3
83 / 123
x:=y+8 y:=3
84 / 123
85 / 123
86 / 123
87 / 123
88 / 123
89 / 123
90 / 123
91 / 123
92 / 123
93 / 123
94 / 123
95 / 123
96 / 123
97 / 123
98 / 123
99 / 123
100 / 123
101 / 123
102 / 123
103 / 123
13In principle, one could also arrange the opposite order (interpreting kill and
104 / 123
105 / 123
106 / 123
107 / 123
108 / 123
109 / 123
110 / 123
111 / 123
112 / 123
113 / 123
114 / 123
115 / 123
116 / 123
117 / 123
118 / 123
119 / 123
120 / 123
121 / 123
122 / 123
[Aho et al., 2007] Aho, A. V., Lam, M. S., Sethi, R., and Ullman, J. D. (2007). Compilers: Principles, Techniques and Tools. Pearson,Addison-Wesley, second edition. [Aho et al., 1986] Aho, A. V., Sethi, R., and Ullman, J. D. (1986). Compilers: Principles, Techniques and Tools. Addison-Wesley. 123 / 123