SLIDE 20 control-flow graph. Each statement in the program is a node in the graph. If statement S1 can be followed by statement S2 then there is an edge from S1 to S2.
- In determining the live range of a variable we work backwards
through the control-flow graph, examining statements. – If a variable b is used in a statement (i.e. its value is taken) then b must have been live on the edge leading to the state- ment. – If a variable is assigned into in a statement (i.e. its value is set) then it must be dead on the edge leading to the statement.
Utilising the results
The effect of understanding and making use of the results of liveness analysis is to allow us to see that two variables could be replaced by
a ← 0 L1 : b ← a + 1 c ← c + b a ← b ∗ 2 if a < N goto L1 return c a ← 0 L1 : a ← a + 1 c ← c + a a ← a ∗ 2 if a < N goto L1 return c b ← 0 L1 : b ← b + 1 c ← c + b b ← b ∗ 2 if b < N goto L1 return c
77
edges which come from predecessor nodes. The set Pred[n] is all the predecessors of n and the set Succ[n] is the set of all successors.
- An assigment to a variable or temporary defines that variable. An
- ccurrence of a variable in an expression uses the variable. We
can speak of the def of a variable as the set of node that use it, and conversely for a graph node. Similarly we can speak of the uses of a variable or graph node.
- A variable is live on an edge if there is a directed path from that
edge to a use of the variable which does not go through any defs. A variable is live-in if it is live on any of the in-edges of a node. It is live-out if live on any out-edges.
Calculation of liveness by iteration
/ ∗ initialise the edge sets ∗ / for each n in [n] ← {};
repeat for each n / ∗ record the old values ∗ / in′ [n] ← in [n];
/ ∗ compute the new values ∗ / in [n] ← use [n] ∪ (out [n] − def [n]);
for each s in succ [n]
- ut [n] ← out [n] ∪ in [s];
until in′ [n] = in [n] and out′ [n] = out [n] for all n
78
Index
abstract syntax, 24 accepting, 14 accesses, 44 activation record, 37 aliases, 65 alphabet, 6 associativity, 9 back end, 49 basic blocks, 64, 71 bindings, 27 block structure, 42 bodies, 36 body, 62 C_basicBlocks, 64 C_block, 64 C_linearize, 64, 70 C_stmListList, 64 C_stmListList_, 64 C_traceSchedule, 64 call-by-reference, 41 callee, 38 callee-save, 39 caller, 38 caller-save, 39 canonical trees, 64, 65 commute, 65 commute, 69 concrete syntax, 24 conservatively approximate, 66 control flow, 71 control-flow graph, 77 Cx, 52 dangling references, 40 defines, 78 display, 42 do_exp, 67 do_stm, 67–69 dynamic programming, 75 E_enventry_, 48 environments, 27 epilogue, 62 escapes, 42 expRefList, 67 expRefList_, 67 expressions, 9 F_access, 44 F_access_, 45 F_accessList, 44 F_accessList_, 44 F_allocLocal, 44 F_Exp, 56 F_formals, 44 F_FP, 56 F_frame, 44 F_name, 44 F_newFrame, 44 F_wordSize, 56 factors, 9 frame pointer, 38 framesize, 38 front end, 49 garbage collector, 60 headers, 36 heap, 60 in-edges, 78 InFrame, 45 InReg, 45 instruction emission, 76 instruction selection, 73 intermediate representation, 49 interprocedural register allocation, 40 isNop, 68 item, 16 Jouette, 74 label, 47 lambda lifting, 42 language, 6 leaf functions, 40 leaves, 75 left-factor, 13 79 INDEX INDEX Left-to-right parse, leftmost derivation, 1-symbol lookahead, 12 Left-to-right parse, rightmost deriva- tion, k-token lookahead, 14 linear, 70 live, 76 live range, 77 live-in, 78 live-out, 78 liveness analysis, 76 lookahead, 14 Maximal Munch, 75 non-terminal, 7 non-terminals, 11
- ptimal, 74
- ptimum, 74
- ut-edges, 78
parse tree, 24 PatchList, 53 patchList, 53 patchList_, 53 position stack, 25 precedence, 9 predecessor, 78 predictive parsing table, 12 productions, 6 prologue, 62 recursive descent, 9 reduce-reduce, 21 reference declarations, 66 register allocator, 39 register windows, 40 registers, 38 reorder, 67 return address, 41 rewrite, 64 scope, 27 semantic actions, 23 semantic analysis, 27 semantic value, 23, 25 seq, 68 shift-reduce, 21 stack, 14 stack frame, 37 stack pointer, 37 start symbol, 7 states, 16 static link, 42 static nesting depth, 42 stmExp, 67 strings, 6 successor, 78 symbol tables, 27 symbols, 6 Temp_empty, 48 Temp_enter, 48 Temp_LabelList, 48 Temp_labelstring, 48 Temp_layerMap, 48 Temp_look, 48 Temp_name, 48 Temp_namedlabel, 48 Temp_newlabel, 48 Temp_newtemp, 48 Temp_TempList, 48 temporaries, 76 temporary, 47 terminal, 7 terminals, 11 terms, 9 tiling, 73 Tr_Cx, 52 Tr_Ex, 52 Tr_exp, 52 Tr_exp_, 52 Tr_Nx, 52 trace, 71, 72 traces, 64 transExp, 32, 33 transition table, 15 transVar, 33, 34 tree pattern, 73 type declaration, 30 type environment, 31 type expression, 30 unCx, 53 unEx, 53 unNx, 53 uses, 78
80