STATIC ANALYSIS�
Advanced Optimizations
Much much more….
Takeaway of Optimization
Last Time
Register Allocation
Last Time (How?)
Register Allocation
Intermediate Representation (Illustrative)
Types
Stack to Three-Address Code
Stack |
t1 |
|
|
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
load_local 0
assert_integer
get_integer
sub_const_2 2
return
]
}
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
]
}
(Code after Type and Constant Analysis)
Stack to Three-Address Code
Stack |
t1 |
|
|
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
load_local 0
assert_integer
get_integer
sub_const_2 2
return
]
}
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
t1 = load_local 0
]
}
Stack to Three-Address Code
Stack |
t2 |
|
|
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
t1 = load_local 0
t2 = assert_integer t1
]
}
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
load_local 0
assert_integer
get_integer
sub_const_2 2
return
]
}
Stack to Three-Address Code
Stack |
t3 |
|
|
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
t1 = load_local 0
t2 = assert_integer t1
t3 = get_integer t2
]
}
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
load_local 0
assert_integer
get_integer
sub_const_2 2
return
]
}
Stack to Three-Address Code
Stack |
t4 |
|
|
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
t1 = load_local 0
t2 = assert_integer t1
t3 = get_integer t2
t4 = sub_int32 t3 2
]
}
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
load_local 0
assert_integer
get_integer
sub_const_2 2
return
]
}
Stack to Three-Address Code
Stack |
|
|
|
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
load_local 0
assert_integer
get_integer
sub_const_2 2
return
]
}
function {
parameter_count = 1
local_vars = [y, x],
constants = [None, 2],
instructions = [
t1 = load_local 0
t2 = assert_integer t1
t3 = get_integer t2
t4 = sub_int32 t3 2
return t4
]
}
Virtual Machine Showdown: Stack Versus Registers
Yunhe Shi, David Gregg, Andrew Beatty, and M. Anton Ertl
Is a Constant in s = s+a*b?
s = 0;
a = 4;
i = 0;
k == 0
b = 1;
b = 2;
i < n
s = s + a*b;
i = i + 1;
return s
Yes!
On all reaching
definitions
a = 4
Constant Propagation Transform
s = 0;
a = 4;
i = 0;
k == 0
b = 1;
b = 2;
i < n
s = s + 4*b;
i = i + 1;
return s
Yes!
On all reaching
definitions
a = 4
Is b Constant in s = s+a*b?
s = 0;
a = 4;
i = 0;
k == 0
b = 1;
b = 2;
i < n
s = s + a*b;
i = i + 1;
return s
No!
One reaching
definition with
b = 1
One reaching
definition with
b = 2
How? Static Analysis: Key Concepts
Chaotic Iteration
y=0;
t=1;
x=x+1;
y=y+2;
t=t+2;
y=t-1;
end
P2
P1
P3
P5
General Analysis Framework
FORMAL FRAMEWORK
Key Concepts
Is a Constant in s = s+a*b?
s = 0;
a = 4;
i = 0;
k == 0
b = 1;
b = 2;
i < n
s = s + a*b;
i = i + 1;
return s
Yes!
On all reaching
definitions
a = 4
Fact/Property
Analysis: Set of Facts/Properties
Key Concepts
Symbolic/Abstract Execution
Is b Constant in s = s+a*b?
s = 0;
a = 4;
i = 0;
k == 0
b = 1;
b = 2;
i < n
s = s + a*b;
i = i + 1;
return s
No!
One reaching
definition with
b = 1
One reaching
definition with
b = 2
Merging Facts
Merging Facts
b = 1;
b = 1;
b = 1;
b = 1;
b = 1;
b = 1;
b = 1;
b = 1;
Constant
Sign
Interval
Set
Merging Facts
b = 1;
b = 2;
b = 1;
b = 2;
b = 1;
b = 2;
b = 1;
b = 2;
Constant
Sign
Interval
Set
Merging Facts
b = 0;
b = 1;
b = 0;
b = 1;
b = 0;
b = 1;
b = 0;
b = 1;
Constant
Sign
Interval
Set
Merging Facts
b = -1;
b = 1;
b = -1;
b = 1;
b = -1;
b = 1;
b = -1;
b = 1;
Constant
Sign
Interval
Set
Merging Facts