























Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!
























Reading Material
Conservative Approach to Control Dependences
Superblock
1: r1 = r2 + r32: r4 = load(r1)3: p1 = cmpp(r3 == 0)4: branch p1 Exit15: store (r4, -1)6: r2 = r2 – 47: r5 = load(r2)8: p2 = cmpp(r5 > 9)9: branch p2 Exit
Note: Control flow in red bold
Upward Code Motion Across Branches
Y
Restriction 1a (register op)
»
The destination of op is not inliveout(br)
»
Wrongly kill a live value
Y
Restriction 1b (memory op)
»
Op does not modify the memory
»
Actually live memory is whatmatters, but that is often too hard todetermine
Y
Restriction 2
»
Op must not cause an exception thatmay terminate the program executionwhen br is taken
»
Op is executed more often than it issupposed to (speculated
)
»
Page fault or cache miss are ok
Y
Insert control dep when eitherrestriction is violated
… if (x > 0)
y = z / x
…
control flow graph^ 1: branch x <= 0
2: y = z / x
Add Control Dependences to a Superblock
Superblock
Assumed liveout sets
1: r1 = r2 + r32: r4 = load(r1)3: p1 = cmpp(r2 == 0)4: branch p1 Exit15: store (r4, -1)6: r2 = r2 – 47: r5 = load(r2)8: p2 = cmpp(r5 > 9)9: branch p2 Exit
{r1}
{r2}
All ops have cdep to op 9!
{r5}
Notes: All branches are control dependent on one another. If no compensation, all ops dependent on last branch
Relaxing Code Motion Restrictions
Y
Upward code motion is generallymore effective
»
Speculate that an op is useful (justlike an out-of-order processor withbranch pred)
»
Start ops early, hide latency, overlapexecution, more parallelism
Y
Removing restriction 1
»
For register ops – use registerrenaming
»
Could rename memory too, butgenerally not worth it
Y
Removing restriction 2
»
Need hardware support (akaspeculation models
)
y
Some ops don’t cause exceptions
y
Ignore exceptions
y
Delay exceptions
1: branch x <= 0
2: y = z / x
R1: y is not in liveout(1) R2: op 2 will never cause
an exception when op1 is taken
Class Problem
1: r1 = r7 + 42: branch p1 Exit13: store (r1, -1)4: branch p2 Exit25: r2 = load(r7)6: r3 = r2 – 47: branch p3 Exit38: r4 = r3 / r
{r4} {r1} {r2}
{r4, r8}
Draw the dependence graph assuming the restricted speculation model
General Speculation Model
Y
Program terminating (traps)
y
Div by 0, illegal address
Fixable (normal and handledat run time)
y
Page fault, TLB miss
Y
Processor provides non-trapping versions of alloperations (div, load, etc)
Return some bogus value (0)when error occurs
R2 is completely ignored,only R1 limits speculation
Speculative ops convertedinto non-trapping version
Fixable exceptions handled asusual for non-trapping ops
Remove edge from 4 to 7
Class Problem
1: r1 = r7 + 42: branch p1 Exit13: store (r1, -1)4: branch p2 Exit25: r2 = load(r7)6: r3 = r2 – 47: branch p3 Exit38: r4 = r3 / r
{r4} {r1} {r2}
{r4, r8}
Sentinel Speculation Model
1: branch x == 0
Y
Debugging issue (is a program everfully correct?)
Y
Extra page faults
Y
Mark speculative ops (opcode bit)
Exceptions for speculative ops arenoted, but not handed immediately(return garbage value)
Check for exception conditions inthe “home block” of speculativepotentially excepting ops
2: y = *x 3: z = y + 4
4: *w = z
2’: y = *x 3’: z = y + 4
1: branch x == 0
check exception
4: *w = z
Delaying Speculative Exceptions (2)
1: branch x == 0
Y
Test NAT bit of appropriateregister (last register in dependencechain) in home block
Explicit checks
y
Insert new operation to check NAT
Implicit checks
y
Non-speculative use of registerautomatically serves as NAT check
Y
Figure out the exact cause
Handle if possible
Check with NAT conditionbranches to “recovery code”
Compiler generates the recoverycode specific to each check
2: y = *x 3: z = y + 4
4: *w = z
2’: y = *x 3’: z = y + 4
1: branch x == 0
check NAT(z)
4: *w = z
Delaying Speculative Exceptions (3)
2’: y = *x 3’: z = y + 4
1: branch x == 0 branch NAT(z) fixup
4: *w = z
2’’: y = *x 3’’: z = y + 4
jump done
fixup:
done:
Recovery code
In recovery code, the exception condition will be regenerated as the excepting op is re-executed with the same inputs If the exception can be handled, it is, all dependent ops are re-executed, and execution is returned to point after the check If the exception is a program error, execution is terminated in the recovery code
Recovery code consists of chain of operations starting with a potentially excepting speculative op up to its corresponding check
Class Problem
1: r1 = r7 + 42: branch p1 Exit13: store (r1, -1)4: branch p2 Exit25: r2 = load(r7)6: r3 = r2 – 47: branch p3 Exit38: r4 = r3 / r
{r4} {r1} {r2}
{r4, r8}
Move ops 5, 6, 8 as far up in the SB as possible assuming sentinel speculation support
Insert the necessary checks and recovery code (assume ld, st, and div can cause exceptions)
Trace Scheduling
Y
Invented by Josh Fisher andJohn Ellis in the early 80’s
Bulldog compiler
Multiflow compiler
Y
Traces have both sideentrances and exits
Scheduler must worry aboutboth
Trace
1: r1 = r2 + r32: r4 = load(r1)3: p1 = cmpp(r3 == 0)4: branch p1 Exit15: store (r4, -1)6: r2 = r2 – 47: r5 = load(r2)8: p2 = cmpp(r5 > 9)9: branch p2 Exit
{r2}
{r4}
{r4} {r2}
{r5}