Instruction Scheduling Beyond Basic Blocks Copyright 2003 Keith
Instruction Scheduling: Beyond Basic Blocks Copyright 2003, Keith D. Cooper, Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit permission to make copies of these materials for their personal use.
Local Scheduling As long as we stay within a single block • List scheduling does well • Problem is hard, so tie-breaking matters More descendants in dependence graph ® Prefer operation with a last use over one with none ® Breadth first makes progress on all paths ¨ Tends toward more ILP & fewer interlocks ® Depth first tries to complete uses of a value ¨ Tends to use fewer registers ® Classic work on this is Gibbons & Muchnick
Local Scheduling Forward and backward can produce different results 8 8 load. I 1 lshift 7 2 cmp 8 load. I 2 7 8 load. I 3 7 7 Subscript to identify 7 add 1 add 2 add 3 add 4 add. I 5 5 5 store 1 store 2 store 3 store 4 store 5 Block from SPEC benchmark “go” cbr Latency to the cbr load. I 4 1 Operation 8 load. I add. I store cmp 1 1 2 1 4 1
Local Scheduling F o r w a r d S c h e d u l e Int 1 load. I 1 lshift 2 load. I 3 3 load. I 4 add 1 4 add 2 add 3 5 add 4 add. I 6 cmp Mem store 1 store 2 7 store 3 8 store 4 9 store 5 10 11 12 13 cbr B a c k w a r d S c h e d u l e Int Mem 1 load. I 4 2 add. I lshift 3 add 4 load. I 3 4 add 3 load. I 2 store 5 5 add 2 load. I 1 store 4 6 add 1 store 3 7 store 2 8 store 1 9 10 11 cmp 12 cbr 13 Using latency to root as the priority
Local Scheduling Schielke’s RBF algorithm • Run 5 passes of forward list scheduling and 5 passes of backward list scheduling • Break each tie randomly • Keep the best schedule Shortest time to completion ® Other metrics are possible Randomized Backward & Forward ® In practice, this does very well (shortest time + fewest registers)
Scheduling Larger Regions Superlocal Scheduling • Work EBB at a time • Example has four EBBs B 1 B 2 B 4 B 3 e f B 5 h i B 6 a b c d l j k g
Scheduling Larger Regions Superlocal Scheduling • Work EBB at a time • Example has four EBBs • Only two have nontrivial paths ® B 1 {B 1, B 2, B 4 } & {B 1, B 3 } • Having B 1 in both causes conflicts ® B 2 Moving an op out of B 1 causes problems B 4 B 3 e f B 5 h i B 6 a b c d l j k g
Scheduling Larger Regions Superlocal Scheduling • Work EBB at a time • Example has four EBBs • Only two have nontrivial paths ® B 1 {B 1, B 2, B 4 } & {B 1, B 3 } • Having B 1 in both causes conflicts ® B 2 Moving an op out of B 1 causes problems B 4 B 5 l no c here ! B 3 c, e f h i B 6 a b c d j k g
Scheduling Larger Regions Superlocal Scheduling • Work EBB at a time • Example has four EBBs • Only two have nontrivial paths ® B 1 {B 1, B 2, B 4 } & {B 1, B 3 } • Having B 1 in both causes conflicts Moving an op out of B 1 causes problems ® Must insert “compensation” code in B 3 B 4 ® Increases code space B 2 ® B 5 l This one wasn’t done for speed! B 3 c, e f h i B 6 a b c d j k c g
Scheduling Larger Regions Superlocal Scheduling • Work EBB at a time • Example has four EBBs • Only two have nontrivial paths ® B 1 {B 1, B 2, B 4 } & {B 1, B 3 } • Having B 1 in both causes conflicts ® B 2 Moving an op into B 1 causes problems B 4 B 3 e f B 5 h i B 6 a b c d l j k g
Scheduling Larger Regions Superlocal Scheduling • Work EBB at a time • Example has four EBBs • Only two have nontrivial paths ® B 1 {B 1, B 2, B 4 } & {B 1, B 3 } B 2 • Having B 1 in both causes conflicts Moving an op into B 1 causes problems B 4 ® Lengthens {B 1, B 3 } ® Adds computation to {B 1, B 3 } ® May need compensation code, too ¨ Renaming may avoid “undo f” a b c d, f B 3 undo f g e f ® B 5 h i B 6 l This makes the path even longer! j k
Scheduling Larger Regions Superlocal Scheduling • How much can we get? B 1 Schielke saw 11 to 12% speed ups ® Constrained away compensation code ® • Why was this harder than DVNT? ® ® ® DVNT moved information Scheduling moves ops DVNT moves forward Scheduling moves both ways. B 4 Value tables partition nicely Dependence graph does not B 2 B 3 e f B 5 h i B 6 a b c d g j k l Value numbering is the best case for superlocal scope
Scheduling Larger Regions More Aggressive Superlocal Scheduling • Clone blocks to create more context B 2 Join points create blocks that must work in multiple contexts B 4 B 1 B 3 e f B 5 h i B 6 a b c d l j k 3 paths g 2 paths
Scheduling Larger Regions More Aggressive Superlocal Scheduling • Clone blocks to create more context • Some blocks can combine ® B 1 Single successor, single predecessor B 2 B 4 B 6 a h i l a b c d B 3 e f B 5 a B 6 b j k l B 5 b B 6 c g j k l
Scheduling Larger Regions More Aggressive Superlocal Scheduling • Clone blocks to create more context • Some blocks can combine ® B 1 Single successor, single predecessor B 2 B 4 B 6 a h i l a b c d B 3 e f B 5 a B 6 b j k l B 5 b B 6 c g j k l
Scheduling Larger Regions More Aggressive Superlocal Scheduling • Clone blocks to create more context • Some blocks can combine ® Single successor, single predecessor • Now schedule EBBs B 2 {B 1, B 2, B 4 }, {B 1, B 2, B 5 q }, {B 1, B 3, B 5 b } ® B 1 Pay heed to compensation code B 4 h i l B 3 e f B 5 a • Works well forward motion • Backward motion still has off-path problems ® a b c d Speeding up one path can slow down others (undo) j k l B 5 b g j k l
Scheduling Larger Regions Trace Scheduling • Start with execution counts for edges ® B 1 Obtained by profiling B 2 B 4 B 3 e f B 5 h i B 6 a b c d l j k g
Scheduling Larger Regions 10 Trace Scheduling • Start with execution counts for edges ® B 1 Obtained by profiling a b c d • Pick the “hot” path 7 B 2 B 3 e f 2 5 B 4 3 B 5 h i 5 B 6 3 j k 5 l g Block counts could mislead us — see B 5
Scheduling Larger Regions 10 Trace Scheduling • Start with execution counts for edges ® B 1 Obtained by profiling a b c d • Pick the “hot” path ® B 1, B 2, B 4, B 6 7 • Schedule it B 2 Compensation code in B 3, B 5 if needed ® Get the hot path right! ® If we picked the right path, the other blocks do not matter as much ® B 3 e f 2 5 B 4 B 5 h i Places a premium on quality profiles 5 B 6 3 l 3 j k 5 g
Scheduling Larger Regions 10 Trace Scheduling Entire CFG • Pick & schedule hot path • Insert compensation code • Remove hot path from CFG Repeat the process until CFG is empty B 1 7 B 2 Idea • Hot paths matter • Farther off hot path, less it matters 3 B 3 e f 2 5 B 4 a b c d B 5 h i 5 B 6 l 3 j k 5 g
- Slides: 20