0% found this document useful (0 votes)
81 views

Type Systems For Optimizing Stack-Based Code

This document discusses type systems for optimizing stack-based code. It outlines some of the challenges in optimizing bytecode directly compared to high or intermediate-level code. Expressions and statements are not explicit in stack-based code, related instructions can be far apart, and expressions can span multiple basic blocks. The document then describes optimizations for dead stores, load-pop pairs, duplicating loads, and store-load pairs in stack-based code. It provides an example of dead code elimination in stack-based code where removing a dead store would also require removing the preceding load and add instructions.

Uploaded by

Yonas Biniam
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Type Systems For Optimizing Stack-Based Code

This document discusses type systems for optimizing stack-based code. It outlines some of the challenges in optimizing bytecode directly compared to high or intermediate-level code. Expressions and statements are not explicit in stack-based code, related instructions can be far apart, and expressions can span multiple basic blocks. The document then describes optimizations for dead stores, load-pop pairs, duplicating loads, and store-load pairs in stack-based code. It provides an example of dead code elimination in stack-based code where removing a dead store would also require removing the preceding load and add instructions.

Uploaded by

Yonas Biniam
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 25

Type Systems for Optimizing

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

You might also like