Transcript PPT

Debugging Optimized Code
Steven Osman
Debugging Optimized Code is
Hard…
Un-optimized code has a correlation
between source and object code
Optimizing compilers rearrange, add
and remove code. This results in:
Code location problems
 Data value problems

Talk Overview
Understanding the problems
Introducing Source-Level Debugging of
Scalar Optimized Code
Classifying data-value problems
Identifying data-value problems
What’s next?
The Code Location Problem
Source
S1:
S2:
S3:
S4:
y=0;
a=b+c;
x=2;
y=z*3;
Optimized Assembly
I1:
I2:
I3:
I4:
I5:
I6:
We want a breakpoint at S2
ld r1, b
ld r2, c
ld r5, z
mul r6, r5, 3
mov r4, 2
add r3, r1, r2
<S2>
<S2>
<S4>
<S4>
<S3>
<S2>
The Data-Value Problem
Source
S1:
S2:
S3:
S4:
y=0;
a=b+c;
x=2;
y=z*3;
Optimized Assembly
I1:
I2:
I3:
I4:
I5:
I6:
ld r1, b
ld r2, c
ld r5, z
mul r6, r5, 3
mov r4, 2
add r3, r1, r2
What is the value of y at S2?
<S2>
<S2>
<S4>
<S4>
<S3>
<S2>
Source-Level Debugging of
Scalar Optimized Code
By Ali-Reza Adl-Tabatabai and Thomas
Gross
Identifies data-value problems
No changes to the optimized code
Uses knowledge of optimizations
Some Simple Terminology
Expected value = value a variable
should have
Actual value = value stored in register
Current = Actual value IS expected
value (true for all in unoptimzed code)
Endangered = Not current
Noncurrent = Actual IS NOT expected
 Suspect = Actual may be expected

Code Hoisting
E0: x=u-v
E1: x=y+z
Bkpt1
Bkpt2
E2: x=y+z
Bkpt3
Code Hoisting
E0: x=u-v
E1: x=y+z
E3: x=y+z
Bkpt1
Bkpt2
E2: x=y+z
Bkpt3
E2=RedCopy(E3)
Hoist Reaches
E0: x=u-v
E1: x=y+z
E3: x=y+z
Bkpt1
Bkpt2
E2: x=y+z
Bkpt3
E2=RedCopy(E3)
Dead Code Elimination
E0: x=y+z
Bkpt1
Bkpt3
E1: …=x
Bkpt2
Bkpt4
Bkpt5
E2: x=u-v
Bkpt6
Dead Code Elimination
E0: x=y+z
Bkpt1
Bkpt3
E3: x=y+z
Bkpt2
E1: …=x
Bkpt4
Bkpt5
E2: x=u-v
Bkpt6
Dead Reaching
E0: x=y+z
Bkpt1
Bkpt3
E3: x=y+z
Bkpt2
E1: …=x
Bkpt4
Bkpt5
E2: x=u-v
Bkpt6
What’s Next?
Good paper, but it only warns
programmer
Suggestions about how to get the
expected value
Alok Ladsariya’s talk…