Title: Pegasus: A Program Intermediate Representation
1Pegasus A Program Intermediate Representation
- Mihai Budiu
- April 9, 2002
2Original MotivationCompiling C to Hardware
HLL program
Compiler
Circuit
Reconfigurable hardware
3Context
Phoenix project http//www.cs.cmu.edu/phoenix Re
configurable nanotechology
ASHApplication-Specific Hardware
CASHCompiler for ASH
Pegasus Predicated Explicit GAted Simple Uniform
SSAIntermediate Representation
4Pegasus
- Intermediate program representation
- Unifies
- Static-Single Assignment (SSA)
- Predication
- Speculative execution
- Dataflow machines
- Precise semantics
- Sparse
- Very efficient for scalar optimizations
5ModelData is Produced and Consumed
7
3
5
6ModelAsynchronous Computation
ack
data
rdy
one for each consumer
7Outline
- Pegasus features
- Building Pegasus
- Hyperblock formation
- Path predicates
- Predication Speculation SSA
- Inter-hyperblock control-flow
- Side-effect sequencing
- Optimizations
- Conclusions
8Building Pegasus Overview
- divide CFG in regions(atomic execution units)
- implement each region
- link regions
- optimize
- generate code
CFG
9Hyperblocks
- CFG fragment
- One entry, multiple exits
- No back-edges
- DAGs
- Introduced for EPIC
basic block
10Speculation
- Hyperblock unit of speculation(execute
everything inside) - Can partition CFG in many ways
Maximum speculation
No speculation
11Covering CFG with Hyperblocks
- We chose maximal hyperblocks
- Interval analysis
- hyperblocks minimum intervals
- Entry points
- loop entry
- loop exit successors
- predecessors in different hypers
- CFG Edges
- internal (thick)
- cross (thin)incl. backedges (blue)
12Outline
- Pegasus features
- Building Pegasus
- Hyperblock formation
- Path predicates
- Predication Speculation SSA
- Inter-hyperblock control-flow
- Side-effect sequencing
- Optimizations
- Conclusions
13Block- and Edge-Predicates
e
s
t
b
P(b) true iff b is executed
14Predicated Execution
if (x gt 0) y -x else y 2x z / y
15Predication in Pegasus
p(a)
p(b)
p(c)
p(d)
16Outline
- Pegasus features
- Building Pegasus
- Hyperblock formation
- Path predicates
- Predication Speculation SSA
- Inter-hyperblock control-flow
- Side-effect sequencing
- Optimizations
- Conclusions
17Speculative Execution
f()0
f()
h()
g()
if (f()) g() else h()
h()
g()
Code
Sequential
Speculative
18Predicate Promotion Speculation
19Speculation in Pegasus
side-effect
predicatecomputation
predicatecomputation
instructions
instructions
Delete predicates of instructions w/o side-effects
20Predicates Speculation G-SSA
p
a e if (x) goto L
q
a f if (y) goto L
r
L ... a ...
21Example
22Outline
- Pegasus features
- Building Pegasus
- Hyperblock formation
- Path predicates
- Predication Speculation SSA
- Inter-hyperblock control-flow
- Side-effect sequencing
- Optimizations
- Conclusions
23Merge and eta
i1
i2
o
o some i
24Cross-edges
25Example
26Outline
- Pegasus features
- Building Pegasus
- Hyperblock formation
- Path predicates
- Predication Speculation SSA
- Inter-hyperblock control-flow
- Side-effect sequencing
- Optimizations
- Conclusions
27Handling Pointers
p 2 a q
p
2
- Must preserveprogram order fornon-commutative
side-effects
q
a
28Example
29Outline
- Pegasus features
- Building Pegasus
- Optimizations
- Conclusions
30Free Optimizations
- Global constant propagation
- Copy propagation
- Unreachable code elimination
- Straightening
- Branch chaining
- (Almost) minimal SSA representation
31Control-Flow Optimizations on Pegasus
CFG
Pegasus
optimize
optimize
Pegasus
CFG
32Constant Folding
5
3
8
33Dead-Code Elimination
34Global Common Subexpression Elimination
35GCSE
- Same as
- partial redundancy elimination
- value numbering
- redundant load elimination
- code hoisting
- tail merging
36Store Forwarding
a
e
p
tk
tk
37Loop-invariant Code Motion
8
38New Algebraic Simplifications
constant ifs
gt minimal SSA
39Optimizations
- Those presented take linear time
- Do not require dataflow analysis
- Do not require incremental recomputations
- Complete implementation 1000 C lines(incl.
constant folding strength reduction, but
except loop-invariant code motion) - All required information is encoded in graph.
40Conclusions
- Pegasus is a practical IR
- Sparse SSA space complexity
- Easy to build (linear time)
- Encodes data-flow and control-flow
- Complete description of program
- Precise semantics
- Efficient for optimizations (linear time for
most scalar optimizations)
41Extra Slides
- Generating hardware
- Lenient evaluation
- Loop pipelining
- Semantics
- Reconfigurable hardware
42Generating Hardware from Pegasus
- Almost one-to-one correspondence
- naturally asynchronous implementation
- extensible to globally-async, locally sync
- Special care for efficient speculation
- lenient operations
back
43Critical Paths
x
b
0
if (x gt 0) y -x else y bx
!
y
44Executing Lenient Operators
x
b
0
if (x gt 0) y -x else y bx
!
y
45Lenient Operations
- Multiplexors
- Boolean (and, or)
- Predicated operations, when predicate is false
back
46Pipelining
47Loop Pipelining
48Loop Pipelining
back
49Semantics
- Precise formulation for all operations
- Only 3 main types of operations
- strict
- lenient
- non-strict
- Enables formal correctness proofs
back
50Reconfigurable Hardware
back to presentation
51Main RH Ingredient RAM Cell
data in
0
control
Switch controlled by a 1-bit RAM cell
back