Type Systems For Optimizing Stack-Based Code
Type Systems For Optimizing Stack-Based Code
Stack-based Code
Presented by:- Nebiyou Enbakom
1
Compiler Design, AAIT
Introduction
Dead Code Elimination
Store/Load+ Elimination
Related Work
Conclusion
Review
Compiler Design ,AAIT
2
3
Compiler Design ,AAIT
Optimizing bytecode directly offers challenges not
present in high or
intermediate-level program optimizations.
The following reasons can be outlined
Expressions and statements are not explicit. In a
naive approach, a reconstruction of expression
trees from instructions would be required for many
optimizations.
:
Compiler Design ,AAIT
4
Related instructions are not necessarily next to each other. A
value could be put on the stack, a number of other instructions
executed and only then the value used and popped. This
means that related instructions, for example those that put a
value on a stack, and those that consume it, can be arbitrarily
far apart. Links between them need to be found during the
analysis.
A single expression can span several different basic blocks.
The Java Virtual Machine specification does not require zero
stack depth at control flow junctions, so an expression used in
a basic block can be partially computed in other basic blocks.
Compiler Design ,AAIT
5
The analyses and optimizations in this paper
address
dead stores
load-pop pairs
duplicating loads and
store-load pairs, which are typical
optimization situations in stack-based code.
6
Compiler Design ,AAIT
Dead code elimination
Dead Code elimination optimization removes
program statements that do not affect the values
of variables that are live at the end of the
program.
For example the program x := z + y could be
compiled into
0, load z
1, load y
2, add
3, store x
4.
8
Compiler Design ,AAIT
If the analysis shows that x is dead, then in the
intermediate code, the assignment to x can be
deleted. In the stack-based code however, not
only the store instruction on line 3, but also
lines 0-2 should be deleted.
In stack-based code optimizations statements
and expression can span several basic blocks.
10
Compiler Design ,AAIT
11
Compiler Design ,AAIT
Compiler Design ,AAIT
12
13
Compiler Design ,AAIT
14
Compiler Design ,AAIT
15
Compiler Design ,AAIT
Compiler Design ,AAIT
16
17
Compiler Design ,AAIT
18
Compiler Design ,AAIT
19
Compiler Design ,AAIT
Compiler Design ,AAIT
20
21
Compiler Design ,AAIT
22
Compiler Design ,AAIT
23
Compiler Design ,AAIT
Compiler Design ,AAIT
24
THANK YOU!
25
Compiler Design ,AAIT