Type Systems for Optimizing Stack-based Code

Post on 20-Jul-2016

18 views 0 download

description

optimization of stack based code

Transcript of Type Systems for Optimizing Stack-based Code

Type Systems for Optimizing Stack-based Code

Presented by:- Nebiyou Enbakom

1Compiler Design, AAIT

IntroductionDead Code EliminationStore/Load+ EliminationRelated WorkConclusionReview

Compiler Design ,AAIT 2

3Compiler Design ,AAIT

Optimizing bytecode directly offers challenges not present in high orintermediate-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.

6Compiler 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.

8Compiler 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.

10Compiler Design ,AAIT

11Compiler Design ,AAIT

Compiler Design ,AAIT 12

13Compiler Design ,AAIT

14Compiler Design ,AAIT

15Compiler Design ,AAIT

Compiler Design ,AAIT 16

17Compiler Design ,AAIT

18Compiler Design ,AAIT

19Compiler Design ,AAIT

Compiler Design ,AAIT 20

21Compiler Design ,AAIT

22Compiler Design ,AAIT

23Compiler Design ,AAIT

Compiler Design ,AAIT 24

THANK YOU!

25Compiler Design ,AAIT