High Level Synthesis - 02 - Basic Concepts
High Level Synthesis - 02 - Basic Concepts
Basic Concepts
26/02/21
HLS: Basic Concepts
2
Why use intermediate representations?
Simplifies retargeting
to new host • isolates back end from front end
-3-
Kinds of IR
3-address code
Hybrid combinations
-4-
Definition. Basic Blocks
Idea:
• Cannot jump in a basic block (except at beginning)
• Cannot jump out of a basic block (except at end)
• Each instruction in a basic block is executed after all the
preceding instructions have been executed
-5-
Basic Block Example
-7-
Basic Block Example
1 A=4
2 t1 = A * B Leaders
3 L1: t2 = t1/C
4 if t2 < W goto L2 Basic blocks
5 M = t1 * k
6 t3 = M + I
7 L2: H = I
8 M = t3 – H
9 if t3 >= 0 goto L4
10 L3: goto L1
11 L4: goto L3
8
Control-Flow Graphs
❑ Control-flow graph:
– Node: an instruction or sequence of instructions (a basic block)
• Two instructions i, j in same basic block
iff execution of i guarantees execution of j
– Directed edge: potential flow of control
– Distinguished start node Entry
• First instruction in program
9
Control-Flow Edges
10
Static Single Assignment Form
11
Why Static?
- 12 -
Example: Sequence
Original SSA
a := b + c a1 := b1 + c1
b := c + 1 b2 := c1 + 1
d := b + c d1 := b2 + c1
a := a + 1 a2 := a1 + 1
e := a + b e1 := a2 + b2
13
Example: Condition
Original SSA
if B then if B then
a := b a1 := b
else else
a := c a2 := c
end End
… a …
… a? …
14
Solution: -Function
Original SSA
if B then if B then
a := b a1 := b
else else
a := c a2 := c
end End
… a … a3 := (a1,a2)
… a3 …
15
The -Function
16
SSA and CFG
17
Control flow graph
if x = y then
S1
else
S2
end
S3
18
SSA: a Simple Example
if B then
a1 := 1
else
a2 := 2
End
a3 := PHI(a1,a2)
… a3 …
19
3-address code
x – 2 * y t1 = 2 * y
t2 = x – t1
> Advantages:
— compact form
— names for intermediate values
20
Typical 3-address codes
x = y op z
x = op y
assignments
x = y[i]
x=y
branches goto L
conditional branches if x relop y goto L
param x
procedure calls param y
call p
x = &y
address and pointer assignments
*y = z
21
Data flow graphs
❑ Graph:
– Vertices = operations.
– Edges = dependencies.
22
Data Flow Graph (cont.)
23
Dataflow graph Example
xl = x + dx
ul = u - (3 * x * u * dx) - (3 * y * dx)
yl = y + u * dx
c = xl < a
24
Example of Data Flow Graph
continued
xl = x + dx
ul = u - (3 * x * u * dx)
- (3 * y * dx)
yl = y + u * dx
c = xl < a
25
CDFG: control data flow graph
BB2
BB1
* *
+
1: t = a + b; BB0
2: u = a – b;
3: if (a < b)
4: v = t + c; BB2
else
{
5: w = u + c; BB3
6: v = w – d;
}
7: x = v + e; BB4
8: y = v – e;
27 27