25
Type Systems for Optimizing Stack-based Code Presented by:- Nebiyou Enbakom 1 Compiler Design, AAIT

Type Systems for Optimizing Stack-based Code

Embed Size (px)

DESCRIPTION

optimization of stack based code

Citation preview

Page 1: Type Systems for Optimizing Stack-based Code

Type Systems for Optimizing Stack-based Code

Presented by:- Nebiyou Enbakom

1Compiler Design, AAIT

Page 2: Type Systems for Optimizing Stack-based Code

IntroductionDead Code EliminationStore/Load+ EliminationRelated WorkConclusionReview

Compiler Design ,AAIT 2

Page 3: Type Systems for Optimizing Stack-based Code

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.

:

Page 4: Type Systems for Optimizing Stack-based Code

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.

Page 5: Type Systems for Optimizing Stack-based Code

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.

Page 6: Type Systems for Optimizing Stack-based Code

6Compiler Design ,AAIT

Page 7: Type Systems for Optimizing Stack-based Code

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.

Page 8: Type Systems for Optimizing Stack-based Code

8Compiler Design ,AAIT

Page 9: Type Systems for Optimizing Stack-based Code

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.

Page 10: Type Systems for Optimizing Stack-based Code

10Compiler Design ,AAIT

Page 11: Type Systems for Optimizing Stack-based Code

11Compiler Design ,AAIT

Page 12: Type Systems for Optimizing Stack-based Code

Compiler Design ,AAIT 12

Page 13: Type Systems for Optimizing Stack-based Code

13Compiler Design ,AAIT

Page 14: Type Systems for Optimizing Stack-based Code

14Compiler Design ,AAIT

Page 15: Type Systems for Optimizing Stack-based Code

15Compiler Design ,AAIT

Page 16: Type Systems for Optimizing Stack-based Code

Compiler Design ,AAIT 16

Page 17: Type Systems for Optimizing Stack-based Code

17Compiler Design ,AAIT

Page 18: Type Systems for Optimizing Stack-based Code

18Compiler Design ,AAIT

Page 19: Type Systems for Optimizing Stack-based Code

19Compiler Design ,AAIT

Page 20: Type Systems for Optimizing Stack-based Code

Compiler Design ,AAIT 20

Page 21: Type Systems for Optimizing Stack-based Code

21Compiler Design ,AAIT

Page 22: Type Systems for Optimizing Stack-based Code

22Compiler Design ,AAIT

Page 23: Type Systems for Optimizing Stack-based Code

23Compiler Design ,AAIT

Page 24: Type Systems for Optimizing Stack-based Code

Compiler Design ,AAIT 24

Page 25: Type Systems for Optimizing Stack-based Code

THANK YOU!

25Compiler Design ,AAIT