132:. In other words, if applying liveness analysis to a function with a particular number of logical branches within it, the analysis is performed starting from the end of the function working towards the beginning (hence "backwards"), and a variable is considered live if any of the branches moving forward within the function might potentially (hence "may") need the variable's current value. This is in contrast to a "backwards must" analysis which would instead enforce this condition on all branches moving forward.
759:// in: {}; predecessor blocks: none b1: a = 3; b = 5; d = 4; x = 100; //x is never being used later thus not in the out set {a,b,d} if a > b then // out: {a,b,d} //union of all (in) successors of b1 => b2: {a,b}, and b3:{b,d} // in: {a,b}; predecessor blocks: b1 b2: c = a + b; d = 2; // out: {b,d} // in: {b,d}; predecessor blocks: b1 and b2 b3: endif c = 4; return b * d + c; // out:{}
885:
Initializing with the empty set is an optimistic initialization: all variables start out as dead. Note that the out-states cannot shrink from one iteration to the next, although the out-state can be smaller than the in-state. This can be seen from the fact that after the first iteration the out-state
746:
The in-state of a block is the set of variables that are live at the start of the block. Its out-state is the set of variables that are live at the end of it. The out-state is the union of the in-states of the block's successors. The transfer function of a statement is applied by making the variables
789:
Solving the data flow equations starts with initializing all in-states and out-states to the empty set. The work list is initialized by inserting the exit point (b3) in the work list (typical for backward flow). Its computed in-state differs from the previous one, so its predecessors b1 and b2 are
344:
521:
648:
411:
882:
Note that b1 was entered in the list before b2, which forced processing b1 twice (b1 was re-entered as predecessor of b2). Inserting b2 before b1 would have allowed earlier completion.
741:
214:
177:
216:: The set of variables that are assigned a value in s (in many books that discuss compiler design, KILL (s) is also defined as the set of variables assigned a value in s
924:
1071:
55:
at some point if it holds a value that may be needed in the future, or equivalently if its value may be read before the next time the variable is written to.
230:
1105:
417:
917:
1277:
1313:
1154:
1055:
886:
can only change by a change of the in-state. Since the in-state starts as the empty set, it can only grow in further iterations.
1303:
1196:
910:
105:
1091:
1175:
1308:
1226:
1191:
529:
350:
1115:
990:
970:
77:} because both are used in the multiplication on line 3. But the set of live variables after line 1 is only {
975:
1123:
1100:
1005:
44:
654:
125:
1252:
1247:
1201:
1128:
952:
947:
1282:
1206:
1050:
778:
has been written. The out-state of b1 is the union of the in-states of b2 and b3. The definition of
1262:
1133:
1025:
933:
186:
149:
1257:
1221:
1040:
1030:
980:
121:
40:
1138:
962:
100:
is not used later, but there is insufficient information to justify removing all of line 3 as
1272:
1211:
1081:
1060:
1020:
1000:
1267:
179:: The set of variables that are used in s before any assignment in the same basic block.
1242:
1216:
1015:
1010:
995:
339:{\displaystyle {\mbox{LIVE}}_{in}={\mbox{GEN}}\cup ({\mbox{LIVE}}_{out}-{\mbox{KILL}})}
1297:
790:
inserted and the process continues. The progress is summarized in the table below.
17:
985:
1065:
1159:
129:
28:
120:
Liveness analysis is a "backwards may" analysis. The analysis is done in a
516:{\displaystyle {\mbox{LIVE}}_{out}=\bigcup _{p\in succ}{\mbox{LIVE}}_{in}}
902:
747:
that are written dead, then making the variables that are read live.
220:, but this does not change the solution of the dataflow equation):
906:
895:
Aho, Alfred; Lam, Monica; Sethi, Ravi; Ullman, Jeffrey (2007).
659:
534:
489:
423:
356:
318:
287:
264:
236:
191:
154:
657:
532:
420:
353:
233:
189:
152:
135:
The dataflow equations used for a given basic block
69:
The set of live variables between lines 2 and 3 is {
1235:
1184:
1168:
1147:
1114:
1090:
1039:
961:
940:
85:is updated later, on line 2. The value of variable
735:
642:
515:
405:
338:
208:
171:
643:{\displaystyle {\mbox{GEN}}=\{x_{1},...,x_{n}\}}
406:{\displaystyle {\mbox{LIVE}}_{out}={\emptyset }}
1072:Induction variable recognition and elimination
918:
786:is not live immediately after the statement.
143:in live variable analysis are the following:
8:
897:Compilers: Principles, Techniques, and Tools
730:
724:
637:
599:
51:at each point in the program. A variable is
925:
911:
903:
709:
690:
658:
656:
631:
606:
584:
565:
533:
531:
495:
488:
457:
429:
422:
419:
398:
362:
355:
352:
317:
293:
286:
263:
242:
235:
232:
190:
188:
153:
151:
116:Expression in terms of dataflow equations
792:
1106:Sparse conditional constant propagation
7:
736:{\displaystyle {\mbox{KILL}}=\{y\}}
399:
25:
766:The in-state of b3 only contains
1056:Common subexpression elimination
63:Consider the following program:
1197:Compile-time function execution
718:
715:
683:
677:
665:
593:
590:
558:
552:
540:
510:
504:
482:
476:
447:
441:
392:
374:
333:
330:
324:
311:
305:
282:
276:
270:
257:
251:
203:
197:
166:
160:
1:
209:{\displaystyle {\mbox{KILL}}}
1176:Interprocedural optimization
782:in b2 can be removed, since
172:{\displaystyle {\mbox{GEN}}}
92:Note that the assignment to
1227:Profile-guided optimization
1192:Bounds-checking elimination
1330:
991:Loop-invariant code motion
899:(2 ed.). p. 608.
89:is not used in this code.
971:Automatic parallelization
66:b = 3 c = 5 a = f(b * c)
124:order, and the dataflow
1314:Static program analysis
976:Automatic vectorization
1304:Compiler optimizations
1124:Instruction scheduling
1101:Global value numbering
1077:Live-variable analysis
1006:Loop nest optimization
934:Compiler optimizations
737:
644:
517:
407:
340:
210:
173:
33:live variable analysis
1253:Control-flow analysis
1248:Array-access analysis
1202:Dead-code elimination
1160:Tail-call elimination
1129:Instruction selection
953:Local value numbering
948:Peephole optimization
738:
645:
518:
408:
341:
211:
174:
96:may be eliminated as
1283:Value range analysis
1207:Expression templates
1051:Available expression
655:
530:
418:
351:
231:
187:
150:
1263:Dependence analysis
1134:Register allocation
1026:Software pipelining
126:confluence operator
1309:Data-flow analysis
1258:Data-flow analysis
1222:Partial evaluation
1031:Strength reduction
981:Induction variable
733:
663:
640:
538:
513:
493:
486:
427:
403:
360:
336:
322:
291:
268:
240:
206:
195:
169:
158:
139:and exiting block
81:}, since variable
41:data-flow analysis
1291:
1290:
1139:Rematerialization
880:
879:
764:
763:
662:
537:
492:
453:
426:
359:
321:
290:
267:
239:
194:
157:
43:to calculate the
37:liveness analysis
18:Liveness analysis
16:(Redirected from
1321:
1273:Pointer analysis
1212:Inline expansion
1082:Use-define chain
1061:Constant folding
1021:Loop unswitching
1001:Loop interchange
927:
920:
913:
904:
900:
793:
755:
754:
742:
740:
739:
734:
714:
713:
695:
694:
664:
660:
649:
647:
646:
641:
636:
635:
611:
610:
589:
588:
570:
569:
539:
535:
522:
520:
519:
514:
503:
502:
494:
490:
485:
440:
439:
428:
424:
412:
410:
409:
404:
402:
373:
372:
361:
357:
345:
343:
342:
337:
323:
319:
304:
303:
292:
288:
269:
265:
250:
249:
241:
237:
215:
213:
212:
207:
196:
192:
178:
176:
175:
170:
159:
155:
111:
103:
99:
95:
88:
84:
80:
76:
72:
21:
1329:
1328:
1324:
1323:
1322:
1320:
1319:
1318:
1294:
1293:
1292:
1287:
1268:Escape analysis
1236:Static analysis
1231:
1180:
1164:
1143:
1116:Code generation
1110:
1086:
1042:
1035:
957:
936:
931:
894:
892:
760:
753:
705:
686:
653:
652:
627:
602:
580:
561:
528:
527:
487:
421:
416:
415:
354:
349:
348:
285:
234:
229:
228:
224:
185:
184:
148:
147:
118:
109:
101:
97:
93:
86:
82:
78:
74:
70:
67:
61:
39:) is a classic
23:
22:
15:
12:
11:
5:
1327:
1325:
1317:
1316:
1311:
1306:
1296:
1295:
1289:
1288:
1286:
1285:
1280:
1278:Shape analysis
1275:
1270:
1265:
1260:
1255:
1250:
1245:
1243:Alias analysis
1239:
1237:
1233:
1232:
1230:
1229:
1224:
1219:
1217:Jump threading
1214:
1209:
1204:
1199:
1194:
1188:
1186:
1182:
1181:
1179:
1178:
1172:
1170:
1166:
1165:
1163:
1162:
1157:
1151:
1149:
1145:
1144:
1142:
1141:
1136:
1131:
1126:
1120:
1118:
1112:
1111:
1109:
1108:
1103:
1097:
1095:
1088:
1087:
1085:
1084:
1079:
1074:
1069:
1063:
1058:
1053:
1047:
1045:
1037:
1036:
1034:
1033:
1028:
1023:
1018:
1016:Loop unrolling
1013:
1011:Loop splitting
1008:
1003:
998:
996:Loop inversion
993:
988:
983:
978:
973:
967:
965:
959:
958:
956:
955:
950:
944:
942:
938:
937:
932:
930:
929:
922:
915:
907:
891:
888:
878:
877:
874:
871:
868:
865:
861:
860:
857:
854:
851:
848:
844:
843:
840:
837:
834:
831:
827:
826:
823:
820:
817:
814:
810:
809:
806:
803:
800:
797:
762:
761:
758:
752:
751:Second example
749:
744:
743:
732:
729:
726:
723:
720:
717:
712:
708:
704:
701:
698:
693:
689:
685:
682:
679:
676:
673:
670:
667:
650:
639:
634:
630:
626:
623:
620:
617:
614:
609:
605:
601:
598:
595:
592:
587:
583:
579:
576:
573:
568:
564:
560:
557:
554:
551:
548:
545:
542:
524:
523:
512:
509:
506:
501:
498:
484:
481:
478:
475:
472:
469:
466:
463:
460:
456:
452:
449:
446:
443:
438:
435:
432:
413:
401:
397:
394:
391:
388:
385:
382:
379:
376:
371:
368:
365:
346:
335:
332:
329:
326:
316:
313:
310:
307:
302:
299:
296:
284:
281:
278:
275:
272:
262:
259:
256:
253:
248:
245:
222:
221:
218:before any use
205:
202:
199:
181:
180:
168:
165:
162:
117:
114:
65:
60:
57:
24:
14:
13:
10:
9:
6:
4:
3:
2:
1326:
1315:
1312:
1310:
1307:
1305:
1302:
1301:
1299:
1284:
1281:
1279:
1276:
1274:
1271:
1269:
1266:
1264:
1261:
1259:
1256:
1254:
1251:
1249:
1246:
1244:
1241:
1240:
1238:
1234:
1228:
1225:
1223:
1220:
1218:
1215:
1213:
1210:
1208:
1205:
1203:
1200:
1198:
1195:
1193:
1190:
1189:
1187:
1183:
1177:
1174:
1173:
1171:
1167:
1161:
1158:
1156:
1155:Deforestation
1153:
1152:
1150:
1146:
1140:
1137:
1135:
1132:
1130:
1127:
1125:
1122:
1121:
1119:
1117:
1113:
1107:
1104:
1102:
1099:
1098:
1096:
1093:
1089:
1083:
1080:
1078:
1075:
1073:
1070:
1067:
1064:
1062:
1059:
1057:
1054:
1052:
1049:
1048:
1046:
1044:
1038:
1032:
1029:
1027:
1024:
1022:
1019:
1017:
1014:
1012:
1009:
1007:
1004:
1002:
999:
997:
994:
992:
989:
987:
984:
982:
979:
977:
974:
972:
969:
968:
966:
964:
960:
954:
951:
949:
946:
945:
943:
939:
935:
928:
923:
921:
916:
914:
909:
908:
905:
901:
898:
889:
887:
883:
875:
872:
869:
866:
863:
862:
858:
855:
852:
849:
846:
845:
841:
838:
835:
832:
829:
828:
824:
821:
818:
815:
812:
811:
807:
805:new in-state
804:
802:old in-state
801:
798:
795:
794:
791:
787:
785:
781:
777:
773:
769:
757:
756:
750:
748:
727:
721:
710:
706:
702:
699:
696:
691:
687:
680:
674:
671:
668:
651:
632:
628:
624:
621:
618:
615:
612:
607:
603:
596:
585:
581:
577:
574:
571:
566:
562:
555:
549:
546:
543:
526:
525:
507:
499:
496:
479:
473:
470:
467:
464:
461:
458:
454:
450:
444:
436:
433:
430:
414:
395:
389:
386:
383:
380:
377:
369:
366:
363:
347:
327:
314:
308:
300:
297:
294:
279:
273:
260:
254:
246:
243:
227:
226:
225:
219:
200:
183:
182:
163:
146:
145:
144:
142:
138:
133:
131:
127:
123:
115:
113:
107:
90:
64:
58:
56:
54:
50:
46:
42:
38:
34:
30:
19:
1076:
896:
893:
884:
881:
788:
783:
779:
775:
771:
767:
765:
745:
223:
217:
140:
136:
134:
119:
112:, perhaps).
106:side effects
91:
68:
62:
52:
48:
36:
32:
26:
1068:elimination
986:Loop fusion
941:Basic block
796:processing
35:(or simply
1298:Categories
1148:Functional
1066:Dead store
890:References
808:work list
799:out-state
108:(printing
1041:Data-flow
700:⋯
678:←
575:⋯
553:←
462:∈
455:⋃
400:∅
315:−
280:∪
130:set union
122:backwards
104:may have
47:that are
45:variables
29:compilers
1043:analysis
867:{a,b,d}
825:(b1,b2)
774:, since
59:Example
1169:Global
1094:-based
856:{a,b}
850:{b,d}
833:{b,d}
822:{b,d}
1185:Other
859:(b1)
842:(b2)
110:b * c
963:Loop
770:and
661:KILL
491:LIVE
425:LIVE
358:LIVE
320:KILL
289:LIVE
238:LIVE
193:KILL
53:live
49:live
1092:SSA
876:()
873:{}
870:{}
864:b1
853:{}
847:b2
839:{}
836:{}
830:b1
819:{}
816:{}
813:b3
536:GEN
266:GEN
156:GEN
128:is
27:In
1300::
73:,
31:,
926:e
919:t
912:v
784:c
780:c
776:c
772:d
768:b
731:}
728:y
725:{
722:=
719:]
716:)
711:n
707:x
703:,
697:,
692:1
688:x
684:(
681:f
675:y
672::
669:d
666:[
638:}
633:n
629:x
625:,
622:.
619:.
616:.
613:,
608:1
604:x
600:{
597:=
594:]
591:)
586:n
582:x
578:,
572:,
567:1
563:x
559:(
556:f
550:y
547::
544:d
541:[
511:]
508:p
505:[
500:n
497:i
483:]
480:s
477:[
474:c
471:c
468:u
465:s
459:p
451:=
448:]
445:s
442:[
437:t
434:u
431:o
396:=
393:]
390:l
387:a
384:n
381:i
378:f
375:[
370:t
367:u
364:o
334:)
331:]
328:s
325:[
312:]
309:s
306:[
301:t
298:u
295:o
283:(
277:]
274:s
271:[
261:=
258:]
255:s
252:[
247:n
244:i
204:]
201:s
198:[
167:]
164:s
161:[
141:f
137:s
102:f
98:a
94:a
87:a
83:c
79:b
75:c
71:b
20:)
Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.