An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

21
An introduction to Esterel and its compilation Dumitru Potop, fresh PhD

Transcript of An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Page 1: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

An introduction to Esterel and its compilation

Dumitru Potop, fresh PhD

Page 2: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Outline

• (Long) Introduction– Embedded systems, Reactive systems,

Synchronous paradigm

• Esterel– Syntax and intuitive semantics

• Esterel translation schemes– Automata-based– Circuit-based– “Simulation”-based

Page 3: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Embedded systems

• Airplanes, cars, phones, washing machines, video cameras contain computers!– Complex, custom hardware/software architectures

• Specific problems in their development:– Specification, due to interdisciplinarity

• Specific languages, methods

– Compilation• Implementations must fit tight specifications• Joint development of hardware and software

– Insuring correctness, fault tolerance, and robustness (expensive bugs)

Page 4: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Reactive systems (Harel, 1987)

• Emphasis on communication and control

• React to input events with appropriate output events, according to the state

• Examples: digital circuits, man-machine interfaces, communication protocols

state

… …Inputs Outputs

Page 5: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Synchronous paradigm

• Cycle-based execution model, global clock• Perfect synchrony• Causality

Inputevent

Outputevent

computation

memory

Page 6: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Synchronous paradigm

• Synchrony = abstraction of the real world:

• Natural in circuits– Advantages: clear semantics, codesign, verification

methods– Problem: combining circuit semantics with a higher-

level description style

time

Execution instants

Page 7: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Synchronous languages

• Esterel (Berry et al.), ECL– Structural imperative (Ada-like) style– Fit for control-dominated parts

• Lustre (Halbwachs et al.), Signal (LeGuernic et al)– Dataflow networks– Circuit-like, low-level

• Argos (Maranichi), SyncCharts (André)– Visual Statecharts-like formalisms

Page 8: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

The Esterel language

• Structural imperative style– Intuitive, modular

• Basic constructs– Classical control flow: p;q, p||q, loop p end– Preemption:abort p when S, suspend p when S– Exception handling: trap T in p end, exit T– Division into instants: pause, await S– Signals: signal S in p end, emit S, present S then p else q end

Page 9: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

The Esterel language

• Example 1:

loop [ await A || await B ]; emit O; haltevery R

Page 10: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

The Esterel language

• Example 2:

signal S in await I ; emit S|| await S ; emit Oend signal

Page 11: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

The Esterel language

• Constructive causality – Correct causality cycles – Instantaneous reaction to signal absence

(analysis of not yet executed code)

signal S,T in emit S; present T then present S else emit T end end;end

causality cycle

break the cycle

Page 12: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Old translation schemes

• Automata translation– Fast, large code

1

2 3

4

0

/RBA /RBA

/ORAB

/ORA/ORB

R/ R/

R/

switch(state){case 0: state=1; break;case 1: if(!R)if(A)if(B) {O=1;state=4;} else state=2; else if(B)state=3;break;case 2: if(R)state=1; else if(B){O=1;state=4;} break;case 3: if(R)state=1; else if(A){O=1;state=4;} break;case 4: if(R)state=1;break;}

loop [ await A || await B ]; emit O; haltevery R

Page 13: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Old translation schemes

• Circuit translation– Slow, small code

boot

R

A

B

O

RESET = R & !BOOTA_TRIGGER = A_OUT & !RESET A_THEN = A_TRIGGER & AA_ELSE = A_TRIGGER & !AA_TERM = A_THEN | ! A_TRIGGERA_IN = BOOT | RESET | A_ELSE B_TRIGGER = B_OUT & !RESETB_THEN = B_TRIGGER & BB_ELSE = B_TRIGGER & !BB_TERM = B_THEN | ! B_TRIGGERB_IN = BOOT | RESET | B_ELSEACTIVE = A_TRIGGER | B_TRIGGERO = A_TERM & B_TERM & ACTIVE

loop [ await A || await B ]; emit O; haltevery R

Page 14: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Old translation schemes

• Direct semantic simulation (Edwards, Bertin)– Fast, small code through static scheduling

– Restrict the class of accepted programs

Resume: if(R) goto Start ; else if (A_active | B_active) { if (A_active & A) { A_active=0 ; } if (B_active & B) { B_active=0 ; } if (!(A_active | B_active)) { emit O ; } } goto Out;Start: A_active=1 ; B_active=1 ;Out:

loop [ await A || await B ]; emit O; haltevery R

Page 15: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Old translation schemes

Explicit FSM Circuits

Very large,Very fast

SmallSlow

Bisimulation(fc2tools)

RTL optimizations(SIS)

Expensive, slowGeneral

Cheap, fastGeneral*

Efficient code

Very smallVery fast

Classical control-flow optimizations

Cheap, fastOnly “acyclic” programs

*=sccausal or slow simulation

Semantically complete

Generated code(without optim.)

Optimization

Problems

Compilingmethod

Do not scale up wellSemantics (acyclic=?)Less powerful optim.

?Intermediate

model

Page 16: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

What I wanted• Generate efficient code for “good” programs• Generate code for all programs• Understand cyclicity at a higher level • Inexpensive optimizations based on static

analysis

• Formalize the efficient approach– New intermediate format/model (GRC)

• Hierarchical state representation• Control-flow graph• No specific encoding

How

Page 17: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

[2]

[3]

0[1]

enter 5

enter 4enter 3enter 2exit 1

2

enter 6exit 3K0

Inactive[4]

R

exit 2

4A

exit 4 K0[4]

K1[4]Inactive[5]

5B

exit 5 K0[5]

K1[5][6]

K1

emit O

#

||

0

1

2

boot:

await A

await B

haltloop-every

#

34

5

6

loop [ await A;emit B || await B ]; emit O; halt every R

emit B

GRC format – a small example

Page 18: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

GRC format – utility

• Supports the full Esterel semantics

• Analysis and optimization at GRC code level

• Supports optimized encoding and scheduling algorithms

Page 19: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Conclusion

• A very brief introduction to Esterel, its compilation, and my work

• During my PhD:– New Esterel semantics– Intermediate model for Esterel programs– Static analysis and optimization at this level– General code generation scheme– The best compiler yet

Page 20: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Past

• PhD at Ecole des Mines de Paris, with Gérard Berry

• Complete the work started during the PhD

• Investigate aspects related to code distribution (Benveniste et al.)

Future

Page 21: An introduction to Esterel and its compilation Dumitru Potop, fresh PhD.

Results

• Prototype compiler (acyclic case)

• Examples:1. Turbo channel bus2. Berry’s wristwatch3. Video generator4. Shock absorber5. Operating system

model6. Avionics fuel controller7. Avionics cockpit8. Man-machine interface

Size (kbytes)

0

50

100

150

200

250

300

350

1 2 3 4 5 6 7 8

GRC2C

FTR&D

Synopsys

Test configuration: PIII/1GHz/128M/Linuxgcc-2.96 –O, 1Mcycle random or given

Relative execution

time(%grc2c)

0

50

100

150

200

250

300

350

400

450

500

1 2 3 4 5 6 7 8

GRC2C

FTR&D

Synopsys