Instruction Scheduling: Beyond Basic Blocks

Slides:



Advertisements
Similar presentations
Register Allocation Consists of two parts: Goal : minimize spills
Advertisements

Code Optimization, Part II Regional Techniques Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp.
Operator Strength Reduction From Cooper, Simpson, & Vick, “Operator Strength Reduction”, ACM TOPLAS, 23(5), See also § of EaC2e. 1COMP 512,
Optimal Instruction Scheduling for Multi-Issue Processors using Constraint Programming Abid M. Malik and Peter van Beek David R. Cheriton School of Computer.
Components of representation Control dependencies: sequencing of operations –evaluation of if & then –side-effects of statements occur in right order Data.
Limits on ILP. Achieving Parallelism Techniques – Scoreboarding / Tomasulo’s Algorithm – Pipelining – Speculation – Branch Prediction But how much more.
SSA-Based Constant Propagation, SCP, SCCP, & the Issue of Combining Optimizations 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon,
Instruction Scheduling, III Software Pipelining Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp.
Intermediate Representations Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
Code Shape III Booleans, Relationals, & Control flow Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled.
1 CS 201 Compiler Construction Lecture 13 Instruction Scheduling: Trace Scheduler.
U NIVERSITY OF M ASSACHUSETTS, A MHERST Department of Computer Science Emery Berger University of Massachusetts, Amherst Advanced Compilers CMPSCI 710.
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Instruction Scheduling II: Beyond Basic Blocks Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp.
Code Optimization, Part III Global Methods Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412.
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Introduction to Optimization, II Value Numbering & Larger Scopes Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students.
Spring 2014Jim Hogg - UW - CSE - P501O-1 CSE P501 – Compiler Construction Instruction Scheduling Issues Latencies List scheduling.
Combining Scheduling & Allocation Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
Local Register Allocation & Lab Exercise 1 Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp.
Order from Chaos — the big picture — 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Order from Chaos — the big picture — C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved.
Operator Strength Reduction C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved. Students.
Building SSA Form, III 1COMP 512, Rice University This lecture presents the problems inherent in out- of-SSA translation and some ways to solve them. Copyright.
Cleaning up the CFG Eliminating useless nodes & edges C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon,
Local Instruction Scheduling — A Primer for Lab 3 — Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Local Instruction Scheduling — A Primer for Lab 3 — Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled.
Global Register Allocation via Graph Coloring Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp.
Introduction to Code Generation Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice.
Dead Code Elimination This lecture presents the algorithm Dead from EaC2e, Chapter 10. That algorithm derives, in turn, from Rob Shillner’s unpublished.
Boolean & Relational Values Control-flow Constructs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in.
Cleaning up the CFG Eliminating useless nodes & edges This lecture describes the algorithm Clean, presented in Chapter 10 of EaC2e. The algorithm is due.
Profile-Guided Code Positioning See paper of the same name by Karl Pettis & Robert C. Hansen in PLDI 90, SIGPLAN Notices 25(6), pages 16–27 Copyright 2011,
Building SSA Form, I 1COMP 512, Rice University Copyright 2011, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled in Comp 512 at.
Instruction Scheduling Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Profile Guided Code Positioning C OMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved.
Instruction Scheduling: Beyond Basic Blocks Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp.
Introduction to Optimization
Local Register Allocation & Lab Exercise 1
Finding Global Redundancies with Hopcroft’s DFA Minimization Algorithm
Local Instruction Scheduling
Context-sensitive Analysis
Introduction to Optimization
Instruction Scheduling Hal Perkins Summer 2004
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Intermediate Representations
Introduction to Code Generation
Wrapping Up Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University have explicit.
CS 201 Compiler Construction
Building SSA Form COMP 512 Rice University Houston, Texas Fall 2003
Instruction Scheduling Hal Perkins Winter 2008
Local Instruction Scheduling — A Primer for Lab 3 —
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Code Shape III Booleans, Relationals, & Control flow
Intermediate Representations
Optimization through Redundancy Elimination: Value Numbering at Different Scopes COMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith.
The Last Lecture COMP 512 Rice University Houston, Texas Fall 2003
Lexical Analysis — Part II: Constructing a Scanner from Regular Expressions Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved.
Peephole Optimization & Other Post-Compilation Techniques COMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper & Linda Torczon,
Local Register Allocation & Lab Exercise 1
Introduction to Optimization
Instruction Scheduling: Beyond Basic Blocks
Optimizing Compilers CISC 673 Spring 2011 Static Single Assignment II
Instruction Scheduling Hal Perkins Autumn 2005
Copyright 2003, Keith D. Cooper & Linda Torczon, all rights reserved.
Algebraic Reassociation of Expressions COMP 512 Rice University Houston, Texas Fall 2003 P. Briggs & K.D. Cooper, “Effective Partial Redundancy Elimination,”
Lecture 17: Register Allocation via Graph Colouring
The Partitioning Algorithm for Detecting Congruent Expressions COMP 512 Rice University Houston, Texas Fall 2003 Copyright 2003, Keith D. Cooper.
CSE P 501 – Compilers SSA Hal Perkins Autumn /31/2019
Instruction Scheduling Hal Perkins Autumn 2011
Presentation transcript:

Instruction Scheduling: Beyond Basic Blocks Copyright 2003, Keith D. Cooper, Ken 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

Block from SPEC benchmark “go” Local Scheduling Forward and backward can produce different results Latency to the cbr 8 8 8 8 8 cbr cmp store1 store2 store3 store4 store5 add1 add2 add3 add4 addI loadI1 lshift loadI2 loadI3 loadI4 Subscript to identify 7 7 7 7 7 2 5 5 5 5 5 Block from SPEC benchmark “go” 1 Operation load loadI add addI store cmp Latency 1 2 4

Using latency to root as the priority Local Scheduling F o r w a d S c h e u l Int Mem 1 loadI1 lshift 2 loadI2 loadI3 3 loadI4 add1 4 add2 add3 5 add4 addI store1 6 cmp store2 7 store3 8 store4 9 store5 10 11 12 13 cbr B a c k w r d S h e u l Int Mem 1 loadI4 2 addI lshift 3 add4 loadI3 4 add3 loadI2 store5 5 add2 loadI1 store4 6 add1 store3 7 store2 8 store1 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 (shortest time + fewest registers) In practice, this does very well Randomized Backward & Forward

Scheduling Larger Regions Superlocal Scheduling Work EBB at a time Example has four EBBs a b c d g e f h i l j k B1 B2 B4 B6 B5 B3

Scheduling Larger Regions Superlocal Scheduling Work EBB at a time Example has four EBBs Only two have nontrivial paths {B1,B2,B4 } & {B1,B3 } Having B1 in both causes conflicts Moving an op out of B1 causes problems a b c d g e f h i l j k B1 B2 B4 B6 B5 B3

Scheduling Larger Regions Superlocal Scheduling Work EBB at a time Example has four EBBs Only two have nontrivial paths {B1,B2,B4 } & {B1,B3 } Having B1 in both causes conflicts Moving an op out of B1 causes problems a b c d g c,e f h i l j k B1 B2 B4 B6 B5 B3 no c here !

Scheduling Larger Regions Superlocal Scheduling Work EBB at a time Example has four EBBs Only two have nontrivial paths {B1,B2,B4 } & {B1,B3 } Having B1 in both causes conflicts Moving an op out of B1 causes problems Must insert “compensation” code in B3 Increases code space a b c d g c,e f h i l j k B1 B2 B4 B6 B5 B3 This one wasn’t done for speed!

Scheduling Larger Regions Superlocal Scheduling Work EBB at a time Example has four EBBs Only two have nontrivial paths {B1,B2,B4 } & {B1,B3 } Having B1 in both causes conflicts Moving an op into B1 causes problems a b c d g e f h i l j k B1 B2 B4 B6 B5 B3

Scheduling Larger Regions Superlocal Scheduling Work EBB at a time Example has four EBBs Only two have nontrivial paths {B1,B2,B4 } & {B1,B3 } Having B1 in both causes conflicts Moving an op into B1 causes problems Lengthens {B1,B3 } Adds computation to {B1,B3 } May need compensation code, too Renaming may avoid “undo f” a b c d,f undo f g e f h i l j k B1 B2 B4 B6 B5 B3 This makes the path even longer!

Scheduling Larger Regions Superlocal Scheduling How much can we get? 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 Value tables partition nicely Dependence graph does not a b c d g e f h i l j k B1 B2 B4 B6 B5 B3 Value numbering is the best case for superlocal scope

Scheduling Larger Regions More Aggressive Superlocal Scheduling Clone blocks to create more context a b c d g e f h i l j k B1 B2 B4 B6 B5 B3 Join points create blocks that must work in multiple contexts 2 paths 3 paths

Scheduling Larger Regions More Aggressive Superlocal Scheduling Clone blocks to create more context Some blocks can combine Single successor, single predecessor B1 a b c d B2 B3 e f g B4 B5a B5b h i j k j k B6a B6b B6c l l l

Scheduling Larger Regions More Aggressive Superlocal Scheduling Clone blocks to create more context Some blocks can combine Single successor, single predecessor B1 a b c d B2 B3 e f g B4 B5a B5b h i j k j k B6a B6b B6c l l 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 {B1,B2,B4 }, {B1,B2,B5q }, {B1,B3,B5b } Pay heed to compensation code Works well for forward motion Backward motion still has off-path problems Speeding up one path can slow down others (undo) B1 a b c d B2 B3 e f g B4 B5a B5b h i l j k l j k l

Scheduling Larger Regions Trace Scheduling Start with execution counts for edges Obtained by profiling a b c d g e f h i l j k B1 B2 B4 B6 B5 B3

Scheduling Larger Regions 10 Trace Scheduling Start with execution counts for edges Obtained by profiling Pick the “hot” path a b c d g e f h i l j k B1 B2 B4 B6 B5 B3 7 3 5 2 3 5 5 Block counts could mislead us — see B5

Scheduling Larger Regions 10 Trace Scheduling Start with execution counts for edges Obtained by profiling Pick the “hot” path B1,B2,B4,B6 Schedule it Compensation code in B3,B5 if needed Get the hot path right! If we picked the right path, the other blocks do not matter as much Places a premium on quality profiles B1 a b c d 7 3 B2 B3 e f g 5 2 3 B4 B5 h i j k 5 5 B6 l

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 Idea Hot paths matter Farther off hot path, less it matters a b c d g e f h i l j k B1 B2 B4 B6 B5 B3 7 3 5 2 3 5 5