1: 2: // test dead code elimination 3: 4: void main ( ) 5: { 6: int x,y,z; 7: 8: x = 1; // dead 9: y = 2; 10: z = 3 + y; // dead 11: x = 5 + y; 12: y = 6; // dead 13: z = 7; 14: x = 8 + x; 15: y = 9; // dead 16: z = z + x; 17: 18: printStr("Result (should be 22) = "); 19: printInt(z); 20: printLn(); 21: } 22: ** Global Variables ** printLn, void, function, param = main, void, function, param = printStr, void, function, param = String printInt, void, function, param = int ** Local Variables in main() ** z, int y, int x, int TREE_PROC: main { TREE_INSTR: x = 1 TREE_INSTR: y = 2 TREE_INSTR: z = (3 PLUS y) TREE_INSTR: x = (5 PLUS y) TREE_INSTR: y = 6 TREE_INSTR: z = 7 TREE_INSTR: x = (8 PLUS x) TREE_INSTR: y = 9 TREE_INSTR: z = (z PLUS x) TREE_INSTR: CALL printStr("Result (should be 22) = ") TREE_INSTR: CALL printInt(z) TREE_INSTR: CALL printLn() } END_PROC ** Basic block: 0 ** Length: 1 Successors: 1 Predecessors: GEN {} KILL {} IN {} OUT {} > 0: iconst_1 ** Basic block: 1 ** Length: 1 Successors: 2 Predecessors: 0 GEN {} KILL {3} IN {} OUT {} > 1: istore_3 ** Basic block: 2 ** Length: 1 Successors: 3 Predecessors: 1 GEN {} KILL {} IN {} OUT {} > 2: iconst_2 ** Basic block: 3 ** Length: 1 Successors: 4 Predecessors: 2 GEN {} KILL {2} IN {} OUT {2} > 3: istore_2 ** Basic block: 4 ** Length: 1 Successors: 5 Predecessors: 3 GEN {} KILL {} IN {2} OUT {2} > 4: iconst_3 ** Basic block: 5 ** Length: 1 Successors: 6 Predecessors: 4 GEN {2} KILL {} IN {2} OUT {2} > 5: iload_2 ** Basic block: 6 ** Length: 1 Successors: 7 Predecessors: 5 GEN {} KILL {} IN {2} OUT {2} > 6: iadd ** Basic block: 7 ** Length: 1 Successors: 8 Predecessors: 6 GEN {} KILL {1} IN {2} OUT {2} > 7: istore_1 ** Basic block: 8 ** Length: 1 Successors: 9 Predecessors: 7 GEN {} KILL {} IN {2} OUT {2} > 8: iconst_5 ** Basic block: 9 ** Length: 1 Successors: 10 Predecessors: 8 GEN {2} KILL {} IN {2} OUT {} > 9: iload_2 ** Basic block: 10 ** Length: 1 Successors: 11 Predecessors: 9 GEN {} KILL {} IN {} OUT {} > 10: iadd ** Basic block: 11 ** Length: 1 Successors: 12 Predecessors: 10 GEN {} KILL {3} IN {} OUT {3} > 11: istore_3 ** Basic block: 12 ** Length: 1 Successors: 13 Predecessors: 11 GEN {} KILL {} IN {3} OUT {3} > 12: bipush 6 ** Basic block: 13 ** Length: 1 Successors: 14 Predecessors: 12 GEN {} KILL {2} IN {3} OUT {3} > 14: istore_2 ** Basic block: 14 ** Length: 1 Successors: 15 Predecessors: 13 GEN {} KILL {} IN {3} OUT {3} > 15: bipush 7 ** Basic block: 15 ** Length: 1 Successors: 16 Predecessors: 14 GEN {} KILL {1} IN {3} OUT {1, 3} > 17: istore_1 ** Basic block: 16 ** Length: 1 Successors: 17 Predecessors: 15 GEN {} KILL {} IN {1, 3} OUT {1, 3} > 18: bipush 8 ** Basic block: 17 ** Length: 1 Successors: 18 Predecessors: 16 GEN {3} KILL {} IN {1, 3} OUT {1} > 20: iload_3 ** Basic block: 18 ** Length: 1 Successors: 19 Predecessors: 17 GEN {} KILL {} IN {1} OUT {1} > 21: iadd ** Basic block: 19 ** Length: 1 Successors: 20 Predecessors: 18 GEN {} KILL {3} IN {1} OUT {1, 3} > 22: istore_3 ** Basic block: 20 ** Length: 1 Successors: 21 Predecessors: 19 GEN {} KILL {} IN {1, 3} OUT {1, 3} > 23: bipush 9 ** Basic block: 21 ** Length: 1 Successors: 22 Predecessors: 20 GEN {} KILL {2} IN {1, 3} OUT {1, 3} > 25: istore_2 ** Basic block: 22 ** Length: 1 Successors: 23 Predecessors: 21 GEN {1} KILL {} IN {1, 3} OUT {3} > 26: iload_1 ** Basic block: 23 ** Length: 1 Successors: 24 Predecessors: 22 GEN {3} KILL {} IN {3} OUT {} > 27: iload_3 ** Basic block: 24 ** Length: 1 Successors: 25 Predecessors: 23 GEN {} KILL {} IN {} OUT {} > 28: iadd ** Basic block: 25 ** Length: 1 Successors: 26 Predecessors: 24 GEN {} KILL {1} IN {} OUT {1} > 29: istore_1 ** Basic block: 26 ** Length: 1 Successors: 27 Predecessors: 25 GEN {} KILL {} IN {1} OUT {1} > 30: getstatic 12 ** Basic block: 27 ** Length: 1 Successors: 28 Predecessors: 26 GEN {} KILL {} IN {1} OUT {1} > 33: ldc 31 ** Basic block: 28 ** Length: 1 Successors: 29 Predecessors: 27 GEN {} KILL {} IN {1} OUT {1} > 35: invokevirtual 26 ** Basic block: 29 ** Length: 1 Successors: 30 Predecessors: 28 GEN {} KILL {} IN {1} OUT {1} > 38: getstatic 12 ** Basic block: 30 ** Length: 1 Successors: 31 Predecessors: 29 GEN {1} KILL {} IN {1} OUT {} > 41: iload_1 ** Basic block: 31 ** Length: 1 Successors: 32 Predecessors: 30 GEN {} KILL {} IN {} OUT {} > 42: invokevirtual 29 ** Basic block: 32 ** Length: 1 Successors: 33 Predecessors: 31 GEN {} KILL {} IN {} OUT {} > 45: getstatic 12 ** Basic block: 33 ** Length: 1 Successors: 34 Predecessors: 32 GEN {} KILL {} IN {} OUT {} > 48: invokevirtual 18 ** Basic block: 34 ** Length: 1 Successors: 35 Predecessors: 33 GEN {} KILL {} IN {} OUT {} > 51: return ** Basic block: 35 ** Length: 0 Successors: Predecessors: 34 GEN {} KILL {} IN {} OUT {} <<---- Live Ranges ---->> [B 0] [Live ] 0: iconst_1 [B 1] [Live ] 1: istore_3 [B 2] [Live ] 2: iconst_2 [B 3] [Live ] 3: istore_2 [B 4] [Live 2 ] 4: iconst_3 [B 5] [Live 2 ] 5: iload_2 [B 6] [Live 2 ] 6: iadd [B 7] [Live 2 ] 7: istore_1 [B 8] [Live 2 ] 8: iconst_5 [B 9] [Live 2 ] 9: iload_2 [B 10] [Live ] 10: iadd [B 11] [Live ] 11: istore_3 [B 12] [Live 3 ] 12: bipush 6 [B 13] [Live 3 ] 14: istore_2 [B 14] [Live 3 ] 15: bipush 7 [B 15] [Live 3 ] 17: istore_1 [B 16] [Live 1 3 ] 18: bipush 8 [B 17] [Live 1 3 ] 20: iload_3 [B 18] [Live 1 ] 21: iadd [B 19] [Live 1 ] 22: istore_3 [B 20] [Live 1 3 ] 23: bipush 9 [B 21] [Live 1 3 ] 25: istore_2 [B 22] [Live 1 3 ] 26: iload_1 [B 23] [Live 3 ] 27: iload_3 [B 24] [Live ] 28: iadd [B 25] [Live ] 29: istore_1 [B 26] [Live 1 ] 30: getstatic 12 [B 27] [Live 1 ] 33: ldc 31 [B 28] [Live 1 ] 35: invokevirtual 26 [B 29] [Live 1 ] 38: getstatic 12 [B 30] [Live 1 ] 41: iload_1 [B 31] [Live ] 42: invokevirtual 29 [B 32] [Live ] 45: getstatic 12 [B 33] [Live ] 48: invokevirtual 18 [B 34] [Live ] 51: return <<---- Local Variables in main() ---->> LocalVariable(start_pc = 0, length = 51, index = 0:String[] argv) LocalVariable(start_pc = 0, length = 51, index = 1:int z) LocalVariable(start_pc = 0, length = 51, index = 2:int y) LocalVariable(start_pc = 0, length = 51, index = 3:int x) <<---- Global Variables ---->> Compiled from "" public class test7 extends java.lang.Object{ public static void main(java.lang.String[]); Code: 0: iconst_1 1: pop 2: iconst_2 3: istore_2 4: iconst_3 5: iload_2 6: iadd 7: pop 8: iconst_5 9: iload_2 10: iadd 11: istore_3 12: bipush 6 14: pop 15: bipush 7 17: istore_1 18: bipush 8 20: iload_3 21: iadd 22: istore_3 23: bipush 9 25: pop 26: iload_1 27: iload_3 28: iadd 29: istore_1 30: getstatic #12; //Field java/lang/System.out:Ljava/io/PrintStream; 33: ldc #31; //String Result (should be 22) = 35: invokevirtual #26; //Method java/io/PrintStream.print:(Ljava/lang/String;)V 38: getstatic #12; //Field java/lang/System.out:Ljava/io/PrintStream; 41: iload_1 42: invokevirtual #29; //Method java/io/PrintStream.print:(I)V 45: getstatic #12; //Field java/lang/System.out:Ljava/io/PrintStream; 48: invokevirtual #18; //Method java/io/PrintStream.println:()V 51: return public test7(); Code: 0: aload_0 1: invokespecial #42; //Method java/lang/Object."":()V 4: return }