1 cs 201 compiler construction lecture 13 instruction scheduling: trace scheduler

Post on 20-Dec-2015

217 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

1

CS 201Compiler Construction

Lecture 13Instruction Scheduling:

Trace Scheduler

Instruction Scheduling

Modern processors can exploit Instruction Level Parallelism (ILP) by simultaneously executing multiple instructions. Instruction scheduling influences effectiveness with which ILP is exploited.Pipelined processors (e.g., ARM): reordering of instructions avoids delays due hazards.EPIC/VLIW processors (e.g. Itanium): a single long instruction is packed with multiple operations (conventional instructions) that can be simultaneously executed.

2

Compiler Support

Analyze dependences and rearrange the order of instructions, i.e. perform instruction scheduling.Pipelined: limited amount of ILP is required -- can be uncovered by reordering instructions within each basic block.EPIC/VLIW: much more ILP is required -- can be uncovered by examining code from multiple basic blocks.

3

Compiler Support

Two techniques that go beyond basic block boundaries to uncover ILP:(Acyclic Schedulers) Trace Scheduling: examines a trace – a sequence of basic blocks along an acyclic program path; instruction scheduling can result in movement of instructions across basic block boundaries.(Cyclic Schedulers) Software Pipelining: examines basic blocks corresponding to consecutive loop iterations; instruction scheduling can result in movement of instructions across loop iterations.

4

Trace Scheduling

A trace is a sequence of basic blocks that does not extend across loop boundaries.

5

• Select a trace• Determine the instruction schedule for the trace• Introduce compensation code to preserve program semantics• Repeat the above steps till some part of the program is yet to be scheduled

Trace Selection

Selection of traces is extremely important for overall performance – traces should represent paths that are executed frequently.

A fast instruction schedule for one path is obtained at the expense of a slower schedule for the other path due to speculative code motion.

6

Picking Traces

O – operation/instructionCount(o) – number of times o is expected to be executed during an entire program run.Prob(e) – probability that an edge e will be executed -- important for conditional branches. Count(e) = Count(branch) x Prob(e)

o Counts are estimated using profiling – measure counts by running the program on a representative input.

7

Algorithm for Trace Construction

1. Pick an operation with the largest execution count as the seed of the trace.

2. Grow the trace backward from the seed.3. Grow the trace forward from the seed.

8

Given that p is in the trace, include s in the trace iff:1.Of all edges leaving p, e has the largest execution count.2.Of all edges entering s, e has the highest execution count.Same approach taken to grow the trace backward.

Algorithm Contd..

Trace stops growing forward when:Count(e1) < count(e2)

9

Premature termination of trace can occur in the above algorithm. To prevent this, a slight modification is required.

Algorithm Contd..

Lets say A-B-C-D has been included in the current trace.

Count(D-E) > Count(D-F) => add ECount(C-E) > Count(D-E) => do not add

E

10

Premature termination occurs because the trace that can include C-E can no longer be formed because C is already in the current trace.

Modification: consider only edges P-E st P is not already part of he current trace.

Algorithm Contd..

Trace cannot cross loop boundaries:• if the edge encountered is a loop back edge; or• if edge enters into a loopthen stop growing the trace.

11

1 & 2 cannot be placed in the same trace because the edge directly connecting them is a loop back edge and edges indirectly connecting them cross loop boundaries.

Instruction Scheduling

Construct a DAG for the selected trace.Generate an instruction schedule using a scheduling heuristic: list scheduling with critical path first.Following generation of the instruction schedule introduction of compensation code may be required to preserve program semantics.

12

Compensation Code

Consider movement of instructions across basic block boundaries, i.e. past splits and merges in the control flow graph.1. Movement of a statement past/below a Split:

13

Compensation Code Contd..

2. Movement of a statement above a Join:

14

Compensation Code Contd..

15

3. Movement of a statement above a Split:

No compensation code introduced – speculation.Note that i<-i+2 can be moved above spilt if i is dead along the off-trace path.

Compensation Code Contd..

16

4. Movement of a statement below a Join:

This case will not arise assuming dead code has been removed.

Compensation Code Contd..

17

5. Movement of a branch across a split.

Compensation Code Contd..

18

6. Movement of a branch above a join.

Compensation Code Contd..

19

6. Movement of a branch above a join.

Compensation Code Contd..

20

7. Packing multiple branches in a long instruction.

Code Explosion

21

Code Explosion Contd..

22

Building a DAG for Scheduling

DAG contains the following edges:1.Write-After-Read data dependence2.Write-After-Write data dependence3.Read-After-Write data dependence4.Conditional jumps: introduce write-after-conditional-read edge between IF e & x=c+d to prevent movement of x=c+d above IF e.

23

Building a DAG Contd..

5. Condition jumps:– Introduce off-live edge

between x=a+b nd IF e.– This edge does not

constrain movement past IF e; it indicates that if x=a+b is moved past IF e then it can be eliminated from the trace but a copy must be placed along the off-trace path.

24

top related