Title: Compiling Esterel into Sequential Code
1Compiling Esterel intoSequential Code
Advanced Technology Group
2An Application
CoCentricTM System Studio
Control
Dataflow
Esterel
Dataflow Compiler
This work
C
C
Compiled Simulation
3The Esterel Language
4The Esterel Language
- Developed by G. Berry et al. starting 1983
5The Esterel Language
emit B if C emit D
Force signal B to be present in this cycle
Emit D if signal C is present
6The Esterel Language
await A emit B if C emit D
pause
Wait for next cycle with A present
Wait for next cycle
7The Esterel Language
loop await A emit B if C emit
D pause end
Infinite loop
8The Esterel Language
loop await A emit B if C emit
D pause end loop if B emit C
pause end
Run concurrently
9The Esterel Language
loop await A emit B if C emit
D pause end loop if B emit C
pause end
Same-cycle bidirectional communication
10The Esterel Language
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
Restart when RESET present
11The Esterel Language
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
Good for hierarchical FSMs
12The Esterel Language
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
Bad at manipulating data
13New Compiler
14The New Compiler
Esterel
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
15The New Compiler
Esterel
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
16The New Compiler
Esterel
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
17The New Compiler
Esterel
C
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
Void foo() switch (st) 0 if (IN3)
st 5 goto L5 1 if (RES)
st 3 goto L8 L5 switch
Step 4 Generate C
18The New Compiler
Esterel
C
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
Void foo() switch (st) 0 if (IN3)
st 5 goto L5 1 if (RES)
st 3 goto L8 L5 switch
- Generated code is 2 to 100? faster
- 1/2 to 1? the size
Concurrent Control-Flow Graph
Sequential Control-Flow Graph
Scheduled CCFG
19The New Compiler
Esterel
C
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
Void foo() switch (st) 0 if (IN3)
st 5 goto L5 1 if (RES)
st 3 goto L8 L5 switch
Flow similar to Lin DAC 98
Concurrent Control-Flow Graph
Sequential Control-Flow Graph
Scheduled CCFG
20Step 1 Build Concurrent CFG
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
RESET
21Add Threads
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
RESET
Fork
Join
22Split at Pauses
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
RESET
1
1
s
2
2
23Add Code Between Pauses
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
RESET
1
s
2
A
B
C
D
s2
s1
24Build Right Thread
every RESET do loop await A emit B
if C emit D pause end loop if B
emit C pause end end
25Step 2 Schedule
Add arcs for communication
RESET
Topological sort Optimal scheduling
NP-Complete Bad schedules OK
1
s
2
A
B
B
C
C
D
s2
s1
26Step 3 Sequentialize
- Hardest part Removing concurrency
- Simulate the Concurrent CFG
- Main Loop
- For each node in scheduled order,
- Insert context switch if from different thread
- Copy node connect predecessors
27Context Switching Code
28Run First Node
RESET
RESET
29Run First Part of Left Thread
RESET
1
s
2
B
1
s
A
2
A
B
30Context switch Save State
RESET
1
s
2
B
A
t0
t1
31Rejoin
RESET
1
s
2
B
A
t0
t1
32Run Right Thread
RESET
1
s
2
B
A
t0
t1
B
B
C
C
33Context Switch Restore State
RESET
1
s
2
B
A
t0
t1
B
C
0
1
t
34Resume Left Thread
RESET
1
s
2
B
A
t0
t1
B
C
C
0
1
t
D
D
C
s2
s1
s2
s1
35Step 3 Finished
RESET
RESET
1
s
2
B
1
s
A
2
A
t0
t1
B
B
B
C
C
C
0
1
t
D
D
C
s2
s1
s2
s1
36Related Work and Experiments
37Existing Esterel Compilers
Capacity
Simulation Speed
38Existing Esterel Compilers
Capacity
Automata V3 Berry 87, Polis DAC 95
Simulation Speed
39Existing Esterel Compilers
Logic gates V4, V5 Berry 92, 96
Capacity
Automata V3 Berry 87, Polis DAC 95
Simulation Speed
40Speed of Generated Code
Average cycle time (ms)
Size (source lines)
41Size of Generated Code
Object code size (K)
Size (source lines)
42Why This Wins
Automata
Zero overhead Code duplicated
Gates
No duplication Not event driven runs idle
code Significant overhead
New
Only active code runs No code duplication
Some overhead
43Why Not Event-Driven?
- Already exclusively running active code
- Behavior of event queue is simulated once at
compile-time and hardwired - Technically difficult for Esterel
- Netlist includes mixture of event and
level-sensitive entities
44Summary
- Esterel
- Deterministic concurrency
- Good for hierarchical FSMs
- New Compiler
- Build concurrent control-flow graph
- Schedule
- Sequentialize add context switches
- Results
- Code runs 2 to 100? faster
- 1 to 1/2 the size