This document discusses global code scheduling techniques. It defines global scheduling as strategies that operate on more than one basic block. The key techniques discussed are:
1. Basic block definition, primitive code motion, upward code motion, and downward code motion.
2. Upward code motion moves operations from one block to another it dominates, while satisfying data dependencies. Downward code motion considers dominance and post-dominance.
3. Global scheduling algorithms use region-based scheduling and speculative code motion to move operations between control-equivalent or dominating blocks. Advanced techniques add new blocks or implement downward motion.
3. DEFINITION
• A list of scheduling algorithm is used to create the
schedule for each basic block.
• The algorithm keeps a list of candidate
instructions,candlnsts,which contains all instructions in the
candidate block.
• It creates the schedule clock by clock.
4. STRATEGIES:
• Strategies that contains more than one basic block at a time are referred to as global
scheduling.
CONDITIONS:
1. All instructions in the original program are executed in the optimised one.
2. While the optimized program may execute extra instructions speculatively,these
instructions must not have any unwanted side effects.
5. BASIC BLOCK
• A basic block is constituted by set of instructions in
which the control entre the block through the first
instructions and leaves the block via the last instruction
without any deterrence or jump/branch in between
them.
6. PRIMITIVE CODE MOTION
Source program :
• Its involved in moving
Operation around by
Way of simple.
If (a ==0) goto L
C ==b
e = d + d
7. UPWARD CODE MOTION
• It’s move as operation from block SRC up a control flow path to block dsk.
• Such a move does not violate any data deoendences and it makes the path through dst and
src run faster.
• Case 1:
if src does not postdominate dst
In this case there exits a path that passes through dst that does not reach src.
This code motion is illegal unless techoperation moved has no unwanted side effects.
8. CASE:2 If dst does not dominant src
In this case there exists a path that reach src without first going through dst.
CONSTRAINTS :
1. The operands of the operation must hold the same values as in the original.
2. The result does not overwrite a value that is still needed and,
3. If itself a not subsequently overwritten before reaching src.
9. DOWNWARD CODE MOTION
• If is moving an operation from block src down a control flow path to block dst.
• CASE 1: src does not dominate dst.
There exists a path to dst that does not passes through src.
• CASE 2: dst does not post dominant src.
There exists a path through src does not pass through dst.
10. EXAMPLE
• If (x== 0) a=b;
Else a= c;
d=a;
(X==0)
(a==c) (a==b)
(d==a)
11. UPDATING DATA DEPENDENCE
• Code motions can change data dependence relations between operations.
• Thus the data dependence
Just be updated after each
Code motion.
X=1 X=2
12. GLOBAL SCHEDULING ALGORITHM
• Region based scheduling
• Two easiest form of code motion
1. Moving Operation up to control equivalent basic blocks.
2. Moving operation Speculatively up one branch to a dominating
predecessor.
13. ALGORITHM
For (i=0;i<N;i++)
{
S(i);
}
Can be unrolled
For(i=0;i+4<N;i+=4)
{
S(i);
S(i+1);
S(i+2);
S(i+3);
}
Repeat
S;
Until C;
Can be unrolled as
Repeatt
{
S;
If ( C. ) break;
S;
If (C ) break;
S;
}
Until C ;
14. ADVANCED CODE MOTION TECHNIQUES
• Adding new basic block along the control flow edges originating from blocks with more
than one predecessor.
• The code to be executed in each basic block is scheduling once for all as each block is
visited, because algorithm only move operation up to dominating block.
• Implementing download code motion is harder is an algorithm that visit that topological
order.